a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# get-pci-ids: extract pci vendor/device ids from linux net drivers
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Copyright (C) 2003 Georg Baum <gbaum@users.sf.net>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# This program is free software; you can redistribute it and/or modify
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# it under the terms of the GNU General Public License as published by
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# the Free Software Foundation; either version 2 of the License, or
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# (at your option) any later version.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# This program is distributed in the hope that it will be useful,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# but WITHOUT ANY WARRANTY; without even the implied warranty of
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# GNU General Public License for more details.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# You should have received a copy of the GNU General Public License
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# along with this program; if not, write to the Free Software
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# - Does not recognize all drivers because some require special cflags.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Fails also on some drivers that do belong to other architectures
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# than the one of the machine this script is running on.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# This is currently not so important because all drivers that have an
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Etherboot counterpart are recognized.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Where to find the kernel sources
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Sanity checks
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync print STDERR "Usage: get-pci-ids [path to kernel sources]\n";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync print STDERR " /usr/src/linux is assumed if no path is given.\n";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync print STDERR "Could not find $kernel_src/include/linux/version.h.\n";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync print STDERR "$kernel_src is probably no Linux kernel source tree.\n";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Flags that are needed to preprocess the drivers.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Some drivers need optimization
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncmy $cflags="-D__KERNEL__ -I$kernel_src/include -I$kernel_src/net/inet -O2";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# The C preprocessor. It needs to spit out the preprocessed source on stdout.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# List of drivers. We parse every .c file. It does not harm if it does not contain a driver.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncmy @drivers = split /\s+/, `find $kernel_src/drivers/net -name '*.c' | sort`;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Kernel version
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncmy $version = `grep UTS_RELEASE $kernel_src/include/linux/version.h`;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync$version =~ s/\s*#define\s+UTS_RELEASE\s+"(\S+)".*$/$1/g;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Architecture
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Print header
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncprint "# PCI vendor/device ids extracted from Linux $version on $uname[4] at " . gmtime() . "\n";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync# Process the drivers
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync my $command = "$cpp $cflags -I" . dirname($driver) . " $driver";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync open DRIVER, "$command |" or die "Could not execute\n\"$command\".\n";
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync # This line contains a full entry or the last part of it.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync # Push the vendor and device id to @lines if this line is not empty.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync my ($vendor_id, $device_id, $remainder) = split /\W+/, $_, 3;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync push @lines, "$vendor_id $device_id\n" if($vendor_id && $device_id);
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync # This line does contain a partial entry. Remember it.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync close DRIVER; # No "or die", because $cpp fails on some files
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync # Print each vendor/device id combination only once.