Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 1 | %{ |
Patrick Georgi | ea063cb | 2020-05-08 19:28:13 +0200 | [diff] [blame] | 2 | /* sconfig, coreboot device tree compiler */ |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 4 | |
Patrick Georgi | 114e7b2 | 2010-05-05 11:19:50 +0000 | [diff] [blame] | 5 | #include "sconfig.h" |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 6 | |
Stefan Reinauer | 2e78aa5 | 2016-05-07 01:11:14 -0700 | [diff] [blame] | 7 | int yylex(); |
| 8 | void yyerror(const char *s); |
| 9 | |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 10 | static struct bus *cur_parent; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 11 | static struct chip_instance *cur_chip_instance; |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 12 | static struct fw_config_field *cur_field; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 13 | |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 14 | %} |
| 15 | %union { |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 16 | struct device *dev; |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 17 | struct chip_instance *chip_instance; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 18 | char *string; |
| 19 | int number; |
| 20 | } |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 21 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 22 | %token CHIP DEVICE REGISTER ALIAS REFERENCE ASSOCIATION 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 Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 23 | %% |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 24 | devtree: { cur_parent = root_parent; } | devtree chip | devtree fw_config_table; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 25 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 26 | chipchildren: chipchildren device | chipchildren chip | chipchildren registers | chipchildren reference | /* empty */ ; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 27 | |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 28 | devicechildren: devicechildren device | devicechildren chip | devicechildren resource | devicechildren subsystemid | devicechildren ioapic_irq | devicechildren smbios_slot_desc | devicechildren registers | devicechildren fw_config_probe | /* empty */ ; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 29 | |
| 30 | chip: CHIP STRING /* == path */ { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 31 | $<chip_instance>$ = new_chip_instance($<string>2); |
| 32 | chip_enqueue_tail(cur_chip_instance); |
| 33 | cur_chip_instance = $<chip_instance>$; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 34 | } |
Patrick Georgi | 8f625f6 | 2010-05-05 13:13:47 +0000 | [diff] [blame] | 35 | chipchildren END { |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 36 | cur_chip_instance = chip_dequeue_tail(); |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 39 | device: DEVICE BUS NUMBER /* == devnum */ alias status { |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame^] | 40 | $<dev>$ = new_device_raw(cur_parent, cur_chip_instance, $<number>2, $<string>3, $<string>4, $<number>5); |
Furquan Shaikh | 9319826 | 2018-06-03 04:22:17 -0700 | [diff] [blame] | 41 | cur_parent = $<dev>$->last_bus; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 42 | } |
Patrick Georgi | 8f625f6 | 2010-05-05 13:13:47 +0000 | [diff] [blame] | 43 | devicechildren END { |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 44 | cur_parent = $<dev>6->parent; |
| 45 | }; |
| 46 | |
Duncan Laurie | e335c2e | 2020-07-29 16:28:43 -0700 | [diff] [blame^] | 47 | device: DEVICE REFERENCE STRING status { |
| 48 | $<dev>$ = new_device_reference(cur_parent, cur_chip_instance, $<string>3, $<number>4); |
| 49 | cur_parent = $<dev>$->last_bus; |
| 50 | } |
| 51 | devicechildren END { |
| 52 | cur_parent = $<dev>5->parent; |
| 53 | }; |
| 54 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 55 | alias: /* empty */ { |
| 56 | $<string>$ = NULL; |
| 57 | } | ALIAS STRING { |
| 58 | $<string>$ = $<string>2; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Ronald G. Minnich | 466ca2c | 2019-10-22 02:02:24 +0000 | [diff] [blame] | 61 | status: BOOL | STATUS ; |
Hung-Te Lin | 936dbe1 | 2018-09-10 10:51:26 +0800 | [diff] [blame] | 62 | |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 63 | resource: RESOURCE NUMBER /* == resnum */ EQUALS NUMBER /* == resval */ |
Patrick Georgi | 68befd5 | 2010-05-05 12:05:25 +0000 | [diff] [blame] | 64 | { add_resource(cur_parent, $<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 65 | |
Nico Huber | 8e1ea52 | 2020-06-03 10:20:07 -0700 | [diff] [blame] | 66 | reference: REFERENCE STRING /* == alias */ ASSOCIATION STRING /* == field in chip config */ |
| 67 | { add_reference(cur_chip_instance, $<string>4, $<string>2); } ; |
| 68 | |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 69 | registers: REGISTER STRING /* == regname */ EQUALS STRING /* == regval */ |
Furquan Shaikh | c56ae2f | 2018-05-31 10:33:16 -0700 | [diff] [blame] | 70 | { add_register(cur_chip_instance, $<string>2, $<string>4); } ; |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 71 | |
Sven Schnelle | 270a908 | 2011-03-01 19:58:15 +0000 | [diff] [blame] | 72 | subsystemid: SUBSYSTEMID NUMBER NUMBER |
| 73 | { add_pci_subsystem_ids(cur_parent, strtol($<string>2, NULL, 16), strtol($<string>3, NULL, 16), 0); }; |
| 74 | |
| 75 | subsystemid: SUBSYSTEMID NUMBER NUMBER INHERIT |
| 76 | { add_pci_subsystem_ids(cur_parent, strtol($<string>2, NULL, 16), strtol($<string>3, NULL, 16), 1); }; |
| 77 | |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 78 | ioapic_irq: IOAPIC_IRQ NUMBER PCIINT NUMBER |
| 79 | { add_ioapic_info(cur_parent, strtol($<string>2, NULL, 16), $<string>3, strtol($<string>4, NULL, 16)); }; |
Patrick Rudolph | ac24d3c | 2019-04-12 14:42:17 +0200 | [diff] [blame] | 80 | |
| 81 | smbios_slot_desc: SLOT_DESC STRING STRING STRING STRING |
| 82 | { add_slot_desc(cur_parent, $<string>2, $<string>3, $<string>4, $<string>5); }; |
| 83 | |
| 84 | smbios_slot_desc: SLOT_DESC STRING STRING STRING |
| 85 | { add_slot_desc(cur_parent, $<string>2, $<string>3, $<string>4, NULL); }; |
| 86 | |
| 87 | smbios_slot_desc: SLOT_DESC STRING STRING |
| 88 | { add_slot_desc(cur_parent, $<string>2, $<string>3, NULL, NULL); }; |
| 89 | |
Duncan Laurie | 47b7b34 | 2020-05-15 15:39:08 -0700 | [diff] [blame] | 90 | /* fw_config: firmware configuration table */ |
| 91 | fw_config_table: FW_CONFIG_TABLE fw_config_table_children END { }; |
| 92 | |
| 93 | /* fw_config -> field */ |
| 94 | fw_config_table_children: fw_config_table_children fw_config_field | /* empty */ ; |
| 95 | |
| 96 | /* field -> option */ |
| 97 | fw_config_field_children: fw_config_field_children fw_config_option | /* empty */ ; |
| 98 | |
| 99 | /* field <start-bit> <end-bit> */ |
| 100 | fw_config_field: FW_CONFIG_FIELD STRING NUMBER /* == start bit */ NUMBER /* == end bit */ { |
| 101 | cur_field = new_fw_config_field($<string>2, strtoul($<string>3, NULL, 0), strtoul($<string>4, NULL, 0)); |
| 102 | } |
| 103 | fw_config_field_children END { }; |
| 104 | |
| 105 | /* field <bit> (for single-bit fields) */ |
| 106 | fw_config_field: FW_CONFIG_FIELD STRING NUMBER /* == bit */ { |
| 107 | cur_field = new_fw_config_field($<string>2, strtoul($<string>3, NULL, 0), strtoul($<string>3, NULL, 0)); |
| 108 | } |
| 109 | fw_config_field_children END { }; |
| 110 | |
| 111 | /* field (for adding options to an existing field) */ |
| 112 | fw_config_field: FW_CONFIG_FIELD STRING { |
| 113 | cur_field = get_fw_config_field($<string>2); |
| 114 | } |
| 115 | fw_config_field_children END { }; |
| 116 | |
| 117 | /* option <value> */ |
| 118 | fw_config_option: FW_CONFIG_OPTION STRING NUMBER /* == field value */ |
| 119 | { add_fw_config_option(cur_field, $<string>2, strtoul($<string>3, NULL, 0)); }; |
| 120 | |
| 121 | /* probe <field> <option> */ |
| 122 | fw_config_probe: FW_CONFIG_PROBE STRING /* == field */ STRING /* == option */ |
| 123 | { add_fw_config_probe(cur_parent, $<string>2, $<string>3); } |
Patrick Georgi | 7e8c9aa | 2010-04-08 11:37:43 +0000 | [diff] [blame] | 124 | %% |