Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions drivers/pmdomain/apple/pmgr-pwrstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ struct apple_pmgr_ps {
/* Hardware auto-managed domain armed early at boot (apple,auto-managed). */
bool auto_managed;
bool inherited_on;
/* Left clock gated by the boot loader: power gated at sync_state if still unused. */
bool boot_clkgated;
bool no_auto_enable;
bool needs_reset_idle_wait;
bool strict_state;
Expand Down Expand Up @@ -1103,24 +1101,6 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev)
ps->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP;
}

/*
* genpd registers a domain that is not on as off, and never powers off a domain it
* holds off. A boot loader can leave one clock gated: still powered, and with no
* consumer to raise it, nothing gates it, through system sleep too. Note a domain
* settled there, both target and actual clock gated and no transition pending; one
* on its way to another state is left as it is. It is gated at sync_state, once its
* consumers have probed (apple_pmgr_ps_sync_state()), not here: a consumer may yet
* take over state the boot loader left in it.
*/
if (!active && !(ps->genpd.flags & GENPD_FLAG_ALWAYS_ON)) {
u32 reg;

ps->boot_clkgated = !regmap_read(regmap, ps->offset, &reg) &&
FIELD_GET(APPLE_PMGR_PS_TARGET, reg) == APPLE_PMGR_PS_CLKGATE &&
FIELD_GET(APPLE_PMGR_PS_ACTUAL, reg) == APPLE_PMGR_PS_CLKGATE &&
!(reg & APPLE_PMGR_BUSY);
}

/* Turn on auto-PM if the domain is already on, unless it must stay off */
if (active && !ps->firmware_owned && !ps->inherited_on &&
!ps->no_auto_enable && !ps->auto_managed)
Expand Down Expand Up @@ -1792,48 +1772,12 @@ static const struct dev_pm_ops apple_pmgr_ps_pm_ops = {
NOIRQ_SYSTEM_SLEEP_PM_OPS(apple_pmgr_ps_suspend_noirq, apple_pmgr_ps_resume_noirq)
};

/*
* All of the domain's direct consumers have probed (fw_devlink). A leaf domain the boot
* loader left clock gated that no consumer has raised since and that is still clock gated
* has nothing that uses it: power gate it, so the hardware matches what genpd holds.
* Skip domains that have subdomains: fw_devlink calls sync_state on a parent as soon as
* its child apple-pmgr-pwrstate devices probe, before those subdomains' own consumers
* probe and while a child may still be left clock gated in hardware.
*/
static void apple_pmgr_ps_sync_state(struct device *dev)
{
struct apple_pmgr_ps *ps = dev_get_drvdata(dev);
unsigned long flags;
u32 reg;

of_genpd_sync_state(dev->of_node);
if (!ps || !ps->boot_clkgated)
return;

spin_lock_irqsave(&ps->genpd.slock, flags);
ps->boot_clkgated = false;
if (ps->genpd.status == GENPD_STATE_OFF && !atomic_read(&ps->genpd.sd_count) &&
list_empty(&ps->genpd.parent_links) &&
!regmap_read(ps->regmap, ps->offset, &reg) &&
FIELD_GET(APPLE_PMGR_PS_TARGET, reg) == APPLE_PMGR_PS_CLKGATE &&
FIELD_GET(APPLE_PMGR_PS_ACTUAL, reg) == APPLE_PMGR_PS_CLKGATE &&
!(reg & APPLE_PMGR_BUSY)) {
dev_dbg(dev, "PS %s: boot clock gated and unused, power gating it\n",
ps->genpd.name);
if (apple_pmgr_ps_set(&ps->genpd, APPLE_PMGR_PS_PWRGATE, false))
dev_warn(dev, "PS %s: cannot power gate it, left as it is\n",
ps->genpd.name);
}
spin_unlock_irqrestore(&ps->genpd.slock, flags);
}

static struct platform_driver apple_pmgr_ps_driver = {
.probe = apple_pmgr_ps_probe,
.driver = {
.name = "apple-pmgr-pwrstate",
.of_match_table = apple_pmgr_ps_of_match,
.pm = pm_sleep_ptr(&apple_pmgr_ps_pm_ops),
.sync_state = apple_pmgr_ps_sync_state,
},
};

Expand Down
50 changes: 5 additions & 45 deletions tools/testing/selftests/drivers/apple/pmgr-inherited.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only OR MIT
"""Run production PMGR probe admission (inherited and boot-loader state) against host register mocks."""
"""Run production inherited PMGR admission against host register mocks."""
import os
from pathlib import Path
import re
Expand Down Expand Up @@ -63,7 +63,6 @@ def main():
#define dev_err(...) ((void)0)
#define dev_dbg(...) ((void)0)
#define dev_info(...) ((void)0)
#define dev_warn(...) ((void)0)
#define dev_err_ratelimited(...) ((void)0)
#define dev_err_probe(dev,err,...) (err)
#define usleep_range(...) ((void)0)
Expand All @@ -79,14 +78,10 @@ def main():
struct platform_device { struct device dev; };
struct dev_pm_ops { int (*runtime_suspend)(struct device *); };
struct dev_pm_domain { struct dev_pm_ops ops; };
struct list_head { struct list_head *next, *prev; };
static inline bool list_empty(const struct list_head *h) { return h->next == h; }
struct generic_pm_domain {
struct dev_pm_domain domain;
const char *name;
unsigned flags, status, slock;
int sd_count;
struct list_head parent_links;
int (*power_on)(struct generic_pm_domain *), (*power_off)(struct generic_pm_domain *);
};
struct of_phandle_args { struct device_node *np; int args_count, args[8]; };
Expand Down Expand Up @@ -158,18 +153,14 @@ def main():
{ (void)d; (void)flags; return calloc(1,s); }
static void *driver_data;
static void platform_set_drvdata(struct platform_device *p, void *v) { (void)p; driver_data=v; }
static void *dev_get_drvdata(struct device *d) { (void)d; return driver_data; }
#define atomic_read(p) (*(p))
static unsigned genpd_sync_count;
static void of_genpd_sync_state(struct device_node *n) { (void)n; genpd_sync_count++; }
static int regmap_read(struct regmap *m, u32 offset, u32 *v)
{ (void)offset; m->reads++; *v=m->value; return m->error; }
static int regmap_update_bits(struct regmap *m, u32 offset, u32 mask, u32 val)
{ (void)offset; m->writes++; m->value=(m->value&~mask)|val; return 0; }
#define regmap_read_poll_timeout_atomic(m,o,v,cond,delay,bound) \
(regmap_read(m,o,&v) ?: ((cond) ? 0 : -ETIMEDOUT))
static int pm_genpd_init(struct generic_pm_domain *g, void *gov, bool off)
{ (void)gov; g->parent_links.next=&g->parent_links; g->parent_links.prev=&g->parent_links; init_count++; initialized_off=off; return 0; }
{ (void)g; (void)gov; init_count++; initialized_off=off; return 0; }
static int of_genpd_add_provider_simple(struct device_node *n, struct generic_pm_domain *g)
{ (void)n; (void)g; provider_count++; return 0; }
static void pm_genpd_remove_device(struct device *d) { (void)d; }
Expand All @@ -192,7 +183,7 @@ def main():
"apple_pmgr_ps_power_off", "apple_pmgr_reset_assert", "apple_pmgr_reset_deassert",
"apple_pmgr_reset_reset", "apple_pmgr_reset_status", "apple_pmgr_reset_xlate",
"apple_pmgr_ps_hold_parents", "apple_pmgr_ps_release_parents",
"apple_pmgr_ps_always_on", "apple_pmgr_ps_probe", "apple_pmgr_ps_sync_state"]
"apple_pmgr_ps_always_on", "apple_pmgr_ps_probe"]
tests = r'''
static void clean(u32 value, int error)
{ map=(struct regmap){ .value=value, .error=error }; init_count=provider_count=reset_count=0;
Expand Down Expand Up @@ -268,42 +259,11 @@ def main():
assert(!map.reads && !map.writes);
free(driver_data); driver_data=NULL;
puts("ok 4 - contradictory policy fails before MMIO; firmware policy remains unchanged");
struct device_node plain={ .name="power-controller@428", .status=true };
struct device pd={ .of_node=&plain };
/* Settled clock gated (target and actual 4, not busy): noted at probe, not touched. */
assert(!probe(&plain,0x44,0) && !map.writes && initialized_off);
ps=driver_data; assert(ps->boot_clkgated);
/* sync_state: still off, no subdomain on, still clock gated: gated once, then never again. */
genpd_sync_count=0; ps->genpd.status=GENPD_STATE_OFF;
apple_pmgr_ps_sync_state(&pd);
assert(genpd_sync_count==1 && map.writes==1 && !ps->boot_clkgated);
apple_pmgr_ps_sync_state(&pd); assert(map.writes==1);
/* Consumer raised it, subdomain on, subdomain attached (off), or state moved: left alone. */
for (int c=0; c<4; c++) {
struct list_head child_link;
assert(!probe(&plain,0x44,0)); ps=driver_data; assert(ps->boot_clkgated);
ps->genpd.status=GENPD_STATE_OFF;
if (c==0) ps->genpd.status=1;
if (c==1) ps->genpd.sd_count=1;
if (c==2) map.value=0x4f;
if (c==3) { ps->genpd.parent_links.next=&child_link; child_link.prev=&ps->genpd.parent_links; }
apple_pmgr_ps_sync_state(&pd);
assert(!map.writes && !ps->boot_clkgated);
}
/* On its way on, already gated, or mid-transition: not noted, sync_state leaves it. */
const u32 untouched[]={0x4f,0x00,0x40,0x04,0x44|APPLE_PMGR_BUSY};
for(unsigned i=0;i<sizeof(untouched)/sizeof(*untouched);i++) {
assert(!probe(&plain,untouched[i],0) && !map.writes && initialized_off);
ps=driver_data; assert(!ps->boot_clkgated);
apple_pmgr_ps_sync_state(&pd); assert(!map.writes);
}
free(driver_data); driver_data=NULL;
puts("ok 5 - only a domain left settled clock gated and unused is power gated, at sync_state");
return 0;
}
'''
program = preamble + definitions + fake_set + "\n".join(function(source,n) for n in names) + tests
print("TAP version 13\n1..6", flush=True)
print("TAP version 13\n1..5", flush=True)
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
with tempfile.TemporaryDirectory(prefix="apple-pmgr-inherited-") as temporary:
tmp=Path(temporary)
Expand All @@ -326,7 +286,7 @@ def main():
result = subprocess.run([str(tmp/"test")],capture_output=True)
if result.returncode == 0:
raise RuntimeError(f"negative control passed: {name}")
print("ok 6 - unchecked admission and unowned reset negative controls are rejected")
print("ok 5 - unchecked admission and unowned reset negative controls are rejected")
return 0


Expand Down
Loading