From 01d7545b506c7c243fc639d8bebb4f9dc49a17d1 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Fri, 23 Feb 2007 10:38:22 +0000 Subject: [PATCH] Set up default root device. Fix up printk stuff. Fix up dts to set up ops struct member. Fix dts for qemu mainboard. We are getting past stage2 now, it is time for elfboot. Signed-off-by: Ronald G. Minnich Acked-by: Ronald G. Minnich Acked-by: Stefan Reinauer git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@88 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- arch/x86/Makefile | 3 +- arch/x86/cachemain.c | 4 +- devices/device.c | 32 ++++++------- devices/root_device.c | 57 ++++++++++++----------- include/device/device.h | 2 + mainboard/emulation/qemu-i386/dts | 5 +- mainboard/emulation/qemu-i386/mainboard.c | 7 ++- util/dtc/flattree.c | 10 ++++ 8 files changed, 69 insertions(+), 51 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index a8490b795f..5fd004f4df 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -56,6 +56,7 @@ $(obj)/linuxbios.stage2: $(obj)/stage0.init $(obj)/statictree.o $(Q)$(CC) $(INITCFLAGS) -c $(src)/lib/stage2.c -o $(obj)/stage2.o $(Q)$(CC) $(INITCFLAGS) -c $(src)/devices/device.c -o $(obj)/device.o $(Q)$(CC) $(INITCFLAGS) -c $(src)/devices/device_util.c -o $(obj)/device_util.o + $(Q)$(CC) $(INITCFLAGS) -c $(src)/devices/root_device.c -o $(obj)/root_device.o $(Q)$(CC) $(INITCFLAGS) -c $(src)/lib/mem.c -o $(obj)/mem.o $(Q)$(CC) $(INITCFLAGS) -c $(src)/lib/malloc.c -o $(obj)/malloc.o $(Q)$(CC) $(INITCFLAGS) -c $(src)/lib/clog2.c -o $(obj)/clog2.o @@ -65,7 +66,7 @@ $(obj)/linuxbios.stage2: $(obj)/stage0.init $(obj)/statictree.o # leave a .o with full symbols in it for debugging. $(Q)cd $(obj); $(LD) -R $(obj)/stage0.o -Ttext 0x1000 \ -o $(obj)/linuxbios.stage2.o stage2.o device.o \ - device_util.o mem.o malloc.o clog2.o mainboard.o \ + device_util.o root_device.o mem.o malloc.o clog2.o mainboard.o \ statictree.o $(Q)objcopy -O binary $(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2 diff --git a/arch/x86/cachemain.c b/arch/x86/cachemain.c index 1449697831..dffe9fdc62 100644 --- a/arch/x86/cachemain.c +++ b/arch/x86/cachemain.c @@ -200,9 +200,7 @@ printk(BIOS_INFO, "Start search at 0x%x, size %d\n", archive.start, archive.len) #endif ); - ret = run_file(&archive, "normal/stage2", (void *)0x1000); - if (ret) - die("Failed stage2 code\n"); + (void) run_file(&archive, "normal/stage2", (void *)0x1000); printk(BIOS_INFO, "Done stage2 code\n"); diff --git a/devices/device.c b/devices/device.c index ba918d2b86..f2e5e3c176 100644 --- a/devices/device.c +++ b/devices/device.c @@ -697,15 +697,15 @@ void dev_root_phase3(void) root->chip_ops->enable_dev(root); } if (!root->ops) { - printk(BIOS_ERR, "dev_root missing 'ops' initialization\n"); + printk(BIOS_ERR, "dev_root_phase3 missing 'ops' initialization\nPhase 3: Failed\n"); return; } if (!root->ops->phase3) { - printk(BIOS_ERR, "dev_root ops struct missing 'phase3' initialization in ops structure"); + printk(BIOS_ERR, "dev_root ops struct missing 'phase3' initialization in ops structure\nPhase 3: Failed"); return; } subordinate = dev_phase3(root, 0); - printk(BIOS_INFO, "done\n"); + printk(BIOS_INFO, "Phase 3: done\n"); } /** @@ -727,25 +727,25 @@ void dev_phase4(void) struct resource *io, *mem; struct device *root; - printk(BIOS_INFO, "Allocating resources...\n"); + printk(BIOS_INFO, "Phase 4:Allocating resources...\n"); root = &dev_root; if (!root->ops) { - printk(BIOS_ERR, "dev_root missing ops initialization\n"); + printk(BIOS_ERR, "Phase 4: dev_root missing ops initialization\nPhase 4: Failed\n"); return; } if (!root->ops->phase4_read_resources) { - printk(BIOS_ERR, "dev_root ops missing read_resources\n"); + printk(BIOS_ERR, "dev_root ops missing read_resources\nPhase 4: Failed\n"); return; } if (!root->ops->phase4_set_resources) { - printk(BIOS_ERR, "dev_root ops missing set_resources\n"); + printk(BIOS_ERR, "dev_root ops missing set_resources\nPhase 4: Failed\n"); return; } - printk(BIOS_INFO, "Reading resources...\n"); + printk(BIOS_INFO, "Phase 4: Reading resources...\n"); root->ops->phase4_read_resources(root); - printk(BIOS_INFO, "Done reading resources.\n"); + printk(BIOS_INFO, "Phase 4: Done reading resources.\n"); /* Get the resources */ io = &root->resource[0]; @@ -767,15 +767,15 @@ void dev_phase4(void) #endif /* Store the computed resource allocations into device registers ... */ - printk(BIOS_INFO, "Setting resources...\n"); + printk(BIOS_INFO, "Phase 4: Setting resources...\n"); root->ops->phase4_set_resources(root); - printk(BIOS_INFO, "Done setting resources.\n"); + printk(BIOS_INFO, "Phase 4: Done setting resources.\n"); #if 0 mem->flags |= IORESOURCE_STORED; report_resource_stored(root, mem, ""); #endif - printk(BIOS_INFO, "Done allocating resources.\n"); + printk(BIOS_INFO, "Phase 4: Done allocating resources.\n"); } /** @@ -786,12 +786,12 @@ void dev_phase4(void) */ void dev_root_phase5(void) { - printk(BIOS_INFO, "Enabling resources...\n"); + printk(BIOS_INFO, "Phase 5: Enabling resources...\n"); /* now enable everything. */ dev_phase5(&dev_root); - printk(BIOS_INFO, "done.\n"); + printk(BIOS_INFO, "Phase 5: done.\n"); } /** @@ -811,10 +811,10 @@ void dev_phase6(void) dev->ops && dev->ops->phase6) { if (dev->path.type == DEVICE_PATH_I2C) { - printk(BIOS_DEBUG, "smbus: %s[%d]->", + printk(BIOS_DEBUG, "Phase 6: smbus: %s[%d]->", dev_path(dev->bus->dev), dev->bus->link); } - printk(BIOS_DEBUG, "%s init\n", dev_path(dev)); + printk(BIOS_DEBUG, "Phase 6: %s init\n", dev_path(dev)); dev->initialized = 1; dev->ops->phase6(dev); } diff --git a/devices/root_device.c b/devices/root_device.c index 599f5efa0c..5bfd893170 100644 --- a/devices/root_device.c +++ b/devices/root_device.c @@ -17,14 +17,14 @@ #include #include #include -#include +//#include /** * Read the resources for the root device, * that encompass the resources for the entire system. * @param root Pointer to the device structure for the system root device */ -void root_dev_read_resources(device_t root) +void root_dev_read_resources(struct device * root) { struct resource *resource; @@ -58,7 +58,7 @@ void root_dev_read_resources(device_t root) * and every device under it which are all of the devices. * @param root Pointer to the device structure for the system root device */ -void root_dev_set_resources(device_t root) +void root_dev_set_resources(struct device * root) { struct bus *bus; @@ -67,7 +67,7 @@ void root_dev_set_resources(device_t root) &root->resource[0], IORESOURCE_IO, IORESOURCE_IO); compute_allocate_resource(bus, &root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM); - assign_resources(bus); + phase4_assign_resources(bus); } /** @@ -93,12 +93,12 @@ void root_dev_set_resources(device_t root) * @return Largest bus number used. */ static int smbus_max = 0; -unsigned int scan_static_bus(device_t bus, unsigned int max) +unsigned int scan_static_bus(struct device * bus, unsigned int max) { - device_t child; + struct device * child; unsigned link; - printk_spew("%s for %s\n", __func__, dev_path(bus)); + printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus)); for(link = 0; link < bus->links; link++) { /* for smbus bus enumerate */ @@ -110,28 +110,29 @@ unsigned int scan_static_bus(device_t bus, unsigned int max) if (child->chip_ops && child->chip_ops->enable_dev) { child->chip_ops->enable_dev(child); } - if (child->ops && child->ops->enable) { - child->ops->enable(child); + /* sigh. Have to enable to scan ... */ + if (child->ops && child->ops->phase5) { + child->ops->phase5(child); } if (child->path.type == DEVICE_PATH_I2C) { - printk_debug("smbus: %s[%d]->", + printk(BIOS_DEBUG, "smbus: %s[%d]->", dev_path(child->bus->dev), child->bus->link ); } - printk_debug("%s %s\n", + printk(BIOS_DEBUG, "%s %s\n", dev_path(child), child->enabled?"enabled": "disabled"); } } for(link = 0; link < bus->links; link++) { for(child = bus->link[link].children; child; child = child->sibling) { - if (!child->ops || !child->ops->scan_bus) + if (!child->ops || !child->ops->phase3) continue; - printk_spew("%s scanning...\n", dev_path(child)); - max = scan_bus(child, max); + printk(BIOS_SPEW, "%s scanning...\n", dev_path(child)); + max = dev_phase3(child, max); } } - printk_spew("%s for %s done\n", __func__, dev_path(bus)); + printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus)); return max; } @@ -149,18 +150,18 @@ unsigned int scan_static_bus(device_t bus, unsigned int max) * enable_resources() -> device_operation::enable_resources() * device_operation::enable_resources() -> enable_children_resources() */ -void enable_childrens_resources(device_t dev) +void enable_childrens_resources(struct device * dev) { unsigned link; for(link = 0; link < dev->links; link++) { - device_t child; + struct device * child; for(child = dev->link[link].children; child; child = child->sibling) { - enable_resources(child); + dev_phase5(child); } } } -void root_dev_enable_resources(device_t dev) +void root_dev_enable_resources(struct device * dev) { enable_childrens_resources(dev); } @@ -173,19 +174,19 @@ void root_dev_enable_resources(device_t dev) * * This function is the default scan_bus() method of the root device. */ -unsigned int root_dev_scan_bus(device_t root, unsigned int max) +unsigned int root_dev_scan_bus(struct device * root, unsigned int max) { return scan_static_bus(root, max); } -void root_dev_init(device_t root) +void root_dev_init(struct device * root) { } void root_dev_reset(struct bus *bus) { - printk_info("Reseting board...\n"); - hard_reset(); + printk(BIOS_INFO, "Reseting board... NOT! Define hard_reset please\n"); +// hard_reset(); } /** @@ -196,11 +197,11 @@ void root_dev_reset(struct bus *bus) * of a motherboard can override this if you want non-default behavior. */ struct device_operations default_dev_ops_root = { - .read_resources = root_dev_read_resources, - .set_resources = root_dev_set_resources, - .enable_resources = root_dev_enable_resources, - .init = root_dev_init, - .scan_bus = root_dev_scan_bus, + .phase4_read_resources = root_dev_read_resources, + .phase4_set_resources = root_dev_set_resources, + .phase5 = root_dev_enable_resources, + .phase6 = root_dev_init, + .phase3 = root_dev_scan_bus, .reset_bus = root_dev_reset, }; diff --git a/include/device/device.h b/include/device/device.h index 926b747da4..a60776398d 100644 --- a/include/device/device.h +++ b/include/device/device.h @@ -37,6 +37,8 @@ struct bus; /* we are moving from the confusing naming scheme to a numbering scheme. We are hoping * this makes it easier for people to know the order of operations. + * So far, it is not clear. We may actually want to have names like dev_phase5_enable_resources. + * The numbering is nice, the naming is nice, what to do? */ struct device_operations { // void (*enable)(struct device * dev); diff --git a/mainboard/emulation/qemu-i386/dts b/mainboard/emulation/qemu-i386/dts index 25ead1adbf..883198a642 100644 --- a/mainboard/emulation/qemu-i386/dts +++ b/mainboard/emulation/qemu-i386/dts @@ -1,6 +1,7 @@ /{ + config="mainboard,emulation,qemu-i386"; + cpus { - config="mainboard,emulation,qemu-i386"; emulation,qemu-i386@0{ enabled; on_mainboard; @@ -22,7 +23,7 @@ %% -struct mainboard_emulation_qemu_i386_config cpus = { +struct mainboard_emulation_qemu_i386_config root = { .nothing = 1, }; diff --git a/mainboard/emulation/qemu-i386/mainboard.c b/mainboard/emulation/qemu-i386/mainboard.c index 1037bb1688..9db2e6b92f 100644 --- a/mainboard/emulation/qemu-i386/mainboard.c +++ b/mainboard/emulation/qemu-i386/mainboard.c @@ -22,6 +22,11 @@ #include // #include "dtc.h" +static void enable_dev(struct device *dev){ + printk(BIOS_INFO, "qemu-i386 enable_dev done\n"); +} + struct chip_operations mainboard_emulation_qemu_i386_ops = { - .name = "QEMU Mainboard" + .name = "QEMU Mainboard", + .enable_dev = enable_dev }; diff --git a/util/dtc/flattree.c b/util/dtc/flattree.c index 7bcce8dbac..1ce8320b44 100644 --- a/util/dtc/flattree.c +++ b/util/dtc/flattree.c @@ -500,10 +500,13 @@ static void linuxbios_emit_special(void *e, struct node *tree) { FILE *f = e; struct property *prop; + int ops_set = 0; + int is_root = 0; fprintf(f, "struct device dev_%s = {\n", tree->label); /* special case -- the root has a distinguished path */ if (! strncmp(tree->label, "root", 4)){ + is_root = 1; fprintf(f, "\t.path = { .type = DEVICE_PATH_ROOT },\n"); } @@ -528,6 +531,10 @@ static void linuxbios_emit_special(void *e, struct node *tree) fprintf(f, "\t.chip_ops = &%s_ops,\n", clean(prop->val.val, 0)); fprintf(f, "\t.chip_info = &%s,\n", clean(tree->label, 1)); } + if (streq(prop->name, "ops")){ + fprintf(f, "\t.ops = &%s,\n", clean(prop->val.val, 0)); + ops_set = 1; + } } if (tree->next_sibling) @@ -554,6 +561,9 @@ static void linuxbios_emit_special(void *e, struct node *tree) if (tree->next) fprintf(f, "\t.next = &dev_%s,\n", tree->next->label); + if ((! ops_set) && is_root) + fprintf(f, "\t.ops = &default_dev_ops_root,\n"); + fprintf(f, "};\n"); }