aboutsummaryrefslogtreecommitdiff
path: root/util/sconfig/main.c
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@google.com>2020-07-29 16:28:43 -0700
committerFurquan Shaikh <furquan@google.com>2020-10-09 23:25:46 +0000
commite335c2e02fcf7ee15dd5ae947a19d65390729263 (patch)
tree5c87d2f2a63c40c2c62b601da185d9743db215b5 /util/sconfig/main.c
parentb9a7d779b3cb48bb784d0856b6bb5f3fc6b4c1f7 (diff)
sconfig: Allow chipset to provide a base devicetree
This change extends the devicetree override one more layer and allows the chipset to provide the base devicetree. This allows the chipset to assign alias names to devices as well as set default register values. This works for both the baseboard devicetree.cb as well as variant overridetree.cb. chipset.cb: device pci 15.0 alias i2c0 off end devicetree.cb: device ref i2c0 on end BUG=b:156957424 Change-Id: Ia7500a62f6211243b519424ef3834b9e7615e2fd Signed-off-by: Duncan Laurie <dlaurie@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/44037 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'util/sconfig/main.c')
-rw-r--r--util/sconfig/main.c97
1 files changed, 76 insertions, 21 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index dbb266b346..bff721548b 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -69,6 +69,9 @@ typedef enum {
/* Root device of primary tree. */
static struct device base_root_dev;
+/* Root device of chipset tree. */
+static struct device chipset_root_dev;
+
/* Root device of override tree (if applicable). */
static struct device override_root_dev;
@@ -88,6 +91,20 @@ static struct device base_root_dev = {
.bus = &base_root_bus,
};
+static struct bus chipset_root_bus = {
+ .id = 0,
+ .dev = &chipset_root_dev,
+};
+
+static struct device chipset_root_dev = {
+ .name = "chipset_root",
+ .chip_instance = &mainboard_instance,
+ .path = " .type = DEVICE_PATH_ROOT ",
+ .parent = &chipset_root_bus,
+ .enabled = 1,
+ .bus = &chipset_root_bus,
+};
+
static struct bus override_root_bus = {
.id = 0,
.dev = &override_root_dev,
@@ -689,28 +706,13 @@ static const struct device *find_alias(const struct device *const parent,
return NULL;
}
-struct device *new_device(struct bus *parent,
- struct chip_instance *chip_instance,
- const int bustype, const char *devnum,
- char *alias, int status)
+static struct device *new_device_with_path(struct bus *parent,
+ struct chip_instance *chip_instance,
+ const int bustype, int path_a, int path_b,
+ char *alias, int status)
{
- char *tmp;
- int path_a;
- int path_b = 0;
struct device *new_d;
- /* Check for alias name conflicts. */
- if (alias && find_alias(&base_root_dev, alias)) {
- printf("ERROR: Alias already exists: %s\n", alias);
- exit(1);
- }
-
- path_a = strtol(devnum, &tmp, 16);
- if (*tmp == '.') {
- tmp++;
- path_b = strtol(tmp, NULL, 16);
- }
-
/* If device is found under parent, no need to allocate new device. */
new_d = get_dev(parent, path_a, path_b, bustype, chip_instance);
if (new_d) {
@@ -794,6 +796,46 @@ struct device *new_device(struct bus *parent,
return new_d;
}
+struct device *new_device_reference(struct bus *parent,
+ struct chip_instance *chip_instance,
+ const char *reference, int status)
+{
+ const struct device *dev = find_alias(&base_root_dev, reference);
+
+ if (!dev) {
+ printf("ERROR: Unable to find device reference %s\n", reference);
+ exit(1);
+ }
+
+ return new_device_with_path(parent, chip_instance, dev->bustype, dev->path_a,
+ dev->path_b, NULL, status);
+}
+
+struct device *new_device_raw(struct bus *parent,
+ struct chip_instance *chip_instance,
+ const int bustype, const char *devnum,
+ char *alias, int status)
+{
+ char *tmp;
+ int path_a;
+ int path_b = 0;
+
+ /* Check for alias name conflicts. */
+ if (alias && find_alias(root_parent->dev, alias)) {
+ printf("ERROR: Alias already exists: %s\n", alias);
+ exit(1);
+ }
+
+ path_a = strtol(devnum, &tmp, 16);
+ if (*tmp == '.') {
+ tmp++;
+ path_b = strtol(tmp, NULL, 16);
+ }
+
+ return new_device_with_path(parent, chip_instance, bustype, path_a, path_b, alias,
+ status);
+}
+
static void new_resource(struct device *dev, int type, int index, int base)
{
struct resource *r = S_ALLOC(sizeof(struct resource));
@@ -1315,6 +1357,7 @@ static void usage(void)
printf(" -r | --output_h : Path to header static.h file (required)\n");
printf(" -m | --mainboard_devtree : Path to mainboard devicetree file (required)\n");
printf(" -o | --override_devtree : Path to override devicetree file (optional)\n");
+ printf(" -p | --chipset_devtree : Path to chipset/SOC devicetree file (optional)\n");
exit(1);
}
@@ -1683,6 +1726,7 @@ int main(int argc, char **argv)
static const struct option long_options[] = {
{ "mainboard_devtree", 1, NULL, 'm' },
{ "override_devtree", 1, NULL, 'o' },
+ { "chipset_devtree", 1, NULL, 'p' },
{ "output_c", 1, NULL, 'c' },
{ "output_h", 1, NULL, 'r' },
{ "help", 1, NULL, 'h' },
@@ -1690,11 +1734,12 @@ int main(int argc, char **argv)
};
const char *override_devtree = NULL;
const char *base_devtree = NULL;
+ const char *chipset_devtree = NULL;
const char *outputc = NULL;
const char *outputh = NULL;
int opt, option_index;
- while ((opt = getopt_long(argc, argv, "m:o:c:r:h", long_options,
+ while ((opt = getopt_long(argc, argv, "m:o:p:c:r:h", long_options,
&option_index)) != EOF) {
switch (opt) {
case 'm':
@@ -1703,6 +1748,9 @@ int main(int argc, char **argv)
case 'o':
override_devtree = strdup(optarg);
break;
+ case 'p':
+ chipset_devtree = strdup(optarg);
+ break;
case 'c':
outputc = strdup(optarg);
break;
@@ -1718,7 +1766,14 @@ int main(int argc, char **argv)
if (!base_devtree || !outputc || !outputh)
usage();
- parse_devicetree(base_devtree, &base_root_bus);
+ if (chipset_devtree) {
+ /* Use the chipset devicetree as the base, then override
+ with the mainboard "base" devicetree. */
+ parse_devicetree(chipset_devtree, &base_root_bus);
+ parse_override_devicetree(base_devtree, &chipset_root_dev);
+ } else {
+ parse_devicetree(base_devtree, &base_root_bus);
+ }
if (override_devtree)
parse_override_devicetree(override_devtree, &override_root_dev);