From 98d103b8a5b473e26ed7da819a21f92b3687019c Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 30 Nov 2026 07:14:29 -0500 Subject: [PATCH 1/5] drm/asahi: allow firmware-managed GFX idle power-off The shared G15/G16 runtime sends device-control opcode 0x0a with a zero argument at startup. This requests a wake and keeps the GPU on. On the G15S handoff the boot loader also forces the GFX power domain active while the GPU lacks a PMP supplier. When the kernel supplies that missing link, release the matching power-domain hold in the same changeset. At GPU admission check that PMGR permits automatic power and the runtime has a handoff guard for powered-register accesses. Release the bootstrap hold in the final policy command and persist the value for firmware re-import. Give the cores the longer of the two successive idle intervals and Fender the shorter interval. This keeps short gaps between submissions warm while retaining the full-domain idle budget. On J773g the domain gated at about 42 ms in 16/16 post-fence windows and the 2 ms and 20 ms wake latencies returned to their control levels. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/boot.rs | 55 ++++++++++++------- drivers/gpu/drm/asahi/g16/fw/channels.rs | 16 ++++-- drivers/gpu/drm/asahi/g16/fw/initdata.rs | 21 ++++++- drivers/gpu/drm/asahi/g16/initdata.rs | 7 +++ drivers/soc/apple/display-gate.c | 15 +++++ .../drivers/gpu/asahi-m4/check-abi-26b123.rs | 11 +++- .../drivers/gpu/asahi-m4/check-channels.rs | 11 +++- 7 files changed, 105 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index 5864452f42fa3..e6c4ed802e6cf 100644 --- a/drivers/gpu/drm/asahi/g16/boot.rs +++ b/drivers/gpu/drm/asahi/g16/boot.rs @@ -7,7 +7,7 @@ //! holds the PMP AGX vote (25G83; 26B123 sends none), prepares owned objects and publishes //! context0 while ASC RUN is clear. //! It negotiates RTKit protocol12, accepts only the inherited EP1 crash buffer, then submits -//! initdata plus the consume-only NOP and policy (re-import Globals, start; 0x1a, 0x34 and +//! initdata plus the consume-only NOP and policy (re-import Globals, idle power-off; 0x1a, 0x34 and //! 0x0a on 25G83, 0x19, 0x35 and 0x0a on 26B123). Control+0x14 and exact retired indices //! qualify READY; no M3 firmware constants or device-control sequence are reused. //! Firmware-reachable backing and the RTKit cookie remain retained until reboot. @@ -469,6 +469,7 @@ impl Rtkit { /// The result of admission: everything probe-time checks established, nothing written. pub(crate) struct Admitted { + allow_idle: bool, pub(crate) regs: regs::Regs, pub(crate) adt: KBox, } @@ -485,7 +486,7 @@ pub(crate) struct Session { /// The PPL handoff page, mapped here only to read the firmware's powered flag /// ([`hw::FwLayout::powered`]); `None` when the firmware keeps the GPU powered. handoff: Option, - /// True once cold boot (`START`) has completed and the firmware may idle-power-off the GPU. + /// True once cold boot has completed and runtime device-control writes need the power guard. booted: bool, } @@ -700,18 +701,11 @@ pub(crate) fn admit( cfg.chip_id, regs.asc_control()? ); - Ok(KBox::init(init!(Admitted { regs, adt }), GFP_KERNEL)?) -} - -/// Posts one device control with only the opcode and waits for it. -fn devctl_op( - session: &mut Session, - channels: &mut Channels, - events: &mut Events, - init: &InitData, - opcode: u32, -) -> Result { - channel::devctl_submit(session, channels, events, init, &DevCtl::op(opcode), true) + // A retained genpd vote keeps the target active. Automatic mode lets the + // firmware change the actual state behind that vote. + const PMGR_AUTO_ENABLE: u32 = 1 << 28; + let allow_idle = adt.layout.powered.is_some() && power_state & PMGR_AUTO_ENABLE != 0; + Ok(KBox::init(init!(Admitted { regs, adt, allow_idle }), GFP_KERNEL)?) } /// Wait for one boot control to retire, requiring stable consumer+completion indices. @@ -878,13 +872,20 @@ fn run( let base = 1; let scheduler = init.control.as_ref().ok_or(EINVAL)?; let scheduler_word = init.firmware_data().scheduler; - devctl_op(session, channels, events, init, devctl.import_globals)?; + channel::devctl_submit( + session, + channels, + events, + init, + &DevCtl::op(devctl.import_globals), + true, + )?; wait_boot_control(session, channels, events, init, base + 1, 5000)?; let pending = scheduler.r32(scheduler_word)?; if kind == hw::Start::MacOs27_2 { // The InitData request (1) can still be pending here on 26B123: the firmware consumes it // when it powers the GPU up or recovers, and the boot records need not power it up. Post - // START with it pending; never stack a second request. + // the idle policy with it pending; never stack a second request. if pending > 1 { channels.log_stop( session, @@ -903,8 +904,23 @@ fn run( } scheduler.w32(scheduler_word, 1)?; } + // Bootstrap needs the GPU awake while the host publishes its channel indices. + // Release that hold only where the runtime guards powered-register accesses. + // Keep the backing policy in sync so a firmware re-import preserves idle gating. + let allow_idle = init.allow_idle; + init.globals.as_ref().ok_or(ENODEV)?.w32( + super::fw::initdata::GLOBALS_IDLE_POWER_OFF, + u32::from(allow_idle), + )?; regs::wmb(); - devctl_op(session, channels, events, init, devctl.start)?; + channel::devctl_submit( + session, + channels, + events, + init, + &DevCtl::idle_power_off(allow_idle), + true, + )?; wait_boot_control(session, channels, events, init, base + 2, 2000)?; let receive_kick = if g15s_channels { hw::engine::G15S_RECEIVE_DOORBELL @@ -925,7 +941,7 @@ fn run( || channels.devctl.write()? != base + 2 || (kind == hw::Start::Wake25G83 && scheduler.r32(scheduler_word)? != 0) { - channels.log_stop(session, init, "boot controls not settled after START"); + channels.log_stop(session, init, "boot controls not settled after idle policy"); return Err(EBUSY); } dev_info!( @@ -984,7 +1000,7 @@ pub(crate) fn start( cfg: &'static Config, shared: &Arc, ) -> Result> { - let Admitted { regs, adt } = KBox::into_inner(admitted); + let Admitted { regs, adt, allow_idle } = KBox::into_inner(admitted); let d: ARef = shared.dev.clone(); // Cold ownership must hold before the PMP vote as well as immediately before RUN. if regs.asc_control()? & regs::ASC_RUN != 0 { @@ -1107,6 +1123,7 @@ pub(crate) fn start( cfg, &session.regs, id.cores.count_ones(), + allow_idle, &mut objects, )?); if let Some((init, _, _)) = built.as_ref() { diff --git a/drivers/gpu/drm/asahi/g16/fw/channels.rs b/drivers/gpu/drm/asahi/g16/fw/channels.rs index 395b82134bcdb..e37b10850cd65 100644 --- a/drivers/gpu/drm/asahi/g16/fw/channels.rs +++ b/drivers/gpu/drm/asahi/g16/fw/channels.rs @@ -53,8 +53,8 @@ impl SubmitRecord { pub(crate) mod devctl { /// Re-import Globals. pub(crate) const IMPORT_GLOBALS: u32 = 0x34; - /// Start. - pub(crate) const START: u32 = 0x0a; + /// Set the firmware idle power-off policy. + pub(crate) const IDLE_POWER_OFF: u32 = 0x0a; /// Initial no-op, staged before the initdata doorbell. pub(crate) const NOP: u32 = 0x1a; /// PB growth reply. @@ -64,23 +64,20 @@ pub(crate) mod devctl { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) struct Opcodes { pub(crate) import_globals: u32, - pub(crate) start: u32, pub(crate) nop: u32, pub(crate) grow_reply: u32, } pub(crate) const V25G83: Opcodes = Opcodes { import_globals: IMPORT_GLOBALS, - start: START, nop: NOP, grow_reply: GROW_REPLY, }; - /// 26B123 device-control opcodes (re-import Globals 0x35, start 0x0a, no-op 0x19, + /// 26B123 device-control opcodes (re-import Globals 0x35, no-op 0x19, /// PB growth reply 7). pub(crate) const V26B123: Opcodes = Opcodes { import_globals: 0x35, - start: 0x0a, nop: 0x19, grow_reply: 7, }; @@ -102,6 +99,13 @@ impl DevCtl { Self { words } } + /// A zero argument wakes the GPU and holds it on. One permits firmware-managed idle. + pub(crate) fn idle_power_off(allow: bool) -> Self { + let mut record = Self::op(devctl::IDLE_POWER_OFF); + record.words[1] = u32::from(allow); + record + } + /// The opcode. pub(crate) const fn opcode(&self) -> u32 { self.words[0] diff --git a/drivers/gpu/drm/asahi/g16/fw/initdata.rs b/drivers/gpu/drm/asahi/g16/fw/initdata.rs index ab15e9d40e53b..8168cd291eb9c 100644 --- a/drivers/gpu/drm/asahi/g16/fw/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/fw/initdata.rs @@ -19,6 +19,9 @@ pub(crate) const OBJECT_COUNT: usize = 31; pub(crate) const LOADER_COUNT: usize = 42; pub(crate) const LOADER_STRIDE: usize = 0x28; +/// Globals word imported by firmware at boot and recovery. Zero holds the GPU awake. +pub(crate) const GLOBALS_IDLE_POWER_OFF: usize = 0x30; + /// Stable positions in the firmware's object inventory. pub(crate) mod id { pub(crate) const ROOT: usize = 0; @@ -559,6 +562,20 @@ const fn runs_fit(runs: &[Run], size: usize) -> bool { true } +// 25G83 offsets; later layouts move both delay words together. +const CORE_IDLE_OFF_DELAY: usize = 0x9b8; +const FENDER_IDLE_OFF_DELAY: usize = 0x9bc; +const SHORT_IDLE_MS: u32 = 2; +const LONG_IDLE_MS: u32 = 40; + +/// The core and Fender off timers run in sequence. Use the longer interval +/// before core power-off so a short gap between submissions can resume at once. +/// The complete domain still falls idle after the same total interval. +pub(crate) fn set_runtime_idle_delays(layout: &Layout, globals: &mut [u8]) -> Result<(), ()> { + put32(globals, remap(layout.globals, CORE_IDLE_OFF_DELAY, 4)?, LONG_IDLE_MS)?; + put32(globals, remap(layout.globals, FENDER_IDLE_OFF_DELAY, 4)?, SHORT_IDLE_MS) +} + /// Fixed 25G83 GLOBALS words remapped into every ABI; shared by `encode_for` and `layout_fits`. const GLOBALS_FIXED: &[(usize, u32)] = &[ (0x78, 1), @@ -567,8 +584,8 @@ const GLOBALS_FIXED: &[(usize, u32)] = &[ (0x998, 40), (0x99c, 10), (0x9a0, 250), - (0x9b8, 2), - (0x9bc, 40), + (CORE_IDLE_OFF_DELAY, SHORT_IDLE_MS), + (FENDER_IDLE_OFF_DELAY, LONG_IDLE_MS), (0x9c0, 5), // Firmware DM2 (compute) progress-watchdog thresholds (~4 ms/tick): // - 0x9c8 (26B123 0x9cc): secondary DM2 soft-preempt watchdog, raised from 40 (~0.16 s) diff --git a/drivers/gpu/drm/asahi/g16/initdata.rs b/drivers/gpu/drm/asahi/g16/initdata.rs index 0fedb4d9d0f8b..a23cc02aac428 100644 --- a/drivers/gpu/drm/asahi/g16/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/initdata.rs @@ -18,6 +18,8 @@ use super::object::{Class, FwObject, Objects, Placement, Request}; /// Firmware graph handles. The small root.Control and large FirmwareData are /// intentionally separate: only the former carries the READY acknowledgement. pub(crate) struct InitData { + /// The admitted power domain and handoff support firmware-managed idle. + pub(crate) allow_idle: bool, /// The firmware ABI these objects were encoded for. pub(crate) abi: FwAbi, pub(crate) layout: &'static wire::Layout, @@ -103,6 +105,7 @@ pub(crate) fn build( cfg: &super::Config, regs: &super::regs::Regs, enabled_cores: u32, + allow_idle: bool, objects: &mut Objects, ) -> Result<(InitData, Channels, u32)> { let abi = adt.layout.abi; @@ -307,6 +310,9 @@ pub(crate) fn build( .ok_or(EINVAL)?, GFP_KERNEL, )?; + if allow_idle { + wire::set_runtime_idle_delays(layout, &mut images[id::GLOBALS]).map_err(|()| EINVAL)?; + } // Host startup policy: Main and PowerPerformance contain the top row, but the // published selectors remain S1 until the thermal owner admits a raise. for at in layout.pstate_selectors { @@ -325,6 +331,7 @@ pub(crate) fn build( ); Ok(( InitData { + allow_idle, abi, layout, globals: Some(graph[id::GLOBALS].clone()), diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index c5d17e78eaa6a..621d9290725ce 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -981,6 +981,21 @@ static int __init gate_gpu_pmp_link(struct of_changeset *cs, struct device_node ret = -EINVAL; else if (!linked) ret = of_changeset_add_prop_u32(cs, gpu, "apple,pmp", pmp->phandle); + + /* + * The G16 boot handoff removes the PMP link and forces GFX on for + * cold start. When this changeset supplies the link, let PMGR + * follow the running firmware's idle requests. Keep the policy of + * a tree that already provided its own GPU supplier. + */ + if (!ret && !linked && of_property_present(gpu, "apple,g16-handoff-version")) { + struct device_node *domain = of_parse_phandle(gpu, "power-domains", 0); + struct property *hold = of_find_property(domain, "apple,no-auto-pm", NULL); + + if (hold) + ret = of_changeset_remove_property(cs, domain, hold); + of_node_put(domain); + } of_node_put(linked); out: of_node_put(gpu); diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs index 710decfdd57f4..346cf403bd62c 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-abi-26b123.rs @@ -523,8 +523,15 @@ fn catalog() { assert_eq!(FW_26B123.leaves.map(|l| l.len()), Some(0)); // Device control. let (a, b) = (FwAbi::V25G83.devctl(), FwAbi::V26B123.devctl()); - assert_eq!((a.import_globals, a.start, a.nop, a.grow_reply), (0x34, 0x0a, 0x1a, 7)); - assert_eq!((b.import_globals, b.start, b.nop, b.grow_reply), (0x35, 0x0a, 0x19, 7)); + assert_eq!((a.import_globals, a.nop, a.grow_reply), (0x34, 0x1a, 7)); + assert_eq!((b.import_globals, b.nop, b.grow_reply), (0x35, 0x19, 7)); + for layout in [&wire::V26B123, &wire::G15S_26B123] { + let mut globals = vec![0u8; layout.object_size[wire::id::GLOBALS]]; + wire::set_runtime_idle_delays(layout, &mut globals).unwrap(); + assert_eq!(&globals[0x9bc..0x9c0], &40u32.to_le_bytes()); + assert_eq!(&globals[0x9c0..0x9c4], &2u32.to_le_bytes()); + assert_eq!(&globals[0x30..0x34], &[0; 4]); + } // FirmwareData, selectors, register map. let (v25, v26) = (FW_25G83.initdata, FW_26B123.initdata); let (d25, d26) = (&v25.firmware_data, &v26.firmware_data); diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-channels.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-channels.rs index 2ef3e8fd5fe7a..37c1d2fc5de61 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-channels.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-channels.rs @@ -41,12 +41,19 @@ fn main() { let expected=std::fs::read(&args[1]).unwrap(); if let Some(off)=got.iter().zip(&expected).position(|(a,b)|a!=b){panic!("channel/graph differs at{off:#x}: C={:#x},Rust={:#x}",expected[off],got[off]);} assert_eq!(got.len(),expected.len()); - assert_eq!((channels::devctl::NOP,channels::devctl::IMPORT_GLOBALS,channels::devctl::START),(0x1a,0x34,0x0a)); + use channels::devctl::{IDLE_POWER_OFF, IMPORT_GLOBALS, NOP}; + assert_eq!((NOP, IMPORT_GLOBALS, IDLE_POWER_OFF), (0x1a, 0x34, 0x0a)); assert_eq!(backend_hw::engine::DEVCTL_DOORBELL,0x0084000000000011); assert_eq!((backend_hw::ep::FIRMWARE,backend_hw::ep::DOORBELL,backend_hw::ep::INITDATA),(0x20,0x21,0x0081000000000000)); - for op in [channels::devctl::NOP,channels::devctl::IMPORT_GLOBALS,channels::devctl::START] { + for op in [NOP, IMPORT_GLOBALS, IDLE_POWER_OFF] { let record=channels::DevCtl::op(op);assert_eq!(record.opcode(),op);let bytes=record.to_bytes(); assert_eq!(&bytes[..4],&op.to_le_bytes());assert!(bytes[4..].iter().all(|&v|v==0)); } + for allow in [false, true] { + let bytes = channels::DevCtl::idle_power_off(allow).to_bytes(); + assert_eq!(&bytes[..4], &0x0au32.to_le_bytes()); + assert_eq!(&bytes[4..8], &u32::from(allow).to_le_bytes()); + assert!(bytes[8..].iter().all(|&v| v == 0)); + } println!("1080 submit records/kicks and4queue/context/context-one notifier images / {} bytes match qualified C; initial device-control opcodes pass",got.len()); } From 10f8b8e30822e4bb114a5fc1a67a56fed93558e7 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 30 Nov 2026 09:20:17 -0500 Subject: [PATCH 2/5] drm/asahi: keep the idle decision local to firmware startup Admission decides whether the domain can idle. Only InitData setup and the final boot control consume that decision. Pass it directly to both steps. Keeping a copy in the firmware graph changed field offsets in the submission, polling and retirement paths even though they never read that flag. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/boot.rs | 3 ++- drivers/gpu/drm/asahi/g16/initdata.rs | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index e6c4ed802e6cf..634ca9b270ab2 100644 --- a/drivers/gpu/drm/asahi/g16/boot.rs +++ b/drivers/gpu/drm/asahi/g16/boot.rs @@ -782,6 +782,7 @@ fn run( built: &mut (InitData, Channels, u32), cfg: &Config, log_buffer: Option<(u64, usize)>, + allow_idle: bool, ) -> Result { let dev = session.dev.clone(); let (init, channels, _) = built; @@ -907,7 +908,6 @@ fn run( // Bootstrap needs the GPU awake while the host publishes its channel indices. // Release that hold only where the runtime guards powered-register accesses. // Keep the backing policy in sync so a firmware re-import preserves idle gating. - let allow_idle = init.allow_idle; init.globals.as_ref().ok_or(ENODEV)?.w32( super::fw::initdata::GLOBALS_IDLE_POWER_OFF, u32::from(allow_idle), @@ -1166,6 +1166,7 @@ pub(crate) fn start( built.as_mut().ok_or(EINVAL)?, cfg, log_buffer, + allow_idle, )?; session.booted = true; Ok(()) diff --git a/drivers/gpu/drm/asahi/g16/initdata.rs b/drivers/gpu/drm/asahi/g16/initdata.rs index a23cc02aac428..80958f7efe595 100644 --- a/drivers/gpu/drm/asahi/g16/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/initdata.rs @@ -18,8 +18,6 @@ use super::object::{Class, FwObject, Objects, Placement, Request}; /// Firmware graph handles. The small root.Control and large FirmwareData are /// intentionally separate: only the former carries the READY acknowledgement. pub(crate) struct InitData { - /// The admitted power domain and handoff support firmware-managed idle. - pub(crate) allow_idle: bool, /// The firmware ABI these objects were encoded for. pub(crate) abi: FwAbi, pub(crate) layout: &'static wire::Layout, @@ -331,7 +329,6 @@ pub(crate) fn build( ); Ok(( InitData { - allow_idle, abi, layout, globals: Some(graph[id::GLOBALS].clone()), From 40178c02b870a76ce69a11a239c571aacfacc504 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 30 Nov 2026 10:34:30 -0500 Subject: [PATCH 3/5] drm/asahi: sample the startup cooling backstop across GPU idle Autonomous GFX idle also stops the firmware notifications that drive GPU housekeeping. On J773g the package stayed at 50-58 C, but the driver took just one cooling sample over eight seconds and kept the startup ceiling at S1. The first workload then spent 1.4-1.8 seconds qualifying for the top state. Arm the existing idle worker when the admitted GPU can idle and uses PMP cooling. Collect real provider readings at the thermal polling cadence while the startup backstop can still relax. Stop the extra polls on a sensor error, a warm reading, or once the independent backstop reaches the governor demand. Keep the normal protection and time checks and require a live reading for these startup observations. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/boot.rs | 2 +- drivers/gpu/drm/asahi/g16/glue.c | 23 ++++++++++++++++++- drivers/gpu/drm/asahi/g16/glue.h | 2 ++ drivers/gpu/drm/asahi/g16/mod.rs | 6 ++++- drivers/gpu/drm/asahi/g16/poll.rs | 6 ++++- drivers/gpu/drm/asahi/g16/power.rs | 13 +++++++++++ include/linux/soc/apple/pmp-cooling.h | 7 ++++++ .../gpu/asahi-m4/check-thermal-policy.c | 21 +++++++++++++++++ 8 files changed, 76 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index 634ca9b270ab2..0336133bb6f4e 100644 --- a/drivers/gpu/drm/asahi/g16/boot.rs +++ b/drivers/gpu/drm/asahi/g16/boot.rs @@ -469,7 +469,7 @@ impl Rtkit { /// The result of admission: everything probe-time checks established, nothing written. pub(crate) struct Admitted { - allow_idle: bool, + pub(super) allow_idle: bool, pub(crate) regs: regs::Regs, pub(crate) adt: KBox, } diff --git a/drivers/gpu/drm/asahi/g16/glue.c b/drivers/gpu/drm/asahi/g16/glue.c index 583dbc61d78f8..b44e5e4e20bb4 100644 --- a/drivers/gpu/drm/asahi/g16/glue.c +++ b/drivers/gpu/drm/asahi/g16/glue.c @@ -83,6 +83,7 @@ struct asahi_g16_cooling { long zone_critical_mc; bool zone_limits_valid; int zone_err; + bool startup_sampling; }; struct asahi_g16_cooling *asahi_g16_cooling_register(struct device *dev); @@ -326,6 +327,19 @@ bool asahi_g16_cooling_has_pmp(const struct asahi_g16_cooling *cooling) return cooling->pmp_node != NULL; } +/* Set before the GPU owner publishes its state. */ +bool asahi_g16_cooling_arm_startup(struct asahi_g16_cooling *cooling) +{ + cooling->startup_sampling = !!cooling->pmp_node; + return cooling->startup_sampling; +} + +/* Called under the GPU owner lock. */ +unsigned int asahi_g16_cooling_startup_poll_ms(const struct asahi_g16_cooling *cooling) +{ + return cooling->startup_sampling ? ASAHI_G16_ZONE_POLL_FAST_MS : 0; +} + /* Serialized by the GPU owner. Provider lifetime and MMIO access stay with * PMP: this consumer owns no SRAM mapping and cannot restart its firmware. * An idle GPU samples about twice a second and makes no heat, so with nothing @@ -390,7 +404,7 @@ int asahi_g16_cooling_sample(struct asahi_g16_cooling *cooling, u64 now, bool id if (!ret) { cooling->valid_ns = now; cooling->valid_mc = *temperature; - } else if (ret == -ENODATA && + } else if (ret == -ENODATA && !(idle && cooling->startup_sampling) && apple_pmp_hold_nodata(cooling->valid_ns, cooling->valid_mc, now, idle)) { *temperature = cooling->valid_mc; @@ -404,6 +418,13 @@ int asahi_g16_cooling_sample(struct asahi_g16_cooling *cooling, u64 now, bool id *power = apple_pmp_gpu_power_state(cooling->pmp); apple_pmp_cooling_observe(&cooling->policy, now, *governor); *backstop = apple_pmp_cooling_level(&cooling->policy); + /* + * Only live, cool PMP reads can advance the extra idle observations. + * Normal work drives later policy changes. + */ + if (cooling->startup_sampling && + !apple_pmp_cooling_startup_pending(&cooling->policy, *temperature, ret, *governor)) + cooling->startup_sampling = false; return ret; } diff --git a/drivers/gpu/drm/asahi/g16/glue.h b/drivers/gpu/drm/asahi/g16/glue.h index c5cd057ef405e..a1053e5c45f1a 100644 --- a/drivers/gpu/drm/asahi/g16/glue.h +++ b/drivers/gpu/drm/asahi/g16/glue.h @@ -7,6 +7,8 @@ struct device; u32 asahi_g16_timebase_hz(void); bool asahi_g16_cooling_has_pmp(const struct asahi_g16_cooling *cooling); +bool asahi_g16_cooling_arm_startup(struct asahi_g16_cooling *cooling); +unsigned int asahi_g16_cooling_startup_poll_ms(const struct asahi_g16_cooling *cooling); int asahi_g16_display_prepare(struct device *dev, const char *display_compat); #endif /* _ASAHI_G16_GLUE_H */ diff --git a/drivers/gpu/drm/asahi/g16/mod.rs b/drivers/gpu/drm/asahi/g16/mod.rs index 22201f8107ea4..ff041b5cf5a9a 100644 --- a/drivers/gpu/drm/asahi/g16/mod.rs +++ b/drivers/gpu/drm/asahi/g16/mod.rs @@ -643,8 +643,9 @@ impl Gpu { res: shared_regs::G16Resources, ) -> Result> { // Admission (probe-time checks), then the firmware start to READY. - let power = power::Power::new(dev.as_ref().as_ref())?; + let mut power = power::Power::new(dev.as_ref().as_ref())?; let admitted = boot::admit(pdev, dev, cfg, res)?; + let sample_at_startup = admitted.allow_idle && power.arm_startup_sampling(); let data = admitted.adt.data.clone(); // pin_init exposes initialized fields by name, so `dev` is shadowed after // the platform-device field. Retain the typed DRM device before that point. @@ -741,6 +742,9 @@ impl Gpu { GFP_KERNEL, )?; gpu.retain()?; + if sample_at_startup { + gpu.shared.poll_now(); + } Ok(gpu) } diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index 295b7b359d550..59e341e796372 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -94,7 +94,11 @@ impl Shared { } else if firmware.power.utilization.decaying() { super::power::policy::WINDOW_NS } else { - return; + let ms = firmware.power.startup_poll_ms(); + if ms == 0 { + return; + } + u64::from(ms) * 1_000_000 }; self.mod_poll(kernel::time::msecs_to_jiffies((delay_ns / 1_000_000) as u32).max(1)); } diff --git a/drivers/gpu/drm/asahi/g16/power.rs b/drivers/gpu/drm/asahi/g16/power.rs index e476ccb497bb2..a83ffd727c1e3 100644 --- a/drivers/gpu/drm/asahi/g16/power.rs +++ b/drivers/gpu/drm/asahi/g16/power.rs @@ -39,6 +39,8 @@ extern "C" { fn asahi_g16_clpc_gpu_get(dev: *mut c_void, out: *mut *mut c_void) -> core::ffi::c_int; fn asahi_g16_clpc_gpu_set_active(gpu: *mut c_void, active: bool); fn asahi_g16_clpc_gpu_put(gpu: *mut c_void); + fn asahi_g16_cooling_arm_startup(cooling: *mut core::ffi::c_void) -> bool; + fn asahi_g16_cooling_startup_poll_ms(cooling: *const core::ffi::c_void) -> u32; fn asahi_g16_cooling_register(dev: *mut c_void) -> *mut c_void; fn asahi_g16_cooling_unregister(cooling: *mut c_void); fn asahi_g16_cooling_has_pmp(cooling: *const c_void) -> bool; @@ -273,6 +275,17 @@ impl Power { } } + /// Arm the PMP startup check before autonomous GPU idle can stop its notifications. + pub(crate) fn arm_startup_sampling(&mut self) -> bool { + // SAFETY: the cooling object is live and the firmware state is still unpublished. + unsafe { asahi_g16_cooling_arm_startup(self.cooling.inner.as_ptr()) } + } + + pub(crate) fn startup_poll_ms(&self) -> u32 { + // SAFETY: Cooling owns this allocation and the device mutex serializes the policy. + unsafe { asahi_g16_cooling_startup_poll_ms(self.cooling.inner.as_ptr()) } + } + /// Whether the CLPC floor is held across an idle gap awaiting expiry. pub(crate) fn clpc_holding(&self) -> bool { self.clpc_hold.holding() diff --git a/include/linux/soc/apple/pmp-cooling.h b/include/linux/soc/apple/pmp-cooling.h index 6f65811188fe5..2fa997e7d4cb7 100644 --- a/include/linux/soc/apple/pmp-cooling.h +++ b/include/linux/soc/apple/pmp-cooling.h @@ -66,6 +66,13 @@ static inline unsigned int apple_pmp_cooling_level(const struct apple_pmp_coolin return s->level; } +/* Whether another valid idle observation can relax the startup backstop. */ +static inline bool apple_pmp_cooling_startup_pending(const struct apple_pmp_cooling *s, + long mc, int error, unsigned int governor) +{ + return !error && mc < APPLE_PMP_RELEASE_MC && (s->hard || s->level > governor); +} + /* Sample at the fast cadence whenever a decision could depend on it. */ static inline bool apple_pmp_cooling_fast(const struct apple_pmp_cooling *s, long mc, int error) diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-thermal-policy.c b/tools/testing/selftests/drivers/gpu/asahi-m4/check-thermal-policy.c index b5cb914e78ad6..eb96e5f0deb25 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-thermal-policy.c +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-thermal-policy.c @@ -34,6 +34,25 @@ static unsigned int selector(unsigned int configured, unsigned int cap, return result ? result : 1; } +static bool startup_observations(void) +{ + struct apple_pmp_cooling state; + unsigned int i; + + apple_pmp_cooling_init(&state); + if (!apple_pmp_cooling_startup_pending(&state, 50000, 0, 0) || + apple_pmp_cooling_startup_pending(&state, 50000, -1, 0) || + apple_pmp_cooling_startup_pending(&state, APPLE_PMP_RELEASE_MC, 0, 0)) + return false; + + for (i = 1; i <= 20 && apple_pmp_cooling_startup_pending(&state, 50000, 0, 0); i++) + apple_pmp_cooling_sample(&state, i * 250000000ULL, 50000, 0); + if (state.hard || state.level) + return false; + apple_pmp_cooling_observe(&state, i * 250000000ULL, 3); + return !apple_pmp_cooling_startup_pending(&state, 50000, 0, 3); +} + int main(void) { struct apple_pmp_cooling p; @@ -43,6 +62,8 @@ int main(void) int error; unsigned int governor, power, configured, cap, user; + if (!startup_observations()) + return 1; apple_pmp_cooling_init(&p); while (scanf(" %c %llu %ld %d %u %u %u %u %u %llu", &op, &now, &mc, &error, &governor, &power, &configured, &cap, &user, &query) == 10) { From c53b7255beeadec9a935c4e3662624cb01cfd577 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 30 Nov 2026 14:35:53 -0500 Subject: [PATCH 4/5] tools/asahi: cover GFX handoff in PMP supplier host tests The supplier harness compiles the production display-gate link helper. Model the OF lookup and removal APIs used to drop the GFX hold when adding the missing PMP link. Exercise the handoff path and check that an existing supplier or a tree without the handoff retains the hold. Signed-off-by: DjDeveloperr --- tools/asahi/t6030-pmp-supplier-tests.c | 56 +++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/tools/asahi/t6030-pmp-supplier-tests.c b/tools/asahi/t6030-pmp-supplier-tests.c index c32e373a0c702..4cf047b11dabf 100644 --- a/tools/asahi/t6030-pmp-supplier-tests.c +++ b/tools/asahi/t6030-pmp-supplier-tests.c @@ -17,12 +17,18 @@ typedef uint64_t u64; typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8; +struct property { + int unused; +}; struct device_node { const char *compatible; bool available, has_reg, has_pmp, has_report, no_ack; + bool has_g16_handoff; int reg_cells, pmp_cells, report_cells, refs; u32 reg, phandle; struct device_node *pmp, *report, *child, *sibling, *parent; + struct device_node *power_domain; + struct property *no_auto_pm; }; struct device { struct device_node *of_node; @@ -121,6 +127,8 @@ static const struct gate_soc gate_t6030 = { 6030 }, gate_t8122 = { 8122 }, other_soc = { 0 }; static const struct gate_soc *gate_soc; static struct device_node supplier_node, other_node, gpu, extra_gpu; +static struct device_node gfx_domain; +static struct property gfx_hold; static struct device_node report14, extra_report, report25, entry7, entry17; static struct device_node *nodes[9]; static struct device supplier, consumer; @@ -138,6 +146,7 @@ static struct device *pmp_device; /* Set only while the PMP is stopped for a system sleep, which this test never does. */ static bool pmp_asleep; static int pmp_lock, ready_calls, add_calls, add_result; +static int remove_calls; static int poll_calls, device_locked, power_calls, power_result, link_calls; static int find_calls, lockable, present_device, link_ok; static int case_count; @@ -210,6 +219,8 @@ static bool of_property_present(const struct device_node *node, { if (!strcmp(prop, "apple,pmp")) return node->has_pmp; + if (!strcmp(prop, "apple,g16-handoff-version")) + return node->has_g16_handoff; assert(!strcmp(prop, "apple,pmp-report")); return node->has_report; } @@ -244,6 +255,8 @@ static struct device_node *of_parse_phandle(struct device_node *node, return node->has_pmp && node->pmp_cells >= 1 ? of_node_get(node->pmp) : NULL; + if (!strcmp(prop, "power-domains")) + return of_node_get(node->power_domain); assert(!strcmp(prop, "apple,pmp-report")); return node->has_report && node->report_cells >= 1 ? of_node_get(node->report) : @@ -258,6 +271,21 @@ static int of_changeset_add_prop_u32(struct of_changeset *cs, add_calls++; return add_result; } +static struct property *of_find_property(const struct device_node *node, + const char *name, int *lenp) +{ + assert(!strcmp(name, "apple,no-auto-pm") && !lenp); + return node ? node->no_auto_pm : NULL; +} +static int of_changeset_remove_property(struct of_changeset *cs, + struct device_node *node, + struct property *prop) +{ + assert(cs && node == &gfx_domain && prop == &gfx_hold); + assert(add_calls == 1 && !add_result); + remove_calls++; + return 0; +} static struct device_node *of_get_parent(struct device_node *node) { return of_node_get(node->parent); @@ -407,6 +435,7 @@ static void balanced(void) { for (size_t i = 0; i < sizeof(nodes) / sizeof(nodes[0]); i++) assert(!nodes[i]->refs); + assert(!gfx_domain.refs); assert(!managed_start.waiters); assert(!supplier.refs && !consumer.refs && !native_report.dev.refs && !passive_report.dev.refs); @@ -424,6 +453,7 @@ static void reset(void) gpu = (struct device_node){ .compatible = "apple,agx-t6030", .available = true }; extra_gpu = (struct device_node){ 0 }; + gfx_domain = (struct device_node){ .no_auto_pm = &gfx_hold }; report14 = (struct device_node){ .compatible = "apple,t6030-pmp-v2-report", .available = true, @@ -482,6 +512,7 @@ static void reset(void) pmp_device = &supplier; pmp_data = (void *)1; ready_calls = add_calls = add_result = poll_calls = 0; + remove_calls = 0; power_calls = power_result = link_calls = find_calls = 0; gfx_check_result = gfx_check_calls = gfx_set_calls = 0; lockable = present_device = link_ok = 1; @@ -524,6 +555,8 @@ int main(void) (void)of_machine_is_compatible; (void)of_property_read_bool; (void)of_property_present; + (void)of_find_property; + (void)of_changeset_remove_property; (void)gate_find_one; (void)apple_pmp_report_t6030_entry; (void)apple_pmp_report_wait_t6030_14; @@ -743,9 +776,30 @@ int main(void) gpu.has_pmp = true; gpu.pmp_cells = 2; gpu.pmp = &supplier_node; - assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && !add_calls); + gpu.has_g16_handoff = true; + gpu.power_domain = &gfx_domain; + assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && + !add_calls && !remove_calls); balanced(); case_count++; +#if CONFIG_APPLE_T8122_GPU_PMP_LINK + /* Drop the GFX hold only on handoff and after queuing the missing link. */ + reset(); + t8122(); + gpu.power_domain = &gfx_domain; + assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && + add_calls == 1 && !remove_calls); + balanced(); + case_count++; + reset(); + t8122(); + gpu.has_g16_handoff = true; + gpu.power_domain = &gfx_domain; + assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && + add_calls == 1 && remove_calls == 1); + balanced(); + case_count++; +#endif /* Actual existing consumer link uses the exact supplier and balances refs. */ reset(); gpu.has_pmp = true; From d66b146f6903ca7ae59905cf39fba4ac3c0bd287 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 18:25:13 -0500 Subject: [PATCH 5/5] soc: apple: display-gate: drop the GFX hold once per changeset gate_gpu_pmp_link() drops apple,no-auto-pm with the link it adds for a handed-over GPU. gate_gpu_agx_entry() drops it too, through gate_gpu_auto_pm(), in the same changeset. Nothing is applied in between, so a T6030 whose PMP report has the AGX request would queue the removal twice. The second one fails with -ENODEV and takes the whole changeset, and with it the PMP, down. Skip the removal if the changeset already has it. Cover both orders in the T6030 PMP supplier host test, with a mutant. Signed-off-by: DjDeveloperr --- drivers/soc/apple/display-gate.c | 5 ++++ tools/asahi/t6030-pmp-supplier-tests.c | 37 ++++++++++++++++++++++++- tools/asahi/t6030-pmp-supplier-tests.py | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index e710de6ef1053..2e8206ef19323 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -953,8 +953,13 @@ static int __init gate_gpu_auto_pm(struct of_changeset *cs, struct device_node * { struct device_node *domain = of_parse_phandle(gpu, "power-domains", 0); struct property *prop = domain ? of_find_property(domain, "apple,no-auto-pm", NULL) : NULL; + struct of_changeset_entry *ce; int ret = 0; + /* gate_gpu_pmp_link() may have dropped it with the link: a second removal would fail. */ + list_for_each_entry(ce, &cs->entries, node) + if (ce->action == OF_RECONFIG_REMOVE_PROPERTY && ce->prop == prop) + prop = NULL; if (prop) ret = of_changeset_remove_property(cs, domain, prop); of_node_put(domain); diff --git a/tools/asahi/t6030-pmp-supplier-tests.c b/tools/asahi/t6030-pmp-supplier-tests.c index 5eae56113a2d0..f2e68fac43392 100644 --- a/tools/asahi/t6030-pmp-supplier-tests.c +++ b/tools/asahi/t6030-pmp-supplier-tests.c @@ -13,6 +13,7 @@ #define EPROBE_DEFER 517 #define PMP_REPORT_READY 1 #define DL_FLAG_AUTOREMOVE_CONSUMER 1 +#define OF_RECONFIG_REMOVE_PROPERTY 1 #define BIT_ULL(n) (1ULL << (n)) typedef uint64_t u64; typedef uint32_t u32; @@ -42,8 +43,16 @@ struct platform_device { struct device_link { int unused; }; + +struct of_changeset_entry { + struct of_changeset_entry *next; + unsigned long action; + struct property *prop; +}; struct of_changeset { - int unused; + struct { + struct of_changeset_entry *first; + } entries; }; struct gate_soc { int id; @@ -134,6 +143,7 @@ static const struct gate_soc *gate_soc; static struct device_node supplier_node, other_node, gpu, extra_gpu; static struct device_node gfx_domain; static struct property gfx_hold; +static struct of_changeset_entry gfx_removal; static struct device_node report14, extra_report, report25, entry7, entry17; static struct device_node *nodes[9]; static struct device supplier, consumer; @@ -288,6 +298,10 @@ static int of_changeset_remove_property(struct of_changeset *cs, { assert(cs && node == &gfx_domain && prop == &gfx_hold); assert(add_calls == 1 && !add_result); + gfx_removal = (struct of_changeset_entry){ + .action = OF_RECONFIG_REMOVE_PROPERTY, .prop = prop + }; + cs->entries.first = &gfx_removal; remove_calls++; return 0; } @@ -579,6 +593,7 @@ int main(void) (void)of_property_present; (void)of_find_property; (void)of_changeset_remove_property; + (void)gate_gpu_auto_pm; (void)gate_find_one; (void)apple_pmp_report_t6030_entry; (void)apple_pmp_report_wait_t6030_14; @@ -802,6 +817,26 @@ int main(void) assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && !add_calls); balanced(); case_count++; + /* A hold the link dropped is not dropped again in that changeset. */ + reset(); + cs = (struct of_changeset){ 0 }; + gpu.has_g16_handoff = true; + gpu.power_domain = &gfx_domain; + assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && + add_calls == 1 && remove_calls == 1); + assert(gate_gpu_auto_pm(&cs, &gpu) == 0 && remove_calls == 1); + balanced(); + case_count++; + /* The link left it: dropped once. */ + reset(); + cs = (struct of_changeset){ 0 }; + gpu.power_domain = &gfx_domain; + assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && + add_calls == 1 && !remove_calls); + assert(gate_gpu_auto_pm(&cs, &gpu) == 0 && remove_calls == 1); + assert(gate_gpu_auto_pm(&cs, &gpu) == 0 && remove_calls == 1); + balanced(); + case_count++; #else assert(gate_gpu_pmp_link(&cs, &supplier_node) == 0 && !find_calls); balanced(); diff --git a/tools/asahi/t6030-pmp-supplier-tests.py b/tools/asahi/t6030-pmp-supplier-tests.py index bbe8daa8a41de..74ad0fd573a32 100755 --- a/tools/asahi/t6030-pmp-supplier-tests.py +++ b/tools/asahi/t6030-pmp-supplier-tests.py @@ -96,6 +96,7 @@ def main(): assert "depends on APPLE_DISPLAY_GATE" in section parts = [function(gate, "static struct device_node *__init gate_find_one("), function(gate, "static int __init gate_gpu_pmp_link("), + function(gate, "static int __init gate_gpu_auto_pm("), function(report, "static struct device_node *apple_pmp_report_t6030_entry("), function(report, "static int apple_pmp_report_wait_t6030_14("), function(report, "int apple_pmp_report_wait_supplier_ready("), @@ -149,6 +150,7 @@ def main(): ("entry-reference", "\tof_node_put(entry);\n\tof_node_put(pmp);", "\tof_node_put(pmp);"), ("gate-config", "IS_ENABLED(CONFIG_APPLE_T6030_GPU_PMP_LINK) && gate_soc == &gate_t6030", "gate_soc == &gate_t6030"), ("gate-phandle-shape", 'of_property_count_u32_elems(gpu, "apple,pmp") != 1', "false"), + ("gate-hold-once", "&& ce->prop == prop)", "&& false)"), ("serialized-command", "\tguard(mutex)(&pmp_lock);", "\t(void)&pmp_lock;"), ("gfx-check-error", "ret = apple_pmp_report_check_t6030_gfx(pmp_device);", "ret = (apple_pmp_report_check_t6030_gfx(pmp_device), 0);"),