Skip to content

iommu/apple-dart: drain TLB flushes and fault IRQs when display DART goes dark - #3307

Merged
RyanTheTide merged 3 commits into
mainfrom
feat/apple-dart-display-dark-drain
Nov 27, 2026
Merged

RyanTheTide merged 3 commits into
mainfrom
feat/apple-dart-display-dark-drain

Conversation

@erikwb

@erikwb erikwb commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Drain in-flight display DART TLB flush writers, map TCR readers, and shared fault IRQ handlers before lowering display power domains at runtime, preserve display_dark and display_tlb_stale if reopen drain or TLB invalidation fails, and propagate dark/stream errors across all apple-dcp callers.
Tested: Built drivers/iommu/apple-dart.o and drivers/gpu/drm/apple/dcp.o (ARCH=arm64 LLVM=1 W=1, 0 warnings), strict checkpatch.pl (0 errors, 0 warnings, 0 checks), tools/asahi/backlight-coldboot-tests.py, tools/asahi/apple-dart-range-tests.py, tools/asahi/dart-sleep-writer-tests.py, tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py, and tools/testing/selftests/drivers/gpu/apple-dcp/run.py host suite PASS at eab8b5157340. Hardware-verified on J713 (M4 MacBook Air, macOS 27.2 firmware, default cmdline) in a combined trial build merging j713-dcpext/air-dcpext-272 (7a8022a6d24d) with #3297 (2b1bab104938), #3300 (6a84c1d95460), #3307 (eab8b5157340), and #3308 (05d728d91d68): clean DART dark enter/exit and stream stop/restore across idle power-off and pm_test=devices deep suspend/resume for both external DCPs (0 errors/warnings).
Risk: two-way door · Macs using runtime display power-down or S2R DART transitions (T8020, T8140, T8142, T6041, and T8132 v27).
Not yet: Full hardware S2R wake cycle on J713 and verification on T8020 / T8140 / T8142 / T6041 Macs.

Details

When a display DART is marked display_dark before its power domain is lowered at runtime, an in-flight TLB flush that already passed the display_dark check or a shared fault IRQ handler can still reach DART MMIO after the domain powers off. Conversely, clearing display_dark after a failed or incomplete TLB flush or before T8020 stream disable/restore completes can reopen DMA with stale translations.

  • Track active display TLB flush writers (display_writers) and dark-mode page-table sync writers (display_dark_writers) under managed_lock in apple_dart_domain_flush_tlb_range().
  • Gate apple_dart_irq() on display_dark, serialize with dart->lock for map TCR readers, and call synchronize_irq() in apple_dart_display_dark_enter().
  • Return an error from apple_dart_display_dark_exit() and preserve display_dark and display_tlb_stale on drain timeout or TLB invalidation failure; disable T8020 target streams immediately after apple_dart_hw_reset() and enable streams only after apple_dart_display_dark_exit() succeeds.
  • Return int from apple_dart_power_dark() and propagate errors from apple_dart_power_dark(), apple_dart_display_streams(), and D572 dcp_s2r_dart_power() (serialized under s2r_dart_lock) across dcp_s2r_domains_off(), dcp_s2r_ext_domains_off(), dcp_s2r_ext_start(), dcp_s2r_warm_restart(), dcp_s2r_display_on(), dcp_s2r_light_running(), dcp_s2r_prewarm_work(), dcp_t6041_ext_darts_dark(), dcp_t6041_stop_one(), and dcp_t6041_start_one().
  • Commit eab8b5157340 updates host-test harness stubs (apple-dart-range-tests.py, dart-sleep-writer-tests.py, bcm4377-radio-sids.py) for managed_lock, display_writers, and display_dark_writers.
Evidence

…goes dark

When a display DART is marked display_dark before its power domain is
lowered at runtime, a TLB flush that already passed the display_dark
check or a shared fault IRQ handler can still reach DART MMIO after the
domain powers off.

Track active display TLB flush writers and dark-mode page-table sync
writers under managed_lock, gate apple_dart_irq() on display_dark,
drain in-flight writers, map TCR readers, and fault IRQs before
returning from apple_dart_power_dark(..., true) and
apple_dart_display_streams(..., false, ...), and drain dark writers
while flushing any stale TLB updates before clearing display_dark or
re-enabling streams. On a failed or incomplete reopen drain/flush,
preserve display_dark and display_tlb_stale and return the error.

Return an error from apple_dart_power_dark() and propagate errors from
apple_dart_power_dark() and apple_dart_display_streams(..., true, ...)
in all apple-dcp callers so power domains are never lowered after a
drain failure and firmware is never restarted with stale DART state.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team as code owners November 26, 2026 20:18
@erikwb
erikwb requested review from LiamRay11 and maralcbr November 26, 2026 20:18
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 9dd8b87b: ready to merge

Check Detail
CI at head ok 20 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 9dd8b87b
Conflicts ok none
PR text ok Risk: two-way · Macs using runtime display power-down or S2R DART transitions (T8020, T8140, T8142, T6041, and T8132 v27).

Areas: area:display, area:gpu, area:platform
Merge: gh pr merge 3307 --merge (Owners and Core through the bypass: add --admin).

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

…king

Update the standalone C harness stubs in apple-dart-range-tests.py,
dart-sleep-writer-tests.py, and bcm4377-radio-sids.py for the
managed_lock, display_writers, and display_dark_writers fields used by
apple_dart_domain_flush_tlb_range().

Signed-off-by: Erik Bourget <[email protected]>
…ay-dark-drain

# Conflicts:
#	drivers/gpu/drm/apple/dcp.c
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) labels Nov 27, 2026
@sithglan

Copy link
Copy Markdown
Contributor

Hardware verification row on J813 (M5 MacBook Air 13-inch, T8142, appledrm.s2r_untested=1), verified via stacked #3308 head 944b0ba788d2 (carrying #3307 9dd8b87b003c as an ancestor): PASS.

  • Exercised display and DCP DART dark-drain across post-boot external DCP (506e00000.dcp, 3aae00000.dcp) idle power-off, two full deep sleep/wake cycles (t8142_wake_s=8, SUSPEND_RC=0, boot object resumes 0 -> 1 -> 2), and post-resume idle re-gating.
  • 0 DART/IOMMU faults, 0 new kernel warnings/errors, 0 failed systemd units; internal panel eDP-1 (2560x1600), apple_sep, and Wi-Fi recovered cleanly across both cycles.

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

Review at 9dd8b87b003c: approve, 0 blockers. Rows on a second generation are still owed before merge (see below).

  • TLB flush writers:
    • display_dark is set and the display_writers / display_dark_writers counts are taken under the same managed_lock. So every flush is either counted, and drained by apple_dart_display_dark_enter(), or takes the memory-only dark path and marks the TLB stale.
    • Every exit from the lit path drops display_writers: the gate path, the runtime-PM failure and the normal end. The only early continue comes before the count.
  • Dark exit: apple_dart_display_dark_exit() clears display_dark only once there are no dark writers and no stale flag. It invalidates and loops when a dark writer raced in, so a memory-only write is always followed by an invalidation before the streams come back. Streams are re-enabled only after it succeeds:
    • T8020 disables the target streams right after apple_dart_hw_reset();
    • T8110 enables only after a successful dark exit.
  • Other readers:
    • apple_dart_irq() checks display_dark before and after pm_runtime_resume_and_get(), and synchronize_irq() waits out a handler already past the check.
    • The dart->lock round trip waits out a map path reading DART_TCR.
  • Error propagation (dcp.c):
    • apple_dart_power_dark() / apple_dart_display_streams() failures now abort before the domains go down, since s2r_domains_up only drops after a successful dark.
    • They also stop firmware start after a failed reopen.
    • D572's DART result is serialized with s2r_active under s2r_dart_lock and checked by every waiter.
  • Checks:
    • checkpatch.pl --strict 0/0/0 on both commits. They are signed off, with no attribution, and the branch merges cleanly onto current main.
    • CI: 21/21 checks pass.
  • Behaviour change to note: dcp_t6041_stop_one() no longer skips an ext_dead external pipe. On its first sleep that pipe now has its RUN bit cleared and its DART streams stopped while its domains are still up (the stop step runs before the power words), and t6041_ext_seen keeps it skipped afterwards. That reads as safe, but the PR text doesn't mention it, and the T6041 sleep path has no row.
  • Not blocking: apple_dart_irq() returns IRQ_NONE while dark. A level-triggered fault that is already pending at dark entry could count as unhandled on a shared line. The window is short, but worth keeping in mind if "nobody cared" ever shows up.
  • Hardware: sithglan's J813 (T8142) row ran #3308's head 944b0ba788d2, which has this head as an ancestor: idle power-off plus two deep sleep cycles, 0 DART faults. The J713 run in the body is a combined trial build at eab8b5157340.
  • Owed before merge:
    • A row at this head on a second generation (T8132 or a T8020-DART M1/M2), since this is shared DART code.
    • A T6041 sleep row for the dcp_t6041_stop_one() change.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 27, 2026
@RyanTheTide
RyanTheTide merged commit f8fa6d8 into main Nov 27, 2026
22 checks passed
@RyanTheTide
RyanTheTide deleted the feat/apple-dart-display-dark-drain branch November 27, 2026 13:21
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) area:platform Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants