From 5303d2ffd2392345bac98986cd70164095b7a7fd Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 18:00:29 +1100 Subject: [PATCH 1/2] Revert "pmdomain: apple: pmgr-pwrstate: do not gate parent domains at sync_state" This reverts commit eb64ee5fb02cecfeebe6d296c7c26e3ba1b7f61a. Signed-off-by: Ryan Murray --- drivers/pmdomain/apple/pmgr-pwrstate.c | 12 +++++------- .../selftests/drivers/apple/pmgr-inherited.py | 11 +++-------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index 48e6dc49b02cd..bcc89eabb2c14 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -1793,12 +1793,11 @@ static const struct dev_pm_ops apple_pmgr_ps_pm_ops = { }; /* - * 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. + * All of the domain's consumers have probed (fw_devlink). A domain the boot loader left + * clock gated that no consumer has raised since, with no subdomain on and still clock + * gated, has nothing that uses it: power gate it, so the hardware matches what genpd + * holds. A consumer that took over its state raised it first; a domain whose consumer + * never probes stays as the boot loader left it. */ static void apple_pmgr_ps_sync_state(struct device *dev) { @@ -1813,7 +1812,6 @@ static void apple_pmgr_ps_sync_state(struct device *dev) 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, ®) && FIELD_GET(APPLE_PMGR_PS_TARGET, reg) == APPLE_PMGR_PS_CLKGATE && FIELD_GET(APPLE_PMGR_PS_ACTUAL, reg) == APPLE_PMGR_PS_CLKGATE && diff --git a/tools/testing/selftests/drivers/apple/pmgr-inherited.py b/tools/testing/selftests/drivers/apple/pmgr-inherited.py index 54973a75ed0ca..77bc6a11afd20 100755 --- a/tools/testing/selftests/drivers/apple/pmgr-inherited.py +++ b/tools/testing/selftests/drivers/apple/pmgr-inherited.py @@ -79,14 +79,11 @@ 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]; }; @@ -169,7 +166,7 @@ def main(): #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; } @@ -278,15 +275,13 @@ def main(): 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; + /* A consumer raised it, a subdomain is on, or it moved on since probe: left alone. */ + for (int c=0; c<3; c++) { 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); } From 740315a5c846352efc1b224833bc06e2b2d44b11 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 18:00:39 +1100 Subject: [PATCH 2/2] Revert "Merge pull request #3668 from aurora-silicon/satchlj/pmgr-gate-clockgated" This reverts commit 1d9a2ac0, reversing changes made to its first parent. It resets the 14-inch M1 Pro MacBook Pro (J316s, T6000) at the first s2idle cycle: the boot's journal ends mid-suspend with nothing logged and the Mac restarts. Reproduced three times on one-shot boots (main a171afd2 with #3668's head, the same tree plus #3689, and main cf03d96b, which also has eb64ee5f); the same tree with #3668 reverted suspends and wakes 2/2, as does the older saved kernel. Revert both until a version that keeps the T6000 sleep path powered is shown on that Mac. Rows and the A/B are on #3668. Signed-off-by: Ryan Murray --- drivers/pmdomain/apple/pmgr-pwrstate.c | 54 ------------------- .../selftests/drivers/apple/pmgr-inherited.py | 43 ++------------- 2 files changed, 4 insertions(+), 93 deletions(-) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index bcc89eabb2c14..bd1be40ac76a6 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -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; @@ -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, ®) && - 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) @@ -1792,46 +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 consumers have probed (fw_devlink). A domain the boot loader left - * clock gated that no consumer has raised since, with no subdomain on and still clock - * gated, has nothing that uses it: power gate it, so the hardware matches what genpd - * holds. A consumer that took over its state raised it first; a domain whose consumer - * never probes stays as the boot loader left it. - */ -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) && - !regmap_read(ps->regmap, ps->offset, ®) && - 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, }, }; diff --git a/tools/testing/selftests/drivers/apple/pmgr-inherited.py b/tools/testing/selftests/drivers/apple/pmgr-inherited.py index 77bc6a11afd20..36a4ca738e011 100755 --- a/tools/testing/selftests/drivers/apple/pmgr-inherited.py +++ b/tools/testing/selftests/drivers/apple/pmgr-inherited.py @@ -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 @@ -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) @@ -83,7 +82,6 @@ def main(): struct dev_pm_domain domain; const char *name; unsigned flags, status, slock; - int sd_count; 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]; }; @@ -155,10 +153,6 @@ 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) @@ -189,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; @@ -265,40 +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); - /* A consumer raised it, a subdomain is on, or it moved on since probe: left alone. */ - for (int c=0; c<3; c++) { - 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; - 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;iboot_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) @@ -321,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