vendredi 8 août 2014

Pilote de périphérique dans le système de mémoire virtuelle - Stack Overflow


Assume that there is a device using memory-mapped I/O i.e. there is a specific range of physical memory assigned to this device


If virtual memory system is not used, then it is quite straightforward to manipulate the device through read/write operations done with corresponding physical addresses


What if there is virtual memory system ?


Device driver needs to be aware of that specific range of physical memory assigned to that device, but how does it access that address range if it should use virtual addresses instead of physical ?




In case of memory mapped IO devices, any physical address shared by that device can be mapped to the kernel virtual memory using the ioremap() API [1].


Hence in your case, we can map the physical address 0x1234 using ioremap() to obtain its kernel virtual address and start writing data to this address.


[1] http://lxr.gwbnsh.net.cn/linux/arch/cris/mm/ioremap.c




It's been a long time since I've done it, but my recollection is that when you map a block of physical memory, the address in your user space corresponds to that physical memory. Writing to your user-space address is a write to the physical memory.



Assume that there is a device using memory-mapped I/O i.e. there is a specific range of physical memory assigned to this device


If virtual memory system is not used, then it is quite straightforward to manipulate the device through read/write operations done with corresponding physical addresses


What if there is virtual memory system ?


Device driver needs to be aware of that specific range of physical memory assigned to that device, but how does it access that address range if it should use virtual addresses instead of physical ?



In case of memory mapped IO devices, any physical address shared by that device can be mapped to the kernel virtual memory using the ioremap() API [1].


Hence in your case, we can map the physical address 0x1234 using ioremap() to obtain its kernel virtual address and start writing data to this address.


[1] http://lxr.gwbnsh.net.cn/linux/arch/cris/mm/ioremap.c



It's been a long time since I've done it, but my recollection is that when you map a block of physical memory, the address in your user space corresponds to that physical memory. Writing to your user-space address is a write to the physical memory.


0 commentaires:

Enregistrer un commentaire