Skip to contentSkip to conversation

arm: mach-k3: common: Clamp RAM end address to board-usable region in spl_enable_cache()

PATCH In review Devarsh Thakkar 3 participants 3 messages Feb 24

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

PATCH 1/1 arm: mach-k3: common: Clamp RAM end address to board-usable region in spl_enable_cache()

commit ba20b2443c29 ("arm: mach-k3: common: Reserve video memory from end of the RAM") switched spl_enable_cache() to use gd->ram_top directly but omitted the board_get_usable_ram_top() call that limits RAM configuration and provides updated RAM end address per memory map used by board and impacts subsequent allocations and reservations. For e.g. here it impacts how high the TLB may be placed.

On Verdin AM62 (512 MiB), the raw end of RAM (0xA0000000) is inside OP-TEE's region. board_get_usable_ram_top() in verdin-am62.c returns 0x9C000000 to keep relocations below it, but spl_enable_cache() never called it. commit 42b3ee7fa524 ("arm: mach-k3: am62x: Enable memory firewall support") then enforced the OP-TEE firewall, turning the silent corruption into a hard hang.

Fix by calling board_get_usable_ram_top() after computing raw ram_top, consistent with setup_dest_addr() in board_f.c. A weak default is provided for boards that do not need to restrict the RAM top.

Fixes ba20b2443c29 ("arm: mach-k3: common: Reserve video memory from end of the RAM")
---
 arch/arm/mach-k3/common.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-k3/common.c +6 -0
index 0a686efa1319..2f3df5519c53 100644
@@ -407,6 +407,11 @@ void k3_fix_rproc_clock(const char *path)
 		       path, a_core_frequency / 1000000, speed_grade);
 }
 
+__weak phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
+{
+	return gd->ram_top;
+}
+
 void spl_enable_cache(void)
 {
 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
@@ -420,6 +425,7 @@ void spl_enable_cache(void)
 	gd->arch.tlb_size = PGTABLE_SIZE;
 
 	gd->ram_top += get_effective_memsize();
+	gd->ram_top = board_get_usable_ram_top(0);
 	gd->relocaddr = gd->ram_top;
 
 	ret = spl_reserve_video_from_ram_top();
Signature · 1 line
2.39.1
Tested-by on v1 1/1
#1 lore raw
Quoted 14 lines · Devarsh Thakkar

commit ba20b2443c29 ("arm: mach-k3: common: Reserve video memory from end of the RAM") switched spl_enable_cache() to use gd->ram_top directly but omitted the board_get_usable_ram_top() call that limits RAM configuration and provides updated RAM end address per memory map used by board and impacts subsequent allocations and reservations. For e.g. here it impacts how high the TLB may be placed.

On Verdin AM62 (512 MiB), the raw end of RAM (0xA0000000) is inside OP-TEE's region. board_get_usable_ram_top() in verdin-am62.c returns 0x9C000000 to keep relocations below it, but spl_enable_cache() never called it. commit 42b3ee7fa524 ("arm: mach-k3: am62x: Enable memory firewall support") then enforced the OP-TEE firewall, turning the silent corruption into a hard hang.

Quoted 8 lines

Fix by calling board_get_usable_ram_top() after computing raw ram_top, consistent with setup_dest_addr() in board_f.c. A weak default is provided for boards that do not need to restrict the RAM top.

Fixes ba20b2443c29 ("arm: mach-k3: common: Reserve video memory from end of the RAM")

Thanks Devarsh,

#2 lore raw
In reply to Devarsh Thakkar
Quoted 8 lines · Devarsh Thakkar

commit ba20b2443c29 ("arm: mach-k3: common: Reserve video memory from end of the RAM") switched spl_enable_cache() to use gd->ram_top directly but omitted the board_get_usable_ram_top() call that limits RAM configuration and provides updated RAM end address per memory map used by board and impacts subsequent allocations and reservations. For e.g. here it impacts how high the TLB may be placed.

[...]

Applied to u-boot/master, thanks!

[1/1] arm: mach-k3: common: Clamp RAM end address to board-usable region in spl_enable_cache()

      commit: 26048cdb4ce35b4119e82df2aafb1ebf3f611480
Signature · 1 line
Tom