Add reserved-memory nodes to QCS615 and QCS6490 device trees to
define platform-specific memory regions that should not be used by
the operating system.

Implement efi_add_known_memory() function in board.c code to
parse reserved-memory nodes from device tree and register them with
the EFI memory map. This ensures proper memory protection during EFI
boot and prevents conflicts with firmware-reserved regions.

Signed-off-by: Balaji Selvanathan <[email protected]>
---
Changes in v2:
- Instead of adding reserved region info in a new
  qcom_reserved_memory.c file, added the regions to reserved memory
  node in override dts.
- Link to v1: 
https://lore.kernel.org/u-boot/[email protected]/
---
 arch/arm/dts/qcs615-ride-u-boot.dtsi     | 56 +++++++++++++++++++++++
 arch/arm/dts/qcs6490-rb3gen2-u-boot.dtsi | 26 +++++++++++
 arch/arm/mach-snapdragon/board.c         | 58 ++++++++++++++++++++++++
 3 files changed, 140 insertions(+)

diff --git a/arch/arm/dts/qcs615-ride-u-boot.dtsi 
b/arch/arm/dts/qcs615-ride-u-boot.dtsi
index 68fffc70fcb..ec607061ba0 100644
--- a/arch/arm/dts/qcs615-ride-u-boot.dtsi
+++ b/arch/arm/dts/qcs615-ride-u-boot.dtsi
@@ -11,4 +11,60 @@
                      <0x0 0xc0000000 0x0 0xc0000000>,
                      <0x1 0x80000000 0x1 0x00000000>;
        };
+
+       reserved-memory {
+               #address-cells = <2>;
+               #size-cells = <2>;
+               ranges;
+
+               hyp_mem: hyp@80000000 {
+                       reg = <0x0 0x80000000 0x0 0x600000>;
+                       no-map;
+               };
+
+               xbl_boot_mem: xbl-boot@85d00000 {
+                       reg = <0x0 0x85d00000 0x0 0x200000>;
+                       no-map;
+               };
+
+               aop_mem: aop@85f00000 {
+                       reg = <0x0 0x85f00000 0x0 0x20000>;
+                       no-map;
+               };
+
+               xbl_dt_mem: xbl-dt@85f40000 {
+                       reg = <0x0 0x85f40000 0x0 0x30000>;
+                       no-map;
+               };
+
+               tz_stat_mem: tz-stat@86200000 {
+                       reg = <0x0 0x86200000 0x0 0x100000>;
+                       no-map;
+               };
+
+               tags_mem: tags@86300000 {
+                       reg = <0x0 0x86300000 0x0 0x1200000>;
+                       no-map;
+               };
+
+               tz_mem: tz@87500000 {
+                       reg = <0x0 0x87500000 0x0 0x500000>;
+                       no-map;
+               };
+
+               tzapps_mem: tzapps@87a00000 {
+                       reg = <0x0 0x87a00000 0x0 0x1c00000>;
+                       no-map;
+               };
+
+               pil_mem: pil@8ab00000 {
+                       reg = <0x0 0x8ab00000 0x0 0xcc17000>;
+                       no-map;
+               };
+
+               secure_dsp_mem: secure-dsp@a0000000 {
+                       reg = <0x0 0xa0000000 0x0 0x1600000>;
+                       no-map;
+               };
+       };
 };
diff --git a/arch/arm/dts/qcs6490-rb3gen2-u-boot.dtsi 
b/arch/arm/dts/qcs6490-rb3gen2-u-boot.dtsi
index 8d4871135fa..cf6de0036d5 100644
--- a/arch/arm/dts/qcs6490-rb3gen2-u-boot.dtsi
+++ b/arch/arm/dts/qcs6490-rb3gen2-u-boot.dtsi
@@ -15,6 +15,32 @@
                      <0 0xC3400000 0 0x3CC00000>,
                      <1 0x00000000 1 0x00000000>;
        };
+
+       reserved-memory {
+               #address-cells = <2>;
+               #size-cells = <2>;
+               ranges;
+
+               axon_dma_mem: axon-dma@80600000 {
+                       reg = <0x0 0x80600000 0x0 0x100000>;
+                       no-map;
+               };
+
+               xbl_dt_mem: xbl-dt@80894000 {
+                       reg = <0x0 0x80894000 0x0 0x40000>;
+                       no-map;
+               };
+
+               pil_reserved_mem: pil-reserved@84300000 {
+                       reg = <0x0 0x84300000 0x0 0x16b00000>;
+                       no-map;
+               };
+
+               display_mem: display@e1000000 {
+                       reg = <0x0 0xe1000000 0x0 0x2400000>;
+                       no-map;
+               };
+       };
 };
 
 &usb_1 {
diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c
index 5fb3240acc5..f32d29a9242 100644
--- a/arch/arm/mach-snapdragon/board.c
+++ b/arch/arm/mach-snapdragon/board.c
@@ -19,8 +19,10 @@
 #include <dm/uclass-internal.h>
 #include <dm/read.h>
 #include <power/regulator.h>
+#include <efi_loader.h>
 #include <env.h>
 #include <fdt_support.h>
+#include <fdtdec.h>
 #include <init.h>
 #include <linux/arm-smccc.h>
 #include <linux/bug.h>
@@ -709,6 +711,62 @@ static void carve_out_reserved_memory(void)
        }
 }
 
+/**
+ * efi_add_known_memory() - Add platform-specific reserved memory to EFI map
+ *
+ * This function is called by the EFI memory initialization code to allow
+ * platforms to add their reserved memory regions to the EFI memory map.
+ * For Qualcomm platforms, this parses the reserved-memory nodes from the
+ * device tree and adds them to the EFI memory map.
+ */
+void efi_add_known_memory(void)
+{
+       ofnode parent, node;
+       fdt_addr_t addr;
+       fdt_size_t size;
+       const char *name;
+
+       if (!IS_ENABLED(CONFIG_EFI_LOADER))
+               return;
+
+       /* Parse reserved-memory nodes from device tree */
+       parent = ofnode_path("/reserved-memory");
+       if (!ofnode_valid(parent)) {
+               log_debug("No reserved-memory node found in device tree\n");
+               return;
+       }
+
+       log_debug("Adding reserved-memory regions to EFI memory map\n");
+
+       ofnode_for_each_subnode(node, parent) {
+               if (!ofnode_is_enabled(node))
+                       continue;
+
+               addr = ofnode_get_addr_size_index(node, 0, &size);
+               if (addr != FDT_ADDR_T_NONE) {
+                       efi_status_t ret;
+
+                       name = ofnode_get_name(node);
+                       ret = efi_add_memory_map(addr, size,
+                                                EFI_RESERVED_MEMORY_TYPE);
+
+                       if (ret != EFI_SUCCESS) {
+                               log_err("Failed to reserve %s (0x%llx-0x%llx): 
%lu\n",
+                                       name ? name : "unknown",
+                                       (unsigned long long)addr,
+                                       (unsigned long long)(addr + size),
+                                       ret & ~EFI_ERROR_MASK);
+                       } else {
+                               log_debug("Reserved %s: 0x%llx-0x%llx (%llu 
KB)\n",
+                                         name ? name : "unknown",
+                                         (unsigned long long)addr,
+                                         (unsigned long long)(addr + size),
+                                         (unsigned long long)(size / 1024));
+                       }
+               }
+       }
+}
+
 /* This function open-codes setup_all_pgtables() so that we can
  * insert additional mappings *before* turning on the MMU.
  */
-- 
2.34.1

Reply via email to