From 7e8f0dce76e894b453e0c94f186a60393b349e71 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 14:23:30 +1100 Subject: [PATCH 01/14] drm/apple: audio: keep the DP audio domain while its DCP firmware runs A DCP that keeps its coprocessor running through a system sleep sets its wakeup path in its suspend, so genpd keeps its power domains on. The DP audio block that DCP firmware drives sits in a domain of its own, which the dp-audio device holds only while runtime-active: its late sleep callback suspends it, and genpd powers the domain off at noirq under the still running DCP firmware. On the Mac mini M2 (J473, macOS 27.2 firmware), once Linux has started the primary DCP, s2idle then hard-resets the machine almost every time (19 of 20 attempts, no log). The J473 is the M2 machine that enables the primary DCP's DP audio block; the external DCP's block, enabled on every M2, sits in a domain marked always-on. With the dp-audio device unbound, which leaves the domain held, the same kernel passes 5 of 5 sleeps in one boot; with appledrm not loaded, 4 of 4; and the production kernel, which never starts that DCP, 5 of 5. Hold the domain from the late callback when the linked DCP has set its wakeup path for this sleep, or has no driver bound (its firmware may still run, left by a boot stage or an earlier bind). Every device's .suspend has run by then, so the DCP's choice is known. The decision comes from the DCP's own sleep state and the OF graph link, not from the SoC or firmware version. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/audio.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index 565016dcd7a89..4066f6e4781e3 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -2071,6 +2071,37 @@ static __maybe_unused int dcpaud_system_suspend(struct device *dev) return 0; } +/* + * The DCP's firmware drives this block. A DCP that keeps its coprocessor + * running through a sleep keeps its own power domains for it (its suspend + * sets its wakeup path), and this block's domain must stay with them: + * cutting it at noirq under running DCP firmware resets the machine. A DCP + * device without a driver may still run firmware that a boot stage or an + * earlier bind left running, so its block is kept too. Every device's + * .suspend has run before this late phase, so the DCP's choice is known. + */ +static __maybe_unused int dcpaud_suspend_late(struct device *dev) +{ + struct device_node *endpoint, *dcp_node = NULL; + struct platform_device *dcp_pdev = NULL; + + endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0); + if (endpoint) { + dcp_node = of_graph_get_remote_port_parent(endpoint); + of_node_put(endpoint); + } + if (dcp_node && of_device_is_available(dcp_node)) + dcp_pdev = of_find_device_by_node(dcp_node); + of_node_put(dcp_node); + if (dcp_pdev) { + if (!device_is_bound(&dcp_pdev->dev) || device_wakeup_path(&dcp_pdev->dev)) + device_set_wakeup_path(dev); + put_device(&dcp_pdev->dev); + } + + return pm_runtime_force_suspend(dev); +} + /* * Runtime PM stops in the late phase and comes back in the early one, so it * works through every device's .suspend and .resume. The display resumes @@ -2083,7 +2114,7 @@ static __maybe_unused int dcpaud_system_suspend(struct device *dev) static const struct dev_pm_ops dcpaud_pm_ops = { .prepare = pm_sleep_ptr(dcpaud_pm_prepare), SYSTEM_SLEEP_PM_OPS(dcpaud_system_suspend, NULL) - LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) + LATE_SYSTEM_SLEEP_PM_OPS(dcpaud_suspend_late, pm_runtime_force_resume) RUNTIME_PM_OPS(dcpaud_suspend, dcpaud_resume, NULL) }; From 16930559199091aa1f83267934a31d5ac4e1455c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 14:33:37 +1100 Subject: [PATCH 02/14] tools/asahi: test the DP audio domain hold for a sleep Build the real dcpaud_suspend_late() and dcpaud_pm_ops from drivers/gpu/drm/apple/audio.c against stubs and run every combination of OF graph link, DCP device, bound driver, DCP wakeup path and runtime force-suspend result. The domain is held exactly when the linked DCP is on its own wakeup path or has no driver; every reference is dropped; pm_runtime_force_suspend() runs once and its result is returned; the late sleep slots carry the new callback. Four mutations (bound-only, leak-device, leak-node, invert-wakeup) and the code before the change must fail. Signed-off-by: Ryan Murray --- tools/asahi/dcpaud-sleep-hold-tests.c | 233 +++++++++++++++++++++++++ tools/asahi/dcpaud-sleep-hold-tests.py | 129 ++++++++++++++ tools/asahi/run-host-tests.py | 5 + 3 files changed, 367 insertions(+) create mode 100644 tools/asahi/dcpaud-sleep-hold-tests.c create mode 100755 tools/asahi/dcpaud-sleep-hold-tests.py diff --git a/tools/asahi/dcpaud-sleep-hold-tests.c b/tools/asahi/dcpaud-sleep-hold-tests.c new file mode 100644 index 0000000000000..1c50ae05d6897 --- /dev/null +++ b/tools/asahi/dcpaud-sleep-hold-tests.c @@ -0,0 +1,233 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * The actual dcp-dp-audio late sleep callback and dev_pm_ops against an OF + * graph and driver-core model that counts every node and device reference. + */ +#include +#include +#include +#include +#include + +/* The harness builds with -Wno-unused-function. */ +#define __maybe_unused +#define pm_sleep_ptr(fn) (fn) + +/* ACTUAL_PM_MACROS */ + +struct device_node { + int refs; + bool available; +}; + +struct device { + struct device_node *of_node; + int refs; + bool bound, wakeup_path, set_wakeup_path; +}; + +struct platform_device { + struct device dev; +}; + +struct dev_pm_ops { + int (*prepare)(struct device *dev); + int (*suspend)(struct device *dev); + int (*resume)(struct device *dev); + int (*freeze)(struct device *dev); + int (*thaw)(struct device *dev); + int (*poweroff)(struct device *dev); + int (*restore)(struct device *dev); + int (*suspend_late)(struct device *dev); + int (*resume_early)(struct device *dev); + int (*freeze_late)(struct device *dev); + int (*thaw_early)(struct device *dev); + int (*poweroff_late)(struct device *dev); + int (*restore_early)(struct device *dev); + int (*runtime_suspend)(struct device *dev); + int (*runtime_resume)(struct device *dev); + int (*runtime_idle)(struct device *dev); +}; + +/* The model: the dpaudio node, its endpoint, the DCP node and device. */ +static struct device_node audio_node, endpoint_node, dcp_node; +static struct platform_device dcp_pdev; +static struct device audio_dev = { .of_node = &audio_node }; +static bool have_endpoint, have_remote, have_pdev; +static int force_suspend_ret, force_suspend_calls, find_calls; + +static void get_node(struct device_node *np) +{ + assert(np->refs >= 0); + np->refs++; +} + +static void of_node_put(struct device_node *np) +{ + if (!np) + return; + assert(np == &endpoint_node || np == &dcp_node); + assert(np->refs > 0); + np->refs--; +} + +static struct device_node *of_graph_get_endpoint_by_regs(const struct device_node *parent, + int port, int reg) +{ + assert(parent == &audio_node && port == 0 && reg == 0); + if (!have_endpoint) + return NULL; + get_node(&endpoint_node); + return &endpoint_node; +} + +static struct device_node *of_graph_get_remote_port_parent(const struct device_node *np) +{ + assert(np == &endpoint_node && endpoint_node.refs > 0); + if (!have_remote) + return NULL; + get_node(&dcp_node); + return &dcp_node; +} + +static bool of_device_is_available(const struct device_node *np) +{ + assert(np == &dcp_node && dcp_node.refs > 0); + return np->available; +} + +static struct platform_device *of_find_device_by_node(struct device_node *np) +{ + assert(np == &dcp_node && dcp_node.refs > 0); + find_calls++; + if (!have_pdev) + return NULL; + dcp_pdev.dev.refs++; + return &dcp_pdev; +} + +static void put_device(struct device *dev) +{ + assert(dev == &dcp_pdev.dev && dev->refs > 0); + dev->refs--; +} + +static bool device_is_bound(struct device *dev) +{ + assert(dev == &dcp_pdev.dev && dev->refs > 0); + return dev->bound; +} + +static bool device_wakeup_path(struct device *dev) +{ + assert(dev == &dcp_pdev.dev && dev->refs > 0); + return dev->wakeup_path; +} + +static void device_set_wakeup_path(struct device *dev) +{ + assert(dev == &audio_dev); + dev->set_wakeup_path = true; +} + +static int pm_runtime_force_suspend(struct device *dev) +{ + assert(dev == &audio_dev); + force_suspend_calls++; + return force_suspend_ret; +} + +static int pm_runtime_force_resume(struct device *dev) +{ + (void)dev; + return 0; +} + +/* The rest of the driver's callbacks only have to be distinct symbols. */ +static int dcpaud_pm_prepare(struct device *dev) +{ + (void)dev; + return 1; +} + +static int dcpaud_system_suspend(struct device *dev) +{ + (void)dev; + return 2; +} + +static int dcpaud_suspend(struct device *dev) +{ + (void)dev; + return 3; +} + +static int dcpaud_resume(struct device *dev) +{ + (void)dev; + return 4; +} + +/* ACTUAL_FUNCTION */ + +/* ACTUAL_PM_OPS */ + +int main(void) +{ + unsigned int cases = 0, held = 0; + + for (unsigned int bits = 0; bits < 128; bits++) { + bool expect; + int ret; + + have_endpoint = bits & 1; + have_remote = bits & 2; + dcp_node.available = bits & 4; + have_pdev = bits & 8; + dcp_pdev.dev.bound = bits & 16; + dcp_pdev.dev.wakeup_path = bits & 32; + force_suspend_ret = bits & 64 ? -EBUSY : 0; + endpoint_node.refs = dcp_node.refs = dcp_pdev.dev.refs = 0; + audio_dev.set_wakeup_path = false; + force_suspend_calls = find_calls = 0; + + /* The PM core calls the late slot for every system sleep. */ + ret = dcpaud_pm_ops.suspend_late(&audio_dev); + + expect = have_endpoint && have_remote && dcp_node.available && have_pdev && + (!dcp_pdev.dev.bound || dcp_pdev.dev.wakeup_path); + if (audio_dev.set_wakeup_path != expect) + fprintf(stderr, "case %#x: wakeup path %d, expected %d\n", bits, + audio_dev.set_wakeup_path, expect); + assert(audio_dev.set_wakeup_path == expect); + /* Every reference taken is dropped, whatever the topology. */ + assert(!endpoint_node.refs && !dcp_node.refs && !dcp_pdev.dev.refs); + /* An unavailable or missing DCP node is never looked up. */ + if (!(have_endpoint && have_remote && dcp_node.available)) + assert(!find_calls); + /* The runtime PM force-suspend always runs and its result is returned. */ + assert(force_suspend_calls == 1); + assert(ret == force_suspend_ret); + held += expect; + cases++; + } + + /* The wiring: late suspend and its siblings, then the rest unchanged. */ +#ifdef HAVE_SUSPEND_LATE + assert(dcpaud_pm_ops.suspend_late == dcpaud_suspend_late); + assert(dcpaud_pm_ops.freeze_late == dcpaud_suspend_late); + assert(dcpaud_pm_ops.poweroff_late == dcpaud_suspend_late); +#endif + assert(dcpaud_pm_ops.resume_early == pm_runtime_force_resume); + assert(dcpaud_pm_ops.thaw_early == pm_runtime_force_resume); + assert(dcpaud_pm_ops.restore_early == pm_runtime_force_resume); + assert(dcpaud_pm_ops.prepare == dcpaud_pm_prepare); + assert(dcpaud_pm_ops.suspend == dcpaud_system_suspend); + assert(!dcpaud_pm_ops.resume); + assert(dcpaud_pm_ops.runtime_suspend == dcpaud_suspend); + assert(dcpaud_pm_ops.runtime_resume == dcpaud_resume); + + printf("%u late-suspend cases passed, %u hold the dp-audio domain; pm ops wired\n", + cases, held); + return 0; +} diff --git a/tools/asahi/dcpaud-sleep-hold-tests.py b/tools/asahi/dcpaud-sleep-hold-tests.py new file mode 100755 index 0000000000000..66a5475bf6117 --- /dev/null +++ b/tools/asahi/dcpaud-sleep-hold-tests.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Run the actual dcp-dp-audio late sleep callback over every DCP topology. + +genpd powers the dp-audio domain off at noirq unless the device is on the +wakeup path, and cutting it under running DCP firmware resets the J473 on +s2idle. dcpaud_suspend_late() puts dp-audio on the wakeup path when the DCP +linked by its OF graph exists and is unbound or on its own wakeup path. The +fixture builds the real function and the real dcpaud_pm_ops (with the +kernel's PM_OPS macros) from drivers/gpu/drm/apple/audio.c against an OF +graph and driver-core model that counts every node and device reference. + +--mutation names a change to the production function that the matrix must +kill. --ref reads audio.c from an older revision: before the fix the late +slot was pm_runtime_force_suspend, which never holds the domain, so the +matrix fails (the old-code negative control). +""" +import argparse +import json +import os +import re +import resource +import subprocess +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +AUDIO = "drivers/gpu/drm/apple/audio.c" +PM = "include/linux/pm.h" + +MUTATIONS = { + # Hold only for a DCP on its wakeup path; an unbound DCP loses the domain. + "bound-only": ("!device_is_bound(&dcp_pdev->dev) || device_wakeup_path(", + "device_wakeup_path("), + # Leak the DCP device reference from of_find_device_by_node(). + "leak-device": ("\t\tput_device(&dcp_pdev->dev);\n", ""), + # Leak the DCP node reference from of_graph_get_remote_port_parent(). + "leak-node": ("\tof_node_put(dcp_node);\n", ""), + # Hold for a bound DCP that is NOT on its wakeup path. + "invert-wakeup": ("|| device_wakeup_path(", "|| !device_wakeup_path("), +} + + +def block(text, start): + begin = text.index("{", start) + depth, end = 1, begin + 1 + while depth: + depth += (text[end] == "{") - (text[end] == "}") + end += 1 + return end + + +def function(text, name): + match = re.search(r"^static [^\n;]*\bint " + name + r"\(struct device \*dev\)\n\{", + text, re.M) + if not match: + return None + return text[match.start():block(text, match.start())] + + +def pm_ops(text): + start = text.index("static const struct dev_pm_ops dcpaud_pm_ops = {") + return text[start:block(text, start)] + ";\n" + + +def macro(text, name): + match = re.search(r"^#define " + name + r"\(.*?[^\\]\n", text, re.M | re.S) + assert match, name + return match.group() + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.split("\n", 1)[0]) + parser.add_argument("--ref", help="read audio.c from this revision") + parser.add_argument("--mutation", choices=sorted(MUTATIONS)) + parser.add_argument("--out", type=Path) + args = parser.parse_args() + + if args.ref: + audio = subprocess.check_output(["git", "show", f"{args.ref}:{AUDIO}"], + cwd=ROOT, text=True) + else: + audio = (ROOT / AUDIO).read_text() + pm = (ROOT / PM).read_text() + late = function(audio, "dcpaud_suspend_late") + if args.mutation: + old, new = MUTATIONS[args.mutation] + if not late or late.count(old) != 1: + raise RuntimeError(f"mutation {args.mutation} did not apply exactly once") + late = late.replace(old, new) + + macros = "".join(macro(pm, name) for name in + ("SYSTEM_SLEEP_PM_OPS", "LATE_SYSTEM_SLEEP_PM_OPS", "RUNTIME_PM_OPS")) + code = (Path(__file__).with_suffix(".c").read_text() + .replace("/* ACTUAL_PM_MACROS */", macros) + .replace("/* ACTUAL_FUNCTION */", late or "") + .replace("/* ACTUAL_PM_OPS */", pm_ops(audio))) + + def run(out): + out.mkdir(parents=True, exist_ok=True) + source, binary = out / "dcpaud-sleep-hold.c", out / "dcpaud-sleep-hold" + source.write_text(code) + subprocess.run([os.environ.get("CC", "cc"), "-std=gnu11", "-O1", "-g", "-Wall", + "-Wextra", "-Werror", "-Wno-unused-function", + "-fsanitize=address,undefined", + "-fno-sanitize-recover=all"] + + (["-DHAVE_SUSPEND_LATE"] if late else []) + + [str(source), "-o", str(binary)], check=True) + result = subprocess.run([str(binary)], capture_output=True, text=True) + (out / "results.json").write_text(json.dumps({ + "exit": result.returncode, + "stdout": result.stdout, + "stderr": result.stderr, + "ref": args.ref, + "mutation": args.mutation, + "limits": "OF graph, driver core and runtime PM are host models; no genpd, no DCP.", + }, indent=2) + "\n") + print(result.stdout + result.stderr, end="") + return result.returncode != 0 + + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + if args.out: + return run(args.out.resolve()) + with tempfile.TemporaryDirectory(prefix="dcpaud-sleep-hold-") as out: + return run(Path(out)) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 1f0d5963f9290..c9e95d9d42451 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -177,6 +177,11 @@ def mutations(flag, names, base, expect=KILL): 'missing-control-firmware', 'missing-control-descriptor', 'missing-owner-ipc', 'missing-owner-firmware', 'missing-owner-descriptor', 'missing-owner-arena'), out()), + # a7638d51880c, the parent of the fix, ran pm_runtime_force_suspend in the late + # slot, so the dp-audio domain dropped under a running DCP. + 'dcpaud-sleep-hold-tests.py': [(out(), PASS)] + + mutations('--mutation', ('bound-only', 'leak-device', 'leak-node', 'invert-wakeup'), out()) + + [(out() + ['--ref', 'a7638d51880ce077cfb3edfa7ff638de2be74c85'], KILL)], 'dcp-bw-scratch-window-tests.py': [([], PASS)] + mutations('--mutation', ('old-check', 'start-only'), []), 'clpc-gpu-demand-tests.py': [([], PASS)], 'clpc-high-power-cleanup-tests.py': [(out(), PASS), From d64d9816b3ded241a0e1d9672db9f52856b14b89 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 19:12:14 +1100 Subject: [PATCH 03/14] drm/apple: audio: hold the DP audio domain only while the DCP firmware runs dcpaud_suspend_late() kept the DP audio domain whenever the linked DCP was on its wakeup path. The DCP's suspend also sets that path where it stops its firmware (the S2R stops, the T8132 external stop and power gate), so on those sleeps the domain stayed on with nothing using it. Have the DCP record whether its suspend left the coprocessor running (the default hold, a retained external DCP, a running T8132 DCP) and read that from the DP audio late suspend through dcp_sleep_keeps_firmware(). A DCP without a driver still counts as running, as before. The driver data is read under the DCP's device lock. The host test now builds dcp_sleep_keeps_firmware() too and checks the lock; its mutations cover holding for a stopped DCP, inverting the flag, dropping the unbound case and skipping the lock. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/audio.c | 16 ++++--- drivers/gpu/drm/apple/dcp-internal.h | 6 +++ drivers/gpu/drm/apple/dcp.c | 30 +++++++++++++ drivers/gpu/drm/apple/dcp.h | 1 + drivers/gpu/drm/apple/iomfb_m4.c | 17 ++++++++ drivers/gpu/drm/apple/iomfb_m4.h | 2 + tools/asahi/dcpaud-sleep-hold-tests.c | 51 ++++++++++++++++------ tools/asahi/dcpaud-sleep-hold-tests.py | 59 ++++++++++++++++++-------- tools/asahi/run-host-tests.py | 3 +- 9 files changed, 148 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index 4066f6e4781e3..1d6c5f73627d6 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -2073,12 +2073,14 @@ static __maybe_unused int dcpaud_system_suspend(struct device *dev) /* * The DCP's firmware drives this block. A DCP that keeps its coprocessor - * running through a sleep keeps its own power domains for it (its suspend - * sets its wakeup path), and this block's domain must stay with them: - * cutting it at noirq under running DCP firmware resets the machine. A DCP - * device without a driver may still run firmware that a boot stage or an - * earlier bind left running, so its block is kept too. Every device's - * .suspend has run before this late phase, so the DCP's choice is known. + * running through a sleep keeps its own power domains for it, and this + * block's domain must stay with them: cutting it at noirq under running DCP + * firmware resets the machine. A DCP that stops its firmware for the sleep + * needs nothing held here, so the domain goes down as before. A DCP device + * without a driver may still run firmware that a boot stage or an earlier + * bind left running, so its block is kept too. Every device's .suspend has + * run before this late phase, so the DCP's choice is known + * (dcp_sleep_keeps_firmware()). */ static __maybe_unused int dcpaud_suspend_late(struct device *dev) { @@ -2094,7 +2096,7 @@ static __maybe_unused int dcpaud_suspend_late(struct device *dev) dcp_pdev = of_find_device_by_node(dcp_node); of_node_put(dcp_node); if (dcp_pdev) { - if (!device_is_bound(&dcp_pdev->dev) || device_wakeup_path(&dcp_pdev->dev)) + if (dcp_sleep_keeps_firmware(&dcp_pdev->dev)) device_set_wakeup_path(dev); put_device(&dcp_pdev->dev); } diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 515e6bf065f09..92bdd7f438441 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -858,6 +858,12 @@ struct apple_dcp { struct delayed_work secure_poll_wq; /* Stopped and not restarted, which outlives a suspend that gets refused. */ bool s2r_fw_down; + /* + * Its last system suspend left the firmware running and its domains on + * (wakeup path), see dcp_sleep_keeps_firmware(). Cleared by the next + * suspend and resume. + */ + bool sleep_fw_runs; /* DCPEXT kept down through a dark wake, see dcp_s2r_dark_finish(). */ bool s2r_dark_held; struct notifier_block s2r_pm_nb; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index d1c2d02efdd4b..b4ff87f88c24c 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9740,10 +9740,36 @@ static void dcp_t8132_sleep_stopped(struct apple_dcp *dcp) WRITE_ONCE(dcp->t8132_release_late, false); } +/** + * dcp_sleep_keeps_firmware - whether a DCP's firmware runs through this sleep + * @dev: the DCP device + * + * For blocks the DCP's firmware drives (DP audio), from their late or noirq + * suspend, after every device's .suspend: true when the DCP's suspend left + * its coprocessor running with its domains on, or when no driver is bound + * (a boot stage or an earlier bind may have left the firmware running). + * False when the suspend stopped the firmware (S2R, the 27.x sleep, an M4 + * stop or power gate) or never ran it. + */ +bool dcp_sleep_keeps_firmware(struct device *dev) +{ + struct apple_dcp *dcp; + bool runs; + + device_lock(dev); + dcp = dev->driver ? dev_get_drvdata(dev) : NULL; + runs = !dev->driver || (dcp && dcp->sleep_fw_runs); + device_unlock(dev); + + return runs; +} +EXPORT_SYMBOL_GPL(dcp_sleep_keeps_firmware); + static int dcp_platform_suspend(struct device *dev) { struct apple_dcp *dcp = dev_get_drvdata(dev); + dcp->sleep_fw_runs = false; /* Its power sequences may crash the DCP and blank the panel. */ if (dcp_takeover_was_aborted(dcp)) return -EBUSY; @@ -9799,6 +9825,7 @@ static int dcp_platform_suspend(struct device *dev) return ret; } dcp_t8132_sleep_stopped(dcp); + dcp->sleep_fw_runs = !iomfb_m4_sleep_stopped(dcp); device_set_wakeup_path(dev); return 0; } @@ -9854,6 +9881,7 @@ static int dcp_platform_suspend(struct device *dev) /* Pair with the H17P unpark; native26 has its own retained resume. */ if (dcp_is_external_h17p(dcp)) dcp_typec_route_park(dcp); + dcp->sleep_fw_runs = true; device_set_wakeup_path(dev); if (dcp_is_ext26(dcp)) dev_dbg(dev, "native26 retained s2idle stop; firmware and supplier leases held\n"); @@ -9887,6 +9915,7 @@ static int dcp_platform_suspend(struct device *dev) * domains to stay on. We need this as we do not support full * shutdown properly yet. */ + dcp->sleep_fw_runs = true; device_set_wakeup_path(dev); /* Last: the steps above still talk to the coprocessor. */ dcp_hold_for_sleep(dcp); @@ -9898,6 +9927,7 @@ static int dcp_platform_resume(struct device *dev) { struct apple_dcp *dcp = dev_get_drvdata(dev); + dcp->sleep_fw_runs = false; if (dcp_takeover_was_aborted(dcp)) return 0; diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index f1d0f49026d60..41243ff65d8b0 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -63,6 +63,7 @@ struct apple_encoder { #define to_apple_encoder(x) container_of(x, struct apple_encoder, base) void dcp_poweroff(struct platform_device *pdev); +bool dcp_sleep_keeps_firmware(struct device *dev); int dcp_typec_prepare_route(struct apple_dcp *dcp); void dcp_poweron(struct platform_device *pdev); void dcp_external_recover(struct platform_device *pdev); diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index 42caa27a508a0..a85010b15c719 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -5836,6 +5836,23 @@ bool iomfb_m4_ext_stopped(struct apple_dcp *owner) return stopped; } +/* + * Its CPU is down for the sleep: an external DCP stopped for a deep sleep, or + * an internal one powered down with its domains (iomfb_m4_power_gate()). + */ +bool iomfb_m4_sleep_stopped(struct apple_dcp *owner) +{ + struct iomfb_m4 *dcp = owner->v26_6; + bool stopped; + + if (!dcp) + return false; + mutex_lock(&dcp->lock); + stopped = dcp->ext_stopped || dcp->gated; + mutex_unlock(&dcp->lock); + return stopped; +} + /* apple-drm, a consumer of this device, has blanked the panel before this. */ int iomfb_m4_suspend(struct apple_dcp *owner) { diff --git a/drivers/gpu/drm/apple/iomfb_m4.h b/drivers/gpu/drm/apple/iomfb_m4.h index 6e09d07e0c899..cfd10118d0836 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.h +++ b/drivers/gpu/drm/apple/iomfb_m4.h @@ -81,6 +81,7 @@ void iomfb_m4_ext_relink_lost(struct apple_dcp *dcp); void iomfb_m4_ext_relink_wait(struct apple_dcp *dcp, unsigned long deadline); int iomfb_m4_ext_relink_end(struct apple_dcp *dcp); bool iomfb_m4_ext_stopped(struct apple_dcp *dcp); +bool iomfb_m4_sleep_stopped(struct apple_dcp *dcp); /* The caller has waited for the producer fence before publishing the DMA GEM. */ int iomfb_m4_present(struct apple_dcp *dcp, struct drm_framebuffer *fb, @@ -164,6 +165,7 @@ static inline void iomfb_m4_ext_relink_lost(struct apple_dcp *dcp) { } static inline void iomfb_m4_ext_relink_wait(struct apple_dcp *dcp, unsigned long deadline) { } static inline int iomfb_m4_ext_relink_end(struct apple_dcp *dcp) { return 0; } static inline bool iomfb_m4_ext_stopped(struct apple_dcp *dcp) { return false; } +static inline bool iomfb_m4_sleep_stopped(struct apple_dcp *dcp) { return false; } static inline int iomfb_m4_present(struct apple_dcp *dcp, struct drm_framebuffer *fb, dma_addr_t dva, size_t mapped) diff --git a/tools/asahi/dcpaud-sleep-hold-tests.c b/tools/asahi/dcpaud-sleep-hold-tests.c index 1c50ae05d6897..640472dce91d1 100644 --- a/tools/asahi/dcpaud-sleep-hold-tests.c +++ b/tools/asahi/dcpaud-sleep-hold-tests.c @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * The actual dcp-dp-audio late sleep callback and dev_pm_ops against an OF - * graph and driver-core model that counts every node and device reference. + * The actual dcp-dp-audio late sleep callback and dev_pm_ops, and the DCP's + * dcp_sleep_keeps_firmware(), against an OF graph and driver-core model that + * counts every node and device reference and checks the device lock. */ #include #include @@ -12,6 +13,7 @@ /* The harness builds with -Wno-unused-function. */ #define __maybe_unused #define pm_sleep_ptr(fn) (fn) +#define EXPORT_SYMBOL_GPL(sym) /* ACTUAL_PM_MACROS */ @@ -20,10 +22,21 @@ struct device_node { bool available; }; +struct device_driver { + int unused; +}; + struct device { struct device_node *of_node; int refs; - bool bound, wakeup_path, set_wakeup_path; + const struct device_driver *driver; + void *drvdata; + bool locked, set_wakeup_path; +}; + +/* What the DCP's suspend left: see the sites setting it in dcp.c. */ +struct apple_dcp { + bool sleep_fw_runs; }; struct platform_device { @@ -52,6 +65,8 @@ struct dev_pm_ops { /* The model: the dpaudio node, its endpoint, the DCP node and device. */ static struct device_node audio_node, endpoint_node, dcp_node; static struct platform_device dcp_pdev; +static const struct device_driver dcp_driver; +static struct apple_dcp dcp_state; static struct device audio_dev = { .of_node = &audio_node }; static bool have_endpoint, have_remote, have_pdev; static int force_suspend_ret, force_suspend_calls, find_calls; @@ -112,16 +127,23 @@ static void put_device(struct device *dev) dev->refs--; } -static bool device_is_bound(struct device *dev) +/* The driver core's contract: driver and driver data are read under the lock. */ +static void device_lock(struct device *dev) { - assert(dev == &dcp_pdev.dev && dev->refs > 0); - return dev->bound; + assert(dev == &dcp_pdev.dev && dev->refs > 0 && !dev->locked); + dev->locked = true; } -static bool device_wakeup_path(struct device *dev) +static void device_unlock(struct device *dev) { - assert(dev == &dcp_pdev.dev && dev->refs > 0); - return dev->wakeup_path; + assert(dev == &dcp_pdev.dev && dev->locked); + dev->locked = false; +} + +static void *dev_get_drvdata(const struct device *dev) +{ + assert(dev == &dcp_pdev.dev && dev->locked && dev->driver); + return dev->drvdata; } static void device_set_wakeup_path(struct device *dev) @@ -168,6 +190,8 @@ static int dcpaud_resume(struct device *dev) return 4; } +/* ACTUAL_DCP_FUNCTION */ + /* ACTUAL_FUNCTION */ /* ACTUAL_PM_OPS */ @@ -184,8 +208,10 @@ int main(void) have_remote = bits & 2; dcp_node.available = bits & 4; have_pdev = bits & 8; - dcp_pdev.dev.bound = bits & 16; - dcp_pdev.dev.wakeup_path = bits & 32; + dcp_pdev.dev.driver = bits & 16 ? &dcp_driver : NULL; + dcp_pdev.dev.drvdata = bits & 16 ? &dcp_state : NULL; + dcp_state.sleep_fw_runs = bits & 32; + dcp_pdev.dev.locked = false; force_suspend_ret = bits & 64 ? -EBUSY : 0; endpoint_node.refs = dcp_node.refs = dcp_pdev.dev.refs = 0; audio_dev.set_wakeup_path = false; @@ -195,13 +221,14 @@ int main(void) ret = dcpaud_pm_ops.suspend_late(&audio_dev); expect = have_endpoint && have_remote && dcp_node.available && have_pdev && - (!dcp_pdev.dev.bound || dcp_pdev.dev.wakeup_path); + (!dcp_pdev.dev.driver || dcp_state.sleep_fw_runs); if (audio_dev.set_wakeup_path != expect) fprintf(stderr, "case %#x: wakeup path %d, expected %d\n", bits, audio_dev.set_wakeup_path, expect); assert(audio_dev.set_wakeup_path == expect); /* Every reference taken is dropped, whatever the topology. */ assert(!endpoint_node.refs && !dcp_node.refs && !dcp_pdev.dev.refs); + assert(!dcp_pdev.dev.locked); /* An unavailable or missing DCP node is never looked up. */ if (!(have_endpoint && have_remote && dcp_node.available)) assert(!find_calls); diff --git a/tools/asahi/dcpaud-sleep-hold-tests.py b/tools/asahi/dcpaud-sleep-hold-tests.py index 66a5475bf6117..142a69ccb941c 100755 --- a/tools/asahi/dcpaud-sleep-hold-tests.py +++ b/tools/asahi/dcpaud-sleep-hold-tests.py @@ -5,12 +5,16 @@ genpd powers the dp-audio domain off at noirq unless the device is on the wakeup path, and cutting it under running DCP firmware resets the J473 on s2idle. dcpaud_suspend_late() puts dp-audio on the wakeup path when the DCP -linked by its OF graph exists and is unbound or on its own wakeup path. The +linked by its OF graph exists and is unbound or kept its firmware running +through the sleep (dcp_sleep_keeps_firmware()); a DCP that stopped its +firmware (S2R, the 27.x sleep, an M4 stop) leaves the domain to genpd. The fixture builds the real function and the real dcpaud_pm_ops (with the -kernel's PM_OPS macros) from drivers/gpu/drm/apple/audio.c against an OF -graph and driver-core model that counts every node and device reference. +kernel's PM_OPS macros) from drivers/gpu/drm/apple/audio.c, and the real +dcp_sleep_keeps_firmware() from dcp.c, against an OF graph and driver-core +model that counts every node and device reference and checks that the +DCP's driver data is read under its device lock. ---mutation names a change to the production function that the matrix must +--mutation names a change to a production function that the matrix must kill. --ref reads audio.c from an older revision: before the fix the late slot was pm_runtime_force_suspend, which never holds the domain, so the matrix fails (the old-code negative control). @@ -26,18 +30,26 @@ ROOT = Path(__file__).resolve().parents[2] AUDIO = "drivers/gpu/drm/apple/audio.c" +DCP = "drivers/gpu/drm/apple/dcp.c" PM = "include/linux/pm.h" +# (file, old, new): each must apply exactly once and the matrix must kill it. MUTATIONS = { - # Hold only for a DCP on its wakeup path; an unbound DCP loses the domain. - "bound-only": ("!device_is_bound(&dcp_pdev->dev) || device_wakeup_path(", - "device_wakeup_path("), + # Hold only for a bound DCP that kept its firmware; an unbound DCP loses the domain. + "bound-only": ("dcp", "runs = !dev->driver || (dcp && dcp->sleep_fw_runs);", + "runs = dcp && dcp->sleep_fw_runs;"), + # Hold for any bound DCP, also one that stopped its firmware for the sleep. + "stopped-holds": ("dcp", "(dcp && dcp->sleep_fw_runs)", "(dcp != NULL)"), + # Hold for a bound DCP that stopped its firmware, not for one that kept it. + "invert-runs": ("dcp", "(dcp && dcp->sleep_fw_runs)", "(dcp && !dcp->sleep_fw_runs)"), + # Read the driver data without the device lock. + "no-lock": ("dcp", "\tdevice_lock(dev);\n", ""), # Leak the DCP device reference from of_find_device_by_node(). - "leak-device": ("\t\tput_device(&dcp_pdev->dev);\n", ""), + "leak-device": ("audio", "\t\tput_device(&dcp_pdev->dev);\n", ""), # Leak the DCP node reference from of_graph_get_remote_port_parent(). - "leak-node": ("\tof_node_put(dcp_node);\n", ""), - # Hold for a bound DCP that is NOT on its wakeup path. - "invert-wakeup": ("|| device_wakeup_path(", "|| !device_wakeup_path("), + "leak-node": ("audio", "\tof_node_put(dcp_node);\n", ""), + # Back to the wakeup-path test that also held for a stopped DCP. + "ignore-dcp": ("audio", "if (dcp_sleep_keeps_firmware(&dcp_pdev->dev))", "if (true)"), } @@ -58,6 +70,13 @@ def function(text, name): return text[match.start():block(text, match.start())] +def dcp_function(text): + match = re.search(r"^bool dcp_sleep_keeps_firmware\(struct device \*dev\)\n\{", text, re.M) + if not match: + return None + return text[match.start():block(text, match.start())] + + def pm_ops(text): start = text.index("static const struct dev_pm_ops dcpaud_pm_ops = {") return text[start:block(text, start)] + ";\n" @@ -77,22 +96,28 @@ def main(): args = parser.parse_args() if args.ref: - audio = subprocess.check_output(["git", "show", f"{args.ref}:{AUDIO}"], - cwd=ROOT, text=True) + audio, dcp = (subprocess.check_output(["git", "show", f"{args.ref}:{path}"], + cwd=ROOT, text=True) for path in (AUDIO, DCP)) else: - audio = (ROOT / AUDIO).read_text() + audio, dcp = ((ROOT / path).read_text() for path in (AUDIO, DCP)) pm = (ROOT / PM).read_text() late = function(audio, "dcpaud_suspend_late") + keeps = dcp_function(dcp) if args.mutation: - old, new = MUTATIONS[args.mutation] - if not late or late.count(old) != 1: + where, old, new = MUTATIONS[args.mutation] + body = late if where == "audio" else keeps + if not body or body.count(old) != 1: raise RuntimeError(f"mutation {args.mutation} did not apply exactly once") - late = late.replace(old, new) + if where == "audio": + late = late.replace(old, new) + else: + keeps = keeps.replace(old, new) macros = "".join(macro(pm, name) for name in ("SYSTEM_SLEEP_PM_OPS", "LATE_SYSTEM_SLEEP_PM_OPS", "RUNTIME_PM_OPS")) code = (Path(__file__).with_suffix(".c").read_text() .replace("/* ACTUAL_PM_MACROS */", macros) + .replace("/* ACTUAL_DCP_FUNCTION */", keeps or "") .replace("/* ACTUAL_FUNCTION */", late or "") .replace("/* ACTUAL_PM_OPS */", pm_ops(audio))) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index c9e95d9d42451..c1017b5c1f84d 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -180,7 +180,8 @@ def mutations(flag, names, base, expect=KILL): # a7638d51880c, the parent of the fix, ran pm_runtime_force_suspend in the late # slot, so the dp-audio domain dropped under a running DCP. 'dcpaud-sleep-hold-tests.py': [(out(), PASS)] - + mutations('--mutation', ('bound-only', 'leak-device', 'leak-node', 'invert-wakeup'), out()) + + mutations('--mutation', ('bound-only', 'stopped-holds', 'invert-runs', 'no-lock', + 'leak-device', 'leak-node', 'ignore-dcp'), out()) + [(out() + ['--ref', 'a7638d51880ce077cfb3edfa7ff638de2be74c85'], KILL)], 'dcp-bw-scratch-window-tests.py': [([], PASS)] + mutations('--mutation', ('old-check', 'start-only'), []), 'clpc-gpu-demand-tests.py': [([], PASS)], From 19f90d0e8a3a1dffc753589b17f06ca2430a2baa Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 22:07:03 +1100 Subject: [PATCH 04/14] tools/asahi: model the DCP's firmware-runs flag in the retained-sleep test dcpext26-suspend-route-tests builds the retained-external block of dcp_platform_suspend() against its own struct apple_dcp, which now needs the sleep_fw_runs field that block sets. Add it, and check that the flag is set together with the wakeup path and stays clear when the retained sleep is refused (firmware not running, disconnect failure). Signed-off-by: Ryan Murray --- tools/asahi/dcpext26-suspend-route-tests.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/asahi/dcpext26-suspend-route-tests.py b/tools/asahi/dcpext26-suspend-route-tests.py index 8067762a9fc1b..67f13cf1bde28 100644 --- a/tools/asahi/dcpext26-suspend-route-tests.py +++ b/tools/asahi/dcpext26-suspend-route-tests.py @@ -58,7 +58,7 @@ def function(text, name): struct apple_dcp { struct { int iomfb_method_profile; } hw; void *coproc_reg; - bool crashed, ext26_blocked, external_suspended; + bool crashed, ext26_blocked, external_suspended, sleep_fw_runs; int external_error; }; static unsigned run=1, parks, unparks, wake_paths, disabled, enabled; @@ -81,19 +81,19 @@ def function(text, name): struct apple_dcp native={.hw.iomfb_method_profile=DCP_IOMFB_METHODS_J613_EXT26, .coproc_reg=(void *)0x1000,.external_suspended=true}; assert(suspend_path(&dev,&native)==0); - assert(parks==0 && disabled==0 && wake_paths==1); + assert(parks==0 && disabled==0 && wake_paths==1 && native.sleep_fw_runs); assert(resume_path(&dev,&native)==0 && unparks==0 && !native.external_suspended); - reset_counts();run=0; - assert(suspend_path(&dev,&native)==-EHOSTDOWN && parks==0 && wake_paths==0); + reset_counts();run=0;native.sleep_fw_runs=false; + assert(suspend_path(&dev,&native)==-EHOSTDOWN && parks==0 && wake_paths==0 && !native.sleep_fw_runs); assert(resume_path(&dev,&native)==-EHOSTDOWN && native.ext26_blocked && native.external_error==-EHOSTDOWN); run=1;reset_counts();disconnect_error=-EBUSY; assert(suspend_path(&dev,&native)==-EBUSY && parks==0 && wake_paths==0 && enabled==0); struct apple_dcp h17p={.hw.iomfb_method_profile=DCP_IOMFB_METHODS_H17P_EXTERNAL}; disconnect_error=0;reset_counts(); - assert(suspend_path(&dev,&h17p)==0 && parks==1 && disabled==1 && wake_paths==1); + assert(suspend_path(&dev,&h17p)==0 && parks==1 && disabled==1 && wake_paths==1 && h17p.sleep_fw_runs); assert(resume_path(&dev,&h17p)==0 && unparks==1); - reset_counts();disconnect_error=-EBUSY; - assert(suspend_path(&dev,&h17p)==-EBUSY && parks==0 && wake_paths==0 && disabled==1 && enabled==1); + reset_counts();disconnect_error=-EBUSY;h17p.sleep_fw_runs=false; + assert(suspend_path(&dev,&h17p)==-EBUSY && parks==0 && wake_paths==0 && disabled==1 && enabled==1 && !h17p.sleep_fw_runs); struct apple_dcp other={0};disconnect_error=0;reset_counts(); assert(suspend_path(&dev,&other)==0 && resume_path(&dev,&other)==0 && parks==0 && unparks==0); } @@ -106,4 +106,5 @@ def function(text, name): result = subprocess.run([str(path.with_suffix(''))]) if result.returncode: sys.exit(1) -print('PASS retained sleep: H17P park/unpark paired; native26 no park, RUN refusal; disconnect rollback preserved') +print('PASS retained sleep: H17P park/unpark paired; native26 no park, RUN refusal; disconnect rollback preserved; ' + 'firmware-runs flag set with the wakeup path only') From 002e5071067d1c7ae3cb28dd81aff48115c06652 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 23:57:29 +1100 Subject: [PATCH 05/14] drm/apple: dcp: say dcp_sleep_keeps_firmware() is for late suspend only It takes the DCP's device lock, which can sleep, so a noirq caller must not use it. Its only caller is the DP audio late suspend. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b4ff87f88c24c..7852d5e22a492 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9744,8 +9744,9 @@ static void dcp_t8132_sleep_stopped(struct apple_dcp *dcp) * dcp_sleep_keeps_firmware - whether a DCP's firmware runs through this sleep * @dev: the DCP device * - * For blocks the DCP's firmware drives (DP audio), from their late or noirq - * suspend, after every device's .suspend: true when the DCP's suspend left + * For blocks the DCP's firmware drives (DP audio), from their late suspend, + * after every device's .suspend. It takes the DCP's device lock, which can + * sleep, so it is not for the noirq phase. True when the DCP's suspend left * its coprocessor running with its domains on, or when no driver is bound * (a boot stage or an earlier bind may have left the firmware running). * False when the suspend stopped the firmware (S2R, the 27.x sleep, an M4 From 3437a5a3730eaedf6708bc1cabcdb808235e32c7 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 13:45:12 +1100 Subject: [PATCH 06/14] drm/apple: dcp: keep the DP PHY of a DCP whose firmware runs through a sleep A DCP that keeps its coprocessor running through a sleep puts itself on the wakeup path, so genpd leaves its own domains up. The DP PHY that its firmware drives is a separate device under its own domain, and genpd powers that domain off at noirq like any other. With the firmware still running, that resets the SoC: on the M2 Mac mini (J473) with firmware 27.2, s2idle reset in the first freeze whenever a DCP driver was bound, both for the HDMI dcpext (dptx_ext_phy) and for the USB-C primary (its route's ATC PHY). Holding both PHY domains on through the sleep was enough for the sleep to pass; holding either one alone was not. Where the suspend leaves the firmware running (sleep_fw_runs), also put the provider devices of the DCP's dp-phy and of its active Type-C route's PHY on the wakeup path. A DCP that stops its firmware for the sleep leaves its PHYs to genpd as before. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7852d5e22a492..78464acdb2e07 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9766,6 +9766,27 @@ bool dcp_sleep_keeps_firmware(struct device *dev) } EXPORT_SYMBOL_GPL(dcp_sleep_keeps_firmware); +/* + * A DCP whose firmware runs through a sleep keeps driving the DP PHY of its + * output, so the PHY's power domain has to stay up with the DCP's own: cut at + * noirq under the running firmware, it resets the SoC (J473, firmware 27.2). + * Put the PHY devices in use on the wakeup path, as the DCP itself is. + */ +static void dcp_phy_set_wakeup_path(struct phy *phy) +{ + if (!IS_ERR_OR_NULL(phy) && phy->dev.parent) + device_set_wakeup_path(phy->dev.parent); +} + +static void dcp_sleep_hold_phys(struct apple_dcp *dcp) +{ + struct apple_dcp_typec_route *route = READ_ONCE(dcp->active_typec_route); + + dcp_phy_set_wakeup_path(dcp->phy); + if (route) + dcp_phy_set_wakeup_path(route->phy); +} + static int dcp_platform_suspend(struct device *dev) { struct apple_dcp *dcp = dev_get_drvdata(dev); @@ -9828,6 +9849,8 @@ static int dcp_platform_suspend(struct device *dev) dcp_t8132_sleep_stopped(dcp); dcp->sleep_fw_runs = !iomfb_m4_sleep_stopped(dcp); device_set_wakeup_path(dev); + if (dcp->sleep_fw_runs) + dcp_sleep_hold_phys(dcp); return 0; } if (dcp_is_ext26(dcp) && pm_suspend_target_state != PM_SUSPEND_TO_IDLE) { @@ -9884,6 +9907,7 @@ static int dcp_platform_suspend(struct device *dev) dcp_typec_route_park(dcp); dcp->sleep_fw_runs = true; device_set_wakeup_path(dev); + dcp_sleep_hold_phys(dcp); if (dcp_is_ext26(dcp)) dev_dbg(dev, "native26 retained s2idle stop; firmware and supplier leases held\n"); return 0; @@ -9918,6 +9942,7 @@ static int dcp_platform_suspend(struct device *dev) */ dcp->sleep_fw_runs = true; device_set_wakeup_path(dev); + dcp_sleep_hold_phys(dcp); /* Last: the steps above still talk to the coprocessor. */ dcp_hold_for_sleep(dcp); From c672252ba5d2569273cf90b1bc6b01fbf5ba8361 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 13:45:12 +1100 Subject: [PATCH 07/14] tools/asahi: test the DCP sleep PHY hold Build the real dcp_phy_set_wakeup_path() and dcp_sleep_hold_phys() from dcp.c against a small driver-core model and check which PHY providers end up on the wakeup path: a dcpext's own dp-phy, a primary's Type-C route PHY, both, neither, an error pointer from the optional lookup and a PHY without a provider. Four mutations (no route PHY, no own PHY, the class device instead of the provider, no error check) must fail. Signed-off-by: Ryan Murray --- tools/asahi/dcp-sleep-phy-hold-tests.py | 134 ++++++++++++++++++++++++ tools/asahi/run-host-tests.py | 3 + 2 files changed, 137 insertions(+) create mode 100755 tools/asahi/dcp-sleep-phy-hold-tests.py diff --git a/tools/asahi/dcp-sleep-phy-hold-tests.py b/tools/asahi/dcp-sleep-phy-hold-tests.py new file mode 100755 index 0000000000000..05105c3c8dcef --- /dev/null +++ b/tools/asahi/dcp-sleep-phy-hold-tests.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Run the actual DCP sleep PHY hold over every PHY topology. + +A DCP whose firmware keeps running through a sleep keeps driving the DP PHY +of its output. genpd powers the PHY's domain off at noirq unless the PHY's +device is on the wakeup path, and cutting it under the running firmware +resets the J473 (firmware 27.2) on s2idle. dcp_sleep_hold_phys() puts the +provider device of the DCP's own dp-phy and of its active Type-C route's PHY +on the wakeup path. The fixture builds the real dcp_phy_set_wakeup_path() and +dcp_sleep_hold_phys() from drivers/gpu/drm/apple/dcp.c against a small +driver-core model and checks which devices end up on the wakeup path. + +--mutation names a change to the production functions that the matrix must +kill. +""" +import argparse +import os +import re +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +DCP = "drivers/gpu/drm/apple/dcp.c" + +MUTATIONS = { + # Forget the Type-C route's PHY (the USB-C output of a primary DCP). + "no-route": ("\tif (route)\n\t\tdcp_phy_set_wakeup_path(route->phy);\n", ""), + # Forget the DCP's own dp-phy (the HDMI output of a dcpext). + "no-own-phy": ("\tdcp_phy_set_wakeup_path(dcp->phy);\n", ""), + # Mark the PHY class device instead of the provider genpd sees. + "class-device": ("device_set_wakeup_path(phy->dev.parent);", "device_set_wakeup_path(&phy->dev);"), + # Trust an error pointer. + "no-err-check": ("!IS_ERR_OR_NULL(phy) && ", "phy && "), +} + +HARNESS = r''' +#include +#include +#include +#include +#include +#include +static volatile int cur_line; +static void on_segv(int sig) { char b[64]; int n = snprintf(b, sizeof(b), "FAIL line %d (signal %d)\n", cur_line, sig); write(1, b, n); _exit(1); } +#define READ_ONCE(x) (x) +#define MAX_ERRNO 4095 +#define IS_ERR_VALUE(x) ((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO) +static inline bool IS_ERR_OR_NULL(const void *p) { return !p || IS_ERR_VALUE((unsigned long)p); } +struct device { struct device *parent; bool wakeup_path; }; +static void device_set_wakeup_path(struct device *dev) +{ + if (IS_ERR_VALUE((unsigned long)dev)) { printf("FAIL line %d error pointer\n", cur_line); exit(1); } + dev->wakeup_path = true; +} +struct phy { struct device dev; }; +struct apple_dcp_typec_route { struct phy *phy; }; +struct apple_dcp { struct phy *phy; struct apple_dcp_typec_route *active_typec_route; }; +@@FUNCS@@ +int main(void) +{ + struct device own_prov = {0}, route_prov = {0}, other_prov = {0}; + struct phy own = { .dev = { .parent = &own_prov } }; + struct phy rphy = { .dev = { .parent = &route_prov } }; + struct phy orphan = { .dev = { .parent = NULL } }; + struct apple_dcp_typec_route route = { .phy = &rphy }, noroute_phy = { .phy = NULL }; + struct apple_dcp d; + int fail = 0; + + signal(SIGSEGV, on_segv); +#define RESET() do { own_prov.wakeup_path = route_prov.wakeup_path = other_prov.wakeup_path = false; \ + own.dev.wakeup_path = rphy.dev.wakeup_path = orphan.dev.wakeup_path = false; } while (0) +#define CHECK(name, cond) do { if (!(cond)) { printf("FAIL line %d %s\n", __LINE__, name); fail++; } else printf("ok %s\n", name); } while (0) +#define HOLD(dcp) do { cur_line = __LINE__; fflush(stdout); dcp_sleep_hold_phys(dcp); } while (0) + /* dcpext: its own dp-phy, no Type-C route */ + RESET(); d.phy = &own; d.active_typec_route = NULL; HOLD(&d); + CHECK("dcpext dp-phy provider held", own_prov.wakeup_path && !own.dev.wakeup_path); + /* primary with a Type-C route and no own phy */ + RESET(); d.phy = NULL; d.active_typec_route = &route; HOLD(&d); + CHECK("route phy provider held", route_prov.wakeup_path && !rphy.dev.wakeup_path && !own_prov.wakeup_path); + /* both */ + RESET(); d.phy = &own; d.active_typec_route = &route; HOLD(&d); + CHECK("both held", own_prov.wakeup_path && route_prov.wakeup_path); + /* nothing to hold */ + RESET(); d.phy = NULL; d.active_typec_route = NULL; HOLD(&d); + CHECK("none", !own_prov.wakeup_path && !route_prov.wakeup_path && !other_prov.wakeup_path); + /* an optional phy lookup error and a route without a phy */ + RESET(); d.phy = (struct phy *)(intptr_t)-19; d.active_typec_route = &noroute_phy; HOLD(&d); + CHECK("error phy and phy-less route ignored", !own_prov.wakeup_path && !route_prov.wakeup_path); + /* a phy without a provider parent */ + RESET(); d.phy = &orphan; d.active_typec_route = NULL; HOLD(&d); + CHECK("parentless phy ignored", !orphan.dev.wakeup_path); + printf("%d failures\n", fail); + return fail != 0; +} +''' + +def extract(src, name): + m = re.search(r'^static void %s\(.*?^}\n' % re.escape(name), src, re.S | re.M) + if not m: + sys.exit(f"{name} not found in {DCP}") + return m.group(0) + +def run(mutation): + src = (ROOT / DCP).read_text() + funcs = extract(src, "dcp_phy_set_wakeup_path") + "\n" + extract(src, "dcp_sleep_hold_phys") + if mutation: + old, new = MUTATIONS[mutation] + if funcs.count(old) != 1: + sys.exit(f"mutation {mutation} does not apply exactly once") + funcs = funcs.replace(old, new) + with tempfile.TemporaryDirectory() as tmp: + c = Path(tmp) / "t.c" + exe = Path(tmp) / "t" + c.write_text(HARNESS.replace("@@FUNCS@@", funcs)) + flags = ["-std=gnu11", "-Wall"] + ([] if mutation else ["-Werror"]) + subprocess.run([os.environ.get("CC", "cc"), *flags, "-o", exe, c], check=True) + r = subprocess.run([exe], capture_output=True, text=True) + out = r.stdout + r.stderr + bad = r.returncode != 0 + return bad, out + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--mutation", choices=sorted(MUTATIONS)) + a = ap.parse_args() + bad, out = run(a.mutation) + print(out, end="") + sys.exit(1 if bad else 0) + +if __name__ == "__main__": + main() diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index c1017b5c1f84d..d82fd59b625ce 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -183,6 +183,9 @@ def mutations(flag, names, base, expect=KILL): + mutations('--mutation', ('bound-only', 'stopped-holds', 'invert-runs', 'no-lock', 'leak-device', 'leak-node', 'ignore-dcp'), out()) + [(out() + ['--ref', 'a7638d51880ce077cfb3edfa7ff638de2be74c85'], KILL)], + # A DCP whose firmware runs through the sleep holds its DP PHYs' domains. + 'dcp-sleep-phy-hold-tests.py': [([], PASS)] + + mutations('--mutation', ('no-route', 'no-own-phy', 'class-device', 'no-err-check'), []), 'dcp-bw-scratch-window-tests.py': [([], PASS)] + mutations('--mutation', ('old-check', 'start-only'), []), 'clpc-gpu-demand-tests.py': [([], PASS)], 'clpc-high-power-cleanup-tests.py': [(out(), PASS), From 2267280d9c771a7df3b616272977b18c6a19c698 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 16:12:49 +1100 Subject: [PATCH 08/14] drm/apple: dcp: keep a still-attached HDMI link through a sleep The system suspend of a DCP whose firmware keeps running reported its fixed HDMI output unplugged and released its link on every sleep, since 0b1c93b9 ("drm: apple: dptx: Issue HPD event early on gpio/type-c disconnect"), also with the display still attached. After the wake nothing connects it again: HPD stayed high through the sleep, so no edge comes, and the CRTC that userspace turned off for the unplug never runs dcp_poweron(). On the M2 Mac mini (firmware 27.2) the release also timed out (RemotePort call 7, -110) and the converter pulsed HPD after the relink, and HDMI stayed dark after the first s2idle. Release it only when its HPD reads low, as DPMS off does (dcp_poweroff()). A display that stays attached keeps its link through the sleep, as through DPMS off, and resume lights it again through dcp_poweron(). A display that is unplugged during the sleep is still reported and released as when awake. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 78464acdb2e07..52fce51dbec2f 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9930,7 +9930,18 @@ static int dcp_platform_suspend(struct device *dev) if (dcp->hdmi_hpd_irq) { disable_irq(dcp->hdmi_hpd_irq); - if (!dcp->active_typec_route) { + /* + * The firmware runs through this sleep, so the HDMI output + * keeps its link as through DPMS off (see dcp_poweroff()), and + * resume lights it again through dcp_poweron(). Only a display + * that is gone is reported and released here. Releasing one + * that stays attached reports it unplugged, and nothing + * connects it again after the wake: its HPD stays high, so no + * edge comes, and a CRTC userspace turned off for the unplug + * never runs dcp_poweron(). + */ + if (!dcp->active_typec_route && + gpiod_get_value_cansleep(dcp->hdmi_hpd) <= 0) { disconnected_hpd_event(dcp->connector); dcp_dptx_disconnect(dcp, 0); } From 245f899b2725ea8111f6ceb71bdd15a90fb2693f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 16:25:45 +1100 Subject: [PATCH 09/14] tools/asahi: stub the DP PHY hold in the dcpext26 suspend route test The test builds dcp_platform_suspend() from dcp.c, which now also holds the DP PHYs of a DCP whose firmware runs through the sleep. That hold has its own test; stub it here. Signed-off-by: Ryan Murray --- tools/asahi/dcpext26-suspend-route-tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/asahi/dcpext26-suspend-route-tests.py b/tools/asahi/dcpext26-suspend-route-tests.py index 67f13cf1bde28..5201f36841e49 100644 --- a/tools/asahi/dcpext26-suspend-route-tests.py +++ b/tools/asahi/dcpext26-suspend-route-tests.py @@ -70,6 +70,8 @@ def function(text, name): static void dcp_enable_typec_work(struct apple_dcp *d) { enabled++; } static int dcp_external_disconnect(struct apple_dcp *d,bool wait) { return disconnect_error; } static void device_set_wakeup_path(struct device *d) { wake_paths++; } +/* The DP PHY hold has its own test (dcp-sleep-phy-hold-tests.py). */ +static void dcp_sleep_hold_phys(struct apple_dcp *d) { (void)d; } static void reset_counts(void) { parks=unparks=wake_paths=disabled=enabled=0; } ''' code = pre + function(header, 'dcp_is_ext26') + '\n' + function(source, 'dcp_is_external_h17p') + '\n' + function(source, 'dcp_is_retained_external') From 702e0c301cfb4745597920aba7aaf8df80e7d384 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 16:45:21 +1100 Subject: [PATCH 10/14] drm/apple: read the sleep PHYs under the fabric lock Read the selected Type-C route and the PHY pointers together while the display fabric holds its route lock. Mark those provider devices before a route handoff can change the selected PHY. The host fixture checks that the provider is marked under the same lock. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-fabric.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/apple/dcp-fabric.h | 1 + drivers/gpu/drm/apple/dcp.c | 21 --------------------- tools/asahi/dcp-sleep-phy-hold-tests.py | 21 +++++++++++++++++---- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 08f5057cf1a9d..b81598df13062 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -4995,6 +4995,29 @@ int dcp_register_typec_routes(struct apple_dcp *dcp) return dcp_fabric_run_probe(!!routes, dcp_register_typec_routes_present, &ctx); } +/* + * A DCP whose firmware runs through a sleep keeps driving the DP PHY of its + * output, so the PHY's power domain has to stay up with the DCP's own: cut at + * noirq under the running firmware, it resets the SoC (J473, firmware 27.2). + * Put the PHY devices in use on the wakeup path, as the DCP itself is. + */ +static void dcp_phy_set_wakeup_path(struct phy *phy) +{ + if (!IS_ERR_OR_NULL(phy) && phy->dev.parent) + device_set_wakeup_path(phy->dev.parent); +} + +void dcp_sleep_hold_phys(struct apple_dcp *dcp) +{ + struct apple_dcp_typec_route *route; + + guard(mutex)(&dcp_typec_fabric_lock); + route = dcp->active_typec_route; + dcp_phy_set_wakeup_path(dcp->phy); + if (route) + dcp_phy_set_wakeup_path(route->phy); +} + /* * A sleep that reaches its commit powers the crossbar off. Take the output of a direct * route down while it still has power, as a released display's is, and select it again diff --git a/drivers/gpu/drm/apple/dcp-fabric.h b/drivers/gpu/drm/apple/dcp-fabric.h index 65082081e2b1b..a7d13d8094278 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.h +++ b/drivers/gpu/drm/apple/dcp-fabric.h @@ -131,6 +131,7 @@ bool dcp_is_t8132_ext(const struct apple_dcp *dcp); /* DCP probe, resume and endpoint teardown hooks. */ int dcp_register_typec_routes(struct apple_dcp *dcp); +void dcp_sleep_hold_phys(struct apple_dcp *dcp); void dcp_typec_route_park(struct apple_dcp *dcp); void dcp_typec_route_unpark(struct apple_dcp *dcp); int dcp_fabric_sleep_release(struct apple_dcp *dcp, s64 ms[2]); diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 52fce51dbec2f..6792821229e16 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9766,27 +9766,6 @@ bool dcp_sleep_keeps_firmware(struct device *dev) } EXPORT_SYMBOL_GPL(dcp_sleep_keeps_firmware); -/* - * A DCP whose firmware runs through a sleep keeps driving the DP PHY of its - * output, so the PHY's power domain has to stay up with the DCP's own: cut at - * noirq under the running firmware, it resets the SoC (J473, firmware 27.2). - * Put the PHY devices in use on the wakeup path, as the DCP itself is. - */ -static void dcp_phy_set_wakeup_path(struct phy *phy) -{ - if (!IS_ERR_OR_NULL(phy) && phy->dev.parent) - device_set_wakeup_path(phy->dev.parent); -} - -static void dcp_sleep_hold_phys(struct apple_dcp *dcp) -{ - struct apple_dcp_typec_route *route = READ_ONCE(dcp->active_typec_route); - - dcp_phy_set_wakeup_path(dcp->phy); - if (route) - dcp_phy_set_wakeup_path(route->phy); -} - static int dcp_platform_suspend(struct device *dev) { struct apple_dcp *dcp = dev_get_drvdata(dev); diff --git a/tools/asahi/dcp-sleep-phy-hold-tests.py b/tools/asahi/dcp-sleep-phy-hold-tests.py index 05105c3c8dcef..b0cf23c94c5d1 100755 --- a/tools/asahi/dcp-sleep-phy-hold-tests.py +++ b/tools/asahi/dcp-sleep-phy-hold-tests.py @@ -8,7 +8,7 @@ resets the J473 (firmware 27.2) on s2idle. dcp_sleep_hold_phys() puts the provider device of the DCP's own dp-phy and of its active Type-C route's PHY on the wakeup path. The fixture builds the real dcp_phy_set_wakeup_path() and -dcp_sleep_hold_phys() from drivers/gpu/drm/apple/dcp.c against a small +dcp_sleep_hold_phys() from drivers/gpu/drm/apple/dcp-fabric.c against a small driver-core model and checks which devices end up on the wakeup path. --mutation names a change to the production functions that the matrix must @@ -23,7 +23,7 @@ from pathlib import Path ROOT = Path(__file__).resolve().parents[2] -DCP = "drivers/gpu/drm/apple/dcp.c" +DCP = "drivers/gpu/drm/apple/dcp-fabric.c" MUTATIONS = { # Forget the Type-C route's PHY (the USB-C output of a primary DCP). @@ -44,14 +44,27 @@ #include #include static volatile int cur_line; +static bool dcp_typec_fabric_lock; +static bool *lock_acquire(bool *held) +{ + if (*held) + abort(); + *held = true; + return held; +} +static void lock_release(bool **held) { **held = false; } +#define guard(kind) bool *__attribute__((cleanup(lock_release))) held = lock_acquire static void on_segv(int sig) { char b[64]; int n = snprintf(b, sizeof(b), "FAIL line %d (signal %d)\n", cur_line, sig); write(1, b, n); _exit(1); } -#define READ_ONCE(x) (x) #define MAX_ERRNO 4095 #define IS_ERR_VALUE(x) ((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO) static inline bool IS_ERR_OR_NULL(const void *p) { return !p || IS_ERR_VALUE((unsigned long)p); } struct device { struct device *parent; bool wakeup_path; }; static void device_set_wakeup_path(struct device *dev) { + if (!dcp_typec_fabric_lock) { + printf("FAIL line %d wakeup mark without fabric lock\n", cur_line); + exit(1); + } if (IS_ERR_VALUE((unsigned long)dev)) { printf("FAIL line %d error pointer\n", cur_line); exit(1); } dev->wakeup_path = true; } @@ -98,7 +111,7 @@ ''' def extract(src, name): - m = re.search(r'^static void %s\(.*?^}\n' % re.escape(name), src, re.S | re.M) + m = re.search(r'^(?:static )?void %s\(.*?^}\n' % re.escape(name), src, re.S | re.M) if not m: sys.exit(f"{name} not found in {DCP}") return m.group(0) From 1274718dc5fde504e2ea7ac670d938556640764c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 16:45:21 +1100 Subject: [PATCH 11/14] arm64: dts: apple: t8112: allow the display PHY domains to wake Describe active wakeup for the external DPTX and two ATC USB domains. A domain that is off at PMGR probe can be powered by a later display attachment. The property lets genpd honor a subsequent consumer wakeup-path mark while the DCP keeps running through suspend. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8112-pmgr.dtsi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi index e2564eac95e50..ba14aa4eac309 100644 --- a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi @@ -715,6 +715,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "dptx_ext_phy"; + apple,sleep-wakeup-path; }; ps_dispdfr_fe: power-controller@3e0 { @@ -1288,6 +1289,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc0_usb"; + apple,sleep-wakeup-path; power-domains = <&ps_atc0_usb_aon>, <&ps_atc0_common>; }; @@ -1297,6 +1299,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc1_usb"; + apple,sleep-wakeup-path; power-domains = <&ps_atc1_usb_aon>, <&ps_atc1_common>; }; From 31ba92a7d68c1a3c733d58f1e091dc2f9c6cef5a Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 16:51:49 +1100 Subject: [PATCH 12/14] drm/apple: dcp: release an HDMI display unplugged during a sleep A DCP whose firmware runs through a sleep keeps an attached HDMI display's link, so the display lights again on wake. Its HPD IRQ is masked through the sleep, and on a fixed HDMI output nothing else sees an unplug made then: the connector stayed connected after the wake. On resume, before the HPD IRQ is enabled again, release a display whose HPD now reads low, as an unplug while awake is: report the hotplug, release the DPTX link and tell the fabric. An edge from then on is replayed when the IRQ comes back. A failed GPIO read cannot establish absence and leaves the display connected; a pipeline a Type-C display owns is not touched. A T6030 native HDMI output still releases its link at suspend, attached or not: its resume sets the converter, PHY and crossbar up again (dcp_fabric_hdmi_reinit()), which needs the link down. tools/asahi/dcp-hdmi-sleep-unplug-tests.py runs the real suspend HDMI block and the resume release over kept, unplugged-in-sleep, gone-before, GPIO error, borrowed and T6030 native cases, and checks the release runs before the IRQ comes back; five mutations are killed. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 27 ++- tools/asahi/dcp-hdmi-sleep-unplug-tests.py | 188 +++++++++++++++++++++ tools/asahi/run-host-tests.py | 4 + 3 files changed, 217 insertions(+), 2 deletions(-) create mode 100755 tools/asahi/dcp-hdmi-sleep-unplug-tests.py diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 6792821229e16..210c95547a484 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9917,10 +9917,13 @@ static int dcp_platform_suspend(struct device *dev) * that stays attached reports it unplugged, and nothing * connects it again after the wake: its HPD stays high, so no * edge comes, and a CRTC userspace turned off for the unplug - * never runs dcp_poweron(). + * never runs dcp_poweron(). A T6030 native output's resume sets + * its PHY and crossbar up again (dcp_fabric_hdmi_reinit()), + * which needs the link down, so it is still released. */ if (!dcp->active_typec_route && - gpiod_get_value_cansleep(dcp->hdmi_hpd) <= 0) { + (dcp->external_native || + gpiod_get_value_cansleep(dcp->hdmi_hpd) <= 0)) { disconnected_hpd_event(dcp->connector); dcp_dptx_disconnect(dcp, 0); } @@ -9939,6 +9942,23 @@ static int dcp_platform_suspend(struct device *dev) return 0; } +/* + * The suspend kept an attached HDMI display's link (dcp_platform_suspend()). + * One unplugged during the sleep made no edge the masked HPD IRQ saw, and + * nothing else reports it: release it now, as an unplug while awake is. + */ +static void dcp_hdmi_unplugged_in_sleep(struct apple_dcp *dcp) +{ + if (READ_ONCE(dcp->active_typec_route) || !dcp->connector || + !READ_ONCE(dcp->connector->connected) || + gpiod_get_value_cansleep(dcp->hdmi_hpd) != 0) + return; + dev_info(dcp->dev, "HDMI display unplugged during sleep\n"); + disconnected_hpd_event(dcp->connector); + dcp_dptx_disconnect(dcp, 0); + dcp_fabric_hdmi_unplugged(dcp); +} + static int dcp_platform_resume(struct device *dev) { struct apple_dcp *dcp = dev_get_drvdata(dev); @@ -9985,6 +10005,9 @@ static int dcp_platform_resume(struct device *dev) /* The HDMI output's PHY and crossbar may have lost their setup in sleep. */ if (dcp->external_native) dcp_fabric_hdmi_reinit(dcp, "after system sleep"); + /* Before the HPD IRQ comes back: an edge from now on is replayed. */ + if (dcp->hdmi_hpd_irq) + dcp_hdmi_unplugged_in_sleep(dcp); /* Observe future edges before sampling any edges lost in sleep. */ if (dcp->hdmi_hpd_irq) dcp_fabric_run_resume(&dcp_resume_ops, dcp); diff --git a/tools/asahi/dcp-hdmi-sleep-unplug-tests.py b/tools/asahi/dcp-hdmi-sleep-unplug-tests.py new file mode 100755 index 0000000000000..df588dcdc16e2 --- /dev/null +++ b/tools/asahi/dcp-hdmi-sleep-unplug-tests.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Run the real HDMI sleep keep-link and the unplugged-in-sleep release. + +A DCP whose firmware runs through a sleep keeps an attached HDMI display's +link (dcp_platform_suspend()), so the display lights again on wake. Its HPD +IRQ is masked through the sleep, so a display unplugged during it makes no +edge anyone sees: dcp_hdmi_unplugged_in_sleep() releases it on resume, before +the IRQ comes back. A T6030 native output still releases the link at suspend, +because its resume sets the PHY and crossbar up again. + +The fixture compiles the HDMI block of dcp_platform_suspend() and +dcp_hdmi_unplugged_in_sleep() from drivers/gpu/drm/apple/dcp.c against mocks +and checks which displays are released. --mutation names a change to the +production code that the matrix must kill. +""" +import argparse +import re +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +DCP = 'drivers/gpu/drm/apple/dcp.c' +RESUME_CALL = '\tif (dcp->hdmi_hpd_irq)\n\t\tdcp_hdmi_unplugged_in_sleep(dcp);\n' + +MUTATIONS = { + # Keep a T6030 native output's link, which its resume reinit tears down. + 'keep-native': ('(dcp->external_native ||\n\t\t gpiod_get_value_cansleep(dcp->hdmi_hpd) <= 0)', + '(gpiod_get_value_cansleep(dcp->hdmi_hpd) <= 0)'), + # Release on a failed GPIO read, which cannot establish absence. + 'gpio-error': ('gpiod_get_value_cansleep(dcp->hdmi_hpd) != 0)\n\t\treturn;', + 'gpiod_get_value_cansleep(dcp->hdmi_hpd) > 0)\n\t\treturn;'), + # Release the HDMI connector while a Type-C display owns the pipeline. + 'ignore-borrowed': ('if (READ_ONCE(dcp->active_typec_route) || !dcp->connector ||', + 'if (!dcp->connector ||'), + # Leave the hybrid fabric thinking HDMI is still there. + 'no-fabric': ('\tdcp_dptx_disconnect(dcp, 0);\n\tdcp_fabric_hdmi_unplugged(dcp);\n}', + '\tdcp_dptx_disconnect(dcp, 0);\n}'), + # Never look for an unplug after the sleep. + 'no-resume-check': (RESUME_CALL, ''), +} + +def block(text, start): + opening = text.index('{', start) + depth = 0 + for end in range(opening, len(text)): + depth += text[end] == '{' + depth -= text[end] == '}' + if not depth: + return text[start:end + 1] + raise AssertionError('unbalanced production block') + +def function(text, name): + match = re.search(r'\n(static [^\n;]*\b' + name + r'\([^;{}]*\)\n)\{', text) + assert match, name + return block(text, match.start(1)) + +HARNESS = r''' +#include +#include +#include +#define READ_ONCE(x) (x) +#define dev_info(...) ((void)0) +struct device { int unused; }; +struct gpio_desc { int level; }; +struct apple_connector { bool connected; }; +struct apple_dcp { + struct device *dev; + void *active_typec_route; + struct apple_connector *connector; + struct gpio_desc *hdmi_hpd; + int hdmi_hpd_irq; + bool external_native; +}; +static unsigned hpd_events, disconnects, fabric_unplugs, irq_off; +static int gpiod_get_value_cansleep(struct gpio_desc *g) { return g->level; } +static void disable_irq(int irq) { irq_off++; } +static void disconnected_hpd_event(struct apple_connector *c) { c->connected = false; hpd_events++; } +static int dcp_dptx_disconnect(struct apple_dcp *d, int port) { disconnects++; return 0; } +static void dcp_fabric_hdmi_unplugged(struct apple_dcp *d) { fabric_unplugs++; } +static void reset(void) { hpd_events = disconnects = fabric_unplugs = irq_off = 0; } +''' + +CHECKS = r''' +static void suspend_hdmi(struct apple_dcp *dcp) { SUSPEND } + +static int failures; +#define CHECK(c) do { if (!(c)) { printf("FAIL line %d (%s: %s)\n", __LINE__, case_name, #c); failures++; } } while (0) + +int main(void) +{ + const char *case_name; + struct apple_connector con; + struct gpio_desc hpd; + struct apple_dcp dcp; + int route; + +#define SETUP(name, L, N) do { case_name = name; reset(); con.connected = true; \ + hpd.level = L; dcp = (struct apple_dcp){ .connector = &con, .hdmi_hpd = &hpd, \ + .hdmi_hpd_irq = 7, .external_native = N }; } while (0) + + /* Attached through the sleep: kept, lit again on wake. */ + SETUP("kept", 1, false); + suspend_hdmi(&dcp); + CHECK(irq_off == 1 && con.connected && !disconnects); + dcp_hdmi_unplugged_in_sleep(&dcp); + CHECK(con.connected && !disconnects && !fabric_unplugs); + + /* Unplugged during the sleep: released on resume, fabric told. */ + SETUP("unplugged-in-sleep", 1, false); + suspend_hdmi(&dcp); + hpd.level = 0; + dcp_hdmi_unplugged_in_sleep(&dcp); + CHECK(!con.connected && hpd_events == 1 && disconnects == 1 && fabric_unplugs == 1); + + /* Gone before the sleep: released at suspend, nothing on resume. */ + SETUP("gone-before", 0, false); + suspend_hdmi(&dcp); + CHECK(!con.connected && disconnects == 1); + dcp_hdmi_unplugged_in_sleep(&dcp); + CHECK(disconnects == 1 && hpd_events == 1 && !fabric_unplugs); + + /* A failed GPIO read cannot establish absence. */ + SETUP("gpio-error", 1, false); + suspend_hdmi(&dcp); + hpd.level = -5; + dcp_hdmi_unplugged_in_sleep(&dcp); + CHECK(con.connected && !disconnects); + + /* A Type-C display owns the pipeline: the HDMI side is not touched. */ + SETUP("borrowed", 0, false); + dcp.active_typec_route = &route; + suspend_hdmi(&dcp); + dcp_hdmi_unplugged_in_sleep(&dcp); + CHECK(con.connected && !disconnects && !hpd_events && !fabric_unplugs); + + /* T6030 native output: released at suspend even while attached. */ + SETUP("native", 1, true); + suspend_hdmi(&dcp); + CHECK(!con.connected && disconnects == 1); + dcp_hdmi_unplugged_in_sleep(&dcp); + CHECK(disconnects == 1); + + if (failures) + return 1; + puts("PASS HDMI sleep: attached kept, unplugged-in-sleep released on resume, " + "gone-before released at suspend, GPIO error and borrowed pipeline untouched, " + "T6030 native released"); + return 0; +} +''' + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--mutation', choices=sorted(MUTATIONS)) + args = parser.parse_args() + + source = (ROOT / DCP).read_text() + if args.mutation: + old, new = MUTATIONS[args.mutation] + assert source.count(old) == 1, args.mutation + source = source.replace(old, new) + + resume = function(source, 'dcp_platform_resume') + # The release runs while the HPD IRQ is still masked: an edge from then + # on is replayed when dcp_fabric_run_resume() enables it. + if RESUME_CALL not in resume or \ + resume.index(RESUME_CALL) > resume.index('dcp_fabric_run_resume(&dcp_resume_ops, dcp)'): + print('FAIL line 0 (resume: no unplugged-in-sleep release before the HPD IRQ comes back)') + sys.exit(1) + + suspend = function(source, 'dcp_platform_suspend') + hdmi = block(suspend, suspend.index('\tif (dcp->hdmi_hpd_irq) {\n\t\tdisable_irq')) + code = HARNESS + function(source, 'dcp_hdmi_unplugged_in_sleep') + \ + CHECKS.replace('SUSPEND', hdmi) + + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / 'check.c' + path.write_text(code) + subprocess.run(['clang', '-std=gnu11', '-Wall', '-Werror', '-Wno-unused-function', + '-fsanitize=address,undefined', str(path), '-o', str(path.with_suffix(''))], + check=True) + sys.exit(subprocess.run([str(path.with_suffix(''))]).returncode) + +if __name__ == '__main__': + main() diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index d82fd59b625ce..48f7fb10a528a 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -186,6 +186,10 @@ def mutations(flag, names, base, expect=KILL): # A DCP whose firmware runs through the sleep holds its DP PHYs' domains. 'dcp-sleep-phy-hold-tests.py': [([], PASS)] + mutations('--mutation', ('no-route', 'no-own-phy', 'class-device', 'no-err-check'), []), + # An HDMI display kept through a sleep but unplugged during it is released on resume. + 'dcp-hdmi-sleep-unplug-tests.py': [([], PASS)] + + mutations('--mutation', ('keep-native', 'gpio-error', 'ignore-borrowed', 'no-fabric', + 'no-resume-check'), []), 'dcp-bw-scratch-window-tests.py': [([], PASS)] + mutations('--mutation', ('old-check', 'start-only'), []), 'clpc-gpu-demand-tests.py': [([], PASS)], 'clpc-high-power-cleanup-tests.py': [(out(), PASS), From ca69a305525df1b2f7b18e9c4dfd095908f376d4 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 18:04:58 +1100 Subject: [PATCH 13/14] arm64: dts: apple: revert T8112 display PHY wakeup flags The J473 combined kernel stalled before journald with the newly composed Stage 2 and reached userspace with the earlier Stage 2 on the same kernel. The compiled device trees differ by the three wakeup properties added by 1274718dc5fd. Remove those properties while the handoff is investigated. The J473 and J413 device trees compile, and the combined J473 firmware-27 DTB built after this revert is byte-identical to the booted reference. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8112-pmgr.dtsi | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi index ba14aa4eac309..e2564eac95e50 100644 --- a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi @@ -715,7 +715,6 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "dptx_ext_phy"; - apple,sleep-wakeup-path; }; ps_dispdfr_fe: power-controller@3e0 { @@ -1289,7 +1288,6 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc0_usb"; - apple,sleep-wakeup-path; power-domains = <&ps_atc0_usb_aon>, <&ps_atc0_common>; }; @@ -1299,7 +1297,6 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc1_usb"; - apple,sleep-wakeup-path; power-domains = <&ps_atc1_usb_aon>, <&ps_atc1_common>; }; From be351654938d17c85c569eeaa65e125f4e6bd425 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 18:24:01 +1100 Subject: [PATCH 14/14] drm/apple: serialize HDMI resume unplug with route assignment The resume path checks the fixed HDMI connector before releasing the link, then acquires the fabric mutex to update connector presence. A competing Type-C route selection can claim the DPTX port in that gap. Hold the fabric mutex across the ownership check, port release and presence update. Keep the established fabric-to-HPD lock order. The extracted fixture verifies that resume holds the fabric guard while releasing the link. Both arm64 DCP objects build and all six fixture mutations are rejected. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-fabric.c | 29 ++++++++++++- drivers/gpu/drm/apple/dcp.c | 13 +----- drivers/gpu/drm/apple/dcp.h | 2 + tools/asahi/dcp-hdmi-sleep-unplug-tests.py | 50 ++++++++++++++++------ tools/asahi/run-host-tests.py | 2 +- 5 files changed, 68 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index b81598df13062..eda8620c020eb 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -1213,12 +1213,12 @@ static void dcp_hdmi_capacity_available(void *ctx) * never tracked: when the hold expires, the desktop has let the HDMI CRTC go * and the hybrid is free for a Type-C display again. */ -void dcp_fabric_hdmi_unplugged(struct apple_dcp *dcp) +static void dcp_fabric_hdmi_unplugged_locked(struct apple_dcp *dcp) { unsigned long flags; u64 generation; - guard(mutex)(&dcp_typec_fabric_lock); + lockdep_assert_held(&dcp_typec_fabric_lock); generation = dcp_hdmi_edge(dcp); if (!generation) return; @@ -1230,6 +1230,31 @@ void dcp_fabric_hdmi_unplugged(struct apple_dcp *dcp) dcp_fabric_hybrid_kick(dcp, 0); } +void dcp_fabric_hdmi_unplugged(struct apple_dcp *dcp) +{ + guard(mutex)(&dcp_typec_fabric_lock); + dcp_fabric_hdmi_unplugged_locked(dcp); +} + +/* + * Release a fixed HDMI link unplugged while its HPD IRQ was masked. Hold + * the fabric lock from the ownership check through the presence update so + * a Type-C route cannot take the same DPTX port during the release. + */ +void dcp_hdmi_unplugged_in_sleep(struct apple_dcp *dcp) +{ + guard(mutex)(&dcp_typec_fabric_lock); + + if (dcp->active_typec_route || !dcp->connector || + !READ_ONCE(dcp->connector->connected) || + gpiod_get_value_cansleep(dcp->hdmi_hpd) != 0) + return; + + dev_info(dcp->dev, "HDMI display unplugged during sleep\n"); + dcp_hdmi_disconnect(dcp); + dcp_fabric_hdmi_unplugged_locked(dcp); +} + static void dcp_hdmi_settle_work(struct work_struct *work) { struct apple_dcp *dcp = container_of(to_delayed_work(work), diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7fdb7b58a96f5..f0b4d13341a78 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -10258,21 +10258,10 @@ static int dcp_platform_suspend(struct device *dev) return 0; } -/* - * The suspend kept an attached HDMI display's link (dcp_platform_suspend()). - * One unplugged during the sleep made no edge the masked HPD IRQ saw, and - * nothing else reports it: release it now, as an unplug while awake is. - */ -static void dcp_hdmi_unplugged_in_sleep(struct apple_dcp *dcp) +void dcp_hdmi_disconnect(struct apple_dcp *dcp) { - if (READ_ONCE(dcp->active_typec_route) || !dcp->connector || - !READ_ONCE(dcp->connector->connected) || - gpiod_get_value_cansleep(dcp->hdmi_hpd) != 0) - return; - dev_info(dcp->dev, "HDMI display unplugged during sleep\n"); disconnected_hpd_event(dcp->connector); dcp_dptx_disconnect(dcp, 0); - dcp_fabric_hdmi_unplugged(dcp); } static int dcp_platform_resume(struct device *dev) diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index 41243ff65d8b0..19cbea3122184 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -184,6 +184,8 @@ bool apple_t8122_25g83_board(void); void dcp_typec_hybrid_first_dt(void); void dcp_fabric_hdmi_unplugged(struct apple_dcp *dcp); +void dcp_hdmi_unplugged_in_sleep(struct apple_dcp *dcp); +void dcp_hdmi_disconnect(struct apple_dcp *dcp); void dcp_fabric_hybrid_kick(struct apple_dcp *dcp, unsigned int delay_ms); void dcp_hdmi_yield_link(struct apple_dcp *dcp); void dcp_link_recovery_schedule(struct apple_dcp *dcp); diff --git a/tools/asahi/dcp-hdmi-sleep-unplug-tests.py b/tools/asahi/dcp-hdmi-sleep-unplug-tests.py index df588dcdc16e2..b1ef7a00daa23 100755 --- a/tools/asahi/dcp-hdmi-sleep-unplug-tests.py +++ b/tools/asahi/dcp-hdmi-sleep-unplug-tests.py @@ -9,10 +9,10 @@ the IRQ comes back. A T6030 native output still releases the link at suspend, because its resume sets the PHY and crossbar up again. -The fixture compiles the HDMI block of dcp_platform_suspend() and -dcp_hdmi_unplugged_in_sleep() from drivers/gpu/drm/apple/dcp.c against mocks -and checks which displays are released. --mutation names a change to the -production code that the matrix must kill. +The fixture compiles the HDMI block of dcp_platform_suspend() and the +fabric's dcp_hdmi_unplugged_in_sleep() against mocks. It checks which +outputs are released and that the fabric lock covers the resume release. +--mutation names a change to the production code that the matrix must kill. """ import argparse import re @@ -23,6 +23,7 @@ ROOT = Path(__file__).resolve().parents[2] DCP = 'drivers/gpu/drm/apple/dcp.c' +FABRIC = 'drivers/gpu/drm/apple/dcp-fabric.c' RESUME_CALL = '\tif (dcp->hdmi_hpd_irq)\n\t\tdcp_hdmi_unplugged_in_sleep(dcp);\n' MUTATIONS = { @@ -33,11 +34,11 @@ 'gpio-error': ('gpiod_get_value_cansleep(dcp->hdmi_hpd) != 0)\n\t\treturn;', 'gpiod_get_value_cansleep(dcp->hdmi_hpd) > 0)\n\t\treturn;'), # Release the HDMI connector while a Type-C display owns the pipeline. - 'ignore-borrowed': ('if (READ_ONCE(dcp->active_typec_route) || !dcp->connector ||', + 'ignore-borrowed': ('if (dcp->active_typec_route || !dcp->connector ||', 'if (!dcp->connector ||'), # Leave the hybrid fabric thinking HDMI is still there. - 'no-fabric': ('\tdcp_dptx_disconnect(dcp, 0);\n\tdcp_fabric_hdmi_unplugged(dcp);\n}', - '\tdcp_dptx_disconnect(dcp, 0);\n}'), + 'no-fabric': ('\tdcp_fabric_hdmi_unplugged_locked(dcp);\n', ''), + 'no-fabric-lock': ('\tguard(mutex)(&dcp_typec_fabric_lock);\n', ''), # Never look for an unplug after the sleep. 'no-resume-check': (RESUME_CALL, ''), } @@ -53,7 +54,7 @@ def block(text, start): raise AssertionError('unbalanced production block') def function(text, name): - match = re.search(r'\n(static [^\n;]*\b' + name + r'\([^;{}]*\)\n)\{', text) + match = re.search(r'\n((?:static )?[^\n;]*\b' + name + r'\([^;{}]*\)\n)\{', text) assert match, name return block(text, match.start(1)) @@ -79,7 +80,26 @@ def function(text, name): static void disable_irq(int irq) { irq_off++; } static void disconnected_hpd_event(struct apple_connector *c) { c->connected = false; hpd_events++; } static int dcp_dptx_disconnect(struct apple_dcp *d, int port) { disconnects++; return 0; } -static void dcp_fabric_hdmi_unplugged(struct apple_dcp *d) { fabric_unplugs++; } +static int dcp_typec_fabric_lock; +static int *hold_lock(int *lock) +{ + assert(!*lock); + *lock = 1; + return lock; +} +static void release_lock(int **lock) { **lock = 0; } +#define guard(kind) int *held_##kind __attribute__((cleanup(release_lock))) = hold_lock +static void dcp_hdmi_disconnect(struct apple_dcp *dcp) +{ + assert(dcp_typec_fabric_lock); + disconnected_hpd_event(dcp->connector); + dcp_dptx_disconnect(dcp, 0); +} +static void dcp_fabric_hdmi_unplugged_locked(struct apple_dcp *d) +{ + assert(dcp_typec_fabric_lock); + fabric_unplugs++; +} static void reset(void) { hpd_events = disconnects = fabric_unplugs = irq_off = 0; } ''' @@ -158,10 +178,15 @@ def main(): args = parser.parse_args() source = (ROOT / DCP).read_text() + unplug = function((ROOT / FABRIC).read_text(), 'dcp_hdmi_unplugged_in_sleep') if args.mutation: old, new = MUTATIONS[args.mutation] - assert source.count(old) == 1, args.mutation - source = source.replace(old, new) + if old in unplug: + assert unplug.count(old) == 1, args.mutation + unplug = unplug.replace(old, new) + else: + assert source.count(old) == 1, args.mutation + source = source.replace(old, new) resume = function(source, 'dcp_platform_resume') # The release runs while the HPD IRQ is still masked: an edge from then @@ -173,8 +198,7 @@ def main(): suspend = function(source, 'dcp_platform_suspend') hdmi = block(suspend, suspend.index('\tif (dcp->hdmi_hpd_irq) {\n\t\tdisable_irq')) - code = HARNESS + function(source, 'dcp_hdmi_unplugged_in_sleep') + \ - CHECKS.replace('SUSPEND', hdmi) + code = HARNESS + unplug + CHECKS.replace('SUSPEND', hdmi) with tempfile.TemporaryDirectory() as directory: path = Path(directory) / 'check.c' diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 9605e7101c81f..874ddbc5e1d1a 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -193,7 +193,7 @@ def mutations(flag, names, base, expect=KILL): # An HDMI display kept through a sleep but unplugged during it is released on resume. 'dcp-hdmi-sleep-unplug-tests.py': [([], PASS)] + mutations('--mutation', ('keep-native', 'gpio-error', 'ignore-borrowed', 'no-fabric', - 'no-resume-check'), []), + 'no-fabric-lock', 'no-resume-check'), []), # A fixed (non-Type-C) output takes its DP AV service again after a sleep. 'dpavserv-admission-tests.py': [([], PASS)] + mutations('--mutation', ('old-cable-wait', 'ignore-generation', 'ignore-cable',