From 3d69149a7e9e9a899d57f48bee26f98614f88935 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Wed, 27 Oct 2021 18:21:11 +0200 Subject: [PATCH] feat(st-clock): do not refcount on non-secure clocks in bl32 This change removes reference counting support in clock gating implementation for clocks that rely on non-secure only RCC resources. As RCC registers are accessed straight by non-secure world for these clocks, secure world cannot safely store the clock state and even disabling such clock from secure world can jeopardize the non-secure world clock management framework and drivers. As a consequence, for such clocks, stm32_clock_enable() forces the clock ON without any increment of a refcount and stm32_clock_disable() does not disable the clock. Change-Id: I0cc159b36a25dbc8676f05edf2668ae63c640537 Signed-off-by: Etienne Carriere --- drivers/st/clk/stm32mp1_clk.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/st/clk/stm32mp1_clk.c b/drivers/st/clk/stm32mp1_clk.c index 49146115b..6b862dabd 100644 --- a/drivers/st/clk/stm32mp1_clk.c +++ b/drivers/st/clk/stm32mp1_clk.c @@ -636,6 +636,13 @@ static const struct stm32mp1_clk_gate *gate_ref(unsigned int idx) return &stm32mp1_clk_gate[idx]; } +#if defined(IMAGE_BL32) +static bool gate_is_non_secure(const struct stm32mp1_clk_gate *gate) +{ + return gate->secure == N_S; +} +#endif + static const struct stm32mp1_clk_sel *clk_sel_ref(unsigned int idx) { return &stm32mp1_clk_sel[idx]; @@ -1120,6 +1127,14 @@ static void __stm32mp1_clk_enable(unsigned long id, bool with_refcnt) return; } +#if defined(IMAGE_BL32) + if (gate_is_non_secure(gate)) { + /* Enable non-secure clock w/o any refcounting */ + __clk_enable(gate); + return; + } +#endif + stm32mp1_clk_lock(&refcount_lock); if (gate_refcounts[i] == 0U) { @@ -1157,6 +1172,13 @@ static void __stm32mp1_clk_disable(unsigned long id, bool with_refcnt) return; } +#if defined(IMAGE_BL32) + if (gate_is_non_secure(gate)) { + /* Don't disable non-secure clocks */ + return; + } +#endif + stm32mp1_clk_lock(&refcount_lock); if (gate_refcounts[i] == 0U) {