3 # get-pci-ids: extract pci vendor/device ids from linux net drivers
5 # Copyright (C) 2003 Georg Baum <gbaum@users.sf.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # Known bugs/limitations:
23 # - Does not recognize all drivers because some require special cflags.
24 # Fails also on some drivers that do belong to other architectures
25 # than the one of the machine this script is running on.
26 # This is currently not so important because all drivers that have an
27 # Etherboot counterpart are recognized.
31 use File
::Basename
"dirname";
34 # Where to find the kernel sources
35 my $kernel_src = "/usr/src/linux";
43 print STDERR
"Too many arguments.\n";
44 print STDERR
"Usage: get-pci-ids [path to kernel sources]\n";
45 print STDERR
" /usr/src/linux is assumed if no path is given.\n";
49 unless(-f
"$kernel_src/include/linux/version.h") {
50 print STDERR
"Could not find $kernel_src/include/linux/version.h.\n";
51 print STDERR
"$kernel_src is probably no Linux kernel source tree.\n";
55 # Flags that are needed to preprocess the drivers.
56 # Some drivers need optimization
57 my $cflags="-D__KERNEL__ -I$kernel_src/include -I$kernel_src/net/inet -O2";
59 # The C preprocessor. It needs to spit out the preprocessed source on stdout.
62 # List of drivers. We parse every .c file. It does not harm if it does not contain a driver.
63 my @drivers = split /\s+/, `find $kernel_src/drivers/net -name '*.c' | sort`;
66 my $version = `grep UTS_RELEASE $kernel_src/include/linux/version.h`;
68 $version =~ s/\s*#define\s+UTS_RELEASE\s+"(\S+)".*$/$1/g;
75 print "# PCI vendor/device ids extracted from Linux $version on $uname[4] at " . gmtime() . "\n";
80 foreach $driver (@drivers) {
82 # Preprocess to expand macros
83 my $command = "$cpp $cflags -I" . dirname
($driver) . " $driver";
84 open DRIVER
, "$command |" or die "Could not execute\n\"$command\".\n";
86 # Extract the pci_device_id structure
91 if(/^\s*static\s+struct\s+pci_device_id/) {
92 # This file contains a driver. Print the name.
93 $driver =~ s!$kernel_src/drivers/net/!!g;
99 if(/\};/ or /{\s*0\s*,?\s*}/) {
104 if(/\}\s*,?\s*\n?$/) {
105 # This line contains a full entry or the last part of it.
108 s/[,\{\};\(\)]//g; # Strip punctuation
109 s/^\s+//g; # Eat whitespace at beginning of line
110 tr
[A
-Z
][a
-z
]; # Convert to lowercase
111 # Push the vendor and device id to @lines if this line is not empty.
112 # We ignore everything else that might be there
113 my ($vendor_id, $device_id, $remainder) = split /\W+/, $_, 3;
114 push @lines, "$vendor_id $device_id\n" if($vendor_id && $device_id);
116 # This line does contain a partial entry. Remember it.
122 close DRIVER
; # No "or die", because $cpp fails on some files
124 # Now print out the sorted values
125 @lines = sort @lines;
128 # Print each vendor/device id combination only once.
129 # Some drivers (e.g. e100) do contain subfamilies
130 print if($_ ne $lastline);