First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / scanpci / pciid2c.pl
blobb8947ed05f3d81faa36425335e7a76db4f336281
1 #!/usr/bin/perl
3 # $XdotOrg$
5 # Automatically generate the data structures for PCI vendor/device lists
6 # from the pci.ids file.
8 # It should be run as:
10 # perl pciid2c.pl ../common/xf86PciInfo.h < pci.ids > xf86PciStdIds.h
13 # Copyright © 2002 by The XFree86 Project, Inc.
15 # Permission is hereby granted, free of charge, to any person obtaining a
16 # copy of this software and associated documentation files (the "Software"),
17 # to deal in the Software without restriction, including without limitation
18 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 # and/or sell copies of the Software, and to permit persons to whom the
20 # Software is furnished to do so, subject to the following conditions:
22 # The above copyright notice and this permission notice shall be included in
23 # all copies or substantial portions of the Software.
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 # THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
29 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31 # OTHER DEALINGS IN THE SOFTWARE.
33 # Except as contained in this notice, the name of the copyright holder(s)
34 # and author(s) shall not be used in advertising or otherwise to promote
35 # the sale, use or other dealings in this Software without prior written
36 # authorization from the copyright holder(s) and author(s).
40 # Author: David Dawes
42 # $XFree86: xc/programs/Xserver/hw/xfree86/scanpci/pciid2c.pl,v 1.3 2003/08/24 17:37:10 dawes Exp $
45 if (@ARGV[0]) {
46 $infofile = @ARGV[0];
50 # The basic pci.ids format is:
51 # - Vendor lines start with four (lower case) hex digits
52 # - Device lines start with one tab followed by four hex digits
53 # - Subsystem lines start with two tabs followed by two sets of four
54 # hex digits.
55 # - Class overrides for devices start with two tabs followed by a "C",
56 # followed by four hex digits with the class/subclass value.
57 # - Class lines start with a "C".
58 # - Comment lines start with a '#'.
59 # - Blank lines are ignored.
61 # We allow for extra lines to be appended to modify existing entries or
62 # add new ones. To add/modify Device entries without modifying the
63 # Vendor name, a special vendor name of '"' is used (mnemonic: "ditto").
64 # Similarly for adding subsystem names without modifying (or adding)
65 # a corresponding device entry. To rename an existing entry, simply
66 # provide the new name. To remove an existing entry, use the special
67 # name '-'.
70 while (<STDIN>) {
71 # Process data lines
72 if (/^([0-9a-f]{4})\s+(.*)/) {
73 $vendor = $1;
74 if ($2 eq '-') {
75 delete($vendors{$vendor});
76 } elsif ($2 ne '"') {
77 $vendors{$vendor} = $2;
78 # Remove " characters
79 $vendors{$vendor} =~ s/"//g;
80 # Remove multiple "?" sequences to avoid trigraphs
81 $vendors{$vendor} =~ s/\?+/\?/g;
83 } elsif (/^\t([0-9a-f]{4})\s+(.*)/) {
84 $device = $1;
85 if ($2 eq '-') {
86 delete($devices{$vendor}{$device});
87 } elsif ($2 ne '"') {
88 $devices{$vendor}{$device} = $2;
89 # Remove " characters
90 $devices{$vendor}{$device} =~ s/"//g;
91 # Remove multiple "?" sequences to avoid trigraphs
92 $devices{$vendor}{$device} =~ s/\?+/\?/g;
94 } elsif (/^\t\t([0-9a-f]{4})\s+([0-9a-f]{4})\s+(.*)/) {
95 $v = $1;
96 $s = $2;
97 if ($3 eq '-') {
98 delete($subsystems{$v}{$s});
99 delete($devsubsystems{$vendor}{$device}{"$v-$s"});
100 } elsif ($3 ne '"') {
101 if ($subsystems{$v}{$s}) {
102 #print STDERR "Duplicate subsytem: $v, $s, \"$subsystems{$v}{$s}\", \"$3\"\n";
104 $subsystems{$v}{$s} = $3;
105 # Remove " characters
106 $subsystems{$v}{$s} =~ s/"//g;
107 # Remove multiple "?" sequences to avoid trigraphs
108 $subsystems{$v}{$s} =~ s/\?+/\?/g;
109 $devsubsystems{$vendor}{$device}{"$v-$s"} = $subsystems{$v}{$s};
111 } elsif (/^\t\tC\s+([0-9a-f]{4})/) {
112 $classes{$vendor}{$device} = $1;
114 # Ignore all other lines.
117 # Find which vendors are "video" vendors.
118 if ($infofile) {
119 open(INFO, "<$infofile") || die "Can't open $infofile";
120 while (<INFO>) {
121 if (/^#define\s+PCI_VENDOR_.*0x([0-9a-fA-F]{4})/) {
122 $vendor = $1;
123 $vendor =~ tr/A-F/a-f/;
124 $video{$vendor} = 1;
130 # This layout is quite different from that used in the old xf86PciInfo.h
131 # file. One main difference is that the list is initialised at runtime.
132 # It's currently a flat list. This could be improved.
135 # Print out header information.
137 $proj = "XdotOrg";
138 print "
140 * THIS FILE IS AUTOMATICALLY GENERATED -- DO NOT EDIT
142 * It is generated by pciid2c.pl using data from the following files:
144 * ../etc/pci.ids
145 * ../etc/extrapci.ids
146 * ../common/xf86PciInfo.h
150 * Copyright © 2002 by the XFree86 Project, Inc.
152 * The pci.ids file and the data it contains are from the Linux PCI ID's
153 * Project (http://pciids.sf.net/). It is maintained by Martin Mares
154 * <mj\@ucw.cz> and other volunteers. The pci.ids file is licensed under
155 * the BSD 3-clause or GPL version 2 or later licenses.
158 #include \"xf86PciInfo.h\"
159 #ifndef NULL
160 #define NULL (void *)0
161 #endif
165 # The following #ifdefs are used:
166 # - INIT_SUBSYS_INFO -- initialise subsystem data
167 # - INIT_VENDOR_SUBSYS_INFO -- initialise a vendor<->subsystem table.
168 # - VENDOR_INCLUDE_NONVIDEO -- include data for non-video vendors.
170 # Define static variables with all of the strings.
172 foreach $vendor (sort keys %vendors) {
173 if ($infofile && !$video{$vendor}) {
174 print "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
176 print "static const char pci_vendor_${vendor}[] = \"$vendors{$vendor}\";\n";
177 foreach $device (sort keys %{$devices{$vendor}}) {
178 print "static const char pci_device_${vendor}_${device}[] = " .
179 "\"$devices{$vendor}{$device}\";\n";
180 foreach $subsys (sort keys %{$devsubsystems{$vendor}{$device}}) {
181 $s = $subsys;
182 ($v) = split /-/, $s;
183 if ($infofile && !$video{$vendor} && $video{$v}) {
184 print "#endif\n";
186 $s =~ s/-/_/;
187 print "#ifdef INIT_SUBSYS_INFO\n";
188 print "static const char pci_subsys_${vendor}_${device}_${s}[] = " .
189 "\"$devsubsystems{$vendor}{$device}{$subsys}\";\n";
190 print "#endif\n";
191 if ($infofile && !$video{$vendor} && $video{$v}) {
192 print "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
196 if ($infofile && !$video{$vendor}) {
197 print "#endif\n";
202 # Pre-initialise the table structures (from the inner to the outer).
204 # First, the subsys structures.
206 print "#ifdef INIT_SUBSYS_INFO\n";
207 foreach $vendor (sort keys %vendors) {
208 if ($infofile && !$video{$vendor}) {
209 $pre = "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
210 } else {
211 undef($pre);
212 undef($post);
214 foreach $device (sort keys %{$devices{$vendor}}) {
215 foreach $subsys (sort keys %{$devsubsystems{$vendor}{$device}}) {
216 $s = $subsys;
217 $s =~ tr/-/_/;
218 ($vid, $sid) = split /_/, $s;
219 if ($pre) {
220 print $pre;
221 undef($pre);
222 $post = "#endif\n";
224 if ($infofile && !$video{$vendor} && $video{$vid}) {
225 print "#endif\n";
227 print "static const pciSubsystemInfo " .
228 "pci_ss_info_${vendor}_${device}_$s =\n";
229 print "\t{0x$vid, 0x$sid, pci_subsys_${vendor}_${device}_$s, 0};\n";
230 print "#undef pci_ss_info_$s\n";
231 print "#define pci_ss_info_$s pci_ss_info_${vendor}_${device}_$s\n";
232 if ($infofile && !$video{$vendor} && $video{$vid}) {
233 print "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
237 if ($post) {
238 print $post;
239 undef($post);
243 # Next, the list of per vendor+device subsystem arrays
245 foreach $vendor (sort keys %vendors) {
246 if ($infofile && !$video{$vendor}) {
247 $pre = "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
248 } else {
249 undef($pre);
250 undef($post);
252 foreach $device (sort keys %{$devices{$vendor}}) {
253 if (scalar(keys %{$devsubsystems{$vendor}{$device}}) > 0) {
254 if ($pre) {
255 print $pre;
256 undef($pre);
257 $post = "#endif\n";
259 print "static const pciSubsystemInfo *pci_ss_list_${vendor}_${device}[] = {\n";
260 foreach $sub (sort keys %{$devsubsystems{$vendor}{$device}}) {
261 $sub =~ s/-/_/;
262 print "\t&pci_ss_info_${vendor}_${device}_${sub},\n";
264 print "\tNULL\n};\n";
265 } else {
266 print "#define pci_ss_list_${vendor}_${device} NULL\n";
269 if ($post) {
270 print $post;
271 undef($post);
275 # Next, the list of per vendor subsystem arrays
277 print "#ifdef INIT_VENDOR_SUBSYS_INFO\n";
278 foreach $vendor (sort keys %vendors) {
279 if (scalar(keys %{$subsystems{$vendor}}) > 0) {
280 if ($infofile && !$video{$vendor}) {
281 print "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
283 print "static const pciSubsystemInfo *pci_ss_list_${vendor}[] = {\n";
284 foreach $sub (sort keys %{$subsystems{$vendor}}) {
285 print "\t&pci_ss_info_${vendor}_${sub},\n";
287 print "\tNULL\n};\n";
288 if ($infofile && !$video{$vendor}) {
289 print "#endif\n";
291 } else {
292 print "#define pci_ss_list_${vendor} NULL\n";
295 print "#endif /* INIT_VENDOR_SUBSYS_INFO */\n";
296 print "#endif /* INIT_SUBSYS_INFO */\n";
298 # Next the device structures
300 foreach $vendor (sort keys %vendors) {
301 if ($infofile && !$video{$vendor}) {
302 $pre = "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
303 } else {
304 undef($pre);
305 undef($post);
307 foreach $device (sort keys %{$devices{$vendor}}) {
308 if ($pre) {
309 print $pre;
310 undef($pre);
311 $post = "#endif\n";
313 if ($classes{$vendor}{$device}) {
314 $class = "0x$classes{$vendor}{$device}";
315 } else {
316 $class = "0";
318 print "static const pciDeviceInfo " .
319 "pci_dev_info_${vendor}_${device} = {\n";
320 print "\t0x$device, pci_device_${vendor}_${device},\n";
321 print "#ifdef INIT_SUBSYS_INFO\n";
322 print "\tpci_ss_list_${vendor}_${device},\n";
323 print "#else\n";
324 print "\tNULL,\n";
325 print "#endif\n";
326 print "\t$class\n};\n";
328 if ($post) {
329 print $post;
330 undef($post);
334 # Next, the list of per vendor device arrays
336 foreach $vendor (sort keys %vendors) {
337 if (scalar(keys %{$devices{$vendor}}) > 0) {
338 if ($infofile && !$video{$vendor}) {
339 print "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
341 print "static const pciDeviceInfo *pci_dev_list_${vendor}[] = {\n";
342 foreach $device (sort keys %{$devices{$vendor}}) {
343 print "\t&pci_dev_info_${vendor}_${device},\n";
345 print "\tNULL\n};\n";
346 if ($infofile && !$video{$vendor}) {
347 print "#endif\n";
349 } else {
350 print "#define pci_dev_list_${vendor} NULL\n";
354 # Next, the main vendor list
356 print "
357 static const pciVendorInfo pciVendorInfoList[] = {
360 foreach $vendor (sort keys %vendors) {
361 if ($infofile && !$video{$vendor}) {
362 print "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
364 print "\t{0x$vendor, pci_vendor_$vendor, pci_dev_list_$vendor},\n";
365 if ($infofile && !$video{$vendor}) {
366 print "#endif\n";
369 print "\t{0x0000, NULL, NULL}\n};\n";
371 # Finally, the main vendor/subsystem list
373 print "
374 #if defined(INIT_VENDOR_SUBSYS_INFO) && defined(INIT_SUBSYS_INFO)
375 static const pciVendorSubsysInfo pciVendorSubsysInfoList[] = {
378 foreach $vendor (sort keys %vendors) {
379 if ($infofile && !$video{$vendor}) {
380 print "#ifdef VENDOR_INCLUDE_NONVIDEO\n";
382 print "\t{0x$vendor, pci_vendor_$vendor, pci_ss_list_$vendor},\n";
383 if ($infofile && !$video{$vendor}) {
384 print "#endif\n";
387 print "\t{0x0000, NULL, NULL}\n};\n";
388 print "#endif\n";