rockchip: sdram: Fix issues observed on RK3576
Subsystems (3)
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 two issues observed on a Rockchip RK3576 board testing Heiko's RK3576 series [1].
[1] https://patchwork.ozlabs.org/cover/2013854/
Jonas Karlman (2):
rockchip: sdram: Allow the first bank to extend beyond 4 GiB
rockchip: sdram: Fix reserve of 2 MiB at start of DRAM
arch/arm/mach-rockchip/sdram.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
Signature · 1 line
2.48.1
PATCH 1/2 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.
--- arch/arm/mach-rockchip/sdram.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/mach-rockchip/sdram.c +2 -0
@@ -310,6 +310,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
Re: [PATCH 1/2] rockchip: sdram: Allow the first bank to extend beyond 4 GiB
Quoted 5 lines · Jonas Karlman
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
0x40000000and continue beyond the 4 GiB mark.Signed-off-by Jonas Karlman <[email protected]>
Thanks,
- Kever
Quoted 17 lines
--- arch/arm/mach-rockchip/sdram.c | 2 ++ 1 file changed, 2 insertions(+)arch/arm/mach-rockchip/sdram.c +2
-0@@ -310,6 +310,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
PATCH 2/2 rockchip: sdram: Fix reserve of 2 MiB at start of DRAM
In reply to Jonas KarlmanNormally 2 MiB at the beginning of DRAM is reserved for TF-A use. However, this only works as intended when DRAM starts at 0x0.
When DRAM starts at e.g. 0x40000000 this reservation never happens, and U-Boot or Linux may try to read/write into secure memory.
Fix this by taking CFG_SYS_SDRAM_BASE into consideration when reserving 2 MiB at start of DRAM.
Also change to use SZ_2M and SZ_32M for consistency.
--- arch/arm/mach-rockchip/sdram.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm/mach-rockchip/sdram.c +6 -6
@@ -182,9 +182,9 @@ static int rockchip_dram_init_banksize(void)* BL31 (TF-A) reserves the first 2MB but DDR_MEM tag may not * have it, so force this space as reserved. */ -if (start_addr <SZ_2M ) { - size -=SZ_2M - start_addr; - start_addr =SZ_2M ; +if (start_addr <CFG_SYS_SDRAM_BASE +SZ_2M ) { + size -=CFG_SYS_SDRAM_BASE +SZ_2M - start_addr; + start_addr =CFG_SYS_SDRAM_BASE +SZ_2M ; }/*
@@ -302,8 +302,8 @@ int dram_init_banksize(void)debug ("Couldn't use ATAG (%d) to detect DDR layout, falling back...\n" , ret); -/* Reserve 0x200000 for ATF bl31 */ - gd->bd->bi_dram[0 ].start =0x200000 ; +/* Reserve 2M for ATF bl31 */ + gd->bd->bi_dram[0 ].start =CFG_SYS_SDRAM_BASE +SZ_2M ; gd->bd->bi_dram[0 ].size = top - gd->bd->bi_dram[0 ].start;/* Add usable memory beyond the blob of space for peripheral near 4GB */
@@ -332,7 +332,7 @@ int dram_init_banksize(void) gd->bd->bi_dram[0 ].size =0x8400000 ;/* Reserve 32M for OPTEE with TA */ gd->bd->bi_dram[1 ].start =CFG_SYS_SDRAM_BASE - + gd->bd->bi_dram[0 ].size +0x2000000 ; + + gd->bd->bi_dram[0 ].size +SZ_32M ; gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start; }#else
Signature · 1 line
2.48.1
Re: [PATCH 2/2] rockchip: sdram: Fix reserve of 2 MiB at start of DRAM
Quoted 6 lines · Jonas Karlman
Normally 2 MiB at the beginning of DRAM is reserved for TF-A use. However, this only works as intended when DRAM starts at
0x0.When DRAM starts at e.g.
0x40000000this reservation never happens, and U-Boot or Linux may try to read/write into secure memory.
Quoted 6 lines
Fix this by taking
CFG_SYS_SDRAM_BASEinto consideration when reserving 2 MiB at start of DRAM.Also change to use
SZ_2MandSZ_32Mfor consistency.Signed-off-by Jonas Karlman <[email protected]>
Thanks,
- Kever
Quoted 41 lines
--- arch/arm/mach-rockchip/sdram.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)arch/arm/mach-rockchip/sdram.c +6
-6@@ -182,9 +182,9 @@ static int rockchip_dram_init_banksize(void)* BL31 (TF-A) reserves the first 2MB but DDR_MEM tag may not * have it, so force this space as reserved. */ -if (start_addr <SZ_2M ) { - size -=SZ_2M - start_addr; - start_addr =SZ_2M ; +if (start_addr <CFG_SYS_SDRAM_BASE +SZ_2M ) { + size -=CFG_SYS_SDRAM_BASE +SZ_2M - start_addr; + start_addr =CFG_SYS_SDRAM_BASE +SZ_2M ; }/* @@ -302,8 +302,8 @@ int dram_init_banksize(void)debug ("Couldn't use ATAG (%d) to detect DDR layout, falling back...\n" , ret); -/* Reserve 0x200000 for ATF bl31 */ - gd->bd->bi_dram[0 ].start =0x200000 ; +/* Reserve 2M for ATF bl31 */ + gd->bd->bi_dram[0 ].start =CFG_SYS_SDRAM_BASE +SZ_2M ; gd->bd->bi_dram[0 ].size = top - gd->bd->bi_dram[0 ].start;/* Add usable memory beyond the blob of space for peripheral near 4GB */ @@ -332,7 +332,7 @@ int dram_init_banksize(void) gd->bd->bi_dram[0 ].size =0x8400000 ;/* Reserve 32M for OPTEE with TA */ gd->bd->bi_dram[1 ].start =CFG_SYS_SDRAM_BASE - + gd->bd->bi_dram[0 ].size +0x2000000 ; + + gd->bd->bi_dram[0 ].size +SZ_32M ; gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start; }#else
Re: [PATCH 2/2] rockchip: sdram: Fix reserve of 2 MiB at start of DRAM
In reply to Jonas KarlmanHi Jonas,
This patch has the same main change with Heiko's patch.
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Thanks,
- Kever
Quoted 53 lines · Jonas Karlman
Normally 2 MiB at the beginning of DRAM is reserved for TF-A use. However, this only works as intended when DRAM starts at
0x0.When DRAM starts at e.g.
0x40000000this reservation never happens, and U-Boot or Linux may try to read/write into secure memory.Fix this by taking
CFG_SYS_SDRAM_BASEinto consideration when reserving 2 MiB at start of DRAM.Also change to use
SZ_2MandSZ_32Mfor consistency.Signed-off-by Jonas Karlman <[email protected]>--- arch/arm/mach-rockchip/sdram.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)arch/arm/mach-rockchip/sdram.c +6
-6@@ -182,9 +182,9 @@ static int rockchip_dram_init_banksize(void)* BL31 (TF-A) reserves the first 2MB but DDR_MEM tag may not * have it, so force this space as reserved. */ -if (start_addr <SZ_2M ) { - size -=SZ_2M - start_addr; - start_addr =SZ_2M ; +if (start_addr <CFG_SYS_SDRAM_BASE +SZ_2M ) { + size -=CFG_SYS_SDRAM_BASE +SZ_2M - start_addr; + start_addr =CFG_SYS_SDRAM_BASE +SZ_2M ; }/* @@ -302,8 +302,8 @@ int dram_init_banksize(void)debug ("Couldn't use ATAG (%d) to detect DDR layout, falling back...\n" , ret); -/* Reserve 0x200000 for ATF bl31 */ - gd->bd->bi_dram[0 ].start =0x200000 ; +/* Reserve 2M for ATF bl31 */ + gd->bd->bi_dram[0 ].start =CFG_SYS_SDRAM_BASE +SZ_2M ; gd->bd->bi_dram[0 ].size = top - gd->bd->bi_dram[0 ].start;/* Add usable memory beyond the blob of space for peripheral near 4GB */ @@ -332,7 +332,7 @@ int dram_init_banksize(void) gd->bd->bi_dram[0 ].size =0x8400000 ;/* Reserve 32M for OPTEE with TA */ gd->bd->bi_dram[1 ].start =CFG_SYS_SDRAM_BASE - + gd->bd->bi_dram[0 ].size +0x2000000 ; + + gd->bd->bi_dram[0 ].size +SZ_32M ; gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start; }#else
Re: [PATCH 2/2] rockchip: sdram: Fix reserve of 2 MiB at start of DRAM
Hi Kever,
Quoted 6 lines · Kever Yang
Hi Jonas,
This patch has the same main change with Heiko's patch.
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Ohh, I have completely missed that patch when testing the RK3576 series. Not sure how, sorry for extra noise and please ignore my patch :-)
Regards,
Jonas
Quoted 57 lines
Thanks,
- KeverQuoted 53 lines · Jonas Karlman
Normally 2 MiB at the beginning of DRAM is reserved for TF-A use. However, this only works as intended when DRAM starts at
0x0.When DRAM starts at e.g.
0x40000000this reservation never happens, and U-Boot or Linux may try to read/write into secure memory.Fix this by taking
CFG_SYS_SDRAM_BASEinto consideration when reserving 2 MiB at start of DRAM.Also change to use
SZ_2MandSZ_32Mfor consistency.Signed-off-by Jonas Karlman <[email protected]>--- arch/arm/mach-rockchip/sdram.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)arch/arm/mach-rockchip/sdram.c +6
-6@@ -182,9 +182,9 @@ static int rockchip_dram_init_banksize(void)* BL31 (TF-A) reserves the first 2MB but DDR_MEM tag may not * have it, so force this space as reserved. */ -if (start_addr <SZ_2M ) { - size -=SZ_2M - start_addr; - start_addr =SZ_2M ; +if (start_addr <CFG_SYS_SDRAM_BASE +SZ_2M ) { + size -=CFG_SYS_SDRAM_BASE +SZ_2M - start_addr; + start_addr =CFG_SYS_SDRAM_BASE +SZ_2M ; }/* @@ -302,8 +302,8 @@ int dram_init_banksize(void)debug ("Couldn't use ATAG (%d) to detect DDR layout, falling back...\n" , ret); -/* Reserve 0x200000 for ATF bl31 */ - gd->bd->bi_dram[0 ].start =0x200000 ; +/* Reserve 2M for ATF bl31 */ + gd->bd->bi_dram[0 ].start =CFG_SYS_SDRAM_BASE +SZ_2M ; gd->bd->bi_dram[0 ].size = top - gd->bd->bi_dram[0 ].start;/* Add usable memory beyond the blob of space for peripheral near 4GB */ @@ -332,7 +332,7 @@ int dram_init_banksize(void) gd->bd->bi_dram[0 ].size =0x8400000 ;/* Reserve 32M for OPTEE with TA */ gd->bd->bi_dram[1 ].start =CFG_SYS_SDRAM_BASE - + gd->bd->bi_dram[0 ].size +0x2000000 ; + + gd->bd->bi_dram[0 ].size +SZ_32M ; gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start; }#else