1 | # Clean PCI header script
|
---|
2 | #
|
---|
3 | # Copyright 2006, Haiku.
|
---|
4 | # Distributed under the terms of the MIT License.
|
---|
5 | #
|
---|
6 | # Authors:
|
---|
7 | # John Drinkwater, john@nextraweb.com
|
---|
8 | #
|
---|
9 | # Use with http://pciids.sourceforge.net/pci.ids
|
---|
10 | # run as: awk -f pci-clean pci.ids > pcihdr.h
|
---|
11 |
|
---|
12 | BEGIN {
|
---|
13 | FS = " "
|
---|
14 | print "#if 0"
|
---|
15 | print "#\tPCIHDR.H: PCI Vendors, Devices, and Class Type information\n#"
|
---|
16 | print "#\tGenerated by pci-clean, sourced from the web at the following URL:\n#\thttp://pciids.sourceforge.net/pci.ids\n#"
|
---|
17 | print "#\tHeader created on " strftime( "%A, %d %b %Y %H:%M:%S %Z", systime() )
|
---|
18 | print "#endif"
|
---|
19 |
|
---|
20 | print "typedef struct _PCI_DEVTABLE\n{\n\tunsigned short VenId ;\n\tunsigned short DevId ;\n\tchar *\tChipDesc ;\n} PCI_DEVTABLE, *PPCI_DEVTABLE ;\n"
|
---|
21 | print "PCI_DEVTABLE\tPciDevTable [] =\n{"
|
---|
22 | }
|
---|
23 |
|
---|
24 | # matches vendor - starts with an id as first thing on the line
|
---|
25 | /^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
|
---|
26 | if ( length(vendor) > 0 ) vendor = vendor ",\n"
|
---|
27 | vend = substr($0, 7)
|
---|
28 | gsub( /\"/, "\\\"", vend )
|
---|
29 | vendor = vendor "\t{ 0x" $1 ", \"" vend "\" }"
|
---|
30 | # store vendor ID for possible devices afterwards
|
---|
31 | currentVendor = $1
|
---|
32 | }
|
---|
33 |
|
---|
34 | # matches device
|
---|
35 | /^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
|
---|
36 |
|
---|
37 | if ( devices++ > 0 ) { a = "," } else { a = "" }
|
---|
38 | device = substr($0, 8)
|
---|
39 | gsub( /\"/, "\\\"", device )
|
---|
40 | print "\t" a "{ 0x" currentVendor ", 0x" $1 ", \"" device "\" }"
|
---|
41 | }
|
---|
42 |
|
---|
43 | # matches subvendor device
|
---|
44 | /^\t\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
|
---|
45 |
|
---|
46 | if ( devices++ > 0 ) { a = "," } else { a = "" }
|
---|
47 | device = substr($0, 14)
|
---|
48 | gsub( /\"/, "\\\"", device )
|
---|
49 | print "\t" a "{ 0x" $1 ", 0x" $2 ", \"" device "\" }"
|
---|
50 | }
|
---|
51 |
|
---|
52 | # match device class - store data for later
|
---|
53 | /^C [[:xdigit:]][[:xdigit:]] / {
|
---|
54 | class = $2
|
---|
55 | classdes = substr($0, 7)
|
---|
56 | gsub( /\"/, "\\\"", classdes )
|
---|
57 |
|
---|
58 | }
|
---|
59 |
|
---|
60 | # match subclass, use device class data captured earlier, and output
|
---|
61 | /^\t[[:xdigit:]][[:xdigit:]] / {
|
---|
62 | if ( length(classes) > 0 ) classes = classes ",\n"
|
---|
63 | if ( currentclass != class) { classes = classes "\n"; currentclass = class }
|
---|
64 | subclassdes = substr($0, 6)
|
---|
65 | gsub( /\"/, "\\\"", subclassdes )
|
---|
66 |
|
---|
67 | classes = classes "\t{ 0x" class ", 0x" $1 ", 0x00, \"" classdes "\", \"" subclassdes "\", \"\" }"
|
---|
68 | subclass = $1
|
---|
69 | }
|
---|
70 |
|
---|
71 | # match programming interface
|
---|
72 | /^\t\t[[:xdigit:]][[:xdigit:]] / {
|
---|
73 | if ( $1 != "00" ) {
|
---|
74 | if ( length(classes) > 0 ) classes = classes ",\n"
|
---|
75 | progif = substr($0, 7)
|
---|
76 | gsub( /\"/, "\\\"", progif )
|
---|
77 | classes = classes "\t{ 0x" class ", 0x" subclass ", 0x" $1 ", \"" classdes "\", \"" subclassdes "\", \"" progif "\" }"
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | # We've processed the file, now output.
|
---|
82 | END {
|
---|
83 |
|
---|
84 | print "} ;\n\n// Use this value for loop control during searching:\n#define PCI_DEVTABLE_LEN (sizeof(PciDevTable)/sizeof(PCI_DEVTABLE))\n";
|
---|
85 |
|
---|
86 | if ( length( vendor ) > 0 ) {
|
---|
87 | print "\ntypedef struct _PCI_VENTABLE\n{\n\tunsigned short\tVenId ;\n\tchar *\tVenFull ;\n} PCI_VENTABLE, *PPCI_VENTABLE ;\n"
|
---|
88 | print "PCI_VENTABLE\tPciVenTable [] =\n{"
|
---|
89 | print vendor
|
---|
90 | print "};\n\n// Use this value for loop control during searching:\n#define\tPCI_VENTABLE_LEN\t(sizeof(PciVenTable)/sizeof(PCI_VENTABLE))\n"
|
---|
91 | }
|
---|
92 |
|
---|
93 | if ( length( classes) > 0 ) {
|
---|
94 | print "typedef struct _PCI_CLASSCODETABLE\n{\n\tunsigned char BaseClass ;\n\tunsigned char SubClass ;\n\tunsigned char ProgIf ;\n\tchar *\t\tBaseDesc ;\n\tchar *\t\tSubDesc ;\n\tchar *\t\tProgDesc ;\n} PCI_CLASSCODETABLE, *PPCI_CLASSCODETABLE ;\n"
|
---|
95 | print "PCI_CLASSCODETABLE PciClassCodeTable [] =\n{"
|
---|
96 | print classes
|
---|
97 | print "} ;\n\n// Use this value for loop control during searching:\n#define PCI_CLASSCODETABLE_LEN (sizeof(PciClassCodeTable)/sizeof(PCI_CLASSCODETABLE))\n"
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 | print "char *\tPciCommandFlags [] =\n{\n\t\"I/O Access\",\n\t\"Memory Access\",\n\t\"Bus Mastering\",\n\t\"Special Cycles\",\n\t\"Memory Write & Invalidate\",\n\t\"Palette Snoop\",\n\t\"Parity Errors\",\n\t\"Wait Cycles\",\n\t\"System Errors\",\n\t\"Fast Back-To-Back\",\n\t\"Reserved 10\",\n\t\"Reserved 11\",\n\t\"Reserved 12\",\n\t\"Reserved 13\",\n\t\"Reserved 14\",\n\t\"Reserved 15\"\n} ;\n"
|
---|
102 | print "// Use this value for loop control during searching:\n#define PCI_COMMANDFLAGS_LEN (sizeof(PciCommandFlags)/sizeof(char *))\n"
|
---|
103 | print "char *\tPciStatusFlags [] =\n{\n\t\"Reserved 0\",\n\t\"Reserved 1\",\n\t\"Reserved 2\",\n\t\"Reserved 3\",\n\t\"Reserved 4\",\n\t\"66 MHz Capable\",\n\t\"User-Defined Features\",\n\t\"Fast Back-To-Back\",\n\t\"Data Parity Reported\",\n\t\"\",\n\t\"\",\n\t\"Signalled Target Abort\",\n\t\"Received Target Abort\",\n\t\"Received Master Abort\",\n\t\"Signalled System Error\",\n\t\"Detected Parity Error\"\n} ;\n"
|
---|
104 | print "// Use this value for loop control during searching:\n#define PCI_STATUSFLAGS_LEN (sizeof(PciStatusFlags)/sizeof(char *))\n"
|
---|
105 | print "char *\tPciDevSelFlags [] =\n{\n\t\"Fast Devsel Speed\",\n\t\"Medium Devsel Speed\",\n\t\"Slow Devsel Speed\",\n\t\"Reserved 9&10\"\n} ;\n"
|
---|
106 | print "// Use this value for loop control during searching:\n#define PCI_DEVSELFLAGS_LEN (sizeof(PciDevSelFlags)/sizeof(char *))\n\n"
|
---|
107 |
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|