[SeaBIOS] [PATCH] Allow optionroms and "low mem" to share space.
Kevin O'Connor
kevin at koconnor.net
Mon May 21 03:27:14 CEST 2012
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 at koconnor.net>
---
src/config.h | 1 -
src/optionroms.c | 74 +++++++++++++++++++++++++++++++++------------------
src/pmm.c | 47 ++++++++++++++++++++++++---------
src/shadow.c | 5 ++-
src/util.h | 4 ++-
tools/layoutrom.py | 2 +
6 files changed, 90 insertions(+), 43 deletions(-)
diff --git a/src/config.h b/src/config.h
index 23591b9..3a70867 100644
--- a/src/config.h
+++ b/src/config.h
@@ -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
diff --git a/src/optionroms.c b/src/optionroms.c
index 5ce8af8..3ef0d3c 100644
--- a/src/optionroms.c
+++ b/src/optionroms.c
@@ -18,8 +18,6 @@
// The end of the last deployed rom.
u32 RomEnd = BUILD_ROM_START;
-// The maximum memory location a rom may extend to.
-u32 RomTop;
/****************************************************************
@@ -118,17 +116,13 @@ 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()) {
+ int ret = rom_reserve(RomEnd + romsize);
+ if (ret) {
// Option rom doesn't fit.
warn_noalloc();
return NULL;
@@ -144,15 +138,29 @@ static int
init_optionrom(struct rom_header *rom, u16 bdf, int isvga)
{
if (! is_valid_rom(rom))
- return -1;
+ goto fail;
+ int ret = rom_reserve((u32)rom + rom->size * 512);
+ if (ret) {
+ warn_noalloc();
+ goto fail;
+ }
if (isvga || get_pnp_rom(rom))
// Only init vga and PnP roms here.
callrom(rom, bdf);
- RomEnd = (u32)rom + ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
+ u32 newend = (u32)rom + ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
+ ret = rom_reserve(newend);
+ if (ret) {
+ warn_noalloc();
+ goto fail;
+ }
+ RomEnd = newend;
return 0;
+fail:
+ rom_reserve(RomEnd);
+ return -1;
}
#define RS_PCIROM (1LL<<33)
@@ -180,6 +188,23 @@ 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);
+ int ret = rom_reserve(RomEnd + size);
+ if (ret) {
+ warn_noalloc();
+ return NULL;
+ }
+ ret = romfile_copy(file, (void*)RomEnd, size);
+ if (ret <= 0) {
+ rom_reserve(RomEnd);
+ return NULL;
+ }
+ return (void*)RomEnd;
+}
+
// 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 +212,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 +227,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);
}
@@ -343,7 +366,7 @@ optionrom_setup(void)
if (CONFIG_OPTIONROMS_DEPLOYED) {
// Option roms are already deployed on the system.
u32 pos = RomEnd;
- while (pos < max_rom()) {
+ while (pos < rom_get_top()) {
int ret = init_optionrom((void*)pos, 0, 0);
if (ret)
pos += OPTION_ROM_ALIGN;
@@ -403,6 +426,7 @@ optionrom_setup(void)
static int S3ResumeVgaInit;
int ScreenAndDebug;
+struct rom_header *VgaROM;
// Call into vga code to turn on console.
void
@@ -423,7 +447,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*)RomEnd, 0, rom_get_top() - RomEnd);
// Find and deploy PCI VGA rom.
struct pci_device *pci;
@@ -439,12 +463,11 @@ vga_setup(void)
run_file_roms("vgaroms/", 1, NULL);
}
- if (RomEnd == BUILD_ROM_START) {
+ if (RomEnd == BUILD_ROM_START)
// No VGA rom found
- RomEnd += OPTION_ROM_ALIGN;
return;
- }
+ VgaROM = (void*)BUILD_ROM_START;
enable_vga_console();
}
@@ -453,8 +476,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);
}
diff --git a/src/pmm.c b/src/pmm.c
index 1648bf2..9d3ce4b 100644
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -162,9 +162,13 @@ findLast(struct zone_s *zone)
/****************************************************************
- * Setup
+ * 0xc0000-0xf0000 management
****************************************************************/
+static struct allocinfo_s *RomBase;
+
+#define OPROM_HEADER_RESERVE 16
+
// Return start of code in 0xc0000-0xf0000 space.
static inline u32 lowmemend(void) {
extern u8 code32flat_start[], code32init_end[];
@@ -172,7 +176,29 @@ static inline u32 lowmemend(void) {
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);
+}
+
+// Request space for an optionrom in 0xc0000-0xf0000 area.
+int rom_reserve(u32 addr)
+{
+ u32 newend = ALIGN(addr, OPTION_ROM_ALIGN) + OPROM_HEADER_RESERVE;
+ if (newend > (u32)RomBase->allocend)
+ return -1;
+ if (newend < (u32)_datalow_base + OPROM_HEADER_RESERVE)
+ newend = (u32)_datalow_base + OPROM_HEADER_RESERVE;
+ RomBase->data = RomBase->dataend = (void*)newend;
+ return 0;
+}
+
+
+/****************************************************************
+ * Setup
+ ****************************************************************/
void
malloc_setup(void)
@@ -204,9 +230,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 +271,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);
diff --git a/src/shadow.c b/src/shadow.c
index 70f04c5..b2a05c7 100644
--- a/src/shadow.c
+++ b/src/shadow.c
@@ -79,12 +79,13 @@ make_bios_readonly_intel(u16 bdf, u32 pam0)
wbinvd();
// Write protect roms from 0xc0000-0xf0000
+ u32 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;
}
diff --git a/src/util.h b/src/util.h
index e0e98f0..f600086 100644
--- a/src/util.h
+++ b/src/util.h
@@ -401,7 +401,7 @@ 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 u32 RomEnd;
extern int ScreenAndDebug;
// bootsplash.c
@@ -420,6 +420,8 @@ void pnp_setup(void);
// pmm.c
extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
+u32 rom_get_top(void);
+int rom_reserve(u32 addr);
void malloc_setup(void);
void malloc_fixupreloc(void);
void malloc_finalize(void);
diff --git a/tools/layoutrom.py b/tools/layoutrom.py
index 1ae7c83..74b410f 100755
--- a/tools/layoutrom.py
+++ b/tools/layoutrom.py
@@ -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,
--
1.7.6.5
More information about the SeaBIOS
mailing list