Repository navigation
media: apple: add a scaler/CSC (MSR) mem2mem driver - #1162
RyanTheTide wants to merge 5 commits into
Conversation
Every Apple silicon SoC has one or more MSR engines: memory-to-memory scalers with a programmable colour-space converter, chroma resampling, flip/rotate and alpha fill. macOS reaches them through IOSurfaceAccelerator and VideoToolbox; Linux has had no driver, so scaling and YUV/RGB conversion fall back to the CPU or GPU. Hardware-version 10 (M1) through 22 (A18 Pro) program the engine through MMIO and signal completion with an interrupt. This first step binds the existing apple,scaler nodes for T6041 (M4 Pro/Max) and T8140 (A18 Pro): it attaches the MSR power domains with runtime-PM links, requires the DART, reads the identity and idle state, clears and masks the interrupt and keeps the engine idle. The video device and job submission follow once the RGB path is qualified on hardware. The DT nodes stay disabled, so nothing changes on existing systems. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The job path needs three pieces of register encoding that do not depend on the hardware being present, so add them with KUnit coverage first: - the formats the engine is known to take: 32-bit B,G,R,A (ARGB32 and XRGB32 in V4L2 terms), NV12/NV12M and P010, with their layout class, format code, subsampling descriptor and component order; - the colour-space converter: a 3x3 Q3.12 matrix with input and output offsets (2^-24 of full scale, 26-bit signed), derived from the Kr/Kb luma coefficients of BT.601, BT.709 and BT.2020 for limited and full range, in both directions; - the scaler ratio register, Q22 with the two lowest bits clear. The tests compare against the register values used for the same conversions in a capture of the engine on macOS 27 on an M4 Pro: all six matrices and the offsets match bit for bit. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Add the job builder the submission path will use: it turns a source image, a destination image and an optional colour matrix into the ordered register writes for one job, ending with the pre-start tag and START. It covers conversions without scaling, which are the common case (decoder output to RGB, RGB to encoder input): - read and write DMA: layout, format code, subsampling, plane addresses, strides, component order, picture and per-plane sizes; - alpha fill when the source has no alpha and the destination does; - chroma upsampling for 4:2:x sources and downsampling for 4:2:x destinations, ordered dither when going from 10 to 8 bits; - the scaler at 1:1 (filters off, unit Q22 ratios); - the CSC matrix, offsets and clamps; - the per-plane memory request words and control words the engine is driven with on every job. KUnit builds three 1080p jobs (NV12 BT.709 to ARGB32, ARGB32 to NV12, P010 BT.2020 to ARGB32) and checks that every register ends with the value the engine was given for the same job on macOS, and that nothing else is written. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Expose the engine as a V4L2 memory-to-memory device. The OUTPUT queue takes NV12, NV12M, P010, ARGB32 or XRGB32, the CAPTURE queue any of them at the same size. Y'CbCr to R'G'B' and back uses the colorimetry of the Y'CbCr side (BT.601, BT.709 or BT.2020, limited or full range); the R'G'B' side is full range and keeps the primaries and transfer function, since the engine only changes the encoding. Each job is written with MMIO in one go from the register list the job builder produces, START last. Completion and errors arrive on the MSR interrupt; an error or a 500 ms timeout fails the job and resets the engine through its power-domain reset before the next one. Interrupts are enabled on the first job after every power-up. Not yet tested on hardware: the DT nodes stay disabled until the qualification run. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
After every power-up and after a failed job, wait for the engine to go idle, write RESET 1 then 0 without reading anything in between (the register file does not answer while reset is held), wait for idle again, then clear stale status and enable the done and error interrupts. Only if the engine never goes idle fall back to the PMGR reset of its power domain and retry once; otherwise fail the job. This is the start-up order the engine expects on every generation from M1 Max onwards. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
|
First J616s hardware attempt (2026-11-08 04:54 AEDT), with the module built from 44d118c against 7.3.0-aurora-fleet27 and a one-shot trial DTB (never committed) that sets The driver never reached the hardware. Both nodes sit in the Next: retry with a trial DTB that also enables those two pwrstate nodes. The DT patch that enables the scaler on the J616s has to enable them too. |
|
J616s hardware PASS, second trial (2026-11-08 05:14 AEDT): the same module (44d118c, built for 7.3.0-aurora-fleet27) and a one-shot trial DTB (never committed) that also sets pmgr
|
Adds a V4L2 mem2mem driver for the scaler and colour-space converter (MSR) that every Apple silicon SoC has. Nothing on Linux used it, so YUV/RGB conversion and scaling fell back to the CPU or GPU.
Four commits:
apple,t6041-scalerandapple,t8140-scalernodes, attaches MSR-V and the ASE core domain with runtime PM links, requires the DART, reads the identity and idle state, masks and clears the interrupt.How the register values were found: a dtrace capture of the macOS driver on an M4 Pro (macOS 27.0) while known VideoToolbox and IOSurfaceAccelerator conversions ran. macOS feeds every job to the engine as a register stream, so the capture has each offset and value. All six CSC matrices the driver computes match what macOS programmed bit for bit, and KUnit rebuilds three captured 1080p jobs (NV12 BT.709 to ARGB32, ARGB32 to NV12, P010 BT.2020 to ARGB32) register for register. The hardware output of those jobs on macOS matched a software BT.601/709 reference within 1 LSB. Image-quality tuning seen in the capture (polyphase filter tables, de-ringing parameters) is not used; scaling comes later with filters generated from a public kernel.
Scope: hardware-version 10 to 22 (M1 to M4, A18 Pro) program the engine directly. Hardware-version 23 and later (M5, M6) put firmware in front and are not matched. The match table has T6041 and T8140 for now; the other direct-family compatibles follow once their bindings land.
Testing:
Draft until the hardware run.
🤖 Generated with Claude Code