From af9a5464509a49422c40891084c22b607503389d Mon Sep 17 00:00:00 2001 From: sheldonh Date: Thu, 22 Nov 2001 14:26:30 +0000 Subject: Add the script that will be used to maintain src/share/misc/pci_vendors. The script written and used originally by msmith has been lost. This version takes the Boemler and Heckenbach lists and produces merged output. It defaults to ignoring any entries from Heckenbach already found in Boemler but the -l option causes it to take the entry with the longest description where an entry appears in both lists. If this script is replaced, care should be taken to 1) Always use upper-case hexidecimal tokens in device ids. 2) Always keep device lists sorted within vendor lists, which must also be sorted. 3) Do not try to include input from the previous pci_vendors file, since bogus ids seem to be removed from both the Boemler and Heckenbach lists from time to time. --- tools/tools/README | 1 + tools/tools/pciid/mk_pci_vendors.pl | 232 ++++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+) create mode 100644 tools/tools/pciid/mk_pci_vendors.pl (limited to 'tools') diff --git a/tools/tools/README b/tools/tools/README index dc0a5f0..0d47beb 100644 --- a/tools/tools/README +++ b/tools/tools/README @@ -18,6 +18,7 @@ kerncruft Shellscript to find orphaned *.c files in /sys kerninclude Shellscript to find unused #includes in the kernel. kernxref Shellscript to cross reference symbols in the LINT kernel. mid Create a Message-ID database for mailing lists. +pciid Generate src/share/misc/pci_vendors. portsinfo Generate list of new ports for last two weeks. scsi-defects Get at the primary or grown defect list of a SCSI disk. upgrade Scripts used for upgrading an installed system. diff --git a/tools/tools/pciid/mk_pci_vendors.pl b/tools/tools/pciid/mk_pci_vendors.pl new file mode 100644 index 0000000..0868046 --- /dev/null +++ b/tools/tools/pciid/mk_pci_vendors.pl @@ -0,0 +1,232 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2001 Sheldon Hearn. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +# usage: mk_pci_vendors [-lq] [-p pcidevs.txt] [-v vendors.txt] +# +# Generate src/share/misc/pci_vendors from the Heckenbach and Boemler +# lists, currently available at: +# +# Boemler: http://www.yourvote.com/pci/ +# Heckenbach: http://members.hyperlink.com.au/~chart/pci.htm +# +# -l Where an entry is found in both input lists, use the entry with +# the longest description. The default is for the Boemler file to +# override the Heckenback file. +# -q Do not print diagnostics. +# -p Specify the pathname of the Heckenbach file. (Default ./pcidevs.txt) +# -v Specify the pathname of the Boemler file. (Default ./vendors.txt) +# +use strict; +use Getopt::Std; + +my $PROGNAME = 'mk_pci_vendors'; +my $VENDORS_FILE = 'vendors.txt'; +my $PCIDEVS_FILE = 'pcidevs.txt'; + +my $cur_vendor; +my %opts; +my %vendors; +my ($descr, $existing, $id, $line, $rv, $winner, $optlused); + +my $IS_VENDOR = 1; +my $IS_DEVICE = 2; +my $V_DESCR = 0; +my $V_DEVSL = 1; +my $W_NOCONTEST = 0; +my $W_VENDORS = 1; +my $W_PCIDEVS = 2; + +sub vendors_parse($\$\$); +sub pcidevs_parse($\$\$); + +if (not getopts('lp:qv:', \%opts) or @ARGV > 0) { + print STDERR "usage: $PROGNAME [-lq] [-p pcidevs.txt] [-v vendors.txt]\n"; + exit 1; +} + +if (not defined($opts{p})) { + $opts{p} = $PCIDEVS_FILE; +} +if (not defined($opts{v})) { + $opts{v} = $VENDORS_FILE; +} +foreach (('l', 'q')) { + if (not exists($opts{$_})) { + $opts{$_} = 0; + } else { + $opts{$_} = 1; + } +} + +open(VENDORS, "< $opts{v}") or + die "$PROGNAME: $opts{v}: $!\n"; +while ($line = ) { + chomp($line); + $rv = vendors_parse($line, $id, $descr); + if ($rv == $IS_VENDOR) { + if (exists($vendors{$id})) { + die "$PROGNAME: $id: duplicate vendor ID\n"; + } + $vendors{$id} = [$descr, {}]; + $cur_vendor = $id; + } elsif ($rv == $IS_DEVICE) { + ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr; + } +} +close(VENDORS); + +open(PCIDEVS, "< $opts{p}") or + die "$PROGNAME: $opts{p}: $!\n"; +while ($line = ) { + chomp($line); + $rv = pcidevs_parse($line, $id, $descr); + if ($rv == $IS_VENDOR) { + if (not exists($vendors{$id})) { + $vendors{$id} = [$descr, {}]; + $winner = $W_NOCONTEST; + } elsif ($opts{l}) { + $existing = $vendors{$id}->[$V_DESCR]; + if (length($existing) < length($descr)) { + $vendors{$id}->[$V_DESCR] = $descr; + $winner = $W_PCIDEVS; + } else { + $winner = $W_VENDORS; + } + } else { + $winner = $W_VENDORS; + } + $cur_vendor = $id; + if (not $opts{q} and $winner != $W_NOCONTEST) { + $existing = $vendors{$id}->[$V_DESCR]; + print STDERR "$PROGNAME: ", + $winner == $W_VENDORS ? "Boemler" : "Heckenbach", + " vendor wins: $id\t$existing\n"; + } + } elsif ($rv == $IS_DEVICE) { + if (not exists(${$vendors{$cur_vendor}->[$V_DEVSL]}{$id})) { + ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr; + $winner = $W_NOCONTEST; + } elsif ($opts{l}) { + $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id}; + if (length($existing) < length($descr)) { + ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = + $descr; + $winner = $W_PCIDEVS; + } else { + $winner = $W_VENDORS; + } + } else { + $winner = $W_VENDORS; + } + if (not $opts{q} and $winner != $W_NOCONTEST) { + $existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id}; + print STDERR "$PROGNAME: ", + $winner == $W_VENDORS ? "Boemler" : "Heckenbach", + " device wins: $id\t$existing\n"; + } + } +} +close(PCIDEVS); + +$optlused = $opts{l} ? "with" : "without"; +print <[$V_DESCR]; + print "$id\t$descr\n"; + foreach $id (sort keys %{$vendors{$cur_vendor}->[$V_DEVSL]}) { + $descr = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id}; + print "\t$id\t$descr\n"; + } +} +exit 0; + + +# Parse a line from the Boemler file and place the ID and description +# in the scalars referenced by $id_ref and $descr_ref. +# +# On success, returns $IS_VENDOR if the line represents a vendor entity +# or $IS_DEVICE if the line represents a device entity. +# +# Returns 0 on failure. +# +sub vendors_parse($\$\$) +{ + my ($line, $id_ref, $descr_ref) = @_; + + if ($line =~ /^([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) { + ($$id_ref, $$descr_ref) = (uc($1), $2); + return $IS_VENDOR; + } elsif ($line =~ /^\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) { + ($$id_ref, $$descr_ref) = (uc($1), $2); + return $IS_DEVICE; + } elsif (not $opts{q} and + $line !~ /^\s*$/ and $line !~ /^;/) { + chomp($line); + print STDERR "$PROGNAME: ignored Boemler: $line\n"; + } + + return 0; +} + +# Parse a line from the Heckenbach file and place the ID and description +# in the scalars referenced by $id_ref and $descr_ref. +# +# On success, returns $IS_VENDOR if the line represents a vendor entity +# or $IS_DEVICE if the line represents a device entity. +# +# Returns 0 on failure. +# +sub pcidevs_parse($\$\$) +{ + my ($line, $id_ref, $descr_ref) = @_; + + if ($line =~ /^V\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) { + ($$id_ref, $$descr_ref) = (uc($1), $2); + return $IS_VENDOR; + } elsif ($line =~ /^D\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) { + ($$id_ref, $$descr_ref) = (uc($1), $2); + return $IS_DEVICE; + } elsif (not $opts{q} and + $line !~ /^\s*$/ and $line !~ /^[;ORSX]/) { + print STDERR "$PROGNAME: ignored Heckenbach: $line\n"; + } + + return 0; +} -- cgit v1.1