PCI Configuration Space - Bus Enumeration

Bus Enumeration

In order to address a PCI device it must be mapped into the I/O port address space or the memory-mapped address space of the system. The system's firmware/device drivers or the operating system will program the Base Address Registers (commonly called BARs) to inform the device of its address mapping by writing configuration commands to the PCI controller. Because all PCI devices are in an inactive state upon system reset, they will not have any addresses assigned to them by which the operating system or device drivers can communicate with them. Either the BIOS or the operating system geographically addresses the PCI slots (e.g. the first PCI slot, the second PCI slot, or the third PCI slot, etc., on the motherboard) through the PCI controller using the per slot IDSEL (Initialization Device Select) signals.

Since there is no direct method for the BIOS or OS to determine which PCI slots have devices installed (nor the functions the device implements) the PCI bus(es) must be enumerated. Bus enumeration is performed by attempting to read the Vendor- and Device ID register for each combination of bus number and device number, at the device's function #0.

If there is no device that implements the function zero (i.e., vendor and device ID registers), the bus master performs an abort and returns all 1s in binary (hexadecimal FFFFFFFF). All ones is an invalid VID/DID value, thus a device driver can tell that the specified combination bus/device/function (B/D/F) does not exist. So, when a read to a function ID of zero for given bus/device causes the master (initiator) to abort, it must then be presumed that no working device exists on that bus because devices are required to implement function number zero. In this case, reads to the remaining functions numbers (1–7) are not necessary as they also will not exist.

When a read to a specified BDF combination vendor ID register succeeds, the BIOS or OS knows it exists. It write all 1s to the BARs, and read back the devices requested memory size in the form of 0s where don't care address is. The design implies that all address spaces used are a power of two and are naturally aligned. At this point BIOS or OS program the memory mapped and I/O port addresses the function will respond to into the devices' BAR configuration register. These addresses stay valid as long as the system remains turned on. On power off, all these settings are lost and on the next system boot, the configuration procedure is repeated all over again. Since this entire process is fully automated, the computer user is spared the task of configuring any newly added hardware manually by modifying settings of DIP switches on the cards themselves. This is how plug and play is implemented.

If a PCI-to-PCI bridge is found, the system must assign the secondary PCI bus beyond the bridge a bus number other than 0, and then enumerate the devices on that secondary bus.

Each non-bridge PCI device function can implement up to 6 BARs, each of which can respond to different addresses in I/O port and memory-mapped address space. Each BAR describes a region :

PCI BAR Bits
Bits Description Values
For all PCI BARs
0 Region Type 0 = Memory
1 = I/O (deprecated)
For Memory BARs
2-1 Locatable 0 = any 32-bit
1 = < 1MiB
2 = any 64-bit
3 Prefetchable 0 = no
1 = yes
31-4 Base Address 16-byte aligned
For I/O BARs (Deprecated)
1 Reserved
31-2 Base Address 4-byte aligned

A device can have a ROM which can contain driver code or configuration information.

Read more about this topic:  PCI Configuration Space

Famous quotes containing the word bus:

    Nora was always free with it and threw her heart away as if it was a used bus ticket.
    Angela Carter (1940–1992)