Skip to content

Commit 5713325

Browse files
marcanjannau
authored andcommitted
PM: domains: Add a flag to defer power-off until all consumers probe
In some cases, power domains are active on boot and must remain turned on until all their dependent drivers probe. Examples are: - Boot-time framebuffers - Devices that run coprocessors which are handed off already running - Parent power domains with children that are also on at boot The genpd core currently powers off the genpd as soon as a single consumer device probes and goes into runtime suspend or when general probing is complete, whichever comes first. That breaks any devices which haven't probed yet. To fix this, add a GENPD_FLAG_DEFER_OFF which requests that the genpd core refuse to power down a domain if there are any consumer devices that either haven't probed yet, or whose device nodes do not exist yet (but fwlinks do). Genpd providers can set this if they expect to be critical for devices (e.g. if they are powered on at boot). It is possible for a device to be runtime suspended from its probe callback. If this is the last device to probe, this is allowable. To account for this, check whether the device whose callbacks are being invoked in the probing state, and in that case, allow 1 instead of 0 pending devices. Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent bb1e9fd commit 5713325

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

drivers/pmdomain/core.c

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define pr_fmt(fmt) "PM: " fmt
88

99
#include <linux/delay.h>
10+
#include <linux/fwnode.h>
1011
#include <linux/idr.h>
1112
#include <linux/kernel.h>
1213
#include <linux/io.h>
@@ -176,6 +177,7 @@ static const struct genpd_lock_ops genpd_raw_spin_ops = {
176177
#define genpd_is_rpm_always_on(genpd) (genpd->flags & GENPD_FLAG_RPM_ALWAYS_ON)
177178
#define genpd_is_opp_table_fw(genpd) (genpd->flags & GENPD_FLAG_OPP_TABLE_FW)
178179
#define genpd_is_dev_name_fw(genpd) (genpd->flags & GENPD_FLAG_DEV_NAME_FW)
180+
#define genpd_is_defer_off(genpd) (genpd->flags & GENPD_FLAG_DEFER_OFF)
179181

180182
static inline bool irq_safe_dev_in_sleep_domain(struct device *dev,
181183
const struct generic_pm_domain *genpd)
@@ -810,6 +812,27 @@ static void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
810812
queue_work(pm_wq, &genpd->power_off_work);
811813
}
812814

815+
/**
816+
* genpd_must_defer - Check whether the genpd cannot be safely powered off.
817+
* @genpd: PM domain about to be powered down.
818+
* @one_dev_probing: True if we are being called from RPM callbacks on a device that
819+
* is probing, to allow poweroff if that device is the sole remaining consumer probing.
820+
*
821+
* Returns true if the @genpd has the GENPD_FLAG_DEFER_OFF flag and there
822+
* are any consumer devices which either do not exist yet (only represented
823+
* by fwlinks) or whose drivers have not probed yet.
824+
*/
825+
static bool genpd_must_defer(struct generic_pm_domain *genpd, bool one_dev_probing)
826+
{
827+
if (genpd_is_defer_off(genpd) && genpd->has_provider) {
828+
int absent = fw_devlink_count_absent_consumers(genpd->provider);
829+
830+
if (absent > (one_dev_probing ? 1 : 0))
831+
return true;
832+
}
833+
return false;
834+
}
835+
813836
/**
814837
* genpd_power_off - Remove power from a given PM domain.
815838
* @genpd: PM domain to power down.
@@ -823,7 +846,7 @@ static void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
823846
* have been powered down, remove power from @genpd.
824847
*/
825848
static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
826-
unsigned int depth)
849+
bool one_dev_probing, unsigned int depth)
827850
{
828851
struct pm_domain_data *pdd;
829852
struct gpd_link *link;
@@ -873,6 +896,14 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
873896
if (not_suspended > 1 || (not_suspended == 1 && !one_dev_on))
874897
return -EBUSY;
875898

899+
/*
900+
* Do not allow PM domain to be powered off if it is marked
901+
* as GENPD_FLAG_DEFER_OFF and there are consumer devices
902+
* which have not probed yet.
903+
*/
904+
if (genpd_must_defer(genpd, one_dev_probing))
905+
return -EBUSY;
906+
876907
if (genpd->gov && genpd->gov->power_down_ok) {
877908
if (!genpd->gov->power_down_ok(&genpd->domain))
878909
return -EAGAIN;
@@ -899,7 +930,7 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
899930
list_for_each_entry(link, &genpd->child_links, child_node) {
900931
genpd_sd_counter_dec(link->parent);
901932
genpd_lock_nested(link->parent, depth + 1);
902-
genpd_power_off(link->parent, false, depth + 1);
933+
genpd_power_off(link->parent, false, false, depth + 1);
903934
genpd_unlock(link->parent);
904935
}
905936

@@ -957,7 +988,7 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth)
957988
child_node) {
958989
genpd_sd_counter_dec(link->parent);
959990
genpd_lock_nested(link->parent, depth + 1);
960-
genpd_power_off(link->parent, false, depth + 1);
991+
genpd_power_off(link->parent, false, false, depth + 1);
961992
genpd_unlock(link->parent);
962993
}
963994

@@ -1024,7 +1055,7 @@ static void genpd_power_off_work_fn(struct work_struct *work)
10241055
genpd = container_of(work, struct generic_pm_domain, power_off_work);
10251056

10261057
genpd_lock(genpd);
1027-
genpd_power_off(genpd, false, 0);
1058+
genpd_power_off(genpd, false, false, 0);
10281059
genpd_unlock(genpd);
10291060
}
10301061

@@ -1089,6 +1120,7 @@ static int genpd_runtime_suspend(struct device *dev)
10891120
struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
10901121
struct gpd_timing_data *td = gpd_data->td;
10911122
bool runtime_pm = pm_runtime_enabled(dev);
1123+
bool probing = dev->links.status != DL_DEV_DRIVER_BOUND;
10921124
ktime_t time_start = 0;
10931125
s64 elapsed_ns;
10941126
int ret;
@@ -1143,7 +1175,7 @@ static int genpd_runtime_suspend(struct device *dev)
11431175
return 0;
11441176

11451177
genpd_lock(genpd);
1146-
genpd_power_off(genpd, true, 0);
1178+
genpd_power_off(genpd, true, probing, 0);
11471179
gpd_data->rpm_pstate = genpd_drop_performance_state(dev);
11481180
genpd_unlock(genpd);
11491181

@@ -1164,6 +1196,7 @@ static int genpd_runtime_resume(struct device *dev)
11641196
struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
11651197
struct gpd_timing_data *td = gpd_data->td;
11661198
bool timed = td && pm_runtime_enabled(dev);
1199+
bool probing = dev->links.status != DL_DEV_DRIVER_BOUND;
11671200
ktime_t time_start = 0;
11681201
s64 elapsed_ns;
11691202
int ret;
@@ -1221,7 +1254,7 @@ static int genpd_runtime_resume(struct device *dev)
12211254
err_poweroff:
12221255
if (!pm_runtime_is_irq_safe(dev) || genpd_is_irq_safe(genpd)) {
12231256
genpd_lock(genpd);
1224-
genpd_power_off(genpd, true, 0);
1257+
genpd_power_off(genpd, true, probing, 0);
12251258
gpd_data->rpm_pstate = genpd_drop_performance_state(dev);
12261259
genpd_unlock(genpd);
12271260
}
@@ -1288,6 +1321,9 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock,
12881321
|| atomic_read(&genpd->sd_count) > 0)
12891322
return;
12901323

1324+
if (genpd_must_defer(genpd, false))
1325+
return;
1326+
12911327
/* Check that the children are in their deepest (powered-off) state. */
12921328
list_for_each_entry(link, &genpd->parent_links, parent_node) {
12931329
struct generic_pm_domain *child = link->child;
@@ -2288,6 +2324,12 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
22882324
return -EINVAL;
22892325
}
22902326

2327+
/* Deferred-off power domains should be powered on at initialization. */
2328+
if (genpd_is_defer_off(genpd) && !genpd_status_on(genpd)) {
2329+
pr_warn("deferred-off PM domain %s is not on at init\n", genpd->name);
2330+
genpd->flags &= ~GENPD_FLAG_DEFER_OFF;
2331+
}
2332+
22912333
/* Multiple states but no governor doesn't make sense. */
22922334
if (!gov && genpd->state_count > 1)
22932335
pr_warn("%s: no governor for states\n", genpd->name);

include/linux/pm_domain.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ struct dev_pm_domain_list {
104104
* GENPD_FLAG_DEV_NAME_FW: Instructs genpd to generate an unique device name
105105
* using ida. It is used by genpd providers which
106106
* get their genpd-names directly from FW.
107+
* GENPD_FLAG_DEFER_OFF: Defer powerdown if there are any consumer
108+
* device fwlinks indicating that some consumer
109+
* devices have not yet probed. This is useful
110+
* for power domains which are active at boot and
111+
* must not be shut down until all consumers
112+
* complete their probe sequence.
107113
*/
108114
#define GENPD_FLAG_PM_CLK (1U << 0)
109115
#define GENPD_FLAG_IRQ_SAFE (1U << 1)
@@ -114,6 +120,7 @@ struct dev_pm_domain_list {
114120
#define GENPD_FLAG_MIN_RESIDENCY (1U << 6)
115121
#define GENPD_FLAG_OPP_TABLE_FW (1U << 7)
116122
#define GENPD_FLAG_DEV_NAME_FW (1U << 8)
123+
#define GENPD_FLAG_DEFER_OFF (1U << 9)
117124

118125
enum gpd_status {
119126
GENPD_STATE_ON = 0, /* PM domain is on */

0 commit comments

Comments
 (0)