Retrieve the EFI info header passed in via x0 and use it to populate the
memory banks when booting with CONFIG_EFI_STUB.

Signed-off-by: Caleb Connolly <[email protected]>
---
 arch/arm/mach-snapdragon/board.c     | 15 +++++++++++++++
 arch/arm/mach-snapdragon/dram.c      | 15 ++++++++++++++-
 arch/arm/mach-snapdragon/qcom-priv.h |  2 ++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c
index dbac8aa2709a..f92b26c88d46 100644
--- a/arch/arm/mach-snapdragon/board.c
+++ b/arch/arm/mach-snapdragon/board.c
@@ -41,8 +41,10 @@ DECLARE_GLOBAL_DATA_PTR;
 static struct mm_region rbx_mem_map[CONFIG_NR_DRAM_BANKS + 2] = { { 0 } };
 
 struct mm_region *mem_map = rbx_mem_map;
 
+struct efi_info_hdr *efi_info __section(".data") = NULL;
+
 static void show_psci_version(void)
 {
        struct arm_smccc_res res;
 
@@ -59,15 +61,28 @@ static void show_psci_version(void)
  */
 void *board_fdt_blob_setup(int *err)
 {
        struct fdt_header *fdt;
+       struct efi_info_hdr *info = NULL;
        bool internal_valid, external_valid;
 
        *err = 0;
        fdt = (struct fdt_header *)get_prev_bl_fdt_addr();
        external_valid = fdt && !fdt_check_header(fdt);
        internal_valid = !fdt_check_header(gd->fdt_blob);
 
+       /*
+        * If EFI_STUB is enabled, we got handed a pointer and it's NOT
+        * a valid FDT, then it might be the efi_info table!
+        */
+       if (CONFIG_IS_ENABLED(EFI_STUB) && fdt && !external_valid)
+               info = (struct efi_info_hdr *)fdt;
+
+       if (info->version == 1) {
+               debug("Got EFI info header!\n");
+               efi_info = info;
+       }
+
        /*
         * There is no point returning an error here, U-Boot can't do anything 
useful in this situation.
         * Bail out while we can still print a useful error message.
         */
diff --git a/arch/arm/mach-snapdragon/dram.c b/arch/arm/mach-snapdragon/dram.c
index ef226e000858..0493653e432b 100644
--- a/arch/arm/mach-snapdragon/dram.c
+++ b/arch/arm/mach-snapdragon/dram.c
@@ -7,12 +7,15 @@
 #define pr_fmt(fmt) "QCOM-DRAM: " fmt
 
 #include <asm-generic/unaligned.h>
 #include <dm.h>
+#include <efi_stub.h>
 #include <log.h>
 #include <sort.h>
 #include <soc/qcom/smem.h>
 
+#include "qcom-priv.h"
+
 #define SMEM_USABLE_RAM_PARTITION_TABLE 402
 #define RAM_PART_NAME_LENGTH            16
 #define RAM_NUM_PART_ENTRIES            32
 #define CATEGORY_SDRAM 0x0E
@@ -89,9 +92,19 @@ static void qcom_configure_bi_dram(void)
 }
 
 int dram_init_banksize(void)
 {
-       qcom_configure_bi_dram();
+#ifdef CONFIG_EFI_STUB
+       gd->arch.table = (phys_addr_t)efi_info;
+       /* We actually parsed a memory map from SMEM (and used it to
+        * set ram_base/ram_top), but it's better to respect the table
+        * from the EFI bootloader.
+        */
+       if (efi_info)
+               dram_init_banksize_from_efi();
+       else
+#endif
+               qcom_configure_bi_dram();
 
        return 0;
 }
 
diff --git a/arch/arm/mach-snapdragon/qcom-priv.h 
b/arch/arm/mach-snapdragon/qcom-priv.h
index 690557463642..58b8cb497482 100644
--- a/arch/arm/mach-snapdragon/qcom-priv.h
+++ b/arch/arm/mach-snapdragon/qcom-priv.h
@@ -4,8 +4,10 @@
 #define __QCOM_PRIV_H__
 
 #include <stdbool.h>
 
+extern struct efi_info_hdr *efi_info;
+
 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
 void qcom_configure_capsule_updates(void);
 #else
 void qcom_configure_capsule_updates(void) {}

-- 
2.47.0

Reply via email to