Skip to content

drm/apple: turn framebuffer damage into a commit - #2319

Closed
RyanTheTide wants to merge 1 commit into
integration/aurorafrom
isw/fbdev-damage
Closed

RyanTheTide wants to merge 1 commit into
integration/aurorafrom
isw/fbdev-damage

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1185

Problem

On the J713 internal panel, a console-only screen (a text greeter on tty1, a VT, a session that fell back to fbcon) freezes about a second after KMS takes over. idle_cache_ms (default 1000) has the DCP present a cached copy of the last frame once nothing has flipped, and leave it only at the next swap. fbcon draws straight into the scanout buffer and never causes a swap: appledrm's framebuffers are created with drm_gem_fb_create, which has no dirty hook, so drm_fbdev_dma sets up its unshadowed path and no damage is ever generated. The only ways back were a commit from somewhere else (fb0 blank/unblank) or appledrm.idle_cache_ms=0 on the command line.

Change

apple_mode_config_funcs.fb_create = drm_gem_fb_create_with_dirty (the dcpext shadow driver already uses it). With a dirty hook:

  • drm_fbdev_dma_driver_fbdev_probe() takes its shadowed, deferred-I/O path; each damage batch goes through drm_fbdev_dma_helper_fb_dirty() to drm_atomic_helper_dirtyfb(), a plane commit of the same framebuffer.
  • On M4 that commit reaches dcp_flush() -> iomfb_m4_present(), which leaves the idle cache (any swap does) and re-arms it through iomfb_m4_idle_cache_kick(). A console that stays static is still cached after idle_cache_ms; one that changes is shown.
  • Userspace DRM_IOCTL_MODE_DIRTYFB callers (front-buffer X, simple KMS clients) get the same behaviour instead of -ENOSYS.

It is not limited to M4 or to the idle cache: no DCP generation shows drawing it was not given a swap for, so the hook is the default for every board the driver binds. Compositors that flip do not call DIRTYFB and see no change.

Testing

  • Compile check on integration/aurora 0abc2f385e + this change: every touched file built for arm64 (gcc, kernel warning flags, -Werror) with no warnings. The full KUnit run is still to do.
  • Hardware: not booted yet. Needed rows: J713 with a text console idle for more than 2 s, then typing (the screen must update, with no appledrm.idle_cache_ms on the command line); and an fbcon regression row (boot console scrolls, VT switch, no DCP errors) on M1 Pro, M2 and M4 Pro. Draft until those are in.

Assisted-by: LLM (Claude:Opus 5.5)

DCP shows only what a swap hands it. A client that draws into the
scanout buffer without flipping is never seen once the firmware stops
refreshing from that buffer, and on the M4 internal panel it does stop:
after idle_cache_ms (1000 ms by default) without a flip, the DCP
presents a cached copy of the last frame until the next swap.

fbcon is such a client. The fbdev emulation only generates damage when
the framebuffer has a dirty hook, and appledrm's framebuffers had none
(drm_gem_fb_create), so the console wrote straight into the scanout
buffer and never caused a swap. On a J713 with a text greeter on tty1
the panel froze about a second after KMS took over, while input and
writes to /dev/tty1 kept working; blanking and unblanking fb0, which
does commit, brought it back. The same holds for any DIRTYFB caller.

Create framebuffers with drm_gem_fb_create_with_dirty, as the
dcpext shadow driver already does. drm_fbdev_dma then runs the
console through its shadowed, deferred-I/O path, and each damage batch
reaches drm_atomic_helper_dirtyfb(), a plane commit of the same
framebuffer. On M4 that is an ordinary iomfb_m4_present(), which also
leaves the idle cache and re-arms it, so a static console still gets
cached. The hook applies to every DCP generation: none of them shows
drawing it was not given a swap for, and compositors that flip are
unaffected because they do not call DIRTYFB.

This removes the need for appledrm.idle_cache_ms=0 on console-only
systems.

Fixes: a150a02 ("drm/apple: m4: Cache a static frame while nothing is flipping")
Closes: #1185
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kazuhidet

Copy link
Copy Markdown
Contributor

Hardware row for this change: J715 (MacBook Air 15-inch, M4, 2025), internal panel, firmware 26.6.2.

The change tested is the same code change as this PR, the fb_create line without the comment block, on integration/aurora 0abc2f3. With it, fbcon on the internal panel updates live. Without it, the console stays on the idle-cached frame.

Machine and build

  • Mac: J715 (apple,j715, apple,t8132), Mac16,13
  • Firmware: asahi,os-fw-version 26.6.2, asahi,system-fw-version 27.2
  • Distribution: Omarchy (Arch Linux ARM base), Hyprland session through sddm
  • Kernel: 7.3.0-j715-aurora+, built from integration/aurora 0abc2f3 plus local J715 bring-up patches: the AIC T8132 EL2 fix, an efifb earlycon and a g16 J715 GFX entry. None of them touch drm/apple.
  • appledrm built as a module, rebuilt with only this change. Command line has no appledrm.idle_cache_ms and no power_gate_ms, so both are at their defaults (1000 and 0).

Results

Test Result
VT text console idle for well over 2 s, then typing at a getty login prompt pass: the screen follows every key
Without this change (stock drm_gem_fb_create), a VT console fail, seen earlier on this machine: the console looks frozen and keys barely show, as in #1185
40 lines written 0.1 s apart to a VT pass
3000-line flood to a VT, full-screen scrolling pass
VT switch from the Hyprland session to a VT and back pass, several times; the compositor keeps working after the switch back
Hyprland session, normal desktop use pass, no visible change
fbcon regression on M1 Pro / M2 / M4 Pro not tested (no such machine here)
Front-buffer X / other DIRTYFB callers not tested

Swap timing on the console

To check that the dirty path does not stall the console, a debug build of the same change added timing to dcp_m4_runtime_swap_full(), iomfb_m4_present() and apple_atomic_commit(). Those logs are not part of the change. The kernel was built without ftrace.

Over 92 + 99 + 226 swaps (write, flood and typing runs):

  • Every console swap re-presents the same DVA.
  • A406 and A407 take about 0.1 ms each.
  • The D590 wait has a median of 10–13 ms and a maximum of 18 ms, so a swap completes within one 60 Hz frame.
  • There are no dcp->lock waits, no flip_done waits and no swap errors.
  • A key press reaches its swap within 16 ms at most.
  • During the 3000-line flood, swaps kept a 60 fps cadence.
  • When the console is idle, cursor blinks still give one swap about every 200 ms, so idle_cache_ms does not engage while the cursor blinks.

No apple-dcp warnings or errors appeared in the kernel log during any of the runs.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 1.

  1. Commit 364fe94 carries Assisted-by: LLM and Co-Authored-By: Claude Opus 5.5 <[email protected]>. Please re-commit with only the human Signed-off-by. The PR body's last line already credits the help.

The change is sound. drivers/gpu/drm/apple/apple_drv.c:793 gives every appledrm framebuffer a dirty hook, so drm_fbdev_dma moves to its shadowed deferred-I/O path and each damage batch becomes a same-framebuffer plane commit through drm_atomic_helper_dirtyfb(). The dcpext driver already uses the same helper (dcpext_drm.c:385). Compositors that flip never call DIRTYFB, so they see no change. The J715 row in the comments shows that the M4 case is fixed on this code with the default idle_cache_ms, and that the dirty swaps stay inside a frame.

The change moves fbcon onto a different path on every DCP generation: a vmalloc shadow of the full panel plus one commit per damage batch. M4 is the only generation that has been run. The PR body's own plan lists the other generations, and they are what this needs before it merges.

HW row: this head on the M1 Pro (J316s), M2 (J413) and M4 Pro (J616s), on the default command line. Pass: the boot console scrolls on the panel up to switch root, a VT switch from gdm to tty3 shows a live login prompt and typing echoes, switching back restores the session, there are no DCP swap errors or timeouts in the log, 0 AVC, 0 failed units and no new kernel errors. A J713 (M4 Air) run on this exact head would close #1185 on the board it was filed for.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Replaced by #2797: the same changes with the commit trailers fixed, on the current integration/aurora.The J715 row from this PR is linked from the new description.

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.

j713 (MacBook Air M4): appledrm idle cache freezes a console-only screen (fbcon never swaps)

2 participants