diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index 04efc8fd0e33f..25f2ff987a8de 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. @@ -485,7 +485,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, } @@ -538,7 +538,8 @@ impl Session { /// Whether the boot power policy sent in [`run`] lets the firmware power the GPU off on its /// own while idle. False while the firmware holds the GPU powered, so it cannot cycle power - /// between commands. + /// between commands. A retained genpd vote keeps the target active; automatic mode, where + /// PMGR has it enabled, lets the firmware change the actual state behind that vote. pub(crate) fn idle_power_off(&self) -> bool { self.adt.layout.powered.is_some() } @@ -714,17 +715,6 @@ pub(crate) fn admit( 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) -} - /// Wait for one boot control to retire, requiring stable consumer+completion indices. fn wait_boot_control( session: &Session, @@ -889,13 +879,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, @@ -914,14 +911,24 @@ 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. + // Held compute UMA managers follow the same policy (`Firmware::note_gpu_idle_if_any`). + let allow_idle = session.idle_power_off(); + init.globals.as_ref().ok_or(ENODEV)?.w32( + super::fw::initdata::GLOBALS_IDLE_POWER_OFF, + u32::from(allow_idle), + )?; regs::wmb(); - let mut policy = DevCtl::op(devctl.start); - if session.idle_power_off() { - // Let the firmware manage idle at the normal boot policy boundary (Globals +0x30 = 1). - // Held compute UMA managers follow the same policy (`Firmware::note_gpu_idle_if_any`). - policy.words[1] = 1; - } - channel::devctl_submit(session, channels, events, init, &policy, true)?; + 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 @@ -942,7 +949,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!( @@ -1124,6 +1131,7 @@ pub(crate) fn start( cfg, &session.regs, id.cores.count_ones(), + session.idle_power_off(), &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/glue.c b/drivers/gpu/drm/asahi/g16/glue.c index afab9ae961b85..8cc3e214289ff 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); @@ -332,6 +333,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 @@ -396,7 +410,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; @@ -410,6 +424,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/initdata.rs b/drivers/gpu/drm/asahi/g16/initdata.rs index fb8adad970769..401791b487881 100644 --- a/drivers/gpu/drm/asahi/g16/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/initdata.rs @@ -103,6 +103,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; @@ -308,6 +309,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 { diff --git a/drivers/gpu/drm/asahi/g16/mod.rs b/drivers/gpu/drm/asahi/g16/mod.rs index 44325be0d8db8..ac2b0bdd6529a 100644 --- a/drivers/gpu/drm/asahi/g16/mod.rs +++ b/drivers/gpu/drm/asahi/g16/mod.rs @@ -653,8 +653,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.adt.layout.powered.is_some() && 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. @@ -757,6 +758,9 @@ impl Gpu { GFP_KERNEL, )?; gpu.retain()?; + if sample_at_startup { + gpu.shared.poll_now(); + } if cfg.deep_sleep { if let Err(error) = sleep::register_pm_notify(&gpu.shared) { dev_warn!(dev.as_ref(), "G16: no sleep PM notifier ({:?})\n", error); diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index 1de5a552f2490..27b132a3b75c2 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 a9965323d04b1..e65f842eacd67 100644 --- a/drivers/gpu/drm/asahi/g16/power.rs +++ b/drivers/gpu/drm/asahi/g16/power.rs @@ -41,6 +41,8 @@ extern "C" { fn asahi_g16_clpc_gpu_set_busy(gpu: *mut c_void, permille: core::ffi::c_uint); fn asahi_g16_clpc_gpu_clear_busy(gpu: *mut c_void); 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; @@ -332,6 +334,17 @@ impl Power { self.clpc.clear_busy(); } + /// 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/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 20fce87740efb..54802a66267d8 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -933,6 +933,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); @@ -949,8 +964,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/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/asahi/t6030-pmp-supplier-tests.c b/tools/asahi/t6030-pmp-supplier-tests.c index 25239eda15281..3e0f7399c656d 100644 --- a/tools/asahi/t6030-pmp-supplier-tests.c +++ b/tools/asahi/t6030-pmp-supplier-tests.c @@ -13,17 +13,24 @@ #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; 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; @@ -36,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; @@ -136,6 +151,9 @@ 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 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; @@ -153,6 +171,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; @@ -225,6 +244,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; } @@ -259,6 +280,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) : @@ -273,6 +296,25 @@ 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); + gfx_removal = (struct of_changeset_entry){ + .action = OF_RECONFIG_REMOVE_PROPERTY, .prop = prop + }; + cs->entries.first = &gfx_removal; + remove_calls++; + return 0; +} static bool pmp_sram_ok = true; @@ -439,6 +481,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); @@ -456,6 +499,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, @@ -514,6 +558,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; @@ -556,6 +601,9 @@ 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_gpu_auto_pm; (void)gate_find_one; (void)apple_pmp_report_t6030_entry; (void)apple_pmp_report_wait_t6030_14; @@ -794,6 +842,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(); @@ -806,9 +874,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; diff --git a/tools/asahi/t6030-pmp-supplier-tests.py b/tools/asahi/t6030-pmp-supplier-tests.py index 7c70812ba9526..f9011a6c888b9 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("), @@ -150,6 +151,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);"), 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 00b2e0964fb43..ca3a580f9821a 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 @@ -538,8 +538,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.unwrap(), FW_26B123.initdata.unwrap()); 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 79b333019eb84..29b51f1bebf40 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()); } 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) { diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 2f61eb12e9196..61f76d1c23deb 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -170,10 +170,11 @@ def item(declaration): # policy, so held compute UMA managers are invalidated whenever that policy lets the firmware # power the GPU off on its own (`note_gpu_idle_if_any`). boot_run_fn = item_in((production.parent / 'boot.rs').read_text(), 'fn run(') -assert boot_run_fn.count('.words[1] = ') == 1, boot_run_fn +assert boot_run_fn.count('DevCtl::idle_power_off(') == 1, boot_run_fn assert ( - boot_run_fn.index('if session.idle_power_off() {') - < boot_run_fn.index('policy.words[1] = 1;') + boot_run_fn.index('let allow_idle = session.idle_power_off();') + < boot_run_fn.index('u32::from(allow_idle),') + < boot_run_fn.index('&DevCtl::idle_power_off(allow_idle),') < boot_run_fn.index('wait_boot_control(session, channels, events, init, base + 2') ), 'the final boot control must follow the power policy the idle check reads' note_gpu_idle_fn = item('fn note_gpu_idle_if_any(')