summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2021-09-16 16:05:56 -0700
committerFelix Held <felix-coreboot@felixheld.de>2021-09-20 12:17:13 +0000
commit0df32c85add990dac5e66e2ced3943e6f7e7905b (patch)
tree27befeb53a3cc8c967ca68a8ca021b0aac5ed596 /util
parentf0227ee2a88aafc460d0137f9d2e61bd813aea0e (diff)
sconfig: Emit device structure pointers if alias names are provided
This change uses _dev_${ALIAS_NAME} as the name for `struct device` if the device has an alias. In addition to that, it emits _dev_${ALIAS_NAME}_ptr which points to the device structure. This allows developers to directly reference a particular device in the tree using alias name without having to walk the entire path. In later CLs, mainboards are transitioned to use this newly emitted device structure pointers. Change-Id: I8306d9efba8e5ca5c0bda41baac9c90ad8b73ece Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/57657 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Diffstat (limited to 'util')
-rw-r--r--util/sconfig/main.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index 9e44dc72ca..685da9dbfe 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -1088,8 +1088,16 @@ static void pass0(FILE *fil, FILE *head, struct device *ptr, struct device *next
return;
}
- char *name = S_ALLOC(10);
- sprintf(name, "_dev%d", dev_id++);
+ char *name;
+
+ if (ptr->alias) {
+ name = S_ALLOC(6 + strlen(ptr->alias));
+ sprintf(name, "_dev_%s", ptr->alias);
+ } else {
+ name = S_ALLOC(11);
+ sprintf(name, "_dev_%d", dev_id++);
+ }
+
ptr->name = name;
fprintf(fil, "STORAGE struct device %s;\n", ptr->name);
@@ -1325,6 +1333,12 @@ static void expose_device_names(FILE *fil, FILE *head, struct device *ptr, struc
fprintf(fil, "DEVTREE_CONST struct device *const __pnp_%04x_%02x = &%s;\n",
ptr->path_a, ptr->path_b, ptr->name);
}
+
+ if (ptr->alias) {
+ fprintf(head, "extern DEVTREE_CONST struct device *const %s_ptr;\n", ptr->name);
+ fprintf(fil, "DEVTREE_CONST struct device *const %s_ptr = &%s;\n",
+ ptr->name, ptr->name);
+ }
}
static void add_siblings_to_queue(struct queue_entry **bfs_q_head,