| 1 |
%{ |
| 2 |
/* sconfig, coreboot device tree compiler */ |
| 3 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 4 |
|
| 5 |
#include <stdint.h> |
| 6 |
#include "sconfig.h" |
| 7 |
|
| 8 |
int yylex(); |
| 9 |
void yyerror(const char *s); |
| 10 |
|
| 11 |
static struct bus *cur_parent; |
| 12 |
static struct chip_instance *cur_chip_instance; |
| 13 |
static struct fw_config_field *cur_field; |
| 14 |
static struct fw_config_field_bits *cur_bits; |
| 15 |
|
| 16 |
%} |
| 17 |
%union { |
| 18 |
struct device *dev; |
| 19 |
struct chip_instance *chip_instance; |
| 20 |
char *string; |
| 21 |
uint64_t number; |
| 22 |
} |
| 23 |
|
| 24 |
%token CHIP DEVICE REGISTER ALIAS REFERENCE ASSOCIATION BOOL STATUS MANDATORY BUS RESOURCE END EQUALS HEX STRING PCI PNP I2C CPU_CLUSTER CPU DOMAIN IRQ DRQ SLOT_DESC SMBIOS_DEV_INFO IO NUMBER SUBSYSTEMID INHERIT PCIINT GENERIC SPI USB MMIO GPIO MDIO FW_CONFIG_TABLE FW_CONFIG_FIELD FW_CONFIG_OPTION FW_CONFIG_PROBE FW_CONFIG_UNPROVISIONED PIPE OPS |
| 25 |
%% |
| 26 |
devtree: { cur_parent = root_parent; } | devtree chip | devtree fw_config_table; |
| 27 |
|
| 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; |
| 33 |
|
| 34 |
devicechildren: devicechildren device | devicechildren chip | devicechildren resource | devicechildren subsystemid | devicechildren smbios_slot_desc | devicechildren smbios_dev_info | devicechildren registers | devicechildren fw_config_probe | devicechildren ops | /* empty */ ; |
| 35 |
|
| 36 |
chip: CHIP STRING /* == path */ { |
| 37 |
$<chip_instance>$ = new_chip_instance($<string>2); |
| 38 |
chip_enqueue_tail(cur_chip_instance); |
| 39 |
cur_chip_instance = $<chip_instance>$; |
| 40 |
} |
| 41 |
chipchildren_dev END { |
| 42 |
cur_chip_instance = chip_dequeue_tail(); |
| 43 |
}; |
| 44 |
|
| 45 |
device: DEVICE BUS NUMBER /* == devnum */ alias status { |
| 46 |
$<dev>$ = new_device_raw(cur_parent, cur_chip_instance, $<number>2, $<string>3, $<string>4, $<number>5); |
| 47 |
cur_parent = $<dev>$->bus; |
| 48 |
} |
| 49 |
devicechildren END { |
| 50 |
cur_parent = $<dev>6->parent; |
| 51 |
}; |
| 52 |
|
| 53 |
device: DEVICE REFERENCE STRING status { |
| 54 |
$<dev>$ = new_device_reference(cur_parent, cur_chip_instance, $<string>3, $<number>4); |
| 55 |
cur_parent = $<dev>$->bus; |
| 56 |
} |
| 57 |
devicechildren END { |
| 58 |
cur_parent = $<dev>5->parent; |
| 59 |
}; |
| 60 |
|
| 61 |
alias: /* empty */ { |
| 62 |
$<string>$ = NULL; |
| 63 |
} | ALIAS STRING { |
| 64 |
$<string>$ = $<string>2; |
| 65 |
}; |
| 66 |
|
| 67 |
status: BOOL | STATUS ; |
| 68 |
|
| 69 |
resource: RESOURCE NUMBER /* == resnum */ EQUALS NUMBER /* == resval */ |
| 70 |
{ add_resource(cur_parent, $<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ; |
| 71 |
|
| 72 |
reference: REFERENCE STRING /* == alias */ ASSOCIATION STRING /* == field in chip config */ |
| 73 |
{ add_reference(cur_chip_instance, $<string>4, $<string>2); } ; |
| 74 |
|
| 75 |
registers: REGISTER STRING /* == regname */ EQUALS STRING /* == regval */ |
| 76 |
{ add_register(cur_chip_instance, $<string>2, $<string>4); } ; |
| 77 |
|
| 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 |
|
| 84 |
smbios_slot_desc: SLOT_DESC STRING STRING STRING STRING |
| 85 |
{ add_slot_desc(cur_parent, $<string>2, $<string>3, $<string>4, $<string>5); }; |
| 86 |
|
| 87 |
smbios_slot_desc: SLOT_DESC STRING STRING STRING |
| 88 |
{ add_slot_desc(cur_parent, $<string>2, $<string>3, $<string>4, NULL); }; |
| 89 |
|
| 90 |
smbios_slot_desc: SLOT_DESC STRING STRING |
| 91 |
{ add_slot_desc(cur_parent, $<string>2, $<string>3, NULL, NULL); }; |
| 92 |
|
| 93 |
smbios_dev_info: SMBIOS_DEV_INFO NUMBER STRING |
| 94 |
{ add_smbios_dev_info(cur_parent, strtol($<string>2, NULL, 0), $<string>3); }; |
| 95 |
|
| 96 |
smbios_dev_info: SMBIOS_DEV_INFO NUMBER |
| 97 |
{ add_smbios_dev_info(cur_parent, strtol($<string>2, NULL, 0), NULL); }; |
| 98 |
|
| 99 |
/* fw_config: firmware configuration table */ |
| 100 |
fw_config_table: FW_CONFIG_TABLE fw_config_table_children END { }; |
| 101 |
|
| 102 |
/* fw_config -> field */ |
| 103 |
fw_config_table_children: fw_config_table_children fw_config_field | /* empty */ ; |
| 104 |
|
| 105 |
/* field -> option */ |
| 106 |
fw_config_field_children: fw_config_field_children fw_config_option | /* empty */ ; |
| 107 |
|
| 108 |
/* <start-bit> <end-bit> */ |
| 109 |
fw_config_field_bits: NUMBER /* == start bit */ NUMBER /* == end bit */ |
| 110 |
{ |
| 111 |
append_fw_config_bits(&cur_bits, strtoul($<string>1, NULL, 0), strtoul($<string>2, NULL, 0)); |
| 112 |
}; |
| 113 |
|
| 114 |
/* field <start-bit> <end-bit>(| <start-bit> <end-bit>)* */ |
| 115 |
fw_config_field_bits_repeating: PIPE fw_config_field_bits fw_config_field_bits_repeating | /* empty */ ; |
| 116 |
|
| 117 |
fw_config_field: FW_CONFIG_FIELD STRING fw_config_field_bits fw_config_field_bits_repeating |
| 118 |
{ cur_field = new_fw_config_field($<string>2, cur_bits); } |
| 119 |
fw_config_field_children END { cur_bits = NULL; }; |
| 120 |
|
| 121 |
/* field <bit> (for single-bit fields) */ |
| 122 |
fw_config_field: FW_CONFIG_FIELD STRING NUMBER /* == bit */ { |
| 123 |
cur_bits = NULL; |
| 124 |
append_fw_config_bits(&cur_bits, strtoul($<string>3, NULL, 0), strtoul($<string>3, NULL, 0)); |
| 125 |
cur_field = new_fw_config_field($<string>2, cur_bits); |
| 126 |
} |
| 127 |
fw_config_field_children END { cur_bits = NULL; }; |
| 128 |
|
| 129 |
/* field (for adding options to an existing field) */ |
| 130 |
fw_config_field: FW_CONFIG_FIELD STRING { |
| 131 |
cur_field = get_fw_config_field($<string>2); |
| 132 |
} |
| 133 |
fw_config_field_children END { cur_bits = NULL; }; |
| 134 |
|
| 135 |
/* option <value> */ |
| 136 |
fw_config_option: FW_CONFIG_OPTION STRING NUMBER /* == field value */ |
| 137 |
{ add_fw_config_option(cur_field, $<string>2, strtoull($<string>3, NULL, 0)); }; |
| 138 |
|
| 139 |
/* probe <field> <option> */ |
| 140 |
fw_config_probe: FW_CONFIG_PROBE STRING /* == field */ STRING /* == option */ |
| 141 |
{ add_fw_config_probe(cur_parent, $<string>2, $<string>3); } |
| 142 |
| /* probe unprovisioned */ |
| 143 |
FW_CONFIG_PROBE FW_CONFIG_UNPROVISIONED |
| 144 |
{ probe_unprovisioned_fw_config(cur_parent); }; |
| 145 |
|
| 146 |
ops: OPS STRING /* == global identifier */ |
| 147 |
{ add_device_ops(cur_parent, $<string>2); } |
| 148 |
|
| 149 |
%% |