summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/bootmem.c21
-rw-r--r--src/lib/coreboot_table.c6
2 files changed, 21 insertions, 6 deletions
diff --git a/src/lib/bootmem.c b/src/lib/bootmem.c
index ea02a16ddc..07391a50de 100644
--- a/src/lib/bootmem.c
+++ b/src/lib/bootmem.c
@@ -21,14 +21,22 @@
#include <device/resource.h>
#include <stdlib.h>
+static int initialized;
static struct memranges bootmem;
-void bootmem_init(void)
+static int bootmem_is_initialized(void)
+{
+ return initialized;
+}
+
+static void bootmem_init(void)
{
const unsigned long cacheable = IORESOURCE_CACHEABLE;
const unsigned long reserved = IORESOURCE_RESERVE;
struct memranges *bm = &bootmem;
+ initialized = 1;
+
/*
* Fill the memory map out. The order of operations is important in
* that each overlapping range will take over the next. Therefore,
@@ -45,6 +53,11 @@ void bootmem_init(void)
void bootmem_add_range(uint64_t start, uint64_t size, uint32_t type)
{
+ if (!bootmem_is_initialized()) {
+ printk(BIOS_ERR, "%s: lib unitialized!\n", __func__);
+ return;
+ }
+
memranges_insert(&bootmem, start, size, type);
}
@@ -55,6 +68,7 @@ void bootmem_write_memory_table(struct lb_memory *mem)
lb_r = &mem->map[0];
+ bootmem_init();
bootmem_dump_ranges();
memranges_each_entry(r, &bootmem) {
@@ -135,6 +149,11 @@ void *bootmem_allocate_buffer(size_t size)
resource_t begin;
resource_t end;
+ if (!bootmem_is_initialized()) {
+ printk(BIOS_ERR, "%s: lib unitialized!\n", __func__);
+ return NULL;
+ }
+
/* 4KiB alignment. */
size = ALIGN(size, 4096);
region = NULL;
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c
index d03b771f48..e786443cf6 100644
--- a/src/lib/coreboot_table.c
+++ b/src/lib/coreboot_table.c
@@ -524,11 +524,7 @@ static uintptr_t write_coreboot_table(uintptr_t rom_table_end)
}
#endif
- /* Initialize the memory map at boot time. */
- bootmem_init();
-
- /* No other memory areas can be added after the memory table has been
- * committed as the entries won't show up in the serialize mem table. */
+ /* Serialize resource map into mem table types (LB_MEM_*) */
bootmem_write_memory_table(lb_memory(head));
/* Record our motherboard */