diff options
author | Patrick Rudolph <patrick.rudolph@9elements.com> | 2018-04-05 09:14:51 +0200 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2018-04-30 09:33:49 +0000 |
commit | 9ab9db0bc5a1bf8bb35980068a840691d54aa5dd (patch) | |
tree | f9b0e0f5999a8a7d24760178a3fafebc59bf807c /src | |
parent | 666c172d385823eefdfeb99ae3a4c20fd1b711f9 (diff) |
lib/bootmem: Introduce custom bootmem tags
Introduce bootmem custom memory tags and use them instead of reusing
LB_MEM tags.
Use asserts in bootmem_add_range to verify parameters.
Tested with uImage payload on Cavium SoC.
Change-Id: I7be8fa792fc7933ca218ecd43d250d3a9c55caa6
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/25633
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/x86/tables.c | 2 | ||||
-rw-r--r-- | src/include/bootmem.h | 19 | ||||
-rw-r--r-- | src/lib/bootmem.c | 66 | ||||
-rw-r--r-- | src/lib/imd_cbmem.c | 2 | ||||
-rw-r--r-- | src/lib/selfboot.c | 2 |
5 files changed, 66 insertions, 25 deletions
diff --git a/src/arch/x86/tables.c b/src/arch/x86/tables.c index 057f6654d4..0a9a3d59b4 100644 --- a/src/arch/x86/tables.c +++ b/src/arch/x86/tables.c @@ -266,5 +266,5 @@ void bootmem_arch_add_ranges(void) /* Memory from 0 through the forwarding_table is reserved. */ const uintptr_t base = 0; - bootmem_add_range(base, forwarding_table - base, LB_MEM_TABLE); + bootmem_add_range(base, forwarding_table - base, BM_MEM_TABLE); } diff --git a/src/include/bootmem.h b/src/include/bootmem.h index 6e7d127f62..df2233f202 100644 --- a/src/include/bootmem.h +++ b/src/include/bootmem.h @@ -20,6 +20,22 @@ #include <stdint.h> #include <boot/coreboot_tables.h> +/** + * Bootmem types match to LB_MEM tags. + * Start at 0x10000 to make sure that the caller doesn't provide LB_MEM tags. + */ +enum bootmem_type { + BM_MEM_FIRST = 0x10000, /* First entry in this list */ + BM_MEM_RAM, /* Memory anyone can use */ + BM_MEM_RESERVED, /* Don't use this memory region */ + BM_MEM_ACPI, /* ACPI Tables */ + BM_MEM_NVS, /* ACPI NVS Memory */ + BM_MEM_UNUSABLE, /* Unusable address space */ + BM_MEM_VENDOR_RSVD, /* Vendor Reserved */ + BM_MEM_TABLE, /* Ram configuration tables are kept in */ + BM_MEM_LAST, /* Last entry in this list */ +}; + /* Write memory coreboot table. Current resource map is serialized into * memtable (LB_MEM_* types). bootmem library is unusable until this function * is called first in the write tables path before payload is loaded. */ @@ -30,7 +46,8 @@ void bootmem_write_memory_table(struct lb_memory *mem); void bootmem_arch_add_ranges(void); /* 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, + const enum bootmem_type tag); /* Print current range map of boot memory. */ void bootmem_dump_ranges(void); diff --git a/src/lib/bootmem.c b/src/lib/bootmem.c index 07391a50de..5e9f7bd1af 100644 --- a/src/lib/bootmem.c +++ b/src/lib/bootmem.c @@ -20,6 +20,7 @@ #include <cbmem.h> #include <device/resource.h> #include <stdlib.h> +#include <assert.h> static int initialized; static struct memranges bootmem; @@ -29,6 +30,30 @@ static int bootmem_is_initialized(void) return initialized; } +/* Convert bootmem tag to LB_MEM tag */ +static uint32_t bootmem_to_lb_tag(const enum bootmem_type tag) +{ + switch (tag) { + case BM_MEM_RAM: + return LB_MEM_RAM; + case BM_MEM_RESERVED: + return LB_MEM_RESERVED; + case BM_MEM_ACPI: + return LB_MEM_ACPI; + case BM_MEM_NVS: + return LB_MEM_NVS; + case BM_MEM_UNUSABLE: + return LB_MEM_UNUSABLE; + case BM_MEM_VENDOR_RSVD: + return LB_MEM_VENDOR_RSVD; + case BM_MEM_TABLE: + return LB_MEM_TABLE; + default: + printk(BIOS_ERR, "ERROR: Unsupported tag %u\n", tag); + return LB_MEM_RESERVED; + } +} + static void bootmem_init(void) { const unsigned long cacheable = IORESOURCE_CACHEABLE; @@ -42,8 +67,8 @@ static void bootmem_init(void) * that each overlapping range will take over the next. Therefore, * add cacheable resources as RAM then add the reserved resources. */ - memranges_init(bm, cacheable, cacheable, LB_MEM_RAM); - memranges_add_resources(bm, reserved, reserved, LB_MEM_RESERVED); + memranges_init(bm, cacheable, cacheable, BM_MEM_RAM); + memranges_add_resources(bm, reserved, reserved, BM_MEM_RESERVED); /* Add memory used by CBMEM. */ cbmem_add_bootmem(); @@ -51,14 +76,13 @@ static void bootmem_init(void) bootmem_arch_add_ranges(); } -void bootmem_add_range(uint64_t start, uint64_t size, uint32_t type) +void bootmem_add_range(uint64_t start, uint64_t size, + const enum bootmem_type tag) { - if (!bootmem_is_initialized()) { - printk(BIOS_ERR, "%s: lib unitialized!\n", __func__); - return; - } + assert(tag > BM_MEM_FIRST && tag < BM_MEM_LAST); + assert(bootmem_is_initialized()); - memranges_insert(&bootmem, start, size, type); + memranges_insert(&bootmem, start, size, tag); } void bootmem_write_memory_table(struct lb_memory *mem) @@ -74,7 +98,7 @@ void bootmem_write_memory_table(struct lb_memory *mem) memranges_each_entry(r, &bootmem) { lb_r->start = pack_lb64(range_entry_base(r)); lb_r->size = pack_lb64(range_entry_size(r)); - lb_r->type = range_entry_tag(r); + lb_r->type = bootmem_to_lb_tag(range_entry_tag(r)); lb_r++; mem->size += sizeof(struct lb_memory_range); @@ -82,21 +106,21 @@ void bootmem_write_memory_table(struct lb_memory *mem) } struct range_strings { - unsigned long tag; + enum bootmem_type tag; const char *str; }; static const struct range_strings type_strings[] = { - { LB_MEM_RAM, "RAM" }, - { LB_MEM_RESERVED, "RESERVED" }, - { LB_MEM_ACPI, "ACPI" }, - { LB_MEM_NVS, "NVS" }, - { LB_MEM_UNUSABLE, "UNUSABLE" }, - { LB_MEM_VENDOR_RSVD, "VENDOR RESERVED" }, - { LB_MEM_TABLE, "CONFIGURATION TABLES" }, + { BM_MEM_RAM, "RAM" }, + { BM_MEM_RESERVED, "RESERVED" }, + { BM_MEM_ACPI, "ACPI" }, + { BM_MEM_NVS, "NVS" }, + { BM_MEM_UNUSABLE, "UNUSABLE" }, + { BM_MEM_VENDOR_RSVD, "VENDOR RESERVED" }, + { BM_MEM_TABLE, "CONFIGURATION TABLES" }, }; -static const char *bootmem_range_string(unsigned long tag) +static const char *bootmem_range_string(const enum bootmem_type tag) { int i; @@ -133,7 +157,7 @@ int bootmem_region_targets_usable_ram(uint64_t start, uint64_t size) break; if (start >= range_entry_base(r) && end <= range_entry_end(r)) { - if (range_entry_tag(r) == LB_MEM_RAM) + if (range_entry_tag(r) == BM_MEM_RAM) return 1; } } @@ -161,7 +185,7 @@ void *bootmem_allocate_buffer(size_t size) if (range_entry_size(r) < size) continue; - if (range_entry_tag(r) != LB_MEM_RAM) + if (range_entry_tag(r) != BM_MEM_RAM) continue; if (range_entry_base(r) >= max_addr) @@ -188,7 +212,7 @@ void *bootmem_allocate_buffer(size_t size) begin = end - size; /* Mark buffer as unusuable for future buffer use. */ - bootmem_add_range(begin, size, LB_MEM_UNUSABLE); + bootmem_add_range(begin, size, BM_MEM_UNUSABLE); return (void *)(uintptr_t)begin; } diff --git a/src/lib/imd_cbmem.c b/src/lib/imd_cbmem.c index cc1294f353..177d2aca1b 100644 --- a/src/lib/imd_cbmem.c +++ b/src/lib/imd_cbmem.c @@ -300,7 +300,7 @@ void cbmem_add_bootmem(void) size_t size = 0; imd_region_used(cbmem_get_imd(), &baseptr, &size); - bootmem_add_range((uintptr_t)baseptr, size, LB_MEM_TABLE); + bootmem_add_range((uintptr_t)baseptr, size, BM_MEM_TABLE); } #if ENV_RAMSTAGE || (IS_ENABLED(CONFIG_EARLY_CBMEM_LIST) \ diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c index 160e8f5516..20886b43b8 100644 --- a/src/lib/selfboot.c +++ b/src/lib/selfboot.c @@ -381,7 +381,7 @@ static int load_self_segments(struct segment *head, struct prog *payload, */ if (check_regions) { bootmem_add_range(ptr->s_dstaddr, ptr->s_memsz, - LB_MEM_UNUSABLE); + BM_MEM_UNUSABLE); } if (!overlaps_coreboot(ptr)) |