Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions drivers/gpu/drm/asahi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/asahi_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 15 additions & 15 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) struct AsahiPlatformDriverData<'bound> {
pub(crate) g16: Option<Arc<crate::g16::Gpu>>,
m3: Option<M3Backend>,
/// 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<Arc<crate::g14_v27_2::Backend>>,
/// Raw `struct device *` of the platform device. Stored once at probe
/// time so the `Drop` impl can find the sysfs file on unregister.
Expand Down Expand Up @@ -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() } {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -396,9 +396,9 @@ impl platform::Driver for AsahiPlatformDriver {
let version: Option<KVec<u32>> = 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);
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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<Core<'_>>,
cfg: &'static hw::HwConfig,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) type Event = slotalloc::Guard<EventInner>;
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
}
Expand Down Expand Up @@ -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<Event> {
self.alloc.try_get(None)
}
Expand Down
6 changes: 5 additions & 1 deletion drivers/gpu/drm/asahi/g14_v27_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 { <GpuManagerG14V13_5 as gpu::Gpu>::base_clock_hz(&self.graph) }
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpu/drm/asahi/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -140,7 +140,7 @@ const DOORBELL_DEVCTRL: u64 = 0x11;
const IOVA_KERN_PRIV_RANGE: Range<u64> = 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<u64> = 0xffffffa181400000..0xffffffa185400000;
/// Private (cached) GPU-RO firmware structure VA range base.
const IOVA_KERN_GPU_RO_RANGE: Range<u64> = 0xffffffa600000000..0xffffffa800000000;
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
};

Expand Down
12 changes: 8 additions & 4 deletions drivers/gpu/drm/asahi/gpu/v27_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 [
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/hw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/asahi/hw/t8112.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ 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<u64>) -> RegisterV27_2 {
RegisterV27_2 { slot, base, size, relative, install }
}

/// 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};
&[
Expand All @@ -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;
Expand Down
15 changes: 1 addition & 14 deletions drivers/gpu/drm/asahi/m3/m3_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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::<u8>();
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;
Expand Down
Loading