lspci/setpci用法小结
目录
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