|
30 | 30 | # Generate src/share/misc/pci_vendors from the Hart and Boemler lists, |
31 | 31 | # currently available at: |
32 | 32 | # |
33 | | -# Boemler: http://www.pcidatabase.com/reports.php?type=tab-delimeted |
| 33 | +# Boemler: http://www.pcidatabase.com/reports.php?type=csv |
34 | 34 | # Hart: http://members.datafast.net.au/dft0802/downloads/pcidevs.txt |
35 | 35 | # |
36 | 36 | # -l Where an entry is found in both input lists, use the entry with |
|
42 | 42 | # |
43 | 43 | use strict; |
44 | 44 | use Getopt::Std; |
| 45 | +use Data::Dumper; |
45 | 46 |
|
46 | 47 | my $PROGNAME = 'mk_pci_vendors'; |
47 | 48 | my $VENDORS_FILE = 'vendors.txt'; |
48 | 49 | my $PCIDEVS_FILE = 'pcidevs.txt'; |
49 | 50 |
|
50 | | -my $cur_vendor; |
| 51 | +my ($cur_vendor, $vendorid, $pciid, $vendor); |
51 | 52 | my %opts; |
52 | | -my %vendors; |
| 53 | +my %pciids = (); |
| 54 | +my %vendors = (); |
53 | 55 | my ($descr, $existing, $id, $line, $rv, $winner, $optlused); |
54 | 56 |
|
55 | 57 | my $IS_VENDOR = 1; |
56 | 58 | my $IS_DEVICE = 2; |
57 | 59 | my $V_DESCR = 0; |
58 | 60 | my $V_DEVSL = 1; |
59 | | -my $W_NOCONTEST = 0; |
| 61 | +my $W_FINAL = 0; |
60 | 62 | my $W_VENDORS = 1; |
61 | 63 | my $W_PCIDEVS = 2; |
62 | 64 |
|
63 | 65 | sub clean_descr($); |
64 | | -sub vendors_parse($\$\$); |
| 66 | +sub vendors_parse($\$\$\$\$); |
65 | 67 | sub pcidevs_parse($\$\$); |
66 | 68 |
|
67 | 69 | if (not getopts('lp:qv:', \%opts) or @ARGV > 0) { |
|
87 | 89 | die "$PROGNAME: $opts{v}: $!\n"; |
88 | 90 | while ($line = <VENDORS>) { |
89 | 91 | 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"; |
94 | 97 | } |
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; |
99 | 100 | } |
100 | 101 | } |
101 | 102 | close(VENDORS); |
|
106 | 107 | chomp($line); |
107 | 108 | $rv = pcidevs_parse($line, $id, $descr); |
108 | 109 | 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]; |
120 | 131 | } else { |
121 | | - $winner = $W_VENDORS; |
| 132 | + $vendors{$vid}[$W_FINAL] = $vendors{$vid}[$W_PCIDEVS]; |
122 | 133 | } |
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]; |
140 | 153 | } else { |
141 | | - $winner = $W_VENDORS; |
| 154 | + $pciids{$vid}{$pciid}[$W_FINAL] = |
| 155 | + $pciids{$vid}{$pciid}[$W_PCIDEVS]; |
142 | 156 | } |
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"; |
151 | 157 | } |
152 | 158 | } |
| 159 | + |
153 | 160 | } |
154 | | -close(PCIDEVS); |
155 | 161 |
|
156 | 162 | $optlused = $opts{l} ? "with" : "without"; |
157 | 163 | print <<HEADER_END; |
|
160 | 166 | ; Automatically generated by src/tools/tools/pciid/mk_pci_vendors.pl |
161 | 167 | ; ($optlused the -l option), using the following source lists: |
162 | 168 | ; |
163 | | -; http://www.pcidatabase.com/reports.php?type=tab-delimeted |
| 169 | +; http://www.pcidatabase.com/reports.php?type=csv |
164 | 170 | ; http://members.datafast.net.au/dft0802/downloads/pcidevs.txt |
165 | 171 | ; |
166 | 172 | ; Manual edits on this file will be lost! |
167 | 173 | ; |
168 | 174 | HEADER_END |
169 | 175 |
|
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"; |
177 | 182 | } |
178 | 183 | } |
179 | 184 | exit 0; |
180 | 185 |
|
181 | 186 |
|
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. |
184 | 189 | # |
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. |
187 | 191 | # |
188 | | -# Returns 0 on failure. |
189 | | -# |
190 | | -sub vendors_parse($\$\$) |
| 192 | +sub vendors_parse($\$\$\$\$) |
191 | 193 | { |
192 | | - my ($line, $id_ref, $descr_ref) = @_; |
| 194 | + my ($line, $vendorid_ref, $pciid_ref, $vendor_ref, $descr_ref) = @_; |
193 | 195 |
|
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 | + } |
204 | 215 | } |
205 | 216 |
|
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; |
207 | 225 | } |
208 | 226 |
|
209 | 227 | # Parse a line from the Hart file and place the ID and description |
|
237 | 255 | { |
238 | 256 | my ($descr) = @_; |
239 | 257 |
|
| 258 | + $descr =~ s/[^[:print:]]//g; |
| 259 | + |
240 | 260 | return $descr; |
241 | 261 | } |
0 commit comments