Skip to content

apple: G5P render and compute for J71t with the device's own firmware - #74

Closed
brkosebay wants to merge 50 commits into
OrchardLinux:mainfrom
brkosebay:apple-g5p-render
Closed

brkosebay wants to merge 50 commits into
OrchardLinux:mainfrom
brkosebay:apple-g5p-render

Conversation

@brkosebay

@brkosebay brkosebay commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Part 8 of 11 of the iPad 5 (J71t) series in this repository; merge after #117.

Problem

The A9 GPU (PowerVR-derived G5P) had no kernel driver, so the desktop rendered in software.

Change

Add the apple-g5p DRM driver: bindings and J71t DT, the render/compute UAPI, the firmware transport and recovery core, buffer VMs with cache visibility, typed render and compute submission, and the GEM exporter's CPU cache contract. The firmware recipe extracts the G5P firmware from the device's own IPSW (src/orchard/apple/agx_g5p.py), and DRM_APPLE_G5P is enabled for apple-16k.

Testing

  • Hardware: iPad 5 Wi-Fi (J71t). Hands-on testing on 2026-11-11 with an integrated build of this series, made before the final failure-path fixes, covered hardware rendering of the desktop and Firefox.
  • 2026-11-12: no further hardware test of this change beyond the above. The hardware results are from the release build tested on J71t that day (20+ warm restarts without a freeze); since then main took several PRs of this series in reworked form, so the top of this series no longer applies to exactly that kernel tree and has not been flown as it is now.
  • Host: the Linux test suite passes at this branch's head, and the kernel and m1n1 patch series apply on apple-16k and apple-4k. At the top of the series the applied kernel tree differs from the built release image only where main took earlier PRs of this series in reworked form, by the closed perf: apple: A9 memory port byte counters #123, and by the new G5P sleep refusal (drivers/drm 0045, not yet run on the device).
  • Other boards that share these drivers or compatibles have not been tested.

Dependencies

Depends on #117.

This branch is stacked on the PRs it depends on and carries their commits; the change of this PR is the commit "apple: G5P render and compute for J71t with the device's own firmware", and the merge commits after it bring the branch onto current main.

This update keeps the branch's history: it merges current main and the updated branch below it into this branch. Nothing is forced.

🤖 Generated with Claude Code

Add the A9 (S8003) G5P render driver used by the merged PowerVR/G5P Mesa
winsys as kernel patches, enable it on J71t in the device tree, set
CONFIG_DRM_APPLE_G5P=y for apple-16k, and add an install-time recipe that
extracts the original META LDR (apple/agx-g5p-c0.ldr) from the device's own
iOS kernelcache into /lib/firmware. No firmware is committed.

The driver provides TYPED_V3 rendering, GEM buffers, VM/arena mappings,
PRIME import/export, syncobj, bounded retirement and recovery. It does not
expose the old compute or fixed-fixture ABI.

Hardware: the exact kernel this derives from (brkosebay/linux a9/gpu-pr1
407b7bf2cbbe) booted on a J71t with the merged Mesa, rendered labwc on the
GPU with KMS scanout at 60 Hz, and passed the G5P device rungs with zero GPU
events. This Orchard adaptation itself has not yet been built by orchard or
run on hardware.

Assisted-by: LLM
kernel/configs/apple-16k/config:
CONFIG_DRM_APPLE_G5P=y
These options provide g5p and its Kconfig dependencies on both page sizes.

Assisted-by: LLM
kernel/configs/apple-16k/config:
CONFIG_APPLE_AOP_GYRO=m
CONFIG_APPLE_AOP_PRESSURE=m
These options provide aop and its Kconfig dependencies on both page sizes.

Assisted-by: LLM
kernel/configs/apple-16k/config:
# CONFIG_NVME_APPLE_ANS_EARLY_USB is not set
These options provide warm-storage and its Kconfig dependencies on both page sizes.

kernel/configs/apple-4k/config:
# CONFIG_NVME_APPLE_ANS_EARLY_USB is not set
These options provide warm-storage and its Kconfig dependencies on both page sizes.

Assisted-by: LLM
kernel/configs/apple-16k/config:
CONFIG_APPLE_AOP_GYRO=m
CONFIG_APPLE_AOP_PRESSURE=m
These options provide aop and its Kconfig dependencies on both page sizes.

Assisted-by: LLM
kernel/configs/apple-16k/config:
# CONFIG_NVME_APPLE_ANS_EARLY_USB is not set
These options provide warm-storage and its Kconfig dependencies on both page sizes.

kernel/configs/apple-4k/config:
# CONFIG_NVME_APPLE_ANS_EARLY_USB is not set
These options provide warm-storage and its Kconfig dependencies on both page sizes.

Assisted-by: LLM
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
A Mac grants an iPad more than the standard USB current, but the charger
took the gadget's reported budget unchecked and the composite gadget
could draw the extra current while the bus was suspended.

Cap and log the USB host budget in the TriStar charger, draw no extra
Apple current while suspended, and let the initramfs and orchard USB
helpers opt J71t into the Mac current profile. Documented in
docs/bring-up/charging/j71t-mac-current.md, with tests.

Assisted-by: LLM
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
The A9 AOP hosts the accelerometer, gyroscope, pressure and
ambient-light sensors. Its firmware needs boot arguments and per-device
calibration that m1n1 did not pass on S8003, and a reloaded AOP (after
kexec or sleep) lost its sensor firmware state, so the sensors did not
come back.

m1n1 passes the A9 AOP boot arguments and sensor calibration. The kernel
selects a certified AOP reload path through device-tree match data
(bindings, DT, mailbox, pmdomain, IIO and AOP driver patches), keeps the
AOP power domain and firmware state for that reload, and refuses a
suspend that would interrupt the firmware's boot. The J71t firmware
recipe gains the AOP pieces, the gyroscope and pressure drivers are
enabled, and J71t's accelerometer and gyroscope move from missing to
working, and its light sensor from untested to working.

Assisted-by: LLM
The USB serial number changed between installed boots and RAM sessions,
so the host saw a new device every boot and could not keep its SSH
known_hosts entry or serial console name.

Share one BOARD/hashed-ID serial format between installed boots and RAM
sessions (usb-identity), and get the per-boot SSH identity through the
existing ACM console. Documented in docs/device-protocol.md, with tests.

Assisted-by: LLM
Opening the Smart Cover should wake the iPad, but the PMIC GPIO driver
had no notion of wake-only events, and arming the cover events while the
cover was absent aborted every suspend.

Describe wake-only events in the apple,d2365-pmic-gpio binding, let the
driver wake from sleep on the listed GPIO events, and list the Smart
Cover events in the J71t DT.

Assisted-by: LLM
Bring this branch onto current main. The merge keeps the other side's
tree; the next commit carries the reworked version of this branch's
change.
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
Bring this branch onto current main and the series it depends on. The
merge keeps the other side's tree; the next commit carries the reworked
version of this branch's change.
A7-A9 have no EL2 and boot without any PSCI firmware, so Linux on an
iPad 5 could not bring secondary CPUs down and up again, and a kexec had
nowhere to park them. CPU hotplug, kexec and a clean poweroff all need a
PSCI implementation that stays resident after m1n1 hands over.

Carry m1n1 patches that keep a small EL3 PSCI implementation resident:
CPU_ON/CPU_OFF with a firmware rendezvous (EL1 WFI/WFE trap to EL3),
SYSTEM_OFF, and a guarded SYSTEM_RESET that boots the default entry
again. The loader marks retained hardware in the device tree after a
PSCI re-entry. The resident PSCI is on by default on these SoCs; the
shipped boot framing keeps psci_reset=0, so SYSTEM_RESET stays off
unless a loader enables it. Adds boot/m1n1/psci-loader and its tests.

Assisted-by: LLM
The A9 GPU (PowerVR-derived G5P) had no kernel driver, so the desktop
rendered in software.

Add the apple-g5p DRM driver: bindings and J71t DT, the render/compute
UAPI, the firmware transport and recovery core, buffer VMs with cache
visibility, typed render and compute submission, and the GEM exporter's
CPU cache contract. The firmware recipe extracts the G5P firmware from
the device's own IPSW (src/orchard/apple/agx_g5p.py), and DRM_APPLE_G5P
is enabled for apple-16k.

Assisted-by: LLM
@brkosebay brkosebay changed the title apple: G5P render support for J71t with the original device firmware apple: G5P render and compute for J71t with the device's own firmware Nov 12, 2026
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.

This branch's own patches in drivers/usb are renumbered to follow
main's.
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.

This branch's own patches in devices/s8000, drivers/base and drivers/usb
are renumbered to follow main's.
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.

This branch's own patches in devices/s8000, drivers/base and drivers/usb
are renumbered to follow main's.
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.

This branch's own patches in devices/s8000, drivers/base,
drivers/pmdomain and drivers/usb are renumbered to follow main's.
The A9 AOP driver on main reads apple,aop-target, apple,chip-id and
apple,chip-revision, and the motion sensor drivers read their factory
calibration, from properties the bootloader fills in. Nothing on main
fills them in; going by the driver's probe, the A9 AOP cannot start
without them (read from the code, not run). This is the m1n1 patch that
fills them in, from OrchardLinux#101, unchanged.

Assisted-by: LLM
From OrchardLinux#101, the part that main did not take with the sensors: the
retained AOP reload across kexec (checksummed shutdown log, power-state
observer, pr_flush export, warm_state attribute). The sensor parts that
main carries are left out of these patches; what remains applies on
top of main's AOP driver and its fresh-start order.

Assisted-by: LLM
From OrchardLinux#110, the part main did not take with the stable USB serial: the
platform layer embeds each supported board's pristine DTB and a
compatible-to-file map in the initrd. Before switching root, the initrd
copies the running board's tree to /run/orchard-kexec/pristine.dtb, or,
after a warm restart, the retained tree the previous kernel named with
orchard_warm.dtb=, and records the boot ID next to it. Warm restart
boots the next kernel with that tree, never with one rebuilt from an
updated /boot.

No feature table is added: whether warm restart is offered is decided
from the mechanisms it uses, not from a feature state.

Assisted-by: LLM
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.

This branch's own patches in devices/s8000, drivers/base,
drivers/pmdomain and drivers/usb are renumbered to follow main's.
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.

This branch's own patches in devices/s8000, devices/t8010, drivers/base,
drivers/media, drivers/pmdomain, drivers/power and drivers/usb are
renumbered to follow main's.

Main's versions apply first now, so 0011 in drivers/media keep their
change with a diff regenerated for the new context.
From OrchardLinux#101, the suspend precheck that main did not take with the
sensors. It belongs with suspend: it makes the AOP refuse a pre-sync
system sleep while its firmware is starting or stopping.

Assisted-by: LLM
From OrchardLinux#121, the patch main did not take with HEVC. It uses the VXD
sleep stop and sleep gate this branch adds, so it sits here rather
than with the earlier warm restart branch: a failed firmware stop keeps
the firmware, command buffers and power, and kexec takes the cold-reset
path before those pages become the next kernel's RAM.

Assisted-by: LLM
Bring this branch onto current main. Main has since merged OrchardLinux#124, OrchardLinux#122,
OrchardLinux#118, OrchardLinux#121, OrchardLinux#110, OrchardLinux#127, OrchardLinux#101, OrchardLinux#126, OrchardLinux#108 and OrchardLinux#111, several in part or
reworked, and OrchardLinux#123 and OrchardLinux#128 were closed. Where main carries a topic,
main's version is kept; the left-out parts that warm restart and
suspend need come back in OrchardLinux#107 and OrchardLinux#117.

This branch's own patches in devices/s8000, devices/s8003,
devices/t8010, drivers/base, drivers/media, drivers/pmdomain,
drivers/power and drivers/usb are renumbered to follow main's.

Main's versions apply first now, so 0011 in drivers/media keep their
change with a diff regenerated for the new context.
Bringing this branch onto main took main's devices/j71t/firmware.json,
which main rewrote with its AOP firmware, and lost the output the GPU
needs: lib/firmware/apple/agx-g5p-c0.ldr, extracted from the
kernelcache by agx-g5p-ldr-from-kernelcache@1 (src/orchard/recipe.py
still has the step). Without it the G5P driver finds no loader and the
GPU never starts ("autoboot stopped at validate (-2)").

Put the entry back after main's outputs, unchanged; the file is again
main's plus this one output.

Assisted-by: LLM
J71t's agx-g5p-c0.ldr output was lost when main's firmware.json was
merged in, while its recipe step stayed, and no test noticed: the GPU
simply never started. Assert that J71t ships the loader, and that every
step in orchard.recipe.STEPS is used by some board's firmware output,
which holds on main as well.

Assisted-by: LLM
henrikklee pushed a commit that referenced this pull request Nov 14, 2026
Berkay's driver maps one zeroed page at address 0 of the firmware's
address space on every boot, so an access there while the firmware
starts does not fault. The powervr backend left it out; with no hardware
run to show it is not needed, it does what his working driver does.

The bring-up page follows: the page is ported, the page tables' cache
clean is what pvr_mmu already does for every table it changes, and a new
section says what the job path has to bring from his compute and render
code.

[Orchard: ported from orchard PR #74 (apple-g5p boot.inc
g5p_boot_sink_init()) by Berkay Kösebay.]

Built for apple-16k; not run on hardware.

Assisted-by: LLM
henrikklee added a commit that referenced this pull request Nov 14, 2026
The A9's firmware takes a job as a work record the kernel builds. The
record's words that are userspace's (buffer addresses, the firmware's
program words) do not fit the Rogue commands, so the A9 gets one stream
extension per job type next to the A10's: geometry, fragment, compute.
They carry what the render and compute passes of Berkay Kösebay's
apple-g5p UAPI carried (orchard #74), less what the Rogue command and
the HWRT dataset already say. powervr's UAPI header is unchanged.

docs/bring-up/gpu/a9-g5p.md, "The job interface for userspace", defines
every field and where it goes; the Mesa port is built from it.

Assisted-by: LLM
henrikklee pushed a commit that referenced this pull request Nov 14, 2026
The iPad 5's GPU takes geometry, fragment and compute jobs through
powervr's UAPI now, so it can render once Mesa speaks its job format.

What a user gets with it:
- Programs each get their own address space on the GPU; up to two
  frames of one program are in the GPU at a time, a fragment job starts
  as soon as its geometry job is submitted.
- A job that hangs ends after 5 s together with the other jobs in
  flight. The firmware is stopped, the GPU's power domain goes off for
  at least 10 ms, and the next job boots the firmware again. Only the
  program whose job hung loses its GPU context; nothing stays frozen
  until reboot.
- The firmware is stopped a second after the last job and for sleep,
  and booted again on the next use.
- The parameter manager's memory (its pool, its tables, its free list)
  is the kernel's and out of a program's reach.

[Orchard: ported from orchard PR #74 with #119 and #125 by Berkay
Kösebay (apple-g5p render-user-layout.h, render-user-geometry.h,
render-user-msaa.h, render-user-bind.h, render-user-mmu.h,
render-user-pmset.h, render-user-wake.h, compute-user-layout.h,
drm-render-v3.inc, drm-render.inc, drm-compute-v1.inc), as the A9 chip
of the powervr driver's Apple firmware path. The work records, commands
and microsequences this writes are byte for byte what his headers
write for the same inputs (compared on the host for nine target sizes,
one and four samples). What was left out and where the backend differs
is recorded in docs/bring-up/gpu/a9-g5p.md.]

Built for apple-16k; not run on hardware.

Assisted-by: LLM
@henrikklee

Copy link
Copy Markdown
Contributor

Your A9 GPU work is now on main as part of the shared powervr driver, with you as author on the ported code: kernel in orchard #138, Mesa in OrchardLinux/mesa #8, desktop GPU check in omarchy-a #54, OpenGL (Zink) from our Mesa in omarchy-a #55. docs/bring-up/gpu/a9-g5p.md in orchard records what was ported, what was left out and why. This branch head is kept as tag contrib/brkosebay-apple-g5p-render. Closing as superseded; thank you.

@henrikklee henrikklee closed this Nov 14, 2026
henrikklee pushed a commit to brkosebay/hardware that referenced this pull request Nov 15, 2026
The A9's GPU (G5P) runs Apple's firmware on its own META processor. The
agx-g5p-ldr-from-kernelcache@1 step takes that firmware, a META LDR, from
AGXFirmwareKextG5P in the user's kernelcache and accepts only the C0 image
of iPadOS 16.7.10 (size and SHA-256 pinned).

From Berkay Kösebay's G5P work (OrchardLinux#74, 557ef01). Integrated next to the A10
step in orchard.apple.agx, and the J71t recipe writes the image as
lib/firmware/apple/gfx-s8003.bin, the name the GPU driver will request
(the A10's is gfx-t8010.bin). Only J71t gets the output: the image is
qualified on that board.

Assisted-by: LLM
henrikklee pushed a commit to brkosebay/hardware that referenced this pull request Nov 15, 2026
The A9's GPU gets its binding and its node: the Rogue core's registers,
Apple's Fender block, the gfx power domain, five interrupts and the
firmware file the J71t recipe produces (apple/gfx-s8003.bin). The node
is disabled and no driver matches it yet, so no board changes.

From Berkay Kösebay's G5P work (OrchardLinux#74, 557ef01): the register ranges,
power domain and interrupts are his node's, unchanged. Reworked for the
powervr driver's Apple firmware path, which will take the node: the
compatible and register names already follow the A10's node; the label
is gpu, the firmware name is set, and boards enable the node once that
driver binds it.

Assisted-by: LLM
henrikklee pushed a commit to brkosebay/hardware that referenced this pull request Nov 15, 2026
The powervr driver takes the iPad 5's GPU (A9, GT7600) next to the
A10's and starts Apple's firmware on it: it unpacks the tablet's own
firmware image, maps it with the firmware's shared memory and registers
into the kernel VM, programs Fender's boot stream, powers the core up
and waits for the firmware's "alive" event; then it gives the firmware
one empty command and waits until the firmware took it. When idle for a
second the firmware is stopped and the GPU powered off, and started
again on the next use.

One boot path: Apple's unmodified image, the firmware's governor pinned
to the power state the core starts in. The register addresses the
firmware is told and its interrupt number come from the device tree.

Nothing renders yet: the firmware's commands are not written, and no
context can be created. The core counts as experimental, so the driver
binds only with powervr.exp_hw_support=1; without it the probe wakes the
GPU's power block, reads the core's ID and powers it off again.

[Orchard: ported from orchard PR OrchardLinux#74 (apple-g5p boot.inc, boot-layout.h,
pack.h, fender.h, perf-envelope.h, lifecycle.inc) by Berkay Kösebay, as
a chip of the powervr driver's Apple firmware path. What was left out is
recorded in docs/bring-up/gpu/a9-g5p.md.]

Built for apple-16k; not run on hardware.

Assisted-by: LLM
henrikklee pushed a commit to brkosebay/hardware that referenced this pull request Nov 15, 2026
The powervr backend for the iPad 5's GPU carries one boot path of Berkay
Kösebay's apple-g5p driver. This page keeps the rest of what that driver
knows about booting the GPU: its alternate boot paths and why each
existed, the overclock, the firmware's own idle park, power cycling and
recovery, the two lost-GPU races of OrchardLinux#125, the register access rules,
timing values and register meanings, with what was measured on J71t. It
also maps each piece of his boot code to where it lives now.

[Orchard: written from orchard PR OrchardLinux#74, OrchardLinux#119, OrchardLinux#120 and OrchardLinux#125 (apple-g5p)
by Berkay Kösebay; the findings and measurements are his.]

Assisted-by: LLM
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