Skip to content

drm/apple: fill the extended firmware-27 D003 bandwidth reply - #3327

Merged
RyanTheTide merged 6 commits into
mainfrom
fix/dcp-v27-d003-bandwidth-slot
Dec 1, 2026
Merged

RyanTheTide merged 6 commits into
mainfrom
fix/dcp-v27-d003-bandwidth-slot

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: The firmware-27 DCP on J516s asks for a 44-byte D003 (realtime bandwidth) reply, but Linux fills only the 20-byte H17P layout. That leaves the slot offset at 0, so when the DCP powers its M3 down, its bandwidth write lands on PTD entry 0 instead of its dashboard slot (entry 305), and the PMP traps it ("PTD abort (0x0)"). This fills the extended reply's slot offset and size from apple,bw-scratch, as macOS does.
Tested: J516s M3 Pro at 363c468: boots, the DCP comes up and keeps writing its dashboard slot (PTD entry 305), entry 0 stays untouched. The same code on the T6030 sleep branch, with the PMP running: pm_test=devices passes, the DCP's power-down write goes to entry 305 and the PMP survives.
Risk: two-way door · M3 (firmware-27 DCPs that ask for the 44-byte reply); the 20-byte reply and the H17P path keep their encoder.
Not yet: no-op rows on the M5 Pro (20-byte reply) and the Neo (H17P path); the external T6030 DCPs, which this driver runs on firmware 14.7.

Details
  • trampoline_rt_bandwidth_h17p() in iomfb_v27.c picks the layout by the callback's output size. With 0x2c bytes it fills the extended reply: the dashboard address (as before), a zero clock-request word, the slot's offset from its display register window at +0x14 and the slot size (8) at +0x1c. Any other size keeps the short H17P encoder, unchanged.
  • The offset is the one apple,bw-scratch already gives (<&pmgr_dcp 0 5 0x988> on J516s, entry 305 of the update window at disp-5), so there is no new constant or SoC check.
  • On J516s, macOS's reply carries 0x988 at +0x14 and 8 at +0x1c, with the same dashboard address and a zero clock-request word (our boot traces). Its external DCPs get 0x10990 and 0x10998, relative to their own windows.
  • Without the offset, the firmware's bandwidth release at the M3 power-down lands on the update window's first word. Measured on J516s with a PTD read-side watch across a suspend: entry 0, never written since boot, is written with 0 about 58 ms after "power_down_M3: disabling M3", and the PMP reports "PTD abort: (0x0)" 13 ms later.
  • The binding text and the J516s DT comment only describe how the existing apple,bw-scratch specifier serves the extended reply; there is no schema change.
Evidence
  • 363c468 (this branch) on J516s: boots on the internal display; the DCP logs program_M3_rt_config: Using Dashboard 3503d0988. PTD entry 305 kept changing (DCP active) and entry 0 stayed 0x0, stamp 0. This base offers only s2idle, which dwc3 refuses at prepare, so the power-down path runs on the sleep branch.
  • Sleep branch m3pro/t6030-sleep-p20b at b322203 (this commit's code, with the T6030 PMP started), pm_test=devices: power_down_M3: disabling M3 once, no PMP crash; entry 305 0x4000000000900408 -> 0x0; entry 0 0x0, stamp 0 before and after. Before the change, the same branch logged "PTD abort: (0x0)" on every run, 71 ms after the M3 power-down.
  • Reply sizes in our traces: J516s DCP0 asks 4 in / 0x2c out. The M5 Pro's firmware-27 DCP asks for 0x14 out and keeps the short layout.

The extended firmware-27 reply describes the realtime bandwidth slot both
as an address and as a byte offset from its firmware display register
window. Document how the existing apple,bw-scratch specifier supports this
reply.

Signed-off-by: DjDeveloperr <hey@djdev.me>
The J516s DCP requests 44 output bytes for D003. The short H17P encoder
gives it the dashboard address but leaves the extended slot offset and
size at zero. The macOS reply has an offset of 0x988 and a size of 8,
with the same dashboard address and zero clock-request word.

With the offset at zero, the firmware's write of its bandwidth request
when it powers its M3 down lands on the first word of the update window
(PTD entry 0) instead of the dashboard slot, and the PMP traps that
write as "PTD abort (0x0)".

Select the extended format by the callback's output size and supply the
offset already resolved from apple,bw-scratch. Keep the short encoder for
DCPs using the existing format.

Signed-off-by: DjDeveloperr <hey@djdev.me>
Document that the internal display's scratch register is PTD entry 305
within the update window at disp-5.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 22:31
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) 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) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 85c4cf9f: not ready yet

Check Detail
CI at head no failing: KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp, KUnit jpeg
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 bdff788a; the changed files are byte-identical at 85c4cf9f
Conflicts ok none
PR text ok Risk: two-way · M3 (firmware-27 DCPs that ask for the 44-byte reply); the 20-byte reply and the H17P path keep their encoder.

Areas: area:display, 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

Verdict at 363c468374ac: ready. The rows under Not yet are still owed before merge. The M5 Pro row is the second-generation firmware-27 row for this shared code (iomfb_v27.c); please include an external display in it (see the last point under Checked).

Blockers: none.

Checked:

  • Layout.
    • struct dcp_v27_rt_bw_extended_reply is __packed and asserted at 0x2c: the H17P config (dashboard address and clock request) at 0x00, the slot offset at +0x14, the slot size at +0x1c and the status at +0x28. That matches the macOS reply described in the PR (0x988 / 8, zero clock request).
    • All written fields are cpu_to_le32. The unknown_* fields are never written.
  • Bounds. On firmware 27 the dispatcher (iomfb.c, the "unqualified IOMFB callback" check) requires header + in_len + out_len == length inside the 0x8000 shared buffer, and iomfb_v27_callback_size_valid() requires in ≥ 0x4 and out ≥ 0x14 for D003. A 0x2c reply therefore stays inside the record, and reading config_null is in bounds.
    • The dispatcher memsets the output to 0 before the handler, so the unknown words go back as zero.
    • in - sizeof(*header) is the record's own header (in = data + sizeof(*hdr)). iomfb_h17p.c and iomfb_v26_6_desktop.c use the same pattern.
  • Gating.
    • Only an output size of exactly 0x2c takes the new path. Any other size, including the M5 Pro's 0x14, runs the unchanged short encoder, which writes 0x14 bytes inside the at-least-0x14-byte output.
    • A null config (config_null & 1) is refused in both paths, as before.
    • The Neo uses iomfb_h17p.c's own D003 trampoline, and M1/M2 and the T6030 external DCPs use other firmware files. None of them can reach this code.
  • Offset source. disp_bw_scratch_offset is apple,bw-scratch's address minus its display window (dcp_get_bw_scratch_in_window()), so it is 0x988 on J516s. There is no new constant and no SoC check. The binding and DT changes are comments and descriptions only, with no schema change.
  • Build and style.
    • make W=1 drivers/gpu/drm/apple/ (asahi config, LLVM, arm64) compiles iomfb_v27.o with no warnings.
    • t6030-j516s.dtb builds; its dtc warnings are all in nodes this PR doesn't touch.
    • checkpatch --strict is clean on all three commits.
  • Text. The PR text matches the evidence. The power-down result comes from the sleep branch with this code, because this head's J516s base refuses s2idle, and the PR says so. The commits are Signed-off-by DjDeveloperr, with no attribution lines.
  • Other firmware-27 DCPs. The new path also runs for any of them that asks for 0x2c bytes. Several have non-zero apple,bw-scratch offsets: the M4 Pro and M5 Pro external DCPs (dcpext, offsets 0x20000–0x38000). T8132 and T8142 use offset 0. The PR documents the request size only for the J516s internal DCP (0x2c) and the M5 Pro internal DCP (0x14). An external display in the M5 Pro row, with D003's in/out sizes logged, would show whether those DCPs take the new path. Whether they need it, and what they write, is not a blocker.
  • CI. 9 checks passed and 12 were still pending when I posted this.
Evidence

Head 363c468374acef086be99a4e2ff5b25f70516c3d, base main 8e2ee15f3ca3 (the current tip). Linux aarch64 host.

Check Result
checkpatch.pl --strict on 8fcfbbba973a, 8f9a1eb3c5d9, 363c468374ac 0 errors, 0 warnings, 0 checks each
make LLVM=1 W=1 drivers/gpu/drm/apple/ (asahi config, DRM_APPLE=m) CC [M] drivers/gpu/drm/apple/iomfb_v27.o, LD [M] appledrm.o; no compiler warnings
make apple/t6030-j516s.dtb builds; existing dtc warnings only (avd@30a000000, fifo@37ab30000 unit addresses, /aliases names)
dispatcher checks (iomfb.c) firmware 27: sizeof(hdr) + in_len + out_len == length, iomfb_v27_callback_size_valid() = in >= 0x4 && out >= 0x14 for D003, then memset(out, 0, out_len) before the handler

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s (MacBook Pro 14" M5 Pro, T6050) no-op row at exact head 363c468374ac: PASS.

  • Kernel: 7.3.0-m5-rows-k3327h, a warm native build on the M5 of this PR's head alone.
  • Boot: the default command line. The default kernel (7.3.0-m5-cdirect16) was restored afterwards with a clean systemctl reboot, and all 253 ESP file hashes were verified.
  • No PTD reads: nothing reads the PTD; the row uses only dmesg and DRM/compositor state.

1. Displays attached on this rig:

  • The built-in panel is eDP-1 at 3024x1964.
  • Two external 3840x2160 monitors are on DP-2 and DP-5 through dcpext. The other four DP connectors are disconnected.
  • Five DCPs are bound (2b2e00000, 302e00000, 306e00000, 392e00000, 48ae00000).
  • Every connected output came up enabled at its native mode.

2. The D003 reply on this Mac:

  • The driver doesn't log the reply size, and this kernel has no dcp:iomfb_callback tracepoint available. So the size the M5 firmware asks for was not observed directly here.
  • What the log shows instead:
    • 0 D003 bandwidth request is malformed lines and 0 PTD abort lines over the whole boot.
    • The DCP lines this row watches match a main-based boot without this change (linux#3330's row on 2094ccb2a036 + drm/asahi: g17: retire latched compute queues and split multi-command work states #3330), count for count: 7 RTKit: crashlog endpoint not in the endpoint map and 4 DCP syslog get_max_bandwidth: timing NULL.
    • Neither boot logs a program_M3_rt_config/dashboard line on this Mac.

3. One DPMS off/on cycle of all three monitors, through Hyprland, which ran normally:

  • 3 off, then 3 on, and 3 connectors were still connected afterwards.
  • In that window: 0 PTD abort, 0 malformed, 0 DCP crashes and 0 WARN.

4. Whole boot: 0 WARN/BUG/Oops, 0 PTD abort and 0 GPU MMU faults. There is one distinct error-level line (apple-dcp … DCP requested undeclared provider clock index), which the default boot also logs. Failed units: tailscaled.service only, the same as on the default boot.

No display was plugged or unplugged for this row; it covers the monitors already attached.

@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: Changes requested at 363c468374ac.

Blockers: The D003 callback uses the short encoder for every output size other than 44 bytes. The dispatcher clears the declared output area but does not validate sizes against callback prototypes. Require an exact supported output size before encoding and a sufficient input size before reading the request or deriving the header from the input pointer. Also validate the full eight-byte scratch slot against its mapped window for the extended reply. The current scratch resolver accepts a four-byte slot.

Please add short-layout, extended-layout and malformed-length coverage. The reported J516s result covers the new layout; retain the stated M5 Pro, Neo and external-display rows for the shared callback path.

…izes

The firmware-27 D003 callback read the request before checking in_len,
encoded the short reply for any out_len other than the extended size, and
wrote an 8-byte scratch slot that the scratch resolvers only check for
4 bytes. Move the encoding into dcp_v27_rt_bw_reply(), which requires a
complete request, fills only the 0x14 and 0x2c reply layouts, and for the
extended reply requires the whole 8-byte slot inside the mapped scratch
window. Anything else is warned about and the reply stays cleared.

Add KUnit cases for both layouts, malformed lengths and a 4-byte slot.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Pushed bdff788 for the App's length-validation finding. The D003 encoding now lives in dcp_v27_rt_bw_reply(). It requires in_len >= the 4-byte request, fills only the 0x14 short and 0x2c extended reply layouts, and for the extended reply requires the whole 8-byte scratch slot inside the mapped scratch window (the resolvers only check 4 bytes). Anything else logs "D003 bandwidth request is malformed" and leaves the reply cleared.
New KUnit cases in apple-dcp-v27 cover the short layout, the extended layout, malformed in/out lengths and null config, and a refused 4-byte slot. Locally, drivers/gpu/drm/apple/tests/topology.kunitconfig on arm64 QEMU passes 212 tests with 1 skipped. DT and binding files are unchanged.
Still needed: CI, App re-review, and rows at bdff788: J700 boot, plus an external display on J714s or J473 (the J516s row still covers the same layout path).
Thanks @DjDeveloperr.

@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: FINISH at bdff788. The new encoder checks minimum input length, permits exactly the two reply lengths, and checks the whole eight-byte slot without subtraction underflow. The KUnit cases cover both layouts and confirm that malformed input leaves the output unchanged. Please link CI and the current-head J700 boot and J714s or J473 external-display rows. Please also identify the clean provenance for the wire layout in the PR description, citing only project-owned measurements, public sources, or independently authored code.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 29, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

bdff788 J700 (MacBook Neo, T8140, fw 27) PASS: combined guarded one-shot 7.3.0-aurora-peer1+ on main 498d53fd (iomfb_v27.{c,h} byte-identical to bdff788a215b, default cmdline, saved Stage 2 unchanged); fw27 DCP booted cleanly with 0 PTD aborts and 0 DCP crashes, VK api.smoke 8/8 pre/post s2idle 1/1 (rtc0), Enforcing, 0 AVC, 0 failed units; restored saved 7.3.0-aurora-edge.

@RyanTheTide

Copy link
Copy Markdown
Contributor

bdff788 J473 (M2 Mac mini, T8112, fw 27.2, external displays) PASS: combined guarded one-shot 7.3.0-aurora-peer1+ on main 498d53fd (iomfb_v27.{c,h} byte-identical to bdff788a215b, default cmdline, saved Stage 2 unchanged); external displays (card1-DP-2 2560x1440 + card1-HDMI-A-1 1920x1080) active at boot and post-s2idle 1/1 (rtc1), VK api.smoke 8/8, 0 PTD aborts, 0 DCP crashes, Enforcing, 0 AVC, 0 failed units; restored saved 7.3.0-aurora-m2combo30.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor

I merged current main into this branch (85c4cf9f, normal push, no rebase, your commits unchanged). The last CI failures came from main itself on 11-29: the apple-scaler-recovery and g17-compute-owed-stamp fixtures, plus the apple-dcp harness break fixed in #3672. Re-running a job would reuse the old merge commit, so a fresh merge was the only way to clear them. Both merges were conflict-free. Host tests pass on the merged tree. The PR's own code is unchanged from bdff788a, so the existing hardware rows still cover it. Next: CI at this head and the review app's verdict.

@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: HOLD at 85c4cf9f.

Checked: Compared the PR patch before and after the forward merge. The file set and added and removed lines match the reviewed revision. Keep hosted checks, applicable boot/display rows and the clean provenance statement for the wire layout.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 30, 2026
@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 1, 2026

@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 85c4cf9f5bb8

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: Compared the PR patch before and after the forward merge. The file set and added and removed lines match the reviewed revision. Keep hosted checks, applicable boot/display rows and the clean provenance statement for the wire layout.

Follow-ups (not blocking): hosted checks, boot/display rows, provenance statement for wire layout

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 85c4cf9f5bb8 (B2 merge train, 12-01 merge bar). Approval at this head: aurora-silicon-review[bot]. Row: the hardware row at 85c4cf9 that the readiness check found (PR body or comment). CI: linux train L3 = main 429e7e1 + 28 approved PRs (candidate 45c2fa4b): Apple driver compile pass, Apple DTBs W=1 pass, planned KUnit dcp-fabric/dcp-topology/dcp-display/macsmc/spi-hid-apple/mt7932/asahi/sep pass; ave failed to build only because of #3153 (unused static helper under -Werror; #3153 held out) and passes with #3153 reverted from the candidate; host tests apple-dcp and apple-scaler-recovery pass. The rest of the hosted run is queued behind the backlog. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit 59e0ba9 into main Dec 1, 2026
37 of 49 checks passed
@RyanTheTide
RyanTheTide deleted the fix/dcp-v27-d003-bandwidth-slot branch December 1, 2026 08:22
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:platform Area from CODEOWNERS (bot) blast:m3 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-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants