From 6a757b153a4d428bbd080f7c8e9dbcdfb22be95c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 28 Nov 2026 04:11:01 +1100 Subject: [PATCH 1/2] drm/apple: dcp: stop the internal DCP cold where the sleep's commit takes it for good On T8122 the sleep's commit powers the internal display coprocessor down and nothing starts it again after the wake (the SoC's sleep data says so: display_no_restart). Its driver stopped it cold for that commit only on the 26.6 image. On the 27.2 image (J615, MacBook Air 15-inch M3) the DCP took the ordinary suspend path: the commit then cut its power under the running firmware, and on the J615 the commit either fell through at once and the resume ran into the dead firmware (a panic a few seconds after the sleep started), or did not get going at all. Let the sleep driver say which display coprocessor its commit takes for good: apple_sleep_display_no_restart(dev) is true for the first of the sleep node's apple,display-coprocessors (the internal display) on a SoC whose sleep data has display_no_restart, during a firmware sleep. The DCP driver then stops that coprocessor cold before the commit, as it does for 26.6, and leaves it stopped until a reboot. Nothing changes for any other SoC, for external display processors, for suspend-to-idle or for a dry run. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 18 ++++++++++++------ drivers/soc/apple/sleep.c | 15 +++++++++++++++ include/linux/soc/apple/sleep.h | 8 ++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index ac0f8d7ba57da..c540345ce00f0 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -11196,15 +11196,21 @@ static void dcp_dpms_power_off(struct apple_dcp *dcp) } /* - * Internal 26.6 DCP firmware stops cold when firmware-driven deep sleep will - * cut display power, because there is no cold-restart path for it yet. In a - * sleep dry run the coprocessor is left running and takes the ordinary suspend - * path instead. + * An internal DCP's firmware stops cold when a firmware-driven deep sleep will + * cut display power and nothing restarts it after the wake: the 26.6 image, + * and the internal display coprocessor on any image where the SoC's sleep data + * says its commit powers it down for good (apple_sleep_display_no_restart(), + * the firmware-27 T8122 DCP for one). Left running, the commit takes its power + * from under it and the resume talks to firmware that is gone. In a sleep dry + * run the coprocessor is left running and takes the ordinary suspend path + * instead. */ static bool dcp_sleep_owned(struct apple_dcp *dcp) { - return IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) && dcp->fw_compat == DCP_FIRMWARE_V_26_6 && - !dcp->external && apple_sleep_commit_stops_coprocs() && !apple_sleep_dry_run(); + return IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) && + ((dcp->fw_compat == DCP_FIRMWARE_V_26_6 && !dcp->external) || + apple_sleep_display_no_restart(dcp->dev)) && + apple_sleep_commit_stops_coprocs() && !apple_sleep_dry_run(); } bool dcp_s2r_firmware_stopped(struct platform_device *pdev) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 4c25f5fd21cbf..55b1e9e2ebc2f 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1736,6 +1736,21 @@ bool apple_sleep_commit_stops_coprocs(void) } EXPORT_SYMBOL_GPL(apple_sleep_commit_stops_coprocs); +/* + * Whether this firmware sleep's commit powers @dev, the internal display coprocessor (the first + * of apple,display-coprocessors), down with no restart after the wake, as the SoC's sleep data + * says (display_no_restart). Its driver then stops it cold itself, before the commit, and leaves + * it stopped until a reboot. Any other display coprocessor isn't covered. + */ +bool apple_sleep_display_no_restart(struct device *dev) +{ + struct apple_sleep *s = READ_ONCE(apple_sleep); + + return s && dev && s->soc->display_no_restart && s->soc->ndisp && + s->display[0].np && s->display[0].np == dev->of_node && pm_suspend_via_firmware(); +} +EXPORT_SYMBOL_GPL(apple_sleep_display_no_restart); + /* This firmware sleep stops before its commit: a driver must stop nothing it can't restart. */ bool apple_sleep_dry_run(void) { diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index 9b7d29e3ef8d9..1cc538038c2ce 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -155,6 +155,9 @@ int apple_sleep_coproc_wake_error(struct device *dev); */ bool apple_sleep_commit_stops_coprocs(void); +/* This firmware sleep's commit stops @dev, the internal display CPU, for good: see sleep.c. */ +bool apple_sleep_display_no_restart(struct device *dev); + /* This firmware sleep stops before its commit: a driver must stop nothing it can't restart. */ bool apple_sleep_dry_run(void); @@ -421,6 +424,11 @@ static inline bool apple_sleep_dry_run(void) return false; } +static inline bool apple_sleep_display_no_restart(struct device *dev) +{ + return false; +} + static inline void apple_sleep_usb_set_asleep(bool asleep) { } From 66923b11b01d563ce6aa642d83d8fab27ddfc8e4 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 28 Nov 2026 05:59:19 +1100 Subject: [PATCH 2/2] drm/apple: dcp, soc: apple: sleep: stop the display after the sleep's last refusal The previous change stopped the firmware-27 T8122 internal DCP cold in its .suspend. Any later refusal (another device's .suspend, the engine's coprocessor checks, the SMC notice, a pending wakeup, SEP) then unwound to an awake Mac whose panel stays off until a reboot. The engine's own T8122 display_off has the same hole: it powers DISP_CPU down at the start of the entry, before those checks. Stop that DCP where nothing can refuse any more instead: - The DCP's suspend is the ordinary one again (firmware left running), and where the SoC's sleep data says the commit powers this display down for good (apple_sleep_display_no_restart()), it registers a last stop with the sleep engine, in its first pass of stops (as the GPU registers): RTKit AP/IOP idle, polled with interrupts off, the receive bit off and its run bit cleared. - The engine does not count such a readied internal display as a running coprocessor at its refusal check, and powers it down (display_off) only right after that first pass of stops, past the last refusal and still before the wake is armed and macOS's off words drop. A failure there goes on to the commit, as a failed coprocessor stop does. - The DCP's .resume asks apple_sleep_coproc_stopped(): a committed sleep stopped the firmware, which stays stopped until a reboot, as on 26.6; a refused one resumes it as usual. - apple_sleep.refuse_late=1 (test only, one sleep) refuses an early_context sleep at its very last check, after every other, to row what such a refusal unwinds. The 26.6 DCP keeps its cold stop in .suspend, and an engine whose display has no readied stop keeps display_off where it was, so nothing changes for J613 26.6, for other SoCs, for external display processors, for s2idle or for a dry run. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-internal.h | 2 + drivers/gpu/drm/apple/dcp.c | 89 ++++++++++++++++++++++++---- drivers/soc/apple/sleep.c | 38 +++++++++++- 3 files changed, 116 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index ea934cff9ab65..bc134d79c49e0 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -987,6 +987,8 @@ struct apple_dcp { bool s2r_fw_down; /* Stopped cold for firmware-driven sleep, with no restart until reboot. */ bool sleep_cold_stopped; + /* The sleep engine stops it after its last refusal, see dcp_commit_stop_arm(). */ + bool commit_stop_armed; /* * Its last system suspend left the firmware running and its domains on * (wakeup path), see dcp_sleep_keeps_firmware(). Cleared by the next diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index c540345ce00f0..95616735d9c69 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -11196,21 +11196,79 @@ static void dcp_dpms_power_off(struct apple_dcp *dcp) } /* - * An internal DCP's firmware stops cold when a firmware-driven deep sleep will - * cut display power and nothing restarts it after the wake: the 26.6 image, - * and the internal display coprocessor on any image where the SoC's sleep data - * says its commit powers it down for good (apple_sleep_display_no_restart(), - * the firmware-27 T8122 DCP for one). Left running, the commit takes its power - * from under it and the resume talks to firmware that is gone. In a sleep dry - * run the coprocessor is left running and takes the ordinary suspend path - * instead. + * Internal 26.6 DCP firmware stops cold when firmware-driven deep sleep will + * cut display power, because there is no cold-restart path for it yet. In a + * sleep dry run the coprocessor is left running and takes the ordinary suspend + * path instead. */ static bool dcp_sleep_owned(struct apple_dcp *dcp) { - return IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) && - ((dcp->fw_compat == DCP_FIRMWARE_V_26_6 && !dcp->external) || - apple_sleep_display_no_restart(dcp->dev)) && - apple_sleep_commit_stops_coprocs() && !apple_sleep_dry_run(); + return IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) && dcp->fw_compat == DCP_FIRMWARE_V_26_6 && + !dcp->external && apple_sleep_commit_stops_coprocs() && !apple_sleep_dry_run(); +} + +/* Interrupts off, one CPU, after the sleep's last refusal: the idle pair and receive off. */ +static int dcp_commit_stop(void *data) +{ + struct apple_dcp *dcp = data; + struct apple_rtkit *rtk = dcp->rtk ?: dcp_v26_rtkit(dcp); + void __iomem *control = dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL; + unsigned int us; + int ret = -ENODEV; + + if (!IS_ERR_OR_NULL(rtk)) { + ret = apple_rtkit_sleep_idle_polled(rtk, control, &us); + apple_rtkit_mailbox_recv_off(rtk); + } + /* Registered first, it clears its run bit itself, twice as the engine does. */ + writel(readl(control) & ~APPLE_DCP_COPROC_CPU_CONTROL_RUN, control); + writel(readl(control) & ~APPLE_DCP_COPROC_CPU_CONTROL_RUN, control); + + return ret; +} + +/* + * Any other internal DCP whose firmware a firmware-driven deep sleep's commit + * powers down for good, as the SoC's sleep data says + * (apple_sleep_display_no_restart(), the firmware-27 T8122 DCP for one): its + * suspend is the ordinary one, which leaves the firmware running, and the + * sleep engine idles and stops it after the sleep's last refusal + * (dcp_commit_stop()), in its first pass of coprocessor stops, before the + * wake is armed and macOS's off words drop, then powers the display down. + * A sleep refused before then resumes it as usual; one that got that far + * has stopped it, and it stays stopped until a reboot. If the stop can't be registered the + * firmware is left running and the engine refuses the sleep. + */ +static void dcp_commit_stop_arm(struct apple_dcp *dcp) +{ + int ret; + + if (!IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) || dcp->external || + !apple_sleep_display_no_restart(dcp->dev) || !apple_sleep_commit_stops_coprocs() || + apple_sleep_dry_run()) + return; + ret = apple_sleep_coproc_register_first(dcp->dev, dcp_commit_stop, dcp); + if (ret) { + dev_warn(dcp->dev, "no stop registered for the sleep's commit (%d): the sleep is refused\n", + ret); + return; + } + apple_sleep_coproc_set_ready(dcp->dev, true); + dcp->commit_stop_armed = true; +} + +/* True when the sleep's commit stopped the firmware (dcp_commit_stop_arm()). */ +static bool dcp_commit_stop_disarm(struct apple_dcp *dcp) +{ + bool stopped; + + if (!dcp->commit_stop_armed) + return false; + dcp->commit_stop_armed = false; + stopped = apple_sleep_coproc_stopped(dcp->dev); + apple_sleep_coproc_unregister(dcp->dev); + + return stopped; } bool dcp_s2r_firmware_stopped(struct platform_device *pdev) @@ -11510,6 +11568,7 @@ static int dcp_platform_suspend(struct device *dev) dcp_sleep_hold_phys(dcp); /* Last: the steps above still talk to the coprocessor. */ dcp_hold_for_sleep(dcp); + dcp_commit_stop_arm(dcp); return 0; } @@ -11533,6 +11592,12 @@ static int dcp_platform_resume(struct device *dev) if (dcp_v27_sleep_selected(dcp) && READ_ONCE(dcp->sleep_v27_closed)) return dcp_v27_sleep_resume(dcp); + if (dcp_commit_stop_disarm(dcp)) { + dev_warn(dev, "display coprocessor stopped by the sleep's commit; panel stays off until reboot\n"); + WRITE_ONCE(dcp->quiescing, true); + WRITE_ONCE(dcp->sleep_cold_stopped, true); + } + /* Stopped cold, with no restart path until reboot. */ if (READ_ONCE(dcp->sleep_cold_stopped)) return 0; diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 55b1e9e2ebc2f..0771b865ca1cc 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1198,6 +1198,19 @@ static bool apple_sleep_dry(const struct apple_sleep *s) return s->soc->early_context ? s->dry_run : !READ_ONCE(sleep_untested_commit); } +/* + * The internal display of a SoC whose commit powers it down for good (display_no_restart), with + * its coprocessor's stop registered first and readied by its driver: the engine runs that stop + * in its first pass, after the last refusal, and only then powers the display down, so a + * sleep refused before that leaves the display running. Otherwise the display goes down at the + * start of the entry as before. + */ +static bool sleep_display_late(struct apple_sleep *s) +{ + return s->soc->display_no_restart && s->soc->ndisp && s->display[0].np && + !apple_sleep_dry(s) && apple_sleep_coproc_ready_node(s->display[0].np); +} + /* * Untested SoCs: each step of a sleep in PMU scratch, readable after a reset. J815's ADT * pmu-main info-scrpad is 0x8000 + 0x2800; aurora-silicon/linux#1664 (T6041) notes its steps @@ -1981,6 +1994,12 @@ const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) } EXPORT_SYMBOL_GPL(apple_sleep_smc_policy); +/* One sleep, then it clears itself: what a sleep refused at its very last check unwinds. */ +static bool sleep_refuse_late; +module_param_named(refuse_late, sleep_refuse_late, bool, 0644); +MODULE_PARM_DESC(refuse_late, + "TEST ONLY: refuse the next early_context sleep at its last check, after every other"); + static bool sleep_j813_smc_late = true; module_param_named(j813_smc_late, sleep_j813_smc_late, bool, 0444); MODULE_PARM_DESC(j813_smc_late, @@ -3672,6 +3691,9 @@ static int apple_sleep_refuse(struct apple_sleep *s) dev_info(s->dev, "dry run: the display coprocessor is left running; a sleep that commits stops it cold, until a reboot\n"); continue; } + /* Stopped after the last refusal: sleep_display_late(). */ + if (i == 0 && sleep_display_late(s)) + continue; dev_err(s->dev, "refused: a bound display coprocessor is still running\n"); refused = true; } @@ -6371,6 +6393,7 @@ static int apple_sleep_enter_dry(struct apple_sleep *s) static int apple_sleep_enter_prepare(struct apple_sleep *s) { const char *step = "SoC check"; + bool late_display; int ret; if (s->soc->ops->check) { @@ -6387,7 +6410,8 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s) if (apple_sleep_dry(s)) return apple_sleep_enter_dry(s); ret = apple_sleep_cpus_hold(s); - if (!ret) { + late_display = sleep_display_late(s); + if (!ret && !late_display) { step = "display prepare"; if (s->soc->regions) s->regs_staged = true; @@ -6420,6 +6444,11 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s) step = "wakeup pending"; ret = -EBUSY; } + if (!ret && xchg(&sleep_refuse_late, false)) { + step = "test: refuse_late"; + ret = -EBUSY; + dev_info(s->dev, "test: refused at the last check (refuse_late)\n"); + } if (ret && s->soc->regions) dev_info(s->dev, "refused at .enter: %s: %d\n", step, ret); if (!ret && s->soc->ops->display_stop) { @@ -6443,6 +6472,13 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s) /* No returning error path below this point. */ if (!s->soc->ops->display_stop) apple_sleep_coprocs_stop(s, true); + /* Its driver's stop ran just above; past the last refusal, a failure goes on. */ + if (late_display) { + ret = s->soc->ops->display_off(s); + if (ret) + dev_err(s->dev, "display power-down past the last refusal failed: %d\n", + ret); + } if (!s->soc->own_wake) { sleep_wake_arm(s); s->wake_masks_saved = true;