About the lspci command in Linux

The lspci command is a Linux utility used to obtain information about PCI buses and devices connected to the PCI subsystem. You can understand the meaning of the command by looking at the word lspci in two parts. The first part of ls is a standard Linux utility used to display information about files on the filesystem. Pci is the second part of the command, so you can naturally see that the lspci command displays information about the PCI subsystem in the same way that the ls command displays information about the filesystem.

In this article, we will explain the basics of PCI, PCIe, and lspci commands to display information on your system.

What is PCI?

PCI or Peripheral Component Interconnect is an interface for adding additional hardware components to a computer system. PCIe or PCI Express is the updated standard in use today. For example, suppose you want to add an Ethernet card to your computer so that it can access the Internet and communicate. The card needs a protocol to communicate with the rest of the internal system, PCI can be the standard interface used to add this card to your system. You still need a driver for this card for the kernel to be able to use it, however PCI is the slot and also the bus and interface that will be used to add hardware to a system with a standard interface. The PCI linux driver creation will follow some standard interfaces. You can see from the structure below the standard methods that need to be implemented. Techniques such as probing, deleting, suspending, resuming, etc.

struct pci_driver {
struct list_head        node;
const char              *name;
const struct pci_device_id *id_table;
int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
void (*remove)(struct pci_dev *dev);
int (*suspend)(struct pci_dev *dev, pm_message_t state);
int (*resume)(struct pci_dev *dev);
void (*shutdown)(struct pci_dev *dev);
int (*sriov_configure)(struct pci_dev *dev, int num_vfs);
const struct pci_error_handlers *err_handler;
const struct attribute_group **groups;
struct device_driver    driver;
struct pci_dynids       dynids;
};

PCI speed and usage

PCI 3.0 can transfer data at speeds up to 1 GB / s per lane. Different devices can have more than one bandwidth, so it is possible that individual devices can have data transfer rates of several gigabytes. These numbers are always improving as new specs and hardware are released, so always check for the latest and fastest available. The types of components and gadgets you can buy with PCI connectivity include: WIFI adapters, Bluetooth, NVME solid state storage cards, graphics cards, and more.

Exploring the lspci Command

We created an instance of Ubuntu 19.04 in the Google Cloud and now I will run the lspci command and see what happens.

You see one line per device with a numeric code and a verbal description of the device. In fact, this output displays 5 fields per line: slot, class, vendor, device, and version.

So, breaking down the first line, what we have is:

SLOT: 00: 00.0 Class: Bridge Host Vendor: Intel Corporation Device: 440FX – 82441FX PMC Revision: 02

And if you look at slot 00: 04.0, this is our Ethernet controller, which looks like a virtual appliance as part of the virtual magic of Google’s cloud deployment.

To get more detailed and detailed information about each PCI slot, run the following command:

# lspci -vmm

This command breaks each line into component fields and allows you to parse each device with more descriptive labels.

You can also try the -v option for more verbose output

# lspci -v

And use double v or tripple v for verbose output:

# lspci -vvv

Or try the -mm option for the output format read by the script.

# lspci -mm

To find out which kernel driver is used for each device, run the -k option.

Many of my devices use the virtio-pci driver.

Finally, you can even see a hex dump of the “standard part of the configuration space” for each PCI device. You have to be a real core hacker to figure out how to use this information. -x is what gives you the dump output.

# lspci -x

Output

The lspci command is a standard Linux command that you can use to display information about PCI devices on your system. This can be helpful to find out what kind of peripheral equipment you have. It is also very useful for developers, device driver writers, and low-level system specialists to request information about devices, drivers, and system. Enjoy using lspci.

Related Posts