[SeaBIOS] [PATCH 1/5] POST: Consolidate platform preinit() calls.

Kevin O'Connor kevin at koconnor.net
Fri Feb 8 06:06:55 CET 2013


Consolidate the X_preinit() calls together so that a single
per-platform preinit() call fully handles the pre-relocation phase.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/coreboot.c |  6 ++++++
 src/paravirt.c | 10 ++++++++-
 src/paravirt.h |  2 +-
 src/post.c     | 43 +++++++++++++++++----------------------
 src/xen.c      | 64 +++++++++++++++++++++++++++++++---------------------------
 src/xen.h      |  1 -
 6 files changed, 69 insertions(+), 57 deletions(-)

diff --git a/src/coreboot.c b/src/coreboot.c
index 5d013cf..57c9737 100644
--- a/src/coreboot.c
+++ b/src/coreboot.c
@@ -125,6 +125,8 @@ const char *CBvendor = "", *CBpart = "";
 void
 coreboot_preinit(void)
 {
+    if (!CONFIG_COREBOOT)
+        return;
     dprintf(3, "Attempting to find coreboot table\n");
 
     // Find coreboot table.
@@ -176,6 +178,9 @@ coreboot_preinit(void)
         dprintf(1, "Found mainboard %s %s\n", CBvendor, CBpart);
     }
 
+    // Setup malloc.
+    malloc_preinit();
+
     return;
 
 fail:
@@ -184,6 +189,7 @@ fail:
     RamSize = 16*1024*1024;
     RamSizeOver4G = 0;
     add_e820(0, 16*1024*1024, E820_RAM);
+    malloc_preinit();
     return;
 }
 
diff --git a/src/paravirt.c b/src/paravirt.c
index 9022186..ebab256 100644
--- a/src/paravirt.c
+++ b/src/paravirt.c
@@ -22,8 +22,13 @@
 int qemu_cfg_present;
 
 void
-qemu_ramsize_preinit(void)
+qemu_preinit(void)
 {
+    if (!CONFIG_QEMU)
+        return;
+
+    qemu_cfg_preinit();
+
     // On emulators, get memory size from nvram.
     u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16)
               | (inb_cmos(CMOS_MEM_EXTMEM2_HIGH) << 24));
@@ -61,6 +66,9 @@ qemu_ramsize_preinit(void)
         // other page for EPT real mode pagetable
         add_e820(0xfffbc000, 4*4096, E820_RESERVED);
     }
+
+    // Setup malloc.
+    malloc_preinit();
 }
 
 void
diff --git a/src/paravirt.h b/src/paravirt.h
index 4f2d5b8..2448993 100644
--- a/src/paravirt.h
+++ b/src/paravirt.h
@@ -43,7 +43,7 @@ static inline int kvm_para_available(void)
 
 extern int qemu_cfg_present;
 
-void qemu_ramsize_preinit(void);
+void qemu_preinit(void);
 void qemu_biostable_setup(void);
 void qemu_cfg_preinit(void);
 int qemu_cfg_show_boot_menu(void);
diff --git a/src/post.c b/src/post.c
index f2fabbb..4ab020c 100644
--- a/src/post.c
+++ b/src/post.c
@@ -311,27 +311,6 @@ reloc_preinit(void *f, void *arg)
     func(arg);
 }
 
-// Setup for code relocation and then relocate.
-void VISIBLE32INIT
-dopost(void)
-{
-    // Check if we are running under Xen.
-    xen_preinit();
-
-    // Detect ram and setup internal malloc.
-    qemu_cfg_preinit();
-    if (CONFIG_COREBOOT)
-        coreboot_preinit();
-    else if (usingXen())
-        xen_ramsize_preinit();
-    else
-        qemu_ramsize_preinit();
-    malloc_preinit();
-
-    // Relocate initialization code and call maininit().
-    reloc_preinit(maininit, NULL);
-}
-
 // Startup debug output and display software version.
 static void
 debug_splash(void)
@@ -346,12 +325,28 @@ void VISIBLE32INIT
 handle_elf(void)
 {
     debug_splash();
-    dopost();
+
+    coreboot_preinit();
+    xen_preinit();
+
+    // Relocate initialization code and call maininit().
+    reloc_preinit(maininit, NULL);
+}
+
+// Setup code when launched from qemu/kvm/bochs (after memory unlocked).
+void VISIBLE32INIT
+qemu_post(void)
+{
+    qemu_preinit();
+
+    // Relocate initialization code and call maininit().
+    reloc_preinit(maininit, NULL);
 }
 
 // Entry point for Power On Self Test (POST) when running under
 // qemu/kvm/bochs.  Under qemu the memory at 0xc0000-0xfffff may be
-// read-only, so unlock the ram as the first step of booting.
+// read-only and only the first 128K of code may be present.  So
+// unlock and copy all of ram as the first step of booting.
 void VISIBLE32FLAT
 handle_post(void)
 {
@@ -361,5 +356,5 @@ handle_post(void)
     make_bios_writable();
 
     // Now that memory is read/writable - start post process.
-    dopost();
+    qemu_post();
 }
diff --git a/src/xen.c b/src/xen.c
index c9759f0..a506b42 100644
--- a/src/xen.c
+++ b/src/xen.c
@@ -6,7 +6,7 @@
 
 #include "config.h"
 #include "xen.h"
-
+#include "paravirt.h" // qemu_cfg_preinit
 #include "memmap.h" // add_e820
 #include "types.h" // ASM32FLAT
 #include "util.h" // copy_acpi_rsdp
@@ -76,8 +76,40 @@ void xen_preinit(void)
             break;
         }
     }
-    if (!xen_cpuid_base)
+    if (!xen_cpuid_base) {
         dprintf(1, "No Xen hypervisor found.\n");
+        return;
+    }
+
+    qemu_cfg_preinit();
+
+    u64 maxram = 0, maxram_over4G = 0;
+    struct xen_seabios_info *info = (void *)INFO_PHYSICAL_ADDRESS;
+    validate_info(info);
+
+    dprintf(1, "xen: copy e820...\n");
+
+    struct e820entry *e820 = (struct e820entry *)info->e820;
+    int i;
+    for (i = 0; i < info->e820_nr; i++) {
+        struct e820entry *e = &e820[i];
+        if (e->type == E820_ACPI || e->type == E820_RAM) {
+            u64 end = e->start + e->size;
+            if (end > 0x100000000ull) {
+                end -= 0x100000000ull;
+                if (end > maxram_over4G)
+                    maxram_over4G = end;
+            } else if (end > maxram)
+                maxram = end;
+        }
+        add_e820(e->start, e->size, e->type);
+    }
+
+    RamSize = maxram;
+    RamSizeOver4G = maxram_over4G;
+
+    // Setup malloc.
+    malloc_preinit();
 }
 
 static int hypercall_xen_version( int cmd, void *arg)
@@ -121,31 +153,3 @@ void xen_biostable_setup(void)
     for (i=0; i<info->tables_nr; i++)
         copy_table(tables[i]);
 }
-
-void xen_ramsize_preinit(void)
-{
-    u64 maxram = 0, maxram_over4G = 0;
-    int i;
-    struct xen_seabios_info *info = (void *)INFO_PHYSICAL_ADDRESS;
-    struct e820entry *e820 = (struct e820entry *)info->e820;
-    validate_info(info);
-
-    dprintf(1, "xen: copy e820...\n");
-
-    for (i = 0; i < info->e820_nr; i++) {
-        struct e820entry *e = &e820[i];
-        if (e->type == E820_ACPI || e->type == E820_RAM) {
-            u64 end = e->start + e->size;
-            if (end > 0x100000000ull) {
-                end -= 0x100000000ull;
-                if (end > maxram_over4G)
-                    maxram_over4G = end;
-            } else if (end > maxram)
-                maxram = end;
-        }
-        add_e820(e->start, e->size, e->type);
-    }
-
-    RamSize = maxram;
-    RamSizeOver4G = maxram_over4G;
-}
diff --git a/src/xen.h b/src/xen.h
index 9b4178a..2be2453 100644
--- a/src/xen.h
+++ b/src/xen.h
@@ -7,7 +7,6 @@
 extern u32 xen_cpuid_base;
 
 void xen_preinit(void);
-void xen_ramsize_preinit(void);
 void xen_hypercall_setup(void);
 void xen_biostable_setup(void);
 
-- 
1.7.11.7




More information about the SeaBIOS mailing list