grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ppc rfc] memory allocation


From: Hollis Blanchard
Subject: [ppc rfc] memory allocation
Date: Mon, 11 Oct 2004 23:42:23 -0500

This patch (yes I'm sorry its whitespace will be eaten) changes the memory allocation layout: we start after 0x3000 (the exception vectors), then use the /memory/available property to claim all memory up to 20M, where Linux expects to live.

Also we can move grub_console_init() earlier, which I think is a good thing.

We should probably find the true length of /memory/available and then use alloca() to allocate it, since on large or complicated systems it might be large.

I haven't tested this all the way on New World yet (getting the GRUB prompt works), but is the general idea ok?

-Hollis

Index: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v
retrieving revision 1.6
diff -u -r1.6 ieee1275.h
--- include/grub/powerpc/ieee1275/ieee1275.h 12 Oct 2004 03:56:10 -0000 1.6
+++ include/grub/powerpc/ieee1275/ieee1275.h    12 Oct 2004 04:29:11 -0000
@@ -49,6 +49,9 @@
 /* Old World firmware fails seek when "dev:0" is opened.  */
 #define GRUB_IEEE1275_NO_PARTITION_0 0x1

+#define GRUB_IEEE1275_OS_BASE 0x01400000
+#define GRUB_IEEE1275_RESERVED_MEM 0x00003000
+
 

 uint32_t EXPORT_FUNC(grub_ieee1275_decode_int_4) (unsigned char *p);
@@ -98,6 +101,7 @@
int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
                                          int index, int r, int g, int b);

+void EXPORT_FUNC(abort) (void);

 grub_err_t EXPORT_FUNC(grub_devalias_iterate)
      (int (*hook) (struct grub_ieee1275_devalias *alias));
Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v
retrieving revision 1.6
diff -u -r1.6 init.c
--- kern/powerpc/ieee1275/init.c        3 Oct 2004 09:19:10 -0000       1.6
+++ kern/powerpc/ieee1275/init.c        12 Oct 2004 04:29:11 -0000
@@ -46,14 +46,52 @@
   for (;;);
 }

+/* Find free memory in /memory/available. Use it all, up to the OS base. */
+void
+grub_arch_mem_init(void)
+{
+  char data[64];
+  grub_ieee1275_phandle_t memory;
+  grub_size_t actual;
+  struct grub_ieee1275_mem_region *range;
+
+  if (grub_ieee1275_finddevice ("/memory", &memory))
+    abort();
+
+ if (grub_ieee1275_get_property (memory, "available", data, sizeof data,
+                                 &actual))
+    abort ();
+
+  for (range = (struct grub_ieee1275_mem_region *)data;
+       range < (struct grub_ieee1275_mem_region *)(data + actual);
+       range++) {
+    /* Leave GRUB_IEEE1275_OS_BASE and above free.  */
+    if (range->start > GRUB_IEEE1275_OS_BASE)
+      continue;
+    if (range->start + range->size > GRUB_IEEE1275_OS_BASE)
+      range->size = GRUB_IEEE1275_OS_BASE - range->start;
+
+ /* briQ firmware leaves the exception vectors in /memory/available, but
+     * we should really avoid that.  */
+    if (range->start < GRUB_IEEE1275_RESERVED_MEM)
+      {
+       if (range->start + range->size < GRUB_IEEE1275_RESERVED_MEM)
+         continue;
+       range->size -= GRUB_IEEE1275_RESERVED_MEM - range->start;
+       range->start = GRUB_IEEE1275_RESERVED_MEM;
+      }
+
+    if (grub_ieee1275_claim (range->start, range->size, 0, 0) == -1)
+      continue;
+    grub_mm_init_region ((void *) range->start, range->size);
+  }
+}
+
 void
 grub_machine_init (void)
 {
-  if (grub_ieee1275_claim (0x300000, 0x150000, 0, 0) == -1)
-    abort (); /* Damn, we are in trouble!  */
-
-  /* The memory allocations were copied from yaboot.  */
-  grub_mm_init_region ((void *) 0x300000, 0x150000);
+  grub_console_init ();
+  grub_arch_mem_init ();

   /* XXX: Loadable modules are not supported.  */
   grub_env_set ("prefix", "");
@@ -64,7 +102,6 @@
   grub_linux_init ();
   grub_linux_normal_init ();
   grub_ofdisk_init ();
-  grub_console_init ();
 }

 int





reply via email to

[Prev in Thread] Current Thread [Next in Thread]