diff --git a/Documentation/accel/apple-ane.rst b/Documentation/accel/apple-ane.rst index 3c5edd6fd52c0..d59ac53f89cd3 100644 --- a/Documentation/accel/apple-ane.rst +++ b/Documentation/accel/apple-ane.rst @@ -691,9 +691,10 @@ stage that has not run yet, up to the one written, for diagnosis. A stage at or below the completed one is refused with ``-EALREADY``. There is no module parameter and no H14 boot parameter changes the H16 path. H17 still refuses ownership and registration. All build-dependent boot values and ordered masked updates belong to the -H16 27.0 (26A428) match-data profile. The existing preload validator must -accept the resident image before that profile can run. Live mutable patchbay -and firmware tunable values are preserved, with no disk firmware owner. +H16 27.0 (26A428) match-data build shared by the supported H16 profiles +(27.0 26A428, 27.2 26B123, 26.6.2 25G83, and 26.5.2 25F84). The preload +validator must accept the resident image before a profile can run. Live mutable +patchbay and firmware tunable values are preserved, with no disk firmware owner. ``preflight`` raises the five real domains through genpd, in DT order, and checks every requested/ACTUAL low byte twice before reading the engine. @@ -702,7 +703,8 @@ three DART fault status/address words, version/protect/lock headers and four DAPF records per instance against ``apple,dapf-ranges``. The ANE backend writes no engine, DART or DAPF register at this rung. Genpd owns power writes. -``map`` claims an exclusive, singleton IOMMU group and an unmanaged domain +``map`` verifies that none of the three DARTs has TTBR/TCR protection (bit 0) +set before claiming an exclusive, singleton IOMMU group and an unmanaged domain covering the three SID-0 DART instances. Private surfaces currently require a DMA-coherent client; noncoherent clients refuse pool allocation before RUN. No unexported architecture cache helper is called from the module. It checks @@ -822,8 +824,9 @@ The ``ane-h16-boot`` KUnit suite uses a simulated engine, scratch cells, mailbox polling and rings. It covers startup including allocation service, missing READY, wrong/stale table publication, oversized IPC/heap requests, channel bounds, locked DAPF differences, nonzero acks, scratch-3 timeout, -zero tick, default refusal and quarantine after RUN. It also covers matching -locked DAPF, heap/shared overlap, native FREE, foreign FREE and control refusal. +zero tick, default refusal and quarantine after RUN. It also covers DART +protection refusal, matching locked DAPF, heap/shared overlap, native FREE, +foreign FREE and control refusal. H16 program stage ----------------- diff --git a/drivers/accel/ane/ane_h16_backend.c b/drivers/accel/ane/ane_h16_backend.c index 4b1ca924c1759..1839bff767534 100644 --- a/drivers/accel/ane/ane_h16_backend.c +++ b/drivers/accel/ane/ane_h16_backend.c @@ -938,6 +938,10 @@ static int ane_h16_map(void *ctx) unsigned int count = 0, i; int ret; + /* Unmanaged domains can otherwise attach retained, firmware-owned roots. */ + ret = ane_h16_dart_protection(b, true); + if (ret) + return ret; if (of_count_phandle_with_args(h->dev->of_node, "iommus", "#iommu-cells") != 3) { dev_err(h->dev, "H16 map requires only SID 0 on three DARTs; refusing extra streams\n"); return -EOPNOTSUPP; @@ -1527,6 +1531,8 @@ static void ane_h16_release(struct ane_h16_device *h) dev_pm_domain_detach(pd, true); } h->acquired = false; + vfree(h->pristine_data); + h->pristine_data = NULL; dev_info(h->dev, "H16 pre-RUN rollback complete; no CPU release\n"); } diff --git a/drivers/accel/ane/ane_h16_boot.h b/drivers/accel/ane/ane_h16_boot.h index 184e04648597c..974c8dc5c7aeb 100644 --- a/drivers/accel/ane/ane_h16_boot.h +++ b/drivers/accel/ane/ane_h16_boot.h @@ -275,6 +275,25 @@ static inline int ane_h16_select_mmio(struct ane_h16_boot *b) return -ENODEV; } +/* TTBR/TCR protection is bit 0, separate from the DAPF lock at +0x208. */ +static inline int ane_h16_dart_protection(struct ane_h16_boot *b, bool require_unlocked) +{ + unsigned int i; + u32 protected = 0; + + if (!b->mmio) + return -ENODEV; + for (i = 0; i < 3; i++) { + u32 value = b->ops->read32(b->ctx, ANE_H16_DART0 + i, + b->mmio->dart_protect); + + b->ops->log(b->ctx, require_unlocked ? "DART map protect" : + "DART preflight protect", i, value); + protected |= value & BIT(0); + } + return require_unlocked && protected ? -EPERM : 0; +} + static inline int ane_h16_preflight(struct ane_h16_boot *b) { const struct ane_h16_build *f = b->build; @@ -300,6 +319,9 @@ static inline int ane_h16_preflight(struct ane_h16_boot *b) if (control || rvbar != f->expected_rvbar) return -EBUSY; ret = ane_h16_select_mmio(b); + if (ret) + return ret; + ret = ane_h16_dart_protection(b, false); if (ret) return ret; ret = ane_h16_faults(b, true); diff --git a/drivers/accel/ane/ane_h16_boot_data.h b/drivers/accel/ane/ane_h16_boot_data.h index 71e82c3940b33..131aca66fe8ff 100644 --- a/drivers/accel/ane/ane_h16_boot_data.h +++ b/drivers/accel/ane/ane_h16_boot_data.h @@ -503,6 +503,20 @@ static const struct ane_h16_profile ane_t8132_profiles[] __maybe_unused = { }, }; +/* 27.2 (26B123) preload on T6041 (J616c): 26A428 DATA layout and zeroed range. */ +static const struct ane_h16_preload_rule ane_h16_preload_26b123 = { + .cells = ane_h16_patchbay_26a428, + .cell_count = ARRAY_SIZE(ane_h16_patchbay_26a428), + .zero_start = 0x17c80, + .zero_end = 0x18320, + .digest = { + 0xd1, 0xbd, 0xb9, 0xd0, 0x4d, 0x6e, 0x35, 0xa7, + 0x31, 0x71, 0xc2, 0xa8, 0xa9, 0x66, 0x38, 0xfe, + 0xc2, 0x6c, 0x4c, 0xed, 0x7a, 0x0e, 0xfd, 0xc4, + 0xb9, 0xde, 0x58, 0x5f, 0x70, 0x92, 0x33, 0x16, + }, +}; + /* Every supported H16 firmware build, matched against the live preload. */ static const struct ane_h16_profile ane_h16_profiles[] __maybe_unused = { { @@ -510,6 +524,11 @@ static const struct ane_h16_profile ane_h16_profiles[] __maybe_unused = { .preload = &ane_h16_preload_26a428, .build = &ane_h16_build_26a428, }, + { + .identity = "H16 27.2 26B123", + .preload = &ane_h16_preload_26b123, + .build = &ane_h16_build_26a428, + }, { .identity = "H16 26.6.2 25G83", .preload = &ane_h16_preload_25g83, diff --git a/drivers/accel/ane/ane_h16_boot_test.c b/drivers/accel/ane/ane_h16_boot_test.c index b4f5af3ec669f..cb143ee388ca4 100644 --- a/drivers/accel/ane/ane_h16_boot_test.c +++ b/drivers/accel/ane/ane_h16_boot_test.c @@ -39,6 +39,8 @@ struct ane_h16_sim { u32 timeout_scratch; u64 timeout_head; u32 lock; + u32 protect[3]; + u32 protect_reads; u32 fault; u32 fault_address_reads; u32 channel_request; @@ -89,8 +91,10 @@ static void sim_check_dart(struct ane_h16_sim *s, enum ane_h16_window w, u32 off KUNIT_ASSERT_NOT_NULL(s->test, m); if (off == m->dart_fault || off == m->dart_address_lo || off == m->dart_address_hi) return; + if (off == m->dart_protect) + return; KUNIT_EXPECT_EQ(s->test, w, ANE_H16_DART0 + s->soc.dapf_dart); - KUNIT_EXPECT_TRUE(s->test, off == m->dart_protect || off == m->dart_lock); + KUNIT_EXPECT_EQ(s->test, off, m->dart_lock); } static void sim_check_dapf(struct ane_h16_sim *s, u32 off, u32 width) @@ -114,7 +118,11 @@ static u32 sim_read32(void *ctx, enum ane_h16_window w, u32 off) sim_check_dart(s, w, off); if (off == s->soc.dart_params) return s->dart_params; - if (off == s->mmio.dart_protect || off == s->mmio.dart_lock) + if (off == s->mmio.dart_protect) { + s->protect_reads |= BIT(w - ANE_H16_DART0); + return s->protect[w - ANE_H16_DART0]; + } + if (off == s->mmio.dart_lock) return s->lock; if (off == s->mmio.dart_fault) return s->fault; @@ -1128,6 +1136,29 @@ static void ane_h16_map_failure_test(struct kunit *test) KUNIT_EXPECT_EQ(test, s->pins, 0U); } +/* Every DART is observed; only bit 0 prevents fresh translation ownership. */ +static void ane_h16_dart_protection_test(struct kunit *test) +{ + struct ane_h16_sim *s = test->priv; + unsigned int i; + + KUNIT_EXPECT_EQ(test, ane_h16_dart_protection(&s->boot, true), -ENODEV); + KUNIT_EXPECT_EQ(test, s->protect_reads, 0U); + KUNIT_ASSERT_EQ(test, ane_h16_select_mmio(&s->boot), 0); + for (i = 0; i < 3; i++) { + s->protect[i] = BIT(0); + s->protect_reads = 0; + KUNIT_EXPECT_EQ(test, ane_h16_dart_protection(&s->boot, true), -EPERM); + KUNIT_EXPECT_EQ(test, s->protect_reads, 7U); + KUNIT_EXPECT_EQ(test, ane_h16_dart_protection(&s->boot, false), 0); + s->protect[i] = BIT(1) | BIT(2); + } + KUNIT_EXPECT_EQ(test, ane_h16_dart_protection(&s->boot, true), 0); + KUNIT_EXPECT_EQ(test, s->dapf_writes, 0U); + KUNIT_EXPECT_EQ(test, s->maps, 0U); + KUNIT_EXPECT_EQ(test, s->scratch_writes, 0U); +} + static void ane_h16_locked_matching_test(struct kunit *test) { struct ane_h16_sim *s = test->priv; @@ -1146,6 +1177,7 @@ static void ane_h16_dapf_program_test(struct kunit *test) unsigned int i; KUNIT_ASSERT_EQ(test, ane_h16_run(&s->boot, ANE_H16_PREFLIGHT), 0); + KUNIT_EXPECT_EQ(test, s->protect_reads, 7U); KUNIT_EXPECT_EQ(test, s->dapf_writes, 0U); KUNIT_ASSERT_EQ(test, ane_h16_run(&s->boot, ANE_H16_MAP), 0); KUNIT_EXPECT_EQ(test, s->dapf_writes, 20U); @@ -1319,6 +1351,7 @@ static void ane_h16_t8132_locked_test(struct kunit *test) static struct kunit_case ane_h16_boot_cases[] = { KUNIT_CASE(ane_h16_alloc_reuse_test), KUNIT_CASE(ane_h16_happy_test), + KUNIT_CASE(ane_h16_dart_protection_test), KUNIT_CASE(ane_h16_locked_matching_test), KUNIT_CASE(ane_h16_dapf_program_test), KUNIT_CASE(ane_h16_dapf_partial_test), diff --git a/drivers/accel/ane/ane_h16_preload_test.c b/drivers/accel/ane/ane_h16_preload_test.c index 2c023d8308250..dec5fdff47cd5 100644 --- a/drivers/accel/ane/ane_h16_preload_test.c +++ b/drivers/accel/ane/ane_h16_preload_test.c @@ -349,7 +349,26 @@ static void preload_profiles_test(struct kunit *test) } } +static void preload_26b123_ce_script_test(struct kunit *test) +{ + struct preload_fixture *f = test->priv; + u8 baseline[SHA256_DIGEST_SIZE], digest[SHA256_DIGEST_SIZE]; + static const u32 positions[] = { 0xb9040, 0xba094, 0xbd03f }; + unsigned int i; + + f->rule = ane_h16_preload_26b123; + KUNIT_ASSERT_EQ(test, preload_digest(f, baseline), 0); + /* The entire live CE script stays in the identity, including its padding. */ + for (i = 0; i < ARRAY_SIZE(positions); i++) { + f->text[positions[i]] ^= 1; + KUNIT_ASSERT_EQ(test, preload_digest(f, digest), 0); + KUNIT_EXPECT_NE(test, memcmp(digest, baseline, sizeof(digest)), 0); + f->text[positions[i]] ^= 1; + } +} + static struct kunit_case preload_cases[] = { + KUNIT_CASE(preload_26b123_ce_script_test), KUNIT_CASE(preload_identity_test), KUNIT_CASE(preload_mutable_test), KUNIT_CASE(preload_framing_test), diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 150cd163924f1..d2e339c406d64 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -544,16 +544,22 @@ static int dcp_dpxbar_tunnel_select_source(struct mux_control *mux, int state) return ret; } +static bool dcp_t6041_ext_v27(const struct apple_dcp *dcp) +{ + return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && dcp->desktop_external; +} + /* - * Desktop 26.x firmware does not power the DP PHY of a Type-C route itself: - * the route does, once its crossbar points at the pipeline, and gives it - * back before the crossbar is released. + * Desktop 26.x and T6041 firmware-27 external processors do not power the DP + * PHY of a Type-C route themselves: the route does, once its crossbar points at + * the pipeline, and gives it back before the crossbar is released. */ static int dcp_typec_route_phy_on(struct apple_dcp_typec_route *route) { int ret; - if (route->dcp->fw_compat != DCP_FIRMWARE_V_26_6_DESKTOP || + if ((route->dcp->fw_compat != DCP_FIRMWARE_V_26_6_DESKTOP && + !dcp_t6041_ext_v27(route->dcp)) || route->phy_powered) return 0; ret = phy_init(route->phy); @@ -597,7 +603,8 @@ int dcp_typec_phy_on(struct apple_dcp *dcp) */ if (route->tunnel) return 0; - if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP && + if ((dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t6041_ext_v27(dcp)) && route->deactivate_xbar_done) return -ENODEV; return dcp_typec_route_phy_on(route); @@ -925,7 +932,8 @@ static int dcp_typec_route_deactivate(struct apple_dcp_typec_route *route) * attached. Desktop 26.x powers the PHY with the route, so an * idle pipeline must not point at one. */ - dcp->phy = dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP ? + dcp->phy = (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t6041_ext_v27(dcp)) ? NULL : dcp->typec_routes[0].phy; if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) WRITE_ONCE(dcp->xbar, NULL); @@ -2016,6 +2024,7 @@ static int dcp_typec_route_apply(struct typec_mux_dev *mux, * when HPD returns. */ if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t6041_ext_v27(dcp) || dcp_t8142_ext(dcp)) { port->preferred_route = port->owner; port->hpd = false; @@ -2142,6 +2151,7 @@ static int dcp_typec_route_apply(struct typec_mux_dev *mux, */ if (!port->owner && !hpd && (route->dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t6041_ext_v27(route->dcp) || dcp_t8142_ext(route->dcp))) { port->applied_valid = true; return 0; @@ -2613,13 +2623,15 @@ int dcp_direct_crossbar_link(struct apple_dcp *dcp, bool up) struct mux_control *xbar = NULL; int ret; - if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0 && !dcp_t6041_ext_v27(dcp)) return dcp_direct_crossbar_link_t6050(dcp, up); /* - * On T6030, a T8132 dcpext and the selected native26 pipeline, - * selecting a crossbar output only routes it; link-up enables clocks. + * On T6030, a T6041 firmware-27 dcpext, a T8132 dcpext and the selected + * native26 pipeline, selecting a crossbar output only routes it; + * link-up enables clocks. */ if (!of_machine_is_compatible("apple,t6030") && + !dcp_t6041_ext_v27(dcp) && !dcp_is_t8132_ext(dcp) && !dcp_is_ext26(dcp)) return 0; guard(mutex)(&dcp->tb_lock); diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7cde46e009096..8a33895235852 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -5853,9 +5854,10 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) ret = dcp_read_fw_version(dev, "apple,firmware-version", fw_str); /* - * T6041 (M4 Pro/Max) is driven only with the 26.5.2 and 26.6.2 firmware - * its desktop IOMFB instance was written for: the boot firmware and its - * compatibility version must both be exactly the same one of those. + * T6041 (M4 Pro/Max) uses its desktop IOMFB instance on 26.5.2 and + * 26.6.2 firmware, where boot firmware and compatibility versions must + * match. The pinned 27.2 (26B123) T6041 DCP image uses the firmware-27 + * backend on internal and external display processors. */ if (of_device_is_compatible(dev->of_node, "apple,t6041-dcp") || of_device_is_compatible(dev->of_node, "apple,t6041-dcpext")) { @@ -5865,7 +5867,23 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) if (ret >= 0 && compat_ret >= 0 && !strcmp(fw_str, compat_str) && (!strcmp(fw_str, "26.5.2") || !strcmp(fw_str, "26.6.2"))) return DCP_FIRMWARE_V_26_6_DESKTOP; - dev_err(dev, "T6041 display not started: DCP firmware %s (compat %s) is not 26.5.2 or 26.6.2\n", + if (apple_t6041_dcp_v27_2(dev->of_node) || + apple_t6041_dcpext_v27_2(dev->of_node)) { + if (!iomfb_v27_methods(compat_str)) { + dev_err(dev, "DCP firmware-compat %s has no 27.x method table\n", + compat_str); + return DCP_FIRMWARE_UNKNOWN; + } + missing = iomfb_v27_missing_method(iomfb_v27_methods(compat_str), + &num_missing); + if (missing) { + dev_err(dev, "DCP firmware-compat %s not started: no ID known for %u methods (first: %s)\n", + compat_str, num_missing, missing); + return DCP_FIRMWARE_UNKNOWN; + } + return DCP_FIRMWARE_V_27_0; + } + dev_err(dev, "T6041 display not started: unsupported DCP firmware %s (compat %s)\n", ret >= 0 ? fw_str : "missing", compat_ret >= 0 ? compat_str : "missing"); return DCP_FIRMWARE_UNKNOWN; @@ -6088,6 +6106,32 @@ static int dcp_firmware_metadata_v27(struct apple_dcp *dcp) return -EINVAL; clocks: + /* + * T6041 device trees carry the single 712 MHz disp0 clock unless the + * boot loader publishes the two /arm-io/disp0 provider clocks + * (376 at 712 MHz and 460 at 0 Hz). Expose the same two-entry table + * when apple,clock-ids is absent so getClockFrequency(0/1) matches. + */ + if (!of_property_present(dev->of_node, "apple,clock-ids") && + of_device_is_compatible(dev->of_node, "apple,t6041-dcp")) { + struct clk *clk = devm_clk_get_optional(dev, NULL); + + if (IS_ERR(clk)) + return PTR_ERR(clk); + if (!clk) + return 0; + dcp->firmware_clocks = devm_kcalloc(dev, 2, + sizeof(*dcp->firmware_clocks), + GFP_KERNEL); + if (!dcp->firmware_clocks) + return -ENOMEM; + dcp->firmware_clocks[0].clk = clk; + dcp->num_firmware_clocks = 2; + return 0; + } + if (!of_property_present(dev->of_node, "apple,clock-ids") && + of_device_is_compatible(dev->of_node, "apple,t6041-dcpext")) + return 0; clocks = of_property_count_u32_elems(dev->of_node, "apple,clock-ids"); if (clocks == -ENODATA && of_property_present(dev->of_node, "apple,clock-ids")) @@ -6794,10 +6838,13 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v cancel_work_sync(&dcp->bl_register_wq); cancel_work_sync(&dcp->bl_update_wq); } - devm_clk_put(dev, dcp->clk); + if (dcp->clk) + devm_clk_put(dev, dcp->clk); dcp->clk = NULL; /* optional and possibly NULL, released with the bind's devres group */ dcp->clk_194 = NULL; + dcp->firmware_clocks = NULL; + dcp->num_firmware_clocks = 0; } static const struct component_ops dcp_comp_ops = { @@ -6966,7 +7013,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) fw_compat = dcp_check_firmware_version(dev); if (fw_compat == DCP_FIRMWARE_UNKNOWN) return -ENODEV; - if (fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { + if (fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + (fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dev->of_node, "apple,t6041-dcp"))) { ret = dcp_validate_t6041_dt(dev); if (ret) return ret; @@ -7086,6 +7135,24 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) if (fw_compat == DCP_FIRMWARE_V_27_0 && of_device_is_compatible(dev->of_node, "apple,t8142-dcp")) dcp->hw.iomfb_method_profile = DCP_IOMFB_METHODS_DEFAULT; + /* + * T6041 internal panel on firmware 27 adopts the running DCP session + * with 41-bit firmware DMA addressing and no DPTX port services, + * matching the H17-generation internal-panel profile. + */ + if (fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dev->of_node, "apple,t6041-dcp")) { + dcp->hw.firmware_dma_bits = 41; + dcp->hw.num_dptx_ports = 0; + dcp->hw.adopt_live_session = true; + } + if (fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dev->of_node, "apple,t6041-dcpext")) { + dcp->hw.firmware_dma_bits = 41; + dcp->hw.num_dptx_ports = 2; + dcp->hw.adopt_live_session = true; + dcp->hw.sink_metadata_edid = true; + } /* * A SoC with derived power words is offered the stop only when asked for, and only on * firmware 27.0, whose calls are the ones that ran with them. @@ -7235,7 +7302,8 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) } dcp->fixed_phy = dcp->phy; - if (fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { + if (fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + (fw_compat == DCP_FIRMWARE_V_27_0 && dcp->desktop_external)) { ret = dcp_desktop_probe_routes(dcp); if (ret) return ret; @@ -7357,7 +7425,8 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) if (IS_ERR(dcp->dp2hdmi_pwren)) return PTR_ERR(dcp->dp2hdmi_pwren); /* The converter rails must be stable before DCP requests the link. */ - if (fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP && + if ((fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + (fw_compat == DCP_FIRMWARE_V_27_0 && dcp->desktop_external)) && (dcp->hdmi_pwren || dcp->dp2hdmi_pwren)) msleep(100); diff --git a/drivers/gpu/drm/asahi/fwid.rs b/drivers/gpu/drm/asahi/fwid.rs index df20d3c406626..f9525c0c08f30 100644 --- a/drivers/gpu/drm/asahi/fwid.rs +++ b/drivers/gpu/drm/asahi/fwid.rs @@ -476,12 +476,16 @@ mod tests { else { panic!("T6041 must identify its loaded firmware"); }; - assert_eq!(builds.len(), 3); - // The last two admit the 25G83 images, with the 40- and the 32-core configuration. + assert_eq!(builds.len(), 5); + // Builds 1..=2 (25G83) and 3..=4 (26B123) admit the 40- and 32-core configurations. assert_eq!(builds[1].images.len(), builds[2].images.len()); for (a, b) in builds[1].images.iter().zip(builds[2].images) { assert_eq!((a.entropy, a.text_sha256), (b.entropy, b.text_sha256)); } + assert_eq!(builds[3].images.len(), builds[4].images.len()); + for (a, b) in builds[3].images.iter().zip(builds[4].images) { + assert_eq!((a.entropy, a.text_sha256), (b.entropy, b.text_sha256)); + } for (i, build) in builds[..2].iter().enumerate() { let other = &builds[1 - i]; for image in build.images { @@ -489,10 +493,27 @@ mod tests { let found = measured(build.images, image.data_size, entropy, digest); assert!(core::ptr::eq(found.unwrap(), image)); assert!(measured(other.images, image.data_size, entropy, digest).is_none()); + assert!(measured(builds[3].images, image.data_size, entropy, digest).is_none()); assert!(measured(build.images, 0x13c000, entropy, digest).is_none()); } } - // Only the 25G83 build runs its own configuration: the 25G83 register map, 40 cores. + for image in builds[3].images { + let digest = image.text_sha256; + let found = lookup(builds[3].images, image.text_size, image.data_size, |_| { + Some(digest) + }); + assert!(core::ptr::eq(found.unwrap(), image)); + assert!( + lookup(builds[0].images, image.text_size, image.data_size, |_| Some(digest)) + .is_none() + ); + assert!( + lookup(builds[1].images, image.text_size, image.data_size, |_| Some(digest)) + .is_none() + ); + assert!(lookup(builds[3].images, 0x60000, image.data_size, |_| Some(digest)).is_none()); + } + // 25F84 uses CONFIG directly; 25G83 and 26B123 pair 40- and 32-core configurations. assert!(builds[0].config.is_none()); let g83 = builds[1].config.unwrap(); let map = &crate::hw::t6041::REGISTER_WINDOWS_25G83; @@ -514,6 +535,11 @@ mod tests { assert_eq!(g83_32.core_layout.cores, Some((4, 32))); assert!(g83_32.reserved_slots.is_empty()); assert_eq!(g83_32.windows.len(), map.len()); + let b123_40 = builds[3].config.unwrap(); + assert_eq!(b123_40.core_layout.cores, Some((4, 40))); + let b123_32 = builds[4].config.unwrap(); + assert_eq!(b123_32.core_layout.cores, Some((4, 32))); + assert_eq!(b123_32.windows.len(), map.len()); } #[cfg(CONFIG_DRM_ASAHI_G16)] diff --git a/drivers/gpu/drm/asahi/g17/fw/channels.rs b/drivers/gpu/drm/asahi/g17/fw/channels.rs index 1dd6ad86c9c4a..30e103b62e2ac 100644 --- a/drivers/gpu/drm/asahi/g17/fw/channels.rs +++ b/drivers/gpu/drm/asahi/g17/fw/channels.rs @@ -349,7 +349,7 @@ pub(crate) enum DeviceControlOp { IdlePowerOff = 0x0a, /// Release a logical queue's scheduler state ([`SchedulerStateRelease`]). SchedulerStateRelease = 0x14, - /// M5 encoding of the same scheduler-state release. + /// M5 and 26B123 encoding of the same scheduler-state release. M5SchedulerStateRelease = 0x13, /// Release a free list's buffer slot ([`FreeListRelease`]). FreeListRelease = 0x2e, @@ -363,7 +363,7 @@ impl DeviceControlOp { /// records it has drained and keeps the GPU cores powered while they /// differ. pub(crate) const fn asserts_gpu_power(self) -> bool { - !matches!(self, Self::FreeListRelease) + !matches!(self, Self::FreeListRelease | Self::M5SchedulerStateRelease) } } @@ -675,6 +675,26 @@ mod tests { assert!(bytes[24..].iter().all(|byte| *byte == 0)); } + #[test] + fn scheduler_state_release_opcodes_and_power() { + let legacy = ControlRecord::SchedulerStateRelease(SchedulerStateRelease::new( + 0x70_0420_0000, + *b"Q001", + )); + assert_eq!(legacy.opcode(), DeviceControlOp::SchedulerStateRelease); + assert!(legacy.opcode().asserts_gpu_power()); + + let mut rel27 = SchedulerStateRelease::new(0x70_0420_0000, *b"Q001"); + rel27.opcode = DeviceControlOp::M5SchedulerStateRelease as u32; + let record27 = ControlRecord::SchedulerStateRelease(rel27); + assert_eq!(record27.opcode(), DeviceControlOp::M5SchedulerStateRelease); + assert!(!record27.opcode().asserts_gpu_power()); + assert_eq!( + u32::from_le_bytes(record27.bytes()[..4].try_into().unwrap()), + 0x13 + ); + } + #[test] fn an_unrecognized_type_7_layout_stays_unknown() { assert_eq!(record(&[7, 1, 2, 128, 0x300]).decode(), Ok(Event::Unknown(7))); diff --git a/drivers/gpu/drm/asahi/g17/fw/initdata.rs b/drivers/gpu/drm/asahi/g17/fw/initdata.rs index caf2ba6b658e6..a70b5763eac4d 100644 --- a/drivers/gpu/drm/asahi/g17/fw/initdata.rs +++ b/drivers/gpu/drm/asahi/g17/fw/initdata.rs @@ -28,6 +28,7 @@ use kernel::prelude::*; use super::clear; pub(crate) mod v25g83; +pub(crate) mod v26b123; /// Interface version at root `+0x00`; the firmware rejects any other. pub(crate) const INTERFACE_VERSION: [u16; 4] = [0x04c0, 0x0396, 0xa322, 0x0c8a]; diff --git a/drivers/gpu/drm/asahi/g17/fw/initdata/v26b123.rs b/drivers/gpu/drm/asahi/g17/fw/initdata/v26b123.rs new file mode 100644 index 0000000000000..c949028d82878 --- /dev/null +++ b/drivers/gpu/drm/asahi/g17/fw/initdata/v26b123.rs @@ -0,0 +1,442 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! T6041 26B123 initialization wire layouts. +//! +//! The merged root keeps its geometry with a new interface version. The main +//! configuration keeps its control ring at `+0x4c0` while moving the unaligned +//! power pointer by 16 bytes. Register descriptors keep their encoding, with +//! 60 slots and a reordered resource table. + +use super::{ + MainConfig as LegacyMainConfig, MainConfigArgs, PrimaryViews, RegionC, RegisterMapEntry, + RegisterWindow, RootArgs, SecondaryRoot, +}; +use kernel::prelude::*; + +pub(crate) const INTERFACE_VERSION: [u16; 4] = [0x04c0, 0x8398, 0x6339, 0x0c8b]; +pub(crate) const REGISTER_MAP_SLOTS: usize = 60; +/// Separate GPTBAT MMIO resource, outside the 60-entry register table. +pub(crate) const GPTBAT_PHYS: u64 = 0x2_88d6_0000; +pub(crate) const GPTBAT_SIZE: u32 = 0x8000; + +/// Captured cold-start power state, including its limiter tuning. +#[repr(C)] +pub(crate) struct PowerState(pub(crate) [u8; 0x6d8]); + +// SAFETY: A byte array has no invalid representations or padding. +unsafe impl Zeroable for PowerState {} + +impl PowerState { + pub(crate) fn init(&mut self, max_power_mw: u32) { + self.0.fill(0); + for (offset, value) in [ + (0x10, 31), + (0x14, 0x3cf5c290), + (0x18, 0x3f19999a), + (0x1c, 40), + (0x20, 1), + (0xc8, 11000), + (0xcc, 8000), + (0xd8, 0x42080000), + (0xdc, 0x40baaaaa), + (0xf0, 9900), + (0xf4, 200), + (0x108, 0x42c80000), + (0x10c, 0x43c80000), + (0x110, 200), + (0x128, 1), + (0x12c, max_power_mw), + (0x130, 0x3e99999a), + (0x134, 0x3e0b4396), + (0x624, 0x41700000), + (0x628, 0x40a00000), + (0x62c, 32), + (0x630, 1000), + (0x640, 900), + ] { + self.0[offset..offset + 4].copy_from_slice(&value.to_le_bytes()); + } + } +} + +/// The first page of region C. Fields following `+0x38` shift by four bytes. +#[repr(C)] +pub(crate) struct RegionCPrefix(pub(crate) [u8; 0x1000]); + +// SAFETY: A byte array has no invalid representations or padding. +unsafe impl Zeroable for RegionCPrefix {} + +impl RegionCPrefix { + pub(crate) fn init(&mut self, legacy: &RegionC) { + // SAFETY: RegionC is packed and all fields are initialized integers. + let old = + unsafe { core::slice::from_raw_parts((legacy as *const RegionC).cast::(), 0x1000) }; + self.0[..0x38].copy_from_slice(&old[..0x38]); + self.0[0x38..0x3c].copy_from_slice(&1u32.to_le_bytes()); + self.0[0x3c..].copy_from_slice(&old[0x38..0xffc]); + // Cold-start policy words in previously reserved fields. + self.0[0x9dc..0x9e0].copy_from_slice(&50u32.to_le_bytes()); + self.0[0xe0c..0xe10].copy_from_slice(&250u32.to_le_bytes()); + } +} + +pub(crate) struct PowerArgs { + pub(crate) config_va: u64, + pub(crate) aon_va: u64, + /// Caller value of the build's variable startup word. + pub(crate) startup_word: u32, +} + +#[repr(C)] +pub(crate) struct PowerConfig(pub(crate) [u8; 0x6c48]); + +// SAFETY: Byte arrays have no invalid representations or padding. +unsafe impl Zeroable for PowerConfig {} + +static_assert!(size_of::() == 0x6c48); + +impl PowerConfig { + pub(crate) fn init( + &mut self, + legacy: &super::v25g83::PowerConfig25G83, + args: &PowerArgs, + ) -> Result { + let status = args.config_va.checked_add(0x80).ok_or(EINVAL)?; + if args.config_va == 0 || args.aon_va == 0 { + return Err(EINVAL); + } + let old = &legacy.0; + self.0.fill(0); + self.0[4..0x9c].copy_from_slice(&old[4..0x9c]); + self.0[0xb0..0xfc].copy_from_slice(&old[0xa0..0xec]); + self.0[0x934..0x2888].copy_from_slice(&old[0x924..0x2878]); + self.0[0x28a0..0x2cb0].copy_from_slice(&old[0x2878..0x2c88]); + self.0[0x2d20..0x3160].copy_from_slice(&old[0x2d00..0x3140]); + self.0[0x3b98..0x630c].copy_from_slice(&old[0x3b50..0x62c4]); + self.0[0x6348..0x63f0].copy_from_slice(&old[0x6320..0x63c8]); + // Cold native startup has no legacy reporter/timestamp state. Only the + // chip's leakage coefficients survive in the relocated tail. + self.0[0x6ad4..0x6bb4].copy_from_slice(&old[0x642c..0x650c]); + for (start, end) in [ + (0xac8, 0xacc), + (0xad0, 0xad4), + (0xaf0, 0xb34), + (0xb3c, 0xb40), + (0xb98, 0xb9c), + (0xba0, 0xba4), + (0xbd8, 0xbe8), + (0x2274, 0x2278), + (0x22d8, 0x22dc), + (0x2878, 0x287c), + (0x2884, 0x2888), + (0x2900, 0x2904), + (0x2a34, 0x2a38), + (0x2a54, 0x2a58), + (0x2a6c, 0x2b70), + (0x2bc4, 0x2bc8), + (0x2bec, 0x2bf8), + ] { + self.0[start..end].fill(0); + } + // T6041 cold-start policy observed on native 26B123 boots. Some legacy + // controller tunings revert to the shared defaults in this build. + for (offset, value) in [ + (0xa80, 8), + (0xa8c, 0x3f000000), + (0xa94, 0x3f000000), + (0xae0, 0x5dc00), + (0x2204, 0x42c80000), + (0x2220, 100), + (0x29e4, 124), + (0x29f0, 0x3f77bdef), + (0x29f8, 0x3d042108), + (0x2bbc, 0x45fa0000), + (0x2c10, 8000), + (0x2f0c, 0x42c80000), + ] { + self.word32(offset, value); + } + self.0[0x2a2c..0x2a30].copy_from_slice(&old[0x9e0..0x9e4]); + for offset in [0x44, 0x9c, 0xa0, 0xa4, 0xa8, 0x2f34, 0x6ac8] { + self.word32(offset, 1); + } + self.0[0x3b98..0x3ba0].copy_from_slice(&status.to_le_bytes()); + self.0[0x6340..0x6348].copy_from_slice(&args.aon_va.to_le_bytes()); + self.word32(0x6a7c, args.startup_word); + Ok(()) + } + + fn word32(&mut self, offset: usize, value: u32) { + self.0[offset..offset + 4].copy_from_slice(&value.to_le_bytes()); + } +} + +pub(crate) fn merged_root( + args: &RootArgs, + status_b_va: u64, + power_state_va: u64, + config_va: u64, +) -> SecondaryRoot { + let mut root = SecondaryRoot::merged(args, status_b_va, power_state_va, config_va); + root.root.version = INTERFACE_VERSION; + root +} + +/// The common main-config fields followed by the 26B123 power pointer. +#[repr(C, packed)] +pub(crate) struct MainConfig { + common: [u8; 0x471], + reserved_471: [u8; 0x10], + pub(crate) power_config_va: u64, + reserved_489: [u8; 0x37], +} + +/// Addresses of independently owned channel, descriptor and view objects. +pub(crate) struct MainArgs<'a> { + pub(crate) common: &'a MainConfigArgs, + pub(crate) primary_views: &'a PrimaryViews, + pub(crate) view_va: [u64; 5], + pub(crate) firmware_area_va: [u64; 2], + pub(crate) work_rings_va: u64, + pub(crate) power_config_va: u64, +} + +// SAFETY: This is a packed sequence of integers and byte arrays. +unsafe impl Zeroable for MainConfig {} + +static_assert!(core::mem::offset_of!(MainConfig, power_config_va) == 0x481); +static_assert!(size_of::() == 0x4c0); + +impl MainConfig { + /// Builds all fields, including the merged-role defaults, from host inputs. + /// Work rings may be placed independently of the hardware-data bundle. + pub(crate) fn init_merged(&mut self, args: &MainArgs<'_>) -> Result { + // SAFETY: LegacyMainConfig contains integers and byte arrays only. + let mut common: LegacyMainConfig = unsafe { core::mem::zeroed() }; + common.init_primary(args.common, args.primary_views); + common.view_va = args.view_va; + common.firmware_area_va = args.firmware_area_va; + common.unk_300 = 4; + common.unk_32c = 0; + common.unk_344 = 0; + for channel in 0..super::WORK_CHANNELS { + let offset = super::work_ring_offset(channel) - super::bundle::WORK_RINGS; + common.channels[channel].0[3] = args + .work_rings_va + .checked_add(offset as u64) + .ok_or(EINVAL)?; + } + self.init(&common, args.power_config_va); + Ok(()) + } + + /// Reuses the common channel/view/descriptor fields. The old power slot and + /// both reserved tails are zero, independently of the legacy pointer value. + pub(crate) fn init(&mut self, common: &LegacyMainConfig, power_config_va: u64) { + // SAFETY: LegacyMainConfig is packed and contains initialized integers + // only. The common prefix ends before its old power pointer. + let bytes = unsafe { + core::slice::from_raw_parts((common as *const LegacyMainConfig).cast::(), 0x471) + }; + self.common.copy_from_slice(bytes); + self.reserved_471.fill(0); + self.power_config_va = power_config_va; + self.reserved_489.fill(0); + } +} + +/// Slots with the reserved/shared bit, including descriptors with no mapping. +const SHARED_SLOTS: &[usize] = &[ + 0, 2, 3, 5, 6, 7, 8, 9, 11, 12, 17, 20, 22, 25, 26, 27, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 42, 43, 44, 45, 46, 47, 48, 52, 53, 54, 55, 58, +]; + +/// The 25 physical T6041 windows keep their tuples, but 13 change slots. +pub(crate) fn register_slot(old: usize) -> Result { + Ok(match old { + 0 | 3 | 4 | 9 | 10 | 11 | 12 | 14 | 15 | 17 | 20 | 22 => old, + 26 => 31, + 28 => 33, + 29 => 34, + 31 => 36, + 32 => 37, + 33 => 38, + 34 => 39, + 35 => 40, + 37 => 42, + 39 => 44, + 40 => 45, + 41 => 46, + 43 => 48, + _ => return Err(EINVAL), + }) +} + +/// Register descriptors at hardware-data `+0x640`. +#[repr(C)] +pub(crate) struct RegisterTable { + pub(crate) entries: [RegisterMapEntry; REGISTER_MAP_SLOTS], +} + +// SAFETY: RegisterMapEntry consists of integers; so does an array of it. +unsafe impl Zeroable for RegisterTable {} + +static_assert!(size_of::() == 0x960); + +impl RegisterTable { + /// Builds the table from host-owned mappings; no native GPUVAs are copied. + pub(crate) fn init(&mut self, windows: &[RegisterWindow]) -> Result { + if windows.len() != 25 { + return Err(EINVAL); + } + super::clear(self); + for &slot in SHARED_SLOTS { + self.entries[slot] = RegisterMapEntry::reserved(); + } + let mut used = [false; REGISTER_MAP_SLOTS]; + for window in windows { + let slot = register_slot(window.slot)?; + if window.phys == 0 || window.va == 0 || window.size == 0 || window.instances == 0 { + return Err(EINVAL); + } + window.size.checked_mul(window.instances).ok_or(EINVAL)?; + if used[slot] { + return Err(EINVAL); + } + used[slot] = true; + self.entries[slot] = RegisterMapEntry::window(window); + } + Ok(()) + } +} + +/// Addresses of separately owned objects and optional native calibration policy words. +pub(crate) struct HardwareArgs { + pub(crate) gptbat_va: u64, + pub(crate) gptbat_size: u32, + pub(crate) completion_low: [u64; 2], + pub(crate) completion_high: [u64; 2], + pub(crate) qos_va: u64, + pub(crate) auxiliary_va: u64, + /// Native relative-performance calibration words when preserving exact fractions; + /// `None` keeps the integer relative ladders encoded from `cfg.perf` in `legacy`. + pub(crate) relative_words: Option<([u32; 11], [u32; 11])>, +} + +/// The logical hardware-data object, excluding the aggregate allocation's peers. +#[repr(C)] +pub(crate) struct HardwareData(pub(crate) [u8; 0x2850]); + +// SAFETY: A byte array has no invalid representations or padding. +unsafe impl Zeroable for HardwareData {} + +impl HardwareData { + /// Encodes the shared 25G83 fields in the 26B123 layout. Distinct insertions + /// surround the register table, completion descriptors and auxiliary pointer. + /// The supplied legacy object is an intermediate host value, not firmware data. + pub(crate) fn init( + &mut self, + legacy: &super::v25g83::HwData25G83, + registers: &RegisterTable, + pointers: &HardwareArgs, + ) -> Result { + if pointers.gptbat_size != GPTBAT_SIZE + || pointers.gptbat_va == 0 + || pointers.qos_va == 0 + || pointers.auxiliary_va == 0 + { + return Err(EINVAL); + } + // SAFETY: These packed integer objects contain initialized bytes only. + let old = unsafe { + core::slice::from_raw_parts( + (legacy as *const super::v25g83::HwData25G83).cast::(), + size_of::(), + ) + }; + let table = unsafe { + core::slice::from_raw_parts( + (registers as *const RegisterTable).cast::(), + size_of::(), + ) + }; + self.0.fill(0); + self.0[..0x640].copy_from_slice(&old[..0x640]); + self.0[0x640..0xfa0].copy_from_slice(table); + self.0[0xfb0..0xfdc].copy_from_slice(&old[0xe90..0xebc]); + self.0[0xfdc..0x2734].copy_from_slice(&old[0xec0..0x2618]); + self.0[0x2738..0x27e0].copy_from_slice(&old[0x2618..0x26c0]); + self.0[0x27e8..0x2850].copy_from_slice(&old[0x26c0..0x2728]); + self.word64(0xfa0, pointers.gptbat_va); + self.word32(0xfa8, pointers.gptbat_size); + // T6041-specific native startup policy words. + for (offset, value) in [ + (0x1044, 12), + (0x10c8, 0), + (0x10d4, 20), + (0x271c, 150), + (0x272c, 0), + (0x2734, 1), + (0x2844, 0x10000), + (0x2848, 0x10000), + ] { + self.word32(offset, value); + } + for (index, offset) in [0x2740, 0x2780].into_iter().enumerate() { + self.word64(offset, pointers.completion_low[index]); + self.word64(offset + 8, pointers.completion_high[index]); + } + self.word64(0x27d8, pointers.qos_va); + self.word64(0x27e0, pointers.auxiliary_va); + if let Some((relative_a, relative_b)) = pointers.relative_words { + for index in 0..11 { + self.word32(0x19e4 + index * 4, relative_a[index]); + self.word32(0x1a24 + index * 4, relative_b[index]); + } + } + Ok(()) + } + + fn word32(&mut self, offset: usize, value: u32) { + self.0[offset..offset + 4].copy_from_slice(&value.to_le_bytes()); + } + + fn word64(&mut self, offset: usize, value: u64) { + self.0[offset..offset + 8].copy_from_slice(&value.to_le_bytes()); + } +} + +pub(crate) struct AonSensor { + pub(crate) key: [u8; 4], + pub(crate) selector: u32, + pub(crate) config: u32, +} + +/// Nineteen 12-byte native sensor rows, with unused rows zeroed. +#[repr(C)] +pub(crate) struct AonTable(pub(crate) [[u32; 3]; 19]); + +// SAFETY: Integer arrays only. +unsafe impl Zeroable for AonTable {} + +static_assert!(size_of::() == 0xe4); + +impl AonTable { + pub(crate) fn init(&mut self, sensors: &[AonSensor]) -> Result { + if sensors.len() > 19 { + return Err(EINVAL); + } + super::clear(self); + for (index, sensor) in sensors.iter().enumerate() { + if sensor.key == [0; 4] || sensors[..index].iter().any(|row| row.key == sensor.key) { + return Err(EINVAL); + } + self.0[index] = [ + u32::from_be_bytes(sensor.key), + sensor.selector, + sensor.config, + ]; + } + Ok(()) + } +} diff --git a/drivers/gpu/drm/asahi/g17/fw/render.rs b/drivers/gpu/drm/asahi/g17/fw/render.rs index e44093ab16252..1482ac68f2beb 100644 --- a/drivers/gpu/drm/asahi/g17/fw/render.rs +++ b/drivers/gpu/drm/asahi/g17/fw/render.rs @@ -1753,30 +1753,33 @@ mod ta_mode_tests { } } - /// The variants of the builds T6041 admits: 25F84, then 25G83, which the 40- and the - /// 32-core configurations run with the same rules. - fn t6041_variants() -> [&'static Variant; 2] { + /// The variants of the builds T6041 admits: 25F84, then 25G83 and 26B123, each of which the + /// 40- and the 32-core configurations run with the same rules. + fn t6041_variants() -> [&'static Variant; 3] { let Firmware::Identified(builds) = crate::hw::t6041::CONFIG.firmware else { panic!("T6041 must identify its loaded firmware"); }; - assert_eq!(builds.len(), 3); - let (g83, g83_32) = (builds[1].variant, builds[2].variant); - assert_eq!(g83.ta_mode_1, g83_32.ta_mode_1); - assert_eq!(g83.compute, g83_32.compute); - assert_eq!(g83.programs, g83_32.programs); - [builds[0].variant, g83] + assert_eq!(builds.len(), 5); + for (full, cut) in [(1, 2), (3, 4)] { + let (full, cut) = (builds[full].variant, builds[cut].variant); + assert_eq!(full.ta_mode_1, cut.ta_mode_1); + assert_eq!(full.compute, cut.compute); + assert_eq!(full.programs, cut.programs); + } + [builds[0].variant, builds[1].variant, builds[3].variant] } /// The TA mode of every admitted T6041 build. fn t6041_ta_mode_1() -> bool { - let [f84, g83] = t6041_variants(); + let [f84, g83, b123] = t6041_variants(); assert_eq!(f84.ta_mode_1, g83.ta_mode_1); + assert_eq!(f84.ta_mode_1, b123.ta_mode_1); f84.ta_mode_1 } #[test] fn policy_is_local_to_the_admitted_t6041_builds() { - let [f84, g83] = t6041_variants(); + let [f84, g83, b123] = t6041_variants(); let pro = selected(&crate::hw::t6040::CONFIG.firmware); assert_eq!(f84.compute, crate::g17::fw::compute::ComputeProgram::V25F84); assert!(f84.split_firmware_area); @@ -1786,7 +1789,10 @@ mod ta_mode_tests { assert_eq!(g83.opening_record, pro.opening_record); assert_eq!(g83.qid_floor, pro.qid_floor); assert_eq!(g83.registration, pro.registration); - for max in [f84, g83] { + // 26B123 runs 25F84's compute program with one firmware area. + assert_eq!(b123.compute, f84.compute); + assert!(!b123.split_firmware_area); + for max in [f84, g83, b123] { assert_eq!(max.programs, RegisterPrograms::V25G83); assert!(max.ta_mode_1); } diff --git a/drivers/gpu/drm/asahi/g17/fw/variant.rs b/drivers/gpu/drm/asahi/g17/fw/variant.rs index 7c3ee790dc941..59e9a5382cf8c 100644 --- a/drivers/gpu/drm/asahi/g17/fw/variant.rs +++ b/drivers/gpu/drm/asahi/g17/fw/variant.rs @@ -87,6 +87,8 @@ pub(crate) struct Variant { pub(crate) compute: super::compute::ComputeProgram, pub(crate) opening_record: bool, pub(crate) split_firmware_area: bool, + /// Uses the 26B123 initialization layouts and scheduler-release opcode. + pub(crate) v26b123: bool, /// Command validation applies the M5 command set: resource commands, the M5 render and /// compute flags, 8x MSAA and the M5 tile-buffer limit. pub(crate) m5_commands: bool, @@ -157,6 +159,7 @@ pub(crate) const V26A428: Variant = Variant { compute: super::compute::ComputeProgram::G17P, opening_record: true, split_firmware_area: false, + v26b123: false, m5_commands: false, registration_power_hold: true, render_id_at_create: true, @@ -197,6 +200,7 @@ pub(crate) const V25G83: Variant = Variant { compute: super::compute::ComputeProgram::G17P, opening_record: true, split_firmware_area: false, + v26b123: false, m5_commands: false, registration_power_hold: true, render_id_at_create: false, @@ -225,8 +229,16 @@ pub(crate) const V25F84: Variant = Variant { ..V25G83 }; +/// The T6041 27.2 firmware (26B123, `mBoot-20457.41.3`). +pub(crate) const V26B123: Variant = Variant { + split_firmware_area: false, + v26b123: true, + ..V25F84 +}; + const _: () = { assert!(super::queue::PointerBlock::valid_layout(&V26A428.pointers)); assert!(super::queue::PointerBlock::valid_layout(&V25G83.pointers)); assert!(super::queue::PointerBlock::valid_layout(&V25F84.pointers)); + assert!(super::queue::PointerBlock::valid_layout(&V26B123.pointers)); }; diff --git a/drivers/gpu/drm/asahi/g17/initdata.rs b/drivers/gpu/drm/asahi/g17/initdata.rs index c505bbd5b3b45..45671b6181a93 100644 --- a/drivers/gpu/drm/asahi/g17/initdata.rs +++ b/drivers/gpu/drm/asahi/g17/initdata.rs @@ -17,6 +17,7 @@ use kernel::{c_str, prelude::*, sync::Arc}; use t8140::{kernel_window as high, low}; mod v25g83; +mod v26b123; mod m5; mod work_pair; pub(crate) mod outer_credit; @@ -172,6 +173,7 @@ impl WorkPublication<'_> { /// Session-long storage and mappings. Aliases are released before their backing objects. pub(super) struct InitData { m5: bool, + v26b123: bool, /// The M5 firmware build's layout, where [`Self::m5`]. graph: &'static super::fw::m5::initdata::Graph, outer_credits: Option>, @@ -186,6 +188,7 @@ pub(super) struct InitData { cluster: usize, bundle: usize, region_c: usize, + region_c_shift: usize, qos: usize, pb: usize, page_pool: usize, @@ -291,6 +294,7 @@ impl InitData { pub(super) fn new() -> Self { Self { m5: false, + v26b123: false, graph: &super::fw::m5::initdata::M5_GRAPH, outer_credits: None, _single_publisher: core::marker::PhantomData, @@ -301,6 +305,7 @@ impl InitData { cluster: 0, bundle: 0, region_c: 0, + region_c_shift: 0, qos: 0, pb: 0, page_pool: 0, @@ -477,7 +482,7 @@ impl InitData { /// A scheduler-state release record in the family's opcode. pub(super) fn scheduler_release(&self, page_va: u64, id: [u8; 4]) -> super::fw::channels::SchedulerStateRelease { let mut record = super::fw::channels::SchedulerStateRelease::new(page_va, id); - if self.m5 { + if self.m5 || self.v26b123 { record.opcode = super::fw::m5::queue::SCHEDULER_RELEASE_OPCODE; } record @@ -1171,6 +1176,7 @@ impl InitData { variant: &super::fw::Variant, ) -> Result { self.pm_metrics_va = cfg.pm_metrics()?.va; + self.v26b123 = variant.v26b123; self.recovery_slot_keys = cfg.recovery_slot_keys; let range = uat.geometry().kernel_range(); let env = BuildEnv { @@ -1679,7 +1685,12 @@ impl InitData { let region = self.object(self.region_c)?; let (effort_offset, override_offset) = if self.m5 { (super::fw::m5::power::EFFORT, super::fw::m5::power::EFFORT_OVERRIDE) - } else { (abi::RegionC::EFFORT, abi::RegionC::UNK_E8) }; + } else { + ( + abi::RegionC::EFFORT + self.region_c_shift, + abi::RegionC::UNK_E8 + self.region_c_shift, + ) + }; let override_word = region.word(override_offset)?; let effort_word = region.word(effort_offset)?; let line = region.pointer(effort_offset, 4)?; @@ -1697,7 +1708,11 @@ impl InitData { pub(super) fn effort(&self) -> Result { Ok(self .object(self.region_c)? - .word(if self.m5 { super::fw::m5::power::EFFORT } else { abi::RegionC::EFFORT })? + .word(if self.m5 { + super::fw::m5::power::EFFORT + } else { + abi::RegionC::EFFORT + self.region_c_shift + })? .load(Ordering::Relaxed)) } @@ -1876,8 +1891,11 @@ impl InitData { let ring = self.object(self.bundle)?.pointer(offset, record.len())?; let power = self .object(self.region_c)? - .pointer(if self.m5 { self.graph.power_assert_tally } - else { abi::RegionC::POWER_ASSERT_TALLY }, 4)?; + .pointer(if self.m5 { + self.graph.power_assert_tally + } else { + abi::RegionC::POWER_ASSERT_TALLY + self.region_c_shift + }, 4)?; let producer = self.control_producer()?; // SAFETY: The checked pointers remain valid for the lifetime of this non-Sync owner. // Firmware only reads records after the producer store and the device mutex serializes diff --git a/drivers/gpu/drm/asahi/g17/initdata/v25g83.rs b/drivers/gpu/drm/asahi/g17/initdata/v25g83.rs index c0485c4932e48..26b87dc1826b5 100644 --- a/drivers/gpu/drm/asahi/g17/initdata/v25g83.rs +++ b/drivers/gpu/drm/asahi/g17/initdata/v25g83.rs @@ -44,6 +44,18 @@ impl InitData { let objects = self.build_25g83_objects(env, variant.split_firmware_area)?; self.views = Some(objects.views); self.initialize_25g83(env, cfg, active_cores, &tables, &bundle, &objects, variant)?; + if variant.v26b123 { + self.upgrade_26b123( + env, + cfg, + active_cores, + &bundle, + objects.aon, + objects.power_state, + objects.firmware_area, + objects.views, + )?; + } if cfg.uat_quirks.clean_tables { // Write back every host-built byte before the firmware may read it. for object in self.objects.iter_mut() { diff --git a/drivers/gpu/drm/asahi/g17/initdata/v26b123.rs b/drivers/gpu/drm/asahi/g17/initdata/v26b123.rs new file mode 100644 index 0000000000000..955ccccd9f159 --- /dev/null +++ b/drivers/gpu/drm/asahi/g17/initdata/v26b123.rs @@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! T6041 26B123 initialization graph. Legacy constructors supply common values +//! in unpublished storage; the 26B123 views are built into distinct allocations +//! before the root is published, and the session retains every allocation until +//! ASC stop. + +use super::{abi, low, BuildEnv, BundleObjects, CpuMap, InitData}; +use crate::{ + g17::{Config, Role}, + mmu, +}; +use abi::{v25g83 as old, v26b123 as v}; +use core::sync::atomic::Ordering; +use kernel::prelude::*; + +// Relative-performance calibration observed on native 40-core T6041 26B123 boots. +const RELATIVE_A: [u32; 11] = [ + 0, 0x41219d11, 0x4194a46c, 0x41cd5835, 0x41f9b2d3, 0x42220d2d, 0x424ab13c, 0x4279cf40, + 0x428cb17b, 0x429da759, 0x42c80000, +]; +const RELATIVE_B: [u32; 11] = [ + 0, 0, 0x41b4a529, 0x4213bdf0, 0x423d0842, 0x42679ce6, 0x42882108, 0x429d18c6, 0x42a81085, + 0x42b694a5, 0x42c80000, +]; + +impl InitData { + #[expect(clippy::too_many_arguments, reason = "Explicit retained graph objects")] + pub(super) fn upgrade_26b123( + &mut self, + env: &BuildEnv<'_>, + cfg: &Config, + active_cores: u32, + bundle: &BundleObjects, + aon: usize, + power_state: usize, + firmware_area: usize, + views: [usize; 5], + ) -> Result { + use mmu::PROT_FW_PRIV_RW as FP; + use mmu::PROT_FW_SHARED_RW as FS; + use CpuMap::WriteCombined as WC; + + // Both 32-core and 40-core T6041 parts have four GPU clusters (g0TR..g3TR); + // core counts, AMCC windows, OPPs, and power limits come from `cfg` via + // `initialize_25g83()` and `Gpu::new()`'s core-layout check. + if cfg.chip_id != crate::hw::t6041::CHIP_ID || env.clusters != 4 { + return Err(EINVAL); + } + let chip = cfg.chip.ok_or(EINVAL)?; + let bundle_va = self.object(self.bundle)?.gpu_va(); + let cluster_va = self.object(self.cluster)?.gpu_va(); + let config_va = cluster_va + old::private::CONFIG as u64; + let aon_va = self.object(aon)?.gpu_va(); + // The existing register window already maps the complete GPTBAT span + // with firmware MMIO permissions; reuse its first 0x8000 bytes. + let gptbat = cfg + .windows + .iter() + .find(|window| window.phys == v::GPTBAT_PHYS && window.size >= v::GPTBAT_SIZE) + .ok_or(EINVAL)?; + let auxiliary = self.add(env.dynamic(mmu::UAT_PGSZ, mmu::UAT_PGSZ as u64, FP, WC)?)?; + let hardware = self.add(env.dynamic(mmu::UAT_PGSZ, mmu::UAT_PGSZ as u64, FP, WC)?)?; + let power = self.add(env.dynamic(0x8000, mmu::UAT_PGSZ as u64, FP, WC)?)?; + let region = self.add(env.dynamic(mmu::UAT_PGSZ, mmu::UAT_PGSZ as u64, FS, WC)?)?; + + // SAFETY: RegisterTable consists of initialized integer descriptors only. + let mut registers: v::RegisterTable = unsafe { core::mem::zeroed() }; + registers.init(cfg.windows)?; + let args = v::HardwareArgs { + gptbat_va: gptbat.va, + gptbat_size: v::GPTBAT_SIZE, + completion_low: bundle.completion_rings.map(|ring| ring.low_va), + completion_high: bundle.completion_rings.map(|ring| ring.high_va), + qos_va: self.object(bundle.qos)?.gpu_va(), + auxiliary_va: self.object(auxiliary)?.gpu_va(), + relative_words: (active_cores == 40).then_some((RELATIVE_A, RELATIVE_B)), + }; + let legacy_hw = self + .object(self.bundle)? + .pointer(0, size_of::())? + .cast::(); + self.object_mut(hardware)? + .initialize::(0, |hw| { + // SAFETY: This checked, initialized legacy view remains in a distinct + // retained allocation. No graph has been published to the firmware. + hw.init(unsafe { &*legacy_hw }, ®isters, &args) + })?; + let startup_word = self + .object(self.bundle)? + .word(old::POWER_CONFIG + 0x63d4)? + .load(Ordering::Relaxed); + let legacy_power = self + .object(self.bundle)? + .pointer(old::POWER_CONFIG, size_of::())? + .cast::(); + self.object_mut(power)? + .initialize::(0, |power| { + // SAFETY: The initialized legacy power view is in the distinct bundle. + power.init( + unsafe { &*legacy_power }, + &v::PowerArgs { + config_va, + aon_va, + startup_word, + }, + ) + })?; + let legacy_region = self + .object(self.region_c)? + .pointer(0, size_of::())? + .cast::(); + self.object_mut(region)? + .initialize::(0, |region| { + // SAFETY: The old region remains retained and is distinct from `region`. + region.init(unsafe { &*legacy_region }); + Ok(()) + })?; + self.region_c = region; + self.region_c_shift = 4; + self.object_mut(power_state)? + .initialize::(0, |state| { + state.init(chip.max_power_mw); + Ok(()) + })?; + self.object_mut(aon)? + .initialize::(0, |table| { + table.init(&[ + v::AonSensor { + key: *b"g0TR", + selector: 0x00c20001, + config: 0x1401, + }, + v::AonSensor { + key: *b"g1TR", + selector: 0x00970001, + config: 0x1401, + }, + v::AonSensor { + key: *b"g2TR", + selector: 0x00920001, + config: 0x1401, + }, + v::AonSensor { + key: *b"g3TR", + selector: 0x00c70001, + config: 0x1401, + }, + v::AonSensor { + key: *b"r0TR", + selector: 0x012c0001, + config: 0x1401, + }, + ]) + })?; + + let main_offset = abi::bundle::MAIN_CONFIG[Role::Primary as usize]; + let main_va = bundle_va + main_offset as u64; + let common = abi::MainConfigArgs { + bundle_va: self.object(hardware)?.gpu_va(), + main_config_va: main_va, + state_grid_va: cluster_va + self.state_offset(Role::Primary) as u64, + status_a_va: cluster_va + old::private::STATUS_A as u64, + pb_descriptors_low_va: low::PB_DESCRIPTORS, + page_pool_descriptors_low_va: low::PAGE_POOL_DESCRIPTORS, + }; + // Preserve the already constructed host-owned descriptor addresses. + let old_main = self + .object(self.bundle)? + .pointer(main_offset, size_of::())? + .cast::(); + // SAFETY: The bundle view is initialized and not yet published. Copy only + // integer values before initialize clears that same view below. + let primary_views = unsafe { + abi::PrimaryViews { + zero_page_va: (*old_main).zero_page_va, + pb_descriptors_va: (*old_main).pb_descriptors_va, + page_pool_descriptors_va: (*old_main).page_pool_descriptors_va, + } + }; + let mut view_va = [0; 5]; + for (va, index) in view_va.iter_mut().zip(views) { + *va = self.object(index)?.gpu_va(); + } + let firmware_area_va = self.object(firmware_area)?.gpu_va(); + let main_args = v::MainArgs { + common: &common, + primary_views: &primary_views, + view_va, + firmware_area_va: [firmware_area_va; 2], + work_rings_va: bundle_va + abi::bundle::WORK_RINGS as u64, + power_config_va: self.object(power)?.gpu_va(), + }; + self.object_mut(self.bundle)? + .initialize::(main_offset, |main| main.init_merged(&main_args))?; + let root = abi::RootArgs { + region_a_va: self.object(bundle.region_a)?.gpu_va(), + region_c_va: self.object(self.region_c)?.gpu_va(), + main_config_va: main_va, + status_a_va: common.status_a_va, + ias: cfg.uat_ias, + oas: cfg.uat_oas, + }; + let merged = v::merged_root( + &root, + cluster_va + old::private::STATUS_B as u64, + self.object(power_state)?.gpu_va(), + config_va, + ); + self.object_mut(self.roots)?.write(0, merged)?; + Ok(()) + } +} diff --git a/drivers/gpu/drm/asahi/hw/t6041.rs b/drivers/gpu/drm/asahi/hw/t6041.rs index 5dc8020b89f49..faf60992e14d4 100644 --- a/drivers/gpu/drm/asahi/hw/t6041.rs +++ b/drivers/gpu/drm/asahi/hw/t6041.rs @@ -63,16 +63,16 @@ pub(super) const BASE: Config = Config { }, }; -/// The 40-core M4 Max. 25F84 runs this configuration; 25G83 runs [`CONFIG_25G83`], or -/// [`super::t6041_25g83::CONFIG`] on a 32-core part. +/// The 40-core M4 Max. 25F84 runs this configuration; 25G83 runs [`CONFIG_25G83`], 26B123 runs +/// [`BASE`], and a 32-core part runs [`super::t6041_25g83::CONFIG`] on both 25G83 and 26B123. pub(crate) const CONFIG: Config = Config { firmware: fw::variant::Firmware::Identified(&BUILDS), ..BASE }; -/// The 25G83 image is admitted twice, with the configuration of each measured core layout; +/// The 25G83 and 26B123 images are admitted twice, with the configuration of each core layout; /// the one that matches the probed cores is used. -const BUILDS: [fw::variant::Build; 3] = [ +const BUILDS: [fw::variant::Build; 5] = [ BUILD_25F84, fw::variant::Build { config: Some(&CONFIG_25G83), @@ -83,8 +83,39 @@ const BUILDS: [fw::variant::Build; 3] = [ config: Some(&super::t6041_25g83::CONFIG), ..BUILD_25G83 }, + fw::variant::Build { + config: Some(&BASE), + ..BUILD_26B123 + }, + fw::variant::Build { + name: "macOS 27.2 (26B123, iBoot mBoot-20457.41.3), 32 cores", + config: Some(&super::t6041_25g83::CONFIG), + ..BUILD_26B123 + }, ]; +pub(super) const BUILD_26B123: fw::variant::Build = fw::variant::Build { + os_version: [27, 2, 0], + name: "macOS 27.2 (26B123, iBoot mBoot-20457.41.3)", + images: &[crate::fwid::FirmwareBuild { + name: "Apple GFX 26B123 for T6041 (normalized loaded image)", + text_size: 0x64000, + data_size: 0xcc000, + entropy: &[[0x5d88c, 0x5d96f]], + boot_filled: &[], + text_sha256: [ + 0xcc, 0x4c, 0xb8, 0x28, 0x54, 0x6d, 0x5e, 0xc6, 0x39, 0xfa, 0x14, 0xc1, 0xcc, 0x6c, + 0xef, 0xc7, 0x27, 0x40, 0x40, 0xfd, 0xbd, 0x5c, 0xb5, 0xa6, 0xec, 0xc4, 0x38, 0xb0, + 0x3c, 0x84, 0x90, 0x3b, + ], + }], + variant: &fw::variant::Variant { + ta_mode_1: true, + ..fw::variant::V26B123 + }, + config: None, +}; + const BUILD_25F84: fw::variant::Build = fw::variant::Build { os_version: [26, 5, 2], name: "macOS 26.5.2 (25F84, iBoot mBoot-18000.121.3)", diff --git a/drivers/gpu/drm/asahi/hw/t6041_25g83.rs b/drivers/gpu/drm/asahi/hw/t6041_25g83.rs index e23b419364a78..955e45e14d2c3 100644 --- a/drivers/gpu/drm/asahi/hw/t6041_25g83.rs +++ b/drivers/gpu/drm/asahi/hw/t6041_25g83.rs @@ -47,7 +47,7 @@ pub(super) const CONFIG: Config = Config { perf: Some(&PERF), region_c: Some(®ION_C), chip: Some(&CHIP), - firmware: fw::variant::Firmware::Identified(&[t6041::BUILD_25G83]), + firmware: fw::variant::Firmware::Identified(&[t6041::BUILD_25G83, t6041::BUILD_26B123]), core_layout: CoreLayout { cores: Some((4, 32)), alternate_core_masks: None, diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index 3df2214e6db63..d60cb51223fb9 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -1884,6 +1884,9 @@ impl AopData { } else { bootargs.copy_to_slice(&mut bytes); } + let ed0p_key = from_fourcc(b"ED0p"); + let need_ed0p = patches.iter().any(|&(k, v)| k == ed0p_key && v.is_some()); + let mut seen_ed0p = false; let first = offset - start; let arg_bytes = &mut bytes[first..first + size]; let mut idx = 0; @@ -1901,10 +1904,17 @@ impl AopData { if *k != key { continue; } - // `None` keeps the value the firmware image carries. + // `None` keeps the value the firmware image carries (including + // an unused `ED0p` entry on firmware without `__EDATA`). let Some(v) = v else { break; }; + if key == ed0p_key { + if seen_ed0p || len != mem::size_of::() { + return Err(EINVAL); + } + seen_ed0p = true; + } if len > mem::size_of::() { return Err(EINVAL); } @@ -1913,6 +1923,9 @@ impl AopData { } idx += len; } + if need_ed0p && !seen_ed0p { + return Err(EINVAL); + } if word_access { for (i, chunk) in bytes.chunks_exact(4).enumerate() { let address = start + i * 4; @@ -2029,9 +2042,12 @@ impl AopData { /// IOMMU core maps them in the default domain when the device is added /// (one to one when the IOVA is the physical address, translated /// otherwise), so they are only checked here. Every page has to be mapped - /// where the DT says, the external code (`__ETEXT`) at `ec0p` and any - /// other segment (`__OS_LOG`) at its physical address. - fn check_fw_regions(dev: &device::Device, ec0p: u64) -> Result<()> { + /// where the DT says, with the external code (`__ETEXT`) at `ec0p`. + /// Other segments may also use translated IOVAs: macOS 27 firmware adds + /// `__EDATA` after the external code, while `__OS_LOG` remains + /// identity-mapped. Returns the unique additional translated region for + /// `ED0p`, if any, requiring it to follow and not overlap `__ETEXT`. + fn check_fw_regions(dev: &device::Device, ec0p: u64) -> Result> { // SAFETY: `dev` is a live device being probed. let np = unsafe { (*dev.as_raw()).of_node }; if np.is_null() { @@ -2056,11 +2072,14 @@ impl AopData { return Err(ENODEV); } let mut etext = false; + let mut etext_end = 0; + let mut external_data = None; for idx in 0..count { let (phys, iova, size) = Self::fw_region(np, idx).inspect_err(|e| { dev_err!(dev, "Invalid firmware memory-region {} ({:?})", idx, e); })?; if phys % FW_REGION_PAGE != 0 + || size == 0 || size % FW_REGION_PAGE != 0 || size > FW_REGION_MAX_SIZE || iova % FW_REGION_PAGE != 0 @@ -2076,14 +2095,9 @@ impl AopData { return Err(EINVAL); } etext = true; - } else if iova != phys { - dev_err!( - dev, - "Firmware memory-region {} at IOVA {:#x}, neither EC0p {:#x} nor its physical address", - idx, - iova, - ec0p - ); + etext_end = iova + size; + } else if iova != phys && external_data.replace((iova, size)).is_some() { + dev_err!(dev, "Multiple translated external data regions"); return Err(EINVAL); } let mut off = 0; @@ -2107,7 +2121,22 @@ impl AopData { dev_err!(dev, "No firmware memory-region at EC0p {:#x}", ec0p); return Err(ENOENT); } - Ok(()) + if let Some((iova, size)) = external_data { + if iova < etext_end { + dev_err!( + dev, + "External data region precedes or overlaps the external code" + ); + return Err(EINVAL); + } + dev_info!( + dev, + "Validated external data region at IOVA {:#x}, size {:#x}", + iova, + size + ); + } + Ok(external_data) } /// Leaks every allocation the firmware may still access. Called when the @@ -3174,10 +3203,12 @@ impl platform::Driver for AopDriver { let asc_req = pdev.io_request_by_index(1).ok_or(EINVAL)?; let asc_mmio = asc_req.iomap_sized::()?; let asc_mmio = asc_mmio.as_view().relaxed(); - if cfg.fw_regions { + let ed0p = if cfg.fw_regions { // Before anything is written to the AOP: no mapping, no start. - AopData::check_fw_regions(pdev.as_ref(), cfg.ec0p)?; - } + AopData::check_fw_regions(pdev.as_ref(), cfg.ec0p)?.map(|(iova, _)| iova) + } else { + None + }; let data = AopData::new(pdev, cfg)?; // Whatever fails below leaves the AOP running and its children // registering; the same teardown as unbind's cleans that up. @@ -3188,6 +3219,7 @@ impl platform::Driver for AopDriver { &aop_mmio, &[ (from_fourcc(b"EC0p"), Some(cfg.ec0p)), + (from_fourcc(b"ED0p"), ed0p), (from_fourcc(b"nCal"), cfg.ncal), (from_fourcc(b"alig"), Some(cfg.alig)), (from_fourcc(b"AOPt"), Some(cfg.aopt)), diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index 3b0b162ed6799..cb83809720eb0 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -1233,6 +1233,59 @@ static void __init gate_t6041_max_no_display(struct kunit *test) KUNIT_EXPECT_EQ(test, of_count_phandle_with_args(display, "iommus", "#iommu-cells"), 1); } +static void __init gt_max_set_dcp_fw(struct kunit *test, const char *path, + const char *uuid, const u32 compat[3]) +{ + struct device_node *np = gt_node(test, path); + struct gate_test *t = test->priv; + + KUNIT_ASSERT_EQ(test, + of_changeset_add_prop_string(&t->cs, np, "apple,firmware-uuid", uuid), + 0); + KUNIT_ASSERT_EQ(test, + of_changeset_add_prop_u32_array(&t->cs, np, "apple,firmware-version", + compat, 3), + 0); + KUNIT_ASSERT_EQ(test, + of_changeset_add_prop_u32_array(&t->cs, np, "apple,firmware-compat", + compat, 3), + 0); +} + +/* Unapproved firmware 27 adopts only the internal panel: external chains stay off. */ +static void __init gate_t6041_max_firmware27_internal_only(struct kunit *test) +{ + static const u32 compat[3] = { 27, 2, 0 }; + + gt_max_fill(test, 0); + gt_max_fill(test, 1); + gt_max_set_dcp_fw(test, "/dcp@402e00000", + "71F140DC-F18D-31B3-9772-537A5CC8400D", compat); + gt_max_run(test); + gt_max_expect_chain(test, 0, false); + gt_max_expect_chain(test, 1, false); + gt_max_expect_display(test, 0); +} + +/* Headless T6041 (e.g. J575c) also checks each external DCP's firmware-27 UUID. */ +static void __init gate_t6041_max_v27_2(struct kunit *test) +{ + static const u32 compat[3] = { 27, 2, 0 }; + + gt_max_fill(test, 0); + gt_max_fill(test, 1); + gt_max_fill(test, 2); + gt_max_set_dcp_fw(test, "/dcp@402e00000", APPLE_T6041_DCP_26B123_UUID, compat); + gt_max_set_dcp_fw(test, "/dcp@602e00000", APPLE_T6041_DCP_26B123_UUID, compat); + gt_max_set_dcp_fw(test, "/dcp@606e00000", + "71F140DC-F18D-31B3-9772-537A5CC8400D", compat); + gt_max_run(test); + gt_max_expect_chain(test, 0, true); + gt_max_expect_chain(test, 1, true); + gt_max_expect_chain(test, 2, false); + gt_max_expect_display(test, BIT(0) | BIT(1)); +} + static struct kunit_case gate_t6041_max_cases[] __refdata = { KUNIT_CASE(gate_t6041_max_enabled), KUNIT_CASE(gate_t6041_max_no_memory), @@ -1242,6 +1295,8 @@ static struct kunit_case gate_t6041_max_cases[] __refdata = { KUNIT_CASE(gate_t6041_max_enabled_by_loader), KUNIT_CASE(gate_t6041_max_missing_node), KUNIT_CASE(gate_t6041_max_no_display), + KUNIT_CASE(gate_t6041_max_firmware27_internal_only), + KUNIT_CASE(gate_t6041_max_v27_2), {} }; diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 03db5ed73e343..6b7ba7525fdf2 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -108,6 +108,7 @@ #include #include #include +#include #include #include #include @@ -2139,10 +2140,14 @@ static void __init gate_t6041_internal(void) !gate_marked(nodes[T6041_PIODMA])) goto out; - /* The desktop IOMFB instance is written for the 26.6.2 firmware only. */ - if (of_property_count_u32_elems(nodes[T6041_DCP], "apple,firmware-compat") != 3 || - of_property_read_u32_array(nodes[T6041_DCP], "apple,firmware-compat", version, 3) || - version[0] != 26 || version[1] != 6 || version[2] != 2) + /* + * The desktop IOMFB instance is written for the 26.6.2 firmware; the + * pinned 27.2 (26B123) T6041 DCP image uses the firmware-27 backend. + */ + if (!apple_t6041_dcp_v27_2(nodes[T6041_DCP]) && + (of_property_count_u32_elems(nodes[T6041_DCP], "apple,firmware-compat") != 3 || + of_property_read_u32_array(nodes[T6041_DCP], "apple,firmware-compat", version, 3) || + version[0] != 26 || version[1] != 6 || version[2] != 2)) goto out; nodes[T6041_DCP_DART] = gate_target(nodes[T6041_DCP], "iommus", "#iommu-cells", @@ -2180,6 +2185,9 @@ static void __init gate_t6041_internal(void) for (i = 0; i < ARRAY_SIZE(t6041_enable) && !ret; i++) ret = of_changeset_update_prop_string(&t6041_gate, nodes[t6041_enable[i]], "status", "okay"); + if (!ret && gate_disabled(nodes[T6041_PIODMA])) + ret = of_changeset_update_prop_string(&t6041_gate, nodes[T6041_PIODMA], + "status", "okay"); if (!ret) ret = of_changeset_apply(&t6041_gate); if (ret) @@ -3237,6 +3245,23 @@ static int __init t6041_max_apply(unsigned int i, struct device_node *display) return ret; } +static bool __init gate_t6041_v27_unapproved(const struct device_node *np, + bool external) +{ + u32 compat[3]; + + if (!np || + of_property_count_u32_elems(np, "apple,firmware-compat") != + ARRAY_SIZE(compat) || + of_property_read_u32_array(np, "apple,firmware-compat", + compat, ARRAY_SIZE(compat)) || + compat[0] != 27) + return false; + + return external ? !apple_t6041_dcpext_v27_2(np) : + !apple_t6041_dcp_v27_2(np); +} + /* * The internal display first, as on the M4 Pro: an accepted handoff enables * the display subsystem with the DCP. Then each external chain is enabled in @@ -3248,7 +3273,7 @@ static int __init t6041_max_apply(unsigned int i, struct device_node *display) */ static void __init gate_t6041_max_run(void) { - struct device_node *display; + struct device_node *display, *internal; unsigned int i; int ret; @@ -3267,12 +3292,35 @@ static void __init gate_t6041_max_run(void) of_node_put(display); return; } + /* + * T6041 external display processors support the desktop 26.x firmware + * and the pinned 27.2 (26B123) firmware-27 image; leave external chains + * disabled on any unapproved firmware-27 build. + */ + internal = of_find_node_by_path("dcp"); + if (!internal) + internal = of_find_compatible_node(NULL, NULL, gate_soc->dcp_compat); + if (gate_t6041_v27_unapproved(internal, false)) { + staged_info("firmware 27 internal display only, external displays left off\n"); + of_node_put(internal); + of_node_put(display); + return; + } + of_node_put(internal); for (i = 0; i < ARRAY_SIZE(t6041_max_stages); i++) { const struct gate_staged *st = t6041_max_stage(i); const char *dcp = st->nodes[st->nr - 1]; + struct device_node *ext; if (!staged_ready(st)) continue; + ext = of_find_node_by_path(dcp); + if (gate_t6041_v27_unapproved(ext, true)) { + staged_info("%s: unapproved firmware 27, chain left off\n", dcp); + of_node_put(ext); + continue; + } + of_node_put(ext); ret = t6041_max_apply(i, display); if (ret) staged_err("%s: could not enable the chain: %d\n", dcp, ret); diff --git a/drivers/soc/apple/t6041-gate-test.dtso b/drivers/soc/apple/t6041-gate-test.dtso index e77e3415199a3..094b4d10fecb8 100644 --- a/drivers/soc/apple/t6041-gate-test.dtso +++ b/drivers/soc/apple/t6041-gate-test.dtso @@ -228,6 +228,11 @@ #iommu-cells = <1>; }; + dcp@402e00000 { + compatible = "apple,t6041-dcp"; + status = "disabled"; + }; + display-subsystem { compatible = "apple,display-subsystem"; iommus = <&disp_dart 0>; diff --git a/include/linux/soc/apple/display.h b/include/linux/soc/apple/display.h index 1bf7c14f62178..2d7522f2cac10 100644 --- a/include/linux/soc/apple/display.h +++ b/include/linux/soc/apple/display.h @@ -2,6 +2,10 @@ #ifndef _LINUX_SOC_APPLE_DISPLAY_H_ #define _LINUX_SOC_APPLE_DISPLAY_H_ +#include +#include +#include + struct device; /* Initial native display admission, before starting retained GPU firmware. */ @@ -9,4 +13,37 @@ int apple_drm_t6030_link_device(struct device *consumer); int apple_drm_t6031_link_device(struct device *consumer); int apple_drm_t8132_link_device(struct device *consumer); +/* T6041 DCP image shipped with macOS 27.2 (26B123). */ +#define APPLE_T6041_DCP_26B123_UUID "964EDE5B-8F78-38C2-A727-519CC9F0AF27" + +static inline bool apple_t6041_dcp_any_v27_2(const struct device_node *np, + const char *compat_name) +{ + const char *uuid; + u32 fw[3], compat[3]; + + if (!np || !of_device_is_compatible(np, compat_name) || + of_property_count_strings(np, "apple,firmware-uuid") != 1 || + of_property_read_string(np, "apple,firmware-uuid", &uuid) || + strcmp(uuid, APPLE_T6041_DCP_26B123_UUID) || + of_property_count_u32_elems(np, "apple,firmware-version") != 3 || + of_property_count_u32_elems(np, "apple,firmware-compat") != 3 || + of_property_read_u32_array(np, "apple,firmware-version", fw, 3) || + of_property_read_u32_array(np, "apple,firmware-compat", compat, 3)) + return false; + + return fw[0] == 27 && fw[1] == 2 && fw[2] == 0 && + compat[0] == 27 && compat[1] == 2 && compat[2] == 0; +} + +static inline bool apple_t6041_dcp_v27_2(const struct device_node *np) +{ + return apple_t6041_dcp_any_v27_2(np, "apple,t6041-dcp"); +} + +static inline bool apple_t6041_dcpext_v27_2(const struct device_node *np) +{ + return apple_t6041_dcp_any_v27_2(np, "apple,t6041-dcpext"); +} + #endif diff --git a/tools/asahi/aop-bootargs-tests.py b/tools/asahi/aop-bootargs-tests.py index fd2920a7a3353..699390faad348 100644 --- a/tools/asahi/aop-bootargs-tests.py +++ b/tools/asahi/aop-bootargs-tests.py @@ -73,7 +73,34 @@ let got=u32::from_le_bytes(d.bytes.borrow()[40..44].try_into().unwrap()); let wanted=want.unwrap_or_else(||cfg.ncal.unwrap() as u32);assert_eq!(got,wanted,"{} nCal written",name); } - println!("PASS aligned/unaligned byte and word access, unchanged writes, malformed tables, bounds, failed readback, None keeps the firmware value, per-SoC nCal"); + // ED0p: writes 8-byte IOVA when an external data region is present, preserves unused ED0p when None, + // and rejects missing, duplicate, or non-8-byte ED0p entries without writing MMIO. + let ed0p=from_fourcc(b"ED0p"); + let ec0p=from_fourcc(b"EC0p"); + let ed0p_iova=0x1000_0020_000u64; + let mut t27=[0u8;32]; + t27[0..4].copy_from_slice(&ec0p.to_le_bytes());t27[4..8].copy_from_slice(&8u32.to_le_bytes()); + t27[16..20].copy_from_slice(&ed0p.to_le_bytes());t27[20..24].copy_from_slice(&8u32.to_le_bytes()); + t27[24..32].copy_from_slice(&0xdead_beef_cafe_babeu64.to_le_bytes()); + let d=fixture(32,&t27); + assert_eq!(patch_with(&d,&[(ec0p,Some(0x1000_0000_000)),(ed0p,Some(ed0p_iova))]),Ok(())); + assert_eq!(u64::from_le_bytes(d.bytes.borrow()[32+24..32+32].try_into().unwrap()),ed0p_iova,"ED0p not written"); + let d=fixture(32,&t27); + assert_eq!(patch_with(&d,&[(ec0p,Some(0x1000_0000_000)),(ed0p,None)]),Ok(())); + assert_eq!(u64::from_le_bytes(d.bytes.borrow()[32+24..32+32].try_into().unwrap()),0xdead_beef_cafe_babeu64,"unused ED0p overwritten"); + let d=fixture(32,&t27[..16]); + assert_eq!(patch_with(&d,&[(ec0p,Some(0x1000_0000_000)),(ed0p,Some(ed0p_iova))]),Err(EINVAL),"missing ED0p accepted"); + assert!(d.writes.borrow().is_empty()); + let mut dup=[0u8;32]; + dup[0..16].copy_from_slice(&t27[16..32]);dup[16..32].copy_from_slice(&t27[16..32]); + let d=fixture(32,&dup); + assert_eq!(patch_with(&d,&[(ed0p,Some(ed0p_iova))]),Err(EINVAL),"duplicate ED0p accepted"); + assert!(d.writes.borrow().is_empty()); + let mut short=t27;short[20..24].copy_from_slice(&4u32.to_le_bytes()); + let d=fixture(32,&short[..28]); + assert_eq!(patch_with(&d,&[(ec0p,Some(0x1000_0000_000)),(ed0p,Some(ed0p_iova))]),Err(EINVAL),"4-byte ED0p accepted"); + assert!(d.writes.borrow().is_empty()); + println!("PASS aligned/unaligned byte and word access, unchanged writes, malformed tables, bounds, failed readback, None keeps the firmware value, per-SoC nCal, ED0p external data"); } ''' @@ -148,6 +175,11 @@ def main(): result = compile_run(rustc, p, binary, bad) assert result.returncode != 0 and 'None overwrote the firmware value' in result.stderr, result.stderr print('PASS negative control: None written as 0') + bad = code.replace('if need_ed0p && !seen_ed0p {', 'if need_ed0p && false {') + assert bad != code + result = compile_run(rustc, p, binary, bad) + assert result.returncode != 0 and 'missing ED0p accepted' in result.stderr, result.stderr + print('PASS negative control: missing ED0p ignored') for soc, val in (('T8112', 'Some(0)'), ('T6040', 'Some(0)'), ('T6000', 'Some(1)')): start = code.index('const HW_CFG_%s: AopHwConfig' % soc) at = code.index(' ncal: ', start) diff --git a/tools/asahi/dcpext26-crossbar-union-tests.py b/tools/asahi/dcpext26-crossbar-union-tests.py index 2edbcc37a4489..9607ad8ee202e 100644 --- a/tools/asahi/dcpext26-crossbar-union-tests.py +++ b/tools/asahi/dcpext26-crossbar-union-tests.py @@ -57,7 +57,7 @@ def function(text, name): struct device *dev; struct apple_dcp_typec_route *active_typec_route; struct mux_control *fixed_xbar, *direct_xbar_up; - bool fixed_route_selected; + bool fixed_route_selected, desktop_external; }; static const char *machine; static unsigned links, v27, locks; @@ -120,10 +120,13 @@ def function(text, name): d.fixed_route_selected = false; d.direct_xbar_up = NULL; reset(); assert(dcp_direct_crossbar_link(&d, true) == 0 && links == 0); - /* The V27 PHY helper precedes every family admission/lock. */ + /* The V27 PHY helper precedes every family admission/lock except T6041 dcpext. */ d.fw_compat = DCP_FIRMWARE_V_27_0; reset(); assert(dcp_direct_crossbar_link(&d, true) == 37); assert(v27 == 1 && links == 0 && locks == 0); + d.desktop_external = true; d.active_typec_route = &route; + reset(); assert(dcp_direct_crossbar_link(&d, true) == 0); + assert(v27 == 0 && links == 1 && locks == 1); } machine = "apple,other"; node.compatible = "apple,other-dcp"; struct apple_dcp unrelated = { .dev = &dev, .active_typec_route = &route }; @@ -134,6 +137,7 @@ def function(text, name): } ''' unit = pre + function(header, 'dcp_is_ext26') + '\n' +unit += function(source, 'dcp_t6041_ext_v27') + '\n' unit += function(source, 'dcp_is_t8132_ext') + '\n' + link + '\n' + cases with tempfile.TemporaryDirectory() as tmp: c = Path(tmp) / 'crossbar.c' diff --git a/tools/asahi/t6040-calibration-tests.py b/tools/asahi/t6040-calibration-tests.py index d802013175b97..5f2e3a0a0511d 100644 --- a/tools/asahi/t6040-calibration-tests.py +++ b/tools/asahi/t6040-calibration-tests.py @@ -170,6 +170,7 @@ def main(): for source, target in [ ("g17/fw/initdata.rs", "initdata.rs"), ("g17/fw/initdata/v25g83.rs", "initdata/v25g83.rs"), + ("g17/fw/initdata/v26b123.rs", "initdata/v26b123.rs"), ]: text = (DRIVER / source).read_text() (root / target).write_text(text.replace("use kernel::prelude::*;", "use crate::prelude::*;")) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index e634c2f04effd..1154c16541893 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -187,3 +187,194 @@ def syslog(root): return 0; } ''' + + +def t6041_v27_admission(root): + display_h = (root / 'include/linux/soc/apple/display.h').read_text() + helper = display_h[display_h.index('#define APPLE_T6041_DCP_26B123_UUID'): + display_h.index('\n#endif')] + iomfb_h = (root / 'drivers/gpu/drm/apple/iomfb.h').read_text() + methods_decl = iomfb_h[iomfb_h.index('enum dcpep_method {'): + iomfb_h.index('#define IOMFB_MAX_CB')] + v27_c = (root / 'drivers/gpu/drm/apple/iomfb_v27.c').read_text() + v27_tables = v27_c[v27_c.index('static const struct dcp_method_entry dcp_methods_27_0'): + v27_c.index('/* The template\'s calls resolve through')] + dcp_c = (root / 'drivers/gpu/drm/apple/dcp.c').read_text() + selector_full = block(dcp_c, 'static enum dcp_firmware_version dcp_check_firmware_version(') + cutoff = '\n\tret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str);\n\tif (ret < 0)' + selector = selector_full[:selector_full.index(cutoff)] + '\n\t(void)v14_board;\n\treturn DCP_FIRMWARE_UNKNOWN;\n}\n' + return r''' +#include +#include +#include +#include +#include +typedef uint32_t u32; +enum dcp_firmware_version { + DCP_FIRMWARE_UNKNOWN, + DCP_FIRMWARE_V_26_6_DESKTOP, + DCP_FIRMWARE_V_27_0, +}; +struct dcp_v14_board; +struct apple_dcp_hw_data { enum dcp_firmware_version firmware_compat; }; +struct device_node { + const char *compatible; + const char *uuid; + int uuid_count; + u32 fw[3]; + int fw_cells; + u32 compat[3]; + int compat_cells; +}; +struct device { + struct device_node *of_node; + const struct apple_dcp_hw_data *hw; +}; +static int of_device_is_compatible(const struct device_node *np, const char *s) +{ + return np && np->compatible && !strcmp(np->compatible, s); +} +static int of_property_count_strings(const struct device_node *np, const char *name) +{ + assert(!strcmp(name, "apple,firmware-uuid")); + return np ? np->uuid_count : -1; +} +static int of_property_read_string(const struct device_node *np, const char *name, const char **out) +{ + assert(!strcmp(name, "apple,firmware-uuid")); + if (!np || np->uuid_count < 1 || !np->uuid) + return -1; + *out = np->uuid; + return 0; +} +static int of_property_count_u32_elems(const struct device_node *np, const char *name) +{ + if (!np) + return -1; + if (!strcmp(name, "apple,firmware-version")) + return np->fw_cells; + if (!strcmp(name, "apple,firmware-compat")) + return np->compat_cells; + return -1; +} +static int of_property_read_u32_array(const struct device_node *np, const char *name, u32 *out, size_t n) +{ + const u32 *src; + int cells; + if (!np || n != 3) + return -1; + if (!strcmp(name, "apple,firmware-version")) { + src = np->fw; + cells = np->fw_cells; + } else if (!strcmp(name, "apple,firmware-compat")) { + src = np->compat; + cells = np->compat_cells; + } else { + return -1; + } + if (cells != 3) + return -1; + memcpy(out, src, 3 * sizeof(u32)); + return 0; +} +#define DCP_FW_VERSION_STR_LEN 32 +#define GFP_KERNEL 0 +#define dev_err(...) ((void)0) +static void *devm_kmemdup(struct device *dev, const void *src, size_t len, unsigned int gfp) +{ + (void)dev; (void)src; (void)len; (void)gfp; + return NULL; +} +static const struct apple_dcp_hw_data *of_device_get_match_data(struct device *dev) +{ + return dev->hw; +} +static int dcp_read_fw_version(struct device *dev, const char *name, char *out) +{ + u32 v[3]; + if (of_property_count_u32_elems(dev->of_node, name) != 3 || + of_property_read_u32_array(dev->of_node, name, v, 3)) + return -1; + snprintf(out, DCP_FW_VERSION_STR_LEN, "%u.%u.%u", v[0], v[1], v[2]); + return 3; +} +''' + helper + '\n' + methods_decl + '\n' + v27_tables + '\n' + selector + r''' +static struct device_node node; +static struct apple_dcp_hw_data hw_t6041; +static struct device dev = { .of_node = &node, .hw = &hw_t6041 }; + +static void reset_t6041_26b123(bool ext) +{ + node = (struct device_node){ + .compatible = ext ? "apple,t6041-dcpext" : "apple,t6041-dcp", + .uuid = APPLE_T6041_DCP_26B123_UUID, + .uuid_count = 1, + .fw = { 27, 2, 0 }, + .fw_cells = 3, + .compat = { 27, 2, 0 }, + .compat_cells = 3, + }; +} + +static void expect_rejected(void) +{ + assert(!apple_t6041_dcp_v27_2(&node)); + assert(!apple_t6041_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); +} + +int main(void) +{ + assert(!apple_t6041_dcp_v27_2(NULL)); + assert(!apple_t6041_dcpext_v27_2(NULL)); + + /* + * Internal only matches apple_t6041_dcp_v27_2; external only matches + * apple_t6041_dcpext_v27_2. No of_machine_is_compatible() stub is defined + * in this translation unit, enforcing at compile time that admission keys + * solely on the DCP IP compatible and firmware identity. + */ + reset_t6041_26b123(false); + assert(apple_t6041_dcp_v27_2(&node)); + assert(!apple_t6041_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); + + reset_t6041_26b123(true); + assert(!apple_t6041_dcp_v27_2(&node)); + assert(apple_t6041_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); + + for (unsigned ext = 0; ext < 2; ext++) { + /* Reject non-T6041 DCP compatibles. */ + reset_t6041_26b123(ext); node.compatible = "apple,t6031-dcp"; expect_rejected(); + + /* Reject missing, multi-string, or non-26B123 firmware UUIDs (including 26B131). */ + reset_t6041_26b123(ext); node.uuid_count = 0; expect_rejected(); + reset_t6041_26b123(ext); node.uuid_count = 2; expect_rejected(); + reset_t6041_26b123(ext); node.uuid = "00000000-0000-0000-0000-000000000000"; expect_rejected(); + reset_t6041_26b123(ext); node.uuid = "71F140DC-F18D-31B3-9772-537A5CC8400D"; expect_rejected(); + + /* Reject malformed or non-27.2.0 firmware/compat tuples. */ + reset_t6041_26b123(ext); node.fw_cells = 2; expect_rejected(); + reset_t6041_26b123(ext); node.compat_cells = 4; expect_rejected(); + reset_t6041_26b123(ext); node.fw[1] = 0; expect_rejected(); + reset_t6041_26b123(ext); node.compat[1] = 0; expect_rejected(); + reset_t6041_26b123(ext); node.fw[2] = 1; node.compat[2] = 1; expect_rejected(); + } + + /* Desktop 26.5.2 and 26.6.2 remain DCP_FIRMWARE_V_26_6_DESKTOP on internal and external. */ + for (unsigned minor = 5; minor <= 6; minor++) { + for (unsigned ext = 0; ext < 2; ext++) { + reset_t6041_26b123(ext); + node.uuid = "other"; + node.fw[0] = 26; node.fw[1] = minor; node.fw[2] = 2; + node.compat[0] = 26; node.compat[1] = minor; node.compat[2] = 2; + assert(!apple_t6041_dcp_v27_2(&node)); + assert(!apple_t6041_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_26_6_DESKTOP); + } + } + puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); + return 0; +} +''' diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py index 05a825197e978..1918958c334f6 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py @@ -88,6 +88,7 @@ def main(): ('m4', 'm4-panel-timing', m4.timing, ((),), ('-Wno-unused-function', '-Wno-unused-const-variable')), ('boot', 'oslog-events', boot.oslog, ((),), ()), ('boot', 'syslog-policy', boot.syslog, ((),), ()), + ('boot', 't6041-v27-admission', boot.t6041_v27_admission, ((),), ()), ('edid', 'dpavserv-start', edid.startup, ((),), ()), ('edid', 'service-rebind', edid.rebind, ((),), ()), ('edid', 'provider-admission', edid.admission, ((),), ()), diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py index bcf5b0d3f1b0f..90005ca179a62 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py @@ -71,6 +71,7 @@ def check(name, unit, cases=((),), negative=False, flags=()): static bool dcp_typec_route_no_dp_alt(const struct apple_dcp_typec_route *route) { (void)route; return false; } struct apple_dcp; static bool dcp_is_t8132_ext(const struct apple_dcp *dcp) { (void)dcp; return false; } + static bool dcp_t6041_ext_v27(const struct apple_dcp *dcp) { (void)dcp; return false; } #define dcp_queue_typec_reconnect(dcp,delay) ((void)(dcp),(void)(delay)) #define dev_info_once(...) ((void)0) #define USB_TYPEC_DP_SID 0xff01