Chapter 7: Configuration & Registers

Configuration Space, Capabilities, and Extended Capabilities

Configuration Space

Every PCIe function has a configuration space that software uses for discovery and setup.

Configuration Space Layout

  • Bytes 0-63: PCI-compatible header (Type 0 or Type 1)
  • Bytes 64-255: PCI Capabilities
  • Bytes 256-4095: PCIe Extended Capabilities
PCI Header (0x00-0x3F) PCI Capabilities (0x40-0xFF) PCIe Extended Capabilities (0x100-0xFFF) 4 KB Configuration Space

Type 0 Configuration Header (Endpoints)

OffsetRegisterSize
00hVendor ID16 bits
02hDevice ID16 bits
04hCommand16 bits
06hStatus16 bits
08hRevision ID8 bits
09hClass Code24 bits
0ChCache Line Size8 bits
0DhLatency Timer8 bits
0EhHeader Type8 bits
0FhBIST8 bits
10h-24hBase Address Registers (BAR0-5)6 × 32 bits
2ChSubsystem Vendor ID16 bits
2EhSubsystem ID16 bits
30hExpansion ROM Base32 bits
34hCapabilities Pointer8 bits
3ChInterrupt Line8 bits
3DhInterrupt Pin8 bits

Type 1 Configuration Header (Bridges)

Type 1 headers are used by switches and bridges to define routing:

Base Address Registers (BARs)

BARs define memory and I/O regions that the device exposes:

Bit 0: Memory (0) or I/O (1) For Memory: Bits [2:1]: Type (00=32-bit, 10=64-bit) Bit 3: Prefetchable Bits [31:4]: Base Address (16-byte aligned min)

BAR Sizing Algorithm

  1. Write all 1s to BAR
  2. Read back the value
  3. Mask type bits and invert
  4. Add 1 to get size

PCI Capabilities

Capabilities are linked list structures starting at Capabilities Pointer (offset 34h):

Cap IDCapabilityRequired?
01hPower ManagementYes
05hMSIMSI or MSI-X
10hPCI ExpressYes
11hMSI-XMSI or MSI-X

PCIe Extended Capabilities

Extended capabilities start at offset 100h and include:

Enhanced Configuration Access Mechanism (ECAM)

ECAM provides memory-mapped access to all 4KB of configuration space:

Address = ECAM_Base + (Bus << 20) + (Device << 15) + (Function << 12) + Register Example: Bus 0, Device 1, Function 0, Register 0x10 Address = ECAM_Base + 0x00008010