Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing physical memory from linux kernel

Can we access any physical memory via some kernel code.? Because, i wrote a device driver which only had init_module and exit_module.. the code is following.

int init_module(void) {
    unsigned char *p = (unsigned char*)(0x10);
    printk( KERN_INFO  "I got %u \n", *p);
    return 0;
}

and a dummy exit_module.. the problem is the computer gets hung when i do lsmod.. What happens? Should i get some kinda permission to access the mem location?

kindly explain.. I'm a beginner!

like image 372
raj Avatar asked Oct 25 '11 18:10

raj


2 Answers

To access real physical memory you should use phys_to_virt function. In case it is io memory (e.g. PCI memory) you should have a closer look at ioremap.

This whole topic is very complex, if you are a beginner I would suggest some kernel/driver development books/doc.

like image 155
flolo Avatar answered Nov 16 '22 03:11

flolo


I suggest reading the chapter about memory in this book:

http://lwn.net/Kernel/LDD3/

It's available online for free. Good stuff!

like image 20
hochl Avatar answered Nov 16 '22 04:11

hochl