<p>Furquan Shaikh has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/26804">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">util/sconfig: Get rid of next pointer in struct device<br><br>next pointer in struct device is used for adding ".next" field for a<br>device while generating static.c. Now that we are using breadth-first<br>walk to walk the device tree, bfs_queue can be used to determine what<br>the next node is in the queue and add that to ".next" field.<br><br>Additionally, if there is no node left in the bfs_queue, then current<br>node is the last device in the list. It can be set to last_dev<br>variable.<br><br>This change gets rid of "next" pointer in struct device and uses<br>bfs_queue to determine the ".next" field for any given node. It also<br>eliminates the need of having a "lastnode" variable.<br><br>BUG=b:80081934<br>TEST=Verified that all boards build successfully using abuild and<br>static.c generated with and without this CL differs only in the order<br>of .next list. The reason for the difference is that the traversal<br>order was different earlier.<br><br>Change-Id: Ic54a0d5c799baa222bb1ddba01726ee5d29c0cd5<br>Signed-off-by: Furquan Shaikh <furquan@google.com><br>---<br>M util/sconfig/main.c<br>M util/sconfig/sconfig.h<br>M util/sconfig/sconfig.tab.c_shipped<br>M util/sconfig/sconfig.y<br>4 files changed, 30 insertions(+), 22 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/04/26804/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/util/sconfig/main.c b/util/sconfig/main.c</span><br><span>index d60fb03..7540fc5 100644</span><br><span>--- a/util/sconfig/main.c</span><br><span>+++ b/util/sconfig/main.c</span><br><span>@@ -20,9 +20,8 @@</span><br><span> </span><br><span> extern int linenum;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-struct device *head, *lastnode;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static struct chip chip_header;</span><br><span style="color: hsl(120, 100%, 40%);">+struct device *tree_root;</span><br><span> </span><br><span> /*</span><br><span>  * This is intentionally shared between chip and device structure ids because it</span><br><span>@@ -152,6 +151,14 @@</span><br><span>      return data;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void *peek_queue_head(struct queue *queue)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!queue)</span><br><span style="color: hsl(120, 100%, 40%);">+           return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        return queue->data;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct queue *chip_queue;</span><br><span> </span><br><span> void chip_enqueue_tail(void *data)</span><br><span>@@ -172,8 +179,6 @@</span><br><span>      dev->parent = parent;</span><br><span>     dev->subsystem_vendor = -1;</span><br><span>       dev->subsystem_device = -1;</span><br><span style="color: hsl(0, 100%, 40%);">-  head->next = dev;</span><br><span style="color: hsl(0, 100%, 40%);">-    head = dev;</span><br><span>  return dev;</span><br><span> }</span><br><span> </span><br><span>@@ -448,9 +453,6 @@</span><br><span>   if (device_has_instance(parent) && !parent->last_instance->children)</span><br><span>           parent->last_instance->children = new_d;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-      lastnode->next = new_d;</span><br><span style="color: hsl(0, 100%, 40%);">-      lastnode = new_d;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>    switch (bustype) {</span><br><span>   case PCI:</span><br><span>            new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}";</span><br><span>@@ -591,7 +593,7 @@</span><br><span>      dev->pci_irq_info[srcpin].ioapic_dst_id = apicid;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void pass0(FILE * fil, struct device *ptr)</span><br><span style="color: hsl(120, 100%, 40%);">+static void pass0(FILE * fil, struct device *ptr, struct device *next)</span><br><span> {</span><br><span>  if (ptr->id == 0) {</span><br><span>               fprintf(fil, "DEVTREE_CONST struct bus %s_links[];\n",</span><br><span>@@ -606,6 +608,12 @@</span><br><span>      if (ptr->children || device_has_instance(ptr))</span><br><span>                    fprintf(fil, "DEVTREE_CONST struct bus %s_links[];\n",</span><br><span>                             ptr->name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      if (next)</span><br><span style="color: hsl(120, 100%, 40%);">+             return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     fprintf(fil, "DEVTREE_CONST struct device * DEVTREE_CONST last_dev = &%s;\n",</span><br><span style="color: hsl(120, 100%, 40%);">+           ptr->name);</span><br><span> }</span><br><span> </span><br><span> static void emit_resources(FILE *fil, struct device *ptr)</span><br><span>@@ -683,7 +691,7 @@</span><br><span>   fprintf(fil, "\t};\n");</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void pass1(FILE * fil, struct device *ptr)</span><br><span style="color: hsl(120, 100%, 40%);">+static void pass1(FILE * fil, struct device *ptr, struct device *next)</span><br><span> {</span><br><span>     int pin;</span><br><span>     struct chip_instance *chip_ins = ptr->chip_instance;</span><br><span>@@ -738,8 +746,8 @@</span><br><span>        if (chip_ins->chip->chiph_exists)</span><br><span>              fprintf(fil, "\t.chip_info = &%s_info_%d,\n",</span><br><span>                  chip_ins->chip->name_underscore, chip_ins->id);</span><br><span style="color: hsl(0, 100%, 40%);">-        if (ptr->next)</span><br><span style="color: hsl(0, 100%, 40%);">-               fprintf(fil, "\t.next=&%s\n", ptr->next->name);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (next)</span><br><span style="color: hsl(120, 100%, 40%);">+             fprintf(fil, "\t.next=&%s\n", next->name);</span><br><span>  fprintf(fil, "};\n");</span><br><span> </span><br><span>  emit_resources(fil, ptr);</span><br><span>@@ -773,15 +781,17 @@</span><br><span> }</span><br><span> </span><br><span> static void walk_device_tree(FILE * fil, struct device *ptr,</span><br><span style="color: hsl(0, 100%, 40%);">-                           void (*func) (FILE *, struct device *))</span><br><span style="color: hsl(120, 100%, 40%);">+                       void (*func) (FILE *, struct device *,</span><br><span style="color: hsl(120, 100%, 40%);">+                                      struct device *))</span><br><span> {</span><br><span>    struct queue *bfs_queue = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+       struct device *tmp;</span><br><span> </span><br><span>      enqueue_tail(&bfs_queue, ptr);</span><br><span> </span><br><span>       while ((ptr = dequeue_head(&bfs_queue))) {</span><br><span>               add_children_to_queue(&bfs_queue, ptr);</span><br><span style="color: hsl(0, 100%, 40%);">-             func(fil, ptr);</span><br><span style="color: hsl(120, 100%, 40%);">+               func(fil, ptr, peek_queue_head(bfs_queue));</span><br><span>  }</span><br><span> }</span><br><span> </span><br><span>@@ -848,7 +858,8 @@</span><br><span>     }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void inherit_subsystem_ids(FILE * file, struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+static void inherit_subsystem_ids(FILE * file, struct device *dev,</span><br><span style="color: hsl(120, 100%, 40%);">+                                struct device *next)</span><br><span> {</span><br><span>  struct device *p;</span><br><span> </span><br><span>@@ -899,7 +910,7 @@</span><br><span> </span><br><span>      yyrestart(filec);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   lastnode = head = &root;</span><br><span style="color: hsl(120, 100%, 40%);">+  tree_root = &root;</span><br><span> </span><br><span>   yyparse();</span><br><span> </span><br><span>@@ -918,9 +929,7 @@</span><br><span>         walk_device_tree(autogen, &root, inherit_subsystem_ids);</span><br><span>         fprintf(autogen, "\n/* pass 0 */\n");</span><br><span>      walk_device_tree(autogen, &root, pass0);</span><br><span style="color: hsl(0, 100%, 40%);">-    fprintf(autogen, "\n/* pass 1 */\n"</span><br><span style="color: hsl(0, 100%, 40%);">-           "DEVTREE_CONST struct device * DEVTREE_CONST last_dev = &%s;\n",</span><br><span style="color: hsl(0, 100%, 40%);">-          lastnode->name);</span><br><span style="color: hsl(120, 100%, 40%);">+   fprintf(autogen, "\n/* pass 1 */\n");</span><br><span>      walk_device_tree(autogen, &root, pass1);</span><br><span> </span><br><span>     fclose(autogen);</span><br><span>diff --git a/util/sconfig/sconfig.h b/util/sconfig/sconfig.h</span><br><span>index 76913c5..e4f2270 100644</span><br><span>--- a/util/sconfig/sconfig.h</span><br><span>+++ b/util/sconfig/sconfig.h</span><br><span>@@ -108,7 +108,6 @@</span><br><span>   */</span><br><span>  int linknum;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        struct device *next;</span><br><span>         struct device *children;</span><br><span>     struct device *latestchild;</span><br><span>  struct device *next_sibling;</span><br><span>@@ -123,7 +122,7 @@</span><br><span>   struct dev_instance *last_instance;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-extern struct device *head;</span><br><span style="color: hsl(120, 100%, 40%);">+extern struct device *tree_root;</span><br><span> </span><br><span> void fold_in(struct device *parent);</span><br><span> </span><br><span>diff --git a/util/sconfig/sconfig.tab.c_shipped b/util/sconfig/sconfig.tab.c_shipped</span><br><span>index 61f3b50..152e70d 100644</span><br><span>--- a/util/sconfig/sconfig.tab.c_shipped</span><br><span>+++ b/util/sconfig/sconfig.tab.c_shipped</span><br><span>@@ -1287,7 +1287,7 @@</span><br><span>     {</span><br><span>         case 2:</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    { cur_parent = head; }</span><br><span style="color: hsl(120, 100%, 40%);">+    { cur_parent = tree_root; }</span><br><span> </span><br><span>     break;</span><br><span> </span><br><span>diff --git a/util/sconfig/sconfig.y b/util/sconfig/sconfig.y</span><br><span>index 37ac95f..48a727f 100755</span><br><span>--- a/util/sconfig/sconfig.y</span><br><span>+++ b/util/sconfig/sconfig.y</span><br><span>@@ -33,7 +33,7 @@</span><br><span> </span><br><span> %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</span><br><span> %%</span><br><span style="color: hsl(0, 100%, 40%);">-devtree: { cur_parent = head; } chip { postprocess_devtree(); } ;</span><br><span style="color: hsl(120, 100%, 40%);">+devtree: { cur_parent = tree_root; } chip { postprocess_devtree(); } ;</span><br><span> </span><br><span> chipchildren: chipchildren device | chipchildren chip | chipchildren registers | /* empty */ ;</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/26804">change 26804</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/26804"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ic54a0d5c799baa222bb1ddba01726ee5d29c0cd5 </div>
<div style="display:none"> Gerrit-Change-Number: 26804 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Furquan Shaikh <furquan@google.com> </div>