Electronic – How does a PCIe device know that its 4K configuration space is mapped to memory address

pcipcie

PCIe spec defines 3 address spaces:

  • Memory
  • IO
  • Configuration

I can configure the BAR register to specify the memory address range that a PCIe device will claim.

How does a PCIe device know that its configuration space can be accessed through the memory address as well, i.e. MMCFG?

Or in other words, how to enable MMCFG for a PCIe device and tell the device where its configuration space is mapped to?

Best Answer

The memory mapping is an implementation detail inside the root complex, the card is sent CfgRd and CfgWr TLPs. The destination address information inside the TLP is filled out from the address used in the ECAM access, and the completion reply is translated back into a memory access result when it is received, by matching the tag field in the Cpl TLP.

The configuration space accesses are routed by the bridges, which are aware of the device numbers assigned to devices below them, and will forward the TLP only to the correct port.

The first TLP that arrives in a card will be a configuration access TLP, which contains the card's device number as the destination address, and the card will assume that the request was routed correctly and use that address going forward.