Repository navigation
[follow-up to #155] accel/ane: retain live firmware buffers and EXEC references - #191
Merged
Merged
Conversation
The T6021 (M2 Max) ANE coprocessor mailbox is an ASC mailbox, but only one of its interrupts is known: the Apple device tree gives the ANE a single interrupt line. The binding requires the four ASC mailbox interrupts in a fixed order, so a node for this mailbox fails dtbs_check. Add the apple,t6021-ane-mailbox compatible with the apple,asc-mailbox-v4 fallback. For it, recv-not-empty is the only required interrupt; send-empty, send-not-empty and recv-empty may follow in that order. Without send-empty, the OS must poll the FIFO status before it sends. The other variants keep their constraints. The four-interrupt rule moves into a condition that excludes the ANE and AOP setup mailboxes, and the AOP setup mailbox states its minimum of two interrupts, which the top-level limit gave it before. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The T6021 (M2 Max) ANE coprocessor mailbox has one known AIC line, which the device tree names recv-not-empty. apple-mailbox insists on a send-empty IRQ as well, so it cannot bind that mailbox. Look send-empty up with platform_get_irq_byname_optional(). When the node has none (-ENXIO), do not request it, and let apple_mbox_send() wait for FIFO space by polling the A2I control register, the way its atomic path already does (100 us steps, 500 ms timeout, under tx_lock). Any other lookup error still fails the probe with -ENODEV. A mailbox whose node names send-empty takes the old path unchanged: the IRQ is requested at the same point with the same flags and name, and a non-atomic send still sleeps on tx_empty. All 71 apple-mailbox nodes in arch/arm64/boot/dts/apple name send-empty today. The Rust wrapper (RUST_APPLE_MAILBOX) needs no change. It only calls apple_mbox_get_byname(), apple_mbox_start(), apple_mbox_send() and apple_mbox_stop(), and never reads the IRQ fields, so a Rust client gets the poll through apple_mbox_send(). An equivalent change ran on an M2 Max lab kernel (Asahi 7.1.13 base) from 2026-09-24 to 2026-09-30, where apple-mailbox bound the one-interrupt ANE mailbox. The FIFO-full poll itself did not run there: with the ANE firmware in use (from macOS 13.5), the host sends no mailbox message after probe. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Add a binding for the Neural Engine (ANE) of the Apple T8103 (M1), T6000 (M1 Pro, Max and Ultra), T6020, T6021, T6022 (M2 Pro, Max and Ultra) and T8112 (M2). These are the compatibles that the ane and ane_t6021 drivers match. On T8103 and T6000 the node has the engine register window, one interrupt, the three ANE DARTs and five power domains. On T602x a coprocessor runs the ANE firmware, so the node also has the PMGR and power state windows, eight power domains, the coprocessor reset and mailbox, and an IOVA-only reservation for the firmware entry alias. The T8112 node has the T602x windows plus the two eFuse words that give the SoC revision to the firmware, seven power domains and the mailbox. The schema goes in npu/ with the other neural processing units, and in the ARM/APPLE MACHINE SUPPORT entry with the other Apple bindings. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The T8112 (M2) ANE coprocessor has an ASC mailbox at the same offset in its block as the T6021 ANE, and the Apple device tree also gives that ANE a single interrupt line (520). Add apple,t8112-ane-mailbox to the ANE mailbox variant, with the same interrupt rules as apple,t6021-ane-mailbox. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Add a DRM accel driver for the Apple Neural Engine (ANE). One Kconfig symbol, DRM_ACCEL_ANE, builds two modules from this directory: - ane binds apple,t8103-ane and apple,t6000-ane (M1, and die 0 of the M1 Pro, Max and Ultra). Linux starts no ANE firmware on these SoCs: the host writes task descriptors to the engine's task queue and maps the buffers through the three ANE DARTs (ABI 1, DRM_IOCTL_ANE_SUBMIT). - ane_t6021 binds apple,t6020-ane, apple,t6021-ane, apple,t6022-ane and apple,t8112-ane (M2 Pro, Max and Ultra die 0, and M2). On these SoCs Linux must start the ANE coprocessor. The driver loads the firmware with request_firmware(), checks it against a SHA-256 pin, copies it to its own DMA memory, starts the coprocessor, and sends LOAD, CREATE and CALL commands on the firmware's command ring (ABI 2, DRM_IOCTL_ANE_PROG_LOAD, DRM_IOCTL_ANE_PROC_CREATE and DRM_IOCTL_ANE_EXEC). Both register /dev/accel/accel*. include/uapi/drm/ane_accel.h has the ioctls of both ABIs, and the DRM major version tells userspace which ABI the device has. The sources are those of the out-of-tree omarchy-ane driver at tag v0.4.0 (16d13ef52dc6), which started from the ane driver of Eileen Yoon. The move changes only the build glue: the SPDX comment style, the include path of the UAPI header, an include of drm.h and the Linux-syscall-note in the UAPI header, and the module version, which the out-of-tree build took from git describe (MODULE_VERSION and one log line). Compiled for arm64, every object has the same code as the out-of-tree build, except for the argument list of that log line. The out-of-tree build of this code ran on T8103 (M1), T6001 (M1 Max) and T6021 (M2 Max) with linux-asahi 7.1.13. T6000, T6002, T6020, T6022 and T8112 have not run it. ane also matches apple,t6020-ane and apple,t6021-ane and refuses them at probe; ane_t6021 binds them. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Describe the M1 Neural Engine: the engine window at 0x26bc04000, the three ANE DARTs, and the ane_base and ane_set1..5 power states (ane_sys_cpu -> ane_base -> ane_set1..5). apple-dart owns the DARTs and the engine maps through their IOMMU domain. The ane driver binds these nodes. They equal, property for property with phandles compared by target path, the live device tree of a MacBook Pro 13" M1 (j293) on which the out-of-tree build of the same driver code was bound on 2026-09-30 (linux-asahi 7.1.13): 80 properties over the ane node, its DARTs and the eight ANE power states. Enabled: Linux starts no ANE firmware on T8103. Until the ane module loads, apple-dart binds the three DARTs and apple-pmgr-pwrstate registers the new states, as on that machine. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Describe the die 0 Neural Engine of the M1 Pro, Max and Ultra: the engine window at 0x285c04000, the three ANE DARTs, and the ane_set0, ane_base and ane_set1..5 power states (ane_sys_cpu -> ane_set0 -> ane_base -> ane_set1..5). ane_set5 is described but the ane node does not use it: it lies past the end of the ADT ANE pmgr range (0xc02c). The states are added on die 0 only; the M1 Ultra die 1 ANE stays undescribed. The pmgr window already spans 0x1c000 here, so it covers 0xc000..0xc030 without change. These nodes equal the packaged omarchy-ane device-tree overlay that booted on a MacBook Pro 16" M1 Max (j316c) on 2026-09-30 (linux-asahi 7.1.13): the out-of-tree build of the ane driver bound at 285c04000.ane and an inference smoke test matched its reference output hash. Property for property, with phandles compared by target path, the subtree is identical. One name differs: the overlay calls the node ane@284000000 (the ADT engine block base), which dtc W=1 flags (simple_bus_reg) because reg starts at 0x285c04000. It is ane@285c04000 here. The driver matches on the compatible. Enabled: Linux starts no ANE firmware on T6000. Until the ane module loads, apple-dart binds the three DARTs and apple-pmgr-pwrstate registers the new states, as on that machine. The M1 Pro and M1 Ultra share this die 0 block; only the M1 Max has run it. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Describe the die 0 Neural Engine of the M2 Pro, Max and Ultra: the whole 32 MiB engine range at 0x284000000 plus the PMGR state words and the SET window, IRQ 884, three ANE DARTs, the eight existing ANE power states with ane_cpu as the reset, the ANE coprocessor mailbox at 0x285408000, and an IOVA-only reservation for the firmware entry alias (16 MiB at 0x10000000000 in the ANE DART domain). The shared die 0 file uses apple,t6021-ane. t6020.dtsi and t6022.dtsi change it to apple,t6020-ane and apple,t6022-ane, because ane_t6021 has per-SoC data, for example the SoC revision it gives the firmware. The Apple device tree gives the ANE one interrupt line, so the mailbox names only recv-not-empty, and apple-mailbox polls for TX space. ane_dart0 is in the always-on pmp domain, as in the tree that booted; ane_sys was never booted for this DART. The nodes are enabled. By default ane_t6021 runs the firmware from its own memory (fw_alias_reserved=0), so it needs no reserved-memory node from the bootloader, and it does not start the mailbox (hello_wait_ms=0). The memory-region is an IOVA reservation only. Tested with the out-of-tree build of the same driver code: a MacBook Pro 14" M2 Max (j414c) ran linux-asahi 7.1.13 with these node values from an overlay and the packaged m1n1 1.6.1, and its test programs gave bit-exact results. That tree had two differences: the mailbox also named a placeholder send-empty line (AIC 1833), which the stock apple-mailbox needs, and the nodes came from an overlay. Earlier runs on the same machine used a one-interrupt mailbox node with a poll-TX apple-mailbox. Not tested: this kernel tree was not booted, and no M2 Pro or M2 Ultra ran these nodes. Their values are from the macOS 13.5 device trees of those machines, which give the same die 0 ANE values as the M2 Max. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Describe the M2 Neural Engine: the whole 32 MiB engine range at 0x26a000000 plus the PMGR window, the SET window and the two eFuse words that give the SoC revision to the firmware, IRQ 520, three ANE DARTs (IRQ 521, in ane_sys), the ANE coprocessor mailbox at 0x26b408000, and the seven ANE power states ane_sys_cpu, ane_td, ane_base and ane_set1..4 (0xc008..0xc038). ane_sys_cpu is a child of ane_sys, and each later state is a child of the one before. The values are those of the omarchy-ane T8112 overlay. Its sources are the /arm-io/ane and /arm-io/dart-ane nodes of the macOS 13.5 and 27.0 device trees, which are the same on j413, j415, j473 and j493, and the power-on order of the macOS 13.5 ANE kext. The mailbox sits at the same offset in the ANE block as on T6021 and names only recv-not-empty (the ANE interrupt); the overlay adds a placeholder send-empty line, which this tree does not need because apple-mailbox polls for TX. The mailbox, the DARTs and the ane node stay disabled: no T8112 has run the ane_t6021 driver or booted these nodes. The other ANE nodes in this series have the values of trees that ran the driver on an M1, an M1 Max or an M2 Max. A board or overlay that tests the driver enables the five nodes. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The ane module matched apple,t6020-ane and apple,t6021-ane, but it refused to bind both: T6020 had no proven SET-block base, and T6021 bound only with the allow_unqualified module parameter. The M2 family does not use the host-driven task manager of this module. Its coprocessor runs the ANE firmware, and the ane_t6021 module drives it for T6020, T6021, T6022 and T8112. The two entries made udev load both modules for every T602x ANE node, and the ane probe, when it ran first, failed with -ENODEV and logged an error. Remove the two entries and their SoC descriptors. Every remaining SoC has proven constants, so also remove the qualification tiers and the allow_unqualified parameter, and get the descriptor with of_device_get_match_data(). Each compatible of the apple,ane binding, and each ANE node in the apple device trees, now matches exactly one of the two match tables. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Prepare include/uapi/drm/ane_accel.h for a stable in-tree ABI. Prefix every macro of the header with DRM_ANE_, as other DRM UAPI headers do: ANE_TILE_COUNT, ANE_FIFO_NID and ANE_CMD_GRAN become DRM_ANE_TILE_COUNT, DRM_ANE_FIFO_NID and DRM_ANE_CMD_GRAN, ANE_ABI_MAJOR and ANE_ABI_M2_MAJOR become DRM_ANE_ABI_V1 and DRM_ANE_ABI_V2, and ANE_M2_MAX_BINDS becomes DRM_ANE_MAX_BINDS. ANE_M2_MAX_SECTIONS was 16, but the driver accepts at most 9 sections (ids 1 to 9). It becomes DRM_ANE_MAX_SECTIONS with the value 9, and a BUILD_BUG_ON() keeps it equal to the firmware LOAD record count. Add DRM_IOCTL_ANE_GET_CAPS (number 0x00, free until now) to both drivers. It reports the ABI version, the chip family (H13 or H14), and the size of each array entry that PROG_LOAD and EXEC read through a user pointer. Its flags field has no defined flag and must be zero. Its size field gives the number of bytes that the driver filled in, so the structure can grow at its end. Reject a nonzero pad or reserved field with -EINVAL in every ioctl: BO_INIT and BO_FREE on ABI version 2 (ABI version 1 already did), the pad of PROG_LOAD, of each generic bind and of EXEC, and the flags and reserved fields of each EXEC buffer. The field drm_ane_exec_io.dma was already reserved: the driver gives the firmware the address of bo_handle. Rename it to reserved. Add kernel-doc for every structure. Keep one header with an explicit ABI version, not one header per ABI. The two drivers share the DRM driver name, the accel node, the BO_INIT/BO_FREE structures and the ioctl number space. One header per ABI would either duplicate the shared structures under two names or need a third header for them, and it would let the two headers give one ioctl number to two structures. Userspace already supports both ABI versions from one binary and selects by the version major. The version is explicit: DRM_IOCTL_VERSION major and drm_ane_get_caps.abi_version both report DRM_ANE_ABI_V1 or DRM_ANE_ABI_V2, an ioctl number is never reused, and a driver rejects the ioctls of the other version. The ioctl numbers and the layout of every existing structure do not change: an aarch64 offsetof()/sizeof() check of the old and new header gives identical values for all existing structures, fields and ioctl command values. Userspace that left a pad field of BO_FREE or of a generic bind uninitialised can now get -EINVAL on ABI version 2. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
checkpatch --strict reports 27 MACRO_ARG_PRECEDENCE checks for the task manager and task queue register macros. Put each macro argument in parentheses. No functional change: all callers pass simple expressions, and the non-debug sections of all seven objects are byte-identical before and after this change (arm64, gcc 12.2.0). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
checkpatch reports a MEMORY_BARRIER warning for the four barriers without a comment, and an UNCOMMENTED_DEFINITION check for the three mutexes. Say what each barrier orders and what each mutex protects. Comments only. The non-debug sections of all seven objects are byte-identical before and after this change, except the line number in the one __dyndbg entry of ane_t6021_rtclient_main.o (arm64, gcc 12.2.0). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
checkpatch reports seven ALLOC_WITH_SIZEOF warnings and one ALLOC_SIZEOF_STRUCT check. Allocate the single objects with kzalloc_obj(), which uses GFP_KERNEL when no flags are given. No functional change: kzalloc_obj() expands to kzalloc() of the same size and flags, and the non-debug sections of all seven objects are byte-identical before and after this change (arm64, gcc 12.2.0). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Fix the style issues that checkpatch --strict reports and that need no change to the generated code: - join the split MODULE_PARM_DESC() strings of ane_t6021_fwload.c (SPLIT_STRING), - wrap three lines longer than 100 columns (LONG_LINE, LONG_LINE_STRING), - move two multi-line trailing comments in ane_t6021_boot.h and one after a #define above the code they describe (BLOCK_COMMENT_STYLE), - use ARRAY_SIZE(), min_t() and BIT() (ARRAY_SIZE, MINMAX, BIT_MACRO), - add braces to the unbalanced if/else statements (BRACES), - remove a pair of unnecessary parentheses (UNNECESSARY_PARENTHESES), - do not end a line with an open parenthesis (OPEN_ENDED_LINE), - reword a comment that checkpatch reads as a fall-through annotation (PREFER_FALLTHROUGH). No functional change: the non-debug sections of all seven objects are byte-identical before and after this change (arm64, gcc 12.2.0). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
ane_t6021 loads apple/ane/t602x_ane0_fw_selene_rc4x.macho on T602x and apple/ane/h14_ane_fw_bia_j4xx.macho on T8112. Declare both with MODULE_FIRMWARE() and keep each name in one macro. The firmware is a distribution concern: omarchy-ane-firmware-fetch installs these files under /lib/firmware/apple/ane. When request_firmware() fails, name the file and how to install it. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Add producer-side statistics to both ANE drivers. /sys/class/accel/accel<N>/device/ane_stats is a read-only (0444) file with two cumulative counters, one "key value" pair per line: - busy_ns: the nanoseconds the engine was busy since bind. A busy period opens when the first submission arrives on an idle engine and closes when the last one completes. Overlapping submissions share a period, so busy_ns is the union of the submit-to-completion windows, not their sum. ane serializes submissions behind engine_lock, so there the union is the sum. A read adds the time of the open period, so the value also increases while work is in flight. - jobs: the completed engine submissions since bind. ane counts each ANE_SUBMIT. ane_t6021 counts only CSNE_CMD_PROCEDURE_CALL. The control-plane commands on the same path and the boot transport are not engine work and do not count. A submission that fails still completes its begin/complete pair, so the counters stay balanced. Documentation/ABI/testing/sysfs-class-accel-ane describes the file. The ane_timeline debugfs file shows the latest submissions from a ring that the driver allocates at probe: seq, submit_ns, start_ns, end_ns, tasks, rc and tmst. Each slot has a sequence number, so a reader skips a slot that is in flight or that a later submission reuses. ane records the raw TM tick as tmst. ane_t6021 has no host TM path and records 0. Both drivers create the file with drm_debugfs_add_file(). The producer uses atomics only. It does not allocate, lock or format. A transition sentinel in the inflight count keeps the fold of one busy period and the start of the next apart. The next period starts at or after the fold end of the previous one. Both modules have a read-only stats parameter, default 1, that the driver reads at probe. With stats=0, or when the ring allocation fails, the driver creates no stats files and the submission path skips the counters. Testing: in the tree, this code is compile-verified only (arm64 W=1, =m and =y, and checkpatch --strict). A host test of the accounting through a kernel API shim passes. It includes a model check of all orders of three jobs, with a preemption at each atomic operation. The out-of-tree omarchy-ane driver with the same accounting passed the hardware gates on T8103 (M1) and T6001 (M1 Max). That version read max_end for the period start before it took the transition sentinel; this commit reads it after. The T6021 (M2 Max) path is in test. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The die 0 ANE power states that came with the ANE support in Joshua Warren's #155 include ps_ane_set5 at 0xc030, but the comment above them puts the end of the ANE's pmgr range at 0xc02c. The ane node does not use it either: it lists set1 to set4, and the driver takes its power domains from that list. The node was still live on every M1 Pro, Max and Ultra. The pmgr driver probes each enabled power-controller: it reads the register, sets the auto-PM enable bit if the state is active, and genpd turns unused domains off late in boot. Linux should not do any of that to a register outside the block it describes. Drop the node, and say in the comment why there is no set5. Found in a review of #155. Signed-off-by: Chris Kearney <chris@kearneymail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i (cherry picked from commit 7280b1168af21b04adde3a38ae8fa07a1ab54f84)
The ANE support from Joshua Warren's #155 enables the ANE on every chip that describes it except the M2 (T8112): the M1 (T8103) directly, and every M1 Pro/Max/Ultra (T6000/T6001/T6002) and M2 Pro/Max/Ultra (T6020/T6021/T6022) through the shared die 0 files. The driver has run on the M1 Max (T6001) and the M2 Max (T6021) only, and these device tree nodes have not booted on any machine yet. On an untested chip that means the ANE's DARTs, mailbox and power states probe and touch the hardware on every boot, and the driver binds, which on the M2 family starts the ANE firmware by default. Make the ANE node, its DARTs and mailbox, and the power states added for it default to disabled where they are described, and enable them per SoC: - t6001.dtsi enables them on the M1 Max: MacBook Pro j314c and j316c, and Mac Studio j375c. - t6021.dtsi enables them on the M2 Max: MacBook Pro j414c and j416c, and Mac Studio j475c. - t6000.dtsi and t6020.dtsi include those files, so they define APPLE_ANE_UNTESTED first and the M1 Pro and M2 Pro stay off. - t6002 and t6022 (Ultra) build die 0 from the shared files and never see an enable, so they stay off. - t8103.dtsi gets the same enable block behind a one-line APPLE_ANE_UNTESTED define, so enabling the M1 ANE after a supervised boot is a one-line deletion. Power states that predate #155 (ane_sys and ane_sys_cpu on t600x and t8103, and the ANE states in t602x-pmgr.dtsi) keep their status. Where the ANE stays off, each device tree is the pre-#155 one plus disabled nodes, apart from the inert ane-alias-iova reserved-memory entry on t602x, which has no reg or size and is only read through the ANE's memory-region. On the M1 Max and M2 Max the device tree is unchanged, except that the t600x ANE power states now carry an explicit status = "okay". Found in a review of #155. Signed-off-by: Chris Kearney <chris@kearneymail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i (cherry picked from commit ecf86ec16ece1313dd16e135779bf7d93469f16f)
Joshua Warren's #155 adds the M2 (T8112) ANE with its node, mailbox and DARTs disabled, since it has not run there. The seven power states added for it (ane_sys_cpu, ane_td, ane_base and ane_set1 to ane_set4) have no status, though, so they are live on every boot of an M2 MacBook Air, 13" MacBook Pro or Mac mini. The pmgr driver probes each of them: it reads the register, sets the auto-PM enable bit if the state is active, and genpd turns unused domains off late in boot. Nothing consumes them while the ANE is disabled. Disable them as well, so the ANE and everything only it uses are off together, and say so above them. ane_sys predates #155 and keeps its status. Found in a review of #155. Signed-off-by: Chris Kearney <chris@kearneymail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i (cherry picked from commit 72c7bd0c7a03d768daf7774e9481d9024825434c)
The M2 ANE module from Joshua Warren's #155 logs its probe and firmware boot progress with dev_emerg(). These lines came from bring-up, where each one had to reach the console before the write it announced. With fw_start on by default, an M2 Max now prints about twenty emergency-level lines on every boot, which go to every console and terminal regardless of loglevel and bury real emergencies. Use the level each message deserves: - the per-phase BOOT-PHASE markers and the probe register readouts (ane_cpu ACTUAL, PWGATE, the engine reads, staging and dispatch, the legacy ack and hello start) become dev_dbg(); dynamic debug still gets them for crash attribution; - the outcome lines (sequence returned, done without a CPU start, the legacy hello result) become dev_info(); - the SCRATCH/RVBAR/tick dump, printed only when the ANE CPU was released but never reported READY, becomes dev_err(). The 30 ms drain after each phase marker is left as it is, and the comment above it now says how to see the marker. No other drivers/accel/ane code logs at emergency, alert or critical level. Found in a review of #155. Signed-off-by: Chris Kearney <chris@kearneymail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i (cherry picked from commit d7ec38757843b95b2414d385965358d615647f01)
ane_t6021.ko is built from ane_t6021_rtclient_main.o, ane_t6021_fwload.o and ane_t6021_boot.o, and each of the three carries its own MODULE_LICENSE() and MODULE_DESCRIPTION(), so modinfo reports three licenses and three descriptions for the one module. The comment on the extra copies says the objects also link into an ane_t6021_rtclient.ko, but the Makefile from Joshua Warren's #155 builds no such module. Keep the set next to module_init() in ane_t6021_rtclient_main.c and drop the copies, and their comment, from the fwload and boot objects. The MODULE_FIRMWARE() lines stay with the firmware loader. Found in a review of #155. Signed-off-by: Chris Kearney <chris@kearneymail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FwdG63dRaMrRbYrUBkSa1i (cherry picked from commit 9b8b60c4c8a11c969a547f3f8805664ae176ed72)
Both modules log bring-up tracing at info level on every probe: the ANERD/ANEWR recovery trace and the ps probe SET window reads in ane_tm.c, the ANE-resume progress lines and the first ps probe in ane_drv.c, one line for each DART in ane_dart.c, and in ane_t6021 each ChMan table entry, each RTKit endpoint start and app message, the CONFIG_GET words, and the firmware alias, PMU map and staging addresses. Make them dev_dbg(). Dynamic debug still shows them for crash attribution. The outcome lines stay at info level: DART containment armed, loaded ane, tm recovered, the ChMan table result, the chip revision, the boot result lines and loaded ane_t6021. Faults stay at error and warning level. No other code changes. After this change, the only info lines on the ane probe path are "DART containment armed" and "loaded ane". Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The ane module takes a runtime PM reference in probe and holds it until remove, so the ANE power domains and its three DARTs stay powered for as long as the driver is bound, also when no process uses the ANE. Drop the probe reference at the end of probe and use runtime PM autosuspend. The device suspends autosuspend_ms (default 1500) after the last file open, ioctl or close, and the next one resumes it through ane_runtime_resume(), which enables the task manager again. The new module parameter autosuspend_ms=0 keeps the device powered while the driver is bound. power/autosuspend_delay_ms and power/control change the behavior at run time. Every path that touches the engine or the ANE's own DART registers now holds a reference: - the ioctls, through one wrapper for the native and the 32-bit compat entry points, so both get the command filter and the reference; - the reset sysfs attribute, which power-cycles the partitions and then writes the engine; - the file release, which frees the BOs of the file (each unmap flushes the DART TLBs) and can run the recovery in postclose. It keeps a reference to the struct device, because drm_release() can free the ane_device; - remove, which unmaps the remaining BOs and detaches the power domains. apple-dart saves and restores the stream TCR and TTBR registers in its own runtime PM callbacks, and the ANE is its consumer through a DL_FLAG_PM_RUNTIME device link, so the IOMMU state survives the suspend. Measurements on hardware are pending. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
BO_INIT maps a buffer object one page at a time with iommu_map(). Each
call syncs the TLB of every DART in the domain, so a buffer of N pages
costs 3 * N TLB invalidates on the three ANE DARTs. A 458 MB buffer has
27,955 pages and needs 83,865 invalidates.
Map the buffer with one iommu_map_sgtable() instead. iommu_map_sg()
writes the PTEs of each physically contiguous run and syncs the TLBs
once for the whole range. Keep the old per-page path behind the new
module parameter map_batch (default 1; 0 selects the old path). BOs
mapped either way unmap the same way.
Keep the stray PTE recovery on both paths. iommu_map_sg() unmaps what it
mapped before it returns an error, so after -EEXIST every valid PTE left
in the reserved range is a stray: clear the range page by page and try
once more. A short return would give a BO whose tail has no PTEs, so
clear the range page by page and fail BO_INIT with -EIO. The page by
page clear also serves the stale-mapping purge in probe.
Measured with map_batch=1 against map_batch=0, with bit-exact program
outputs and exact job counts:
M1 (T8103) laptop: BO_INIT 179.85 ms -> 22.77 ms,
cold open 165 to 173 ms faster
M1 Max (T6001) laptop: BO_INIT 232.7 ms -> 24.7 ms,
open 787.9 ms -> 574.3 ms
A stress run was clean on both.
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
The ANE node, its DARTs, its mailbox and the power states only it uses are disabled on the M1 (T8103), the M1 Pro (T6000) and the M2 Pro (T6020) behind APPLE_ANE_UNTESTED, because the driver had run only on the M1 Max and the M2 Max. It has now run with this tree's own driver on all three. Each chip has a passing row in the public community dataset (promotion_check --remote: judged, driver_source=intree, 20 smoke calls that match the golden bit for bit, no ANE, DART or mailbox fault): M1 (T8103) row 3559e0f328ba M1 Pro (T6000) row 6eb94f49985b M2 Pro (T6020) row 3c9389040f51 Remove the define from t6000.dtsi, t6020.dtsi and t8103.dtsi. No file defines it after this, so also remove the #ifndef APPLE_ANE_UNTESTED guards in t6001.dtsi, t6021.dtsi and t8103.dtsi, and correct the comments that said the ANE had not run on the M1 Pro and the M2 Pro. The ANE is now enabled on the t8103 boards (j274, j293, j313, j456, j457), the t6000 boards (j314s, j316s) and the t6020 boards (j414s, j416s, j474s). The DTBs of the t6001, t6002, t6021, t6022 and t8112 boards do not change: t6002.dtsi and t6022.dtsi include neither t6001.dtsi nor t6021.dtsi, so the ANE stays disabled on the M1 Ultra (T6002), the M2 Ultra (T6022) and the M2 (T8112). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Closing any ANE file cleared the global wedge before recovery checked it, so the reset was skipped and live DMA backing could be freed or reused. Retry recovery with the wedge and module pin intact. Only the existing successful reset path may clear them; a failed reset requires a reboot and must preserve resources across unrelated file closes. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The firmware reference flag prevented physical deallocation but did not stop BO_FREE or the last VMA close returning an in-flight IO BO to the global pool. Take one kref per IO element under bo_lock and release all acquired references only after the command completes. Validation errors unwind the same reference budget, and firmware failures latch quarantine before any final put can recycle storage. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
A failed drain freed scratch pages and IOVA reservations before attempting to stop the DMA-active engine. Store the bounded scratch registry on the device, protected by engine_lock, so it survives the request's return. Reclaim it with the existing preserved BO registry only after successful recovery or a safe removal. Normal confirmed-idle completion still releases scratch immediately. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closing any ANE file cleared the global wedge before recovery checked
it, so the reset was skipped and live DMA backing could be freed or
reused. Retry recovery with the wedge and module pin intact. Only the
existing successful reset path may clear them; a failed reset requires
a reboot and must preserve resources across unrelated file closes.
The firmware reference flag prevented physical deallocation but did
not stop BO_FREE or the last VMA close returning an in-flight IO BO
to the global pool. Take one kref per IO element under bo_lock and
release all acquired references only after the command completes.
Validation errors unwind the same reference budget, and firmware
failures latch quarantine before any final put can recycle storage.
A failed drain freed scratch pages and IOVA reservations before
attempting to stop the DMA-active engine. Store the bounded scratch
registry on the device, protected by engine_lock, so it survives
the request's return. Reclaim it with the existing preserved BO
registry only after successful recovery or a safe removal. Normal
confirmed-idle completion still releases scratch immediately.
Follow-up to #155; original contributor commits are preserved. These fixes are based on public Linux/PR source and Linux-side tests.
Validation: full arm64 Image, modules and DTB build passed; strict checkpatch passed for the final code changes with only the required Assisted-by trailer diagnostic excluded. Deterministic source-extracted regression tests passed, with the original implementation failing the relevant negative control.
Hardware qualification on aurora-edge is pending. No boot, suspend, fault-injection or firmware recovery pass is claimed. The publication gate is separate from runtime acceptance.
🤖 Generated with Claude Code