From: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
Date: Mon, 23 Aug 2021 02:43:06 +0000 (+0800)
Subject: imx8m: Restrict usable memory based on rom_pointer[0]
X-Git-Tag: v2025.01-rc5-pxa1908~1673^2~46
X-Git-Url: http://git.dujemihanovic.xyz/img/static/login.html?a=commitdiff_plain;h=5a6af8c19ab8c9a7dd44db9406b68fcb7fe5ee18;p=u-boot.git

imx8m: Restrict usable memory based on rom_pointer[0]

When TEE is loaded, we need to restrict the memory usage based
on rom_pointer[0]

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Frieder Schrempf <frieder.schrempf@kontron.de>
Cc: uboot-imx <uboot-imx@nxp.com>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
---

diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c
index f2ddc834d4..863508776d 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -298,16 +298,26 @@ phys_size_t get_effective_memsize(void)
 
 ulong board_get_usable_ram_top(ulong total_size)
 {
+	ulong top_addr = PHYS_SDRAM + gd->ram_size;
+
 	/*
 	 * Some IPs have their accessible address space restricted by
 	 * the interconnect. Let's make sure U-Boot only ever uses the
 	 * space below the 4G address boundary (which is 3GiB big),
 	 * even when the effective available memory is bigger.
 	 */
-	if (PHYS_SDRAM + gd->ram_size > 0x80000000)
-		return 0x80000000;
+	if (top_addr > 0x80000000)
+		top_addr = 0x80000000;
+
+	/*
+	 * rom_pointer[0] stores the TEE memory start address.
+	 * rom_pointer[1] stores the size TEE uses.
+	 * We need to reserve the memory region for TEE.
+	 */
+	if (rom_pointer[0] && rom_pointer[1] && top_addr > rom_pointer[0])
+		top_addr = rom_pointer[0];
 
-	return PHYS_SDRAM + gd->ram_size;
+	return top_addr;
 }
 
 static u32 get_cpu_variant_type(u32 type)