]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
refactor(st-clock): use refcnt instead of secure status
authorYann Gautier <yann.gautier@st.com>
Wed, 19 Jan 2022 12:57:49 +0000 (13:57 +0100)
committerYann Gautier <yann.gautier@st.com>
Thu, 27 Jan 2022 17:06:07 +0000 (18:06 +0100)
Rework the internal functions __stm32mp1_clk_enable/disable to check for
reference count instead of secure status for a clock.
Some functions now unused can be removed.

Change-Id: Ie4359110d7144229f85c961dcd5a019222c3fd25
Signed-off-by: Yann Gautier <yann.gautier@st.com>
drivers/st/clk/stm32mp1_clk.c
include/drivers/st/stm32mp1_clk.h

index 3227f1c872d07a7b3a6d20728af1efca6835d691..3fe21efec9e62c42b64533cbe4889c7701802b2a 100644 (file)
@@ -1062,17 +1062,6 @@ static bool __clk_is_enabled(struct stm32mp1_clk_gate const *gate)
        return mmio_read_32(rcc_base + gate->offset) & BIT(gate->bit);
 }
 
-unsigned int stm32mp1_clk_get_refcount(unsigned long id)
-{
-       int i = stm32mp1_clk_get_gated_id(id);
-
-       if (i < 0) {
-               panic();
-       }
-
-       return gate_refcounts[i];
-}
-
 /* Oscillators and PLLs are not gated at runtime */
 static bool clock_is_always_on(unsigned long id)
 {
@@ -1101,11 +1090,10 @@ static bool clock_is_always_on(unsigned long id)
        }
 }
 
-void __stm32mp1_clk_enable(unsigned long id, bool secure)
+static void __stm32mp1_clk_enable(unsigned long id, bool with_refcnt)
 {
        const struct stm32mp1_clk_gate *gate;
        int i;
-       unsigned int *refcnt;
 
        if (clock_is_always_on(id)) {
                return;
@@ -1118,22 +1106,31 @@ void __stm32mp1_clk_enable(unsigned long id, bool secure)
        }
 
        gate = gate_ref(i);
-       refcnt = &gate_refcounts[i];
+
+       if (!with_refcnt) {
+               __clk_enable(gate);
+               return;
+       }
 
        stm32mp1_clk_lock(&refcount_lock);
 
-       if (stm32mp_incr_shrefcnt(refcnt, secure) != 0) {
+       if (gate_refcounts[i] == 0U) {
                __clk_enable(gate);
        }
 
+       gate_refcounts[i]++;
+       if (gate_refcounts[i] == UINT_MAX) {
+               ERROR("Clock %lu refcount reached max value\n", id);
+               panic();
+       }
+
        stm32mp1_clk_unlock(&refcount_lock);
 }
 
-void __stm32mp1_clk_disable(unsigned long id, bool secure)
+static void __stm32mp1_clk_disable(unsigned long id, bool with_refcnt)
 {
        const struct stm32mp1_clk_gate *gate;
        int i;
-       unsigned int *refcnt;
 
        if (clock_is_always_on(id)) {
                return;
@@ -1146,11 +1143,21 @@ void __stm32mp1_clk_disable(unsigned long id, bool secure)
        }
 
        gate = gate_ref(i);
-       refcnt = &gate_refcounts[i];
+
+       if (!with_refcnt) {
+               __clk_disable(gate);
+               return;
+       }
 
        stm32mp1_clk_lock(&refcount_lock);
 
-       if (stm32mp_decr_shrefcnt(refcnt, secure) != 0) {
+       if (gate_refcounts[i] == 0U) {
+               ERROR("Clock %lu refcount reached 0\n", id);
+               panic();
+       }
+       gate_refcounts[i]--;
+
+       if (gate_refcounts[i] == 0U) {
                __clk_disable(gate);
        }
 
index c46892b78e135d05bf9a81535cc084577283b44d..59c7c0bd6dbf759dfce0c07b02453efa2d77f438 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019, STMicroelectronics - All Rights Reserved
+ * Copyright (c) 2018-2022, STMicroelectronics - All Rights Reserved
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -28,31 +28,6 @@ int stm32mp1_clk_init(void);
 bool stm32mp1_rcc_is_secure(void);
 bool stm32mp1_rcc_is_mckprot(void);
 
-void __stm32mp1_clk_enable(unsigned long id, bool caller_is_secure);
-void __stm32mp1_clk_disable(unsigned long id, bool caller_is_secure);
-
-static inline void stm32mp1_clk_enable_non_secure(unsigned long id)
-{
-       __stm32mp1_clk_enable(id, false);
-}
-
-static inline void stm32mp1_clk_enable_secure(unsigned long id)
-{
-       __stm32mp1_clk_enable(id, true);
-}
-
-static inline void stm32mp1_clk_disable_non_secure(unsigned long id)
-{
-       __stm32mp1_clk_disable(id, false);
-}
-
-static inline void stm32mp1_clk_disable_secure(unsigned long id)
-{
-       __stm32mp1_clk_disable(id, true);
-}
-
-unsigned int stm32mp1_clk_get_refcount(unsigned long id);
-
 /* SMP protection on RCC registers access */
 void stm32mp1_clk_rcc_regs_lock(void);
 void stm32mp1_clk_rcc_regs_unlock(void);