Page 1 of 1

Paging & Memory Mapped I/O

Posted: Sat Jun 19, 2010 12:52 pm
by Zerith
Hello,
I have ran into this problem today when trying to think about how my VGA driver would work.

Assuming a given device uses memory mapped i/o, the driver for the device would need to use identity-mapped memory.

For example, the device uses memory mapped i/o at address 0xD0000000, then when the driver tries to access (virtual) address
0xD0000000 - it should be translated to physical address 0xD0000000.

In this case, how would driver identity-map the specific memory area for the device? would it have to directly manipulate the
paging structures!? the sole thought of this makes me sick.

And, if the kernel was to identity-map it, how would it know in advance which addresses have to be identity-mapped?

Re: Paging & Memory Mapped I/O

Posted: Sat Jun 19, 2010 2:56 pm
by gravaera
Hi:

Your Virtual Memory Manager manages each process's virtual address space, and is supposed to be able to map pages in any address space to any frame or range of frames in RAM.

When a driver starts up, it either queries a parent driver for MMIO mappings or it will "know" its MMIO mapping (for devices which have a well established MMIO range across implementations). It sends a request to the VMM for the physical mem range to be mapped into its address space, and your VMM maps the p-mem to a v-address, and returns the v-address. Note well that this v-address need not be the corresponding p-address of the device's MMIO range.

The VMM could very well decide to map physical 0xD0000000 to 0x3A000000 in your driver's address space. Your driver must access the MMIO range as offsets from the returned virtual base address.

--All the best,
gravaera.

Re: Paging & Memory Mapped I/O

Posted: Sat Jun 19, 2010 10:49 pm
by Zerith
Alright, thank you very much for simplifying this.

Re: Paging & Memory Mapped I/O

Posted: Sun Jun 20, 2010 2:25 am
by skyking
Yes, the virtual-to-physical mapping need not even be continuous. The driver has to know what need to be known in order to work out the virtual addresses - sometimes (if you're using DMA transfers fx) this means that the driver needs to know the actual virtual-to-physical (and implicitly the physical-to-virtual) mapping.

Normally it wouldn't be a problem to identity map the physical memory region and if that were a problem it should be possible to arrange a continuous mapping.