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>
This commit is contained in:
committed by
Tim Wawrzynczak
parent
ad7c8ffba9
commit
8e1ea525d1
@@ -57,6 +57,9 @@ struct chip_instance {
|
||||
/* Pointer to registers for this chip. */
|
||||
struct reg *reg;
|
||||
|
||||
/* Pointer to references for this chip. */
|
||||
struct reg *ref;
|
||||
|
||||
/* Pointer to chip of which this is instance. */
|
||||
struct chip *chip;
|
||||
|
||||
@@ -123,6 +126,9 @@ struct device {
|
||||
/* Name of this device. */
|
||||
char *name;
|
||||
|
||||
/* Alias of this device (for internal references) */
|
||||
char *alias;
|
||||
|
||||
/* Path of this device. */
|
||||
char *path;
|
||||
int path_a;
|
||||
@@ -172,7 +178,7 @@ extern struct bus *root_parent;
|
||||
struct device *new_device(struct bus *parent,
|
||||
struct chip_instance *chip_instance,
|
||||
const int bustype, const char *devnum,
|
||||
int status);
|
||||
char *alias, int status);
|
||||
|
||||
void add_resource(struct bus *bus, int type, int index, int base);
|
||||
|
||||
@@ -195,6 +201,7 @@ void *chip_dequeue_tail(void);
|
||||
|
||||
struct chip_instance *new_chip_instance(char *path);
|
||||
void add_register(struct chip_instance *chip, char *name, char *val);
|
||||
void add_reference(struct chip_instance *chip, char *name, char *alias);
|
||||
|
||||
struct fw_config_field *get_fw_config_field(const char *name);
|
||||
|
||||
|
Reference in New Issue
Block a user