lspci

From LinuxReviews
Jump to navigationJump to search

lspci is a handy GNU/Linux command-line utility which will display all kinds of incriminating information about a computers PCI and PCIe devices. It is provided by the pciutils package.

Examples

lspci will, without any arguments, show a simple list of the devices that are connected to the system - not just those that are in PCI(e) slots; it will also show bridges and on-board devices. Here is a partial example of what lspcis output will look like:

02:04.0 PCI bridge: Advanced Micro Devices, Inc. [AMD] 300 Series Chipset PCIe Port (rev 02)
03:00.0 USB controller: ASMedia Technology Inc. ASM1143 USB 3.1 Host Controller
04:00.0 Ethernet controller: Intel Corporation I211 Gigabit Network Connection (rev 03)
05:00.0 Ethernet controller: Qualcomm Atheros Killer E2500 Gigabit Ethernet Controller (rev 10)
07:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Ellesmere [Radeon RX 470/480/570/570X/580/580X/590] (rev ef)
07:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Ellesmere HDMI Audio [Radeon RX 470/480 / 570/580/590]
08:00.0 Non-Essential Instrumentation [1300]: Advanced Micro Devices, Inc. [AMD] Zeppelin/Raven/Raven2 PCIe Dummy Function

Adding the -v will make lspci output a lot more information about each device. Adding it twice (-vv) adds even more information to that list. Most of the information lspci -v and lspci -vv can display is only available as root. lspci will happily run lspci -vv as any user and present what it can find out as a regular user. This will be a much shorter list than you get if you run lspci -vv as root.

lspci has a useful -t option which provides a handy tree output which shows what devices are connected to what bridge. Using this option will, by default, only list the PCIe IDs. Combining it with -v to get a "verbose" output is therefore a good idea.

Lspci-tv-example.jpg
Example of lspci -tv output.

lspci has a lot more switches. Consult the lspci manual page or run lspci -h to see them all.

Listing PCIe devices IOMMU Groups

lspci can't and won't show you what IOMMU group a PCIe device belongs to. That's fine, it is possible to find out without it's help and use it to list the actual information about each device. The trick is to poke around in /sys/ to get the relevant information.

Lspci-listing-iommu-groups.jpg
Example output of a script using lspci to get information about a systems IOMMU devices.

File: /usr/local/bin/lsiommu.sh
#!/bin/bash
for d in /sys/kernel/iommu_groups/*/devices/*; do
  n=${d#*/iommu_groups/*}; n=${n%%/*}
  printf 'IOMMU Group %s ' "$n"
  lspci -nns "${d##*/}"
done

Place this in $HOME/bin or /usr/local/bin/ and make it executable with chmod a+x to use it. It can be used as a regular user, it does not require root.


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.