Make the device tree available in the rom stage

We thought about two ways to do this change. The way we decided to try
was to
1. drop all ops from devices in romstage
2. constify all devices in romstage (make them read-only) so we can
   compile static.c into romstage
3. the device tree "devices" can be used to read configuration from
   the device tree (and nothing else, really)
4. the device tree devices are accessed through struct device * in
   romstage only. device_t stays the typedef to int in romstage
5. Use the same static.c file in ramstage and romstage

We declare structs as follows:
ROMSTAGE_CONST struct bus dev_root_links[];
ROMSTAGE_CONST is const in romstage and empty in ramstage; This
forces all of the device tree into the text area.

So a struct looks like this:
static ROMSTAGE_CONST struct device _dev21 = {
 #ifndef __PRE_RAM__
        .ops = 0,
 #endif
        .bus = &_dev7_links[0],
        .path = {.type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x1c,3)}}},
        .enabled = 0,
        .on_mainboard = 1,
        .subsystem_vendor = 0x1ae0,
        .subsystem_device = 0xc000,
        .link_list = NULL,
        .sibling = &_dev22,
 #ifndef __PRE_RAM__
        .chip_ops = &southbridge_intel_bd82x6x_ops,
 #endif
        .chip_info = &southbridge_intel_bd82x6x_info_10,
        .next=&_dev22
};

Change-Id: I722454d8d3c40baf7df989f5a6891f6ba7db5727
Signed-off-by: Ronald G. Minnich <rminnich@chromium.org>
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/1398
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 0b15ac5..b44a551 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -2,11 +2,12 @@
 #define DEVICE_H
 
 #include <stdint.h>
+#include <stddef.h>
 #include <device/resource.h>
 #include <device/path.h>
 
-
 struct device;
+#ifndef __PRE_RAM__
 typedef struct device * device_t;
 struct pci_operations;
 struct pci_bus_operations;
@@ -42,12 +43,14 @@
 	const struct smbus_bus_operations *ops_smbus_bus;
 	const struct pci_bus_operations *ops_pci_bus;
 };
+#endif
 
 
 struct bus {
-	device_t 	dev;		/* This bridge device */
-	device_t 	children;	/* devices behind this bridge */
-	struct bus	*next;		/* The next bridge on this device */
+
+	ROMSTAGE_CONST struct device * 	dev;		/* This bridge device */
+	ROMSTAGE_CONST struct device * 	children;	/* devices behind this bridge */
+	ROMSTAGE_CONST struct bus	*next;		/* The next bridge on this device */
 	unsigned	bridge_ctrl;	/* Bridge control register */
 	unsigned char	link_num;	/* The index of this link */
 	uint16_t	secondary; 	/* secondary bus number */
@@ -70,10 +73,12 @@
 };
 
 struct device {
-	struct bus *	bus;		/* bus this device is on, for bridge
+	ROMSTAGE_CONST struct bus *	bus;		/* bus this device is on, for bridge
 					 * devices, it is the up stream bus */
-	device_t	sibling;	/* next device on this bus */
-	device_t	next;		/* chain of all devices */
+
+	ROMSTAGE_CONST struct device *	sibling;	/* next device on this bus */
+
+	ROMSTAGE_CONST struct device *	next;		/* chain of all devices */
 
 	struct device_path path;
 	unsigned 	vendor;
@@ -89,23 +94,24 @@
 	u8 command;
 
 	/* Base registers for this device. I/O, MEM and Expansion ROM */
-	struct resource *resource_list;
+	ROMSTAGE_CONST struct resource *resource_list;
 
 	/* links are (downstream) buses attached to the device, usually a leaf
 	 * device with no children has 0 buses attached and a bridge has 1 bus
 	 */
-	struct bus *link_list;
+	ROMSTAGE_CONST struct bus *link_list;
 
 	struct device_operations *ops;
 	const struct chip_operations *chip_ops;
-	void *chip_info;
+	ROMSTAGE_CONST void *chip_info;
 };
 
 /**
  * This is the root of the device tree. The device tree is defined in the
  * static.c file and is generated by the config tool at compile time.
  */
-extern struct device	dev_root;
+extern ROMSTAGE_CONST struct device	dev_root;
+#ifndef __PRE_RAM__
 extern struct device	*all_devices;	/* list of all devices */
 
 extern struct resource	*free_resources;
@@ -195,5 +201,10 @@
 
 void tolm_test(void *gp, struct device *dev, struct resource *new);
 u32 find_pci_tolm(struct bus *bus);
-
+#else
+ROMSTAGE_CONST struct device * dev_find_slot (unsigned int bus,
+						unsigned int devfn);
+ROMSTAGE_CONST struct device * dev_find_slot_on_smbus (unsigned int bus,
+							unsigned int addr);
+#endif
 #endif /* DEVICE_H */