Mapping physical addresses to virtual address linux

*爱你&永不变心* 提交于 2019-11-30 13:53:57
Longfield

What you are trying to do is accessing what is called IO memory. I can only encourage you to read the Linux Device Drivers (LDD) book and more specifically the chapter 9.

To "allocate" such an area, you need to call

struct resource *request_mem_region(unsigned long start, unsigned long len, char *name)

. Before your driver can access it, you have to assign it a virtual address, this is done with a call to

void *ioremap(unsigned long phys_addr, unsigned long size)

To ensure that your driver will then work on different architectures/platforms, be sure to use some accessor function to such areas ( ioread8/16/32 or iowrite8/16/32 and all of their variants).

Jeyaram

In Kernel module, remap_pfn_range() can be used to convert the physical address to virtual address. The following link will be helpful.

How remap_pfn_range remaps kernel memory to user space?

Divyank Shukla

In Kernel module, remap_pfn_range() can be used to convert the physical address to virtual address. When you don't have a actual devices you can: 1) create a virtual device and, 2) use mmap to those virtual devices to access the very same kernel memory through remap_pfn_range virtual mapping of that process. 3) Usually in dedicated environments you may addition want to pin those physical pages lest they are taken away from your process. 4) You also share these physical addresses with different processes but will need to handle synchronization, independently through other IPC mechanisms as to each process they will look as different addresses.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!