Search code examples
linuxx86bios

How does Linux find devices on x86 IO address bus at boot?


So devices are arranged on x86 device bus with unique ranges somehow. AFAIK, in the old days if you were using DOS or some real mode OS you could configure these ranges through the BIOS. Device also had conventional addresses. This site show a Table - Common Hex Addresses. But Linux doesn't use the BIOS. I can't believe that these addresses are hard coded into any OS including Linux anymore. Modern Linux kernel surely must somehow dynamically discovering devices on this address bus and there address ranges. But how?!


Solution

  • Some device addresses are fixed , and "defined" by the platform. Others are dyanamic (programmable) and these are usually set-up by the firmware during boot. It depends if we're talking about system devices or add-on peripherals.

    Most devices are found via typical PCI bus scanning, where each device exports its various BARs via registers in PCI config space. These BARs (and thus address ranges) are programmed by the firmware at boot, and can refer to memory or I/O port addresses.

    Another means of device discovery is via ACPI tables. The kernel finds the ACPI tables by scanning through a prescribed memory region looking for a marker. These tables are constructed by the firmware at boot.

    There is a good deal of information on OSdev.org.

    There are a small number of hard-coded addresses in the kernel. You can easily look these up by browsing through the arch/x86 directory. These are addresses that simply do not change because they are part of the platform "definition" (and I use that word loosely). A couple examples include the text-mode VGA memory at B8000 and the BIOS data area at 400.

    Linux kernel source code: