1

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?

3
  • What language is this, in which you use an = in a #define directive? Commented Jul 20, 2016 at 8:13
  • My mistake, I copied wrong. Commented Jul 20, 2016 at 13:23
  • Why is this "off-topic" it's totally on topic, and is a completely valid question! Commented Sep 6, 2018 at 10:05

1 Answer 1

2

You need to set up a kernel virtual address mapping for the location e.g.

mem_addr = ioremap_nocache(BASEADDR + OFFSET, SIZE);

(you appear to have asked the same question twice - see enter link description here).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.