From cdfa82f58037859cdfaaf7c69afff09d71fed5c2 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Wed, 25 Nov 2026 02:24:42 +0000 Subject: [PATCH 1/2] drm/apple: update adaptive sync on an installed firmware-27 pair The same 4K240 timing and color can be installed twice when a paired display returns after resume. The second commit changes only the adaptive-sync minimum. It rebuilds both engines and blocks the compositor for almost another second. Keep a working pair when the installed timing, color and HDR state still match, and send the existing adaptive-sync parameter to both engines. Preserve the frame completion state. A command failure falls back to the full installation, as do changes to the installed mode. Signed-off-by: Diljit Singh --- drivers/gpu/drm/apple/dcp-peer-frames-v27.h | 13 +++++++++ .../gpu/drm/apple/dcp-peer-runtime-v27.inc | 29 +++++++++++++++++-- tools/asahi/dcp-peer-shown-tests.py | 13 +++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-peer-frames-v27.h b/drivers/gpu/drm/apple/dcp-peer-frames-v27.h index 749aea5499244..ebd747a52eb8c 100644 --- a/drivers/gpu/drm/apple/dcp-peer-frames-v27.h +++ b/drivers/gpu/drm/apple/dcp-peer-frames-v27.h @@ -8,10 +8,23 @@ * outstanding swaps, as in the existing single-pipe retirement path. */ struct dcp_peer_frames_v27 { + u32 timing; + u32 color; + u32 min_vrr; + bool output_hdr; u32 first, submitted, engine[2], retired, shown[2]; bool active, armed, failed, have[2], have_retired, have_shown[2]; }; +static inline bool dcp_peer_vrr_only_v27(const struct dcp_peer_frames_v27 *frames, + u32 timing, u32 color, u32 min_vrr, + bool output_hdr) +{ + return frames->active && !frames->failed && frames->timing == timing && + frames->color == color && frames->min_vrr != min_vrr && + frames->output_hdr == output_hdr; +} + static inline void dcp_peer_frame_submit_v27(struct dcp_peer_frames_v27 *s, u32 id) { if (!s->armed) { diff --git a/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc b/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc index 4e6a5e68566ca..641aef85f7e77 100644 --- a/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc @@ -112,7 +112,7 @@ static int dcp_peer_limited_stop_v27(struct apple_dcp *dcp, struct apple_dcp *pe int dcp_peer_modeset_v27(struct apple_dcp *dcp, u32 timing, u32 color, u32 min_vrr) { struct apple_dcp *peer; - bool limited, prepared; + bool limited, prepared, vrr_only; int ret = -EOPNOTSUPP; if (!peer_scanout || !peer_allocation_probe || @@ -145,11 +145,30 @@ int dcp_peer_modeset_v27(struct apple_dcp *dcp, u32 timing, u32 color, u32 min_v ret = -EBUSY; goto unlock; } + vrr_only = dcp->peer_tiling.modeset_complete && + peer->peer_tiling.modeset_complete && + dcp_peer_vrr_only_v27(&dcp->peer_frames, timing, color, + min_vrr, dcp->output_hdr); } if (limited) { ret = dcp_peer_limited_stop_v27(dcp, peer); goto peer_unlock; } + /* + * Adaptive sync uses parameter 15 on both engines. Leave a running + * pair installed when its timing and color are still current. If + * either engine refuses the update, rebuild both with the new rate. + */ + if (vrr_only && !dcp_peer_param_v27(dcp, peer, 15, 3, min_vrr)) { + guard(mutex)(&dcp_peer_lock); + if (dcp_peer_vrr_only_v27(&dcp->peer_frames, timing, color, + min_vrr, dcp->output_hdr)) { + dcp->peer_frames.min_vrr = min_vrr; + dev_dbg(dcp->dev, "paired adaptive sync minimum %#x\n", min_vrr); + ret = 0; + goto peer_unlock; + } + } ret = dcp_peer_prepare_v27(dcp, peer, min_vrr); if (ret) goto peer_unlock; @@ -158,7 +177,13 @@ int dcp_peer_modeset_v27(struct apple_dcp *dcp, u32 timing, u32 color, u32 min_v dcp_peer_finish_v27(dcp, peer); if (!ret) { guard(mutex)(&dcp_peer_lock); - dcp->peer_frames = (struct dcp_peer_frames_v27){ .active = true }; + dcp->peer_frames = (struct dcp_peer_frames_v27){ + .timing = timing, + .color = color, + .min_vrr = min_vrr, + .output_hdr = dcp->output_hdr, + .active = true, + }; dev_info(dcp->dev, "paired DRM mode ready: timing=%u color=%u min_vrr=%#x\n", timing, color, min_vrr); } diff --git a/tools/asahi/dcp-peer-shown-tests.py b/tools/asahi/dcp-peer-shown-tests.py index 1b26c2d3ab408..ccf7dfae223f3 100644 --- a/tools/asahi/dcp-peer-shown-tests.py +++ b/tools/asahi/dcp-peer-shown-tests.py @@ -38,6 +38,19 @@ u32 w = 0; bool shown = true; + /* A new adaptive-sync minimum can reuse only the installed mode. */ + s = (struct dcp_peer_frames_v27){ .timing = 81, .color = 86, .active = true }; + assert(dcp_peer_vrr_only_v27(&s, 81, 86, 0x300000, false)); + assert(!dcp_peer_vrr_only_v27(&s, 81, 86, 0, false)); + assert(!dcp_peer_vrr_only_v27(&s, 80, 86, 0x300000, false)); + assert(!dcp_peer_vrr_only_v27(&s, 81, 85, 0x300000, false)); + assert(!dcp_peer_vrr_only_v27(&s, 81, 86, 0x300000, true)); + s.failed = true; + assert(!dcp_peer_vrr_only_v27(&s, 81, 86, 0x300000, false)); + s.failed = false; + s.active = false; + assert(!dcp_peer_vrr_only_v27(&s, 81, 86, 0x300000, false)); + /* First modeset of a pair: both engines display swap 5. */ s = paired(5, 5); assert(!dcp_peer_frame_complete_v27(&s, 0, 5, true, &w, &shown)); From 9fa8c0838f8cf6f95b4620cb0a2bfc69881478a9 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Tue, 24 Nov 2026 21:44:52 -0500 Subject: [PATCH 2/2] drm/apple: recheck paired DCP state after adaptive-sync RPC dcp_peer_modeset_v27() drops dcp_peer_lock across the blocking dcp_peer_param_v27() calls to both engines. While unlocked, dcp_peer_release_locked() or a platform-limit change can clear modeset_complete, release the peer reservation, or impose the pair limit without clearing peer_frames.active. Re-verify peer ownership, platform limit, and both engines' modeset_complete flags under dcp_peer_lock after dcp_peer_param_v27() returns. Return -EBUSY if ownership was lost, stop a newly limited pair outside dcp_peer_lock via dcp_peer_limited_stop_v27() (or return -EOPNOTSUPP if already unprepared), and otherwise fall through to the full pair rebuild when the fast path is no longer valid. Signed-off-by: Diljit Singh --- .../gpu/drm/apple/dcp-peer-runtime-v27.inc | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc b/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc index 641aef85f7e77..647d691f35652 100644 --- a/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc @@ -159,13 +159,35 @@ int dcp_peer_modeset_v27(struct apple_dcp *dcp, u32 timing, u32 color, u32 min_v * pair installed when its timing and color are still current. If * either engine refuses the update, rebuild both with the new rate. */ - if (vrr_only && !dcp_peer_param_v27(dcp, peer, 15, 3, min_vrr)) { - guard(mutex)(&dcp_peer_lock); - if (dcp_peer_vrr_only_v27(&dcp->peer_frames, timing, color, - min_vrr, dcp->output_hdr)) { - dcp->peer_frames.min_vrr = min_vrr; - dev_dbg(dcp->dev, "paired adaptive sync minimum %#x\n", min_vrr); - ret = 0; + if (vrr_only) { + bool still_owned, updated = false; + + ret = dcp_peer_param_v27(dcp, peer, 15, 3, min_vrr); + scoped_guard(mutex, &dcp_peer_lock) { + still_owned = dcp->peer_reserved == peer && + peer->peer_owner == dcp; + limited = still_owned && + dcp_peer_limited_pair_locked(dcp, &prepared); + if (!ret && !limited && still_owned && + dcp->peer_tiling.modeset_complete && + peer->peer_tiling.modeset_complete && + dcp_peer_vrr_only_v27(&dcp->peer_frames, timing, + color, min_vrr, + dcp->output_hdr)) { + dcp->peer_frames.min_vrr = min_vrr; + dev_dbg(dcp->dev, "paired adaptive sync minimum %#x\n", min_vrr); + updated = true; + } + } + if (updated) + goto peer_unlock; + if (!still_owned) { + ret = -EBUSY; + goto peer_unlock; + } + if (limited) { + ret = prepared ? dcp_peer_limited_stop_v27(dcp, peer) + : -EOPNOTSUPP; goto peer_unlock; } }