# PCI 配置空间

**PCI 配置空间**是 PCI 本地总线规范定义的一个专用地址空间，其中每个 PCI 功能都暴露一组标准的配置寄存器，其寻址独立于设备的 I/O 空间和内存空间。固件和操作系统通过读写这些寄存器来发现设备、识别设备，并在开始任何设备特定的编程之前分配中断线和内存范围等资源。<sup>[1](https://uefi.org/specs/UEFI/2.9_A/Apx_R_Glossary.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 标准大小 | 传统 PCI 和 PCI-X 模式 1 设备具有 256 字节的配置空间；PCI-X 模式 2 和 PCIe 设备具有 4096 字节<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup> |
| 标准化头部 | 空间的前 64 字节是标准化的；其余字节为设备专用<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup> |
| 寻址 | 一次配置访问由总线号（8 位）、设备号（5 位）、功能号（3 位）和寄存器号（6 位）构成<sup>[3](https://www.cs.uml.edu/~bill/cs516/Exam_2_Take_Home.pdf)</sup> |
| 传统访问路径 | 在大多数 PC-AT 架构系统和典型的 Intel 芯片组上，配置空间通过 I/O 端口 0xCF8 和 0xCFC 访问<sup>[1](https://uefi.org/specs/UEFI/2.9_A/Apx_R_Glossary.html)</sup> |
| 能力列表 | 指向第一个能力的指针位于偏移 0x34；ID 包括电源管理（0x01）、MSI（0x05）、PCI-X（0x07）、PCI Express（0x10）和 MSI-X（0x11）<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup> |
| 扩展能力 | PCIe 扩展能力从第一个 256 字节之后开始；ID 包括高级错误报告（0x01）、设备序列号（0x03）、访问控制服务（0x0D）、SR-IOV（0x10）和可调整大小的 BAR（0x15）<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup> |
| 段限制 | 单个 PCI 段限制为 256 条总线，且不同段不共享同一配置空间<sup>[4](https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf)</sup> |

## 标准头部的布局

每个功能的前 64 字节构成 PCI 配置头部。它以偏移 0x00 处的 16 位厂商 ID 和 0x02 处的 16 位设备 ID 开头，随后在 0x04 处是命令寄存器，软件用它来使能 I/O 空间、内存空间和[总线主控](https://www.edgepedia.org/zh/bus-mastering)中的响应，在 0x06 处是状态寄存器，其各位报告中断状态、奇偶校验错误以及设备是否支持能力列表等状况。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup>

偏移 0x08 的低 8 位存放修订 ID，高 24 位存放类代码，这是一个只读字段，指定设备所执行的功能类型。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup><sup> • </sup><sup>[5](https://www.khoury.northeastern.edu/~pjd/cs7680/homework/pci-enumeration.html)</sup> 偏移 0x0e 存放头部类型，它区分三种布局：类型 0 用于普通设备，类型 1 用于 PCI 到 PCI 桥，类型 2 用于 CardBus，其中位 0x80 表示可能是多功能设备。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup>

**基址寄存器。** 类型 0 头部在偏移 0x10 到 0x24 处提供六个 32 位基址寄存器（BAR），用于定位设备的内存或 I/O 区域。BAR 的最低位选择 I/O 空间还是内存空间，内存 BAR 带有区分 32 位与 64 位寻址以及可预取性的位。BAR 的解码大小通过向寄存器写入 0xffffffff 再读回来确定；只有设备解码的位保持置位。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup>

桥头部用总线号窗口替换了大部分设备字段：偏移 0x18 到 0x1a 处的主总线号、从总线号和下级总线号寄存器定义桥后方的总线号范围，而 I/O、内存和可预取内存的基址与限址寄存器定义桥向下游转发的地址窗口。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup>

## 设备识别与枚举

配置空间是系统软件发现所连接设备的机制。

**检测缺失。** 空槽通过读取对应配置空间的第一个 32 位字来检测：如果不存在设备，结果为 0xFFFFFFFF，因为 0xFFFF 是无效的厂商代码。<sup>[5](https://www.khoury.northeastern.edu/~pjd/cs7680/homework/pci-enumeration.html)</sup> [枚举](https://www.edgepedia.org/zh/enumeration)软件以这种方式遍历总线号、设备号和功能号，桥头部告诉它应扫描哪些下游总线号。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup>

偏移 0x2c 和 0x2e 处的子系统厂商 ID 和子系统设备 ID 寄存器让附加卡厂商能够区分各自的卡，即使这些卡搭载相同的 PCI 控制器并因此具有相同的厂商 ID 和设备 ID。<sup>[6](https://e2e.ti.com/cfs-file.ashx/__key/communityserver-discussions-components-files/639/1016.PCI.Local.Bus.Specification.Revision.3.0.pdf)</sup>

## 能力列表

标准头部为可选特性增加了一种链表机制。当状态寄存器中的能力列表位置位时，偏移 0x34（PCI_CAPABILITY_LIST）处的字节给出第一个能力列表条目的偏移。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup><sup> • </sup><sup>[6](https://e2e.ti.com/cfs-file.ashx/__key/communityserver-discussions-components-files/639/1016.PCI.Local.Bus.Specification.Revision.3.0.pdf)</sup> 每个能力至少 4 字节：一个能力 ID 字节、一个链接到下一入口的下一指针字节（0 终止列表）以及一个 16 位标志字。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup>

[Linux 内核](https://www.edgepedia.org/zh/linux-kernel)的寄存器定义枚举了标准能力 ID，包括电源管理（0x01）、[加速图形端口](https://www.edgepedia.org/zh/accelerated-graphics-port)（0x02）、重要产品数据（0x03）、消息信号中断（0x05）、PCI-X（0x07）、[HyperTransport](https://www.edgepedia.org/zh/hypertransport)（0x08）、厂商特定（0x09）、PCI Express（0x10）、MSI-X（0x11）和 PCI 增强分配（0x14）。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup> PCI Express 能力本身以一个头部开头，其低字节读作 0x10，标识其为 PCIe 能力结构，其下一指针字节继续链接。<sup>[7](https://nvmexpress.org/wp-content/uploads/NVM-Express-PCI-Express-Transport-Specification-Revision-1.2-2025.03.11-Ratified-1.pdf)</sup>

## 扩展配置空间

PCI Express 和 PCI-X 模式 2 将空间从 256 字节扩展到每个功能 4096 字节。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup><sup> • </sup><sup>[8](https://learn.microsoft.com/en-us/windows-hardware/drivers/pci/accessing-pci-device-configuration-space)</sup> 从 0x100 开始的区域存放 PCIe 扩展能力结构，每个结构以一个 32 位头部开头，软件从中提取 16 位扩展能力 ID、4 位版本和 12 位下一指针，该指针要么为 0 以结束列表，要么至少为 0x100。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup><sup> • </sup><sup>[9](https://wiki.osdev.org/MCFG)</sup> 已定义的扩展 ID 包括高级错误报告（0x01）、虚拟通道（0x02）、设备序列号（0x03）、功率预算（0x04）、访问控制服务（0x0D）、备用路由 ID（0x0E）、地址转换服务（0x0F）、单根 I/O 虚拟化（0x10）、页请求接口（0x13）和可调整大小的 BAR（0x15）。<sup>[2](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)</sup>

内核的 Rust 绑定直接编码了这两种大小：配置空间要么是普通（256 字节），要么是扩展（4096 字节），PCI 子系统只会报告这两个值之一。<sup>[10](https://rust.docs.kernel.org/kernel/pci/enum.ConfigSpaceSize.html)</sup>

## 软件如何访问该空间

**传统 I/O 端口。** 在大多数 PC-AT 架构系统和典型的 Intel 芯片组上，配置空间通过 I/O 端口 0xCF8 和 0xCFC 访问；也可以有许多其他实现方式。<sup>[1](https://uefi.org/specs/UEFI/2.9_A/Apx_R_Glossary.html)</sup> 8 位总线号、5 位设备号、3 位功能号和 6 位寄存器号构成配置地址。<sup>[3](https://www.cs.uml.edu/~bill/cs516/Exam_2_Take_Home.pdf)</sup>

**内存映射访问。** PCIe 系统支持内存映射的配置空间访问，系统 BIOS 或固件通过定义 MCFG 表来声明它。<sup>[8](https://learn.microsoft.com/en-us/windows-hardware/drivers/pci/accessing-pci-device-configuration-space)</sup> 使用内存映射访问时，查找设备的工作方式与传统 PCI 相同，区别在于内核访问的是内存区域而非使用 CPU I/O。<sup>[9](https://wiki.osdev.org/MCFG)</sup>

**操作系统接口。** Linux 驱动使用 pci_(read|write)_config_(byte|word|dword) 来访问由 struct pci_dev 指针表示的设备的配置空间；这些函数成功时返回 0，失败时返回 PCIBIOS 错误码。在没有 pci_dev 的情况下，pci_bus_(read|write)_config_(byte|word|dword) 对总线上的给定设备和功能进行寻址，而 pci_find_capability() 定位特定能力的寄存器块。<sup>[11](https://github.com/torvalds/linux/blob/master/Documentation/PCI/pci.rst)</sup> 用户空间可以读写 sysfs 中为每个设备暴露的二进制 config 文件。<sup>[12](https://kernel.org/doc/html/v6.7/PCI/sysfs-pci.html)</sup> 在 Windows 上，受支持的方法是 BUS_INTERFACE_STANDARD 总线接口以及 IRP_MN_READ_CONFIG 和 IRP_MN_WRITE_CONFIG 请求包；[Windows XP](https://www.edgepedia.org/zh/windows-xp) 以及 [Windows Server 2003](https://www.edgepedia.org/zh/windows-server-2003) 及更高版本对配置空间头部和能力链表中的所有能力拥有独占控制权，因此驱动不得修改这些寄存器，但可以写入头部和能力列表之外的厂商定义配置空间。<sup>[8](https://learn.microsoft.com/en-us/windows-hardware/drivers/pci/accessing-pci-device-configuration-space)</sup>

## 虚拟化与段

PCIe 的 SR-IOV 特性让单个物理功能支持多个虚拟功能。当 VF 被使能时，它们在配置空间中像普通 PCI 设备一样出现，但 VF 配置空间头部中的 BAR 是只读的零；软件转而使用 PF 的 SR-IOV 能力中的 VF BAR 寄存器来发现大小并分配地址。<sup>[13](https://kernel.org/doc/html/v6.16/arch/powerpc/pci_iov_resource_on_powernv.html)</sup>

由于单个 PCI 段限制为 256 条总线，具有更多总线的系统使用多个 PCI 段组，且不同段不共享同一配置空间，尽管它们可能共享相同的 I/O、内存和可预取内存空间。<sup>[4](https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf)</sup> ACPI 的 _SEG 对象位于 PCI 主机桥下，其求值结果为描述 PCI 段组的整数。<sup>[14](https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/06_Device_Configuration/Device_Configuration.html)</sup>

## References

1. [UEFI Specification 2.9A, Appendix R Glossary: PCI Configuration Space](https://uefi.org/specs/UEFI/2.9_A/Apx_R_Glossary.html)
2. [include/uapi/linux/pci_regs.h, Linux kernel](https://linux.googlesource.com/linux/kernel/git/zohar/linux-integrity/%2B/refs/heads/next-integrity/include/uapi/linux/pci_regs.h)
3. [PCI Enumeration course notes, Khoury College, Northeastern University](https://www.cs.uml.edu/~bill/cs516/Exam_2_Take_Home.pdf)
4. [UEFI Specification, version 2.9](https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf)
5. [In-class: PCI Enumeration, Khoury College, Northeastern University](https://www.khoury.northeastern.edu/~pjd/cs7680/homework/pci-enumeration.html)
6. [PCI Local Bus Specification Revision 3.0 (TI mirror)](https://e2e.ti.com/cfs-file.ashx/__key/communityserver-discussions-components-files/639/1016.PCI.Local.Bus.Specification.Revision.3.0.pdf)
7. [NVM Express PCI Express Transport Specification, Revision 1.2](https://nvmexpress.org/wp-content/uploads/NVM-Express-PCI-Express-Transport-Specification-Revision-1.2-2025.03.11-Ratified-1.pdf)
8. [Accessing PCI Device Configuration Space, Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/drivers/pci/accessing-pci-device-configuration-space)
9. [PCI Express, OSDev Wiki (MCFG)](https://wiki.osdev.org/MCFG)
10. [ConfigSpaceSize in kernel::pci, Rust kernel documentation](https://rust.docs.kernel.org/kernel/pci/enum.ConfigSpaceSize.html)
11. [How To Write Linux PCI Drivers, Linux kernel documentation](https://github.com/torvalds/linux/blob/master/Documentation/PCI/pci.rst)
12. [Accessing PCI device resources through sysfs, Linux kernel documentation](https://kernel.org/doc/html/v6.7/PCI/sysfs-pci.html)
13. [PCI Express I/O Virtualization Resource on PowerNV, Linux kernel documentation](https://kernel.org/doc/html/v6.16/arch/powerpc/pci_iov_resource_on_powernv.html)
14. [ACPI Specification 6.4, Device Configuration](https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/06_Device_Configuration/Device_Configuration.html)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Boards, peripherals & form factors › Motherboards & form factors › Expansion slots and daughterboards

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/pci-configuration-space

English original: https://www.edgepedia.org/pci-configuration-space
