From 0c01afde5108ed24870220ab470cfca5fedd5e73 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 02:45:01 +1100 Subject: [PATCH 1/3] dt-bindings: npu: apple,ane: document T8122 (M3) H15 ANE Document apple,t8122-ane (single H15 engine, ane-type 0xb0, one interrupt, three register windows engine/pmgr/aux-0, five ANE power domains, five DAPF records, and preloaded firmware) and allow the T8122 27.2 DATA IOVA (0x100000c8000) and T8132 27.2 DATA IOVA (0x100000bc000) in apple,firmware-iovas. Signed-off-by: Ryan Murray --- .../devicetree/bindings/npu/apple,ane.yaml | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/npu/apple,ane.yaml b/Documentation/devicetree/bindings/npu/apple,ane.yaml index 999599f852d8a..033bfd15cf963 100644 --- a/Documentation/devicetree/bindings/npu/apple,ane.yaml +++ b/Documentation/devicetree/bindings/npu/apple,ane.yaml @@ -23,7 +23,10 @@ description: yet established. T8132 has a single H16 engine, two interrupts, six register windows (no second-engine aux-3), and five DAPF records. Its virtual ANE-SYS-V gate resolves to the ANE system domain; ANE-SYS-V-PMP - is a firmware notification gate with no physical PMGR power state. + is a firmware notification gate with no physical PMGR power state. T8122 + has a single H15 engine, one interrupt, three register windows (engine, + pmgr, aux-0), five ANE power domains, five DAPF records, and preloaded + firmware. properties: compatible: @@ -37,6 +40,7 @@ properties: - apple,t6041-ane - apple,t6050-ane - apple,t8112-ane + - apple,t8122-ane - apple,t8132-ane - apple,t8140-ane - apple,t8142-ane @@ -139,12 +143,13 @@ properties: $ref: /schemas/types.yaml#/definitions/uint64-array items: - const: 0x10000000000 - - const: 0x100000c0000 + - enum: [0x100000bc000, 0x100000c0000, 0x100000c8000] description: - Device addresses of the preloaded TEXT and DATA segments. Their sizes - are 0xc0000 and 0x2ac000 bytes respectively. The bootloader supplies - the physical reservations. The device addresses are fixed by the - firmware layout and may be described statically. + Device addresses of the preloaded TEXT and DATA segments. The bootloader + supplies the physical reservations. The device addresses are fixed by the + firmware layout (TEXT at 0x10000000000; DATA at 0x100000bc000 on T8132 + 27.2, 0x100000c0000 on H16/H17 26.x, or 0x100000c8000 on T8122 27.2) and + may be described statically. apple,dapf-ranges: $ref: /schemas/types.yaml#/definitions/uint64-matrix @@ -155,7 +160,7 @@ properties: - description: Physical start address, inclusive - description: Physical end address, inclusive description: - Four (five on T6050 and T8132) DART address protection filter (DAPF) + Four (five on T6050, T8122 and T8132) DART address protection filter (DAPF) ranges, in hardware record order. Each pair contains inclusive 64-bit physical bounds, not a base and length. The same records apply to all three ANE DARTs. Firmware accesses these registers through identity mappings of the @@ -175,7 +180,7 @@ properties: apple,ane-type: $ref: /schemas/types.yaml#/definitions/uint32 - enum: [0x100, 0x110, 0x200] + enum: [0xb0, 0x100, 0x110, 0x200] description: Firmware generation identifier supplied by the bootloader apple,firmware-preloaded: @@ -366,6 +371,33 @@ allOf: - apple,ane-type - apple,firmware-preloaded - apple,dapf-ranges + - if: + properties: + compatible: + const: apple,t8122-ane + then: + properties: + interrupts: + maxItems: 1 + reg: + minItems: 3 + maxItems: 3 + reg-names: + items: + - const: engine + - const: pmgr + - const: aux-0 + power-domains: + minItems: 5 + maxItems: 5 + apple,ane-type: + const: 0xb0 + apple,dapf-ranges: + minItems: 5 + required: + - apple,ane-type + - apple,firmware-preloaded + - apple,dapf-ranges - if: properties: compatible: @@ -388,6 +420,7 @@ allOf: - apple,t8140-ane - apple,t6041-ane - apple,t6050-ane + - apple,t8122-ane - apple,t8142-ane - apple,t8132-ane then: From 0882c538809a9d4b20ee6367fc0583c898baceb3 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 02:45:01 +1100 Subject: [PATCH 2/3] arm64: dts: apple: t8122: describe and enable M3 Neural Engine on J615 Add the four ANE sub-block PMGR power states (ane_mpm, ane_cpu, ane_td, ane_base), three ANE DARTs (311800000/311810000/311820000), and the /soc/ane@310000000 node (disabled at SoC level) to T8122, and enable them on J615 (M3 Air). Mark ps_ane_sys and ps_ane_cpu with apple,no-auto-pm so PMGR does not set AUTO_ENABLE behind the cold-started ANE firmware during startup. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8122-j615.dts | 16 ++++++ .../boot/dts/apple/t8122-peripherals.dtsi | 57 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8122-pmgr.dtsi | 38 +++++++++++++ 3 files changed, 111 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8122-j615.dts b/arch/arm64/boot/dts/apple/t8122-j615.dts index a03573b0e2c38..67de05d68cf67 100644 --- a/arch/arm64/boot/dts/apple/t8122-j615.dts +++ b/arch/arm64/boot/dts/apple/t8122-j615.dts @@ -180,3 +180,19 @@ &nvram_qspi { read-only; }; + +&ane_dart0 { + status = "okay"; +}; + +&ane_dart1 { + status = "okay"; +}; + +&ane_dart2 { + status = "okay"; +}; + +&ane { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8122-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8122-peripherals.dtsi index 355199f3a6a86..1e4b51a2d791e 100644 --- a/arch/arm64/boot/dts/apple/t8122-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8122-peripherals.dtsi @@ -141,12 +141,69 @@ status = "disabled"; }; + ane_dart0: iommu@311800000 { + compatible = "apple,t8122-dart", "apple,t8110-dart"; + reg = <0x3 0x11800000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_ane_sys>; + apple,dma-range = <0x0 0x0 0x400 0x0>; + status = "disabled"; + }; + dart_ane_companion3: filter@311804000 { compatible = "apple,t8122-dapf", "apple,dapf"; reg = <0x3 0x11804000 0x0 0x4000>; status = "disabled"; }; + ane_dart1: iommu@311810000 { + compatible = "apple,t8122-dart", "apple,t8110-dart"; + reg = <0x3 0x11810000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_ane_sys>; + apple,dma-range = <0x0 0x0 0x400 0x0>; + status = "disabled"; + }; + + ane_dart2: iommu@311820000 { + compatible = "apple,t8122-dart", "apple,t8110-dart"; + reg = <0x3 0x11820000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_ane_sys>; + apple,dma-range = <0x0 0x0 0x400 0x0>; + status = "disabled"; + }; + + ane: ane@310000000 { + compatible = "apple,t8122-ane"; + reg = <0x3 0x10000000 0x0 0x2000000>, + <0x2 0xd0700000 0x0 0x18000>, + <0x2 0xd0724000 0x0 0x4000>; + reg-names = "engine", "pmgr", "aux-0"; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&ane_dart0 0>, <&ane_dart1 0>, <&ane_dart2 0>; + power-domains = <&ps_ane_sys>, <&ps_ane_cpu>, <&ps_ane_mpm>, + <&ps_ane_td>, <&ps_ane_base>; + apple,ane-type = <0xb0>; + apple,firmware-preloaded; + /* ADT dapf-instance-0: inclusive CPU addresses, in record order. */ + apple,dapf-ranges = /bits/ 64 <0x2a5468000 0x2a5468003>, + /bits/ 64 <0x2d0700438 0x2d070043b>, + /bits/ 64 <0x2d070c000 0x2d070c01b>, + /bits/ 64 <0x2d072682c 0x2d072682f>, + /bits/ 64 <0x292468000 0x292468003>; + /* Default layout; the loader supplies per-boot physical reservations. */ + apple,firmware-iovas = /bits/ 64 <0x10000000000 0x100000c8000>; + status = "disabled"; + }; + apcie1_piodma: dma-controller@595010000 { compatible = "apple,t8122-pcie-piodma", "apple,pcie-piodma"; reg = <0x5 0x95010000 0x0 0x4000>, diff --git a/arch/arm64/boot/dts/apple/t8122-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8122-pmgr.dtsi index 982cdc301e194..05bbe95509d71 100644 --- a/arch/arm64/boot/dts/apple/t8122-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8122-pmgr.dtsi @@ -792,6 +792,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "ane_sys"; + apple,no-auto-pm; }; ps_apcie_gp: power-controller@440 { @@ -1119,6 +1120,43 @@ power-domains = <&ps_venc_me0>; }; + ps_ane_mpm: power-controller@c000 { + compatible = "apple,t8122-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc000 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ane_mpm"; + power-domains = <&ps_ane_sys>; + }; + + ps_ane_cpu: power-controller@c008 { + compatible = "apple,t8122-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc008 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ane_cpu"; + apple,no-auto-pm; + power-domains = <&ps_ane_sys>; + }; + + ps_ane_td: power-controller@c010 { + compatible = "apple,t8122-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc010 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ane_td"; + power-domains = <&ps_ane_sys>; + }; + + ps_ane_base: power-controller@c018 { + compatible = "apple,t8122-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc018 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ane_base"; + power-domains = <&ps_ane_td>, <&ps_ane_cpu>; + }; + ps_disp_cpu: power-controller@10000 { compatible = "apple,t8122-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; reg = <0x10000 4>; From abf39d86cf87d8e82fb23e3b929cea59beb287b1 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 02:45:02 +1100 Subject: [PATCH 3/3] accel/ane: h15: support M3 (T8122) 27.2 ANE on shared H16 backend Wire T8122 (M3, H15 on macOS 27.2 / 26B123) directly into the shared AP-direct H16 backend and HWX validator without chip or firmware gates: - Replace fixed H16/H17 HWX descriptor branches with a data-driven target table supporting H15 (0x890/0x8b0 record offsets, 8 header words, trailer BAR 5, no perf record, zero-prologue task descriptors) and 1-byte/4-byte-header task relocation. - Guard optional CE setup when build->ce == 0 (T8122 has no CE block) and enable switch_safe program switching for chip_family >= 15. - Add ane_t8122_platform, ane_h15_mmio_t8122 (DART rev 2.0, 5 DAPF records at DART0+0x4000), ane_h15_build_t8122_26b123 (ASC wrapper at +0x1400044, scratch at +0x1840050, 27.2 firmware-requested table, preload tail heap, 2 ms power-gate hold, cold restart + program replay across sleep), and the J615 26B123 cross-boot preload digest pin. - Add KUnit coverage for the T8122 platform definition, zero-CE H15 boot path, and H15 HWX validation/relocation. Signed-off-by: Ryan Murray --- drivers/accel/ane/ane_fw_platform.c | 59 ++++++++ drivers/accel/ane/ane_fw_platform.h | 1 + drivers/accel/ane/ane_fw_platform_test.c | 27 ++++ drivers/accel/ane/ane_fw_transport.h | 2 +- drivers/accel/ane/ane_h16_boot.h | 9 +- drivers/accel/ane/ane_h16_boot_data.h | 85 ++++++++++++ drivers/accel/ane/ane_h16_boot_test.c | 21 +++ drivers/accel/ane/ane_h16_hwx.c | 145 ++++++++++++++------ drivers/accel/ane/ane_h16_hwx.h | 3 +- drivers/accel/ane/ane_h16_hwx_test.c | 80 +++++++++++ drivers/accel/ane/ane_h16_program.c | 27 +++- drivers/accel/ane/ane_h16_tasks.h | 34 +++-- drivers/accel/ane/ane_t6021_rtclient_main.c | 5 + 13 files changed, 439 insertions(+), 59 deletions(-) diff --git a/drivers/accel/ane/ane_fw_platform.c b/drivers/accel/ane/ane_fw_platform.c index 40212a20e2768..1963f6b6b1050 100644 --- a/drivers/accel/ane/ane_fw_platform.c +++ b/drivers/accel/ane/ane_fw_platform.c @@ -33,6 +33,20 @@ static const u32 ane_t8132_reg_sizes[] = { 0x2000000, 0x18000, 0x4000, 0x30000, 0xff4000, 0x4000, }; +/* T8122 (M3) H15: engine, PMGR and PMGR aux-0 windows from the ADT. */ +static const char * const ane_t8122_reg_names[] = { + "engine", "pmgr", "aux-0", +}; + +static const u32 ane_t8122_reg_sizes[] = { + 0x2000000, 0x18000, 0x4000, +}; + +/* The same five domains; ANE_SYS sits at +0x438 in the T8122 PMGR. */ +static const u32 ane_t8122_power_words[] = { + 0x438, 0xc008, 0xc000, 0xc010, 0xc018, +}; + /* Offsets in reg[1]; genpd, never the ANE driver, owns transitions. */ static const u32 ane_h16_power_words[] = { 0x3c0, 0xc008, 0xc000, 0xc010, 0xc018, @@ -64,6 +78,51 @@ static const u8 ane_t6050_text_pin_27_0[] = { 0xd1, 0xa2, 0x20, 0xd0, 0xee, 0x43, 0x8b, 0x8f, }; +/* + * M3 (T8122): H15 engine running the macOS 27.2 (26B123) firmware on the + * shared H16 AP-direct backend: ASC wrapper at +0x1400000, scratch at + * +0x1840050, doorbell/IPI at +0x1844000, ANE_SYS at PMGR +0x438, and five + * DAPF records at DART0 + 0x4000. Cold restart + program replay across sleep. + */ +const struct ane_fw_platform ane_t8122_platform = { + .h16_profiles = ane_t8122_profiles_26b123, + .h16_profile_count = ARRAY_SIZE(ane_t8122_profiles_26b123), + .h16_mmio = ane_h15_mmio_t8122, + .h16_mmio_count = ARRAY_SIZE(ane_h15_mmio_t8122), + .dart_params = 0x8, + .dapf_dart = 0, + .dapf_offset = 0x4000, + .dapf_size = SZ_16K, + .dapf_count = 5, + .soc = 0x8122, + .chip_family = 15, + .ane_type = 0xb0, + .hwx_subtype = 6, + .task_generation = 15, + .interrupt_count = 1, + .irq_role = ANE_FW_IRQ_UNKNOWN, + .owner = ANE_FW_OWNER_AP, + .reg_names = ane_t8122_reg_names, + .reg_sizes = ane_t8122_reg_sizes, + .reg_count = ARRAY_SIZE(ane_t8122_reg_names), + .wrapper = 0x1400000, + .mailbox = 0x1408000, + .scratch = 0x1840050, + .doorbell = 0x1844000, + .irq_status = 0x184c000, + .irq_ack = 0x1850000, + .power_words = ane_t8122_power_words, + .power_count = ARRAY_SIZE(ane_t8122_power_words), + .build_name = "27.2 26B123", + .preload_dva = { 0x10000000000, 0x100000c8000 }, + .preload_size = { 0xc8000, 0x2a4000 }, + .stream_mask = BIT(0), + .sleep_cold = true, + .boot_qualified = true, + .firmware_preloaded = true, + .safe_reset = false, +}; + const struct ane_fw_platform ane_h16_platform = { .h16_profiles = ane_h16_profiles, .h16_profile_count = ARRAY_SIZE(ane_h16_profiles), diff --git a/drivers/accel/ane/ane_fw_platform.h b/drivers/accel/ane/ane_fw_platform.h index edceacedc9553..4e7799273da53 100644 --- a/drivers/accel/ane/ane_fw_platform.h +++ b/drivers/accel/ane/ane_fw_platform.h @@ -186,6 +186,7 @@ ane_fw_sleep_path(const struct ane_fw_platform *platform) extern const struct ane_fw_platform ane_h16_platform, ane_h17_platform, ane_t6050_platform, ane_t8142_platform; +extern const struct ane_fw_platform ane_t8122_platform; extern const struct ane_fw_platform ane_t8132_platform; int ane_fw_platform_preflight(struct platform_device *pdev, const struct ane_fw_platform *soc); diff --git a/drivers/accel/ane/ane_fw_platform_test.c b/drivers/accel/ane/ane_fw_platform_test.c index 70e7bc1167e29..31119a89111aa 100644 --- a/drivers/accel/ane/ane_fw_platform_test.c +++ b/drivers/accel/ane/ane_fw_platform_test.c @@ -89,6 +89,32 @@ static void ane_platform_staged_bind_test(struct kunit *test) } #if IS_BUILTIN(CONFIG_DRM_ACCEL_ANE) && IS_BUILTIN(CONFIG_DRM_ACCEL_ANE_FW_KUNIT_TEST) +/* M3 (T8122) H15: three reg windows, five DAPF records at DART0 + 0x4000, cold sleep. */ +static void ane_t8122_platform_test(struct kunit *test) +{ + struct platform_device *pdev = platform_device_alloc("ane-t8122", -1); + u64 phys[] = { 0x100000000, 0x200000000 }; + + KUNIT_ASSERT_NOT_NULL(test, pdev); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.soc, 0x8122U); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.chip_family, 15U); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.ane_type, 0xb0U); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.hwx_subtype, 6U); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.reg_count, 3U); + KUNIT_EXPECT_STREQ(test, ane_t8122_platform.reg_names[2], "aux-0"); + KUNIT_EXPECT_FALSE(test, ane_t8122_platform.has_xl); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.dapf_dart, 0U); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.dapf_offset, 0x4000U); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.dapf_count, 5); + KUNIT_EXPECT_EQ(test, ane_t8122_platform.power_words[0], 0x438U); + KUNIT_EXPECT_TRUE(test, ane_t8122_platform.sleep_cold); + KUNIT_EXPECT_TRUE(test, ane_fw_preload_ranges_valid(&ane_t8122_platform, phys, + ane_t8122_platform.preload_size, + ane_t8122_platform.preload_dva)); + KUNIT_EXPECT_EQ(test, ane_fw_platform_preflight(pdev, &ane_t8122_platform), -EINVAL); + platform_device_put(pdev); +} + /* One engine: no aux-3, five DAPF records; a node without DT is refused. */ static void ane_t8132_platform_test(struct kunit *test) { @@ -221,6 +247,7 @@ static void ane_t8142_bridge_ops_test(struct kunit *test) static struct kunit_case ane_fw_platform_cases[] = { #if IS_BUILTIN(CONFIG_DRM_ACCEL_ANE) && IS_BUILTIN(CONFIG_DRM_ACCEL_ANE_FW_KUNIT_TEST) + KUNIT_CASE(ane_t8122_platform_test), KUNIT_CASE(ane_t8132_platform_test), KUNIT_CASE(ane_t8132_builds_test), KUNIT_CASE(ane_t6050_builds_test), diff --git a/drivers/accel/ane/ane_fw_transport.h b/drivers/accel/ane/ane_fw_transport.h index e0e1a0edd1211..bb166d37f1554 100644 --- a/drivers/accel/ane/ane_fw_transport.h +++ b/drivers/accel/ane/ane_fw_transport.h @@ -377,7 +377,7 @@ ane_fw_transport_bar_context(struct ane_fw_transport *t, u8 *copy, size_t size) */ static inline bool ane_fw_transport_switch_safe(const struct ane_fw_transport *t) { - return t->soc->chip_family == 16 || t->soc->chip_family == 17; + return t->soc->chip_family >= 15; } /* ane_fw_transport_publish_at() offset that copies to the end of the arena. */ diff --git a/drivers/accel/ane/ane_h16_boot.h b/drivers/accel/ane/ane_h16_boot.h index 671e2e3ec5dbf..a606deb941e6e 100644 --- a/drivers/accel/ane/ane_h16_boot.h +++ b/drivers/accel/ane/ane_h16_boot.h @@ -439,10 +439,13 @@ static inline int ane_h16_prepare(struct ane_h16_boot *b) { const struct ane_h16_build *f = b->build; unsigned int i, j; - int ret = ane_h16_ce(b); + int ret; - if (ret) - return ret; + if (f->ce) { + ret = ane_h16_ce(b); + if (ret) + return ret; + } for (i = 0; i < f->tunable_count; i++) { const struct ane_h16_tunables *group = &f->tunables[i]; diff --git a/drivers/accel/ane/ane_h16_boot_data.h b/drivers/accel/ane/ane_h16_boot_data.h index b845bf347d211..8298ab635b7d6 100644 --- a/drivers/accel/ane/ane_h16_boot_data.h +++ b/drivers/accel/ane/ane_h16_boot_data.h @@ -600,4 +600,89 @@ static const struct ane_h16_profile ane_h16_profiles[] __maybe_unused = { }, }; +/* + * T8122 (M3) ANE DARTs, revision 2.0 (PARAMS3 0x2a2a0200). Same fault/protect/ + * lock and DAPF record layout as T6041/T8132, with the DAPF bank at DART0 + * + 0x4000. + */ +static const struct ane_h16_mmio ane_h15_mmio_t8122[] __maybe_unused = { + { + .dart_revision = 0x0200, + .dart_fault = 0x100, + .dart_address_lo = 0x170, + .dart_address_hi = 0x174, + .dart_protect = 0x200, + .dart_lock = 0x208, + .dapf_records = 0, + .dapf_stride = 0x40, + .dapf_end_mask = ~3ULL, + .dapf_r0 = 0x31, + .dapf_r4 = 0, + .dapf_r20 = 1, + }, +}; + +/* T8122 (M3) H15 27.2 (26B123): no CE block and no pre-RUN engine tunables. */ +static const struct ane_h16_build ane_h15_build_t8122_26b123 = { + .cpu_control = 0x1400044, + .rvbar = 0x1050000, + .ready = 0x08042006, + .run = 0x10, + .scratch_polls = 1000, + .scratch_delay_us = 1000, + .command_timeout_ns = 3000000000ULL, + .pool_dva = 0x10000384000, + .ipc_dva = 0x100003d0000, + .heap_dva = 0x100003e4000, + .shared_dva = 0x10001300000, + .expected_rvbar = 0x10000000001, + .pool_size = 0x40000, + .init_offset = 0x180, + .init_size = 0x174, + .config_span = 0x380000, + .config_window = 0x10000000, + .template_count = 64, + .template_word = 0x12c, + .template_value = 4, + .max_channels = 0x21, + .max_heap = SZ_16M, + .native_free = true, + .startup = { { 4, 12 }, { 0, 12 }, { 3, 16 }, { 0x22, 100 } }, +}; + +/* + * M3 Air (J615) 27.2 (26B123) preload: TEXT 0xc8000, DATA 0x2a4000. + * Patchbay cells in DATA order (GKTS, ECAP, ARcM mutable; ABOI, ZSOI fixed). + */ +static const struct ane_h16_preload_cell ane_h15_patchbay_26b123_t8122[] = { + { "GKTS", 0x6850, 8, true }, + { "ECAP", 0x6943, 8, true }, + { "ARcM", 0x6a18, 4, true }, + { "ABOI", 0x6a75, 8, false }, + { "ZSOI", 0x6a85, 4, false }, +}; + +static const struct ane_h16_preload_rule ane_h15_preload_26b123_j615 = { + .cells = ane_h15_patchbay_26b123_t8122, + .cell_count = ARRAY_SIZE(ane_h15_patchbay_26b123_t8122), + .zero_start = 0x2a4000, + .zero_end = 0x2a4000, + .text_size = 0xc8000, + .data_size = 0x2a4000, + .digest = { + 0xed, 0x4a, 0x5a, 0xcf, 0x99, 0x53, 0x21, 0xd1, + 0x51, 0xca, 0xc8, 0xec, 0x2d, 0x2b, 0xf1, 0x1a, + 0x0f, 0xb7, 0x34, 0x4c, 0x43, 0xc0, 0xec, 0x24, + 0x01, 0x6b, 0x59, 0x09, 0x37, 0xee, 0x29, 0x17, + }, +}; + +static const struct ane_h16_profile ane_t8122_profiles_26b123[] __maybe_unused = { + { + .identity = "H15 T8122 27.2 26B123 J615", + .preload = &ane_h15_preload_26b123_j615, + .build = &ane_h15_build_t8122_26b123, + }, +}; + #endif /* __ANE_H16_BOOT_DATA_H__ */ diff --git a/drivers/accel/ane/ane_h16_boot_test.c b/drivers/accel/ane/ane_h16_boot_test.c index b4ea8bebf04cb..88047e7d938f2 100644 --- a/drivers/accel/ane/ane_h16_boot_test.c +++ b/drivers/accel/ane/ane_h16_boot_test.c @@ -1318,6 +1318,26 @@ static void ane_h16_no_xl_test(struct kunit *test) KUNIT_EXPECT_EQ(test, s->xl_writes, 0U); } +/* H15 (T8122): no CE block, no tunables, five DAPF records, DART rev 0x200. */ +static void ane_h16_t8122_no_ce_test(struct kunit *test) +{ + struct ane_h16_sim *s = test->priv; + + s->build = ane_h15_build_t8122_26b123; + s->mmio = ane_h15_mmio_t8122[0]; + s->dart_params = 0x2a2a0200; + s->soc.h16_mmio = ane_h15_mmio_t8122; + s->soc.h16_mmio_count = ARRAY_SIZE(ane_h15_mmio_t8122); + s->soc.dapf_count = 5; + s->soc.has_xl = false; + s->ce_timeout = true; + s->expect_tuning = 0; + KUNIT_ASSERT_EQ(test, ane_h16_run(&s->boot, ANE_H16_STARTUP), 0); + KUNIT_EXPECT_EQ(test, s->tuning_writes, 0U); + KUNIT_EXPECT_EQ(test, s->ce_ack, 0ULL); + KUNIT_EXPECT_EQ(test, s->dapf_writes, 25U); +} + /* The T8132 boots with its own engine writes only: no XL or C1PPT. */ static void ane_h16_t8132_tunables_test(struct kunit *test) { @@ -1402,6 +1422,7 @@ static struct kunit_case ane_h16_boot_cases[] = { KUNIT_CASE(ane_h16_dapf_five_test), KUNIT_CASE(ane_h16_dapf_five_readback_test), KUNIT_CASE(ane_h16_no_xl_test), + KUNIT_CASE(ane_h16_t8122_no_ce_test), KUNIT_CASE(ane_h16_t8132_tunables_test), KUNIT_CASE(ane_h16_t8132_locked_test), KUNIT_CASE(ane_h16_t8132_locked_strobe_test), diff --git a/drivers/accel/ane/ane_h16_hwx.c b/drivers/accel/ane/ane_h16_hwx.c index cb98778bab3be..c8b6dfeeadda1 100644 --- a/drivers/accel/ane/ane_h16_hwx.c +++ b/drivers/accel/ane/ane_h16_hwx.c @@ -16,7 +16,62 @@ struct hwx_range { u64 start, size; }; +struct hwx_target { + u32 subtype; + u32 linear, mixed; + unsigned int header_words; + u32 trailer_bar; + bool has_perf_record; + bool allow_zero_prologue; + bool require_tight_end; + bool allow_stabs_note; + bool allow_slot5_table; + bool allow_zero_scratch_text_flags; +}; + +static const struct hwx_target *hwx_target(u32 subtype) +{ + static const struct hwx_target targets[] = { + { + .subtype = ANE_HWX_SUBTYPE_H15, + .linear = 0x890, + .mixed = 0x8b0, + .header_words = 8, + .trailer_bar = 5, + .allow_zero_prologue = true, + }, + { + .subtype = ANE_HWX_SUBTYPE_H16, + .linear = 0x8a0, + .mixed = 0x8c0, + .header_words = 9, + .trailer_bar = 4, + .has_perf_record = true, + .require_tight_end = true, + }, + { + .subtype = ANE_HWX_SUBTYPE_H17, + .linear = 0x8a0, + .mixed = 0x8c0, + .header_words = 9, + .trailer_bar = 4, + .has_perf_record = true, + .allow_zero_prologue = true, + .allow_stabs_note = true, + .allow_slot5_table = true, + .allow_zero_scratch_text_flags = true, + }, + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(targets); i++) + if (targets[i].subtype == subtype) + return &targets[i]; + return NULL; +} + struct hwx_parser { + const struct hwx_target *target; const u8 *bytes; size_t size, command_end; struct ane_h16_hwx info; @@ -117,7 +172,7 @@ static int hwx_segment(struct hwx_parser *p, const u8 *c, u32 length) * zin_ane_compiler 10.205 marks it 0 there too on H17 (relocations are checked below). */ flags = get_unaligned_le32(c + 68); - if (text && p->info.subtype == ANE_HWX_SUBTYPE_H17 && p->info.scratch.size) { + if (text && p->target->allow_zero_scratch_text_flags && p->info.scratch.size) { if (flags != 4 && flags) return -ENOEXEC; } else if (flags != (surface ? 6 : text ? (p->info.scratch.size ? 4 : 0) : 4)) { @@ -229,16 +284,16 @@ static u32 hwx_trailer_value(const u8 *c, u32 offset) static int hwx_program(struct hwx_parser *p) { + const struct hwx_target *t = p->target; const u8 *c = p->bytes + p->info.program_offset; struct ane_h16_hwx *info = &p->info; - u32 length = get_unaligned_le32(c + 4), records, record_limit, table, i; + u32 length = get_unaligned_le32(c + 4), records, record_limit, table, i, off, count; u32 prologue = 1; size_t final_end = 0; u64 work_limit = 0; - bool mixed = length == 0x8c0; + bool mixed = length == t->mixed; - /* H17 streams open with 0 (linked programs) or 1 (Apple's matmul and add output). */ - if (info->subtype == ANE_HWX_SUBTYPE_H17 && info->text.size >= 4 && + if (t->allow_zero_prologue && info->text.size >= 4 && !get_unaligned_le32(p->bytes + info->text.offset)) prologue = 0; /* Nonzero cells only; every other byte is checked below. */ @@ -250,9 +305,9 @@ static int hwx_program(struct hwx_parser *p) u8 *expected; int ret = -ENOEXEC; - if (length != 0x8a0 && !mixed) + if (length != t->linear && !mixed) return -ENOEXEC; - if (get_unaligned_le32(c + 0xc) != (mixed ? 0x22a : 0x222) || + if (get_unaligned_le32(c + 0xc) != length / 4 - 6 || get_unaligned_le64(c + 0x10) != info->text.vm || get_unaligned_le64(c + 0x810) != info->text.vm || get_unaligned_le64(c + 0x20) != info->constants.vm || @@ -261,7 +316,7 @@ static int hwx_program(struct hwx_parser *p) get_unaligned_le32(c + 0x838) != U32_MAX || get_unaligned_le32(c + 0x83c) != U32_MAX || get_unaligned_le32(c + 0x844) != 0xffff || - get_unaligned_le32(c + 0x848) != (mixed ? 0x8b8 : 0x898)) + get_unaligned_le32(c + 0x848) != length - 8) return -ENOEXEC; records = get_unaligned_le32(c + 0x860); info->tasks = get_unaligned_le32(c + 0x830); @@ -281,7 +336,7 @@ static int hwx_program(struct hwx_parser *p) * kernel fill consecutive slots from slot 6 (+0x70); Apple's zin_ane_compiler 10.205 * starts the same run at slot 5 (+0x60) on H17, the task stream naming slots 5, 6, 7. */ - table = info->subtype == ANE_HWX_SUBTYPE_H17 && get_unaligned_le64(c + 0x60) ? 0x60 : 0x70; + table = t->allow_slot5_table && get_unaligned_le64(c + 0x60) ? 0x60 : 0x70; for (i = 0; i < 5; i++) { u64 base = i < info->surface_count ? info->surfaces[i].section.vm : i == info->surface_count ? info->kernel.vm : 0; @@ -297,7 +352,7 @@ static int hwx_program(struct hwx_parser *p) */ for (i = 0; i < info->surface_count; i++) work_limit += info->surfaces[i].allocation; - if (get_unaligned_le32(c + (mixed ? 0x8b0 : 0x890)) > work_limit) + if (get_unaligned_le32(c + length - 16) > work_limit) return -ENOEXEC; /* Construct the exact fixed trailer and reserved-space expectation. */ @@ -308,29 +363,36 @@ static int hwx_program(struct hwx_parser *p) memcpy(expected + common[i], c + common[i], 4); for (i = 0; i < 5; i++) memcpy(expected + table + i * 16, c + table + i * 16, 8); - put_unaligned_le32(4, expected + 0x868); - put_unaligned_le32(mixed ? 4 : 2, expected + 0x870); - put_unaligned_le32(mixed ? 2 : 7, expected + 0x878); - put_unaligned_le32(8, expected + 0x87c); - put_unaligned_le32(mixed ? get_unaligned_le32(c + 0x858) : hwx_trailer_value(c, 0x880), - expected + 0x880); - put_unaligned_le32(mixed ? 3 : 9, expected + 0x888); - put_unaligned_le32(8, expected + 0x88c); + count = 1 + (mixed ? 2 : 0) + (t->has_perf_record ? 1 : 0); + put_unaligned_le32(t->trailer_bar, expected + 0x868); + put_unaligned_le32(count, expected + 0x870); + off = 0x878; if (mixed) { - put_unaligned_le32(0x08020004, expected + 0x890); - put_unaligned_le32(8, expected + 0x894); - put_unaligned_le32(7, expected + 0x898); - put_unaligned_le32(8, expected + 0x89c); - put_unaligned_le32(hwx_trailer_value(c, 0x8a0), expected + 0x8a0); - put_unaligned_le32(9, expected + 0x8a8); - put_unaligned_le32(8, expected + 0x8ac); + put_unaligned_le32(2, expected + off); + put_unaligned_le32(8, expected + off + 4); + put_unaligned_le32(get_unaligned_le32(c + 0x858), expected + off + 8); + off += 16; + put_unaligned_le32(3, expected + off); + put_unaligned_le32(8, expected + off + 4); + put_unaligned_le32(0x08020004, expected + off + 8); + put_unaligned_le32(8, expected + off + 12); + off += 16; } - memcpy(expected + (mixed ? 0x8b0 : 0x890), c + (mixed ? 0x8b0 : 0x890), 4); - memcpy(expected + (mixed ? 0x8b8 : 0x898), "main", 5); + if (t->has_perf_record) { + put_unaligned_le32(7, expected + off); + put_unaligned_le32(8, expected + off + 4); + put_unaligned_le32(hwx_trailer_value(c, off + 8), expected + off + 8); + off += 16; + } + put_unaligned_le32(9, expected + off); + put_unaligned_le32(8, expected + off + 4); + memcpy(expected + off + 8, c + off + 8, 4); + off += 16; + memcpy(expected + off, "main", 5); if (!memcmp(c, expected, length)) { - ret = ane_hx_task_stream_validate_limit(p->bytes + info->text.offset, - info->text.size, info->tasks, prologue, - &record_limit, &final_end); + ret = ane_hx_task_stream_validate_hdr(p->bytes + info->text.offset, + info->text.size, info->tasks, prologue, + t->header_words, &record_limit, &final_end); /* This compiler hint need not equal the encoded record count. */ if (!ret && (!records || records > record_limit)) ret = -ENOEXEC; @@ -339,8 +401,7 @@ static int hwx_program(struct hwx_parser *p) * zero blocks after it leave the engine armed, and the next * EXECUTE on the device times out. */ - if (!ret && info->subtype == ANE_HWX_SUBTYPE_H16 && - final_end != info->text.size) + if (!ret && t->require_tight_end && final_end != info->text.size) ret = -ENOEXEC; } kfree(expected); @@ -493,7 +554,7 @@ static int hwx_symbols(struct hwx_parser *p) * n_desc holds the stabs type number. They name no address; their strings are * still checked below. */ - bool h17 = p->info.subtype == ANE_HWX_SUBTYPE_H17; + bool h17 = p->target->allow_stabs_note; bool stab = h17 && (s[4] == 0x20 || s[4] == 0x80); if (strx >= p->strsize || @@ -549,8 +610,8 @@ static bool hwx_relocations_in_payload(const struct hwx_parser *p, unsigned long continue; } end = pos + words * 4; - record = pos + 9 * 4; - if ((get_unaligned_le32(text + pos + 8 * 4) & 3) == 3) + record = pos + p->target->header_words * 4; + if ((get_unaligned_le32(text + pos + (p->target->header_words - 1) * 4) & 3) == 3) record += 4; while (record < end) { u32 header = get_unaligned_le32(text + record); @@ -569,6 +630,7 @@ static bool hwx_relocations_in_payload(const struct hwx_parser *p, unsigned long int ane_h16_hwx_validate(const void *bytes, size_t size, struct ane_h16_hwx *info) { + const struct hwx_target *target; struct hwx_parser *p; const void *relocations; const u8 *c = bytes; @@ -579,11 +641,12 @@ int ane_h16_hwx_validate(const void *bytes, size_t size, struct ane_h16_hwx *inf if (!c || !info || size < 32 || size > ANE_H16_HWX_MAX || get_unaligned_le32(c) != 0xbeefface || get_unaligned_le32(c + 4) != 0x80 || - (get_unaligned_le32(c + 8) != ANE_HWX_SUBTYPE_H16 && - get_unaligned_le32(c + 8) != ANE_HWX_SUBTYPE_H17) || get_unaligned_le32(c + 12) != 2 || get_unaligned_le32(c + 24) != 0x200000 || get_unaligned_le32(c + 28)) return -ENOEXEC; + target = hwx_target(get_unaligned_le32(c + 8)); + if (!target) + return -ENOEXEC; count = get_unaligned_le32(c + 16); length = get_unaligned_le32(c + 20); if (!count || count > HWX_COMMANDS_MAX || !hwx_fits(32, length, size)) @@ -591,10 +654,11 @@ int ane_h16_hwx_validate(const void *bytes, size_t size, struct ane_h16_hwx *inf p = kzalloc_obj(*p); if (!p) return -ENOMEM; + p->target = target; p->bytes = bytes; p->size = size; p->command_end = 32 + (size_t)length; - p->info.subtype = get_unaligned_le32(p->bytes + 8); + p->info.subtype = target->subtype; for (i = 0; i < count; i++) { u32 cmd, len; @@ -628,7 +692,8 @@ int ane_h16_hwx_validate(const void *bytes, size_t size, struct ane_h16_hwx *inf goto invalid; p->tensors[p->tensor_count++] = pos; } else if (get_unaligned_le32(c + 8) == 4) { - if (p->info.program_offset || (len != 0x8a0 && len != 0x8c0)) + if (p->info.program_offset || + (len != p->target->linear && len != p->target->mixed)) goto invalid; p->info.program_offset = pos; } else { @@ -657,7 +722,7 @@ int ane_h16_hwx_validate(const void *bytes, size_t size, struct ane_h16_hwx *inf * LC_NOTE: zin_ane_compiler 10.205 (H17) records its runtime version * inline, offset 40 into this command, 4 bytes. It maps nothing. */ - if (p->info.subtype != ANE_HWX_SUBTYPE_H17 || p->note || len != 48 || + if (!p->target->allow_stabs_note || p->note || len != 48 || !hwx_name(c + 8, "rt.version") || get_unaligned_le64(c + 24) != 40 || get_unaligned_le64(c + 32) != 4 || !hwx_zero(c, 44, len)) goto invalid; diff --git a/drivers/accel/ane/ane_h16_hwx.h b/drivers/accel/ane/ane_h16_hwx.h index dedfa58741964..7b2fe402cad72 100644 --- a/drivers/accel/ane/ane_h16_hwx.h +++ b/drivers/accel/ane/ane_h16_hwx.h @@ -10,7 +10,8 @@ #define ANE_H16_SECTIONS 8 #define ANE_H16_REGIONS 7 #define ANE_H16_HWX_MAX (SZ_256M + SZ_1M) -/* Mach-O CPU subtypes of the two targets that share this container form. */ +/* Mach-O CPU subtypes of the targets that share this container form. */ +#define ANE_HWX_SUBTYPE_H15 6 #define ANE_HWX_SUBTYPE_H16 7 #define ANE_HWX_SUBTYPE_H17 9 diff --git a/drivers/accel/ane/ane_h16_hwx_test.c b/drivers/accel/ane/ane_h16_hwx_test.c index 05952de6b9ca1..896fd719fe3b7 100644 --- a/drivers/accel/ane/ane_h16_hwx_test.c +++ b/drivers/accel/ane/ane_h16_hwx_test.c @@ -829,6 +829,85 @@ static void hwx_h17_zin_test(struct kunit *test) #undef AS_H16 } +/* + * H15 (M3, subtype 6): 0x890 linear / 0x8b0 mixed program descriptor (no fp32 + * trailer record, trailer_bar 5), 8-word task header, prologue 0 or 1. + */ +static void hwx_h15_test(struct kunit *test) +{ + unsigned int form; + + for (form = 0; form < 2; form++) { + struct hwx_fixture *f = fixture_create(test, form, false); + struct ane_h16_hwx info = {}; + u32 prog_len = form ? 0x8b0 : 0x890; + u32 old_len = form ? 0x8c0 : 0x8a0; + u8 *c, *text, *section; + + KUNIT_ASSERT_NOT_NULL(test, f); + /* Shrink the program descriptor command by 16 bytes (drop key=7 record). */ + c = f->bytes + f->program; + put_unaligned_le32(ANE_HWX_SUBTYPE_H15, f->bytes + 8); + put_unaligned_le32(prog_len, c + 4); + put_unaligned_le32(form ? 0x226 : 0x21e, c + 0xc); + put_unaligned_le32(form ? 0x8a8 : 0x888, c + 0x848); + put_unaligned_le32(5, c + 0x868); + put_unaligned_le32(form ? 3 : 1, c + 0x870); + if (form) { + /* Mixed 0x8b0: keep key=2 and key=3, move key=9 to +0x898. */ + put_unaligned_le32(9, c + 0x898); + put_unaligned_le32(8, c + 0x89c); + put_unaligned_le32(0, c + 0x8a0); + put_unaligned_le32(0, c + 0x8a4); + memcpy(c + 0x8a8, "main", 5); + } else { + /* Linear 0x890: single key=9 record at +0x878. */ + put_unaligned_le32(9, c + 0x878); + put_unaligned_le32(8, c + 0x87c); + put_unaligned_le32(0, c + 0x880); + put_unaligned_le32(0, c + 0x884); + memcpy(c + 0x888, "main", 5); + } + /* Shift remaining load commands + symtab/strings back by 16 bytes. */ + memmove(c + prog_len, c + old_len, f->reloc + 8 - (f->program + old_len)); + f->cursor -= 16; + f->symtab -= 16; + f->symbols -= 16; + f->strings -= 16; + put_unaligned_le32(f->cursor - 32, f->bytes + 20); + put_unaligned_le32(f->symbols, f->bytes + f->symtab + 8); + put_unaligned_le32(f->strings, f->bytes + f->symtab + 16); + + /* H15 task stream: 8-word header + 2-word record (40 B) + 16 B prologue. */ + text = f->bytes + SZ_16K; + section = f->bytes + f->text_command + 72; + memset(text, 0, 64); + put_unaligned_le32(0, text); + put_unaligned_le32(10 << 16, text + 16); + put_unaligned_le32(0x4100 / 4, text + 48); + put_unaligned_le64(56, section + 40); + put_unaligned_le32(14, c + 0x824); + + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), 0); + KUNIT_EXPECT_EQ(test, info.subtype, ANE_HWX_SUBTYPE_H15); + KUNIT_EXPECT_EQ(test, info.tasks, 1U); + /* Prologue 1 is accepted too. */ + put_unaligned_le32(1, text); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), 0); + /* H16 rejects an H15 layout. */ + put_unaligned_le32(ANE_HWX_SUBTYPE_H16, f->bytes + 8); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), -ENOEXEC); + put_unaligned_le32(ANE_HWX_SUBTYPE_H15, f->bytes + 8); + /* A 9-word H16 task header fails H15 validation. */ + put_unaligned_le32(11 << 16, text + 16); + put_unaligned_le32(0, text + 48); + put_unaligned_le32(0x4100 / 4, text + 52); + put_unaligned_le64(60, section + 40); + put_unaligned_le32(15, c + 0x824); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), -ENOEXEC); + } +} + static struct kunit_case hwx_cases[] = { KUNIT_CASE(hwx_forms_test), KUNIT_CASE(hwx_header_test), @@ -849,6 +928,7 @@ static struct kunit_case hwx_cases[] = { KUNIT_CASE(hwx_load_resources_test), KUNIT_CASE(hwx_import_bounds_test), KUNIT_CASE(hwx_h17_zin_test), + KUNIT_CASE(hwx_h15_test), {} }; diff --git a/drivers/accel/ane/ane_h16_program.c b/drivers/accel/ane/ane_h16_program.c index e7d9c67bc89a9..c835fab0f1076 100644 --- a/drivers/accel/ane/ane_h16_program.c +++ b/drivers/accel/ane/ane_h16_program.c @@ -448,12 +448,35 @@ int ane_h16_custom_bars(const struct ane_h16_hwx_snapshot *snapshot, ret = ane_h16_hwx_snapshot_check(snapshot); if (ret) return ret; - if (!hwx->program_offset || snapshot->size < 0x8a0 || - hwx->program_offset > snapshot->size - 0x8a0) + if (!hwx->program_offset || snapshot->size < 0x890 || + hwx->program_offset > snapshot->size - 0x890) return -ENOEXEC; c = (const u8 *)snapshot->bytes + hwx->program_offset; *count = 0; length = get_unaligned_le32(c + 4); + if (length == 0x890) + return 0; + if (length == 0x8b0) { + if (snapshot->size < 0x8b0 || hwx->program_offset > snapshot->size - 0x8b0) + return -ENOEXEC; + bar = get_unaligned_le16(c + 0x890); + offset = c[0x893]; + width = c[0x894]; + if (!width || width > 16 || offset > 64 - width || dsid >= BIT(width)) + return -ENOEXEC; + bars[0] = (struct ane_h16_custom_bar) { + .configuration = 1, + .value_type = 1, + .bar = bar, + .bit_offset = offset, + .bit_width = width, + .value = dsid, + }; + *count = 1; + return 0; + } + if (snapshot->size < 0x8a0 || hwx->program_offset > snapshot->size - 0x8a0) + return -ENOEXEC; bar = get_unaligned_le32(c + 0x868); offset = get_unaligned_le32(c + 0x878); width = get_unaligned_le32(c + 0x87c); diff --git a/drivers/accel/ane/ane_h16_tasks.h b/drivers/accel/ane/ane_h16_tasks.h index e96ff85d778ab..166d46abdae0d 100644 --- a/drivers/accel/ane/ane_h16_tasks.h +++ b/drivers/accel/ane/ane_h16_tasks.h @@ -35,25 +35,27 @@ static inline bool ane_h16_register_valid(u32 word) /* * A stream opens with a 16-byte frame: little-endian u32 @prologue, then - * twelve reserved zero bytes. H16 programs open with 1; measured H17 programs - * open with 0 or 1. The last task may end at the end of the section; - * every other task is padded with zeros to 16 bytes. This structural gate - * does not replace container/tensor/aperture validation. + * twelve reserved zero bytes. H15/H16/H17 programs share this framing with + * @header_words fixed words per task (8 on H15, 9 on H16 and H17). The last + * task may end at the end of the section; every other task is padded with + * zeros to 16 bytes. This structural gate does not replace container/tensor/ + * aperture validation. */ static inline int -ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_tasks, - u32 prologue, u32 *record_limit, size_t *final_end) +ane_hx_task_stream_validate_hdr(const void *text, size_t size, u32 expected_tasks, + u32 prologue, unsigned int fixed_header_words, + u32 *record_limit, size_t *final_end) { const u8 *p = text; size_t pos = 16, last = 0; u32 tasks = 0, limit = 0; - if (!p || !expected_tasks || size < 16 || size > ANE_H16_TASK_MAX || - (size & 3) || get_unaligned_le32(p) != prologue || - memchr_inv(p + 4, 0, 12)) + if (!p || !expected_tasks || !fixed_header_words || size < 16 || + size > ANE_H16_TASK_MAX || (size & 3) || + get_unaligned_le32(p) != prologue || memchr_inv(p + 4, 0, 12)) return -ENOEXEC; while (pos < size) { - u32 words, header_words = 9; + u32 words, header_words = fixed_header_words; size_t end, padded, rec; if (size - pos < 16) @@ -65,10 +67,10 @@ ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_ta pos += 16; continue; } - if (words < 9 || words > (size - pos) / 4) + if (words < fixed_header_words || words > (size - pos) / 4) return -ENOEXEC; end = pos + words * 4; - if ((get_unaligned_le32(p + pos + 8 * 4) & 3) == 3) + if ((get_unaligned_le32(p + pos + (fixed_header_words - 1) * 4) & 3) == 3) header_words++; if (words < header_words) return -ENOEXEC; @@ -117,6 +119,14 @@ ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_ta return 0; } +static inline int +ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_tasks, + u32 prologue, u32 *record_limit, size_t *final_end) +{ + return ane_hx_task_stream_validate_hdr(text, size, expected_tasks, prologue, 9, + record_limit, final_end); +} + static inline int ane_hx_task_stream_validate(const void *text, size_t size, u32 expected_tasks, u32 prologue) { diff --git a/drivers/accel/ane/ane_t6021_rtclient_main.c b/drivers/accel/ane/ane_t6021_rtclient_main.c index 65ed18f09c580..e0adce4d01fb8 100644 --- a/drivers/accel/ane/ane_t6021_rtclient_main.c +++ b/drivers/accel/ane/ane_t6021_rtclient_main.c @@ -4423,6 +4423,10 @@ static void ane_rtclient_remove(struct platform_device *pdev) "remove HELD: no teardown — reboot reclaims\n"); } +static const struct ane_t602x_soc ane_t8122_soc = { + .platform = &ane_t8122_platform, +}; + static const struct ane_t602x_soc ane_h16_soc = { .platform = &ane_h16_platform, }; @@ -4448,6 +4452,7 @@ static const struct of_device_id ane_rtclient_of_match[] = { { .compatible = "apple,t6021-ane", .data = &ane_t6021_soc }, { .compatible = "apple,t6022-ane", .data = &ane_t6022_soc }, { .compatible = "apple,t8112-ane", .data = &ane_t8112_soc }, + { .compatible = "apple,t8122-ane", .data = &ane_t8122_soc }, { .compatible = "apple,t6041-ane", .data = &ane_h16_soc }, { .compatible = "apple,t8132-ane", .data = &ane_t8132_soc }, { .compatible = "apple,t8140-ane", .data = &ane_h17_soc },