Paging & Memory Mapped I/O

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Zerith
Posts: 14
Joined: Sun Jul 05, 2009 4:01 pm

Paging & Memory Mapped I/O

Post 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?
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Paging & Memory Mapped I/O

Post 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.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Zerith
Posts: 14
Joined: Sun Jul 05, 2009 4:01 pm

Re: Paging & Memory Mapped I/O

Post by Zerith »

Alright, thank you very much for simplifying this.
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Paging & Memory Mapped I/O

Post 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.
Post Reply