Skip to content

media: apple: prores: bind T6041's second engine (apr1) on the multi-job ring - #2661

Open
RyanTheTide wants to merge 6 commits into
media/prores-decode-v4-20261121from
media/prores-apr1-on-v4-20261121
Open

RyanTheTide wants to merge 6 commits into
media/prores-decode-v4-20261121from
media/prores-apr1-on-v4-20261121

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #2509, rebuilt on the ProRes decode stack (#2620, the base of this PR). #2509 was written for the single-job driver; the stack's multi-job ring changed the completion path, so its interrupt workaround is re-ported here rather than merged.

Problem

The M4 Max (T6041) has a second ProRes engine, apr1, that could never bind: its node has a core and a wrapper window but no SCODEC (aux) window, and the T6041 variant required all three. The T6041 device tree had no ProRes nodes at all. On a J616c, apr1 also finishes every job and sets IRQ_STATUS without its AIC line going high, so each job waits for the 4 ms watchdog (125 fps against 1100-1600 on apr0).

Change

  • Binding: an apple,t6041-prores node may have two reg entries (core, wrapper) or three (core, wrapper, aux). Other compatibles are unchanged. (clean pick of media: apple: prores: bind T6041's second engine (apr1) without an aux window #2509's f7419f1)
  • Driver: the SCODEC windows after core and wrapper are mapped only when the node's reg-names lists them. This keys on the hardware description, not on a compatible or an instance. (clean pick of 49aceef)
  • DT: t6041.dtsi describes apr0 and apr1, disabled; the J616c enables both. (clean pick of 45ba8f9)
  • Completion poll, ported to the ring: the interrupt handler's body becomes apr_service(), shared by the IRQ and a 100 us hrtimer. When the watchdog finds finished jobs on an engine whose interrupt line has never fired, the timer polls that engine while jobs are in the ring, and an interrupt ends the poll. Every arm is an hrtimer_start() under hw_lock. On the ring the watchdog also finds a completion ahead of its interrupt on working lines (seen on the M1 Pro), so "no interrupt yet for this job" alone does not start the poll (69a9475).
  • Wrapper readback, ported: the first time a wrapper does not take its rows, the driver logs each one (before, written, read back), and checks once more after a completed job. That check runs only with the ring empty.

Testing

M1 Pro (J316s) row on 69a9475 done: v4 against 69a9475 gives identical output hashes, fps, MIXED/DRAIN/KILL/TWO/OOB results, 0 bad dmesg lines, and no poll message (#2661 (comment)).

Still to run

  • J616c (M4 Max) row on this head: apr0 and apr1 decode and encode, fps, output hashes, and the wrapper readback lines for apr1 (none for apr0).
How the poll sits on the ring
  • apr_irq() now only calls apr_service(apr); apr_service() reads IRQ_STATUS, takes every finished job off the ring with apr_take_done(apr, done, &n), and gives them back outside hw_lock, exactly as the IRQ path did before.
  • The watchdog sets irq_missing for an engine with finished jobs whose line has never fired (irq_seen); apr_irq() sets irq_seen and clears irq_missing. While it is set, apr_device_run() arms the 100 us timer for that engine, and apr_service() re-arms it while njobs is non-zero.
  • The wrapper re-check after a completed job runs only when the ring is empty, so it never rewrites the wrapper under a queued job.
  • The interrupt stays requested: if the line does work, the IRQ and the timer race to the same apr_service() and the second one finds nothing.

Commits: 32a7032, 55e8a22, 2d2dab3 = git cherry-pick -x of #2509's f7419f1, 49aceef, 45ba8f9; 26222da and 2a93a0d are the two ports; 69a9475 limits the poll to a line that has never fired.

Assisted-by: LLM (Claude:Opus 5.5)

The M4 Max has a second ProRes engine, apr1, outside the SCODEC block.
Its Apple device tree node lists only the engine and wrapper windows and
no SCODEC system window, so a T6041 node may now have two reg entries
(core, wrapper) as well as three (core, wrapper, aux). The other
compatibles are unchanged.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit f7419f1)
The T6041 variant asked for core, wrapper and aux and failed the probe
without all three. apr1 on the M4 Max sits outside the SCODEC block and
has no aux window, so it could not bind.

Keep core and wrapper required, and map the later SCODEC windows (aux,
and ctrl on T6050) only when the node's reg-names lists them. Without
the window the system or control rows are not applied, which the
power-up path already allows. This follows the hardware description in
the device tree, not the compatible or the instance.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 49aceef)
Describe the two ProRes engines of the M4 Max from the J616c device
tree. apr0 sits in the SCODEC block at the same addresses as on the
T6040, with its SCODEC system window, DART and the SCODEC and
SCODEC_STREAMING power domains. apr1 has only its engine and wrapper
windows, interrupt 2010, its own single-stream DART at 0x585020000
(interrupt 2007) and the PRORES power domain (PMGR main bank, 0x3a8,
under FAB6_SOC), which also resets it.

All of it stays disabled in the SoC file. The J616c enables both
engines.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 45ba8f9)
On a J616c (M4 Max) the second ProRes engine, apr1, finishes every job
and raises IRQ_STATUS, but its AIC line never goes high. Each apr1 job
then waits for the watchdog's 4 ms poll (about 8 ms at HZ=250), so apr1
runs at 125 fps whatever the profile, against 1100-1600 fps on apr0.

Once the watchdog finds a finished job without its interrupt, mark the
engine and poll its completions with a 100 us hrtimer while it has jobs
in the ring. The poll and the interrupt handler share one service
routine, so finished jobs are given back the same way whichever sees
them first; the interrupt stays requested, and the watchdog still
handles timeouts and resets. Every arm of the timer is an
hrtimer_start() under hw_lock: on submission, from the watchdog, and
from the service routine while jobs remain.

This is linux#2509's completion poll ported to the multi-job ring.

Reported-by: AxxzyWasTaken <98161954+AxxzyWasTaken@users.noreply.github.com>
Link: #2509
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
T6041's apr1 wrapper does not end up like apr0's after the power-up
rows: 0x338-0x350, 0x430-0x448, 0x948 and 0xa50 stay 0, 0xc00 reads 0xf
against 0x7fffffff, and 0x018-0x044 show a shifted 0x001d00xx pattern,
whether the rows are written once or twice.

Read every wrapper row back after it is written. The first time an
instance's wrapper does not take its rows, log each such row with its
value before the write, the value written and the value read back,
followed by a count. If any row did not take, apply and check the rows
once more before the next job after the engine has completed one, while
the ring is empty and the engine idle, and log that count too. This
separates a block that ignores the writes, a block with a different
layout and a block that was not yet clocked at power-up. Bit 31 is left
out of the comparison: the 0x000-0x044 rows are written with it set and
read it back as 0 on apr0 too.

This is linux#2509's read-back ported to the multi-job ring.

Reported-by: AxxzyWasTaken <98161954+AxxzyWasTaken@users.noreply.github.com>
Link: #2509
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

@AxxzyWasTaken, could you run your J616c row on this head (2a93a0d)? It's #2509 again, but the poll now sits on #2620's multi-job ring, so the numbers you got on 44cc1db don't carry over. What would settle it:

  • apr0 and apr1 decode and encode fps (HQ and 4444), and whether the output matches apr0 byte for byte
  • apr1 should log completion found without an interrupt, polling every 100 us once, and apr0 shouldn't
  • the wrapper readback lines for apr1, if any appear (there should be none for apr0)
  • dmesg free of new errors

I'll post an M1 Pro decode no-regression row against #2620's hashes here.

The completion poll started the first time the watchdog found a finished
job that no interrupt had given back. On the multi-job ring that also
happens on engines whose line works: on an M1 Pro (T6000) the watchdog
finds a completion ahead of its interrupt on every module load, so the
engine was switched to the 100 us poll for good.

Remember whether the line has ever fired. Start the poll only for an
engine whose jobs finish while its line has never fired, as apr1 on the
M4 Max, and stop it as soon as an interrupt arrives.

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

Copy link
Copy Markdown
Contributor Author

M1 Pro (T6000) no-regression row, fleet77, module swap: #2620's head (64b404a) vs this PR's 2a93a0d, one boot.

One thing it turned up, and the reason for the new commit 69a9475: on this Mac the watchdog finds a finished job before its interrupt on every module load (#2620 logs that too, as its one-time completion found without an interrupt). 2a93a0d took that as a dead line and switched the engine to the 100 us poll for good, even though the line works. It cost no fps here, but it's wrong. 69a9475 starts the poll only for an engine whose line has never fired (apr1 on the M4 Max), and an interrupt ends it. KUnit 35/35, W=1 and checkpatch clean. A v4 vs 69a9475 row on the M1 Pro is queued.

@AxxzyWasTaken: please row 69a9475 rather than 2a93a0d. On your J616c, apr1 should log jobs finish without an interrupt, polling every 100 us once and apr0 should log nothing.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

M1 Pro (T6000) row on 69a9475, fleet77, module swap against #2620's head 64b404a, one boot:

  • Decode SHA 6/6 identical, the same hashes as before. fps equal (2160p HQ 771.3-771.7 vs 771.7-771.8, 2160p 4444 496.4 in both, 1080p within noise). MIXED, DRAIN 6/6, KILL x20, TWO and OOB 60/60 are identical, with 0 bad dmesg lines.
  • 69a9475 never logs jobs finish without an interrupt here: the line fires, so the poll never starts. The four completion found without an interrupt lines in this run all come from media: apple: prores: hardware ProRes decode on every APR engine, several jobs in the ring #2620's module (its one-time warning, once per load).

So on a Mac whose interrupt works, this PR now behaves exactly like #2620. What's left is the J616c row on 69a9475.

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

Adversarial Pre-PR Checklist Review (head 69a947526a34)

Requesting changes for §2 production-readiness blockers and a suspend lifecycle gap.

Blockers

  1. §2 Lab-only diagnostic code & boot-time dev_warn flood under spin_lock_irqsave (drivers/media/platform/apple/prores/apple-prores-drv.c:1255-1316, :1889-1899):

    • Commit 2a93a0df adds apr_apply_check(), wrapper_checked, and wrapper_recheck explicitly as a diagnostic probe ("This separates a block that ignores the writes, a block with a different layout and a block that was not yet clocked at power-up").
    • On every J616c boot, apr_hw_init() emits ~20+ dev_warn() lines (one per mismatched row plus summary) while holding spin_lock_irqsave(&apr->hw_lock, flags), and apr_device_run() rewrites all 62 wrapper registers on the next idle submission and logs an unconditional dev_warn() ("%u of %zu wrapper rows did not take after a completed job", even when 0).
    • This is a lab-only diagnostic path left in production code (§2) and violates the §5 regression bar (0 new kernel errors/warnings on boot). Remove the diagnostic read-back / second-pass rewrite and dev_warn flood from the driver.
  2. §2 Applying apr0's SCODEC wrapper table to apr1 + magic 100 us hrtimer poll (APR_FAST_POLL_US = 100):

    • apr1 sits outside SCODEC and visibly rejects or shifts a large subset of apr_t6041_wrapper_tunables (which came from a J616s apr0 trace), while APR_FAST_POLL_US = 100 polls around an uninvestigated missing AIC interrupt (IRQ 2010).
    • Writing an incompatible SCODEC wrapper table onto a non-SCODEC wrapper block and masking an unresolved interrupt routing issue behind a magic 100 us timer fails §2 ("no magic delay or depth"). Please either identify apr1's actual wrapper init / interrupt routing (or drop inapplicable SCODEC wrapper rows cleanly) and justify any unavoidable fallback without diagnostic mismatch writes.
  3. Suspend lifecycle gap (drivers/media/platform/apple/prores/apple-prores-drv.c:2681-2689):

    • apr_suspend() waits for !atomic_read(&apr->outstanding) and calls pm_runtime_force_suspend(dev), but never cancels &apr->poll (or &apr->watchdog). If the last job was retired by apr_watchdog() or apr_irq() while apr->poll was armed, the hrtimer remains queued across suspend. Cancel &apr->poll and &apr->watchdog in apr_suspend() once the ring drains (matching apr_cleanup()).

Other Checklist Notes (§1, §3, §4, §5, §6, CI)

  • §1 / §3 / §4 / §6: Binding (apple,prores.yaml), optional SCODEC window mapping (i >= 2 in apr_probe() with zero-initialized regs[4]), and t6041.dtsi node placement under / (matching t604x.dtsi) look structurally sound; all 6 commits have human identity + Signed-off-by: with no agent trailers, and the PR body has Assisted-by:.
  • CI & §5: Stacked on unmerged #2620 (media/prores-decode-v4-20261121) with 0 CI checks run on this PR. After addressing the blockers above and running CI, a J616c (M4 Max) HW row on the live head (apr0 + apr1 encode & decode, hashes, suspend/resume, 0 SELinux denials, 0 failed units, 0 new kernel errors) is still required.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Closing for now: apr1 needs its real interrupt routing and wrapper setup instead of a 100 us poll and the apr0 table; the binding and DT part can come back on its own.

@RyanTheTide RyanTheTide reopened this Nov 22, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Reopened and kept as a draft; the comment above lists what it still needs before review. cc @niteria

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.

2 participants