Author: rminnich Date: 2008-10-29 19:29:19 +0100 (Wed, 29 Oct 2008) New Revision: 963
Modified: coreboot-v3/device/device.c coreboot-v3/device/root_device.c Log: Make it so that read_resources only reads resources.
dev_phase4 will call compute_allocate. This is an early pass at making the device tree code a little more readable. We have done a pass on the stage2 code and are comfortable with phases 1-3 and 5-6; phase 4 is the phase that is really tough to follow. We are working on cleaning that up today.
This change tested and working on dbe62.
We are well aware that as more complex targets appear this code may break on them. At the same time, we are determined to untangle the thicket of code in phase 4, since this code has been a source of confusion for several years now.
There used to be a recursion: compute_allocate_resource would ALWAYS call read_resources, which would in turn call compute_allocate_resource.
We are attempting to resolve this in a clearer manner.
boots to linux on dbe62 boots to etherboot on qemu
Signed-off-by: Ronald G. Minnich rminnich@gmail.com Acked-by: Peter Stuge peter@stuge.se
Modified: coreboot-v3/device/device.c =================================================================== --- coreboot-v3/device/device.c 2008-10-29 18:12:22 UTC (rev 962) +++ coreboot-v3/device/device.c 2008-10-29 18:29:19 UTC (rev 963) @@ -271,7 +271,7 @@ * * @param bus Bus to read the resources on. */ -static void read_resources(struct bus *bus) +void read_resources(struct bus *bus) { struct device *curdev;
@@ -913,7 +913,39 @@ root->ops->phase4_read_resources(root); printk(BIOS_INFO, "Phase 4: Done reading resources.\n");
- /* Get the resources. */ + /* we have read the resources. We now compute the global allocation of resources. + * We have to create a root resource for the base of the tree. The root resource should contain the entire + * address space for IO and MEM resources. The allocation of device resources will be done from this + * resource address space. + */ + + /* Allocate a resource from the root device resource pool and initialize the system wide I/O space constraints. */ + io = new_resource(root, 0); + io->base = 0x400; + io->size = 0; + io->align = 0; + io->gran = 0; + io->limit = 0xffffUL; + io->flags = IORESOURCE_IO; + + /* Allocate a resource from the root device resource pool and initialize the system wide + * memory resources constraints. + */ + mem = new_resource(root, 1); + mem->base = 0; + mem->size = 0; + mem->align = 0; + mem->gran = 0; + mem->limit = 0xffffffffUL; + mem->flags = IORESOURCE_MEM; + + compute_allocate_resource(&root->link[0], io, + IORESOURCE_IO, IORESOURCE_IO); + + compute_allocate_resource(&root->link[0], mem, + IORESOURCE_MEM, IORESOURCE_MEM); + + /* Now we need to adjust the resources. The issue is that mem grows downward. io = &root->resource[0]; mem = &root->resource[1];
@@ -934,6 +966,13 @@ allocate_vga_resource(); #endif
+ /* now rerun the compute allocate with the adjusted resources */ + compute_allocate_resource(&root->link[0], io, + IORESOURCE_IO, IORESOURCE_IO); + + compute_allocate_resource(&root->link[0], mem, + IORESOURCE_MEM, IORESOURCE_MEM); + /* Store the computed resource allocations into device registers. */ printk(BIOS_INFO, "Phase 4: Setting resources...\n"); root->ops->phase4_set_resources(root); @@ -999,3 +1038,43 @@ dev->have_resources); } } + +void show_one_resource(struct device *dev, struct resource *resource, + const char *comment) +{ + char buf[10]; + unsigned long long base, end; + base = resource->base; + end = resource_end(resource); + buf[0] = '\0'; + if (resource->flags & IORESOURCE_PCI_BRIDGE) { +#if PCI_BUS_SEGN_BITS + sprintf(buf, "bus %04x:%02x ", dev->bus->secondary >> 8, + dev->link[0].secondary & 0xff); +#else + sprintf(buf, "bus %02x ", dev->link[0].secondary); +#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); + +} + +void show_all_devs_resources(void) +{ + struct device *dev; + + printk(BIOS_INFO, "Show all devs...\n"); + for (dev = all_devices; dev; dev = dev->next) { + int i; + printk(BIOS_SPEW, + "%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++) + show_one_resource(dev, &dev->resource[i], ""); + } +}
Modified: coreboot-v3/device/root_device.c =================================================================== --- coreboot-v3/device/root_device.c 2008-10-29 18:12:22 UTC (rev 962) +++ coreboot-v3/device/root_device.c 2008-10-29 18:29:19 UTC (rev 963) @@ -35,29 +35,13 @@ */ void root_dev_read_resources(struct device *root) { - struct resource *resource; + void read_resources(struct bus *bus); + void show_all_devs_resources(void);
- /* Initialize the system wide I/O space constraints. */ - resource = new_resource(root, 0); - resource->base = 0x400; - resource->size = 0; - resource->align = 0; - resource->gran = 0; - resource->limit = 0xffffUL; - resource->flags = IORESOURCE_IO; - compute_allocate_resource(&root->link[0], resource, - IORESOURCE_IO, IORESOURCE_IO); + read_resources(&root->link[0]);
- /* Initialize the system wide memory resources constraints. */ - resource = new_resource(root, 1); - resource->base = 0; - resource->size = 0; - resource->align = 0; - resource->gran = 0; - resource->limit = 0xffffffffUL; - resource->flags = IORESOURCE_MEM; - compute_allocate_resource(&root->link[0], resource, - IORESOURCE_MEM, IORESOURCE_MEM); + printk(BIOS_DEBUG, "%s: Done allocating\n", __FUNCTION__); + show_all_devs_resources(); }
/** @@ -68,15 +52,7 @@ */ void root_dev_set_resources(struct device *root) { - struct bus *bus; - - bus = &root->link[0]; - compute_allocate_resource(bus, - &root->resource[0], IORESOURCE_IO, - IORESOURCE_IO); - compute_allocate_resource(bus, &root->resource[1], IORESOURCE_MEM, - IORESOURCE_MEM); - phase4_assign_resources(bus); + phase4_assign_resources(&root->link[0]); }
/**