diff mbox series

[RFC,06/31] lmb: reserve and add common memory regions post relocation

Message ID 20240607185240.1892031-7-sughosh.ganu@linaro.org
State New
Headers show
Series Make U-Boot memory reservations coherent | expand

Commit Message

Sughosh Ganu June 7, 2024, 6:52 p.m. UTC
The LMB module provides API's for allocating chunks of memory. The LMB
module should not be allocating memory regions that are in use, or
that might be occupied by the U-Boot image. Prevent allocations of
memory areas used by the U-Boot image by reserving these regions once
U-Boot has been relocated. Also add the rest of the memory that is
available for allocations to the LMB's memory map.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
 common/board_r.c | 15 +++++++++++++++
 include/lmb.h    | 14 ++++++++++++++
 lib/lmb.c        | 14 +++++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

Comments

Tom Rini June 10, 2024, 5:30 p.m. UTC | #1
On Sat, Jun 08, 2024 at 12:22:15AM +0530, Sughosh Ganu wrote:

> The LMB module provides API's for allocating chunks of memory. The LMB
> module should not be allocating memory regions that are in use, or
> that might be occupied by the U-Boot image. Prevent allocations of
> memory areas used by the U-Boot image by reserving these regions once
> U-Boot has been relocated. Also add the rest of the memory that is
> available for allocations to the LMB's memory map.
> 
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

Reviewed-by: Tom Rini <trini@konsulko.com>
diff mbox series

Patch

diff --git a/common/board_r.c b/common/board_r.c
index da0b80f24f..a9f0b0cec1 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -22,6 +22,7 @@ 
 #include <hang.h>
 #include <image.h>
 #include <irq_func.h>
+#include <lmb.h>
 #include <log.h>
 #include <net.h>
 #include <asm/cache.h>
@@ -555,6 +556,17 @@  static int run_main_loop(void)
 	return 0;
 }
 
+#if defined(CONFIG_LMB)
+static int initr_lmb(void)
+{
+	lmb_reserve_common((void *)gd->fdt_blob);
+
+	lmb_add_memory(gd->bd);
+
+	return 0;
+}
+#endif
+
 /*
  * Over time we hope to remove these functions with code fragments and
  * stub functions, and instead call the relevant function directly.
@@ -613,6 +625,9 @@  static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_EFI_LOADER
 	efi_memory_init,
+#endif
+#if defined(CONFIG_LMB)
+	initr_lmb,
 #endif
 	initr_binman,
 #ifdef CONFIG_FSP_VERSION2
diff --git a/include/lmb.h b/include/lmb.h
index 8f8a32c2ca..d2b829ace1 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -125,6 +125,20 @@  void board_lmb_reserve(void);
 void arch_lmb_reserve(void);
 void arch_lmb_reserve_generic(ulong sp, ulong end, ulong align);
 
+/**
+ * lmb_reserve_common() - Reserve memory region occupied by U-Boot image
+ * @fdt_blob: pointer to the FDT blob
+ *
+ * Reserve common areas of memory that are occupied by the U-Boot image.
+ * This function gets called once U-Boot has been relocated, so that any
+ * request for memory allocations would not touch memory region occupied
+ * by the U-Boot image, heap, bss etc.
+ *
+ * Return: None
+ *
+ */
+void lmb_reserve_common(void *fdt_blob);
+
 #endif /* __KERNEL__ */
 
 #endif /* _LINUX_LMB_H */
diff --git a/lib/lmb.c b/lib/lmb.c
index b0c9e2ef30..8003aae6f7 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -216,7 +216,19 @@  static __maybe_unused int efi_lmb_reserve(void)
 	return 0;
 }
 
-static void lmb_reserve_common(void *fdt_blob)
+/**
+ * lmb_reserve_common() - Reserve memory region occupied by U-Boot image
+ * @fdt_blob: pointer to the FDT blob
+ *
+ * Reserve common areas of memory that are occupied by the U-Boot image.
+ * This function gets called once U-Boot has been relocated, so that any
+ * request for memory allocations would not touch memory region occupied
+ * by the U-Boot image, heap, bss etc.
+ *
+ * Return: None
+ *
+ */
+void lmb_reserve_common(void *fdt_blob)
 {
 	arch_lmb_reserve();
 	board_lmb_reserve();