I'm currently working on a PCI device driver for Ubuntu. I have some example code about PCI driver, but I have difficult on understanding the ioremap and file_operation.mmap.
The description of file operation mmap:
Memory mapping is one of the most interesting features of modern Unix systems. As far as drivers are concerned, memory mapping can be implemented to provide user programs with direct access to device memory. Mapping a device means associating a range of user-space addresses to device memory. Whenever the program reads or writes in the assigned address range, it is actually accessing the device.
The description of ioremap:
On many systems, I/O memory is not directly accessible in this way at all. So a mapping must be set up first. This is the role of the ioremap function.The function is designed specifically to assign virtual addresses to I/O memory regions.
The above description all come from "makelinux". But still I'm not sure if I correctly understand the difference between the two functions. For now, I understand it the way like this: The fops.mmap
(file operation mmap) associates a range of user-space addresses to device memory. Which means for a pci device, we do real address map for the device's BAR
with fops.mmap
.
And with ioremap
, we do virtual address map for these "real addresses" got from fops.mmap
.
Could someone tell me if I was wrong? Thx~
PS. I posted this also in Ubuntu community, hope I didn't break any rules.