Skip to contentSkip to conversation

sunxi: add PRCM secure switch register definition

PATCH New Icenowy Zheng 4 participants 10 messages Jul 20, 2017 – Aug 11, 2017

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

PATCH 1/2 sunxi: add PRCM secure switch register definition

Some new Allwinner SoCs' PRCM has a secure switch register, which controls the access to some clock and power registers in PRCM block.

Add the definition of this register and its bits in the PRCM header file.

---
 arch/arm/include/asm/arch-sunxi/prcm.h | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/include/asm/arch-sunxi/prcm.h +6 -0
index ae3880b13b..ba4427c925 100644
@@ -196,6 +196,10 @@
 #define PRCM_CPU3_PWR_CLAMP(n) (((n) & 0xff) << 0)
 #define PRCM_CPU3_PWR_CLAMP_MASK PRCM_CPU3_PWR_CLAMP(0xff)
 
+#define PRCM_SEC_SWITCH_APB0_CLK_NONSEC (0x1 << 0)
+#define PRCM_SEC_SWITCH_PLL_CFG_NONSEC (0x1 << 1)
+#define PRCM_SEC_SWITCH_PWR_GATE_NONSEC (0x1 << 2)
+
 #ifndef __ASSEMBLY__
 #include <linux/compiler.h>
 
@@ -233,6 +237,8 @@ struct __packed sunxi_prcm_reg {
 	u32 dram_pwr;		/* 0x180 */
 	u8 res12[0xc];		/* 0x184 */
 	u32 dram_tst;		/* 0x190 */
+	u8 res13[0x3c];		/* 0x194 */
+	u32 prcm_sec_switch;	/* 0x1d0 */
 };
 
 void prcm_apb0_enable(u32 flags);
Signature · 1 line
2.13.0
#1 lore raw

PATCH 2/2 sunxi: switch PRCM to non-secure on H3/H5 SoCs

The PRCM of H3/H5 SoCs have a secure/non-secure switch, which controls the access to some clock/power related registers in PRCM.

Current Linux kernel will access the CPUS (AR100) clock in the PRCM block, so the PRCM should be switched to non-secure.

Add code to switch the PRCM to non-secure.

---
 arch/arm/mach-sunxi/clock_sun6i.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-sunxi/clock_sun6i.c +6 -0
index ec5b026ef5..870ff5b1e0 100644
@@ -66,11 +66,17 @@ void clock_init_sec(void)
 #ifdef CONFIG_MACH_SUNXI_H3_H5
 	struct sunxi_ccm_reg * const ccm =
 		(struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+	struct sunxi_prcm_reg * const prcm =
+		(struct sunxi_prcm_reg *)SUNXI_PRCM_BASE;
 
 	setbits_le32(&ccm->ccu_sec_switch,
 		     CCM_SEC_SWITCH_MBUS_NONSEC |
 		     CCM_SEC_SWITCH_BUS_NONSEC |
 		     CCM_SEC_SWITCH_PLL_NONSEC);
+	setbits_le32(&prcm->prcm_sec_switch,
+		     PRCM_SEC_SWITCH_APB0_CLK_NONSEC |
+		     PRCM_SEC_SWITCH_PLL_CFG_NONSEC |
+		     PRCM_SEC_SWITCH_PWR_GATE_NONSEC);
 #endif
 }
 
Signature · 1 line
2.13.0
#2 lore raw

PATCH 2/2 sunxi: switch PRCM to non-secure on H3/H5 SoCs

Quoted 7 lines · 在 2017-07-20 14:00,Icenowy Zheng 写道:

The PRCM of H3/H5 SoCs have a secure/non-secure switch, which controls the access to some clock/power related registers in PRCM.

Current Linux kernel will access the CPUS (AR100) clock in the PRCM block, so the PRCM should be switched to non-secure.

Add code to switch the PRCM to non-secure.

Ping.

Maxime and Jagan, can you merge this patchset?

This is necessary for R_CCU to work properly on H3.

Quoted 28 lines
---
 arch/arm/mach-sunxi/clock_sun6i.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-sunxi/clock_sun6i.c +6 -0
index ec5b026ef5..870ff5b1e0 100644
@@ -66,11 +66,17 @@ void clock_init_sec(void)
 #ifdef CONFIG_MACH_SUNXI_H3_H5
 	struct sunxi_ccm_reg * const ccm =
 		(struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+	struct sunxi_prcm_reg * const prcm =
+		(struct sunxi_prcm_reg *)SUNXI_PRCM_BASE;
 
 	setbits_le32(&ccm->ccu_sec_switch,
 		     CCM_SEC_SWITCH_MBUS_NONSEC |
 		     CCM_SEC_SWITCH_BUS_NONSEC |
 		     CCM_SEC_SWITCH_PLL_NONSEC);
+	setbits_le32(&prcm->prcm_sec_switch,
+		     PRCM_SEC_SWITCH_APB0_CLK_NONSEC |
+		     PRCM_SEC_SWITCH_PLL_CFG_NONSEC |
+		     PRCM_SEC_SWITCH_PWR_GATE_NONSEC);
 #endif
 }
#3 lore raw

PATCH 2/2 sunxi: switch PRCM to non-secure on H3/H5 SoCs

Quoted 7 lines · icenowy at aosc.io
Quoted 6 lines · 在 2017-07-20 14:00,Icenowy Zheng 写道:

The PRCM of H3/H5 SoCs have a secure/non-secure switch, which controls the access to some clock/power related registers in PRCM.

Current Linux kernel will access the CPUS (AR100) clock in the PRCM block, so the PRCM should be switched to non-secure.

Quoted 7 lines
Quoted 1 line

Add code to switch the PRCM to non-secure.

Ping.

Maxime and Jagan, can you merge this patchset?

This is necessary for R_CCU to work properly on H3.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170726/9c164f2d/attachment.sig>
#4 lore raw

PATCH 2/2 sunxi: switch PRCM to non-secure on H3/H5 SoCs

Quoted 10 lines · Maxime Ripard
Quoted 9 lines · icenowy at aosc.io
Quoted 7 lines · 在 2017-07-20 14:00,Icenowy Zheng 写道:

The PRCM of H3/H5 SoCs have a secure/non-secure switch, which controls the access to some clock/power related registers in PRCM.

Current Linux kernel will access the CPUS (AR100) clock in the PRCM block, so the PRCM should be switched to non-secure.

Add code to switch the PRCM to non-secure.

Quoted 7 lines
Quoted 5 lines

Ping.

Maxime and Jagan, can you merge this patchset?

This is necessary for R_CCU to work properly on H3.

#5 lore raw

PATCH 1/2 sunxi: add PRCM secure switch register definition

In reply to Icenowy Zheng
Quoted 7 lines · Icenowy Zheng

Some new Allwinner SoCs' PRCM has a secure switch register, which controls the access to some clock and power registers in PRCM block.

Add the definition of this register and its bits in the PRCM header file.

Could you provide a reference as to where or how you found out about this?

Thanks
ChenYu

#6 lore raw

PATCH 1/2 sunxi: add PRCM secure switch register definition

Quoted 11 lines · 在 2017-08-08 12:13,Chen-Yu Tsai 写道:
Quoted 7 lines · Icenowy Zheng

Some new Allwinner SoCs' PRCM has a secure switch register, which controls the access to some clock and power registers in PRCM block.

Add the definition of this register and its bits in the PRCM header file.

Could you provide a reference as to where or how you found out about this?

https://github.com/tinalinux/brandy/blob/r18-v0.9/arm-trusted-firmware-1.0/plat/sun50iw1p1/sunxi_security.c#L105

Quoted 3 lines

Thanks
ChenYu

#7 lore raw

PATCH 1/2 sunxi: add PRCM secure switch register definition

Quoted 10 lines · On Tue, Aug 8, 2017 at 2:46 PM, <[email protected]> wrote:
Quoted 9 lines · 在 2017-08-08 12:13,Chen-Yu Tsai 写道:
Quoted 7 lines · Icenowy Zheng

Some new Allwinner SoCs' PRCM has a secure switch register, which controls the access to some clock and power registers in PRCM block.

Add the definition of this register and its bits in the PRCM header file.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Could you provide a reference as to where or how you found out about this?

https://github.com/tinalinux/brandy/blob/r18-v0.9/arm-trusted-firmware-1.0/plat/sun50iw1p1/sunxi_security.c#L105

I assume you've mapped out what each bit means by testing it?

#8 lore raw

PATCH 1/2 sunxi: add PRCM secure switch register definition

Quoted 15 lines · 在 2017-08-09 11:46,Chen-Yu Tsai 写道:
Quoted 14 lines · On Tue, Aug 8, 2017 at 2:46 PM, <[email protected]> wrote:
Quoted 13 lines · 在 2017-08-08 12:13,Chen-Yu Tsai 写道:
Quoted 8 lines · Icenowy Zheng

Some new Allwinner SoCs' PRCM has a secure switch register, which controls the access to some clock and power registers in PRCM block.

Add the definition of this register and its bits in the PRCM header file.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Could you provide a reference as to where or how you found out about this?

https://github.com/tinalinux/brandy/blob/r18-v0.9/arm-trusted-firmware-1.0/plat/sun50iw1p1/sunxi_security.c#L105

I assume you've mapped out what each bit means by testing it?

Yes.

Toggling bit 0 will make at least 0x0 (CPUS_CFG_REG) inaccessible. Toggling bit 1 will make at least 0x40 and 0x44 (PLL_CTRL_REG{0,1}) inaccessible.
Toggling bit 2 will make at least 0x120 (VDD_SYS_PWR_RST) inaccessible.

(The register names are from http://linux-sunxi.org/PRCM )

Quoted 2 lines
#9 lore raw

PATCH 1/2 sunxi: add PRCM secure switch register definition

In reply to Icenowy Zheng
Quoted 7 lines · Icenowy Zheng

Some new Allwinner SoCs' PRCM has a secure switch register, which controls the access to some clock and power registers in PRCM block.

Add the definition of this register and its bits in the PRCM header file.

Applied both in u-boot-sunxi/master

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.