diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index 565016dcd7a89..1d6c5f73627d6 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -2071,6 +2071,39 @@ 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, 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) +{ + 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 (dcp_sleep_keeps_firmware(&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 +2116,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) }; diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 08f5057cf1a9d..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), @@ -4995,6 +5020,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-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 35e0ae975e315..bd48c63790371 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -896,6 +896,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 0e13fb3caa63a..f0b4d13341a78 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -10053,10 +10053,37 @@ 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 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 + * 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; @@ -10115,7 +10142,10 @@ 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); + 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) { @@ -10170,7 +10200,9 @@ 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); + 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; @@ -10193,7 +10225,21 @@ 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(). 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 && + (dcp->external_native || + gpiod_get_value_cansleep(dcp->hdmi_hpd) <= 0)) { disconnected_hpd_event(dcp->connector); dcp_dptx_disconnect(dcp, 0); } @@ -10203,17 +10249,26 @@ 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); + dcp_sleep_hold_phys(dcp); /* Last: the steps above still talk to the coprocessor. */ dcp_hold_for_sleep(dcp); return 0; } +void dcp_hdmi_disconnect(struct apple_dcp *dcp) +{ + disconnected_hpd_event(dcp->connector); + dcp_dptx_disconnect(dcp, 0); +} + 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; if (dcp_is_iboot(dcp)) @@ -10257,6 +10312,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/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index f1d0f49026d60..19cbea3122184 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); @@ -183,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/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/dcp-hdmi-sleep-unplug-tests.py b/tools/asahi/dcp-hdmi-sleep-unplug-tests.py new file mode 100755 index 0000000000000..b1ef7a00daa23 --- /dev/null +++ b/tools/asahi/dcp-hdmi-sleep-unplug-tests.py @@ -0,0 +1,212 @@ +#!/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 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 +import subprocess +import sys +import tempfile +from pathlib import Path + +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 = { + # 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 (dcp->active_typec_route || !dcp->connector ||', + 'if (!dcp->connector ||'), + # Leave the hybrid fabric thinking HDMI is still there. + '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, ''), +} + +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 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; } +''' + +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() + unplug = function((ROOT / FABRIC).read_text(), 'dcp_hdmi_unplugged_in_sleep') + if args.mutation: + old, new = MUTATIONS[args.mutation] + 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 + # 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 + unplug + 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/dcp-sleep-phy-hold-tests.py b/tools/asahi/dcp-sleep-phy-hold-tests.py new file mode 100755 index 0000000000000..b0cf23c94c5d1 --- /dev/null +++ b/tools/asahi/dcp-sleep-phy-hold-tests.py @@ -0,0 +1,147 @@ +#!/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-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 +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-fabric.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 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 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; +} +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/dcpaud-sleep-hold-tests.c b/tools/asahi/dcpaud-sleep-hold-tests.c new file mode 100644 index 0000000000000..640472dce91d1 --- /dev/null +++ b/tools/asahi/dcpaud-sleep-hold-tests.c @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * 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 +#include +#include +#include + +/* The harness builds with -Wno-unused-function. */ +#define __maybe_unused +#define pm_sleep_ptr(fn) (fn) +#define EXPORT_SYMBOL_GPL(sym) + +/* ACTUAL_PM_MACROS */ + +struct device_node { + int refs; + bool available; +}; + +struct device_driver { + int unused; +}; + +struct device { + struct device_node *of_node; + int refs; + 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 { + 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 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; + +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--; +} + +/* 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 && !dev->locked); + dev->locked = true; +} + +static void device_unlock(struct device *dev) +{ + 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) +{ + 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_DCP_FUNCTION */ + +/* 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.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; + 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.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); + /* 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..142a69ccb941c --- /dev/null +++ b/tools/asahi/dcpaud-sleep-hold-tests.py @@ -0,0 +1,154 @@ +#!/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 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, 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 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). +""" +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" +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 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": ("audio", "\t\tput_device(&dcp_pdev->dev);\n", ""), + # Leak the DCP node reference from of_graph_get_remote_port_parent(). + "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)"), +} + + +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 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" + + +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, dcp = (subprocess.check_output(["git", "show", f"{args.ref}:{path}"], + cwd=ROOT, text=True) for path in (AUDIO, DCP)) + else: + 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: + 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") + 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))) + + 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/dcpext26-suspend-route-tests.py b/tools/asahi/dcpext26-suspend-route-tests.py index 8067762a9fc1b..5201f36841e49 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; @@ -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') @@ -81,19 +83,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 +108,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') diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index a9c9a3b519486..874ddbc5e1d1a 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -181,6 +181,19 @@ 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', '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'), []), + # 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-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',