From 53283b1e364fb464eb2d54dcd0367ca969c78098 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sat, 3 Mar 2007 00:39:30 +0000 Subject: [PATCH] fix a stupid bug in malloc. add debug printks. make dtc put 'root' as the first_node, instead of making the last node be the first node .... much happier in linuxbios. sprintf is broken ... dammit. I hope someone will fix it. I've got about another week of full-time I can spend on this and then I go back to part time. So I'm going to need some help soon. other fixups, and also, make the dts conform to the needs of the device tree. So we have a domain0 and a device (0,0) that is the north. Mostly things are working, but we're STILL not getting any memory in the LB tables from the north. The device tree is a bitch. Signed-off-by: Ronald G. Minnich Acked-by: Ronald G. Minnich Acked-by: Stefan Reinauer git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@175 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- arch/x86/linuxbios_table.c | 1 + device/device.c | 41 +++++++++++++++++++--- device/device_util.c | 5 +++ device/pci_device.c | 18 ++++++---- lib/malloc.c | 2 +- lib/stage2.c | 17 +++++++-- mainboard/emulation/qemu-x86/dts | 10 ++++-- northbridge/intel/i440bxemulation/i440bx.c | 1 + util/dtc/flattree.c | 14 ++++++++ 9 files changed, 91 insertions(+), 18 deletions(-) diff --git a/arch/x86/linuxbios_table.c b/arch/x86/linuxbios_table.c index 2a2deca7be..52e333a426 100644 --- a/arch/x86/linuxbios_table.c +++ b/arch/x86/linuxbios_table.c @@ -181,6 +181,7 @@ void lb_memory_range(struct lb_memory *mem, u32 type, u64 start, u64 size) { int entries; + printk(BIOS_SPEW-2, "%s: start 0x%lx size 0x%lx\n", __func__, start, size); entries = (mem->size - sizeof(*mem))/sizeof(mem->map[0]); mem->map[entries].start = pack_lb64(start); mem->map[entries].size = pack_lb64(size); diff --git a/device/device.c b/device/device.c index f1a7986a47..a2842c3ab0 100644 --- a/device/device.c +++ b/device/device.c @@ -90,6 +90,8 @@ struct device * alloc_dev(struct bus *parent, struct device_path *path) { struct device * dev, *child; int link; + static char thissucks[64]; + static int fuck = 0; // spin_lock(&dev_lock); @@ -128,6 +130,21 @@ struct device * alloc_dev(struct bus *parent, struct device_path *path) *last_dev_p = dev; last_dev_p = &dev->next; + /* give the device a name */ + dev -> dtsname = malloc(32); + if (dev->dtsname == 0) { + die("DEV: out of memory.\n"); + } + sprintf(thissucks, "dynamic %s", dev_path(dev)); + printk(BIOS_INFO, "thissucks is %s dev is %p dev->dtsname is %p\n", thissucks, dev, dev->dtsname); + sprintf(dev->dtsname, "dynamic %s", dev_path(dev)); + printk(BIOS_INFO, "after sprintf dtsname is %s\n", dev->dtsname); + memcpy(dev->dtsname, thissucks, strlen(thissucks)); + printk(BIOS_INFO, "after strcpy dtsname is %s\n", dev->dtsname); + /* FUCK. sprintf doesn't work. */ + dev->dtsname[0] = '0' + fuck++; + dev->dtsname[1] = 0; + // spin_unlock(&dev_lock); return dev; } @@ -154,13 +171,15 @@ static void read_resources(struct bus *bus) { struct device *curdev; - printk(BIOS_SPEW, "%s read_resources bus %d link: %d\n", + printk(BIOS_SPEW, "%s: %s(%s) read_resources bus %d link: %d\n", __func__, bus->dev->dtsname, dev_path(bus->dev), bus->secondary, bus->link); /* Walk through all of the devices and find which resources they need. */ for(curdev = bus->children; curdev; curdev = curdev->sibling) { unsigned links; int i; + printk(BIOS_SPEW, "%s: %s(%s) have_resources %d enabled %d\n", __func__, bus->dev->dtsname, + dev_path(bus->dev), curdev->have_resources, curdev->enabled); if (curdev->have_resources) { continue; } @@ -168,8 +187,8 @@ static void read_resources(struct bus *bus) continue; } if (!curdev->ops || !curdev->ops->phase4_read_resources) { - printk(BIOS_ERR, "%s missing phase4_read_resources\n", - dev_path(curdev)); + printk(BIOS_ERR, "%s: %s(%s) missing phase4_read_resources\n", __func__, + curdev->dtsname, dev_path(curdev)); continue; } curdev->ops->phase4_read_resources(curdev); @@ -194,7 +213,7 @@ static void read_resources(struct bus *bus) } } } - printk(BIOS_SPEW, "%s read_resources bus %d link: %d done\n", + printk(BIOS_SPEW, "%s: %s(%s) read_resources bus %d link: %d done\n", __func__, bus->dev->dtsname, dev_path(bus->dev), bus->secondary, bus->link); } @@ -659,7 +678,7 @@ unsigned int dev_phase3_scan(struct device * busdevice, unsigned int max) do_phase3 = 1; while(do_phase3) { int link; - printk(BIOS_INFO, "%s: scanning %s\n", __FUNCTION__, dev_path(busdevice)); + printk(BIOS_INFO, "%s: scanning %s(%s)\n", __FUNCTION__, busdevice->dtsname, dev_path(busdevice)); new_max = busdevice->ops->phase3_scan(busdevice, max); do_phase3 = 0; for(link = 0; link < busdevice->links; link++) { @@ -837,3 +856,15 @@ void dev_phase6(void) printk(BIOS_INFO, "Phase 6: Devices initialized.\n"); } + +void show_all_devs(void) { + + struct device *dev; + + printk(BIOS_INFO, "show all devs..\n"); + for(dev = all_devices; dev; dev = dev->next) { + printk(BIOS_SPEW, "%s(%s): enabled %d have_resources %d initialized %d\n", + dev->dtsname, dev_path(dev), dev->enabled, dev->have_resources, dev->initialized); + } +} + diff --git a/device/device_util.c b/device/device_util.c index 3392b11a6c..5f9695b3bd 100644 --- a/device/device_util.c +++ b/device/device_util.c @@ -505,12 +505,17 @@ void search_global_resources( resource_search_t search, void *gp) { struct device *curdev; + printk(BIOS_SPEW-2, "%s: mask %x type %x \n", __func__, type_mask, type); for(curdev = all_devices; curdev; curdev = curdev->next) { int i; + printk(BIOS_SPEW, "%s: dev %s, have_resources %d #resources %d\n", __func__, curdev->dtsname, + curdev->have_resources, curdev->resources); /* Ignore disabled devices */ if (!curdev->have_resources) continue; for(i = 0; i < curdev->resources; i++) { struct resource *resource = &curdev->resource[i]; + printk(BIOS_SPEW, "%s: dev %s, resource %d, flags %x\n", __func__, curdev->dtsname, + i, resource->flags); /* If it isn't the right kind of resource ignore it */ if ((resource->flags & type_mask) != type) { continue; diff --git a/device/pci_device.c b/device/pci_device.c index c3229ac22a..2a1bb438e8 100644 --- a/device/pci_device.c +++ b/device/pci_device.c @@ -612,7 +612,7 @@ void pci_dev_enable_resources(struct device *dev) command = pci_read_config16(dev, PCI_COMMAND); command |= dev->command; command |= (PCI_COMMAND_PARITY + PCI_COMMAND_SERR); /* error check */ - printk(BIOS_DEBUG,"%s cmd <- %02x\n", dev_path(dev), command); + printk(BIOS_DEBUG,"%s: %s(%s) cmd <- %02x\n", __func__, dev->dtsname, dev_path(dev), command); pci_write_config16(dev, PCI_COMMAND, command); } @@ -781,6 +781,7 @@ static void set_pci_ops(struct device *dev) { struct pci_driver *driver; if (dev->ops) { + printk(BIOS_INFO, "%s: dev %p(%s) already has ops %p\n", __func__, dev, dev->dtsname, dev->ops); return; } @@ -829,6 +830,7 @@ static void set_pci_ops(struct device *dev) dev->class >> 8, dev->hdr_type); } } + printk(BIOS_INFO, "%s: dev %p(%s) set ops to %p\n", __func__, dev, dev->dtsname, dev->ops); return; } @@ -851,12 +853,15 @@ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn) { struct device *dev; dev = 0; + printk(BIOS_INFO, "%s: list is %p, *list is %p\n", __func__, list, *list); for(; *list; list = &(*list)->sibling) { + printk(BIOS_INFO, "%s: check dev %s \n", __func__, (*list)->dtsname); if ((*list)->path.type != DEVICE_PATH_PCI) { - printk(BIOS_ERR,"%s: child %s not a pci device: it's type %d\n", __FUNCTION__, - dev_path(*list), (*list)->path.type); + printk(BIOS_ERR,"%s: child %s(%s) not a pci device: it's type %d\n", __FUNCTION__, + (*list)->dtsname, dev_path(*list), (*list)->path.type); continue; } + printk(BIOS_INFO, "%s: check dev %s it has devfn 0x%x\n", __func__, (*list)->dtsname, (*list)->path.u.pci.devfn); if ((*list)->path.u.pci.devfn == devfn) { /* Unlink from the list */ dev = *list; @@ -1027,7 +1032,7 @@ unsigned int pci_scan_bus(struct bus *bus, struct device * old_devices; struct device * child; - printk(BIOS_DEBUG, "%s start\n", __func__); + printk(BIOS_DEBUG, "%s start bus %p, bus->dev %p\n", __func__, bus, bus->dev); #if PCI_BUS_SEGN_BITS printk(BIOS_DEBUG,"PCI: pci_scan_bus for bus %04x:%02x\n", bus->secondary >> 8, bus->secondary & 0xff); #else @@ -1035,6 +1040,7 @@ unsigned int pci_scan_bus(struct bus *bus, #endif old_devices = bus->children; + printk(BIOS_DEBUG, "%s: old_devices %p, dev for this bus %p(%s)\n", __func__, old_devices, bus->dev, bus->dev->dtsname); bus->children = 0; post_code(0x24); @@ -1049,12 +1055,12 @@ unsigned int pci_scan_bus(struct bus *bus, /* First thing setup the device structure */ dev = pci_scan_get_dev(&old_devices, devfn); - printk(BIOS_SPEW-2,"PCI: pci_scan_bus pci_scan_get_dev returns dev %s\n", dev->dtsname); + printk(BIOS_SPEW-2,"PCI: pci_scan_bus pci_scan_get_dev returns dev %s\n", dev ? dev->dtsname :"None (no dev in tree yet)"); /* See if a device is present and setup the device * structure. */ dev = pci_probe_dev(dev, bus, devfn); - printk(BIOS_SPEW-2,"PCI: pci_scan_bus pci_probe_dev returns dev %s\n", dev->dtsname); + printk(BIOS_SPEW-2,"PCI: pci_scan_bus pci_probe_dev returns dev %p(%s)\n", dev, dev->dtsname); /* if this is not a multi function device, * or the device is not present don't waste diff --git a/lib/malloc.c b/lib/malloc.c index 4e7fb128da..42e4cbc5c4 100644 --- a/lib/malloc.c +++ b/lib/malloc.c @@ -59,7 +59,7 @@ void *malloc(size_t size) die("OUT OF MEMORY\n"); } - size = (size + 3) & 3; /* Align */ + size = (size + 3) & (~3); /* Align */ p = free_mem_ptr; free_mem_ptr += size; diff --git a/lib/stage2.c b/lib/stage2.c index a324353cbf..f6edca2a65 100644 --- a/lib/stage2.c +++ b/lib/stage2.c @@ -62,6 +62,7 @@ it with the version available from LANL. */ int stage2(void) { + void show_all_devs(void); post_code(0x20); dev_init(); @@ -69,7 +70,11 @@ int stage2(void) * before printk can be used */ post_code(0x30); - dev_phase1(); + dev_phase1(); +show_all_devs(); + +// printk_notice("LinuxBIOS-%s%s %s booting...\n", +// linuxbios_version, linuxbios_extra_version, linuxbios_build); // printk_notice("LinuxBIOS-%s%s %s booting...\n", // linuxbios_version, linuxbios_extra_version, linuxbios_build); @@ -80,27 +85,33 @@ int stage2(void) */ post_code(0x40); dev_phase2(); +show_all_devs(); /* walk physical devices and add any dynamic devices to the * device tree */ post_code(0x30); dev_root_phase3(); +show_all_devs(); /* Compute and assign the bus resources. */ post_code(0x40); dev_phase4(); +show_all_devs(); /* Now actually enable devices on the bus */ post_code(0x50); dev_root_phase5(); +show_all_devs(); /*initialize devices on the bus */ post_code(0x60); - dev_phase6(); - + dev_phase6(); +show_all_devs(); + post_code(0x70); write_tables(); +show_all_devs(); return 0; } diff --git a/mainboard/emulation/qemu-x86/dts b/mainboard/emulation/qemu-x86/dts index 2f69b3e515..2322616cb4 100644 --- a/mainboard/emulation/qemu-x86/dts +++ b/mainboard/emulation/qemu-x86/dts @@ -5,11 +5,15 @@ cpus { enabled; }; - northbridge,intel,i440bxemulation{ + domain0{ enabled; config="northbridge,intel,i440bxemulation"; ops="default_pci_ops_dev"; - pcipath = "0,0"; + pcidomain = "0"; + device0,0{ + enabled; + pcipath="0,0"; + }; /* southbridge,intel,piix4{ pcipath = "0,0"; enabled; @@ -25,6 +29,6 @@ struct mainboard_emulation_qemu_x86_config root = { .nothing = 1, }; -struct northbridge_intel_i440bx_config northbridge_intel_i440bxemulation = { +struct northbridge_intel_i440bx_config domain0 = { .ramsize = CONFIG_NORTHBRIDGE_INTEL_I440BXEMULATION_RAMSIZE, }; diff --git a/northbridge/intel/i440bxemulation/i440bx.c b/northbridge/intel/i440bxemulation/i440bx.c index 910f1c2fa2..936496331e 100644 --- a/northbridge/intel/i440bxemulation/i440bx.c +++ b/northbridge/intel/i440bxemulation/i440bx.c @@ -79,6 +79,7 @@ static void ram_resource(struct device * dev, unsigned long index, resource->size = ((resource_t)sizek) << 10; resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \ IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; + printk(BIOS_INFO, "%s: add ram resoource %d bytes\n", __func__, resource->size); } static void pci_domain_set_resources(struct device * dev) diff --git a/util/dtc/flattree.c b/util/dtc/flattree.c index b24d893a8c..b93776712a 100644 --- a/util/dtc/flattree.c +++ b/util/dtc/flattree.c @@ -554,6 +554,8 @@ static void linuxbios_emit_special(FILE *e, struct node *tree) } if (tree->next_sibling) fprintf(f, "\t.sibling = &dev_%s,\n", tree->next_sibling->label); + if (tree->next) + fprintf(f, "\t.next = &dev_%s,\n", tree->next->label); /* now do we do next? */ /* this will need to do a bus for every child. And, below, we're going to need to find which bus we're on*/ /* for now, let's keep it to the minimum that will work, while we see if we like this. */ @@ -1098,6 +1100,17 @@ labeltree(struct node *tree) } +/* the root, weirdly enough, is last on the 'next' chain. yuck. */ +void fix_next(struct node *root){ + extern struct node *first_node; + struct node *next2last, *next; + for(next = first_node; next; next = next->next) + if (next->next == root) + next2last = next; + next2last->next = NULL; + root->next = first_node; + first_node = root; +} void dt_to_linuxbios(FILE *f, struct boot_info *bi, int version, int boot_cpuid_phys) { @@ -1124,6 +1137,7 @@ void dt_to_linuxbios(FILE *f, struct boot_info *bi, int version, int boot_cpuid_ bi->dt->name = bi->dt->label = "root"; /* steps: emit all structs. Then emit the initializers, with the pointers to other structs etc. */ + fix_next(bi->dt); /* emit any includes that we need -- TODO: ONLY ONCE PER TYPE*/ fprintf(f, "#include \n#include \n"); flatten_tree_emit_includes(bi->dt, &linuxbios_emitter, f, &strbuf, vi);