]> pere.pagekite.me Git - homepage.git/commitdiff
New post.
authorPetter Reinholdtsen <pere@hungry.com>
Sat, 22 Jan 2011 23:14:48 +0000 (23:14 +0000)
committerPetter Reinholdtsen <pere@hungry.com>
Sat, 22 Jan 2011 23:14:48 +0000 (23:14 +0000)
blog/data/2011-01-23-hardware-info.txt [new file with mode: 0644]

diff --git a/blog/data/2011-01-23-hardware-info.txt b/blog/data/2011-01-23-hardware-info.txt
new file mode 100644 (file)
index 0000000..fad6349
--- /dev/null
@@ -0,0 +1,76 @@
+Title: Which module is loaded for a given PCI device?
+Tags: english, debian
+Date: 2011-01-23 00:15
+
+<p>In the discover-data package in Debian, there is a script to report
+useful information about the running hardware for use when people
+report missing information.  One part I find very useful when
+debugging, is the part report which kernel module is loaded for a
+given PCI device.  To see the output, make sure discover-data is
+installed and run <tt>/usr/share/bug/discover-data 3>&1</tt>.  The
+relevant output on one of my machines like this:
+
+<pre>
+loaded modules:
+10de:03eb i2c_nforce2
+10de:03f1 ohci_hcd
+10de:03f2 ehci_hcd
+10de:03f0 snd_hda_intel
+10de:03ec pata_amd
+10de:03f6 sata_nv
+1022:1103 k8temp
+109e:036e bttv
+109e:0878 snd_bt87x
+11ab:4364 sky2
+</pre>
+
+<p>The code in question look like this, slightly modified for
+readability and to drop the output to file descriptor 3:</p>
+
+<pre>
+if [ -d /sys/bus/pci/devices/ ] ; then
+    echo loaded pci modules:
+    (
+        cd /sys/bus/pci/devices/
+        for address in * ; do
+            if [ -d "$address/driver/module" ] ; then
+                module=`cd $address/driver/module ; pwd -P | xargs basename`
+                if grep -q "^$module " /proc/modules ; then
+                    address=$(echo $address |sed s/0000://)
+                   id=`lspci -n -s $address | tail -n 1 | awk '{print $3}'`
+                    echo "$id $module"
+                fi
+            fi
+        done
+    )
+    echo
+fi
+</pre>
+
+<p>Similar code could be used to extract USB device module
+mappings:</p>
+
+<pre>
+if [ -d /sys/bus/usb/devices/ ] ; then
+    echo loaded usb modules:
+    (
+        cd /sys/bus/usb/devices/
+        for address in * ; do
+            if [ -d "$address/driver/module" ] ; then
+                module=`cd $address/driver/module ; pwd -P | xargs basename`
+                if grep -q "^$module " /proc/modules ; then
+                    address=$(echo $address |sed s/0000://)
+                    id=$(lsusb -s $address | tail -n 1 | awk '{print $6}')
+                    if [ "$id" ] ; then
+                        echo "$id $module"
+                    fi
+                fi
+            fi
+        done
+    )
+    echo
+fi
+</pre>
+
+<p>This might perhaps be something to include in other tools as
+well.</p>