<bus/pci/pcireg.h>: Add a definition for XHCI programming interface.
[dragonfly.git] / sys / bus / u4b / devlist2h.awk
1 #! /usr/bin/awk -f
2 #       $DragonFly: src/sys/bus/pci/devlist2h.awk,v 1.2 2004/02/19 20:47:56 joerg Exp $
3 #       $NetBSD: devlist2h.awk,v 1.7 2003/12/05 04:33:27 grant Exp $
4 #
5 # Copyright (c) 1995, 1996 Christopher G. Demetriou
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 #    notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the distribution.
16 # 3. All advertising materials mentioning features or use of this software
17 #    must display the following acknowledgement:
18 #      This product includes software developed by Christopher G. Demetriou.
19 # 4. The name of the author may not be used to endorse or promote products
20 #    derived from this software without specific prior written permission
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #
33 BEGIN {
34         nproducts = nvendors = blanklines = 0
35         dfile="pcidevs_data.h"
36         hfile="pcidevs.h"
37 }
38 NR == 1 {
39         printf("/*\n") > dfile
40         printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
41             > dfile
42         printf(" */\n") > dfile
43
44         printf("/*\n") > hfile
45         printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
46             > hfile
47         printf(" */\n") > hfile
48
49         next
50 }
51 NF > 0 && $1 == "vendor" {
52         nvendors++
53
54         vendorindex[$2] = nvendors;             # record index for this name, for later.
55         vendors[nvendors, 1] = $2;              # name
56         vendors[nvendors, 2] = $3;              # id
57         printf("#define\tPCI_VENDOR_%s\t%s\t", vendors[nvendors, 1],
58             vendors[nvendors, 2]) > hfile
59
60         i = 3; f = 4;
61
62         # comments
63         ocomment = oparen = 0
64         if (f <= NF) {
65                 printf("\t/* ") > hfile
66                 ocomment = 1;
67         }
68         while (f <= NF) {
69                 if ($f == "#") {
70                         printf("(") > hfile
71                         oparen = 1
72                         f++
73                         continue
74                 }
75                 if (oparen) {
76                         printf("%s", $f) > hfile
77                         if (f < NF)
78                                 printf(" ") > hfile
79                         f++
80                         continue
81                 }
82                 vendors[nvendors, i] = $f
83                 printf("%s", vendors[nvendors, i]) > hfile
84                 if (f < NF)
85                         printf(" ") > hfile
86                 i++; f++;
87         }
88         if (oparen)
89                 printf(")") > hfile
90         if (ocomment)
91                 printf(" */") > hfile
92         printf("\n") > hfile
93
94         next
95 }
96 NF > 0 && $1 == "product" {
97         nproducts++
98
99         products[nproducts, 1] = $2;            # vendor name
100         products[nproducts, 2] = $3;            # product id
101         products[nproducts, 3] = $4;            # id
102         printf("#define\tPCI_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
103             products[nproducts, 2], products[nproducts, 3]) > hfile
104
105         i=4; f = 5;
106
107         # comments
108         ocomment = oparen = 0
109         if (f <= NF) {
110                 printf("\t/* ") > hfile
111                 ocomment = 1;
112         }
113         while (f <= NF) {
114                 if ($f == "#") {
115                         printf("(") > hfile
116                         oparen = 1
117                         f++
118                         continue
119                 }
120                 if (oparen) {
121                         printf("%s", $f) > hfile
122                         if (f < NF)
123                                 printf(" ") > hfile
124                         f++
125                         continue
126                 }
127                 products[nproducts, i] = $f
128                 printf("%s", products[nproducts, i]) > hfile
129                 if (f < NF)
130                         printf(" ") > hfile
131                 i++; f++;
132         }
133         if (oparen)
134                 printf(")") > hfile
135         if (ocomment)
136                 printf(" */") > hfile
137         printf("\n") > hfile
138
139         next
140 }
141 {
142         if ($0 == "")
143                 blanklines++
144         print $0 > hfile
145         if (blanklines < 2)
146                 print $0 > dfile
147 }
148 END {
149         # print out the match tables
150
151         printf("\n") > dfile
152
153         printf("const struct pci_knowndev pci_knowndevs[] = {\n") > dfile
154         for (i = 1; i <= nproducts; i++) {
155                 printf("\t{\n") > dfile
156                 printf("\t    PCI_VENDOR_%s, PCI_PRODUCT_%s_%s,\n",
157                     products[i, 1], products[i, 1], products[i, 2]) \
158                     > dfile
159                 printf("\t    ") > dfile
160                 printf("0") > dfile
161                 printf(",\n") > dfile
162
163                 vendi = vendorindex[products[i, 1]];
164                 printf("\t    \"") > dfile
165                 j = 3;
166                 needspace = 0;
167                 while ((vendi, j) in vendors) {
168                         if (needspace)
169                                 printf(" ") > dfile
170                         printf("%s", vendors[vendi, j]) > dfile
171                         needspace = 1
172                         j++
173                 }
174                 printf("\",\n") > dfile
175
176                 printf("\t    \"") > dfile
177                 j = 4;
178                 needspace = 0;
179                 while ((i, j) in products) {
180                         if (needspace)
181                                 printf(" ") > dfile
182                         printf("%s", products[i, j]) > dfile
183                         needspace = 1
184                         j++
185                 }
186                 printf("\",\n") > dfile
187                 printf("\t},\n") > dfile
188         }
189         for (i = 1; i <= nvendors; i++) {
190                 printf("\t{\n") > dfile
191                 printf("\t    PCI_VENDOR_%s, 0,\n", vendors[i, 1]) \
192                     > dfile
193                 printf("\t    PCI_KNOWNDEV_NOPROD,\n") \
194                     > dfile
195                 printf("\t    \"") > dfile
196                 j = 3;
197                 needspace = 0;
198                 while ((i, j) in vendors) {
199                         if (needspace)
200                                 printf(" ") > dfile
201                         printf("%s", vendors[i, j]) > dfile
202                         needspace = 1
203                         j++
204                 }
205                 printf("\",\n") > dfile
206                 printf("\t    NULL,\n") > dfile
207                 printf("\t},\n") > dfile
208         }
209         printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
210         printf("};\n") > dfile
211         close(dfile)
212         close(hfile)
213 }