diff --git a/arch/arm64/boot/dts/apple/t6030-dcp.dtsi b/arch/arm64/boot/dts/apple/t6030-dcp.dtsi index c2324b1083a61..511ebabee55b3 100644 --- a/arch/arm64/boot/dts/apple/t6030-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t6030-dcp.dtsi @@ -87,6 +87,8 @@ <0x2 0x8e850000 0x0 0x4000>; power-domains = <&ps_disp_cpu>; clocks = <&clk_disp0>; + /* Display bandwidth request slot in the disp-5 window. */ + apple,bw-scratch = <&pmgr_dcp 0 5 0x988>; #address-cells = <2>; #size-cells = <2>; ranges; @@ -97,6 +99,12 @@ }; }; + pmgr_dcp: power-management@3503d0000 { + reg = <0x3 0x503d0000 0x0 0x4000>; + reg-names = "dcp-fw-pmgr"; + #apple,bw-scratch-cells = <3>; + }; + dcpext_dart: iommu@2d130c000 { compatible = "apple,t6030-dart", "apple,t8110-dart"; reg = <0x2 0xd130c000 0x0 0x4000>; diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index c040f80df8e80..a6521dc75b9e7 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -23,6 +23,7 @@ appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_hdmi.o t8152_typec.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += iomfb_iboot.o iboot_drm.o appledrm-y += iomfb_h17p.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_h17p_test.o parser_test.o +appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_v27_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_external_hdr_hints_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += apple_resume_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += apple_boot_display_test.o diff --git a/drivers/gpu/drm/apple/dcp-firmware-test.c b/drivers/gpu/drm/apple/dcp-firmware-test.c index b0990bb1c0f68..1b411f88c84f7 100644 --- a/drivers/gpu/drm/apple/dcp-firmware-test.c +++ b/drivers/gpu/drm/apple/dcp-firmware-test.c @@ -100,10 +100,226 @@ static void dcp_firmware_27_empty_clock_table(struct kunit *test) KUNIT_EXPECT_EQ(test, dcp_firmware_clocks_v27(dcp), -EINVAL); } +/* + * Explicit match-data and image-UUID pins stay ahead of generic firmware-27 + * admission: T8122 wrong/missing 27.2 UUIDs and internal T8142 unknown 27.x + * builds are terminally refused rather than using generic v27 or H17P, + * while generic refmac DCPs (T6030, T8112) take firmware 27 on complete 27.x + * method tables and refuse incomplete ones. + */ +static void dcp_firmware_27_pin_precedence(struct kunit *test) +{ + static const char t6030[] = "apple,t6030-dcp"; + static const char t6041[] = "apple,t6041-dcp\0apple,dcp"; + static const char t6041_ext[] = "apple,t6041-dcpext\0apple,dcpext"; + static const char t8122[] = "apple,t8122-dcp\0apple,dcp"; + static const char t8122_ext[] = "apple,t8122-dcpext\0apple,dcpext"; + static const char t8142[] = "apple,t8142-dcp"; +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) + static const char t8132[] = "apple,t8132-dcp"; +#endif + static const char bad_uuid[] = "00000000-0000-0000-0000-000000000000"; + __be32 compat_26_6[] = { cpu_to_be32(26), cpu_to_be32(6), cpu_to_be32(2) }; + __be32 compat_27_0[] = { cpu_to_be32(27), 0, 0 }; + __be32 compat_27_1[] = { cpu_to_be32(27), cpu_to_be32(1), 0 }; + __be32 compat_27_2[] = { cpu_to_be32(27), cpu_to_be32(2), 0 }; + __be32 compat_27_3[] = { cpu_to_be32(27), cpu_to_be32(3), 0 }; + struct dcp_pin_precedence_fixture { + struct property props[4]; + struct property ext_props[3]; + struct device_node node; + struct device_node ext_node; + struct device dev; + } *fx; + + fx = kunit_kzalloc(test, sizeof(*fx), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, fx); + + fx->props[0] = (struct property) { + .name = "apple,firmware-compat", + .length = sizeof(compat_27_2), + .value = compat_27_2, + .next = &fx->props[1], + }; + fx->props[1] = (struct property) { + .name = "apple,firmware-version", + .length = sizeof(compat_27_2), + .value = compat_27_2, + .next = &fx->props[2], + }; + fx->props[2] = (struct property) { + .name = "apple,firmware-uuid", + .length = sizeof(bad_uuid), + .value = (void *)bad_uuid, + .next = &fx->props[3], + }; + fx->props[3] = (struct property) { + .name = "compatible", + .length = sizeof(t6030), + .value = (void *)t6030, + }; + fx->ext_props[0] = (struct property) { + .name = "apple,firmware-compat", + .length = sizeof(compat_27_2), + .value = compat_27_2, + .next = &fx->ext_props[1], + }; + fx->ext_props[1] = (struct property) { + .name = "apple,firmware-version", + .length = sizeof(compat_27_2), + .value = compat_27_2, + .next = &fx->ext_props[2], + }; + fx->ext_props[2] = (struct property) { + .name = "compatible", + .length = sizeof(t8122_ext), + .value = (void *)t8122_ext, + }; + fx->node.properties = fx->props; + fx->ext_node.properties = fx->ext_props; + fx->dev.init_name = "dcp-firmware-test"; + fx->dev.of_node = &fx->node; + fx->dev.driver = &apple_platform_driver.driver; + + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_V_27_0); + + fx->props[0].value = compat_27_3; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + fx->props[0].value = compat_27_2; + + /* T6041 internal and external UUID pins remain enforced on 27.2. */ + fx->props[3].length = sizeof(t6041); + fx->props[3].value = (void *)t6041; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + + fx->props[2].length = sizeof(APPLE_T6041_DCP_26B123_UUID); + fx->props[2].value = (void *)APPLE_T6041_DCP_26B123_UUID; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_V_27_0); + + fx->props[3].length = sizeof(t6041_ext); + fx->props[3].value = (void *)t6041_ext; + fx->props[2].length = sizeof(bad_uuid); + fx->props[2].value = (void *)bad_uuid; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + + fx->props[2].name = "apple,unrelated"; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + + fx->props[2].name = "apple,firmware-uuid"; + fx->props[2].length = sizeof(APPLE_T6041_DCP_26B123_UUID); + fx->props[2].value = (void *)APPLE_T6041_DCP_26B123_UUID; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_V_27_0); + + /* T8122 wrong or missing 27.2 UUID is terminally refused (never takes generic v27). */ + fx->props[3].length = sizeof(t8122); + fx->props[3].value = (void *)t8122; + fx->props[2].name = "apple,firmware-uuid"; + fx->props[2].length = sizeof(bad_uuid); + fx->props[2].value = (void *)bad_uuid; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + KUNIT_EXPECT_FALSE(test, + apple_t8122_dcpext_v27_2_for_internal(&fx->ext_node, &fx->node)); + + fx->props[2].name = "apple,unrelated"; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + KUNIT_EXPECT_FALSE(test, + apple_t8122_dcpext_v27_2_for_internal(&fx->ext_node, &fx->node)); + + fx->props[2].name = "apple,firmware-uuid"; + fx->props[2].length = sizeof(APPLE_T8122_DCP_26B123_UUID); + fx->props[2].value = (void *)APPLE_T8122_DCP_26B123_UUID; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_V_27_0); + KUNIT_EXPECT_TRUE(test, + apple_t8122_dcpext_v27_2_for_internal(&fx->ext_node, &fx->node)); + + /* T8122 external with mismatched version is terminally refused regardless of live tree. */ + fx->ext_props[1].value = compat_27_0; + KUNIT_EXPECT_FALSE(test, + apple_t8122_dcpext_v27_2_for_internal(&fx->ext_node, &fx->node)); + fx->dev.of_node = &fx->ext_node; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + fx->ext_props[1].value = compat_27_2; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + apple_t8122_dcpext_v27_2(&fx->ext_node) ? + DCP_FIRMWARE_V_27_0 : DCP_FIRMWARE_UNKNOWN); + fx->dev.of_node = &fx->node; + + /* Internal T8142: known 27.x takes v27, unknown 27.x is refused (never takes H17P). */ + fx->props[3].length = sizeof(t8142); + fx->props[3].value = (void *)t8142; + fx->props[0].value = compat_27_0; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_V_27_0); + fx->props[0].value = compat_27_2; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_V_27_0); + fx->props[0].value = compat_27_1; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + fx->props[0].value = compat_27_3; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_UNKNOWN); + fx->props[0].value = compat_26_6; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_H17P); + fx->props[0].value = compat_27_2; + +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) + /* T8132 keeps its M4 match-data pin on 27.2. */ + fx->props[3].length = sizeof(t8132); + fx->props[3].value = (void *)t8132; + KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), + DCP_FIRMWARE_M4); +#endif +} + +static void dcp_typec_routes_available_children(struct kunit *test) +{ + static const char disabled[] = "disabled"; + static const char okay[] = "okay"; + struct property child_status = { + .name = "status", .length = sizeof(disabled), .value = (void *)disabled, + }; + struct device_node child = { + .name = "route", .full_name = "route@0", .properties = &child_status, + }; + struct device_node routes = { + .name = "typec-routes", .full_name = "typec-routes", + }; + struct device_node parent = { + .name = "dcp", .full_name = "dcp", .child = &routes, + }; + + /* Empty typec-routes container has no available route children. */ + KUNIT_EXPECT_FALSE(test, dcp_has_available_typec_routes(&parent)); + + /* Container with only disabled child routes has no available routes. */ + routes.child = &child; + KUNIT_EXPECT_FALSE(test, dcp_has_available_typec_routes(&parent)); + + /* Available child route activates Type-C route detection. */ + child_status.length = sizeof(okay); + child_status.value = (void *)okay; + KUNIT_EXPECT_TRUE(test, dcp_has_available_typec_routes(&parent)); +} + static struct kunit_case dcp_firmware_cases[] = { KUNIT_CASE(dcp_firmware_13_5_compat), KUNIT_CASE(dcp_firmware_27_method_admission), KUNIT_CASE(dcp_firmware_27_empty_clock_table), + KUNIT_CASE(dcp_firmware_27_pin_precedence), + KUNIT_CASE(dcp_typec_routes_available_children), {} }; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index cb77aa8eabd5a..24dbe1812727e 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -322,6 +322,8 @@ struct apple_dcp_hw_data { * standard RTKit wake instead of starting or restarting the ASC. */ bool adopt_live_session; + /* Bootloader property marking this DCP as running under iBoot. */ + const char *iboot_handoff; enum dcp_firmware_version firmware_compat; /* Firmware-visible clock aperture, independent of the AP PMGR window. */ const struct resource *firmware_clock; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 4e48c4574624f..fa6a9f824ce9d 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6203,39 +6203,70 @@ static enum dcp_firmware_version dcp_v27_method_table(struct device *dev, return DCP_FIRMWARE_V_27_0; } +/* + * Firmware 27 is selected by the ABI the DCP reports, the same on every SoC: + * a DCP or dcpext whose firmware-compat is 27 or later runs the common + * firmware-27 instance with the method table of that build. The interfaces + * written for older firmware make it panic (T8142 on 27.0 with H17P: "ap_link: + * callback failed with: 0x5"), so a 27 or later build without a complete + * table is not started at all. Pure, so the host test runs the same rule. + */ +enum dcp_v27_admission dcp_v27_admission(const char *compat, + const struct dcp_method_entry **methods, + const char **missing, + unsigned int *num_missing) +{ + unsigned int major; + + *methods = NULL; + *missing = NULL; + *num_missing = 0; + if (sscanf(compat, "%u.", &major) != 1 || major < 27) + return DCP_V27_NOT_V27; + *methods = iomfb_v27_methods(compat); + if (!*methods) + return DCP_V27_NO_TABLE; + *missing = iomfb_v27_missing_method(*methods, num_missing); + if (*missing) + return DCP_V27_INCOMPLETE; + return DCP_V27_ADMITTED; +} + +/* + * Returns true if the DCP reports firmware 27 or later, with @version the + * firmware-27 instance or DCP_FIRMWARE_UNKNOWN if this build cannot be started. + */ +static bool dcp_firmware_27(struct device *dev, + enum dcp_firmware_version *version) +{ + char compat[DCP_FW_VERSION_STR_LEN]; + const struct dcp_method_entry *methods; + unsigned int num_missing; + const char *missing; + + if (dcp_read_fw_version(dev, "apple,firmware-compat", compat) < 0) + return false; + if (dcp_v27_admission(compat, &methods, &missing, &num_missing) == + DCP_V27_NOT_V27) + return false; + /* Logs why a build without a complete table is not started. */ + *version = dcp_v27_method_table(dev, compat); + return true; +} + static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) { const struct apple_dcp_hw_data *hw = of_device_get_match_data(dev); const struct dcp_v14_board *v14_board; char compat_str[DCP_FW_VERSION_STR_LEN]; char fw_str[DCP_FW_VERSION_STR_LEN]; + enum dcp_firmware_version version; int ret; /* - * T8142 (J813) on macOS 27.0: the H17P interface written for its 26.x - * firmware makes the 27.0 DCP firmware panic right after the first - * hotplug ("ap_link: callback failed with: 0x5"). It runs the T6050's - * firmware-27 generation, and so does 27.2, with the 27.2 method table. + * T6050 and T8142 dcpext were introduced on firmware 27 and have no + * older interface. */ - if (of_device_is_compatible(dev->of_node, "apple,t8142-dcp")) { - ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - if (ret >= 0 && (!strcmp(compat_str, "27.0.0") || - !strcmp(compat_str, "27.2.0"))) - return DCP_FIRMWARE_V_27_0; - } - - /* - * The T8122 (M3 MacBook Air) internal DCP on the 27.2 (26B123) image - * runs the firmware-27 backend with the 27.2 table, as the T6041's - * 27.2 internal DCP does. Its 14.x image keeps the native 14.7 path - * and the 25G83 profile its own, below. - */ - if (apple_t8122_dcp_v27_2(dev->of_node)) { - /* Checked by apple_t8122_dcp_v27_2(). */ - dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - return dcp_v27_method_table(dev, compat_str); - } - if (hw->firmware_compat == DCP_FIRMWARE_V_27_0) { ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); if (ret < 0) { @@ -6246,8 +6277,20 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) } /* - * SoCs introduced with H17-generation firmware pin its interface; the - * loader may not recognise their boot firmware version. + * T8142 (J813) on firmware 27 or later: the H17P interface written for + * its 26.x firmware makes 27.x firmware panic right after the first + * hotplug ("ap_link: callback failed with: 0x5"). Keep ahead of its + * H17P match-data pin so known 27.x builds take the common firmware-27 + * backend and unknown 27.x builds are terminally refused. + */ + if (of_device_is_compatible(dev->of_node, "apple,t8142-dcp") && + dcp_firmware_27(dev, &version)) + return version; + + /* + * SoCs introduced with M4 or H17-generation firmware pin their + * interface; keep explicit match-data pins ahead of the generic + * firmware-27 rule below so T8132/T8140 stay on their pinned backend. */ if (hw->firmware_compat != DCP_FIRMWARE_UNKNOWN) return hw->firmware_compat; @@ -6259,7 +6302,8 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) * 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. + * backend on internal and external display processors. Keep ahead of + * dcp_firmware_27() so the T6041 image UUID pin remains enforced. */ if (of_device_is_compatible(dev->of_node, "apple,t6041-dcp") || of_device_is_compatible(dev->of_node, "apple,t6041-dcpext")) { @@ -6278,6 +6322,25 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) return DCP_FIRMWARE_UNKNOWN; } + /* + * T8122 (M3 MacBook Air) internal and external DCPs pin the 27.2 + * (26B123) image UUID on firmware 27.x: any wrong or missing UUID on a + * firmware 27+ build is terminally refused rather than falling through + * to generic firmware-27 or legacy 14.x selection. + */ + if ((of_device_is_compatible(dev->of_node, "apple,t8122-dcp") || + of_device_is_compatible(dev->of_node, "apple,t8122-dcpext")) && + dcp_firmware_27(dev, &version)) { + if (apple_t8122_dcp_v27_2(dev->of_node) || + apple_t8122_dcpext_v27_2(dev->of_node)) + return version; + dev_err(dev, "T8122 display not started: unpinned 27.x DCP firmware UUID\n"); + return DCP_FIRMWARE_UNKNOWN; + } + + if (dcp_firmware_27(dev, &version)) + return version; + ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); if (ret < 0) { dev_err(dev, "Could not read 'apple,firmware-compat': %d\n", ret); @@ -6472,6 +6535,80 @@ VISIBLE_IF_KUNIT void dcp_enable_typec_work(struct apple_dcp *dcp) } } +static bool dcp_has_available_typec_routes(struct device_node *np) +{ + struct device_node *routes, *child; + bool avail = false; + + routes = of_get_child_by_name(np, "typec-routes"); + if (!routes) + return false; + if (of_device_is_available(routes)) { + for_each_available_child_of_node(routes, child) { + of_node_put(child); + avail = true; + break; + } + } + of_node_put(routes); + return avail; +} + +static bool dcp_is_internal_panel_only(const struct apple_dcp *dcp) +{ + struct device_node *np = dcp->dev->of_node; + + return dcp->panel_identity && !dcp->dcpext && + !of_property_present(np, "phys") && + !dcp_has_available_typec_routes(np); +} + +static u8 dcp_dart_dma_bits(struct device_node *np) +{ + struct of_phandle_args args; + u32 range[4]; + u64 base, size, end; + int ret; + + ret = of_parse_phandle_with_args(np, "iommus", "#iommu-cells", 0, &args); + if (ret) + return 0; + ret = of_property_read_u32_array(args.np, "apple,dma-range", range, 4); + of_node_put(args.np); + if (ret) + return 0; + base = ((u64)range[0] << 32) | range[1]; + size = ((u64)range[2] << 32) | range[3]; + if (!size || base + size < base) + return 0; + end = base + size - 1; + return clamp_t(u8, fls64(end), 32, 48); +} + +static void dcp_apply_dt_profile(struct apple_dcp *dcp) +{ + struct device_node *np = dcp->dev->of_node; + u32 running; + + if (of_property_present(np, "apple,rtkit-handoff")) + dcp->hw.adopt_live_session = true; + + if (dcp->fw_compat != DCP_FIRMWARE_V_27_0) + return; + + /* iBoot can leave the ASC running without negotiating RTKit. */ + if (dcp->hw.iboot_handoff && + of_property_read_variable_u32_array(np, dcp->hw.iboot_handoff, + &running, 1, 1) == 1 && + running == 1) + dcp->hw.adopt_live_session = true; + + if (!dcp->hw.firmware_dma_bits) + dcp->hw.firmware_dma_bits = dcp_dart_dma_bits(np); + if (dcp_is_internal_panel_only(dcp)) + dcp->hw.num_dptx_ports = 0; +} + /* * The provider clocks firmware 27 asks for by index (getClockFrequency): * apple,clock-ids, published by the boot loader from the ADT. @@ -6482,24 +6619,20 @@ static int dcp_firmware_clocks_v27(struct apple_dcp *dcp) int clocks, index, ret; /* - * 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. - */ - /* - * The T8122 /arm-io/disp0 names the same pair (345 at 712 MHz, the - * device tree's disp0 clock, and 416 at 0 Hz). + * Internal panels whose device tree carries only the single unnamed + * disp0 clock without apple,clock-ids (T6041, T8122, T6030, T6031, + * T8112): expose the two-entry [disp0, 0 Hz] table so + * getClockFrequency(0/1) matches /arm-io/disp0. Non-panel paths or + * nodes without a single unnamed clock still require apple,clock-ids. */ if (!of_property_present(dev->of_node, "apple,clock-ids") && - (of_device_is_compatible(dev->of_node, "apple,t6041-dcp") || - of_device_is_compatible(dev->of_node, "apple,t8122-dcp"))) { - struct clk *clk = devm_clk_get_optional(dev, NULL); + dcp_is_internal_panel_only(dcp) && + !of_property_present(dev->of_node, "clock-names") && + of_count_phandle_with_args(dev->of_node, "clocks", "#clock-cells") == 1) { + struct clk *clk = devm_clk_get(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); @@ -7868,6 +8001,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) */ if (fw_compat != DCP_FIRMWARE_V_14_7 && fw_compat != DCP_FIRMWARE_V_26_6 && + fw_compat != DCP_FIRMWARE_V_27_0 && fw_compat != DCP_FIRMWARE_M4 && !of_property_present(dev->of_node, "apple,bw-scratch") && !hw->firmware_clock) @@ -7981,9 +8115,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) if (ret) return ret; dcp->hw = *(struct apple_dcp_hw_data *)of_device_get_match_data(dev); - /* A boot stage handed this DCP over running: keep its session. */ - if (of_property_present(dev->of_node, "apple,rtkit-handoff")) - dcp->hw.adopt_live_session = true; + dcp_apply_dt_profile(dcp); /* The link report: on the board it has run on (dcp_j714s_ext()). */ if (!dcp_j714s_ext(dev)) dcp->hw.link_report = false; @@ -7994,28 +8126,6 @@ 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; - } - /* - * The same for the T8122 internal panel on firmware 27: its DART - * window is 0x100_0000_0000 + 64 GiB, and dcpext drives the external - * ports. - */ - if (fw_compat == DCP_FIRMWARE_V_27_0 && - of_device_is_compatible(dev->of_node, "apple,t8122-dcp")) { - dcp->hw.firmware_dma_bits = 41; - dcp->hw.num_dptx_ports = 0; - dcp->hw.adopt_live_session = true; - } /* * The T8122 external processor on firmware 27: the boot loader leaves * it unpowered (its DISPEXT domains are off at handoff), so Linux @@ -8026,14 +8136,16 @@ 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,t8122-dcpext")) { - dcp->hw.firmware_dma_bits = 41; + if (!dcp->hw.firmware_dma_bits) + dcp->hw.firmware_dma_bits = 41; dcp->hw.num_dptx_ports = 2; dcp->hw.fw_14_7_endpoints = false; dcp->hw.adopt_live_session = false; } if (fw_compat == DCP_FIRMWARE_V_27_0 && of_device_is_compatible(dev->of_node, "apple,t6041-dcpext")) { - dcp->hw.firmware_dma_bits = 41; + if (!dcp->hw.firmware_dma_bits) + dcp->hw.firmware_dma_bits = 41; dcp->hw.num_dptx_ports = 2; dcp->hw.adopt_live_session = true; dcp->hw.sink_metadata_edid = true; @@ -10859,15 +10971,18 @@ static const struct apple_dcp_hw_data apple_dcp_hw_dcp = { }; static const struct apple_dcp_hw_data apple_dcp_hw_t6030 = { + .iboot_handoff = "apple,t6030-handoff", .num_dptx_ports = 1, }; static const struct apple_dcp_hw_data apple_dcp_hw_t8122 = { + .iboot_handoff = "apple,t8122-handoff", .num_dptx_ports = 2, }; /* The internal panel only, through the 14.x IOMFB, as on T6030. */ static const struct apple_dcp_hw_data apple_dcp_hw_t6031 = { + .iboot_handoff = "apple,t6031-handoff", .num_dptx_ports = 1, }; @@ -10900,6 +11015,7 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8132_dcpext = { /* T6041 (M4 Pro/Max), desktop 26.6 firmware */ static const struct apple_dcp_hw_data apple_dcp_hw_t6041 = { + .iboot_handoff = "apple,t6041-handoff", .num_dptx_ports = 2, }; diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index 6c1c258c3c54e..f2745dde65580 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -94,6 +94,19 @@ bool dcp_fw_compat_is_desktop(struct platform_device *pdev); bool dcp_panel_edr(struct platform_device *pdev); bool dcp_ext_color_props_supported(struct platform_device *pdev); unsigned int dcp_gamma_lut_size(struct platform_device *pdev); +/* Whether a DCP reporting firmware-compat @compat runs the firmware-27 instance. */ +enum dcp_v27_admission { + DCP_V27_NOT_V27, /* older than 27: the older interfaces decide */ + DCP_V27_NO_TABLE, /* 27 or later, no method table for the build */ + DCP_V27_INCOMPLETE, /* 27 or later, a method has no known ID */ + DCP_V27_ADMITTED, +}; + +struct dcp_method_entry; +enum dcp_v27_admission dcp_v27_admission(const char *compat, + const struct dcp_method_entry **methods, + const char **missing, + unsigned int *num_missing); /* T6041 external display processors may join the DRM device. */ bool dcp_t6041_ext_enabled(void); void dcp_backlight_takeover_registered(struct platform_device *pdev); diff --git a/drivers/gpu/drm/apple/iomfb_v27_test.c b/drivers/gpu/drm/apple/iomfb_v27_test.c new file mode 100644 index 0000000000000..0c20e9c0d1f89 --- /dev/null +++ b/drivers/gpu/drm/apple/iomfb_v27_test.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* Copyright 2026 Aurora Silicon */ + +/* + * Firmware 27 is selected by the firmware-compat a DCP reports, on every SoC: + * 27 or later runs the firmware-27 instance when the build has a complete + * method table and is not started otherwise; older firmware is left to the + * older interfaces. These tests cover that rule and the in-tree tables. + */ + +#include +#include +#include + +#include "dcp.h" +#include "iomfb.h" +#include "iomfb_v27.h" + +static enum dcp_v27_admission admission(const char *compat) +{ + const struct dcp_method_entry *methods; + unsigned int num_missing; + const char *missing; + + return dcp_v27_admission(compat, &methods, &missing, &num_missing); +} + +/* Builds with a complete table start, whatever SoC reports them. */ +static void v27_complete_table_admits_test(struct kunit *test) +{ + const struct dcp_method_entry *methods; + unsigned int num_missing; + const char *missing; + + KUNIT_EXPECT_EQ(test, dcp_v27_admission("27.2.0", &methods, &missing, + &num_missing), + DCP_V27_ADMITTED); + KUNIT_EXPECT_PTR_EQ(test, methods, iomfb_v27_methods("27.2.0")); + KUNIT_EXPECT_PTR_EQ(test, missing, NULL); + KUNIT_EXPECT_EQ(test, num_missing, 0U); + KUNIT_EXPECT_EQ(test, admission("27.0.0"), DCP_V27_ADMITTED); +} + +/* 27 or later without a usable table is refused, never handed down. */ +static void v27_unusable_table_refuses_test(struct kunit *test) +{ + const struct dcp_method_entry *methods; + unsigned int num_missing; + const char *missing; + + KUNIT_EXPECT_EQ(test, admission("27.1.0"), DCP_V27_NO_TABLE); + KUNIT_EXPECT_EQ(test, admission("28.0.0"), DCP_V27_NO_TABLE); + KUNIT_EXPECT_EQ(test, dcp_v27_admission("27.3.0", &methods, &missing, + &num_missing), + DCP_V27_INCOMPLETE); + KUNIT_EXPECT_NOT_NULL(test, missing); + KUNIT_EXPECT_GT(test, num_missing, 0U); +} + +/* Older firmware keeps the 26.x, 14.x and 13.x selection. */ +static void v27_older_firmware_not_v27_test(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, admission("26.6.2"), DCP_V27_NOT_V27); + KUNIT_EXPECT_EQ(test, admission("26.5.2"), DCP_V27_NOT_V27); + KUNIT_EXPECT_EQ(test, admission("14.7.0"), DCP_V27_NOT_V27); + KUNIT_EXPECT_EQ(test, admission("13.5.0"), DCP_V27_NOT_V27); + KUNIT_EXPECT_EQ(test, admission("12.3.0"), DCP_V27_NOT_V27); + KUNIT_EXPECT_EQ(test, admission("UNKNOWN"), DCP_V27_NOT_V27); +} + +static struct kunit_case v27_cases[] = { + KUNIT_CASE(v27_complete_table_admits_test), + KUNIT_CASE(v27_unusable_table_refuses_test), + KUNIT_CASE(v27_older_firmware_not_v27_test), + {} +}; + +static struct kunit_suite v27_suite = { + .name = "apple-dcp-v27", + .test_cases = v27_cases, +}; + +kunit_test_suite(v27_suite); + +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index 7e736522740b0..da24641472994 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -790,6 +790,17 @@ static void __init gate_t6030_other_pmp_image(struct kunit *test) gt_expect_untouched(test); } +/* The 27.2 (26B123) T6030 PMP image is taken as well. */ +static void __init gate_t6030_pmp_image_27_2(struct kunit *test) +{ + struct gate_test *t = test->priv; + + t->pmp_uuid = "5D66805B-E4AD-335E-BDC3-26828C682AAC"; + gt_set_string(test, gt_t6030.values, "apple,tunable-uuid", t->pmp_uuid); + gt_run(test); + gt_expect_enabled(test); +} + static void __init gate_t6030_enabled_again(struct kunit *test) { gt_run(test); @@ -1185,6 +1196,7 @@ static struct kunit_case gate_t6030_cases[] __refdata = { KUNIT_CASE(gate_t6030_no_marker), KUNIT_CASE(gate_t6030_t6031_power_layout), KUNIT_CASE(gate_t6030_other_pmp_image), + KUNIT_CASE(gate_t6030_pmp_image_27_2), KUNIT_CASE(gate_t6030_enabled_again), {} }; diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index dc57af0dd1651..931fe3ef1adf8 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -161,6 +161,14 @@ static struct device_node *gate_pmp_values __initdata; */ static const char gate_pmp_uuid[] __initconst = "2F4EB4C4-001B-3ACF-A9A0-68D8E42FC3A7"; +/* + * The T6030 PMP image of the 27.2 (26B123) system firmware, as the J516S ADT + * names it. Its soc-device records are those of the J516S overlay, and the PMP + * report driver checks the running image against the values the boot loader + * passes, so the same PMP support takes either image. + */ +static const char gate_t6030_pmp_uuid_27_2[] __initconst = "5D66805B-E4AD-335E-BDC3-26828C682AAC"; + /* The T8122 PMP image of the 14.x system firmware. */ static const char gate_t8122_pmp_uuid[] __initconst = "3B18C886-4C70-349B-B1C4-70F35DE2C5CD"; @@ -255,6 +263,7 @@ static const struct gate_soc gate_t6030 __initconst = { .dcp_full_name = "dcp@28ec00000", .pmp_values = "/chosen/asahi,t6030-pmp", .pmp_uuid = gate_pmp_uuid, + .pmp_uuid_alt = gate_t6030_pmp_uuid_27_2, .report_compat = "apple,t6030-pmp-v2-report", .disp_entry = "report@7", .pmp_dtbo = __dtbo_t6030_pmp_begin, diff --git a/include/linux/soc/apple/display.h b/include/linux/soc/apple/display.h index c0ae42df744cd..86a12be7bc1c9 100644 --- a/include/linux/soc/apple/display.h +++ b/include/linux/soc/apple/display.h @@ -93,11 +93,11 @@ static inline bool apple_t8122_dcp_v27_2(const struct device_node *np) * DCP's region). So it qualifies when both of its own are 27.2.0 and the * internal DCP was handed over on the 27.2 image. */ -static inline bool apple_t8122_dcpext_v27_2(const struct device_node *np) +static inline bool +apple_t8122_dcpext_v27_2_for_internal(const struct device_node *np, + const struct device_node *internal_dcp) { - struct device_node *dcp; u32 fw[3], compat[3]; - bool internal; if (!np || !of_device_is_compatible(np, "apple,t8122-dcpext") || of_property_count_u32_elems(np, "apple,firmware-version") != 3 || @@ -108,8 +108,19 @@ static inline bool apple_t8122_dcpext_v27_2(const struct device_node *np) compat[0] != 27 || compat[1] != 2 || compat[2] != 0) return false; + return apple_t8122_dcp_v27_2(internal_dcp); +} + +static inline bool apple_t8122_dcpext_v27_2(const struct device_node *np) +{ + struct device_node *dcp; + bool internal; + + if (!np || !of_device_is_compatible(np, "apple,t8122-dcpext")) + return false; + dcp = of_find_compatible_node(NULL, NULL, "apple,t8122-dcp"); - internal = apple_t8122_dcp_v27_2(dcp); + internal = apple_t8122_dcpext_v27_2_for_internal(np, dcp); of_node_put(dcp); return internal; } diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index 28533a70b2292..74a7a11da1940 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -196,25 +196,41 @@ def syslog(root): ''' -def _v27_prelude(root, helpers): - """Host stand-ins for the OF and DCP calls, then the production display.h - helpers named in @helpers, the firmware-27 method tables and - dcp_v27_method_table().""" +def _v27_prelude(root): + """Host stand-ins for OF and legacy board checks, then the live selector.""" display_h = (root / 'include/linux/soc/apple/display.h').read_text() uuid_defines = [line for line in display_h.splitlines() if line.startswith(('#define APPLE_T6041_DCP_26B123_UUID ', '#define APPLE_T8122_DCP_26B123_UUID '))] assert len(uuid_defines) == 2 - helper = '\n'.join((*uuid_defines, *( - block(display_h, 'static inline bool ' + name + '(') for name in helpers))) + helpers = ('static inline bool apple_dcp_image_v27_2(', + 'static inline bool apple_t6041_dcp_any_v27_2(', + 'static inline bool apple_t6041_dcp_v27_2(', + 'static inline bool apple_t6041_dcpext_v27_2(', + 'static inline bool apple_t8122_dcp_v27_2(', + 'static inline bool\napple_t8122_dcpext_v27_2_for_internal(', + 'static inline bool apple_t8122_dcpext_v27_2(') + helper = '\n'.join((*uuid_defines, *(block(display_h, marker) for marker in helpers))) 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() - method_table = block(dcp_c, 'static enum dcp_firmware_version dcp_v27_method_table(') + apple = root / 'drivers/gpu/drm/apple' + dcp_c = (apple / 'dcp.c').read_text() + version_defs = '\n'.join(line for line in dcp_c.splitlines() + if line.startswith('#define DCP_FW_VERSION_')) + version_enum = block((apple / 'version_utils.h').read_text(), + 'enum dcp_firmware_version {') + ';' + admission_enum = block((apple / 'dcp.h').read_text(), 'enum dcp_v27_admission {') + ';' + selector = '\n'.join(block(dcp_c, marker) for marker in ( + 'static int dcp_read_fw_version(', + 'static enum dcp_firmware_version dcp_v27_method_table(', + 'enum dcp_v27_admission dcp_v27_admission(', + 'static bool dcp_firmware_27(', + 'static enum dcp_firmware_version dcp_check_firmware_version(', + )) return r''' #include #include @@ -224,20 +240,16 @@ def _v27_prelude(root, helpers): #include #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) typedef uint32_t u32; -enum dcp_firmware_version { - DCP_FIRMWARE_UNKNOWN, - DCP_FIRMWARE_V_26_6_DESKTOP, - DCP_FIRMWARE_V_27_0, -}; +''' + version_defs + '\n' + version_enum + '\n' + admission_enum + r''' 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]; + u32 fw[DCP_FW_VERSION_MAX_LEN]; int fw_cells; - u32 compat[3]; + u32 compat[DCP_FW_VERSION_MAX_LEN]; int compat_cells; }; struct device { @@ -248,11 +260,11 @@ def _v27_prelude(root, helpers): { return np && np->compatible && !strcmp(np->compatible, s); } -/* The tree's display processors, for of_find_compatible_node(); unused by some units. */ +/* The tree's display processors, for of_find_compatible_node(). */ static struct device_node *of_nodes[2]; static int of_node_refs; -__attribute__((unused)) static struct device_node *of_find_compatible_node(struct device_node *from, - const char *type, const char *s) +static struct device_node *of_find_compatible_node(struct device_node *from, + const char *type, const char *s) { assert(!from && !type); for (unsigned i = 0; i < 2; i++) @@ -262,7 +274,7 @@ def _v27_prelude(root, helpers): } return NULL; } -__attribute__((unused)) static void of_node_put(struct device_node *np) +static void of_node_put(struct device_node *np) { if (np) assert(of_node_refs-- > 0); @@ -290,29 +302,30 @@ def _v27_prelude(root, helpers): 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) +static int of_property_read_variable_u32_array(const struct device_node *np, const char *name, + u32 *out, int min, int max) { + int cells = of_property_count_u32_elems(np, name); 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; + + if (cells < min || cells > max) + return -EINVAL; + src = !strcmp(name, "apple,firmware-version") ? np->fw : np->compat; + memcpy(out, src, cells * sizeof(*out)); + return cells; +} +static int of_property_read_u32_array(const struct device_node *np, const char *name, u32 *out, int n) +{ + int ret = of_property_read_variable_u32_array(np, name, out, n, n); + + return ret < 0 ? ret : 0; } -#define DCP_FW_VERSION_STR_LEN 32 +#define scnprintf snprintf +#define strscpy(dst, src, size) snprintf((dst), (size), "%s", (src)) #define GFP_KERNEL 0 -#define dev_err(...) ((void)0) +#define dev_warn(...) ((void)0) +#define IS_ERR(ptr) false +static void dev_err(struct device *dev, const char *format, ...) {} static void *devm_kmemdup(struct device *dev, const void *src, size_t len, unsigned int gfp) { (void)dev; (void)src; (void)len; (void)gfp; @@ -322,29 +335,121 @@ def _v27_prelude(root, helpers): { return dev->hw; } -static int dcp_read_fw_version(struct device *dev, const char *name, char *out) +/* No internal board profile is present in these fixtures. */ +static bool of_property_present(struct device_node *np, const char *name) +{ + assert(!strcmp(name, "apple,j613-25g83-profile")); + return false; +} +static bool apple_t8122_25g83_board(void) { return false; } +static int of_property_read_u32(struct device_node *np, const char *name, u32 *out) +{ + return -ENOENT; +} +static const struct dcp_v14_board *iomfb_v14_7_board(struct device *dev) { return NULL; } +static const char *iomfb_v14_7_board_name(const struct dcp_v14_board *board) { return ""; } +static bool ext26; +static bool dcp_ext26_admitted(struct device_node *np) { return ext26; } +''' + helper + '\n' + methods_decl + '\n' + v27_tables + '\n' + selector + '\n' + + +def v27_panel_handoff(root): + source = (root / 'drivers/gpu/drm/apple/dcp.c').read_text() + profiles = ('t6030', 't8122', 't6031', 't6041') + match = '\n'.join(block(source, f'static const struct apple_dcp_hw_data apple_dcp_hw_{soc} =') + + ';' for soc in profiles) + profile = block(source, 'static void dcp_apply_dt_profile(') + return r''' +#include +#include +#include +#include +typedef uint8_t u8; +typedef uint32_t u32; +enum { DCP_FIRMWARE_V_27_0 = 27 }; +struct device_node { + bool rtkit_handoff; + const char *marker; + u32 value; +}; +struct device { struct device_node *of_node; }; +struct apple_dcp_hw_data { + bool adopt_live_session; + const char *iboot_handoff; + unsigned num_dptx_ports; + u8 firmware_dma_bits; +}; +struct apple_dcp { + struct device *dev; + struct apple_dcp_hw_data hw; + int fw_compat; +}; +static bool of_property_present(struct device_node *np, const char *name) +{ + assert(!strcmp(name, "apple,rtkit-handoff")); + return np->rtkit_handoff; +} +static int of_property_read_variable_u32_array(struct device_node *np, const char *name, + u32 *value, int min, int max) { - 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)) + assert(min == 1 && max == 1); + if (!np->marker || strcmp(name, np->marker)) return -1; - snprintf(out, DCP_FW_VERSION_STR_LEN, "%u.%u.%u", v[0], v[1], v[2]); - return 3; + *value = np->value; + return 1; +} +/* All probes see the same DART aperture and panel-only topology. */ +static u8 dcp_dart_dma_bits(struct device_node *np) { return 41; } +static bool dcp_is_internal_panel_only(struct apple_dcp *dcp) { return true; } +''' + match + '\n' + profile + r''' +static void check(struct apple_dcp_hw_data hw, struct device_node node, bool live) +{ + struct device dev = { .of_node = &node }; + struct apple_dcp dcp = { .dev = &dev, .hw = hw, .fw_compat = DCP_FIRMWARE_V_27_0 }; + + dcp_apply_dt_profile(&dcp); + assert(dcp.hw.adopt_live_session == live); + assert(dcp.hw.firmware_dma_bits == 41); + assert(dcp.hw.num_dptx_ports == 0); } -''' + helper + '\n' + methods_decl + '\n' + v27_tables + '\n' + method_table + '\n' + +int main(void) +{ + const struct { + const struct apple_dcp_hw_data *hw; + const char *marker; + } panels[] = { + { &apple_dcp_hw_t6030, "apple,t6030-handoff" }, + { &apple_dcp_hw_t8122, "apple,t8122-handoff" }, + { &apple_dcp_hw_t6031, "apple,t6031-handoff" }, + { &apple_dcp_hw_t6041, "apple,t6041-handoff" }, + }; + + for (unsigned i = 0; i < sizeof(panels) / sizeof(panels[0]); i++) { + struct apple_dcp_hw_data hw = *panels[i].hw; + struct device_node node = {}; + + check(hw, node, false); + node.rtkit_handoff = true; + check(hw, node, true); + node.rtkit_handoff = false; + node.marker = panels[i].marker; + check(hw, node, false); + node.value = 1; + check(hw, node, true); + node.marker = panels[i ? 0 : 1].marker; + check(hw, node, false); + } + return 0; +} +''' def t6041_v27_admission(root): - 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 _v27_prelude(root, ('apple_dcp_image_v27_2', - 'apple_t6041_dcp_any_v27_2', 'apple_t6041_dcp_v27_2', - 'apple_t6041_dcpext_v27_2', 'apple_t8122_dcp_v27_2')) + selector + r''' + return _v27_prelude(root) + 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 const struct apple_dcp_hw_data hw; +static struct device dev = { .of_node = &node, .hw = &hw }; static void reset_t6041_26b123(bool ext) { @@ -387,10 +492,14 @@ def t6041_v27_admission(root): 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(); + /* A different SoC follows generic admission, without the T6041 UUID pin. */ + node.compatible = "apple,t6031-dcp"; + node.uuid_count = 0; + 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 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(); @@ -419,11 +528,9 @@ def t6041_v27_admission(root): } /* * The M3 Air's (T8122) internal DCP handed over with its 27.2 image runs - * the 27.2 table, on any T8122 board; its dcpext, another image, its - * 14.x image and other releases do not. + * the 27.2 table. The external processor needs the internal handoff, + * other firmware-27 images are refused and 14.7 stays on a legacy ABI. */ - static struct apple_dcp_hw_data hw_t8122; - dev.hw = &hw_t8122; reset_t6041_26b123(false); node.compatible = "apple,t8122-dcp"; node.uuid = APPLE_T8122_DCP_26B123_UUID; @@ -439,53 +546,33 @@ def t6041_v27_admission(root): assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); node.uuid = APPLE_T8122_DCP_26B123_UUID; node.uuid_count = 0; assert(!apple_t8122_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); node.uuid_count = 2; assert(!apple_t8122_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); node.uuid_count = 1; node.fw[0] = 14; node.fw[1] = 7; node.fw[2] = 0; node.compat[0] = 14; node.compat[1] = 7; node.compat[2] = 0; assert(!apple_t8122_dcp_v27_2(&node)); - assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_14_7_TEMPLATE); node.fw[0] = 27; node.fw[1] = 2; node.fw[2] = 1; node.compat[0] = 27; node.compat[1] = 2; node.compat[2] = 1; assert(!apple_t8122_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); node.fw[2] = 0; node.compat[2] = 0; assert(apple_t8122_dcp_v27_2(&node)); - dev.hw = &hw_t6041; puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); - puts("PASS T8122 internal DCP on its 27.2 image alone runs the 27.2 table"); + puts("PASS T8122 internal DCP needs its 27.2 image for the 27.2 table"); return 0; } ''' def t8122_dcpext_v27_admission(root): - """apple_t8122_dcpext_v27_2() and the apple,t8122-dcpext arm of - dcp_check_firmware_version(), both as the tree has them.""" - dcp_c = (root / 'drivers/gpu/drm/apple/dcp.c').read_text() - selector = block(dcp_c, 'static enum dcp_firmware_version dcp_check_firmware_version(') - arm = block(selector, selector.index( - 'if (of_device_is_compatible(dev->of_node, "apple,t8122-dcpext")) {')) - unit = _v27_prelude(root, ('apple_dcp_image_v27_2', 'apple_t8122_dcp_v27_2', - 'apple_t8122_dcpext_v27_2')) - # The arm runs with the firmware-compat the selector read before it. - return r''' -#define DCP_FIRMWARE_H17P 0x17 -#define DCP_FIRMWARE_V_14_7_TEMPLATE 0x147 -''' + unit + r''' -static bool ext26; -static bool dcp_ext26_admitted(struct device_node *np) { (void)np; return ext26; } -static enum dcp_firmware_version t8122_dcpext_arm(struct device *dev) -{ - char compat_str[DCP_FW_VERSION_STR_LEN] = ""; - - dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - ''' + arm + r''' - return DCP_FIRMWARE_UNKNOWN; -} - + return _v27_prelude(root) + r''' static struct device_node dcp, dcpext; -static struct device dev = { .of_node = &dcpext }; +static const struct apple_dcp_hw_data hw; +static struct device dev = { .of_node = &dcpext, .hw = &hw }; static void set(u32 *v, u32 a, u32 b, u32 c) { v[0] = a; v[1] = b; v[2] = c; } @@ -509,7 +596,7 @@ def t8122_dcpext_v27_admission(root): static void expect(bool v27_2, enum dcp_firmware_version want) { assert(apple_t8122_dcpext_v27_2(&dcpext) == v27_2); - assert(t8122_dcpext_arm(&dev) == want); + assert(dcp_check_firmware_version(&dev) == want); assert(!of_node_refs); } @@ -546,14 +633,16 @@ def t8122_dcpext_v27_admission(root): expect(false, DCP_FIRMWARE_UNKNOWN); reset(); dcpext.fw_cells = 0; expect(false, DCP_FIRMWARE_UNKNOWN); reset(); dcpext.compat_cells = 4; expect(false, DCP_FIRMWARE_UNKNOWN); + /* A 27.x refusal is terminal even if the legacy gate would admit it. */ + reset(); ext26 = true; dcp.uuid_count = 0; expect(false, DCP_FIRMWARE_UNKNOWN); puts("PASS T8122 dcpext 27.2 refuses other or malformed versions"); /* The 14.7 template and the native 26.x path are as before. */ reset(); set(dcpext.fw, 14, 7, 0); set(dcpext.compat, 14, 7, 0); expect(false, DCP_FIRMWARE_V_14_7_TEMPLATE); - reset(); ext26 = true; expect(true, DCP_FIRMWARE_H17P); reset(); set(dcpext.fw, 26, 6, 2); set(dcpext.compat, 26, 6, 2); expect(false, DCP_FIRMWARE_UNKNOWN); + ext26 = true; expect(false, DCP_FIRMWARE_H17P); puts("PASS T8122 dcpext 14.7.0 keeps the template, native 26.x keeps H17P"); 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 f62924a6d8443..2d111c5bed964 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py @@ -92,8 +92,9 @@ 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', 'v27-panel-handoff', boot.v27_panel_handoff, ((),), ()), ('boot', 't6041-v27-admission', boot.t6041_v27_admission, ((),), ()), - ('boot', 't8122-dcpext-v27-admission', boot.t8122_dcpext_v27_admission, ((),), ('-Wno-unused-function',)), + ('boot', 't8122-dcpext-v27-admission', boot.t8122_dcpext_v27_admission, ((),), ()), ('boot', 'v27-tag-translation', boot.v27_tag_translation, ((),), ()), ('edid', 'dpavserv-start', edid.startup, ((),), ()), ('edid', 'service-rebind', edid.rebind, ((),), ()),