Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/25583
Change subject: lib/bootmem: Add method to walk memory tables ......................................................................
lib/bootmem: Add method to walk memory tables
Add a method to walk specified memory tables and call a function for each memory range.
Merge LB_MEM_RAM_DONT_OVERLAP into LB_MEM_RAM on request, to ease working with memory regions intended for payloads.
Required for uImage support in coreboot.
Tested on Cavium SoC.
Change-Id: I0004e5ad5fe2289827f370f0d0f9979d3cbd3926 Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/include/bootmem.h M src/lib/bootmem.c 2 files changed, 48 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/25583/1
diff --git a/src/include/bootmem.h b/src/include/bootmem.h index b825272..b16bcc0 100644 --- a/src/include/bootmem.h +++ b/src/include/bootmem.h @@ -41,6 +41,23 @@ /* Print current range map of boot memory. */ void bootmem_dump_ranges(void);
+typedef bool (*range_action_t)(const struct range_entry *r, void *arg); + +/** + * Walk memory tables and call the provided function, for every region, + * that is bigger than min_size. The caller has to return false to break + * out of the loop any time, or return true to continue. + * + * @param merge_ram_dont_overlap If true, LB_MEM_RAM_DONT_OVERLAP regions + * appear as usable RAM and will never appear in one callback. + * The regions are merged with usable RAM regions. + * If false, all regions are provided as is. + * @param action The function to call for each memory range. + * @param Pointer passed to function @action. Set to NULL if unused. + */ +void bootmem_walk(const bool merge_ram_dont_overlap, range_action_t action, + void *arg); + /* Return 1 if region targets usable RAM, 0 otherwise. */ int bootmem_region_targets_usable_ram(uint64_t start, uint64_t size);
diff --git a/src/lib/bootmem.c b/src/lib/bootmem.c index f00ce13..f34e773 100644 --- a/src/lib/bootmem.c +++ b/src/lib/bootmem.c @@ -133,6 +133,37 @@ } }
+void bootmem_walk(const bool merge_ram_dont_overlap, range_action_t action, + void *arg) +{ + const struct range_entry *r; + struct memranges *memranges; + struct memranges bm; + + assert (action); + + if (merge_ram_dont_overlap) { + /** + * Convert LB_MEM_RAM_DONT_OVERLAP to LB_MEM_RAM and merge + * ranges: + * The caller doesn't care about memory used by firmware. + */ + memranges_clone(&bm, &bootmem); + memranges_update_tag(&bm, LB_MEM_RAM_DONT_OVERLAP, LB_MEM_RAM); + } + + memranges = merge_ram_dont_overlap ? &bm : &bootmem ; + + memranges_each_entry(r, memranges) { + if (!action(r, arg)) + goto out; + } + +out: + if (merge_ram_dont_overlap) + memranges_teardown(&bm); +} + int bootmem_region_targets_usable_ram(uint64_t start, uint64_t size) { const struct range_entry *r;