Suppose I have a memory-mapped peripheral which can be read from or written to at some address, say 0x43C00000. I want to be able to read from that same memory location in my Linux OS in order to communicate with that peripheral. Since the address in question would be a physical address, I should be able to write a kernel module that can read from that address location.
In the kernel, if I have something like
#define BASE_ADDR 0x43C00000
#define OFFSET 4
int * mem_addr;
mem_addr = BASEADDR + OFFSET;
That, I think, should give me the pointer to the second writing block of the peripheral, at 0x43C00004. Printing
printk(KERN_INFO "%p\n", mem_addr)
seems to tell me this is right.
Now if I try to do something like
printk(KERN_INFO "%d\n", *mem_addr);
I would have thought that that should therefore read the data that is being written to memory by my peripheral, accomplishing what I was trying to do. But if I try putting a statement like this into a module, Linux kills it. Looking at my /var/log/messages I see this:
Oops: 0000 [#1] SMP
Modules linked in; TEST_MOD(0+) ...
followed by a bunch of information about register states. So I'm apparently not allowed to just read memory like that. Is there some way to grant access to a kernel module to read memory?
=in a#definedirective?