From c653623d59bc207d035078b63d4bfe1c45e6f58d Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Tue, 10 Apr 2018 09:34:29 +0200 Subject: lib/bootmem: Add method to walk memory tables Add a method to walk bootmem memory tables and call a function for each memory range. The tables might not match with OS sight of view. Return true if the callback function returned false. Required for FIT support in coreboot to find a usable RAM region. Tested on Cavium SoC. Change-Id: I0004e5ad5fe2289827f370f0d0f9979d3cbd3926 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/25583 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner Reviewed-by: Aaron Durbin --- src/include/bootmem.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/include') diff --git a/src/include/bootmem.h b/src/include/bootmem.h index 4964c18f38..161f482e13 100644 --- a/src/include/bootmem.h +++ b/src/include/bootmem.h @@ -68,6 +68,19 @@ void bootmem_add_range(uint64_t start, uint64_t size, /* 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. + * The caller has to return false to break out of the loop any time, or + * return true to continue. + * + * @param action The function to call for each memory range. + * @param arg Pointer passed to function @action. Set to NULL if unused. + * @return true if the function 'action' returned false. + */ +bool bootmem_walk(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); -- cgit v1.2.3