Skip to content

drm: apple: t8132: a cursor plane on external outputs (KWin on the M4 mini's HDMI) - #2296

Open
DjDeveloperr wants to merge 3 commits into
mainfrom
djdev/t8132-ext-cursor-plane
Open

DjDeveloperr wants to merge 3 commits into
mainfrom
djdev/t8132-ext-cursor-plane

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The T8132 (M4) external outputs (t8132_ext_drm.c: the J713's USB-C displays, and the J773g Mac mini's HDMI with #1192) offer only a primary plane. KWin 6.8 then puts its cursor on that plane and every modeset fails with EINVAL (Plane must cover entire CRTC), so the desktop never lights the output unless KWIN_FORCE_SW_CURSOR=1 is set. This series adds a cursor plane and stops frames from being dropped while swaps are in flight.

Commits

  1. iommu: apple-dart: room for more external display host windows. The SID0 arena goes from 10 to 16 slices (6 to 12 host windows). With a cursor plane, KWin's frame buffers plus its cursor buffers ran the 6 windows out.
  2. drm: apple: t8132: a cursor plane on external outputs.
    • The plane is presented as the swap's upper surface 1, the way the swap record already describes upper surfaces (dcp_m4_upper): ARGB8888, pre-multiplied, surface ID 2.
    • The atomic check accepts only what the DCP takes as an upper surface: unscaled, 32x32 to 256x256 on screen, from the buffer's first byte.
      • A cursor partly off the right or bottom edge is shown as its on-screen part.
      • One off the top or left edge, or with under 32 px left on screen, is refused, so the compositor draws it itself.
    • Every swap carries the cursor with the frame, copied frames included.
    • The cursor framebuffer gets a SID0 window of its own. It is tracked like the frame's window, so a window is never unmapped while a swap may still show it.
  3. drm: apple: t8132: let a frame wait for the swaps in flight.
    • When both direct slots were in flight, a direct frame got -EBUSY and was dropped. The same happened to a copied frame while any direct swap was in flight.
    • On the J773g this showed as frame not shown: -16 after every 120 Hz modeset.
    • Frames now wait, at most 1 s, with the session lock dropped.

Testing

On a J773g (Mac mini M4) with a G81SF on HDMI, kernel 7.3.0 = this series + #1192 + #2166 on the M4 mini GPU stack:

  • Atomic test client, 1920x1080 at 60 and 120 Hz:
    • Accepted and committed: a 64x64 cursor with the modeset, mid screen, in the bottom-right corner, with 40 px visible at the right/bottom edges, and a 32x32 crop.
    • Refused at TEST_ONLY: 20 px visible at the right, off the left or top edge, and a 16x16 crop.
    • 240 cursor-only commits in a row, 0 failed (16.6 ms each at 60 Hz). The firmware took every upper-surface swap; no swap errors.
  • KWin 6.8:
    • It lights HDMI with its cursor on the cursor plane, which follows a uinput pointer.
    • It still logs a few Modeset failed: Invalid argument at start: its own trial of the cursor on the primary plane, before it settles. Harmless.
  • Dropped frames: no frame not shown in boots or across five suspend-to-idle cycles. The only cursor misses are ~0.3 s while KWin starts, when every window is busy.
  • Host tests: tools/asahi/run-host-tests.py --only apple-dcp (m4-wire-golden included) gives the same 15 failures on this branch as on integration/aurora 0abc2f3. All 15 are new-clang -Werror warnings in other units.

The J713 external path is the same code; it is untested there.

An external display DART's SID0 arena holds the two retained copy surfaces
(four slices) and the host windows of directly scanned-out framebuffers, one
32 MiB slice each. Ten slices leave six windows. A compositor that also
puts its cursor on a plane of its own (the next commit) uses three windows
for its frames and up to three for its cursor buffers, besides the
console's, and the windows ran out: the frame fell back to the copy path and
the cursor was not shown.

Take sixteen slices, which leaves twelve windows. The arena is fixed at
admission from the slices nothing else uses; generic DMA keeps the rest of
the 2048.

Signed-off-by: Diljit Singh <[email protected]>
The T8132 external outputs (the J713's USB-C displays, and the J773g Mac
mini's HDMI with the main DCP) offered one plane, the primary. KWin 6.8 then
puts its cursor on that plane and every modeset fails with EINVAL ("Plane
must cover entire CRTC", a 64x64 buffer as a 32x32 destination), so the
desktop never lights the output unless KWIN_FORCE_SW_CURSOR=1 is set.

Add a cursor plane to each output and present it as the swap's upper surface
1, the way the swap record already describes upper surfaces:
- ARGB8888, linear, pre-multiplied (is_premultiplied set), zpos 1, under
  surface ID 2;
- the check takes what the DCP takes as an upper surface: unscaled, 32x32 to
  256x256 on screen, from the buffer's first byte, the pitch a multiple of
  64 bytes. A cursor partly off the right or bottom edge is shown as its
  on-screen part; one off the top or left edge, or with less than 32 pixels
  left on screen, is refused, so that the compositor draws it itself;
- every swap carries the cursor with the frame, the copied frames included:
  a commit of the cursor alone presents the frame on screen again with it;
- the cursor's framebuffer is mapped in a SID0 window of its own, tracked
  as the frame's is (the swap going out, the swaps in flight, given-up
  swaps, what a confirmed swap put on screen), so that a window is never
  unmapped while a swap may still show it. Twelve windows instead of eight.

Tested on a J773g (Mac mini M4) with a G81SF monitor on HDMI at 1920x1080,
60 and 120 Hz (kernel 7.3.0 with #1192):
- a raw atomic client: a 64x64 cursor with the modeset, then mid screen, in
  the bottom-right corner, 40 px visible at the right and bottom edges and a
  32x32 crop are accepted and committed; 20 px visible at the right, off the
  left or top edge, and a 16x16 crop are refused; 240 cursor-only commits in
  a row, none failed (16.6 ms each at 60 Hz);
- KWin 6.8 drives the output with the cursor on the cursor plane, which
  follows a uinput pointer; no swap errors.

Signed-off-by: Diljit Singh <[email protected]>
With both slots for direct swaps in flight, iomfb_m4_ext_present_direct()
returned -EBUSY and the frame was dropped; and a frame that fell back to the
copy path while a direct swap was in flight was refused with -EBUSY too.
On the J773g Mac mini this showed as "frame not shown: -16", about ten in
a row after every 120 Hz modeset (fbcon, then KWin) while the display took
its first frames, and more whenever the host windows ran out. A dropped
frame's flip event is still sent, so a compositor that then goes idle leaves
the screen on the frame before.

Let the frame wait instead, with the session lock dropped: a direct one for
the oldest swap in flight to complete or be given up, a copied one for all
of them, 1 s at most each, then go out (-EBUSY only after that).

Tested on a J773g with KWin at 1920x1080@120 over HDMI: no "frame not
shown" in the boot or across three suspend-to-idle cycles (with the
previous commits).

Signed-off-by: Diljit Singh <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

No blockers.

Checked at the head: the cursor's SID0 window is tracked everywhere the frame's is. That covers ext_swap_cwin for the swap going out, ext_q[].cwin for swaps in flight, ext_lost_swap[].cwin for given-up swaps, the on_screen updates in dcp_m4_ext_shown()/dcp_m4_ext_late_d590(), and the resets in dcp_m4_ext_retired(). dcp_m4_ext_win_idle() refuses a window any of these still names, so a cursor buffer is never unmapped while a swap may show it. Both new waits (dcp_m4_ext_drain_direct() and the goto again loop in iomfb_m4_ext_present_direct()) drop the session lock, re-read dcp->runtime or recheck hold/orphan/sleep/error and the DART gate after relocking, and are bounded. The err_cursor unwind in t8132_ext_out_init() is in the right order. The commits are signed off and have no Co-Authored-By or Assisted-by trailers.

  1. Suggestion: drivers/gpu/drm/apple/t8132_ext_drm.c:186 refuses a cursor with under 32 px left on screen at the right or bottom edge. KWin falls back to a software cursor on a TEST_ONLY failure, but a legacy DRM_IOCTL_MODE_CURSOR/drmModeMoveCursor client (Xorg modesetting without atomic) gets EINVAL on each move near those edges. The present side already handles such a cursor: dcp_m4_ext_cursor() (iomfb_m4.c:4965) drops a cursor that dcp_m4_upper_check_on() rejects and still shows the frame. Accepting that case in the check and letting the present path drop the sliver would keep legacy clients working, with only the minimum-size check left as a firmware constraint.

The PR body ends with the "Generated with Claude Code" line rather than an Assisted-by: LLM (...) line.

HW row: an M4 MacBook Air (J713) with a USB-C display on the same kernel and default command line: KWin lights the output with the cursor on the cursor plane, 240 cursor-only commits 0 failed, no frame not shown across 3 s2idle cycles; and for both Macs the regression summary (0 AVC denials, 0 failed units, 0 new kernel errors).

Assisted-by: LLM (Claude:Opus 5.5)

@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026

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

Verdict at 7fcae884f422

Request changes. The cursor plane, SID0 window lifecycle tracking, and iomfb_m4_ext_present_direct() wait loop are solid, but iomfb_m4_ext_present() drops dcp->lock in dcp_m4_ext_drain_direct() without re-validating dcp->runtime, link/timing state, or ext_mode_stale after reacquiring the lock.

Blockers

  1. Missing post-unlock state re-validation in iomfb_m4_ext_present() (drivers/gpu/drm/apple/iomfb_m4.c:4448-4458):
    • dcp_m4_ext_drain_direct(dcp, r) unlocks dcp->lock while waiting on dcp->ext_settle_wq (iomfb_m4.c:4180-4183).
    • Upon returning 0, iomfb_m4_ext_present() only re-checks dcp_m4_ext_scanout_gate(dcp) (DART state) and ext_hold_id / ext_orphan_start / ext_sleeping / dcp->error. It does not re-read r = dcp->runtime and does not re-check !r || !smp_load_acquire(&r->done) || !r->ext_connected || !READ_ONCE(r->ext_cur_timing) || r->ext_mode_stale || r->ext_buf_pending.
    • Concrete race on sink disconnect (D575(0)): While dcp->lock is dropped in dcp_m4_ext_drain_direct(), D575(0) (iomfb_m4.c:1811-1821) clears r->ext_connected = false and r->ext_cur_timing = 0 and schedules ext_async_work to give up inflight direct swaps with -ENOLINK. Because dcp_m4_ext_swap_give_up() (iomfb_m4.c:2137) only sets r->ext_hold_id on -ETIMEDOUT (not -ENOLINK) and D575(0) does not set ext_dart_down (D572(0) arrives separately), ext_orphan_start, ext_sleeping, or dcp->error, dcp_m4_ext_drain_direct() returns 0, dcp_m4_ext_scanout_gate() can still return 0, and iomfb_m4_ext_present() proceeds to copy the frame and submit dcp_m4_runtime_swap_full() onto a disconnected, unpowered link with ext_cur_timing == 0 (violating its documented contract at iomfb_m4.c:4395-4396). Similarly, if r->ext_mode_stale or r->ext_buf_pending transitions while the lock is dropped, those guards are bypassed.
    • Suggested fix: Mirror iomfb_m4_ext_present_direct() (iomfb_m4.c:5016-5045) in this same commit by looping back to an again: label after dcp_m4_ext_drain_direct() (bounded by the existing 1 s deadline) so r = dcp->runtime, r->done, ext_connected, ext_cur_timing, ext_buf_pending, ext_mode_stale, dcp_m4_ext_scanout_gate(), and hold/orphan/sleep/error are all re-checked consistently.

Checked

  • 5 changed files (drivers/iommu/apple-dart-dcp.h, drivers/gpu/drm/apple/dcp-m4-frame.h, drivers/gpu/drm/apple/iomfb_m4.h, drivers/gpu/drm/apple/iomfb_m4.c, drivers/gpu/drm/apple/t8132_ext_drm.c) across all 3 commits audited in full.
  • Verified sound:
    • DCP_DART_DISPEXT_SLOTS increase (10 -> 16) leaves 12 host windows alongside 4 copy-surface slices.
    • Cursor SID0 window tracking (ext_swap_cwin, ext_q[].cwin, ext_lost_swap[].cwin, on_screen updates in dcp_m4_ext_shown() / dcp_m4_ext_late_d590(), resets in dcp_m4_ext_retired(), and dcp_m4_ext_win_idle() refusal) prevents unmapping any cursor buffer while a swap can still show it.
    • iomfb_m4_ext_present_direct() properly uses goto again; after dropping dcp->lock to re-validate dcp->runtime and all link/mode/error invariants.
    • t8132_ext_out_init() err_cursor unwind order is correct.
  • CI & trailers: host-tests SUCCESS, MERGEABLE, all 3 commits have clean Signed-off-by: with zero AI trailers.
  • Non-blocking note: PR description footer (Generated with Claude Code) and missing J713 USB-C hardware row were already flagged earlier.
  • Untested scope: Static code audit only (userspace-only review environment; no kernel build or boot performed here).
Evidence
  • Traced iomfb_m4_ext_present() (iomfb_m4.c:4398-4566), dcp_m4_ext_drain_direct() (iomfb_m4.c:4170-4186), iomfb_m4_ext_present_direct() (iomfb_m4.c:5001-5046), D575 (iomfb_m4.c:1800-1825), and dcp_m4_ext_swap_give_up() (iomfb_m4.c:2108-2147) at 7fcae884f422.
  • CI at head 7fcae884f422: host-tests SUCCESS.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at 7fcae884: not ready yet

Check Detail
CI at head ok 1 check passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by satchlj
Hardware row at head no no line with the head SHA 7fcae884, a Mac and a result in the PR body or a comment
Conflicts no merge conflicts with main: merge it in (no force push)
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:display

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

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Nov 29, 2026
@satchlj

satchlj commented Nov 30, 2026

Copy link
Copy Markdown
Member

Verdict: FINISH, then merge at 7fcae884f422. Re-checked against the current merge bar (better than before, and nothing that worked breaks).

Blocker:

  1. drivers/gpu/drm/apple/iomfb_m4.c:4448-4458, iomfb_m4_ext_present(): dcp_m4_ext_drain_direct() drops dcp->lock, and after it returns 0 only the DART gate and hold/orphan/sleep/error are checked again, not ext_connected, ext_cur_timing, ext_mode_stale or ext_buf_pending. An unplug (D575(0)) while the lock is dropped clears ext_connected and ext_cur_timing, and the frame is then swapped onto the disconnected link. The base has no unlocked wait here; this PR's last commit adds it. Fix: go back to the top checks after the drain, as iomfb_m4_ext_present_direct() does with again:.

Dropped: the conflict with main (a merge-up for maintainers), the PR-body footer and the row request. Nothing else is open from me.

This branch has not been deployed

No deployments
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) changes-requested A reviewer requested changes (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants