Skip to content

dcp: speak the firmware-27 dptx-port interface and answer OOB service calls - #591

Merged
RyanTheTide merged 6 commits into
mainfrom
fix/584-dptx-v27-oob
Dec 1, 2026
Merged

RyanTheTide merged 6 commits into
mainfrom
fix/584-dptx-v27-oob

Conversation

@satchlj

@satchlj satchlj commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

What: The dptx-port service is started on endpoint 0x2c with the firmware-27 message layout when the DCP firmware announces 0x2c and not 0x2a (the T6050 DCP's does), and AFKv2 out-of-band service calls from the firmware are answered instead of refused. Before, aura waited on 0x2a, which that firmware does not have, and could not answer the firmware's PHY callbacks. Stacked on #590; refs #584.

Tested: one J775c row on the previous stack (#590 at 5b5765f) never started the dptx-port service: #590's route fell back to the internal engine. This PR's commit is unchanged, rebased onto #590's new head. No hardware row at this head. Host only: tests/python/test_dptx_v27_oob.py builds the real rtkit_has_endpoint() / rtkit_access_remote() (over a model DART and RAM), the AFKv2 peer-command path of src/afk.c, and the endpoint choice and v27 calls of src/dcp/dptx_port_ep.c against stand-ins (ASan/UBSan); 4 tests, all fail on its base and pass here.

Risk: two-way · every AFKv2 display firmware that sends out-of-band service calls (T6050, T8152): those were refused as unsupported and are now dispatched to the service's call handler with bounded, DART-checked buffers. The v27 layout only where the firmware announces 0x2c and not 0x2a (T6050). Every machine that announces 0x2a keeps it and its layout.

Not yet: a J775c HDMI row (dptx-port opens on 0x2c, connect, request-display and training callbacks succeed); a T8152 J873g HDMI and USB-C regression row, since its out-of-band calls now reach its handler.

Details
  • Endpoint: dcp_dptx_endpoint() uses 0x2a when the IOP's endpoint map has it, else 0x2c when it has that (rtkit_has_endpoint()), else 0x2a. The endpoint the firmware announced selects the layout; no chip or firmware version is checked.
  • v27 layout (dcp_dptx_if_t.v27): validate-connection before connect; validate and connect replies of eight bytes without a status word; connect echoes the attributes it took, and a port behind a DP-to-HDMI converter does not claim supportsHPD (the AP reports it, dcp_dptx_needs_ap_hpd()); request-display and hotplug without status, hotplug echoing its state; group-1 link records (3, 4) returned with their result words cleared; drive settings as a lane count at 16 (set) or 0 (get) and lanes from 32, checked against DisplayPort's levels (swing and pre-emphasis 0..3, sum at most 3) before the PHY; a 160-byte tiling-hints record with its status at 0x90; link-fault reports acknowledged, as on T8152. The connect echo check is the same rule as display/dptx: don't reject a DPTX connect reply over the unk field #292's.
  • Out-of-band calls (afkv2_handle_oob_command()): request read from the firmware's tx buffer and reply written to its rx buffer through rtkit_access_remote(), which requires every 16 KiB page of each span to be mapped in the session's DART and to land in RAM, maps nothing, and does the cache maintenance. Both buffers at most 16 KiB, the reply within the command's capacity, a valid service-call header. Status in the response's value; a failed call returns no bytes and keeps the descriptor. Anything else is still refused without touching a firmware address.
  • The AFKv2 command tx buffer is cleaned after it is written and the rx buffer invalidated before it is read.
  • tests/python/test_dcp_shutdown_failures.py: its interface stand-in gains the new field and endpoint choice.
  • On top of rtkit: answer OSLog on the legacy mailbox and echo its channel-zero counter #587 the RTKit boot host needs the stand-ins rtkit_access_remote() uses (a separate test commit on the trial stack).
Evidence

Cases: endpoint map lookup; a two-page span with the DART's DRAM-mask bit, written and read back through two non-contiguous pages with cache maintenance; an unmapped page, a page outside RAM, empty, wrapping and DART-less spans refused with nothing copied. An out-of-band call dispatched with its group, command and length, its reply in the firmware's buffer and status 0; a failing call's status with no bytes; refused before the call when the reply exceeds the capacity, the reply buffer is unmapped, the request is short or its magic wrong. Endpoint choice for {0x2a, 0x2c}, {0x2c}, {}; group-1 records, other calls left to the common handler, tiling hints, drive settings set and read back, out-of-range levels and lane counts refused without a PHY call.

clang-format 20.1.8 clean. ESP Stage 2 builds.

@satchlj

satchlj commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Rebased onto #590's new head a6b35aa (stack rebase, commit unchanged): old head 9468348, new head b401a3c.

@satchlj
satchlj force-pushed the fix/584-dptx-v27-oob branch from b401a3c to 3c89289 Compare November 30, 2026 01:55
@satchlj

satchlj commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Rebased onto #590's new head 446f285, conflict-free, with an identical diff: b401a3c -> 3c89289.

… calls

The T6050 DCP's firmware 27 hosts its dptx-port RemotePort service on
endpoint 0x2c and announces no 0x2a, so dcp_dptx_init() waited on an
endpoint that is not there. On that endpoint it also speaks a later
message layout, and it makes its own service calls to the AP out of band:
the request and the reply are in its buffers, named by address and
length in the command, which AFK rejected.

Endpoint: use 0x2a where the firmware announces it, as before, and 0x2c
where it announces only that (rtkit_has_endpoint(), from the endpoint map
the IOP sent). The endpoint is what selects the layout below; no chip or
firmware version is checked.

On that layout (dcp_dptx_if_t.v27):

 - the connection is validated before it is taken;
 - validate-connection and connect replies are eight bytes with no status
   word; the connect reply echoes the attributes it took, and a port
   behind a DP-to-HDMI converter does not claim supportsHPD (the AP
   reports that HPD);
 - request-display and the hotplug call return no status; hotplug echoes
   the state it took;
 - the firmware's group-1 link record calls (3 and 4) carry its own
   pointers and are returned as given with their result words cleared;
   drive settings come as a lane count at 16 (set) or 0 (get) and the
   lanes from 32, checked against DisplayPort's levels before the PHY sees
   them; tiling hints are a 160-byte record whose status is at 0x90; link
   fault reports are acknowledged, as on T8152.

Out-of-band service calls (command flags bit 0), on any AFKv2 endpoint
whose service takes calls: the request is copied from the firmware's tx
buffer and the reply to its rx buffer only when every page of each is
mapped in the session's DART and lands in RAM (rtkit_access_remote(),
nothing is mapped for it), both are at most 16 KiB and the reply fits
the command's capacity. The status goes back in the response's value; a
failed call returns no bytes. Anything else is still refused as
unsupported without touching a firmware address. Before this, every such
call was refused.

The AFKv2 command's tx buffer is cleaned to memory after it is written
and its rx buffer invalidated before it is read, as the firmware's DMA
needs on any machine where those buffers are cached.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj force-pushed the fix/584-dptx-v27-oob branch from 3c89289 to f7771e5 Compare November 30, 2026 15:32
@satchlj

satchlj commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

rebased onto fix/584-hdmi-route-adt 0b82cba: old head 3c89289, new head f7771e5, conflicts in src/dcp.c (dp2hdmi is set inside main's new dp2hdmi_gpio block), src/dcp/dptx_port_ep.c (main already adds drive[4] and the group-1 GetDriveSettings call; link fault reports are acked on T8152, T8103 or the v27 layout).

@satchlj

satchlj commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

J775c (M5 Max Studio) row for the rebased stack at these heads: #589 a81571f6, #590 0b82cba4, #591 f7771e54, #592 d86af18d, #597 85982071, #602 83946b1d, #605 f8d4f63e, all on main f380f03c. Trial Stage 2 is lab/584-rebased-trial c9cb7a0c = this stack + #587 + #338 (raw image sha256 9473514e…). Only Stage 2 changed from this Mac's default. The kernel is the packaged linux-aurora (linux main e6c7b032 + linux#3686/#3689/#3682), Stage 1 is main 1e01a273 NO_DISPLAY, firmware 27.2.

Stage 2:

dart: /arm-io/dart-dcpext0: three-table stream, vm-base 0x10000000000, 1 root entry
dcp-dptx: endpoint 0x2c announces the dptx-port service
display: swapped! (swap_id=0)
DCP: T6050: dcpext0 handed off with the display subsystem: firmware 27.0, framebuffer 0x10fd805c000+0x854000
DCP: T6050: dcpext1 handed off: bw-scratch 0x30000
FDT: dcpext0: live RTKit session v12, 3 system buffer(s), epmap 0000011d 00823f3f
Preparing to boot kernel at 0x10004400000 with fdt at 0x1000eb80000

Linux: HDMI-A-1 connected 2560x1440, boot scanout retired by displayed swap 3, system level cache allocation enabled on 32 planes, 0 failed units, Wi-Fi up, and it returned to the saved default unaided. GPU bandwidth d4/d8 742/856 GB/s, render tri d1/d8 133.3/23.9 µs, llama-2-7B Q4_0 pp512 3,088 / tg128 110.7. That matches the pre-rebase stack within run-to-run spread.

@satchlj
satchlj marked this pull request as ready for review November 30, 2026 15:41
@satchlj
satchlj requested review from a team as code owners November 30, 2026 15:41
@github-actions github-actions Bot added blast:all 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 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge readiness at 924e4dd9: not ready yet

Check Detail
CI at head no failing: gcc, Pytest (ubuntu-latest + gcc), Pytest (ubuntu-latest + llvm), Pytest (macos-26 + llvm-brew), Pytest (macos-15 + llvm-brew)
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head ok comment at ece3e344; the changed files are byte-identical at 924e4dd9
Conflicts ok none
PR text ok Risk: two-way · every AFKv2 display firmware that sends out-of-band service calls (T6050, T8152): those were refused as unsupported and are now dispatched to the service's call handler with bounded, DART-checked buffers. The v27 layout only where the firmware announces 0x2c and not 0x2a (T6050). Every machine that announces 0x2a keeps it and its layout.

Areas: none matched in CODEOWNERS

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

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

Blockers:

  • Unaligned cache maintenance and destructive dc_ivac_range() on firmware-supplied DVAs (src/rtkit.c:931-941): CACHE_RANGE_OP (src/memory.c:29-34) starts at u64 p = (u64)addr and loops while (p < p + length) { cacheop(op, p); p += 64; } without aligning p down to CACHE_LINE_SIZE (64). Because rtkit_access_remote() accepts arbitrary firmware-supplied dva offsets, any pa that is not 64-byte aligned and crosses a 64-byte boundary (e.g., pa = ...0x30, chunk = 24, end = ...0x48) advances p from ...0x30 to ...0x70 >= end and skips the trailing cache line (...0x40), leaving stale bytes in AP cache on !to_iop reads and uncleaned tail bytes on to_iop writes. Furthermore, dc_ivac_range() executes bare dc ivac (invalidate without clean), which discards any adjacent dirty AP data sharing a partial boundary cache line with an unaligned firmware buffer. Align the cache-maintenance span down/up to CACHE_LINE_SIZE (64 bytes) and use dc_civac_range() (clean+invalidate) on the !to_iop read path.
  • Stacked on open PR #590: targets feature branch fix/584-hdmi-route-adt (not yet merged to main).
  • Pending T8152 regression row: the T8152 (J873g) HDMI/USB-C regression row noted under Not yet is still outstanding (AFKv2 OOB service calls now dispatch to the handler on T8152 as well; exact-head f7771e54 J775c HDMI + SLC row is posted and clean).

Checked:

  • Audited all production changes (src/afk.c, src/dcp.c, src/dcp.h, src/dcp/dptx_port_ep.c, src/rtkit.c, src/rtkit.h).
  • Verified afkv2_handle_oob_command() validates packet size, AFKV2_OOB_MAX (16 KiB) bounds, oob->rxlen <= cmd->value, pre-checks rxbuf DART/RAM containment before allocation, checks "ipcx" magic and call->length, zeroes packet.oob.rxlen on error, and frees request/response on all paths.
  • Verified afkv2_copy_response() (dc_ivac_range) and afkv2_command() (dc_cvac_range) operate on page-aligned epic->rxbuf.bfr/epic->txbuf.bfr, so every cache line in [0, size) is covered there.
  • Verified dcp_dptx_endpoint() selects 0x2c only when 0x2a is absent and 0x2c is present in the endpoint map (rtkit_has_endpoint()), dptxport_call_v27() validates group-1 link record sizes, 160-byte tiled-display hints, and drive-setting bounds (voltage <= 3, pre_emphasis <= 3, voltage + pre_emphasis <= 3, count <= 4), and dptxport_connect() omits supportsHPD (0x100) on v27 dp2hdmi ports while checking echoed attributes.
  • Verified rtkit_remote_page() intentionally preserves high T6050 3-table IOVA bits (dva & ~rtk->dva_base) and validates full-span RAM bounds before reading/writing.
  • Hosted CI is green at f7771e54 (8/8 checks passed: policy, ESP stage 2 vital size, selftest, pr-text, readiness).
Evidence
  • Head SHA: f7771e54317af9397da0f6720acf5ccf43bc2399 (base=fix/584-hdmi-route-adt, MERGEABLE, 8P/0F/0Q CI).
  • src/memory.c:29-34: CACHE_RANGE_OP starts at unaligned u64 p = (u64)addr; u64 end = p + length; while (p < end) { cacheop(op, p); p += CACHE_LINE_SIZE; } with CACHE_RANGE_OP(dc_ivac_range, "dc ivac").
  • Exact-head J775c row (#591#issuecomment-7283293452) confirmed dcp-dptx: endpoint 0x2c announces the dptx-port service, swap_id=0, HDMI-A-1 connected 2560x1440, SLC enabled on 32 planes, 0 failed units.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at f7771e54

Blockers:

  1. src/dcp/dptx_port_ep.c:607: on a v27 SET_DRIVE_SETTINGS call, only data_size is checked against 32 + count * 12. reply_size is only checked to be at least 32. Line 624 then copies count * 12 bytes to reply + 32, so a call with 4 lanes and a 32-byte reply writes 48 bytes past the reply. On the out-of-band path that reply is the calloc(oob->rxlen) buffer. Fix: check reply_size on both paths, as main's group-1 handler does a few lines further down: count > ARRAY_SIZE(port->drive) || (set && data_size < 32 + count * sizeof(*port->drive)) || reply_size < 32 + count * sizeof(*port->drive).
  2. src/rtkit.c:934 and :936: the cache maintenance misses the last line of a span that doesn't start on a 64-byte line. CACHE_RANGE_OP (src/memory.c:29) starts at the address it's given and steps by 64 while p < end. For a firmware buffer at …0x30 with 24 bytes, it cleans or invalidates the line at …0x00 and stops, so the line at …0x40 is never touched. dva comes from the firmware here, so nothing guarantees alignment. The read path then copies a stale tail on the second call into a reused tx buffer, and the write path leaves the reply's tail in the AP cache. Fix: in rtkit_access_remote(), run the maintenance over ALIGN_DOWN((u64)pa, 64) to ALIGN_UP((u64)pa + chunk, 64). Or align p down in CACHE_RANGE_OP, which changes nothing for callers that are already aligned.
  3. Row: afkv2_handle_command() now sends every AFKv2 out-of-band call to the service's handler, not only the v27 endpoint's, so T8152 runs new code. The T8152 J873 HDMI and USB-C row from Not yet is needed before merge.

Checked: 0x2c is chosen only when the firmware's endpoint map has it and doesn't have 0x2a, and there's no chip check. Out-of-band buffers are capped at 16 KiB, every page is checked against the DART and RAM before use, the reply is checked against the command's capacity, the ipcx header and length are checked, and nothing is mapped. The group-1 link records and the tiling-hints record are bounds-checked. Drive levels are checked against DisplayPort's limits before the PHY sees them. The J775c row for the rebased stack is at this head.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Nov 30, 2026
Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Merged main 2a7854a (via the branch below); one conflict resolved in src/dcp/dptx_port_ep.c: kept main's link-fault check, which already covers v27.

@RyanTheTide
RyanTheTide changed the base branch from fix/584-hdmi-route-adt to main December 1, 2026 06:52
…ache ops

Validate reply_size against 32 + count * sizeof(*port->drive) on v27
SET_DRIVE_SETTINGS as well as GET_DRIVE_SETTINGS, preventing a short
reply buffer from being overrun when echoing the lane settings.

In rtkit_access_remote(), align cache maintenance spans down and up to
64-byte cache lines and use dc_civac_range() on the !to_iop read path so
unaligned firmware DVAs never skip trailing cache lines or discard
adjacent dirty AP data sharing a boundary line.

Extend test_dptx_v27_oob.py to cover both cases.

Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) labels Dec 1, 2026
@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Addressed both code blockers at ece3e344 (merged main 378497cf, which includes #590 and #587):

  1. src/dcp/dptx_port_ep.c: validate reply_size >= 32 + count * sizeof(*port->drive) on v27 SET_DRIVE_SETTINGS as well as GET_DRIVE_SETTINGS.
  2. src/rtkit.c: align rtkit_access_remote() cache maintenance spans down/up to 64-byte cache lines and use dc_civac_range() on the !to_iop read path so partial boundary lines neither miss trailing lines nor discard adjacent dirty AP data.
  3. Added regression checks for both cases in tests/python/test_dptx_v27_oob.py and added rtkit_access_remote() stand-ins to tests/rtkit_boot_host/ (25/25 host tests pass under ASan/UBSan).

Updated Stage 2 hardware row for J775c at this head will follow once the current build finishes.

@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

J775c (M5 Max) row: a Stage 2 built from aura main 2a7854a3 with #590→#605 merged at their current heads (built tree 6b52b129, reports 1.0.0b17-g6b52b129), trial boot on the default command line: Stage 2 handed dcpext0 over live, apple-drm bound 2b2e00000.dcp, HDMI connected (console and greeter), SLC enabled, 0 failed units; the reboot out returned to the default unaided.

@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

J775c (M5 Max Studio) Stage 2 hardware row at the updated heads: #591 ece3e344, #592 f086b09c, #597 0bc4529b, #602 5d3b1f39, #605 6b52b129 on main 378497cf (Stage 2 built cleanly from main + this stack: 1.0.0b17-g6b52b129, raw aura.bin sha256 2a7f7410…; Stage 1 1e01a273 NO_DISPLAY, system firmware 27.2, kernel 7.3.0-1-46.5-ARCH, default command line):

  • One-shot Stage 2 trial booted cleanly and returned unaided to default.
  • apple-drm display-subsystem: bound 2b2e00000.dcp (ops dcp_comp_ops [appledrm])
  • HDMI-A-1 status: connected
  • apple-mcc 2220000000.memory-controller: system level cache allocation enabled on 32 planes
  • systemctl --failed: 0 failed units.

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

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both reported code failures are fixed at this head. The drive-settings handler checks the reply span on both paths, and remote cache maintenance covers both boundary lines of each span. The PR records a J775c stack row at the earlier fixed head.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 924e4dd95d3d (B2 merge train, 12-01 merge bar). Approval at this head: RyanTheTide. Row: J775c (M5 Max Studio) Stage 2 row for the whole stack (satchlj, on #591; heads since then only merge main). CI: aura train A3 = main f6d78b6 + #591 #592 #597 #602 #605 (candidate 548f83df): gcc normal + ESP_STAGE2 pass, no new warnings; pytest 1749 passed / 0 failed. Hosted CI is queued behind the backlog. Revert: git revert -m 1 <merge commit>.

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

Labels

blast:all Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (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.

3 participants