util/sconfig: Get rid of bus pointer in device structure

The only reason bus pointer existed in device structure in sconfig was
to allow a node to point to the parent which could be a chip and bus
which is the true parent in device tree hierarchy. Now that chip is no
longer a device, there is no need for separate bus and parent
pointers. This change gets rid of the redundant bus pointer in struct
device in sconfig.

BUG=b:80081934
TEST=Verified that static.c generated for all boards built by abuild
is same with and without this change.

Change-Id: I21f8fe1545a9ed53d66d6d4462df4a5d63023844
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/26736
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Furquan Shaikh 2018-05-31 07:52:00 -07:00
parent a0cc5a697c
commit a9b642999b
4 changed files with 20 additions and 27 deletions

View File

@ -50,7 +50,6 @@ static struct device root = {
.path = " .type = DEVICE_PATH_ROOT ", .path = " .type = DEVICE_PATH_ROOT ",
.ops = "&default_dev_ops_root", .ops = "&default_dev_ops_root",
.parent = &root, .parent = &root,
.bus = &root,
.enabled = 1 .enabled = 1
}; };
@ -107,13 +106,12 @@ void *chip_dequeue_tail(void)
return data; return data;
} }
static struct device *new_dev(struct device *parent, struct device *bus) static struct device *new_dev(struct device *parent)
{ {
struct device *dev = malloc(sizeof(struct device)); struct device *dev = malloc(sizeof(struct device));
memset(dev, 0, sizeof(struct device)); memset(dev, 0, sizeof(struct device));
dev->id = ++count; dev->id = ++count;
dev->parent = parent; dev->parent = parent;
dev->bus = bus;
dev->subsystem_vendor = -1; dev->subsystem_vendor = -1;
dev->subsystem_device = -1; dev->subsystem_device = -1;
head->next = dev; head->next = dev;
@ -123,7 +121,7 @@ static struct device *new_dev(struct device *parent, struct device *bus)
static int device_match(struct device *a, struct device *b) static int device_match(struct device *a, struct device *b)
{ {
if ((a->bustype == b->bustype) && (a->bus == b->bus) if ((a->bustype == b->bustype) && (a->parent == b->parent)
&& (a->path_a == b->path_a) && (a->path_b == b->path_b)) && (a->path_a == b->path_a) && (a->path_b == b->path_b))
return 1; return 1;
return 0; return 0;
@ -242,12 +240,12 @@ struct chip *new_chip(char *path)
return new_chip; return new_chip;
} }
struct device *new_device(struct device *parent, struct device *busdev, struct device *new_device(struct device *parent, struct chip *chip,
struct chip *chip, const int bus, const char *devnum, const int bustype, const char *devnum,
int enabled) int enabled)
{ {
struct device *new_d = new_dev(parent, busdev); struct device *new_d = new_dev(parent);
new_d->bustype = bus; new_d->bustype = bustype;
char *tmp; char *tmp;
new_d->path_a = strtol(devnum, &tmp, 16); new_d->path_a = strtol(devnum, &tmp, 16);
@ -274,7 +272,7 @@ struct device *new_device(struct device *parent, struct device *busdev,
lastdev->nextdev = new_d; lastdev->nextdev = new_d;
lastdev = new_d; lastdev = new_d;
switch (bus) { switch (bustype) {
case PCI: case PCI:
new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}"; new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}";
break; break;
@ -332,7 +330,7 @@ void alias_siblings(struct device *d)
while (d) { while (d) {
int link = 0; int link = 0;
struct device *cmp = d->next_sibling; struct device *cmp = d->next_sibling;
while (cmp && (cmp->bus == d->bus) && (cmp->path_a == d->path_a) while (cmp && (cmp->parent == d->parent) && (cmp->path_a == d->path_a)
&& (cmp->path_b == d->path_b)) { && (cmp->path_b == d->path_b)) {
if (!cmp->used) { if (!cmp->used) {
if (device_match(d, cmp)) { if (device_match(d, cmp)) {
@ -468,8 +466,8 @@ static void pass1(FILE *fil, struct device *ptr)
fprintf(fil, "#if !DEVTREE_EARLY\n"); fprintf(fil, "#if !DEVTREE_EARLY\n");
fprintf(fil, "\t.ops = %s,\n", (ptr->ops) ? (ptr->ops) : "0"); fprintf(fil, "\t.ops = %s,\n", (ptr->ops) ? (ptr->ops) : "0");
fprintf(fil, "#endif\n"); fprintf(fil, "#endif\n");
fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->bus->name, fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->parent->name,
ptr->bus->link); ptr->parent->link);
fprintf(fil, "\t.path = {"); fprintf(fil, "\t.path = {");
fprintf(fil, ptr->path, ptr->path_a, ptr->path_b); fprintf(fil, ptr->path, ptr->path_a, ptr->path_b);
fprintf(fil, "},\n"); fprintf(fil, "},\n");

View File

@ -85,7 +85,6 @@ struct device {
struct pci_irq_info pci_irq_info[4]; struct pci_irq_info pci_irq_info[4];
struct device *parent; struct device *parent;
struct device *bus;
struct device *next; struct device *next;
struct device *nextdev; struct device *nextdev;
struct device *children; struct device *children;
@ -110,8 +109,8 @@ void fold_in(struct device *parent);
void postprocess_devtree(void); void postprocess_devtree(void);
struct chip *new_chip(char *path); struct chip *new_chip(char *path);
struct device *new_device(struct device *parent, struct device *busdev, struct device *new_device(struct device *parent, struct chip *chip,
struct chip *chip, const int bus, const char *devnum, const int bustype, const char *devnum,
int enabled); int enabled);
void alias_siblings(struct device *d); void alias_siblings(struct device *d);
void add_resource(struct device *dev, int type, int index, int base); void add_resource(struct device *dev, int type, int index, int base);

View File

@ -85,7 +85,7 @@
int yylex(); int yylex();
void yyerror(const char *s); void yyerror(const char *s);
static struct device *cur_parent, *cur_bus; static struct device *cur_parent;
static struct chip *cur_chip; static struct chip *cur_chip;
@ -487,8 +487,8 @@ static const yytype_uint8 yytranslate[] =
static const yytype_uint8 yyrline[] = static const yytype_uint8 yyrline[] =
{ {
0, 36, 36, 36, 38, 38, 38, 38, 40, 40, 0, 36, 36, 36, 38, 38, 38, 38, 40, 40,
40, 40, 40, 40, 42, 42, 51, 51, 63, 66, 40, 40, 40, 40, 42, 42, 51, 51, 61, 64,
69, 72, 75 67, 70, 73
}; };
#endif #endif
@ -1287,7 +1287,7 @@ yyreduce:
{ {
case 2: case 2:
{ cur_parent = cur_bus = head; } { cur_parent = head; }
break; break;
@ -1318,9 +1318,8 @@ yyreduce:
case 16: case 16:
{ {
(yyval.device) = new_device(cur_parent, cur_bus, cur_chip, (yyvsp[-2].number), (yyvsp[-1].string), (yyvsp[0].number)); (yyval.device) = new_device(cur_parent, cur_chip, (yyvsp[-2].number), (yyvsp[-1].string), (yyvsp[0].number));
cur_parent = (yyval.device); cur_parent = (yyval.device);
cur_bus = (yyval.device);
} }
break; break;
@ -1329,7 +1328,6 @@ yyreduce:
{ {
cur_parent = (yyvsp[-2].device)->parent; cur_parent = (yyvsp[-2].device)->parent;
cur_bus = (yyvsp[-2].device)->bus;
fold_in((yyvsp[-2].device)); fold_in((yyvsp[-2].device));
alias_siblings((yyvsp[-2].device)->children); alias_siblings((yyvsp[-2].device)->children);
} }

View File

@ -20,7 +20,7 @@
int yylex(); int yylex();
void yyerror(const char *s); void yyerror(const char *s);
static struct device *cur_parent, *cur_bus; static struct device *cur_parent;
static struct chip *cur_chip; static struct chip *cur_chip;
%} %}
@ -33,7 +33,7 @@ static struct chip *cur_chip;
%token CHIP DEVICE REGISTER BOOL BUS RESOURCE END EQUALS HEX STRING PCI PNP I2C APIC CPU_CLUSTER CPU DOMAIN IRQ DRQ IO NUMBER SUBSYSTEMID INHERIT IOAPIC_IRQ IOAPIC PCIINT GENERIC SPI USB MMIO %token CHIP DEVICE REGISTER BOOL BUS RESOURCE END EQUALS HEX STRING PCI PNP I2C APIC CPU_CLUSTER CPU DOMAIN IRQ DRQ IO NUMBER SUBSYSTEMID INHERIT IOAPIC_IRQ IOAPIC PCIINT GENERIC SPI USB MMIO
%% %%
devtree: { cur_parent = cur_bus = head; } chip { postprocess_devtree(); } ; devtree: { cur_parent = head; } chip { postprocess_devtree(); } ;
chipchildren: chipchildren device | chipchildren chip | chipchildren registers | /* empty */ ; chipchildren: chipchildren device | chipchildren chip | chipchildren registers | /* empty */ ;
@ -49,13 +49,11 @@ chip: CHIP STRING /* == path */ {
}; };
device: DEVICE BUS NUMBER /* == devnum */ BOOL { device: DEVICE BUS NUMBER /* == devnum */ BOOL {
$<device>$ = new_device(cur_parent, cur_bus, cur_chip, $<number>2, $<string>3, $<number>4); $<device>$ = new_device(cur_parent, cur_chip, $<number>2, $<string>3, $<number>4);
cur_parent = $<device>$; cur_parent = $<device>$;
cur_bus = $<device>$;
} }
devicechildren END { devicechildren END {
cur_parent = $<device>5->parent; cur_parent = $<device>5->parent;
cur_bus = $<device>5->bus;
fold_in($<device>5); fold_in($<device>5);
alias_siblings($<device>5->children); alias_siblings($<device>5->children);
}; };