Skip to content

media: apple: scaler: T8142 (M5) MSR23 - #2221

Merged
RyanTheTide merged 4 commits into
aurora-silicon:mainfrom
m0d16l14n1:j815/t8142-scaler-msr23
Nov 27, 2026
Merged

RyanTheTide merged 4 commits into
aurora-silicon:mainfrom
m0d16l14n1:j815/t8142-scaler-msr23

Conversation

@m0d16l14n1

@m0d16l14n1 m0d16l14n1 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What: a driver for the M5's scaler/CSC engine (MSR23, which sits behind a Cortex-M core) in apple-scaler. It covers conversion between BGRA, NV12/16/24, P010 and GREY, scaling up to 4x either way, crop, compose, quarter turns and flips. The T8142 DTS enables it. There are four commits: the binding, the driver, the geometry, and the DTS.
Tested: J815 (MacBook Air 15" M5) at 5f370f8cde82: the job suite compared byte for byte with macOS 27.2's output for the same input gives 51 identical and 21 differing by the generated filter taps (the scl-*/gd2-*/scaled geo* jobs), with 2 refused as designed (odd sizes). 22 generated jobs from the same table are 8 self-consistent and 14 identical plus consistent. The driver's suspend/resume path ran three times (resume 102 ms through msr23_restart()) and the suite gave the same 51/21/2 afterwards. 0 job errors, 0 DART faults. Regression at boot: 0 SELinux denials (SELinux off), 0 failed units, 0 new kernel errors.
Risk: two-way door. Only T8142 (M5) machines: the scaler node is enabled there and nowhere else, and the older MMIO generations (up to v22) take the same path as before.
Not yet: J704 / J813 rows (I have neither); the at-most-one-code-value bound of the differing jobs at this head (it needs the test module that loads other taps); 10-bit RGB (ARGB2101010), odd sizes and border fill around a compose rectangle.

Details

The AP doesn't program MSR23's registers. It hands the core block lists in a DMA ring, and the driver builds each job's register image from the job's parameters.

Firmware

  • Core image: iBoot pre-loads the core's __TEXT into its SRAM (ADT pre-loaded = 1), and the driver starts it. The variant's firmware file is uploaded only when the SRAM holds none and the core has never run: writing the SRAM under a core that has run hangs the machine. A file shorter than the reset vector or larger than the SRAM text is ignored with a warning.
  • Start-up: power-up register writes, core start, a hello from the mailbox, one init message and four shared pages.
  • Variant data: the firmware name and the power-up writes, each with the time to wait after it, so a later MSR23 SoC can reuse the code.

Jobs

  • Submission: a ring of block-list records in a shared page plus a write pointer; completion arrives through a status ring. A job whose status is an error, or belongs to another job, fails with -EIO and takes the core out of service, as a timeout does.
  • Builder (apple-scaler-msr23.c): sizes, strides and plane codes per side; scaler steps, initial phases and polyphase filter bins per axis; the colour matrix (asc_csc_compute()), chroma up/downsampling, and the dither of a 10-bit source written at 8 bits; the spill buffer size. The firmware tiles each job itself.
  • Filter taps: 8 ratio bins of 9 taps at 32 phases, generated from a stated design (a Kaiser-windowed sinc per scaling ratio) by tools/media/apple-scaler/msr23_filters.py, which also documents how the engine stores them. msr23_filters.py --check reports 0 differing words against the driver's table.
  • DART window: every plane of the source and the destination is checked over vb2_plane_size() before a job is queued.
  • Formats: B,G,R,A (V4L2 ABGR32, MSR23 only), NV12, NV16, NV24, P010 and GREY. Sizes: even, 64 to 4096 wide, up to 4K UHD in area. Scaling: up to 4x down or up per axis.
  • Geometry: OUTPUT crop and CAPTURE compose selections; V4L2_CID_ROTATE in quarter turns, and HFLIP/VFLIP mirroring the rotated picture; rectangles are even and at least 64 pixels. Rotate and both flips are grabbed while either queue streams.
  • Refused at STREAMON: a pair outside this range, quarter turns of 4:2:2, and a 1:1 conversion combined with a mirror or half turn.
  • Unbind: asc_cleanup() cancels the job work before v4l2_m2m_release(), so no job reaches the m2m device or the registers after either is gone.

Changed on this head (review of 4a69f01a3012): the unbind order, the firmware size checks, the per-plane DART window check and the control grab above, plus the suspend comment and an indent. Rebased onto main; it merges cleanly with main 8c6bd8d.

Build: checkpatch --strict clean (only the MAINTAINERS note for the new file; scaler/ is listed); each commit builds with W=1 as a module; the apple-scaler KUnit suite passes on arm64 QEMU (22/22); the T8142 J704/J813/J815 DTBs build. v4l2-compliance 1.32: 47/48, Cropping and Composing OK. The one failure is testM2MFormats's rule that the CAPTURE colorimetry equals the OUTPUT's, which a colour-space converter doesn't follow (an RGB capture of a Y'CbCr output).

Evidence

J815, macOS 27.2 stub, this head merged with the other J815 PRs into one test kernel on main 2943fff; module apple-scaler.ko from that kernel, bound to 305000000.scaler, /dev/video14.

run MATCH DIFF UNSUPPORTED job errors DART faults
suite at boot 51 21 2 0 0
suite after 3 suspend/resume passes 51 21 2 0 0
  • MATCH (byte-identical to macOS): every colour conversion (BGRA <-> NV12 at BT.601/709/2020, video and full range; BGRA -> P010, NV16, NV24; P010 -> BGRA), the 1/3, 1/4 and one-axis downscales, and the unscaled turns, flips and crops (BGRA, NV12, NV24, P010 and GREY, up to 4K).
  • DIFF: jobs that scale by a ratio whose taps the driver generates (scl-down2/up2/down1p5/up1p5/mixed/near1/small, scl-down2-nv12, the gd2-* sizes, 4K BGRA <-> 1080p NV12, and the scaled geo3/geo4 jobs, including the compose job, whose area outside the rectangle stays zero).
  • UNSUPPORTED: scl-odd-bgra (1002x564) and geo-letterbox (odd picture height): odd sizes are refused by design.
  • Generated jobs (other sizes from the same conversions): 8 CONSISTENT (0 bytes differ between runs), 14 MATCH + CONSISTENT, 12 RAN (reference itself a DIFF).

Results are the same across boots. msr23_filters.py --check: 0 differing words.

@m0d16l14n1
m0d16l14n1 force-pushed the j815/t8142-scaler-msr23 branch 2 times, most recently from d4dc7f1 to 7249b78 Compare November 19, 2026 08:49
@m0d16l14n1 m0d16l14n1 changed the title WIP: media: apple: scaler: T8142 (M5) MSR23, replaying captured macOS jobs media: apple: scaler: T8142 (M5) MSR23 Nov 19, 2026
@m0d16l14n1
m0d16l14n1 marked this pull request as ready for review November 19, 2026 08:49
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, this is a big step: a job builder that computes each job instead of replaying captures, with 43 jobs checked on J815 hardware. A few things:

  1. Board coverage. MSR23 and its core are part of T8142, so ps_msr, ps_msr_ase_core, scaler0_dart and scaler0 should be enabled in t8142-peripherals.dtsi, not only in t8142-j815.dts (lines 475-493). Please drop their status = "disabled" and the J815 overrides. If a board lacks the pre-loaded core image, the S0/S1 checks already handle that at probe.

  2. apple-scaler-drv.c:1869: the variant comment still says "no job path yet".

  3. The comment at apple-scaler-msr23.c:347-348 and parts of the description explain the code by reference to other software. Please describe the registers and the filter by what they are. If the 8 x 144 taps (msr23_filters, line 126 on) follow a known design, such as a windowed sinc with a given window and cutoff per ratio bin, please generate them from that and say so in a comment. The same goes for msr23_powerup (drv.c:906): tie the rows to the ADT nodes or register fields where you can. Please also trim the description to the design and the test results.

  4. Firmware name and power-up table are fixed T8142 constants in the MSR23 path. Putting them in the variant data would let a later MSR23 SoC reuse the code.

Rows: J815 is covered. Once the node is SoC-level, a J704 or J813 owner can run 1920x1080 BGRA to 1280x720 NV12 (BT.709, video range), 100 jobs. Pass: output byte-identical to the J815 output for the same input, no job error, no DART fault. We can run no-regression rows on our A18 Pro (Neo) and M4 Pro (MSR20 paths).

@m0d16l14n1
m0d16l14n1 force-pushed the j815/t8142-scaler-msr23 branch from 7249b78 to 3d722ce Compare November 19, 2026 14:23
@m0d16l14n1

m0d16l14n1 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@RyanTheTide thanks for the review. All four points are addressed in the new head 3d722ce:

  1. Board coverage. ps_msr, ps_msr_ase_core, scaler0_dart and scaler0 are now enabled in t8142-peripherals.dtsi, and there are no J815 overrides. J704, J813 and J815 DTBs build.
  2. Stale comment. Fixed: the variant now has a job path.
  3. Comments and description. The registers, the filter and the power-up rows are now described by what they do, with no references to other software. The rows are grouped by the aperture they write. The ADT gives these apertures no names, so there is nothing further to tie them to. The 8 x 144 taps are not a plain windowed sinc. They are asymmetric about the phase centre, and the phase-0 column carries a per-bin control word, so I left them as a table and said so in the comment. The description is trimmed to the design and the results.
  4. Variant data. struct apple_scaler_variant now carries the firmware name and the power-up table, and the T8142 entry fills them in.

Also new since your review: crop, compose, 90/180/270 rotation and flips, as a separate commit. On the J815, 26 geometry jobs are byte-identical to macOS 27.2 for the same input: crops, compose into a larger frame (the outside stays untouched), every rotation and flip of BGRA, NV12, NV24, GREY and P010, at up to 4K, combined with scaling and with colour conversion. The other 50 jobs still match, and there were no DART faults. KUnit passes 22/22.

The J704/J813 row you described (1920x1080 BGRA -> 1280x720 NV12, BT.709 video range, 100 jobs) should now run with no board changes.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the quick turnaround. The SoC-level enable, the variant data and the comment fix all look good, and J704, J813 and J815 build here with the scaler enabled on each.

One point is still open, the filter taps (apple-scaler-msr23.c:138). The table is unchanged; only its comment is new. We can't take the coefficients as a bare table. Please generate all 8 bins from a stated design (a script under tools/ or an init function): the kernel, the window, the cutoff and phase offset per bin, and what the per-bin word means. An asymmetric set can still come from a design, for example a fixed phase offset. If it doesn't reproduce the table exactly, a documented design is fine, with the J815 rows re-run against a stated tolerance.

Nit: apple-scaler-hw.c:58 still says MSR23 jobs are replays. The builder computes them now.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Two review points are still open on this head, so a short ping:

  • apple-scaler-msr23.c:138: the polyphase tap table is still a bare list of coefficients. Please generate it from named parameters (the filter kernel and the ratio bins) or explain where each set comes from in terms of the filter design; a coefficient set taken over from the engine's existing jobs as-is can't go in.
  • apple-scaler-hw.c:58 (small): the ABGR32 entry is marked msr23_only with a comment about replaying macOS jobs. Please describe the hardware reason instead (which scaler revision supports this layout), so the flag reads as a capability.

Everything else from the earlier rounds looks resolved. Thanks again.

@m0d16l14n1
m0d16l14n1 force-pushed the j815/t8142-scaler-msr23 branch from 3d722ce to 7f8e392 Compare November 20, 2026 10:15
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

@RyanTheTide both points are addressed in the new head 7f8e392 (squashed, so the series is still three commits on top of the binding):

  1. Filter taps (apple-scaler-msr23.c). The table is now generated from a stated design by tools/media/apple-scaler/msr23_filters.py. Each of the 8 ratio bins is one symmetric kernel sampled at 9 taps and 32 phases:

    • downscaling bins (s = 8/7, 4/3, 8/5, 2, 8/3, 4): sinc(x / s) under a Kaiser window of radius 3.5 s, beta 6.5, a low-pass at the output's Nyquist frequency;
    • upscaling bin: sinc(x) under a Kaiser window of radius 31/16, beta 5 (an interpolating 4-tap kernel);
    • 1:1 bin: pass-through.

    Each phase is normalised to unit gain and rounded to Q12, with the residual going to the largest tap. The script's docstring and the table's comment also describe how the engine stores the phases (1..15 as is, the mirror phases omitted, column 0 holding phase 0 and half of phase 1/2). The comment says to regenerate the table rather than edit it. tools/media/apple-scaler/ is added to the MAINTAINERS entry.

  2. ABGR32 (apple-scaler-hw.c). The comment now states the capability: MSR23 jobs carry the source's alpha byte through to a B,G,R,A output. The earlier engines' alpha handling isn't verified, so they keep offering only ARGB32/XRGB32.

J815 results (MacBook Air 15" M5, against macOS 27.2's output for the same input, 76 jobs: colour conversions at BT.601/709/2020 video and full range, scaling from 1/4 to 4x, NV12/P010/GREY/NV16/NV24, 4K, crops, rotations and flips):

taps byte-identical differs worst
set captured from macOS's jobs (test-only module option, not in this PR) 76 / 76 0 none
generated (this PR) 52 / 76 24 max 1 code value per sample, PSNR 57.8 dB

The captured set reproduces macOS exactly, so the job builder itself is right. The generated taps stay within one code value of Apple's filter. Two further jobs were skipped as intended, because the driver rejects their odd sizes. KUnit and checkpatch are clean.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for 7f8e392. Generating the taps from a stated design (Kaiser-windowed sinc per ratio bin, the 1:1 pass-through, Q12 rounding) with the script in tools/media/apple-scaler/ is what we hoped for, and the note to regenerate rather than edit the table helps. Describing ABGR32 as the MSR23 alpha pass-through, with the earlier engines left out because their alpha handling isn't verified, reads as a capability now. Within one code value of the reference on 24 of 76 jobs and identical on the rest is a good result. Both points are resolved from our side.

…abled

The binding keeps every firmware-fronted scaler disabled until its
firmware handoff, clocks, power and reset ownership are qualified. On
the M5 (T8142) they are: the driver starts the firmware core from the
image iBoot pre-loads, with the two power domains, and runs jobs on the
MacBook Air 15" M5. Keep the T6050 and T8152 instances disabled.

Signed-off-by: Nick <[email protected]>
@m0d16l14n1
m0d16l14n1 force-pushed the j815/t8142-scaler-msr23 branch from 7f8e392 to e6a33be Compare November 22, 2026 03:21
@m0d16l14n1

m0d16l14n1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Housekeeping only: the four commits had an Assisted-by trailer in the message, which the project's rule now keeps out of commits. They are re-made without it, on the same base and with an identical tree (git diff 7f8e3920 e6a33beb is empty). New head: e6a33beb. The description ends with the disclosure line instead of the old "Generated with" line.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of e6a33be: no code blockers; one body fix and one small code point.

Earlier points, at this head:

  • Resolved. The scaler, its DART and both power domains are enabled in arch/arm64/boot/dts/apple/t8142-peripherals.dtsi with no board overrides. The firmware name and power-up writes are variant data.
  • Resolved. The tap table (drivers/media/platform/apple/scaler/apple-scaler-msr23.c:149) is the generator's output: tools/media/apple-scaler/msr23_filters.py --check on this head's apple-scaler-msr23.c reports 0 differing words in all 8 bins.
  • Resolved. The ABGR32 entry describes the MSR23 alpha pass-through as a capability (apple-scaler-hw.c:56-62).

New:

  1. The PR description no longer matches the code. It says the filter taps "are the engine's coefficient set, kept as is for bit-exact output" and that 76 jobs are byte-identical. The table is generated from the Kaiser-windowed sinc design, and the commit message of ac50325 says that, with those taps, 52 of 76 are identical and 24 differ by at most one code value. Please restore the generated-taps wording and that result in the description. The commit message of 8773b05 should also say which taps its 26 geometry jobs ran with.
  2. drivers/media/platform/apple/scaler/apple-scaler-drv.c:1346-1347: if (i == 1) usleep_range(...) ties the post-reset settle to the second entry of the T8142 table, inside the generic start path. Now that the table is variant data, a later SoC whose reset pulse sits elsewhere would get the delay at the wrong write. A per-entry delay field in struct msr23_wr (apple-scaler-drv.c:1088), set on the reset-release write, keeps it with the data.

Rows: the J815 76-job set on this head, with the generated taps. The J704 or J813 row (1920x1080 BGRA -> 1280x720 NV12, BT.709 video range, 100 jobs, byte-identical to the J815 output) is still open for an M5 owner. Our Neo and M4 Pro MSR20 no-regression rows will run on e6a33be.

Assisted-by: LLM (Claude:Opus 5.5)

@m0d16l14n1
m0d16l14n1 force-pushed the j815/t8142-scaler-msr23 branch from e6a33be to 4a69f01 Compare November 22, 2026 05:29
@m0d16l14n1

m0d16l14n1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@RyanTheTide thanks, both done in 4a69f01a:

  1. Description and messages.
    • The description now has the generated-taps wording: a Kaiser-windowed sinc per ratio, from msr23_filters.py, whose --check gives 0 differing words.
    • It also gives both results: all 76 jobs are byte-identical with the captured set, and with the generated taps 52 are byte-identical and 24 are within one code value (≥ 57.8 dB).
    • The geometry commit's message now says its 26 jobs matched macOS byte for byte with the captured set loaded in place of the generated taps. With the generated taps, they are part of the previous commit's 76-job result.
  2. Settle delay. struct msr23_wr has a settle_us field. The T8142 table sets 1000 on the reset-release write ({0, 0x00004, 0x00000000, 1000}), and the start loop waits usleep_range(settle_us, 2 * settle_us) after any write that has one. The i == 1 test is gone. The driver commit's message says that the variant data carries the delay.

The only code change is in apple-scaler-drv.c (+9/-7); the other commits keep their patches. Checks on this head: each commit builds with W=1 as a module, checkpatch --strict reports nothing, and the apple-scaler KUnit suite passes 22/22 on arm64 QEMU.

Rows: the J815 76-job set on this head with the generated taps is owed by me. The J704/J813 row is still open for an M5 owner.

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

Formal §1–§6 pre-PR review at 4a69f01a301253e1ebd76f0540f944210908f142 (against live integration/aurora 70a00e583b03): REQUEST_CHANGES.

Audit Summary (§1–§4, §6)

  • DT / Attribution / Policy / CI (§1–§4, §6): PASS — not superseded on integration/aurora, mergeable: clean, all live CI checks green (host-tests, kunit, rust-build, source, dt-checks, DWC3/ATC matrix). T8142 scaler, DART, and both power domains are enabled at SoC level (t8142-peripherals.dtsi), firmware name and power-up writes + settle_us live in variant data, filter taps are generated from a stated Kaiser-windowed sinc design (tools/media/apple-scaler/msr23_filters.py), all 4 commits carry human author/committer + human Signed-off-by: only, and PR body disclosure + naming are clean.

Code & Lifetime Blockers

  1. LIFO devm teardown UAF and MMIO-after-powerdown on unbind (drivers/media/platform/apple/scaler/apple-scaler-drv.c:1793, 1879, 1894, 1925):
    • asc_v23_probe() registers msr23_cancel_work at :1793 before msr23_put (:1879) and asc_register_video() -> asc_cleanup (:1925).
    • Because devres actions unwind LIFO on remove/unbind, asc_cleanup calls v4l2_m2m_release(asc->m2m_dev) and msr23_put calls pm_runtime_put_sync_suspend(dev) while msr23_work() can still be queued or executing, before msr23_cancel_work ever runs cancel_work_sync(&m->work).
    • An in-flight job will touch powered-down MMIO registers and hit a use-after-free on asc->m2m_dev in asc_finish() -> v4l2_m2m_job_finish(). Cancel m->work inside asc_cleanup (right beside cancel_delayed_work_sync(&asc->watchdog), before v4l2_m2m_release), or register the cancel action strictly after asc_cleanup/video_register_device.
  2. Unchecked fw->size in msr23_s0() and msr23_s1() -> slab/MMIO out-of-bounds read (drivers/media/platform/apple/scaler/apple-scaler-drv.c:1216-1231, 1255):
    • In msr23_s0(), size_t len = fw ? fw->size : MSR23_TEXT_SIZE; is passed directly to kvmalloc(len) and memcpy_fromio(buf, w5, len) followed by memcpy(vec, buf, sizeof(vec)). A truncated on-disk firmware file (fw->size < sizeof(vec)) causes a heap OOB read in memcpy(vec, buf, 8); an oversized file (fw->size > MSR23_SRAM_TEXT_MAX) reads past SRAM into core DRAM/MMIO or past w[5]'s ioremap.
    • In msr23_s1(), if (fw->size > MSR23_SRAM_TEXT_MAX || !msr23_text_valid((const u32 *)fw->data)) is missing a fw->size < 2 * sizeof(u32) bounds check before dereferencing fw->data as two u32 words.
  3. Incomplete DART window validation for multi-planar & spanning buffers (drivers/media/platform/apple/scaler/apple-scaler-drv.c:1603-1609):
    • msr23_run() only checks msr23_in_window(vb2_dma_contig_plane_dma_addr(src, 0), 1) and dst, 0 with length 1.
    • For multi-planar V4L2_PIX_FMT_NV12M, plane 1 is a separate DMA allocation and is never checked against [MSR23_WIN, MSR23_WIN + MSR23_WIN_SPAN). Passing length 1 instead of the plane's mapped size (vb2_plane_size(vb, k) / sizeimage) also allows buffers starting inside the window to overrun its upper bound. Validate every plane across its full byte length (and including out.dst_off[k]).
  4. Unsynchronized hflip/vflip control race + mid-stream invalidation (drivers/media/platform/apple/scaler/apple-scaler-drv.c:816, 831, 874-878, 1535, 1721-1736):
    • asc_start_streaming() grabs only ctx->rotate_ctrl, leaving V4L2_CID_HFLIP and V4L2_CID_VFLIP mutable while streaming.
    • asc_s_ctrl() writes ctx->hflip/ctx->vflip under asc->lock while msr23_work() runs on system_dfl_wq without asc->lock and reads them in msr23_job_of() (unsynchronized data race / torn H+V update).
    • Toggling hflip/vflip mid-stream on a 1:1 CSC job that passed STREAMON also hits msr23_check()'s rejection (s->rgb != d->rgb && sw == dw && sh == dh && (msr23_orient(job) & 0x70)) and starts failing queued buffers with -EINVAL. Grab hflip/vflip while streaming alongside rotate_ctrl (or snapshot under lock and enforce validity).
  5. Minor cleanup nits (fix while touching apple-scaler-drv.c):
    • apple-scaler-drv.c:995: stale comment (/* MSR23 has no m2m device yet; its core is lost and not restarted (logged on resume). */) — MSR23 now registers m2m_dev and asc_resume() calls msr23_restart().
    • apple-scaler-drv.c:1957: stray double-tab indentation on struct resource *res;.

§5 Evidence Blockers

  1. Exact-head hardware & regression evidence still owed on 4a69f01a3012:
    • J815 (M5 Air 15") rerun of the 76-job suite with the generated taps on head 4a69f01a3012, plus a boot regression row (0 SELinux denials, 0 failed units, 0 new kernel errors) and a suspend/resume check exercising msr23_restart().
    • J704 / J813 (other T8142 M5 board) verification (since MSR23 is enabled SoC-wide in t8142-peripherals.dtsi).

The M5's scaler (MSR23) is fronted by a Cortex-M core: the driver no
longer programs the engine's registers but hands the core block lists in
a DMA ring. Bring it up:
- start the image iBoot pre-loads into the core's SRAM (or upload the
  variant's firmware file when the SRAM holds none and the core has never
  run: writing the SRAM under a core that has run hangs the machine);
- write the engine's power-up registers, start the core, take its hello,
  and send the init message and the four shared pages;
- submit jobs through the block-list ring and collect their status from
  the status ring. A job whose status is an error, or whose status entry
  belongs to another job, fails and takes the core out of service, as a
  timeout does.

The firmware file name and the power-up writes, each with the time to
wait after it (1 ms after the reset release on T8142), are variant
data, so a later MSR23 SoC can reuse the code.

Each job is a register image the firmware streams into the engine. The
driver builds it from the job's parameters (apple-scaler-msr23.c): sizes,
strides and plane codes per side, the scaler's steps, initial phases and
polyphase filter bins per axis, the colour matrix (asc_csc_compute()),
chroma up/downsampling, the dither of a 10-bit source written at 8 bits,
and the spill buffer size. Words that are the same in every job are a
defaults table. The polyphase filter taps (8 bins of 9 taps, 32 phases)
are generated from a stated design, a Kaiser-windowed sinc per scaling
ratio, by tools/media/apple-scaler/msr23_filters.py, which also documents
how the engine stores them. The firmware tiles the job itself (job word
0x72000000), so no tile array is built.

The engine takes B,G,R,A (V4L2 ABGR32, added for MSR23 only), NV12,
NV16, NV24, P010 and GREY, even sizes from 64 to 4096 wide and up to 4K
UHD in area, and scales up to 4x down or up per axis. Y'CbCr to Y'CbCr
keeps the matrix and range. Formats are limited to that range, and
STREAMON refuses a pair outside it.

Tested on the MacBook Air 15" M5 (J815) against macOS 27.2's output
for the same input, over 76 jobs: BGRA <-> NV12 at BT.601/709/2020,
video and full range; BGRA -> P010, NV16 and NV24 and P010 -> BGRA; BGRA
scaling from 1/4 to 4x, on both axes or one; NV12, P010 and GREY scaling;
4K BGRA -> 1080p NV12 and back; the conversions at seven sizes from VGA
to 4K; and crops, rotations and flips. With the coefficient set captured
from macOS's own jobs loaded in place of the generated one, all 76 are
byte-identical, which checks everything but the taps. With the generated
taps, 52 are byte-identical and 24 differ by at most one code value per
sample (PSNR 57.8 dB or better).

Add KUnit tests for the builder: a BGRA -> NV12 conversion, scaling
steps and phases, the rejected jobs and the block list.

Signed-off-by: Nick <[email protected]>
The M5 (MSR23) engine reads a rectangle of the source, writes into a
rectangle of the destination, rotates in quarter turns and mirrors.
Expose these as the OUTPUT crop and CAPTURE compose selections and the
V4L2_CID_ROTATE, V4L2_CID_HFLIP and V4L2_CID_VFLIP controls.

- Crop: the source region's size, and its origin per plane in samples of
  that plane; plane sizes and pointers stay those of the whole picture.
- Compose: a picture of the rectangle's size at an offset into the
  destination planes. The rest of the CAPTURE buffer is left as it is.
- Rotation and flips: block 0 +0x64 bits 3-6, a quarter-turn count, then
  mirrors of the rotated picture. The reader rotates, so the scaler and
  the output window work in the destination's orientation.
- A conversion at 1:1 with a quarter turn runs its matrix where a scaled
  job does (block 11); in block 3 the rotated output is wrong. With a
  mirror or a half turn, a 1:1 conversion has not been checked and is
  refused, as are quarter turns of 4:2:2.
- Rectangles are even and at least 64 pixels, like the formats. They
  survive a format change they still fit (v4l2-ctl sets the CAPTURE
  format again when it starts streaming).
- Rotation and both mirrors are fixed while either queue streams: the
  job worker reads them without the device lock, and a mirror can make
  a checked 1:1 pair invalid.

Same-format jobs at 1:1 now take the source's component sizes in the
channel map, as scaled jobs do: before, luma above half scale came out 1
lower.

Tested on the MacBook Air 15" M5 (J815): with the coefficient set
captured from macOS's jobs loaded in place of the generated taps, 26
geometry jobs give output byte-identical to macOS 27.2 for the same
input: quarter and half turns and flips of BGRA, NV12, NV24, P010 and
GREY up to 4K, with and without scaling and conversion; crops of BGRA,
NV12 and P010 with and without scaling and conversion; and compose. The
50 jobs without geometry still match. With the generated taps, these 26
are part of the previous commit's 76-job result (52 byte-identical, 24
within one code value). v4l2-compliance: cropping and composing pass.

Add KUnit tests for the crop and compose words, the orientation codes,
the rejected rectangles and rotations, and the channel map.

Signed-off-by: Nick <[email protected]>
The MSR23 scaler, its DART and its two power domains are part of the
T8142 SoC: enable them in the SoC's peripherals, not per board. A board
whose SRAM holds no pre-loaded core image and that has no firmware file
fails the probe cleanly (-ENOENT).

Tested on the MacBook Air 15" M5 (J815).

Signed-off-by: Nick <[email protected]>
@m0d16l14n1
m0d16l14n1 force-pushed the j815/t8142-scaler-msr23 branch from 4a69f01 to 5f370f8 Compare November 24, 2026 03:38
@m0d16l14n1

m0d16l14n1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Head is now 5f370f8cde82; the fixes are squashed into the commits that introduced each line.

  1. Unbind order: asc_cleanup() now runs cancel_work_sync(&asc->msr->work) after the watchdog cancel and before v4l2_m2m_release(). devres runs it before msr23_put() and msr23_cancel_work(), so no job can reach the m2m device or the registers after either of them.
  2. Firmware size: msr23_s0() warns about a file shorter than the reset vector or larger than MSR23_SRAM_TEXT_MAX and then ignores it. The SRAM is checked as if no file were present. msr23_s1() refuses files under 2 * sizeof(u32) before it reads the vector.
  3. DART window: a new msr23_vb_in_window() checks every plane of the source and the destination over vb2_plane_size(). Compose offsets fall inside the plane, so that check covers them.
  4. Controls while streaming: rotate, hflip and vflip are all grabbed in start_streaming. They are released in stop_streaming once neither queue is streaming. msr23_work() therefore reads values that cannot change underneath it, and a mirror can no longer invalidate a pair that already passed the check.
  5. Nits: the suspend comment and the struct resource *res; indentation are fixed.

Build: the new head builds as an external module against the J815 kernel with W=1 and no warnings.

Hardware so far: on the J815 (7.3.0-aurora-j815-dev), a module carrying the same four fixes and two local-only extra controls loads, runs its jobs, unloads, and lets the boot module rebind with a clean dmesg.

This is not the exact-head evidence you asked for. The next J815 boot runs the exact 5f370f8cde82 module through:

  • the 76-job suite;
  • the regression row: SELinux denials, failed units, new kernel errors;
  • a suspend/resume pass that goes through msr23_restart().

I'll post the numbers here. I have no J704 or J813, so that row needs someone with one of those boards.

@github-actions github-actions Bot added area:bringup Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) labels Nov 24, 2026
@github-actions github-actions Bot added needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at 5f370f8c: ready to merge

Check Detail
CI at head ok 9 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 5f370f8c
Conflicts ok none
PR text ok Risk: two-way · . Only T8142 (M5) machines: the scaler node is enabled there and nowhere else, and the older MMIO generations (up to v22) take the same path as before.

Areas: area:bringup, area:media
Merge: gh pr merge 2221 --merge (Owners and Core through the bypass: add --admin).

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

@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

The exact-head rows for 5f370f8cde82 are in, and the description now leads with them.

J815 (MacBook Air 15" M5), this head merged with the other J815 PRs into one test kernel on main 2943fff; apple-scaler.ko from that kernel.

row result
Job suite against macOS 27.2's output 51 byte-identical, 21 differ (only jobs that scale by a ratio whose taps the driver generates), 2 refused by design (odd sizes). 0 job errors, 0 DART faults.
Generated jobs 8 consistent between runs, 14 identical and consistent.
Suspend/resume the driver's suspend and resume ran three times (resume 102 ms through msr23_restart()); the suite afterwards gave the same 51/21/2.
Regression (boot) 0 SELinux denials (SELinux off), 0 failed units, 0 new kernel errors.

The head merges cleanly with main 8c6bd8d.

Not measured at this head: the at-most-one-code-value bound of the 21 differing jobs, because it needs the test module that loads other taps. Also still open are the J704 and J813 rows, since I have neither board.

@github-actions github-actions Bot added blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 25, 2026

@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 5f370f8cde82: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: one J813 or J815 at this head with the scaler doing a crop, a rotation and a flip, then an unbind and rebind with a job in flight.

Checked: no Apple material, no gates. The unbind order is fixed: cancel_work_sync() runs before v4l2_m2m_release(), and the fixes are squashed into the commits that introduced each line. CI green. Thanks.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 25, 2026 05:43

Superseded by the review at 5f370f8

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) ready-to-merge Meets the merge policy: merge it (bot) labels Nov 25, 2026
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

Merge it please

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Nov 26, 2026
@RyanTheTide
RyanTheTide merged commit 124e30a into aurora-silicon:main Nov 27, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:bringup Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants