setpci – Utility for Querying and Configuring PCI Devices

The setpci command is a Linux utility used for querying and configuring PCI devices. It allows users to view and modify the configuration space of PCI devices, including their vendor ID, device ID, and other settings.

Overview

The setpci command is typically used by system administrators and advanced users who need to configure or troubleshoot PCI devices on a Linux system. The command can be used to read and write values to the configuration space of a PCI device, which is a set of registers that contain information about the device’s capabilities, status, and configuration.

To use the setpci command, you must first determine the bus, device, and function number of the PCI device you want to query or configure. You can use the lspci command to list all PCI devices on your system and their corresponding bus, device, and function numbers.

Once you have identified the PCI device you want to work with, you can use the setpci command to read or write values to its configuration space. For example, to read the vendor ID of a device with bus number 00, device number 1b, and function number 0, you would run the following command:

sudo setpci -s 00:1b.0 vendor

This would output the vendor ID of the device in hexadecimal format.

To write a value to a specific register in the configuration space, you would use the following syntax:

sudo setpci -s bus:device.function register=value

For example, to set the maximum read request size of a device with bus number 01, device number 00, and function number 0 to 4096 bytes, you would run the following command:

sudo setpci -s 01:00.0 68.w=4096

This would write the value 4096 to the register at offset 68 in the configuration space of the specified device.

Options

The setpci command supports several options that can be used to customize its behavior. The following table lists all available options:

Option Description
-s Specifies the bus, device, and function number of the target PCI device in the format bus:device.function.
-v Enables verbose output, which includes additional information about the configuration space of the target device.
-d Specifies the vendor ID and device ID of the target device in the format vendor:device. This option can be used instead of the -s option to specify the device.
-x Displays the entire configuration space of the target device in hexadecimal format.
-X Displays the entire configuration space of the target device in a more readable format.
-h Displays a help message that explains how to use the setpci command.

Troubleshooting Tips

If you encounter issues when using the setpci command, here are some troubleshooting tips that may help:

  • Make sure you have the necessary permissions to access the PCI devices on your system. The setpci command requires root privileges to read and write to the configuration space of a device.
  • Double-check the bus, device, and function number of the target device to ensure that you are accessing the correct device.
  • Be careful when modifying the configuration space of a PCI device, as incorrect values can cause the device to malfunction or become unusable.

Notes

  • The setpci command should be used with caution, as modifying the configuration space of a PCI device can have unintended consequences.
  • Some PCI devices may not support all configuration space registers, or may have vendor-specific registers that are not documented in the PCI specification.
  • The setpci command is not available on all Linux distributions by default, and may need to be installed separately.