[XenPPC] [xenppc-unstable] [POWERPC] memory clean up (phase 3)

2006-08-17 Thread Xen patchbot-xenppc-unstable
# 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)

2006-08-17 Thread Jimi Xenidis
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)) {