diff options
author | Furquan Shaikh <furquan@google.com> | 2018-05-31 10:33:16 -0700 |
---|---|---|
committer | Furquan Shaikh <furquan@google.com> | 2018-06-05 20:58:03 +0000 |
commit | c56ae2ffa16fe0590af015add99354cf34f68a9b (patch) | |
tree | 5e0e582bee1cb92dbbb95cd439d549ccc21a8389 /util/sconfig | |
parent | 369e1f074f7b376e815927ddfc7d8a529ba57500 (diff) |
util/sconfig: Get rid of struct header
Now that chips and devices are treated differently in sconfig, this
change gets rid of struct header and add_header function which were
responsible for maintaining list of headers that need to be added to
static.c.
Instead, struct chip is re-factored into struct chip and
struct chip_instance, where chip is a list of unique chips required by
the mainboard whereas chip_instance is an instance of the chip. One
chip can have multiple instances dependending upon the devices in the
system. Also, struct device is updated to hold a pointer to chip
instance instead of the chip structure. This unique list of chips is
then used to add appropriate headers to static.c
BUG=b:80081934
TEST=Verified using abuild that all boards compile successfully.
Change-Id: I6fccdf7c361b4f55a831195adcda9b21932755aa
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/26739
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/sconfig')
-rw-r--r-- | util/sconfig/main.c | 177 | ||||
-rw-r--r-- | util/sconfig/sconfig.h | 36 | ||||
-rw-r--r-- | util/sconfig/sconfig.tab.c_shipped | 16 | ||||
-rw-r--r-- | util/sconfig/sconfig.tab.h_shipped | 2 | ||||
-rwxr-xr-x | util/sconfig/sconfig.y | 16 |
5 files changed, 133 insertions, 114 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c index 611f05893e..d505d4f5f2 100644 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -22,7 +22,7 @@ extern int linenum; struct device *head, *lastdev; -static struct chip *chip_head; +static struct chip chip_header; /* * This is intentionally shared between chip and device structure ids because it @@ -38,15 +38,24 @@ typedef enum { } translate_t; static struct device root; -static struct chip mainboard = { + +static struct chip_instance mainboard_instance; + +static struct chip mainboard_chip = { .name = "mainboard", .name_underscore = "mainboard", + .instance = &mainboard_instance, +}; + +static struct chip_instance mainboard_instance = { + .id = 0, + .chip = &mainboard_chip, }; static struct device root = { .name = "dev_root", .id = 0, - .chip = &mainboard, + .chip_instance = &mainboard_instance, .path = " .type = DEVICE_PATH_ROOT ", .ops = "&default_dev_ops_root", .parent = &root, @@ -205,14 +214,28 @@ char *translate_name(const char *str, translate_t mode) return b; } -struct chip *new_chip(char *path) +static struct chip *get_chip(char *path) { - struct chip *new_chip = S_ALLOC(sizeof(*new_chip)); + struct chip *h = &chip_header; + + while (h->next) { + int result = strcmp(path, h->next->name); + if (result == 0) + return h->next; + + if (result < 0) + break; + + h = h->next; + } + + struct chip *new_chip = S_ALLOC(sizeof(struct chip)); + new_chip->next = h->next; + h->next = new_chip; - new_chip->id = ++count; new_chip->chiph_exists = 1; new_chip->name = path; - new_chip->name_underscore = translate_name(new_chip->name, UNSLASH); + new_chip->name_underscore = translate_name(path, UNSLASH); struct stat st; char *chip_h = S_ALLOC(strlen(path) + 18); @@ -235,13 +258,24 @@ struct chip *new_chip(char *path) free(chip_h); - new_chip->next = chip_head; - chip_head = new_chip; - return new_chip; } -struct device *new_device(struct device *parent, struct chip *chip, +struct chip_instance *new_chip_instance(char *path) +{ + struct chip *chip = get_chip(path); + struct chip_instance *instance = S_ALLOC(sizeof(*instance)); + + instance->id = ++count; + instance->chip = chip; + instance->next = chip->instance; + chip->instance = instance; + + return instance; +} + +struct device *new_device(struct device *parent, + struct chip_instance *chip_instance, const int bustype, const char *devnum, int enabled) { @@ -260,7 +294,7 @@ struct device *new_device(struct device *parent, struct chip *chip, new_d->name = name; new_d->enabled = enabled; - new_d->chip = chip; + new_d->chip_instance = chip_instance; if (parent->latestchild) { parent->latestchild->next_sibling = new_d; @@ -367,14 +401,14 @@ void add_resource(struct device *dev, int type, int index, int base) dev->rescnt++; } -void add_register(struct chip *chip, char *name, char *val) +void add_register(struct chip_instance *chip_instance, char *name, char *val) { struct reg *r = S_ALLOC(sizeof(struct reg)); r->key = name; r->value = val; - if (chip->reg) { - struct reg *head = chip->reg; + if (chip_instance->reg) { + struct reg *head = chip_instance->reg; // sorting to be equal to sconfig's behaviour int sort = strcmp(r->key, head->key); if (sort == 0) { @@ -383,7 +417,7 @@ void add_register(struct chip *chip, char *name, char *val) } if (sort < 0) { r->next = head; - chip->reg = r; + chip_instance->reg = r; } else { while ((head->next) && (strcmp(head->next->key, r->key) < 0)) @@ -392,7 +426,7 @@ void add_register(struct chip *chip, char *name, char *val) head->next = r; } } else { - chip->reg = r; + chip_instance->reg = r; } } @@ -458,6 +492,7 @@ static void pass0(FILE *fil, struct device *ptr) static void pass1(FILE *fil, struct device *ptr) { int pin; + struct chip_instance *chip_ins = ptr->chip_instance; if (!ptr->used) { if (ptr->id != 0) @@ -505,13 +540,13 @@ static void pass1(FILE *fil, struct device *ptr) fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name); fprintf(fil, "#if !DEVTREE_EARLY\n"); fprintf(fil, "\t.chip_ops = &%s_ops,\n", - ptr->chip->name_underscore); - if (ptr->chip == &mainboard) + chip_ins->chip->name_underscore); + if (chip_ins == &mainboard_instance) fprintf(fil, "\t.name = mainboard_name,\n"); fprintf(fil, "#endif\n"); - if (ptr->chip->chiph_exists) + if (chip_ins->chip->chiph_exists) fprintf(fil, "\t.chip_info = &%s_info_%d,\n", - ptr->chip->name_underscore, ptr->chip->id); + chip_ins->chip->name_underscore, chip_ins->id); if (ptr->nextdev) fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name); fprintf(fil, "};\n"); @@ -595,89 +630,65 @@ static void walk_device_tree(FILE *fil, struct device *ptr, } while (ptr); } -static void add_header(struct chip *chip, struct header *h) -{ - int include_exists = 0; - - while (h->next) { - int result = strcmp(chip->name, h->next->name); - if (result == 0) { - include_exists = 1; - break; - } - if (result < 0) - break; - h = h->next; - } - - if (!include_exists) { - struct header *tmp = h->next; - h->next = S_ALLOC(sizeof(struct header)); - - h->next->chiph_exists = chip->chiph_exists; - h->next->name = chip->name; - h->next->next = tmp; - } -} - -static void emit_headers(FILE *fil) +static void emit_chip_headers(FILE *fil, struct chip *chip) { - struct header *h; - struct chip *chip; - struct header headers = {}; - - for (chip = chip_head; chip; chip = chip->next) - add_header(chip, &headers); + struct chip *tmp = chip; fprintf(fil, "#include <device/device.h>\n"); fprintf(fil, "#include <device/pci.h>\n"); - h = &headers; - while (h->next) { - h = h->next; - if (h->chiph_exists) - fprintf(fil, "#include \"%s/chip.h\"\n", h->name); + + while (chip) { + if (chip->chiph_exists) + fprintf(fil, "#include \"%s/chip.h\"\n", chip->name); + chip = chip->next; } fprintf(fil, "\n#if !DEVTREE_EARLY\n"); fprintf(fil, "__attribute__((weak)) struct chip_operations mainboard_ops = {};\n"); - h = &headers; - while (h->next) { - h = h->next; - char *name_underscore = translate_name(h->name, UNSLASH); + + chip = tmp; + while (chip) { fprintf(fil, "__attribute__((weak)) struct chip_operations %s_ops = {};\n", - name_underscore); - free(name_underscore); + chip->name_underscore); + chip = chip->next; } fprintf(fil, "#endif\n"); } +static void emit_chip_instance(FILE *fil, struct chip_instance *instance) +{ + fprintf(fil, "DEVTREE_CONST struct %s_config %s_info_%d = {", + instance->chip->name_underscore, + instance->chip->name_underscore, + instance->id); + + if (instance->reg) { + fprintf(fil, "\n"); + struct reg *r = instance->reg; + while (r) { + fprintf(fil, "\t.%s = %s,\n", r->key, r->value); + r = r->next; + } + } + fprintf(fil, "};\n\n"); +} + static void emit_chips(FILE *fil) { - struct chip *chip; + struct chip *chip = chip_header.next; + struct chip_instance *instance; - emit_headers(fil); + emit_chip_headers(fil, chip); - for (chip = chip_head; chip; chip = chip->next) { + for (; chip; chip = chip->next) { if (!chip->chiph_exists) continue; - if (chip->reg) { - fprintf(fil, - "DEVTREE_CONST struct %s_config %s_info_%d = {\n", - chip->name_underscore, chip->name_underscore, - chip->id); - struct reg *r = chip->reg; - while (r) { - fprintf(fil, "\t.%s = %s,\n", r->key, r->value); - r = r->next; - } - fprintf(fil, "};\n\n"); - } else { - fprintf(fil, - "DEVTREE_CONST struct %s_config %s_info_%d = { };\n", - chip->name_underscore, chip->name_underscore, - chip->id); + instance = chip->instance; + while (instance) { + emit_chip_instance(fil, instance); + instance = instance->next; } } } diff --git a/util/sconfig/sconfig.h b/util/sconfig/sconfig.h index 1f18907331..960facd7b1 100644 --- a/util/sconfig/sconfig.h +++ b/util/sconfig/sconfig.h @@ -42,13 +42,25 @@ struct pci_irq_info { int ioapic_dst_id; }; -struct chip { +struct chip; +struct chip_instance { /* * Monotonically increasing ID for each newly allocated * node(chip/device). */ int id; + /* Pointer to registers for this chip. */ + struct reg *reg; + + /* Pointer to chip of which this is instance. */ + struct chip *chip; + + /* Pointer to next instance of the same chip. */ + struct chip_instance *next; +}; + +struct chip { /* Indicates if chip header exists for this chip. */ int chiph_exists; @@ -58,8 +70,8 @@ struct chip { /* Name of current chip normalized to _. */ char *name_underscore; - /* Pointer to registers for this chip. */ - struct reg *reg; + /* Pointer to first instance of this chip. */ + struct chip_instance *instance; /* Pointer to next chip. */ struct chip *next; @@ -93,28 +105,21 @@ struct device { struct device *sibling; struct resource *res; - struct chip *chip; + struct chip_instance *chip_instance; }; extern struct device *head; -struct header; -struct header { - char *name; - int chiph_exists; - struct header *next; -}; - void fold_in(struct device *parent); void postprocess_devtree(void); -struct chip *new_chip(char *path); -struct device *new_device(struct device *parent, struct chip *chip, + +struct device *new_device(struct device *parent, + struct chip_instance *chip_instance, const int bustype, const char *devnum, int enabled); void alias_siblings(struct device *d); void add_resource(struct device *dev, int type, int index, int base); -void add_register(struct chip *chip, char *name, char *val); void add_pci_subsystem_ids(struct device *dev, int vendor, int device, int inherit); void add_ioapic_info(struct device *dev, int apicid, const char *_srcpin, @@ -127,3 +132,6 @@ void chip_enqueue_tail(void *data); /* Retrieve chip data from tail of queue. */ void *chip_dequeue_tail(void); + +struct chip_instance *new_chip_instance(char *path); +void add_register(struct chip_instance *chip, char *name, char *val); diff --git a/util/sconfig/sconfig.tab.c_shipped b/util/sconfig/sconfig.tab.c_shipped index fb72b961b4..3f0e0af02a 100644 --- a/util/sconfig/sconfig.tab.c_shipped +++ b/util/sconfig/sconfig.tab.c_shipped @@ -86,7 +86,7 @@ int yylex(); void yyerror(const char *s); static struct device *cur_parent; -static struct chip *cur_chip; +static struct chip_instance *cur_chip_instance; @@ -165,7 +165,7 @@ union YYSTYPE struct device *device; - struct chip *chip; + struct chip_instance *chip_instance; char *string; int number; @@ -1300,9 +1300,9 @@ yyreduce: case 14: { - (yyval.chip) = new_chip((yyvsp[0].string)); - chip_enqueue_tail(cur_chip); - cur_chip = (yyval.chip); + (yyval.chip_instance) = new_chip_instance((yyvsp[0].string)); + chip_enqueue_tail(cur_chip_instance); + cur_chip_instance = (yyval.chip_instance); } break; @@ -1310,7 +1310,7 @@ yyreduce: case 15: { - cur_chip = chip_dequeue_tail(); + cur_chip_instance = chip_dequeue_tail(); } break; @@ -1318,7 +1318,7 @@ yyreduce: case 16: { - (yyval.device) = new_device(cur_parent, cur_chip, (yyvsp[-2].number), (yyvsp[-1].string), (yyvsp[0].number)); + (yyval.device) = new_device(cur_parent, cur_chip_instance, (yyvsp[-2].number), (yyvsp[-1].string), (yyvsp[0].number)); cur_parent = (yyval.device); } @@ -1342,7 +1342,7 @@ yyreduce: case 19: - { add_register(cur_chip, (yyvsp[-2].string), (yyvsp[0].string)); } + { add_register(cur_chip_instance, (yyvsp[-2].string), (yyvsp[0].string)); } break; diff --git a/util/sconfig/sconfig.tab.h_shipped b/util/sconfig/sconfig.tab.h_shipped index e633fe0579..378634789c 100644 --- a/util/sconfig/sconfig.tab.h_shipped +++ b/util/sconfig/sconfig.tab.h_shipped @@ -86,7 +86,7 @@ union YYSTYPE struct device *device; - struct chip *chip; + struct chip_instance *chip_instance; char *string; int number; diff --git a/util/sconfig/sconfig.y b/util/sconfig/sconfig.y index c289c9e26d..a355c77c56 100755 --- a/util/sconfig/sconfig.y +++ b/util/sconfig/sconfig.y @@ -21,12 +21,12 @@ int yylex(); void yyerror(const char *s); static struct device *cur_parent; -static struct chip *cur_chip; +static struct chip_instance *cur_chip_instance; %} %union { struct device *device; - struct chip *chip; + struct chip_instance *chip_instance; char *string; int number; } @@ -40,16 +40,16 @@ chipchildren: chipchildren device | chipchildren chip | chipchildren registers | devicechildren: devicechildren device | devicechildren chip | devicechildren resource | devicechildren subsystemid | devicechildren ioapic_irq | /* empty */ ; chip: CHIP STRING /* == path */ { - $<chip>$ = new_chip($<string>2); - chip_enqueue_tail(cur_chip); - cur_chip = $<chip>$; + $<chip_instance>$ = new_chip_instance($<string>2); + chip_enqueue_tail(cur_chip_instance); + cur_chip_instance = $<chip_instance>$; } chipchildren END { - cur_chip = chip_dequeue_tail(); + cur_chip_instance = chip_dequeue_tail(); }; device: DEVICE BUS NUMBER /* == devnum */ BOOL { - $<device>$ = new_device(cur_parent, cur_chip, $<number>2, $<string>3, $<number>4); + $<device>$ = new_device(cur_parent, cur_chip_instance, $<number>2, $<string>3, $<number>4); cur_parent = $<device>$; } devicechildren END { @@ -62,7 +62,7 @@ resource: RESOURCE NUMBER /* == resnum */ EQUALS NUMBER /* == resval */ { add_resource(cur_parent, $<number>1, strtol($<string>2, NULL, 0), strtol($<string>4, NULL, 0)); } ; registers: REGISTER STRING /* == regname */ EQUALS STRING /* == regval */ - { add_register(cur_chip, $<string>2, $<string>4); } ; + { add_register(cur_chip_instance, $<string>2, $<string>4); } ; subsystemid: SUBSYSTEMID NUMBER NUMBER { add_pci_subsystem_ids(cur_parent, strtol($<string>2, NULL, 16), strtol($<string>3, NULL, 16), 0); }; |