]> xenbits.xensource.com Git - people/andrewcoop/seabios.git/commitdiff
Calculate "RamSize" needed by 16bit interface dynamically.
authorKevin O'Connor <kevin@koconnor.net>
Tue, 19 Feb 2013 06:33:45 +0000 (01:33 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 20 Feb 2013 02:57:24 +0000 (21:57 -0500)
Calculate a LegacyRamSize directly from the e820 map for use by
handle_1588() and handle_15e801() (the only two external interfaces
that require "RamSize").  All other users of the existing RamSize (and
RamSizeOver4G) variables are specific to QEMU, so move the
declarations to paravirt.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
12 files changed:
src/acpi.c
src/coreboot.c
src/misc.c
src/mtrr.c
src/paravirt.c
src/paravirt.h
src/pciinit.c
src/pmm.c
src/smbios.c
src/system.c
src/util.h
src/xen.c

index f7a2e55213f8965b5b9636a742065dc2485b9d6d..7575fc6b792b558c28dd1b79ffd56d51b54d5604 100644 (file)
@@ -13,6 +13,7 @@
 #include "pci_regs.h" // PCI_INTERRUPT_LINE
 #include "ioport.h" // inl
 #include "config.h" // CONFIG_*
+#include "paravirt.h" // RamSize
 #include "dev-q35.h"
 
 /****************************************************/
index 0d4483478ec97e2f8bc3d07d75153389cab2b6fc..f0484e1b71cd3cf6712dad81354fde6dfe361601 100644 (file)
@@ -148,28 +148,15 @@ coreboot_preinit(void)
     if (!cbm)
         goto fail;
 
-    u64 maxram = 0, maxram_over4G = 0;
     int i, count = MEM_RANGE_COUNT(cbm);
     for (i=0; i<count; i++) {
         struct cb_memory_range *m = &cbm->map[i];
         u32 type = m->type;
-        if (type == CB_MEM_TABLE) {
+        if (type == CB_MEM_TABLE)
             type = E820_RESERVED;
-        } else if (type == E820_ACPI || type == E820_RAM) {
-            u64 end = m->start + m->size;
-            if (end > 0x100000000ull) {
-                end -= 0x100000000ull;
-                if (end > maxram_over4G)
-                    maxram_over4G = end;
-            } else if (end > maxram)
-                maxram = end;
-        }
         add_e820(m->start, m->size, type);
     }
 
-    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);
@@ -186,8 +173,6 @@ coreboot_preinit(void)
 fail:
     // No table found..  Use 16Megs as a dummy value.
     dprintf(1, "Unable to find coreboot table!\n");
-    RamSize = 16*1024*1024;
-    RamSizeOver4G = 0;
     add_e820(0, 16*1024*1024, E820_RAM);
     return;
 }
index fb7aad44581b0ad0774570af23a0e836a2d5283c..a34405cae1e6f2baa68ba050e60faf77a9b6bf5e 100644 (file)
 #include "util.h" // debug_enter
 #include "pic.h" // enable_hwirq
 
-// Amount of continuous ram under 4Gig
-u32 RamSize VARFSEG;
-// Amount of continuous ram >4Gig
-u64 RamSizeOver4G;
-
 
 /****************************************************************
  * Misc 16bit ISRs
index 56f85f9be404cd9232dc4ea9e3c10d18c4b8eec1..0f94c2c555d559cd436323a8f78d4a269a8d2118 100644 (file)
@@ -7,6 +7,7 @@
 #include "util.h" // dprintf
 #include "config.h" // CONFIG_*
 #include "pci.h" // pcimem_start
+#include "paravirt.h" // RamSize
 
 #define MSR_MTRRcap                    0x000000fe
 #define MSR_MTRRfix64K_00000           0x00000250
index 9ea3dd535d1f17976e06e8d3d02d68c06a869249..f0610397309417760af7b1b211f895b6fbcef3c5 100644 (file)
 #include "pci.h" // create_pirtable
 #include "xen.h" // xen_biostable_setup
 
+// Amount of continuous ram under 4Gig
+u32 RamSize;
+// Amount of continuous ram >4Gig
+u64 RamSizeOver4G;
 // Type of emulator platform.
 int PlatformRunningOn VARFSEG;
 
@@ -83,6 +87,8 @@ qemu_preinit(void)
 
     /* reserve 256KB BIOS area at the end of 4 GB */
     add_e820(0xfffc0000, 256*1024, E820_RESERVED);
+
+    dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G);
 }
 
 void
index 72377317dbbc6ce5024a8bec1c5fe834a8f0b6be..fce5af954934eb95d2f89c8197b0850ac1cc3e90 100644 (file)
@@ -9,6 +9,8 @@
 #define PF_XEN      (1<<1)
 #define PF_KVM      (1<<2)
 
+extern u32 RamSize;
+extern u64 RamSizeOver4G;
 extern int PlatformRunningOn;
 
 static inline int runningOnQEMU(void) {
index 306b1257776d0309dd251e89a826903180a0cc69..77cac0a8d9ab88f9360aa4ef8435e9ab3972d26d 100644 (file)
@@ -12,6 +12,7 @@
 #include "ioport.h" // PORT_ATA1_CMD_BASE
 #include "config.h" // CONFIG_*
 #include "memmap.h" // add_e820
+#include "paravirt.h" // RamSize
 #include "dev-q35.h"
 
 /* PM Timer ticks per second (HZ) */
index 4805168849516982660d876ac4e11d0413ea69ee..9fca8dc5481468746ee9ad4c0aa57dc7060f63d7 100644 (file)
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -225,8 +225,6 @@ malloc_preinit(void)
     ASSERT32FLAT();
     dprintf(3, "malloc preinit\n");
 
-    dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G);
-
     // Don't declare any memory between 0xa0000 and 0x100000
     add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE);
 
@@ -278,6 +276,26 @@ csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm, u32 hi_pmm_size)
     addSpace(&ZoneTmpLow, (void *)low_pmm, (void *)low_pmm + low_pmm_size);
 }
 
+u32 LegacyRamSize VARFSEG;
+
+// Calculate the maximum ramsize (less than 4gig) from e820 map.
+static void
+calcRamSize(void)
+{
+    u32 rs = 0;
+    int i;
+    for (i=e820_count-1; i>=0; i--) {
+        struct e820entry *en = &e820_list[i];
+        u64 end = en->start + en->size;
+        u32 type = en->type;
+        if (end <= 0xffffffff && (type == E820_ACPI || type == E820_RAM)) {
+            rs = end;
+            break;
+        }
+    }
+    LegacyRamSize = rs >= 1024*1024 ? rs : 1024*1024;
+}
+
 // Update pointers after code relocation.
 void
 malloc_init(void)
@@ -308,6 +326,8 @@ malloc_init(void)
         memset((void*)BUILD_BIOS_ADDR, 0, (u32)code32init_end - BUILD_BIOS_ADDR);
         addSpace(&ZoneFSeg, (void*)BUILD_BIOS_ADDR, code32init_end);
     }
+
+    calcRamSize();
 }
 
 void
@@ -337,6 +357,8 @@ malloc_prepboot(void)
         add_e820((u32)info->dataend, giveback, E820_RAM);
         dprintf(1, "Returned %d bytes of ZoneHigh\n", giveback);
     }
+
+    calcRamSize();
 }
 
 
index a9d76f08048b253bd6992735f8a7f00c5f8bf7d6..f0b83b32b34f0b2291a938e6c1d9e78ab94e1a19 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "util.h" // dprintf
 #include "config.h" // CONFIG_*
+#include "paravirt.h" // RamSize
 #include "smbios.h" // struct smbios_entry_point
 
 struct smbios_entry_point *SMBiosAddr;
index dc1dd7d61402511a2eb22080a9ec6e144b4ccafa..7b481a810706c1288f56fa21cb6db23f59cde58f 100644 (file)
@@ -174,7 +174,7 @@ handle_1587(struct bregs *regs)
 static void
 handle_1588(struct bregs *regs)
 {
-    u32 rs = GET_GLOBAL(RamSize);
+    u32 rs = GET_GLOBAL(LegacyRamSize);
 
     // According to Ralf Brown's interrupt the limit should be 15M,
     // but real machines mostly return max. 63M.
@@ -270,7 +270,7 @@ handle_15e801(struct bregs *regs)
     // regs.u.r16.ax = 0;
     // regs.u.r16.bx = 0;
 
-    u32 rs = GET_GLOBAL(RamSize);
+    u32 rs = GET_GLOBAL(LegacyRamSize);
 
     // Get the amount of extended memory (above 1M)
     if (rs > 16*1024*1024) {
index 9303b5a573c23b61cece525f2414f1caa05b974f..306a8bf8193fc604eacda31198036e3a5118579b 100644 (file)
@@ -371,6 +371,7 @@ int rom_confirm(u32 size);
 void csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm,
                         u32 hi_pmm_size);
 void malloc_preinit(void);
+extern u32 LegacyRamSize;
 void malloc_init(void);
 void malloc_prepboot(void);
 void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
@@ -450,8 +451,6 @@ void reset_vector(void) __noreturn;
 
 // misc.c
 void mathcp_setup(void);
-extern u32 RamSize;
-extern u64 RamSizeOver4G;
 extern u8 BiosChecksum;
 
 // version (auto generated file out/version.c)
index 569fcc03e79c6ac8fca1ffba23086fc17945a093..db542c3a8b99bd5b6e18f23f8e31dea6eb620a9f 100644 (file)
--- a/src/xen.c
+++ b/src/xen.c
@@ -130,7 +130,6 @@ void xen_biostable_setup(void)
 
 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;
@@ -140,18 +139,6 @@ void xen_ramsize_preinit(void)
 
     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;
 }