优秀的编程知识分享平台

网站首页 > 技术文章 正文

深入PCIE——配置空间详解2(pci express 配置)

nanyue 2024-09-03 16:36:58 技术文章 6 ℃

下面将以英伟达的一款显卡的配置空间信息来详细说明配置空间的某些寄存器,其余没有出现的寄存器可以看linux源码。

上一篇忘了BAR空间的说明,如下图:

前面介绍了pci配置空间0~0x3f这段寄存器,在0x40~0xff这段配置空间主要是一些Capbility寄存器,下面是这些寄存器的说明:

 #define PCI_CAP_LIST_ID     0   /* Capability ID */
 #define  PCI_CAP_ID_PM      0x01    /* Power Management */
 #define  PCI_CAP_ID_AGP     0x02    /* Accelerated Graphics Port */
 #define  PCI_CAP_ID_VPD     0x03    /* Vital Product Data */
 #define  PCI_CAP_ID_SLOTID  0x04    /* Slot Identification */
 #define  PCI_CAP_ID_MSI     0x05    /* Message Signalled Interrupts */
 #define  PCI_CAP_ID_CHSWP   0x06    /* CompactPCI HotSwap */
 #define  PCI_CAP_ID_PCIX    0x07    /* PCI-X */
 #define  PCI_CAP_ID_HT      0x08    /* HyperTransport */
 #define  PCI_CAP_ID_VNDR    0x09    /* Vendor-Specific */
 #define  PCI_CAP_ID_DBG     0x0A    /* Debug port */
 #define  PCI_CAP_ID_CCRC    0x0B    /* CompactPCI Central Resource Control */
 #define  PCI_CAP_ID_SHPC    0x0C    /* PCI Standard Hot-Plug Controller */
 #define  PCI_CAP_ID_SSVID   0x0D    /* Bridge subsystem vendor/device ID */
 #define  PCI_CAP_ID_AGP3    0x0E    /* AGP Target PCI-PCI bridge */
 #define  PCI_CAP_ID_SECDEV  0x0F    /* Secure Device */
 #define  PCI_CAP_ID_EXP     0x10    /* PCI Express */
 #define  PCI_CAP_ID_MSIX    0x11    /* MSI-X */
 #define  PCI_CAP_ID_SATA    0x12    /* SATA Data/Index Conf. */
 #define  PCI_CAP_ID_AF      0x13    /* PCI Advanced Features */
 #define  PCI_CAP_ID_EA      0x14    /* PCI Enhanced Allocation */

在一个PCIE设备上,并不包含所有的Capbility寄存器,只有其中一部分寄存器,这些寄存器以链表的形式连接起来,下面就以一个实际的设备来说明配置空间这些寄存器

sudo lspci -s 01:00.0 -xxx
01:00.0 VGA compatible controller: NVIDIA Corporation GK208B [GeForce GT 730] (rev a1)
00: de 10 87 12 07 04 10 00 a1 00 00 03 10 00 80 00
10: 00 00 00 a1 0c 00 00 00 40 00 00 00 0c 00 00 08
20: 40 00 00 00 01 40 00 00 00 00 00 00 de 10 00 00
30: 00 00 00 a2 60 00 00 00 00 00 00 00 ff 01 00 00
40: de 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00
50: 01 00 00 00 01 00 00 00 ce d6 23 00 00 00 00 00
60: 01 68 03 00 08 00 00 00 05 78 81 00 00 30 e0 fe
70: 00 00 00 00 22 40 00 00 10 00 12 00 e1 8d 2c 01
80: 30 29 00 00 82 3c 45 00 40 00 82 10 00 00 00 00
90: 00 00 00 00 00 00 00 00 00 00 00 00 13 00 00 00
a0: 00 00 00 00 06 00 00 00 03 00 01 00 00 00 00 00
b0: 00 00 00 00 09 00 14 01 00 00 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

上面的设备是一款NVIDIA的显卡,0x10de NVIDIA厂商号,0x1287代表设备GeForce GT 730

  1. Command寄存器值为0407h,代表其支持I/O空间、Memory空间、bus mastering(DMA)和奇偶校验。
  2. Status寄存器值为0010h,代表其支持Capability List
  3. Class Code寄存器中,base class code为03h代表其为display设备;sub-class code为00h代表为VGA设备。
  4. Cache Line Size寄存器为10h代表Cache行大小为64 bytes
  5. Header Type寄存器为0x80代表其为多功能PCI Agent设备,另一个功能为Audio device,function号为1
  6. Bar0为0xa1000000,32位非预取 Memory空间;Bar1为0x400000000c,64为预取 Memory空间,基址为0x4000000000;Bar3为0x400800000c,64为预取 Memory空间,基址为0x4008000000;Bar5为0x4001,32位IO空间,基址0x4000。
  7. Expansion ROM 寄存器为bit0为0代表该地址disabled
  8. Capbility Pointer寄存器为60h,代表Capbility链表头寄存器为0x60
  9. Capbility的第一个地址为0x60,0x60的值为01h代表电源管理功能,61h为68h代表下一个Capbility的地址为68h,

下面介绍该设备的Capbility

60h的CAP ID是1,代表电源管理功能,NEXT Capbility Pointer为0x68,62h开始的寄存器为PM Capabilities寄存器,寄存器说明如下:

/* Power Management Registers */

#define PCI_PM_PMC              2       /* PM Capabilities Register */
#define  PCI_PM_CAP_VER_MASK    0x0007  /* Version */
#define  PCI_PM_CAP_PME_CLOCK   0x0008  /* PME clock required */
#define  PCI_PM_CAP_RESERVED    0x0010  /* Reserved field */
#define  PCI_PM_CAP_DSI         0x0020  /* Device specific initialization */
#define  PCI_PM_CAP_AUX_POWER   0x01C0  /* Auxiliary power support mask */
#define  PCI_PM_CAP_D1          0x0200  /* D1 power state support */
#define  PCI_PM_CAP_D2          0x0400  /* D2 power state support */
#define  PCI_PM_CAP_PME         0x0800  /* PME pin supported */
#define  PCI_PM_CAP_PME_MASK    0xF800  /* PME Mask of all supported states */
#define  PCI_PM_CAP_PME_D0      0x0800  /* PME# from D0 */
#define  PCI_PM_CAP_PME_D1      0x1000  /* PME# from D1 */
#define  PCI_PM_CAP_PME_D2      0x2000  /* PME# from D2 */
#define  PCI_PM_CAP_PME_D3      0x4000  /* PME# from D3 (hot) */
#define  PCI_PM_CAP_PME_D3cold  0x8000  /* PME# from D3 (cold) */
#define  PCI_PM_CAP_PME_SHIFT   11      /* Start of the PME Mask in PMC */
#define PCI_PM_CTRL             4       /* PM control and status register */
#define  PCI_PM_CTRL_STATE_MASK 0x0003  /* Current power state (D0 to D3) */
#define  PCI_PM_CTRL_NO_SOFT_RESET      0x0008  /* No reset for D3hot->D0 */
#define  PCI_PM_CTRL_PME_ENABLE 0x0100  /* PME pin enable */
#define  PCI_PM_CTRL_DATA_SEL_MASK      0x1e00  /* Data select (??) */
#define  PCI_PM_CTRL_DATA_SCALE_MASK    0x6000  /* Data scale (??) */
#define  PCI_PM_CTRL_PME_STATUS 0x8000  /* PME pin status */
#define PCI_PM_PPB_EXTENSIONS   6       /* PPB support extensions (??) */
#define  PCI_PM_PPB_B2_B3       0x40    /* Stop clock when in D3hot (??) */
#define  PCI_PM_BPCC_ENABLE     0x80    /* Bus power/clock control enable (??) */
#define PCI_PM_DATA_REGISTER    7       /* (??) */
#define PCI_PM_SIZEOF           8
  1. version字段只读,记录PMC结构的版本号,本设备为3
  2. PME clock位只读,PCIE设备没有使用该寄存器,PCI总线中PME#需要时钟时该位置1
  3. DSI位只读,设备自定义的电源工作方式
  4. AUX字段只读,PCIE设备进入低功耗状态时主电源停止供电,辅助电源继续供电,该字段为辅助电源的电流大小,为0表示不使用辅助电源
  5. D2和D1位只读,为1表示PCIE支持对应状态,PCIE设备可以支持4中状态,D0到D3功耗递减,多数支持电源管理的PCIE设备仅支持D0、D3状态,D1和D2可选。
  6. PME MASK字段只读,表示PCIE设备处于对应状态可以发送PME消息
  7. STATE字段记录PCIE设备所处的状态,为0代表处于D0状态
  8. NO_SOFT_RESET位只读,为1表示PCIE设备从D3 hot状态迁徙到D0状态时不需要内部复位
  9. PME enable位,可读写,为1时表示PCIE设备可以发送PME消息
  10. DATA select字段可读写,软件配置该字段使设备进入D0~D3状态,然后读取DATA字段的数据并乘以10的负DATA scale字段的数据得到功耗。
  11. PME status位,表示PCIE设备可以正常发送PME消息
  12. PCIE没有实现后面的B2_B3和BPCC,PCI总线中BPCC为1使能电源和时钟管理


68h的CAP ID为5,表示PCIE的MSI Capabilities,NEXT Capbility Pointer为0x78,MSI Capabilities寄存器定义如下:

/* Message Signalled Interrupts registers */

#define PCI_MSI_FLAGS           2       /* Message Control */
#define  PCI_MSI_FLAGS_ENABLE   0x0001  /* MSI feature enabled */
#define  PCI_MSI_FLAGS_QMASK    0x000e  /* Maximum queue size available */
#define  PCI_MSI_FLAGS_QSIZE    0x0070  /* Message queue size configured */
#define  PCI_MSI_FLAGS_64BIT    0x0080  /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_MASKBIT  0x0100  /* Per-vector masking capable */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32         8       /* 16 bits of data for 32-bit devices */
#define PCI_MSI_MASK_32         12      /* Mask bits register for 32-bit devices */
#define PCI_MSI_PENDING_32      16      /* Pending intrs for 32-bit devices */
#define PCI_MSI_DATA_64         12      /* 16 bits of data for 64-bit devices */
#define PCI_MSI_MASK_64         16      /* Mask bits register for 64-bit devices */
#define PCI_MSI_PENDING_64      20      /* Pending intrs for 64-bit devices */
  1. Message Control寄存器为0x6a开始的两个字节,其值0x0081代表64位Message 地址,MSI使能
  2. 64位Message 地址为0x00000000fee03000
  3. 16位Message data字段为0x00004022

78h的CAP ID为0x10,表示PCIE的PCI Express Capabilities,NEXT Capbility Pointer为0x00,表示链表结束,PCI Express Capabilities寄存器定义如下:

/* PCI Express capability registers */

#define PCI_EXP_FLAGS           2       /* Capabilities register */
#define PCI_EXP_FLAGS_VERS      0x000f  /* Capability version */
#define PCI_EXP_FLAGS_TYPE      0x00f0  /* Device/Port type */
#define  PCI_EXP_TYPE_ENDPOINT  0x0     /* Express Endpoint */
#define  PCI_EXP_TYPE_LEG_END   0x1     /* Legacy Endpoint */
#define  PCI_EXP_TYPE_ROOT_PORT 0x4     /* Root Port */
#define  PCI_EXP_TYPE_UPSTREAM  0x5     /* Upstream Port */
#define  PCI_EXP_TYPE_DOWNSTREAM 0x6    /* Downstream Port */
#define  PCI_EXP_TYPE_PCI_BRIDGE 0x7    /* PCIe to PCI/PCI-X Bridge */
#define  PCI_EXP_TYPE_PCIE_BRIDGE 0x8   /* PCI/PCI-X to PCIe Bridge */
#define  PCI_EXP_TYPE_RC_END    0x9     /* Root Complex Integrated Endpoint */
#define  PCI_EXP_TYPE_RC_EC     0xa     /* Root Complex Event Collector */
#define PCI_EXP_FLAGS_SLOT      0x0100  /* Slot implemented */
#define PCI_EXP_FLAGS_IRQ       0x3e00  /* Interrupt message number */
#define PCI_EXP_DEVCAP          4       /* Device capabilities */
#define  PCI_EXP_DEVCAP_PAYLOAD 0x00000007 /* Max_Payload_Size */
#define  PCI_EXP_DEVCAP_PHANTOM 0x00000018 /* Phantom functions */
#define  PCI_EXP_DEVCAP_EXT_TAG 0x00000020 /* Extended tags */
#define  PCI_EXP_DEVCAP_L0S     0x000001c0 /* L0s Acceptable Latency */
#define  PCI_EXP_DEVCAP_L1      0x00000e00 /* L1 Acceptable Latency */
#define  PCI_EXP_DEVCAP_ATN_BUT 0x00001000 /* Attention Button Present */
#define  PCI_EXP_DEVCAP_ATN_IND 0x00002000 /* Attention Indicator Present */
#define  PCI_EXP_DEVCAP_PWR_IND 0x00004000 /* Power Indicator Present */
#define  PCI_EXP_DEVCAP_RBER    0x00008000 /* Role-Based Error Reporting */
#define  PCI_EXP_DEVCAP_PWR_VAL 0x03fc0000 /* Slot Power Limit Value */
#define  PCI_EXP_DEVCAP_PWR_SCL 0x0c000000 /* Slot Power Limit Scale */
#define  PCI_EXP_DEVCAP_FLR     0x10000000 /* Function Level Reset */
#define PCI_EXP_DEVCTL          8       /* Device Control */
#define  PCI_EXP_DEVCTL_CERE    0x0001  /* Correctable Error Reporting En. */
#define  PCI_EXP_DEVCTL_NFERE   0x0002  /* Non-Fatal Error Reporting Enable */
#define  PCI_EXP_DEVCTL_FERE    0x0004  /* Fatal Error Reporting Enable */
#define  PCI_EXP_DEVCTL_URRE    0x0008  /* Unsupported Request Reporting En. */
#define  PCI_EXP_DEVCTL_RELAX_EN 0x0010 /* Enable relaxed ordering */
#define  PCI_EXP_DEVCTL_PAYLOAD 0x00e0  /* Max_Payload_Size */
#define  PCI_EXP_DEVCTL_EXT_TAG 0x0100  /* Extended Tag Field Enable */
#define  PCI_EXP_DEVCTL_PHANTOM 0x0200  /* Phantom Functions Enable */
#define  PCI_EXP_DEVCTL_AUX_PME 0x0400  /* Auxiliary Power PM Enable */
#define  PCI_EXP_DEVCTL_NOSNOOP_EN 0x0800  /* Enable No Snoop */
#define  PCI_EXP_DEVCTL_READRQ  0x7000  /* Max_Read_Request_Size */
#define  PCI_EXP_DEVCTL_READRQ_128B  0x0000 /* 128 Bytes */
#define  PCI_EXP_DEVCTL_READRQ_256B  0x1000 /* 256 Bytes */
#define  PCI_EXP_DEVCTL_READRQ_512B  0x2000 /* 512 Bytes */
#define  PCI_EXP_DEVCTL_READRQ_1024B 0x3000 /* 1024 Bytes */
#define  PCI_EXP_DEVCTL_READRQ_2048B 0x4000 /* 2048 Bytes */
#define  PCI_EXP_DEVCTL_READRQ_4096B 0x5000 /* 4096 Bytes */
#define  PCI_EXP_DEVCTL_BCR_FLR 0x8000  /* Bridge Configuration Retry / FLR */
#define PCI_EXP_DEVSTA          10      /* Device Status */
#define  PCI_EXP_DEVSTA_CED     0x0001  /* Correctable Error Detected */
#define  PCI_EXP_DEVSTA_NFED    0x0002  /* Non-Fatal Error Detected */
#define  PCI_EXP_DEVSTA_FED     0x0004  /* Fatal Error Detected */
#define  PCI_EXP_DEVSTA_URD     0x0008  /* Unsupported Request Detected */
#define  PCI_EXP_DEVSTA_AUXPD   0x0010  /* AUX Power Detected */
#define  PCI_EXP_DEVSTA_TRPND   0x0020  /* Transactions Pending */
#define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V1       12      /* v1 endpoints without link end here */
#define PCI_EXP_LNKCAP          12      /* Link Capabilities */
#define  PCI_EXP_LNKCAP_SLS     0x0000000f /* Supported Link Speeds */
#define  PCI_EXP_LNKCAP_SLS_2_5GB 0x00000001 /* LNKCAP2 SLS Vector bit 0 */
#define  PCI_EXP_LNKCAP_SLS_5_0GB 0x00000002 /* LNKCAP2 SLS Vector bit 1 */
#define  PCI_EXP_LNKCAP_SLS_8_0GB 0x00000003 /* LNKCAP2 SLS Vector bit 2 */
#define  PCI_EXP_LNKCAP_SLS_16_0GB 0x00000004 /* LNKCAP2 SLS Vector bit 3 */
#define  PCI_EXP_LNKCAP_MLW     0x000003f0 /* Maximum Link Width */
#define  PCI_EXP_LNKCAP_ASPMS   0x00000c00 /* ASPM Support */
#define  PCI_EXP_LNKCAP_L0SEL   0x00007000 /* L0s Exit Latency */
#define  PCI_EXP_LNKCAP_L1EL    0x00038000 /* L1 Exit Latency */
#define  PCI_EXP_LNKCAP_CLKPM   0x00040000 /* Clock Power Management */
#define  PCI_EXP_LNKCAP_SDERC   0x00080000 /* Surprise Down Error Reporting Capable */
#define  PCI_EXP_LNKCAP_DLLLARC 0x00100000 /* Data Link Layer Link Active Reporting Capable */
#define  PCI_EXP_LNKCAP_LBNC    0x00200000 /* Link Bandwidth Notification Capability */
#define  PCI_EXP_LNKCAP_PN      0xff000000 /* Port Number */
#define PCI_EXP_LNKCTL          16      /* Link Control */
#define  PCI_EXP_LNKCTL_ASPMC   0x0003  /* ASPM Control */
#define  PCI_EXP_LNKCTL_ASPM_L0S 0x0001 /* L0s Enable */
#define  PCI_EXP_LNKCTL_ASPM_L1  0x0002 /* L1 Enable */
#define  PCI_EXP_LNKCTL_RCB     0x0008  /* Read Completion Boundary */
#define  PCI_EXP_LNKCTL_LD      0x0010  /* Link Disable */
#define  PCI_EXP_LNKCTL_RL      0x0020  /* Retrain Link */
#define  PCI_EXP_LNKCTL_CCC     0x0040  /* Common Clock Configuration */
#define  PCI_EXP_LNKCTL_ES      0x0080  /* Extended Synch */
#define  PCI_EXP_LNKCTL_CLKREQ_EN 0x0100 /* Enable clkreq */
#define  PCI_EXP_LNKCTL_HAWD    0x0200  /* Hardware Autonomous Width Disable */
#define  PCI_EXP_LNKCTL_LBMIE   0x0400  /* Link Bandwidth Management Interrupt Enable */
#define  PCI_EXP_LNKCTL_LABIE   0x0800  /* Link Autonomous Bandwidth Interrupt Enable */
#define PCI_EXP_LNKSTA          18      /* Link Status */
#define  PCI_EXP_LNKSTA_CLS     0x000f  /* Current Link Speed */
#define  PCI_EXP_LNKSTA_CLS_2_5GB 0x0001 /* Current Link Speed 2.5GT/s */
#define  PCI_EXP_LNKSTA_CLS_5_0GB 0x0002 /* Current Link Speed 5.0GT/s */
#define  PCI_EXP_LNKSTA_CLS_8_0GB 0x0003 /* Current Link Speed 8.0GT/s */
#define  PCI_EXP_LNKSTA_CLS_16_0GB 0x0004 /* Current Link Speed 16.0GT/s */
#define  PCI_EXP_LNKSTA_NLW     0x03f0  /* Negotiated Link Width */
#define  PCI_EXP_LNKSTA_NLW_X1  0x0010  /* Current Link Width x1 */
#define  PCI_EXP_LNKSTA_NLW_X2  0x0020  /* Current Link Width x2 */
#define  PCI_EXP_LNKSTA_NLW_X4  0x0040  /* Current Link Width x4 */
#define  PCI_EXP_LNKSTA_NLW_X8  0x0080  /* Current Link Width x8 */
#define  PCI_EXP_LNKSTA_NLW_SHIFT 4     /* start of NLW mask in link status */
#define  PCI_EXP_LNKSTA_LT      0x0800  /* Link Training */
#define  PCI_EXP_LNKSTA_SLC     0x1000  /* Slot Clock Configuration */
#define  PCI_EXP_LNKSTA_DLLLA   0x2000  /* Data Link Layer Link Active */
#define  PCI_EXP_LNKSTA_LBMS    0x4000  /* Link Bandwidth Management Status */
#define  PCI_EXP_LNKSTA_LABS    0x8000  /* Link Autonomous Bandwidth Status */
#define PCI_CAP_EXP_ENDPOINT_SIZEOF_V1  20      /* v1 endpoints with link end here */
#define PCI_EXP_SLTCAP          20      /* Slot Capabilities */
#define  PCI_EXP_SLTCAP_ABP     0x00000001 /* Attention Button Present */
#define  PCI_EXP_SLTCAP_PCP     0x00000002 /* Power Controller Present */
#define  PCI_EXP_SLTCAP_MRLSP   0x00000004 /* MRL Sensor Present */
#define  PCI_EXP_SLTCAP_AIP     0x00000008 /* Attention Indicator Present */
#define  PCI_EXP_SLTCAP_PIP     0x00000010 /* Power Indicator Present */
#define  PCI_EXP_SLTCAP_HPS     0x00000020 /* Hot-Plug Surprise */
#define  PCI_EXP_SLTCAP_HPC     0x00000040 /* Hot-Plug Capable */
#define  PCI_EXP_SLTCAP_SPLV    0x00007f80 /* Slot Power Limit Value */
#define  PCI_EXP_SLTCAP_SPLS    0x00018000 /* Slot Power Limit Scale */
#define  PCI_EXP_SLTCAP_EIP     0x00020000 /* Electromechanical Interlock Present */
#define  PCI_EXP_SLTCAP_NCCS    0x00040000 /* No Command Completed Support */
#define  PCI_EXP_SLTCAP_PSN     0xfff80000 /* Physical Slot Number */
#define PCI_EXP_SLTCTL          24      /* Slot Control */
#define  PCI_EXP_SLTCTL_ABPE    0x0001  /* Attention Button Pressed Enable */
#define  PCI_EXP_SLTCTL_PFDE    0x0002  /* Power Fault Detected Enable */
#define  PCI_EXP_SLTCTL_MRLSCE  0x0004  /* MRL Sensor Changed Enable */
#define  PCI_EXP_SLTCTL_PDCE    0x0008  /* Presence Detect Changed Enable */
#define  PCI_EXP_SLTCTL_CCIE    0x0010  /* Command Completed Interrupt Enable */
#define  PCI_EXP_SLTCTL_HPIE    0x0020  /* Hot-Plug Interrupt Enable */
#define  PCI_EXP_SLTCTL_AIC     0x00c0  /* Attention Indicator Control */
#define  PCI_EXP_SLTCTL_ATTN_IND_ON    0x0040 /* Attention Indicator on */
#define  PCI_EXP_SLTCTL_ATTN_IND_BLINK 0x0080 /* Attention Indicator blinking */
#define  PCI_EXP_SLTCTL_PWR_IND_OFF    0x0300 /* Power Indicator off */
#define  PCI_EXP_SLTCTL_PCC     0x0400  /* Power Controller Control */
#define  PCI_EXP_SLTCTL_PWR_ON         0x0000 /* Power On */
#define  PCI_EXP_SLTCTL_PWR_OFF        0x0400 /* Power Off */
#define  PCI_EXP_SLTCTL_EIC     0x0800  /* Electromechanical Interlock Control */
#define  PCI_EXP_SLTCTL_DLLSCE  0x1000  /* Data Link Layer State Changed Enable */
#define PCI_EXP_SLTSTA          26      /* Slot Status */
#define  PCI_EXP_SLTSTA_ABP     0x0001  /* Attention Button Pressed */
#define  PCI_EXP_SLTSTA_PFD     0x0002  /* Power Fault Detected */
#define  PCI_EXP_SLTSTA_MRLSC   0x0004  /* MRL Sensor Changed */
#define  PCI_EXP_SLTSTA_PDC     0x0008  /* Presence Detect Changed */
#define  PCI_EXP_SLTSTA_CC      0x0010  /* Command Completed */
#define  PCI_EXP_SLTSTA_MRLSS   0x0020  /* MRL Sensor State */
#define  PCI_EXP_SLTSTA_PDS     0x0040  /* Presence Detect State */
#define  PCI_EXP_SLTSTA_EIS     0x0080  /* Electromechanical Interlock Status */
#define  PCI_EXP_SLTSTA_DLLSC   0x0100  /* Data Link Layer State Changed */
#define PCI_EXP_RTCTL           28      /* Root Control */
#define  PCI_EXP_RTCTL_SECEE    0x0001  /* System Error on Correctable Error */
#define  PCI_EXP_RTCTL_SENFEE   0x0002  /* System Error on Non-Fatal Error */
#define  PCI_EXP_RTCTL_SEFEE    0x0004  /* System Error on Fatal Error */
#define  PCI_EXP_RTCTL_PMEIE    0x0008  /* PME Interrupt Enable */
#define  PCI_EXP_RTCTL_CRSSVE   0x0010  /* CRS Software Visibility Enable */
#define PCI_EXP_RTCAP           30      /* Root Capabilities */
#define  PCI_EXP_RTCAP_CRSVIS   0x0001  /* CRS Software Visibility capability */
#define PCI_EXP_RTSTA           32      /* Root Status */
#define PCI_EXP_RTSTA_PME       0x00010000 /* PME status */
#define PCI_EXP_RTSTA_PENDING   0x00020000 /* PME pending */
/*
 * The Device Capabilities 2, Device Status 2, Device Control 2,
 * Link Capabilities 2, Link Status 2, Link Control 2,
 * Slot Capabilities 2, Slot Status 2, and Slot Control 2 registers
 * are only present on devices with PCIe Capability version 2.
 * Use pcie_capability_read_word() and similar interfaces to use them
 * safely.
 */
#define PCI_EXP_DEVCAP2         36      /* Device Capabilities 2 */
#define  PCI_EXP_DEVCAP2_COMP_TMOUT_DIS 0x00000010 /* Completion Timeout Disable supported */
#define  PCI_EXP_DEVCAP2_ARI            0x00000020 /* Alternative Routing-ID */
#define  PCI_EXP_DEVCAP2_ATOMIC_ROUTE   0x00000040 /* Atomic Op routing */
#define  PCI_EXP_DEVCAP2_ATOMIC_COMP32  0x00000080 /* 32b AtomicOp completion */
#define  PCI_EXP_DEVCAP2_ATOMIC_COMP64  0x00000100 /* 64b AtomicOp completion */
#define  PCI_EXP_DEVCAP2_ATOMIC_COMP128 0x00000200 /* 128b AtomicOp completion */
#define  PCI_EXP_DEVCAP2_LTR            0x00000800 /* Latency tolerance reporting */
#define  PCI_EXP_DEVCAP2_OBFF_MASK      0x000c0000 /* OBFF support mechanism */
#define  PCI_EXP_DEVCAP2_OBFF_MSG       0x00040000 /* New message signaling */
#define  PCI_EXP_DEVCAP2_OBFF_WAKE      0x00080000 /* Re-use WAKE# for OBFF */
#define PCI_EXP_DEVCAP2_EE_PREFIX       0x00200000 /* End-End TLP Prefix */
#define PCI_EXP_DEVCTL2         40      /* Device Control 2 */
#define  PCI_EXP_DEVCTL2_COMP_TIMEOUT   0x000f  /* Completion Timeout Value */
#define  PCI_EXP_DEVCTL2_COMP_TMOUT_DIS 0x0010  /* Completion Timeout Disable */
#define  PCI_EXP_DEVCTL2_ARI            0x0020  /* Alternative Routing-ID */
#define PCI_EXP_DEVCTL2_ATOMIC_REQ      0x0040  /* Set Atomic requests */
#define PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK 0x0080 /* Block atomic egress */
#define  PCI_EXP_DEVCTL2_IDO_REQ_EN     0x0100  /* Allow IDO for requests */
#define  PCI_EXP_DEVCTL2_IDO_CMP_EN     0x0200  /* Allow IDO for completions */
#define  PCI_EXP_DEVCTL2_LTR_EN         0x0400  /* Enable LTR mechanism */
#define  PCI_EXP_DEVCTL2_OBFF_MSGA_EN   0x2000  /* Enable OBFF Message type A */
#define  PCI_EXP_DEVCTL2_OBFF_MSGB_EN   0x4000  /* Enable OBFF Message type B */
#define  PCI_EXP_DEVCTL2_OBFF_WAKE_EN   0x6000  /* OBFF using WAKE# signaling */
#define PCI_EXP_DEVSTA2         42      /* Device Status 2 */
#define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V2       44      /* v2 endpoints without link end here */
#define PCI_EXP_LNKCAP2         44      /* Link Capabilities 2 */
#define  PCI_EXP_LNKCAP2_SLS_2_5GB      0x00000002 /* Supported Speed 2.5GT/s */
#define  PCI_EXP_LNKCAP2_SLS_5_0GB      0x00000004 /* Supported Speed 5GT/s */
#define  PCI_EXP_LNKCAP2_SLS_8_0GB      0x00000008 /* Supported Speed 8GT/s */
#define  PCI_EXP_LNKCAP2_SLS_16_0GB     0x00000010 /* Supported Speed 16GT/s */
#define  PCI_EXP_LNKCAP2_CROSSLINK      0x00000100 /* Crosslink supported */
#define PCI_EXP_LNKCTL2         48      /* Link Control 2 */
#define PCI_EXP_LNKCTL2_TLS             0x000f
#define PCI_EXP_LNKCTL2_TLS_2_5GT       0x0001 /* Supported Speed 2.5GT/s */
#define PCI_EXP_LNKCTL2_TLS_5_0GT       0x0002 /* Supported Speed 5GT/s */
#define PCI_EXP_LNKCTL2_TLS_8_0GT       0x0003 /* Supported Speed 8GT/s */
#define PCI_EXP_LNKCTL2_TLS_16_0GT      0x0004 /* Supported Speed 16GT/s */
#define PCI_EXP_LNKSTA2         50      /* Link Status 2 */
#define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2  52      /* v2 endpoints with link end here */
#define PCI_EXP_SLTCAP2         52      /* Slot Capabilities 2 */
#define PCI_EXP_SLTCTL2         56      /* Slot Control 2 */
#define PCI_EXP_SLTSTA2         58      /* Slot Status 2 */

这个Capabilities太长,这里就不详细分析了,但是这里面的寄存器很重要,例如我们可以修改这里来强制PCIE link到低速率如GEN 1来调试板卡上的一些问题。

下面是这个显卡配置空间的详细信息,可以和上面的定义对照着看下,0x100以后的配置空间没有详细的规范,这里不再介绍


sudo lspci -s 01:00.0 -vvv
01:00.0 VGA compatible controller: NVIDIA Corporation GK208B [GeForce GT 730] (rev a1) (prog-if 00 [VGA controller])
    Subsystem: NVIDIA Corporation GK208B [GeForce GT 730]
    Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
    Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
    Latency: 0, Cache Line Size: 64 bytes
    Interrupt: pin A routed to IRQ 128
    Region 0: Memory at a1000000 (32-bit, non-prefetchable) [size=16M]
    Region 1: Memory at 4000000000 (64-bit, prefetchable) [size=128M]
    Region 3: Memory at 4008000000 (64-bit, prefetchable) [size=32M]
    Region 5: I/O ports at 4000 [size=128]
    Expansion ROM at 000c0000 [disabled] [size=128K]
    Capabilities: [60] Power Management version 3
        Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-)
        Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
    Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
        Address: 00000000fee03000  Data: 4022
    Capabilities: [78] Express (v2) Legacy Endpoint, MSI 00
        DevCap: MaxPayload 256 bytes, PhantFunc 0, Latency L0s unlimited, L1 <64us
            ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset-
        DevCtl: CorrErr- NonFatalErr- FatalErr- UnsupReq-
            RlxdOrd+ ExtTag+ PhantFunc- AuxPwr- NoSnoop+
            MaxPayload 256 bytes, MaxReadReq 512 bytes
        DevSta: CorrErr- NonFatalErr- FatalErr- UnsupReq- AuxPwr- TransPend-
        LnkCap: Port #0, Speed 5GT/s, Width x8, ASPM L0s L1, Exit Latency L0s <512ns, L1 <4us
            ClockPM+ Surprise- LLActRep- BwNot- ASPMOptComp+
        LnkCtl: ASPM Disabled; RCB 64 bytes, Disabled- CommClk+
            ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
        LnkSta: Speed 5GT/s (ok), Width x8 (ok)
            TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
        DevCap2: Completion Timeout: Range AB, TimeoutDis+ NROPrPrP- LTR-
             10BitTagComp- 10BitTagReq- OBFF Not Supported, ExtFmt- EETLPPrefix-
             EmergencyPowerReduction Not Supported, EmergencyPowerReductionInit-
             FRS-
             AtomicOpsCap: 32bit- 64bit- 128bitCAS-
        DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis- LTR- OBFF Disabled,
             AtomicOpsCtl: ReqEn-
        LnkCap2: Supported Link Speeds: 2.5-5GT/s, Crosslink- Retimer- 2Retimers- DRS-
        LnkCtl2: Target Link Speed: 8GT/s, EnterCompliance- SpeedDis-
             Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
             Compliance De-emphasis: -6dB
        LnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete- EqualizationPhase1-
             EqualizationPhase2- EqualizationPhase3- LinkEqualizationRequest-
             Retimer- 2Retimers- CrosslinkRes: unsupported
    Capabilities: [100 v1] Virtual Channel
        Caps:   LPEVC=0 RefClk=100ns PATEntryBits=1
        Arb:    Fixed- WRR32- WRR64- WRR128-
        Ctrl:   ArbSelect=Fixed
        Status: InProgress-
        VC0:    Caps:   PATOffset=00 MaxTimeSlots=1 RejSnoopTrans-
            Arb:    Fixed- WRR32- WRR64- WRR128- TWRR128- WRR256-
            Ctrl:   Enable+ ID=0 ArbSelect=Fixed TC/VC=ff
            Status: NegoPending- InProgress-
    Capabilities: [128 v1] Power Budgeting <?>
    Capabilities: [600 v1] Vendor Specific Information: ID=0001 Rev=1 Len=024 <?>
    Kernel driver in use: nouveau
    Kernel modules: nvidiafb, nouveau
最近发表
标签列表