[XenPPC] [xenppc-unstable] [POWERPC] memory clean up (phase 3)
# HG changeset patch # User Jimi Xenidis [EMAIL PROTECTED] # Node ID 697bd866535ba6d73de5fc6c988e96bc034bbdd0 # Parent 5e4dcc79f29a9dc5217a86b561e36b8d07c2d7dc [POWERPC] memory clean up (phase 3) The following changes are included: Open Firmware: - use all args for of_claim() - handle broken claim methods as best we can - describe where the Dom0 image is comming from - stop copying the Dom0 image Heaps: - make sure we do not overwrite the oftree - release as much memory as possible to xenheap - release Dom0 image after we are done with it - Lots of checks and simplifications --- xen/arch/powerpc/boot_of.c | 127 +++-- xen/arch/powerpc/setup.c | 107 + 2 files changed, 137 insertions(+), 97 deletions(-) diff -r 5e4dcc79f29a -r 697bd866535b xen/arch/powerpc/boot_of.c --- a/xen/arch/powerpc/boot_of.cThu Aug 17 07:10:57 2006 -0400 +++ b/xen/arch/powerpc/boot_of.cThu Aug 17 16:21:34 2006 -0400 @@ -26,6 +26,7 @@ #include xen/spinlock.h #include xen/serial.h #include xen/time.h +#include xen/sched.h #include asm/page.h #include asm/io.h #include exceptions.h @@ -322,17 +323,18 @@ static void __init of_test(const char *o } } -static int __init of_claim(void * virt, u32 size) +static int __init of_claim(u32 virt, u32 size, u32 align) { int rets[1] = { OF_FAILURE }; -of_call(claim, 3, 1, rets, virt, size, 0/*align*/); +of_call(claim, 3, 1, rets, virt, size, align); if (rets[0] == OF_FAILURE) { -DBG(%s 0x%p 0x%08x - FAIL\n, __func__, virt, size); -return OF_FAILURE; -} - -DBG(%s 0x%p 0x%08x - 0x%x\n, __func__, virt, size, rets[0]); +DBG(%s 0x%08x 0x%08x 0x%08x - FAIL\n, __func__, virt, size, align); +return OF_FAILURE; +} + +DBG(%s 0x%08x 0x%08x 0x%08x - 0x%08x\n, __func__, virt, size, align, +rets[0]); return rets[0]; } @@ -683,32 +685,47 @@ static int boot_of_fixup_chosen(void *me } static ulong space_base; -static ulong find_space(u32 size, ulong align, multiboot_info_t *mbi) +static int broken_claim; + +/* + * The following function is necessary because we cannot depend on all + * FW to actually allocate us any space, so we look for it _hoping_ + * that at least is will fail if we try to claim something that + * belongs to FW. This hope does not seem to be true on some version + * of PIBS. + */ +static ulong find_space(u32 size, u32 align, multiboot_info_t *mbi) { memory_map_t *map = (memory_map_t *)((ulong)mbi-mmap_addr); ulong eomem = ((u64)map-length_high 32) | (u64)map-length_low; ulong base; -of_printf(%s base=0x%016lx eomem=0x%016lx size=0x%08x align=0x%lx\n, +if (size == 0) return base; + +if (align == 0) +of_panic(cannot call %s() with align of 0\n, __func__); + +if (!broken_claim) { +/* just try and claim it to the FW chosen address */ +base = of_claim(0, size, align); +if (base != OF_FAILURE) +return base; +of_printf(%s: Firmware does not allocate memory for you\n, __func__); +broken_claim = 1; +} + +of_printf(%s base=0x%016lx eomem=0x%016lx size=0x%08x align=0x%x\n, __func__, space_base, eomem, size, align); base = ALIGN_UP(space_base, PAGE_SIZE); -if ((base + size) = 0x400) return 0; -if (base + size eomem) of_panic(not enough RAM\n); - -if (size == 0) return base; -if (of_claim((void*)base, size) != OF_FAILURE) { -space_base = base + size; -return base; -} else { -for(base += 0x10; (base+size) 0x400; base += 0x10) { -of_printf(Trying 0x%016lx\n, base); -if (of_claim((void*)base, size) != OF_FAILURE) { -space_base = base + size; -return base; -} -} -return 0; -} + +while ((base + size) rma_size(cpu_rma_order())) { +if (of_claim(base, size, 0) != OF_FAILURE) { +space_base = base + size; +return base; +} +base += (PAGE_SIZE align) ? PAGE_SIZE : align; +} +of_panic(Cannot find memory in the RMA\n); } /* PIBS Version 1.05. 04/26/2005 has an incorrect /ht/isa/ranges @@ -834,9 +851,8 @@ static void boot_of_module(ulong r3, ulo static module_t mods[3]; void *oftree; ulong oftree_sz = 48 * PAGE_SIZE; -char *mod0_start; +ulong mod0_start; ulong mod0_size; -ulong mod0; static const char sepr[] = -- ; extern char dom0_start[] __attribute__ ((weak)); extern char dom0_size[] __attribute__ ((weak)); @@ -844,59 +860,48 @@ static void boot_of_module(ulong r3, ulo if ((r3 0) (r4 0)) { /* was it handed to us in registers ? */ -mod0_start = (void *)r3; +mod0_start = r3; mod0_size = r4; +of_printf(%s: Dom0 was loaded and found using r3/r4: +
Re: [XenPPC] [xenppc-unstable] [POWERPC] memory clean up (phase 3)
BTW: This has been tested with DOM0_IMAGE=...vmlinux.strip, tho' it would be better to use a zImage anyway. -JX On Aug 17, 2006, at 4:21 PM, Xen patchbot-xenppc-unstable wrote: # HG changeset patch # User Jimi Xenidis [EMAIL PROTECTED] # Node ID 697bd866535ba6d73de5fc6c988e96bc034bbdd0 # Parent 5e4dcc79f29a9dc5217a86b561e36b8d07c2d7dc [POWERPC] memory clean up (phase 3) The following changes are included: Open Firmware: - use all args for of_claim() - handle broken claim methods as best we can - describe where the Dom0 image is comming from - stop copying the Dom0 image Heaps: - make sure we do not overwrite the oftree - release as much memory as possible to xenheap - release Dom0 image after we are done with it - Lots of checks and simplifications --- xen/arch/powerpc/boot_of.c | 127 ++ +-- xen/arch/powerpc/setup.c | 107 + 2 files changed, 137 insertions(+), 97 deletions(-) diff -r 5e4dcc79f29a -r 697bd866535b xen/arch/powerpc/boot_of.c --- a/xen/arch/powerpc/boot_of.cThu Aug 17 07:10:57 2006 -0400 +++ b/xen/arch/powerpc/boot_of.cThu Aug 17 16:21:34 2006 -0400 @@ -26,6 +26,7 @@ #include xen/spinlock.h #include xen/serial.h #include xen/time.h +#include xen/sched.h #include asm/page.h #include asm/io.h #include exceptions.h @@ -322,17 +323,18 @@ static void __init of_test(const char *o } } -static int __init of_claim(void * virt, u32 size) +static int __init of_claim(u32 virt, u32 size, u32 align) { int rets[1] = { OF_FAILURE }; -of_call(claim, 3, 1, rets, virt, size, 0/*align*/); +of_call(claim, 3, 1, rets, virt, size, align); if (rets[0] == OF_FAILURE) { -DBG(%s 0x%p 0x%08x - FAIL\n, __func__, virt, size); -return OF_FAILURE; -} - -DBG(%s 0x%p 0x%08x - 0x%x\n, __func__, virt, size, rets[0]); +DBG(%s 0x%08x 0x%08x 0x%08x - FAIL\n, __func__, virt, size, align); +return OF_FAILURE; +} + +DBG(%s 0x%08x 0x%08x 0x%08x - 0x%08x\n, __func__, virt, size, align, +rets[0]); return rets[0]; } @@ -683,32 +685,47 @@ static int boot_of_fixup_chosen(void *me } static ulong space_base; -static ulong find_space(u32 size, ulong align, multiboot_info_t *mbi) +static int broken_claim; + +/* + * The following function is necessary because we cannot depend on all + * FW to actually allocate us any space, so we look for it _hoping_ + * that at least is will fail if we try to claim something that + * belongs to FW. This hope does not seem to be true on some version + * of PIBS. + */ +static ulong find_space(u32 size, u32 align, multiboot_info_t *mbi) { memory_map_t *map = (memory_map_t *)((ulong)mbi-mmap_addr); ulong eomem = ((u64)map-length_high 32) | (u64)map- length_low; ulong base; -of_printf(%s base=0x%016lx eomem=0x%016lx size=0x%08x align=0x%lx\n, +if (size == 0) return base; + +if (align == 0) +of_panic(cannot call %s() with align of 0\n, __func__); + +if (!broken_claim) { +/* just try and claim it to the FW chosen address */ +base = of_claim(0, size, align); +if (base != OF_FAILURE) +return base; +of_printf(%s: Firmware does not allocate memory for you \n, __func__); +broken_claim = 1; +} + +of_printf(%s base=0x%016lx eomem=0x%016lx size=0x%08x align=0x%x\n, __func__, space_base, eomem, size, align); base = ALIGN_UP(space_base, PAGE_SIZE); -if ((base + size) = 0x400) return 0; -if (base + size eomem) of_panic(not enough RAM\n); - -if (size == 0) return base; -if (of_claim((void*)base, size) != OF_FAILURE) { -space_base = base + size; -return base; -} else { -for(base += 0x10; (base+size) 0x400; base += 0x10) { -of_printf(Trying 0x%016lx\n, base); -if (of_claim((void*)base, size) != OF_FAILURE) { -space_base = base + size; -return base; -} -} -return 0; -} + +while ((base + size) rma_size(cpu_rma_order())) { +if (of_claim(base, size, 0) != OF_FAILURE) { +space_base = base + size; +return base; +} +base += (PAGE_SIZE align) ? PAGE_SIZE : align; +} +of_panic(Cannot find memory in the RMA\n); } /* PIBS Version 1.05. 04/26/2005 has an incorrect /ht/isa/ranges @@ -834,9 +851,8 @@ static void boot_of_module(ulong r3, ulo static module_t mods[3]; void *oftree; ulong oftree_sz = 48 * PAGE_SIZE; -char *mod0_start; +ulong mod0_start; ulong mod0_size; -ulong mod0; static const char sepr[] = -- ; extern char dom0_start[] __attribute__ ((weak)); extern char dom0_size[] __attribute__ ((weak)); @@ -844,59 +860,48 @@ static void boot_of_module(ulong r3, ulo if ((r3 0) (r4 0)) {
Re: [XenPPC] [PATCH] Fix possible random return value from find_space
Thanks Amos.. I adapted it a little bit.. good catch.. pushed. -JX On Aug 17, 2006, at 6:30 PM, Amos Waterland wrote: In find_space, if the user passes zero for the size argument she will get a random value returned. Signed-off-by: Amos Waterland [EMAIL PROTECTED] --- boot_of.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -r da9637bef06a xen/arch/powerpc/boot_of.c --- a/xen/arch/powerpc/boot_of.cThu Aug 17 17:58:07 2006 -0400 +++ b/xen/arch/powerpc/boot_of.cThu Aug 17 18:28:02 2006 -0400 @@ -698,7 +698,7 @@ static ulong find_space(u32 size, u32 al { memory_map_t *map = (memory_map_t *)((ulong)mbi-mmap_addr); ulong eomem = ((u64)map-length_high 32) | (u64)map- length_low; -ulong base; +ulong base = 0x0; if (size == 0) return base; ___ Xen-ppc-devel mailing list Xen-ppc-devel@lists.xensource.com http://lists.xensource.com/xen-ppc-devel ___ Xen-ppc-devel mailing list Xen-ppc-devel@lists.xensource.com http://lists.xensource.com/xen-ppc-devel
[XenPPC] [PATCH] Init secondary processors up to assigning r13
This patch brings the secondary processors up to the point where they have a per-processor structure pointer in r13, at which point they just enter a spinloop. If you test it, you should see two additional pieces of output on your console: spinning up secondary processor #1: ping = 0x: pong = 0x1 spinning up secondary processor #2: ping = 0x: pong = 0x2 spinning up secondary processor #3: ping = 0x: pong = 0x3 (XEN) CPU #1: Hello World! SP = 1fe60 TOC = 757e78 HID0 = 5111818000 (XEN) CPU #2: Hello World! SP = 1be60 TOC = 757e78 HID0 = 5111818000 (XEN) CPU #3: Hello World! SP = 79fe60 TOC = 757e78 HID0 = 5111818000 I think this patch is a candidate for merging. I will submit a patch next for smp_processor_id, and then one for making the secondary processors join the idle domain, but I would like to have any necessary discussion about this portion first. Note that this patch also makes arch/powerpc build with -Wshadow, since otherwise it is way too easy to accidentaly shadow the global parea variable which is supposed to only be referred to in r13. Tested on systemsim-gpul with up to four simulated processors, Maple-D with two processors, JS20 with two processors, and JS21 with four processors. Signed-off-by: Amos Waterland [EMAIL PROTECTED] --- arch/powerpc/Makefile |2 - arch/powerpc/boot_of.c | 53 +--- arch/powerpc/mpic.c |2 - arch/powerpc/ofd_fixup.c|4 +- arch/powerpc/powerpc64/exceptions.S | 31 + arch/powerpc/powerpc64/ppc970.c | 22 -- arch/powerpc/setup.c| 52 ++- include/asm-powerpc/config.h|2 - include/asm-powerpc/current.h |3 +- include/asm-powerpc/processor.h |2 - 10 files changed, 152 insertions(+), 21 deletions(-) diff -r 7855f2e80748 xen/arch/powerpc/Makefile --- a/xen/arch/powerpc/Makefile Thu Aug 17 20:38:08 2006 -0400 +++ b/xen/arch/powerpc/Makefile Thu Aug 17 22:24:30 2006 -0400 @@ -46,7 +46,7 @@ obj-y += elf32.o # These are extra warnings like for the arch/ppc directory but may not # allow the rest of the tree to build. -PPC_C_WARNINGS += -Wundef -Wmissing-prototypes -Wmissing-declarations +PPC_C_WARNINGS += -Wundef -Wmissing-prototypes -Wmissing-declarations -Wshadow CFLAGS += $(PPC_C_WARNINGS) LINK=0x40 diff -r 7855f2e80748 xen/arch/powerpc/boot_of.c --- a/xen/arch/powerpc/boot_of.cThu Aug 17 20:38:08 2006 -0400 +++ b/xen/arch/powerpc/boot_of.cThu Aug 17 22:24:30 2006 -0400 @@ -31,6 +31,9 @@ #include asm/io.h #include exceptions.h #include of-devtree.h + +/* Secondary processors use this for handshaking with main processor. */ +volatile unsigned int __spin_ack; static ulong of_vec; static ulong of_msr; @@ -955,7 +958,7 @@ static int __init boot_of_cpus(void) static int __init boot_of_cpus(void) { int cpus; -int cpu; +int cpu, bootcpu; int result; u32 cpu_clock[2]; @@ -980,10 +983,53 @@ static int __init boot_of_cpus(void) cpu_khz /= 1000; of_printf(OF: clock-frequency = %ld KHz\n, cpu_khz); -/* FIXME: should not depend on the boot CPU bring the first child */ +/* Look up which CPU we are running on right now. */ +result = of_getprop(bof_chosen, cpu, bootcpu, sizeof (bootcpu)); +if (result == OF_FAILURE) +of_panic(Failed to look up boot cpu\n); + cpu = of_getpeer(cpu); while (cpu 0) { -of_start_cpu(cpu, (ulong)spin_start, 0); +unsigned int cpuid, ping, pong; +unsigned long now, then, timeout; + +if (cpu == bootcpu) { +of_printf(skipping boot cpu!\n); +continue; +} + +result = of_getprop(cpu, reg, cpuid, sizeof(cpuid)); +if (result == OF_FAILURE) +of_panic(cpuid lookup failed\n); + +of_printf(spinning up secondary processor #%d: , cpuid); + +__spin_ack = ~0x0; +ping = __spin_ack; +pong = __spin_ack; +of_printf(ping = 0x%x: , ping); + +mb(); +result = of_start_cpu(cpu, (ulong)spin_start, cpuid); +if (result == OF_FAILURE) +of_panic(start cpu failed\n); + +/* We will give the secondary processor five seconds to reply. */ +then = mftb(); +timeout = then + (5 * timebase_freq); + +do { +now = mftb(); +if (now = timeout) { +of_printf(BROKEN: ); +break; +} + +mb(); +pong = __spin_ack; +} while (pong == ping); +of_printf(pong = 0x%x\n, pong); + cpu = of_getpeer(cpu); } return 1; @@ -1031,6 +1077,7 @@ multiboot_info_t __init *boot_of_init( boot_of_rtas(); /* end of OF */ +of_printf(Quiescing Open Firmware ...\n); of_call(quiesce, 0, 0, NULL); return mbi; diff -r