[PATCH v5 6/8] cpuidle: Add RISC-V SBI CPU idle driver

Anup Patel anup at brainfault.org
Wed Jun 9 03:36:51 PDT 2021


On Mon, Jun 7, 2021 at 12:09 AM Samuel Holland <samuel at sholland.org> wrote:
>
> On 6/2/21 6:23 AM, Anup Patel wrote:
> > The RISC-V SBI HSM extension provides HSM suspend call which can
> > be used by Linux RISC-V to enter platform specific low-power state.
> >
> > This patch adds a CPU idle driver based on RISC-V SBI calls which
> > will populate idle states from device tree and use SBI calls to
> > entry these idle states.
> >
> > Signed-off-by: Anup Patel <anup.patel at wdc.com>
> > ---
> >  MAINTAINERS                   |   7 +
> >  drivers/cpuidle/Kconfig       |   5 +
> >  drivers/cpuidle/Kconfig.riscv |  15 +
> >  drivers/cpuidle/Makefile      |   4 +
> >  drivers/cpuidle/cpuidle-sbi.c | 626 ++++++++++++++++++++++++++++++++++
> >  5 files changed, 657 insertions(+)
> >  create mode 100644 drivers/cpuidle/Kconfig.riscv
> >  create mode 100644 drivers/cpuidle/cpuidle-sbi.c
> >
> > ...
> > diff --git a/drivers/cpuidle/cpuidle-sbi.c b/drivers/cpuidle/cpuidle-sbi.c
> > new file mode 100644
> > index 000000000000..f743684d07de
> > --- /dev/null
> > +++ b/drivers/cpuidle/cpuidle-sbi.c
> > @@ -0,0 +1,626 @@
> > ...
> > +     /* 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));
> > +             return ret;
> > +     }
> > +
> > +     ret = cpuidle_register(drv, NULL);
> > +     if (ret)
> > +             goto deinit;
> > +
> > +     cpuidle_cooling_register(drv);
> > +
> > +     return 0;
> > +deinit:
> > +     sbi_cpuidle_deinit_cpu(cpu);
> > +     return ret;
> > +}
> > +
> > +static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
>
> This function should be moved inside the CONFIG_DT_IDLE_GENPD block
> below. Otherwise it is defined but unused.

Indeed, sbi_cpuidle_pd_power_off() should be under
"#ifdef CONFIG_DT_IDLE_GENPD". I will update in the
next patch revision.

>
> > +{
> > +     struct genpd_power_state *state = &pd->states[pd->state_idx];
> > +     u32 *pd_state;
> > +
> > +     if (!state->data)
> > +             return 0;
> > +
> > +     if (!sbi_cpuidle_pd_allow_domain_state)
> > +             return -EBUSY;
> > +
> > +     /* OSI mode is enabled, set the corresponding domain state. */
> > +     pd_state = state->data;
> > +     sbi_set_domain_state(*pd_state);
> > +
> > +     return 0;
> > +}
> > +
> > +static void sbi_cpuidle_domain_sync_state(struct device *dev)
> > +{
> > +     /*
> > +      * All devices have now been attached/probed to the PM domain
> > +      * topology, hence it's fine to allow domain states to be picked.
> > +      */
> > +     sbi_cpuidle_pd_allow_domain_state = true;
> > +}
> > +
> > +#ifdef CONFIG_DT_IDLE_GENPD
> > +
> > +struct sbi_pd_provider {
> > +     struct list_head link;
> > +     struct device_node *node;
> > +};
> > +
> > +static LIST_HEAD(sbi_pd_providers);
> > +
> > +static int sbi_pd_init(struct device_node *np)
> > +{
> > +     struct generic_pm_domain *pd;
> > +     struct sbi_pd_provider *pd_provider;
> > +     struct dev_power_governor *pd_gov;
> > +     int ret = -ENOMEM, state_count = 0;
> > +
> > +     pd = dt_idle_pd_alloc(np, sbi_dt_parse_state_node);
> > +     if (!pd)
> > +             goto out;
> > ...

Regards,
Anup



More information about the linux-arm-kernel mailing list