insert_e820(int i, u64 start, u64 size, u32 type)
{
if (e820_count >= CONFIG_MAX_E820) {
- dprintf(1, "Overflowed e820 list!\n");
+ warn_noalloc();
return;
}
e->type = type;
}
+static const char *
+e820_type_name(u32 type)
+{
+ switch (type) {
+ case E820_RAM: return "RAM";
+ case E820_RESERVED: return "RESERVED";
+ case E820_ACPI: return "ACPI";
+ case E820_NVS: return "NVS";
+ case E820_UNUSABLE: return "UNUSABLE";
+ case E820_HOLE: return "HOLE";
+ default: return "UNKNOWN";
+ }
+}
+
// Show the current e820_list.
static void
-dump_map()
+dump_map(void)
{
dprintf(1, "e820 map has %d items:\n", e820_count);
int i;
for (i=0; i<e820_count; i++) {
struct e820entry *e = &e820_list[i];
u64 e_end = e->start + e->size;
- dprintf(1, " %d: %08x%08x - %08x%08x = %d\n", i
+ dprintf(1, " %d: %08x%08x - %08x%08x = %d %s\n", i
, (u32)(e->start >> 32), (u32)e->start
, (u32)(e_end >> 32), (u32)e_end
- , e->type);
+ , e->type, e820_type_name(e->type));
}
}
//dump_map();
}
-// Prep for memmap stuff - init bios table locations.
-void
-memmap_setup()
-{
- e820_count = 0;
-}
-
// Report on final memory locations.
void
-memmap_finalize()
+memmap_finalize(void)
{
dump_map();
}
-
-
-/****************************************************************
- * malloc
- ****************************************************************/
-
-#define MINALIGN 16
-
-struct zone_s {
- u32 top, bottom, cur;
-};
-
-static struct zone_s ZoneHigh, ZoneFSeg;
-
-static void *
-__malloc(struct zone_s *zone, u32 size)
-{
- u32 newpos = (zone->cur - size) / MINALIGN * MINALIGN;
- if ((s32)(newpos - zone->bottom) < 0)
- // No space
- return NULL;
- zone->cur = newpos;
- return (void*)newpos;
-}
-
-// Allocate memory at the top of 32bit ram.
-void *
-malloc_high(u32 size)
-{
- return __malloc(&ZoneHigh, size);
-}
-
-// Allocate memory in the 0xf0000-0x100000 area of ram.
-void *
-malloc_fseg(u32 size)
-{
- return __malloc(&ZoneFSeg, size);
-}
-
-void
-malloc_setup()
-{
- dprintf(3, "malloc setup\n");
-
- // Memory in 0xf0000 area.
- memset(BiosTableSpace, 0, CONFIG_MAX_BIOSTABLE);
- ZoneFSeg.bottom = (u32)BiosTableSpace;
- ZoneFSeg.top = ZoneFSeg.cur = ZoneFSeg.bottom + CONFIG_MAX_BIOSTABLE;
-
- // Find memory at the top of ram.
- u32 top = 0;
- int i;
- for (i=e820_count-1; i>=0; i--) {
- struct e820entry *e = &e820_list[i];
- u64 end = e->start + e->size;
- if (e->type != E820_RAM || end > 0xffffffff
- || e->size < CONFIG_MAX_HIGHTABLE)
- continue;
- top = end;
- break;
- }
- if (top < 1024*1024 + CONFIG_MAX_HIGHTABLE) {
- // No memory above 1Meg
- memset(&ZoneHigh, 0, sizeof(ZoneHigh));
- return;
- }
- ZoneHigh.bottom = top - CONFIG_MAX_HIGHTABLE;
- ZoneHigh.top = ZoneHigh.cur = ZoneHigh.bottom + CONFIG_MAX_HIGHTABLE;
- add_e820(ZoneHigh.bottom, CONFIG_MAX_HIGHTABLE, E820_RESERVED);
-}
-
-void
-malloc_finalize()
-{
- dprintf(3, "malloc finalize\n");
-
- // Give back unused high ram.
- u32 giveback = (ZoneHigh.cur - ZoneHigh.bottom) / 4096 * 4096;
- add_e820(ZoneHigh.bottom, giveback, E820_RAM);
-
- // Report statistics
- u32 used = ZoneFSeg.top - ZoneFSeg.cur;
- u32 avail = ZoneFSeg.top - ZoneFSeg.bottom;
- dprintf(1, "malloc_fseg used=%d (%d%%)\n"
- , used, (100 * used) / avail);
- used = ZoneHigh.top - ZoneHigh.cur;
- avail = ZoneHigh.top - ZoneHigh.bottom;
- dprintf(1, "malloc_high used=%d (%d%%) (returned %d)\n"
- , used, (100 * used) / avail, giveback);
-}