Home linux lspci 工具
Post
Cancel

linux lspci 工具

查看手册

1
$ man 8 lspci

该工具最好以root 权限运行,否则有些关于pcie设备的信息无法获取。

显示系统中扫描到的PCIe设备(OS枚举完毕后的)

直接使用 lspci 命令即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ sudo lspci
00:00.0 Host bridge: Intel Corporation Device 4668 (rev 02)
00:01.0 PCI bridge: Intel Corporation Device 460d (rev 02)
00:02.0 VGA compatible controller: Intel Corporation Device 4680 (rev 0c)
00:06.0 PCI bridge: Intel Corporation Device 464d (rev 02)
00:0a.0 Signal processing controller: Intel Corporation Device 467d (rev 01)
00:14.0 USB controller: Intel Corporation Device 7ae0 (rev 11)
00:14.2 RAM memory: Intel Corporation Device 7aa7 (rev 11)
00:15.0 Serial bus controller [0c80]: Intel Corporation Device 7acc (rev 11)
00:15.1 Serial bus controller [0c80]: Intel Corporation Device 7acd (rev 11)
00:15.2 Serial bus controller [0c80]: Intel Corporation Device 7ace (rev 11)
00:15.3 Serial bus controller [0c80]: Intel Corporation Device 7acf (rev 11)
00:16.0 Communication controller: Intel Corporation Device 7ae8 (rev 11)
00:17.0 SATA controller: Intel Corporation Device 7ae2 (rev 11)
00:19.0 Serial bus controller [0c80]: Intel Corporation Device 7afc (rev 11)
00:19.1 Serial bus controller [0c80]: Intel Corporation Device 7afd (rev 11)
00:1c.0 PCI bridge: Intel Corporation Device 7ab8 (rev 11)
00:1c.2 PCI bridge: Intel Corporation Device 7aba (rev 11)
00:1d.0 PCI bridge: Intel Corporation Device 7ab0 (rev 11)
00:1f.0 ISA bridge: Intel Corporation Device 7a84 (rev 11)
00:1f.3 Audio device: Intel Corporation Device 7ad0 (rev 11)
00:1f.4 SMBus: Intel Corporation Device 7aa3 (rev 11)
00:1f.5 Serial bus controller [0c80]: Intel Corporation Device 7aa4 (rev 11)
01:00.0 Memory controller: Xilinx Corporation Device 5048
01:00.1 Memory controller: Xilinx Corporation Device 5049
02:00.0 Non-Volatile memory controller: Sandisk Corp Device 501e
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller (rev 05)
05:00.0 Non-Volatile memory controller: Intel Corporation NVMe Datacenter SSD [3DNAND, Beta Rock Controller]

默认是以BDF的形式显示的,如上例中的 01:00.0 Memory controller: Xilinx Corporation Device 5048 , 其中 01 是总线号,00是设备号, .0 是功能号。

需要PCI设备能成功link up起来,才能被OS识别

查看某一PCI设备的详细信息

使用 -s [[[[<domain>]:]<bus>]:][<device>][.[<func>]] 指定设备, 并使用 -vvv 查看详细信息,需要使用root权限才能查看更多信息。 本质是解析pcie 设备的config header,也可以不解析,查看原始的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
$ sudo lspci -s 01:00.0 -vvv
01:00.0 Memory controller: Xilinx Corporation Device 5048
	Subsystem: Xilinx Corporation Device 000e
	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
	Region 0: Memory at 70000000 (64-bit, prefetchable) [size=128M]
	Region 2: Memory at 78000000 (64-bit, prefetchable) [size=128K]
	Capabilities: [40] 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: [48] MSI: Enable- Count=1/1 Maskable- 64bit+
		Address: 0000000000000000  Data: 0000
	Capabilities: [60] MSI-X: Enable- Count=32 Masked-
		Vector table: BAR=0 offset=00008000
		PBA: BAR=0 offset=00008fe0
	Capabilities: [70] Express (v2) Endpoint, MSI 00
		DevCap:	MaxPayload 512 bytes, PhantFunc 0, Latency L0s <64ns, L1 <1us
			ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset- SlotPowerLimit 75.000W
		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 8GT/s, Width x16, ASPM not supported
			ClockPM- Surprise- LLActRep- BwNot- ASPMOptComp+
		LnkCtl:	ASPM Disabled; RCB 64 bytes Disabled- CommClk+
			ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
		LnkSta:	Speed 8GT/s (ok), Width x16 (ok)
			TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
		DevCap2: Completion Timeout: Range BC, TimeoutDis+, NROPrPrP-, LTR-
			 10BitTagComp+, 10BitTagReq-, OBFF Not Supported, ExtFmt-, EETLPPrefix-
			 EmergencyPowerReduction Not Supported, EmergencyPowerReductionInit-
			 FRS-, TPHComp-, ExtTPHComp-
			 AtomicOpsCap: 32bit- 64bit- 128bitCAS-
		DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR-, OBFF Disabled
			 AtomicOpsCtl: ReqEn-
		LnkCtl2: Target Link Speed: 8GT/s, EnterCompliance- SpeedDis-
			 Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
			 Compliance De-emphasis: -6dB
		LnkSta2: Current De-emphasis Level: -6dB, EqualizationComplete+, EqualizationPhase1+
			 EqualizationPhase2+, EqualizationPhase3+, LinkEqualizationRequest-
	Capabilities: [100 v1] Advanced Error Reporting
		UESta:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UEMsk:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UESvrt:	DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-
		CESta:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- AdvNonFatalErr-
		CEMsk:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- AdvNonFatalErr+
		AERCap:	First Error Pointer: 00, ECRCGenCap- ECRCGenEn- ECRCChkCap- ECRCChkEn-
			MultHdrRecCap- MultHdrRecEn- TLPPfxPres- HdrLogCap-
		HeaderLog: 00000000 00000000 00000000 00000000
	Capabilities: [180 v1] Alternative Routing-ID Interpretation (ARI)
		ARICap:	MFVC- ACS-, Next Function: 1
		ARICtl:	MFVC- ACS-, Function Group: 0
	Capabilities: [1c0 v1] Secondary PCI Express
		LnkCtl3: LnkEquIntrruptEn-, PerformEqu-
		LaneErrStat: 0
	Capabilities: [3a0 v1] Data Link Feature <?>
	Capabilities: [600 v1] Vendor Specific Information: ID=0020 Rev=0 Len=010 <?>
	Kernel driver in use: xclmgmt
	Kernel modules: xclmgmt

$ sudo lspci -s 01:00.1 -vvv
01:00.1 Memory controller: Xilinx Corporation Device 5049
	Subsystem: Xilinx Corporation Device 000e
	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
	Region 0: Memory at 78020000 (64-bit, prefetchable) [size=64K]
	Region 2: Memory at 60000000 (64-bit, prefetchable) [size=256M]
	Capabilities: [40] 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: [48] MSI: Enable- Count=1/1 Maskable- 64bit+
		Address: 0000000000000000  Data: 0000
	Capabilities: [60] MSI-X: Enable+ Count=32 Masked-
		Vector table: BAR=0 offset=00008000
		PBA: BAR=0 offset=00008fe0
	Capabilities: [70] Express (v2) Endpoint, MSI 00
		DevCap:	MaxPayload 512 bytes, PhantFunc 0, Latency L0s <64ns, L1 <1us
			ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset- SlotPowerLimit 75.000W
		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 8GT/s, Width x16, ASPM not supported
			ClockPM- Surprise- LLActRep- BwNot- ASPMOptComp+
		LnkCtl:	ASPM Disabled; RCB 64 bytes Disabled- CommClk+
			ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
		LnkSta:	Speed 8GT/s (ok), Width x16 (ok)
			TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
		DevCap2: Completion Timeout: Range BC, TimeoutDis+, NROPrPrP-, LTR-
			 10BitTagComp+, 10BitTagReq-, OBFF Not Supported, ExtFmt-, EETLPPrefix-
			 EmergencyPowerReduction Not Supported, EmergencyPowerReductionInit-
			 FRS-, TPHComp-, ExtTPHComp-
			 AtomicOpsCap: 32bit- 64bit- 128bitCAS-
		DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR-, OBFF Disabled
			 AtomicOpsCtl: ReqEn-
		LnkSta2: Current De-emphasis Level: -6dB, EqualizationComplete-, EqualizationPhase1-
			 EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
	Capabilities: [100 v1] Advanced Error Reporting
		UESta:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UEMsk:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UESvrt:	DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-
		CESta:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- AdvNonFatalErr-
		CEMsk:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- AdvNonFatalErr+
		AERCap:	First Error Pointer: 00, ECRCGenCap- ECRCGenEn- ECRCChkCap- ECRCChkEn-
			MultHdrRecCap- MultHdrRecEn- TLPPfxPres- HdrLogCap-
		HeaderLog: 00000000 00000000 00000000 00000000
	Capabilities: [180 v1] Alternative Routing-ID Interpretation (ARI)
		ARICap:	MFVC- ACS-, Next Function: 0
		ARICtl:	MFVC- ACS-, Function Group: 0
	Capabilities: [600 v1] Vendor Specific Information: ID=0020 Rev=0 Len=010 <?>
	Kernel driver in use: xocl
	Kernel modules: xocl

  • 很多名词后面带有 加减号 -/+-表示disable,未开启或不支持, +表示enable,开启
  • Region 0 ,Region 2 这种即表示BAR空间寄存器,这是系统枚举PCI设备时分配的
  • 后面各种Capabilities就是解析出来的PCIe设备支持的能力,如电源管理PM,MSI/MSI-X,AER等
  • 最后显示该设备可用的驱动和正在使用的驱动

查看某一PCI设备的config header原始信息

使用 -s [[[[<domain>]:]<bus>]:][<device>][.[<func>]] 指定设备, 并使用 -xxx 查看PCI config header 前256字节的dump信息, 如果要查看PCIe的前面4096扩展配置头信息,使用 -xxxx 即可。 一般查看信息使用 -vvv 直接查看解析信息即可,是对应的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ sudo lspci -s 01:00.0 -xxx
01:00.0 Memory controller: Xilinx Corporation Device 5048
00: ee 10 48 50 06 00 10 00 00 00 80 05 10 00 80 00
10: 0c 00 00 70 00 00 00 00 0c 00 00 78 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 ee 10 0e 00
30: 00 00 00 00 40 00 00 00 00 00 00 00 ff 00 00 00
40: 01 48 03 da 08 00 00 00 05 60 80 00 00 00 00 00
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
60: 11 70 1f 00 00 80 00 00 e0 8f 00 00 00 00 00 00
70: 10 00 02 00 22 80 2c 01 30 29 00 00 03 f1 43 00
80: 40 00 03 11 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 16 00 01 00 00 00 00 00 0e 00 80 01
a0: 03 00 1e 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 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

查看PCI设备厂商号和设备号

因为BDF号是设备号的一部分,但在PCI设备驱动中时,需要匹配完整的厂商号和设备号,仅使用BDF就不行了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ sudo lspci -nn
sudo: unable to resolve host hw-cpr: Name or service not known
00:00.0 Host bridge [0600]: Intel Corporation Device [8086:4668] (rev 02)
00:01.0 PCI bridge [0604]: Intel Corporation Device [8086:460d] (rev 02)
00:02.0 VGA compatible controller [0300]: Intel Corporation Device [8086:4680] (rev 0c)
00:06.0 PCI bridge [0604]: Intel Corporation Device [8086:464d] (rev 02)
00:0a.0 Signal processing controller [1180]: Intel Corporation Device [8086:467d] (rev 01)
00:14.0 USB controller [0c03]: Intel Corporation Device [8086:7ae0] (rev 11)
00:14.2 RAM memory [0500]: Intel Corporation Device [8086:7aa7] (rev 11)
00:15.0 Serial bus controller [0c80]: Intel Corporation Device [8086:7acc] (rev 11)
00:15.1 Serial bus controller [0c80]: Intel Corporation Device [8086:7acd] (rev 11)
00:15.2 Serial bus controller [0c80]: Intel Corporation Device [8086:7ace] (rev 11)
00:15.3 Serial bus controller [0c80]: Intel Corporation Device [8086:7acf] (rev 11)
00:16.0 Communication controller [0780]: Intel Corporation Device [8086:7ae8] (rev 11)
00:17.0 SATA controller [0106]: Intel Corporation Device [8086:7ae2] (rev 11)
00:19.0 Serial bus controller [0c80]: Intel Corporation Device [8086:7afc] (rev 11)
00:19.1 Serial bus controller [0c80]: Intel Corporation Device [8086:7afd] (rev 11)
00:1c.0 PCI bridge [0604]: Intel Corporation Device [8086:7ab8] (rev 11)
00:1c.2 PCI bridge [0604]: Intel Corporation Device [8086:7aba] (rev 11)
00:1d.0 PCI bridge [0604]: Intel Corporation Device [8086:7ab0] (rev 11)
00:1f.0 ISA bridge [0601]: Intel Corporation Device [8086:7a84] (rev 11)
00:1f.3 Audio device [0403]: Intel Corporation Device [8086:7ad0] (rev 11)
00:1f.4 SMBus [0c05]: Intel Corporation Device [8086:7aa3] (rev 11)
00:1f.5 Serial bus controller [0c80]: Intel Corporation Device [8086:7aa4] (rev 11)
01:00.0 Memory controller [0580]: Xilinx Corporation Device [10ee:5048]
01:00.1 Memory controller [0580]: Xilinx Corporation Device [10ee:5049]
02:00.0 Non-Volatile memory controller [0108]: Sandisk Corp Device [15b7:501e]
04:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125] (rev 05)
05:00.0 Non-Volatile memory controller [0108]: Intel Corporation NVMe Datacenter SSD [3DNAND, Beta Rock Controller] [8086:0a54]

最后显示的就是 厂商号和设备号,pci设备中会用来匹配ID table。

另外,可以看到,所谓的PCI设备的功能号,实际最终的设备号不同的,这样PCI设备驱动就能区分加载不同驱动了。 BDF中的device对应物理上的同一个PCIe设备,但是逻辑上的设备号其实是不同的,而驱动中匹配的是后者。

修改PCI设备的配置空间

使用 setpci 命令,可以直接修改PCIe设备的配置空间,而不需要依赖设备驱动程序。 也可以在pci设备驱动中修改。

1
$ man setpci
This post is licensed under CC BY 4.0 by the author.

PCIe 热拔插

VSCode+GDB远程调试