1

I am working on an SoC with an embedded ARM and lots of hard-wired IP blocks. Each hardware block is memory mapped into the ARM space, i.e., the registers to control the hardware block is in the space 32-bit address space of the ARM CPU. We have Linux running on this CPU.

To access the hardware blocks, I use mmap as follows in an app that can run as root:

 fd = open("/dev/mem", O_RDWR | O_SYNC);
 mptr = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, phy_addr);

I want to understand a few things better before providing the BSP for other software engineers to develop code:

  1. Is MAP_SHARED correct thing to do or do I need MAP_NORESERVE also? Basically, I am accessing the hardware registers so I don't need to allocate swap space, correct?

  2. How do I make sure that read/write to the virtual space (mptr above) do not go through cache? volatile keyword is only for compiler optimizations.

  3. The entire hardware space is quite large actually - 16 MB (lots of SRAM and lots of registers). Can the length parameter to mmap be that large or will that cause trouble creating page tables and mapping? Will I need to create various virtual memory pointers or can I just get mptr and then just add the physical address offset and read/write hardware addresses happily?

Thanks a lot,

guraaf
  • 163
  • 4
  • 12
  • possible duplicate of [Memory mapped IO - how is it done?](http://stackoverflow.com/questions/9654504/memory-mapped-io-how-is-it-done) – aruisdante Oct 29 '14 at 19:31
  • In addition, you may wish to read http://www.gnu.org/software/libc/manual/html_node/Memory_002dmapped-I_002fO.html and http://www.xml.com/ldd/chapter/book/ch08.html for some additional documentation – aruisdante Oct 29 '14 at 19:35
  • Hello all, I went through many more pages on stackoverflow (as suggested above) and then some more on Linux device drivers, etc. I still didn't understand how would I ensure that I bypass the cache. None of the pages address this specifically. Also, do I need MAP_FIXED as well? Thanks for more pointers! – guraaf Nov 02 '14 at 23:14

0 Answers0