Skip to content

soc: apple: T8140 AOP services and CT817 ALS (reworked, 30 patches) - #11

Merged
RyanTheTide merged 30 commits into
aurora-wipfrom
series/neo-aop-als-20260924
Sep 25, 2026
Merged

RyanTheTide merged 30 commits into
aurora-wipfrom
series/neo-aop-als-20260924

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

soc: apple: harden T8140 AOP services and CT817 ALS (v2)

Rework of the audited head a6eaab7 after review. The three commits
(one 1,330-line driver change, one IIO change, one MAINTAINERS change)
are replaced by a 30-patch series on top of aurora-wip with PR #10 and
PR #20 merged. Every patch is one change and builds on its own; the
generic bug fixes carry Fixes: tags; T8140 behaviour is gated on match
data so T8103/T8112/T6000/T6020 keep their behaviour except for the
fixes below.

What changed since a6eaab7

Kernel crate

  • rust: workqueue: OwnedQueue — an owned ordered workqueue, replacing
    the driver's raw alloc_workqueue_noprof()/drain_workqueue() wrapper.
  • FakehidListener/MessageProcessor gain Send + Sync; the new
    ReportListener has them too. No unsafe impl Send for listener entries.
  • FakehidRegistration lives in kernel::soc::apple::aop (it was in the
    IIO module) and both sensor drivers unregister from unbind.
  • <dyn AOP>::from_child() replaces the copy-pasted drvdata cast in the
    children and returns EPROBE_DEFER until the AOP has published its
    driver data. The removed driver-core helpers of PR arm64: apple: T8140/J700 platform prerequisites (reworked) #10 are not used.
  • SourceRing no longer exposes its buffer; read(offset, &mut [u8])
    copies a span out. iova, size(), source_ring(),
    add_report_listener()/remove_report_listener() keep their names and
    signatures; the callback constraints are documented.

Generic fixes (all SoCs), each with Fixes:

  • reply tag bound off-by-one; message/announcement length checks; endpoint
    range check in the RTKit receive callback; child fwnode reference kept
    until registration; shared buffer owned before its address is published;
    bounds-checked ring accesses with volatile pointer words; service
    registration serialized with removal on an owned queue; bounded (5 s)
    EPIC call wait with abandoned-slot tags so a late reply cannot complete
    a later call (that is what makes the timeout safe on tagged v2 firmware);
    bounded per-endpoint shutdown wait that only stops started endpoints;
    teardown in unbind (device still bound) and unwind of a failed probe;
    listener removal on child unbind; iio_device_alloc() NULL check.
  • Messages an endpoint cannot handle are skipped instead of stalling the
    ring; the log is throttled.
  • IIO: processed lux is reported as IIO_VAL_INT_PLUS_MICRO; short reports
    no longer store a fake 0; -ENODATA until the first report arrives.

T8140 (behind epic_v4, setup_port, quiesce_on_unbind,
required_endpoints, patch_bootargs in the match data)

  • EPIC v4 headers (inline_len only on v4; v2 bytes unchanged);
    one call at a time per untagged endpoint; a timed-out call closes that
    endpoint until the late reply arrives (no whole-AOP latch).
  • Setup-port handshake: per-message GFP_ATOMIC work items from the
    hard-IRQ mailbox callback onto an ordered queue (the pattern rtkit.c
    uses), sends with atomic = false from process context, uninterruptible
    CondVar::wait_timeout() waits with remaining-jiffies accounting, no
    Coherent::as_mut() over the shared arena, unknown management messages
    ignored rather than fatal.
  • Unbind: RtKit::shutdown(); if unconfirmed, DMA is retained, children
    stay registered but unbound with a driver_override no driver matches
    (exported __device_set_driver_override()), and a re-probe is refused
    until reboot. Legacy SoCs keep their existing stop-and-free removal.
  • apple,t8140-aop match entry; required endpoints 0x20/0x21/0x22/0x23/0x2b,
    the rest best-effort; legacy SoCs still require every advertised endpoint.
  • APPLE_AOP selects RUST_APPLE_MAILBOX and RUST_FW_LOADER_ABSTRACTIONS
    (APPLE_AOP=m with IIO_AOP_SENSOR_ALS=n builds).
  • CT817 support in the ALS driver; report listeners and the source ring
    are the last two driver patches, for the T8140 AOP audio driver (PR ASoC: apple: T8140 (J700) AOP audio and macaudio routing (reworked, 12 patches) #13,
    which needs the ring.read() change).
  • MAINTAINERS: the AOP files added to the T8140/J700 entry (not the Asahi
    block); no Documentation/arch/arm64 file.

ALS calibration

The T8140 firmware does not start the CT817 until the AP has sent the
sensor's calibration over setup-port endpoint 0x21: an 80-byte message
(64-bit operation code 0x0746b8d665152e31, 64-bit body length 56, 64 bytes
of data). It is machine-specific and not part of the
kernel, so:

  • the binding gains an optional firmware-name on the ALS node
    (dt-bindings: iio: light: apple,t8140-aop-als), and the J700 DTS sets
    apple/j700-aop-als-cal.bin;
  • the AOP core loads it with request_nowarn() before starting the AFK
    endpoints, validates only its shape, and there is no MODULE_FIRMWARE
    for it (initramfs tools on other Apple machines see nothing);
  • a missing property or file leaves the sensor off with one log line and
    the AOP running; the ALS channel returns -ENODATA until the first
    report, instead of reading 0 lux forever.

Checks run

Compile-tested only; not run on hardware.

  • Each of the 30 commits built in order (W=1) with rust/kernel.o,
    drivers/soc/apple/aop.o, aop_als.o, aop_las.o,
    rust/helpers/helpers.o: 0 warnings, 0 errors.
  • CLIPPY=1 at the head: no warnings from code added by this series
    (remaining warnings in the touched files are pre-existing base code).
  • rustfmt --check on every touched file; make rustfmtcheck fails only on
    unrelated files (asahi initdata.rs, drm gem shmem.rs).
  • sparse (C=2) on rust/helpers/helpers.o (the only C change): clean.
  • dt_binding_check on the ALS schema and CHECK_DTBS=y on
    apple/t8140-j700.dtb: clean.
  • checkpatch --strict --codespell on every patch: 0 errors, 0 checks;
    only the known Assisted-by/Co-authored-by trailer noise and "Unknown
    commit id" for the three Fixes: SHAs that the shallow clone lacks.

Not tested

Nothing has been booted. In particular untested: the legacy SoCs with the
generic fixes (receive path, call timeout, teardown order); the J700
setup-port boot and ALS calibration push; whether the calibration must
precede start_afk() or only the first ALS call; the v4 untagged-reply
attribution; RtKit::shutdown() on the J700 and the retained-DMA path;
the source ring with PR #13. Not done: moving the setup arena's DMA off
the mailbox provider's device (needs a DT topology change to the merged
PR #10 bindings) and a re-handshake for a v4 endpoint after a timeout
(needs firmware data).

🤖 Generated with Claude Code

@RyanTheTide
RyanTheTide force-pushed the series/neo-prerequisites-20260924 branch from ee76ce3 to 021cafc Compare September 24, 2026 03:06
@RyanTheTide
RyanTheTide force-pushed the series/neo-aop-als-20260924 branch from f226a90 to a6eaab7 Compare September 24, 2026 03:06
@RyanTheTide
RyanTheTide force-pushed the series/neo-prerequisites-20260924 branch from 021cafc to 2903144 Compare September 25, 2026 14:54
@RyanTheTide
RyanTheTide changed the base branch from series/neo-prerequisites-20260924 to aurora-wip September 25, 2026 14:54
RyanTheTide and others added 24 commits September 26, 2026 02:03
The workqueue abstraction only hands out the system queues. A driver
that needs its work items to run one at a time in queueing order, or
that has to wait for all of its outstanding work before it tears down
the state the work uses, has no safe way to get a workqueue of its own
and ends up calling alloc_workqueue(), drain_workqueue() and
destroy_workqueue() through raw bindings.

Add OwnedQueue, a wrapper around a workqueue allocated with
alloc_ordered_workqueue(). It dereferences to Queue, so work items are
enqueued on it like on the system queues. drain() exposes
drain_workqueue(); its documentation states the rule that every other
producer has to be stopped first, because the kernel refuses (with a
warning) to queue work from outside the queue while it drains. Drop
calls destroy_workqueue(), which drains the queue before freeing it.

alloc_ordered_workqueue() is a variadic macro, so a helper with a fixed
"%s" format takes the name; the kernel copies it into the workqueue.

The T8140 AOP driver uses it to serialize the registration of its
service devices with its own teardown and to run its setup-port
protocol in order.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The AOP driver stores every fake-HID listener as an Arc<dyn
FakehidListener> in a list that its RTKit receive worker walks, while
the child driver that registered the listener keeps its own reference
and reads the same object from the IIO read path. FakehidListener has
no Send or Sync bound, so the driver's list entry carries an unsafe
impl Send with no argument for why the trait object may cross threads.

Make Send + Sync supertraits of FakehidListener, and of the sensors'
MessageProcessor, which is the only non-trivially-Sync field of the
type that implements it. The driver's unsafe impl then goes away: an
Arc<dyn FakehidListener> is Send and Sync on its own.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
A reply's tag selects the slot of the call it answers. The check that
guards the slot lookup allows tag == AOP_MAX_CALLS + 1, and the lookup
then indexes one past the end of the calls array. Tags come from the
firmware, so a stray reply would take the RTKit receive worker down.

Reject tags above AOP_MAX_CALLS.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The receive path splits every ring entry at the size of the EPIC header
without checking that the entry is that long, and it reads a service
announcement through a struct pointer without checking that the payload
holds the struct. Both lengths come from the firmware; a short entry
panics in split_at() and a short announcement reads past the payload.

Check both lengths and report a short message instead. While at it,
decode the header fields and the announcement from the byte slices, so
that no pointer casts remain in the receive path. The announcement is a
NUL-padded 32-byte name followed by the channel at byte 32; the old
struct split the name at 20 bytes, which made no difference for the
names the firmware uses but is not the layout of the message.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The ring buffer accessors index the endpoint's shared buffer with
offsets and sizes that come from the firmware: the ring geometry from
the InitRX/InitTX messages, the entry sizes from the ring itself. Since
the switch from CoherentAllocation::as_slice() to plain slicing, an
offset outside the allocation is no longer reported as an error but
panics in the RTKit receive worker, as does a ring whose stated buffer
size exceeds the ring size or whose entry size exceeds the room left
before the read pointer.

Route every access through one bounds-checked helper and return EIO for
anything outside the allocation. Validate the ring geometry when it is
announced: the header blocks have to fit, the block size has to be a
nonzero power of two because the entry alignment relies on it, and the
buffer size has to be nonzero. Check the wrap arithmetic in the receive
and send paths for underflow.

The read and write pointer words are written by one side and polled by
the other at any time, so a plain slice over them does not meet
Coherent::as_ref()'s condition that the device stays away from the
memory. Access them with volatile loads and stores, the kernel's
READ_ONCE()/WRITE_ONCE(), and copy entries with raw pointer copies whose
comments state the ring rule that makes them race-free: an entry is
only read between the read and the write pointer and only written
between the write and the read pointer.

Fixes: 7a7c137 ("fixup! soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The RTKit receive callback subtracts AFK_ENDPOINT_START from the
endpoint number and indexes the endpoint table with the result without
checking either step. Overflow checks are enabled in this configuration,
so a message on an endpoint below 0x20 panics in the subtraction and one
on an endpoint above 0x2e panics in the indexing. The endpoint number
comes from the mailbox.

Look the endpoint up through one checked conversion and ignore messages
on endpoints the driver does not drive, with a warning. Use the same
conversion for the endpoint of a service in the call paths, so that a
malformed service record returns EINVAL instead of panicking.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The service registration work looks up the child firmware node by name,
which returns a counted reference, and passes the raw pointer to
platform_device_register_full(). The reference is dropped inside the
map() closure that extracts the pointer, before the registration runs,
so the platform device is created from a node the driver no longer
holds. It only works because the parent's own node keeps its children
alive.

Keep the reference until platform_device_register_full() has returned;
the registration takes a reference of its own on success.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
Service devices are registered from work items on the system workqueue,
one per service announcement, and remove() walks the list of registered
children without waiting for that work. A registration that is still
queued or running when the AOP is removed registers its child after the
list was walked, so the child is never unregistered and outlives the
parent's driver data that its probe reads. The work item also pushes
the new device onto the list only after registering it and merely logs
when the push fails, which leaks a registered device the same way.

Run the registrations on a workqueue owned by the driver, and have
remove() set a removal flag under a gate that register_service() takes
while queueing, then drain the queue. After the drain the list of
children is complete. Reserve the list slot before registering the
device so that a registered device is always tracked, and unregister it
on the spot if the push fails after all rather than leaking it.

Wrap the child pointers in a type whose only operation is to unregister
the device once. With that, and with Send + Sync listeners, AopData is
Send and Sync by construction and its unsafe impls go, as does the one
on AFKEndpoint, which never had a field that needed it.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
A caller of epic_call() waits for the reply in TASK_UNINTERRUPTIBLE
with no timeout. If the firmware never answers, which happens when it
has crashed or when a request concerns a fabric the AP has powered off,
the caller is stuck in D state for good, and so is anything that then
waits for that task, such as an unbind of the child driver.

Wait at most five seconds, using CondVar::wait_timeout() with the
remaining time carried across spurious wakeups, and return ETIMEDOUT.
The wait stays uninterruptible on purpose: a signal must not abandon a
transaction whose reply is about to arrive.

A reply carries the tag of its call, and the tag is the index of the
call's slot. Freeing the slot on timeout would let the next call reuse
the tag, and a reply that arrives late would then complete that call
with the wrong result. Instead, a timed-out call leaves its slot marked
as abandoned; the slot is reserved until the reply arrives and is
dropped. A doorbell that fails after the entry was written to the ring
is handled the same way, since the next doorbell delivers the entry.

Merge the two arrays that tracked a call and its return buffer into one
slot enum, and replace the unwrap() of the return buffer in
epic_call_ret() with an error.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
stop() sends a shutdown to every endpoint the firmware advertises and
waits for the acknowledgment without a timeout. Two things go wrong
with that. An endpoint whose AFK handshake was never started, because
start() failed part way through, is shut down anyway and never answers,
so the removal hangs. And a firmware that has stopped answering leaves
the unbind in D state for good, which is exactly when one would want to
unbind. One shared completion serves all endpoints, too, so a late
acknowledgment from one endpoint completes the wait for the next.

Record which endpoints were started and shut down only those. Give each
endpoint its own completion, wait at most five seconds for it, and on a
timeout warn, remember the error and carry on with the remaining
endpoints, so that stop() always returns.

Also return ENODEV instead of unwrapping a missing RTKit handle in
start() and stop().

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The AOP is only taken down from Drop, which the driver core runs after
the device is unbound, and nothing at all cleans up after a probe that
fails once the co-processor runs. Several things follow from that:

 - The shared ring buffers are dma_alloc_coherent() allocations on the
   device; freeing them after unbind frees them on a device whose DMA
   configuration is already gone.
 - A probe that fails in start() returns with the CPU running, the
   RTKit handle dropped while endpoints are live, and service devices
   still being registered by the work items the announcements queued.
   Those children stay registered, and their probes read the parent's
   driver data, which never gets published.
 - The RTKit handle is dropped while the rtkit lock is held. Dropping it
   waits for the RTKit receive worker, and that worker takes the same
   lock to deliver a message, so a message arriving during removal
   deadlocks the unbind.
 - epic_call() and the receive callback unwrap the RTKit handle, which
   is None once removal has started while a child's call is in flight.

Move the teardown to unbind, where the device is still bound, and make
it idempotent so that Drop stays as a fallback. Run the same teardown
from a scope guard when probe fails. Unbind the children first, while
the transport still works and their unbind can talk to their services,
then drop any listener a child left behind, mark the transport as
closing so no further call is started, stop the endpoints, take the
RTKit handle out of the shared state and drop it with the lock
released, and unregister the children last. A missing handle is now an
error (ENODEV) in the call paths and ends the receive callback.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
recv_get_buf() allocates the endpoint's shared buffer, sends its address
to the firmware and only then stores the allocation in the endpoint. If
the send fails, the allocation is dropped on the error path and the
memory returns to the allocator, although the message may already have
reached the firmware, which then DMAs into memory the kernel reuses.

Store the buffer first and send the address afterwards. A failed send
then leaves the buffer owned by the endpoint until the driver is torn
down, which is the conservative outcome. Also replace the placeholder
safety comment on the bound-device conversion with the actual argument:
the callback can only run while the RTKit handle exists, and the handle
is dropped before the device is unbound.

Fixes: dc97e13 ("soc: apple: Add support for the AOP co-processor")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
When a ring entry cannot be handled, because it is too short, carries
an unknown category or subtype, or is a reply with no call in flight,
the receive loop returns before it advances the read pointer. The entry
is then read again on the next doorbell, with the same result, so one
bad message stalls the endpoint for the rest of the boot and prints two
error lines per doorbell.

Skip such messages instead: log them and advance past them, since the
ring position is still known. Only errors that make the ring position
untrustworthy, an invalid entry magic or an entry outside the buffer,
still end the loop. Throttle the log to the powers of two of a
per-endpoint drop count, so that a stream of unhandled messages cannot
flood it, and print the category, subtype, tag and channel of the
dropped message together with the reason in that one line.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The ALS and lid-angle drivers register their sensor data as a fake-HID
listener with the AOP core and never remove it. When the child driver
is unbound or its module unloaded, the AOP keeps calling the listener
for every report: the sensor data stays alive through the Arc the AOP
holds, but its vtable points into module text that may be gone, and
the IIO device it feeds has been unregistered.

Add FakehidRegistration to the AOP client API: it owns one subscription
and removes it on unregister() or drop. Removing a listener takes the
same lock as report dispatch, so it returns only once no callback into
the listener is running. Have both drivers hold a registration as their
first field, unregister it from unbind while the IIO device still
exists, and let drop take care of a probe that fails after subscribing.
Since a service can now only be subscribed once per bound driver, the
AOP core rejects a second listener for the same service with EBUSY
instead of shadowing the first.

Fixes: 81556e2 ("iio: common: Add AOP sensor drivers")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
IIORegistration::new() writes the private data, name, channels and
callbacks into the device returned by iio_device_alloc() without
checking for NULL, so an allocation failure dereferences a null pointer.

Return ENOMEM instead. The Drop impl already skips a null device, so
the partially built registration unwinds cleanly.

Fixes: 81556e2 ("iio: common: Add AOP sensor drivers")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
A sensor's probe reads the AOP core's driver data from its parent
device. The core registers the sensor devices from a workqueue while it
is still probing, and the driver core publishes a driver's data only
once its probe returns, so a sensor that probes early finds no data and
borrows a null pointer as an Arc.

Add AOP::from_child() to the client API: it returns the core behind a
service device, or EPROBE_DEFER while the core has not published yet,
in which case the driver core retries the probe once the core has
bound. The lookup relies on the core's driver type being
repr(transparent) over the Arc; the contract is now documented in both
places instead of being assumed in every child. Also check that the
service record the core attaches as platform data is present.

Fixes: 81556e2 ("iio: common: Add AOP sensor drivers")
Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The processed illuminance channel is reported as IIO_VAL_INT after the
lux value, which the sensor delivers as a single-precision float, has
been truncated to an integer. Anything below one lux reads as zero,
which in a dim room is the whole range of interest for auto-brightness.
A report too short to hold the value also stores a fake zero, and the
lid-angle decoder indexes its report without checking its length.

Have the message processors return the reading in micro-units, or None
when the report carries none, and store it as such. read_raw() then
reports processed values as IIO_VAL_INT_PLUS_MICRO and raw values as
IIO_VAL_INT. Readings are capped so that both parts fit the i32 values
IIO passes around; a report without a reading leaves the previous one
in place. The float conversion is done in integer arithmetic, since
floating point is not available in the kernel: negative values clamp
to zero, NaN and the infinities carry no reading.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
A sensor's channel reads as zero from the moment the IIO device is
registered until the first report arrives, and stays at zero if reports
never come, as on an ambient light sensor whose calibration is missing
and which the firmware therefore never starts. Userspace cannot tell
that apart from darkness.

Track whether a reading has arrived and return ENODATA from read_raw()
until one has. The reading is published with release ordering and the
flag read with acquire ordering, so a reader that sees the flag sees
the reading.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The T8140 AOP firmware does not start the ambient light sensor until
the application processor has handed it the sensor's calibration over
the AOP's setup-port mailbox: without it the sensor answers property
reads and accepts its reporting interval, and then never reports. The
calibration is an 80-byte setup-port message that the machine's own
firmware sends the AOP; it is specific to the machine and is not part
of the operating system, so the operating system has to load it from a
file the machine's owner provides.

Add an optional firmware-name property naming that file, so that the
name is chosen per machine rather than hard-coded per SoC.

Assisted-by: LLM checkpatch dt_binding_check
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The AOP firmware of the J700 starts its CT817 ambient light sensor only
after the application processor has sent the sensor's calibration over
the setup-port mailbox. The calibration is the machine's own and is not
distributed with the kernel.

Name the file the AOP driver loads it from, so that an owner who has
extracted their machine's calibration can install it under that name.

Assisted-by: LLM checkpatch dtbs_check
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The T8140 AOP firmware speaks EPIC with version 4 sub-headers. The
sub-header is the same size as the version 2 one but carries a 64-bit
timestamp between the subtype and the tag, so the tag of a reply sits
eight bytes further in. The firmware also expects a call to advertise
the size of the reply it can take in the inline_len field: macOS sets
it on every call it makes to this firmware, and while a property read
happens to be answered with zero there, other calls are not guaranteed
to be.

Add the version 4 layout, select the tag offset by the sub-header
version the message itself declares, and build version 4 headers, with
inline_len set to the return buffer size, on firmware that a new
epic_v4 flag in the match data marks as speaking it. No compatible sets
the flag yet, and the header sent to the existing SoCs is unchanged.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The replies of the T8140 AOP firmware do not echo the tag of the call
they answer, so a reply cannot be matched to its call by tag. With two
calls in flight on one endpoint the results could be swapped.

On firmware marked epic_v4, let each endpoint carry one call at a time:
callers take a per-endpoint turn that they hold until the reply or the
timeout. A reply whose tag matches no call in flight is then attributed
to the endpoint's single occupied slot. When a call times out, its slot
stays abandoned and the endpoint refuses further calls, because a new
call's reply could not be told from the late one; the late reply, if it
comes, frees the slot and the endpoint is usable again. If it never
comes, the endpoint stays closed until the driver is rebound, which the
timeout message says.

Tagged firmware is not affected: it keeps its concurrent calls and its
tag matching.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The T8140 AOP firmware boots through a second mailbox besides the RTKit
one, its "setup port". Messages on it are a 64-bit word plus an
endpoint number. Endpoint 0 runs the management handshake: the firmware
sends HELLO (answered with the same version word), an endpoint map in
fragments (each echoed back, the last one flagged in bit 51), and a
few messages that want a fixed answer or none. Once the RTKit side has
reached AP power on, the host requests the setup port's AP power state
and the firmware reports it. Five service endpoints (0x20, 0x21, 0x23,
0x30 and 0x32) then each request a host-to-AOP message page and an
AOP-to-host reply window of 0x400 or 0x1000 16-byte entries, which the
host hands out of an arena of 13 pages that it maps through the setup
mailbox's own DART stream and describes to the firmware as
(5 << 60) | (direction << 54) | (pages << 48) | (iova >> 4). Boot is
complete when the power state is on and all five endpoints have their
buffers; the AFK endpoints are started only then.

Add this handshake behind a setup_port flag in the match data, which no
compatible sets yet. The mailbox interrupt handler may not sleep, so it
allocates a small work item atomically for each message, the same way
the RTKit core defers its own messages, and queues it on an ordered
workqueue that handles the messages one at a time under the setup
lock; a message it fails to queue is lost, and the port is marked as
failed rather than left waiting for a reply that cannot come. All sends
happen from that worker or from process context and may sleep for FIFO
room. Waits on the port are uninterruptible, bounded, and carry the
remaining time across wakeups; they end early once the port has
failed. Unknown management messages and words on endpoints without
buffers are logged and ignored, not treated as fatal.

The arena is allocated on the mailbox provider's device, since its node
carries the DART stream. The mailbox lookup adds a device link to that
provider, so it stays bound for as long as the AOP is, and the arena is
released while the AOP is still bound. The port is closed on removal by
dropping the mailbox and draining the queue, both outside the setup
lock.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
Removal stops the AFK endpoints and frees the RTKit handle, but never
shuts the co-processor down. Its firmware keeps running on the shared
ring buffers and, on the T8140, on the setup arena, all of which return
to the allocator when the driver data is dropped. The existing SoCs
have always been removed this way and are left as they are; the T8140,
whose firmware also owns DMA windows the host handed it over the setup
port, gets a quiesce_on_unbind flag in its match data.

With the flag set, removal asks the RTKit core for a shutdown after the
endpoints have stopped. If the firmware does not acknowledge it, the
buffers it may still write to cannot be freed: the endpoint buffers and
the setup arena are leaked, the RTKit handle is dropped with its shared
buffers retained, and the service devices stay registered so that their
IOMMU domains keep the mappings the firmware may use, but are given a
driver override that no driver matches so that nothing binds to them
again. A static flag then keeps this device from probing again until a
reboot, since the firmware's state is unknown. Nothing of this happens
unless the co-processor was actually started.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide and others added 6 commits September 26, 2026 02:04
Bind to apple,t8140-aop. The T8140 AOP firmware is loaded by the
bootloader and left stopped with its boot arguments in place, so the
EC0p/nCal/alig/AOPt patching that the other SoCs need is not applied
to it. It boots through the setup port and speaks EPIC with version 4
sub-headers, and it is shut down on unbind.

The firmware advertises more AFK endpoints than it starts. Its
application map is 0x20 misc, 0x21 aop-audio, 0x22 aop-voicetrigger,
0x23 als and 0x2b aop-audprov, which are also the endpoints macOS
starts on this AOP. Those are required; any other advertised endpoint
that fails to start is skipped with a warning instead of failing the
probe. The existing SoCs keep requiring every advertised endpoint.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The T8140 AOP firmware does not start the ambient light sensor until the
application processor has sent the sensor's calibration to setup-port
endpoint 0x21. Without it the sensor answers property reads and accepts
its reporting interval, and then never reports anything.

Add the setup port's request interface: a payload is copied into the
endpoint's message page, (3 << 60) | length announces it, the firmware
answers with a result word after writing a status byte at the start of
the reply window, and 4 << 60 releases the request. An endpoint takes
one request at a time. A request that times out leaves the endpoint
busy until its late reply arrives, so that a later request cannot be
completed by it; a result word other than the ones the caller accepts
is an error and the request is not released. Waits are uninterruptible
and bounded.

Load the calibration through the firmware loader from the file named by
the ALS node's firmware-name property and send it before the AFK
endpoints start, so it precedes any client of the ALS service. The file
is an 80-byte message: a 64-bit operation code, a 64-bit body length of
56, and 64 bytes of data, which are checked for shape only and sent as
captured; the firmware answers it with 0x2000000000000004 rather than
the 0x2000000000000001 of other requests. The calibration is specific
to the machine and cannot be distributed with the kernel, so no
MODULE_FIRMWARE names it. A node without the property or a file that is
not installed leaves the sensor off with a message, not the AOP down.

Select RUST_FW_LOADER_ABSTRACTIONS, which kernel::firmware needs;
APPLE_AOP=m with IIO_AOP_SENSOR_ALS=n builds again.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The T8140 (J700) ambient light sensor is a CT817. The AOP reports it by
its part number rather than by a code name, and its report differs from
the CT720's despite the shared family: it is 32 bytes with two raw
channel floats at +0x08 and +0x0c and the lux float at +0x1c, one byte
below the CT720's offset.

Its calibration is not an ALS property but a setup-port message that
the AOP driver sends before the endpoints start, so the driver does not
request the legacy calibration file for it. What arms the sensor is the
zero to non-zero transition of its report interval, which the sensor
accepts only after its batch and raw interval properties have been
written (with the values 1 and 0 that it runs with on the T8140) and
its verbosity set to 6. The sensor answers each of these writes with a
not-permitted status yet applies them, so the status is logged and only
a transport failure aborts the probe. Fetching the HID report descriptor
on this endpoint is never answered, and writing the MODE (0xd7) or 0xe4
properties wedges the AOP for the rest of the boot, so neither is done.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The AOP delivers only fake-HID reports to child drivers; any other
report subtype is dropped. The T8140 low-power microphone service
reports its producer position as EPIC reports of subtype 0x20, which
the AOP audio driver needs to follow the firmware's writes into the
source ring.

Add ReportListener to the AOP client API together with
add_report_listener() and remove_report_listener(), keyed by service
and subtype, with one listener per key. Reports that no listener claims
keep being dropped and counted like other unhandled messages. The
documentation of both listener traits now states the constraints the
callbacks run under: the RTKit lock, the endpoint lock and the listener
list lock are held, so a callback may neither sleep for long nor call
back into the AOP, and removal returns only once no callback into the
listener runs any more. Listeners are cleared on removal after the
children have been unbound.

The T8140 AOP audio driver, submitted separately, is the user.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The T8140 AOP firmware produces the low-power microphone's audio frames
into a ring in host memory that the application processor hands it over
setup-port endpoint 0x20: a 24-byte request of the operation code
0x6b803ce492bd9547, the ring's IOVA and its size. The ring is DMA of the
audio child device, whose node carries the DART stream the firmware
reaches it through. The firmware accepts one such binding per boot; a
second one is answered with 0x2000000000000009. So the ring cannot
belong to the audio driver, which may be bound and unbound repeatedly:
the AOP core owns it and hands the same ring to every probe.

Add SourceRing to the AOP client API and AOP::source_ring(), which
allocates the ring on the audio child on first use, binds it, and
returns it, or the existing ring, thereafter. The binding is recorded
before the firmware learns the address; if the request fails, the ring
is kept and never bound again, since even a timeout may mean the
firmware took it, and later calls fail with EIO. The ring's buffer is
not exposed: SourceRing::read() copies a span out, and its documentation
states that only a span the firmware has published through its producer
report is meaningful. On removal the ring is freed after the audio child
is unbound and before it is unregistered, while its IOMMU domain still
exists, and it is retained when the shutdown is unconfirmed.

The T8140 AOP audio driver, submitted separately, is the user.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch rustfmt
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
The Apple AOP driver, the AOP sensor drivers and their Rust support code
now carry the T8140 and J700 support this series adds. List them under
the APPLE T8140 SOC AND J700 (MACBOOK NEO) SUPPORT entry; they remain
covered by ARM/APPLE MACHINE SUPPORT through drivers/soc/apple/ as well.

Assisted-by: LLM checkpatch
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide force-pushed the series/neo-aop-als-20260924 branch from a6eaab7 to 0d65c53 Compare September 25, 2026 16:10
@RyanTheTide RyanTheTide changed the title soc: apple: harden T8140 AOP services and CT817 ALS soc: apple: T8140 AOP services and CT817 ALS (reworked, 30 patches) Sep 25, 2026
@RyanTheTide
RyanTheTide marked this pull request as ready for review September 25, 2026 16:11
@RyanTheTide
RyanTheTide merged commit 7693112 into aurora-wip Sep 25, 2026
@RyanTheTide
RyanTheTide deleted the series/neo-aop-als-20260924 branch September 26, 2026 12:44
cb2206 pushed a commit to cb2206/linux that referenced this pull request Oct 5, 2026
…batch-control

Allow bounded M3 render batch tuning between GPU submissions
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.

1 participant