Proc – Where Does lspci Gather Its Information From?

documentationproc

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)

Best Answer

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, "\206\200\36\36\7\0\20\0\304\0\4\6\20\0\201\0\0\0\0\0\0\0\0\0\0\7\7\0\360\0\0
\0"..., 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.

Related Question