clk: rockchip: rk3588: keep the OTP gates shared with the secure world on
Subsystems (2)
PATCH 1/1 clk: rockchip: rk3588: keep the OTP gates shared with the secure world on
The secure OTP controller (OTPC_S) shares three clock gates in CRU_CLKGATE_CON18 with the non-secure one: clk_otpc_arb, clk_otpc_auto_rd_g and clk_otp_phy_g. The kernel treats them as ordinary
gates: clk_otpc_auto_rd_g is disabled as unused at the end of boot, and the rockchip-otp nvmem driver enables clk_otpc_arb and clk_otp_phy_g around each read and disables them again afterwards.
Firmware in the secure world (OP-TEE reads its hardware unique key and the secure boot state from OTPC_S, and programs them) has no way to take a reference on these clocks. Once Linux has gated them, every secure OTP access times out, and a normal-world nvmem read on another CPU can gate them in the middle of a secure access, including a fuse programming cycle.
Mark the three gates critical so the normal world never turns them off. They are 24 MHz gates for the OTP block only.
--- drivers/clk/rockchip/clk-rk3588.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/rockchip/clk-rk3588.c +3 -3
@@ -1158,11 +1158,11 @@ static struct rockchip_clk_branch rk3588_early_clk_branches[] __initdata = { RK3588_CLKGATE_CON(18), 9, GFLAGS),GATE (CLK_OTPC_NS ,"clk_otpc_ns" ,"xin24m" ,0 ,RK3588_CLKGATE_CON (18 ),10 ,GFLAGS ), -GATE (CLK_OTPC_ARB ,"clk_otpc_arb" ,"xin24m" ,0 , +GATE (CLK_OTPC_ARB ,"clk_otpc_arb" ,"xin24m" ,CLK_IS_CRITICAL ,RK3588_CLKGATE_CON (18 ),11 ,GFLAGS ), -GATE (CLK_OTP_PHY_G ,"clk_otp_phy_g" ,"xin24m" ,0 , +GATE (CLK_OTP_PHY_G ,"clk_otp_phy_g" ,"xin24m" ,CLK_IS_CRITICAL ,RK3588_CLKGATE_CON (18 ),13 ,GFLAGS ), -GATE (CLK_OTPC_AUTO_RD_G ,"clk_otpc_auto_rd_g" ,"xin24m" ,0 , +GATE (CLK_OTPC_AUTO_RD_G ,"clk_otpc_auto_rd_g" ,"xin24m" ,CLK_IS_CRITICAL ,RK3588_CLKGATE_CON (18 ),12 ,GFLAGS ), GATE(PCLK_SARADC, "pclk_saradc", "pclk_top_root", 0,
Signature · 1 line
2.56.0
Quoted 15 lines · Nikolay Bryskin
The secure OTP controller (
OTPC_S) shares three clock gates inCRU_CLKGATE_CON18with the non-secure one:clk_otpc_arb,clk_otpc_auto_rd_gandclk_otp_phy_g. The kernel treats them as ordinary
gates:clk_otpc_auto_rd_gis disabled as unused at the end of boot, and the rockchip-otp nvmem driver enablesclk_otpc_arbandclk_otp_phy_garound each read and disables them again afterwards.Firmware in the secure world (OP-TEE reads its hardware unique key and the secure boot state from
OTPC_S, and programs them) has no way to take a reference on these clocks. Once Linux has gated them, every secure OTP access times out, and a normal-world nvmem read on another CPU can gate them in the middle of a secure access, including a fuse programming cycle.
Quoted 2 lines
Mark the three gates critical so the normal world never turns them off. They are 24 MHz gates for the OTP block only.
If OPTEE needs some resources kept online, maybe the OPTEE DT node should have a reference to them?
Otherwise everyone is just playing whack-a-mole in each separate driver. And for folks that don't have OPTEE, it's a potential waste of power.
ChenYu
Quoted 29 lines
--- drivers/clk/rockchip/clk-rk3588.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/clk/rockchip/clk-rk3588.c +3
-4@@ -1158,11 +1158,11 @@ static struct rockchip_clk_branch rk3588_early_clk_branches[] __initdata = { RK3588_CLKGATE_CON(18), 9, GFLAGS),GATE (CLK_OTPC_NS ,"clk_otpc_ns" ,"xin24m" ,0 ,RK3588_CLKGATE_CON (18 ),10 ,GFLAGS ), -GATE (CLK_OTPC_ARB ,"clk_otpc_arb" ,"xin24m" ,0 , +GATE (CLK_OTPC_ARB ,"clk_otpc_arb" ,"xin24m" ,CLK_IS_CRITICAL ,RK3588_CLKGATE_CON (18 ),11 ,GFLAGS ), -GATE (CLK_OTP_PHY_G ,"clk_otp_phy_g" ,"xin24m" ,0 , +GATE (CLK_OTP_PHY_G ,"clk_otp_phy_g" ,"xin24m" ,CLK_IS_CRITICAL ,RK3588_CLKGATE_CON (18 ),13 ,GFLAGS ), -GATE (CLK_OTPC_AUTO_RD_G ,"clk_otpc_auto_rd_g" ,"xin24m" ,0 , +GATE (CLK_OTPC_AUTO_RD_G ,"clk_otpc_auto_rd_g" ,"xin24m" ,CLK_IS_CRITICAL ,RK3588_CLKGATE_CON (18 ),12 ,GFLAGS ), GATE(PCLK_SARADC, "pclk_saradc", "pclk_top_root", 0, --2.56.0