2 /* sconfig, coreboot device tree compiler */
3 /* SPDX-License-Identifier: GPL-2.0-only */
9 void yyerror(const char *s
);
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
;
19 struct chip_instance
*chip_instance
;
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 PIPE OPS
26 devtree: { cur_parent
= root_parent
; } | devtree chip | devtree fw_config_table
;
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
;
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 */ ;
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
>$
;
41 chipchildren_dev END
{
42 cur_chip_instance
= chip_dequeue_tail
();
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
;
50 cur_parent
= $
<dev
>6->parent
;
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
;
58 cur_parent
= $
<dev
>5->parent
;
64 $
<string>$
= $
<string>2;
67 status: BOOL | STATUS
;
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)); } ;
72 reference: REFERENCE STRING
/* == alias */ ASSOCIATION STRING
/* == field in chip config */
73 { add_reference
(cur_chip_instance
, $
<string>4, $
<string>2); } ;
75 registers: REGISTER STRING
/* == regname */ EQUALS STRING
/* == regval */
76 { add_register
(cur_chip_instance
, $
<string>2, $
<string>4); } ;
78 subsystemid: SUBSYSTEMID NUMBER NUMBER
79 { add_pci_subsystem_ids
(cur_parent
, strtol
($
<string>2, NULL
, 16), strtol
($
<string>3, NULL
, 16), 0); };
81 subsystemid: SUBSYSTEMID NUMBER NUMBER INHERIT
82 { add_pci_subsystem_ids
(cur_parent
, strtol
($
<string>2, NULL
, 16), strtol
($
<string>3, NULL
, 16), 1); };
84 smbios_slot_desc: SLOT_DESC STRING STRING STRING STRING
85 { add_slot_desc
(cur_parent
, $
<string>2, $
<string>3, $
<string>4, $
<string>5); };
87 smbios_slot_desc: SLOT_DESC STRING STRING STRING
88 { add_slot_desc
(cur_parent
, $
<string>2, $
<string>3, $
<string>4, NULL
); };
90 smbios_slot_desc: SLOT_DESC STRING STRING
91 { add_slot_desc
(cur_parent
, $
<string>2, $
<string>3, NULL
, NULL
); };
93 smbios_dev_info: SMBIOS_DEV_INFO NUMBER STRING
94 { add_smbios_dev_info
(cur_parent
, strtol
($
<string>2, NULL
, 0), $
<string>3); };
96 smbios_dev_info: SMBIOS_DEV_INFO NUMBER
97 { add_smbios_dev_info
(cur_parent
, strtol
($
<string>2, NULL
, 0), NULL
); };
99 /* fw_config: firmware configuration table */
100 fw_config_table: FW_CONFIG_TABLE fw_config_table_children END
{ };
102 /* fw_config -> field */
103 fw_config_table_children: fw_config_table_children fw_config_field |
/* empty */ ;
105 /* field -> option */
106 fw_config_field_children: fw_config_field_children fw_config_option |
/* empty */ ;
108 /* <start-bit> <end-bit> */
109 fw_config_field_bits: NUMBER
/* == start bit */ NUMBER
/* == end bit */
111 append_fw_config_bits
(&cur_bits
, strtoul
($
<string>1, NULL
, 0), strtoul
($
<string>2, NULL
, 0));
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 */ ;
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
; };
121 /* field <bit> (for single-bit fields) */
122 fw_config_field: FW_CONFIG_FIELD STRING NUMBER
/* == bit */ {
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
);
127 fw_config_field_children END
{ cur_bits
= NULL
; };
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);
133 fw_config_field_children END
{ cur_bits
= NULL
; };
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)); };
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); }
143 ops: OPS STRING
/* == global identifier */
144 { add_device_ops
(cur_parent
, $
<string>2); }