diff mbox series

[1/2] PM / Domains: Enable locking for syscore devices for IRQ safe genpds

Message ID 20200901082707.106860-2-ulf.hansson@linaro.org
State New
Headers show
Series cpuidle: psci: Enable s2idle when using PSCI OSI | expand

Commit Message

Ulf Hansson Sept. 1, 2020, 8:27 a.m. UTC
The genpd lock is currently not being used, while suspending/resuming
syscore devices through genpd. This because we need to avoid using a mutex
when running in the syscore phase.

However, the locking can be useful under special circumstances (as shown in
subsequent changes) and for a genpd having the flag GENPD_FLAG_IRQ_SAFE
set. Therefore, let's make use of the lock when it's possible.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

---
 drivers/base/power/domain.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

-- 
2.25.1
diff mbox series

Patch

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 2cb5e04cf86c..55d99a36bf6b 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -1342,18 +1342,27 @@  static void genpd_complete(struct device *dev)
 static void genpd_syscore_switch(struct device *dev, bool suspend)
 {
 	struct generic_pm_domain *genpd;
+	bool use_lock;
 
 	genpd = dev_to_genpd_safe(dev);
 	if (!genpd)
 		return;
 
+	use_lock = genpd_is_irq_safe(genpd);
+
+	if (use_lock)
+		genpd_lock(genpd);
+
 	if (suspend) {
 		genpd->suspended_count++;
-		genpd_sync_power_off(genpd, false, 0);
+		genpd_sync_power_off(genpd, use_lock, 0);
 	} else {
-		genpd_sync_power_on(genpd, false, 0);
+		genpd_sync_power_on(genpd, use_lock, 0);
 		genpd->suspended_count--;
 	}
+
+	if (use_lock)
+		genpd_unlock(genpd);
 }
 
 void pm_genpd_syscore_poweroff(struct device *dev)