Skip to content

drm/apple: train a Type-C display link again when the sink repeats IRQ_HPD, so a display that trained blank gets its picture - #2604

Closed
funkzy wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
funkzy:pr/dcp-irqhpd-retrain
Closed

funkzy wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
funkzy:pr/dcp-irqhpd-retrain

Conversation

@funkzy

@funkzy funkzy commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On the Mac Studio (M5 Ultra, J775D), a DisplayPort monitor on a USB-C port can come up with a signal and no picture, after boot or after a replug: its link training reported errors, and the sink then raises IRQ_HPD about every 19 s. Each request ends in dcp_retrain_oob(), and the hotplug worker applies the active mode again. On firmware 27 a mode set with an unchanged timing does not train the link again, so the screen stays blank until userspace sets another mode.

Why this shape

IRQ_HPD had one answer, a replay of the active mode, and the driver already has a second one for a link that must be trained again: the CRTC power cycle used for a rebuilt T6020 tunnel (dcp_retrain_active_crtc() with power_cycle). An earlier version chose between them by firmware version (27), which would power cycle on IRQ_HPDs raised for HDCP, MCCS or a dock's state, and gates on a version rather than on what happened. Here the sink's behaviour decides: a repeat IRQ_HPD within 30 s of a replay means the replay did not help, so the existing power-cycle path runs, at most twice per connection, with an unplug resetting the count. A power cycle counts against a budget only once it was started, through one helper for both budgets, this one and the T6020 tunnel's: a pass that finds no active CRTC to cycle, or a mode a commit already set, spends nothing. Where a same-mode set does train the link, the sink stops raising IRQ_HPD after the replay and no power cycle follows, so older firmware keeps today's behaviour for sinks the replay fixes. H17P pipes and the T6030 external processors keep their own handling.

Change

Two commits in drivers/gpu/drm/apple.

The first changes when the count that dj's 8800ffe ("drm/apple: power-cycle a T6020 tunnel CRTC that lost its mode") added is taken. dcp_retrain_active_crtc() now reports whether it started a power cycle, by asking the CRTC to turn off, and the hotplug worker counts a rebuilt T6020 tunnel's power cycle (DCP_TUNNEL_POWER_CYCLES) only then; one whose off fails still counts. The rest of that commit's design stays: the branch condition, the cap and its reset when the mode is valid. Before, the slot was spent before the modeset locks were taken; a pass that found no active CRTC this connector can retrain, or a mode a commit had already set, did nothing and still used it up. The dcpext26 retrain host test passes the new argument and checks it on every path.

The second answers a sink's repeated IRQ_HPD. A Type-C sink's IRQ_HPD still gets the replay of the mode first, which is enough when the sink raised it for something other than its link (HDCP, MCCS, a test request, a dock's state). Only when the same sink raises IRQ_HPD again within 30 s of that replay does the hotplug worker turn the CRTC off and on, the path it already uses for a rebuilt T6020 tunnel, which trains the link anew. At most two power cycles per display connection, counted like the tunnel's, only once started (dcp_power_cycle_done()); an unplug resets the count. The connector stays connected, userspace gets no hotplug event, and the link status is not set to bad, so userspace does not race the retrain.

Which machines: every DCP pipe behind a Type-C port, on every firmware, with no version check. The replay comes first and the cap of two per connection keeps the power cycle to sinks the replay did not help. Where a mode set of an unchanged timing trains the link again, a sink whose link the replay fixed stops raising IRQ_HPD and no power cycle follows; a sink that keeps raising IRQ_HPD with a good link blanks at most twice per connection there too. H17P pipes and the T6030 external processors keep their own handling. The 30 s window follows from the blank sink's measured 18.9 to 19.5 s IRQ_HPD period; the cap of two bounds what a sink that raises IRQ_HPD with a good link can cost (two blanks per connection).

Testing

On the J775D (Mac Studio, M5 Ultra), on this PR's own base: integration/aurora 00cbc67 plus #1973, which the J775D's desktop needs for its GPU node, and nothing else. Kit pr2604-4 is that base with this PR at 24c9b1a; kit pr2604-4b is the same base without it. One read-only one-shot boot of each through the 27.0 firmware stub with Aura main dff1235d8bac, default command line, a dead-man armed at each boot and the temperature guard running. Both booted to the desktop on HDMI with no DCP crash or recovery and the same failed units (iwd.service and systemd-networkd-persistent-storage.service, as on every read-only test boot). ALARM has no SELinux, so there is no AVC count. The kernel error lines of this PR's boot are a subset of the base's: the base boot also logged usb 3-1: device not accepting address 2, error -108, a Type-C USB start-up error outside anything this PR touches (it changes only drivers/gpu/drm/apple and its host test). The IRQ_HPD and power-cycle paths did not run: the DisplayPort monitor was on a USB-C port that this tree routes to no display coprocessor, so no DisplayPort sink came up. That row is listed under Still to run. Upstream host tests: 461 of 461 on the base and with #1973 and this PR, no result differs, the updated dcpext26 retrain test included. checkpatch --strict: clean on both commits.

Extra evidence, not this PR's own row: the previous head, 4f921ee (one commit, counting a power cycle before the retrain), on integration/aurora b21dcc6 with #1973 (kit pr2604-1): the same results in one boot, IRQ_HPD again not reached. An earlier form of these two commits, the same code with older comments, gave the same results on integration/aurora bb9f8ec with #1973.

Extra evidence, not this PR's own row: on our integration test kit (integration/aurora e0ee46a plus #1650, an earlier #1973 and two local commits) with the previous head's change (the same power cycle, counted before the retrain rather than after it), through the 27.2 stub, a DisplayPort monitor on the routed USB-C port and HDMI on the other DCP, three boots; the first two ran with a firmware 27 check in place, which takes the same path on this firmware. In two, link training at boot reported errors; the sink's first IRQ_HPD (10.7 and 10.4 s) got the replay and the link stayed as it was; its second, 19.1 and 19.0 s later, power cycled the CRTC, the link trained and came up at 32.2 and 31.9 s, and no further IRQ_HPD came up to 72 and 123 s. In the other boot the link recovered through the existing relink, and a cable replug trained cleanly, the desktop back a few seconds after the plug. HDMI kept its desktop throughout, and neither DCP crashed or recovered. Kernel error lines not in a control boot without a DisplayPort monitor: the link-training faults this change answers, and in one boot one display-coprocessor log line during the relink.

Still to run

  • The own-base IRQ_HPD row: kits pr2604-4 and pr2604-4b with the DisplayPort monitor on the routed USB-C port and someone watching it, a boot each (replay, then a power cycle on a repeat) and a replug.
  • The T6020 tunnel count (first commit): we have no M2 Pro or M2 Max. dj, or an M2 Pro/Max owner: a Type-C display through a dock that rebuilds the tunnel, a replug, the power-cycle count in the kernel log and 0 DCP crashes, with and without this PR.
  • No sink that raises IRQ_HPD while its link is good (a dock, an HDCP monitor) was available.
  • Macs on older DCP firmware (12.3 to 26.6) with a Type-C display: not tested; rows from their owners welcome (a boot and a replug, and a dock or HDCP monitor if available).
  • Other firmware 27 machines with a Type-C display: not tested.
Full description

IRQ_HPD does not always mean a lost link: HDCP, MCCS, test requests and dock or adapter state changes raise it too, and for those applying the mode again is enough. So a Type-C sink's IRQ_HPD still gets that replay first. Only when the sink raises IRQ_HPD again within 30 s of a replay does the hotplug worker turn the CRTC off and on, as it already does for a rebuilt T6020 tunnel (dcp_retrain_active_crtc() with power_cycle). That releases the DPTX link and connects it again before the mode is set, so the link is trained anew. The connector stays connected and userspace gets no hotplug event. The link status is not set to bad for a power cycle, so that userspace does not race it with a mode set of its own.

Each power cycle needs a replay that did not help before it, and a display connection gets at most two (DCP_SINK_IRQ_POWER_CYCLES); an unplug starts the count again. A sink that keeps raising IRQ_HPD while its link is good therefore blanks at most twice per connection, and is then only answered with the replay. The window is 30 s because the blank sink above repeats IRQ_HPD every 18.9 to 19.5 s: a window of a few seconds would never see its second request.

The request reaches the worker as a hotplug reason of the connector, DCP_HOTPLUG_SINK_IRQ, as Ryan Murray suggested in review: it is queued with READY in one atomic_or(), after the mode was invalidated, and the worker takes it with the other reasons in its one atomic_xchg(). A flag read apart from the reasons could be taken by a run already under way, and the run queued for that IRQ_HPD would then go without it. The apple-dcp selftests, which build dcp_typec_route_apply() on the host, get a stub for the new dcp_retrain_sink_irq() beside the one for dcp_retrain_oob().

Unchanged:

  • a sink the firmware disconnected: dcp_dptx_recover_irq() (e19eb21);
  • a running relink: it connects the sink anew (dcp_typec_sink_relink(), 5afc29b and a907f77);
  • H17P pipes and the T6030 external processors (890572d).
Full test results (extra evidence: our integration test kit on integration/aurora e0ee46a, not this PR's own row)
  • Before: after boot and after a cable replug, the monitor showed a signal and no picture; IRQ_HPD came every 19 s (15 in 280 s); a mode change (1920x1080@75, then back to @60) brought the picture and stopped the requests.
  • First boot with this change: link training at boot reported errors. The sink's first IRQ_HPD, at 10.7 s, got the replay, and the firmware left the link as it was. Its second, 19.1 s later, power cycled the CRTC: the link was trained again and up at 32.2 s, and no further IRQ_HPD came up to 72 s, when the check ended.
  • Second boot: the link recovered through the relink before an IRQ_HPD reached the replay, and a cable replug trained cleanly, with the desktop back on the monitor a few seconds after the plug.
  • Third boot, this head (no firmware check): link training at boot reported errors. The first IRQ_HPD, at 10.4 s, got the replay; the second, 19.0 s later, power cycled the CRTC (1 of 2), and the link was up at 31.9 s. No further IRQ_HPD came up to 123 s. Failed units: iwd.service and systemd-networkd-persistent-storage.service, as in the control boot; the kernel's error and warning lines are the same set as in the first boot. Nobody watched the DisplayPort monitor in this boot.
  • HDMI kept its desktop throughout, and neither DCP crashed or recovered.
  • An earlier form of this change, which power cycled on the first IRQ_HPD, ran on integration/aurora at e0ee46a: the desktop showed on DisplayPort 3.5 s after the first mode set, no IRQ_HPD came in the next 680 s, and two replugs trained cleanly.
  • checkpatch --strict: clean. The appledrm build has no new warning. Upstream host tests: 451 of 451, the apple-dcp suite included.
  • Kernel log and units: compared line by line with a boot of the same kernel base without the change (no DisplayPort monitor attached), after removing timestamps and numbers: the added error lines are the DisplayPort link faults at boot and, in the second boot, one display-coprocessor log line during the relink. The boot journals list the same failed units in all three boots.

Thanks to Ryan Murray for the hotplug-reason design in review.

  • Clean-room: no Apple code, strings, firmware, RE output or tuning values
  • No chip/board/firmware-version gate where a hardware property can decide
  • Works on the default kernel command line; no hacks, delays or lab-only paths
  • Safety limits come from the machine, not from constants in code
  • Hardware safety rules followed for every test boot
  • Third-party commits unchanged; reporters and testers credited
  • Commits: human Signed-off-by only; no co-author or Assisted-by trailers
  • Tested on the affected hardware; no regression

Assisted-by: LLM (Claude:Opus 5.5)

@funkzy

funkzy commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

dj, a small one in your Type-C retrain path, for when you have a minute.

On the J775D (firmware 27, 27.2 stub), a DisplayPort monitor on USB-C came up with a signal and no picture after boot
and after a replug. The sink then raised IRQ_HPD every ~19 s; each went through dcp_retrain_oob() and the hotplug
worker's drm_atomic_helper_reset_crtc(), which sets the same mode again, and on firmware 27 that does not retrain the
link. A mode change brought the picture and stopped the requests.

The fix reuses your power-cycle path in dcp_retrain_active_crtc() (the T6020 tunnel one) for that case only: a
firmware 27 pipe, connected Type-C sink, IRQ_HPD. The IRQ_HPD branch sets a flag before dcp_retrain_oob(); the
hotplug worker consumes it at the top and takes power_cycle, without the link-status-bad property. Chris Kearney's
recovery of a disconnected sink, sithglan's relink, H17P, T6030 and other firmware stay as they are.

On the J775D it trained the link again 3.5 s after the first mode set, the desktop showed, and no IRQ_HPD followed in
680 s; two replugs came back.

Would you rather have the flag in the hotplug reasons (connector->hotplug_reasons) instead of a field on the DCP? I
kept it beside tunnel_power_cycles since that is where the worker's power-cycle state already lives.

@RyanTheTide

RyanTheTide commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

host-tests fails in the apple-dcp suite on this head (6f5685e): tests 75-79 and 85 report not ok (actual-dcp-finalizer-recovery, provider-order-releases-failed-lease, failed-safe-allows-new-dp-admission, altmode-safe-skips-quiescence, concurrent-prepare-set-stale-quiescence, mux-release-stages). Other PRs on the same integration base pass the suite, so it is the dcp-fabric.c change. Run it locally with python3 -I tools/asahi/run-host-tests.py --only apple-dcp, or see the job's apple-dcp/log artifact.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The diagnosis makes sense, and reusing the power-cycle path is a reasonable fix. Two things before it goes in:

  • Nothing limits the new power cycle. Every IRQ_HPD on a firmware 27 Type-C sink sets sink_irq_relink (dcp-fabric.c:2216). dcp_retrain_oob() always invalidates the mode (iomfb.c:1576), so each one ends in a CRTC off/on (iomfb.c:1534). IRQ_HPD is not only a link loss: HDCP CP_IRQ, MCCS, test requests and dock or adapter state changes raise it too. Before, those cost a same-timing reset; now each one blanks the screen. The T6020 tunnel use of this path is capped by DCP_TUNNEL_POWER_CYCLES, but the sink IRQ case is not counted (iomfb.c:2023). A sink that raises IRQ_HPD regularly while its link is fine would blank every time. Could the power cycle be kept for when the plain replay did not help, for example a second IRQ_HPD on the same connection within a few seconds of the last replay, with a per-connection cap like the tunnel path?
  • On your question: yes, I would put it in connector->hotplug_reasons. dcp_hotplug() reads the reasons (iomfb.c:1930) and the new flag (iomfb.c:1952) separately, so a run already between those two lines can take the flag, and the run queued for that IRQ then sees false. A reason bit taken by the same atomic_xchg avoids that, and it belongs to the connector the work is for.

It would also help to have a run with a sink that raises IRQ_HPD while its link is good (a dock or an HDCP monitor), to show it does not blank in a loop.

Assisted-by: LLM (Claude:Opus 5.5)

@funkzy
funkzy force-pushed the pr/dcp-irqhpd-retrain branch from 6f5685e to 7adafdc Compare November 21, 2026 03:19
@funkzy

funkzy commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Both points are in the updated commit; the PR still has one commit.

Host tests. The apple-dcp failures were one compile error, and test 74 (actual-dcp-normal-safe) failed the same way as 75-79 and 85. These tests build dcp_typec_route_apply() against their own model of struct apple_dcp, which has neither sink_irq_relink nor DCP_FIRMWARE_V_27_0. The fabric code now reads neither. It calls a new dcp_retrain_sink_irq() instead, and transaction.py gets a stub for it beside the one for dcp_retrain_oob(). No assertion changes. run-host-tests.py, base against the new head: 451 of 451 pass on both, and no result differs. We should have caught this before pushing.

(a) Bounded power cycle. A firmware 27 Type-C sink's IRQ_HPD gets the plain same-mode replay first, as it did before this PR. Only when the same connection raises IRQ_HPD again within 30 s of that replay does the hotplug worker power cycle the CRTC. Each power cycle needs a replay that did not help before it, and a connection gets at most two (DCP_SINK_IRQ_POWER_CYCLES). The count starts again after an unplug: it is keyed to typec_unplugs, which the CRTC off and on of a power cycle does not change. So a sink that keeps raising IRQ_HPD while its link is good blanks at most twice per connection, and after that it only gets the replay. The replay still sets the link status to bad, as before; the power cycle does not.

On the window: 30 s is not "a few seconds". The blank-trained sink here repeats IRQ_HPD every 18.9 to 19.5 s (14 intervals in one boot), and that repeat is the only sign we get that the replay did not help. With a window of a few seconds the second request is never seen, and the display stays blank. 30 s is about 1.5 times that period. The longer window means more IRQ_HPDs can count as a repeat; the cap of two per connection limits what that costs. If you would rather have a shorter window, 25 s still covers this sink, with less margin.

(b) Reason bit. Done. DCP_HOTPLUG_SINK_IRQ is a bit in connector->hotplug_reasons, queued with READY in one atomic_or() after the mode is invalidated, and taken by the worker's existing atomic_xchg(). dcp->sink_irq_relink is gone.

J775D (M5 Ultra), 27.2 stub, a DisplayPort monitor on a USB-C port and HDMI on the other DCP:

case result
boot, link trained with errors first IRQ_HPD at 10.7 s: replay, link unchanged; second, 19.1 s later: power cycle 1 of 2, link up at 32.2 s; no further IRQ_HPD up to 72 s
boot, link recovered by the existing relink the one IRQ_HPD came during the relink and took that path: no replay, no power cycle; desktop on DP (seen on the monitor)
cable replug trained cleanly, no IRQ_HPD; desktop back on DP within about 5-6 s of the plug (seen on the monitor)
HDMI desktop throughout, both boots
DCP no crash or recovery

Nobody watched the DP monitor during the boot with the power cycle. The earlier version of this patch, which power cycled on the first IRQ_HPD, was watched, and the picture appeared after the cycle.

Sink that raises IRQ_HPD with a good link. We have no dock and no HDCP monitor here, so I can't show the no-loop case on hardware. With the cap, such a sink costs at most two blanks per connection.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Checked the updated commit. Both points are covered. A sink IRQ gets the plain replay first. The CRTC is power-cycled only when the same connection asks again within DCP_SINK_IRQ_WINDOW_MS of that replay, at most DCP_SINK_IRQ_POWER_CYCLES times per connection, and an unplug resets the count. That bounds a misbehaving sink to two blanks. DCP_HOTPLUG_SINK_IRQ now goes through hotplug_reasons with the same atomic_xchg(), so the race is gone. The 30 s window makes sense given the 19 s repeat you measured. The J775D table is a good row, and the remaining gap (a good-link sink that keeps raising IRQ_HPD) is bounded by the cap.

Assisted-by: LLM (Claude:Opus 5.5)

@funkzy
funkzy force-pushed the pr/dcp-irqhpd-retrain branch from 7adafdc to 4f921ee Compare November 21, 2026 06:20
@funkzy

funkzy commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Following Aurora's pre-PR checklist, I've dropped the firmware 27 condition. A repeated IRQ_HPD now power cycles the CRTC on every firmware, still only after a replay of the mode that did not help, and at most twice per connection.

Where a mode set of an unchanged timing trains the link again, the replay should already fix a blank link, so the sink stops asking and no power cycle follows. The cost on other firmware is a sink that keeps raising IRQ_HPD while its link is good: up to two blanks per connection, where today it gets none.

We only have the J775D, on firmware 27. Could your lab run a Type-C DisplayPort monitor on a Mac with older DCP firmware (12.3 to 26.6) on this head? A boot and a replug would do, and a dock or an HDCP monitor too if you have one. The kernel logs sink IRQ_HPD again: power cycling to train the link for each power cycle; a row with the picture result and that line's count would tell us whether the condition can stay out.

Here, on the J775D (firmware 27), this head behaves as before: a boot whose link trained with errors got the replay at the first IRQ_HPD and one power cycle 19.0 s later, after which the link came up and no IRQ_HPD followed up to 123 s. Host tests: 451 of 451 on base and head.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 4f921ee: No blockers.

Both points from our last comment stay resolved at this head. The power cycle comes only after a replay that did not help, within DCP_SINK_IRQ_WINDOW_MS, at most DCP_SINK_IRQ_POWER_CYCLES per connection (iomfb.c:1619), and the reason goes through hotplug_reasons (iomfb.c:2011). The only change since 7adafdc is that the firmware 27 condition is gone: sink_irq = reasons & DCP_HOTPLUG_SINK_IRQ (iomfb.c:2011), plus the matching comment edits in dcp-fabric.c, dcp-internal.h and iomfb.c. That is correct. The decision now rests on what the sink does, not on the firmware version. Where a same-timing mode set does retrain, the replay ends the requests and dcp_sink_irq_power_cycle() never returns true. The worst case is still two blanks per connection. Nothing else in the diff changed.

HW row: a Mac on pre-27 DCP firmware (M1 Pro or M2) on this head with a USB-C DisplayPort monitor: boot plus two replugs, then the same with a dock or an HDCP monitor. Pass: picture on every plug, the count of sink IRQ_HPD again: power cycling lines (expected 0 for a good link, never more than 2 per connection), 0 DCP crashes, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

On the row you asked for: I tried the A18 Pro (J700, firmware 26.x) with this head's appledrm ready to swap in, but its only external display is behind a DisplayLink adapter, not DisplayPort alt mode. card1-DP-1 stays disconnected with no modes, so the Type-C DP path this changes never runs there. I didn't take the test boot. I don't have a pre-27 Mac with a USB-C DisplayPort monitor attached right now, so the older-firmware row is still open.

Assisted-by: LLM (Claude:Opus 5.5)

@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.

Pre-PR checklist review at 4f921eebe48e (CI: host-tests passing, 451/451 including apple-dcp).

Code & policy (§1–§4, §6): 0 blockers.

  • §1: Dropping the firmware-27 gate is right; escalation now depends purely on sink repeat behavior (DCP_HOTPLUG_SINK_IRQ) across all Type-C DCP firmwares.
  • §2: Queuing DCP_HOTPLUG_SINK_IRQ | DCP_HOTPLUG_READY in one atomic_or() after dcp_mode_invalidate() and consuming it in dcp_hotplug()'s atomic_xchg() avoids the worker race cleanly. Verified dcp->typec_unplugs is incremented only on real disconnect (dcp_dptx_disconnect_oob() in drivers/gpu/drm/apple/dcp.c:3920) and never on dcp_set_crtc_active(), so the 2-power-cycle-per-connection cap holds and resets properly on unplug. DCP_SINK_IRQ_WINDOW_MS (30 s) is a measured repeat-detection window (~1.5× observed 18.9–19.5 s repeat interval), not a sleep/retry hack.
  • §4 / §6: Single commit carries human author/committer and Signed-off-by: only (zero AI trailers); PR body has Assisted-by:; naming clean.

Holding for §5 hardware evidence (and minor housekeeping):

  • Pre-27 DCP firmware Mac (12.3–26.6) row still open: Because the firmware-27 gate is gone, this path runs on every Type-C DCP firmware. Still needs a USB-C DisplayPort boot + replug run on a pre-27 Mac (plus a dock/HDCP good-link IRQ_HPD check if available), reporting picture on every plug, sink IRQ_HPD again: power cycling count (expected 0 on good links, <= 2 worst case), 0 DCP crashes, and 0 new kernel errors.
  • J775D live head (4f921eeb): Boot log confirms replay -> 2nd IRQ_HPD 19.0 s later -> power cycle 1/2 -> link up at 31.9 s with 0 further IRQ_HPD to 123 s and 0 new failed units, though the PR notes nobody visually watched the monitor on that boot; visual confirmation on the live head would close that gap too.
  • Please also check/confirm the unchecked - [ ] Hardware safety rules followed for every test boot item in the PR body checklist, and update the PR title (which still says firmware 27) to match the commit subject.

Minor non-blocking note:

  • In dcp_hotplug() (drivers/gpu/drm/apple/iomfb.c:2081), dcp_sink_irq_power_cycle() runs before dcp_retrain_active_crtc() checks whether an active retrainable CRTC exists (iomfb.c:1533). If a sink raises repeated IRQ_HPD before userspace enables a CRTC, it could consume a power-cycle budget slot without actually cycling.

Assisted-by: LLM (Gemini 4 Neon)

… so a retrain with nothing to cycle no longer uses up the budget

The hotplug worker spent one of a rebuilt T6020 tunnel's
DCP_TUNNEL_POWER_CYCLES, the budget that commit 8800ffe
("drm/apple: power-cycle a T6020 tunnel CRTC that lost its mode") added,
before dcp_retrain_active_crtc() took the modeset locks. There, finding
no active CRTC this connector can retrain, or a mode a commit has
already set, it does nothing, yet the slot was gone: two such passes
left a later lost mode without its power cycle until the mode was valid
again.

dcp_retrain_active_crtc() now reports whether it started a power cycle,
by asking the CRTC to turn off, and the worker counts it only then. A
power cycle whose off fails still counts, so the budget still bounds
the attempts, and it is still reset when the mode is valid.

The dcpext26 retrain host test passes the new argument and checks it:
set for the power cycle it does, clear when a commit has set the mode,
when there is no active CRTC, and on the reset and release paths.

Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
…Q_HPD, so a display that trained blank gets its picture

On the M5 Ultra Mac Studio (J775D), a DisplayPort monitor on a USB-C
port can come up with a signal and no picture, after boot or after a
replug: its link training reported errors, and the sink then raises
IRQ_HPD every 19 s. Each request goes to dcp_retrain_oob(), and the
hotplug worker applies the active mode again. On firmware 27 a mode set
with an unchanged timing does not train the link again, so the display
stays blank until userspace sets another mode.

IRQ_HPD does not always mean a lost link: HDCP, MCCS, test requests and
dock or adapter state changes raise it too, and for those applying the
mode again is enough. So a Type-C sink's IRQ_HPD still gets that replay
first. Only when the sink raises IRQ_HPD again within 30 s
of a replay does the hotplug worker turn the CRTC off and on, as it
already does for a rebuilt T6020 tunnel (dcp_retrain_active_crtc() with
power_cycle). That releases the DPTX link and connects it again before
the mode is set, so the link is trained anew. The connector stays
connected and userspace gets no hotplug event. The link status is not
set to bad for a power cycle, so that userspace does not race it with a
mode set of its own.

Each power cycle needs a replay that did not help before it, and a
display connection gets at most two (DCP_SINK_IRQ_POWER_CYCLES); an
unplug starts the count again. A power cycle is counted only once it was
started, the CRTC asked to turn off, by dcp_power_cycle_done(), which
counts a T6020 tunnel's too: one asked for with no active CRTC to cycle,
or with a mode a commit had already set, spends nothing. A sink that
keeps raising IRQ_HPD while its link is good therefore blanks at most
twice per connection, and is then only answered with the replay. The
window is 30 s because the blank sink above repeats IRQ_HPD every 18.9
to 19.5 s: a window of a few seconds would never see its second request.

The request reaches the worker as a hotplug reason of the connector,
DCP_HOTPLUG_SINK_IRQ, as Ryan Murray suggested in review: it is queued
with READY in one atomic_or(), after the mode was invalidated, and the
worker takes it with the other reasons in its one atomic_xchg(). A flag
read apart from the reasons could be taken by a run already under way,
and the run queued for that IRQ_HPD would then go without it. The
apple-dcp selftests, which build dcp_typec_route_apply() on the host,
get a stub for the new dcp_retrain_sink_irq() beside the one for
dcp_retrain_oob().

The other IRQ_HPD cases are unchanged: a sink the firmware disconnected
still goes through dcp_dptx_recover_irq(), a running relink still
connects the sink anew (dcp_typec_sink_relink()), H17P pipes and the
T6030 external processors keep their own handling.

The new path applies on every firmware, with no version check: the
replay comes first, and the cap of two per connection keeps the power
cycle to sinks the replay did not help. Where a mode set of an
unchanged timing trains the link again, a sink whose link the replay
fixed stops raising IRQ_HPD and no power cycle follows; a sink that
keeps raising IRQ_HPD with a good link blanks at most twice per
connection there too. It was tested on firmware 27, on the J775D only.

Tested on the J775D through the 27.2 stub, with a DisplayPort monitor
on a USB-C port and HDMI on the other DCP, in three boots; the first
two ran with a firmware 27 check in place, which takes the same path on
this firmware. In two of them link training at boot reported errors.
The sink's first IRQ_HPD, at 10.4 and 10.7 s, got the replay, and the
firmware left the link as it was. Its second, 19.0 and 19.1 s later,
power cycled the CRTC: the link was trained again and up at 31.9 and
32.2 s, and no further IRQ_HPD came up to 123 and 72 s, when the checks
ended. In the other boot the link recovered through the relink before
an IRQ_HPD reached the replay, and a cable replug trained cleanly, with
the desktop back on the monitor a few seconds after the plug. HDMI kept
its desktop throughout, and neither DCP crashed or recovered. No sink
that raises IRQ_HPD while its link is good, such as a dock or an HDCP
monitor, and no Mac on older DCP firmware was available for testing.

Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
@funkzy
funkzy force-pushed the pr/dcp-irqhpd-retrain branch from 4f921ee to 24c9b1a Compare November 22, 2026 18:54
@funkzy funkzy changed the title drm/apple: train a firmware 27 Type-C display link again on IRQ_HPD, so a display that trained blank gets its picture drm/apple: train a Type-C display link again when the sink repeats IRQ_HPD, so a display that trained blank gets its picture Nov 22, 2026
@funkzy

funkzy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. On your minor note: you were right, and it is fixed in the new head, 24c9b1a. dcp_sink_irq_power_cycle() spent a slot before dcp_retrain_active_crtc() knew whether an active, retrainable CRTC existed, and the T6020 tunnel count from your 8800ffe was taken the same way. The PR is now two commits:

  • The first makes dcp_retrain_active_crtc() report whether it started a power cycle (asked the CRTC to turn off), and counts a tunnel power cycle only then; one whose off fails still counts. The rest of 8800ffe's design is unchanged. The dcpext26 retrain host test passes the new argument and checks it on each path.
  • The second, the IRQ_HPD change, only decides whether to ask for a power cycle. dcp_power_cycle_done() counts it afterwards, for both budgets. A pass with no active CRTC to cycle, or with a mode a commit already set, spends nothing, and the sink's replay stays pending.

We have no M2 Pro or Max, so the tunnel count is untested here. If you or an M2 Pro/Max owner can run it: a Type-C display through a dock that rebuilds the tunnel, a replug, the power-cycle count in the kernel log and 0 DCP crashes, with and without this PR.

Own-base row for this head: integration/aurora 00cbc67 plus #1973 (the J775D's GPU node, for the desktop), with and without this PR, nothing else. Kits pr2604-4 and pr2604-4b, 27.0 firmware, published Aura main dff1235d8bac, default command line. Both boot to the desktop with no DCP crash or recovery and the same failed units. This PR's kernel error lines are a subset of the base's. Host tests: 461 of 461 on base and head, no result differs. checkpatch --strict is clean on both commits.

The IRQ_HPD case did not run, though: the DisplayPort monitor was on a USB-C port this tree doesn't route to a display coprocessor. The replay-then-power-cycle boot, its baseline and a replug on this base, with someone watching the monitor, come next. Until then the earlier IRQ_HPD boots stay in the body as labelled extra evidence with their base.

Your other hold item is still open too: the row on pre-27 DCP firmware (12.3 to 26.6). No such Mac here; the body asks their owners.

The hardware-safety box stays unticked for a stated reason. The three IRQ_HPD boots of 11-20, cited as extra evidence, ran before our dead-man and temperature guard. Every own-base boot ran under both. I'll tick the box once the IRQ_HPD row has been rerun under them.

The title follows the second commit's subject.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 24c9b1a: no blockers.

  • The first commit fixes the early spend. dcp_retrain_active_crtc() sets *cycled only on the branch that asks the CRTC to turn off (iomfb.c:1548), and the tunnel budget is taken after the call, only then (iomfb.c:2128). The host test checks it on every path, including the two passes that are asked to cycle but have nothing to do.
  • In the second commit, dcp_sink_irq_power_cycle() now only decides, and dcp_power_cycle_done() (iomfb.c:1664) spends the budget for a cycle that ran. A pass with no active CRTC leaves the replay pending, so a repeat in the same window tries again, and the cap still holds. Both points from the earlier review stay resolved.
  • One small thing for whoever runs the rows: the log line is now sink IRQ_HPD again: power cycled the CRTC to train the link (n of 2), not the power cycling text that earlier comments said to count. Matching on sink IRQ_HPD again: finds both.

On the T6020 tunnel count: I don't have an M2 Pro or Max either, so that row still needs an owner. The rows still open are the ones you list: the watched replay-then-power-cycle boot and a replug at this head on its own base, and a Mac on pre-27 DCP firmware with a USB-C DisplayPort monitor.

Assisted-by: LLM (Claude:Opus 5.5)

@funkzy

funkzy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #2879, which takes a different approach after finding the cause: on the alt-mode path a sink's IRQ_HPD was answered by re-applying the unchanged mode instead of reaching the firmware's DPTX port. The power-cycle retry on a repeated IRQ_HPD is withdrawn.

Thanks to Ryan and dj for the reviews here. dj, the T6020 tunnel-count fix from this PR's last head is available as its own PR if you want it.

@funkzy funkzy closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants