3 * The contents of this file are subject to the Mozilla Public License
4 * Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License
6 * at http://www.mozilla.org/MPL/
8 * Software distributed under the License is distributed on an "AS IS"
9 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10 * the License for the specific language governing rights and
11 * limitations under the License.
13 * The initial developer of the original code is David A. Hinds
14 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
15 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
17 * Alternatively, the contents of this file may be used under the
18 * terms of the GNU General Public License version 2 (the "GPL"), in
19 * which case the provisions of the GPL are applicable instead of the
20 * above. If you wish to allow the use of your version of this file
21 * only under the terms of the GPL and not to allow others to use
22 * your version of this file under the MPL, indicate your decision by
23 * deleting the provisions above and replace them with the notice and
24 * other provisions required by the GPL. If you do not delete the
25 * provisions above, a recipient may use your version of this file
26 * under either the MPL or the GPL.
29 #include <sys/types.h>
36 #include <pcmcia/cs_types.h>
37 #include <pcmcia/cs.h>
38 #include <pcmcia/cistpl.h>
42 /* If bison: generate nicer error messages */
43 #define YYERROR_VERBOSE 1
45 extern int current_lineno;
47 void yyerror(const char *msg, ...);
48 static tuple_info_t *new_tuple(u_char type, cisparse_t *parse);
52 %token STRING NUMBER FLOAT VOLTAGE CURRENT SIZE
53 %token VERS_1 MANFID FUNCID CONFIG CFTABLE MFC CHECKSUM
54 %token POST ROM BASE LAST_INDEX CJEDEC AJEDEC
55 %token DEV_INFO ATTR_DEV_INFO NO_INFO
56 %token TIME TIMING WAIT READY RESERVED
57 %token VNOM VMIN VMAX ISTATIC IAVG IPEAK IDOWN
58 %token VCC VPP1 VPP2 IO MEM
59 %token DEFAULT BVD WP RDYBSY MWAIT AUDIO READONLY PWRDOWN
60 %token BIT8 BIT16 LINES RANGE
61 %token IRQ_NO MASK LEVEL PULSE SHARED
73 %type <num> NUMBER SIZE VOLTAGE CURRENT TIME
75 %type <pwr> pwr pwrlist
76 %type <parse> vers_1 manfid funcid config cftab io mem irq timing
77 %type <parse> dev_info attr_dev_info checksum cjedec ajedec
78 %type <tuple> tuple chain cis;
93 } else if ($2 == NULL) {
96 tuple_info_t *tail = $1;
97 while (tail->next != NULL) tail = tail->next;
104 mfc: MFC '{' chain '}'
106 | mfc ',' '{' chain '}'
111 { $$ = new_tuple(CISTPL_DEVICE, $1); }
113 { $$ = new_tuple(CISTPL_DEVICE_A, $1); }
115 { $$ = new_tuple(CISTPL_VERS_1, $1); }
117 { $$ = new_tuple(CISTPL_MANFID, $1); }
119 { $$ = new_tuple(CISTPL_FUNCID, $1); }
121 { $$ = new_tuple(CISTPL_CONFIG, $1); }
123 { $$ = new_tuple(CISTPL_CFTABLE_ENTRY, $1); }
129 { $$ = new_tuple(CISTPL_JEDEC_C, $1); }
131 { $$ = new_tuple(CISTPL_JEDEC_A, $1); }
135 { $$ = calloc(1, sizeof(cisparse_t)); }
136 | dev_info NUMBER TIME ',' SIZE
138 $$->device.dev[$$->device.ndev].type = $2;
139 $$->device.dev[$$->device.ndev].speed = $3;
140 $$->device.dev[$$->device.ndev].size = $5;
146 attr_dev_info: ATTR_DEV_INFO
147 { $$ = calloc(1, sizeof(cisparse_t)); }
148 | attr_dev_info NUMBER TIME ',' SIZE
150 $$->device.dev[$$->device.ndev].type = $2;
151 $$->device.dev[$$->device.ndev].speed = $3;
152 $$->device.dev[$$->device.ndev].size = $5;
155 | attr_dev_info NO_INFO
160 $$ = calloc(1, sizeof(cisparse_t));
161 $$->version_1.major = $2;
162 $2 -= floor($2+0.01);
163 while (fabs($2 - floor($2+0.5)) > 0.01) {
166 $$->version_1.minor = $2+0.01;
170 cistpl_vers_1_t *v = &$$->version_1;
173 pos = v->ofs[v->ns-1];
174 pos += strlen(v->str+pos)+1;
177 strcpy(v->str+pos, $3);
182 manfid: MANFID NUMBER ',' NUMBER
184 $$ = calloc(1, sizeof(cisparse_t));
185 $$->manfid.manf = $2;
186 $$->manfid.card = $4;
190 funcid: FUNCID NUMBER
192 $$ = calloc(1, sizeof(cisparse_t));
193 $$->funcid.func = $2;
196 { $$->funcid.sysinit |= CISTPL_SYSINIT_POST; }
198 { $$->funcid.sysinit |= CISTPL_SYSINIT_ROM; }
201 cjedec: CJEDEC NUMBER NUMBER
203 $$ = calloc(1, sizeof(cisparse_t));
204 $$->jedec.id[0].mfr = $2;
205 $$->jedec.id[0].info = $3;
208 | cjedec ',' NUMBER NUMBER
210 $$->jedec.id[$$->jedec.nid].mfr = $3;
211 $$->jedec.id[$$->jedec.nid++].info = $4;
215 ajedec: AJEDEC NUMBER NUMBER
217 $$ = calloc(1, sizeof(cisparse_t));
218 $$->jedec.id[0].mfr = $2;
219 $$->jedec.id[0].info = $3;
222 | ajedec ',' NUMBER NUMBER
224 $$->jedec.id[$$->jedec.nid].mfr = $3;
225 $$->jedec.id[$$->jedec.nid++].info = $4;
229 config: CONFIG BASE NUMBER MASK NUMBER LAST_INDEX NUMBER
231 $$ = calloc(1, sizeof(cisparse_t));
232 $$->config.base = $3;
233 $$->config.rmask[0] = $5;
234 $$->config.last_idx = $7;
240 $$.present = CISTPL_POWER_VNOM;
245 $$.present = CISTPL_POWER_VMIN;
250 $$.present = CISTPL_POWER_VMAX;
255 $$.present = CISTPL_POWER_ISTATIC;
260 $$.present = CISTPL_POWER_IAVG;
265 $$.present = CISTPL_POWER_IPEAK;
270 $$.present = CISTPL_POWER_IDOWN;
275 pwrlist: /* nothing */
281 $$.present |= 1<<($2.present);
282 $$.param[$2.present] = $2.param[0];
289 | timing RESERVED TIME
292 io: cftab IO NUMBER '-' NUMBER
294 int n = $$->cftable_entry.io.nwin;
295 $$->cftable_entry.io.win[n].base = $3;
296 $$->cftable_entry.io.win[n].len = $5-$3+1;
297 $$->cftable_entry.io.nwin++;
299 | io ',' NUMBER '-' NUMBER
301 int n = $$->cftable_entry.io.nwin;
302 $$->cftable_entry.io.win[n].base = $3;
303 $$->cftable_entry.io.win[n].len = $5-$3+1;
304 $$->cftable_entry.io.nwin++;
307 { $$->cftable_entry.io.flags |= CISTPL_IO_8BIT; }
309 { $$->cftable_entry.io.flags |= CISTPL_IO_16BIT; }
310 | io LINES '=' NUMBER ']'
311 { $$->cftable_entry.io.flags |= $4; }
315 mem: cftab MEM NUMBER '-' NUMBER '@' NUMBER
317 int n = $$->cftable_entry.mem.nwin;
318 $$->cftable_entry.mem.win[n].card_addr = $3;
319 $$->cftable_entry.mem.win[n].host_addr = $7;
320 $$->cftable_entry.mem.win[n].len = $5-$3+1;
321 $$->cftable_entry.mem.nwin++;
323 | mem ',' NUMBER '-' NUMBER '@' NUMBER
325 int n = $$->cftable_entry.mem.nwin;
326 $$->cftable_entry.mem.win[n].card_addr = $3;
327 $$->cftable_entry.mem.win[n].host_addr = $7;
328 $$->cftable_entry.mem.win[n].len = $5-$3+1;
329 $$->cftable_entry.mem.nwin++;
332 { $$->cftable_entry.io.flags |= CISTPL_IO_8BIT; }
334 { $$->cftable_entry.io.flags |= CISTPL_IO_16BIT; }
337 irq: cftab IRQ_NO NUMBER
338 { $$->cftable_entry.irq.IRQInfo1 = ($3 & 0x0f); }
339 | cftab IRQ_NO MASK NUMBER
341 $$->cftable_entry.irq.IRQInfo1 = IRQ_INFO2_VALID;
342 $$->cftable_entry.irq.IRQInfo2 = $4;
345 { $$->cftable_entry.irq.IRQInfo1 |= IRQ_PULSE_ID; }
347 { $$->cftable_entry.irq.IRQInfo1 |= IRQ_LEVEL_ID; }
349 { $$->cftable_entry.irq.IRQInfo1 |= IRQ_SHARE_ID; }
352 cftab: CFTABLE NUMBER
354 $$ = calloc(1, sizeof(cisparse_t));
355 $$->cftable_entry.index = $2;
358 { $$->cftable_entry.flags |= CISTPL_CFTABLE_DEFAULT; }
360 { $$->cftable_entry.flags |= CISTPL_CFTABLE_BVDS; }
362 { $$->cftable_entry.flags |= CISTPL_CFTABLE_WP; }
364 { $$->cftable_entry.flags |= CISTPL_CFTABLE_RDYBSY; }
366 { $$->cftable_entry.flags |= CISTPL_CFTABLE_MWAIT; }
368 { $$->cftable_entry.flags |= CISTPL_CFTABLE_AUDIO; }
370 { $$->cftable_entry.flags |= CISTPL_CFTABLE_READONLY; }
372 { $$->cftable_entry.flags |= CISTPL_CFTABLE_PWRDOWN; }
374 { $$->cftable_entry.vcc = $3; }
376 { $$->cftable_entry.vpp1 = $3; }
378 { $$->cftable_entry.vpp2 = $3; }
385 checksum: CHECKSUM NUMBER '-' NUMBER '=' NUMBER
390 static tuple_info_t *new_tuple(u_char type, cisparse_t *parse)
392 tuple_info_t *t = calloc(1, sizeof(tuple_info_t));
399 void yyerror(const char *msg, ...)
405 sprintf(str, "error at line %d: ", current_lineno);
406 vsprintf(str+strlen(str), msg, ap);
407 fprintf(stderr, "%s\n", str);
412 void main(int argc, char *argv[])