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>
This commit is contained in:
Furquan Shaikh 2021-09-16 16:05:56 -07:00 committed by Felix Held
parent f0227ee2a8
commit 0df32c85ad
1 changed files with 16 additions and 2 deletions

View File

@ -1088,8 +1088,16 @@ static void pass0(FILE *fil, FILE *head, struct device *ptr, struct device *next
return; return;
} }
char *name = S_ALLOC(10); char *name;
sprintf(name, "_dev%d", dev_id++);
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; ptr->name = name;
fprintf(fil, "STORAGE struct device %s;\n", ptr->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", fprintf(fil, "DEVTREE_CONST struct device *const __pnp_%04x_%02x = &%s;\n",
ptr->path_a, ptr->path_b, ptr->name); 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, static void add_siblings_to_queue(struct queue_entry **bfs_q_head,