diff --git a/Documentation/devicetree/bindings/npu/apple,ane.yaml b/Documentation/devicetree/bindings/npu/apple,ane.yaml index d254171112b02..c2ac6bac48fe9 100644 --- a/Documentation/devicetree/bindings/npu/apple,ane.yaml +++ b/Documentation/devicetree/bindings/npu/apple,ane.yaml @@ -26,7 +26,10 @@ description: 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. + firmware. On T8112 the boot loader may also hand over the firmware iBoot + preloaded (macOS 27.2 and later stubs). It then adds the TEXT and DATA + reservations, their device addresses and apple,firmware-preloaded, and + the driver cold-starts that firmware instead of staging a disk image. properties: compatible: @@ -137,7 +140,8 @@ properties: maxItems: 2 description: On T602x, the IOVA-only reservation of the firmware entry alias. - On T6041, T6050, T8132 and T8140, bootloader-provided physical TEXT + On T6041, T6050, T8132 and T8140, and on T8112 when the bootloader + hands the preload over, bootloader-provided physical TEXT and DATA preload reservations in that order. Each reservation must have no-map, must not be reusable, and must remain reserved until reboot. Physical addresses vary per boot and must not be hard-coded in a board DTS. @@ -150,14 +154,15 @@ properties: apple,firmware-iovas: $ref: /schemas/types.yaml#/definitions/uint64-array items: - - const: 0x10000000000 - - enum: [0x100000bc000, 0x100000c0000, 0x100000c8000] + - enum: [0x800000000, 0x10000000000] + - enum: [0x8000d8000, 0x100000bc000, 0x100000c0000, 0x100000c8000] description: 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. + 27.2, 0x100000c0000 on H16/H17 26.x, or 0x100000c8000 on T8122 27.2; + on T8112 27.2 TEXT at 0x800000000 and DATA at 0x8000d8000) and may be + described statically. apple,dapf-ranges: $ref: /schemas/types.yaml#/definitions/uint64-matrix @@ -168,7 +173,7 @@ properties: - description: Physical start address, inclusive - description: Physical end address, inclusive description: - Four (five on T6050, T8122 and T8132) DART address protection filter (DAPF) + Four (five on T6050, T8122 and T8132; four on T8112) 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 @@ -188,9 +193,15 @@ properties: apple,ane-type: $ref: /schemas/types.yaml#/definitions/uint32 - enum: [0xb0, 0x100, 0x110, 0x200, 0x210, 0x220] + enum: [0x80, 0xb0, 0x100, 0x110, 0x200, 0x210, 0x220] description: Firmware generation identifier supplied by the bootloader + dma-coherent: + description: + The engine's memory accesses are cache coherent. Required for the + shared backend's private firmware surfaces; on T8112 it is described + only for macOS 27.2 stubs, whose preload hand-off uses that backend. + apple,firmware-preloaded: type: boolean description: @@ -497,16 +508,32 @@ allOf: - const: pmgr - const: set - const: fuse + apple,exclave-assigned: false + required: + - interrupt-names + + - if: + properties: + compatible: + not: + contains: + enum: + - apple,t8112-ane + - apple,t8140-ane + - apple,t6041-ane + - apple,t6050-ane + - apple,t8122-ane + - apple,t8142-ane + - apple,t8132-ane + then: + properties: memory-region: maxItems: 1 memory-region-names: false apple,firmware-iovas: false apple,ane-type: false apple,firmware-preloaded: false - apple,exclave-assigned: false apple,dapf-ranges: false - required: - - interrupt-names - if: properties: @@ -565,9 +592,32 @@ allOf: minItems: 7 maxItems: 7 resets: false - memory-region: false + memory-region: + minItems: 2 + apple,ane-type: + const: 0x80 + apple,dapf-ranges: + maxItems: 4 required: - mboxes + if: + anyOf: + - required: + - memory-region + - required: + - memory-region-names + - required: + - apple,firmware-iovas + - required: + - apple,firmware-preloaded + then: + required: + - apple,firmware-preloaded + - memory-region + - memory-region-names + - apple,firmware-iovas + - apple,ane-type + - apple,dapf-ranges - if: properties: diff --git a/arch/arm64/boot/dts/apple/t8112-ane-fw27.dtsi b/arch/arm64/boot/dts/apple/t8112-ane-fw27.dtsi new file mode 100644 index 0000000000000..ed9d0ac94b6e5 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8112-ane-fw27.dtsi @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * T8112 with macOS 27 system firmware (27.2 stub): the boot loader may hand + * the ANE firmware iBoot preloaded over, and the driver then starts it cold + * on the shared AP-direct backend, whose private firmware surfaces need a + * cache-coherent client. The 13.5 legacy path keeps its own description. + */ + +&ane { + dma-coherent; +}; diff --git a/arch/arm64/boot/dts/apple/t8112-j413-fw27.dts b/arch/arm64/boot/dts/apple/t8112-j413-fw27.dts index 42bbfe557bd2c..c81560b529253 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413-fw27.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413-fw27.dts @@ -2,3 +2,4 @@ /* J413 with macOS 27 system firmware (27.2 stub). */ #include "t8112-j413.dts" #include "t8112-mtp-fw27.dtsi" +#include "t8112-ane-fw27.dtsi" diff --git a/arch/arm64/boot/dts/apple/t8112-j415-fw27.dts b/arch/arm64/boot/dts/apple/t8112-j415-fw27.dts index 043e97b0b60ac..32cf8efea00f8 100644 --- a/arch/arm64/boot/dts/apple/t8112-j415-fw27.dts +++ b/arch/arm64/boot/dts/apple/t8112-j415-fw27.dts @@ -2,3 +2,4 @@ /* J415 with macOS 27 system firmware (27.2 stub). */ #include "t8112-j415.dts" #include "t8112-mtp-fw27.dtsi" +#include "t8112-ane-fw27.dtsi" diff --git a/arch/arm64/boot/dts/apple/t8112-j473.dts b/arch/arm64/boot/dts/apple/t8112-j473.dts index 24e5eebfcff7e..4f336f3bc84fd 100644 --- a/arch/arm64/boot/dts/apple/t8112-j473.dts +++ b/arch/arm64/boot/dts/apple/t8112-j473.dts @@ -227,6 +227,7 @@ #include "t8112-j473-peripherals.dtsi" +#include "t8112-ane-fw27.dtsi" /* * The 27.2 GPU firmware keeps running through suspend-to-idle. Gating the GFX diff --git a/arch/arm64/boot/dts/apple/t8112-j493-fw27.dts b/arch/arm64/boot/dts/apple/t8112-j493-fw27.dts index 5dbac9ea74833..8349778149fe1 100644 --- a/arch/arm64/boot/dts/apple/t8112-j493-fw27.dts +++ b/arch/arm64/boot/dts/apple/t8112-j493-fw27.dts @@ -2,3 +2,4 @@ /* J493 with macOS 27 system firmware (27.2 stub). */ #include "t8112-j493.dts" #include "t8112-mtp-fw27.dtsi" +#include "t8112-ane-fw27.dtsi" diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 3b7e30fd444e1..3c88deef45f04 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -2016,6 +2016,17 @@ <&ps_ane_base>, <&ps_ane_set1>, <&ps_ane_set2>, <&ps_ane_set3>, <&ps_ane_set4>; mboxes = <&ane_mbox>; + /* + * For a boot loader preload hand-off (macOS 27.2 stubs), + * from the J473 27.2 ADT: ane-type and dart-ane + * dapf-instance-0, inclusive CPU addresses, in record + * order. The legacy disk loader ignores them. + */ + apple,ane-type = <0x80>; + apple,dapf-ranges = /bits/ 64 <0x22b45c000 0x22b45c003>, + /bits/ 64 <0x23b70c000 0x23b70c03b>, + /bits/ 64 <0x23b7004a8 0x23b7004ab>, + /bits/ 64 <0x206468000 0x206468003>; }; dispext0_dart: iommu@271304000 { diff --git a/drivers/accel/ane/ane_fw_cold.c b/drivers/accel/ane/ane_fw_cold.c index b1c52e765471b..643ceb067e672 100644 --- a/drivers/accel/ane/ane_fw_cold.c +++ b/drivers/accel/ane/ane_fw_cold.c @@ -262,7 +262,7 @@ static int ane_fw_quarantine(struct ane_fw_backend *b, int error) return error; } -static bool ane_fw_raw_boot(void) +bool ane_fw_raw_boot(void) { struct device_node *chosen __free(device_node) = of_find_node_by_path("/chosen"); const char *evidence; diff --git a/drivers/accel/ane/ane_fw_cold.h b/drivers/accel/ane/ane_fw_cold.h index 10cc760ef2945..d4000bb708f14 100644 --- a/drivers/accel/ane/ane_fw_cold.h +++ b/drivers/accel/ane/ane_fw_cold.h @@ -307,6 +307,9 @@ static inline int ane_fw_heap_tail(const u64 dva[2], const u64 size[2], u64 limi /* The exact /chosen/apple,ane-cold-boot value a raw loader boot publishes. */ #define ANE_FW_COLD_BOOT_EVIDENCE "raw-no-xnu-ane-untouched-v1" +/* /chosen/apple,ane-cold-boot names a raw loader boot (ANE_FW_COLD_BOOT_EVIDENCE). */ +bool ane_fw_raw_boot(void); + /* * What the loader handed off, as read from the DT and the TEXT segment, and * the live state of the engine. marker is /chosen/apple,ane-cold-boot or diff --git a/drivers/accel/ane/ane_fw_platform.c b/drivers/accel/ane/ane_fw_platform.c index d3fb1012b2d00..034ee0e860e85 100644 --- a/drivers/accel/ane/ane_fw_platform.c +++ b/drivers/accel/ane/ane_fw_platform.c @@ -47,6 +47,20 @@ static const u32 ane_t8122_power_words[] = { 0x438, 0xc008, 0xc000, 0xc010, 0xc018, }; +/* T8112 (M2): the legacy H14 windows: engine, PMGR, power gate set, fuse. */ +static const char * const ane_t8112_reg_names[] = { + "engine", "pmgr", "set", "fuse", +}; + +static const u32 ane_t8112_reg_sizes[] = { + 0x2000000, 0x18000, 0x4000, 0x8, +}; + +/* ANE_SYS (+0x4a8), then the seven ANE domains in power-domains order. */ +static const u32 ane_t8112_power_words[] = { + 0x4a8, 0xc008, 0xc010, 0xc018, 0xc020, 0xc028, 0xc030, 0xc038, +}; + /* Offsets in reg[1]; genpd, never the ANE driver, owns transitions. */ static const u32 ane_h16_power_words[] = { 0x3c0, 0xc008, 0xc000, 0xc010, 0xc018, @@ -123,6 +137,62 @@ const struct ane_fw_platform ane_t8122_platform = { .safe_reset = false, }; +/* + * M2 (T8112): H14 engine running the macOS 27.2 (26B123) firmware iBoot + * preloaded, on the shared H16 AP-direct backend. Selected only when the boot + * loader hands the preload over (ane_fw_preload_handoff()); otherwise the + * legacy H14 path stages the disk image as before. The ASC wrapper, mailbox, + * doorbell and IRQ words are those of the legacy H14 path (SCRATCH0 at + * +0x1840048, IPI at +0x1844000); the four DAPF records sit at DART0 + + * 0x4000. Seven power domains, the first the CPU domain under ANE_SYS, with + * the "set" power gate in front of it. The interrupt line is the ASC + * mailbox's, which its own node owns. Cold restart + program replay across + * sleep. + */ +const struct ane_fw_platform ane_t8112_platform = { + .h16_profiles = ane_t8112_profiles_26b123, + .h16_profile_count = ARRAY_SIZE(ane_t8112_profiles_26b123), + .h16_mmio = ane_h14_mmio_t8112, + .h16_mmio_count = ARRAY_SIZE(ane_h14_mmio_t8112), + .dart_params = 0x8, + .dapf_dart = 0, + .dapf_offset = 0x4000, + .dapf_size = SZ_16K, + .dapf_count = 4, + .soc = 0x8112, + .chip_family = 14, + .ane_type = 0x80, + .hwx_subtype = 5, + .task_generation = 14, + .interrupt_count = 1, + .irq_role = ANE_FW_IRQ_MAILBOX, + .owner = ANE_FW_OWNER_AP, + .reg_names = ane_t8112_reg_names, + .reg_sizes = ane_t8112_reg_sizes, + .reg_count = ARRAY_SIZE(ane_t8112_reg_names), + .wrapper = 0x1400000, + .mailbox = 0x1408000, + .scratch = 0x1840048, + .doorbell = 0x1844000, + .irq_status = 0x184c000, + .irq_ack = 0x1850000, + .power_words = ane_t8112_power_words, + .power_count = ARRAY_SIZE(ane_t8112_power_words), + .domain_count = 7, + .sys_parent = true, + .pwgate_window = "set", + .pwgate_offset = 0x8b8, + .dart_reattach = true, + .build_name = "27.2 26B123", + .preload_dva = { 0x800000000, 0x8000d8000 }, + .preload_size = { 0xd8000, 0x614000 }, + .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), @@ -583,6 +653,37 @@ const struct ane_fw_platform *ane_fw_platform_build(struct device_node *np, } EXPORT_SYMBOL_GPL(ane_fw_platform_build); +/* + * Whether the boot loader handed this ANE's preloaded firmware over for the + * driver to cold-start: two available firmware-text/firmware-data reserved + * regions, their device addresses, the preload marker and the raw-boot + * evidence in /chosen. Only the DT is read. A SoC whose ANE also has a legacy + * path (T8112) takes the shared backend only with all of them. + */ +bool ane_fw_preload_handoff(struct device_node *np) +{ + unsigned int i; + + if (!np || !of_property_read_bool(np, "apple,firmware-preloaded") || + of_property_count_u32_elems(np, "memory-region") != 2 || + of_property_count_strings(np, "memory-region-names") != 2 || + of_property_count_u64_elems(np, "apple,firmware-iovas") != 2 || + !ane_fw_raw_boot()) + return false; + for (i = 0; i < 2; i++) { + struct device_node *mem __free(device_node) = + of_parse_phandle(np, "memory-region", i); + const char *name; + + if (!mem || !of_device_is_available(mem) || + of_property_read_string_index(np, "memory-region-names", i, &name) || + strcmp(name, i ? "firmware-data" : "firmware-text")) + return false; + } + return true; +} +EXPORT_SYMBOL_GPL(ane_fw_preload_handoff); + static int ane_fw_preload_check(struct device *dev, const struct ane_fw_platform *soc) { diff --git a/drivers/accel/ane/ane_fw_platform.h b/drivers/accel/ane/ane_fw_platform.h index 4a127866b0a7d..94a5abc36fb42 100644 --- a/drivers/accel/ane/ane_fw_platform.h +++ b/drivers/accel/ane/ane_fw_platform.h @@ -9,8 +9,10 @@ #include #include -/* DAPF records: four on T6041 and T8140, five on T6050 and T8132. */ +/* DAPF records: four on T6041, T8112 and T8140, five on T6050 and T8132. */ #define ANE_FW_DAPF_MAX 5 +/* ANE power domains of the H16 backend: five on H15/H16, seven on T8112. */ +#define ANE_FW_DOMAINS_MAX 7 struct device_node; struct platform_device; @@ -25,6 +27,11 @@ enum ane_fw_owner { enum ane_fw_irq_role { ANE_FW_IRQ_UNKNOWN, ANE_FW_IRQ_CHANNELS, + /* + * The line is the ASC mailbox's receive interrupt, which the mailbox + * node's driver owns (T8112): the backend polls and never requests it. + */ + ANE_FW_IRQ_MAILBOX, }; struct ane_fw_bridge_op { @@ -68,6 +75,28 @@ struct ane_fw_platform { u32 irq_ack; const u32 *power_words; u32 power_count; + /* + * The ANE power domains the H16 backend attaches, in power-domains + * order; 0 means five. With sys_parent, power-domains[0] is the CPU + * domain and its parent (ANE_SYS, which the DARTs sit in) is the one + * power cycled on its own; otherwise power-domains[0] is ANE_SYS. + */ + u8 domain_count; + bool sys_parent; + /* + * A power gate word (T8112: "set" + 0x8b8, bits 29:28 set = closed) + * that must be open before power-domains[0] turns on and closed again + * after it turns off. NULL: none. + */ + const char *pwgate_window; + u32 pwgate_offset; + /* + * The ANE DARTs lose SID0's translation registers when the engine + * powers off, and their own runtime resume runs before the ANE domains + * are back (T8112: DART1 faulted NO TTBR after an idle power + * cycle). The backend attaches its domain again after every power-up. + */ + bool dart_reattach; u64 preload_dva[2]; u64 preload_size[2]; u16 stream_mask; @@ -192,6 +221,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_t8112_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); @@ -206,6 +236,7 @@ int ane_fw_platform_runtime_resume(struct device *dev); int ane_fw_preload_range(struct device_node *np, unsigned int index, u64 *phys, u64 *size); const struct ane_fw_platform *ane_fw_platform_build(struct device_node *np, const struct ane_fw_platform *soc); +bool ane_fw_preload_handoff(struct device_node *np); int ane_h16_backend_probe(struct platform_device *pdev, const struct ane_fw_platform *soc); void ane_h16_backend_remove(struct platform_device *pdev); int ane_h16_backend_suspend(struct device *dev); diff --git a/drivers/accel/ane/ane_fw_platform_test.c b/drivers/accel/ane/ane_fw_platform_test.c index b871dcebe9154..1faa62dc6e15a 100644 --- a/drivers/accel/ane/ane_fw_platform_test.c +++ b/drivers/accel/ane/ane_fw_platform_test.c @@ -5,6 +5,8 @@ #include #include "ane_fw_platform.h" +#include "ane_h16_boot.h" +#include "ane_h16_preload.h" static void ane_preload_ranges_test(struct kunit *test) { @@ -116,6 +118,59 @@ static void ane_t8122_platform_test(struct kunit *test) platform_device_put(pdev); } +/* + * M2 (T8112) 27.2: the legacy H14 windows and seven domains under ANE_SYS, + * the "set" power gate, four DAPF records, the mailbox-owned interrupt line, + * the J473 preload pin. A node without DT has no hand-off and keeps the + * legacy path. + */ +static void ane_t8112_platform_test(struct kunit *test) +{ + const struct ane_fw_platform *p = &ane_t8112_platform; + struct platform_device *pdev = platform_device_alloc("ane-t8112", -1); + u64 phys[] = { 0x80093c000, 0x800be8000 }; + u64 dva[] = { 0x800000000, 0x8000d8000 }; + u64 size[] = { 0xd8000, 0x614000 }; + + KUNIT_ASSERT_NOT_NULL(test, pdev); + KUNIT_EXPECT_EQ(test, p->soc, 0x8112U); + KUNIT_EXPECT_EQ(test, p->chip_family, 14U); + KUNIT_EXPECT_EQ(test, p->ane_type, 0x80U); + KUNIT_EXPECT_EQ(test, p->hwx_subtype, 5U); + KUNIT_EXPECT_EQ(test, p->reg_count, 4U); + KUNIT_EXPECT_STREQ(test, p->reg_names[2], "set"); + KUNIT_EXPECT_STREQ(test, p->pwgate_window, "set"); + KUNIT_EXPECT_EQ(test, p->pwgate_offset, 0x8b8U); + KUNIT_EXPECT_EQ(test, p->domain_count, 7); + KUNIT_EXPECT_LE(test, p->domain_count, ANE_FW_DOMAINS_MAX); + KUNIT_EXPECT_TRUE(test, p->sys_parent); + KUNIT_EXPECT_TRUE(test, p->dart_reattach); + KUNIT_EXPECT_FALSE(test, ane_t8122_platform.dart_reattach); + KUNIT_EXPECT_EQ(test, p->power_count, 8U); + KUNIT_EXPECT_EQ(test, p->power_words[0], 0x4a8U); + KUNIT_EXPECT_EQ(test, p->irq_role, ANE_FW_IRQ_MAILBOX); + KUNIT_EXPECT_EQ(test, p->scratch, 0x1840048U); + KUNIT_EXPECT_EQ(test, p->mailbox, 0x1408000U); + KUNIT_EXPECT_EQ(test, p->dapf_offset, 0x4000U); + KUNIT_EXPECT_EQ(test, p->dapf_count, 4); + KUNIT_EXPECT_FALSE(test, p->has_xl); + KUNIT_EXPECT_TRUE(test, p->sleep_cold); + KUNIT_EXPECT_FALSE(test, p->sleep_warm); + KUNIT_ASSERT_EQ(test, p->h16_profile_count, 1U); + KUNIT_EXPECT_STREQ(test, p->h16_profiles[0].identity, "H14 T8112 27.2 26B123 J473"); + KUNIT_EXPECT_EQ(test, p->h16_profiles[0].preload->text_size, 0xd8000U); + KUNIT_EXPECT_EQ(test, p->h16_profiles[0].preload->data_size, 0x614000U); + KUNIT_EXPECT_TRUE(test, ane_fw_preload_ranges_valid(p, phys, size, dva)); + /* Another layout (the T8122's) is not this build. */ + KUNIT_EXPECT_FALSE(test, ane_fw_preload_ranges_valid(p, phys, + ane_t8122_platform.preload_size, + ane_t8122_platform.preload_dva)); + KUNIT_EXPECT_FALSE(test, ane_fw_preload_handoff(NULL)); + KUNIT_EXPECT_FALSE(test, ane_fw_preload_handoff(pdev->dev.of_node)); + KUNIT_EXPECT_EQ(test, ane_fw_platform_preflight(pdev, p), -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) { @@ -253,6 +308,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_t8112_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_h16_backend.c b/drivers/accel/ane/ane_h16_backend.c index a7ad062ed426a..84f2bd11a7e0d 100644 --- a/drivers/accel/ane/ane_h16_backend.c +++ b/drivers/accel/ane/ane_h16_backend.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -57,7 +58,11 @@ struct ane_h16_device { struct ane_h16_boot boot; struct device *dev; void __iomem *window[ANE_H16_WINDOWS]; - struct device *power[5]; + struct device *power[ANE_FW_DOMAINS_MAX]; + /* The T8112 power gate word, or NULL (ane_fw_platform.pwgate_window). */ + void __iomem *pwgate_base; + void __iomem *pwgate; + bool pwgate_opened; /* Optional "perf" floor, voted only while an EXECUTE is in flight. */ struct device *perf; bool perf_held; @@ -127,14 +132,14 @@ struct ane_h16_device { bool rpm_enabled; bool rpm_held; bool rpm_busy; - /* genpd's transitions of each of the five domains across a sleep. */ + /* genpd's transitions of each ANE domain across a sleep. */ struct ane_h16_genpd { struct notifier_block nb; struct ane_h16_device *h; bool added; unsigned int offs, ons; u64 off_at, off_ns; - } genpd[5]; + } genpd[ANE_FW_DOMAINS_MAX]; u64 resume_ready_ns; /* EXCLAVE_MODE_STOP completed in this firmware boot (variant build). */ bool mode_stopped; @@ -485,11 +490,74 @@ static int ane_h16_warm_boot(struct ane_h16_device *h) } /* Called by genpd under its lock, in the noirq phase too: record only. */ +/* + * The T8112 power gate. Its word gates the ANE: bits 29:28 set (it reads + * 0x30000000) is closed, both clear is open. It must be open before the CPU + * domain (power-domains[0]) turns on and is closed again after that turns + * off, with ANE_SYS, its parent, on both times: genpd calls this after the + * parent is on and before the domain is written (PRE_ON), and after the + * domain is off and before the parent goes off (OFF). Only the two known + * values are written; any other word fails the power-up without a write. + */ +#define ANE_H16_PWGATE_CLOSED GENMASK(29, 28) +#define ANE_H16_PWGATE_POLL_US 10 +#define ANE_H16_PWGATE_TIMEOUT_US 100000 + +static int ane_h16_pwgate_event(struct ane_h16_device *h, unsigned long action) +{ + u32 gate; + int ret; + + switch (action) { + case GENPD_NOTIFY_PRE_ON: + gate = readl(h->pwgate); + if (!(gate & ANE_H16_PWGATE_CLOSED)) + return NOTIFY_OK; + if (gate != ANE_H16_PWGATE_CLOSED) { + dev_err(h->dev, "H16 ANE: power gate word %#x is not a known state\n", + gate); + return notifier_from_errno(-EIO); + } + writel(0, h->pwgate); + ret = readl_poll_timeout_atomic(h->pwgate, gate, !(gate & ANE_H16_PWGATE_CLOSED), + ANE_H16_PWGATE_POLL_US, + ANE_H16_PWGATE_TIMEOUT_US); + if (ret) { + writel(ANE_H16_PWGATE_CLOSED, h->pwgate); + dev_err(h->dev, "H16 ANE: power gate did not open (word %#x)\n", gate); + return notifier_from_errno(ret); + } + h->pwgate_opened = true; + return NOTIFY_OK; + case GENPD_NOTIFY_OFF: + if (!h->pwgate_opened) + return NOTIFY_OK; + h->pwgate_opened = false; + writel(ANE_H16_PWGATE_CLOSED, h->pwgate); + ret = readl_poll_timeout_atomic(h->pwgate, gate, + (gate & ANE_H16_PWGATE_CLOSED) == + ANE_H16_PWGATE_CLOSED, + ANE_H16_PWGATE_POLL_US, + ANE_H16_PWGATE_TIMEOUT_US); + if (ret) + dev_warn(h->dev, "H16 ANE: power gate did not close (word %#x)\n", gate); + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + static int ane_h16_genpd_event(struct notifier_block *nb, unsigned long action, void *data) { struct ane_h16_genpd *g = container_of(nb, struct ane_h16_genpd, nb); u64 now = ktime_get_boottime_ns(); + if (g == &g->h->genpd[0] && g->h->pwgate) { + int ret = ane_h16_pwgate_event(g->h, action); + + if (ret != NOTIFY_OK && ret != NOTIFY_DONE) + return ret; + } if (action == GENPD_NOTIFY_OFF) { g->offs++; g->off_at = now; @@ -504,7 +572,7 @@ static int ane_h16_genpd_event(struct notifier_block *nb, unsigned long action, static void ane_h16_genpd_record(struct ane_h16_device *h) { - char line[160]; + char line[256]; int n = 0; for (unsigned int i = 0; i < h->powered; i++) @@ -537,6 +605,13 @@ static int ane_h16_sys_cycle(struct ane_h16_device *h) struct device_node *np = of_parse_phandle(h->dev->of_node, "power-domains", 0); int ret; + /* T8112: power-domains[0] is the CPU domain; ANE_SYS is its parent. */ + if (np && h->boot.soc->sys_parent) { + struct device_node *cpu = np; + + np = of_parse_phandle(cpu, "power-domains", 0); + of_node_put(cpu); + } if (!np) return -ENODEV; ret = apple_pmgr_ps_cycle(np); @@ -546,6 +621,28 @@ static int ane_h16_sys_cycle(struct ane_h16_device *h) return ret; } +/* + * After the engine is powered up again: on a SoC whose ANE DARTs lose SID0's + * translation registers with the engine (dart_reattach), attaching the + * retained domain again rewrites them from its page tables and synchronizes + * the TLBs, as the H17 cold path does. The DART devices' own runtime resume + * runs before the ANE domains are up, so it cannot restore them there. + */ +static int ane_h16_dart_reattach(struct ane_h16_device *h) +{ + int ret; + + if (!h->boot.soc->dart_reattach || !h->attached) + return 0; + iommu_detach_device(h->domain, h->dev); + ret = iommu_attach_device(h->domain, h->dev); + if (ret) { + h->attached = false; + dev_err(h->dev, "H16 ANE: DART attach after power-up failed, error %d\n", ret); + } + return ret; +} + static int ane_h16_power_cycle(struct ane_h16_device *h, bool verify) { struct ane_h16_boot *b = &h->boot; @@ -560,7 +657,8 @@ static int ane_h16_power_cycle(struct ane_h16_device *h, bool verify) offs[i] = h->genpd[i].offs; if (h->engine_on) ane_h16_power_down(h); - for (i = 1; verify && i < h->powered; i++) { + /* With sys_parent, power-domains[0] is a child of ANE_SYS too. */ + for (i = h->boot.soc->sys_parent ? 0 : 1; verify && i < h->powered; i++) { if (!h->genpd[i].added || h->genpd[i].offs == offs[i]) { dev_err(h->dev, "H16 ANE: domain %u did not power off; no restart\n", i); /* Powered again, so the quarantine can read its evidence. */ @@ -576,6 +674,8 @@ static int ane_h16_power_cycle(struct ane_h16_device *h, bool verify) } } ret = ane_h16_power_up(h); + if (!ret) + ret = ane_h16_dart_reattach(h); if (!ret) ret = ane_h16_dapf(b, true); if (!ret) @@ -1212,7 +1312,8 @@ static int ane_h16_map_heap_tail(struct ane_h16_device *h) { struct ane_h16_boot *b = &h->boot; u64 tail = b->soc->preload_dva[1] + b->soc->preload_size[1]; - u64 end = b->soc->preload_dva[0] + b->build->config_span; + u64 end = b->soc->preload_dva[0] + + (b->build->tail_end ?: b->build->config_span); struct ane_fw_surface s; int ret; @@ -1949,12 +2050,24 @@ static void ane_h16_release(struct ane_h16_device *h) while (h->powered) { struct device *pd = h->power[--h->powered]; + /* The power gate notifier closes the gate as the CPU domain goes off. */ + if (h->pwgate && h->genpd[h->powered].added) { + pm_runtime_put_sync(pd); + dev_pm_genpd_remove_notifier(pd); + h->genpd[h->powered].added = false; + dev_pm_domain_detach(pd, true); + continue; + } if (h->genpd[h->powered].added) dev_pm_genpd_remove_notifier(pd); h->genpd[h->powered].added = false; pm_runtime_put_sync(pd); dev_pm_domain_detach(pd, true); } + if (h->pwgate_base) + iounmap(h->pwgate_base); + h->pwgate_base = NULL; + h->pwgate = NULL; WRITE_ONCE(h->engine_on, false); h->acquired = false; vfree(h->pristine_data); @@ -2058,7 +2171,7 @@ static int ane_h16_acquire(struct platform_device *pdev, struct ane_h16_device * { struct device_node *np = pdev->dev.of_node; static const char * const names[] = { "engine", "pmgr", "aux-3" }; - unsigned int i, j; + unsigned int i, j, domains; bool perf; int ret, irq, n; @@ -2068,24 +2181,52 @@ static int ane_h16_acquire(struct platform_device *pdev, struct ane_h16_device * h->boot.pmu_base = pmgr ? pmgr->start : 0; } + domains = h->boot.soc->domain_count ?: 5; + if (domains > ANE_FW_DOMAINS_MAX) + return -EINVAL; n = of_count_phandle_with_args(np, "power-domains", "#power-domain-cells"); - perf = n == 6 && of_property_match_string(np, "power-domain-names", "perf") == 5; - if (n != 5 && !perf) + perf = n == domains + 1 && + of_property_match_string(np, "power-domain-names", "perf") == domains; + if (n != domains && !perf) return -EINVAL; - for (i = 0; i < 5; i++) { + if (h->boot.soc->pwgate_window) { + struct resource *r = platform_get_resource_byname(pdev, IORESOURCE_MEM, + h->boot.soc->pwgate_window); + + if (!r || resource_size(r) < h->boot.soc->pwgate_offset + 4) + return -ENODEV; + h->pwgate_base = ioremap_np(r->start, resource_size(r)); + if (!h->pwgate_base) + return -ENOMEM; + h->pwgate = h->pwgate_base + h->boot.soc->pwgate_offset; + } + for (i = 0; i < domains; i++) { struct device *pd = dev_pm_domain_attach_by_id(h->dev, i); if (IS_ERR_OR_NULL(pd)) return pd ? PTR_ERR(pd) : -ENODEV; + h->genpd[h->powered].h = h; + h->genpd[h->powered].nb.notifier_call = ane_h16_genpd_event; + /* The power gate must see the CPU domain's first PRE_ON. */ + if (h->pwgate) { + h->genpd[h->powered].added = + !dev_pm_genpd_add_notifier(pd, &h->genpd[h->powered].nb); + if (!i && !h->genpd[h->powered].added) { + dev_pm_domain_detach(pd, true); + return -EBUSY; + } + } ret = pm_runtime_resume_and_get(pd); if (ret < 0) { + if (h->genpd[h->powered].added) + dev_pm_genpd_remove_notifier(pd); + h->genpd[h->powered].added = false; dev_pm_domain_detach(pd, true); return ret; } - h->genpd[h->powered].h = h; - h->genpd[h->powered].nb.notifier_call = ane_h16_genpd_event; - h->genpd[h->powered].added = - !dev_pm_genpd_add_notifier(pd, &h->genpd[h->powered].nb); + if (!h->pwgate) + h->genpd[h->powered].added = + !dev_pm_genpd_add_notifier(pd, &h->genpd[h->powered].nb); h->power[h->powered++] = pd; } if (perf) { @@ -2151,6 +2292,9 @@ static int ane_h16_acquire(struct platform_device *pdev, struct ane_h16_device * } if (!h->window[ANE_H16_DAPF]) return -ENODEV; + /* The ASC mailbox node's driver owns this line; the backend polls. */ + if (h->boot.soc->irq_role == ANE_FW_IRQ_MAILBOX) + return 0; irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; diff --git a/drivers/accel/ane/ane_h16_boot.h b/drivers/accel/ane/ane_h16_boot.h index 61fac3f1e3f07..f32ba76e7a885 100644 --- a/drivers/accel/ane/ane_h16_boot.h +++ b/drivers/accel/ane/ane_h16_boot.h @@ -101,7 +101,26 @@ struct ane_h16_build { u32 template_value; u32 max_channels; u32 max_heap; + /* + * Host RAM the firmware keeps state in after DATA, which the preload + * does not cover: up to this offset from the TEXT DVA (0: config_span, + * so the tail ends where the config span does). T8112 27.2 has its + * sharedMemoryBase at TEXT + DATA, inside the span it is given, and + * needs the tail beyond it. + */ + u32 tail_end; + /* A heap request below this is rounded up to it (0: taken as asked). */ + u32 heap_floor; + /* + * Init block words of the H14 contract: the TEXT DVA at +0x00, and + * init_or_value ORed into the word at init_or_offset (0: none). + */ + bool init_text_dva; + u32 init_or_offset; + u32 init_or_value; bool native_free; + /* FREE takes the DVA|1 reply (H14 27.2, as H17 25G83). */ + bool dva_free; bool c1ppt; const struct ane_h16_tunables *tunables; size_t tunable_count; @@ -590,6 +609,8 @@ static inline int ane_h16_scratch_boot(struct ane_h16_boot *b) ipc_bytes = (u64)b->requests[1] + 1; heap_bytes = b->requests[3]; /* Host policy. IPC cannot reach the fixed heap; no guessed firmware ceiling. */ + if (heap_bytes && heap_bytes < f->heap_floor) + heap_bytes = f->heap_floor; if (!b->requests[0] || b->requests[0] >= f->max_channels || ipc_bytes < ANE_FW_TABLE_SIZE || ipc_bytes > f->heap_dva - f->ipc_dva || heap_bytes > f->max_heap || @@ -606,6 +627,8 @@ static inline int ane_h16_scratch_boot(struct ane_h16_boot *b) } p = (u8 *)b->pool.cpu + f->init_offset; memset(p, 0, f->init_size); + if (f->init_text_dva) + put_unaligned_le64(b->soc->preload_dva[0], p); put_unaligned_le64(f->ipc_dva, p + 8); put_unaligned_le64(f->config_span, p + 0x10); put_unaligned_le64(f->config_window - f->config_span, p + 0x18); @@ -616,6 +639,9 @@ static inline int ane_h16_scratch_boot(struct ane_h16_boot *b) put_unaligned_le64(f->pool_size, p + 0x60); put_unaligned_le32(f->template_count, p + 0x68); put_unaligned_le32(f->template_value, p + f->template_word); + if (f->init_or_offset) + put_unaligned_le32(get_unaligned_le32(p + f->init_or_offset) | f->init_or_value, + p + f->init_or_offset); b->transport_ops->write_barrier(b->ctx); ane_h16_write(b, 0, lower_32_bits(f->pool_dva + f->init_offset)); ane_h16_write(b, 1, upper_32_bits(f->pool_dva + f->init_offset)); @@ -629,6 +655,7 @@ static inline int ane_h16_scratch_boot(struct ane_h16_boot *b) if (ret) return ret; b->transport.native_free = f->native_free; + b->transport.allow_free = f->dva_free; b->ops->log(b->ctx, "table validated", f->ipc_dva, ANE_FW_CHANNELS); ret = ane_fw_transport_arm(&b->transport); if (ret) diff --git a/drivers/accel/ane/ane_h16_boot_data.h b/drivers/accel/ane/ane_h16_boot_data.h index 674268580a3eb..76d65991f2403 100644 --- a/drivers/accel/ane/ane_h16_boot_data.h +++ b/drivers/accel/ane/ane_h16_boot_data.h @@ -708,4 +708,134 @@ static const struct ane_h16_profile ane_t8122_profiles_26b123[] __maybe_unused = }, }; +/* + * T8112 (M2) ANE DARTs, revision 1.1 (PARAMS3 0x24240101 on all three, J473 + * 27.2): the same fault, protect and lock words and DAPF record layout as the + * T8122 (the J473 27.2 ADT dart-ane gives the same dapf-instance record + * words, r0 0x31, r4 0 and r20 1, and tags DART0 + 0x4000 FPAD). + */ +static const struct ane_h16_mmio ane_h14_mmio_t8112[] __maybe_unused = { + { + .dart_revision = 0x0101, + .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, + }, +}; + +/* + * The engine writes the T8112 legacy boot makes before every CPU release + * (ane_t6021_boot_run(), step P-1), which also preceded the first 27.2 + * H14 boot on the J473; whole words. + */ +static const struct ane_h16_tunable ane_h14_engine_t8112[] = { + { 0x000, 0xffffffff, 0x00000010 }, + { 0x038, 0xffffffff, 0x00050020 }, + { 0x03c, 0xffffffff, 0x000a0030 }, + { 0x400, 0xffffffff, 0x40010001 }, + { 0x600, 0xffffffff, 0x01ffffff }, + { 0x738, 0xffffffff, 0x00200020 }, + { 0x798, 0xffffffff, 0x00100030 }, + { 0x7f8, 0xffffffff, 0x0100000a }, + { 0x900, 0xffffffff, 0x00000101 }, + { 0x410, 0xffffffff, 0x00001100 }, + { 0x420, 0xffffffff, 0x00001100 }, + { 0x430, 0xffffffff, 0x00001100 }, +}; + +static const struct ane_h16_tunables ane_h14_tunables_t8112[] = { + { .window = ANE_H16_ENGINE, .values = ane_h14_engine_t8112, + .count = ARRAY_SIZE(ane_h14_engine_t8112) }, +}; + +/* + * T8112 (M2) H14 27.2 (26B123), booted from the iBoot preload: TEXT 0xd8000 + * at 0x800000000, DATA 0x614000 after it (RVBAR latched at the TEXT DVA). + * The init block is the H16 one with the legacy H14 words: TEXT DVA at +0x00, + * a config span of TEXT + DATA (the firmware's sharedMemoryBase), a 16 KiB + * heap floor and the nap-prevention bit (template +0x84 bit 0). The firmware + * keeps state in 2 MiB of host RAM after DATA; pool, IPC and heap follow it, + * spaced as on H16, and SHAREDMALLOC and programs use the window above + * 0x802000000, all below the DART's 36-bit limit. The boot ACK is the H16 one + * (the host writes READY to SCRATCH3 and the firmware clears it, as macOS 27.2 + * does on the J473); FREE replies are DVA|1. + */ +static const struct ane_h16_build ane_h14_build_t8112_26b123 = { + .cpu_control = 0x1400044, + .rvbar = 0x1050000, + .ready = 0x08042006, + .run = 0x10, + .scratch_polls = 1000, + .scratch_delay_us = 1000, + .command_timeout_ns = 3000000000ULL, + .pool_dva = 0x8008f0000, + .ipc_dva = 0x80093c000, + .heap_dva = 0x800950000, + .shared_dva = 0x802000000, + .expected_rvbar = 0x800000001, + .pool_size = 0x40000, + .init_offset = 0, + .init_size = 0x174, + .config_span = 0x6ec000, + .config_window = 0x10000000, + .template_count = 64, + .template_word = 0x12c, + .template_value = 4, + .max_channels = 0x21, + .max_heap = SZ_16M, + .tail_end = 0x8ec000, + .heap_floor = SZ_16K, + .init_text_dva = true, + .init_or_offset = 0x6c + 0x84, + .init_or_value = 1, + .dva_free = true, + .tunables = ane_h14_tunables_t8112, + .tunable_count = ARRAY_SIZE(ane_h14_tunables_t8112), + .startup = { { 4, 12 }, { 0, 12 }, { 3, 16 }, { 0x22, 100 } }, +}; + +/* + * M2 mini (J473) 27.2 (26B123) preload: TEXT 0xd8000, DATA 0x614000. Two + * J473 boots: TEXT identical, DATA differing only in GKTS and ECAP (8 bytes + * each). Patchbay cells in DATA order, the T8122 table's shape. + */ +static const struct ane_h16_preload_cell ane_h14_patchbay_26b123_t8112[] = { + { "GKTS", 0x6330, 8, true }, + { "ECAP", 0x6423, 8, true }, + { "ARcM", 0x64f8, 4, true }, + { "ABOI", 0x6555, 8, false }, + { "ZSOI", 0x6565, 4, false }, +}; + +static const struct ane_h16_preload_rule ane_h14_preload_26b123_j473 = { + .cells = ane_h14_patchbay_26b123_t8112, + .cell_count = ARRAY_SIZE(ane_h14_patchbay_26b123_t8112), + .zero_start = 0x614000, + .zero_end = 0x614000, + .text_size = 0xd8000, + .data_size = 0x614000, + .digest = { + 0xab, 0x8a, 0xd9, 0x60, 0xcc, 0x17, 0xd9, 0xaa, + 0x16, 0x53, 0xac, 0x17, 0x5b, 0xca, 0xdb, 0xd6, + 0x8a, 0x55, 0x64, 0x88, 0xc8, 0x37, 0x69, 0x68, + 0x08, 0x6f, 0xc0, 0x2d, 0xa8, 0x8f, 0x75, 0xc4, + }, +}; + +static const struct ane_h16_profile ane_t8112_profiles_26b123[] __maybe_unused = { + { + .identity = "H14 T8112 27.2 26B123 J473", + .preload = &ane_h14_preload_26b123_j473, + .build = &ane_h14_build_t8112_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 2b700799ea9d7..840d8fb21e576 100644 --- a/drivers/accel/ane/ane_h16_boot_test.c +++ b/drivers/accel/ane/ane_h16_boot_test.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT #include #include +#include #include "ane_h16_boot_data.h" @@ -58,6 +59,10 @@ struct ane_h16_sim { bool wrong_table; bool stale_table; bool no_clear; + /* The table was published (DONE); host READY writes to SCRATCH3 after it. */ + bool table_published; + u32 scratch3_ready_writes; + u32 scratch3_early_writes; bool no_startup_reply; bool shared_pending; bool shared_replied; @@ -264,8 +269,14 @@ static void sim_write32(void *ctx, enum ane_h16_window w, u32 off, u32 value) s->scratch[0] = lower_32_bits(address); s->scratch[1] = upper_32_bits(address); } + s->table_published = true; s->scratch[7] = f->ready; } + if (cell == 3 && value == f->ready) { + s->scratch3_ready_writes++; + if (!s->table_published) + s->scratch3_early_writes++; + } if (cell == 3 && value == f->ready && !s->no_clear) s->scratch[3] = 0; return; @@ -1340,6 +1351,176 @@ static void ane_h16_t8122_no_ce_test(struct kunit *test) KUNIT_EXPECT_EQ(test, s->dapf_writes, 25U); } +/* + * H14 (T8112) 27.2: the legacy engine writes before RUN, the H14 init block + * words (TEXT DVA, config span of TEXT + DATA, heap floor, nap bit), the + * H16 boot ACK in the order macOS 27.2 uses on the J473 (READY to SCRATCH3 + * after the table is published, the firmware clears it), and DVA|1 FREE. + */ +static void sim_use_t8112(struct ane_h16_sim *s) +{ + s->build = ane_h14_build_t8112_26b123; + s->mmio = ane_h14_mmio_t8112[0]; + s->dart_params = 0x24240101; + s->soc.h16_mmio = ane_h14_mmio_t8112; + s->soc.h16_mmio_count = ARRAY_SIZE(ane_h14_mmio_t8112); + s->soc.dapf_count = 4; + s->soc.dapf_offset = 0x4000; + s->soc.has_xl = false; + s->soc.scratch = 0x1840048; + s->soc.doorbell = 0x1844000; + s->soc.irq_status = 0x184c000; + s->soc.irq_ack = 0x1850000; + s->soc.preload_dva[0] = 0x800000000; + s->soc.preload_dva[1] = 0x8000d8000; + s->soc.chip_family = 14; + s->ce_timeout = true; + s->expect_tuning = ARRAY_SIZE(ane_h14_engine_t8112); + /* The J473's requests: 8 channels, IPC 0xc441 bytes, a 15 MiB heap. */ + s->channel_request = 8; + s->ipc_request = 0xc440; + s->heap_request = 0xf00000; +} + +static void ane_h16_t8112_boot_test(struct kunit *test) +{ + struct ane_h16_sim *s = test->priv; + unsigned int i; + u8 *p; + + sim_use_t8112(s); + KUNIT_ASSERT_EQ(test, ane_h16_run(&s->boot, ANE_H16_STARTUP), 0); + KUNIT_EXPECT_EQ(test, s->tuning_writes, (u32)ARRAY_SIZE(ane_h14_engine_t8112)); + for (i = 0; i < ARRAY_SIZE(ane_h14_engine_t8112); i++) + KUNIT_EXPECT_EQ(test, s->engine[ane_h14_engine_t8112[i].offset / 4], + ane_h14_engine_t8112[i].value); + KUNIT_EXPECT_EQ(test, s->ce_ack, 0ULL); + KUNIT_EXPECT_EQ(test, s->scratch3_ready_writes, 1U); + KUNIT_EXPECT_EQ(test, s->scratch3_early_writes, 0U); + KUNIT_EXPECT_EQ(test, s->scratch[3], 0U); + KUNIT_EXPECT_EQ(test, s->command_count, 4U); + KUNIT_EXPECT_TRUE(test, s->boot.transport.allow_free); + KUNIT_EXPECT_FALSE(test, s->boot.transport.native_free); + /* Five DAPF writes per record, four records. */ + KUNIT_EXPECT_EQ(test, s->dapf_writes, 20U); + KUNIT_EXPECT_EQ(test, s->boot.pool.dva, 0x8008f0000ULL); + KUNIT_EXPECT_EQ(test, s->boot.ipc.dva, 0x80093c000ULL); + KUNIT_EXPECT_EQ(test, s->boot.ipc.size, (size_t)0x10000); + KUNIT_EXPECT_EQ(test, s->boot.heap.dva, 0x800950000ULL); + KUNIT_EXPECT_EQ(test, s->boot.heap.size, (size_t)0xf00000); + /* The init block opens the pool, as the legacy H14 boot publishes it. */ + KUNIT_EXPECT_EQ(test, s->build.init_offset, 0U); + p = (u8 *)s->boot.pool.cpu; + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p), 0x800000000ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 8), 0x80093c000ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x10), 0x6ec000ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x18), 0x10000000ULL - 0x6ec000); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x20), 0x800950000ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x28), 0xf00000ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x50), 0xc441ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x58), 0x8008f0000ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x60), 0x40000ULL); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(p + 0x68), 64U); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(p + 0x6c + 0x84), 1U); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(p + 0x12c), 4U); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(p + 0x30), 0ULL); + /* The firmware tail ends where the pool begins, no later. */ + KUNIT_EXPECT_LE(test, 0x800000000ULL + s->build.tail_end, s->build.pool_dva); + KUNIT_EXPECT_GT(test, s->build.tail_end, s->build.config_span); +} + +/* A heap request below 16 KiB is raised to the floor, as the legacy H14 boot did. */ +static void ane_h16_t8112_heap_floor_test(struct kunit *test) +{ + struct ane_h16_sim *s = test->priv; + + sim_use_t8112(s); + s->heap_request = 0x100; + KUNIT_ASSERT_EQ(test, ane_h16_run(&s->boot, ANE_H16_STARTUP), 0); + KUNIT_EXPECT_EQ(test, s->boot.heap.size, (size_t)SZ_16K); + KUNIT_EXPECT_EQ(test, get_unaligned_le64((u8 *)s->boot.pool.cpu + 0x28), (u64)SZ_16K); +} + +/* No heap request: no heap surface, the floor stays unused. */ +static void ane_h16_t8112_no_heap_test(struct kunit *test) +{ + struct ane_h16_sim *s = test->priv; + + sim_use_t8112(s); + s->heap_request = 0; + KUNIT_ASSERT_EQ(test, ane_h16_run(&s->boot, ANE_H16_STARTUP), 0); + KUNIT_EXPECT_NULL(test, s->boot.heap.cpu); + KUNIT_EXPECT_EQ(test, get_unaligned_le64((u8 *)s->boot.pool.cpu + 0x28), 0ULL); +} + +/* A firmware that never clears the READY the host wrote to SCRATCH3 times out. */ +static void ane_h16_t8112_ack_timeout_test(struct kunit *test) +{ + struct ane_h16_sim *s = test->priv; + + sim_use_t8112(s); + s->no_clear = true; + KUNIT_EXPECT_EQ(test, ane_h16_run(&s->boot, ANE_H16_BOOT), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, s->scratch3_ready_writes, 1U); + KUNIT_EXPECT_EQ(test, s->scratch3_early_writes, 0U); + KUNIT_EXPECT_TRUE(test, s->boot.quarantined); + KUNIT_EXPECT_EQ(test, s->command_count, 0U); +} + +/* A DART revision outside the T8112 table is refused before any write. */ +static void ane_h16_t8112_revision_test(struct kunit *test) +{ + struct ane_h16_sim *s = test->priv; + + sim_use_t8112(s); + s->dart_params = 0x2a2a0202; + KUNIT_EXPECT_EQ(test, ane_h16_run(&s->boot, ANE_H16_STARTUP), -ENODEV); + KUNIT_EXPECT_EQ(test, s->tuning_writes, 0U); + KUNIT_EXPECT_EQ(test, s->dapf_writes, 0U); + KUNIT_EXPECT_FALSE(test, s->boot.ran); +} + +/* + * The J473 27.2 pin: its cells frame a preload of the J473 shape (tag at + * value - 8, width at value - 4), the mutable ones normalize, and a preload + * other than the measured one is refused. + */ +static void ane_h16_t8112_preload_rule_test(struct kunit *test) +{ + const struct ane_h16_preload_rule *r = &ane_h14_preload_26b123_j473; + u8 *text = kunit_kzalloc(test, r->text_size, GFP_KERNEL); + u8 *data = vzalloc(r->data_size); + u8 digest[SHA256_DIGEST_SIZE], again[SHA256_DIGEST_SIZE]; + unsigned int i; + + KUNIT_ASSERT_NOT_NULL(test, text); + KUNIT_ASSERT_NOT_NULL(test, data); + KUNIT_EXPECT_PTR_EQ(test, ane_t8112_profiles_26b123[0].preload, r); + for (i = 0; i < r->cell_count; i++) { + memcpy(data + r->cells[i].value - 8, r->cells[i].tag, 4); + put_unaligned_le32(r->cells[i].width, data + r->cells[i].value - 4); + } + KUNIT_EXPECT_EQ(test, ane_h16_preload_digest(r, text, r->text_size, data, + r->data_size, digest), 0); + /* GKTS and ECAP change on every boot: the digest does not. */ + memset(data + 0x6330, 0x5a, 8); + memset(data + 0x6423, 0xa5, 8); + KUNIT_EXPECT_EQ(test, ane_h16_preload_digest(r, text, r->text_size, data, + r->data_size, again), 0); + KUNIT_EXPECT_MEMEQ(test, digest, again, sizeof(digest)); + KUNIT_EXPECT_EQ(test, ane_h16_preload_validate(r, text, r->text_size, data, + r->data_size), -ENOEXEC); + /* A fixed cell, or a moved tag, is not this build. */ + data[0x6555] ^= 1; + KUNIT_EXPECT_EQ(test, ane_h16_preload_digest(r, text, r->text_size, data, + r->data_size, again), 0); + KUNIT_EXPECT_MEMNEQ(test, digest, again, sizeof(digest)); + data[0x6330 - 8] ^= 1; + KUNIT_EXPECT_EQ(test, ane_h16_preload_digest(r, text, r->text_size, data, + r->data_size, again), -ENOEXEC); + vfree(data); +} + /* The T8132 boots with its own engine writes only: no XL or C1PPT. */ static void ane_h16_t8132_tunables_test(struct kunit *test) { @@ -1425,6 +1606,12 @@ static struct kunit_case ane_h16_boot_cases[] = { 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_t8112_boot_test), + KUNIT_CASE(ane_h16_t8112_no_heap_test), + KUNIT_CASE(ane_h16_t8112_ack_timeout_test), + KUNIT_CASE(ane_h16_t8112_heap_floor_test), + KUNIT_CASE(ane_h16_t8112_revision_test), + KUNIT_CASE(ane_h16_t8112_preload_rule_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_t6021.h b/drivers/accel/ane/ane_t6021.h index a6c2b3f192cd1..f3f0925975463 100644 --- a/drivers/accel/ane/ane_t6021.h +++ b/drivers/accel/ane/ane_t6021.h @@ -774,6 +774,11 @@ struct ane_asc_tunables; */ struct ane_t602x_soc { const struct ane_fw_platform *platform; + /* + * Taken instead of the legacy path only when the boot loader hands the + * preload over (ane_fw_preload_handoff(); T8112 on a 27.2 stub). + */ + const struct ane_fw_platform *handoff_platform; u32 soc; u32 soc_revision; bool revision_fuse; diff --git a/drivers/accel/ane/ane_t6021_fwload.c b/drivers/accel/ane/ane_t6021_fwload.c index 69c7a0adc2c69..d0ee877237fea 100644 --- a/drivers/accel/ane/ane_t6021_fwload.c +++ b/drivers/accel/ane/ane_t6021_fwload.c @@ -74,6 +74,7 @@ #include #include +#include "ane_fw_platform.h" #include "ane_t6021.h" #include "ane_t6021_boot.h" #include "ane_fw_validate.h" @@ -217,6 +218,7 @@ const struct ane_t602x_soc ane_t6022_soc = { }; const struct ane_t602x_soc ane_t8112_soc = { + .handoff_platform = &ane_t8112_platform, .soc = 0x8112, .revision_fuse = true, .fw = &ane_fw_bia, .tunables = &ane_t8112_asc_tunables, .ps_cpu_off = 0xc008, .pwgate_off = 0x8b8, diff --git a/drivers/accel/ane/ane_t6021_rtclient_main.c b/drivers/accel/ane/ane_t6021_rtclient_main.c index 92e642ecdb4d4..f578b09c7b416 100644 --- a/drivers/accel/ane/ane_t6021_rtclient_main.c +++ b/drivers/accel/ane/ane_t6021_rtclient_main.c @@ -3933,6 +3933,24 @@ static struct ane_t6021_pm *ane_rtclient_get_sleep_pm(struct device *dev) return &ane->sleep_pm; } +/* + * The shared firmware platform a matched ANE binds through, or NULL for the + * H13/H14 rtclient: the SoC's own platform, or (T8112) the one the boot + * loader's preload hand-off selects. Decided from the DT alone, so probe, + * sleep, remove and sysfs always agree. + */ +static const struct ane_fw_platform * +ane_rtclient_platform(struct device_node *np, const struct ane_t602x_soc *soc) +{ + if (!soc) + return NULL; + if (soc->platform) + return soc->platform; + if (soc->handoff_platform && ane_fw_preload_handoff(np)) + return soc->handoff_platform; + return NULL; +} + /* * One platform driver binds the H13/H14 rtclient and, through the shared * firmware platform, the H16 backend, each with its own drvdata. Dispatch by @@ -3940,9 +3958,9 @@ static struct ane_t6021_pm *ane_rtclient_get_sleep_pm(struct device *dev) */ static bool ane_rtclient_is_platform(struct device *dev) { - const struct ane_t602x_soc *soc = of_device_get_match_data(dev); - - return soc && ane_fw_sleep_path(soc->platform) == ANE_SLEEP_FW_BACKEND; + return ane_fw_sleep_path(ane_rtclient_platform(dev->of_node, + of_device_get_match_data(dev))) == + ANE_SLEEP_FW_BACKEND; } static int __maybe_unused ane_rtclient_sleep_pm_suspend(struct device *dev) @@ -4470,14 +4488,15 @@ static int ane_rtclient_probe_inner(struct platform_device *pdev, static int ane_rtclient_probe(struct platform_device *pdev) { const struct ane_t602x_soc *soc = of_device_get_match_data(&pdev->dev); + const struct ane_fw_platform *platform = ane_rtclient_platform(pdev->dev.of_node, soc); bool hardware_touched = false; int ret; if (!soc) return -ENODEV; - /* Later generations cannot enter H14 boot or parameter paths. */ - if (soc->platform) - return ane_fw_platform_probe(pdev, soc->platform); + /* Later generations, and a handed-over preload, cannot enter H14 boot paths. */ + if (platform) + return ane_fw_platform_probe(pdev, platform); mutex_lock(&ane_rtclient_probe_guard_lock); if (ane_rtclient_probe_failed_dirty || ane_rtclient_active) { @@ -4512,7 +4531,7 @@ static void ane_rtclient_remove(struct platform_device *pdev) const struct ane_t602x_soc *soc = of_device_get_match_data(&pdev->dev); struct ane_rtclient *ane = platform_get_drvdata(pdev); - if (soc->platform) { + if (ane_rtclient_platform(pdev->dev.of_node, soc)) { ane_fw_platform_remove(pdev); return; } @@ -4627,7 +4646,7 @@ static umode_t ane_t6021_stats_is_visible(struct kobject *kobj, const struct ane_t602x_soc *soc = of_device_get_match_data(dev); struct ane_rtclient *ane = dev_get_drvdata(dev); - if (soc->platform || !ane) + if (ane_rtclient_platform(dev->of_node, soc) || !ane) return 0; if (attr == &dev_attr_ane_stats.attr && !ane->stats_slots) return 0; @@ -4670,9 +4689,10 @@ static int __init ane_rtclient_init(void) */ for_each_matching_node_and_match(np, ane_rtclient_of_match, &match) { const struct ane_t602x_soc *soc = match->data; + const struct ane_fw_platform *platform = ane_rtclient_platform(np, soc); struct platform_device *pdev; - if (!soc->platform) + if (!platform) continue; if (!of_device_is_available(np)) continue; @@ -4682,13 +4702,13 @@ static int __init ane_rtclient_init(void) pr_info("ane: H16 ANE: firmware transport unvalidated; keeping disabled\n"); return -EOPNOTSUPP; } - if (ane_fw_platform_staged(soc->platform)) { - ret = ane_fw_staged_init(pdev, soc->platform); + if (ane_fw_platform_staged(platform)) { + ret = ane_fw_staged_init(pdev, platform); /* No loader hand-off: the probe below refuses quietly. */ if (ret == -ENODEV) ret = 0; } else { - ret = ane_fw_platform_preflight(pdev, soc->platform); + ret = ane_fw_platform_preflight(pdev, platform); } put_device(&pdev->dev); if (ret)