Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion Documentation/accel/apple-ane.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ EVENT_REPORT 0x0300 6 0x60 (firmware to host)
These sizes bound the observed version, not future firmware. POWER_GATE has
a u32 Boolean at +8. The execute-size increment of 0x18 counts custom BAR
records. The channel numbers are observed table indices;
their mapping to channel names remains unproved. The parser retains each
the clean cold-boot facts identify their channel names. The parser retains each
descriptor's original index rather than assuming name order is wire order.

The transport prepares the H16 envelope and rejects unrecognized runtime
Expand Down Expand Up @@ -178,3 +178,72 @@ KUnit covers byte-exact synthetic execute fields, all 1..64 buffer counts,
zero/one/two custom BAR lengths, wide DVAs/spans, reserved-zero output,
boundary and overflow refusal, all event states, interleaved identities,
ISP routing and malformed reports. No test packet is copied from a capture.

Shared H16/H17 firmware transport
--------------------------------

``ane_fw_transport.h`` supplies device-independent ring operations over owned
coherent surfaces and caller-provided memory, DMA-barrier, MMIO, clock and
allocation accessors. Engine-relative doorbell and pending/acknowledge offsets
come from ``ane_fw_platform`` match data. The caller must establish ownership,
firmware identity, power and the private DMA domain before using it. This
helper does not change probe or enable either generation.

Initialization copies exactly eight 0x100-byte descriptors from the IPC
surface and validates their names, types, bits, slot counts, alignment and
non-overlapping ranges, including exclusion of the table itself. IO and
DATA_CHAIN_H2T require type 0; SHAREDMALLOC and IO_T2H require type 1. Each
operation checks the immutable table snapshot. Only type-0 slots are armed,
in word-1, word-2, word-0 order, with values 0, 0, 1 and a DMA write barrier.
Descriptor geometry and doorbell bits remain authoritative. Logical channel
names are independent of their descriptor order.

Publication copies a command into a 64-byte-aligned arena inside the pool,
after the caller's reserved boot prefix. It publishes both length words,
a DMA write barrier, the command DVA, another barrier and the descriptor's
doorbell bit. There is one outstanding transaction per sending channel;
heads advance modulo the descriptor slot count only after a successful
reply. A reply requires the exact DVA with bit 0 set, unchanged length,
zero result word, zero command prefix, unchanged u16 ID and zero u16 ack.
Bit 1 is corruption even before ownership returns. Nonzero ack is returned
as ``-EREMOTEIO`` and retained for diagnosis.

IO_T2H is present when word 0 has bit 0 clear and either word 0 or word 1 is
nonzero. Reports must be four-byte aligned and wholly inside one owned
surface. The transport copies the report before setting word 0 bit 0 and
ringing the descriptor doorbell, without changing the other slot words.
Report dispatch and pending UUID lookup belong to the caller. In particular,
consuming a stale UUID report cannot complete an unrelated request, and the
DATA_CHAIN reply acknowledges submission rather than inference completion.

The SHAREDMALLOC provider accepts allocation tuples only. Requests are
rounded to 16 KiB, with a 1 MiB request ceiling, the exact 2 MiB allocation
with tag 0x45585050 exception, 12 MiB in rounded allocations and 64 handles.
The allocation callback supplies a zeroed, pinned private-domain mapping;
the transport checks its size, DVA alignment, overflow and exclusion from
all other owned surfaces before publishing it. Handles are nonzero ordinals.
FREE and distinguishable control tuples return ``-EOPNOTSUPP`` through the
mandatory refusal logger. An all-zero slot is empty and cannot distinguish
a control request. No FREE/control reply is invented while that form is
unspecified.

IRQ service reads pending once, rejects bits above 7 and writes the exact
nonzero snapshot to acknowledge. The wait helper services one allocation at
a time and checks the original absolute monotonic deadline, including time
spent inside the allocation callback. Servicing never starts a new timeout.

The caller serializes all entry points. Initialize a fresh transport only
before firmware starts or after a proved reset. The pool arena is monotonic
and returns ``-ENOSPC`` when exhausted; command storage is not recycled.
Successful reply bodies remain in the pool transaction span. A timeout,
malformed firmware tuple, allocation failure or firmware refusal latches an
error, retains the transaction and mappings and stops further publication.
No surface is freed by these helpers, including a rejected allocation result.
The backend must retain mappings, power and module references until reset.

The field contract follows the clean H16/H17 cold-boot facts, sections 1,
7 through 11, and the SPEC-r2 channel and deadline rules. Allocation limits
are conservative host policy observed sufficient on H17, rather than
firmware-advertised authority. The KUnit suite uses synthetic memory and
accessor traces, with no MMIO or hardware access. Its configuration fragment
is ``drivers/accel/ane/transport.kunitconfig`` and runs on x86_64 and arm64.
3 changes: 2 additions & 1 deletion drivers/accel/ane/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ config DRM_ACCEL_ANE_FW_KUNIT_TEST
default KUNIT_ALL_TESTS
help
Check preload ranges, 27.x channel and reply validation, RTKit
management ordering, and H16 task/relocation bounds without hardware.
management ordering, H16 task/relocation bounds, and the shared H16/H17
ring transport and bounded allocation provider without hardware.
These tests can run on architectures other than Apple arm64.

If unsure, say N.
3 changes: 2 additions & 1 deletion drivers/accel/ane/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
obj-$(CONFIG_DRM_ACCEL_ANE) += ane.o ane_t6021.o
obj-$(CONFIG_DRM_ACCEL_ANE_KUNIT_TEST) += ane_drv_test.o
obj-$(CONFIG_DRM_ACCEL_ANE_FW_KUNIT_TEST) += ane_fw_platform_test.o \
ane_fw_protocol_test.o ane_h16_tasks_test.o ane_h16_execute_test.o
ane_fw_protocol_test.o ane_h16_tasks_test.o ane_h16_execute_test.o \
ane_fw_transport_test.o

ane-y := \
ane_drv.o \
Expand Down
11 changes: 8 additions & 3 deletions drivers/accel/ane/ane_fw_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct ane_fw_channel {

static inline bool ane_fw_contains(u64 base, u64 bytes, u64 addr, u64 size)
{
return size <= bytes && addr >= base && addr - base <= bytes - size;
return bytes <= U64_MAX - base && size <= bytes && addr >= base &&
addr - base <= bytes - size;
}

/* Parse a host-owned descriptor snapshot; output indices are logical names. */
Expand All @@ -42,7 +43,8 @@ ane_fw_channels_parse(const void *table, u64 ipc_dva, size_t ipc_size,
u32 seen = 0;
unsigned int i, j;

if (!table || !ane_fw_contains(ipc_dva, ipc_size, table_dva, ANE_FW_TABLE_SIZE))
if (!table || !channels ||
!ane_fw_contains(ipc_dva, ipc_size, table_dva, ANE_FW_TABLE_SIZE))
return -EPROTO;
table_off = table_dva - ipc_dva;
for (i = 0; i < ANE_FW_CHANNELS; i++) {
Expand Down Expand Up @@ -76,7 +78,8 @@ ane_fw_channels_parse(const void *table, u64 ipc_dva, size_t ipc_size,
return -EPROTO;
}
if (seen != GENMASK(ANE_FW_CHANNELS - 1, 0) ||
parsed[1].type != 0 || parsed[5].type != 1)
parsed[1].type != 0 || parsed[5].type != 1 ||
parsed[6].type != 1 || parsed[7].type != 0)
return -EPROTO;
for (i = 0; i < ANE_FW_CHANNELS; i++) {
u64 end = parsed[i].offset + parsed[i].slots * ANE_FW_SLOT_SIZE;
Expand Down Expand Up @@ -130,6 +133,8 @@ ane_fw_reply_status(u64 header, u64 slot_length, u64 slot_result,
{
const u8 *p = command;

if (header & 2)
return -EPROTO;
if (!(header & 1))
return -EAGAIN;
if (!command || length < 8 || (command_dva & 1) || header != (command_dva | 1) ||
Expand Down
Loading