[PATCH v3 1/4] PM: domains: Allow power off queuing from providers
From: Abel Vesa
Date: Mon Mar 27 2023 - 15:38:48 EST
In some cases, the providers might choose to refuse powering off some
domains until all of the consumers have had a chance to probe, that is,
until sync state callback has been called. Such providers might choose
to disable such domains on their own, from the sync state callback. So,
in order to do that, they need a way to queue up a power off request.
Since the generic genpd already has such API, make that available to
those providers.
Signed-off-by: Abel Vesa <abel.vesa@xxxxxxxxxx>
Reviewed-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
---
drivers/base/power/domain.c | 18 ++++++++++--------
include/linux/pm_domain.h | 4 ++++
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 32084e38b73d..209b8152e948 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -643,16 +643,18 @@ static int _genpd_power_off(struct generic_pm_domain *genpd, bool timed)
}
/**
- * genpd_queue_power_off_work - Queue up the execution of genpd_power_off().
+ * pm_genpd_queue_power_off - Queue up the execution of genpd_power_off().
* @genpd: PM domain to power off.
*
* Queue up the execution of genpd_power_off() unless it's already been done
- * before.
+ * before. The sole purpose of this being exported is to allow the providers
+ * to disable the unused domains from their sync_state callback.
*/
-static void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
+void pm_genpd_queue_power_off(struct generic_pm_domain *genpd)
{
queue_work(pm_wq, &genpd->power_off_work);
}
+EXPORT_SYMBOL_GPL(pm_genpd_queue_power_off);
/**
* genpd_power_off - Remove power from a given PM domain.
@@ -1096,7 +1098,7 @@ static int __init genpd_power_off_unused(void)
mutex_lock(&gpd_list_lock);
list_for_each_entry(genpd, &gpd_list, gpd_list_node)
- genpd_queue_power_off_work(genpd);
+ pm_genpd_queue_power_off(genpd);
mutex_unlock(&gpd_list_lock);
@@ -1431,7 +1433,7 @@ static void genpd_complete(struct device *dev)
genpd->prepared_count--;
if (!genpd->prepared_count)
- genpd_queue_power_off_work(genpd);
+ pm_genpd_queue_power_off(genpd);
genpd_unlock(genpd);
}
@@ -2703,7 +2705,7 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
}
/* Check if PM domain can be powered off after removing this device. */
- genpd_queue_power_off_work(pd);
+ pm_genpd_queue_power_off(pd);
/* Unregister the device if it was created by genpd. */
if (dev->bus == &genpd_bus_type)
@@ -2718,7 +2720,7 @@ static void genpd_dev_pm_sync(struct device *dev)
if (IS_ERR(pd))
return;
- genpd_queue_power_off_work(pd);
+ pm_genpd_queue_power_off(pd);
}
static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
@@ -2879,7 +2881,7 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
}
pm_runtime_enable(virt_dev);
- genpd_queue_power_off_work(dev_to_genpd(virt_dev));
+ pm_genpd_queue_power_off(dev_to_genpd(virt_dev));
return virt_dev;
}
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index f776fb93eaa0..b7991bf98e1c 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -231,6 +231,7 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
int pm_genpd_init(struct generic_pm_domain *genpd,
struct dev_power_governor *gov, bool is_off);
int pm_genpd_remove(struct generic_pm_domain *genpd);
+void pm_genpd_queue_power_off(struct generic_pm_domain *genpd);
int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state);
int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb);
int dev_pm_genpd_remove_notifier(struct device *dev);
@@ -278,6 +279,9 @@ static inline int pm_genpd_remove(struct generic_pm_domain *genpd)
return -EOPNOTSUPP;
}
+static inline void pm_genpd_queue_power_off(struct generic_pm_domain *genpd)
+{ }
+
static inline int dev_pm_genpd_set_performance_state(struct device *dev,
unsigned int state)
{
--
2.34.1