summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorsheldonh <sheldonh@FreeBSD.org>2001-11-22 14:26:30 +0000
committersheldonh <sheldonh@FreeBSD.org>2001-11-22 14:26:30 +0000
commitaf9a5464509a49422c40891084c22b607503389d (patch)
tree417ca549626d708283384fd0ebc23184facfe344 /tools
parentebe2ce32d24bd6e4db11fde485f9bde3c6696c5e (diff)
downloadFreeBSD-src-af9a5464509a49422c40891084c22b607503389d.zip
FreeBSD-src-af9a5464509a49422c40891084c22b607503389d.tar.gz
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/README1
-rw-r--r--tools/tools/pciid/mk_pci_vendors.pl232
2 files changed, 233 insertions, 0 deletions
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 = <VENDORS>) {
+ 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 = <PCIDEVS>) {
+ 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 <<HEADER_END;
+; \$FreeBSD\$
+;
+; Automatically generated by src/tools/tools/pciid/mk_pci_vendors.pl
+; ($optlused the -l option), using the following source lists:
+;
+; http://www.yourvote.com/pci/vendors.txt
+; http://members.hyperlink.com.au/~chart/download/pcidevs.txt
+;
+; Manual edits on this file will be lost!
+;
+HEADER_END
+
+foreach $cur_vendor (sort keys %vendors) {
+ $id = $cur_vendor;
+ $descr = $vendors{$id}->[$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;
+}
OpenPOWER on IntegriCloud