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