Modify MxL's CGU clk driver to make it secure boot compatible
v4 cover Modify MxL's CGU clk driver to make it secure boot compatible
MxL's CGU driver was found to be lacking below required features. Add these required lacking features:
1. Since it is a core driver, it has to conform to secure boot & secure access architecture. In order for the register accesses to be secure access compliant, it needs regmap support as per our security architecture. Hence, replace direct read/writel with regmap based IO. Also remove redundant spinlocks from the driver as they are no longer necessary because regmap uses its own lock.
2. In MxL's LGM SoC, gate clocks can be controlled either from CGU clk driver i.e. this driver or directly from power management driver/daemon. It is dependent on the power policy/profile requirements of the end product.
To support such use cases, provide option to override gate clks enable/disable by adding a flag GATE_CLK_HW which controls if these gate clks are controlled by HW i.e. this driver or overridden in order to allow it to be controlled by power profiles instead.
3. Fix a bug related to missing flags in one 'dcl' clk entry.
This patch series is based on below git tree (linux-v6.0-rc1):git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git
v4:
- Address review concern (Stephen Boyd)
- Change the design of how GATE_CLKs are overridden. Make the clk provider return NULL when that clk needs to be overridden.
v3:
- Address review concern (Stephen Boyd)
- Change the method of fixing invalid width for reg read/write.
v2:
- Add option to override gate clks
- Fix a clk entry by adding relevant flags
v1:
- Initial version
Rahul Tanwar (4):
clk: mxl: Switch from direct readl/writel based IO to regmap based IO
clk: mxl: Remove redundant spinlocks
clk: mxl: Add option to override gate clks
clk: mxl: Fix a clk entry by adding relevant flags
drivers/clk/x86/Kconfig | 5 +- drivers/clk/x86/clk-cgu-pll.c | 23 ++------ drivers/clk/x86/clk-cgu.c | 105 ++++++++++------------------------ drivers/clk/x86/clk-cgu.h | 46 +++++++-------- drivers/clk/x86/clk-lgm.c | 18 +++--- 5 files changed, 72 insertions(+), 125 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/4 clk: mxl: Switch from direct readl/writel based IO to regmap based IO
Earlier version of driver used direct io remapped register read writes using readl/writel. But we need secure boot access which is only possible when registers are read & written using regmap. This is because the security bus/hook is written & coupled only with regmap layer.
Switch the driver from direct readl/writel based register accesses to regmap based register accesses.
Additionally, update the license headers to latest status.
--- drivers/clk/x86/Kconfig | 5 +++-- drivers/clk/x86/clk-cgu-pll.c | 10 +++++---- drivers/clk/x86/clk-cgu.c | 5 +++-- drivers/clk/x86/clk-cgu.h | 38 +++++++++++++++++++---------------- drivers/clk/x86/clk-lgm.c | 13 ++++++++---- 5 files changed, 42 insertions(+), 29 deletions(-)
drivers/clk/x86/Kconfig +3 -2
@@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only config CLK_LGM_CGU depends on OF && HAS_IOMEM && (X86 || COMPILE_TEST) + select MFD_SYSCON select OF_EARLY_FLATTREE bool "Clock driver for Lightning Mountain(LGM) platform" help - Clock Generation Unit(CGU) driver for Intel Lightning Mountain(LGM) - network processor SoC. + Clock Generation Unit(CGU) driver for MaxLinear's x86 based + Lightning Mountain(LGM) network processor SoC.
drivers/clk/x86/clk-cgu-pll.c +6 -4
@@ -1,8 +1,9 @@// SPDX-License-Identifier: GPL-2.0 /* +* Copyright (C) 2020-2022 MaxLinear, Inc. * Copyright (C) 2020 Intel Corporation. -* Zhu YiXin <[email protected]> -* Rahul Tanwar <[email protected]> +* Zhu Yixin <[email protected]> +* Rahul Tanwar <[email protected]> */ #include <linux/clk-provider.h>
@@ -76,8 +77,9 @@ static int lgm_pll_enable(struct clk_hw *hw)spin_lock_irqsave (&pll->lock, flags);lgm_set_clk_val (pll->membase, pll->reg,0 ,1 ,1 ); - ret =readl_poll_timeout_atomic (pll->membase + pll->reg, - val, (val &0x1 ),1 ,100 ); + ret =regmap_read_poll_timeout_atomic (pll->membase, pll->reg, + val, (val &0x1 ),1 ,100 ); +spin_unlock_irqrestore (&pll->lock, flags);return ret;
drivers/clk/x86/clk-cgu.c +3 -2
@@ -1,8 +1,9 @@// SPDX-License-Identifier: GPL-2.0 /* +* Copyright (C) 2020-2022 MaxLinear, Inc. * Copyright (C) 2020 Intel Corporation. -* Zhu YiXin <[email protected]> -* Rahul Tanwar <[email protected]> +* Zhu Yixin <[email protected]> +* Rahul Tanwar <[email protected]> */ #include <linux/clk-provider.h> #include <linux/device.h>
drivers/clk/x86/clk-cgu.h +21 -17
@@ -1,18 +1,19 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* Copyright(c) 2020 Intel Corporation. -* Zhu YiXin <[email protected]> -* Rahul Tanwar <[email protected]> +* Copyright (C) 2020-2022 MaxLinear, Inc. +* Copyright (C) 2020 Intel Corporation. +* Zhu Yixin <[email protected]> +* Rahul Tanwar <[email protected]> */ #ifndef __CLK_CGU_H #define __CLK_CGU_H -#include <linux/io.h> +#include <linux/regmap.h> struct lgm_clk_mux { struct clk_hw hw; - void __iomem *membase; + struct regmap *membase; unsigned int reg; u8 shift; u8 width;
@@ -22,7 +23,7 @@ struct lgm_clk_mux {struct lgm_clk_divider {struct clk_hw hw; -void __iomem *membase; +struct regmap *membase;unsigned int reg;u8 shift;u8 width;
@@ -35,7 +36,7 @@ struct lgm_clk_divider {struct lgm_clk_ddiv {struct clk_hw hw; -void __iomem *membase; +struct regmap *membase;unsigned int reg;u8 shift0;u8 width0;
@@ -53,7 +54,7 @@ struct lgm_clk_ddiv {struct lgm_clk_gate {struct clk_hw hw; -void __iomem *membase; +struct regmap *membase;unsigned int reg;u8 shift;unsigned long flags;
@@ -77,7 +78,7 @@ enum lgm_clk_type {* @clk_data: array of hw clocks and clk number. */ struct lgm_clk_provider { -void __iomem *membase; +struct regmap *membase;struct device_node *np;struct device *dev;struct clk_hw_onecell_data clk_data;
@@ -92,7 +93,7 @@ enum pll_type {struct lgm_clk_pll {struct clk_hw hw; -void __iomem *membase; +struct regmap *membase;unsigned int reg;unsigned long flags;enum pll_type type;
@@ -300,29 +301,32 @@ struct lgm_clk_branch { .div = _d, \ } -static inline void lgm_set_clk_val (void __iomem *membase,u32 reg, +static inline void lgm_set_clk_val (struct regmap *membase,u32 reg,u8 shift,u8 width,u32 set_val) {u32 mask = (GENMASK (width -1 ,0 ) << shift); -u32 regval; - regval =readl (membase + reg); - regval = (regval & ~mask) | ((set_val << shift) & mask); -writel (regval, membase + reg); +regmap_update_bits (membase, reg, mask, set_val << shift); } -static inline u32 lgm_get_clk_val (void __iomem *membase,u32 reg, +static inline u32 lgm_get_clk_val (struct regmap *membase,u32 reg,u8 shift,u8 width) {u32 mask = (GENMASK (width -1 ,0 ) << shift);u32 val; - val =readl (membase + reg); +if (regmap_read (membase, reg, &val)) { +WARN_ONCE (1 ,"Failed to read clk reg: 0x%x\n" , reg); +return 0 ; + } + val = (val & mask) >> shift;return val; } + +int lgm_clk_register_branches (struct lgm_clk_provider *ctx,const struct lgm_clk_branch *list,unsigned int nr_clk);
drivers/clk/x86/clk-lgm.c +9 -4
@@ -1,10 +1,12 @@// SPDX-License-Identifier: GPL-2.0 /* +* Copyright (C) 2020-2022 MaxLinear, Inc. * Copyright (C) 2020 Intel Corporation. -* Zhu YiXin <[email protected]> -* Rahul Tanwar <[email protected]> +* Zhu Yixin <[email protected]> +* Rahul Tanwar <[email protected]> */ #include <linux/clk-provider.h> +#include <linux/mfd/syscon.h> #include <linux/of.h> #include <linux/platform_device.h> #include <dt-bindings/clock/intel,lgm-clk.h>
@@ -433,9 +435,12 @@ static int lgm_cgu_probe(struct platform_device *pdev) ctx->clk_data.num =CLK_NR_CLKS ; - ctx->membase =devm_platform_ioremap_resource (pdev,0 ); -if (IS_ERR (ctx->membase)) + ctx->membase =syscon_node_to_regmap (np); +if (IS_ERR_OR_NULL (ctx->membase)) { +dev_err (dev,"Failed to get clk CGU iomem\n" );return PTR_ERR (ctx->membase); + } + ctx->np = np; ctx->dev = dev;
Signature · 1 line
2.17.1
Re: [PATCH v4 1/4] clk: mxl: Switch from direct readl/writel based IO to regmap based IO
Quoting Rahul Tanwar (2022-10-12 23:48:30)
Quoted 6 lines
Earlier version of driver used direct io remapped register read writes using readl/writel. But we need secure boot access which is only possible when registers are read & written using regmap. This is because the security bus/hook is written & coupled only with regmap layer.
Quoted 8 lines
Switch the driver from direct readl/writel based register accesses to regmap based register accesses.
Additionally, update the license headers to latest status.
Reviewed-by Yi xin Zhu <[email protected]>Signed-off-by Rahul Tanwar <[email protected]>---
Applied to clk-next
PATCH v4 2/4 clk: mxl: Remove redundant spinlocks
In reply to Rahul TanwarPatch 1/4 of this patch series switches from direct readl/writel based register access to regmap based register access. Instead of using direct readl/writel, regmap API's are used to read, write & read-modify-write clk registers. Regmap API's already use their own spinlocks to serialize the register accesses across multiple cores in which case additional driver spinlocks becomes redundant.
Hence, remove redundant spinlocks from driver in this patch 2/4.
--- drivers/clk/x86/clk-cgu-pll.c | 13 ------ drivers/clk/x86/clk-cgu.c | 80 ++++------------------------------- drivers/clk/x86/clk-cgu.h | 6 --- drivers/clk/x86/clk-lgm.c | 1 - 4 files changed, 9 insertions(+), 91 deletions(-)
drivers/clk/x86/clk-cgu-pll.c +0 -13
@@ -41,13 +41,10 @@ static unsigned long lgm_pll_recalc_rate(struct clk_hw *hw, unsigned long prate) {struct lgm_clk_pll *pll =to_lgm_clk_pll (hw);unsigned int div, mult, frac; -unsigned long flags; -spin_lock_irqsave (&pll->lock, flags); mult =lgm_get_clk_val (pll->membase,PLL_REF_DIV (pll->reg),0 ,12 ); div =lgm_get_clk_val (pll->membase,PLL_REF_DIV (pll->reg),18 ,6 ); frac =lgm_get_clk_val (pll->membase, pll->reg,2 ,24 ); -spin_unlock_irqrestore (&pll->lock, flags);if (pll->type ==TYPE_LJPLL ) div *=4 ;
@@ -58,12 +55,9 @@ static unsigned long lgm_pll_recalc_rate(struct clk_hw *hw, unsigned long prate)static int lgm_pll_is_enabled (struct clk_hw *hw) {struct lgm_clk_pll *pll =to_lgm_clk_pll (hw); -unsigned long flags;unsigned int ret; -spin_lock_irqsave (&pll->lock, flags); ret =lgm_get_clk_val (pll->membase, pll->reg,0 ,1 ); -spin_unlock_irqrestore (&pll->lock, flags);return ret; }
@@ -71,16 +65,13 @@ static int lgm_pll_is_enabled(struct clk_hw *hw)static int lgm_pll_enable (struct clk_hw *hw) {struct lgm_clk_pll *pll =to_lgm_clk_pll (hw); -unsigned long flags;u32 val;int ret; -spin_lock_irqsave (&pll->lock, flags);lgm_set_clk_val (pll->membase, pll->reg,0 ,1 ,1 ); ret =regmap_read_poll_timeout_atomic (pll->membase, pll->reg, val, (val &0x1 ),1 ,100 ); -spin_unlock_irqrestore (&pll->lock, flags);return ret; }
@@ -88,11 +79,8 @@ static int lgm_pll_enable(struct clk_hw *hw)static void lgm_pll_disable (struct clk_hw *hw) {struct lgm_clk_pll *pll =to_lgm_clk_pll (hw); -unsigned long flags; -spin_lock_irqsave (&pll->lock, flags);lgm_set_clk_val (pll->membase, pll->reg,0 ,1 ,0 ); -spin_unlock_irqrestore (&pll->lock, flags); }static const struct clk_ops lgm_pll_ops = {
@@ -123,7 +111,6 @@ lgm_clk_register_pll(struct lgm_clk_provider *ctx,return ERR_PTR (-ENOMEM ); pll->membase = ctx->membase; - pll->lock = ctx->lock; pll->reg = list->reg; pll->flags = list->flags; pll->type = list->type;
drivers/clk/x86/clk-cgu.c +9 -71
321 lines not on this page · raw message
drivers/clk/x86/clk-cgu.h +0 -6
@@ -18,7 +18,6 @@ struct lgm_clk_mux {u8 shift;u8 width;unsigned long flags; -spinlock_t lock; };struct lgm_clk_divider {
@@ -31,7 +30,6 @@ struct lgm_clk_divider {u8 width_gate;unsigned long flags;const struct clk_div_table *table; -spinlock_t lock; };struct lgm_clk_ddiv {
@@ -49,7 +47,6 @@ struct lgm_clk_ddiv {unsigned int mult;unsigned int div;unsigned long flags; -spinlock_t lock; };struct lgm_clk_gate {
@@ -58,7 +55,6 @@ struct lgm_clk_gate {unsigned int reg;u8 shift;unsigned long flags; -spinlock_t lock; };enum lgm_clk_type {
@@ -82,7 +78,6 @@ struct lgm_clk_provider {struct device_node *np;struct device *dev;struct clk_hw_onecell_data clk_data; -spinlock_t lock; };enum pll_type {
@@ -97,7 +92,6 @@ struct lgm_clk_pll {unsigned int reg;unsigned long flags;enum pll_type type; -spinlock_t lock; };/**
drivers/clk/x86/clk-lgm.c +0 -1
@@ -444,7 +444,6 @@ static int lgm_cgu_probe(struct platform_device *pdev) ctx->np = np; ctx->dev = dev; -spin_lock_init (&ctx->lock); ret =lgm_clk_register_plls (ctx, lgm_pll_clks,ARRAY_SIZE (lgm_pll_clks));
Signature · 1 line
2.17.1
Re: [PATCH v4 2/4] clk: mxl: Remove redundant spinlocks
Quoting Rahul Tanwar (2022-10-12 23:48:31)
Quoted 7 lines
Patch 1/4 of this patch series switches from direct readl/writel based register access to regmap based register access. Instead of using direct readl/writel, regmap API's are used to read, write & read-modify-write clk registers. Regmap API's already use their own spinlocks to serialize the register accesses across multiple cores in which case additional driver spinlocks becomes redundant.
Quoted 5 lines
Hence, remove redundant spinlocks from driver in this patch 2/4.
Reviewed-by Yi xin Zhu <[email protected]>Signed-off-by Rahul Tanwar <[email protected]>---
Applied to clk-next
PATCH v4 3/4 clk: mxl: Add option to override gate clks
In reply to Rahul TanwarIn MxL's LGM SoC, gate clocks can be controlled either from CGU clk driver i.e. this driver or directly from power management driver/daemon. It is dependent on the power policy/profile requirements of the end product.
To support such use cases, provide option to override gate clks enable/disable by adding a flag GATE_CLK_HW which controls if these gate clks are controlled by HW i.e. this driver or overridden in order to allow it to be controlled by power profiles instead.
--- drivers/clk/x86/clk-cgu.c | 15 ++++++++++++++- drivers/clk/x86/clk-cgu.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/clk/x86/clk-cgu.c +14 -1
@@ -354,8 +354,21 @@ int lgm_clk_register_branches(struct lgm_clk_provider *ctx, hw =lgm_clk_register_fixed_factor (ctx, list);break ;case CLK_TYPE_GATE : - hw =lgm_clk_register_gate (ctx, list); +if (list->gate_flags &GATE_CLK_HW ) + hw =lgm_clk_register_gate (ctx, list); +else +/* +* GATE_CLKs can be controlled either from +* CGU clk driver i.e. this driver or directly +* from power management driver/daemon. It is +* dependent on the power policy/profile requirements +* of the end product. To override control of gate +* clks from this driver, provide NULL for this index +* of gate clk provider. +*/ + hw =NULL ;break ; +default :dev_err (ctx->dev,"invalid clk type\n" );return -EINVAL ;
drivers/clk/x86/clk-cgu.h +1 -0
@@ -197,6 +197,7 @@ struct lgm_clk_branch {/* clock flags definition */ #define CLOCK_FLAG_VAL_INIT BIT(16)#define MUX_CLK_SW BIT(17) +#define GATE_CLK_HW BIT(18)#define LGM_MUX (_id, _name, _pdata, _f, _reg, \ _shift, _width, _cf, _v) \
Signature · 1 line
2.17.1
Re: [PATCH v4 3/4] clk: mxl: Add option to override gate clks
Quoting Rahul Tanwar (2022-10-12 23:48:32)
Quoted 4 lines
In MxL's LGM SoC, gate clocks can be controlled either from CGU clk driver i.e. this driver or directly from power management driver/daemon. It is dependent on the power policy/profile requirements of the end product.
Quoted 8 lines
To support such use cases, provide option to override gate clks enable/disable by adding a flag
GATE_CLK_HWwhich controls if these gate clks are controlled by HW i.e. this driver or overridden in order to allow it to be controlled by power profiles instead.Reviewed-by Yi xin Zhu <[email protected]>Signed-off-by Rahul Tanwar <[email protected]>---
Applied to clk-next
PATCH v4 4/4 clk: mxl: Fix a clk entry by adding relevant flags
In reply to Rahul TanwarOne of the clock entry "dcl" clk has some HW limitations. One is that its rate can only by changed by changing its parent clk's rate & two is that HW does not support enable/disable for this clk.
Handle above two limitations by adding relevant flags. Add standard flag CLK_SET_RATE_PARENT to handle rate change and add driver internal flag DIV_CLK_NO_MASK to handle enable/disable.
--- drivers/clk/x86/clk-cgu.c | 5 +++-- drivers/clk/x86/clk-cgu.h | 1 + drivers/clk/x86/clk-lgm.c | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-)
drivers/clk/x86/clk-cgu.c +3 -2
@@ -164,8 +164,9 @@ static int lgm_clk_divider_enable_disable(struct clk_hw *hw, int enable) {struct lgm_clk_divider *div =to_lgm_clk_divider (hw); -lgm_set_clk_val (div->membase, div->reg, div->shift_gate, - div->width_gate, enable); +if (div->flags !=DIV_CLK_NO_MASK ) +lgm_set_clk_val (div->membase, div->reg, div->shift_gate, + div->width_gate, enable);return 0 ; }
drivers/clk/x86/clk-cgu.h +1 -0
@@ -198,6 +198,7 @@ struct lgm_clk_branch {#define CLOCK_FLAG_VAL_INIT BIT(16)#define MUX_CLK_SW BIT(17)#define GATE_CLK_HW BIT(18) +#define DIV_CLK_NO_MASK BIT(19)#define LGM_MUX (_id, _name, _pdata, _f, _reg, \ _shift, _width, _cf, _v) \
drivers/clk/x86/clk-lgm.c +2 -2
@@ -255,8 +255,8 @@ static const struct lgm_clk_branch lgm_branch_clks[] = {LGM_FIXED (LGM_CLK_SLIC ,"slic" ,NULL ,0 ,CGU_IF_CLK1 ,8 ,2 ,CLOCK_FLAG_VAL_INIT ,8192000 ,2 ),LGM_FIXED (LGM_CLK_DOCSIS ,"v_docsis" ,NULL ,0 ,0 ,0 ,0 ,0 ,16000000 ,0 ), -LGM_DIV (LGM_CLK_DCL ,"dcl" ,"v_ifclk" ,0 ,CGU_PCMCR , -25 ,3 ,0 ,0 ,0 ,0 , dcl_div), +LGM_DIV (LGM_CLK_DCL ,"dcl" ,"v_ifclk" ,CLK_SET_RATE_PARENT ,CGU_PCMCR , +25 ,3 ,0 ,0 ,DIV_CLK_NO_MASK ,0 , dcl_div),LGM_MUX (LGM_CLK_PCM ,"pcm" , pcm_p,0 ,CGU_C55_PCMCR ,0 ,1 ,CLK_MUX_ROUND_CLOSEST ,0 ), LGM_FIXED_FACTOR(LGM_CLK_DDR_PHY, "ddr_phy", "ddr",
Signature · 1 line
2.17.1
Re: [PATCH v4 4/4] clk: mxl: Fix a clk entry by adding relevant flags
Quoting Rahul Tanwar (2022-10-12 23:48:33)
Quoted 4 lines
One of the clock entry "dcl" clk has some HW limitations. One is that its rate can only by changed by changing its parent clk's rate & two is that HW does not support enable/disable for this clk.
Quoted 8 lines
Handle above two limitations by adding relevant flags. Add standard flag
CLK_SET_RATE_PARENTto handle rate change and add driver internal flagDIV_CLK_NO_MASKto handle enable/disable.Fixes d058fd9e8984c ("clk: intel: Add CGU clock driver for a new SoC")Reviewed-by Yi xin Zhu <[email protected]>Signed-off-by Rahul Tanwar <[email protected]>---
Applied to clk-next