Skip to content

drm/asahi: stop the legacy GPU firmware at the sleep commit - #4313

Draft
JJRPF wants to merge 2 commits into
aurora-silicon:mainfrom
JJRPF:fix/asahi-g14x-legacy-s2r
Draft

JJRPF wants to merge 2 commits into
aurora-silicon:mainfrom
JJRPF:fix/asahi-g14x-legacy-s2r

Conversation

@JJRPF

@JJRPF JJRPF commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What: A J414s installed today gets the macOS 13.5 stub: aurora-installer offers every model 13.5 and has no j414s in its 27.2 list. With that stub the GPU runs the legacy backend, whose sleep_prepare() refuses every deep sleep (-EBUSY). Since #4228 makes deep the J414s default, every suspend on a stock J414s install fails and the Mac stays awake. Neither #4245's veto (only Thunderbolt registers one) nor the PCIe-C fallback in 30eef1aaf6a8 catches a refusal from a device's prepare. This gives the legacy backend the steps the 27.2 backend already takes: let running work retire, have the sleep driver stop the firmware at its commit, and warm-restart it after the wake.
Tested: J414s M2 Pro, OS firmware 13.5 / system firmware 27.2, at d87896540c36 on aurora/main efef6707019e, stock command line (no apple_sleep.*): 8/8 deep sleeps on the full desktop (boot object resumes 0 -> 8), 3 of them with two GPU clients drawing (both still running after each wake). One sleep refused before the commit (pm_test=devices) left the firmware running, with no GPU error. Afterwards: 10 CPUs, Wi-Fi, Bluetooth and audio back; suspend_stats success 9, fail 0. aurora/main without this commit on the same Mac refused its deep sleep at the GPU (genpd_prepare returns -16); the code refuses unconditionally on this backend. The previous revision (19e136dff81e on 828abb4aa624) also slept 4 x ~1 h back to back on battery (boot object resumes 8 -> 12, 0 GPU errors).
Risk: two-way door · every Mac whose GPU runs the legacy backend (G13/G14 on firmware older than 27.2) once it reaches a deep sleep; today that is the J414s on the 13.5 stub. No change to s2idle or to the 27.2, M3, G15, G16, G17 or M5 backends.
Not yet: J416s/J474s and M2 Max; M1-family legacy (T8103/T600x) once their deep sleep is enabled; a refusal after the commit (the restart path is shared with a real wake, but no test reaches it); pm_test=platform, which hung this Mac with the earlier version of this change after the GPU had already failed.

Details
  • gpu.rs, sleep_prepare(): needs the sleep driver's commit to stop coprocessors (apple_sleep_commit_stops_coprocs()), else -EBUSY as before. Waits up to 1 s for the firmware's pending-submission count to reach 0, else -EBUSY. Then registers a commit-time stop (apple_sleep_coproc_register_first()). The firmware keeps running until the commit, after every refusal, so a refused sleep has nothing to undo.
  • The stop runs at the commit with interrupts off: apple_rtkit_sleep_idle_polled(), the mailbox's receive off, ASC CPU_CONTROL run bit cleared, as in g14_v27_2_commit_stop.
  • suspend_noirq: refuses (-EBUSY) if work started after the prepare, holds the GPU power domain for the commit (asahi_sleep_pd_suspend_noirq_hold), and from then on nothing is sent to the firmware until sleep_complete().
  • sleep_complete(): unregisters the stop. A firmware that was stopped gets a warm RTKit restart, its coprocessor started again, a boot and a kick; a failed restart marks the GPU crashed. A sleep refused before the commit leaves it alone.
  • driver.rs: the legacy branch of sleep_prepare passes the ASC control register; a dry run registers the stop as a real sleep does, since the sleep driver's checks look for it; the firmware stops only at the commit, which a dry run never reaches. The G17 and other backends' branches are unchanged. Probe keeps the ASC mapping (regs::AscControl) and starts the coprocessor through it; Resources::start_cpu() is gone.
  • No firmware-version gate: the backend probe already picks the legacy manager.
  • Overlap: soc: apple: sleep: keep s2idle default on legacy GPU/DCP firmware #4207 keeps s2idle the default on T8103/T8112 with GPU firmware below 27, and edits the same None => EBUSY arm of driver.rs, so whichever lands second needs a small rebase. With this in, its GPU rule is no longer needed for the GPU's sake; its DCP below 14 rule is separate.
Evidence
  • Without (aurora/main a0e5cf151159, one deep attempt): PM: suspend entry (deep), aurora 406400000.gpu: PM: device_prepare(): genpd_prepare returns -16, PM: Some devices failed to suspend.
  • With (d87896540c36), per sleep: s2r: GPU firmware stops at the sleep commit, apple-sleep 28e080000.sleep-controller: back from sleep, boot object resumes N -> N+1, s2r: GPU firmware restarted warm (real true, idle ~2.7 ms, kick Ok(())). Walls 38/47/53/47 s idle (30/45/45/45 s alarms), 38/32/32 s under load, 32 s after the refusal (rtcwake -d rtc1 -m mem; on main rtc0 is macsmc-rtc, which has no wakeup).
  • Refused before the commit (pm_test=devices): s2r: sleep refused before the commit; GPU firmware kept running.
  • An earlier version idled the firmware at prepare and woke it after a refusal; that wake timed out (RTKit: IOP power acknowledgment failed: -62) and lost the GPU. This version doesn't idle before the commit.
  • Other messages, not from the GPU: PS prores: resync after sleep failed: -5 per wake; Bluetooth hci0: Opcode 0x0c24/0x0c01/0x0c1a failed: -110 after alternate wakes and 0x0c24 failed: -112 at the next suspend entry (the -112 also appears without this commit).
  • Logs: https://jjrpf.com/S2R/worklog (C95, C97, C98).

@JJRPF
JJRPF requested review from a team and DjDeveloperr as code owners December 4, 2026 13:01
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Merge readiness at ca44ae55: not ready yet

Check Detail
CI at head ok 4 checks passed
Review no needs one approving review from Core, Omarchy Mac or Aurora Maintainers (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA ca44ae55, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · every Mac whose GPU runs the legacy backend (G13/G14 on firmware older than 27.2) once it reaches a deep sleep; today that is the J414s on the 13.5 stub. No change to s2idle or to the 27.2, M3, G15, G16, G17 or M5 backends.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@lucasvllima

Copy link
Copy Markdown

Tested this PR on J493 (Apple MacBook Pro (13-inch, M2, 2022), T8112, G14G on 13.5 OS stub / mBoot-20457.41.3 system FW) and hit a dry-run bug in driver.rs (sleep_prepare):

Issue with if unsafe { apple_sleep_dry_run() } { return 0; }

On an .untested SoC profile (apple_sleep.deep=1, untested_commit=0), returning early before gpu.sleep_prepare(...) causes two problems:

  1. apple_sleep_coproc_register_first() / apple_sleep_coproc_set_ready(..., true) never run, so t8112_sleep_check() (and t8103_sleep_check()) immediately abort the dry run with:
    apple-sleep 23b700000.sleep: refused: the GPU's driver is bound
    
  2. self.sleep_stop remains None, so gpu.sleep_holds_pd() returns false in sleep_suspend_noirq_driver() while the legacy GPU firmware is still running.

Verification with the early return removed

Since gpu.sleep_prepare() already defers stopping the firmware until the commit (which does not run on a dry run) and sleep_complete() already handles !stopped cleanly, removing the apple_sleep_dry_run() early return (and its extern "C" declaration) fixes the dry-run path end-to-end on J493 (13.5 stub):

PM: suspend entry (deep)
aurora 206400000.gpu: s2r: GPU firmware stops at the sleep commit
apple-sleep 23b700000.sleep: 6 coprocessors up and stopped
apple-sleep 23b700000.sleep: dry run: every check passed; refusing before the first stop and the commit (untested SoC, apple_sleep.untested_commit=1 lets it through)
apple_pmp 23b500000.pmp: sleep refused before the commit: firmware never stopped
aurora 206400000.gpu: s2r: sleep refused before the commit; GPU firmware kept running
PM: suspend exit

(Also minor rebase note against current main: probe_g18 in driver.rs needs legacy: None, asc: None in its AsahiPlatformDriverData initializer.)

@DjDeveloperr

DjDeveloperr commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

@lucasvllima @JJRPF you should upgrade to 27.2 stub, 13.5 is not supported for long and S2R is designed to work only on new stub going forward

@lucasvllima

Copy link
Copy Markdown

@DjDeveloperr Got it, thanks! I'm running Omarchy (4.6 RC / linux-aurora 7.3.0) on my J493 — just to confirm: is there a recommended way today to upgrade an existing Omarchy Linux install (13.5 -> 27.2 stub) without wiping/reinstalling Linux, or should I wait for aurora-upgrade (aurora-silicon/aurora-installer#238 and aurora-silicon/aurora-installer#240) / an Omarchy installer update to land?

@JJRPF

JJRPF commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Long sleep on the same J414s (13.5 OS stub), same commit 19e136dff81e, on battery with nothing plugged in: 4 h of deep sleep, as four back-to-back sleeps of 3580 s. The PMU RTC won't take an alarm more than ~3591 s ahead (rtcwake -s 14400 gives ERANGE), so one 4 h alarm isn't possible.

  • 4/4 real sleeps, each 3582 s wall, boot object resumes 8 -> 12
  • every wake: s2r: GPU firmware stops at the sleep commit, then s2r: GPU firmware restarted warm (real true, idle ~2.7 ms, kick Ok(()))
  • after the last one: a GPU client renders, audio plays, CPUs 0-9 online, Wi-Fi and Bluetooth up, no GPU errors, suspend_stats 13 success / 0 fail for the boot
  • battery 100% before and after

On the legacy GPU backend (G13/G14 firmware older than 27.2, such as
the M2 Pro/Max G14X on the 13.5 firmware) sleep_prepare() has no
handler, so it returns -EBUSY for every deep sleep and the system
suspend fails. With the J414s defaulting to deep sleep
(apple,sleep-tested), and the installer giving a J414s the 13.5 stub,
a J414s installed today cannot suspend at all.

Give the legacy GpuManager the steps the 27.2 backend takes:

- sleep_prepare() lets submitted work retire (up to one second) and
  refuses the sleep with -EBUSY if any is still running. It then
  registers a stop with the sleep driver instead of idling the
  firmware, which keeps running until the commit, after every
  refusal.
- suspend_noirq refuses the sleep if work started after the prepare,
  keeps the GPU power domain on for the commit, and from then on
  nothing is sent to the firmware until sleep_complete().
- At the commit the stop idles the firmware by polling and clears the
  ASC run bit.
- sleep_complete() restarts a firmware that was stopped: a warm RTKit
  restart, the coprocessor started again through ASC CPU_CONTROL, a
  boot, then a kick. A sleep refused before the commit leaves it
  running, so nothing has to be woken.
- A dry run never reaches the commit, so the firmware keeps running;
  the stop is registered all the same, since the sleep driver's checks
  look for it. No other backend's behaviour changes.

The ASC control register is kept mapped for the stop and the restart,
so probe starts the coprocessor through the same mapping, and
Resources::start_cpu() goes.

Signed-off-by: Justin Pfister <git@jjrpf.com>
@JJRPF

JJRPF commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr understood that 27.2 is the target. The catch is that a J414s installed today still gets 13.5: aurora-installer offers 13.5 to every model and its 27.2 list has no j414s, and there's no in-place stub upgrade yet (aurora-installer#238 / #240). With #4228 making deep the J414s default, those installs fail every suspend until they reinstall.

If you'd rather not carry legacy GPU sleep at all, the smaller fix is for the legacy backend to register a deep veto (#4245) so those Macs go to s2idle instead. I can switch this PR to that. Which do you prefer?

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 19e136d

Failure: drivers/gpu/drm/asahi/driver.rs:296 unconditionally calls the external symbol apple_sleep_dry_run from the installed PM callback. With DRM_ASAHI=y and APPLE_SOC_SLEEP=n, Kconfig still permits the GPU driver, but the Makefile omits the only external definition. The disabled configuration's C inline stub does not emit a symbol for Rust. An isolated link of the exact Rust callback fails with undefined symbol: apple_sleep_dry_run. The base callback links without the provider, and the new callback links when the provider is present. Keep the no-SoC-sleep configuration free of that external reference.

Checked: Reviewed the three-file diff and traced PM callback registration, the ASC mapping lifetime and the commit-time stop and warm restart. The isolated test exercises the actual base and head callback bodies. The author reports eight passing J414s cycles with Apple SoC sleep enabled. The substantive hosted fork workflows were skipped.

@JJRPF
JJRPF force-pushed the fix/asahi-g14x-legacy-s2r branch from 19e136d to d878965 Compare December 4, 2026 22:17
@JJRPF

JJRPF commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@lucasvllima thanks for testing on J493 and for tracking that down. Folded in: the apple_sleep_dry_run() early return and its extern are gone, so a dry run registers the stop and marks it ready like a real sleep, and sleep_holds_pd() sees it. Also rebased onto current main (efef6707019e) with legacy: None, asc: None in probe_g18 (built with G18 on and off).

This also takes care of the review bot's point: the extern it flagged was the only new reference outside #[cfg(CONFIG_APPLE_SOC_SLEEP)], so with APPLE_SOC_SLEEP=n nothing new links against the sleep driver any more.

Retested at d87896540c36 on the J414s (13.5 stub), stock cmdline: 8/8 deep sleeps (4 idle, 3 with two GPU clients drawing, 1 after a refused sleep), the pm_test=devices refusal left the firmware running with no GPU error, suspend_stats 9/0. Body updated.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at d878965

Checked: The exact revised Rust sleep callback links and runs without the Apple SoC sleep provider. The removed helper has no remaining reference in the three changed files. The other Apple SoC sleep calls remain configuration-gated. The legacy dry run registers the stop for validation, and the firmware stop still runs through the commit hook. The G18 constructor initializes both legacy-only fields to None.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@JJRPF This branch now conflicts with main (1da341136110) in:

  • drivers/gpu/drm/asahi/driver.rs

Could you forward-merge main into this branch (normal git merge, no rebase/force-push)? If you haven't had a chance within 24 hours, a maintainer can forward-merge main on top for you.

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Dec 5, 2026
Resolve drivers/gpu/drm/asahi/driver.rs: keep the legacy backend's deep-sleep prepare, and give the remaining refusal main's warning.

Signed-off-by: Justin Pfister <git@jjrpf.com>
@JJRPF

JJRPF commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Merged current main (f02bd68a08cb) in as ca44ae5, a normal merge with no force-push. The only conflict was sleep_prepare in driver.rs: the legacy branch keeps its deep-sleep prepare, and the case that still refuses now prints main's "deep sleep refused" warning. The new legacy-firmware check in sleep.c from #4207 only looks at the T8103/T8112 GPU node, so it doesn't affect T6020. Builds clean (LLVM, arm64).

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 5, 2026
@JJRPF

JJRPF commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Holding this one, please don't merge yet. I found a problem with my own testing.

The deep sleeps above ran with a leftover appledrm module from an earlier bisect still in updates/, so the display driver in those runs wasn't main's. With main's appledrm, on the same J414s (13.5 stub, d87896540c36), a deep sleep still completes and the GPU restarts warm, but the internal panel doesn't come back:

apple-dcp 389c00000.dcp: dcp_poweron() starting
apple-dcp 389c00000.dcp: wait for power timed out, connector will be broken
apple-dcp 389c00000.dcp: set_digital_out_mode timed out

As far as I can tell, dcp_s2r_capable() only covers H17P and 27.x firmware, so the 13.5 internal DCP is only powered off for the sleep. The T6020 commit then stops its coprocessor, and nothing starts it again. Today the GPU refuses deep sleep on these Macs, so nobody hits this. With this PR merged, a J414s on the 13.5 stub would wake to a black screen.

The GPU, Wi-Fi, Bluetooth and audio results above still hold with main's appledrm. I'm working on a 13.5 internal DCP restart as a separate PR and will link it here. This should land together with it or after it. Moving this to draft until then.

@JJRPF
JJRPF marked this pull request as draft December 5, 2026 01:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants