目錄
1.lspci用法小結
2.lspci -t
3.setpci用法小結
1.lspci用法小結
參考博客:【PCIe】lspci用法小結 - 知乎
lspci是一個用來顯示系統中所有PCI總線設備或者連接到該總線上所有設備的工具
man lspci
lspci(8) The PCI Utilities lspci(8)NAMElspci - list all PCI devicesSYNOPSISlspci [options]DESCRIPTIONlspci is a utility for displaying information about PCI buses in the system and devices connected to them.By default, it shows a brief list of devices. Use the options described below to request either a more verboseoutput or output intended for parsing by other programs.If you are going to report bugs in PCI device drivers or in lspci itself, please include output of "lspci -vvx" or even better "lspci -vvxxx" (however, see below for possible caveats).Some parts of the output, especially in the highly verbose modes, are probably intelligible only to experienced PCI hackers. For exact definitions of the fields, please consult either the PCI specificationsor the header.h and /usr/include/linux/pci.h include files.Access to some parts of the PCI configuration space is restricted to root on many operating systems, so the features of lspci available to normal users are limited. However, lspci tries its best to display as much as available and mark all other information with <access denied> text.
比較常用的就是
lspci -v :詳細說明并顯示所有設備的詳細信息。
lspci -vvt:顯示詳細的各設備的拓撲以及配置空間信息
OPTIONSBasic display modes-m Dump PCI device data in a backward-compatible machine readable form. See below for details.-mm Dump PCI device data in a machine readable form for easy parsing by scripts. See below for details.-t Show a tree-like diagram containing all buses, bridges, devices and connections between them.Display options-v Be verbose and display detailed information about all devices.-vv Be very verbose and display more details. This level includes everything deemed useful.-vvv Be even more verbose and display everything we are able to parse,
even if it doesn't look interesting at all (e.g., undefined memory regions).-k Show kernel drivers handling each device and also kernel modules capable of handling it.
Turned on by default when -v is given in the normal mode of output.
(Currently works only on Linux with kernel 2.6 or newer.)-x Show hexadecimal dump of the standard part of the configuration space
(the first 64 bytes or 128 bytes for CardBus bridges).-xxx Show hexadecimal dump of the whole PCI configuration space. It is available only to root as several PCI
devices crash when you try to read some parts of the config space (this behavior probably doesn't violate the PCI standard,but it's at least very stupid). However, such devices are rare, so you needn't worry much.-xxxx Show hexadecimal dump of the extended (4096-byte) PCI configuration space available on PCI-X 2.0
and PCI Express buses.-b Bus-centric view. Show all IRQ numbers and addresses as seen by the cards on the PCI bus instead ofas seen by the kernel.-D Always show PCI domain numbers. By default, lspci suppresses them on machines which have only domain 0.Options to control resolving ID's to names-n Show PCI vendor and device codes as numbers instead of looking them up in the PCI ID list.-nn Show PCI vendor and device codes as both numbers and names.-q Use DNS to query the central PCI ID database if a device is not found in the local pci.ids file.If the DNS query succeeds, the result is cached in ~/.pciids-cache and it is recognized in subsequent runs
even if -q is not given any more.
Please use this switch inside automated scripts only with caution to avoid overloading the database servers.-qq Same as -q, but the local cache is reset.-Q Query the central database even for entries which are recognized locally.
Use this if you suspect that the displayed entry is wrong.
Options for selection of devices-s [[[[<domain>]:]<bus>]:][<device>][.[<func>]]Show only devices in the specified domain (in case your machine has several host bridges,
they can either share a common bus number space or each of them can address a PCI domain of its own;
domains are numbered from 0 to ffff),bus (0 to ff), device (0 to 1f) and function (0 to 7).
Each component of the device address can be omitted or set to "*", both meaning "any value".
All numbers are hexadecimal. E.g., "0:" means all devices on bus 0, "0" means all functions of device 0 on any bus,"0.3" selects third function of device 0 on all buses and ".4" shows only the fourth function of each device.-d [<vendor>]:[<device>][:<class>]Show only devices with specified vendor, device and class ID.The ID's are given in hexadecimal and may be omitted or given as "*", both meaning "any value".Other options-i <file>Use <file> as the PCI ID list instead of /usr/share/misc/pci.ids.-p <file>Use <file> as the map of PCI ID's handled by kernel modules.
By default, lspci uses /lib/modules/kernel_version/modules.pcimap. Applies only to Linux systems with recent enough module tools.-M Invoke bus mapping mode which performs a thorough scan of all PCI devices,
including those behind misconfigured bridges, etc. This option gives meaningful results only with a direct hardware
access mode, which usually requires root privileges. Please note that the bus mapper only scans PCI domain 0.--versionShows lspci version. This option should be used stand-alone.PCI access optionsThe PCI utilities use the PCI library to talk to PCI devices (see pcilib(7) for details).
You can use the following options to influence its behavior:-A <method>The library supports a variety of methods to access the PCI hardware.
By default, it uses the first access method available, but you can use this option to override this decision.
See -A help for a list of available methods and their descriptions.-O <param>=<value>The behavior of the library is controlled by several named parameters.
This option allows to set the value of any of the parameters.
Use -O help for a list of known parameters and their default values.-H1 Use direct hardware access via Intel configuration mechanism 1. (This is a shorthand for -A intel-conf1.)-H2 Use direct hardware access via Intel configuration mechanism 2. (This is a shorthand for -A intel-conf2.)-F <file>Instead of accessing real hardware, read the list of devices and values of their configuration registers
from the given file produced by an earlier run of lspci -x.
This is very useful for analysis of user-supplied bug reports, because you can display the hardware configuration
in any way you want without disturbing the user with requests for more dumps.-G Increase debug level of the library.
參數:
-v
使得 lspci 以冗余模式顯示所有設備的詳細信息。
-vv
使得 lspci 以過冗余模式顯示更詳細的信息 (事實上是 PCI 設備能給出的所有東西)。這些數據的確切意義沒有在此手冊頁中解釋,
如果你想知道更多,請參照 /usr/include/linux/pci.h 或者 PCI 規范。
-n
以數字形式顯示 PCI 生產廠商和設備號,而不是在 PCI ID 數據庫中查找它們。
-x
以十六進制顯示 PCI 配置空間 (configuration space) 的前64個字節映像 (標準頭部信息)。此參數對調試驅動和 lspci 本身很有用。
-xxx
以十六進制顯示所有 PCI 配置空間的映像。此選項只有 root 可用,并且很多 PCI 設備在你試圖讀取配置空間的未定義部分時會崩潰
(此操作可能不違反PCI標準,但是它至少非常愚蠢)。
-b
以總線為中心進行查看。顯示所有 IRQ 號和記憶體地址,就像 PCI 總線上的卡看到的一樣,而不是核心看到的內容。
-t
以樹形方式顯示包含所有總線、橋、設備和它們的連接的圖表。
-s [[<bus>]:][<slot>][.[<func>]]
僅顯示指定總線、插槽上的設備或設備上的功能塊信息。設備地址的任何部分都可以忽略,或以「*」代替 (意味著所有值)。
所有數字都是十六進制。例如:「0:」指的是在0號總線上的所有設備;「0」指的是在任意總線上0號設備的所有功能塊;
「0.3」選擇 了所有總線上0號設備的第三個功能塊;「.4」則是只列出每一設備上的第四個功能塊。
-d [<vendor>]:[<device>]
只顯示指定生產廠商和設備 ID 的設備。 這兩個 ID 都以十六進制表示,可以忽略或者以「*」代替 (意味著所有值)。
-i <file>
使用 <file> 作為 PCI ID 數據庫而不是使用預設的 /usr/share/hwdata/pci.ids。
-p <dir>
使用 <dir> 作為包含 PCI 總線信息的目錄而不是使用預設的目錄 /proc/bus/pci。
-m
以機器可讀的方式轉儲 PCI 設備數據 (支持兩種模式:普通和冗余),便於稿本解析。
-M
使用總線映射模式,這種模式對總線進行全面地掃描以查明總線上的所有設備,包括配置錯誤的橋之后的設備。
請注意,此操作只應在調試時使 用,并可能造成系統崩潰 (只在設備有錯誤的時候,但是不幸的是它們存在),此命令只有 root 可以使用。
同時,在不直接接觸硬體的 PCI 訪問模式中使用 -M 參數沒有意義,因為顯示的結果 (排除 lspci 中的 bug 的影響)
與普通的列表模式相同。
--version
顯示 lspci 的版本。這個選項應當單獨使用。PCILIB 選項 PCILIB OPTIONS
PCI 工具使用 PCILIB (一種可移植的庫,提供平臺獨立的函數來訪問 PCI 配置空間)來和PCI卡交互。
下面的選項用來控制庫參數,特別是所用訪問模式的指定。預設情況下,PCILIB 使用第一種可用的訪問模式,不會顯示任何調試信息。
每一個開關選項都列出了一組它所支持的硬件/軟軟件列表。
-P <dir>
使用 linux 2.1 風格的配置,直接訪問目錄 <dir> 而非 /proc/bus/pci 目錄。(只能在linux 2.1或以上版本中使用)
-H1
通過 Intel 架構 1 來實現直接硬體訪問。(只能用於 i386 及其相容機)
-H2
通過Intel 架構2來實現直接硬體訪問。警告:此模式只能尋址任何總線上的前16個設備,并且在很多情況下相當不可靠。
(只能用於 i386 及其相容機)
-S
使用 PCI 系統調用訪問。(只能用於 Alpha 和 Ultra-Sparc 上的 Linux)
-F <file>
從所給的包含 lspci -x命令輸出的檔案中獲取相關信息。這在分析使用者提交的錯誤報告時很有用,
因為你可以用任何方式來顯示硬體配置信息而無需為了獲取更多信息打擾使用者。(可用於所有系統)
-G
增加庫的調試等級。(可用於所有系統)
examples:
lspci -v 以冗余方式顯示所有設備信息
$ lspci -v
00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1480
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Device 1481
00:01.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:01.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Device 1483
00:02.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:03.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:04.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:05.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:07.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482lspci -vv 顯示更詳細設備信息
lspci -nn 以數字形式顯示廠商和設備號lspci | grep -i amd
$ lspci -nn | grep -i amd
00:00.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Device [1022:1480]
00:00.2 IOMMU [0806]: Advanced Micro Devices, Inc. [AMD] Device [1022:1481]
00:01.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Device [1022:1482]
00:01.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:1483]
00:02.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Device [1022:1482]
00:03.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Device [1022:1482]
00:04.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Device [1022:1482]
00:05.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Device [1022:1482]lspci -x 16進制顯示配置空間lspci -t 以樹形方式顯示包含所有總線、橋、設備和它們的連接的圖表。
lspci -s 01:00.0 -vv "僅顯示指定總線、插槽上的設備或設備上的功能塊信息"
$ lspci -s 01:00.0 -vv
01:00.0 VGA compatible controller: NVIDIA Corporation GK208B [GeForce GT 710] (rev a1) (prog-if 00 [VGA controller])Subsystem: Micro-Star International Co., Ltd. [MSI] GK208B [GeForce GT 710]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: 0Interrupt: pin A routed to IRQ 125NUMA node: 0Region 0: Memory at d8000000 (32-bit, non-prefetchable) [size=16M]Region 1: Memory at c8000000 (64-bit, prefetchable) [size=128M]Region 3: Memory at d0000000 (64-bit, prefetchable) [size=32M]Region 5: I/O ports at 3000 [size=128]Expansion ROM at 000c0000 [disabled] [size=128K]Capabilities: <access denied>Kernel driver in use: nouveauKernel modules: nvidiafb, nouveau, nvidia_384_drm, nvidia_384$ lspci -nD | grep -e 1482 -e 1483
0000:00:01.0 0600: 1022:1482
0000:00:01.1 0604: 1022:1483
0000:00:02.0 0600: 1022:1482
0000:00:03.0 0600: 1022:1482
0000:00:04.0 0600: 1022:1482
0000:00:05.0 0600: 1022:1482
0000:00:07.0 0600: 1022:1482
0000:00:08.0 0600: 1022:1482$ lspci | egrep '1482|1483|AMD'
00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1480
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Device 1481
00:01.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:01.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Device 1483
00:02.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:03.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482
00:04.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Device 1482lspci -d 1022: -vv | grep -i Memory 查找所有vendorid為1022的卡
$ lspci -d 1022: -vv | grep -i memoryMemory behind bridge: d8000000-d90fffffPrefetchable memory behind bridge: 00000000c8000000-00000000d1ffffffMemory behind bridge: d9200000-d92fffffRegion 0: Memory at d9200000 (64-bit, non-prefetchable) [size=1M]Memory behind bridge: c2000000-c22fffffRegion 2: Memory at c2100000 (32-bit, non-prefetchable) [disabled] [size=1M]Region 5: Memory at c2208000 (32-bit, non-prefetchable) [disabled] [size=8K]Region 0: Memory at c2000000 (64-bit, non-prefetchable) [size=1M]Region 0: Memory at c2200000 (32-bit, non-prefetchable) [size=32K]
2.lspci -t
在 Linux 系統中,lspci -t
命令用于以樹狀結構(Tree Format)展示 PCI 設備的拓撲連接關系,幫助用戶直觀理解 PCI 總線、橋接器(Bridge)和設備之間的層級結構。這對于分析 PCIe 設備的物理布局、排查設備枚舉問題或優化系統性能非常有用。
輸出示例:
-[0000:00]-+-00.0 Intel Corporation 8th Gen Core Processor Host Bridge/DRAM Registers+-01.0-[01]----00.0 NVIDIA Corporation GP104 [GeForce GTX 1080]+-06.0 Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x1)+-14.0 Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller+-16.0 Intel Corporation Sunrise Point-H CSME HECI #1+-17.0 Intel Corporation Sunrise Point-H SATA Controller [AHCI mode]+-1c.0-[02-04]----00.0 Intel Corporation Sunrise Point-H PCI Express Root Port #1+-1c.4-[05]----00.0 Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller+-1f.0 Intel Corporation Sunrise Point-H LPC Controller+-1f.2 Intel Corporation Sunrise Point-H PMC+-1f.3 Intel Corporation Sunrise Point-H HD Audio Controller+-1f.4 Intel Corporation Sunrise Point-H SMBus Controller
輸出格式解析 1.PCI 域(Domain): [0000:00] 表示 PCI 域號(通常為 0)和根總線號(0)。現代系統中,一個 PCI 域對應一個 Root Complex(根復合體)。 2.設備層級: 橋接器(Bridge):如 1c.0-[02-04],表示該橋接器連接總線 02 到 04,其下可能掛載多個設備或子橋。 終端設備(Endpoint):如 01.0-[01]----00.0,表示總線 01 上的設備,無下級橋接器。 3.設備標識: 00.0、01.0 等為 BDF 號(Bus:Device.Function),例如 0000:00:01.0 表示域 0、總線 0、設備 1、功能 0。 右側為設備名稱(如 NVIDIA Corporation GP104)。
3.setpci用法小結
參考博客:Linux setpci命令教程:管理和調試 PCI 設備(含案例詳解和注意事項)-Linux入門自學網
setpci
是一個強大的Linux命令,用于查詢和配置PCI設備的硬件參數。通過直接訪問PCI配置寄存器,管理員可以讀取或者修改任何PCI設備的配置空間。這個功能在調整系統性能、啟用或禁用硬件特性、進行硬件故障排查時非常有用。
Linux setpci命令的常用選項或參數說明
選項 | 描述 |
---|---|
-s | 指定設備的總線,設備和功能號 |
-d | 過濾查找特定的設備ID |
-v | 顯示詳細輸出 |
-x | 以十六進制顯示配置空間的內容 |
-D | 訪問PCI域 |
Linux setpci命令實例詳解
實例1:列出所有PCI設備的詳細信息 此實例展示如何使用setpci列出所有PCI設備的詳細信息。
[linux@bashcommandnotfound.cn ~]$ lspci -vvv
實例2:讀取特定PCI設備的配置 以下命令讀取總線1,設備0,功能0的設備的配置空間的第一個字節。
[linux@bashcommandnotfound.cn ~]$ setpci -s 01:00.0 0x0.L
實例3:修改PCI設備的配置
此命令將總線1,設備0,功能0的設備的配置空間的第一個字節設置為0x07。
[linux@bashcommandnotfound.cn ~]$ setpci -s 01:00.0 0x0.L=0x07
實例4:讀取具體的配置寄存器值 讀取指定PCI設備的vendor ID值。
[linux@bashcommandnotfound.cn ~]$ setpci -s 01:00.0 vendor
實例5:查找具有特定vendor ID和device ID的PCI設備
如果你想找到具有特定vendor ID和device ID的PCI設備,可以使用以下命令:
[linux@bashcommandnotfound.cn ~]$ lspci -d 8086:1503