blob: 57e939d9f0dafb22fcd3b3643d055db6f37b4c32 [file] [log] [blame]
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +00001%{
Patrick Georgiea063cb2020-05-08 19:28:13 +02002/* sconfig, coreboot device tree compiler */
Patrick Georgi7333a112020-05-08 20:48:04 +02003/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +00004
Patrick Georgi114e7b22010-05-05 11:19:50 +00005#include "sconfig.h"
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +00006
Stefan Reinauer2e78aa52016-05-07 01:11:14 -07007int yylex();
8void yyerror(const char *s);
9
Furquan Shaikh93198262018-06-03 04:22:17 -070010static struct bus *cur_parent;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070011static struct chip_instance *cur_chip_instance;
Duncan Laurie47b7b342020-05-15 15:39:08 -070012static struct fw_config_field *cur_field;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000013
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000014%}
15%union {
Furquan Shaikh93198262018-06-03 04:22:17 -070016 struct device *dev;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070017 struct chip_instance *chip_instance;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000018 char *string;
19 int number;
20}
Sven Schnelle270a9082011-03-01 19:58:15 +000021
Duncan Laurie47b7b342020-05-15 15:39:08 -070022%token CHIP DEVICE REGISTER BOOL STATUS MANDATORY BUS RESOURCE END EQUALS HEX STRING PCI PNP I2C APIC CPU_CLUSTER CPU DOMAIN IRQ DRQ SLOT_DESC IO NUMBER SUBSYSTEMID INHERIT IOAPIC_IRQ IOAPIC PCIINT GENERIC SPI USB MMIO LPC ESPI FW_CONFIG_TABLE FW_CONFIG_FIELD FW_CONFIG_OPTION FW_CONFIG_PROBE
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000023%%
Duncan Laurie47b7b342020-05-15 15:39:08 -070024devtree: { cur_parent = root_parent; } | devtree chip | devtree fw_config_table;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000025
Patrick Georgi8f625f62010-05-05 13:13:47 +000026chipchildren: chipchildren device | chipchildren chip | chipchildren registers | /* empty */ ;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000027
Duncan Laurie47b7b342020-05-15 15:39:08 -070028devicechildren: devicechildren device | devicechildren chip | devicechildren resource | devicechildren subsystemid | devicechildren ioapic_irq | devicechildren smbios_slot_desc | devicechildren registers | devicechildren fw_config_probe | /* empty */ ;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000029
30chip: CHIP STRING /* == path */ {
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070031 $<chip_instance>$ = new_chip_instance($<string>2);
32 chip_enqueue_tail(cur_chip_instance);
33 cur_chip_instance = $<chip_instance>$;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000034}
Patrick Georgi8f625f62010-05-05 13:13:47 +000035 chipchildren END {
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070036 cur_chip_instance = chip_dequeue_tail();
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000037};
38
Hung-Te Lin936dbe12018-09-10 10:51:26 +080039device: DEVICE BUS NUMBER /* == devnum */ status {
Furquan Shaikh93198262018-06-03 04:22:17 -070040 $<dev>$ = new_device(cur_parent, cur_chip_instance, $<number>2, $<string>3, $<number>4);
41 cur_parent = $<dev>$->last_bus;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000042}
Patrick Georgi8f625f62010-05-05 13:13:47 +000043 devicechildren END {
Furquan Shaikh93198262018-06-03 04:22:17 -070044 cur_parent = $<dev>5->parent;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000045};
46
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +000047status: BOOL | STATUS ;
Hung-Te Lin936dbe12018-09-10 10:51:26 +080048
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000049resource: RESOURCE NUMBER /* == resnum */ EQUALS NUMBER /* == resval */
Patrick Georgi68befd52010-05-05 12:05:25 +000050 { add_resource(cur_parent, $<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000051
52registers: REGISTER STRING /* == regname */ EQUALS STRING /* == regval */
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070053 { add_register(cur_chip_instance, $<string>2, $<string>4); } ;
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +000054
Sven Schnelle270a9082011-03-01 19:58:15 +000055subsystemid: SUBSYSTEMID NUMBER NUMBER
56 { add_pci_subsystem_ids(cur_parent, strtol($<string>2, NULL, 16), strtol($<string>3, NULL, 16), 0); };
57
58subsystemid: SUBSYSTEMID NUMBER NUMBER INHERIT
59 { add_pci_subsystem_ids(cur_parent, strtol($<string>2, NULL, 16), strtol($<string>3, NULL, 16), 1); };
60
Sven Schnelle0fa50a12012-06-21 22:19:48 +020061ioapic_irq: IOAPIC_IRQ NUMBER PCIINT NUMBER
62 { add_ioapic_info(cur_parent, strtol($<string>2, NULL, 16), $<string>3, strtol($<string>4, NULL, 16)); };
Patrick Rudolphac24d3c2019-04-12 14:42:17 +020063
64smbios_slot_desc: SLOT_DESC STRING STRING STRING STRING
65 { add_slot_desc(cur_parent, $<string>2, $<string>3, $<string>4, $<string>5); };
66
67smbios_slot_desc: SLOT_DESC STRING STRING STRING
68 { add_slot_desc(cur_parent, $<string>2, $<string>3, $<string>4, NULL); };
69
70smbios_slot_desc: SLOT_DESC STRING STRING
71 { add_slot_desc(cur_parent, $<string>2, $<string>3, NULL, NULL); };
72
Duncan Laurie47b7b342020-05-15 15:39:08 -070073/* fw_config: firmware configuration table */
74fw_config_table: FW_CONFIG_TABLE fw_config_table_children END { };
75
76/* fw_config -> field */
77fw_config_table_children: fw_config_table_children fw_config_field | /* empty */ ;
78
79/* field -> option */
80fw_config_field_children: fw_config_field_children fw_config_option | /* empty */ ;
81
82/* field <start-bit> <end-bit> */
83fw_config_field: FW_CONFIG_FIELD STRING NUMBER /* == start bit */ NUMBER /* == end bit */ {
84 cur_field = new_fw_config_field($<string>2, strtoul($<string>3, NULL, 0), strtoul($<string>4, NULL, 0));
85}
86 fw_config_field_children END { };
87
88/* field <bit> (for single-bit fields) */
89fw_config_field: FW_CONFIG_FIELD STRING NUMBER /* == bit */ {
90 cur_field = new_fw_config_field($<string>2, strtoul($<string>3, NULL, 0), strtoul($<string>3, NULL, 0));
91}
92 fw_config_field_children END { };
93
94/* field (for adding options to an existing field) */
95fw_config_field: FW_CONFIG_FIELD STRING {
96 cur_field = get_fw_config_field($<string>2);
97}
98 fw_config_field_children END { };
99
100/* option <value> */
101fw_config_option: FW_CONFIG_OPTION STRING NUMBER /* == field value */
102 { add_fw_config_option(cur_field, $<string>2, strtoul($<string>3, NULL, 0)); };
103
104/* probe <field> <option> */
105fw_config_probe: FW_CONFIG_PROBE STRING /* == field */ STRING /* == option */
106 { add_fw_config_probe(cur_parent, $<string>2, $<string>3); }
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +0000107%%