[coreboot-gerrit] Change in coreboot[master]: util/sconfig: Get rid of next pointer in struct device

Furquan Shaikh (Code Review) gerrit at coreboot.org
Mon Jun 4 02:49:53 CEST 2018


Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/26804


Change subject: util/sconfig: Get rid of next pointer in struct device
......................................................................

util/sconfig: Get rid of next pointer in struct device

next pointer in struct device is used for adding ".next" field for a
device while generating static.c. Now that we are using breadth-first
walk to walk the device tree, bfs_queue can be used to determine what
the next node is in the queue and add that to ".next" field.

Additionally, if there is no node left in the bfs_queue, then current
node is the last device in the list. It can be set to last_dev
variable.

This change gets rid of "next" pointer in struct device and uses
bfs_queue to determine the ".next" field for any given node. It also
eliminates the need of having a "lastnode" variable.

BUG=b:80081934
TEST=Verified that all boards build successfully using abuild and
static.c generated with and without this CL differs only in the order
of .next list. The reason for the difference is that the traversal
order was different earlier.

Change-Id: Ic54a0d5c799baa222bb1ddba01726ee5d29c0cd5
Signed-off-by: Furquan Shaikh <furquan at google.com>
---
M util/sconfig/main.c
M util/sconfig/sconfig.h
M util/sconfig/sconfig.tab.c_shipped
M util/sconfig/sconfig.y
4 files changed, 30 insertions(+), 22 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/04/26804/1

diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index d60fb03..7540fc5 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -20,9 +20,8 @@
 
 extern int linenum;
 
-struct device *head, *lastnode;
-
 static struct chip chip_header;
+struct device *tree_root;
 
 /*
  * This is intentionally shared between chip and device structure ids because it
@@ -152,6 +151,14 @@
 	return data;
 }
 
+static void *peek_queue_head(struct queue *queue)
+{
+	if (!queue)
+		return NULL;
+
+	return queue->data;
+}
+
 static struct queue *chip_queue;
 
 void chip_enqueue_tail(void *data)
@@ -172,8 +179,6 @@
 	dev->parent = parent;
 	dev->subsystem_vendor = -1;
 	dev->subsystem_device = -1;
-	head->next = dev;
-	head = dev;
 	return dev;
 }
 
@@ -448,9 +453,6 @@
 	if (device_has_instance(parent) && !parent->last_instance->children)
 		parent->last_instance->children = new_d;
 
-	lastnode->next = new_d;
-	lastnode = new_d;
-
 	switch (bustype) {
 	case PCI:
 		new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}";
@@ -591,7 +593,7 @@
 	dev->pci_irq_info[srcpin].ioapic_dst_id = apicid;
 }
 
-static void pass0(FILE * fil, struct device *ptr)
+static void pass0(FILE * fil, struct device *ptr, struct device *next)
 {
 	if (ptr->id == 0) {
 		fprintf(fil, "DEVTREE_CONST struct bus %s_links[];\n",
@@ -606,6 +608,12 @@
 	if (ptr->children || device_has_instance(ptr))
 			fprintf(fil, "DEVTREE_CONST struct bus %s_links[];\n",
 				ptr->name);
+
+	if (next)
+		return;
+
+	fprintf(fil, "DEVTREE_CONST struct device * DEVTREE_CONST last_dev = &%s;\n",
+		ptr->name);
 }
 
 static void emit_resources(FILE *fil, struct device *ptr)
@@ -683,7 +691,7 @@
 	fprintf(fil, "\t};\n");
 }
 
-static void pass1(FILE * fil, struct device *ptr)
+static void pass1(FILE * fil, struct device *ptr, struct device *next)
 {
 	int pin;
 	struct chip_instance *chip_ins = ptr->chip_instance;
@@ -738,8 +746,8 @@
 	if (chip_ins->chip->chiph_exists)
 		fprintf(fil, "\t.chip_info = &%s_info_%d,\n",
 			chip_ins->chip->name_underscore, chip_ins->id);
-	if (ptr->next)
-		fprintf(fil, "\t.next=&%s\n", ptr->next->name);
+	if (next)
+		fprintf(fil, "\t.next=&%s\n", next->name);
 	fprintf(fil, "};\n");
 
 	emit_resources(fil, ptr);
@@ -773,15 +781,17 @@
 }
 
 static void walk_device_tree(FILE * fil, struct device *ptr,
-			     void (*func) (FILE *, struct device *))
+			     void (*func) (FILE *, struct device *,
+					   struct device *))
 {
 	struct queue *bfs_queue = NULL;
+	struct device *tmp;
 
 	enqueue_tail(&bfs_queue, ptr);
 
 	while ((ptr = dequeue_head(&bfs_queue))) {
 		add_children_to_queue(&bfs_queue, ptr);
-		func(fil, ptr);
+		func(fil, ptr, peek_queue_head(bfs_queue));
 	}
 }
 
@@ -848,7 +858,8 @@
 	}
 }
 
-static void inherit_subsystem_ids(FILE * file, struct device *dev)
+static void inherit_subsystem_ids(FILE * file, struct device *dev,
+				  struct device *next)
 {
 	struct device *p;
 
@@ -899,7 +910,7 @@
 
 	yyrestart(filec);
 
-	lastnode = head = &root;
+	tree_root = &root;
 
 	yyparse();
 
@@ -918,9 +929,7 @@
 	walk_device_tree(autogen, &root, inherit_subsystem_ids);
 	fprintf(autogen, "\n/* pass 0 */\n");
 	walk_device_tree(autogen, &root, pass0);
-	fprintf(autogen, "\n/* pass 1 */\n"
-		"DEVTREE_CONST struct device * DEVTREE_CONST last_dev = &%s;\n",
-		lastnode->name);
+	fprintf(autogen, "\n/* pass 1 */\n");
 	walk_device_tree(autogen, &root, pass1);
 
 	fclose(autogen);
diff --git a/util/sconfig/sconfig.h b/util/sconfig/sconfig.h
index 76913c5..e4f2270 100644
--- a/util/sconfig/sconfig.h
+++ b/util/sconfig/sconfig.h
@@ -108,7 +108,6 @@
 	 */
 	int linknum;
 
-	struct device *next;
 	struct device *children;
 	struct device *latestchild;
 	struct device *next_sibling;
@@ -123,7 +122,7 @@
 	struct dev_instance *last_instance;
 };
 
-extern struct device *head;
+extern struct device *tree_root;
 
 void fold_in(struct device *parent);
 
diff --git a/util/sconfig/sconfig.tab.c_shipped b/util/sconfig/sconfig.tab.c_shipped
index 61f3b50..152e70d 100644
--- a/util/sconfig/sconfig.tab.c_shipped
+++ b/util/sconfig/sconfig.tab.c_shipped
@@ -1287,7 +1287,7 @@
     {
         case 2:
 
-    { cur_parent = head; }
+    { cur_parent = tree_root; }
 
     break;
 
diff --git a/util/sconfig/sconfig.y b/util/sconfig/sconfig.y
index 37ac95f..48a727f 100755
--- a/util/sconfig/sconfig.y
+++ b/util/sconfig/sconfig.y
@@ -33,7 +33,7 @@
 
 %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 = head; } chip { postprocess_devtree(); } ;
+devtree: { cur_parent = tree_root; } chip { postprocess_devtree(); } ;
 
 chipchildren: chipchildren device | chipchildren chip | chipchildren registers | /* empty */ ;
 

-- 
To view, visit https://review.coreboot.org/26804
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic54a0d5c799baa222bb1ddba01726ee5d29c0cd5
Gerrit-Change-Number: 26804
Gerrit-PatchSet: 1
Gerrit-Owner: Furquan Shaikh <furquan at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180604/a117579c/attachment-0001.html>


More information about the coreboot-gerrit mailing list