diff mbox series

[v4,03/15] lmb: add and reserve memory above ram_top

Message ID 20241015153717.401371-4-sughosh.ganu@linaro.org
State Accepted
Commit eb052cbb896fee6f947765b44b0d80a54b19ce1a
Headers show
Series Make EFI memory allocations synchronous with LMB | expand

Commit Message

Sughosh Ganu Oct. 15, 2024, 3:37 p.m. UTC
U-Boot does not use memory above ram_top. However, this memory does
need to get registered as part of the memory map, so that subsystems
like EFI pass it on to the operating system as part of the EFI memory
map. Add memory above ram_top and reserve it with the LMB_NOOVERWRITE
flag so that it does not get allocated or re-used.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Suggested-by: Mark Kettenis <kettenis@openbsd.org>
---
Changes since V3: New patch

 lib/lmb.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/lib/lmb.c b/lib/lmb.c
index e1e616679f0..0504a7b3407 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -281,7 +281,6 @@  void lmb_add_memory(void)
 {
 	int i;
 	phys_size_t size;
-	phys_addr_t rgn_top;
 	u64 ram_top = gd->ram_top;
 	struct bd_info *bd = gd->bd;
 
@@ -292,16 +291,16 @@  void lmb_add_memory(void)
 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
 		size = bd->bi_dram[i].size;
 		if (size) {
-			if (bd->bi_dram[i].start > ram_top)
-				continue;
-
-			rgn_top = bd->bi_dram[i].start +
-				bd->bi_dram[i].size;
-
-			if (rgn_top > ram_top)
-				size -= rgn_top - ram_top;
-
 			lmb_add(bd->bi_dram[i].start, size);
+
+			/*
+			 * Reserve memory above ram_top as
+			 * no-overwrite so that it cannot be
+			 * allocated
+			 */
+			if (bd->bi_dram[i].start >= ram_top)
+				lmb_reserve_flags(bd->bi_dram[i].start, size,
+						  LMB_NOOVERWRITE);
 		}
 	}
 }