PCIe Chapter 2: Reading Configuration Space and Finding Capabilities
Starting from an already discovered Function, this chapter queries Device Serial Number (DSN). The feature selects the list; pointers locate its structure; register definitions then determine how to read and assemble the serial number.
Simulated data: Locations and values are created for teaching and do not represent a particular device or platform.
- MSI-X
- Message Signaled Interrupts Extension
- AER
- Advanced Error Reporting
Full Chinese tutorial · Course roadmap · 繁體中文
Separate the target, configuration offset, and CPU address
Segment and BDF (Bus, Device, and Function identifier) select the Function. A byte offset then selects a Register in its 4096-byte Configuration Space: the first 256 bytes are PCI-compatible, and 0x100–0xFFF is the extended region. ECAM (Enhanced Configuration Access Mechanism) provides CPU memory-mapped configuration access. The platform supplies its physical mapping; the offset alone is only a position within the selected Function.
- BDF
- Bus/Device/Function
The conventional Capability list starts through the Header's Capabilities Pointer, at 0x34 for the Type 0/1 layouts used here. The Extended list starts independently at 0x100. The PCI Express Capability belongs to the conventional list; DSN belongs to the Extended list. A name containing PCIe does not establish which list to use.
Reading locations
Base 6.0 §7.2–§7.2.2.2, Figure 7-3 and Table 7-1, pp.905–909; Figure 7-4, p.916; Capabilities Pointer: §7.5.1.1.11, p.926; Extended list: §7.6–§7.6.3, Figures 7-42/7-43 and Table 7-39, pp.1008–1010.
Why can the same offset mean different things?
First read the selected Function’s Header Type Register at 0x0E. Bits 6:0 select the Header Layout: Figure 7-10 shows Type 0, and Figure 7-14 shows Type 1 for Root and Switch Ports. Read the bit positions across each figure and the Function-relative byte offset at the right.
| Offset | Type 0 | Type 1 (Root/Switch Port) |
|---|---|---|
| 0x10–0x14 | Part of the Base Address Register (BAR) area | This Port’s BAR 0 and BAR 1 |
| 0x18 | Part of the BAR area | Primary, Secondary and Subordinate Bus Number fields, among others |
| 0x20 | Part of the BAR area | Memory Base and Memory Limit |
For a 32-bit value at 0x18, first obtain the Header Layout of that same Function. With Type 1, interpret the corresponding bytes as Bus Numbers; with Type 0, the location belongs to the BAR area. Read the particular BAR type and field definition before interpreting it. The Bus Numbers describe the downstream discovery range; Memory Base and Limit describe a resource window. Chapter 3 explains discovery and Chapter 4 resource allocation.
Read bit 7 separately from bits 6:0. The assumed value 0x80 selects Type 0 and indicates that the Device may contain multiple Functions; further probing is needed. VF rules differ and are outside this example. Header Layout and Configuration Request Type 0/1 are separately defined classifications.
- VF
- Virtual Function
Reading route: Base 6.0 §7.5.1.1.9, Figure 7-8 and Table 7-7 (printed/PDF pp.924–925); Figure 7-10 (p.928); Figure 7-14 and its applicability note (p.936). Select the figure from Header Type, then read its offset and field definition.
An ID of zero is different from a Next pointer of zero
A conventional Capability normally starts with an ID in the low byte and a Next pointer in the high byte of a 16-bit read. The teaching list follows 0x40 → 0x50 → 0x70 → 0xD0 → 0, representing PM, Null, PCIe, and MSI-X.
- MSI-X
- Message Signaled Interrupts Extension
| Location and width | Value | Interpretation |
|---|---|---|
| 0x50, 16 bits | 0x7000 | Conventional ID 00h is Null; Next=0x70, so traversal continues. |
| 0x100, 32 bits | 0x18020001 | Extended ID 0001h, AER Version 2; Next=0x180. |
| 0x180, 32 bits | 0x00010003 | Extended ID 0003h, DSN Version 1; Next=0 ends the list. |
Extended ID = header & 0xFFFF
Version = (header >> 16) & 0xF
Next = (header >> 20) & 0xFFC
Next already gives a byte offset from the beginning of the Function. Read at that offset directly; DWORD alignment does not change its unit. For an unknown ID, follow a valid Header to the next entry. The course separately checks range, alignment, and revisited offsets to detect unreliable traversal; valid positions need not increase.
ID and list sources
PM: Figure 7-18/Table 7-14, p.945; PCIe: Figure 7-22/Table 7-18, p.953; MSI-X: Figure 7-59/Table 7-48, pp.1021–1022; Null: §7.9.27, Figure 7-384/Table 7-336, p.1315. Extended Header: Table 7-39, p.1010; AER (Advanced Error Reporting): Figure 7-154/Table 7-134, p.1112. Flit Mode support requires AER Version 3 and is excluded here.
After finding DSN, distinguish data location from display order
Figure 7-242/Table 7-221 identify DSN as ID 0003h. Figure 7-241 then places its Lower DW and Upper DW at structure offsets +0x04 and +0x08. The example reads 0x33221100 at 0x184 and 0x77665544 at 0x188, each as 32 bits.
- DW
- Double Word, a four-byte unit
Register integer = (0x77665544 << 32) | 0x33221100
= 0x7766554433221100
Table 7-222 separately maps Register bytes to EUI-64 bytes. Written from the highest EUI byte to the lowest, the example is 00-11-22-33-44-55-66-77. These values illustrate reconstruction, not an allocated or usable product identifier. Real values must follow the IEEE company identifier and manufacturer extension rules, and the value alone does not authenticate hardware.
DSN is optional. An ordinary Multi-Function Device implementing DSN must implement it in Function 0; other Functions implementing it must return the same value. DSN therefore does not replace the Function Number in BDF (Bus, Device, and Function identifier).
- BDF
- Bus/Device/Function
Exact DSN references
Base 6.0 §7.9.3–§7.9.3.2, Figures 7-241–7-243 and Tables 7-221/7-222, pp.1205–1207. RCiEP and PF/VF conditions differ and are excluded here.
A read value is not automatically safe to write back
Read the Attributes column with the field definition. RO restricts software writes; RW1C (write one to clear) leaves status unchanged when written as zero.
Software must preserve the read value when writing RsvdP (reserved, preserve on writes) bits, whereas RsvdZ (reserved, write zero) requires zero on writes. Reserved fields cannot all use the same update rule. A failed read is not a valid indication of absence, and a successful zero read does not prove that a meaningful Register exists there. Establish the entry point and valid result before interpreting the format.
Attributes and evidence limits
Base 6.0 §7.4, Table 7-2, pp.913–915. Unimplemented Registers return successful zero reads absent other errors: §7.3.3, p.913. An all-zero Extended Header at 0x100 indicates no Extended Capabilities: §7.6.1, p.1009. That rule differs from a conventional Null Capability ID of zero.
Apply the complete query to changed values
The worked query starts at 0x100, reaches DSN at 0x180, and reads its data at 0x184 and 0x188. Next locates a different structure; a data offset locates a field in the current structure. The following variations apply that distinction.
If 0x180 returns 0x24010003, does the DSN Lower DW move to 0x244?
No. 0x240 points to the next structure. The current DSN remains at 0x180, with its Lower DW at 0x184. (Figure 7-241, p.1205; Table 7-39, p.1010.)
Does failure to find DSN in the conventional list prove lack of support?
No. DSN belongs to the Extended list and requires an interface that can access it. Searching the wrong list or lacking access is not valid absence evidence. (§7.6.1, p.1009; §7.9.3, p.1205.)
Continue with Chapter 3 to see how software establishes a discovery path before it knows the downstream BDFs.


Comments