where does lspci gather its information from?

In kernel.org’s documentation on proc I found “[The latest version of this document is available online“. There I says: “… lspci is a synonym for cat /proc/pci“.

Which isn’t the case here, on a Crunchbang 10 system (Debian based). No such directory. I do get the basic idea and, as far as I know, the content of proc is (mainly) created during runtime. (Wrong?). This made me curious:

Question: Where does lspci gather it’s information from? And where is this documented? (Where did I miss something?)

 
Another difference I found: In kernel.org’s documentation, under “Table 1-5: Kernel info in /proc

pci     Deprecated info of PCI bus (new way -> /proc/bus/pci/, decoupled by `lspci)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

lspci is part of pciutils, which is portable to a variety of unix-like OS’s and windows, so it presumably uses different methods depending on platform.

You should be able to tell where it gets its info from in your case via strace lspci. After the preamble accessing libraries, etc, I (using fedora linux) get a lot of open() + pread() calls on stuff in /sys/bus/pci/, e.g.:

open("/sys/bus/pci/devices/0000:00:1c.7/config", O_RDONLY) = 3
pread(3, "2062003636720304462020177360
"..., 64, 0) = 64
close(3)

That’s binary data. After this it reads in /usr/share/hwdata/pci.ids, which is a static universal list distributed with the pciutils package. These are four digit codes which presumably correspond to the info from /sys.

Method 2

/proc

I believe it was moved to /proc/bus/pci, so that all the buses could be kept in a single spot.

$ pwd
/proc/bus/pci

Example

lspci output:

$ lspci | tail -10
03:00.0 Network controller: Intel Corporation Centrino Wireless-N 1000
0d:00.0 SD Host controller: Ricoh Co Ltd Device e822 (rev 01)
0d:00.1 System peripheral: Ricoh Co Ltd Device e230 (rev 01)
0d:00.3 FireWire (IEEE 1394): Ricoh Co Ltd Device e832 (rev 01)
ff:00.0 Host bridge: Intel Corporation Core Processor QuickPath Architecture Generic Non-core Registers (rev 02)
ff:00.1 Host bridge: Intel Corporation Core Processor QuickPath Architecture System Address Decoder (rev 02)
ff:02.0 Host bridge: Intel Corporation Core Processor QPI Link 0 (rev 02)
ff:02.1 Host bridge: Intel Corporation Core Processor QPI Physical 0 (rev 02)
ff:02.2 Host bridge: Intel Corporation Core Processor Reserved (rev 02)
ff:02.3 Host bridge: Intel Corporation Core Processor Reserved (rev 02)

Corresponding tree under /proc/bus/pci:

$ tree . | tail -10
|-- devices
`-- ff
    |-- 00.0
    |-- 00.1
    |-- 02.0
    |-- 02.1
    |-- 02.2
    `-- 02.3

/sys

The other location where device data is kept is under /sys. If you poke around there you’ll notice this directory:

$ ls -l /sys/bus/pci
total 0
drwxr-xr-x  2 root root    0 Dec  1 09:43 devices
drwxr-xr-x 23 root root    0 Nov 30 16:27 drivers
-rw-r--r--  1 root root 4096 Dec  1 10:59 drivers_autoprobe
--w-------  1 root root 4096 Dec  1 10:59 drivers_probe
--w--w----  1 root root 4096 Dec  1 10:59 rescan
-rw-r--r--  1 root root 4096 Dec  1 10:59 resource_alignment
drwxr-xr-x  3 root root    0 Dec  1 10:36 slots
--w-------  1 root root 4096 Nov 30 16:27 uevent


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x