lib/bootmem: tightly couple bootmem_init to bootmem_write_memory_table
In https://review.coreboot.org/25383 people were confused about the ordering of bootmem calls w.r.t. when entries are exposed to the OS. To alleviate this add a notion of bootmem being initialized. In addition to that, only mark bootmem initialized when bootmem_write_memory_table() is called. Any other calls to bootmem before that will report an error on the console. Change-Id: I5bc31f555038ccabb82d902c54f95858679b1695 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/25503 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
99b65668f9
commit
4677f6bbfa
|
@ -20,21 +20,18 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <boot/coreboot_tables.h>
|
#include <boot/coreboot_tables.h>
|
||||||
|
|
||||||
/*
|
/* Write memory coreboot table. Current resource map is serialized into
|
||||||
* Initialize the memory address space prior to payload loading. The bootmem
|
* memtable (LB_MEM_* types). bootmem library is unusable until this function
|
||||||
* serves as the source for the lb_mem table.
|
* is called first in the write tables path before payload is loaded. */
|
||||||
*/
|
void bootmem_write_memory_table(struct lb_memory *mem);
|
||||||
void bootmem_init(void);
|
|
||||||
|
|
||||||
/* Architecture hook to add bootmem areas the architecture controls. */
|
/* Architecture hook to add bootmem areas the architecture controls when
|
||||||
|
* bootmem_write_memory_table() is called. */
|
||||||
void bootmem_arch_add_ranges(void);
|
void bootmem_arch_add_ranges(void);
|
||||||
|
|
||||||
/* Add a range of a given type to the bootmem address space. */
|
/* Add a range of a given type to the bootmem address space. */
|
||||||
void bootmem_add_range(uint64_t start, uint64_t size, uint32_t type);
|
void bootmem_add_range(uint64_t start, uint64_t size, uint32_t type);
|
||||||
|
|
||||||
/* Write memory coreboot table. */
|
|
||||||
void bootmem_write_memory_table(struct lb_memory *mem);
|
|
||||||
|
|
||||||
/* Print current range map of boot memory. */
|
/* Print current range map of boot memory. */
|
||||||
void bootmem_dump_ranges(void);
|
void bootmem_dump_ranges(void);
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,22 @@
|
||||||
#include <device/resource.h>
|
#include <device/resource.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static struct memranges bootmem;
|
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 cacheable = IORESOURCE_CACHEABLE;
|
||||||
const unsigned long reserved = IORESOURCE_RESERVE;
|
const unsigned long reserved = IORESOURCE_RESERVE;
|
||||||
struct memranges *bm = &bootmem;
|
struct memranges *bm = &bootmem;
|
||||||
|
|
||||||
|
initialized = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fill the memory map out. The order of operations is important in
|
* Fill the memory map out. The order of operations is important in
|
||||||
* that each overlapping range will take over the next. Therefore,
|
* 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)
|
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);
|
memranges_insert(&bootmem, start, size, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +68,7 @@ void bootmem_write_memory_table(struct lb_memory *mem)
|
||||||
|
|
||||||
lb_r = &mem->map[0];
|
lb_r = &mem->map[0];
|
||||||
|
|
||||||
|
bootmem_init();
|
||||||
bootmem_dump_ranges();
|
bootmem_dump_ranges();
|
||||||
|
|
||||||
memranges_each_entry(r, &bootmem) {
|
memranges_each_entry(r, &bootmem) {
|
||||||
|
@ -135,6 +149,11 @@ void *bootmem_allocate_buffer(size_t size)
|
||||||
resource_t begin;
|
resource_t begin;
|
||||||
resource_t end;
|
resource_t end;
|
||||||
|
|
||||||
|
if (!bootmem_is_initialized()) {
|
||||||
|
printk(BIOS_ERR, "%s: lib unitialized!\n", __func__);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* 4KiB alignment. */
|
/* 4KiB alignment. */
|
||||||
size = ALIGN(size, 4096);
|
size = ALIGN(size, 4096);
|
||||||
region = NULL;
|
region = NULL;
|
||||||
|
|
|
@ -524,11 +524,7 @@ static uintptr_t write_coreboot_table(uintptr_t rom_table_end)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize the memory map at boot time. */
|
/* Serialize resource map into mem table types (LB_MEM_*) */
|
||||||
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. */
|
|
||||||
bootmem_write_memory_table(lb_memory(head));
|
bootmem_write_memory_table(lb_memory(head));
|
||||||
|
|
||||||
/* Record our motherboard */
|
/* Record our motherboard */
|
||||||
|
|
Loading…
Reference in New Issue