Author: myles
Date: 2008-11-14 17:15:33 +0100 (Fri, 14 Nov 2008)
New Revision: 1024

Modified:
   coreboot-v3/device/device.c
   coreboot-v3/device/device_util.c
   coreboot-v3/include/device/device.h
   coreboot-v3/include/device/path.h
   coreboot-v3/lib/stage2.c
Log:
This patch adds some debug functions, cleans up whitespace (per indent), and 
adds const in a few places.

include/device/path.h
        Make path_eq take const path*.
        
include/device/device.h
        Use const with dev_path, dev_id_string, bus_path, find_dev_path,
        andalloc_find.

device/device.c
        Add functions for tree printing of devs and resources.
        Change %p to more useful info.

device/device_util.c
        Use const changes from device.h.

lib/stage2.c
        Use updated printing functions.

Signed-off-by: Myles Watson <[EMAIL PROTECTED]>
Acked-by: Ronald G. Minnich <[EMAIL PROTECTED]>


Modified: coreboot-v3/device/device.c
===================================================================
--- coreboot-v3/device/device.c 2008-11-14 15:58:59 UTC (rev 1023)
+++ coreboot-v3/device/device.c 2008-11-14 16:15:33 UTC (rev 1024)
@@ -71,7 +71,6 @@
  */
 static int devcnt;
 
-
 /**
  * The device creator.
  *
@@ -86,7 +85,7 @@
 
        printk(BIOS_SPEW, "%s: devcnt %d\n", __FUNCTION__, devcnt);
        /* Should we really die here? */
-       if (devcnt>=MAX_DEVICES) {
+       if (devcnt >= MAX_DEVICES) {
                die("Too many devices. Increase MAX_DEVICES\n");
        }
 
@@ -101,7 +100,8 @@
  * @param dev Pointer to the newly created device structure.
  * @param ops Pointer to device_operations
  */
-void default_device_constructor(struct device *dev, const struct 
device_operations *ops)
+void default_device_constructor(struct device *dev,
+                               const struct device_operations *ops)
 {
        printk(BIOS_DEBUG, "default device constructor called\n");
        dev->ops = ops;
@@ -121,11 +121,11 @@
        int i;
 
        for (i = 0; all_device_operations[i]; i++) {
-               printk(BIOS_SPEW, "%s: check all_device_operations[i] %p\n",
-                      __func__, all_device_operations[i]);
+               printk(BIOS_SPEW, "%s: check all_device_operations[%d]\n",
+                      __func__, i);
                c = all_device_operations[i];
-               printk(BIOS_SPEW, "%s: cons %p, cons id %s\n",
-                      __func__, c, dev_id_string(&c->id));
+               printk(BIOS_SPEW, "%s: cons id %s\n",
+                      __func__, dev_id_string(&c->id));
                if (id_eq(&c->id, id)) {
                        printk(BIOS_SPEW, "%s: match\n", __func__);
                        return c;
@@ -184,17 +184,18 @@
        if (!c)
                c = find_device_operations(&dev->id);
 
-       printk(BIOS_SPEW, "%s: constructor is %p\n", __func__, c);
+       if (c) {
+               printk(BIOS_SPEW, "%s: constructor has ID %s\n", __func__,
+                      dev_id_string(&c->id));
 
-       if(c) {
-               if(c->constructor)
+               if (c->constructor)
                        c->constructor(dev, c);
                else
                        default_device_constructor(dev, c);
-       }
-       else
-               printk(BIOS_INFO, "No ops found and no constructor called for 
%s.\n",
-                       dev_id_string(&dev->id));
+       } else
+               printk(BIOS_INFO,
+                      "No ops found and no constructor called for %s.\n",
+                      dev_id_string(&dev->id));
 }
 
 spin_define(dev_lock);
@@ -217,7 +218,7 @@
        spin_lock(&dev_lock);
 
        /* Find the last child of our parent. */
-       for (child = parent->children; child && child->sibling; /* */) {
+       for (child = parent->children; child && child->sibling; /* */ ) {
                child = child->sibling;
        }
 
@@ -261,7 +262,7 @@
 
        constructor(dev);
 
-out:
+      out:
        spin_unlock(&dev_lock);
        return dev;
 }
@@ -290,10 +291,10 @@
                int i;
                printk(BIOS_SPEW,
                       "%s: %s(%s) dtsname %s have_resources %d enabled %d\n",
-                       __func__, bus->dev? bus->dev->dtsname : "NOBUSDEV",
-                       bus->dev ? dev_path(bus->dev) : "NOBUSDEV",
-                       curdev->dtsname,
-                       curdev->have_resources, curdev->enabled);
+                      __func__, bus->dev ? bus->dev->dtsname : "NOBUSDEV",
+                      bus->dev ? dev_path(bus->dev) : "NOBUSDEV",
+                      curdev->dtsname,
+                      curdev->have_resources, curdev->enabled);
                if (curdev->have_resources) {
                        continue;
                }
@@ -311,7 +312,7 @@
 
                /* Read in subtractive resources behind the current device. */
                links = 0;
-               for (i = 0; i < curdev->resources; i++) {
+               for (i = 0; i < curdev->resources && (curdev->links > 0); i++) {
                        struct resource *resource;
                        unsigned int link;
                        resource = &curdev->resource[i];
@@ -380,8 +381,8 @@
        struct pick_largest_state state;
 
        state.last = *result_res;
-       state.result_dev = 0;
-       state.result = 0;
+       state.result_dev = NULL;
+       state.result = NULL;
        state.seen_last = 0;
 
        search_bus_resources(bus, type_mask, type, pick_largest_resource,
@@ -434,10 +435,12 @@
        base = bridge->base;
 
        printk(BIOS_SPEW,
-              "%s compute_allocate_%s: base: %08llx size: %08llx align: %d 
gran: %d\n",
+              "%s compute_allocate_%s: base: %08llx size: %08llx align: %d 
gran: %d limit: %08llx\n",
               dev_path(bus->dev),
-              (bridge->flags & IORESOURCE_IO) ? "io" : (bridge->flags & 
IORESOURCE_PREFETCH) ? "prefmem" : "mem",
-              base, bridge->size, bridge->align, bridge->gran);
+              (bridge->flags & IORESOURCE_IO) ? "io" : (bridge->flags &
+                                                        IORESOURCE_PREFETCH) ?
+              "prefmem" : "mem", base, bridge->size, bridge->align,
+              bridge->gran, bridge->limit);
 
        /* We want different minimum alignments for different kinds of
         * resources. These minimums are not device type specific but
@@ -454,7 +457,7 @@
        read_resources(bus);
 
        /* Remember we haven't found anything yet. */
-       resource = 0;
+       resource = NULL;
 
        /* Walk through all the devices on the current bus and
         * compute the addresses.
@@ -542,8 +545,10 @@
        printk(BIOS_SPEW,
               "%s compute_allocate_%s: base: %08llx size: %08llx align: %d 
gran: %d done\n",
               dev_path(bus->dev),
-              (bridge->flags & IORESOURCE_IO) ? "io" : (bridge->flags & 
IORESOURCE_PREFETCH) ? "prefmem" : "mem",
-              base, bridge->size, bridge->align, bridge->gran);
+              (bridge->flags & IORESOURCE_IO) ? "io" : (bridge->flags &
+                                                        IORESOURCE_PREFETCH) ?
+              "prefmem" : "mem", base, bridge->size, bridge->align,
+              bridge->gran);
 }
 
 #ifdef CONFIG_PCI_OPTION_ROM_RUN
@@ -754,12 +759,12 @@
        printk(BIOS_DEBUG, "Phase 2: Early setup...\n");
        for (dev = all_devices; dev; dev = dev->next) {
                printk(BIOS_SPEW,
-                       "%s: dev %s: ops %p ops->phase2_fixup %p\n",
-                       __FUNCTION__, dev->dtsname, dev->ops,
-                       dev->ops? dev->ops->phase2_fixup : NULL);
+                      "%s: dev %s: ops %sNULL ops->phase2_fixup %s\n",
+                      __FUNCTION__, dev->dtsname, dev->ops ? "NOT " : "",
+                      dev->ops ? (dev->ops->phase2_fixup ? "NOT NULL" : "NULL")
+                      : "N/A");
                if (dev->ops && dev->ops->phase2_fixup) {
-                       printk(BIOS_SPEW,
-                              "Calling phase2 phase2_fixup...\n");
+                       printk(BIOS_SPEW, "Calling phase2 phase2_fixup...\n");
                        dev->ops->phase2_fixup(dev);
                        printk(BIOS_SPEW, "phase2_fixup done\n");
                }
@@ -788,10 +793,11 @@
        post_code(POST_STAGE2_PHASE3_SCAN_ENTER);
        if (!busdevice || !busdevice->enabled ||
            !busdevice->ops || !busdevice->ops->phase3_scan) {
-               printk(BIOS_INFO, "%s: %s: busdevice %p enabled %d ops %p\n",
-                      __FUNCTION__, busdevice->dtsname, busdevice,
+               printk(BIOS_INFO, "%s: busdevice %s: enabled %d ops %s\n",
+                      __FUNCTION__, busdevice ? busdevice->dtsname : "NULL",
                       busdevice ? busdevice->enabled : 0,
-                      busdevice ? busdevice->ops : NULL);
+                      busdevice ? (busdevice->ops?
+                                   "NOT NULL" : "NULL") : "N/A");
                printk(BIOS_INFO, "%s: can not scan from here, returning %d\n",
                       __FUNCTION__, max);
                return max;
@@ -824,16 +830,14 @@
 /**
  * Determine the existence of devices and extend the device tree.
  *
- * Most of the devices in the system are listed in the mainboard Config.lb
+ * Most of the devices in the system are listed in the mainboard dts
  * file. The device structures for these devices are generated at compile
- * time by the config tool and are organized into the device tree. This
- * function determines if the devices created at compile time actually exist
- * in the physical system.
- * TODO: Fix comment, v3 doesn't have Config.lb files.
+ * time by the config tool and are organized into the device tree, 
statictree.c.
+ * This function determines if the devices created at compile time actually
+ * exist in the physical system.
  *
- * For devices in the physical system but not listed in the Config.lb file,
- * the device structures have to be created at run time and attached to the
- * device tree.
+ * For devices in the physical system but not listed in the dts, the device
+ * structures have to be created at run time and attached to the device tree.
  *
  * This function starts from the root device 'dev_root', scan the buses in
  * the system recursively, modify the device tree according to the result of
@@ -870,6 +874,51 @@
        printk(BIOS_INFO, "Phase 3: Done.\n");
 }
 
+void resource_tree(const struct device *const root, int debug_level, int depth)
+{
+       int i = 0, link = 0;
+       const struct device const *child;
+       char indent[30];        /* If your tree has more levels, it's wrong. */
+
+       for (i = 0; i < depth + 1 && i < 29; i++)
+               indent[i] = ' ';
+       indent[i] = '\0';
+
+       printk(BIOS_DEBUG, "%s%s links %x child on link 0 %s\n",
+              indent, dev_path(root), root->links,
+              root->link[0].children ? root->link[0].children->
+              dtsname : "NULL");
+       for (i = 0; i < root->resources; i++) {
+               printk(BIOS_DEBUG,
+                      "%s%s resource base %llx size %llx align %x gran %x 
limit %llx flags %lx index %lx\n",
+                      indent, dev_path(root), root->resource[i].base,
+                      root->resource[i].size, root->resource[i].align,
+                      root->resource[i].gran, root->resource[i].limit,
+                      root->resource[i].flags, root->resource[i].index);
+       }
+
+       for (link = 0; link < root->links; link++) {
+               for (child = root->link[link].children; child;
+                    child = child->sibling)
+                       resource_tree(child, debug_level, depth + 1);
+       }
+}
+
+void print_resource_tree(const struct device *const root, int debug_level,
+                        const char *msg)
+{
+       /* Bail if root is null. */
+       if (!root) {
+               printk(debug_level, "%s passed NULL for root!\n", __func__);
+               return;
+       }
+
+       /* Bail if not printing to screen. */
+       if (!printk(debug_level, "Show all resources in tree form...%s\n", msg))
+               return;
+       resource_tree(root, debug_level, 0);
+}
+
 /**
  * Configure devices on the device tree.
  *
@@ -948,6 +997,8 @@
        compute_allocate_resource(&root->link[0], mem,
                                  IORESOURCE_MEM, IORESOURCE_MEM);
 
+       print_resource_tree(root, BIOS_DEBUG, "After first compute_allocate.");
+
        /* Now we need to adjust the resources. The issue is that mem grows
         * downward.
         */
@@ -975,9 +1026,12 @@
        compute_allocate_resource(&root->link[0], mem,
                                  IORESOURCE_MEM, IORESOURCE_MEM);
 
+       print_resource_tree(root, BIOS_DEBUG, "After second compute_allocate.");
+
        /* Store the computed resource allocations into device registers. */
        printk(BIOS_INFO, "Phase 4: Setting resources...\n");
        root->ops->phase4_set_resources(root);
+       print_resource_tree(root, BIOS_DEBUG, "After setting resources.");
        printk(BIOS_INFO, "Phase 4: Done setting resources.\n");
 #if 0
        mem->flags |= IORESOURCE_STORED;
@@ -1028,13 +1082,52 @@
        printk(BIOS_INFO, "Phase 6: Devices initialized.\n");
 }
 
-void show_all_devs(void)
+void show_devs_tree(struct device *dev, int debug_level, int depth, int 
linknum)
 {
+       char depth_str[20] = "";
+       int i;
+       struct device *sibling;
+       for (i = 0; i < depth; i++)
+               depth_str[i] = ' ';
+       depth_str[i] = '\0';
+       printk(debug_level, "%s%s(%s): enabled %d have_resources %d devfn %x\n",
+              depth_str, dev->dtsname, dev_path(dev), dev->enabled,
+              dev->have_resources,
+              dev->path.type == DEVICE_PATH_PCI ? dev->path.pci.devfn : 0xff);
+       for (i = 0; i < dev->links; i++) {
+               for (sibling = dev->link[i].children; sibling;
+                    sibling = sibling->sibling)
+                       show_devs_tree(sibling, debug_level, depth + 1, i);
+       }
+}
+
+void show_all_devs_tree(int debug_level, const char *msg)
+{
+       /* Bail if not printing to screen. */
+       if (!printk(debug_level, "Show all devs in tree form...%s\n", msg))
+               return;
+       show_devs_tree(all_devices, debug_level, 0, -1);
+}
+
+void show_devs_subtree(struct device *root, int debug_level, const char *msg)
+{
+       /* Bail if not printing to screen. */
+       if (!printk(debug_level, "Show all devs in subtree %s...%s\n",
+                   root->dtsname, msg))
+               return;
+       printk(debug_level, "%s\n", msg);
+       show_devs_tree(root, debug_level, 0, -1);
+}
+
+void show_all_devs(int debug_level, const char *msg)
+{
        struct device *dev;
 
-       printk(BIOS_INFO, "Show all devs...\n");
+       /* Bail if not printing to screen. */
+       if (!printk(debug_level, "Show all devs...%s\n", msg))
+               return;
        for (dev = all_devices; dev; dev = dev->next) {
-               printk(BIOS_SPEW,
+               printk(debug_level,
                       "%s(%s): enabled %d have_resources %d\n",
                       dev->dtsname, dev_path(dev), dev->enabled,
                       dev->have_resources);
@@ -1042,7 +1135,7 @@
 }
 
 void show_one_resource(struct device *dev, struct resource *resource,
-                           const char *comment)
+                      const char *comment)
 {
        char buf[10];
        unsigned long long base, end;
@@ -1058,10 +1151,10 @@
 #endif
        }
        printk(BIOS_DEBUG, "%s %02lx <- [0x%010llx - 0x%010llx] "
-               "size 0x%08Lx gran 0x%02x %s%s%s\n",
-               dev_path(dev), resource->index, base, end,
-               resource->size, resource->gran, buf,
-               resource_type(resource), comment);
+              "size 0x%08Lx gran 0x%02x %s%s%s\n",
+              dev_path(dev), resource->index, base, end,
+              resource->size, resource->gran, buf,
+              resource_type(resource), comment);
 
 }
 
@@ -1076,7 +1169,7 @@
                       "%s(%s): enabled %d have_resources %d\n",
                       dev->dtsname, dev_path(dev), dev->enabled,
                       dev->have_resources);
-               for(i = 0; i < dev->resources; i++)
+               for (i = 0; i < dev->resources; i++)
                        show_one_resource(dev, &dev->resource[i], "");
        }
 }

Modified: coreboot-v3/device/device_util.c
===================================================================
--- coreboot-v3/device/device_util.c    2008-11-14 15:58:59 UTC (rev 1023)
+++ coreboot-v3/device/device_util.c    2008-11-14 16:15:33 UTC (rev 1024)
@@ -37,7 +37,8 @@
  * @return Pointer to a device structure for the device on bus at path
  *         or 0/NULL if no device is found.
  */
-struct device *find_dev_path(struct bus *parent, struct device_path *path)
+struct device *find_dev_path(const struct bus *parent,
+                            const struct device_path *path)
 {
        struct device *child;
        for (child = parent->children; child; child = child->sibling) {
@@ -130,7 +131,7 @@
                from = all_devices;
        else
                from = from->next;
-       for(;from;from = from->next){
+       for (; from; from = from->next) {
                printk(BIOS_SPEW, "Check %s\n", dev_id_string(&from->id));
                if (id_eq(devid, &from->id))
                        break;
@@ -182,7 +183,7 @@
 }
 
 /* WARNING: NOT SMP-safe! */
-const char *dev_path(struct device *dev)
+const char *dev_path(const struct device *dev)
 {
        static char buffer[DEVICE_PATH_MAX];
        buffer[0] = '\0';
@@ -223,8 +224,7 @@
                                dev->path.pci_domain.domain);
                        break;
                case DEVICE_PATH_PCI_BUS:
-                       sprintf(buffer, "PCI_BUS: %04x",
-                               dev->path.pci_bus.bus);
+                       sprintf(buffer, "PCI_BUS: %04x", dev->path.pci_bus.bus);
                        break;
                case DEVICE_PATH_APIC_CLUSTER:
                        sprintf(buffer, "APIC_CLUSTER: %01x",
@@ -234,8 +234,7 @@
                        sprintf(buffer, "CPU: %02x", dev->path.cpu.id);
                        break;
                case DEVICE_PATH_CPU_BUS:
-                       sprintf(buffer, "CPU_BUS: %02x",
-                               dev->path.cpu_bus.id);
+                       sprintf(buffer, "CPU_BUS: %02x", dev->path.cpu_bus.id);
                        break;
                case DEVICE_PATH_IOPORT:
                        sprintf(buffer, "IOPORT: %02x",
@@ -251,7 +250,7 @@
 }
 
 /* WARNING: NOT SMP-safe! */
-const char *dev_id_string(struct device_id *id)
+const char *dev_id_string(const struct device_id *id)
 {
        static char buffer[DEVICE_ID_MAX];
        buffer[0] = '\0';
@@ -278,8 +277,7 @@
                        break;
                case DEVICE_ID_PCI_DOMAIN:
                        sprintf(buffer, "PCI_DOMAIN: %04x:%04x",
-                               id->pci_domain.vendor,
-                               id->pci_domain.device);
+                               id->pci_domain.vendor, id->pci_domain.device);
                        break;
                case DEVICE_ID_APIC_CLUSTER:
                        sprintf(buffer, "APIC_CLUSTER: %02x:%02x",
@@ -304,14 +302,14 @@
        return buffer;
 }
 
-const char *bus_path(struct bus *bus)
+const char *bus_path(const struct bus *bus)
 {
        static char buffer[BUS_PATH_MAX];
        sprintf(buffer, "%s,%d", dev_path(bus->dev), bus->link);
        return buffer;
 }
 
-int path_eq(struct device_path *path1, struct device_path *path2)
+int path_eq(const struct device_path *path1, const struct device_path *path2)
 {
        int equal = 0;
        if (path1->type == path2->type) {
@@ -332,8 +330,7 @@
                        equal = (path1->i2c.device == path2->i2c.device);
                        break;
                case DEVICE_PATH_APIC:
-                       equal =
-                           (path1->apic.apic_id == path2->apic.apic_id);
+                       equal = (path1->apic.apic_id == path2->apic.apic_id);
                        break;
                case DEVICE_PATH_PCI_DOMAIN:
                        equal =
@@ -402,10 +399,8 @@
                        equal = (path1->cpu.cpuid == path2->cpu.cpuid);
                        break;
                case DEVICE_ID_CPU_BUS:
-                       equal =
-                           (path1->cpu_bus.vendor == path2->cpu_bus.vendor)
-                           && (path1->cpu_bus.device ==
-                               path2->cpu_bus.device);
+                       equal = (path1->cpu_bus.vendor == path2->cpu_bus.vendor)
+                           && (path1->cpu_bus.device == path2->cpu_bus.device);
                        break;
                default:
                        printk(BIOS_ERR, "Unknown device type: %d\n",
@@ -430,7 +425,8 @@
        for (i = 0; i < dev->resources;) {
                resource = &dev->resource[i];
                if (!resource->flags) {
-                       memmove(resource, resource + 1, (dev->resources-i)* 
sizeof(*resource));
+                       memmove(resource, resource + 1,
+                               (dev->resources - i) * sizeof(*resource));
                        dev->resources -= 1;
                        memset(&dev->resource[dev->resources], 0,
                               sizeof(*resource));
@@ -452,7 +448,7 @@
        struct resource *resource;
        int i;
        /* See if there is a resource with the appropriate index. */
-       resource = 0;
+       resource = NULL;
        for (i = 0; i < dev->resources; i++) {
                if (dev->resource[i].index == index) {
                        resource = &dev->resource[i];
@@ -557,7 +553,7 @@
  * @param resource The resource whose limit is desired.
  * @returns The end.
  */
-resource_t resource_end(struct resource *resource)
+resource_t resource_end(struct resource * resource)
 {
        resource_t base, end;
 
@@ -582,7 +578,7 @@
  * @param resource The resource whose maximum is desired.
  * @returns The maximum.
  */
-resource_t resource_max(struct resource *resource)
+resource_t resource_max(struct resource * resource)
 {
        resource_t max;
        max = align_down(resource->limit - resource->size + 1, resource->align);
@@ -634,10 +630,10 @@
 #endif
                }
                printk(BIOS_DEBUG, "%s %02lx <- [0x%010llx - 0x%010llx] "
-                       "size 0x%08Lx gran 0x%02x %s%s%s\n",
-                       dev_path(dev), resource->index, base, end,
-                       resource->size, resource->gran, buf,
-                       resource_type(resource), comment);
+                      "size 0x%08Lx gran 0x%02x %s%s%s\n",
+                      dev_path(dev), resource->index, base, end,
+                      resource->size, resource->gran, buf,
+                      resource_type(resource), comment);
        }
 }
 
@@ -661,7 +657,7 @@
                        if (resource->flags & IORESOURCE_SUBTRACTIVE) {
                                struct bus *subbus;
                                subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK
-                                        (resource->index)];
+                                                      (resource->index)];
                                search_bus_resources(subbus, type_mask, type,
                                                     search, gp);
                                continue;
@@ -675,7 +671,8 @@
                             resource_search_t search, void *gp)
 {
        struct device *curdev;
-       printk(BIOS_SPEW, "%s: mask %lx type %lx \n", __func__, type_mask, 
type);
+       printk(BIOS_SPEW, "%s: mask %lx type %lx \n", __func__, type_mask,
+              type);
        for (curdev = all_devices; curdev; curdev = curdev->next) {
                int i;
                printk(BIOS_SPEW,

Modified: coreboot-v3/include/device/device.h
===================================================================
--- coreboot-v3/include/device/device.h 2008-11-14 15:58:59 UTC (rev 1023)
+++ coreboot-v3/include/device/device.h 2008-11-14 16:15:33 UTC (rev 1024)
@@ -38,16 +38,16 @@
 #define TYPENAME(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d))
 #define DEVICE_ID_MAX 64
 enum device_id_type {
-       DEVICE_ID_NONE  = 0,
-       DEVICE_ID_ROOT  = TYPENAME('R','O','O','T'),
-       DEVICE_ID_PCI   = TYPENAME(' ','P','C','I'),
-       DEVICE_ID_PNP   = TYPENAME(' ','P','N','P'),
-       DEVICE_ID_I2C   = TYPENAME(' ','I','2','C'),
-       DEVICE_ID_APIC  = TYPENAME('A','P','I','C'),
-       DEVICE_ID_PCI_DOMAIN = TYPENAME('P','C','I','D'),
-       DEVICE_ID_APIC_CLUSTER = TYPENAME('A','P','C','C'),
-       DEVICE_ID_CPU = TYPENAME(' ','C','P','U'),
-       DEVICE_ID_CPU_BUS =  TYPENAME(' ','B','U','S'),
+       DEVICE_ID_NONE = 0,
+       DEVICE_ID_ROOT = TYPENAME('R', 'O', 'O', 'T'),
+       DEVICE_ID_PCI  = TYPENAME(' ', 'P', 'C', 'I'),
+       DEVICE_ID_PNP  = TYPENAME(' ', 'P', 'N', 'P'),
+       DEVICE_ID_I2C  = TYPENAME(' ', 'I', '2', 'C'),
+       DEVICE_ID_APIC = TYPENAME('A', 'P', 'I', 'C'),
+       DEVICE_ID_PCI_DOMAIN = TYPENAME('P', 'C', 'I', 'D'),
+       DEVICE_ID_APIC_CLUSTER = TYPENAME('A', 'P', 'C', 'C'),
+       DEVICE_ID_CPU = TYPENAME(' ', 'C', 'P', 'U'),
+       DEVICE_ID_CPU_BUS = TYPENAME(' ', 'B', 'U', 'S'),
 };
 
 struct device;
@@ -56,62 +56,52 @@
 struct smbus_bus_operations;
 struct bus;
 
-
-struct pci_domain_id
-{
+struct pci_domain_id {
        u16 vendor, device;
 };
 
-struct pci_id
-{
+struct pci_id {
        u16 vendor, device;
 };
 
-struct pnp_id
-{
+struct pnp_id {
        u32 device;
 };
 
-struct i2c_id
-{
+struct i2c_id {
        u32 id;
 };
 
-struct apic_id
-{
+struct apic_id {
        u16 vendor, device;
 };
 
-struct apic_cluster_id
-{
+struct apic_cluster_id {
        u16 vendor, device;
 };
 
-struct cpu_id
-{
+struct cpu_id {
        u8 cpuid[24];
 };
 
-struct cpu_bus_id
-{
+struct cpu_bus_id {
        u16 vendor, device;
 };
 
 struct device_id {
        enum device_id_type type;
        union {
-               struct pci_id                   pci;
-               struct pnp_id                   pnp;
-               struct i2c_id                   i2c;
-               struct apic_id                  apic;
+               struct pci_id           pci;
+               struct pnp_id           pnp;
+               struct i2c_id           i2c;
+               struct apic_id          apic;
                struct pci_domain_id    pci_domain;
                struct apic_cluster_id  apic_cluster;
-               struct cpu_id                   cpu;
-               struct cpu_bus_id               cpu_bus;
+               struct cpu_id           cpu;
+               struct cpu_bus_id       cpu_bus;
        };
 };
 
-
 struct device_operations {
        /* the device id for this set of device operations. 
         * In almost all cases, this is non-zero. For the 
@@ -119,8 +109,8 @@
         */
        struct device_id id;
        /* for now, we leave these, since they seem generic */
-       void (*set_link)(struct device * dev, unsigned int link);
-       void (*reset_bus)(struct bus *bus);
+       void (*set_link) (struct device * dev, unsigned int link);
+       void (*reset_bus) (struct bus * bus);
 
        /* A constructor. The constructor for a given device is defined in the
         * device source file.  When is this called? Not for the static tree.
@@ -136,52 +126,51 @@
         * constructors->constructor(constructors->constructor) and a new
         * device is created. 
         */
-       void (*constructor)(struct device *, const struct device_operations *);
+       void (*constructor) (struct device *, const struct device_operations *);
 
        /* set device ops */
-       void (*phase1_set_device_operations)(struct device *dev);
+       void (*phase1_set_device_operations) (struct device * dev);
 
        /* phase 2 is for any magic you have to do before the busses are 
scanned */
-       void (*phase2_fixup)(struct device * dev);
+       void (*phase2_fixup) (struct device * dev);
 
        /* phase 3 is for scanning the bus, if needed. */
-       void (*phase3_chip_setup_dev)(struct device *dev);
+       void (*phase3_chip_setup_dev) (struct device * dev);
        /* some devices need to be enabled to scan. */
-       /* this function enables/disables according the value of 'enabled' in 
the device*/
-       void (*phase3_enable)(struct device * dev);
-       unsigned int (*phase3_scan)(struct device * bus, unsigned int max);
+       /* this function enables/disables based on 'enabled' in the device. */
+       void (*phase3_enable) (struct device * dev);
+       unsigned int (*phase3_scan) (struct device * bus, unsigned int max);
 
        /* typically used by phase4 */
        /* again, if we never use this anywhere else, we may change the names */
-       void (*phase4_read_resources)(struct device * dev);
-       void (*phase4_set_resources)(struct device * dev);
+       void (*phase4_read_resources) (struct device * dev);
+       void (*phase4_set_resources) (struct device * dev);
 
        /* phase 5: enable devices */
-       void (*phase5_enable_resources)(struct device * dev);
+       void (*phase5_enable_resources) (struct device * dev);
 
        /* phase 6: any post-setup device initialization that might be needed */
-       void (*phase6_init)(struct device * dev);
+       void (*phase6_init) (struct device * dev);
 
        const struct pci_operations *ops_pci;
        const struct smbus_bus_operations *ops_smbus_bus;
        const struct pci_bus_operations *ops_pci_bus;
 };
 
-
 struct bus {
-       struct device *         dev;            /* This bridge device */
-       struct device *         children;       /* devices behind this bridge */
+       struct device   *dev;           /* This bridge device */
+       struct device   *children;      /* devices behind this bridge */
        unsigned        bridge_ctrl;    /* Bridge control register */
        unsigned char   link;           /* The index of this link */
-       unsigned char   secondary;      /* secondary bus number */
+       unsigned char   secondary;      /* secondary bus number */
        unsigned char   subordinate;    /* max subordinate bus number */
-       unsigned char   cap;            /* PCi capability offset */
-       unsigned        reset_needed : 1;
-       unsigned        disable_relaxed_ordering : 1;
+       unsigned char   cap;            /* PCi capability offset */
+       unsigned        reset_needed:1;
+       unsigned        disable_relaxed_ordering:1;
 };
 
 #define MAX_RESOURCES 12
-#define MAX_LINKS    8 
+#define MAX_LINKS    8
 #define MAX_DTSNAME_SIZE 64
 /*
  * There is one device structure for each slot-number/function-number
@@ -189,17 +178,17 @@
  */
 
 struct device {
-       struct bus *    bus;            /* bus this device is on, for bridge
+       struct bus      *bus;           /* bus this device is on, for bridge
                                         * devices, it is the up stream bus */
-       struct device * sibling;        /* next device on this bus */
-       struct device * next;           /* chain of all devices */
+       struct device   *sibling;       /* next device on this bus */
+       struct device   *next;          /* chain of all devices */
 
        struct device_path path;
        /* note there is a device id maintained here. This covers the special 
case
         * of default_device_operations, which has an id of zero. 
         */
        struct device_id id;
-       char            dtsname[MAX_DTSNAME_SIZE];      /* the name from the 
dts */
+       char dtsname[MAX_DTSNAME_SIZE]; /* the name from the dts */
        u16 status;
        u8 revision;
        u8 cache_line;
@@ -210,12 +199,12 @@
        u16 subsystem_vendor;
        u16 subsystem_device;
 
-       unsigned int    class;          /* 3 bytes: (base,sub,prog-if) */
-       unsigned int    hdr_type;       /* PCI header type */
-       unsigned int    enabled : 1;    /* set if we should enable the device */
-       unsigned int    have_resources : 1; /* Set if we have read the devices 
resources */
-       unsigned int    on_mainboard : 1;
-       unsigned long   rom_address;
+       unsigned int    class;                  /* 3 bytes: (base,sub,prog-if) 
*/
+       unsigned int    hdr_type;               /* PCI header type */
+       unsigned int    enabled:1;              /* set if we should enable the 
device */
+       unsigned int    have_resources:1;       /* Set if we have read the 
devices resources */
+       unsigned int    on_mainboard:1;
+       unsigned long   rom_address;
 
        u8 command;
 
@@ -234,13 +223,13 @@
        void *device_configuration;
 };
 
-extern struct device   dev_root;       /* root bus */
-extern struct device   *all_devices;   /* list of all devices */
+extern struct device dev_root;         /* root bus */
+extern struct device *all_devices;     /* list of all devices */
 
-
 /* Generic device interface functions */
 struct device_operations *find_device_operations(struct device_id *id);
-struct device * alloc_dev(struct bus *parent, struct device_path *path, struct 
device_id *id);
+struct device *alloc_dev(struct bus *parent, struct device_path *path,
+                        struct device_id *id);
 void dev_enumerate(void);
 void dev_configure(void);
 void dev_enable(void);
@@ -251,34 +240,38 @@
 int reset_bus(struct bus *bus);
 unsigned int scan_bus(struct device *bus, unsigned int max);
 void compute_allocate_resource(struct bus *bus, struct resource *bridge,
-       unsigned long type_mask, unsigned long type);
+                              unsigned long type_mask, unsigned long type);
 void assign_resources(struct bus *bus);
 void enable_resources(struct device *dev);
 void enumerate_static_device(void);
 void enumerate_static_devices(void);
-const char *dev_path(struct device * dev);
-const char *dev_id_string(struct device_id *id);
-const char *bus_path(struct bus *bus);
-void dev_set_enabled(struct device * dev, int enable);
+const char *dev_path(const struct device *dev);
+const char *dev_id_string(const struct device_id *id);
+const char *bus_path(const struct bus *bus);
+void dev_set_enabled(struct device *dev, int enable);
 void disable_children(struct bus *bus);
 
 /* Helper functions */
-struct device * find_dev_path(struct bus *parent, struct device_path *path);
-struct device * alloc_find_dev(struct bus *parent, struct device_path *path, 
struct device_id *id);
-struct device * dev_find_device (struct device_id *devid, struct device * 
from);
+struct device *find_dev_path(const struct bus *parent,
+                            const struct device_path *path);
+struct device *alloc_find_dev(struct bus *parent, struct device_path *path,
+                             struct device_id *id);
+struct device *dev_find_device(struct device_id *devid, struct device *from);
 struct device *dev_find_pci_device(u16 vendor, u16 device, struct device 
*from);
 EXPORT_SYMBOL(dev_find_pci_device);
-struct device * dev_find_class (unsigned int class, struct device * from);
-struct device * dev_find_slot (unsigned int bus, unsigned int devfn);
+struct device *dev_find_class(unsigned int class, struct device *from);
+struct device *dev_find_slot(unsigned int bus, unsigned int devfn);
 EXPORT_SYMBOL(dev_find_slot);
-struct device * dev_find_slot_on_smbus (unsigned int bus, unsigned int addr);
-void default_device_constructor(struct device *dev, const struct 
device_operations *constructor);
+struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr);
+void default_device_constructor(struct device *dev,
+                               const struct device_operations *constructor);
+void show_all_devs(int debug_level, const char *msg);
+void show_all_devs_tree(int debug_level, const char *msg);
 
-
 /* Rounding for boundaries. 
- * Due to some chip bugs, go ahead and roung IO to 16
+ * Due to some chip bugs, go ahead and round IO to 16
  */
-#define DEVICE_IO_ALIGN 16 
+#define DEVICE_IO_ALIGN 16
 #define DEVICE_MEM_ALIGN 4096
 
 resource_t align_up(resource_t val, unsigned long gran);
@@ -287,24 +280,24 @@
 extern struct device_operations default_dev_ops_root;
 
 extern int id_eq(struct device_id *id1, struct device_id *id2);
-void root_dev_read_resources(struct device * dev);
-void root_dev_set_resources(struct device * dev);
-unsigned int scan_static_bus(struct device * bus, unsigned int max);
-void enable_childrens_resources(struct device * dev);
-void root_dev_enable_resources(struct device * dev);
-unsigned int root_dev_scan_bus(struct device * root, unsigned int max);
-void root_dev_init(struct device * dev);
+void root_dev_read_resources(struct device *dev);
+void root_dev_set_resources(struct device *dev);
+unsigned int scan_static_bus(struct device *bus, unsigned int max);
+void enable_childrens_resources(struct device *dev);
+void root_dev_enable_resources(struct device *dev);
+unsigned int root_dev_scan_bus(struct device *root, unsigned int max);
+void root_dev_init(struct device *dev);
 void dev_init(void);
 void dev_phase1(void);
 void dev_phase2(void);
 void dev_root_phase3(void);
-unsigned int dev_phase3_scan(struct device * busdevice, unsigned int max);
+unsigned int dev_phase3_scan(struct device *busdevice, unsigned int max);
 void dev_phase4(void);
 void dev_root_phase5(void);
 void dev_phase6(void);
 
 void phase4_assign_resources(struct bus *bus);
-unsigned int dev_phase3(struct device * bus, unsigned int max);
+unsigned int dev_phase3(struct device *bus, unsigned int max);
 void dev_phase5(struct device *dev);
 
-#endif /* DEVICE_DEVICE_H */
+#endif /* DEVICE_DEVICE_H */

Modified: coreboot-v3/include/device/path.h
===================================================================
--- coreboot-v3/include/device/path.h   2008-11-14 15:58:59 UTC (rev 1023)
+++ coreboot-v3/include/device/path.h   2008-11-14 16:15:33 UTC (rev 1024)
@@ -22,7 +22,7 @@
        DEVICE_PATH_NONE = 0,
        DEVICE_PATH_ROOT,
        DEVICE_PATH_PCI_DOMAIN,
-       DEVICE_PATH_PCI_BUS, 
+       DEVICE_PATH_PCI_BUS,
        DEVICE_PATH_PCI,
        DEVICE_PATH_PNP,
        DEVICE_PATH_I2C,
@@ -33,60 +33,49 @@
        DEVICE_PATH_IOPORT,
 };
 
-struct pci_domain_path
-{
+struct pci_domain_path {
        unsigned domain;
 };
 
-struct pci_bus_path
-{
+struct pci_bus_path {
        unsigned bus;
 };
 
-struct pci_path
-{
+struct pci_path {
        unsigned devfn;
 };
 
-struct pnp_path
-{
+struct pnp_path {
        unsigned port;
        unsigned device;
 };
 
-struct i2c_path
-{
+struct i2c_path {
        unsigned device;
 };
 
-struct apic_path
-{
+struct apic_path {
        unsigned apic_id;
        unsigned node_id;
        unsigned core_id;
 };
 
-struct apic_cluster_path
-{
+struct apic_cluster_path {
        unsigned cluster;
 };
 
-struct cpu_path
-{
+struct cpu_path {
        unsigned id;
 };
 
-struct cpu_bus_path
-{
+struct cpu_bus_path {
        unsigned id;
 };
 
-struct ioport_path
-{
+struct ioport_path {
        unsigned iobase;
 };
 
-
 struct device_path {
        enum device_path_type type;
        union {
@@ -103,10 +92,10 @@
        };
 };
 
-
 #define DEVICE_PATH_MAX 30
 #define BUS_PATH_MAX (DEVICE_PATH_MAX+10)
 
-extern int path_eq(struct device_path *path1, struct device_path *path2);
+extern int path_eq(const struct device_path *path1,
+                  const struct device_path *path2);
 
-#endif /* DEVICE_PATH_H */
+#endif                         /* DEVICE_PATH_H */

Modified: coreboot-v3/lib/stage2.c
===================================================================
--- coreboot-v3/lib/stage2.c    2008-11-14 15:58:59 UTC (rev 1023)
+++ coreboot-v3/lib/stage2.c    2008-11-14 16:15:33 UTC (rev 1024)
@@ -45,9 +45,6 @@
 {
        void *mbi;
 
-       /* TODO: Add comment. */
-       void show_all_devs(void);
-
        post_code(POST_STAGE2_BEGIN);
        dev_init();
 
@@ -56,7 +53,7 @@
         */
        post_code(POST_STAGE2_PHASE1_START);
        dev_phase1();
-       show_all_devs();
+       show_all_devs(BIOS_DEBUG, "After phase 1.");
 
        /* Here is where weird stuff like init_timer handling should be
         * done. This is for ANYTHING that might have to happen before
@@ -64,35 +61,36 @@
         */
        post_code(POST_STAGE2_PHASE2_START);
        dev_phase2();
-       show_all_devs();
+       show_all_devs(BIOS_DEBUG, "After phase 2.");
 
        /* Walk physical devices and add any dynamic devices to the
         * device tree.
         */
        post_code(POST_STAGE2_PHASE3_START);
        dev_root_phase3();
-       show_all_devs();
+       show_all_devs_tree(BIOS_DEBUG, "After phase 3.");
 
        /* Compute and assign the bus resources. */
        post_code(POST_STAGE2_PHASE4_START);
        dev_phase4();
-       show_all_devs();
+       show_all_devs(BIOS_DEBUG, "After phase 4.");
 
        /* Now actually enable devices on the bus. */
        post_code(POST_STAGE2_PHASE5_START);
        dev_root_phase5();
-       show_all_devs();
+       show_all_devs(BIOS_DEBUG, "After phase 5.");
 
        /* Initialize devices on the bus. */
        post_code(POST_STAGE2_PHASE6_START);
        dev_phase6();
-       show_all_devs();
+       show_all_devs(BIOS_DEBUG, "After phase 6.");
 
-       /* TODO: Add comment. */
+       /* Write tables to pass information to the payloads. */
        post_code(POST_STAGE2_WRITE_TABLES);
        mbi = write_tables();
-       show_all_devs();
+       show_all_devs(BIOS_DEBUG, "After writing tables.");
 
        return mbi;
 }
+
 EXPORT_SYMBOL(stage2);


--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to