I have Linux and I have a physical address: (i.e. 0x60000000).
I want to read this address from user-space Linux program.
This address might be in kernel space.
To help you solve this question, we need to get our details right: 16 bit of virtual address space = 2^16 = 65,536 address space. 16 bit of physical address space = 2^16 = 65,536 address space. 4096 Byte page size determines the offset, which is Log(4096) / Log (2) = 12 bit.
page_address() returns the virtual address of a struct page ; this functions can be called only for pages from lowmem.
ioremap() function is used to map the physical addres of an I/O device to the kernel virtual address. Kernel creates a page table i.e mapping of virtual address to the physical address requested. When we do iounmap() this mapping is destroyed.
You need a kernel driver to export the phyisical address to user-level.
Have a look at this driver: https://github.com/claudioscordino/mmap_alloc/blob/master/mmap_alloc.c
Note that this is now possible via /proc/[pid]/pagemap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With