]> pere.pagekite.me Git - homepage.git/blob - blog/data/2011-01-23-hardware-info.txt
Ny post.
[homepage.git] / blog / data / 2011-01-23-hardware-info.txt
1 Title: Which module is loaded for a given PCI and USB device?
2 Tags: english, debian
3 Date: 2011-01-23 00:20
4
5 <p>In the
6 <a href="http://packages.qa.debian.org/discover-data">discover-data</a>
7 package in Debian, there is a script to report useful information
8 about the running hardware for use when people report missing
9 information. One part of this script that I find very useful when
10 debugging hardware problems, is the part mapping loaded kernel module
11 to the PCI device it claims. It allow me to quickly see if the kernel
12 module I expect is driving the hardware I am struggling with. To see
13 the output, make sure discover-data is installed and run
14 <tt>/usr/share/bug/discover-data 3>&1</tt>. The relevant output on
15 one of my machines like this:</p>
16
17 <pre>
18 loaded modules:
19 10de:03eb i2c_nforce2
20 10de:03f1 ohci_hcd
21 10de:03f2 ehci_hcd
22 10de:03f0 snd_hda_intel
23 10de:03ec pata_amd
24 10de:03f6 sata_nv
25 1022:1103 k8temp
26 109e:036e bttv
27 109e:0878 snd_bt87x
28 11ab:4364 sky2
29 </pre>
30
31 <p>The code in question look like this, slightly modified for
32 readability and to drop the output to file descriptor 3:</p>
33
34 <pre>
35 if [ -d /sys/bus/pci/devices/ ] ; then
36 echo loaded pci modules:
37 (
38 cd /sys/bus/pci/devices/
39 for address in * ; do
40 if [ -d "$address/driver/module" ] ; then
41 module=`cd $address/driver/module ; pwd -P | xargs basename`
42 if grep -q "^$module " /proc/modules ; then
43 address=$(echo $address |sed s/0000://)
44 id=`lspci -n -s $address | tail -n 1 | awk '{print $3}'`
45 echo "$id $module"
46 fi
47 fi
48 done
49 )
50 echo
51 fi
52 </pre>
53
54 <p>Similar code could be used to extract USB device module
55 mappings:</p>
56
57 <pre>
58 if [ -d /sys/bus/usb/devices/ ] ; then
59 echo loaded usb modules:
60 (
61 cd /sys/bus/usb/devices/
62 for address in * ; do
63 if [ -d "$address/driver/module" ] ; then
64 module=`cd $address/driver/module ; pwd -P | xargs basename`
65 if grep -q "^$module " /proc/modules ; then
66 address=$(echo $address |sed s/0000://)
67 id=$(lsusb -s $address | tail -n 1 | awk '{print $6}')
68 if [ "$id" ] ; then
69 echo "$id $module"
70 fi
71 fi
72 fi
73 done
74 )
75 echo
76 fi
77 </pre>
78
79 <p>This might perhaps be something to include in other tools as
80 well.</p>