From 3c692400f8418651669b4895a628aff4c7ca3d4a Mon Sep 17 00:00:00 2001 From: Alexandre Ghiti Date: Wed, 8 Nov 2023 08:59:29 +0100 Subject: riscv: Don't use PGD entries for the linear mapping Propagating changes at this level is cumbersome as we need to go through all the page tables when that happens (either when changing the permissions or when splitting the mapping). Note that this prevents the use of 4MB mapping for sv32 and 1GB mapping for sv39 in the linear mapping. Signed-off-by: Alexandre Ghiti Link: https://lore.kernel.org/r/20231108075930.7157-2-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt --- arch/riscv/mm/init.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index b50faa232b5e..1f4d50a235de 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -667,16 +667,16 @@ void __init create_pgd_mapping(pgd_t *pgdp, static uintptr_t __init best_map_size(phys_addr_t pa, uintptr_t va, phys_addr_t size) { - if (!(pa & (PGDIR_SIZE - 1)) && !(va & (PGDIR_SIZE - 1)) && size >= PGDIR_SIZE) - return PGDIR_SIZE; - - if (!(pa & (P4D_SIZE - 1)) && !(va & (P4D_SIZE - 1)) && size >= P4D_SIZE) + if (pgtable_l5_enabled && + !(pa & (P4D_SIZE - 1)) && !(va & (P4D_SIZE - 1)) && size >= P4D_SIZE) return P4D_SIZE; - if (!(pa & (PUD_SIZE - 1)) && !(va & (PUD_SIZE - 1)) && size >= PUD_SIZE) + if (pgtable_l4_enabled && + !(pa & (PUD_SIZE - 1)) && !(va & (PUD_SIZE - 1)) && size >= PUD_SIZE) return PUD_SIZE; - if (!(pa & (PMD_SIZE - 1)) && !(va & (PMD_SIZE - 1)) && size >= PMD_SIZE) + if (IS_ENABLED(CONFIG_64BIT) && + !(pa & (PMD_SIZE - 1)) && !(va & (PMD_SIZE - 1)) && size >= PMD_SIZE) return PMD_SIZE; return PAGE_SIZE; -- cgit v1.2.3 From 9a1b3afddb72d2afafcf60a430a767c77ed82f02 Mon Sep 17 00:00:00 2001 From: Hal Feng Date: Tue, 23 Apr 2024 17:18:53 +0800 Subject: clk: starfive: jh7110: Don't save and restore isp / vout clock registers in sleep pm Add reg_flags to identify clocks. Don't save and restore isp / vout clocks in sleep pm. Signed-off-by: Hal Feng --- drivers/clk/starfive/clk-starfive-jh7110-aon.c | 3 ++- drivers/clk/starfive/clk-starfive-jh7110-isp.c | 3 ++- drivers/clk/starfive/clk-starfive-jh7110-stg.c | 3 ++- drivers/clk/starfive/clk-starfive-jh7110-sys.c | 3 ++- drivers/clk/starfive/clk-starfive-jh7110-vout.c | 3 ++- drivers/clk/starfive/clk-starfive-jh71x0.c | 15 +++++++++++++++ drivers/clk/starfive/clk-starfive-jh71x0.h | 9 +++++++++ 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/clk/starfive/clk-starfive-jh7110-aon.c b/drivers/clk/starfive/clk-starfive-jh7110-aon.c index 62954eb7b50a..ad898b9eeb9c 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-aon.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-aon.c @@ -121,6 +121,7 @@ static int jh7110_aoncrg_probe(struct platform_device *pdev) clk->hw.init = &init; clk->idx = idx; clk->max_div = max & JH71X0_CLK_DIV_MASK; + clk->reg_flags = JH7110_CLK_AON_FLAG; ret = devm_clk_hw_register(&pdev->dev, &clk->hw); if (ret) @@ -131,7 +132,7 @@ static int jh7110_aoncrg_probe(struct platform_device *pdev) if (ret) return ret; - return jh7110_reset_controller_register(priv, "rst-aon", 1); + return jh7110_reset_controller_register(priv, "rst-aon", JH7110_CLK_AON_FLAG); } static const struct of_device_id jh7110_aoncrg_match[] = { diff --git a/drivers/clk/starfive/clk-starfive-jh7110-isp.c b/drivers/clk/starfive/clk-starfive-jh7110-isp.c index ce034ed28532..046a975aeac3 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-isp.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-isp.c @@ -180,6 +180,7 @@ static int jh7110_ispcrg_probe(struct platform_device *pdev) clk->hw.init = &init; clk->idx = idx; clk->max_div = max & JH71X0_CLK_DIV_MASK; + clk->reg_flags = JH7110_CLK_ISP_FLAG; ret = devm_clk_hw_register(&pdev->dev, &clk->hw); if (ret) @@ -190,7 +191,7 @@ static int jh7110_ispcrg_probe(struct platform_device *pdev) if (ret) goto err_exit; - ret = jh7110_reset_controller_register(priv, "rst-isp", 3); + ret = jh7110_reset_controller_register(priv, "rst-isp", JH7110_CLK_ISP_FLAG); if (ret) goto err_exit; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-stg.c b/drivers/clk/starfive/clk-starfive-jh7110-stg.c index dafcb7190592..4b8918d8124a 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-stg.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-stg.c @@ -139,6 +139,7 @@ static int jh7110_stgcrg_probe(struct platform_device *pdev) clk->hw.init = &init; clk->idx = idx; clk->max_div = max & JH71X0_CLK_DIV_MASK; + clk->reg_flags = JH7110_CLK_STG_FLAG; ret = devm_clk_hw_register(&pdev->dev, &clk->hw); if (ret) @@ -149,7 +150,7 @@ static int jh7110_stgcrg_probe(struct platform_device *pdev) if (ret) return ret; - return jh7110_reset_controller_register(priv, "rst-stg", 2); + return jh7110_reset_controller_register(priv, "rst-stg", JH7110_CLK_STG_FLAG); } static const struct of_device_id jh7110_stgcrg_match[] = { diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c index da01a750efcd..a8a2d0b5a226 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c @@ -506,6 +506,7 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev) clk->hw.init = &init; clk->idx = idx; clk->max_div = max & JH71X0_CLK_DIV_MASK; + clk->reg_flags = JH7110_CLK_SYS_FLAG; ret = devm_clk_hw_register(&pdev->dev, &clk->hw); if (ret) @@ -516,7 +517,7 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev) if (ret) return ret; - ret = jh7110_reset_controller_register(priv, "rst-sys", 0); + ret = jh7110_reset_controller_register(priv, "rst-sys", JH7110_CLK_SYS_FLAG); if (ret) return ret; diff --git a/drivers/clk/starfive/clk-starfive-jh7110-vout.c b/drivers/clk/starfive/clk-starfive-jh7110-vout.c index 10cc1ec43925..dcba067c3ba6 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-vout.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-vout.c @@ -187,6 +187,7 @@ static int jh7110_voutcrg_probe(struct platform_device *pdev) clk->hw.init = &init; clk->idx = idx; clk->max_div = max & JH71X0_CLK_DIV_MASK; + clk->reg_flags = JH7110_CLK_VOUT_FLAG; ret = devm_clk_hw_register(&pdev->dev, &clk->hw); if (ret) @@ -197,7 +198,7 @@ static int jh7110_voutcrg_probe(struct platform_device *pdev) if (ret) goto err_exit; - ret = jh7110_reset_controller_register(priv, "rst-vo", 4); + ret = jh7110_reset_controller_register(priv, "rst-vo", JH7110_CLK_VOUT_FLAG); if (ret) goto err_exit; diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.c b/drivers/clk/starfive/clk-starfive-jh71x0.c index 0a023cf226a4..8fe1f06c7e7f 100644 --- a/drivers/clk/starfive/clk-starfive-jh71x0.c +++ b/drivers/clk/starfive/clk-starfive-jh71x0.c @@ -245,6 +245,9 @@ static int jh7110_clk_save_context(struct clk_hw *hw) if (!clk || !priv) return 0; + if (clk->reg_flags == JH7110_CLK_ISP_FLAG || clk->reg_flags == JH7110_CLK_VOUT_FLAG) + return 0; + spin_lock(&priv->rmw_lock); clk->saved_reg = jh71x0_clk_reg_get(clk); spin_unlock(&priv->rmw_lock); @@ -259,6 +262,9 @@ static void jh7110_clk_gate_restore_context(struct clk_hw *hw) if (!clk) return; + if (clk->reg_flags == JH7110_CLK_ISP_FLAG || clk->reg_flags == JH7110_CLK_VOUT_FLAG) + return; + jh71x0_clk_reg_rmw(clk, JH71X0_CLK_ENABLE, clk->saved_reg); } @@ -269,6 +275,9 @@ static void jh7110_clk_div_restore_context(struct clk_hw *hw) if (!clk) return; + if (clk->reg_flags == JH7110_CLK_ISP_FLAG || clk->reg_flags == JH7110_CLK_VOUT_FLAG) + return; + jh71x0_clk_reg_rmw(clk, JH71X0_CLK_DIV_MASK, clk->saved_reg); } @@ -279,6 +288,9 @@ static void jh7110_clk_mux_restore_context(struct clk_hw *hw) if (!clk) return; + if (clk->reg_flags == JH7110_CLK_ISP_FLAG || clk->reg_flags == JH7110_CLK_VOUT_FLAG) + return; + jh71x0_clk_reg_rmw(clk, JH71X0_CLK_MUX_MASK, clk->saved_reg); } @@ -289,6 +301,9 @@ static void jh7110_clk_inv_restore_context(struct clk_hw *hw) if (!clk) return; + if (clk->reg_flags == JH7110_CLK_ISP_FLAG || clk->reg_flags == JH7110_CLK_VOUT_FLAG) + return; + jh71x0_clk_reg_rmw(clk, JH71X0_CLK_INVERT, clk->saved_reg); } diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.h b/drivers/clk/starfive/clk-starfive-jh71x0.h index 320fefeec8ea..ec22bd509691 100644 --- a/drivers/clk/starfive/clk-starfive-jh71x0.h +++ b/drivers/clk/starfive/clk-starfive-jh71x0.h @@ -7,6 +7,14 @@ #include #include +enum JH7110_CLOCK_FLAGS { + JH7110_CLK_SYS_FLAG = 0, + JH7110_CLK_AON_FLAG, + JH7110_CLK_STG_FLAG, + JH7110_CLK_ISP_FLAG, + JH7110_CLK_VOUT_FLAG, +}; + /* register fields */ #define JH71X0_CLK_ENABLE BIT(31) #define JH71X0_CLK_INVERT BIT(30) @@ -107,6 +115,7 @@ struct jh71x0_clk { struct clk_hw hw; unsigned int idx; unsigned int max_div; + unsigned int reg_flags; u32 saved_reg; }; -- cgit v1.2.3 From df5359eb22ba0ce75147f916d4b409199abbafd0 Mon Sep 17 00:00:00 2001 From: Hal Feng Date: Tue, 23 Apr 2024 18:08:06 +0800 Subject: clk: starfive: jh7110-isp: Add sleep pm ops and enable runtime autosuspend Add sleep pm ops and enable runtime autosuspend for isp clock driver. Signed-off-by: Hal Feng --- drivers/clk/starfive/clk-starfive-jh7110-isp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/clk/starfive/clk-starfive-jh7110-isp.c b/drivers/clk/starfive/clk-starfive-jh7110-isp.c index 046a975aeac3..5fe8260b4de2 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-isp.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-isp.c @@ -86,6 +86,18 @@ static struct clk_hw *jh7110_ispclk_get(struct of_phandle_args *clkspec, void *d return ERR_PTR(-EINVAL); } +#ifdef CONFIG_PM_SLEEP +static int jh7110_ispcrg_sleep_suspend(struct device *dev) +{ + return pm_runtime_force_suspend(dev); +} + +static int jh7110_ispcrg_sleep_resume(struct device *dev) +{ + return pm_runtime_force_resume(dev); +} +#endif + #ifdef CONFIG_PM static int jh7110_ispcrg_suspend(struct device *dev) { @@ -105,6 +117,7 @@ static int jh7110_ispcrg_resume(struct device *dev) static const struct dev_pm_ops jh7110_ispcrg_pm_ops = { RUNTIME_PM_OPS(jh7110_ispcrg_suspend, jh7110_ispcrg_resume, NULL) + LATE_SYSTEM_SLEEP_PM_OPS(jh7110_ispcrg_sleep_suspend, jh7110_ispcrg_sleep_resume) }; #endif @@ -138,6 +151,8 @@ static int jh7110_ispcrg_probe(struct platform_device *pdev) return dev_err_probe(priv->dev, ret, "failed to get main clocks\n"); dev_set_drvdata(priv->dev, top); + pm_runtime_use_autosuspend(priv->dev); + pm_runtime_set_autosuspend_delay(priv->dev, 50); /* enable power domain and clocks */ pm_runtime_enable(priv->dev); ret = pm_runtime_get_sync(priv->dev); @@ -195,6 +210,8 @@ static int jh7110_ispcrg_probe(struct platform_device *pdev) if (ret) goto err_exit; + pm_runtime_put_sync(&pdev->dev); + return 0; err_exit: -- cgit v1.2.3 From aa98aa446a728628cf6d61c5b0958a5972d74d99 Mon Sep 17 00:00:00 2001 From: Hal Feng Date: Tue, 23 Apr 2024 18:09:53 +0800 Subject: clk: starfive: jh7110-vout: Add sleep pm ops and enable runtime autosuspend Add sleep pm ops and enable runtime autosuspend for vout clock driver. Signed-off-by: Hal Feng --- drivers/clk/starfive/clk-starfive-jh7110-vout.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/clk/starfive/clk-starfive-jh7110-vout.c b/drivers/clk/starfive/clk-starfive-jh7110-vout.c index dcba067c3ba6..80f9be979c30 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-vout.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-vout.c @@ -91,6 +91,18 @@ static struct clk_hw *jh7110_voutclk_get(struct of_phandle_args *clkspec, void * return ERR_PTR(-EINVAL); } +#ifdef CONFIG_PM_SLEEP +static int jh7110_voutcrg_sleep_suspend(struct device *dev) +{ + return pm_runtime_force_suspend(dev); +} + +static int jh7110_voutcrg_sleep_resume(struct device *dev) +{ + return pm_runtime_force_resume(dev); +} +#endif + #ifdef CONFIG_PM static int jh7110_voutcrg_suspend(struct device *dev) { @@ -110,6 +122,7 @@ static int jh7110_voutcrg_resume(struct device *dev) static const struct dev_pm_ops jh7110_voutcrg_pm_ops = { RUNTIME_PM_OPS(jh7110_voutcrg_suspend, jh7110_voutcrg_resume, NULL) + LATE_SYSTEM_SLEEP_PM_OPS(jh7110_voutcrg_sleep_suspend, jh7110_voutcrg_sleep_resume) }; #endif @@ -143,6 +156,8 @@ static int jh7110_voutcrg_probe(struct platform_device *pdev) return dev_err_probe(priv->dev, ret, "failed to get top clocks\n"); dev_set_drvdata(priv->dev, top); + pm_runtime_use_autosuspend(priv->dev); + pm_runtime_set_autosuspend_delay(priv->dev, 50); /* enable power domain and clocks */ pm_runtime_enable(priv->dev); ret = pm_runtime_get_sync(priv->dev); @@ -202,6 +217,8 @@ static int jh7110_voutcrg_probe(struct platform_device *pdev) if (ret) goto err_exit; + pm_runtime_put_sync(&pdev->dev); + return 0; err_exit: -- cgit v1.2.3