Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert physical address to virtual in Linux and read its content

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.

like image 308
Mikhail Kalashnikov Avatar asked Oct 21 '13 12:10

Mikhail Kalashnikov


People also ask

How can physical address corresponding to virtual address?

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.

Which call we can use to get the virtual address in Linux kernel?

page_address() returns the virtual address of a struct page ; this functions can be called only for pages from lowmem.

What is Ioremap in Linux?

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.


2 Answers

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

like image 166
Claudio Avatar answered Oct 29 '22 07:10

Claudio


Note that this is now possible via /proc/[pid]/pagemap

like image 23
HorseHair Avatar answered Oct 29 '22 08:10

HorseHair