Skip to content
Merged
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
9 changes: 9 additions & 0 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ impl platform::Driver for AsahiPlatformDriver {
// parameter set it; a no-op everywhere else.
unsafe { bindings::apple_pmp_agx_activity_release() };
if let Some(gpu) = this.g17.as_ref() {
#[cfg(CONFIG_DRM_ASAHI_G18)]
crate::g18::compat::g17p::g17p_unpublish_gfx_data();
// Driver data is dropped after devres, so CPU control must happen in unbind.
gpu.shutdown();
}
Expand Down Expand Up @@ -599,6 +601,11 @@ impl AsahiPlatformDriver {
error
);
}
// The G17P firmware DATA diagnostics read only the bound GPU's own data segment.
#[cfg(CONFIG_DRM_ASAHI_G18)]
if cfg.identity.gpu_variant == hw::GpuVariant::P {
crate::g18::compat::g17p::g17p_publish_gfx_data(pdev.as_ref());
}
Ok(AsahiPlatformDriverData {
binding,
_device: reg.device().into(),
Expand Down Expand Up @@ -773,6 +780,8 @@ impl Drop for AsahiPlatformDriverData<'_> {
}
drop(self.stats.take());
if let Some(gpu) = self.g17.as_ref() {
#[cfg(CONFIG_DRM_ASAHI_G18)]
crate::g18::compat::g17p::g17p_unpublish_gfx_data();
// Also covers failure to allocate platform driver data after the probe body returned.
gpu.shutdown();
}
Expand Down
6 changes: 4 additions & 2 deletions drivers/gpu/drm/asahi/g18/compat/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ const PAGE: u64 = crate::pgtable::UAT_PGSZ as u64;
fn map_power_sources() -> bool {
let map_page = |slot: &AtomicPtr<u8>, link: u64| -> bool {
if !slot.load(Ordering::Acquire).is_null() { return true; }
let physical = crate::g18::compat::g17p::g17p_gfx_link_to_physical(link);
let Some(physical) = crate::g18::compat::g17p::g17p_gfx_link_to_physical(link) else {
return false;
};
// SAFETY: same page as the existing bounded diag_knobs probe; WB
// read-only use; retained until module unload.
let ptr = unsafe { bindings::memremap(physical & !(PAGE - 1), PAGE as usize,
Expand All @@ -232,7 +234,7 @@ fn map_power_sources() -> bool {
fn read_firmware_word(page: &AtomicPtr<u8>, link: u64) -> Option<u64> {
let base = page.load(Ordering::Acquire);
if base.is_null() { return None; }
let physical = crate::g18::compat::g17p::g17p_gfx_link_to_physical(link);
let physical = crate::g18::compat::g17p::g17p_gfx_link_to_physical(link)?;
let offset = (physical & (PAGE - 1)) as usize;
// SAFETY: `base` maps the whole containing page for the module lifetime;
// `offset` is 8-aligned (both links are) and below the page size. The
Expand Down
52 changes: 46 additions & 6 deletions drivers/gpu/drm/asahi/g18/compat/g17p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::sync::atomic::{AtomicU32, AtomicU64, Ordering};
use core::ptr::NonNull;
#[cfg(CONFIG_DEV_COREDUMP)]
use kernel::{bindings, ffi::c_void};
use kernel::{addr::PhysicalAddr, prelude::*};
use kernel::{addr::PhysicalAddr, c_str, device, prelude::*};
use crate::pgtable::{UAT_PGMSK, UAT_PGSZ};
// diagnostic_accounting_clocks names the probe as `pgtable::LiveFirmwareU64Probe`.
use crate::g18::compat::g17p as pgtable;
Expand All @@ -25,12 +25,52 @@ const G17P_GFX_LINK_DATA_BASE: u64 = 0xffff_fc00_0004_c000;

const G17P_GFX_LINK_DATA_END: u64 = 0xffff_fc00_0018_0000;

const G17P_GFX_PHYSICAL_DATA_BASE: u64 = 0x0000_0100_01d7_c000;
/// Physical base of the bound G17P GPU's GFX DATA segment, 0 while none is
/// bound. The module parameters that read firmware DATA exist on every Mac.
static G17P_GFX_PHYSICAL_DATA_BASE: AtomicU64 = AtomicU64::new(0);

/// The `fw-data` region's start, if it holds the whole GFX DATA segment. The
/// region holds the data segments of both firmware roles, GFX (ADT sgx
/// gfx-data) first.
fn g17p_fw_data_start(dev: &device::Device) -> Option<u64> {
let resource = dev
.of_node()?
.reserved_mem_region_to_resource_byname(c_str!("fw-data"))
.ok()?;
let start = resource.start();
if start == 0
|| start & (UAT_PGMSK as u64) != 0
|| resource.size() < G17P_GFX_LINK_DATA_END - G17P_GFX_LINK_DATA_BASE
{
return None;
}
Some(start)
}

/// Publish the GFX DATA base of a probed G17P GPU from its `fw-data` region.
/// Without a usable region nothing is published and the diagnostics that read
/// firmware DATA report none.
pub(crate) fn g17p_publish_gfx_data(dev: &device::Device) {
let base = g17p_fw_data_start(dev).unwrap_or(0);
G17P_GFX_PHYSICAL_DATA_BASE.store(base, Ordering::Release);
}

/// Withdraw the published GFX DATA base when the G17P GPU is unbound.
pub(crate) fn g17p_unpublish_gfx_data() {
G17P_GFX_PHYSICAL_DATA_BASE.store(0, Ordering::Release);
}

/// Translate a GFX firmware LINK address into the physical address the host
/// can map. Same arithmetic the render status-page probes use.
pub(crate) fn g17p_gfx_link_to_physical(link: u64) -> u64 {
G17P_GFX_PHYSICAL_DATA_BASE + (link - G17P_GFX_LINK_DATA_BASE)
/// can map. Same arithmetic the render status-page probes use. None while no
/// G17P GPU is bound or for a LINK address outside the DATA segment.
pub(crate) fn g17p_gfx_link_to_physical(link: u64) -> Option<u64> {
if !(G17P_GFX_LINK_DATA_BASE..G17P_GFX_LINK_DATA_END).contains(&link) {
return None;
}
match G17P_GFX_PHYSICAL_DATA_BASE.load(Ordering::Acquire) {
0 => None,
base => Some(base + (link - G17P_GFX_LINK_DATA_BASE)),
}
}

fn g17p_binding_row_address(base: u64, id: u32, stride: u64) -> Option<u64> {
Expand All @@ -55,7 +95,7 @@ pub(crate) fn diagnostic_accounting_clocks() -> Result<[u64; 8]> {
let read = |index: usize| -> Result<u64> {
let link = 0xffff_fc00_0000_0000u64.checked_add(OFFSETS[index]).ok_or(EOVERFLOW)?;
let start = g17p_binding_row_address(link, 0, 8).ok_or(EINVAL)?;
pgtable::LiveFirmwareU64Probe::new(g17p_gfx_link_to_physical(start))
pgtable::LiveFirmwareU64Probe::new(g17p_gfx_link_to_physical(start).ok_or(ENODEV)?)
.and_then(|probe| probe.observe_mask(u64::MAX, 1))
.map(|sample| sample.first)
};
Expand Down
12 changes: 9 additions & 3 deletions drivers/gpu/drm/asahi/g18/compat/timing_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,11 @@ unsafe extern "C" fn diag_get(buf: *mut core::ffi::c_char,
// 177838 idle-off policy (RegionC+0x30 copy), 128a68 keep-on bits.
for (name, link) in [("powerups", 0xffff_fc00_0012_4ba0u64), ("state", 0xffff_fc00_0017_71f8),
("idleoff", 0xffff_fc00_0017_7838), ("keepon", 0xffff_fc00_0012_8a68)] {
let value = crate::g18::compat::g17p::LiveFirmwareU64Probe::new(
crate::g18::compat::g17p::g17p_gfx_link_to_physical(link))
let Some(physical) = crate::g18::compat::g17p::g17p_gfx_link_to_physical(link) else {
let _ = writeln!(out, "{} none (no G17P fw-data region)", name);
continue;
};
let value = crate::g18::compat::g17p::LiveFirmwareU64Probe::new(physical)
.and_then(|probe| probe.observe_mask(u64::MAX, 1))
.map(|sample| sample.first);
let _ = writeln!(out, "{} {:x?}", name, value);
Expand Down Expand Up @@ -437,7 +440,10 @@ unsafe extern "C" fn peek_get(buf: *mut core::ffi::c_char,
let address = PEEK_ADDR.load(Ordering::Relaxed);
if address < PEEK_DATA_START { return 0; }
let page = crate::pgtable::UAT_PGSZ as u64;
let physical = crate::g18::compat::g17p::g17p_gfx_link_to_physical(address);
let Some(physical) = crate::g18::compat::g17p::g17p_gfx_link_to_physical(address) else {
let _ = writeln!(out, "error: no G17P fw-data region");
return out.used as core::ffi::c_int;
};
let room = ((page - (physical & (page - 1))) / 8).min(64) as usize;
let room = room.min(((PEEK_DATA_END - address) / 8) as usize);
let mut values = [0u64; 64];
Expand Down
Loading