Skip to content

drm/imagination: apple: share S8003 PM pools between VMs - #121

Merged
henrikklee merged 2 commits into
OrchardLinux:mainfrom
brkosebay:submit/s8003-pm-shared
Dec 4, 2026
Merged

henrikklee merged 2 commits into
OrchardLinux:mainfrom
brkosebay:submit/s8003-pm-shared

Conversation

@brkosebay

Copy link
Copy Markdown

On the A9 every rendering VM pinned its own two PM pools, 16 MiB per allocated set. The firmware runs one scene at a time per VM, and the job dependency code orders a VM's geometry after the previous VM's fragment work, so at most two scenes are live at once across the system.

  • drm/imagination: apple: report S8003 PM pools in apple_jobs: live PM pool bytes (including replacements prepared for a later geometry job), and each reserved set's capacity, last firmware feedback and control words, in debugfs apple_jobs.
  • drm/imagination: apple: share S8003 PM pools between VMs: one pool per set index, shared by every VM, the way the A10 shares free-list pages. Each scene keeps 128 blocks, and pinned PM memory drops to 32 MiB in total. A wait for a previous user of a shared pool is counted (guard_waits). powervr.apple_pm_shared=0 restores per-set pools.

Tested on the iPad 5 (j71t), 2026-12-02, booted with these two commits:

  • a9 pm pools bytes 33554432 shared 1.
  • Every used idle set reads a full free stack (ctl24 4095, 128 × 32 − 1) at idle, after a glmark2 burst and after cross-client stress. guard_waits 0, no faults or timeouts.
  • glmark2 offscreen 222, the same as per-client pools. Two glmark2s plus shell panel cycles: 90 + 90.
  • Pinned PM memory: 32 MiB for all clients together, down from 32 MiB per rendering client.

Built for j71t with Orchard's kernel/build --kernel-tree (with the follow-up timestamp commit on top).

How to test

On a stock Orchard install with this kernel:

sudo grep '^a9 pm' /sys/kernel/debug/dri/*/apple_jobs      # "shared 1", 33554432 bytes
glmark2-es2-wayland --off-screen & glmark2-es2-wayland --off-screen; wait
sudo grep 'guard_waits' /sys/kernel/debug/dri/*/apple_jobs  # 0 expected

A/B: boot with powervr.apple_pm_shared=0. Expected on the iPad 5: the same scores, and PM memory no longer growing per client. A10: unchanged, because this is the S8003 (A9) path. The A10 already shares its free-list pages.

Account for live PM pool objects, including replacements prepared for a
later geometry job. Expose that total and each reserved set's capacity,
last firmware feedback and control words through apple_jobs.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A9 firmware runs one scene at a time per VM. The job dependency
code orders a VM's geometry after the previous VM's fragment work, so
up to two scenes can be live on the two sets of one VM. Each set's
free list names the PM pages directly.

Share one pool per set index between VMs, as the A10 shares free-list
pages. This keeps 128 blocks per scene and limits pinned PM pool memory
to 32 MiB, down from 16 MiB per allocated set. Count any wait for a
previous user of a shared pool and retain per-set allocation behind
apple_pm_shared=0.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
@henrikklee
henrikklee merged commit 2073d37 into OrchardLinux:main Dec 4, 2026
4 checks passed
henrikklee added a commit that referenced this pull request Dec 4, 2026
drm/imagination: apple: land #122, drop A9 debug switches from #121 and #126
@henrikklee

Copy link
Copy Markdown

Merged, thank you Berkay! Sharing one PM pool per set index between VMs means far less pinned memory per app, and the pool report in apple_jobs is a great help.

What changed after the merge: your fork doesn't accept maintainer pushes, so the cleanup landed as a follow-up in #141:

  • The apple_pm_shared module parameter is gone, and sharing is always on. Debug switches stay on your fork (CONTRIBUTING, "Bring-up material"); main carries the final form.
  • A comment at the shared-pool guard in s8003_submit_geom() now says what the guard relies on: a scene's geometry and fragment jobs are armed in one submission.

Nothing else was left out. One small follow-up you could pick up: with sharing always on, the per-set pool growth path in s8003_prepare_job() / s8003_pm_build() (next_pool, need_pool) can no longer run, so it could go.

Follow-up: the device numbers came from your integration kernel. A run of the merged main on an A9 device would be very welcome.

henrikklee pushed a commit to ricktav/linux that referenced this pull request Dec 4, 2026
The coded-format table was the H.264 unit's own array, installed whole
by apple_vxd_h264_register(). Make it a table of pointers in the device
that each codec unit appends to with apple_vxd_register_coded_fmt(), so
a second codec can sit next to H.264 without the core knowing about it.
The first unit registered stays the default OUTPUT format.

Add apple_vxd_buf_aux_cpu() and apple_vxd_buf_aux_size() next to
apple_vxd_buf_aux_va(): a codec that keeps per-picture state in the
CAPTURE side buffer needs to read and write it.

apple_vxd_cmdbuf_pair_chunk_end() had no user. Make it match the HEVC
per-picture chunk it was written for: AppleD5500 (0xfffffff0062b7ab0)
zeroes 0x40 - (pairs & 7) * 8 bytes past the write pointer and neither
counts them in the packet's byte count nor advances over them.

H.264 output is unchanged: its host command-stream compare still matches
the reference generator on all 76 pictures.

[Orchard: from orchard PR OrchardLinux#121, commit 4016f5e; unchanged]

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Link: OrchardLinux/orchard#231 (comment)
henrikklee pushed a commit to ricktav/linux that referenced this pull request Dec 4, 2026
AppleD5500 decodes HEVC with a register program of its own, distinct
from the AVC one: per slice segment a chunk with the 0x90000000
descriptor, the whole slice NAL by DMA ({0xb0000001, header bits, bytes}
and {0xa.., address}), the 0x30xx/0x34xx command registers and a slice
structure the core copies into the picture's slice parameter buffer
(0xf), each with a kind-1 packet (mailbox 0x81); then one chunk of
single register writes for the picture, the 0x50xx/0x54xx entropy and
0x70xx/0x71xx render registers with the output and reference surfaces
and the scaling lists, with a kind-4 packet (mailbox 0x88) that ends the
job.  The layouts come from the iOS 16.7.10 kext (picture path
0xfffffff0062960a0, per slice 0x62b37d4, per picture 0x62b7ab0) and are
listed register by register in the comments.

This builds that program from the V4L2 HEVC controls.  It is pure code,
like the H.264 builder, so it also builds on the host: a harness feeds
it x265 and VideoToolbox test streams and compares every command word,
slice structure and packet against an independent generator written from
the kext.

Supported: 8-bit 4:2:0, I/P/B, multiple and dependent slice segments,
tiles, WPP, long-term references, weighted prediction, PCM and scaling
lists.  Refused: other chroma formats and bit depths (the Main 10 output
layout is not established), more than 15 references.

The 15 hardware reference slots are named by the V4L2 DPB index; the
kext numbers them in its own DPB order, which never leaves the host.

Nothing calls the builder yet.

[Orchard: from orchard PR OrchardLinux#121, commit 4016f5e; unchanged]

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Link: OrchardLinux/orchard#231 (comment)
henrikklee pushed a commit to ricktav/linux that referenced this pull request Dec 4, 2026
Expose V4L2_PIX_FMT_HEVC_SLICE next to H.264: frame-based decoding with
Annex-B start codes (what FFmpeg's v4l2request hwaccel, GStreamer's
v4l2slh265dec and libva-v4l2-request send), the SPS, PPS, SLICE_PARAMS,
SCALING_MATRIX and DECODE_PARAMS controls, NV12 output.

Per picture the unit locates the slice NALs in the OUTPUT buffer,
resolves the DPB to CAPTURE buffers by timestamp and runs the builder.
The slice header's length comes from data_byte_offset, which FFmpeg and
libva count from the buffer and GStreamer from the slice's start code;
both are accepted.  ENTRY_POINT_OFFSETS is not offered: the hardware
does not take them (the kext never reads them from its slice header).

Buffers follow CHEVCDecoder: per context the four Genc buffers sized
from the picture, the intra, aux-line and stream-state buffers and the
slice structure buffer; per CAPTURE buffer the temporal MVs, fragment
pointer table, above parameters and the record the co-located picture's
words are read back from.  The kext's 1 MiB slice parameter buffer per
picture is one per context here, as it is only read while its picture
decodes.

The unit registers only when the SoC's match data gives the HEVC
parameters, and not on core revision 0x70600 (S8000 A0/A1), which needs
AppleD5500's BRN50577 dummy-picture workaround.

[Orchard: from orchard PR OrchardLinux#121, commit 4016f5e; context adapted to main, which does not carry the VXD sleep patches of PR OrchardLinux#117]

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Link: OrchardLinux/orchard#231 (comment)
henrikklee pushed a commit to ricktav/linux that referenced this pull request Dec 4, 2026
AppleD5500 advertises HEVCSupported for vxd-version 7, 9 and 10 and keys
its HEVC choices on that version (VACreateDecodeDeviceHEVC,
0xfffffff006293f2c, called with the ADT vxd-version): the aux-line and
stream-state buffers are scaled by 2 from version 9 on, versions 7 and 9
write 0x7474 twice after every slice structure, and the 0x701c line
split starts from 0x1800 instead of 0xc00 from version 10 on.  Give the
S8000 (vxd-version 7, A9) and T8010 (10, A10) variants those values,
which turns the HEVC unit on for both.

The J71t decodes HEVC bit-exact against software decoding; the T8010
has not been tried yet.

[Orchard: from orchard PR OrchardLinux#121, commit 4016f5e; the S8000 variant without the sleep_stop flag of PR OrchardLinux#117 (not on main); message updated: HEVC decodes on the J71t]

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Link: OrchardLinux/orchard#231 (comment)
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