Add SiFive power provider driver
Subsystems (5)
v3 cover Add SiFive power provider driver
This patch introduces the SiFive power provider driver, which sets up a generic power domain (genpd) provider to coordinate with the RISC-V SBI cpuidle driver.
To enable this coordination, several functions from the cpuidle-riscv-sbi driver are exposed for use by the external power provider. This allows coordination between power domain management and CPU idle states on SiFive platforms.
Changes in v3:
- Update the explanation for the absence of the SoC-specific compatible string.
- Drop the smc3/tmc3/cmc3 bindings.
- Separate the genpd init and the idle driver init. The genpd remains functional even when the idle state is absent.
- Address the warning from the kernel test robot
Changes in v2:
- Add the driver for SiFive TMC, CMC and SMC
- Drop the sifive,feature-level property
Nick Hu (3):
dt-bindings: power: Add SiFive Domain Management controllers
cpuidle: riscv-sbi: Work with the external pmdomain driver
cpuidle: Add SiFive power provider
.../devicetree/bindings/power/sifive,tmc.yaml | 58 ++++++++++ drivers/cpuidle/Kconfig.riscv | 11 ++ drivers/cpuidle/Makefile | 1 + drivers/cpuidle/cpuidle-riscv-sbi.c | 46 ++++---- drivers/cpuidle/cpuidle-riscv-sbi.h | 20 ++++ drivers/cpuidle/cpuidle-sifive-dmc-pd.c | 102 ++++++++++++++++++ 6 files changed, 220 insertions(+), 18 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/sifive,tmc.yaml create mode 100644 drivers/cpuidle/cpuidle-riscv-sbi.h create mode 100644 drivers/cpuidle/cpuidle-sifive-dmc-pd.c
Signature · 7 lines
2.17.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v3 1/3 dt-bindings: power: Add SiFive Domain Management controllers
SiFive Domain Management controller includes the following components
- SiFive Tile Management Controller
- SiFive Cluster Management Controller
- SiFive Core Complex Management Controller
These controllers control the clock and power domain of the corresponding domain.
Add - {} for the first entry [1][2]. Once the SoCs are ready, we will add the SoC compatible string at that time.
Links:
- [1] https://lore.kernel.org/lkml/[email protected]/
- [2] https://lore.kernel.org/lkml/CAKddAkAzDGL-7MbroRqQnZzPXOquUMKNuGGppqB-d_XZXbcvBA@mail.gmail.com/T/#t
--- .../devicetree/bindings/power/sifive,tmc.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/sifive,tmc.yaml
Documentation/devicetree/bindings/power/sifive,tmc.yaml new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/sifive,tmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SiFive Domain Management Controller + +maintainers: + - Cyan Yang <[email protected]> + - Nick Hu <[email protected]> + - Samuel Holland <[email protected]> + +description: | + SiFive Domain Management Controllers includes the following components + - Tile Management Controller (TMC) + - Cluster Management Controller (CMC) + - Subsystem Management Controller (SMC) + These controllers manage both the clock and power domains of the + associated components. They support the SiFive Quiet Interface Protocol + (SQIP) starting from Version 1. The control method differs from Version + 0, making them incompatible. + +allOf: + - $ref: power-domain.yaml# + +properties: + compatible: + oneOf: + - items: + - {} # Leave a empty for future SoC specific compatible string + - const: sifive,cmc2 + - items: + - {} # Leave a empty for future SoC specific compatible string + - const: sifive,smc0 + - items: + - {} # Leave a empty for future SoC specific compatible string + - const: sifive,smc1 + - items: + - {} # Leave a empty for future SoC specific compatible string + - const: sifive,tmc0 + - items: + - {} # Leave a empty for future SoC specific compatible string + - const: sifive,tmc1 + + reg: + maxItems: 1 + + "#power-domain-cells": + const: 0 + +required: + - compatible + - reg + +additionalProperties: false + +# The example will be added once the SoCs are ready
Signature · 1 line
2.17.1
Re: [PATCH v3 1/3] dt-bindings: power: Add SiFive Domain Management controllers
Quoted 15 lines · Nick Hu
SiFive Domain Management controller includes the following components
- SiFive Tile Management Controller
- SiFive Cluster Management Controller
- SiFive Core Complex Management ControllerThese controllers control the clock and power domain of the corresponding domain.
Add
- {}for the first entry [1][2]. Once the SoCs are ready, we will add the SoC compatible string at that time.Links:
- [1] https://lore.kernel.org/lkml/[email protected]/
- [2] https://lore.kernel.org/lkml/CAKddAkAzDGL-7MbroRqQnZzPXOquUMKNuGGppqB-d_XZXbcvBA@mail.gmail.com/T/#t
Quoted 7 lines
Signed-off-by Nick Hu <[email protected]>Reviewed-by Samuel Holland <[email protected]>--- .../devicetree/bindings/power/sifive,tmc.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/sifive,tmc.yaml
PATCH v3 2/3 cpuidle: riscv-sbi: Work with the external pmdomain driver
In reply to Nick HuTo work with the external pmdomain driver, exposing the sbi_cpuidle_pd_power_off and sbi_dt_parse_state_node so the external pmdomain driver can parse the riscv idle state data and set the domain idle state where powering off. In addition, separate the genpd init and the idle driver init. The genpd remains functional even when the idle state is absent.
--- drivers/cpuidle/cpuidle-riscv-sbi.c | 46 ++++++++++++++++++----------- drivers/cpuidle/cpuidle-riscv-sbi.h | 20 +++++++++++++ 2 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 drivers/cpuidle/cpuidle-riscv-sbi.h
drivers/cpuidle/cpuidle-riscv-sbi.c +28 -18
@@ -27,6 +27,7 @@#include <asm/suspend.h> #include "cpuidle.h" +#include "cpuidle-riscv-sbi.h" #include "dt_idle_states.h" #include "dt_idle_genpd.h"
@@ -43,7 +44,6 @@ struct sbi_domain_state { static DEFINE_PER_CPU_READ_MOSTLY(struct sbi_cpuidle_data, sbi_cpuidle_data); static DEFINE_PER_CPU(struct sbi_domain_state, domain_state);static bool sbi_cpuidle_use_osi; -static bool sbi_cpuidle_use_cpuhp;static bool sbi_cpuidle_pd_allow_domain_state;static inline void sbi_set_domain_state (u32 state)
@@ -171,9 +171,6 @@ static void sbi_idle_init_cpuhp(void) {int err; -if (!sbi_cpuidle_use_cpuhp) -return ; - err = cpuhp_setup_state_nocalls(CPUHP_AP_CPU_PM_STARTING, "cpuidle/sbi:online", sbi_cpuidle_cpuhp_up,
@@ -188,7 +185,7 @@ static const struct of_device_id sbi_cpuidle_state_match[] = { { }, }; -static int sbi_dt_parse_state_node (struct device_node *np,u32 *state) +int sbi_dt_parse_state_node (struct device_node *np,u32 *state) {int err =of_property_read_u32 (np,"riscv,sbi-suspend-param" , state);
@@ -213,10 +210,6 @@ static int sbi_dt_cpu_init_topology(struct cpuidle_driver *drv,if (!sbi_cpuidle_use_osi)return 0 ; - data->dev =dt_idle_attach_cpu (cpu,"sbi" ); -if (IS_ERR_OR_NULL (data->dev)) -return PTR_ERR_OR_ZERO (data->dev); -/* * Using the deepest state for the CPU to trigger a potential selection * of a shared state for the domain, assumes the domain states are all
@@ -226,7 +219,6 @@ static int sbi_dt_cpu_init_topology(struct cpuidle_driver *drv, drv->states[state_count -1 ].enter = sbi_enter_domain_idle_state; drv->states[state_count -1 ].enter_s2idle = sbi_enter_s2idle_domain_idle_state; - sbi_cpuidle_use_cpuhp = true;return 0 ; }
@@ -282,7 +274,6 @@ static void sbi_cpuidle_deinit_cpu(int cpu)struct sbi_cpuidle_data *data =per_cpu_ptr (&sbi_cpuidle_data, cpu);dt_idle_detach_cpu (data->dev); - sbi_cpuidle_use_cpuhp = false; }static int sbi_cpuidle_init_cpu (struct device *dev,int cpu)
@@ -325,8 +316,9 @@ static int sbi_cpuidle_init_cpu(struct device *dev, int cpu)/* Initialize idle states from DT. */ ret =sbi_cpuidle_dt_init_states (dev, drv, cpu, state_count);if (ret) { -pr_err ("HART%ld: failed to init idle states\n" , -cpuid_to_hartid_map (cpu)); +if (ret != -EPROBE_DEFER ) +pr_err ("HART%ld: failed to init idle states\n" , +cpuid_to_hartid_map (cpu));return ret; }
@@ -356,7 +348,7 @@ static void sbi_cpuidle_domain_sync_state(struct device *dev)#ifdef CONFIG_DT_IDLE_GENPD -static int sbi_cpuidle_pd_power_off (struct generic_pm_domain *pd) +int sbi_cpuidle_pd_power_off (struct generic_pm_domain *pd) {struct genpd_power_state *state = &pd->states[pd->state_idx];u32 *pd_state;
@@ -529,6 +521,27 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)return ret; } +/* Attaching the cpu to the corresponding power domain */ +if (sbi_cpuidle_use_osi) { +for_each_present_cpu (cpu) { +struct sbi_cpuidle_data *data =per_cpu_ptr (&sbi_cpuidle_data, cpu); + + data->dev =dt_idle_attach_cpu (cpu,"sbi" ); +if (IS_ERR_OR_NULL (data->dev)) { + ret =PTR_ERR_OR_ZERO (data->dev); +if (ret != -EPROBE_DEFER ) +pr_debug ("Hart%ld: fail to attach the power domain\n" , +cpuid_to_hartid_map (cpu)); + +while (--cpu >=0 ) +dt_idle_detach_cpu (data->dev); +return ret; + } + } +/* Setup CPU hotplut notifiers */ +sbi_idle_init_cpuhp (); + } +/* Initialize CPU idle driver for each present CPU */ for_each_present_cpu (cpu) { ret =sbi_cpuidle_init_cpu (&pdev->dev, cpu);
@@ -539,9 +552,6 @@ static int sbi_cpuidle_probe(struct platform_device *pdev) } } -/* Setup CPU hotplut notifiers */ -sbi_idle_init_cpuhp (); -if (cpuidle_disabled ())pr_info ("cpuidle is disabled\n" );else
@@ -556,7 +566,7 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)cpuidle_unregister (drv);sbi_cpuidle_deinit_cpu (cpu); } - +out:return ret; }
drivers/cpuidle/cpuidle-riscv-sbi.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __CPUIDLE_RISCV_SBI +#define __CPUIDLE_RISCV_SBI + +#ifdef CONFIG_DT_IDLE_GENPD + +int sbi_cpuidle_pd_power_off (struct generic_pm_domain *pd); + +#else + +static inline int sbi_cpuidle_pd_power_off (struct generic_pm_domain *pd) +{ +return 0 ; +} + +#endif + +int sbi_dt_parse_state_node (struct device_node *np,u32 *state); + +#endif
Signature · 1 line
2.17.1
kernel test robot
build botRe: [PATCH v3 2/3] cpuidle: riscv-sbi: Work with the external pmdomain driver
kernel test robot noticed the following build warnings:
Hi Nick,
kernel test robot noticed the following build warnings:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge robh/for-next linus/master v6.16-rc4 next-20250703] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Nick-Hu/cpuidle-riscv-sbi-Work-with-the-external-pmdomain-driver/20250702-181250 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next patch link: https://lore.kernel.org/r/20250702091236.5281-3-nick.hu%40sifive.com patch subject: [PATCH v3 2/3] cpuidle: riscv-sbi: Work with the external pmdomain driver config: riscv-randconfig-001-20250703 (https://download.01.org/0day-ci/archive/20250704/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 13.4.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250704/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/cpuidle/cpuidle-riscv-sbi.c: In function 'sbi_cpuidle_probe':
>> drivers/cpuidle/cpuidle-riscv-sbi.c:569:1: warning: label 'out' defined but not used [-Wunused-label]
569 | out:
| ^~~vim +/out +569 drivers/cpuidle/cpuidle-riscv-sbi.c
493
494 static int sbi_cpuidle_probe(struct platform_device *pdev)
495 {
496 int cpu, ret;
497 struct cpuidle_driver *drv;
498 struct cpuidle_device *dev;
499 struct device_node *pds_node;
500
501 /* Detect OSI support based on CPU DT nodes */
502 sbi_cpuidle_use_osi = true;
503 for_each_possible_cpu(cpu) {
504 struct device_node *np __free(device_node) = of_cpu_device_node_get(cpu);
505 if (np &&
506 of_property_present(np, "power-domains") &&
507 of_property_present(np, "power-domain-names")) {
508 continue;
509 } else {
510 sbi_cpuidle_use_osi = false;
511 break;
512 }
513 }
514
515 /* Populate generic power domains from DT nodes */
516 pds_node = of_find_node_by_path("/cpus/power-domains");
517 if (pds_node) {
518 ret = sbi_genpd_probe(pds_node);
519 of_node_put(pds_node);
520 if (ret)
521 return ret;
522 }
523
524 /* Attaching the cpu to the corresponding power domain */
525 if (sbi_cpuidle_use_osi) {
526 for_each_present_cpu(cpu) {
527 struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu);
528
529 data->dev = dt_idle_attach_cpu(cpu, "sbi");
530 if (IS_ERR_OR_NULL(data->dev)) {
531 ret = PTR_ERR_OR_ZERO(data->dev);
532 if (ret != -EPROBE_DEFER)
533 pr_debug("Hart%ld: fail to attach the power domain\n",
534 cpuid_to_hartid_map(cpu));
535
536 while (--cpu >= 0)
537 dt_idle_detach_cpu(data->dev);
538 return ret;
539 }
540 }
541 /* Setup CPU hotplut notifiers */
542 sbi_idle_init_cpuhp();
543 }
544
545 /* Initialize CPU idle driver for each present CPU */
546 for_each_present_cpu(cpu) {
547 ret = sbi_cpuidle_init_cpu(&pdev->dev, cpu);
548 if (ret) {
549 pr_debug("HART%ld: idle driver init failed\n",
550 cpuid_to_hartid_map(cpu));
551 goto out_fail;
552 }
553 }
554
555 if (cpuidle_disabled())
556 pr_info("cpuidle is disabled\n");
557 else
558 pr_info("idle driver registered for all CPUs\n");
559
560 return 0;
561
562 out_fail:
563 while (--cpu >= 0) {
564 dev = per_cpu(cpuidle_devices, cpu);
565 drv = cpuidle_get_cpu_driver(dev);
566 cpuidle_unregister(drv);
567 sbi_cpuidle_deinit_cpu(cpu);
568 }
> 569 out:
570 return ret;
571 }
572
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v3 3/3 cpuidle: Add SiFive power provider
In reply to Nick HuThe SiFive DMC is the power provider of the devices that inside the SiFive CPU power domains, which include Tile, Cluster and Core Complex power domains. Before the cpu entering the firmware-based idle state, each devices that inside the corresponding domain should be suspended properly. So this driver will create the power provider and set the correct idle state.
--- drivers/cpuidle/Kconfig.riscv | 12 +++ drivers/cpuidle/Makefile | 1 + drivers/cpuidle/cpuidle-sifive-dmc-pd.c | 102 ++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 drivers/cpuidle/cpuidle-sifive-dmc-pd.c
drivers/cpuidle/Kconfig.riscv +12 -0
@@ -13,3 +13,15 @@ config RISCV_SBI_CPUIDLE Select this option to enable RISC-V SBI firmware based CPU idle driver for RISC-V systems. This drivers also supports hierarchical DT based layout of the idle state. + +config SIFIVE_DMC_PD_CPUIDLE + bool "SiFive DMC SBI PD Provider Driver" + depends on ARCH_SIFIVE && RISCV_SBI && PM && OF + select PM_GENERIC_DOMAINS + select PM_GENERIC_DOMAINS_OF + select RISCV_SBI_CPUIDLE + default y + help + Select this option to enable SiFive DMC SBI PD Provider driver. + This driver will create the genpd provider and work with the + RISC-V SBI firmware based CPU idle driver.
drivers/cpuidle/Makefile +1 -0
@@ -42,3 +42,4 @@ obj-$(CONFIG_POWERNV_CPUIDLE) += cpuidle-powernv.o ############################################################################### # RISC-V drivers obj-$(CONFIG_RISCV_SBI_CPUIDLE) += cpuidle-riscv-sbi.o +obj-$(CONFIG_SIFIVE_DMC_PD_CPUIDLE) += cpuidle-sifive-dmc-pd.o
drivers/cpuidle/cpuidle-sifive-dmc-pd.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.17.1