From d172d87381f5ea2ed1a3e3654e606ee76a07f1fb Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 15 Nov 2026 22:59:54 -0500 Subject: [PATCH 1/2] drm/asahi: g17: keep the GPU's firmware session over a cancelled T6050 suspend On the T6050 the GPU's sleep step only closes publication and waits for quiet; the firmware is stopped by the sleep's commit. A suspend refused after that step, with no firmware resume, must not touch that session: marking it lost or releasing it would let the runtime worker stop the firmware, or power the GPU down, while the machine never slept. On the T6050, a cancelled sleep step now keeps the session owned and only reopens publication once the preparations have drained. A step that cannot drain, or a crashed GPU, keeps the session as it is with a warning. A second sleep step while one is still in place is refused, and a GPU that reports no device or a crash during the step is not treated as already down. The resume after a suspend that never reached a firmware resume leaves the session alone. Other G17 GPUs keep their previous behaviour. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/gpu/drm/asahi/g17/sleep.rs | 43 ++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/sleep.rs b/drivers/gpu/drm/asahi/g17/sleep.rs index 8e9ac9e86e1b5..ad9b5fee69b63 100644 --- a/drivers/gpu/drm/asahi/g17/sleep.rs +++ b/drivers/gpu/drm/asahi/g17/sleep.rs @@ -345,9 +345,27 @@ impl Shared { } } - /// Undoes everything short of a stopped firmware. A builder that never finishes would keep - /// publication closed for good, and that is a lost device. - fn sleep_cancel(self: &Arc) { + /// Undoes everything short of a stopped firmware. T6050 keeps an uncertain session owned: + /// marking it lost here would let the runtime worker stop firmware before the commit. + fn sleep_cancel(self: &Arc, commit_only: bool) { + if commit_only { + self.sleeping.store(true, Ordering::Release); + self.join_event_workers(); + let drained = self + .preparations + .wait_drained_until(super::now_ns().saturating_add(DRAIN_NS)); + if self.crashed.load(Ordering::Acquire) + || drained.is_err() + || !self.preparations.reopen() + { + dev_warn!(self.dev.as_ref(), "GPU sleep cancellation retains its session\n"); + return; + } + self.sleeping.store(false, Ordering::Release); + self.sleep_gate.store(false, Ordering::Release); + self.queue_events(); + return; + } self.sleeping.store(false, Ordering::Release); self.sleep_gate.store(false, Ordering::Release); let drained = self @@ -424,8 +442,11 @@ impl Shared { /// Closes publication, waits for quiet, and leaves the stop to the sleep's commit. A refusal /// changes nothing. - fn sleep_down(self: &Arc) -> Result { + fn sleep_down(self: &Arc, commit_only: bool) -> Result { if self.sleeping() { + if commit_only { + return Err(EBUSY); + } let mut state = self.state.lock(); if let Some(firmware) = (*state).as_deref_mut() { lower_domain(firmware); @@ -449,7 +470,8 @@ impl Shared { }); match result { Ok(()) => Ok(()), - Err(error) if error == ENODEV || self.crashed.load(Ordering::Acquire) => { + Err(error) if !commit_only && + (error == ENODEV || self.crashed.load(Ordering::Acquire)) => { // Nothing to save: let the worker finish detaching what's left, and then the // domain only has to be off for the sleep. self.sleeping.store(false, Ordering::Release); @@ -464,7 +486,7 @@ impl Shared { Ok(()) } Err(error) => { - self.sleep_cancel(); + self.sleep_cancel(commit_only); Err(error) } } @@ -540,7 +562,7 @@ impl super::Gpu { ); return Err(EBUSY); } - let result = self.shared.sleep_down(); + let result = self.shared.sleep_down(self.cfg.chip_id == 0x6050); if let Err(error) = result { dev_warn!(self.shared.dev.as_ref(), "GPU refused sleep: {:?}\n", error); } @@ -560,11 +582,16 @@ impl super::Gpu { self.shared.dev.as_ref(), "sleep refused before the commit: GPU firmware never stopped\n" ); - self.shared.sleep_cancel(); + self.shared.sleep_cancel(self.cfg.chip_id == 0x6050); return; } self.shared.sleep_settle_commit(); } + if self.cfg.chip_id == 0x6050 && !real { + // With no physical wake, even an uncertain or stopped session stays owned. + // Neither a refusal nor a missing commit receipt authorizes power or restart. + return; + } if !real && self.shared.sleep_hold() { return; } From 541d9be901a8bfe99882dfccff862d40e2d079fa Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Mon, 16 Nov 2026 06:26:33 -0500 Subject: [PATCH 2/2] drm/asahi: g17: the M5 Pro's commit stop on the J716c too On the J716c the GPU took the generic G17 commit stop, which reads the firmware's mailboxes whatever GFX's power word reads. Between jobs, under automatic power, that word can read off with the firmware still running, and the read then takes a synchronous external abort inside the sleep's last steps. Take the J714s's M5 stop there too: it raises GFX out of automatic power before the idle, reports and only lowers a GFX that is off, and leaves the gating and bridge words alone. The J716c's GPU node has the one power domain the M5 path resolves (GFX, a PMGR power word) and no PMP request, so its power word and the PMP request it withdraws are unchanged. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/gpu/drm/asahi/g17/sleep.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/sleep.c b/drivers/gpu/drm/asahi/g17/sleep.c index 7f2d4f6a92591..5f6d9e0ef3a3a 100644 --- a/drivers/gpu/drm/asahi/g17/sleep.c +++ b/drivers/gpu/drm/asahi/g17/sleep.c @@ -46,12 +46,13 @@ #define ASC_CPU_CONTROL 0x44 #define ASC_CPU_CONTROL_RUN BIT(4) -/* Only the supported M5 board needs a wrapped provider translation here. - * Other G17 clients retain their established direct-domain methods below. +/* Only the M5 boards with a deep sleep need a wrapped provider translation here: the J714s + * and the J716c. Other G17 clients retain their established direct-domain methods below. */ static bool asahi_g17_m5_provider(struct device *dev) { - return of_machine_is_compatible("apple,j714s") && + return (of_machine_is_compatible("apple,j714s") || + of_machine_is_compatible("apple,j716c")) && of_machine_is_compatible("apple,t6050") && of_device_is_compatible(dev->of_node, "apple,agx-g17s"); }