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