Skip to contentSkip to conversation

rockchip: sdram: Fix issues observed on RK3576

PATCH Superseded Jonas Karlman 2 participants 7 messages Jan 23, 2025 – Jan 24, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 7c21ae8efc44..3d3fc327234f 100644
@@ -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
Reviewed-by on v1 1/2
#2 lore raw

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 0x40000000 and continue beyond the 4 GiB mark.

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
index 7c21ae8efc44..3d3fc327234f 100644
@@ -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
#3 lore raw

PATCH 2/2 rockchip: sdram: Fix reserve of 2 MiB at start of DRAM

In reply to 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. 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
index 3d3fc327234f..caca6f917305 100644
@@ -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
Reviewed-by on v1 2/2
#4 lore raw

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. 0x40000000 this 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_BASE into consideration when reserving 2 MiB at start of DRAM.

Also change to use SZ_2M and SZ_32M for consistency.

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
index 3d3fc327234f..caca6f917305 100644
@@ -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
#5 lore raw

Re: [PATCH 2/2] rockchip: sdram: Fix reserve of 2 MiB at start of DRAM

In reply to Jonas Karlman

Hi 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. 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
index 3d3fc327234f..caca6f917305 100644
@@ -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
#6 lore raw

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,
- 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. 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
index 3d3fc327234f..caca6f917305 100644
@@ -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