util/sconfig: Re-factor sconfig to not assume chip as device

This change adds a new structure "struct chip" to identify elements of
type chip rather than re-using the structure for device. Until now
chip was treated as a device while generating the parse tree and then
device tree postprocessing skipped over all the chip entries in
children and sibling pointers of device nodes.

With this change, the device tree will only contain struct device in
the parsed tree. It helps by avoiding unnecessary pointers to chip
structure as children or next_sibling and then skipping those elements
in post processing. Every device can then hold a pointer to its chip.

When generating static.c, chip structure is emitted before device
structure to ensure that the device structure has chip within its
scope. Externally, the only visible change in static.c should be the
order in which chip/device elements are emitted i.e. previously all
chips under a particular device were emitted to static.c and then the
devices using those chips. Now, all chips are emitted before all the
devices in static.c

BUG=b:80081934
TEST=Verified that abuild is successful for all boards. Also, verified
that static.c generated for eve, kahlee, scarlet, asrock imb_a180 is
unchanged from before in node definitions.

Change-Id: I255092f527c8eecb144385eb681df20e54caf8f5
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/26720
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/util/sconfig/sconfig.tab.c_shipped b/util/sconfig/sconfig.tab.c_shipped
index 1832f35..637927a 100644
--- a/util/sconfig/sconfig.tab.c_shipped
+++ b/util/sconfig/sconfig.tab.c_shipped
@@ -86,6 +86,7 @@
 void yyerror(const char *s);
 
 static struct device *cur_parent, *cur_bus;
+static struct chip *cur_chip;
 
 
 
@@ -164,6 +165,7 @@
 
 
 	struct device *device;
+	struct chip *chip;
 	char *string;
 	int number;
 
@@ -484,9 +486,9 @@
   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
 static const yytype_uint8 yyrline[] =
 {
-       0,    34,    34,    34,    36,    36,    36,    36,    38,    38,
-      38,    38,    38,    38,    40,    40,    50,    50,    62,    65,
-      68,    71,    74
+       0,    36,    36,    36,    38,    38,    38,    38,    40,    40,
+      40,    40,    40,    40,    42,    42,    52,    52,    64,    67,
+      70,    73,    76
 };
 #endif
 
@@ -1298,8 +1300,9 @@
   case 14:
 
     {
-	(yyval.device) = new_chip(cur_parent, cur_bus, (yyvsp[0].string));
-	cur_parent = (yyval.device);
+	(yyval.chip) = new_chip((yyvsp[0].string));
+	chip_enqueue_tail(cur_chip);
+	cur_chip = (yyval.chip);
 }
 
     break;
@@ -1307,9 +1310,8 @@
   case 15:
 
     {
-	cur_parent = (yyvsp[-2].device)->parent;
-	fold_in((yyvsp[-2].device));
-	add_header((yyvsp[-2].device));
+	cur_chip = chip_dequeue_tail();
+	add_header((yyvsp[-2].chip));
 }
 
     break;
@@ -1317,7 +1319,7 @@
   case 16:
 
     {
-	(yyval.device) = new_device(cur_parent, cur_bus, (yyvsp[-2].number), (yyvsp[-1].string), (yyvsp[0].number));
+	(yyval.device) = new_device(cur_parent, cur_bus, cur_chip, (yyvsp[-2].number), (yyvsp[-1].string), (yyvsp[0].number));
 	cur_parent = (yyval.device);
 	cur_bus = (yyval.device);
 }
@@ -1343,7 +1345,7 @@
 
   case 19:
 
-    { add_register(cur_parent, (yyvsp[-2].string), (yyvsp[0].string)); }
+    { add_register(cur_chip, (yyvsp[-2].string), (yyvsp[0].string)); }
 
     break;