rockchip: sdram: Fix issues observed on RK3576
Subsystems (3)
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
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
@@ -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
PATCH v3 2/3 rockchip: sdram: Limit usable ram_top to max 4G
In reply to Jonas KarlmanU-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
@@ -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
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_topto max 4G.Signed-off-by Jonas Karlman <[email protected]>
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@@ -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; }
PATCH v3 3/3 rockchip: sdram: Ensure ram_base is correct in SPL
In reply to Jonas KarlmanMost 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
@@ -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
Re: [PATCH v3 3/3] rockchip: sdram: Ensure ram_base is correct in SPL
Quoted 11 lines · Jonas Karlman
Most Rockchip SoCs use
0x0as DRAM base address, however some SoCs use0x60000000and RK3576 use0x40000000as DRAM base address.
CFG_SYS_SDRAM_BASEis defined with correct address for each SoC and U-Boot proper use this to set correctgd->ram_baseinsetup_dest_addr().SPL never assign any value to
gd->ram_baseand instead use the default,0x0. Set correctgd->ram_baseindram_init()to ensure its correctness in SPL.Signed-off-by Jonas Karlman <[email protected]>
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@@ -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);