On Wed, 21 Jun 2023 at 16:40, Abel Vesa <abel.vesa@xxxxxxxxxx> wrote: > > For every provider that doesn't register a sync_state callback, > register a generic one. This new generic sync_state callback queues up a > power off request. > > Signed-off-by: Abel Vesa <abel.vesa@xxxxxxxxxx> > --- > drivers/base/power/domain.c | 23 +++++++++++++++++++++++ > include/linux/pm_domain.h | 3 +++ > 2 files changed, 26 insertions(+) > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > index 5967ade160e2..ec16db0599ac 100644 > --- a/drivers/base/power/domain.c > +++ b/drivers/base/power/domain.c > @@ -654,6 +654,27 @@ static void genpd_queue_power_off_work(struct generic_pm_domain *genpd) > queue_work(pm_wq, &genpd->power_off_work); > } > > +/** > + * pm_genpd_power_off_unused_sync_state - Power off all domains for provider. > + * @dev: Provider's device. > + * > + * Request power off for all unused domains of the provider. > + * This should be used exclusively as sync state callback for genpd providers. > + */ > +void pm_genpd_power_off_unused_sync_state(struct device *dev) > +{ > + struct generic_pm_domain *genpd; > + > + mutex_lock(&gpd_list_lock); > + > + list_for_each_entry(genpd, &gpd_list, gpd_list_node) > + if (genpd->provider && genpd->provider->dev == dev) Not all genpds have the ->provider assigned. Moreover, the of_genpd_mutex is protecting the list of providers, we should use that instead. > + genpd_queue_power_off_work(genpd); > + > + mutex_unlock(&gpd_list_lock); > +} > +EXPORT_SYMBOL_GPL(pm_genpd_power_off_unused_sync_state); Why does this need to be exported? Is there a provider that assigns it's own sync state callback that needs to call this? If that is the case, I would prefer to see a user of this API as a part of the series too. > + > /** > * genpd_keep_on - Tells if the domain should skip the power 'off' request > * @genpd: PM domain to be checked. > @@ -2329,6 +2350,8 @@ static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate, > cp->xlate = xlate; > fwnode_dev_initialized(&np->fwnode, true); > > + dev_set_drv_sync_state(np->fwnode.dev, pm_genpd_power_off_unused_sync_state); > + > mutex_lock(&of_genpd_mutex); > list_add(&cp->link, &of_genpd_providers); > mutex_unlock(&of_genpd_mutex); > diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h > index 3eb32c4b6d4f..78164244b89f 100644 > --- a/include/linux/pm_domain.h > +++ b/include/linux/pm_domain.h > @@ -279,6 +279,9 @@ static inline int pm_genpd_remove(struct generic_pm_domain *genpd) > return -EOPNOTSUPP; > } > > +static inline void pm_genpd_power_off_unused_sync_state(struct device *dev) > +{ } > + > static inline int dev_pm_genpd_set_performance_state(struct device *dev, > unsigned int state) > { Kind regards Uffe