Skip to content

drm: apple: complete the H17P display driver for the MacBook Neo - #203

Merged
RyanTheTide merged 15 commits into
aurora-wipfrom
j700/dcp-complete
Oct 8, 2026
Merged

RyanTheTide merged 15 commits into
aurora-wipfrom
j700/dcp-complete

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This series completes the display driver for the MacBook Neo (J700, T8140, H17P display firmware) on top of aurora-wip. It builds on the DART fix already in aurora-wip (2bad3dba632f, "keep inherited firmware translations visible before attach"), which lets the internal display coprocessor bind.

What's included (15 commits)

  • Firmware callbacks and presents:
    • Runtime callbacks: H17P callbacks that only arrive after startup are now accepted within the bounds of what each handler reads and writes. Previously any of the 26 handled ones was treated as unqualified and stopped the display. The startup tuples measured on the device stay exact. The first time a bounded callback arrives with other lengths, the lengths seen are logged.
    • Aborted presents finish like rejected ones: the brightness reservation is retried, displaced framebuffers stay retained, and the page-flip event is signalled. A late completion for an aborted present is logged and ignored, not treated as a crash. The swap watchdog is settled and abort messages are rate-limited.
    • Register-mapping requests from the firmware are bounded, for all firmware generations:
      • a wrapping size is refused, and so is a zero size;
      • so is a full descriptor table, or a failed DMA mapping;
      • every refusal uses the existing all-zero reply, and other requests are answered as before.
  • Backlight:
    • Range: the full panel range is exposed (525 nits on J700). Powerlog hints are clamped to the ceiling; hints above twice the ceiling are rejected.
    • Registration without a powerlog report: the backlight is still registered, at a mid-range value that is only reported to userspace. The panel keeps the loader's level until userspace writes a level, or until the first DPMS or suspend cycle. Something has to relight the panel after one of those, and it uses the reported value.
    • Re-send requests: the firmware's request to re-send the level is honoured. It is never honoured before Linux knows the level the panel shows (the loader's report, or a completed present), and at most once a second.
    • Failed registration: if the class device cannot be registered, the brightness policy keeps driving presents instead of refusing every present.
  • Lifecycle:
    • System sleep: queued display updates, including a pending brightness retry, are drained before the coprocessor suspends. The fallback registration runs on a freezable workqueue.
    • Firmware crash: a pending page-flip event is signalled and the driver logs that a reboot is needed. This happens only once the pipeline has a CRTC. The H17G profile (T8142) keeps its existing crash handling.
  • Robustness: an enabled but unsupported T8140 external DCP is left out of the display subsystem, so it cannot hold back the internal panel.

Testing

  • Builds:

    • Every commit builds drivers/gpu/drm/apple/ with W=1, with no new warnings, including the KUnit objects.
    • KUnit on arm64 QEMU: 29 of 29 cases pass.
    • A full J700 kernel (Image, modules, DTBs) builds with this series merged into current aurora-wip.
  • Static checks:

    • checkpatch --strict reports only the Assisted-by format warning.
    • M1/M2 firmware: a per-function object comparison showed the 12.3 and 13.x IOMFB objects unchanged except for the register-mapping bounds. That comparison was run on the first nine commits; the follow-up commits only change H17P-gated code or add NULL and early-return guards.
  • KUnit on arm64 QEMU covers:

    • callback bounds;
    • the present abort and stale-completion state machine;
    • backlight takeover, DPMS, suspend, retries and re-send;
    • fallback registration, which never re-sends the default.
  • Hardware (J700) runs used a kernel combining this series, the DT hand-off series and aurora-wip, with the loader's display hand-off. The first nine commits had the full run below. The follow-up fixes had one re-verification boot of the series merged into current aurora-wip, which passed:

    • the DCP binds;
    • GNOME reports brightness control;
    • brightness 2–525 nits follows within 20 ms, with the rail monotonic and 9 µW at 0;
    • 20 of 20 DPMS cycles;
    • an orderly reboot hand-back to the previous kernel, with no shutdown fault.
    Area Result
    Bind The DCP binds. GNOME runs on eDP-1 at 2408×1506, 60 Hz, and reports brightness control.
    Blend CRC Matches the reference values for ARGB with alpha ff, 00 and 80, and for XRGB with X = 00, 80 and ff (all opaque).
    Brightness Follows requests from 2 to 525 nits within 20 ms. The SMC backlight rail rises monotonically from 18 mW to 5.36 W, and reads 9 µW at 0.
    DPMS 20 of 20 blank/wake cycles.
    Reboots Three orderly reboots, including a hand-back to the previous kernel, with no shutdown fault.
    Analytics A 62-minute session passed the firmware's hourly analytics callback (D114, answered) with the display alive.
  • Not exercised on hardware (KUnit and review only):

    • During the 62-minute session the firmware sent only D102, D114 and the per-frame D300. Swap aborts (D593), brightness re-send requests (D594) and the other runtime callbacks with new bounds never fired.
    • On every test boot the backlight registered from the powerlog report, so the fallback registration never ran.
    • The failed-registration path did not run either.
    • s2idle: no wake source is available on the bench.
    • Firmware crash handling.
    • External displays and DP audio are not supported by this driver on T8140 yet.

How it was written

All code is newly written for this series, following the existing driver's conventions.

🤖 Generated with Claude Code

The H17P callback dispatcher only accepts callbacks whose record lengths
appear in the startup observations.  Every other callback that has a
handler is treated as unqualified and marks the coprocessor as crashed,
which stops all presents until the next reboot.

Twenty-six handled callbacks are missing from those observations because
they arrive only after startup: present notifications, swap aborts, the
backlight re-send request, the wall-clock and clock-rate queries, and
several acknowledgements.  A long session that sees any of them loses
the internal panel even though the driver knows how to answer.

Record, for each of them, the input its handler reads and the reply it
writes, and accept any record at least that large.  The dispatcher
already zeroes the whole reply before the handler runs, so a longer
reply carries zeroes beyond the handler's fields.  The measured startup
tuples stay exact, and tags without a handler are still answered with a
zeroed reply as before.

Add a KUnit case that every installed handler has bounds and that the
exact and bounded rules hold.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The prepare callback maps a physical display register range for the
coprocessor.  Its size arrives from the firmware as a 64-bit value but
is rounded into an int, so a large size wraps negative.  The window
check then compares a wrapped end address, and dma_map_resource()
receives the sign-extended size.  The descriptor ID is also taken from
find_first_zero_bit() without checking for a full table, so a mapping
requested while all 128 descriptors are in use writes past the array.  A
failed DMA mapping is only warned about and returned as the device
address.

Keep the size in 64 bits, refuse a zero size or a range that wraps,
refuse when no descriptor is free, and refuse a failed DMA mapping
before claiming a descriptor.  Each refusal is the existing all-zero
reply already used for addresses outside the display windows.  A valid
request is mapped and answered exactly as before.

H17P accepts this callback at runtime from now on, which makes the
bounds matter there too.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
H17P reports an aborted present through its abort callback and never
sends a completion for it.  The driver only traced the callback, so the
present stayed pending: the outbound queue waited until its ten-second
timeout declared the coprocessor crashed, and the page-flip event was
never signalled.

Track the abort in the present state.  After the submit reply, an abort
ends the present like a rejected submission: the brightness reservation
is retried, framebuffers displaced by the present are unarmed and stay
retained for the next completed present, and the DRM event is
signalled.  An abort that arrives before the submit reply is recorded,
and the reply then fails the present instead of waiting for a
completion.  An abort naming a present that is not in flight is only
logged.

Older firmware still only traces the callback.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The enable-backlight-message callback asks the AP to send the panel
level again.  On H17P the level travels only inside a present, so the
existing handler, which sets the older firmware's update flag, sends
nothing: the brightness policy sees no pending change and the queued
brightness transaction returns without presenting.

On the measured H17P profile, mark the effective level dirty and let the
update worker queue a brightness present, which re-presents the retained
scanout as for any other level change.  A blanked panel is re-sent at
zero and keeps its restore target.  Nothing is sent before Linux
controls the level, while a present already carries it, or more than
once a second, so a request repeated after every brightness present
cannot keep the queue busy.  The receive path only schedules the worker;
it never queues a transaction itself.

Older firmware keeps its existing handling.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The H17P backlight is commanded in nits, and the firmware converts them
with its own tables up to the panel ceiling from the device tree, 525
nits on J700.  Takeover still clamps the exposed range to 509 nits, the
end of the older firmware's DAC interpolation table, which H17P never
uses.  The top of the panel's range is therefore unreachable, and a
loader level reported above 509 nits rejects the takeover hint, which
leaves the backlight unregistered until a later report falls below it.

Use the panel ceiling as the H17P maximum, and clamp a powerlog report
above it to the ceiling instead of rejecting it.  The present encoding
already writes the same ceiling into every present.  Older firmware
keeps its existing range.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
H17P never publishes the panel level.  The driver registers its
backlight only when the system endpoint forwards a powerlog report with
the loader's level.  That report is optional: when it does not arrive,
or arrives in a form the parser does not accept, no backlight device is
ever registered and desktops offer no brightness control.

Two seconds after the first pipe enable, register the backlight anyway
if no report has configured it.  Expose the middle of the panel range as
the current level, but present nothing: the policy starts clean, so the
panel keeps the loader's level until userspace writes one.  A report
that arrives later is ignored, as are reports after a hint-based
registration.  The worker is cancelled with the other backlight work on
unbind and shutdown.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
H17P keeps its pipe and display domains running across system sleep,
and blanks the panel with a brightness present instead.  The DRM and
backlight suspend handlers only queue that present: the serialized
IOMFB queue sends it, and finishes it when the firmware reports the
completion.  The DCP suspend handler returned without waiting, so the
blanking present could still be in flight when interrupts are suspended,
leaving the panel lit through the sleep and the transaction stalled
until resume.

Before the DCP suspends, flush the brightness worker and wait up to half
a second for the queue to go idle, twice, since a completed present can
schedule one more brightness present.  A crashed or stopped queue counts
as idle.  If the queue does not drain, log it and continue suspending.
Older firmware does not use the queue and is unaffected.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
When the H17P firmware crashes, the driver marks the coprocessor failed
and reports the connector disconnected.  A present in flight at that
moment never completes, so its page-flip event is only released by the
DRM core's flip timeout, and the compositor stalls on it first.

Schedule the existing delayed vblank work from the crash handler on H17P
so the pending event is signalled.  Framebuffers stay retained, since
the display engine may still be reading the last surface.  H17P has no
in-place restart, so also log that a reboot is needed to restore the
display.

Older firmware keeps its existing crash handling.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
…abled

The display subsystem builds its component match from every available
DCP node and binds only when all of them have bound.  The T8140 external
DCP runs firmware this driver cannot drive yet: its node falls back to
the generic DCP match, which has no firmware profile for it.  Its probe
then either fails, leaving the component master waiting forever, or
selects an older firmware interface from the loader's properties.
Enabling that node in a device tree would therefore take the internal
panel down with it.

Leave T8140 external DCP nodes out of the component match and the
pipeline scan, and refuse them in the DCP probe with an informational
message, so they are never touched.  Other SoCs are unaffected.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The H17P crash handler schedules the delayed vblank work, so that a
present in flight at the time of the crash completes its page-flip
event.  That work dereferences dcp->crtc, which is set only when the
display subsystem links the pipeline.  RTKit is already running before
that: component binding wakes the coprocessor before the DRM device
creates its CRTCs, and a pipeline whose CRTC setup failed stays bound
with no CRTC at all.  A firmware crash in either state then oopses the
workqueue on a NULL CRTC.

Schedule the work from the crash handler only once a CRTC is linked,
and make the delayed vblank work itself return early without one, which
also covers its other callers.  Publish the CRTC with WRITE_ONCE() to
match the lockless readers.

Also limit the crash-time completion to the measured H17P profile, as
every other H17P change in this series is.  The H17G profile (T8142)
keeps its existing crash handling.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
When the backlight class device cannot be registered, the worker zeroes
the panel maximum so that older firmware stops encoding brightness.  On
H17P the brightness policy is already active by then, and the present
path needs that maximum for the ceiling it writes into every present:
with it zeroed, every present is refused and the panel freezes on its
last frame.  Registration is attempted on every H17P boot now, so this
error path is always reachable.

Keep the maximum while the H17P policy is active.  Presents keep their
ceiling and the policy keeps applying DPMS and the firmware's requests;
only the sysfs control is missing.  Log the error code in either case.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Without a loader brightness report, the H17P backlight is registered
with a mid-range default that is only reported to userspace; the panel
keeps the loader's level.  Registration also marks the policy as
controlled, which is the only condition the firmware's re-send request
checked.  A re-send request before userspace writes a level therefore
presented the default and moved the panel from the loader's level to
mid-range, contrary to the intent of the re-send and fallback
registration changes.

Track whether the level the panel shows is known: the loader's reported
level, or one a completed present carried.  Require it for a re-send,
so a re-send request now leaves a panel showing an unknown level
alone.  A rejected present does not make a level known.

A DPMS blank and wake, or a suspend and resume, after a fallback
registration still has to light the panel at some level and uses the
reported default.  The panel keeps the loader's level only until the
first such transition or userspace write.

Also reject powerlog reports above twice the panel ceiling instead of
clamping them, so a corrupt sample cannot become a known level.

Add a KUnit case for the fallback registration, the re-send request,
rejected and completed presents, and the DPMS wake level.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The H17P abort callback is handled as "this present never completes",
but no capture confirms that.  If the firmware still completes an
aborted present, the completion matches no present in flight and the
driver declares the coprocessor crashed, turning the first real abort
into a dead display.

Remember the most recently aborted present.  A completion for it is
logged and otherwise ignored: its displaced framebuffers were already
unarmed and its DRM event signalled when it was aborted, and it does
not disturb a later present in flight.

Also settle the swap watchdog when an accepted present is aborted.
Otherwise a Type-C output would report a missing completion and
retrain one second later.  Rate-limit the abort messages, so that a
firmware that aborts every frame cannot flood the log.

Extend the KUnit present-state case with stale completions.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The sleep drain waited for the IOMFB queue to go idle, but a rejected
blanking present leaves the queue idle with a delayed retry scheduled.
The drain then returned, and the retry ran after the coprocessor's
mailbox had suspended, leaving the panel lit through sleep.

Run a pending brightness retry immediately in each drain pass, and keep
draining while the brightness policy still has a level to send.  Four
passes cover the first attempt and the policy's three retries, each
bounded as before; a level that is still pending after them is logged.

Also queue the fallback backlight registration on the freezable system
workqueue, so that it cannot register a class device in the middle of a
suspend that starts within two seconds of the first pipe enable.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The runtime callbacks accepted within reply bounds are validated
against what their handlers read and write, because no capture of
their record lengths exists.  A longer record is accepted silently, so
a layout that differs from the handler's assumption, for instance a
status word at another offset, would go unnoticed.

The first time each of these callbacks arrives with lengths other than
its handler's, log the lengths seen next to the handler's.  Each tag is
reported at most once per boot, and the measured startup callbacks are
unchanged.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit df7801c into aurora-wip Oct 8, 2026
RyanTheTide added a commit that referenced this pull request Oct 8, 2026
…a dead DCP, seeded backlight level, DCP node references

drm: apple: #203 follow-ups: sleep drain on a dead DCP, seeded backlight level, DCP node references
@DjDeveloperr
DjDeveloperr deleted the j700/dcp-complete branch October 12, 2026 19:15
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.

1 participant