Skip to content

Commit 22d82e6

Browse files
Edwin GroothuisEdwin Groothuis
authored andcommitted
When trying to see if we could update the share/misc/pci_vendors,
I found out that the input format of the Boemler list was different than what the code expected: The last two fields were interpreted as one. Checking the csv version of the list it showed that there was sometimes a chipset number in the column before the card description. This is a rewrite to use the CSV format of the Boemler list. The output is differently formatted: Instead of the "chip description", it is now "description (chip)"
1 parent c048da9 commit 22d82e6

File tree

1 file changed

+99
-79
lines changed

1 file changed

+99
-79
lines changed

tools/tools/pciid/mk_pci_vendors.pl

Lines changed: 99 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# Generate src/share/misc/pci_vendors from the Hart and Boemler lists,
3131
# currently available at:
3232
#
33-
# Boemler: http://www.pcidatabase.com/reports.php?type=tab-delimeted
33+
# Boemler: http://www.pcidatabase.com/reports.php?type=csv
3434
# Hart: http://members.datafast.net.au/dft0802/downloads/pcidevs.txt
3535
#
3636
# -l Where an entry is found in both input lists, use the entry with
@@ -42,26 +42,28 @@
4242
#
4343
use strict;
4444
use Getopt::Std;
45+
use Data::Dumper;
4546

4647
my $PROGNAME = 'mk_pci_vendors';
4748
my $VENDORS_FILE = 'vendors.txt';
4849
my $PCIDEVS_FILE = 'pcidevs.txt';
4950

50-
my $cur_vendor;
51+
my ($cur_vendor, $vendorid, $pciid, $vendor);
5152
my %opts;
52-
my %vendors;
53+
my %pciids = ();
54+
my %vendors = ();
5355
my ($descr, $existing, $id, $line, $rv, $winner, $optlused);
5456

5557
my $IS_VENDOR = 1;
5658
my $IS_DEVICE = 2;
5759
my $V_DESCR = 0;
5860
my $V_DEVSL = 1;
59-
my $W_NOCONTEST = 0;
61+
my $W_FINAL = 0;
6062
my $W_VENDORS = 1;
6163
my $W_PCIDEVS = 2;
6264

6365
sub clean_descr($);
64-
sub vendors_parse($\$\$);
66+
sub vendors_parse($\$\$\$\$);
6567
sub pcidevs_parse($\$\$);
6668

6769
if (not getopts('lp:qv:', \%opts) or @ARGV > 0) {
@@ -87,15 +89,14 @@
8789
die "$PROGNAME: $opts{v}: $!\n";
8890
while ($line = <VENDORS>) {
8991
chomp($line);
90-
$rv = vendors_parse($line, $id, $descr);
91-
if ($rv == $IS_VENDOR) {
92-
if (exists($vendors{$id})) {
93-
die "$PROGNAME: $id: duplicate vendor ID\n";
92+
$rv = vendors_parse($line, $vendorid, $pciid, $vendor, $descr);
93+
if ($rv != 0) {
94+
if (defined $vendors{$vendorid}
95+
&& $vendors{$vendorid}[$W_VENDORS] ne $vendor) {
96+
die "$PROGNAME: $vendorid: duplicate vendor ID\n";
9497
}
95-
$vendors{$id} = [$descr, {}];
96-
$cur_vendor = $id;
97-
} elsif ($rv == $IS_DEVICE) {
98-
${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
98+
$vendors{$vendorid}[$W_VENDORS] = $vendor;
99+
$pciids{$vendorid}{$pciid}[$W_VENDORS] = $descr;
99100
}
100101
}
101102
close(VENDORS);
@@ -106,52 +107,57 @@
106107
chomp($line);
107108
$rv = pcidevs_parse($line, $id, $descr);
108109
if ($rv == $IS_VENDOR) {
109-
if (not exists($vendors{$id})) {
110-
$vendors{$id} = [$descr, {}];
111-
$winner = $W_NOCONTEST;
112-
} elsif ($opts{l}) {
113-
$existing = $vendors{$id}->[$V_DESCR];
114-
if (length($existing) < length($descr)) {
115-
$vendors{$id}->[$V_DESCR] = $descr;
116-
$winner = $W_PCIDEVS;
117-
} else {
118-
$winner = $W_VENDORS;
119-
}
110+
$vendorid = $id;
111+
$vendors{$vendorid}[$W_PCIDEVS] = $descr;
112+
} elsif ($rv == $IS_DEVICE) {
113+
$pciids{$vendorid}{$id}[$W_PCIDEVS] = $descr;
114+
}
115+
}
116+
close(PCIDEVS);
117+
118+
foreach my $vid (keys(%vendors)) {
119+
if (!defined $vendors{$vid}[$W_VENDORS]
120+
&& defined $vendors{$vid}[$W_PCIDEVS]) {
121+
$vendors{$vid}[$W_FINAL] = $vendors{$vid}[$W_PCIDEVS];
122+
} elsif (defined $vendors{$vid}[$W_VENDORS]
123+
&& !defined $vendors{$vid}[$W_PCIDEVS]) {
124+
$vendors{$vid}[$W_FINAL] = $vendors{$vid}[$W_VENDORS];
125+
} elsif (!$opts{l}) {
126+
$vendors{$vid}[$W_FINAL] = $vendors{$vid}[$W_VENDORS];
127+
} else {
128+
if (length($vendors{$vid}[$W_VENDORS]) >
129+
length($vendors{$vid}[$W_PCIDEVS])) {
130+
$vendors{$vid}[$W_FINAL] = $vendors{$vid}[$W_VENDORS];
120131
} else {
121-
$winner = $W_VENDORS;
132+
$vendors{$vid}[$W_FINAL] = $vendors{$vid}[$W_PCIDEVS];
122133
}
123-
$cur_vendor = $id;
124-
if (not $opts{q} and $winner != $W_NOCONTEST) {
125-
$existing = $vendors{$id}->[$V_DESCR];
126-
print STDERR "$PROGNAME: ",
127-
$winner == $W_VENDORS ? "Boemler" : "Hart",
128-
" vendor wins: $id\t$existing\n";
129-
}
130-
} elsif ($rv == $IS_DEVICE) {
131-
if (not exists(${$vendors{$cur_vendor}->[$V_DEVSL]}{$id})) {
132-
${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} = $descr;
133-
$winner = $W_NOCONTEST;
134-
} elsif ($opts{l}) {
135-
$existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
136-
if (length($existing) < length($descr)) {
137-
${$vendors{$cur_vendor}->[$V_DEVSL]}{$id} =
138-
$descr;
139-
$winner = $W_PCIDEVS;
134+
}
135+
136+
foreach my $pciid (keys(%{$pciids{$vid}})) {
137+
if (!defined $pciids{$vid}{$pciid}[$W_VENDORS]
138+
&& defined $pciids{$vid}{$pciid}[$W_PCIDEVS]) {
139+
$pciids{$vid}{$pciid}[$W_FINAL] =
140+
$pciids{$vid}{$pciid}[$W_PCIDEVS];
141+
} elsif (defined $pciids{$vid}{$pciid}[$W_VENDORS]
142+
&& !defined $pciids{$vid}{$pciid}[$W_PCIDEVS]) {
143+
$pciids{$vid}{$pciid}[$W_FINAL] =
144+
$pciids{$vid}{$pciid}[$W_VENDORS];
145+
} elsif (!$opts{l}) {
146+
$pciids{$vid}{$pciid}[$W_FINAL] =
147+
$pciids{$vid}{$pciid}[$W_VENDORS];
148+
} else {
149+
if (length($pciids{$vid}{$pciid}[$W_VENDORS]) >
150+
length($pciids{$vid}{$pciid}[$W_PCIDEVS])) {
151+
$pciids{$vid}{$pciid}[$W_FINAL] =
152+
$pciids{$vid}{$pciid}[$W_VENDORS];
140153
} else {
141-
$winner = $W_VENDORS;
154+
$pciids{$vid}{$pciid}[$W_FINAL] =
155+
$pciids{$vid}{$pciid}[$W_PCIDEVS];
142156
}
143-
} else {
144-
$winner = $W_VENDORS;
145-
}
146-
if (not $opts{q} and $winner != $W_NOCONTEST) {
147-
$existing = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
148-
print STDERR "$PROGNAME: ",
149-
$winner == $W_VENDORS ? "Boemler" : "Hart",
150-
" device wins: $id\t$existing\n";
151157
}
152158
}
159+
153160
}
154-
close(PCIDEVS);
155161

156162
$optlused = $opts{l} ? "with" : "without";
157163
print <<HEADER_END;
@@ -160,50 +166,62 @@
160166
; Automatically generated by src/tools/tools/pciid/mk_pci_vendors.pl
161167
; ($optlused the -l option), using the following source lists:
162168
;
163-
; http://www.pcidatabase.com/reports.php?type=tab-delimeted
169+
; http://www.pcidatabase.com/reports.php?type=csv
164170
; http://members.datafast.net.au/dft0802/downloads/pcidevs.txt
165171
;
166172
; Manual edits on this file will be lost!
167173
;
168174
HEADER_END
169175

170-
foreach $cur_vendor (sort keys %vendors) {
171-
$id = $cur_vendor;
172-
$descr = $vendors{$id}->[$V_DESCR];
173-
print "$id\t$descr\n";
174-
foreach $id (sort keys %{$vendors{$cur_vendor}->[$V_DEVSL]}) {
175-
$descr = ${$vendors{$cur_vendor}->[$V_DEVSL]}{$id};
176-
print "\t$id\t$descr\n";
176+
foreach my $vid (sort keys %vendors) {
177+
$descr = $vendors{$vid}[0];
178+
print "$vid\t$descr\n";
179+
foreach $pciid (sort keys %{$pciids{$vid}}) {
180+
$descr = $pciids{$vid}{$pciid}[0];
181+
print "\t$pciid\t$descr\n";
177182
}
178183
}
179184
exit 0;
180185

181186

182-
# Parse a line from the Boemler file and place the ID and description
183-
# in the scalars referenced by $id_ref and $descr_ref.
187+
# Parse a line from the Boemler file and place the vendor id, pciid,
188+
# vendor description and description in the scalars.
184189
#
185-
# On success, returns $IS_VENDOR if the line represents a vendor entity
186-
# or $IS_DEVICE if the line represents a device entity.
190+
# Returns 0 if there is a problem.
187191
#
188-
# Returns 0 on failure.
189-
#
190-
sub vendors_parse($\$\$)
192+
sub vendors_parse($\$\$\$\$)
191193
{
192-
my ($line, $id_ref, $descr_ref) = @_;
194+
my ($line, $vendorid_ref, $pciid_ref, $vendor_ref, $descr_ref) = @_;
193195

194-
if ($line =~ /^([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
195-
($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
196-
return $IS_VENDOR;
197-
} elsif ($line =~ /^\t([A-Fa-f0-9]{4})\t([^\t].+?)\s*$/) {
198-
($$id_ref, $$descr_ref) = (uc($1), clean_descr($2));
199-
return $IS_DEVICE;
200-
} elsif (not $opts{q} and
201-
$line !~ /^\s*$/ and $line !~ /^;/) {
202-
chomp($line);
203-
print STDERR "$PROGNAME: ignored Boemler: $line\n";
196+
my @a = split(/","/, $line);
197+
$a[0] =~ s/0x//;
198+
$a[1] =~ s/0x//;
199+
200+
$a[0] =~ s/^"//;
201+
$a[4] =~ s/"$//;
202+
203+
$a[0] = uc($a[0]);
204+
$a[1] = uc($a[1]);
205+
206+
return 0 if (length($a[0]) != 4 || length($a[1]) != 4);
207+
208+
if ($a[4] eq "") {
209+
if ($a[3] ne "") {
210+
$a[4] = $a[3];
211+
$a[3] = "";
212+
} else {
213+
$a[4] = "?";
214+
}
204215
}
205216

206-
return 0;
217+
$$vendorid_ref = $a[0];
218+
$$pciid_ref = $a[1];
219+
$$vendor_ref = $a[2];
220+
$$descr_ref = clean_descr($a[4]);
221+
if ($a[3] =~ /[a-zA-Z0-0]/) {
222+
$$descr_ref .= clean_descr(" ($a[3])");
223+
}
224+
return 1;
207225
}
208226

209227
# Parse a line from the Hart file and place the ID and description
@@ -237,5 +255,7 @@ ($)
237255
{
238256
my ($descr) = @_;
239257

258+
$descr =~ s/[^[:print:]]//g;
259+
240260
return $descr;
241261
}

0 commit comments

Comments
 (0)