aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2012-05-20 21:11:43 -0400
committerKevin O'Connor <kevin@koconnor.net>2012-05-21 08:48:36 -0400
commit5e0190817768d656aad987010557a0681624e2b1 (patch)
tree4bce042c5d64ab14241b182023c1959533b73220 /src
parent4f6563ef1bede5da45d7689c1e599b7ab2c13327 (diff)
downloadseabios-5e0190817768d656aad987010557a0681624e2b1.tar.gz
Allow optionroms and "low mem" to share space.
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>
Diffstat (limited to 'src')
-rw-r--r--src/config.h1
-rw-r--r--src/optionroms.c111
-rw-r--r--src/pmm.c72
-rw-r--r--src/shadow.c5
-rw-r--r--src/util.h5
5 files changed, 125 insertions, 69 deletions
diff --git a/src/config.h b/src/config.h
index 23591b97..3a708672 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 5ce8af8e..d5783b92 100644
--- a/src/optionroms.c
+++ b/src/optionroms.c
@@ -16,11 +16,6 @@
#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);
}
diff --git a/src/pmm.c b/src/pmm.c
index 1648bf24..facea6bf 100644
--- 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);
diff --git a/src/shadow.c b/src/shadow.c
index 70f04c5f..11c4d5e3 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 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;
}
diff --git a/src/util.h b/src/util.h
index e0e98f05..c3234494 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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);