From: Ulf Hansson <ulf.hansson@linaro.org>
To: Saravana Kannan <saravanak@google.com>,
Stephen Boyd <sboyd@kernel.org>,
linux-pm@vger.kernel.org
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Michael Grzeschik <m.grzeschik@pengutronix.de>,
Bjorn Andersson <andersson@kernel.org>,
Abel Vesa <abel.vesa@linaro.org>,
Devarsh Thakkar <devarsht@lewv0571a.ent.ti.com>,
Peng Fan <peng.fan@oss.nxp.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Johan Hovold <johan@kernel.org>,
Maulik Shah <maulik.shah@oss.qualcomm.com>,
Ulf Hansson <ulf.hansson@linaro.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 11/11] pmdomain: core: Leave powered-on genpds on until ->sync_state()
Date: Thu, 17 Apr 2025 16:25:09 +0200 [thread overview]
Message-ID: <20250417142513.312939-12-ulf.hansson@linaro.org> (raw)
In-Reply-To: <20250417142513.312939-1-ulf.hansson@linaro.org>
Powering-off a genpd that was on during boot, before all of its consumer
devices have been probed, is certainly prone to problems.
Let's fix these problems by preventing these genpds from being powered-off
until ->sync_state(). Note that, this only works for OF based platform as
->sync_state() are relying on fw_devlink.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/core.c | 12 +++++++++++-
include/linux/pm_domain.h | 1 +
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 695d7d9e5582..a8c56f7a7ba0 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -212,6 +212,12 @@ static inline bool irq_safe_dev_in_sleep_domain(struct device *dev,
return ret;
}
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+static bool genpd_may_stay_on(bool on) { return on; }
+#else
+static bool genpd_may_stay_on(bool on) { return false; }
+#endif
+
static int genpd_runtime_suspend(struct device *dev);
/*
@@ -933,11 +939,12 @@ static void genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
* The domain is already in the "power off" state.
* System suspend is in progress.
* The domain is configured as always on.
+ * The domain was on at boot and still need to stay on.
* The domain has a subdomain being powered on.
*/
if (!genpd_status_on(genpd) || genpd->prepared_count > 0 ||
genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd) ||
- atomic_read(&genpd->sd_count) > 0)
+ genpd->stay_on || atomic_read(&genpd->sd_count) > 0)
return;
/*
@@ -2374,6 +2381,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
atomic_set(&genpd->sd_count, 0);
genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
+ genpd->stay_on = genpd_may_stay_on(!is_off);
genpd->sync_state = GENPD_SYNC_STATE_OFF;
genpd->device_count = 0;
genpd->provider = NULL;
@@ -2640,6 +2648,7 @@ void of_genpd_sync_state(struct device *dev)
list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
if (genpd->provider == &np->fwnode) {
genpd_lock(genpd);
+ genpd->stay_on = false;
genpd_power_off(genpd, false, 0);
genpd_unlock(genpd);
}
@@ -3486,6 +3495,7 @@ static void genpd_provider_sync_state(struct device *dev)
case GENPD_SYNC_STATE_SIMPLE:
genpd_lock(genpd);
+ genpd->stay_on = false;
genpd_power_off(genpd, false, 0);
genpd_unlock(genpd);
break;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 2185ee9e4f7c..c5358cccacad 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -193,6 +193,7 @@ struct generic_pm_domain {
unsigned int performance_state; /* Aggregated max performance state */
cpumask_var_t cpus; /* A cpumask of the attached CPUs */
bool synced_poweroff; /* A consumer needs a synced poweroff */
+ bool stay_on; /* Stay powered-on during boot. */
enum genpd_sync_state sync_state; /* How sync_state is managed. */
int (*power_off)(struct generic_pm_domain *domain);
int (*power_on)(struct generic_pm_domain *domain);
--
2.43.0
next prev parent reply other threads:[~2025-04-17 14:25 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-17 14:24 [PATCH 00/11] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-04-17 14:24 ` [PATCH 01/11] pmdomain: core: Convert genpd_power_off() to void Ulf Hansson
2025-04-22 13:27 ` Abel Vesa
2025-04-17 14:25 ` [PATCH 02/11] pmdomain: core: Simplify return statement in genpd_power_off() Ulf Hansson
2025-04-22 13:28 ` Abel Vesa
2025-04-17 14:25 ` [PATCH 03/11] pmdomain: core: Use genpd->opp_table to simplify error/remove path Ulf Hansson
2025-04-22 13:33 ` Abel Vesa
2025-04-17 14:25 ` [PATCH 04/11] pmdomain: core: Add a bus and a driver for genpd providers Ulf Hansson
2025-04-22 14:02 ` Abel Vesa
2025-04-23 7:34 ` Ulf Hansson
2025-04-17 14:25 ` [PATCH 05/11] pmdomain: core: Use device_set_node() to assign the fwnode too Ulf Hansson
2025-04-17 20:55 ` Saravana Kannan
2025-04-23 7:30 ` Ulf Hansson
2025-04-22 14:04 ` Abel Vesa
2025-04-17 14:25 ` [PATCH 06/11] pmdomain: core: Add the genpd->dev to the genpd provider bus Ulf Hansson
2025-04-22 14:06 ` Abel Vesa
2025-04-17 14:25 ` [PATCH 07/11] pmdomain: core: Export a common ->sync_state() helper for genpd providers Ulf Hansson
2025-04-22 14:10 ` Abel Vesa
2025-05-07 16:23 ` Dan Carpenter
2025-05-08 10:05 ` Ulf Hansson
2025-04-17 14:25 ` [PATCH 08/11] pmdomain: core: Add internal ->sync_state() support " Ulf Hansson
2025-04-18 0:23 ` Saravana Kannan
2025-04-23 7:58 ` Ulf Hansson
2025-04-17 14:25 ` [PATCH 09/11] driver core: Add dev_set_drv_sync_state() Ulf Hansson
2025-04-22 14:15 ` Abel Vesa
2025-04-17 14:25 ` [PATCH 10/11] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers Ulf Hansson
2025-04-18 0:29 ` Saravana Kannan
2025-04-17 14:25 ` Ulf Hansson [this message]
2025-04-18 0:50 ` [PATCH 11/11] pmdomain: core: Leave powered-on genpds on until ->sync_state() Saravana Kannan
2025-04-23 7:46 ` Ulf Hansson
2025-04-18 0:53 ` [PATCH 00/11] pmdomain: Add generic ->sync_state() support to genpd Saravana Kannan
2025-04-24 10:59 ` Tomi Valkeinen
2025-04-25 12:17 ` Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250417142513.312939-12-ulf.hansson@linaro.org \
--to=ulf.hansson@linaro.org \
--cc=abel.vesa@linaro.org \
--cc=andersson@kernel.org \
--cc=devarsht@lewv0571a.ent.ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=m.grzeschik@pengutronix.de \
--cc=maulik.shah@oss.qualcomm.com \
--cc=peng.fan@oss.nxp.com \
--cc=rafael@kernel.org \
--cc=saravanak@google.com \
--cc=sboyd@kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox