Skip to content

Commit 13a4b7f

Browse files
committed
pmdomain: core: Leave powered-on genpds on until late_initcall_sync
Powering-off a genpd that was on during boot, before all of its consumer devices have been probed, is certainly prone to problems. As a step to improve this situation, let's prevent these genpds from being powered-off until genpd_power_off_unused() gets called, which is a late_initcall_sync(). Note that, this still doesn't guarantee that all the consumer devices has been probed before we allow to power-off the genpds. Yet, this should be a step in the right direction. Suggested-by: Saravana Kannan <saravanak@google.com> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106 Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/20250701114733.636510-22-ulf.hansson@linaro.org
1 parent f66c656 commit 13a4b7f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

drivers/pmdomain/core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,11 +931,12 @@ static void genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
931931
* The domain is already in the "power off" state.
932932
* System suspend is in progress.
933933
* The domain is configured as always on.
934+
* The domain was on at boot and still need to stay on.
934935
* The domain has a subdomain being powered on.
935936
*/
936937
if (!genpd_status_on(genpd) || genpd->prepared_count > 0 ||
937938
genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd) ||
938-
atomic_read(&genpd->sd_count) > 0)
939+
genpd->stay_on || atomic_read(&genpd->sd_count) > 0)
939940
return;
940941

941942
/*
@@ -1346,8 +1347,12 @@ static int __init genpd_power_off_unused(void)
13461347
pr_info("genpd: Disabling unused power domains\n");
13471348
mutex_lock(&gpd_list_lock);
13481349

1349-
list_for_each_entry(genpd, &gpd_list, gpd_list_node)
1350+
list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
1351+
genpd_lock(genpd);
1352+
genpd->stay_on = false;
1353+
genpd_unlock(genpd);
13501354
genpd_queue_power_off_work(genpd);
1355+
}
13511356

13521357
mutex_unlock(&gpd_list_lock);
13531358

@@ -2352,6 +2357,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
23522357
INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
23532358
atomic_set(&genpd->sd_count, 0);
23542359
genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
2360+
genpd->stay_on = !is_off;
23552361
genpd->sync_state = GENPD_SYNC_STATE_OFF;
23562362
genpd->device_count = 0;
23572363
genpd->provider = NULL;

include/linux/pm_domain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct generic_pm_domain {
199199
unsigned int performance_state; /* Aggregated max performance state */
200200
cpumask_var_t cpus; /* A cpumask of the attached CPUs */
201201
bool synced_poweroff; /* A consumer needs a synced poweroff */
202+
bool stay_on; /* Stay powered-on during boot. */
202203
enum genpd_sync_state sync_state; /* How sync_state is managed. */
203204
int (*power_off)(struct generic_pm_domain *domain);
204205
int (*power_on)(struct generic_pm_domain *domain);

0 commit comments

Comments
 (0)