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
7 changes: 6 additions & 1 deletion drivers/gpu/drm/asahi/g16/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,12 @@ fn run(
scheduler.w32(scheduler_word, 1)?;
}
regs::wmb();
devctl_op(session, channels, events, init, devctl.start)?;
let mut policy = DevCtl::op(devctl.start);
if session.adt.layout.powered.is_some() {
// Let the firmware manage idle at the normal boot policy boundary (Globals +0x30 = 1).
policy.words[1] = 1;
}
channel::devctl_submit(session, channels, events, init, &policy, true)?;
wait_boot_control(session, channels, events, init, base + 2, 2000)?;
let receive_kick = if g15s_channels {
hw::engine::G15S_RECEIVE_DOORBELL
Expand Down
27 changes: 17 additions & 10 deletions drivers/gpu/drm/asahi/g16/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,23 @@ struct asahi_g16_cooling *asahi_g16_cooling_register(struct device *dev)
cooling->pmp_node = NULL;
}
if (cooling->pmp_node) {
atomic_set(&cooling->state, 8);
cooling->pmp = apple_pmp_gpu_get(dev);
if (IS_ERR(cooling->pmp)) {
if (PTR_ERR(cooling->pmp) == -ENODEV) {
of_node_put(cooling->pmp_node);
cooling->pmp_node = NULL;
cooling->pmp = NULL;
} else if (IS_ERR(cooling->pmp)) {
ret = dev_err_probe(dev, PTR_ERR(cooling->pmp),
"PMP telemetry from %pOF unavailable\n",
cooling->pmp_node);
goto put_node;
}
} else {
/*
* Without an available apple,pmp supplier, thermal-zone
* telemetry drives the fail-closed backstop (starting at maximum
* cooling) while the cooling device remains available to thermal
* policy.
*/
atomic_set(&cooling->state, 0);
}
/*
* Without PMP telemetry, thermal-zone telemetry drives the fail-closed
* backstop while the cooling device remains available to thermal policy.
*/
atomic_set(&cooling->state, cooling->pmp ? 8 : 0);
cooling->cdev = thermal_of_cooling_device_register(dev->of_node, 0,
"aurora-g16g", cooling,
&asahi_g16_cooling_ops);
Expand Down Expand Up @@ -412,6 +412,9 @@ int asahi_g16_cooling_sample(struct asahi_g16_cooling *cooling, u64 now, bool id
/*
* genpd never turned the GFX domain's TVM gate off, so a sleep that lost it goes
* unnoticed: the domain then doesn't come on. Enabled here if it's found clear.
*
* Only a GFX domain whose parent is such a gate has one. T6030's GFX hangs off two
* PMGR words instead (GPX and AFR), which the sleep controller lowers and raises.
*/
int asahi_g16_tvm_enable(struct device *dev);
int asahi_g16_tvm_enable(struct device *dev)
Expand All @@ -428,6 +431,10 @@ int asahi_g16_tvm_enable(struct device *dev)
of_node_put(gfx);
if (!tvm)
return -EINVAL;
if (!of_device_is_compatible(tvm, "apple,t8132-gfx-tvm")) {
of_node_put(tvm);
return 0;
}
reg = of_iomap(tvm, 0);
of_node_put(tvm);
if (!reg)
Expand Down
58 changes: 57 additions & 1 deletion drivers/gpu/drm/asahi/g16/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ pub(crate) struct Config {
pub(crate) host_block_ready: bool,
/// Whether the TVM gate and firmware warm restart are supported.
pub(crate) deep_sleep: bool,
/// Where a deep sleep stops the firmware.
pub(crate) sleep_stop: SleepStop,
/// The stop at the commit touches neither the ASC's page nor the GFX word after the idle
/// (G15S, where the stop is left to the commit).
pub(crate) sleep_quiet_stop: bool,
/// The SRAM a stop in `.prepare` saves before the idle and the restart writes back.
pub(crate) sleep_sram: Option<SleepSram>,
/// Whether render work accepts scratch for ray queries.
pub(crate) supports_render_scs: bool,
/// Whether FS->compute cross-engine barriers require `BarrierType::Hold` (type 1), as on G15.
Expand All @@ -98,6 +105,29 @@ pub(crate) struct Config {
pub(crate) max_tile_buffer: u32,
}

/// SRAM in the "sgx" window that a stop in `.prepare` saves with the firmware running and the
/// restart writes back with GFX on, before the run bit. Offsets in bytes from the window.
#[derive(Clone, Copy, Debug)]
pub(crate) struct SleepSram {
/// Where the saved range starts.
pub(crate) start: usize,
/// Bytes saved.
pub(crate) save: usize,
/// Bytes written back, from `start`.
pub(crate) restore: usize,
}

/// When a deep sleep stops the GPU's firmware and powers its domain off.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(crate) enum SleepStop {
/// In the sleep's commit, with interrupts off and every refusal behind it. A sleep refused
/// before then finds the firmware running; only a real wake restarts it.
Commit,
/// In `.prepare`, before any other device suspends, as macOS does: the firmware restarts
/// warm after every sleep, real or refused.
Prepare,
}

impl Config {
pub(crate) const fn core_slots(&self) -> u32 {
self.num_clusters * self.num_cores_per_cluster
Expand Down Expand Up @@ -244,6 +274,9 @@ pub(crate) mod t8132 {
host_block_zero_order: &super::start_27_2::HOST_BLOCK_ZERO_ORDER,
host_block_ready: true,
deep_sleep: true,
sleep_stop: super::SleepStop::Commit,
sleep_quiet_stop: false,
sleep_sram: None,
supports_render_scs: true,
cross_engine_hold: false,
// macOS 26B123 programs 48 KiB tiles (MSAA4, 32x16 utiles) on this GPU.
Expand Down Expand Up @@ -404,7 +437,27 @@ pub(crate) mod t6030 {
// per-pipe host-block control words cleared before endpoints 0x20/0x21 start.
host_block_zero_order: &[0, 0x1808, 0x3010],
host_block_ready: false,
deep_sleep: false,
// macOS 27.2 on J516s stops the GPU in its device sleep, before any display request
// goes, 4.1 to 4.5 s before the commit: AP and IOP IDLE, the mailbox's receive off, the
// PMP's AGX request withdrawn, then the GFX word off. Its wake raises GFX, makes the
// request again and takes the firmware's HELLO. The same in all three full records
// (s2r-trace ref/t6030-macos-s2r-{entry,wake}-full-{1,2,3}.tsv). There is no TVM gate:
// AFR and the GPU PMGR's other blocks are the sleep controller's.
//
// With the ASC page and sgx hooked as well (lane A, mac-gpustop-1,
// ref/t6030-macos-gpu-stop-asc-sgx.tsv): before the idle macOS saves sgx reg[1]
// +0x60000..+0x80000, in order, 64 bits at a time; after the idle it clears the ASC's
// CPU_CONTROL (never reading CPU_STATUS) before GFX goes off. Its restart writes back
// +0x60000..+0x74000 with GFX on, then sets the run bit and takes the firmware's HELLO.
// sgx reg[1] is at "sgx" +0xd00000 (ADT /arm-io/sgx reg[1], 0x290d00000).
deep_sleep: true,
sleep_stop: super::SleepStop::Prepare,
sleep_quiet_stop: true,
sleep_sram: Some(super::SleepSram {
start: 0xd60000,
save: 0x20000,
restore: 0x14000,
}),
supports_render_scs: false,
cross_engine_hold: true,
max_tile_buffer: super::sizes::TILE_BUFFER_32K,
Expand Down Expand Up @@ -546,6 +599,9 @@ pub(crate) mod t8122 {
host_block_zero_order: &super::start_27_2::HOST_BLOCK_ZERO_ORDER,
host_block_ready: true,
deep_sleep: false,
sleep_stop: super::SleepStop::Commit,
sleep_quiet_stop: false,
sleep_sram: None,
// Measured on the J615 (26B123): vertex-, geometry- and fragment-stage ray
// queries with render scratch run clean. T6030 is not measured yet.
supports_render_scs: true,
Expand Down
11 changes: 11 additions & 0 deletions drivers/gpu/drm/asahi/g16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ pub(crate) struct Shared {
/// From a system sleep's `.prepare` until the firmware restarted: nothing reads its
/// registers and nothing is published.
pub(crate) sleeping: AtomicBool,
/// Kept stopped after a real dark wake while the system suspends again.
sleep_dark_held: AtomicBool,
/// Firmware recovery is active under `Shared::state` (may sleep up to 1000 ms).
pub(crate) recovering: AtomicBool,
/// Whether any base compute unit (`0..BASE_COMPUTE_UNITS`) has been quarantined.
Expand Down Expand Up @@ -689,6 +691,7 @@ impl Gpu {
rtkit_buffer: AtomicU64::new(0),
orphaned: AtomicBool::new(false),
sleeping: AtomicBool::new(false),
sleep_dark_held: AtomicBool::new(false),
recovering: AtomicBool::new(false),
base_compute_quarantined: AtomicBool::new(false),
quarantined_compute_mask: AtomicU32::new(0),
Expand Down Expand Up @@ -727,6 +730,9 @@ impl Gpu {
let firmware = Firmware::start_backend(dev, cfg, booted, &shared, power)?;
let vms = firmware.vms.clone();
*shared.state.lock() = Some(firmware);
// The PMP's request for the GPU while its firmware runs, where the device tree names
// one: macOS holds it from its GPU's start (T6030 PTD request bit 4).
shared.pmp_request(true);
// The engine's statistics file (a debugfs failure does not fail the probe).
if let Err(error) = shared.start_engine() {
dev_warn!(dev.as_ref(), "G16: no aurora-g16 debugfs ({:?})\n", error);
Expand All @@ -745,6 +751,11 @@ impl Gpu {
GFP_KERNEL,
)?;
gpu.retain()?;
if cfg.deep_sleep {
if let Err(error) = sleep::register_pm_notify(&gpu.shared) {
dev_warn!(dev.as_ref(), "G16: no sleep PM notifier ({:?})\n", error);
}
}
Ok(gpu)
}

Expand Down
Loading