Skip to contentSkip to conversation

rockchip: sdram: Fix issues observed on RK3576

PATCH In review Jonas Karlman 2 participants 6 messages Jan 30, 2025 – Feb 5, 2025

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

v3 cover rockchip: sdram: Fix issues observed on RK3576

Most Rockchip AArch64 SoCs have start of DRAM at 0x0. However, the RK3576 instead has start of DRAM at 0x40000000 and can extend continuous beyond the 4 GiB mark.

This series fixes issues observed on a Rockchip RK3576 board testing Heiko's RK3576 series [1].

Changes in v3:
- Fix 32-bit overflow limiting usable ram_top to max 4G

Changes in v2:
- Drop duplicate patch
- Add patch to limit gd->ram_top to max 4G
- Add patch to assign gd->ram_base in SPL
- Collect r-b tag

[1] https://patchwork.ozlabs.org/cover/2013854/

Jonas Karlman (3):
rockchip: sdram: Allow the first bank to extend beyond 4 GiB
rockchip: sdram: Limit usable ram_top to max 4G
rockchip: sdram: Ensure ram_base is correct in SPL

 arch/arm/mach-rockchip/sdram.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH v3 1/3 rockchip: sdram: Allow the first bank to extend beyond 4 GiB

Allow the first bank to extend beyond 4 GiB when the blob of space for peripheral is located before start of DRAM, e.g. when start of DRAM is 0x40000000 and continue beyond the 4 GiB mark.

---
v3: No change
v2: Collect r-b tag

---
 arch/arm/mach-rockchip/sdram.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-rockchip/sdram.c +2 -0
index 1fb01e1c4b13..96a791bda2c3 100644
@@ -309,6 +309,8 @@ int dram_init_banksize(void)
 	if (ram_top > SZ_4G && top < SZ_4G) {
 		gd->bd->bi_dram[1].start = SZ_4G;
 		gd->bd->bi_dram[1].size = ram_top - gd->bd->bi_dram[1].start;
+	} else if (ram_top > SZ_4G && top == SZ_4G) {
+		gd->bd->bi_dram[0].size = ram_top - gd->bd->bi_dram[0].start;
 	}
 #else
 #ifdef CONFIG_SPL_OPTEE_IMAGE
Signature · 1 line
2.48.1
#2 lore raw

PATCH v3 2/3 rockchip: sdram: Limit usable ram_top to max 4G

In reply to Jonas Karlman

U-Boot only works correctly when it uses RAM below the 4G address boundary on Rockchip SoCs. Limit usable gd->ram_top to max 4G.

---
v3: Use u64 to fix 32-bit overflow
v2: New patch

---
 arch/arm/mach-rockchip/sdram.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-rockchip/sdram.c +2 -1
index 96a791bda2c3..4b8b6b9da7c5 100644
@@ -487,7 +487,8 @@ int dram_init(void)
 
 phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
 {
-	unsigned long top = CFG_SYS_SDRAM_BASE + SDRAM_MAX_SIZE;
+	/* Make sure U-Boot only uses the space below the 4G address boundary */
+	u64 top = min_t(u64, CFG_SYS_SDRAM_BASE + SDRAM_MAX_SIZE, SZ_4G);
 
 	return (gd->ram_top > top) ? top : gd->ram_top;
 }
Signature · 1 line
2.48.1
Reviewed-by on v3 2/3
#3 lore raw

Re: [PATCH v3 2/3] rockchip: sdram: Limit usable ram_top to max 4G

Quoted 4 lines · Jonas Karlman

U-Boot only works correctly when it uses RAM below the 4G address boundary on Rockchip SoCs. Limit usable gd->ram_top to max 4G.

Thanks,
- Kever

Quoted 21 lines

---
v3: Use u64 to fix 32-bit overflow
v2: New patch

---
  arch/arm/mach-rockchip/sdram.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-rockchip/sdram.c +2 -1
index 96a791bda2c3..4b8b6b9da7c5 100644
@@ -487,7 +487,8 @@ int dram_init(void)
 
  phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
  {
-	unsigned long top = CFG_SYS_SDRAM_BASE + SDRAM_MAX_SIZE;
+	/* Make sure U-Boot only uses the space below the 4G address boundary */
+	u64 top = min_t(u64, CFG_SYS_SDRAM_BASE + SDRAM_MAX_SIZE, SZ_4G);
 
  	return (gd->ram_top > top) ? top : gd->ram_top;
  }
#4 lore raw

PATCH v3 3/3 rockchip: sdram: Ensure ram_base is correct in SPL

In reply to Jonas Karlman

Most Rockchip SoCs use 0x0 as DRAM base address, however some SoCs use 0x60000000 and RK3576 use 0x40000000 as DRAM base address.

CFG_SYS_SDRAM_BASE is defined with correct address for each SoC and U-Boot proper use this to set correct gd->ram_base in setup_dest_addr().

SPL never assign any value to gd->ram_base and instead use the default, 0x0. Set correct gd->ram_base in dram_init() to ensure its correctness in SPL.

---
v3: No change
v2: New patch

---
 arch/arm/mach-rockchip/sdram.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-rockchip/sdram.c +1 -0
index 4b8b6b9da7c5..f7d32829295c 100644
@@ -478,6 +478,7 @@ int dram_init(void)
 		debug("Cannot get DRAM size: %d\n", ret);
 		return ret;
 	}
+	gd->ram_base = ram.base;
 	gd->ram_size = ram.size;
 	debug("SDRAM base=%lx, size=%lx\n",
 	      (unsigned long)ram.base, (unsigned long)ram.size);
Signature · 1 line
2.48.1
Reviewed-by on v3 3/3
#5 lore raw

Re: [PATCH v3 3/3] rockchip: sdram: Ensure ram_base is correct in SPL

Quoted 11 lines · Jonas Karlman

Most Rockchip SoCs use 0x0 as DRAM base address, however some SoCs use 0x60000000 and RK3576 use 0x40000000 as DRAM base address.

CFG_SYS_SDRAM_BASE is defined with correct address for each SoC and U-Boot proper use this to set correct gd->ram_base in setup_dest_addr().

SPL never assign any value to gd->ram_base and instead use the default, 0x0. Set correct gd->ram_base in dram_init() to ensure its correctness in SPL.

Thanks,
- Kever

Quoted 19 lines

---
v3: No change
v2: New patch

---
  arch/arm/mach-rockchip/sdram.c | 1 +
  1 file changed, 1 insertion(+)
arch/arm/mach-rockchip/sdram.c +1 -0
index 4b8b6b9da7c5..f7d32829295c 100644
@@ -478,6 +478,7 @@ int dram_init(void)
  		debug("Cannot get DRAM size: %d\n", ret);
  		return ret;
  	}
+	gd->ram_base = ram.base;
  	gd->ram_size = ram.size;
  	debug("SDRAM base=%lx, size=%lx\n",
  	      (unsigned long)ram.base, (unsigned long)ram.size);