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