summaryrefslogtreecommitdiff
path: root/util/sconfig/sconfig.y
diff options
context:
space:
mode:
authorNico Huber <nico.huber@secunet.com>2020-06-03 10:20:07 -0700
committerTim Wawrzynczak <twawrzynczak@chromium.org>2020-09-11 17:34:01 +0000
commit8e1ea525d1ea25634db37bf93690e1479a1d748e (patch)
treeddc994a698ad9d28de4d8df7c2fd7b9c3521053e /util/sconfig/sconfig.y
parentad7c8ffba97b74d70e139b3745ce02ae513d2ef2 (diff)
sconfig: Allow to link devices to other device's drivers
Rarely, the driver of one device needs to know about another device that can be anywhere in the device hierarchy. Current applications boil down to EEPROMs that store information that is consumed by some code (e.g. MAC address). The idea is to give device nodes in the `devicetree.cb` an alias that can later be used to link it to a device driver's `config` structure. The driver has to declare a field of type `struct device *`, e.g. struct some_chip_driver_config { DEVTREE_CONST struct device *needed_eeprom; }; In the devicetree, the referenced device gets an alias, e.g. device i2c 0x50 alias my_eeprom on end The author of the devicetree is free to choose any alias name that is unique in the devicetree. Later, when configuring the driver the alias can be used to link the device with the field of a driver's config: chip some/chip/driver use my_eeprom as needed_eeprom end Override devices can add an alias if it does not exist, but cannot change the alias for a device that already exists. Alias names are checked for conflicts both in the base tree and in the override tree. References are resolved after the tree is parsed so aliases and references do not need to be in a specific order in the tree. Change-Id: I058a319f9b968924fbef9485a96c9e3f900a3ee8 Signed-off-by: Nico Huber <nico.huber@secunet.com> Signed-off-by: Duncan Laurie <dlaurie@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/35456 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/sconfig/sconfig.y')
-rwxr-xr-xutil/sconfig/sconfig.y19
1 files changed, 14 insertions, 5 deletions
diff --git a/util/sconfig/sconfig.y b/util/sconfig/sconfig.y
index 57e939d9f0..d441ff812d 100755
--- a/util/sconfig/sconfig.y
+++ b/util/sconfig/sconfig.y
@@ -19,11 +19,11 @@ static struct fw_config_field *cur_field;
int number;
}
-%token CHIP DEVICE REGISTER 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
+%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
%%
devtree: { cur_parent = root_parent; } | devtree chip | devtree fw_config_table;
-chipchildren: chipchildren device | chipchildren chip | chipchildren registers | /* empty */ ;
+chipchildren: chipchildren device | chipchildren chip | chipchildren registers | chipchildren reference | /* empty */ ;
devicechildren: devicechildren device | devicechildren chip | devicechildren resource | devicechildren subsystemid | devicechildren ioapic_irq | devicechildren smbios_slot_desc | devicechildren registers | devicechildren fw_config_probe | /* empty */ ;
@@ -36,12 +36,18 @@ chip: CHIP STRING /* == path */ {
cur_chip_instance = chip_dequeue_tail();
};
-device: DEVICE BUS NUMBER /* == devnum */ status {
- $<dev>$ = new_device(cur_parent, cur_chip_instance, $<number>2, $<string>3, $<number>4);
+device: DEVICE BUS NUMBER /* == devnum */ alias status {
+ $<dev>$ = new_device(cur_parent, cur_chip_instance, $<number>2, $<string>3, $<string>4, $<number>5);
cur_parent = $<dev>$->last_bus;
}
devicechildren END {
- cur_parent = $<dev>5->parent;
+ cur_parent = $<dev>6->parent;
+};
+
+alias: /* empty */ {
+ $<string>$ = NULL;
+} | ALIAS STRING {
+ $<string>$ = $<string>2;
};
status: BOOL | STATUS ;
@@ -49,6 +55,9 @@ status: BOOL | STATUS ;
resource: RESOURCE NUMBER /* == resnum */ EQUALS NUMBER /* == resval */
{ add_resource(cur_parent, $<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ;
+reference: REFERENCE STRING /* == alias */ ASSOCIATION STRING /* == field in chip config */
+ { add_reference(cur_chip_instance, $<string>4, $<string>2); } ;
+
registers: REGISTER STRING /* == regname */ EQUALS STRING /* == regval */
{ add_register(cur_chip_instance, $<string>2, $<string>4); } ;