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:
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?
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.
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,