diff --git a/drivers/gpu/drm/asahi/Kconfig b/drivers/gpu/drm/asahi/Kconfig index d383802ee8825..c440219020779 100644 --- a/drivers/gpu/drm/asahi/Kconfig +++ b/drivers/gpu/drm/asahi/Kconfig @@ -95,6 +95,18 @@ config DRM_ASAHI_M3_T8122 boards and firmware do not gain automatic admission. Other GPUs are not affected. +config DRM_ASAHI_G14_V27_2 + bool "Apple M2 (G14G) on GPU firmware 27.2, compute only" + depends on DRM_ASAHI + # The firmware's UAT is adopted through the G15 backend's handoff helpers. + depends on DRM_ASAHI_G15 + default y + help + Start an M2 GPU (G14G) whose boot loader reports GPU firmware + 27.2, and register a compute-only DRM device on it. Clients use + the 26.x submission interface; render commands are refused. + Other GPUs and firmware versions are not affected. + config DRM_ASAHI_G15 bool "Apple M3 Pro/Max (G15) support" depends on DRM_ASAHI diff --git a/drivers/gpu/drm/asahi/asahi_core.rs b/drivers/gpu/drm/asahi/asahi_core.rs index 5f180203f8369..e0de39368342d 100644 --- a/drivers/gpu/drm/asahi/asahi_core.rs +++ b/drivers/gpu/drm/asahi/asahi_core.rs @@ -27,7 +27,7 @@ mod g18; #[cfg(CONFIG_DRM_ASAHI_M5)] mod m5; mod gpu; -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] mod g14_v27_2; mod hw; mod initdata; diff --git a/drivers/gpu/drm/asahi/driver.rs b/drivers/gpu/drm/asahi/driver.rs index ae25ebbd5255b..03ffba4433a86 100644 --- a/drivers/gpu/drm/asahi/driver.rs +++ b/drivers/gpu/drm/asahi/driver.rs @@ -54,7 +54,7 @@ pub(crate) struct AsahiPlatformDriverData<'bound> { pub(crate) g16: Option>, m3: Option, /// The G14 firmware-27.2 backend, whose firmware must be stopped on unbind. - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: Option>, /// Raw `struct device *` of the platform device. Stored once at probe /// time so the `Drop` impl can find the sysfs file on unregister. @@ -275,7 +275,7 @@ unsafe extern "C" fn sleep_prepare(dev: *mut bindings::device) -> core::ffi::c_i // G14 on firmware 27.2: the firmware keeps running through suspend-to-idle, with nothing in // flight; a sleep that powers the SoC down would lose it, and it has no cold restart, so that // is refused. - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] if let Some(backend) = data.g14_v27_2.as_ref() { // SAFETY: Reads a global flag word. if unsafe { bindings::pm_suspend_via_firmware() } { @@ -297,7 +297,7 @@ unsafe extern "C" fn sleep_prepare(dev: *mut bindings::device) -> core::ffi::c_i unsafe extern "C" fn sleep_complete(dev: *mut bindings::device) { // SAFETY: Called by the PM core. let data = unsafe { sleep_data(dev) }; - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] if let Some(backend) = data.g14_v27_2.as_ref() { backend.sleep_complete(); } @@ -356,7 +356,7 @@ impl platform::Driver for AsahiPlatformDriver { if let Some(m3) = this.m3.as_ref() { m3.stop(); } - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] if let Some(backend) = this.g14_v27_2.as_ref() { backend.stop(); } @@ -396,9 +396,9 @@ impl platform::Driver for AsahiPlatformDriver { let version: Option> = pdev.as_ref().fwnode().ok_or(EIO)? .property_read_array_vec(c"apple,firmware-version", 3)?.optional(); if version.as_deref() == Some(&[27, 2, 0]) { - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] return AsahiPlatformDriver::probe_g14_v27_2(pdev, cfg); - #[cfg(not(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122)))] + #[cfg(not(CONFIG_DRM_ASAHI_G14_V27_2))] return Err(ENODEV); } } @@ -484,7 +484,7 @@ impl platform::Driver for AsahiPlatformDriver { _reg: reg, g17: None, m3: None, - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: None, #[cfg(CONFIG_DRM_ASAHI_G16)] g16: None, @@ -499,7 +499,7 @@ impl platform::Driver for AsahiPlatformDriver { impl AsahiPlatformDriver { /// G14 with firmware 27.2: start the firmware and register a compute-only DRM device. - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] fn probe_g14_v27_2<'bound>( pdev: &'bound platform::Device>, cfg: &'static hw::HwConfig, @@ -559,7 +559,7 @@ impl AsahiPlatformDriver { _reg: reg, g17: None, m3: None, - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: None, #[cfg(CONFIG_DRM_ASAHI_G16)] g16: None, @@ -603,7 +603,7 @@ impl AsahiPlatformDriver { _reg: reg, g17: None, m3: Some(backend), - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: None, raw_dev: core::ptr::null_mut(), raw_stats: core::ptr::null_mut(), @@ -681,7 +681,7 @@ impl AsahiPlatformDriver { _reg: reg, g17: Some(gpu), m3: None, - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: None, #[cfg(CONFIG_DRM_ASAHI_G16)] g16: None, @@ -730,7 +730,7 @@ impl AsahiPlatformDriver { _reg: reg, g17: None, m3: None, - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: None, #[cfg(CONFIG_DRM_ASAHI_G16)] g16: None, @@ -771,7 +771,7 @@ impl AsahiPlatformDriver { _reg: reg, g17: None, m3: None, - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: None, g16: Some(gpu), raw_dev, @@ -829,7 +829,7 @@ impl AsahiPlatformDriver { _reg: reg, g17: None, m3: None, - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] g14_v27_2: None, #[cfg(CONFIG_DRM_ASAHI_G16)] g16: None, @@ -864,7 +864,7 @@ impl Drop for AsahiPlatformDriverData<'_> { if let Some(m3) = self.m3.as_ref() { m3.stop(); } - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] if let Some(backend) = self.g14_v27_2.as_ref() { backend.stop(); } diff --git a/drivers/gpu/drm/asahi/event.rs b/drivers/gpu/drm/asahi/event.rs index a993bca69f507..dbea26792b6c0 100644 --- a/drivers/gpu/drm/asahi/event.rs +++ b/drivers/gpu/drm/asahi/event.rs @@ -54,7 +54,7 @@ pub(crate) type Event = slotalloc::Guard; pub(crate) struct EventValue(u32); impl EventValue { - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) fn raw(self) -> u32 { self.0 } @@ -205,7 +205,7 @@ impl EventManager { } /// Reserve the normal stamp pair for a kernel queue that polls its own completion. - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) fn try_get_polled(&self) -> Result { self.alloc.try_get(None) } diff --git a/drivers/gpu/drm/asahi/g14_v27_2.rs b/drivers/gpu/drm/asahi/g14_v27_2.rs index 773693a0cdfcb..1f6b8a0359b35 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2.rs @@ -6,7 +6,8 @@ //! installs the driver's kernel window in the loader's UAT regions, starts the ASC, holds the //! GPU powered and retires one kernel-owned compute job. [`Backend`] then serves clients //! through the 26.x submission front end (`m3_submit`): each compute command is encoded in the -//! 27.2 layout and published, in order, on the root's queue. Render commands are refused. +//! 27.2 layout and published, in order, on the root's queue. Render commands are refused, and the device +//! reports `DRM_ASAHI_FEATURE_COMPUTE_ONLY`. //! //! The runtime is driven by the firmware's endpoint-0x20 notifications, which it sends after //! publishing records on its event, statistics and log rings: each one runs the service, which @@ -830,9 +831,12 @@ impl gpu::Gpu for Backend { Ok(()) } fn supports_vm_status(&self) -> bool { true } + /// Render commands are refused (`m3_submit`), so the device also reports itself + /// compute-only: graphics userspace then leaves it alone instead of failing its first render. fn feature_flags(&self) -> u64 { uapi::drm_asahi_feature_DRM_ASAHI_FEATURE_VM_STATUS as u64 | uapi::drm_asahi_feature_DRM_ASAHI_FEATURE_SCHEDULED_QUEUES as u64 + | uapi::DRM_ASAHI_FEATURE_COMPUTE_ONLY as u64 } fn tracked_submission(&self) -> bool { true } fn base_clock_hz(&self) -> u32 { ::base_clock_hz(&self.graph) } diff --git a/drivers/gpu/drm/asahi/gpu.rs b/drivers/gpu/drm/asahi/gpu.rs index 2166a7e3dce1e..e9b715aeca980 100644 --- a/drivers/gpu/drm/asahi/gpu.rs +++ b/drivers/gpu/drm/asahi/gpu.rs @@ -112,9 +112,9 @@ pub(crate) const fn init_message(address: u64) -> u64 { } /// The G14 firmware-27.2 root and the records only it uses. -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] mod v27_2; -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) use v27_2::*; const RX_WORK_PENDING: u32 = 1 << 0; @@ -140,7 +140,7 @@ const DOORBELL_DEVCTRL: u64 = 0x11; const IOVA_KERN_PRIV_RANGE: Range = 0xffffffa000000000..0xffffffa600000000; /// The G14 firmware-27.2 timestamp aperture, inside the private range: the private allocator /// stays below it in that profile. -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] const IOVA_G14_V27_2_TIMESTAMP_RANGE: Range = 0xffffffa181400000..0xffffffa185400000; /// Private (cached) GPU-RO firmware structure VA range base. const IOVA_KERN_GPU_RO_RANGE: Range = 0xffffffa600000000..0xffffffa800000000; @@ -200,7 +200,7 @@ pub(crate) enum GraphProfile { Native, /// The G14 firmware-27.2 root (gpu/v27_2.rs) built on these records: no register /// mappings, and the private range ends below that firmware's timestamp aperture. - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] G14V27_2, } @@ -712,7 +712,7 @@ impl GpuManager::ver { let dyncfg = Self::make_dyncfg(dev, res, cfg, &uat)?; let private_end = match profile { GraphProfile::Native => IOVA_KERN_PRIV_RANGE.end, - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] GraphProfile::G14V27_2 => IOVA_G14_V27_2_TIMESTAMP_RANGE.start, }; diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index 8db6c0ded49fd..720c2fd425d3b 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -37,9 +37,6 @@ const TRACE_RECORDS: u32 = 512; const RING_RECORDS: u32 = 256; /// Queue capacity at position block +0x50 (16 x the 0x50 channels). const QUEUE_CAPACITY: u32 = 0x500; -/// Upper performance-state cap, in hundredths, at globals +0x98: the first state above idle. -/// Only this cap has run on hardware. -const STATE_CAP: u32 = 100; /// Board facts the root needs, read from the device tree at probe. pub(crate) struct BoardV27_2 { @@ -119,6 +116,8 @@ fn encode_compute( put64(cmd, 0x334, timestamps + 0x20); put32(stream, 0, 11); + // 13.5 StartCompute.unk_28, at the same place in this layout (the 13.5 G14 path writes 1). + put32(stream, 0x28, 1); put64(stream, 0x160, job.sequence); put64(stream, 0x04, cmd_va + 0x18); put64(stream, 0x0c, cmd_va + 0x68); @@ -810,7 +809,7 @@ impl RootV27_2 { data[offset..offset + 2].copy_from_slice(&value.to_le_bytes()); } let ceiling = pwr.perf_max_pstate * 100; - for (at, value) in [(0x84, pwr.max_power_mw), (0x88, ceiling), (0x8c, ceiling), (0x98, STATE_CAP)] { + for (at, value) in [(0x84, pwr.max_power_mw), (0x88, ceiling), (0x8c, ceiling), (0x98, ceiling)] { put32(data, at, value); } put32(data, 0x6e, 1); @@ -942,6 +941,11 @@ impl RootV27_2 { for (word, value) in policy[0x62b8..0x62f8].chunks_exact_mut(4).zip(cfg.shared3_tab) { word.copy_from_slice(&value.to_le_bytes()); } + // The temperature alarm's service floor, the word before its per-state thresholds (13.5 + // HwDataShared3 places it there too). The alarm runs only in states at or above the + // floor. Nothing on the machine describes the alarm's hysteresis or retry interval, so + // keep it off: a floor of the DT state count lies above every state. + put32(policy, 0x62b4, pwr.perf_states.len() as u32); // Cold-wake operand: the board's base operating point. put32(policy, 0xa4, pwr.perf_base_pstate); for (source, bits) in [ diff --git a/drivers/gpu/drm/asahi/hw/mod.rs b/drivers/gpu/drm/asahi/hw/mod.rs index 2fd17c298d68d..934c52380c43d 100644 --- a/drivers/gpu/drm/asahi/hw/mod.rs +++ b/drivers/gpu/drm/asahi/hw/mod.rs @@ -123,7 +123,7 @@ pub(crate) struct PowerZone { } /// Base of a window in the firmware 27.2 register table. -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] #[derive(Debug, Copy, Clone)] pub(crate) enum RegisterBaseV27_2 { /// A fixed physical address. @@ -133,7 +133,7 @@ pub(crate) enum RegisterBaseV27_2 { } /// One record of the firmware 27.2 register table: 60 slots, each naming one window. -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] #[derive(Debug, Copy, Clone)] pub(crate) struct RegisterV27_2 { pub(crate) slot: usize, diff --git a/drivers/gpu/drm/asahi/hw/t8112.rs b/drivers/gpu/drm/asahi/hw/t8112.rs index 1879be7f8cead..d22238d90247b 100644 --- a/drivers/gpu/drm/asahi/hw/t8112.rs +++ b/drivers/gpu/drm/asahi/hw/t8112.rs @@ -105,7 +105,7 @@ pub(crate) const HWCONFIG: super::HwConfig = HwConfig { sram_size: None, }; -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] const fn reg(slot: usize, base: RegisterBaseV27_2, size: u32, relative: u64, install: Option) -> RegisterV27_2 { RegisterV27_2 { slot, base, size, relative, install } } @@ -113,7 +113,7 @@ const fn reg(slot: usize, base: RegisterBaseV27_2, size: u32, relative: u64, ins /// The firmware 27.2 register table. Writable windows outside SGX are left unmapped, except /// the push-telemetry window (slot 9), which the firmware shares with the PMP; it is mapped /// apart from the others. -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) const REGISTERS_V27_2: &[RegisterV27_2] = { use RegisterBaseV27_2::{Physical, Sgx}; &[ @@ -136,7 +136,7 @@ pub(crate) const REGISTERS_V27_2: &[RegisterV27_2] = { }; /// Slots of the 27.2 register table whose stock mode is read-write. -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) const WRITABLE_V27_2: u64 = { let mut mask = 0u64; let mut slot = 0; diff --git a/drivers/gpu/drm/asahi/m3/m3_client.rs b/drivers/gpu/drm/asahi/m3/m3_client.rs index c1a07d61120d1..7d9169fe1ecc0 100644 --- a/drivers/gpu/drm/asahi/m3/m3_client.rs +++ b/drivers/gpu/drm/asahi/m3/m3_client.rs @@ -63,7 +63,7 @@ pub(crate) fn admit_vm_for( let refusals = REFUSALS.fetch_add(1, Ordering::Relaxed).saturating_add(1); if refusals <= REFUSALS_LOGGED { let task = kernel::current!(); - let comm = task_comm(task); + let comm = super::m3_submit::task_comm(task); let len = comm.iter().position(|&b| b == 0).unwrap_or(comm.len()); let name = core::str::from_utf8(&comm[..len]).unwrap_or("?"); let last = if refusals == REFUSALS_LOGGED { @@ -87,19 +87,6 @@ pub(crate) fn admit_vm_for( } } -/// The name of `task`, for log lines only. -pub(crate) fn task_comm(task: &kernel::task::Task) -> [u8; 16] { - let mut name = [0u8; 16]; - // SAFETY: `comm` is a fixed-size array inside the live task. It is read byte by byte with - // volatile loads because a concurrent rename may change it; a torn name is only printed. - unsafe { - let comm = core::ptr::addr_of!((*task.as_ptr()).comm).cast::(); - for (i, byte) in name.iter_mut().enumerate() { - *byte = comm.add(i).read_volatile(); - } - } - name -} /// Bytes at the start of a compute control stream whose launch records are checked. const LAUNCH_WINDOW: usize = 4096; diff --git a/drivers/gpu/drm/asahi/m3/m3_submit.rs b/drivers/gpu/drm/asahi/m3/m3_submit.rs index b8a377264be8f..df0a26e4babc9 100644 --- a/drivers/gpu/drm/asahi/m3/m3_submit.rs +++ b/drivers/gpu/drm/asahi/m3/m3_submit.rs @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT //! Bounded M3 compute and graphics submissions through the common DRM scheduler/syncobjs. use kernel::{c_str,dma_fence::*,drm::sched,prelude::*,sync::{Arc,Mutex},new_mutex,xarray}; -use crate::{file,m3::agx_uapi,mmu,queue,m3::m3_drm::Shared}; +use crate::{file,m3::agx_uapi,mmu,queue}; +#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] +use crate::m3::m3_drm::Shared; use crate::alloc::Allocator as _; use core::sync::atomic::{AtomicBool, Ordering}; #[derive(Default)] @@ -59,7 +61,12 @@ pub(crate) struct Packet { } /// The runtime a queue's packets go to: the M3 runtime or the G14 firmware-27.2 compute runtime. #[derive(Clone)] -pub(crate) enum Sink { M3(Shared), G14V27_2(Arc) } +pub(crate) enum Sink { + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] + M3(Shared), + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] + G14V27_2(Arc), +} /// The process and thread that submitted a packet, recorded in the submit ioctl. Only logged: /// a renamed task leaves a stale name, which is harmless. #[derive(Copy,Clone)] @@ -68,8 +75,7 @@ impl Owner { fn current()->Self { let task=kernel::current!(); let leader=task.group_leader(); - Self {pid:leader.pid(),process:crate::m3::m3_client::task_comm(leader), - thread:crate::m3::m3_client::task_comm(task)} + Self {pid:leader.pid(),process:task_comm(leader),thread:task_comm(task)} } fn name(comm:&[u8;16])->&str { let len=comm.iter().position(|&b|b==0).unwrap_or(comm.len()); @@ -78,6 +84,19 @@ impl Owner { pub(crate) fn process(&self)->&str {Self::name(&self.process)} pub(crate) fn thread(&self)->&str {Self::name(&self.thread)} } +/// The name of `task`, for log lines only. +pub(crate) fn task_comm(task: &kernel::task::Task) -> [u8; 16] { + let mut name = [0u8; 16]; + // SAFETY: `comm` is a fixed-size array inside the live task. It is read byte by byte with + // volatile loads because a concurrent rename may change it; a torn name is only printed. + unsafe { + let comm = core::ptr::addr_of!((*task.as_ptr()).comm).cast::(); + for (i, byte) in name.iter_mut().enumerate() { + *byte = comm.add(i).read_volatile(); + } + } + name +} impl Packet { pub(crate) fn profile_id(&self)->usize {self as *const Self as usize} pub(crate) fn timestamp_addresses(&self,index:usize)->[u64;2] { @@ -113,9 +132,12 @@ impl Packet { // nonzero: GEM closes otherwise accumulate across completed frames. // Signalling an error is not retirement. crate::m3::agx_memory::publish(); + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] let profile=crate::debug::debug_enabled(crate::debug::DebugFlags::M3PassTiming); + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] let before=if profile {crate::m3::m3_runtime::physical_counter()} else {0}; self.completion.signal(); + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] if profile { let after=crate::m3::m3_runtime::physical_counter(); let status=match result {Ok(())=>0,Err(e)=>e.to_errno()}; @@ -136,7 +158,9 @@ impl sched::JobImpl for Job { // Queue the packet and return its fence; the completion worker publishes and retires // it, so the scheduler can hand over further ready jobs meanwhile. let submitted=match &job.shared { + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] Sink::M3(shared)=>crate::m3::m3_runtime::Runtime::submit(shared,job.packet.clone()), + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] Sink::G14V27_2(runtime)=>runtime.submit(job.packet.clone()), }; if let Err(e)=submitted { @@ -147,8 +171,10 @@ impl sched::JobImpl for Job { Ok(Some(Fence::from_fence(&job.packet.completion))) } fn timed_out(job:&mut JobTimeout,_finished:bool)->sched::Status { - let shared=match &job.shared { - Sink::M3(shared)=>shared.clone(), + match job.shared.clone() { + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] + Sink::M3(shared)=>Self::timed_out_m3(shared,job), + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] Sink::G14V27_2(runtime)=>{ // The runtime's own command timeout fails a hung GPU; a healthy one is late. // Run its service once, so a hang is found without a notification. @@ -156,9 +182,23 @@ impl sched::JobImpl for Job { if runtime.healthy() {return sched::Status::NoHang;} runtime.withdraw(&job.packet); job.packet.finish(Err(EIO)); - return sched::Status::NoDevice; + sched::Status::NoDevice } - }; + } + } + fn cancel(job:&mut Self) { + match &job.shared { + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] + Sink::M3(shared)=>{crate::m3::m3_runtime::Runtime::withdraw(shared,&job.packet);} + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] + Sink::G14V27_2(runtime)=>runtime.withdraw(&job.packet), + } + job.packet.finish(Err(ECANCELED)); + } +} +#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] +impl Job { + fn timed_out_m3(shared:Shared,job:&mut JobTimeout)->sched::Status { // Retain the publishing branch's explicit diagnostic override. if !crate::m3::m3_params::timeout_nohang() { if let Some(r)=Option::as_mut(&mut *shared.lock()) {r.health().mark_failed();} @@ -180,13 +220,6 @@ impl sched::JobImpl for Job { job.packet.finish(Err(EIO)); sched::Status::NoDevice } - fn cancel(job:&mut Self) { - match &job.shared { - Sink::M3(shared)=>{crate::m3::m3_runtime::Runtime::withdraw(shared,&job.packet);} - Sink::G14V27_2(runtime)=>runtime.withdraw(&job.packet), - } - job.packet.finish(Err(ECANCELED)); - } } struct AddressSpace<'a>(&'a mmu::Vm); impl agx_uapi::GpuAddressSpace for AddressSpace<'_> { @@ -210,6 +243,7 @@ pub(crate) struct Queue { urgency:u8, } impl Queue { + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] pub(crate) fn new(shared:Shared,scheduler:Arc>,vm:mmu::Vm,priority:u32,usc:u64, early_tiling:bool, wide_visibility:bool)->Result { agx_uapi::QueueUscWindow{base:usc,user_start:0x4000,user_end:(1u64<<42)-0x8000}.validate().map_err(|_|EINVAL)?; @@ -222,6 +256,7 @@ impl Queue { early_tiling,wide_visibility,urgency,preempt_alloc:None}) } /// A G14 firmware-27.2 compute queue: the same front end, published by that runtime. + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) fn new_g14_v27_2(runtime:Arc,scheduler:Arc>,vm:mmu::Vm,priority:u32,usc:u64, ualloc_priv:Arc>,preempt_bytes:usize)->Result { agx_uapi::QueueUscWindow{base:usc,user_start:0x4000,user_end:(1u64<<42)-0x8000}.validate().map_err(|_|EINVAL)?; @@ -239,8 +274,11 @@ impl queue::Queue for Queue { let vm_job=self.vm.retain_job()?; let mut parser=agx_uapi::UapiCommandParser::new(raw);let mut commands=KVec::new();let mut timestamps=KVec::new();let mut flushes=KVec::new();let mut visibility=KVec::new();let mut render_attachments=KVec::new(); while let Some(command)=parser.next_hardware().map_err(|_|EINVAL)? { + // Only the M3 runtime renders; the G14 firmware-27.2 runtime is compute-only. + #[cfg(not(CONFIG_DRM_ASAHI_M3_T8122))] + if let agx_uapi::ParsedHardwareCommand::Render{..}=command {return Err(EINVAL);} + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] if let agx_uapi::ParsedHardwareCommand::Render{payload,vertex_attachments,fragment_attachments,..}=command { - // The G14 firmware-27.2 runtime is compute-only. if self.preempt_alloc.is_some() {return Err(EINVAL);} if let Err(e)=validate_render(payload,self.usc,&AddressSpace(&self.vm),self.early_tiling) { pr_err!("M3 render rejected {:?}: flags={:#x} size={}x{} layers={} samples={} utile={}x{} sample_size={} depth={:#x} stencil={:#x} zls={:#x} samplers={} heap={:#x}\n",e,payload.flags,payload.width,payload.height,payload.layers,payload.samples,payload.utile_width,payload.utile_height,payload.sample_size,payload.depth.base,payload.stencil.base,payload.zls_control,payload.sampler_count,payload.sampler_heap); @@ -279,6 +317,7 @@ impl queue::Queue for Queue { EINVAL })?; // The launch check decodes the 26.x G15 CDM launch format; G14 streams differ. + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] if self.preempt_alloc.is_none() { crate::m3::m3_client::check_compute_launches(&self.vm,&AddressSpace(&self.vm),c.control_stream_base,c.control_stream_end)?; } @@ -325,6 +364,7 @@ fn encode_attachments(vm: &mmu::Vm, list: &agx_uapi::UapiAttachmentList) Ok(out) } +#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] fn validate_render(r: agx_uapi::UapiRenderCommand, usc: u64, space: &AddressSpace<'_>, early_tiling: bool) -> Result { use agx_uapi::{GpuAddressSpace, GpuAccess}; diff --git a/drivers/gpu/drm/asahi/m3/mod.rs b/drivers/gpu/drm/asahi/m3/mod.rs index cb64aa8f1ecbc..eec633d130199 100644 --- a/drivers/gpu/drm/asahi/m3/mod.rs +++ b/drivers/gpu/drm/asahi/m3/mod.rs @@ -70,17 +70,18 @@ pub(crate) fn t8122_admitted(pdev: &platform::Device>) -> Result<&'stat } // The T8122 runtime, ported from the 7.1.12 release-20 kernel (c46d7dcdb871). -#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] +// The 26.x submission front end, shared with the G14 firmware-27.2 runtime. +#[cfg(any(CONFIG_DRM_ASAHI_M3_T8122, CONFIG_DRM_ASAHI_G14_V27_2))] mod agx_attachments; -#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] +#[cfg(any(CONFIG_DRM_ASAHI_M3_T8122, CONFIG_DRM_ASAHI_G14_V27_2))] mod agx_compute; -#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] +#[cfg(any(CONFIG_DRM_ASAHI_M3_T8122, CONFIG_DRM_ASAHI_G14_V27_2))] mod agx_memory; #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] mod agx_resources; #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] mod agx_status; -#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] +#[cfg(any(CONFIG_DRM_ASAHI_M3_T8122, CONFIG_DRM_ASAHI_G14_V27_2))] pub(crate) mod agx_uapi; #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] mod g15_raw; @@ -124,7 +125,7 @@ mod m3_resources; mod m3_rtkit; #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] mod m3_runtime; -#[cfg(CONFIG_DRM_ASAHI_M3_T8122)] +#[cfg(any(CONFIG_DRM_ASAHI_M3_T8122, CONFIG_DRM_ASAHI_G14_V27_2))] pub(crate) mod m3_submit; #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] mod m3_thermal; @@ -209,7 +210,7 @@ pub(crate) mod m3_mmio_26; mod m3_power_26; pub(crate) mod m3_channel_format; -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) use m3_channel_format::{idle_cursor, submission_entry, Action, CONTROL_BYTES}; -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) use m3_init_storage::DEVICE_CONTROL; diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index a4fd3c7a7a594..0ff2a803f88a4 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -4523,13 +4523,13 @@ mod execution_context_tests { } /// The word GPU firmware 27.2 on G14 exchanges through the handoff region's magic fields. -#[cfg(CONFIG_DRM_ASAHI_G15)] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] const MAGIC_G14_V27_2: u64 = 0x4b1d000000000003; /// The loader's UAT regions as GPU firmware 27.2 on G14 uses them. The driver mirrors its /// kernel window into the firmware's shared second-level table and names its own trees in /// TTBAT context 0 before the ASC starts. -#[cfg(CONFIG_DRM_ASAHI_G15)] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) struct FirmwareWindow { handoff: UatRegion, ttbs: UatRegion, @@ -4540,7 +4540,7 @@ pub(crate) struct FirmwareWindow { pa_mask: u64, } -#[cfg(CONFIG_DRM_ASAHI_G15)] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] impl FirmwareWindow { /// Maps the four regions. Fails with `EBUSY` unless the handoff is idle and the shared /// table and context 0 are empty. diff --git a/drivers/gpu/drm/asahi/object.rs b/drivers/gpu/drm/asahi/object.rs index e3ce17cb7cb7e..ef7027ff1a636 100644 --- a/drivers/gpu/drm/asahi/object.rs +++ b/drivers/gpu/drm/asahi/object.rs @@ -697,7 +697,7 @@ impl> GpuArray { } } -#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] +#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] impl> GpuArray { /// Aligned index in a shared firmware ring, accessed without borrowing its payload. pub(crate) fn shared_index(&self, offset: usize) -> Result<&core::sync::atomic::AtomicU32> { diff --git a/drivers/gpu/drm/asahi/regs.rs b/drivers/gpu/drm/asahi/regs.rs index 658c98de1e77a..7e40d4b137ba9 100644 --- a/drivers/gpu/drm/asahi/regs.rs +++ b/drivers/gpu/drm/asahi/regs.rs @@ -351,7 +351,7 @@ impl Resources<'_> { /// The G14 Fender operating-point word: requested index in bits 3:0, request pending in /// bit 4. Sampled while the firmware holds the GPU powered. - #[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] pub(crate) fn operating_point(&self) -> u32 { self.sgx_read32::<0xd01000>() } diff --git a/include/uapi/drm/asahi_drm.h b/include/uapi/drm/asahi_drm.h index 75301a90c564c..7193c1ef7e454 100644 --- a/include/uapi/drm/asahi_drm.h +++ b/include/uapi/drm/asahi_drm.h @@ -535,6 +535,15 @@ enum drm_asahi_feature { */ #define DRM_ASAHI_FEATURE_RENDER_MESH_OUTPUT ((1ULL) << 38) +/* + * DRM_ASAHI_FEATURE_COMPUTE_ONLY: the device runs compute commands only. + * DRM_ASAHI_CMD_RENDER is refused, so the device cannot serve graphics APIs; + * userspace should not offer it for them. Compute commands, the VM and GEM + * interfaces are unaffected. A feature bit like those of enum + * drm_asahi_feature, defined here like bit 32. + */ +#define DRM_ASAHI_FEATURE_COMPUTE_ONLY ((1ULL) << 41) + #define DRM_ASAHI_PARAM_GROUP_VM_STATUS 1 #define DRM_ASAHI_PARAM_GROUP_QUEUE_LIMITS 2