Xen and QEMU had multiple platform preinit() calls that were invoked right after each other. Merge these together. This simplifies the preinit code.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/coreboot.c | 6 ++---- src/paravirt.c | 10 ++++++++-- src/paravirt.h | 3 +-- src/post.c | 38 ++++++++++++++------------------------ src/xen.c | 57 ++++++++++++++++++++++++++++----------------------------- src/xen.h | 1 - 6 files changed, 53 insertions(+), 62 deletions(-)
diff --git a/src/coreboot.c b/src/coreboot.c index 5d013cf..9f695ad 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. @@ -165,10 +167,6 @@ coreboot_preinit(void) RamSize = maxram; RamSizeOver4G = maxram_over4G;
- // Ughh - coreboot likes to set a map at 0x0000-0x1000, but this - // confuses grub. So, override it. - add_e820(0, 16*1024, E820_RAM); - struct cb_mainboard *cbmb = find_cb_subtable(cbh, CB_TAG_MAINBOARD); if (cbmb) { CBvendor = &cbmb->strings[cbmb->vendor_idx]; diff --git a/src/paravirt.c b/src/paravirt.c index 9022186..5cfda66 100644 --- a/src/paravirt.c +++ b/src/paravirt.c @@ -18,12 +18,16 @@ #include "acpi.h" // acpi_setup #include "mptable.h" // mptable_setup #include "pci.h" // create_pirtable +#include "xen.h" // usingXen
int qemu_cfg_present;
-void +static void qemu_ramsize_preinit(void) { + if (CONFIG_COREBOOT || usingXen()) + return; + // On emulators, get memory size from nvram. u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16) | (inb_cmos(CMOS_MEM_EXTMEM2_HIGH) << 24)); @@ -98,7 +102,7 @@ qemu_cfg_read_entry(void *buf, int e, int len) qemu_cfg_read(buf, len); }
-void qemu_cfg_preinit(void) +void qemu_preinit(void) { char *sig = "QEMU"; int i; @@ -116,6 +120,8 @@ void qemu_cfg_preinit(void) break; } dprintf(4, "qemu_cfg_present=%d\n", qemu_cfg_present); + + qemu_ramsize_preinit(); }
void qemu_cfg_get_uuid(u8 *uuid) diff --git a/src/paravirt.h b/src/paravirt.h index 4f2d5b8..04ebde5 100644 --- a/src/paravirt.h +++ b/src/paravirt.h @@ -43,9 +43,8 @@ static inline int kvm_para_available(void)
extern int qemu_cfg_present;
-void qemu_ramsize_preinit(void); void qemu_biostable_setup(void); -void qemu_cfg_preinit(void); +void qemu_preinit(void); int qemu_cfg_show_boot_menu(void); void qemu_cfg_get_uuid(u8 *uuid); int qemu_cfg_irq0_override(void); diff --git a/src/post.c b/src/post.c index e5435b1..ef67743 100644 --- a/src/post.c +++ b/src/post.c @@ -234,26 +234,6 @@ maininit(void) * Early initialization (preinit) and code relocation ****************************************************************/
-static void -ramsize_preinit(void) -{ - dprintf(3, "Find memory size\n"); - if (CONFIG_COREBOOT) - coreboot_preinit(); - else if (usingXen()) - xen_ramsize_preinit(); - else - qemu_ramsize_preinit(); - - // Don't declare any memory between 0xa0000 and 0x100000 - add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE); - - // Mark known areas as reserved. - add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED); - - dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G); -} - // Update given relocs for the code at 'dest' with a given 'delta' static void updateRelocs(void *dest, u32 *rstart, u32 *rend, u32 delta) @@ -310,12 +290,22 @@ preinit(void) HaveRunPost = 1; outb_cmos(0, CMOS_RESET_CODE);
- // Check if we are running under Xen. + // Run platform preinit calls. + coreboot_preinit(); xen_preinit(); + qemu_preinit(); + dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G); + + // The first 1 megabyte of the e820 map is "magic". Various + // programs expect to see (and will crash if they don't): + // 00000-9fc00=RAM, 9fc00-a0000=RESERVED, f0000-100000=RESERVED. + // Force the e820 map to show this (the ebda e820 entry is added + // in init_bda). + add_e820(0, BUILD_LOWRAM_END, E820_RAM); + add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE); + add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
- // Detect ram and setup internal malloc. - qemu_cfg_preinit(); - ramsize_preinit(); + // Setup malloc. malloc_preinit();
// Relocate initialization code. diff --git a/src/xen.c b/src/xen.c index c9759f0..525039d 100644 --- a/src/xen.c +++ b/src/xen.c @@ -76,8 +76,35 @@ void xen_preinit(void) break; } } - if (!xen_cpuid_base) + if (!xen_cpuid_base) { dprintf(1, "No Xen hypervisor found.\n"); + return; + } + + 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; }
static int hypercall_xen_version( int cmd, void *arg) @@ -121,31 +148,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);