diff mbox series

[v3,12/15] x86: e820: use the lmb API for adding RAM memory

Message ID 20241013105522.391414-13-sughosh.ganu@linaro.org
State Superseded
Headers show
Series Make EFI memory allocations synchronous with LMB | expand

Commit Message

Sughosh Ganu Oct. 13, 2024, 10:55 a.m. UTC
The EFI_CONVENTIONAL_MEMORY type is now being managed through the LMB
module. Add a separate function, lmb_arch_add_memory() to add the RAM
memory to the LMB memory map. The efi_add_known_memory() function is
now used for adding any other memory type to the EFI memory map.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
Changes since V2: None

 arch/x86/lib/e820.c | 47 ++++++++++++++++++++++++++++++++++-----------
 lib/Kconfig         |  2 +-
 2 files changed, 37 insertions(+), 12 deletions(-)

Comments

Simon Glass Oct. 14, 2024, 3:50 p.m. UTC | #1
Hi Sughosh,

On Sun, 13 Oct 2024 at 04:56, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> The EFI_CONVENTIONAL_MEMORY type is now being managed through the LMB
> module. Add a separate function, lmb_arch_add_memory() to add the RAM
> memory to the LMB memory map. The efi_add_known_memory() function is
> now used for adding any other memory type to the EFI memory map.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
> Changes since V2: None
>
>  arch/x86/lib/e820.c | 47 ++++++++++++++++++++++++++++++++++-----------
>  lib/Kconfig         |  2 +-
>  2 files changed, 37 insertions(+), 12 deletions(-)
>

Hmmm x86 is a bit of a mess since it sets up an e820 table and then
uses that to set up EFI!

This should be an event. But otherwise, this patch seems
reasonable...any x86 cleanup can happen later.

Regards,
Simon
diff mbox series

Patch

diff --git a/arch/x86/lib/e820.c b/arch/x86/lib/e820.c
index 122b4f7ca0..d478b7486e 100644
--- a/arch/x86/lib/e820.c
+++ b/arch/x86/lib/e820.c
@@ -4,6 +4,7 @@ 
  */
 
 #include <efi_loader.h>
+#include <lmb.h>
 #include <asm/e820.h>
 #include <asm/global_data.h>
 
@@ -41,15 +42,11 @@  void efi_add_known_memory(void)
 {
 	struct e820_entry e820[E820MAX];
 	unsigned int i, num;
-	u64 start, ram_top;
+	u64 start;
 	int type;
 
 	num = install_e820_map(ARRAY_SIZE(e820), e820);
 
-	ram_top = (u64)gd->ram_top & ~EFI_PAGE_MASK;
-	if (!ram_top)
-		ram_top = 0x100000000ULL;
-
 	for (i = 0; i < num; ++i) {
 		start = e820[i].addr;
 
@@ -72,13 +69,41 @@  void efi_add_known_memory(void)
 			break;
 		}
 
-		if (type == EFI_CONVENTIONAL_MEMORY) {
-			efi_add_conventional_memory_map(start,
-							start + e820[i].size,
-							ram_top);
-		} else {
+		if (type != EFI_CONVENTIONAL_MEMORY)
 			efi_add_memory_map(start, e820[i].size, type);
-		}
 	}
 }
 #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
+
+#if CONFIG_IS_ENABLED(LMB_ARCH_MEM_MAP)
+void lmb_arch_add_memory(void)
+{
+	struct e820_entry e820[E820MAX];
+	unsigned int i, num;
+	u64 ram_top;
+
+	num = install_e820_map(ARRAY_SIZE(e820), e820);
+
+	ram_top = (u64)gd->ram_top & ~EFI_PAGE_MASK;
+	if (!ram_top)
+		ram_top = 0x100000000ULL;
+
+	for (i = 0; i < num; ++i) {
+		if (e820[i].type == E820_RAM) {
+			u64 start, size, rgn_top;
+
+			start = e820[i].addr;
+			size = e820[i].size;
+			rgn_top = start + size;
+
+			if (start > ram_top)
+				continue;
+
+			if (rgn_top > ram_top)
+				size -= rgn_top - ram_top;
+
+			lmb_add(start, size);
+		}
+	}
+}
+#endif /* CONFIG_IS_ENABLED(LMB_ARCH_MEM_MAP) */
diff --git a/lib/Kconfig b/lib/Kconfig
index 3796adc453..269a952031 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -1135,7 +1135,7 @@  config SPL_LMB
 config LMB_ARCH_MEM_MAP
 	bool "Add an architecture specific memory map"
 	depends on LMB
-	default y if FSL_LAYERSCAPE
+	default y if FSL_LAYERSCAPE || X86
 	help
 	  Some architectures have special or unique aspects which need
 	  consideration when adding memory ranges to the list of available