summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/bootmem.h13
-rw-r--r--src/lib/bootmem.c14
2 files changed, 27 insertions, 0 deletions
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);
diff --git a/src/lib/bootmem.c b/src/lib/bootmem.c
index 4fbc4b3a3f..ed45e0f384 100644
--- a/src/lib/bootmem.c
+++ b/src/lib/bootmem.c
@@ -180,6 +180,20 @@ void bootmem_dump_ranges(void)
}
}
+bool bootmem_walk(range_action_t action, void *arg)
+{
+ const struct range_entry *r;
+
+ assert(bootmem_is_initialized());
+
+ memranges_each_entry(r, &bootmem) {
+ if (!action(r, arg))
+ return true;
+ }
+
+ return false;
+}
+
int bootmem_region_targets_usable_ram(uint64_t start, uint64_t size)
{
const struct range_entry *r;