non-root devices are not supposed to be accessed outside of static.c except by
[coreboot.git] / util / sconfig / sconfig.y
1 %{
2 /*
3  * sconfig, coreboot device tree compiler
4  *
5  * Copyright (C) 2010 coresystems GmbH
6  *                 written by Patrick Georgi <patrick.georgi@coresystems.de>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
20  */
21
22 #include "sconfig.h"
23
24 static struct device *cur_parent, *cur_bus;
25
26 %}
27 %union {
28         struct device *device;
29         char *string;
30         int number;
31 }
32 %token CHIP DEVICE REGISTER BOOL BUS RESOURCE END EQUALS HEX STRING PCI PNP I2C APIC APIC_CLUSTER PCI_DOMAIN IRQ DRQ IO NUMBER
33 %%
34 devtree: { cur_parent = cur_bus = head; } chip { postprocess_devtree(); } ;
35
36 chipchildren: chipchildren device | chipchildren chip | chipchildren registers | /* empty */ ;
37
38 devicechildren: devicechildren device | devicechildren chip | devicechildren resource | /* empty */ ;
39
40 chip: CHIP STRING /* == path */ {
41         $<device>$ = new_chip(cur_parent, cur_bus, $<string>2);
42         cur_parent = $<device>$;
43 }
44         chipchildren END {
45         cur_parent = $<device>3->parent;
46         fold_in($<device>3);
47         add_header($<device>3);
48 };
49
50 device: DEVICE BUS NUMBER /* == devnum */ BOOL {
51         $<device>$ = new_device(cur_parent, cur_bus, $<number>2, $<string>3, $<number>4);
52         cur_parent = $<device>$;
53         cur_bus = $<device>$;
54 }
55         devicechildren END {
56         cur_parent = $<device>5->parent;
57         cur_bus = $<device>5->bus;
58         fold_in($<device>5);
59         alias_siblings($<device>5->children);
60 };
61
62 resource: RESOURCE NUMBER /* == resnum */ EQUALS NUMBER /* == resval */
63         { add_resource(cur_parent, $<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ;
64
65 registers: REGISTER STRING /* == regname */ EQUALS STRING /* == regval */
66         { add_register(cur_parent, $<string>2, $<string>4); } ;
67
68 %%