Skip to content

iommu/apple-dart: preserve translations across a firmware 27 DCP cycle - #3807

Merged
RyanTheTide merged 5 commits into
mainfrom
feat/apple-dart-v27-invalid-streams
Dec 2, 2026
Merged

RyanTheTide merged 5 commits into
mainfrom
feat/apple-dart-v27-invalid-streams

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What: Add a firmware-27 display DART power-cycle interface. Gate commands before power-off, verify retained translation registers on power-up, restore the saved stream enables, and keep the DART quiesced if its state was lost. Disabled streams with invalid translation tables may change without becoming active.

Tested: Strict checkpatch and whitespace checks passed. All 24 DART host runs passed, and Clang AArch64 built apple-dart.o.

J516s, integrated kernel af2647f710fd, direct-t357h-02: the internal firmware-27.2 DCP restarted and modeset to 3456×2160 at 120 Hz after both same-boot wakes. Neither wake window added a priority 0–3 kernel record. The second wake failed the RTC latch check.

J516s completed two consecutive deep-sleep cycles on the hardware-tested runtime, with display and PCIe DART restored after both wakes, zero DART faults and clean stock handback. That receipt also covers ed67b5f6dbec, which changed only the KUnit fixture. The subsequent runtime change updates the release sequence.

J714s/T6050 passed the shared-driver check on combined candidate 730f0cadeb6d, which contains ed67b5f6dbec unchanged. Internal eDP stayed active at 3024×1964 and 120 Hz across RTC wake and the separate #3846 PCIe re-entry abort. Display/DCP mappings stayed unchanged, with zero new DART faults and verified stock handback. DART revision 0x0204 excludes the new cycle entry points on this Mac.

Risk: Two-way door. The interface adds no caller. The companion T6030 display series enables it for the internal display DARTs.

Current-head CI: Apple build, host tests, PR text and Asahi KUnit passed.

Not yet: J516s target and J714s shared-driver hardware retests after the release-sequence change, and GitHub maintainer approval. The independent code review found both earlier blockers resolved. Earlier J714s receipt

Gate commands and save the internal display DART streams before
the DCP powers down. Check retained translation registers before
re-enabling streams on wake. Leave unused, invalid streams off
and refuse to resume a DART with lost live mappings.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr marked this pull request as ready for review December 1, 2026 17:03
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 1, 2026 17:03
@github-actions github-actions Bot added blast:m3 Macs affected, from Merge risk (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 Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 01bbc1d1: not ready yet

Check Detail
CI at head ok 11 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at 01bbc1d1
Conflicts ok none
PR text ok Risk: two-way · . The interface adds no caller. The companion T6030 display series enables it for the internal display DARTs. Current-head CI: Apple build, host tests, PR text and Asahi KUnit passed.

Areas: area:platform

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (T6030, M3 Pro) hardware qualification PASS for exact head 91388df2aa9774602453bc213ece02fd61c7e90e (qualified unchanged inside the integrated #3818 T6030 S2R candidate e9ce12c1c2381a20e24ea1ed3ebf19a02ae7f24f, run pr3818-qual-03, 7.3.0-t6030s2r #64, boot=e8c203da-da14-410c-9946-25636a7b8481):

  • 2 consecutive same-boot zero-flag production deep-sleep cycles: resumes 0 -> 1 -> 2 (90.06s + 59.31s, NUB.SPMI0.SW3, MBSE 0x10650, 0 suspend/resume priority 0–3 kernel errors, all 5 PMU scratch regions byte-identical to stock boot).
  • Scoped verification: Apple DART v27 invalid-streams / display DART save-restore (28ec00000.dcp DARTs cleanly torn down and restored on both cycles, 0 ON and 0 AUTO words failed readback).
  • Clean stock handback: verified back on stock 7.3.0 (boot=428632eb-f34e-427f-8014-cd7167d9cea1, both ESPs efab68fa..., empty grubenv, 0 failed units). Non-T6030 shared-driver peer hardware rows remain tracked separately before merge.

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

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FINISH, then merge at 91388df2aa97

  1. drivers/iommu/apple-dart-v27-late.inc:626 discards the result of apple_dart_power_dark(dev, true). It returns -EBUSY when display writers fail to drain and can undo the dark state. The caller can still return a successful cycle handle and allow power-off. Free the new handle and return the error before gating commands or taking the snapshot.

  2. At line 634 the idle-error rollback opens the DART before flushing it. If that flush times out, the function frees the handle with commands available and the stale flag cleared. Preserve a dark, gated state on flush failure as the wake error path does. Exercise both failures along with the shared DART peer check.

Checks and evidence

I traced the existing dark-entry helper and both release paths. J516s exercised the display consumer across two successful power cycles. Apple build, host and DART-related KUnit checks passed.

Check apple_dart_power_dark() in apple_dart_v27_cycle_off() before gating
commands and abort cleanly on failure. In apple_dart_v27_cycle_release(),
when the post-lit TLB flush fails (on either cycle_off() idle-error
rollback or cycle_on()), restore display_tlb_stale, re-enter dark mode,
and re-gate commands instead of leaving the DART live with an un-flushed
TLB.

Add KUnit coverage (apple_dart_test_v27_cycle_errors) for failed dark-mode
entry and failed TLB flush on both rollback and cycle_on().

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Addressed review findings in 83b22f496497:

  • Checked apple_dart_power_dark() in apple_dart_v27_cycle_off() and aborted cleanly before gating commands on error.
  • Hardened apple_dart_v27_cycle_release() so a failed post-lit TLB flush (on both cycle_off() rollback and cycle_on()) restores display_tlb_stale, re-enters dark mode, and re-gates commands.
  • Added KUnit test apple_dart_test_v27_cycle_errors covering dark-entry failure and TLB flush timeout on both rollback and cycle_on().

@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) labels Dec 1, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s hardware verification for exact head 83b22f4964975ea39dffdc870de115a9e12779b3:

  • Verified in merged T6030 S2R candidate (098d2b244e078adb3b5b9c23f220ef84fb76ab0a, boot f713a241-9f3e-4536-bd6d-c27ec12643b1): all DARTs including V27 display DARTs cycled cleanly across 2 physical deep-sleep cycles (1×30s + 1×20s, suspend_stats: success=2, fail=0), with zero DART errors and full internal display + camera + GPU restoration after wake.
  • Stock 7.3.0 restored (boot_id=5c2faf10-ca29-4e2e-8b48-0b040cc2a613).

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro, T6030) hardware row at 83b22f496497: PASS.

  • Scoped check: v27 display DARTs preserved translations across both cycles (apple-dcp eDP-1 3456x2234 link: 1, set_digital_out_mode finished:2125, backlight enabled) and PCIe DARTs (594000000.iommu, 595000000.iommu) restored cleanly after both wakes with 0 DART faults/errors.
  • Verified unchanged inside integrated #3818 candidate 098d2b244e07 (7.3.0-t6030s2r #73, Image SHA-256 d3cc6ddf5e88..., boot 9d3fa896-3c56-4ac3-b39c-62d014311536, zero-flag production cmdline, real installed aurora-sep 1-32 + aurora-sep-host-state 1-2 with zero unit drop-ins): 2 consecutive physical deep-sleep cycles (30.80s + 46.87s, boot object resumes 0 -> 1 -> 2, MBSE 0x10650, NUB.SPMI0.SW3, suspend_stats: success=2 fail=0, 0 new priority 0-3 kernel errors, 0 failed systemd units, eDP-1 3456x2234 link: 1). Clean stock 7.3.0 handback verified on boot 8683f1b3-46f2-46a5-9052-eb8f921dc7c0 (both ESPs stock efab68fa..., empty grubenv, aurora-sep 1-25 0 altered files, mesa-aurora 0 altered files, 0 failed units).

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 2, 2026
Limit the temporary driver override to the cycle-off call. An assertion can abort the test before the final cleanup, leaving the driver core to unbind a KUnit device with the platform driver still installed in its driver pointer. Save and restore the prior driver under the device lock.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Head ed67b5f6dbec changes only the KUnit fixture. It restores the original driver pointer before assertions or device teardown. Production source and the hardware image are unchanged from 83b22f496497, so the two-cycle J516s display and PCIe DART receipt still applies. Strict checkpatch passed. Current-head build and review are pending.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hold at ed67b5f6dbec. Two release paths can leave a stale DART translation.

  1. In apple_dart_v27_cycle_release(), the final flush can complete while a dark writer is still publishing the locked root. The writer records display_tlb_stale before publishing, then returns without invalidating. Release clears that flag and opens the DART without draining display_dark_writers. Use the existing dark-exit protocol to drain writers and flush before reopening. Release · Writer
  2. If cycle-off times out because TLB_CMD_BUSY stays set, rollback calls that same flush and writes FLUSH_ALL before checking whether the command port can accept it. Wait for idle before issuing the command and keep the DART gated if it times out. Cover the in-flight writer and busy rollback in the DART tests. Flush · Rollback

J516s passed two target cycles on the unchanged runtime. J714s/T6050 passed the shared-driver control on combined candidate 730f0cadeb6d, which contains this exact head. The internal panel stayed at 3024×1964 at 120 Hz through RTC wake and the later PCIe re-entry abort tracked in #3846. Display/DCP mappings stayed unchanged, with zero new DART faults and verified stock handback. J714s uses DART revision 0x0204, outside the new cycle path. J516s receipt

Match apple_dart_display_dark_exit() in apple_dart_v27_cycle_release():
mark display_tlb_stale, drain in-flight display_dark_writers under
managed_lock, and complete the post-lit TLB flush before clearing
commands_gated and display_dark. If writers fail to drain or the flush
fails, keep the DART dark, gated, and marked stale.

In apple_dart_v27_cycle_flush() and the pre-stream flush in
apple_dart_v27_cycle_on(), wait for DART_T8110_TLB_CMD_BUSY to clear
before writing FLUSH_ALL so a busy rollback does not clobber an active
TLB command.

Extend apple_dart_test_v27_cycle_errors() to cover busy-command rollback
preservation, in-flight dark-writer draining before the final flush, and
stuck dark-writer -EBUSY rollback.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Addressed both review blockers from #3807 (review) in d9aa641cab45:

  • apple_dart_v27_cycle_release() now marks display_tlb_stale = true, drains in-flight display_dark_writers under managed_lock, and completes apple_dart_v27_cycle_flush() before clearing commands_gated (under d->lock) and display_dark; writer-drain timeout (-EBUSY) or flush failure leaves the DART dark, gated, and marked stale.
  • apple_dart_v27_cycle_flush() and the pre-stream flush in apple_dart_v27_cycle_on() now wait for DART_T8110_TLB_CMD_BUSY to clear before writing FLUSH_ALL, leaving a busy command register untouched on rollback.
  • Extended apple_dart_test_v27_cycle_errors() to cover busy-command rollback preservation, in-flight dark-writer draining before the final flush, and stuck dark-writer -EBUSY rollback.

Local checks at d9aa641cab45: strict checkpatch.pl 0 errors / 0 warnings / 0 checks; GCC W=1 (with and without CONFIG_APPLE_DART_KUNIT_TEST) and Clang AArch64 drivers/iommu/apple-dart.o builds clean; host DART test suites pass. CI and exact-head J516s re-verification next.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hold at d9aa641cab45. Both command writes now wait for idle. The writer drain also handles ordinary completion, a writer arriving during the flush, and a stuck writer. One boundary case still leaves the display DART gated after a successful wake flush.

I ran the exact apple_dart_v27_cycle_release() in a native host harness with controlled writer completion and a stubbed flush. When the writer finished during the 9,999th sleep, the final pass saw zero writers and flushed successfully. Its continue exhausted the loop before it could reopen the DART. The result was -EBUSY, one successful flush, zero writers, stale clear, and both gates still set. cycle_on() then frees the handle. After a successful flush, recheck writers and stale state under managed_lock before applying the retry limit. Cover the final-pass success and preserve the stuck-writer timeout. Release loop

The new KUnit fixture also initializes stack-resident delayed work as ordinary work. That triggers the debug-objects stack warning when work or timer debugging is enabled. Allocate the writer context with kunit_kzalloc() before acquiring the cycle. Fixture

Recheck display_dark_writers and display_tlb_stale under managed_lock
immediately after a successful apple_dart_v27_cycle_flush() so a dark
writer finishing on the final sleep still completes release cleanly
instead of returning -EBUSY with display_tlb_stale cleared. On an actual
retry-budget timeout, re-mark display_tlb_stale = true before returning
-EBUSY.

Allocate apple_dart_test_dark_writer_ctx with kunit_kzalloc() before
entering the cycle instead of placing a delayed_work on the stack.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Folded both items from #3807 (review) in 01bbc1d13c30:

  • apple_dart_v27_cycle_release() now rechecks display_dark_writers and display_tlb_stale under managed_lock immediately after a successful apple_dart_v27_cycle_flush() so a dark writer finishing on the final sleep completes cleanly instead of returning -EBUSY; on an actual retry-budget timeout, display_tlb_stale is re-marked true before returning -EBUSY.
  • apple_dart_test_v27_cycle_errors() now allocates writer_ctx via kunit_kzalloc() before taking the cycle instead of placing delayed_work on the stack.

Strict checkpatch.pl (0/0/0) and GCC/Clang AArch64 apple-dart.o builds (with and without CONFIG_APPLE_DART_KUNIT_TEST) passed; CI running on 01bbc1d13c30 and exact-head J516s S2R verification follows.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No blocking code findings at 01bbc1d13c30. I reran the native host harness against the old and new release functions. The previous head returned -EBUSY when the writer finished on sleep 9,999. This head reopens the DART after one successful flush on sleeps 9,999 and 10,000. A mapping change during the flush triggered a second flush. A stuck writer, continuous changes through the retry limit, and a flush timeout all left the DART dark, gated and marked stale.

With simulated command registers, an already-busy port received zero writes. I also verified that the delayed-work fixture is allocated before the cycle starts and its work is flushed before teardown.

CI and fresh J516s target and J714s shared-driver receipts are still pending for this runtime.

@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 Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s / T6050 shared display-DART control passed at 8a1b64fffebbb5f0bc6456f12fc687f4e0bfa438, which carries exact PR head 01bbc1d13c30 unchanged on main fdad0c5804d8. The warm native 7.3.0-m5-pr3807-8a1b64ff build matched all six staged hashes, and the trial used the stock command line.

  • The physical RTC deep-sleep run slept 29.825 s and returned on the same boot ID 04a30599-79ce-4952-9e22-558a0fa519f6. Kernel S2R success and firmware resume counts both advanced from 0 to 1, with zero suspend failures.
  • The panel returned at 3024 × 1964 at 120 Hz. Pre-sleep and post-wake display snapshots matched. GPUBench RT readback CRC b541b83e matched across the trial and stock. Zero GPU, DART, IOMMU, or DCP faults.
  • J714s display DARTs are revision 0x0204 and keep the existing cycle path. The J516s row still covers the v27 cycle changes at this head.
  • Stock PR67 returned, all boot and Mesa hashes matched, and there were zero new failed units. The partner-checked M4 deadman was disarmed and the hardware lease released.

@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 01bbc1d

Checked:

  • Risk: the interface has no caller in this PR (only apple_dart_v27_cycle_off/on exports, a forward decl and a KUnit case), so nothing changes at runtime until the T6030 display series calls it. cycle_off() refuses every DART already held another way (dispext, managed SIDs, preserve_display, sleep_saved, borrowed, gated/dark, rev >= 2.2), so it can't stack on the existing holds.
  • Error paths: an idle-check failure in cycle_off() rolls back through cycle_release() and frees the cycle. A lost state, a busy TLB or a stream mismatch in cycle_on() leaves the DART dark and gated, then drops the device reference and frees the cycle. cycle_release() drains the dark writers, flushes under d->lock and re-checks before it clears display_dark and commands_gated. A failed drain or flush leaves the DART stale and gated.
  • Ran apple-dart KUnit at this head on the buildbox (arm64, 16K pages): apple_dart_test_v27_cycle_errors, display_keep, gated_commands, gated_irq and the dapf/consumer cases pass, 8/8. Negative control: with the dark-writer check in cycle_release() bypassed (if (!d->display_dark_writers) -> if (1)), v27_cycle_errors fails 5 expectations (flush ran before the writer published, stale left set, the undrained writer not refused), so the new case catches the drain regression.
  • Note, not this PR: the full apple-dart* suite stack-overflows at apple_dart_test_t8132_fw_mirror_selection (a 37 KB on-stack memset with 32 KB task stacks), and it does so on main 13c7f69 too. The 24 cases after it never run, and linux CI doesn't run the apple-dart suite at all. B1 is tracking that as a CI follow-up.

Follow-ups (non-blocking): cycle_on() flushes the TLB inline without d->lock. That's safe while commands are gated, but calling apple_dart_v27_cycle_flush() there would keep a single flush path. Re-run the J516s/J714s rows after the release-sequence change, as the PR body already plans, before the T6030 caller lands.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 01bbc1d13c30.

  • apple_dart_v27_cycle_off() / apple_dart_v27_cycle_on() gate strictly on DART hardware properties (T8110 layout, rev < 0x0202, and mutual exclusion with existing DART holds) and add no runtime caller yet.
  • Lock ordering in apple_dart_v27_cycle_release() (managed_lock -> d->lock, with usleep_range() and apple_dart_v27_cycle_flush() outside managed_lock) matches the existing apple-dart.c dark-exit protocol.
  • Dark-writer drain rechecks !display_dark_writers && !display_tlb_stale under managed_lock after each flush before enforcing the retry bound, and all drain/flush/retention error paths fail closed (leaving display_dark, commands_gated, and display_tlb_stale set).
  • apple_dart_test_v27_cycle_errors heap-allocates its delayed-work context and exercises dark-entry -EBUSY, busy-command-port rollback without touching TLB_CMD, in-flight writer drain ordering, stuck-writer refusal, and flush timeouts on both rollback and wake.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 01bbc1d13c30 (B2 merge train, 12-01 merge bar). Approval at this head: aurora-silicon-review[bot],satchlj. Row: J516s (2 deep-sleep cycles, fw27 DCP restart) + J714s/T6050 shared-driver rows at ed67b5f; head adds only the v27 cycle release drain + KUnit, and the exported cycle API has no caller on main or in this PR (git grep), so no runtime path changes until the T6030 display series. CI: apple-build, host-tests, KUnit (dcp-topology jpeg asahi) green at 01bbc1d; merges cleanly onto main 18edb08. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit a2cc412 into main Dec 2, 2026
10 of 17 checks passed
@RyanTheTide
RyanTheTide deleted the feat/apple-dart-v27-invalid-streams branch December 2, 2026 07:08
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Post-merge check of the landed merge a2cc412a8c69 (main 18edb08ad329 + head 01bbc1d13c30). I built the same merge locally and its tree matches (5db5fbab).

  • Build (x86_64 host, clang 23 arm64 cross, CI config: defconfig + asahi.config): drivers/iommu/ drivers/gpu/drm/apple/ drivers/soc/apple/ drivers/thunderbolt/ built with exit 0. make W=1 drivers/iommu/apple-dart.o has 0 warnings, with and without CONFIG_APPLE_DART_KUNIT_TEST.
  • Hosted Apple build and KUnit (run 46830762608) on that tree plus one CI-only commit (d4e04f50: an apple-dart kunitconfig and two filtered suites):
    • apple-build: pass.
    • dcp-topology: 235 passed, 1 skipped.
    • jpeg + apple-dart-firmware-leaf: 15/15.
    • asahi: 540 passed, 4 skipped.
    • apple_dart_test_v27_cycle_errors: passed alone (1/1) and in a 34-case apple-dart run (34/34).

The 34-case run left out t8132_fw_mirror_selection and the other cases starting with t (topology and the three tunnel cases). Main overflowed the stack in that case before 66cbc2dce245.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area from CODEOWNERS (bot) blast:m3 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants