]> xenbits.xensource.com Git - seabios.git/commitdiff
Allow optionroms and "low mem" to share space.
authorKevin O'Connor <kevin@koconnor.net>
Mon, 21 May 2012 01:11:43 +0000 (21:11 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Mon, 21 May 2012 12:48:36 +0000 (08:48 -0400)
Allow both optionroms and "low mem" allocations to use the e-segment.
(Space is allocated on a "first come, first serve" basis).  This
allows more flexibility in resource assignment.

Also, allow the "low mem" area to use a full 64K.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/config.h
src/optionroms.c
src/pmm.c
src/shadow.c
src/util.h
tools/layoutrom.py

index 23591b979c7734521f8a0104cfe68eac0ea04a0c..3a708672d0cd0e842e4b78b0c0c62db4e90cda11 100644 (file)
@@ -38,7 +38,6 @@
 #define BUILD_ROM_START           0xc0000
 #define BUILD_BIOS_ADDR           0xf0000
 #define BUILD_BIOS_SIZE           0x10000
-#define BUILD_LOWMEM_SIZE         0x8000
 #define BUILD_EXTRA_STACK_SIZE    0x800
 // 32KB for shadow ram copying (works around emulator deficiencies)
 #define BUILD_BIOS_TMP_ADDR       0x30000
index 5ce8af8ec3df62f2270afcd84dd309f4abc391c4..d5783b925365993e1ed94e8cf2f00e9c12367dd7 100644 (file)
 #include "paravirt.h" // qemu_cfg_*
 #include "optionroms.h" // struct rom_header
 
-// The end of the last deployed rom.
-u32 RomEnd = BUILD_ROM_START;
-// The maximum memory location a rom may extend to.
-u32 RomTop;
-
 
 /****************************************************************
  * Helper functions
@@ -118,41 +113,25 @@ get_pci_rom(struct rom_header *rom)
     return pd;
 }
 
-// Return the memory position up to which roms may be located.
-static inline u32 max_rom(void) {
-    return RomTop;
-}
-
-// Copy a rom to its permanent location below 1MiB
-static struct rom_header *
-copy_rom(struct rom_header *rom)
-{
-    u32 romsize = rom->size * 512;
-    if (RomEnd + romsize > max_rom()) {
-        // Option rom doesn't fit.
-        warn_noalloc();
-        return NULL;
-    }
-    dprintf(4, "Copying option rom (size %d) from %p to %x\n"
-            , romsize, rom, RomEnd);
-    iomemcpy((void*)RomEnd, rom, romsize);
-    return (void*)RomEnd;
-}
-
 // Run rom init code and note rom size.
 static int
 init_optionrom(struct rom_header *rom, u16 bdf, int isvga)
 {
     if (! is_valid_rom(rom))
         return -1;
+    struct rom_header *newrom = rom_reserve(rom->size * 512);
+    if (!newrom) {
+        warn_noalloc();
+        return -1;
+    }
+    if (newrom != rom)
+        memmove(newrom, rom, rom->size * 512);
 
-    if (isvga || get_pnp_rom(rom))
+    if (isvga || get_pnp_rom(newrom))
         // Only init vga and PnP roms here.
-        callrom(rom, bdf);
+        callrom(newrom, bdf);
 
-    RomEnd = (u32)rom + ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
-
-    return 0;
+    return rom_confirm(newrom->size * 512);
 }
 
 #define RS_PCIROM (1LL<<33)
@@ -180,6 +159,21 @@ getRomPriority(u64 *sources, struct rom_header *rom, int instance)
  * Roms in CBFS
  ****************************************************************/
 
+static struct rom_header *
+deploy_romfile(u32 file)
+{
+    u32 size = romfile_size(file);
+    struct rom_header *rom = rom_reserve(size);
+    if (!rom) {
+        warn_noalloc();
+        return NULL;
+    }
+    int ret = romfile_copy(file, rom, size);
+    if (ret <= 0)
+        return NULL;
+    return rom;
+}
+
 // Check if an option rom is at a hardcoded location or in CBFS.
 static struct rom_header *
 lookup_hardcode(struct pci_device *pci)
@@ -187,11 +181,10 @@ lookup_hardcode(struct pci_device *pci)
     char fname[17];
     snprintf(fname, sizeof(fname), "pci%04x,%04x.rom"
              , pci->vendor, pci->device);
-    int ret = romfile_copy(romfile_find(fname), (void*)RomEnd
-                           , max_rom() - RomEnd);
-    if (ret <= 0)
-        return NULL;
-    return (void*)RomEnd;
+    u32 file = romfile_find(fname);
+    if (file)
+        return deploy_romfile(file);
+    return NULL;
 }
 
 // Run all roms in a given CBFS directory.
@@ -203,9 +196,8 @@ run_file_roms(const char *prefix, int isvga, u64 *sources)
         file = romfile_findprefix(prefix, file);
         if (!file)
             break;
-        struct rom_header *rom = (void*)RomEnd;
-        int ret = romfile_copy(file, rom, max_rom() - RomEnd);
-        if (ret > 0) {
+        struct rom_header *rom = deploy_romfile(file);
+        if (rom) {
             setRomSource(sources, rom, file);
             init_optionrom(rom, 0, isvga);
         }
@@ -235,6 +227,22 @@ is_pci_vga(struct pci_device *pci)
     return 1;
 }
 
+// Copy a rom to its permanent location below 1MiB
+static struct rom_header *
+copy_rom(struct rom_header *rom)
+{
+    u32 romsize = rom->size * 512;
+    struct rom_header *newrom = rom_reserve(romsize);
+    if (!newrom) {
+        warn_noalloc();
+        return NULL;
+    }
+    dprintf(4, "Copying option rom (size %d) from %p to %p\n"
+            , romsize, rom, newrom);
+    iomemcpy(newrom, rom, romsize);
+    return newrom;
+}
+
 // Map the option rom of a given PCI device.
 static struct rom_header *
 map_pcirom(struct pci_device *pci)
@@ -338,17 +346,17 @@ optionrom_setup(void)
     dprintf(1, "Scan for option roms\n");
     u64 sources[(BUILD_BIOS_ADDR - BUILD_ROM_START) / OPTION_ROM_ALIGN];
     memset(sources, 0, sizeof(sources));
-    u32 post_vga = RomEnd;
+    u32 post_vga = rom_get_last();
 
     if (CONFIG_OPTIONROMS_DEPLOYED) {
         // Option roms are already deployed on the system.
-        u32 pos = RomEnd;
-        while (pos < max_rom()) {
+        u32 pos = post_vga;
+        while (pos < rom_get_top()) {
             int ret = init_optionrom((void*)pos, 0, 0);
             if (ret)
                 pos += OPTION_ROM_ALIGN;
             else
-                pos = RomEnd;
+                pos = rom_get_last();
         }
     } else {
         // Find and deploy PCI roms.
@@ -362,11 +370,12 @@ optionrom_setup(void)
         // Find and deploy CBFS roms not associated with a device.
         run_file_roms("genroms/", 0, sources);
     }
+    rom_reserve(0);
 
     // All option roms found and deployed - now build BEV/BCV vectors.
 
     u32 pos = post_vga;
-    while (pos < RomEnd) {
+    while (pos < rom_get_last()) {
         struct rom_header *rom = (void*)pos;
         if (! is_valid_rom(rom)) {
             pos += OPTION_ROM_ALIGN;
@@ -403,6 +412,7 @@ optionrom_setup(void)
 
 static int S3ResumeVgaInit;
 int ScreenAndDebug;
+struct rom_header *VgaROM;
 
 // Call into vga code to turn on console.
 void
@@ -423,7 +433,7 @@ vga_setup(void)
         init_optionrom((void*)BUILD_ROM_START, 0, 1);
     } else {
         // Clear option rom memory
-        memset((void*)RomEnd, 0, max_rom() - RomEnd);
+        memset((void*)BUILD_ROM_START, 0, rom_get_top() - BUILD_ROM_START);
 
         // Find and deploy PCI VGA rom.
         struct pci_device *pci;
@@ -438,13 +448,13 @@ vga_setup(void)
         // Find and deploy CBFS vga-style roms not associated with a device.
         run_file_roms("vgaroms/", 1, NULL);
     }
+    rom_reserve(0);
 
-    if (RomEnd == BUILD_ROM_START) {
+    if (rom_get_last() == BUILD_ROM_START)
         // No VGA rom found
-        RomEnd += OPTION_ROM_ALIGN;
         return;
-    }
 
+    VgaROM = (void*)BUILD_ROM_START;
     enable_vga_console();
 }
 
@@ -453,8 +463,7 @@ s3_resume_vga_init(void)
 {
     if (!S3ResumeVgaInit)
         return;
-    struct rom_header *rom = (void*)BUILD_ROM_START;
-    if (! is_valid_rom(rom))
+    if (!VgaROM || ! is_valid_rom(VgaROM))
         return;
-    callrom(rom, 0);
+    callrom(VgaROM, 0);
 }
index 1648bf2440eba7b491f1585c8d18b8deb04bd0ed..facea6bfad979c2ca914abd529e91026d78240cf 100644 (file)
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -162,17 +162,66 @@ findLast(struct zone_s *zone)
 
 
 /****************************************************************
- * Setup
+ * 0xc0000-0xf0000 management
  ****************************************************************/
 
-// Return start of code in 0xc0000-0xf0000 space.
+static u32 RomEnd = BUILD_ROM_START;
+static struct allocinfo_s *RomBase;
+
+#define OPROM_HEADER_RESERVE 16
+
+// Return maximum address of read/writable "low mem" space.
 static inline u32 lowmemend(void) {
     extern u8 code32flat_start[], code32init_end[];
     u32 end = CONFIG_RELOCATE_INIT ? (u32)code32init_end : (u32)code32flat_start;
     return end > BUILD_BIOS_ADDR ? BUILD_BIOS_ADDR : end;
 }
 
-#define OPROM_HEADER_RESERVE 16
+// Return the memory position up to which roms may be located.
+u32
+rom_get_top(void)
+{
+    return ALIGN_DOWN((u32)RomBase->allocend - OPROM_HEADER_RESERVE
+                      , OPTION_ROM_ALIGN);
+}
+
+// Return the end of the last deployed rom.
+u32
+rom_get_last(void)
+{
+    return RomEnd;
+}
+
+// Request space for an optionrom in 0xc0000-0xf0000 area.
+struct rom_header *
+rom_reserve(u32 size)
+{
+    u32 newend = ALIGN(RomEnd + size, OPTION_ROM_ALIGN) + OPROM_HEADER_RESERVE;
+    if (newend > (u32)RomBase->allocend)
+        return NULL;
+    if (newend < (u32)_datalow_base + OPROM_HEADER_RESERVE)
+        newend = (u32)_datalow_base + OPROM_HEADER_RESERVE;
+    RomBase->data = RomBase->dataend = (void*)newend;
+    return (void*)RomEnd;
+}
+
+// Confirm space as in use by an optionrom.
+int
+rom_confirm(u32 size)
+{
+    void *new = rom_reserve(size);
+    if (!new) {
+        warn_noalloc();
+        return -1;
+    }
+    RomEnd = ALIGN(RomEnd + size, OPTION_ROM_ALIGN);
+    return 0;
+}
+
+
+/****************************************************************
+ * Setup
+ ****************************************************************/
 
 void
 malloc_setup(void)
@@ -204,9 +253,8 @@ malloc_setup(void)
     // Populate other regions
     addSpace(&ZoneTmpLow, (void*)BUILD_STACK_ADDR, (void*)BUILD_EBDA_MINIMUM);
     addSpace(&ZoneFSeg, BiosTableSpace, &BiosTableSpace[CONFIG_MAX_BIOSTABLE]);
-    u32 lowend = lowmemend();
-    RomTop = ALIGN_DOWN(lowend-BUILD_LOWMEM_SIZE, OPTION_ROM_ALIGN);
-    addSpace(&ZoneLow, (void*)RomTop + OPROM_HEADER_RESERVE, (void*)lowend);
+    addSpace(&ZoneLow, _datalow_base + OPROM_HEADER_RESERVE, (void*)lowmemend());
+    RomBase = findLast(&ZoneLow);
     if (highram) {
         addSpace(&ZoneHigh, (void*)highram
                  , (void*)highram + CONFIG_MAX_HIGHTABLE);
@@ -246,14 +294,10 @@ malloc_finalize(void)
 
     // Place an optionrom signature around used low mem area.
     struct allocinfo_s *info = findLast(&ZoneLow);
-    u32 base = BUILD_BIOS_ADDR;
-    if (info && info->allocend < (void*)BUILD_BIOS_ADDR) {
-        base = ALIGN_DOWN((u32)info->allocend - OPROM_HEADER_RESERVE
-                          , OPTION_ROM_ALIGN);
-        struct rom_header *dummyrom = (void*)base;
-        dummyrom->signature = OPTION_ROM_SIGNATURE;
-        dummyrom->size = (BUILD_BIOS_ADDR - base) / 512;
-    }
+    u32 base = rom_get_top();
+    struct rom_header *dummyrom = (void*)base;
+    dummyrom->signature = OPTION_ROM_SIGNATURE;
+    dummyrom->size = (BUILD_BIOS_ADDR - base) / 512;
     memset((void*)RomEnd, 0, base-RomEnd);
     dprintf(1, "Space available for UMB: %08x-%08x\n", RomEnd, base);
 
index 70f04c5f433a71ab1dd4af9f551ed6d790b0c302..11c4d5e3562ecd583fe1591bccd52695b55c76fc 100644 (file)
@@ -79,12 +79,13 @@ make_bios_readonly_intel(u16 bdf, u32 pam0)
     wbinvd();
 
     // Write protect roms from 0xc0000-0xf0000
+    u32 romend = rom_get_last(), romtop = rom_get_top();
     int i;
     for (i=0; i<6; i++) {
         u32 mem = BUILD_ROM_START + i * 32*1024;
         u32 pam = pam0 + 1 + i;
-        if (RomEnd <= mem + 16*1024 || RomTop <= mem + 32*1024) {
-            if (RomEnd > mem && RomTop > mem + 16*1024)
+        if (romend <= mem + 16*1024 || romtop <= mem + 32*1024) {
+            if (romend > mem && romtop > mem + 16*1024)
                 pci_config_writeb(bdf, pam, 0x31);
             break;
         }
index e0e98f05dfc4103170a48479be600a1a9022b46b..c3234494241a3ec3c542cd6ad759d55a62d3a4c2 100644 (file)
@@ -401,7 +401,6 @@ void call_bcv(u16 seg, u16 ip);
 void optionrom_setup(void);
 void vga_setup(void);
 void s3_resume_vga_init(void);
-extern u32 RomEnd, RomTop;
 extern int ScreenAndDebug;
 
 // bootsplash.c
@@ -420,6 +419,10 @@ void pnp_setup(void);
 
 // pmm.c
 extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
+u32 rom_get_top(void);
+u32 rom_get_last(void);
+struct rom_header *rom_reserve(u32 size);
+int rom_confirm(u32 size);
 void malloc_setup(void);
 void malloc_fixupreloc(void);
 void malloc_finalize(void);
index 1ae7c83d34a21a2eef89ade7a67d4ddb753c403a..74b410f4663aec799332f8d7d0d6c6f3432cdd7f 100755 (executable)
@@ -363,6 +363,7 @@ def writeLinkerScripts(li, entrysym, genreloc, out16, out32seg, out32flat):
     out = outXRefs(sections32all) + """
     %s = 0x%x ;
     _reloc_min_align = 0x%x ;
+    _datalow_base = 0x%x ;
     _datalow_min_align = 0x%x ;
 
     code32flat_start = 0x%x ;
@@ -383,6 +384,7 @@ def writeLinkerScripts(li, entrysym, genreloc, out16, out32seg, out32flat):
     } :text
 """ % (entrysym.name, entrysympos,
        li.sec32init_align,
+       li.datalow_base,
        li.sec32low_align,
        sec32all_start,
        relocstr,