Search code examples
cmemory-managementlinux-device-driveruart

I/O memory region remap


The main reason for I/O memory region is to read/write anything to that memory. If the register address is given, we can use readx/writex (x stands for b/l/w).

Then why do we have to use the address returned by io_remap which is nothing but the same as the address of the particular register given in the data sheet?


Solution

  • ioremap is architecture specific function/macro. On some architectures it won't do anything and just basically return the address specified as an argument. It may do much more than that on other architectures, though. Take arm or x86 as an example - the ioremap will do a lot of checks before letting you using the memory region, for example.

    What's more important than those checks, however, is that ioremap can setup a mapping of virtual addresses (from vmalloc area) to the requested physical ones and ensure that caching is disabled for addresses you are going to use. So in most cases pointer returned by ioremap will not be the same as just numeric address from the datasheet.

    You want caching to be disabled because I/O registers are controlled by some external (from CPU point of view) devices. This means that processor can't know when its content changed, making cache content invalid.