diff --git a/drivers/gpu/drm/asahi/driver.rs b/drivers/gpu/drm/asahi/driver.rs index 8e10ca8e85d8a..18ca057509896 100644 --- a/drivers/gpu/drm/asahi/driver.rs +++ b/drivers/gpu/drm/asahi/driver.rs @@ -288,7 +288,14 @@ unsafe extern "C" fn sleep_prepare(dev: *mut bindings::device) -> core::ffi::c_i } match data.g17.as_ref() { Some(gpu) => kernel::error::from_result(|| gpu.sleep_prepare().map(|_| 0)), - None => EBUSY.to_errno(), + None => { + // SAFETY: `dev` is a valid bound device for the duration of `prepare`. + dev_warn!( + unsafe { kernel::device::Device::::from_raw(dev) }, + "GPU: deep sleep refused, legacy firmware backend has no deep-sleep support\n" + ); + EBUSY.to_errno() + } } } diff --git a/drivers/soc/apple/sleep-t8103.h b/drivers/soc/apple/sleep-t8103.h index aaa04c1a77cfc..dd1cb8e83b8f7 100644 --- a/drivers/soc/apple/sleep-t8103.h +++ b/drivers/soc/apple/sleep-t8103.h @@ -797,8 +797,10 @@ static int t8103_sleep_map_regs(struct apple_sleep *s) np = of_find_compatible_node(NULL, NULL, "apple,agx-t8103"); if (np) { + if (devm_add_action_or_reset(s->dev, apple_sleep_put_node, np)) + return -ENOMEM; + s->gpu_np = np; t->gpu = of_find_device_by_node(np); - of_node_put(np); } if (t->gpu && devm_add_action_or_reset(s->dev, apple_sleep_put_device, &t->gpu->dev)) @@ -1771,6 +1773,7 @@ static const struct apple_sleep_soc t8103_sleep_soc = { .cluster_cpu = { T8103_CLUSTER_E, T8103_CLUSTER_P }, .ncluster_cpu = 2, .ndisp = 1, + .display_legacy_no_wake = true, .stray = t8103_stray, .nstray = ARRAY_SIZE(t8103_stray), .pmu_usid = T8103_PMU_USID, diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 5a9d5865b82b9..08adf6494628e 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -304,8 +304,10 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) { struct device_node *np = of_find_compatible_node(NULL, NULL, "apple,agx-t8112"); if (np) { + if (devm_add_action_or_reset(s->dev, apple_sleep_put_node, np)) + return -ENOMEM; + s->gpu_np = np; t8112.gpu = of_find_device_by_node(np); - of_node_put(np); } if (t8112.gpu && devm_add_action_or_reset(s->dev, apple_sleep_put_device, &t8112.gpu->dev)) @@ -1240,6 +1242,7 @@ static const struct apple_sleep_soc t8112_sleep_soc = { .pwrgate_wake = { 0x000, 0x040 }, .pwrgate_cpm = { T8112_PWRGATE_E, T8112_PWRGATE_P }, .ndisp = 1, + .display_legacy_no_wake = true, .nmcc = 4, .pmu_usid = 0xe, /* Stowe PMU on nub-spmi0:0e (info-leg_scrpad = 0xf700, boot-stage = 0xf701). */ diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index e7c0c6f08ffa1..c0aacedb330d4 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -705,6 +705,11 @@ struct apple_sleep_soc { * it. A dry run leaves it running and doesn't count it among the refusals. */ bool display_no_restart; + /* + * Legacy (< 14) internal display firmware has no deep-sleep wake restart path on this SoC: + * keep s2idle as the default when DCP reports apple,firmware-compat major < 14. + */ + bool display_legacy_no_wake; bool strict_gate_inventory; /* Fail closed if a gate_coprocs DT entry is missing or an unbound must_stop runs. */ bool gate_fail_closed; @@ -993,6 +998,7 @@ struct apple_sleep { bool bound; bool quiesced; } display[SLEEP_DISPLAYS_MAX]; + struct device_node *gpu_np; /* Filled in for the report after a return. */ u32 wake_status[WAKE_WORDS]; @@ -8506,6 +8512,7 @@ static unsigned int apple_sleep_undescribed(struct apple_sleep *s) struct device_node *disp = s->soc->ndisp ? s->display[0].np : NULL; struct device_node *host, *port, *radio = NULL; unsigned int missing = 0; + u32 fw[3]; /* * An internal display coprocessor that is available needs its driver bound and its @@ -8520,6 +8527,31 @@ static unsigned int apple_sleep_undescribed(struct apple_sleep *s) missing++; } + /* + * On SoCs whose legacy 12.x/13.x display firmware has no deep-sleep wake restart path, + * the commit stops the coprocessor cold and the panel stays off until reboot. + */ + if (disp && of_device_is_available(disp) && s->soc->display_legacy_no_wake && + !of_property_read_u32_array(disp, "apple,firmware-compat", fw, 3) && + fw[0] < 14) { + dev_warn(s->dev, "deep sleep: %pOF firmware-compat %u.%u.%u has no deep-sleep wake path\n", + disp, fw[0], fw[1], fw[2]); + missing++; + } + + /* + * On SoCs whose GPU driver supports deep sleep only on the 27.2 firmware handoff, + * older firmware-compat routes to the legacy backend which refuses every deep sleep + * with -EBUSY in prepare. + */ + if (s->gpu_np && of_device_is_available(s->gpu_np) && + !of_property_read_u32_array(s->gpu_np, "apple,firmware-compat", fw, 3) && + fw[0] < 27) { + dev_warn(s->dev, "deep sleep: %pOF firmware-compat %u.%u.%u has no deep-sleep GPU backend\n", + s->gpu_np, fw[0], fw[1], fw[2]); + missing++; + } + /* * Only the region-based SoCs bring ANS's PCIe block back without them. One with its GP * PCIe host apart needs them for an ANS that is off, which apple_sleep_refuse() checks. diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 027458b942ade..3e5bcd337f57d 100644 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -646,6 +646,7 @@ def mutations(flag, names, base, expect=KILL): + mutations('--mutation', ('no-management', 'any-system', 'any-version', 'ignore-ops-version', 'any-buffer-endpoint'), out()), 'rtkit-retained-tests.py': [(out(), PASS)], + 'sleep-legacy-fw-tests.py': [([], PASS)], 't6030-clock-tests.py': [(out(), PASS)], 't6030-display-admission-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)], 't6030-display-linkage-tests.py': [(out('--output') + ['--conf', '{conf}'], PASS)], diff --git a/tools/asahi/sleep-legacy-fw-tests.c b/tools/asahi/sleep-legacy-fw-tests.c new file mode 100644 index 0000000000000..dbfdbb1905e66 --- /dev/null +++ b/tools/asahi/sleep-legacy-fw-tests.c @@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Legacy 12.x/13.x display and GPU firmware-compat checks in apple_sleep_undescribed(). + */ +#include +#include +#include +#include +#include +#include +#include + +typedef uint32_t u32; + +struct device { + struct device_node *of_node; +}; + +struct device_node { + const char *name; + bool available; + bool has_display_power; + bool has_fw_compat; + u32 fw_compat[3]; +}; + +struct apple_sleep_domains { + u32 ans; +}; + +struct apple_sleep_soc { + unsigned int ndisp; + bool display_power_dt; + bool display_legacy_no_wake; + bool gp_host_apart; + const void *regions; + struct apple_sleep_domains ps; +}; + +struct apple_sleep { + const struct apple_sleep_soc *soc; + struct device *dev; + struct { + struct device_node *np; + } display[1]; + struct device_node *gpu_np; + void *apcie_phy_tunable; +}; + +static unsigned int warn_count; + +static void dev_warn(struct device *dev, const char *fmt, ...) +{ + va_list ap; + + (void)dev; + warn_count++; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +} + +static bool of_device_is_available(const struct device_node *np) +{ + return np && np->available; +} + +static bool of_property_present(const struct device_node *np, const char *prop) +{ + if (!np) + return false; + if (!strcmp(prop, "apple,display-power")) + return np->has_display_power; + return false; +} + +static int of_property_read_u32_array(const struct device_node *np, const char *prop, + u32 *out, size_t sz) +{ + if (!np || strcmp(prop, "apple,firmware-compat") || !np->has_fw_compat || sz != 3) + return -EINVAL; + memcpy(out, np->fw_compat, sizeof(np->fw_compat)); + return 0; +} + +static struct device_node *of_parse_phandle(const struct device_node *np, const char *name, + int index) +{ + (void)np; + (void)name; + (void)index; + return NULL; +} + +static void of_node_put(struct device_node *np) +{ + (void)np; +} + +#define for_each_available_child_of_node(parent, child) for ((child) = NULL; (parent) && 0; ) +static int of_pci_get_devfn(struct device_node *np) +{ + (void)np; + return -EINVAL; +} +#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) + +/* ACTUAL_FUNCTIONS */ + +int main(void) +{ + struct device_node sleep_np = { .name = "sleep", .available = true }; + struct device dev = { .of_node = &sleep_np }; + struct apple_sleep_soc soc = { .ndisp = 1, .display_legacy_no_wake = true }; + struct apple_sleep_soc t6000_soc = { .ndisp = 1 }; + struct device_node disp, gpu; + struct apple_sleep s; + + /* M1/M2 laptop on 13.5 stub: both display and GPU lack deep-sleep support. */ + disp = (struct device_node){ + .name = "dcp", .available = true, + .has_fw_compat = true, .fw_compat = { 13, 5, 0 }, + }; + gpu = (struct device_node){ + .name = "gpu", .available = true, + .has_fw_compat = true, .fw_compat = { 13, 5, 0 }, + }; + s = (struct apple_sleep){ + .soc = &soc, .dev = &dev, .display = { { .np = &disp } }, .gpu_np = &gpu, + }; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 2); + assert(warn_count == 2); + + /* M1/M2 desktop on 13.5 stub (internal DCP disabled): legacy GPU still demotes default. */ + disp.available = false; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 1); + assert(warn_count == 1); + + /* M1/M2 laptop on 13.5 stub with GPU disabled: legacy display still demotes default. */ + disp.available = true; + gpu.available = false; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 1); + assert(warn_count == 1); + + /* M1/M2 laptop on 27.2 stub: both display and GPU support deep sleep. */ + disp.available = true; + disp.fw_compat[0] = 27; + disp.fw_compat[1] = 2; + gpu.available = true; + gpu.fw_compat[0] = 27; + gpu.fw_compat[1] = 2; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 0); + assert(warn_count == 0); + + /* M1/M2 desktop on 27.2 stub (internal DCP disabled): deep sleep stays default. */ + disp.available = false; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 0); + assert(warn_count == 0); + + /* SoC with working 13.x DCP wake path (e.g. T6000, display_legacy_no_wake = false): unaffected. */ + disp.available = true; + disp.has_fw_compat = true; + disp.fw_compat[0] = 13; + disp.fw_compat[1] = 5; + disp.fw_compat[2] = 0; + s.soc = &t6000_soc; + s.gpu_np = NULL; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 0); + assert(warn_count == 0); + + /* Newer SoC (no gpu_np tracked, 27.0 display): unaffected. */ + s.soc = &soc; + disp.available = true; + disp.fw_compat[0] = 27; + disp.fw_compat[1] = 0; + s.gpu_np = NULL; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 0); + assert(warn_count == 0); + + /* Display node without apple,firmware-compat: unaffected. */ + disp.has_fw_compat = false; + warn_count = 0; + assert(apple_sleep_undescribed(&s) == 0); + assert(warn_count == 0); + + puts("sleep legacy firmware default gate: PASS"); + return 0; +} diff --git a/tools/asahi/sleep-legacy-fw-tests.py b/tools/asahi/sleep-legacy-fw-tests.py new file mode 100755 index 0000000000000..c099d23444063 --- /dev/null +++ b/tools/asahi/sleep-legacy-fw-tests.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Build and run the legacy GPU/DCP firmware check in apple_sleep_undescribed().""" +from pathlib import Path +import resource +import subprocess +import sys +import tempfile + +# python3 -I, as run-host-tests.py runs it, leaves this directory off sys.path. +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from sleep_test_utils import function # noqa: E402 + +resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) +root = Path(__file__).resolve().parents[2] +sleep = (root / "drivers/soc/apple/sleep.c").read_text() +t8103 = (root / "drivers/soc/apple/sleep-t8103.h").read_text() +t8112 = (root / "drivers/soc/apple/sleep-t8112.h").read_text() + +# Both T8103 and T8112 record their GPU DT node for apple_sleep_undescribed(). +assert "s->gpu_np = np;" in t8103 +assert "s->gpu_np = np;" in t8112 + +actual = [function(sleep, "apple_sleep_undescribed")] +fixture = Path(__file__).with_suffix(".c").read_text() + +with tempfile.TemporaryDirectory(prefix="sleep-legacy-fw-") as tmp: + c, exe = Path(tmp) / "test.c", Path(tmp) / "test" + c.write_text(fixture.replace("/* ACTUAL_FUNCTIONS */", "\n".join(actual))) + subprocess.run( + ["cc", "-std=gnu11", "-Wall", "-Werror", str(c), "-o", str(exe)], + check=True, + ) + subprocess.run([str(exe)], check=True)