Skip to content

drm/imagination: apple: give the A9 firmware its job records uncached - #126

Merged
henrikklee merged 1 commit into
OrchardLinux:mainfrom
brkosebay:a9/fw-uncached-records
Dec 4, 2026
Merged

henrikklee merged 1 commit into
OrchardLinux:mainfrom
brkosebay:a9/fw-uncached-records

Conversation

@brkosebay

@brkosebay brkosebay commented Dec 3, 2026 •

Copy link
Copy Markdown

What

The A9 (S8003) path now gives the firmware its job channels (records, microsequences, pointer rings, commands, stamps, timestamps) and its PM sets through META's uncached window: the channels sit in the root memory after its objects, the PM sets in the root's 16 MiB window. Before, both were in the shared memory, which the firmware reaches through its cached window.

Two probe-time switches keep the old layout one boot parameter away: powervr.apple_ch_uncached and powervr.apple_pm_uncached (both default 1). powervr.apple_touch (default 1, runtime) switches the 1 ms firmware-memory touch off, so a tester can check whether the uncached layout still needs it.

Why

Apple's kext hands the A9 firmware every per-job object through the uncached window (iPad 5, iOS 16.7: channel states at 0x43200000, a TA's record at 0x43230e80, its PM record at 0x43469880). Our A8 and A7 paths already do this. In the cached layout, 57 % of 3D→TA handoffs took ~300 µs instead of ~125 µs. iOS's handoff for the same kind of pass is 62–118 µs.

Result (iPad 5, j71t)

Firefox scrolling a YouTube page by finger, 10 s per run. The firmware's time from a job's end to its finish interrupt is a kernel-only measurement:

Short jobs Before This PR
TA end → finish IRQ, p10 186 µs 32 µs
3D end → finish IRQ, median 257 µs 80 µs
GPU jobs per 10 s 21.3k 24.2k

The frame rate rose from 18 to 22.1–23.7 fps presented (labwc), and renders from 816/s to 966–1133/s. That measurement also had a Mesa change in it, barrier precision (OrchardLinux/mesa#53). With that Mesa change switched off, this kernel gave 20.9 and 17.7 fps, so the kernel alone did not raise fps measurably over the 18 fps baseline. The gain needs both changes. No GPU faults in any run.

These runs used our integration kernel, which carries this commit together with other work that is not upstream yet. This head is the same change, rebased onto main and build-tested only: drivers/gpu/drm/imagination/ compiles with W=1 under orchard_apple16k_defconfig and orchard_apple4k_defconfig. One line of the flown version is left out: an apple_jobs layout line, because the A9 has no apple_jobs hook on main.

Merging: this applies on main. It conflicts textually with #122, which changes the same file nearby. #124 merges cleanly.

A10 and A8

This change is A9-only. Only s8003_variant_a9 gets root_channel, and the A8 and A7 keep channels_root and S8003_PM_SETS_VA. A10 (G9P) code is untouched.

How to test

On an iPad 5:

  1. Boot as usual and scroll a long page in Firefox. The default layout is the uncached one.
  2. Reboot with powervr.apple_ch_uncached=0 powervr.apple_pm_uncached=0 for the old layout, then repeat the scroll and compare frame rates.
  3. cat /sys/module/powervr/parameters/apple_ch_uncached shows which layout is in use.

Expected A9 result: shorter GPU job turnaround on the new layout, with no GPU faults in dmesg. Together with the Mesa barrier-precision change, a scroll goes from about 18 fps to 22–24 fps.

🤖 Generated with Claude Code

Apple's kext hands the A9 firmware every per-job object through META's
uncached window: on the iPad 5 under iOS 16.7 the channel states are at
0x43200000, a TA's W at 0x43230e80, its PM record at 0x43469880 and the
stamps at 0x43438000. The A8 and A7 paths keep their channels there too.
The A9 path had its channels (records, microsequences, pointer rings,
commands, stamps, timestamps) and its PM sets in the shared memory,
which the firmware reaches through its cached window.

In that layout 57 % of the 3D->TA handoffs on a YouTube finger-scroll
take ~300 us against ~125 us for the rest, with the same records; iOS's
Metal gap for the same kind of pass is 62-118 us at any size, and its
TA->3D handoff is ~165 us in its own firmware trace. No microsequence
word selects the slow finishes; the window the firmware reaches the job
objects through is the structural difference.

Put the A9's channels in the root memory after its objects, and its PM
sets in the root's 16 MiB window, as Apple does. On an iPad 5 this cuts
the firmware's end-to-finish-interrupt time for short TA jobs (p10) from
186 us to 32 us and the median short 3D job from 257 us to 80 us, and
the GPU runs 14 % more jobs while Firefox scrolls a YouTube page.

Both moves are switches read at probe (apple_ch_uncached,
apple_pm_uncached, default on), so the old layout stays one boot
parameter away, and s8003_touch() gets a runtime switch (apple_touch).
The A8 and A7 variants have no root_channel and are unchanged.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
@henrikklee
henrikklee merged commit baccc4b 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! Moving the A9 job records and PM sets into the firmware's uncached window, as Apple's kext does, is a great find, and the measurements made the case clear.

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

  • The apple_ch_uncached, apple_pm_uncached and apple_touch module parameters are gone. The uncached layout is always on, and s8003_touch() still runs wherever the variant needs it. Debug switches stay on your fork (CONTRIBUTING, "Bring-up material").
  • The comment explaining the layout moved to pvr_apple_s8003_init(), where the layout is now chosen.

Nothing was left out. 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 AUSB PHY has separate tunables for the device and the host role. The
driver always loads the device tunables, and its set_mode callback was
disabled, so a host controller sharing the PHY ran it with device
tunables.

Implement set_mode as iOS does when it moves the port between the two
roles: load the tunables of the new role, clear the trim word at 0x1c,
then pulse the PHY reset. AUSB_SIG is left alone. Only an actual mode
change pulses the reset, so a second host-side user does not. A
powered-down PHY takes the mode at its next power-on, and power-off
returns it to device mode for the next user.

The DWC2 never sets a PHY mode, and no host controller node in the Apple
device trees has a phys property, so nothing changes until a user calls
phy_set_mode(): the A9/A10 Lightning port role switch added later.

Tested on an iPad 5 (J71t) with the Lightning to USB camera adapter.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; commit message only]

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
…witch

The Lightning port is either the USB device (DWC2) or, for the Lightning
to USB camera adapter, a USB host (EHCI/OHCI), and a role switch moves
it between the two. The adapter announces itself over the Lightning ID
bus, which the charger's Tristar (CBTL1610) masters, so the charger is
where the decision is made.

The charger already sets the device controller's role through its port.
Add an optional phandle to the role switch that gives the PHY to the
host controllers; while the port is a host, the device controller stays
off. A board without it keeps the port a USB device and identifies no
accessory.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; description no longer
 names a board without the switch]

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
A Lightning accessory announces itself on the ID bus: asked for its
digital ID, it answers with six bytes that say what it is and which pins
it uses. The Tristar (CBTL1610) is the bus master. The host loads a
request, reversed, into the TX window that ends at register 0x60, reads
it back, starts the transfer through 0x61 and polls the event register
0x0d; the Tristar clocks the wire, frames BREAKs, appends the request
CRC and leaves the response in the RX window at 0x20.

Add the master as the commands iOS sends, in its order and with its I2C
transaction shapes: GetID (0x74) after acknowledging a latched pin fault
and releasing a latched ID-bus reset hold; for the camera adapter the
follow-up iOS runs before USB host mode, the interface information
(0x76), the module and accessory serials (0x78, 0x7a) and two SystemInfo
packets (0x84) that the adapter normally leaves unanswered, where iOS's
timeout recovery (engine abort, BREAK before the next transfer) applies;
and the power handshake, GetState (0x72) then the power request (0x70).
Serial numbers read from the accessory are not kept.

The ID-bus master is a separate object of the charger module, under the
new APPLE_TRISTAR_ACCESSORY option. The module keeps its name; only the
composite object is spelled with dashes, so that the charger's source
file keeps its name.

Tested on an iPad 5 (J71t) with the Lightning to USB camera adapter.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; commit message only]

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
The Lightning to USB camera adapter (digital ID 11 f0) has the iPad act
as USB host. iOS identifies it on every attach, runs the post-ID
exchange with accessory power on, makes the port a host, then agrees on
power over the ID bus. On unplug the port returns to the USB device
controller.

Add that policy to the charger, active only when the device tree names
the port's role switch (apple,usb-role-switch). Every 250 ms it reads
the Tristar status (VBUS, orientation, plug present) inside the role
switch's monitor, so that no role change overlaps the read. With a plug
attached it asks for the digital ID 300 ms after the plug edge and then
every 2 s (10 s while a USB host has configured the gadget). For the
adapter it switches accessory power on, runs the post-ID exchange,
requests the host role, then runs the power handshake once strict VBUS
appears (two tries, 15 s deadline) and keeps the role, re-checking the
ID every 5 s. Unplug detection follows iOS: a fully empty status at
once (three reads); while the adapter is ours, plug-present clear with
VBUS lingering for 2 s (an unplug in host mode can read 0x25);
plug-present back after 0.5 s or more is a replug, which releases the
role and identifies again. A different ID in host mode (a fast swap to
a computer's cable) releases the role as well.

The charger and the policy share the Tristar under the charger's lock.
While the policy holds the port (from the host request until the role is
given back, and around each accessory-power or role change), the charger
does not sample the mux. A charger on the adapter's power port is then
not identified, and the power handshake's state bytes are not decoded,
so the charger takes it as an unidentified source: 500 mA, through its
usual ramp and battery checks. It identifies the source again once the
policy lets go. Role-switch calls are never made with the charger's lock
held, since the role switch calls back into the charger with its own
lock held. The policy stops with the charger's poll on remove, shutdown
and suspend, and gives a held host role back on unbind. The policy looks
the role switch up from its own poll, so charging never waits for the
role switch to bind. The charger owns the device controller's role (off
until the source is identified). While the policy holds the port, that
role stays off even once the source is identified, so the device
controller never pulls up while the PHY serves the host controllers; the
first poll after the policy lets go turns it on, or identifies the
source again if it was the adapter. Stopping the charger always turns it
on.

A board without the role switch gets no new polling and no extra
Tristar traffic; with the option off, the charger is unchanged.

The interface between the policy and the role switch driver, which
implements it, is added here as include/linux/usb/apple-s8000-role.h:
the policy switches accessory power and lets the role switch sample the
Tristar status. Without the role switch driver the header's stubs return
-EOPNOTSUPP.

Tested on an iPad 5 (J71t) with the Lightning to USB camera adapter.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; input limit in host
 mode is 500 mA instead of 2.1 A after the power handshake, since the
 source behind the adapter is not identified; the policy is the only
 user of the host role, so the host-entry claim is gone]

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
The Apple A9 (S8000/S8003) and A10 (T8010) USB complex has a device-only
DWC2 and a separate EHCI + OHCI host pair behind one AUSB PHY. A USB_CTL
register bank selects whether the PHY serves the host pair. On the
Lightning iPads the port reaches the host pair only through this switch.

Describe the switch: its USB_CTL bank, the shared PHY, the DWC2 whose
gadget it disconnects in the host role, and the EHCI and OHCI child
nodes, which the switch creates only in the host role. A Lightning board
also names the PMIC with the accessory power LDO and the Tristar port
controller, whose ACC pin routing is set up before accessory power is
turned on.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; T8010 compatible added,
 whose USB complex, USB_CTL bank (0x20e0d8000) and PHY tunables the
 Apple device trees of J71b, J72b and J171 give as on J71t]

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
The A9 and A10 USB complex pairs a device-only DWC2 with a separate EHCI
+ OHCI host pair behind one AUSB PHY. On the Lightning iPads the port is
a USB device by default; the camera adapter needs it to be a host.

Add a usb_role switch for the port. Device mode stays the default and
needs no register access. Host mode follows the iOS order: soft-
disconnect the gadget (it stays bound, as iOS keeps the device
controller published), make sure the complex's DMA remap words for the
host pair are set, power the PHY, create EHCI and then OHCI from the
switch's child nodes so that their power domains are on, set USB_CTL bit
1 and then host select, and switch the PHY to its host tunables. Leaving
host mode undoes the steps in reverse and reconnects the gadget, which
comes on once the device controller's own role allows it (the Lightning
charger sets that role).

The Lightning accessory policy in the Tristar charger is the only user
of the host role; userspace cannot set it, so a USB stick in use is
never pulled away by anything but the adapter's unplug. Before the
policy's ID-bus identification and on host entry, the switch powers the
accessory as iOS does: it routes the Tristar ACC pin to the power rail
and the data lanes for USB (ACC_CTRL 0x30 and dxctrl 0xa1 for the
adapter in orientation 1, through an intermediate dxctrl byte when a
lane pair changes), then enables the PMIC's accessory LDO, its switch
and its sleep enable. The Tristar bytes it found are restored when the
power goes off. The policy also samples the Tristar through the switch,
so that no role change overlaps the sample. System sleep is refused in
the host role.

Tested on an iPad 5 (J71t) with the Lightning to USB camera adapter: a
USB stick, a powered USB-C hub with an SD card reader and RTL8152
Ethernet enumerate, and unplugging returns the port to the USB gadget.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; the host role is no
 longer settable from userspace, which also drops the claim interface
 and the 60 s return of a manual host role (patch 0018 there)]

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
Add the A9 USB role switch to the USB complex, disabled, with the EHCI
and OHCI it creates in the host role as its children: they share the
AUSB PHY with usbdev, and the switch decides which side has it. The
EHCI and OHCI nodes move out of the disabled block into the switch.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; the unused ehci0/ohci0
 copies in the #if 0 block are dropped]

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
Enable the S8000 USB role switch on the iPad 5 with the D2365 PMIC
(accessory power LDO) and the Tristar (ACC pin routing), and point the
Lightning charger at it, so that its accessory policy can give the port
to the host controllers while the camera adapter is attached. The
charger keeps setting the device controller's role through its port.

The Apple device tree gives the accessory rail as LDO5 of the PMU
(dock: function-acc_pwr, function-acc_sw_en) and the Tristar as a
CBTL1610 on i2c0.

Tested on an iPad 5 (J71t) with the Lightning to USB camera adapter:
attaching it switches the port to the host role with EHCI and OHCI up;
USB mass storage transfers at about 36 MB/s; a powered USB-C hub
enumerates with its hub, SD card reader and RTL8152 Ethernet; detaching
the adapter returns the port to the device role and restores the USB
gadget.

[Orchard: from orchard PR OrchardLinux#126, commit 864b4971; moved from the t8010
 layer to the iPad 5 board layer]

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Link: OrchardLinux/orchard#231 (comment)
henrikklee added a commit to theChristopher16/linux that referenced this pull request Dec 4, 2026
…mestamps

drm/imagination: apple: account S8003 firmware phase time in apple_jobs

Resolve the conflict with OrchardLinux#126 in s8003_submit_frag(): keep the
per-device PM set address from OrchardLinux#126 and pass OrchardLinux#122's gpu_ticks.
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