Skip to content
Draft
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
55 changes: 42 additions & 13 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub(crate) struct AsahiPlatformDriverData<'bound> {
_reg: drm::Registration<'bound, AsahiDrmDriver>,
/// The G17 GPU, whose coprocessors must be stopped when the driver is unbound.
g17: Option<Arc<g17::Gpu>>,
legacy: Option<Arc<dyn gpu::Gpu>>,
asc: Option<regs::AscControl<'bound>>,
#[cfg(CONFIG_DRM_ASAHI_G16)]
pub(crate) g16: Option<Arc<crate::g16::Gpu>>,
m3: Option<M3Backend>,
Expand Down Expand Up @@ -286,16 +288,19 @@ unsafe extern "C" fn sleep_prepare(dev: *mut bindings::device) -> core::ffi::c_i
if !deep {
return 0;
}
match data.g17.as_ref() {
Some(gpu) => kernel::error::from_result(|| gpu.sleep_prepare().map(|_| 0)),
None => {
// SAFETY: `dev` is a valid bound device for the duration of `prepare`.
dev_warn!(
unsafe { kernel::device::Device::<kernel::device::Normal>::from_raw(dev) },
"GPU: deep sleep refused, legacy firmware backend has no deep-sleep support\n"
);
EBUSY.to_errno()
}
if let Some(gpu) = data.g17.as_ref() {
kernel::error::from_result(|| gpu.sleep_prepare().map(|_| 0))
} else if let (Some(gpu), Some(asc)) = (data.legacy.as_ref(), data.asc.as_ref()) {
// The firmware stops only at the commit, which a dry run never reaches: its stop is
// registered all the same, since the sleep driver's checks look for it.
kernel::error::from_result(|| gpu.sleep_prepare(asc.cpu_control()).map(|_| 0))
} else {
// SAFETY: `dev` is a valid bound device for the duration of `prepare`.
dev_warn!(
unsafe { kernel::device::Device::<kernel::device::Normal>::from_raw(dev) },
"GPU: deep sleep refused, legacy firmware backend has no deep-sleep support\n"
);
EBUSY.to_errno()
}
}

Expand All @@ -321,10 +326,14 @@ fn sleep_pd_init(dev: &kernel::device::Device<Core<'_>>) -> Result {
unsafe extern "C" fn sleep_suspend_noirq_driver(
dev: *mut bindings::device,
) -> core::ffi::c_int {
#[cfg(any(CONFIG_DRM_ASAHI_G14_V27_2, CONFIG_DRM_ASAHI_M3_T8122))]
// SAFETY: Called by the PM core with a bound GPU device.
let data = unsafe { sleep_data(dev) };
let hold_firmware = false;
if let Some(gpu) = data.legacy.as_ref() {
if let Err(e) = gpu.sleep_seal() {
return e.to_errno();
}
}
let hold_firmware = data.legacy.as_ref().is_some_and(|gpu| gpu.sleep_holds_pd());
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
let hold_firmware = hold_firmware
|| data.g14_v27_2
Expand Down Expand Up @@ -369,6 +378,8 @@ unsafe extern "C" fn sleep_complete(dev: *mut bindings::device) {
}
if let Some(gpu) = data.g17.as_ref() {
gpu.sleep_complete();
} else if let (Some(gpu), Some(asc)) = (data.legacy.as_ref(), data.asc.as_ref()) {
gpu.sleep_complete(&|| asc.start_cpu());
}
}

Expand Down Expand Up @@ -499,7 +510,8 @@ impl platform::Driver for AsahiPlatformDriver {
resources.init_mmio()?;

// Start the coprocessor CPU, so UAT can initialize the handoff
regs::Resources::start_cpu(pdev)?;
let asc = regs::AscControl::new(pdev)?;
asc.start_cpu();

let drm = drm::UnregisteredDevice::<AsahiDrmDriver>::new(pdev, Ok(()))?;
// SAFETY: Every adapter calls close_binding in unbind before devres;
Expand Down Expand Up @@ -537,6 +549,7 @@ impl platform::Driver for AsahiPlatformDriver {

let stats = gpu.stats_snapshot();
let debug_stats = gpu.raw_stats_snapshot();
let legacy = Some(gpu.clone());
let data = try_pin_init!(AsahiDrmRegistrationData { gpu, resources });

// SAFETY: `reg` is stored in `AsahiPlatformDriverData` and dropped when the driver is
Expand Down Expand Up @@ -565,6 +578,8 @@ impl platform::Driver for AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: None,
legacy,
asc: Some(asc),
m3: None,
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
g14_v27_2: None,
Expand Down Expand Up @@ -610,6 +625,8 @@ impl AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: None,
legacy: None,
asc: None,
#[cfg(CONFIG_DRM_ASAHI_G16)]
g16: None,
m3: None,
Expand Down Expand Up @@ -655,6 +672,8 @@ impl AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: None,
legacy: None,
asc: None,
m3: None,
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
g14_v27_2: None,
Expand Down Expand Up @@ -713,6 +732,8 @@ impl AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: None,
legacy: None,
asc: None,
m3: Some(backend),
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
g14_v27_2: None,
Expand Down Expand Up @@ -796,6 +817,8 @@ impl AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: Some(gpu),
legacy: None,
asc: None,
m3: None,
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
g14_v27_2: None,
Expand Down Expand Up @@ -845,6 +868,8 @@ impl AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: None,
legacy: None,
asc: None,
m3: None,
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
g14_v27_2: None,
Expand Down Expand Up @@ -887,6 +912,8 @@ impl AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: None,
legacy: None,
asc: None,
m3: None,
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
g14_v27_2: None,
Expand Down Expand Up @@ -945,6 +972,8 @@ impl AsahiPlatformDriver {
_device: reg.device().into(),
_reg: reg,
g17: None,
legacy: None,
asc: None,
m3: None,
#[cfg(CONFIG_DRM_ASAHI_G14_V27_2)]
g14_v27_2: None,
Expand Down
Loading