Tracing the path from UEFI firmware discovery of a PCIe network card to Linux kernel/driver access of PCI configuration space and BARs.

Introduction: Why PCIe Bring-Up Matters

When a Linux network driver begins executing, the PCIe network card it controls already appears to be integrated into the system. Its PCI configuration space is accessible, its Vendor ID and Device ID are visible through tools such as lspci, and its BARs usually already have physical address ranges assigned. These steps are completed before the network driver takes control of the device; they are the result of earlier firmware and kernel PCI enumeration, not something the driver does from scratch.

Long before the operating system loads a driver, a coordinated sequence of steps involving hardware, firmware, and the operating system must complete successfully.

This blog walks through that entire sequence:

  1. System power-on and firmware initialization
  2. UEFI discovery of PCIe devices
  3. Firmware configuration of device resources
  4. Publication of system topology through ACPI tables
  5. Linux rediscovery of PCI devices
  6. Final handoff to the device driver

The goal is not merely to explain PCI enumeration but to clarify how PCI configuration space remains continuously accessible from firmware to operating system without firmware involvement at runtime.

Modern systems rely on ACPI (Advanced Configuration and Power Interface) tables provided by firmware to communicate hardware topology and configuration information to the operating system.

1. Power-On: From Reset Vector to Firmware Execution

When a computer powers on, the CPU begins execution at a fixed reset vector defined by the architecture.

For example on x86 systems:

Reset Vector → 0xFFFFFFF0

At this moment:

  • DRAM is not initialized
  • PCI devices are not yet discovered
  • The operating system is not present

Firmware is responsible for establishing the initial execution environment.

Modern systems use UEFI firmware, which replaces legacy BIOS and provides a modular architecture for early system initialization.

2. UEFI Boot Phases

UEFI firmware executes in several stages. Only two phases are relevant for PCI discovery.

Firmware Execution Overview:

SEC → PEI → DXE → Boot Manager → OS

3. PEI Phase: Preparing the Platform

The Pre-EFI Initialization (PEI) phase performs early hardware initialization.

Major responsibilities include:

  • CPU initialization
  • DRAM discovery and training
  • Platform silicon initialization
  • Creation of Hand-Off Blocks (HOBs)

PEI establishes permanent system memory so that later firmware components can run.

4. Hand-Off Blocks (HOBs): Passing Platform Knowledge Forward

PEI discovers important platform information but does not perform complex driver logic. Instead, it packages discovered information into Hand-Off Blocks (HOBs).

HOBs are structured data records that describe system resources, platform configuration, and initialization results discovered during PEI. They are used to pass system information from PEI to DXE inside firmware.

Conceptually:

SEC
 ↓
PEI
 ↓
HOB list
 ↓
DXE

After DXE consumes the HOB list, firmware publishes the information needed by the operating system through ACPI tables and the UEFI memory map.

DXE
 ↓
ACPI tables + UEFI memory map
 ↓
OS

HOBs are structured firmware data records used to transfer discovered platform state from PEI to DXE.

5. Why PCI Initialization Uses HOBs

Before PCI devices can be enumerated, firmware must know several platform characteristics:

  • Number of PCI root complexes (or host bridges)
  • PCI segment groups associated with those root complexes
  • ECAM base address mappings for each PCI segment group
  • Supported bus-number ranges
  • MMIO and I/O resource windows

This information is discovered during silicon initialization in PEI.

DXE drivers do not independently discover this platform topology; instead, they rely on information produced earlier in the boot flow. Many platforms pass this information through standard or GUID-specific HOBs. DXE consumes the HOB list to obtain initial system state, including memory, I/O, and MMIO resource information.

Every PCIe device contains a small region called PCI configuration space that stores device identification, capability, and control registers used by the device driver to initialize and operate the device. ECAM (Enhanced Configuration Access Mechanism) is the standard mechanism used by modern PCIe systems to access this configuration space. During PEI silicon initialization, firmware discovers or programs the ECAM address mappings for the platform’s PCI segment groups (typically corresponding to one or more PCI root complexes) and makes this information available to DXE.

6. Important HOB Types in PCI Bring-Up

Several HOB types are involved in PCI initialization.

Resource Descriptor HOB

Defines address space regions such as:

  • System RAM
  • PCI MMIO windows
  • I/O port windows

Example structure:

Resource Type: MemoryMappedIO
PhysicalStart: 0x78000000000
Length:        0x100000000

This tells DXE that the region may be used for PCI BAR allocation.

GUID-Specific PCI HOBs

Platforms often define custom GUID HOBs describing PCI topology.

Example conceptual structure:

PCI_ROOT_COMPLEX_INFO_HOB
{
  SegmentNumber
  BusStart
  BusEnd
  EcamBase
}

Memory Allocation HOB

Some HOBs describe memory already allocated by firmware. This prevents later PCI resource allocation from overlapping with:

  • Firmware memory
  • Runtime services
  • ACPI tables

7. DXE Phase: Where PCI Discovery Happens

After PEI completes, the DXE phase begins.

DXE loads firmware drivers responsible for system configuration.

Two DXE drivers are critical for PCI:

PciHostBridgeDxe PciBusDxe

Their roles are very different.

8. PCI Host Bridge: Describing PCI Root Bridges

Before firmware can discover PCI devices, it must define the structure of the PCI fabric.

This is the responsibility of PciHostBridgeDxe.

The driver reads HOB data and constructs a software model of each PCI root bridge, representing the PCI resources exposed by the underlying hardware root complex.

Each root bridge defines:

  • PCI segment number
  • Bus number range
  • I/O and MMIO windows
  • PCI configuration access method

At this stage no PCI devices are yet discovered.

Only the boundaries of the PCI address space are defined.

9. PCI Configuration Space and ECAM

Every PCIe device (PCIe function) contains configuration space that stores identification and control registers.

Key registers include:

  • Vendor ID
  • Device ID
  • Base Address Registers (BARs)
  • Command register
  • Status register
  • Capability list pointer

The operating system and firmware use these registers to:

  • Identify devices
  • Determine device capabilities
  • Configure MMIO regions
  • Enable DMA
  • Configure interrupts

Firmware typically reads the Vendor ID register at offset 0x00 to determine whether a device exists at a particular Bus/Device/Function location.

PCIe devices also expose optional features through a linked list of PCI capability structures stored in configuration space.

Standard PCI capabilities are located in the conventional PCI capability list, while PCIe extended capabilities are located in the extended PCIe configuration space.

Common capabilities include:

CapabilityPurposeType
Power ManagementDevice power statesStandard PCI capability
MSIMessage Signaled InterruptsStandard PCI capability
MSI-XMultiple interrupt vectorsStandard PCI capability
PCI Express CapabilityLink speed and width informationStandard PCI capability
SR-IOVVirtualization supportPCIe extended capability

Standard PCI capabilities are discovered by traversing the PCI capability list pointer stored in conventional PCI configuration space. PCIe extended capabilities are discovered separately by walking the extended capability list beginning at offset 0x100.

10. ECAM (Enhanced Configuration Access Mechanism)

Most modern PCIe systems expose PCI configuration space through ECAM (Enhanced Configuration Access Mechanism).

ECAM allows software to access PCI configuration space using normal memory-mapped I/O transactions.

The ECAM base address and supported bus ranges are published through the MCFG table. MCFG is an ACPI table defined by the PCI Firmware Specification; it tells the OS where ECAM configuration space is mapped for PCI segment groups and bus ranges available at boot.

The MCFG table does not describe or enumerate PCI devices themselves. Instead, it describes:

  • PCI segment numbers
  • ECAM base addresses
  • Supported bus ranges

Each MCFG entry associates a PCI segment group and a bus-number range with an ECAM base address, allowing software to locate the configuration space for PCI devices in that segment.

Relationship between these concepts:

PCI Root Complex
 ↓
PCI segment group
 ↓
MCFG Entry
(BaseAddress, SegmentGroup, StartBus, EndBus)
 ↓
ECAM Address Space
 ↓
PCI Configuration Space

Example ACPI MCFG entry:

BaseAddress = 0xE0000000
SegmentGroup = 0
StartBus     = 0
EndBus       = 255

Software calculates a PCI configuration space address of PCIe device/function using:

ConfigAddress =
    ECAM_BASE
  + (Bus << 20)
  + (Device << 15)
  + (Function << 12)
  + RegisterOffset

When firmware or the Linux kernel accesses this ECAM address range, the PCIe Root Complex decodes the access and converts it into PCI configuration transactions on the PCIe fabric.

Conceptually:

CPU MMIO Access
        ↓
ECAM Address Range
        ↓
PCIe Root Complex
        ↓
PCIe Configuration Transaction
        ↓
PCI Device Configuration Space

This mechanism allows both firmware and the operating system to access PCI configuration space without requiring firmware involvement during runtime.

11. PCI Bus Enumeration in UEFI

Once the host bridge is defined, the PciBusDxe driver begins enumeration.

Enumeration follows the classic PCI model:

Bus → Device → Function

The firmware:

  1. Reads Vendor ID / Device ID
  2. Identifies bridges
  3. Recursively scans secondary buses

12. BAR Discovery and Resource Allocation

Each PCI device advertises its resource requirements using Base Address Registers (BARs).

BARs describe:

  • MMIO regions
  • I/O port regions
  • Register space used by the device

Before assigning addresses, firmware must first determine the size of each BAR.

BAR Size Probing Mechanism

Firmware determines BAR size using a standard probing mechanism defined by the PCI specification.

Example process:

Original BAR0 value: 0x00000000

Step 1:
Write 0xFFFFFFFF to BAR0

Step 2:
Read BAR0 value back from device

Returned value: 0xFFFFF000

The returned value acts as a size mask.

The lower zero bits indicate the required alignment and size of the BAR region.

Calculating BAR Size

Firmware calculates the BAR size using: size = ~(BAR_value & address_mask) + 1

For this example:

BAR value = 0xFFFFF000

Invert bits:
~0xFFFFF000
= 0x00000FFF

Add 1:
0x00000FFF + 1 = 0x00001000

Final BAR size:
0x1000 = 4096 bytes = 4 KB

The lower 12 zero bits indicate the BAR must be aligned to a 4 KB boundary.

Example BAR Allocation

BARTypeSizeAssigned Address
BAR0MMIO4 KB0xFEBF0000
BAR2MMIO128 KB0xD0000000

Firmware then:

  • Assigns non-overlapping address ranges
  • Programs BAR registers
  • Enables memory decoding
  • Enables bus mastering

At this point, the device’s MMIO register space becomes accessible through the system address map.

For PCIe devices, accesses to these MMIO regions are routed by the PCIe Root Complex to the target device on the PCIe fabric.

13. Building ACPI Tables

After PCI enumeration completes, firmware publishes system topology using ACPI tables.

Important ACPI tables involved in PCI and platform discovery include:

TablePurpose
MCFGECAM base and bus ranges
DSDT/SSDTDevice hierarchy
_PRTPCI interrupt routing
_CRSResource windows

These tables allow the operating system to rediscover the hardware environment created by firmware.

Among these tables, the MCFG table provides ECAM mapping entries for PCI segment groups and bus ranges available at boot. It does not enumerate PCI devices; instead, it tells the operating system where PCI Express configuration space is mapped in the physical address space so software can access PCI configuration space through ECAM.

14. Firmware Handoff to the Operating System

UEFI firmware loads a bootloader in EFI format, such as GRUB (grubx64.efi). This bootloader is responsible for loading the operating system kernel. Once the kernel is ready to take control, the OS loader calls ExitBootServices(), terminating UEFI Boot Services.

/boot/efi/EFI/redhat/grubx64.efi is an example of a UEFI bootloader.

This signals that:

  • Boot-time drivers are finished
  • Firmware’s boot-time allocation is handed off; Linux may preserve or reassign resources. The operating system now owns the hardware

At this moment:

  • PCI devices are enumerated
  • BARs are assigned
  • Address decoding is configured

15. When Linux Takes Over

In many systems, Linux reuses the BAR assignments and bus numbering already configured by firmware. However, the kernel may reassign resources or reconfigure parts of the PCI topology if the existing firmware configuration is incomplete, invalid, or conflicts with system requirements.

During early boot, Linux performs the following steps:

  1. Parse ACPI tables
  2. Locate the MCFG
  3. Map the ECAM region
  4. Scan PCI buses

Linux probes each (bus, device, function) combination and rebuilds the PCI bus hierarchy internally.

Each discovered PCI device is represented by a kernel object:

struct pci_dev

16. BAR Validation and Resource Registration

Linux validates BAR assignments and registers them within the kernel’s global resource tree.

These ranges become visible in:

/proc/iomem

Example:

78500000000-7857fffffff : 0000:11:00.0

At this stage:

  • MMIO regions are reserved
  • Devices are known to the kernel
  • No driver initialization has occurred yet.

17. Driver Binding

Linux matches PCI devices against registered drivers using:

  • Vendor ID
  • Device ID
  • Subsystem Vendor ID / Subsystem Device ID
  • Class code

If a match is found, the kernel invokes the driver’s probe() callback.

And as part of the probe, the driver typically calls pci_enable_device() to enable MMIO/IO decoding and then pci_set_master() to enable DMA bus mastering

Reserve device resources – pci_request_regions() – This ensures that the device’s BAR address ranges are reserved and not used by other drivers.

Map device registers – pci_iomap() – This ensures that the device’s BAR address ranges are mapped into the kernel’s virtual address space.

After these steps the driver typically:

  • Reads device registers
  • Configures DMA engines
  • Allocates descriptor rings
  • Enables interrupts (MSI/MSI-X)
  • Registers the network interface with the kernel

At this point the network card is fully initialized and becomes part of the Linux networking subsystem.

After driver initialization, normal PCI device operation proceeds without firmware involvement.

18. Closing the Loop

At this point the lifecycle is complete:

  1. Hardware implements PCI configuration space
  2. PEI discovers platform topology
  3. HOBs pass information to DXE
  4. DXE enumerates PCI devices
  5. ACPI tables describe the environment
  6. Linux rediscovers the hardware
  7. Device drivers take control

From this point onward, the network card becomes part of the runtime kernel subsystem responsible for packet transmission.

Key Takeaways

  • PCI configuration space exists independently of firmware.
  • UEFI discovers and configures PCI devices during DXE.
  • HOBs transfer platform topology information from PEI to DXE.
  • ACPI tables communicate PCI configuration mechanisms to the OS.
  • Linux independently reconstructs the PCI bus hierarchy.
  • Drivers interact directly with hardware without firmware involvement.