PCI Device Access using Proc / Sys File System

(PCI Device Resource Access & Configuration)

This post is about how can we access and configure PCI Device using a different kind of filesystems available in Linux. The two different kinds of filesystems are procfs (legacy) and sysfs (the new type which provides more details than procfs). Both of these provide information about System, Device or, CPU, etc. The procfs is limited in providing the information than sysfs for PCI as well as other devices. 

PCI Device Representation:

  • [[[[<domain>]:]<bus>]:][<slot / device][.[<function>]]
  • domain (16Bit value) => 0000 - FFFF
  • bus (8Bit value) => 00 - FF
  • slot / device (5Bit value) => 00 - 1F
  • function (3Bit value) => 0 - 7
PCI procfs interface:

 Files
Description 
 /proc/bus/pci/devices
Contains enumerated PCI Device information 
/proc/bus/pci/<bus>/<slot>.<func>/ 
Contains the config space data ( hexdump ) 

Example 1: Accessing pci devices with different type of data (device id, vendor id, etc). -- Human readable and easily accessible format.


Example 2: Accessing Ethernet controller.


Linux pci sysfs interface:

 Directory
Description 
/sys/bus/pci/devices 
Contains Enumerated PCI Device information 
/sys/devices/pci0000:00 
Contains Enumerated PCI Device information 
/sys/bus/pci/drivers 
PCI Device drivers 
Example 3: acessing sysfs.



Example 4: Enabling - Disabling Ethernet port (e1000) in sysfs.


sysfs files ( /sys/bus/pci/devices/<domain>:<bus>:<slot>:<func> )


RO: Read Only


Comments