Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
7e8f0dc
drm/apple: audio: keep the DP audio domain while its DCP firmware runs
RyanTheTide Nov 23, 2026
1693055
tools/asahi: test the DP audio domain hold for a sleep
RyanTheTide Nov 23, 2026
d64d981
drm/apple: audio: hold the DP audio domain only while the DCP firmwar…
RyanTheTide Nov 23, 2026
19f90d0
tools/asahi: model the DCP's firmware-runs flag in the retained-sleep…
RyanTheTide Nov 23, 2026
002e507
drm/apple: dcp: say dcp_sleep_keeps_firmware() is for late suspend only
RyanTheTide Nov 23, 2026
3437a5a
drm/apple: dcp: keep the DP PHY of a DCP whose firmware runs through …
RyanTheTide Nov 24, 2026
c672252
tools/asahi: test the DCP sleep PHY hold
RyanTheTide Nov 24, 2026
2267280
drm/apple: dcp: keep a still-attached HDMI link through a sleep
RyanTheTide Nov 24, 2026
245f899
tools/asahi: stub the DP PHY hold in the dcpext26 suspend route test
RyanTheTide Nov 24, 2026
702e0c3
drm/apple: read the sleep PHYs under the fabric lock
RyanTheTide Nov 24, 2026
1274718
arm64: dts: apple: t8112: allow the display PHY domains to wake
RyanTheTide Nov 24, 2026
31ba92a
drm/apple: dcp: release an HDMI display unplugged during a sleep
RyanTheTide Nov 24, 2026
ca69a30
arm64: dts: apple: revert T8112 display PHY wakeup flags
RyanTheTide Nov 24, 2026
8781980
Merge integration/aurora into m2mini/dpaudio-sleep-hold
RyanTheTide Nov 24, 2026
be35165
drm/apple: serialize HDMI resume unplug with route assignment
RyanTheTide Nov 24, 2026
d2e7b95
Merge remote-tracking branch 'aurora/integration/aurora' into HEAD
RyanTheTide Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion drivers/gpu/drm/apple/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
};

Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
69 changes: 68 additions & 1 deletion drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -9740,10 +9740,58 @@ 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);

/*
* 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);

dcp->sleep_fw_runs = false;
/* Its power sequences may crash the DCP and blank the panel. */
if (dcp_takeover_was_aborted(dcp))
return -EBUSY;
Expand Down Expand Up @@ -9799,7 +9847,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) {
Expand Down Expand Up @@ -9854,7 +9905,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;
Expand All @@ -9877,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);
}
Expand All @@ -9887,7 +9951,9 @@ 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);

Expand All @@ -9898,6 +9964,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;

Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/apple/dcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions drivers/gpu/drm/apple/iomfb_m4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/iomfb_m4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
134 changes: 134 additions & 0 deletions tools/asahi/dcp-sleep-phy-hold-tests.py
Original file line number Diff line number Diff line change
@@ -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 <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
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()
Loading
Loading