Skip to contentSkip to conversation

ARM: imx: imx8m: Fix board_get_usable_ram_top()

PATCH In review Marek Vasut 4 participants 4 messages Apr 14, 2022 – Apr 22, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: imx: imx8m: Fix board_get_usable_ram_top()

The 4 GiB boundary is at 0xffffffff+1 , not at 0x80000000, fix this.

The PHYS_SDRAM of i.MX8M is at 0x40000000 , so to restrict ram_top below 4 GiB, the ram_top has to be set to 0xffffffff as it is not an offset from the start of PHYS_SDRAM, but rather a physical address marking the topmost allowed DRAM address.

Fixes e27bddff4b9 ("imx8m: Restrict usable memory to space below 4G boundary")
Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc Peng Fan <[email protected]>
Cc Stefano Babic <[email protected]>
---
 arch/arm/mach-imx/imx8m/soc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +2 -3
index 8171631db10..e7fe7c2fd88 100644
@@ -331,7 +331,7 @@ phys_size_t get_effective_memsize(void)
 
 ulong board_get_usable_ram_top(ulong total_size)
 {
-	ulong top_addr = PHYS_SDRAM + gd->ram_size;
+	ulong top_addr;
 
 	/*
 	 * Some IPs have their accessible address space restricted by
@@ -339,8 +339,7 @@ ulong board_get_usable_ram_top(ulong total_size)
 	 * space below the 4G address boundary (which is 3GiB big),
 	 * even when the effective available memory is bigger.
 	 */
-	if (top_addr > 0x80000000)
-		top_addr = 0x80000000;
+	top_addr = clamp_val((u64)PHYS_SDRAM + gd->ram_size, 0, 0xffffffff);
 
 	/*
 	 * rom_pointer[0] stores the TEE memory start address.
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Marek,

Quoted 7 lines · Marek Vasut

The 4 GiB boundary is at 0xffffffff+1 , not at 0x80000000, fix this.

The PHYS_SDRAM of i.MX8M is at 0x40000000 , so to restrict ram_top below 4 GiB, the ram_top has to be set to 0xffffffff as it is not an offset from the start of PHYS_SDRAM, but rather a physical address marking the topmost allowed DRAM address.

Quoted 6 lines
Fixes e27bddff4b9 ("imx8m: Restrict usable memory to space below 4G boundary")
Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc Peng Fan <[email protected]>
Cc Stefano Babic <[email protected]>

Good catch!

Reviewed-by on v1 1/1
#2 lore raw
In reply to Marek Vasut

Am 14.04.22 um 15:51 schrieb Marek Vasut:

Quoted 9 lines

The 4 GiB boundary is at 0xffffffff+1 , not at 0x80000000, fix this.

The PHYS_SDRAM of i.MX8M is at 0x40000000 , so to restrict ram_top below 4 GiB, the ram_top has to be set to 0xffffffff as it is not an offset from the start of PHYS_SDRAM, but rather a physical address marking the topmost allowed DRAM address.

Fixes e27bddff4b9 ("imx8m: Restrict usable memory to space below 4G boundary")

Thanks for the fix!

Quoted 31 lines
Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc Peng Fan <[email protected]>
Cc Stefano Babic <[email protected]>
---
 arch/arm/mach-imx/imx8m/soc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +2 -3
index 8171631db10..e7fe7c2fd88 100644
@@ -331,7 +331,7 @@ phys_size_t get_effective_memsize(void)
 
 ulong board_get_usable_ram_top(ulong total_size)
 {
-	ulong top_addr = PHYS_SDRAM + gd->ram_size;
+	ulong top_addr;
 
 	/*
 	 * Some IPs have their accessible address space restricted by
@@ -339,8 +339,7 @@ ulong board_get_usable_ram_top(ulong total_size)
 	 * space below the 4G address boundary (which is 3GiB big),
 	 * even when the effective available memory is bigger.
 	 */
-	if (top_addr > 0x80000000)
-		top_addr = 0x80000000;
+	top_addr = clamp_val((u64)PHYS_SDRAM + gd->ram_size, 0, 0xffffffff);
 
 	/*
 	 * rom_pointer[0] stores the TEE memory start address.
#3 lore raw

PATCH 1/1 ARM: imx: imx8m: Fix board_get_usable_ram_top()

In reply to Marek Vasut
Quoted 5 lines

The 4 GiB boundary is at 0xffffffff+1 , not at 0x80000000, fix this. The PHYS_SDRAM of i.MX8M is at 0x40000000 , so to restrict ram_top below 4 GiB, the ram_top has to be set to 0xffffffff as it is not an offset from the start of PHYS_SDRAM, but rather a physical address marking the topmost allowed DRAM address.

Quoted 8 lines
Fixes e27bddff4b9 ("imx8m: Restrict usable memory to space below 4G boundary")
Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc Peng Fan <[email protected]>
Cc Stefano Babic <[email protected]>

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================