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
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ aurora-$(CONFIG_DRM_ASAHI_G15) += g15/glue.o

aurora-$(CONFIG_DRM_ASAHI_G16) += g16/glue.o

aurora-y += retain.o cpu_capacity.o g17/mesh_tvb_floor.o g17/mesh_exclusion.o
aurora-y += retain.o cpu_capacity.o g17/mesh_tvb_floor.o g17/mesh_exclusion.o rtkit_dump.o
aurora-$(CONFIG_DRM_ASAHI_G18) += g18/sync_input.o
aurora-$(CONFIG_DRM_ASAHI_G18) += g18/demand.o
2 changes: 2 additions & 0 deletions drivers/gpu/drm/asahi/asahi_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mod g18;
#[cfg(CONFIG_DRM_ASAHI_M5)]
mod m5;
mod gpu;
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
mod g14_v27_2;
mod hw;
mod initdata;
mod m3;
Expand Down
112 changes: 101 additions & 11 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub(crate) struct AsahiPlatformDriverData<'bound> {
#[cfg(CONFIG_DRM_ASAHI_G16)]
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))]
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.
raw_dev: *mut bindings::device,
Expand Down Expand Up @@ -150,6 +153,7 @@ impl drm::driver::Driver for AsahiDrmDriver {
/// Firmware interface selected by the hardware compatible.
pub(crate) enum ProbeConfig {
Legacy(&'static hw::HwConfig),
LegacyWithG14Handoff(&'static hw::HwConfig),
G17(&'static g17::Config),
/// M5 Pro, Max and Ultra: the ID registers select the configuration.
G17M5,
Expand Down Expand Up @@ -197,7 +201,7 @@ macro_rules! asahi_of_device_table {
),
(
of::DeviceId::new(c"apple,agx-t8112"),
ProbeConfig::Legacy(&hw::t8112::HWCONFIG)
ProbeConfig::LegacyWithG14Handoff(&hw::t8112::HWCONFIG)
),
(
of::DeviceId::new(c"apple,agx-t6000"),
Expand Down Expand Up @@ -267,12 +271,23 @@ unsafe fn sleep_data<'a>(dev: *mut bindings::device) -> &'a AsahiPlatformDriverD

/// Runs before any device suspends, so the GPU goes first and work still in flight can finish.
unsafe extern "C" fn sleep_prepare(dev: *mut bindings::device) -> core::ffi::c_int {
// SAFETY: Called by the PM core.
let data = unsafe { sleep_data(dev) };
// 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))]
if let Some(backend) = data.g14_v27_2.as_ref() {
// SAFETY: Reads a global flag word.
if unsafe { bindings::pm_suspend_via_firmware() } {
return EBUSY.to_errno();
}
return kernel::error::from_result(|| backend.sleep_prepare().map(|_| 0));
}
// SAFETY: Reads a global flag word.
if !unsafe { bindings::pm_suspend_via_firmware() } {
return 0;
}
// SAFETY: Called by the PM core.
let data = unsafe { sleep_data(dev) };
match data.g17.as_ref() {
Some(gpu) => kernel::error::from_result(|| gpu.sleep_prepare().map(|_| 0)),
None => EBUSY.to_errno(),
Expand All @@ -282,7 +297,12 @@ unsafe extern "C" fn sleep_prepare(dev: *mut bindings::device) -> core::ffi::c_i
/// Runs after every device resumed. Does nothing unless [`sleep_prepare`] stopped the firmware.
unsafe extern "C" fn sleep_complete(dev: *mut bindings::device) {
// SAFETY: Called by the PM core.
if let Some(gpu) = unsafe { sleep_data(dev) }.g17.as_ref() {
let data = unsafe { sleep_data(dev) };
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
if let Some(backend) = data.g14_v27_2.as_ref() {
backend.sleep_complete();
}
if let Some(gpu) = data.g17.as_ref() {
gpu.sleep_complete();
}
}
Expand Down Expand Up @@ -339,6 +359,10 @@ 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))]
if let Some(backend) = this.g14_v27_2.as_ref() {
backend.stop();
}
this.close_binding();
}

Expand All @@ -355,8 +379,9 @@ impl platform::Driver for AsahiPlatformDriver {

dev_info!(pdev.as_ref(), "Probing...\n");

let cfg = match info.ok_or(ENODEV)? {
ProbeConfig::Legacy(cfg) => *cfg,
let (cfg, has_g14_handoff) = match info.ok_or(ENODEV)? {
ProbeConfig::Legacy(cfg) => (*cfg, false),
ProbeConfig::LegacyWithG14Handoff(cfg) => (*cfg, true),
ProbeConfig::G17(cfg) => {
return AsahiPlatformDriver::probe_g17(pdev, regs::G17Resources::new(pdev)?, cfg)
}
Expand All @@ -370,6 +395,21 @@ impl platform::Driver for AsahiPlatformDriver {
ProbeConfig::M5 => return Err(ENODEV),
};

let fwnode = pdev.as_ref().fwnode().ok_or(EIO)?;
let compat: KVec<u32> = fwnode
.property_read_array_vec(c"apple,firmware-compat", 3)?
.required_by(pdev.as_ref())?;

// The loader advertises the supported wire layout independently of the image version.
if has_g14_handoff && compat.as_slice() == [27, 2, 0] {
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
return AsahiPlatformDriver::probe_g14_v27_2(
pdev, cfg, hw::t8112::REGISTERS_V27_2, hw::t8112::WRITABLE_V27_2,
);
#[cfg(not(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122)))]
return Err(ENODEV);
}

// SAFETY: The selected SoC's UAT output width bounds all device DMA.
unsafe { pdev.dma_set_mask_and_coherent(DmaMask::try_new(cfg.uat_oas)?)? };

Expand All @@ -381,11 +421,6 @@ impl platform::Driver for AsahiPlatformDriver {
// Start the coprocessor CPU, so UAT can initialize the handoff
regs::Resources::start_cpu(pdev)?;

let fwnode = pdev.as_ref().fwnode().ok_or(EIO)?;
let compat: KVec<u32> = fwnode
.property_read_array_vec(c"apple,firmware-compat", 3)?
.required_by(pdev.as_ref())?;

let drm = drm::UnregisteredDevice::<AsahiDrmDriver>::new(pdev, Ok(()))?;
// SAFETY: Every adapter calls close_binding in unbind before devres;
// probe errors drop this local owner while the bound callback is live.
Expand Down Expand Up @@ -451,6 +486,8 @@ impl platform::Driver for AsahiPlatformDriver {
_reg: reg,
g17: None,
m3: None,
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
g14_v27_2: None,
#[cfg(CONFIG_DRM_ASAHI_G16)]
g16: None,
raw_dev,
Expand All @@ -463,6 +500,43 @@ 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))]
fn probe_g14_v27_2<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
cfg: &'static hw::HwConfig,
registers: &'static [hw::RegisterV27_2],
writable: u64,
) -> Result<AsahiPlatformDriverData<'bound>> {
let crate::g14_v27_2::Started { backend, drm, binding, resources } =
crate::g14_v27_2::start(pdev, cfg, registers, writable)?;
let gpu = backend.clone() as Arc<dyn gpu::Gpu>;
let data = try_pin_init!(AsahiDrmRegistrationData { gpu, resources });
// SAFETY: The registration is stored in the platform data and unregistered when it is
// dropped, after the backend has stopped the firmware.
let reg = match unsafe { drm::Registration::new(pdev.as_ref(), drm, data, 0) } {
Ok(reg) => reg,
Err(error) => {
backend.stop();
return Err(error);
}
};
dev_info!(pdev.as_ref(), "G14 firmware 27.2 running; compute-only DRM device registered\n");
Ok(AsahiPlatformDriverData {
binding,
_device: reg.device().into(),
_reg: reg,
g17: None,
#[cfg(CONFIG_DRM_ASAHI_G16)]
g16: None,
m3: None,
g14_v27_2: Some(backend),
raw_dev: core::ptr::null_mut(),
raw_stats: core::ptr::null_mut(),
stats: None,
})
}

#[cfg(CONFIG_DRM_ASAHI_G15)]
pub(crate) fn probe_g15<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
Expand All @@ -489,6 +563,8 @@ impl AsahiPlatformDriver {
_reg: reg,
g17: None,
m3: None,
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
g14_v27_2: None,
#[cfg(CONFIG_DRM_ASAHI_G16)]
g16: None,
raw_dev: core::ptr::null_mut(),
Expand Down Expand Up @@ -531,6 +607,8 @@ impl AsahiPlatformDriver {
_reg: reg,
g17: None,
m3: Some(backend),
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
g14_v27_2: None,
raw_dev: core::ptr::null_mut(),
raw_stats: core::ptr::null_mut(),
stats: None,
Expand Down Expand Up @@ -612,6 +690,8 @@ impl AsahiPlatformDriver {
_reg: reg,
g17: Some(gpu),
m3: None,
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
g14_v27_2: None,
#[cfg(CONFIG_DRM_ASAHI_G16)]
g16: None,
raw_dev,
Expand Down Expand Up @@ -659,6 +739,8 @@ impl AsahiPlatformDriver {
_reg: reg,
g17: None,
m3: None,
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
g14_v27_2: None,
#[cfg(CONFIG_DRM_ASAHI_G16)]
g16: None,
raw_dev: core::ptr::null_mut(),
Expand Down Expand Up @@ -698,6 +780,8 @@ impl AsahiPlatformDriver {
_reg: reg,
g17: None,
m3: None,
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
g14_v27_2: None,
g16: Some(gpu),
raw_dev,
raw_stats,
Expand Down Expand Up @@ -754,6 +838,8 @@ impl AsahiPlatformDriver {
_reg: reg,
g17: None,
m3: None,
#[cfg(all(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_M3_T8122))]
g14_v27_2: None,
#[cfg(CONFIG_DRM_ASAHI_G16)]
g16: None,
raw_dev: core::ptr::null_mut(),
Expand Down Expand Up @@ -789,5 +875,9 @@ 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))]
if let Some(backend) = self.g14_v27_2.as_ref() {
backend.stop();
}
}
}
11 changes: 11 additions & 0 deletions drivers/gpu/drm/asahi/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ 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))]
pub(crate) fn raw(self) -> u32 {
self.0
}

/// Returns the `EventValue` that succeeds this one.
pub(crate) fn next(&self) -> EventValue {
EventValue(self.0.wrapping_add(0x100))
Expand Down Expand Up @@ -199,6 +204,12 @@ impl EventManager {
Ok(ev)
}

/// 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))]
pub(crate) fn try_get_polled(&self) -> Result<Event> {
self.alloc.try_get(None)
}

/// Signals an event by slot, indicating completion (of one or more commands).
pub(crate) fn signal(&self, slot: u32) {
match self
Expand Down
56 changes: 53 additions & 3 deletions drivers/gpu/drm/asahi/fw/initdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ pub(crate) mod raw {
pub(crate) afr_unkpad: u32,
}

#[versions(AGX)]
#[versions(AGX_V27_2)]
#[derive(Debug)]
#[repr(C)]
pub(crate) struct HwDataB {
Expand All @@ -663,10 +663,15 @@ pub(crate) mod raw {
pub(crate) yuv_matrices: Array<0x3f, Array<3, Array<4, i16>>>,

pub(crate) pad_1c8: Pad<0x8>,
#[ver(V < V27_2)]
pub(crate) io_mappings: Array<IO_MAPPING_COUNT::ver, IOMapping>,
#[ver(V >= V27_2)]
pub(crate) io_mappings: Array<60, crate::g17::fw::initdata::RegisterMapEntry>,

#[ver(V >= V13_0B4)]
pub(crate) sgx_sram_ptr: U64,
#[ver(V >= V27_2)]
pub(crate) coredump_copy_buffer_size: U64,

pub(crate) chip_id: u32,
pub(crate) unk_454: u32,
Expand Down Expand Up @@ -835,7 +840,7 @@ pub(crate) mod raw {
#[ver(V >= V13_0B4)]
pub(crate) unk_c3c: u32,
}
#[versions(AGX)]
#[versions(AGX_V27_2)]
default_zeroed!(HwDataB::ver);

#[derive(Debug)]
Expand Down Expand Up @@ -1243,7 +1248,7 @@ pub(crate) mod raw {
pub(crate) index_mask: U64,
}

#[versions(AGX)]
#[versions(AGX_V27_2)]
#[derive(Debug)]
#[repr(C)]
pub(crate) struct InitData<'a> {
Expand All @@ -1253,20 +1258,65 @@ pub(crate) mod raw {
pub(crate) unk_buf: GpuPointer<'a, &'a [u8]>,
pub(crate) unk_8: u32,
pub(crate) unk_c: u32,
#[ver(V < V27_2)]
pub(crate) runtime_pointers: GpuPointer<'a, super::RuntimePointers::ver>,
#[ver(V < V27_2)]
pub(crate) globals: GpuPointer<'a, super::Globals::ver>,
#[ver(V < V27_2)]
pub(crate) fw_status: GpuPointer<'a, super::FwStatus>,
// From 27.2 the root names opaque records; their layouts live with the 27.2 builder.
#[ver(V >= V27_2)]
pub(crate) runtime_pointers: GpuPointer<'a, &'a [u8]>,
#[ver(V >= V27_2)]
pub(crate) globals: GpuPointer<'a, &'a [u8]>,
#[ver(V >= V27_2)]
pub(crate) role: u32,
#[ver(V >= V27_2)]
pub(crate) host_mapped_fw_allocations: u32,
pub(crate) uat_page_size: u16,
pub(crate) uat_page_bits: u8,
pub(crate) uat_num_levels: u8,
pub(crate) uat_level_info: Array<0x3, UatLevelInfo>,
pub(crate) __pad0: Pad<0x14>,
#[ver(V < V27_2)]
pub(crate) host_mapped_fw_allocations: u32,
#[ver(V < V27_2)]
pub(crate) unk_ac: u32,
#[ver(V < V27_2)]
pub(crate) unk_b0: u32,
#[ver(V < V27_2)]
pub(crate) unk_b4: u32,
#[ver(V < V27_2)]
pub(crate) unk_b8: u32,
#[ver(V >= V27_2)]
pub(crate) status_record: GpuPointer<'a, &'a [u8]>,
#[ver(V >= V27_2)]
pub(crate) control: GpuPointer<'a, &'a [u8]>,
#[ver(V >= V27_2)]
pub(crate) power: GpuPointer<'a, &'a [u8]>,
#[ver(V >= V27_2)]
pub(crate) extra: GpuPointer<'a, &'a [u8]>,
}

// Layout checks for the firmware 27.2 root and hardware data against the 13.5 layout.
const _: () = {
// T8112's older layout locates its optional SRAM pointer after 25 IO records.
assert!(core::mem::offset_of!(HwDataBG14V13_5, io_mappings) == 0x640);
assert!(core::mem::size_of::<IOMapping>() == 0x20);
assert!(core::mem::offset_of!(HwDataBG14V13_5, sgx_sram_ptr) == 0x960);
assert!(core::mem::offset_of!(HwDataBG14V27_2, io_mappings) == 0x640);
assert!(core::mem::offset_of!(HwDataBG14V27_2, sgx_sram_ptr) == 0xfa0);
assert!(core::mem::offset_of!(HwDataBG14V27_2, coredump_copy_buffer_size) == 0xfa8);
assert!(core::mem::offset_of!(HwDataBG14V27_2, chip_id) == 0xfb0);
type Root = InitDataG14V27_2<'static>;
assert!(core::mem::offset_of!(Root, ver_info) == 0);
assert!(core::mem::offset_of!(Root, role) == 0x28);
assert!(core::mem::offset_of!(Root, host_mapped_fw_allocations) == 0x2c);
assert!(core::mem::offset_of!(Root, uat_level_info) == 0x34);
assert!(core::mem::offset_of!(Root, status_record) == 0xa8);
assert!(core::mem::offset_of!(Root, extra) == 0xc0);
assert!(core::mem::size_of::<Root>() == 0xc8);
};
}

#[derive(Debug)]
Expand Down
Loading
Loading