diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2012-05-20 21:11:43 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2012-05-21 08:48:36 -0400 |
commit | 5e0190817768d656aad987010557a0681624e2b1 (patch) | |
tree | 4bce042c5d64ab14241b182023c1959533b73220 /src/pmm.c | |
parent | 4f6563ef1bede5da45d7689c1e599b7ab2c13327 (diff) | |
download | seabios-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/pmm.c')
-rw-r--r-- | src/pmm.c | 72 |
1 files changed, 58 insertions, 14 deletions
@@ -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); |