Skip to content

drm/apple: let a docked M1 deep-sleep with its external display lit - #3655

Merged
RyanTheTide merged 7 commits into
mainfrom
fix/dcpext-unplugged-sleep
Dec 1, 2026
Merged

RyanTheTide merged 7 commits into
mainfrom
fix/dcpext-unplugged-sleep

Conversation

@erikwb

@erikwb erikwb commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What: On firmware-27 external display processors, a Type-C display unplugged under a lit CRTC is left powered off by the firmware. The power-off therefore no longer sends the clear swap and teardown, which the firmware swallows. On the M1 MacBook Air that swallowed clear swap held the IOMFB queue: every docked deep sleep with a lit external display was refused, and the dcpext was declared crashed, dark until a reboot. A second commit reports what an unsettled IOMFB queue is still waiting for.
Tested: At 7afbc1520a85 (forward merge of origin/main d148fbda6dca including #3305 at 7f3f64a9e359, folding unplug retirement into iomfb_retire_present_locked_h17p(), plus combined KUnit guards at 7afbc1520a85):

  • J313 (M1 Air, T8103, DCP firmware 27.2.1, CalDigit TS5, external 3840x2160@120 on 271c00000.dcp) at 7afbc1520a85: clean boot (0 failed units, eDP-1 2560x1600@60 + DP-2 3840x2160@120 + TS5 Ethernet enP1p3s0 UP, 0 new kernel errors); DP-2 DPMS off/on PASS (0 errors); docked deep-sleep attempt (rtcwake -d /dev/rtc1 -m mem -s 15, func dcp_poweroff +p): external 271c00000.dcp PASS — took #3655's combined unplugged-session retirement path (CRTC off after its display was unplugged: leaving the current connection alone, and the pipe the unplug powered off), 0 IOMFB/setPowerState(0) timeouts, 0 crashes, and cleanly restored dpin0, DP-2 3840x2160@120, and enP1p3s0. Full sleep entry on main (645b086d9989..d148fbda6dca) is currently aborted by an unrelated internal panel 231c00000.dcp crash on set_power_state(0) (-16), which reproduces identically on plain origin/main 645b086d9989 without #3655.
  • Builds, KUnit & host tests at 7afbc1520a85: full J313 arm64 LLVM=1 kernel build (0 warnings in drivers/gpu/drm/apple/); arm64 QEMU KUnit (topology.kunitconfig 233/234 with 1 skipped and apple-dcp-dropped-swap 30/30 including stalled_present_retired_test and unplugged_combined_retire_guards_test; PROVE_LOCKING=y apple-dcp-dropped-swap 30/30; display.kunitconfig 201/202 with 1 skipped; tests/.kunitconfig 117/117); dcpext26-queue-tests (+ --drop-v27-close) 2/2, dcp-peer-shown-tests (+ --always-shown, --owner-only) 3/3, backlight-coldboot-tests (+ --negative-controls) 2/2, and apple-dcp (publication-hpd, stale-crtc-poweroff, dropped-swap-teardown, connected-irq-hpd-to-firmware, dcp-sink-irq-fallback, display pass; 14 unrelated fixtures hit Clang 23 -Wunused-but-set-global); checkpatch.pl --strict on 7afbc1520a85 clean (0 errors, 0 warnings).
  • Prior rows at 4261e69d1e9a: J313 M1 Air passed 6/6 sleeps in one boot (docked lit 3/3, docked DPMS-off, unplug while awake, undocked sleep, replug + docked sleep) while control main d02c84abc8de refused docked sleep and crashed 271c00000.dcp; J713 M4 Air (two docked 4K60 displays on its daily + these commits) passed 3/4 docked deep sleeps + DPMS; J716c M5 Max (two docked 4K240 paired displays on its daily + these commits) passed DPMS, docked s2idle, and unplug while awake. Details in Evidence.
    Risk: two-way door · Macs whose external DCP uses the firmware-27 / H17P IOMFB queue (M1 on firmware 27, M4 and M5 dcpexts); others unchanged
    Not yet: Full docked deep-sleep completion on J313 at 7afbc1520a85 is currently gated by the unrelated origin/main internal 231c00000.dcp set_power_state(0) crash (reproduced identically on plain main 645b086d9989; 271c00000.dcp itself passes cleanly at 7afbc1520a85); M4 and M5 rows on main itself (main cannot drive the M4's dock without #3273, and the M5 rows ran on its daily, which carries open DCP PRs; deep sleep on the M5 resets on every kernel, including the default).
Details

The failure. At PM_SUSPEND_PREPARE the USB4 port is torn down while userspace still runs. The firmware loses the DisplayPort sink, powers the external pipe off and reports the unplug. The Type-C mux announces the unplug too (dcp_dptx_disconnect_oob()), and the compositor turns the CRTC off with the mode still valid. The power-off sends the clear swap. The firmware accepts it but never completes it on a pipe it has powered off. The swap watchdog had been cancelled by the CRTC-off path, so the present stays in flight. abort_swaps and setPowerState(0) wait behind it in the queue, setPowerState(0) times out, the DCP suspend cannot settle the queue and refuses the sleep, and ten seconds later the queue timeout declares the coprocessor crashed.

The change.

  • The firmware's own hotplug reports are recorded in one word: the number of unplugs reported, plus whether the last report had a display. The reports that are not display changes are filtered out first, in dcpep_cb_hotplug(). The CRTC notes the count, with the mux's count, wherever it claims its display: at its power-on, and at a mode set that succeeds with the CRTC kept on (dcp_typec_claim()).
  • The display of the CRTC's session is gone, and its pipe with it, once both of these have happened since the claim: the mux announced an unplug and the firmware reported one. The order doesn't matter. On the M1 the firmware reports first, because the USB4 teardown removes the sink before the mux runs.
  • When the CRTC of a display the mux announced unplugged turns off before the firmware's report, the power-off waits for the report, bounded by DCP_TYPEC_FW_UNPLUG_MS. Without it, the power-off runs as before.
  • When the firmware has reported the unplug, iomfb_end_unplugged_session_h17p() sends nothing:
    • a reply still on its way lands first;
    • a present the firmware accepted for the display that went is retired through the shared iomfb_retire_present_locked_h17p() helper (shared with the swap watchdog and #3305's paired-stop stalled-present path): its framebuffers are kept until a later present completes, its swap watchdog is cancelled via dcp_swap_watchdog_cancel() before iomfb_queue_advance(), and any retired paired swap ID is recorded on the peer outside dcp->iomfb.lock via dcp_peer_record_retired_v27(). Each present notes the firmware's unplug count when it is begun, on the same receive path as the reports, so one begun for a display reported on the pipe since is left to complete;
    • its own commit's flip is finished as failed, through dcp_drm_crtc_flip_lost().
  • Queued presents are not sent, because the connector is disconnected (iomfb_atomic_start()).
  • Two cases still get the full power-off: a display the firmware reported on the pipe since, and an active or transitioning pair (peer_transition_active or peer_frames.active), which stops through its own sequence.
  • A present that cannot be retired (busy channels or full retired table) leaves the swap watchdog armed, and nothing is sent behind it.
  • The swap watchdog now also watches the clear swap on queued firmware. A clear swap the pipe swallows, for instance when the firmware's report came late, is retired instead of holding the power-off.
  • An unplug report also arms the watchdog for a present the pipe had accepted, in case the CRTC never turns off.
  • A system sleep cancels the watchdog. It ends an unplugged session the same way before settling the queue, after waiting for the firmware's report of an unplug the mux has announced.
  • The decision is passed to the power-off as an argument. Firmware without the IOMFB queue is unchanged.

Combined retirement with #3305 (7f3f64a9e359, 7afbc1520a85).

  • iomfb_retire_present_locked_h17p() returns a 3-state enum iomfb_retire_result (IOMFB_RETIRE_NONE, IOMFB_RETIRE_FULL, IOMFB_RETIRE_DONE) and takes explicit check_deadline, check_channels_idle, and cancel_watchdog flags.
  • Watchdog (iomfb_retire_dropped_present_h17p()) checks deadline only and returns true on IOMFB_RETIRE_FULL so the watchdog stops re-arming.
  • Paired stop (iomfb_retire_stalled_present_h17p()) checks iomfb_channels_idle(), cancels the watchdog via dcp_swap_watchdog_cancel() before iomfb_queue_advance(), records retired peer IDs outside dcp->iomfb.lock, and returns false on IOMFB_RETIRE_FULL instead of spuriously waking vblank and retrying a 100 ms settle that can only time out.
  • Unplug (iomfb_end_unplugged_session_h17p()) uses the same channels-idle + watchdog-cancel + peer-retire path, keeps drm_crtc_commit reference handling balanced across retired and held paths, and checks peer_transition_active alongside peer_frames.active so an unplug racing a firmware-27 paired transition falls through to paired power-off.

Known limits.

  • An unplug report from the previous display that arrives only after the next display's claim counts for the new session, once that session's own mux unplug comes. Its display is physically gone by then, and its HPD low is sent or about to be. The pipe is sent nothing, and the framebuffers stay referenced.
  • A swap watchdog already running when the session ends could, in a very narrow window, retire the next present. It needs the watchdog to lose the queue lock across two firmware round trips.
  • A sleep after a mux unplug that the firmware never reports waits up to 500 ms for the report.

Overlap with #3273. #3273 (T8132 firmware-27 dock displays) also retires a present whose display went: it keys each present to the Type-C attachment it was begun for and lets the swap watchdog retire it. This PR retires such a present at once, from the power-off and the sleep paths, through the shared retirement helper (iomfb_retire_present_locked_h17p()). They touch the same functions. Whichever lands second folds the two into one mechanism. The M4 row below merges both and runs them together.

Diagnostic commit. When a queue settle times out, the IOMFB queue's state is reported, rate-limited: the active transaction, queued ones, the present in flight, plus channel depths, ACKs and callbacks sampled outside the lock. This names the cause of a refused sleep.

Host-test harness fix (be574d3b3b94). Updates the four host-test extractors that pull dcpep_cb_hotplug(), dcp_poweron(), dcp_poweroff(), dcp_crtc_atomic_modeset(), and iomfb_queue_atomic() out of the driver: stubs dcp_typec_fw_hotplug() in rate.py (publication-hpd), checks dcp_typec_claim() via dcp_crtc_atomic_modeset() and stubs dcp_typec_fw_unplug_wait() / _dcp_poweroff(..., pipe_unplugged) in lifecycle.py (stale-crtc-poweroff), stops the iomfb.c slice at iomfb_atomic_release() and appends iomfb_queue_atomic() in dcpext26-queue-tests.py, and stubs dcp_typec_claim() in backlight-coldboot-tests.py.

Evidence

J313 (M1 Air, T8103), DCP firmware 27.2.1, CalDigit TS5, external 3840x2160@120 on 271c00000.dcp — refreshed row at 7afbc1520a85 (origin/main d148fbda6dca + #3655 combined with #3305): Default command line, one-shot trial kernel.

  • Boot: 0 failed units, eDP-1 2560x1600@60 + DP-2 3840x2160@120 + TS5 Ethernet enP1p3s0 UP, 0 new kernel errors.
  • DP-2 (271c00000.dcp) DPMS off/on: PASS (dpmsStatus: 0 -> 1, 3840x2160@120 Hz, 0 errors).
  • Docked deep-sleep attempt (rtcwake -d /dev/rtc1 -m mem -s 15, fresh boot, func dcp_poweroff +p):
    • External 271c00000.dcp PASS:
      [  248.815026] PM: suspend entry (deep)
      [  249.022126] apple-dcp 271c00000.dcp: dcp_hotplug() connected:0 valid_mode:0 nr_modes:34
      [  249.055222] apple-dcp 271c00000.dcp: CRTC off after its display was unplugged: leaving the current connection alone, and the pipe the unplug powered off
      [  249.070521] apple-dcp 271c00000.dcp: dcp_dptx_disconnect(port=0)
      [  251.204477] apple-dcp 271c00000.dcp: sleep refused: firmware back after a power cycle: 0
      [  251.228783] PM: suspend exit
      [  251.913123] apple-dcp 271c00000.dcp: display routed to Thunderbolt DP tunnel dpin0
      [  252.667302] apple-dcp 271c00000.dcp: set_digital_out_mode finished:2069
      
      0 IOMFB/setPowerState(0) timeouts, 0 271c00000.dcp crashes; DP-2 restored at 3840x2160@120 Hz (dpmsStatus: 1) and TS5 Ethernet (enP1p3s0) UP.
    • Internal 231c00000.dcp crashed on set_power_state(0) (RTKit: co-processor has crashed, no reply to set_power_state(0): -110, PM: failed to suspend: error -16), aborting deep sleep. A matched control run on plain origin/main (645b086d9989, without #3655) reproduces the identical internal 231c00000.dcp crash (ESR=0x96000061, FAR=0xffffffff1018c014, error -16) on both docked sleep and eDP-1 DPMS-off.

Prior J313 (M1 Air, T8103) matrix at 4261e69d1e9a (pre-regression main d02c84abc8de): Kernel config: the J313 daily config. Default command line; rtcwake -d rtc1 -m mem -s 30 in a systemd unit.

Kernel Docked, external lit Docked, external DPMS-off Unplug while awake Undocked sleep
main d02c84a refused 1/1, 271c00000.dcp -16, then IOMFB transaction timed out ... present=1 accepted=1, connector broken — — —
4261e69 (built from 3dbe77d4be97, same tree) 3/3 deep, ~31 s each; DP-2 back at 3840x2160@120 every time 1/1, plus DPMS off/on new path, no errors, 0 failed units 1/1, panel back

Then a replug while awake on 4261e69d1e9a: DP-2 back at 3840x2160, followed by one more docked deep sleep on the new path, for 6/6 sleeps in that boot.

J713 (M4 Air, T8132), at 4261e69d1e9a merged into its daily (main 219311530ef0 + #3273 and other open PRs; the conflicts were in the shared retirement helper and the older base's lack of channels_idle_wq). Two lit 3840x2160@60 displays on the TS5, with the dcpexts 286e00000 / 48ae00000 on firmware 27:

Kernel Docked deep sleep DPMS off/on After wake
J713 daily 2/2 (one at 16 s uptime) — dock displays do not return (Type-C DPTX reconnect failed after 1 retries: -116)
J713 daily + these commits 3/4, every pass on the new path; one reset during the sleep at 17 s uptime, not reproduced at 16 s pass identical to J713 daily

The trial boot has no kernel error lines that the J713 daily boot lacks. The one reset left nothing in the journal past the test marker. The displays not returning after a docked wake on the J713 daily is separate from this change.

J716c (M5 Max, T6050), at 4261e69d1e9a merged into its daily (base a812cfe477e2). That daily carries a third retirement variant, iomfb_retire_stalled_present_h17p(), which the merge keeps. Two lit 3840x2160@240 displays on the TS5, each on a paired DCP. The trial was one boot of a chained trial Stage 2 under the watchdog dead-man:

Kernel DPMS off/on Docked s2idle (woken by key) Unplug while awake Replug while awake
J716c daily (a812cfe477e2) pass pass — externals stay dark: both tunnels route and the peers are reserved, then DP tunnel clock N stopped 30 s later
J716c daily + these commits pass pass both dcpexts on the new path, no errors the same as the daily

No kernel error lines that the default boot lacks. Deep sleep can't be judged on this M5: it resets about 6 s in on every kernel, and an RTC alarm doesn't wake it from s2idle on either kernel.

KUnit at 7afbc1520a85 (qemu arm64, LLVM=1, drivers/gpu/drm/apple/tests):

  • topology.kunitconfig: 233 passed / 1 skipped (apple_g17_rx_util_min_test, needs CONFIG_UCLAMP_TASK, 234 total; apple-dcp-dropped-swap 30/30 passed, including stalled_present_retired_test full-table check and unplugged_combined_retire_guards_test).
  • PROVE_LOCKING=y with DRM_APPLE_KUNIT_TEST=y: apple-dcp-dropped-swap 30/30 passed.
  • display.kunitconfig: 201 passed / 1 skipped (202 total).
  • tests/.kunitconfig: 117/117 passed.

Host builds & tests at 7afbc1520a85:

  • Full J313 arm64 LLVM=1 kernel build: 0 errors, 0 warnings in drivers/gpu/drm/apple/.
  • dcpext26-queue-tests and dcpext26-queue-tests --drop-v27-close (negative control killed): 2/2 pass.
  • dcp-peer-shown-tests (+ --always-shown, --owner-only): 3/3 pass.
  • backlight-coldboot-tests and backlight-coldboot-tests --negative-controls: 2/2 pass.
  • apple-dcp (publication-hpd, stale-crtc-poweroff, dropped-swap-teardown, connected-irq-hpd-to-firmware, dcp-sink-irq-fallback, display pass; 14 unrelated fixtures hit Clang 23 -Wunused-but-set-global under -Wall -Werror).

checkpatch.pl --strict --git 7f3f64a9e359..7afbc1520a85: 0 errors, 0 warnings, 0 checks. git diff --check origin/main...7afbc1520a85 clean.

A DCP's system suspend settles its IOMFB queue first and refuses the sleep
when that times out ("display updates still pending, refusing sleep"). The
refusal does not say what the queue is waiting for: an active transaction,
queued ones, a present the firmware has not finished, or a call or an ACK
still outstanding on one of the channels.

Report that state, rate-limited, from the settle's last pass when it
times out. The queue state is read under the IOMFB lock. The channel
depths, ACK count and callback count change outside that lock, so the
report labels them as samples.

Signed-off-by: Erik Bourget <erik@ebourget.net>
On the J313 (M1, firmware 27.2.1 DCP), deep sleep with a lit external
display on a USB4 dock is refused every time. The display then stays dark
until a reboot:

  dcpext: setPowerState(0) timeout 1000 ms
  dcpext: display updates still pending, refusing sleep
  dcpext: PM: failed to suspend: error -16
  ...
  dcpext: IOMFB transaction timed out: ... present=1 accepted=1

The dock's port is torn down at PM_SUSPEND_PREPARE, while userspace is
still running. The firmware acts on the display's unplug by powering the
external pipe off, then reports the unplug through its hotplug callback.
The compositor then turns the CRTC off, with the mode still valid. The
power-off sends the clear swap. The firmware accepts it but never
completes it on a pipe it has powered off. The present stays in flight,
because the CRTC-off path cancelled the swap watchdog. The IOMFB queue
holds the abort_swaps and setPowerState(0) calls behind it, and they
never reach the firmware. setPowerState(0) times out, the DCP's suspend
cannot settle the queue and refuses the sleep, and ten seconds later the
queue's timeout declares the coprocessor crashed.

Record the firmware's own reports of a Type-C display, after the reports
that are not display changes have been filtered out. One word holds the
number of unplugs reported and whether the last report had a display, so
it is always read whole. The CRTC notes that number, with the mux's
count, wherever it claims its display: at its power-on, and at a mode
set that succeeds with the CRTC kept on. The display of the CRTC's
session is gone, and its pipe with it, once both of these have happened
since the claim: the Type-C mux has announced the unplug, and the
firmware has reported one. They come in either order. The USB4 port's
teardown at the sleep takes the display away, and the firmware reports
it, before the mux announces it. A display's unplug that the firmware
never reported does not stand in for the next display's.

The desktop hears of the unplug from the mux. When the CRTC of such a
display turns off before the firmware's report, the power-off waits for
the report, bounded by a named limit; firmware without the queue does
not wait. Without the report it powers the pipe off as before. On
firmware with the queue, the swap watchdog now also watches the clear
swap, so one the pipe swallows is retired a second later rather than
holding the power-off until the queue's timeout declares the coprocessor
crashed. That covers any panel-less output, such as a fixed HDMI port
whose display drops off at DPMS off, with the watchdog's usual retrain.
An unplug report also has the watchdog retire a present the pipe had
accepted, should the CRTC not turn off.

Once the firmware has reported the unplug, on firmware with the IOMFB
queue, the departing session's present ends. A reply still on its way
lands first: a reply now wakes the channel waiters once its callback has
run. A present the firmware accepted for a display that went is retired,
as the swap watchdog would retire it, with its framebuffers kept until a
later present completes, and only its own commit's flip is finished as
failed. Each present notes the firmware's unplug count when it is begun,
on the same receive path as the reports, so a present begun before the
last unplug report is the departed display's, while one begun for a
display reported on the pipe since is left to complete. Presents
still queued are not sent: the connector is disconnected. The pipe is
then sent nothing, since no scanout of ours is left to stop. Two cases
still get the full power-off, which the old present no longer holds up:
a display the firmware reported on the pipe since, and a pair, which
stops through its own sequence. A present that cannot be retired leaves
the swap watchdog armed, and nothing is sent behind it unless another
display needs its power-off.

A system sleep can come before the compositor turns the CRTC off. Its
suspend cancels the watchdog too, so it ends the unplugged session the
same way before settling the queue, waiting first for the firmware's
report of an unplug the mux has announced, as the power-off does.

The decision is passed to the power-off as an argument. Firmware without
the IOMFB queue powers the pipe off as before.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb requested review from a team as code owners November 29, 2026 20:42
@erikwb
erikwb requested review from LiamRay11 and maralcbr November 29, 2026 20:42
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Merge readiness at d95defac: not ready yet

Check Detail
CI at head running running: apple-build, host-tests, KUnit dcp-fabric dcp-topology dcp-display
Review ok approved by DjDeveloperr, RyanTheTide
Requested changes ok none
Hardware row at head ok comment at d95defac
Conflicts ok none
PR text ok Risk: two-way · Macs whose external DCP uses the firmware-27 / H17P IOMFB queue (M1 on firmware 27, M4 and M5 dcpexts); others unchanged

Areas: area:display, area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 4261e69d

Blockers: None (wait for the queued hosted CI checks at 4261e69d — apple-build, host-tests, readiness, and KUnit matrix jobs — to finish green; kunit and pr-text have already passed).

Checked:

  • Audited both commits (b934f2d0 and 4261e69d, DCO present on both) across all 5 files (dcp-internal.h, dcp.c, iomfb.c, iomfb_template.c, dcp_dropped_swap_test.c):
    • iomfb_queue_report_locked() (iomfb.c:912-924): asserts dcp->iomfb.lock, rate-limits reporting to the final expired pass of iomfb_queue_settle(), and reads lockless channel/ACK/callback counters with READ_ONCE()/atomic_read().
    • dcp_typec_fw_hotplug() / dcp_typec_claim() / dcp_typec_fw_display() (dcp.c:137-188, iomfb_template.c:3281): packs the 31-bit unplug counter and connected bit into a single u32 written only on the RTKit receive path after filtering out non-display-change hotplug callbacks (typec_crtc_off, t6040_relinking, dcp_typec_relink). Both dcp_poweron() and dcp_crtc_atomic_modeset() claim the session; either mux-first or firmware-first unplug order is handled without leaking an unreported unplug across sessions.
    • iomfb_end_unplugged_session_h17p() (iomfb.c:1092-1172): waits up to IOMFB_UNPLUG_REPLY_MS (500 ms) on channels_idle_wq (now woken after callback execution in dcpep_handle_ack()), re-verifies !iomfb_present_unanswered(dcp) under dcp->iomfb.lock, distinguishes departed vs replacement presents via present_fw_unplugs (recorded on the same RX path in dcp_present_begin()), retires accepted presents via shared iomfb_retire_present_locked() while retaining framebuffers, cancels swap_watchdog_wq without _sync under iomfb.lock before iomfb_queue_advance(), and finishes dcp_drm_crtc_flip_lost() + drm_crtc_commit_put() outside the lock (no ref leak or lock inversion). Paired DCPs (peer_frames.active) and replaced displays (DCP_TYPEC_FW_REPLACED) still perform full pipe power-off.
    • dcp_swap_cleared() (iomfb_template.c:2446-2454): else if attaches cleanly to if (status) so an accepted clear swap (status == 0) on queued H17P/V27 firmware arms dcp_swap_watchdog_arm(dcp).
    • dcp_s2r_ext_suspend() (dcp.c:10389): invokes dcp_typec_end_unplugged_for_sleep(dcp) after pausing presentation and before iomfb_queue_settle().
  • Verified hardware evidence across three generations: exact-head J313 (M1, T8103, DCP 27.2.1, TS5 dock) before/after (1/1 baseline refused -> 6/6 deep sleeps + awake unplug/replug PASS, 0 failed units), plus J713 (M4, T8132) and J716c (M5 Max, T6050 paired DCPs) regression rows; arm64 QEMU KUnit 340/340 (apple-dcp-dropped-swap 28/28, 15 new cases, 6/6 mutations killed) and checkpatch.pl --strict clean.
Evidence
  • drivers/gpu/drm/apple/dcp.c:5777-5889 (dcp_typec_fw_*, dcp_typec_end_unplugged_for_sleep), :5961-5972 (dcp_poweroff), :10389 (dcp_s2r_ext_suspend).
  • drivers/gpu/drm/apple/iomfb.c:912-949 (iomfb_queue_report_locked, iomfb_queue_settle), :2359-2363 (dcpep_handle_ack), :4506-4564 (iomfb_retire_present_locked), :4766-4917 (iomfb_end_unplugged_session_h17p, iomfb_watch_unplugged_present_h17p).
  • drivers/gpu/drm/apple/iomfb_template.c:2319-2332 (dcp_present_begin), :2434-2454 (dcp_swap_cleared), :3250-3282 (dcpep_cb_hotplug).
  • drivers/gpu/drm/apple/dcp_dropped_swap_test.c: 15 new KUnit cases covering all unplug/replace/sleep/late-report/held-present/unqueued branches.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at 4261e69d. App approved (NEON-PR-REVIEW2), J313 row matrix PASS. dcp.c/iomfb.c are shared by every DCP Mac (+333/-32), so one more family at this head is needed (J473 + external display, or J616s: Type-C display unplug while awake and while the panel is DPMS-off, one short s2idle, no flip timeouts or DART faults). Merges under the 6-point rule after that and green CI, unless you object.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 29, 2026
@erikwb

erikwb commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

The two patches worked together on the J313 (T8103) daily build c78766a6b703, based on ee2c37398e47 with #3523 at a5af61d67c3e, #3655 at 4261e69d1e9a, and the IOMFB channel wait-queue prerequisite.

  • Docked deep sleep: 1/1 RTC wake with the CalDigit TS5 attached and its external display active. DP-2 returned at 3840×2160 at 120 Hz.
  • Awake reconnect: The display lit on all three observed reconnects. One restored 4K120 and two selected 1080p120. USB4, PCIe and 2.5 Gb/s Ethernet recovered. No DCP power-off or IOMFB transaction timeouts were observed.
  • Mode follow-up: A further reconnect selected 4K60 because DRM marked it preferred. An explicit 4K120 request worked on the same connection. On another reconnect DRM preferred 1080p120 and omitted 4K120 from its mode list, with the same USB4 link rate and lane count.

The combined run supports carrying both fixes in the J313 daily.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 30, 2026
…g tracking

Tracking firmware Type-C unplug reports updated dcpep_cb_hotplug(),
dcp_poweron(), dcp_poweroff(), and dcp_crtc_atomic_modeset() to call
dcp_typec_fw_hotplug(), dcp_typec_claim(), and
dcp_typec_fw_unplug_wait(), added the pipe_unplugged argument to
_dcp_poweroff(), and placed iomfb_end_unplugged_session_h17p() ahead of
iomfb_queue_atomic().

Update the four host-test harnesses that extract those functions:
- rate.py (publication-hpd): stub dcp_typec_fw_hotplug().
- lifecycle.py (stale-crtc-poweroff): verify dcp_typec_claim() via
  dcp_crtc_atomic_modeset(), stub dcp_typec_fw_unplug_wait(), and accept
  pipe_unplugged in _dcp_poweroff().
- dcpext26-queue-tests.py: end the iomfb.c slice at
  iomfb_atomic_release() and append iomfb_queue_atomic() explicitly.
- backlight-coldboot-tests.py: stub dcp_typec_claim().

Signed-off-by: Erik Bourget <erik@ebourget.net>
@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Dec 1, 2026
Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb requested a review from DjDeveloperr as a code owner December 1, 2026 12:17
@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the host-tests CI failures in be574d3b3b94 and forward-merged origin/main (19ee1b5bc9d5) at 5ce4ffaeb3fe.

Changes (be574d3b3b94, test harnesses only): drivers/gpu/drm/apple/ is unchanged from 4261e69d1e9a; the commit updates only the four host-test scripts that extract the modified functions:

  • tools/testing/selftests/drivers/gpu/apple-dcp/rate.py (publication-hpd): stub dcp_typec_fw_hotplug().
  • tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py (stale-crtc-poweroff): verify dcp->crtc_unplugs = dcp->typec_unplugs inside dcp_typec_claim() called from dcp_crtc_atomic_modeset(), stub dcp_typec_fw_unplug_wait(), and add pipe_unplugged to _dcp_poweroff().
  • tools/asahi/dcpext26-queue-tests.py: stop the iomfb.c extraction at iomfb_atomic_release() and append iomfb_queue_atomic() explicitly instead of slicing through to dcp_flush().
  • tools/asahi/backlight-coldboot-tests.py: stub dcp_typec_claim().

Forward merge of origin/main (5ce4ffaeb3fe, 19ee1b5bc9d5): Resolved the dcp_t6041_stop_one() conflict in drivers/gpu/drm/apple/dcp.c to keep main's firmware-27 iomfb_s2r_power_v27() path and pass false (_dcp_poweroff(dcp, false)) on the non-v27 branch.

Checks at 5ce4ffaeb3fe:

  • make O=_build_w1 ARCH=arm64 LLVM=1 W=1 drivers/gpu/drm/apple/ (defconfig + asahi.config, CONFIG_RUST=n): 0 errors, 0 warnings.
  • KUnit (ARCH=arm64, LLVM=1): topology.kunitconfig 231 passed / 1 skipped (232 total; apple-dcp-dropped-swap 28/28 passed), display.kunitconfig 188 passed / 1 skipped (189 total), tests/.kunitconfig 117/117 passed.
  • dcpext26-queue-tests and dcpext26-queue-tests --drop-v27-close (negative control killed): 2/2 pass.
  • backlight-coldboot-tests and backlight-coldboot-tests --negative-controls: 2/2 pass.
  • apple-dcp (publication-hpd, stale-crtc-poweroff, connected-irq-hpd-to-firmware, dcp-sink-irq-fallback pass; in run-host-tests.py --only apple-dcp, 87/101 units pass on Clang 23.1.5, with the remaining 14 unrelated fixtures failing locally on Clang 23's -Wunused-but-set-global under -Wall -Werror).
  • ./scripts/checkpatch.pl --strict --git d02c84abc8de..be574d3b3b94: 0 errors (b934f2d087bb has 1 line-length warning; 4261e69d1e9a and be574d3b3b94 0/0/0); git diff --check origin/main...5ce4ffaeb3fe clean.

Hardware rows / PR body: Scrubbed internal build names from the PR description and updated **Tested:** / **Not yet:** for 5ce4ffaeb3fe. #3273 is still open, and neither J473 nor J616s is available in our lab; J313, J713, and J716c rows were all run against the identical #3655 driver code at 4261e69d1e9a (before the 19ee1b5bc9d5 main merge).

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 1, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

The merge with main at 3330657b1deb conflicts in dcp-internal.h and iomfb.c. The conflict in iomfb.c overlaps #3305’s shared present-retirement helper. Please fold the unplug retirement into that helper while preserving the paired-stop admission checks, framebuffer lifetime, and watchdog ordering. The refreshed docked J313 sleep and reconnect row should cover the combined code.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

This needs a merge of main before it can go in a merge train. Since #3305 landed (3330657), main reworks the h17p present-retire path (iomfb_retire_stalled_present_h17p(), peer_paused, the deadline/channels-idle retire in iomfb.c). This branch changes the same lines for the queue and unplugged-session handling (iomfb_uses_queue(), iomfb_end_unplugged_session_h17p(), iomfb_queue_report_locked()). The conflicts are in dcp-internal.h and 2 hunks of iomfb.c. The two designs need combining by hand, not a mechanical resolution. Your approval and row at 5ce4ffa were in. After the merge-up it needs one re-approval at the new head, then it goes in the next train.

Combine the Type-C unplug present-retirement path with main's shared
iomfb_retire_present_locked_h17p() helper (from #3305):
- Return an explicit iomfb_retire_result (none, full, done) from
  iomfb_retire_present_locked_h17p() so watchdog, paired-stop, and
  unplug callers all share the same retirement, framebuffer-retention,
  watchdog-cancel (before iomfb_queue_advance()), and peer retired-ID
  recording path while preserving each caller's admission checks
  (deadline vs channels-idle) and full-table handling.
- Preserve paired-stop teardown when a firmware-27 paired transition
  is in flight (peer_transition_active) as well as when peer_frames.active
  is set.
- Keep both iomfb_pause_peer() and iomfb_queue_report_locked() in
  iomfb.c and both declarations in dcp-internal.h.

Signed-off-by: Erik Bourget <erik@ebourget.net>
Add KUnit coverage in apple-dcp-dropped-swap for the combined
iomfb_retire_present_locked_h17p() paths:
- verify iomfb_retire_stalled_present_h17p() returns false when the
  retired-present table is full;
- verify iomfb_end_unplugged_session_h17p() holds the present and re-arms
  the watchdog while channels are busy, cancels the watchdog without
  resetting retrain tracking when retiring, retains dropped scanout
  buffers, and falls through to paired power-off while a firmware-27
  paired transition is active.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

We carry this PR in our J313 (M1 Air, T8103) daily kernel alongside #3523 (now on main).

When deep-sleeping a docked J313 with an external firmware-27 display lit (or unplugging under a lit CRTC), USB4 teardown caused firmware to power off the pipe before CRTC power-off sent its clear swap; firmware swallowed that swap, stalling abort_swaps and setPowerState(0) until suspend refused sleep and the 10 s queue timeout declared DCP crashed.

Running smoothly in our J313 daily kernel for docked deep sleep and external display reconnect.

@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr @RyanTheTide Merged origin/main (d148fbda6dca, including #3305 at 3330657b1deb) at 7f3f64a9e359 and added KUnit coverage for the combined paths at 7afbc1520a85.

Combined #3305 + #3655 resolution (7f3f64a9e359):

  • Folded iomfb_end_unplugged_session_h17p() into the shared iomfb_retire_present_locked_h17p() helper, which now returns a 3-state enum iomfb_retire_result (IOMFB_RETIRE_NONE, IOMFB_RETIRE_FULL, IOMFB_RETIRE_DONE) with explicit check_deadline, check_channels_idle, and cancel_watchdog flags.
  • Preserved paired-stop and unplug admission checks (iomfb_channels_idle()), framebuffer retention (dcp_unarm_retained_framebuffers() + dcp->iomfb.dropped), watchdog cancellation via dcp_swap_watchdog_cancel() under dcp->iomfb.lock before iomfb_queue_advance(), and peer retired-ID recording via dcp_peer_record_retired_v27() outside dcp->iomfb.lock for all three callers.
  • On a full retired table (IOMFB_RETIRE_FULL), iomfb_retire_stalled_present_h17p() now returns false instead of spuriously waking vblank and retrying settle, while iomfb_retire_dropped_present_h17p() retains true for the watchdog and iomfb_end_unplugged_session_h17p() holds the present and re-arms the watchdog.
  • iomfb_end_unplugged_session_h17p() now checks peer_transition_active alongside peer_frames.active so an unplug racing a firmware-27 paired transition still falls through to paired power-off.
  • Kept both iomfb_pause_peer() and iomfb_queue_report_locked() in iomfb.c and both declarations in dcp-internal.h.

Checks & J313 hardware row at 7afbc1520a85:

  • KUnit (arm64 QEMU, LLVM=1): topology.kunitconfig 233/234 (1 skipped; apple-dcp-dropped-swap 30/30, including unplugged_combined_retire_guards_test and full-table coverage in stalled_present_retired_test), PROVE_LOCKING=y apple-dcp-dropped-swap 30/30, display.kunitconfig 201/202 (1 skipped), tests/.kunitconfig 117/117.
  • Host tests: dcpext26-queue-tests 2/2, dcp-peer-shown-tests 3/3, backlight-coldboot-tests 2/2, and apple-dcp (publication-hpd, stale-crtc-poweroff, dropped-swap-teardown, connected-irq-hpd-to-firmware, dcp-sink-irq-fallback, display) pass.
  • J313 (M1 Air, T8103, DCP 27.2.1, CalDigit TS5, external 3840x2160@120 on 271c00000.dcp) at 7afbc1520a85: clean boot (0 failed units, eDP-1 2560x1600@60 + DP-2 3840x2160@120 + enP1p3s0 UP); DP-2 DPMS off/on PASS; docked deep-sleep attempt (rtcwake -d /dev/rtc1 -m mem -s 15, func dcp_poweroff +p): external 271c00000.dcp cleanly took the combined unplugged-session retirement path (CRTC off after its display was unplugged: leaving the current connection alone, and the pipe the unplug powered off), 0 IOMFB/setPowerState(0) timeouts, 0 crashes, and cleanly restored dpin0, DP-2 3840x2160@120, and enP1p3s0. Full deep-sleep entry on main (645b086d9989..d148fbda6dca) is currently aborted by an unrelated internal panel 231c00000.dcp crash on set_power_state(0) (-16), which reproduces identically on plain origin/main 645b086d9989 without #3655.

Updated the PR body with the 7afbc1520a85 results; ready for re-approval once hosted CI completes.

RyanTheTide
RyanTheTide previously approved these changes Dec 1, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the #3305 merge resolution and guard tests at 7afbc15. The watchdog keeps its deadline gate. Paired stop and unplug still require idle channels, and a full retired table leaves the pending present and references untouched. Successful unplug retirement keeps the dropped buffers and lets the paired stop run during a transition. The exact-head dropped-swap suite reports 30/30 with lock proving enabled.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drivers/gpu/drm/apple/iomfb.c:4637 drops #3305’s 100 ms follow-up settle when the retired table is full. The caller in dcp-peer-runtime-v27.inc:359 uses the return value to decide whether to wait again. A full table leaves the accepted present in flight, and a later completion still clears the retired entries. In a host reproduction using both versions of the helper and a completion at 550 ms, main settled successfully, while this head returned -EBUSY at 500 ms. Returning res != IOMFB_RETIRE_NONE restored the retry in the same reproduction. Please keep peer-ID recording and vblank limited to IOMFB_RETIRE_DONE, preserve the retry for IOMFB_RETIRE_FULL, and update the regression test to cover a late completion.

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) and removed ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) labels Dec 1, 2026
…s full

In iomfb_retire_stalled_present_h17p(), returning
res == IOMFB_RETIRE_DONE dropped the 100 ms follow-up
iomfb_queue_settle() in dcp_peer_stop_v27_once() whenever the
retired-present table was full (IOMFB_RETIRE_FULL). Because a full table
leaves the accepted present in flight, a late completion arriving during
that window still finishes the present and clears the retired entries.

Keep dcp_peer_record_retired_v27() and dcp_drm_crtc_vblank() gated on
IOMFB_RETIRE_DONE so an unretired present is neither recorded as retired
on the peer nor prematurely signalled, while returning
res != IOMFB_RETIRE_NONE to preserve the follow-up settle retry.

Update stalled_present_retired_test to verify peer retired-ID recording
and vblank gating on full vs retired states, and add
stalled_present_full_late_completion_test covering a late completion
settling the queue during the follow-up window.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 1, 2026
@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Good catch — fixed in d95defac5c6c.

iomfb_retire_stalled_present_h17p() now keeps dcp_peer_record_retired_v27() and dcp_drm_crtc_vblank() gated on IOMFB_RETIRE_DONE while returning res != IOMFB_RETIRE_NONE, preserving the 100 ms follow-up iomfb_queue_settle() in dcp_peer_stop_v27_once() when the retired-present table is full.

Updated stalled_present_retired_test in drivers/gpu/drm/apple/dcp_dropped_swap_test.c to verify peer retired-ID and vblank gating across IOMFB_RETIRE_FULL and IOMFB_RETIRE_DONE, and added stalled_present_full_late_completion_test covering a late completion arriving during the follow-up settle window and clearing the full retired table.

Verified at d95defac5c6c:

  • arm64 KUnit topology.kunitconfig (234 passed, 1 skipped apple_g17_rx_util_min_test, apple-dcp-dropped-swap 31/31) and display.kunitconfig (201 passed, 1 skipped)
  • W=1 compile on iomfb.o and dcp_dropped_swap_test.o (0 warnings), checkpatch.pl --strict (0 errors, 0 warnings, 0 checks), host selftests passed
  • Docked J313 (M1 MBA, CalDigit TS5) boot at d95defac5c6c: clean boot, eDP-1 + DP-2 4K120 DSC, 0 failed units
  • J713 (M4 MBA) batched build containing d95defac5c6c: clean boot, DPMS off/on, and 15 s deep sleep pass

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 1, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the full-table case at d95defac. FULL now takes the caller’s 100 ms follow-up settle, while peer retirement recording and vblank remain DONE-only. The new KUnit case exercises the late completion and checks the queue settles, the retired table clears, and framebuffer references remain correct. The author reports 31/31 dropped-swap tests and a clean exact-head docked J313 boot.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked d95defac. A full retired-present table now preserves the 100 ms follow-up settle, and only a successful retirement records the peer ID and signals vblank. The late-completion test covers the reported failure, including clearing the retired table and retaining the right framebuffer references. The author reports 31/31 dropped-swap tests passing. Hosted CI and a docked J313 sleep and reconnect run on this head remain pending.

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at d95defac5c6c (B2 merge train, 12-01 merge bar). Approval at this head: DjDeveloperr,RyanTheTide. Row: in the PR body at 5ce4ffa (same PR claim; later heads = erikwb's merge of main (#3305 retire rework), guard tests and Dj's requested retry fix, all reviewed at head). CI: train L18 = main + #3655d95defac: Apple build + changed .c objects pass, KUnit dcp-fabric/dcp-topology/dcp-display pass, host tests apple-dcp/dcp 91 ok; DjDeveloperr approved at head Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit 5064714 into main Dec 1, 2026
13 of 14 checks passed
@RyanTheTide
RyanTheTide deleted the fix/dcpext-unplugged-sleep branch December 1, 2026 22:48
erikwb added a commit that referenced this pull request Dec 2, 2026
Reconcile the #3273 dock-display present-retirement, Type-C release, and host-test changes with main (c948713, including #2673, #3655, and #3939):

- drivers/gpu/drm/apple/dcp.c, dcp-internal.h: drop the removed dcpext_scanout_* hooks from dcp_dptx_connect_raw() and dcp_dptx_release_locked(), keep release_owed and the AFK release ticket, retain both dcp_swap_watchdog_keep() and dcp_swap_watchdog_cancel(), and keep main's dcp_typec_fw_unplug_wait() + _dcp_poweroff(dcp, pipe_unplugged) in dcp_poweroff() alongside iomfb_present_lost(dcp, true).
- drivers/gpu/drm/apple/iomfb.c: combine iomfb_retire_dropped_present_h17p() attachment reporting with main's shared iomfb_retire_present_locked_h17p() helper while keeping iomfb_present_begun_h17p() and iomfb_present_lost().
- drivers/gpu/drm/apple/iomfb_template.c, dcp_dropped_swap_test.c: record both iomfb_present_begun_h17p() attachment and present_fw_unplugs in dcp_present_begin() and dropped_test_start().
- tools/testing/selftests/drivers/gpu/apple-dcp/edid.py, lifecycle.py, tools/asahi/dock-display-replug-tests.py: keep both the AFK ticket fields in struct epic_cmd_info / apple_dcp_afkep and main's T6030 firmware 27.2 sleep stub (j516s_panel_service) in edid.py, and reconcile poweroff_replug / dock-display-replug mocks with _dcp_poweroff(), dcp_swap_watchdog_cancel(), and iomfb_retire_present_locked_h17p().

Signed-off-by: Erik Bourget <erik@ebourget.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants