Search code examples
linux-kerneldriverdevice-driverkernel

Clarifying who decides memory mappings and port IO mappings


I studied a bit about port mapped IO and memory mapped IO and I figured out how the first works (not the second yet), so if you have something well-explained about how memory mapped IO is performed (I heard it's about intercepting page faults by the OS to reroute them to the devices) please let me know.

Anyway my question is: communicating with the internal real time clock (RTS) uses an I/O Port mapping and you need to use outb(byte_selected,0x70) and similar functions on the 0x70 port.. who decided the 0x70 port? How can I figure out where are they declared? And what about memory mapping IOs? Who decides what addresses are associated to what devices? And if I added my own device to the system, how would its memory be mapped?

I've still a lot of confusion about OS-hw communications..


Solution

  • Memory mappings are decided by the hardware manufacturer and are hardwired on the bus. They cannot be changed whatsoever and the correct mappings must be read from the hardware specification.

    Some pluggable buses like PCI work by having their own address space for their devices. They can detect the presence of devices and their needs in terms of I/O and assign them ranges within this reserved space. The CPU can then access it through its own space using PCI registers, or more efficiently through DMA. See this page for more details: http://tldp.org/LDP/tlk/dd/pci.html

    Note that not all devices work with mapped I/O - for instance, USB devices do not use memory I/O and only communicate with the host through well-defined USB commands.