Search code examples
memorylinux-kernelkernellinux-device-drivervirtual-address-space

Can I load data from RAM by using pointer to memory with physical addressing?


Can I load data from RAM by using pointer to memory with physical addressing(not to virtual) from my driver (Linux-kernel) without allocating pages (PDEs/PTEs) in virtual addressing?


Solution

  • Yes! "/dev/mem" is an image of physical memory, and you can even access this from user space.

    For example, to access physical address 0x7000000, the code below summarizes the steps:

    fd = open("/dev/mem", O_RDWR);
    map = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x7000000);