40

I've read about the difference between port mapped IO and memory mapped IO, but I can't figure out how memory mapped Io is implemented in modern operating systems (windows or linux)

What I know is that a part of the physical memory is reserved to communicate with the hardware and there's a MMIO Unit involved in taking care of the bus communication and other memory-related stuff

How would a driver communicate with underlying hardware? What are the functions that the driver would use? Are the addresses to communicate with a video card fixed or is there some kind of "agreement" before using them?

I'm still rather confused

3
  • 1
    Have you looked at Using I/O Memory and Memory Mapping and DMA? Commented Mar 11, 2012 at 11:38
  • 1
    Let's see if I got it(in linux): 1) I assign a memory IO area at the address the hardware producer told me to 2) I use ioremap to get it translated from physical addresses to virtual addresses (so this resolves both segmentation and paging I suppose) 3) I use iowrite/ioread and similar to read and write in that area. Is this correct? Commented Mar 11, 2012 at 11:58
  • That is correct, remember to free to allocate memory region after usage. Commented Mar 11, 2012 at 12:12

3 Answers 3

49

The following statement in your question is wrong:

What I know is that a part of the physical memory is reserved to communicate with the hardware

A part of the physical memory is not reserved for communication with the hardware. A part of the physical address space, to which the physical memory and memory mapped IO are mapped, is. This memory layout is permanent, but user programs do not see it directly - instead, they run into their own virtual address space to which the kernel can decide to map, wherever it wants, physical memory and IO ranges.

You may want to read the following articles which I believe contain answers to most of your questions:

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, I read them all and I found them useful to my purposes
As of 22/02/2022 the images in the above 3 links have disappeared.
They are visible to me at the moment, probably a temporary issue?
4

Are you asking about Memory mapped files, or memory mapped port-IO?

Memory mapped files are done by paging out the pages and intercepting page-faults to those addresses. This is all done by the OS by negotiation between the file-system manager and the page-fault handler.

Memory mapped port-IO is done at the CPU level by overloading address lines as port-IO lines which allow writes to memory to be translated onto the QPI bus lines as port-IO. This is all done by the processor interacting with the motherboard. The only other thing that the OS needs to do is to tell the MMU not to coalese reads and writes through the PAE must-writethrough and no-cache bits.

2 Comments

Some expansion of the acronyms would be very helpful here.
This is actually the answer that guided me to the write direction. "As far as a program is concerned, addresses in its logical address space are always available. However, if an application accesses an address on a memory page that is not currently in physical RAM, a page fault occurs. When that happens, the virtual memory system invokes a special page-fault handler to respond to the fault immediately." This handler may do different things, including interaction with disk.
3

http://en.wikipedia.org/wiki/Memory-mapped_I/O

http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/IO/mapped.html

Essentially it is just a form of accessing the data, as if you are saving / reading from the memory. But the hardware will snoop on the address bus, and when it sees the address targetting for him, it will just receive the data on the data bus.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.