diff --git a/arch/arm64/boot/dts/apple/t8132-j773g.dts b/arch/arm64/boot/dts/apple/t8132-j773g.dts index 4f26103dda7e9..879b2676783aa 100644 --- a/arch/arm64/boot/dts/apple/t8132-j773g.dts +++ b/arch/arm64/boot/dts/apple/t8132-j773g.dts @@ -54,9 +54,9 @@ * Every node is disabled. On macOS 27.2 the boot loader (aura) fills * dcpext0's firmware memory and firmware clocks, leaves the main DCP running * idle, and enables the display subsystem on iBoot's framebuffer; the display - * gate (drivers/soc/apple/display-gate.c) then enables this chain and points - * the display subsystem at dispext0's DART. On the M4 26.6.2 firmware path - * none of it is enabled from here. + * gate (drivers/soc/apple/display-gate.c) then enables the admitted external + * chains and points the display subsystem at their scanout DARTs. On the M4 + * 26.6.2 firmware path none of it is enabled from here. */ / { reserved-memory { @@ -81,6 +81,27 @@ no-map; status = "disabled"; }; + + dcpext1_text: dcpext1-text { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + + dcpext1_data: dcpext1-data { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + + dcpext1_heap: dcpext1-heap { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; }; }; @@ -123,6 +144,17 @@ apple,always-on; }; +/* + * The M4 Air PMGR policy disables ps_dptx_phy; J773g wires lpdptx_phy and + * its boot framebuffer to it. Keep the domain enabled and always on so + * lpdptx_phy does not defer the display subsystem and Linux never powers it + * off under iBoot's HDMI boot framebuffer (e.g. during s2idle or nomodeset). + */ +&ps_dptx_phy { + apple,always-on; + status = "okay"; +}; + &dcpext0_mbox { /delete-property/ power-domains; }; @@ -155,6 +187,97 @@ memory-region-names = "text", "data", "heap"; }; +/* + * Stage 2 only admits a powered pipe. Keep the firmware's state of its + * parents, including an off pipe on a boot without an external display. + * Its CPU remains under hardware control. + */ +&ps_dispext1_sys { + apple,firmware-owned; +}; + +&ps_dispext1_fe { + apple,firmware-owned; +}; + +&dcpext1_mbox { + /delete-property/ power-domains; +}; + +&dcpext1_dart { + /delete-property/ power-domains; +}; + +&dispext1_dart { + /delete-property/ power-domains; +}; + +/* + * dcpext1 feeds the three rear ports through UFP endpoint 2, port 0 + * (selector 4). Stage 2 needs the processor and its DART disabled while + * validating the live handoff. The display gate then enables its chain. + */ +&dcpext1 { + /delete-property/ power-domains; + apple,connector-type = "USB-C"; + phys = <&atcphy0 PHY_TYPE_DP>, <&atcphy1 PHY_TYPE_DP>, <&atcphy3 PHY_TYPE_DP>; + phy-names = "typec0", "typec1", "typec2"; + mux-controls = <&atc0_dpxbar 0>, <&atc1_dpxbar 0>, + <&atc0_dpxbar 1>, <&atc0_dpxbar 2>, + <&atc1_dpxbar 1>, <&atc1_dpxbar 2>, + <&atc3_dpxbar 0>, <&atc3_dpxbar 1>, <&atc3_dpxbar 2>; + mux-control-names = "typec0", "typec1", + "typec0-dpin0", "typec0-dpin1", + "typec1-dpin0", "typec1-dpin1", + "typec2", "typec2-dpin0", "typec2-dpin1"; + apple,typec-mux-indices = <4 4 4>; + apple,typec-dptx-phys = <0 1 3>; + + memory-region = <&dcpext1_text>, <&dcpext1_data>, <&dcpext1_heap>; + memory-region-names = "text", "data", "heap"; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + status = "disabled"; + + port { + dcpext1_typec0: endpoint { + remote-endpoint = <&typec0_dcpext1>; + }; + }; + }; + + route@1 { + reg = <1>; + mode-switch; + status = "disabled"; + + port { + dcpext1_typec1: endpoint { + remote-endpoint = <&typec1_dcpext1>; + }; + }; + }; + + route@2 { + reg = <2>; + mode-switch; + status = "disabled"; + + port { + dcpext1_typec3: endpoint { + remote-endpoint = <&typec3_dcpext1>; + }; + }; + }; + }; +}; + /* * Without this, the PMP firmware faults in the PMC block (0x382800000) * shortly after it starts on this board. J713 keeps ps_pmc out of Linux @@ -195,12 +318,50 @@ }; }; +&atc0_dpxbar { + status = "okay"; +}; + +&atcphy0 { + apple,dp-alt-mode; +}; + +&atc1_dpxbar { + status = "okay"; +}; + +&atcphy1 { + apple,dp-alt-mode; +}; + +&atc3_dpxbar { + status = "okay"; +}; + &typec0 { label = "USB-C Back Middle"; + + ports { + port@3 { + reg = <3>; + typec0_dcpext1: endpoint { + remote-endpoint = <&dcpext1_typec0>; + }; + }; + }; }; &typec1 { label = "USB-C Back Left"; + + ports { + port@3 { + reg = <3>; + typec1_dcpext1: endpoint { + remote-endpoint = <&dcpext1_typec1>; + }; + }; + }; }; /* ATC3's port controller (ADT nub-spmi-a0 hpm3). */ @@ -237,12 +398,20 @@ remote-endpoint = <&atcphy3_typec_lanes>; }; }; + + port@3 { + reg = <3>; + typec3_dcpext1: endpoint { + remote-endpoint = <&dcpext1_typec3>; + }; + }; }; }; }; }; &atcphy3 { + apple,dp-alt-mode; status = "okay"; ports { diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index ab20d7fa91e95..1539f9cb2d6f5 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -493,7 +493,8 @@ config APPLE_CLPC config APPLE_DISPLAY_GATE bool "Apple internal display enable gate" - depends on ARCH_APPLE && OF_DYNAMIC && OF_OVERLAY + depends on ARCH_APPLE || (COMPILE_TEST && KUNIT) + depends on OF_DYNAMIC && OF_OVERLAY default ARCH_APPLE help The T6030 device tree keeps the internal display nodes disabled so @@ -572,7 +573,8 @@ config APPLE_DISPLAY_GATE_KUNIT_TEST that binds late still powers the external displays up. On the J616c: each external display chain is enabled without a PMP once its processor has firmware memory, and the display subsystem's - status is never written. + status is never written. On T8132: keep the scanout DARTs of just the + admitted HDMI, Type-C and internal display pipes. config APPLE_AURORA_BOOT_SECURITY tristate "Report how the boot chain verified this boot" diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 7cfc1004d2a36..f9cbc2475dd64 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -40,7 +40,8 @@ apple-display-gate-y := display-gate.o t6030-pmp.dtbo.o t6030-j516s-pmp.dtbo.o apple-display-gate-$(CONFIG_APPLE_DISPLAY_GATE_KUNIT_TEST) += t6031-gate-test.dtbo.o \ t6030-gate-test.dtbo.o \ t8122-gate-test.dtbo.o \ - t6041-gate-test.dtbo.o + t6041-gate-test.dtbo.o \ + t8132-gate-test.dtbo.o # The gate adds the interrupt parent from the base tree at boot. DTC_FLAGS_t6030-pmp := -Wno-interrupts_property DTC_FLAGS_t6030-j516s-pmp := -Wno-interrupts_property diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index 66fa36af14c90..b542bbd79c372 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -40,6 +40,8 @@ extern const u8 __dtbo_t8122_gate_test_begin[]; extern const u8 __dtbo_t8122_gate_test_end[]; extern const u8 __dtbo_t6041_gate_test_begin[]; extern const u8 __dtbo_t6041_gate_test_end[]; +extern const u8 __dtbo_t8132_gate_test_begin[]; +extern const u8 __dtbo_t8132_gate_test_end[]; /* One SoC's test tree and what the gate should make of it. */ struct gt_soc { @@ -220,7 +222,7 @@ static void __init gt_run(struct kunit *test) struct gate_test *t = test->priv; KUNIT_ASSERT_EQ(test, of_changeset_apply(&t->cs), 0); - gate_run(); + gate_run(true); } static bool __init gt_okay(struct kunit *test, const char *path) @@ -877,12 +879,6 @@ static void __init gt_expect_dcpext(struct kunit *test, bool enabled, const u64 gt_expect_dcpext_mode(test, enabled, enabled, window); } -static void __init gt_require_display_driver(struct kunit *test) -{ - if (!IS_ENABLED(CONFIG_DRM_APPLE)) - kunit_skip(test, "the gate keeps the dcpext off without the display driver"); -} - /* Without the boot loader's firmware-ready mark the dcpext stays disabled. */ static void __init gate_t8122_dcpext_not_ready(struct kunit *test) { @@ -894,7 +890,6 @@ static void __init gate_t8122_dcpext_not_ready(struct kunit *test) /* On 14.7.0 it starts with the device tree's windows. */ static void __init gate_t8122_dcpext_v14_7(struct kunit *test) { - gt_require_display_driver(test); gt_t8122_dcpext_firmware(test, gt_v14_7, gt_v14_7); gt_run(test); gt_expect_dcpext(test, true, NULL); @@ -904,7 +899,6 @@ static void __init gate_t8122_dcpext_v14_7(struct kunit *test) /* The boot loader's default marker (<2>) is accepted alongside <1>. */ static void __init gate_t8122_dcpext_loader_default_marker(struct kunit *test) { - gt_require_display_driver(test); gt_add_u32(test, GT_T8122_DCPEXT, "apple,t8122-dcpext-firmware-ready", 2); gt_set_u32_array(test, GT_T8122_DCPEXT, "apple,firmware-version", gt_v14_7, 3); gt_set_u32_array(test, GT_T8122_DCPEXT, "apple,firmware-compat", gt_v14_7, 3); @@ -925,7 +919,6 @@ static void __init gate_t8122_dcpext_other_marker(struct kunit *test) /* apple,no-shared-display-dart keeps dispext0_dart out and leaves fbdma on. */ static void __init gate_t8122_dcpext_board_mirrors(struct kunit *test) { - gt_require_display_driver(test); gt_t8122_dcpext_firmware(test, gt_v14_7, gt_v14_7); gt_add_bool(test, GT_T8122_DCPEXT, "apple,no-shared-display-dart"); gt_run(test); @@ -945,7 +938,6 @@ static void __init gate_t8122_dcpext_board_no_fbdma(struct kunit *test) /* On 27.2 with apple,no-shared-display-dart, DARTs get the panel window and fbdma stays on. */ static void __init gate_t8122_dcpext_v27_2_mirrors(struct kunit *test) { - gt_require_display_driver(test); gt_t8122_dcp_v27_2(test); gt_t8122_dcpext_firmware(test, gt_v27_2, gt_v27_2); gt_add_bool(test, GT_T8122_DCPEXT, "apple,no-shared-display-dart"); @@ -959,7 +951,6 @@ static void __init gate_t8122_dcpext_v27_2_mirrors(struct kunit *test) */ static void __init gate_t8122_dcpext_v27_2(struct kunit *test) { - gt_require_display_driver(test); gt_t8122_dcp_v27_2(test); gt_t8122_dcpext_firmware(test, gt_v27_2, gt_v27_2); gt_run(test); @@ -1008,7 +999,6 @@ static void __init gate_t8122_dcpext_other_firmware(struct kunit *test) /* Without the panel's window there is none to give it: nothing changes. */ static void __init gate_t8122_dcpext_v27_2_no_panel_window(struct kunit *test) { - gt_require_display_driver(test); gt_t8122_dcp_v27_2(test); gt_t8122_dcpext_firmware(test, gt_v27_2, gt_v27_2); gt_remove(test, "/t8122-soc/iommu@28d30c000", "apple,dma-range"); @@ -1485,8 +1475,8 @@ 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]) +static void __init gt_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; @@ -1511,8 +1501,8 @@ static void __init gate_t6041_max_unapproved_firmware27(struct kunit *test) 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_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); @@ -1527,10 +1517,10 @@ static void __init gate_t6041_max_v27_2(struct kunit *test) 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_set_dcp_fw(test, "/dcp@402e00000", APPLE_T6041_DCP_26B123_UUID, compat); + gt_set_dcp_fw(test, "/dcp@602e00000", APPLE_T6041_DCP_26B123_UUID, compat); + gt_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); @@ -1564,6 +1554,161 @@ static struct kunit_suite gate_t6041_max_suite __refdata = { .test_cases = gate_t6041_max_cases, }; +static const struct gt_soc gt_t8132 __initconst = { + .soc = &gate_t8132, + .fixture = __dtbo_t8132_gate_test_begin, + .fixture_end = __dtbo_t8132_gate_test_end, +}; + +static int gt_fixture_t8132 __initdata = -1; + +static int __init gt_t8132_suite_init(struct kunit_suite *suite) +{ + return gt_apply_fixture(>_t8132, >_fixture_t8132); +} + +static int __init gt_t8132_init(struct kunit *test) +{ + return gt_init(test, >_t8132); +} + +#define M4_TEST "/t8132-gate-test/" +#define M4_PANEL BIT(0) +#define M4_EXT0 BIT(1) +#define M4_EXT1 BIT(2) + +static void __init gt_t8132_check(struct kunit *test, unsigned int handoff, bool typec_driver) +{ + static const char * const pipes[] = { "panel", "hdmi", "typec" }; + static const char * const scanout[] = { "internal-dart", "fixed-dart", "typec-dart" }; + static const char * const laptop_nodes[] = { "panel", "typec", "typec-fw", "typec-dart", + "typec-mailbox" }; + struct device_node *display = gt_node(test, M4_TEST "display"); + struct device_node *internal = gt_node(test, M4_TEST "panel"); + struct gate_test *t = test->priv; + unsigned int expected = handoff & (typec_driver ? ~0U : ~M4_EXT1); + unsigned int i, seen = 0; + struct of_changeset cs; + struct of_phandle_args args; + bool laptop = handoff & M4_PANEL; + bool hdmi = !laptop && (expected & M4_EXT0); + char path[80]; + + for (i = 0; i < ARRAY_SIZE(pipes); i++) { + if (!(handoff & BIT(i))) + continue; + snprintf(path, sizeof(path), M4_TEST "%s", laptop && i == 1 ? "typec0" : pipes[i]); + gt_set_dcp_fw(test, path, APPLE_T8132_DCP_26B123_UUID, gt_v27_2); + } + if (laptop && (handoff & M4_EXT0)) { + gt_set_string(test, M4_TEST "typec0", "status", "okay"); + gt_set_string(test, M4_TEST "fixed-mailbox", "status", "okay"); + gt_set_string(test, M4_TEST "fixed-dart", "status", "okay"); + gt_set_string(test, M4_TEST "fixed-fw", "status", "okay"); + } + if (laptop) { + for (i = 0; i < ARRAY_SIZE(laptop_nodes); i++) { + snprintf(path, sizeof(path), M4_TEST "%s", laptop_nodes[i]); + gt_set_string(test, path, "status", "okay"); + } + } + KUNIT_ASSERT_EQ(test, of_changeset_apply(&t->cs), 0); + of_changeset_init(&cs); + KUNIT_ASSERT_EQ(test, gate_t8132_prepare(&cs, display, internal, false, true, + typec_driver), 0); + KUNIT_ASSERT_EQ(test, of_changeset_apply(&cs), 0); + KUNIT_EXPECT_EQ(test, of_device_is_available(display), !!expected); + KUNIT_EXPECT_EQ(test, gt_okay(test, M4_TEST "hdmi"), hdmi); + KUNIT_EXPECT_EQ(test, gt_okay(test, M4_TEST "hdmi/piodma"), hdmi); + KUNIT_EXPECT_EQ(test, gt_okay(test, M4_TEST "fixed-phy"), hdmi); + KUNIT_EXPECT_EQ(test, gt_okay(test, M4_TEST "typec/piodma"), !!(expected & M4_EXT1)); + KUNIT_EXPECT_EQ(test, gt_okay(test, M4_TEST "typec/typec-routes/route"), + !!(expected & M4_EXT1)); + KUNIT_EXPECT_EQ(test, gt_okay(test, M4_TEST "typec0/typec-routes/route"), + laptop && (expected & M4_EXT0)); + if (expected) { + KUNIT_EXPECT_EQ(test, of_count_phandle_with_args(display, "iommus", "#iommu-cells"), + (int)hweight32(expected)); + for (i = 0; !of_parse_phandle_with_args(display, "iommus", "#iommu-cells", + i, &args); i++) { + unsigned int j; + + KUNIT_EXPECT_TRUE(test, of_device_is_available(args.np)); + KUNIT_EXPECT_EQ(test, args.args_count, 1); + KUNIT_EXPECT_EQ(test, args.args[0], 0); + for (j = 0; j < ARRAY_SIZE(scanout); j++) + if (of_node_name_eq(args.np, scanout[j])) + seen |= BIT(j); + of_node_put(args.np); + } + KUNIT_EXPECT_EQ(test, seen, expected); + } else { + KUNIT_EXPECT_FALSE(test, gt_okay(test, M4_TEST "internal-dart")); + } + of_changeset_revert(&cs); + of_changeset_destroy(&cs); +} + +static void __init gate_t8132_usbc_only(struct kunit *test) +{ + gt_t8132_check(test, M4_EXT1, true); +} + +static void __init gate_t8132_headless(struct kunit *test) +{ + gt_t8132_check(test, 0, true); +} + +static void __init gate_t8132_hdmi_only(struct kunit *test) +{ + gt_t8132_check(test, M4_EXT0, true); +} + +static void __init gate_t8132_hdmi_and_usbc(struct kunit *test) +{ + gt_t8132_check(test, M4_EXT0 | M4_EXT1, true); +} + +static void __init gate_t8132_panel_and_usbc(struct kunit *test) +{ + gt_t8132_check(test, M4_PANEL | M4_EXT1, true); +} + +static void __init gate_t8132_panel_and_two_usbc(struct kunit *test) +{ + gt_t8132_check(test, M4_PANEL | M4_EXT0 | M4_EXT1, true); +} + +static void __init gate_t8132_panel_only(struct kunit *test) +{ + gt_t8132_check(test, M4_PANEL, true); +} + +static void __init gate_t8132_no_typec_driver(struct kunit *test) +{ + gt_t8132_check(test, M4_EXT1, false); +} + +static struct kunit_case gate_t8132_cases[] __refdata = { + KUNIT_CASE(gate_t8132_usbc_only), + KUNIT_CASE(gate_t8132_headless), + KUNIT_CASE(gate_t8132_hdmi_only), + KUNIT_CASE(gate_t8132_hdmi_and_usbc), + KUNIT_CASE(gate_t8132_panel_and_usbc), + KUNIT_CASE(gate_t8132_panel_and_two_usbc), + KUNIT_CASE(gate_t8132_panel_only), + KUNIT_CASE(gate_t8132_no_typec_driver), + {} +}; + +static struct kunit_suite gate_t8132_suite __refdata = { + .name = "apple-display-gate-t8132", + .suite_init = gt_t8132_suite_init, + .init = gt_t8132_init, + .exit = gt_exit, + .test_cases = gate_t8132_cases, +}; + /* T6030 first: the T6031 and T8122 trees describe a PMP, which it refuses. */ kunit_test_init_section_suites(&gate_t6030_suite, &gate_t6031_suite, &gate_t8122_suite, - &gate_t6041_suite, &gate_t6041_max_suite); + &gate_t6041_suite, &gate_t6041_max_suite, &gate_t8132_suite); diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 9f97a6ca034a5..ce20ddaf2a82e 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -86,14 +86,10 @@ * processor has that memory and the display subsystem is enabled, before any * device exists (see gate_t6041_max_run()). * - * On T8132 (apple,t8132) off the M4 26.6.2 firmware path (first the Mac mini, - * J773g, on macOS 27.2), aura hands over external display processors as on the - * J575c: it fills their firmware memory, adds their firmware clocks, and - * enables the display subsystem on iBoot's boot framebuffer. For any - * apple,t8132-dcpext with a fixed dp-phy running the pinned 27.2 image, the - * gate derives the chain from its phandles and enables it in one changeset - * (see gate_t8132_run()). On the M4 26.6.2 firmware path (and on M4 Airs) the - * J713 dcpext routes below apply instead. + * On T8132 the firmware-27 handoff supplies the image identity, firmware + * memory and clocks of each external processor. Enable each complete HDMI + * or Type-C chain with its scanout mapping. The 26.6.2 firmware-ready + * handoff keeps its own Type-C route policy. */ #define pr_fmt(fmt) fmt @@ -118,7 +114,6 @@ #include #include #include -#include #include #include #include @@ -356,10 +351,11 @@ static const struct gate_soc gate_t6041_max __initconst = { static void __init gate_t8132_run(void); /* - * T8132 off the M4 26.6.2 firmware path (the Airs take - * gate_j713_dcpext_routes() before gate_socs[] is walked): enable any - * fixed-DP external display chain (phy-names = "dp-phy") running the pinned - * 27.2 image, as on the J575c. + * T8132 external display gate (both the legacy 26.6.2/Air path after + * gate_j713_dcpext_routes() and off-firmware-path 27.2 boots): enable + * admitted fixed-DP and Type-C external display chains on the pinned 27.2 + * image, or retire the display subsystem on panel-less boots with no + * admitted pipe. */ static const struct gate_soc gate_t8132 __initconst = { .machine = "apple,t8132", @@ -2058,7 +2054,7 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) of_node_put(dart); } -static void __init gate_t8122_dcpext(bool panel) +static void __init gate_t8122_dcpext(bool panel, bool display_driver) { struct device_node *np; @@ -2070,7 +2066,7 @@ static void __init gate_t8122_dcpext(bool panel) * driver's mode switches: without a display driver that would * take USB from both ports of a J613. */ - else if (!IS_ENABLED(CONFIG_DRM_APPLE)) + else if (!display_driver) gate_ext_refuse(np, "the display driver is not built"); else if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) gate_ext_refuse(np, "nomodeset is on the command line"); @@ -2079,7 +2075,7 @@ static void __init gate_t8122_dcpext(bool panel) } } -static void __init gate_run(void) +static void __init gate_run(bool display_driver) { struct device_node *np[GATE_NR_NODES] = {}; struct device_node *ps[PMP_PS_NR] = {}; @@ -2100,7 +2096,7 @@ static void __init gate_run(void) if (gate_soc->dcpext) gate_dcpext(panel ? NULL : "the internal display was not handed over"); if (gate_soc == &gate_t8122) - gate_t8122_dcpext(panel); + gate_t8122_dcpext(panel, display_driver); gate_reuse_put(); of_node_put(aic); for (i = 0; i < PMP_PS_NR; i++) @@ -3528,54 +3524,6 @@ static void __init gate_j713_dcpext_routes(void) gate_cs_free(cs); } -/* - * A T8132 dcpext on its Type-C routes handed over with the 27.2 image (the - * MacBook Air's (J713) dcpext0 and dcpext1 on macOS 27.2): aura hands it over - * as it hands over the J773g's (its firmware memory, the 26B123 image and its - * pipe's firmware clocks) beside the internal display, and writes no - * apple,t8132-dcpext-firmware-ready: it runs the firmware-27 backend as a - * pipe of the internal display's DRM device (apple_t8132_dcpext_v27_2()), - * not the M4 one. Its node and DARTs are enabled in the tree already. - * - * Enable the Type-C routes and the PIODMA child of each such dcpext, and add - * its display DART (its PIODMA's) to the display subsystem's iommus, in one - * changeset: the scanout of every pipe goes through the display subsystem's - * domain. Only - * once the internal handoff has enabled the display subsystem; a dcpext - * without firmware memory or with another image is left as it is. - */ -static int __init gate_t8132_v27_dispext_dart(struct device_node *dcp, struct device_node **dart) -{ - struct of_phandle_args args; - struct device_node *piodma; - int ret; - - piodma = of_get_child_by_name(dcp, "piodma"); - if (!piodma) - return -ENODEV; - ret = of_parse_phandle_with_args(piodma, "iommus", "#iommu-cells", 0, &args); - of_node_put(piodma); - if (ret) - return ret; - *dart = args.np; - return 0; -} - -/* Its PIODMA child is disabled in the SoC tree, as for the J773g: enable it. */ -static int __init gate_t8132_v27_piodma(struct of_changeset *cs, struct device_node *dcp) -{ - struct device_node *piodma; - int ret = 0; - - piodma = of_get_child_by_name(dcp, "piodma"); - if (!piodma) - return -ENODEV; - if (!of_device_is_available(piodma)) - ret = of_changeset_update_prop_string(cs, piodma, "status", "okay"); - of_node_put(piodma); - return ret; -} - static bool __init gate_t8132_v27_memory(struct device_node *dcp) { struct device_node *region; @@ -3608,14 +3556,14 @@ static bool __init gate_has_typec_routes(struct device_node *dcp) } /* - * The display subsystem's iommus with each display DART in @darts that it - * does not name yet appended once, on the stream ID the subsystem uses on its - * own display DART (its first entry): the scanout of every pipe has the same - * stream layout. + * Every pipe scans out on the same stream. A laptop keeps its existing + * scanout DARTs. Without the internal pipe, replace its unusable mapping + * with exactly the DARTs of the admitted external pipes. */ static int __init gate_t8132_v27_display_iommus(struct of_changeset *cs, struct device_node *display, - struct device_node *const *darts, unsigned int n) + struct device_node *const *darts, unsigned int n, + bool keep_scanout) { bool present[2] = {}; struct of_phandle_args args; @@ -3636,7 +3584,7 @@ static int __init gate_t8132_v27_display_iommus(struct of_changeset *cs, if (one_cell && !i) sid = args.args[0]; for (k = 0; k < n; k++) - if (args.np == darts[k]) + if (keep_scanout && args.np == darts[k]) present[k] = true; of_node_put(args.np); if (!one_cell) @@ -3650,6 +3598,8 @@ static int __init gate_t8132_v27_display_iommus(struct of_changeset *cs, if (!nr || of_count_phandle_with_args(display, "iommus", "#iommu-cells") != (int)nr || old->length != 2 * nr * sizeof(*value)) return -EINVAL; + if (!keep_scanout) + nr = 0; for (k = 0; k < n; k++) { if (!darts[k]->phandle) return -EINVAL; @@ -3670,7 +3620,7 @@ static int __init gate_t8132_v27_display_iommus(struct of_changeset *cs, kfree(value); return -ENOMEM; } - memcpy(value, old->value, old->length); + memcpy(value, old->value, 2 * nr * sizeof(*value)); for (i = 2 * nr, k = 0; k < n; k++) { if (present[k]) continue; @@ -3693,440 +3643,200 @@ static int __init gate_t8132_v27_display_iommus(struct of_changeset *cs, } /* - * Selected by its nodes alone, on any board and either firmware path: an - * available T8132 dcpext handed over with the 27.2 image - * (apple_t8132_dcpext_v27_2()) that has Type-C routes, its text, data and - * heap firmware memory, and an enabled display subsystem. A fixed-PHY dcpext - * (the J773g's HDMI dcpext0) has no Type-C routes and keeps its own chain. + * A panel-less Stage 2 leaves each external chain disabled. Laptops can + * supply an already enabled Type-C processor and providers. In both cases + * its PIODMA and routes become usable only with the scanout domain. */ -static void __init gate_t8132_dcpext_v27(void) -{ - struct device_node *darts[2] = {}, *display, *np; - const char *why = NULL; - struct of_changeset *cs; - unsigned int n = 0, i; - int ret = 0; +static int __init gate_t8132_pipe(struct of_changeset *cs, struct device_node *dcp, + struct device_node **scanout, bool typec, const char **reason) +{ + enum { FW_DART, DISP_DART, MBOX, PHY, PIODMA, DCP, NR_NODES }; + static const char *const missing_reasons[NR_NODES] = { + [FW_DART] = "invalid or missing firmware DART", + [DISP_DART] = "invalid or missing scanout DART", + [MBOX] = "missing mailbox", + [PHY] = "missing fixed dp-phy", + [PIODMA] = "missing piodma", + [DCP] = "missing dcp", + }; + struct device_node *nodes[NR_NODES] = {}; + struct of_phandle_args args; + bool available = of_device_is_available(dcp); + int phy, i, j, ret = -ENODEV; - display = of_find_compatible_node(NULL, NULL, "apple,t8132-display-subsystem"); - if (!display) - return; - /* - * As for the J613 (gate_t8122_dcpext()): enabled routes make the - * Type-C port controllers wait for the display driver's mode switches. - * Without a T8132 display driver, not built or kept off by nomodeset, - * none registers and USB is lost on both ports. - */ - if (!IS_ENABLED(CONFIG_DRM_APPLE) || !IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132)) - why = "the T8132 display driver is not built"; - else if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) - why = "nomodeset is on the command line"; - if (why) { - pr_info("apple-t8132-display: 27.2 dcpext Type-C routes left disabled: %s\n", why); - of_node_put(display); - return; + if (!gate_t8132_v27_memory(dcp)) { + *reason = "no firmware memory"; + return -ENODEV; } - cs = gate_cs_alloc(); - if (!cs) { - of_node_put(display); - return; + if (!of_property_present(dcp, "apple,clock-ids")) { + *reason = "no firmware clocks"; + return -ENODEV; } - for_each_compatible_node(np, NULL, "apple,t8132-dcpext") { - if (!of_device_is_available(np) || !apple_t8132_dcpext_v27_2(np)) - continue; - /* A fixed-PHY (HDMI) dcpext has its own chain. */ - if (!gate_has_typec_routes(np)) - continue; - if (!gate_t8132_v27_memory(np)) { - pr_info("apple-t8132-display: %pOF: 27.2 image without firmware memory, left off\n", - np); - continue; + if (!typec) { + if (available) { + *reason = "fixed-DP processor already enabled"; + return -ENODEV; + } + phy = of_property_match_string(dcp, "phy-names", "dp-phy"); + if (phy < 0 || + of_parse_phandle_with_args(dcp, "phys", "#phy-cells", phy, &args)) { + *reason = "no fixed dp-phy"; + return -ENODEV; } - if (!of_device_is_available(display)) { - pr_info("apple-t8132-display: %pOF: display subsystem not enabled, left off\n", - np); + nodes[PHY] = args.np; + } + if (of_parse_phandle_with_args(dcp, "mboxes", "#mbox-cells", 0, &args)) { + *reason = "no mailbox"; + goto out; + } + nodes[MBOX] = args.np; + nodes[DCP] = of_node_get(dcp); + nodes[PIODMA] = of_get_child_by_name(dcp, "piodma"); + /* apple-dart mirrors locked roots for DARTs named by this clocked DCP. */ + nodes[FW_DART] = gate_target(dcp, "iommus", "#iommu-cells", 1, 23, "apple,t8132-dart"); + nodes[DISP_DART] = gate_target(nodes[PIODMA], "iommus", "#iommu-cells", 1, 16, + "apple,t8132-dart"); + + for (i = 0; i < NR_NODES; i++) { + /* Type-C PHYs also serve USB. Only a fixed PHY belongs to this chain. */ + if (i == PHY && typec) continue; + if (!nodes[i]) { + *reason = missing_reasons[i]; + goto out; } - if (n == ARRAY_SIZE(darts)) { - ret = -E2BIG; - of_node_put(np); - break; + if (!of_device_is_available(nodes[i]) && + of_property_match_string(nodes[i], "status", "disabled") < 0) { + *reason = "unexpected provider status"; + goto out; } - ret = gate_t8132_v27_dispext_dart(np, &darts[n]); - if (!ret) - ret = gate_t8132_v27_piodma(cs, np); - if (!ret) - ret = gate_ext_routes(cs, np, "okay"); - if (ret) { - of_node_put(np); - break; + /* A pre-enabled laptop pipe can still have its PIODMA disabled. */ + if (of_device_is_available(nodes[i]) != available && !(i == PIODMA && available)) { + *reason = "mixed enabled state"; + goto out; } - n++; + for (j = 0; j < i; j++) + if (nodes[i] == nodes[j]) { + *reason = "duplicate provider node"; + goto out; + } } - if (!ret && n) - ret = gate_t8132_v27_display_iommus(cs, display, darts, n); - if (!ret && n) - ret = of_changeset_apply(cs); - - for (i = 0; i < ARRAY_SIZE(darts); i++) - of_node_put(darts[i]); - of_node_put(display); - if (ret) - pr_err("apple-t8132-display: 27.2 dcpext Type-C routes left disabled: %d\n", ret); - else if (n) - pr_info("apple-t8132-display: 27.2: Type-C routes and display DARTs enabled for %u dcpext(s)\n", - n); - /* Applied, it stays: the live tree refers to it. */ - if (ret || !n) - gate_cs_free(cs); -} - -/* The display subsystem's iommus become <@dart 0>, whatever they were. */ -static int __init gate_iommus_set(struct of_changeset *cs, struct device_node *display, - struct device_node *dart) -{ - struct property *prop; - __be32 *value; - if (!dart->phandle) - return -EINVAL; - prop = kzalloc_obj(*prop); - value = kmalloc(2 * sizeof(*value), GFP_KERNEL); - if (!prop || !value) { - kfree(prop); - kfree(value); - return -ENOMEM; - } - value[0] = cpu_to_be32(dart->phandle); - value[1] = cpu_to_be32(0); - prop->name = "iommus"; - prop->length = 2 * sizeof(*value); - prop->value = value; - return of_changeset_update_property(cs, display, prop); -} - -enum { - T8132_HDMI_PHY, - T8132_HDMI_FW_DART, - T8132_HDMI_DISP_DART, - T8132_HDMI_MBOX, - T8132_HDMI_PIODMA, - T8132_HDMI_DCP, - T8132_HDMI_NR, -}; - -/* - * Check that every memory-region of @np is an available apple,asc-mem node, - * as staged_firmware_memory() does for path-addressed stages. - */ -static bool __init staged_node_firmware_memory(struct device_node *np) -{ - struct device_node *chosen, *region; - int i, n; - u32 record[2]; - - n = of_count_phandle_with_args(np, "memory-region", NULL); - for (i = 0; i < n; i++) { - region = of_parse_phandle(np, "memory-region", i); - if (region && of_device_is_available(region) && - of_device_is_compatible(region, "apple,asc-mem")) { - of_node_put(region); + for (i = 0; i < NR_NODES; i++) { + if (!nodes[i] || of_device_is_available(nodes[i])) continue; - } - of_node_put(region); - n = -ENODEV; - break; + ret = of_changeset_update_prop_string(cs, nodes[i], "status", "okay"); + if (ret) + goto out; } - if (n > 0) - return true; - chosen = of_find_node_by_path("/chosen"); - if (chosen && !of_property_read_u32_array(chosen, "m4,dcpext", record, 2)) - staged_err("%pOF: no firmware memory (loader record <%u %u>), nothing enabled\n", - np, record[0], record[1]); - else - staged_err("%pOF: no firmware memory, nothing enabled\n", np); - of_node_put(chosen); - return false; -} - -/* - * A T8132 internal display processor handed over with the 27.2 (26B123) image - * and firmware-27 clock metadata (apple,clock-ids): present on a laptop with - * an internal panel (e.g. a 14-inch MacBook Pro), absent on a headless Mac - * mini whose main DCP is left running idle. - */ -static bool __init gate_t8132_dcp_v27_2(const struct device_node *np) -{ - return apple_dcp_image_v27_2(np, "apple,t8132-dcp", - APPLE_T8132_DCP_26B123_UUID) && - of_property_present(np, "apple,clock-ids"); -} - -static void __init gate_t8132_put_nodes(struct device_node *nodes[T8132_HDMI_NR]) -{ - unsigned int i; - - for (i = 0; i < T8132_HDMI_NR; i++) { + ret = typec ? gate_ext_routes(cs, dcp, "okay") : 0; + if (!ret) + *scanout = of_node_get(nodes[DISP_DART]); +out: + for (i = 0; i < NR_NODES; i++) of_node_put(nodes[i]); - nodes[i] = NULL; - } + return ret; } -/* - * Derive a fixed-DP T8132 dcpext's chain from its own DT phandles: the dp-phy - * PHY, firmware DART (iommus), display DART (piodma's iommus), mailbox - * (mboxes), piodma child, then the dcpext node itself. - */ -static int __init gate_t8132_resolve_fixed_dp(struct device_node *dcp, - int phy_idx, - struct device_node *nodes[T8132_HDMI_NR]) +/* Build one changeset so no enabled pipe can precede its scanout mapping. */ +static int __init gate_t8132_prepare(struct of_changeset *cs, struct device_node *display, + struct device_node *internal, bool legacy, + bool modeset, bool typec_driver) { + struct device_node *darts[2] = {}; struct of_phandle_args args; + /* + * On panel Macs (J713/J715, J604, J623/J624), aura always hands over + * the internal DCP when bringing up the 27.2 display stack; without an + * admitted internal DCP (e.g. headless J773g), disp0's scanout mapping + * is unusable and is replaced or retired. + */ + bool panel = legacy || (of_device_is_available(internal) && + apple_t8132_dcp_v27_2(internal)); + unsigned int n = 0, i; + int ret = 0; - memset(nodes, 0, T8132_HDMI_NR * sizeof(*nodes)); - - if (of_parse_phandle_with_args(dcp, "phys", "#phy-cells", phy_idx, &args)) - goto fail; - nodes[T8132_HDMI_PHY] = args.np; - - if (of_parse_phandle_with_args(dcp, "iommus", "#iommu-cells", 0, &args)) - goto fail; - nodes[T8132_HDMI_FW_DART] = args.np; - - if (of_parse_phandle_with_args(dcp, "mboxes", "#mbox-cells", 0, &args)) - goto fail; - nodes[T8132_HDMI_MBOX] = args.np; - - nodes[T8132_HDMI_PIODMA] = of_get_child_by_name(dcp, "piodma"); - if (!nodes[T8132_HDMI_PIODMA]) - goto fail; - - if (of_parse_phandle_with_args(nodes[T8132_HDMI_PIODMA], "iommus", - "#iommu-cells", 0, &args)) - goto fail; - nodes[T8132_HDMI_DISP_DART] = args.np; - - nodes[T8132_HDMI_DCP] = of_node_get(dcp); - return 0; - -fail: - gate_t8132_put_nodes(nodes); - return -EINVAL; -} - -/* Every node of @nodes is distinct and still disabled, and its processor has firmware memory. */ -static bool __init gate_t8132_fixed_dp_ready(struct device_node *nodes[T8132_HDMI_NR]) -{ - unsigned int i, j; + if (!of_device_is_available(display)) + return 0; + for_each_compatible_node_scoped(dcp, NULL, "apple,t8132-dcpext") { + bool typec = gate_has_typec_routes(dcp); + struct device_node *dart = NULL; + const char *reason = NULL; - if (!staged_node_firmware_memory(nodes[T8132_HDMI_DCP])) - return false; - for (i = 0; i < T8132_HDMI_NR; i++) { - if (!nodes[i]) - return false; - for (j = 0; j < i; j++) { - if (nodes[j] == nodes[i]) { - staged_err("%pOF: duplicate node in chain, nothing enabled\n", - nodes[i]); - return false; - } + if (!modeset || !apple_t8132_dcpext_v27_2(dcp) || (typec && !typec_driver) || + (legacy && (!typec || !of_device_is_available(dcp)))) + continue; + ret = gate_t8132_pipe(cs, dcp, &dart, typec, &reason); + if (ret == -ENODEV) { + pr_info("apple-t8132-display: incomplete handoff for %pOF (%s)\n", + dcp, reason ? reason : "unknown"); + ret = 0; + continue; } - if (of_device_is_available(nodes[i])) { - staged_err("%pOF: already enabled, nothing changed\n", nodes[i]); - return false; + if (ret) + goto out; + if (n == ARRAY_SIZE(darts)) { + of_node_put(dart); + ret = -E2BIG; + goto out; + } + darts[n++] = dart; + } + if (n) { + ret = gate_t8132_v27_display_iommus(cs, display, darts, n, panel); + } else if (!panel) { + ret = of_changeset_update_prop_string(cs, display, "status", "disabled"); + /* The parked internal processor can still own its PIODMA DART. */ + for (i = 0; !ret && !of_device_is_available(internal) && + !of_parse_phandle_with_args(display, "iommus", "#iommu-cells", i, &args); + i++) { + if (of_device_is_available(args.np)) + ret = of_changeset_update_prop_string(cs, args.np, "status", + "disabled"); + of_node_put(args.np); } } - /* - * The processor runs on through the handover, behind DARTs the boot - * loader leaves locked: adopting it needs apple-dart to keep their - * firmware roots. Off that, the firmware DART's probe fails (-EBUSY on - * the J773g), the processor and its PHY never probe, and the display - * subsystem never binds. - */ - if (!apple_dart_keeps_locked_roots(nodes[T8132_HDMI_FW_DART]) || - !apple_dart_keeps_locked_roots(nodes[T8132_HDMI_DISP_DART])) { - staged_info("%pOF: the firmware roots of %pOF and %pOF are not kept, HDMI left off\n", - nodes[T8132_HDMI_DCP], nodes[T8132_HDMI_FW_DART], - nodes[T8132_HDMI_DISP_DART]); - return false; - } - return true; +out: + for (i = 0; i < n; i++) + of_node_put(darts[i]); + return ret; } -/* - * A headless T8132 (no internal display processor handed over on 27.2) whose - * HDMI chain stays off: the display subsystem the boot loader enabled for it - * has no processor left to bind, since the main DCP is the M4 backend's on its - * firmware path only (apple_dcp_usable()). Left enabled it never registers, - * and the GPU, whose first start follows a handed-over display, waits for it - * for good. Disable it, as when the boot loader hands over no display: the - * boot framebuffer stays, and the GPU starts on it. Its DART (disp0's), which - * the boot loader enabled with it, goes too unless the main DCP, whose piodma - * also maps through it, is enabled. - */ -static void __init gate_t8132_display_off(void) +static void __init gate_t8132_run(void) { - struct device_node *display, *internal; - struct of_phandle_args args; + struct device_node *display __free(device_node) = + of_find_compatible_node(NULL, NULL, gate_t8132.display_compat); + struct device_node *internal __free(device_node) = + of_find_compatible_node(NULL, NULL, gate_t8132.dcp_compat); + bool legacy = apple_t8132_firmware_path(); struct of_changeset *cs; - bool panel, internal_on; - int i, ret; + bool modeset; + int ret; - display = of_find_node_by_path("disp0"); - if (!display) - display = of_find_compatible_node(NULL, NULL, gate_soc->display_compat); - if (!display || !of_device_is_compatible(display, gate_soc->display_compat) || - !of_device_is_available(display)) { - of_node_put(display); + if (!of_device_is_available(display)) return; - } - internal = of_find_node_by_path("dcp"); - if (!internal) - internal = of_find_compatible_node(NULL, NULL, gate_soc->dcp_compat); - panel = gate_t8132_dcp_v27_2(internal); - internal_on = of_device_is_available(internal); - of_node_put(internal); - if (panel) { - of_node_put(display); - return; - } - cs = gate_cs_alloc(); - if (!cs) { - staged_err("%pOF: could not allocate changeset\n", display); - of_node_put(display); + if (!cs) return; - } - ret = of_changeset_update_prop_string(cs, display, "status", "disabled"); - for (i = 0; !ret && !internal_on && - !of_parse_phandle_with_args(display, "iommus", "#iommu-cells", i, &args); i++) { - if (of_device_is_available(args.np)) - ret = of_changeset_update_prop_string(cs, args.np, "status", "disabled"); - of_node_put(args.np); - } - if (!ret) - ret = of_changeset_apply(cs); - if (ret) { + modeset = IS_ENABLED(CONFIG_DRM_APPLE) && + !(IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()); + ret = gate_t8132_prepare(cs, display, internal, legacy, modeset, + IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132)); + if (ret && modeset && !legacy) { + pr_err("apple-t8132-display: could not prepare display handoff (%d), retiring display\n", + ret); gate_cs_free(cs); - staged_err("%pOF: could not disable it without HDMI: %d\n", display, ret); - } else { - staged_info("no HDMI chain and no internal display: %pOF disabled, boot framebuffer kept\n", - display); - } - of_node_put(display); -} - -/* - * T8132 on macOS 27.2 (off the M4 26.6.2 firmware path): any apple,t8132-dcpext - * wired to a fixed DP PHY (phy-names = "dp-phy", e.g. the J773g HDMI port) - * runs through the firmware-27 backend (apple_t8132_dcpext_v27_2()). Its chain - * is derived from its DT phandles and enabled in one changeset once aura has - * given it firmware memory and enabled the display subsystem, and only for the - * pinned 27.2 image. - * - * When the main DCP is also handed over on 27.2 (a T8132 laptop with an - * internal panel), dispext's display DART is appended to the display - * subsystem's iommus so the internal panel keeps its DART. When the main DCP - * is not handed over (a headless Mac mini), disp0's DART is left unprobed by - * apple-dart and would hold the display subsystem's probe forever, so iommus - * is replaced with dispext's DART instead. - * - * With no chain enabled (no handover, a refused one, or nomodeset), a headless - * T8132 boots as without this gate: see gate_t8132_display_off(). - */ -static void __init gate_t8132_run(void) -{ - struct device_node *display = NULL, *internal, *dcp; - struct device_node *nodes[T8132_HDMI_NR]; - bool append_dart = false; - bool display_checked = false; - bool enabled = false; - unsigned int i; - int phy_idx, ret; - - staged_prefix = gate_soc->prefix; - if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) { - gate_t8132_display_off(); - return; - } - - for_each_compatible_node(dcp, NULL, "apple,t8132-dcpext") { - struct of_changeset *cs; - - phy_idx = of_property_match_string(dcp, "phy-names", "dp-phy"); - if (phy_idx < 0) - continue; - - if (!apple_t8132_dcpext_v27_2(dcp)) { - if (of_property_present(dcp, "apple,firmware-compat")) - staged_info("%pOF: not the 27.2 (26B123) image, HDMI left off\n", - dcp); - continue; - } - - if (!display_checked) { - display_checked = true; - display = of_find_node_by_path("disp0"); - if (!display) - display = of_find_compatible_node(NULL, NULL, - gate_soc->display_compat); - if (!display || !of_device_is_compatible(display, - gate_soc->display_compat)) { - staged_err("no display subsystem, HDMI left off\n"); - of_node_put(display); - of_node_put(dcp); - return; - } - if (!of_device_is_available(display)) { - staged_info("display subsystem not enabled, HDMI left off\n"); - of_node_put(display); - of_node_put(dcp); - return; - } - internal = of_find_node_by_path("dcp"); - if (!internal) - internal = of_find_compatible_node(NULL, NULL, - gate_soc->dcp_compat); - append_dart = gate_t8132_dcp_v27_2(internal); - of_node_put(internal); - } - - if (gate_t8132_resolve_fixed_dp(dcp, phy_idx, nodes)) { - staged_err("%pOF: incomplete fixed-DP chain, HDMI left off\n", dcp); - continue; - } - if (!gate_t8132_fixed_dp_ready(nodes)) { - gate_t8132_put_nodes(nodes); - continue; - } - cs = gate_cs_alloc(); - if (!cs) { - staged_err("%pOF: could not allocate changeset\n", dcp); - gate_t8132_put_nodes(nodes); - continue; - } - ret = append_dart ? - gate_iommus_append(cs, display, nodes[T8132_HDMI_DISP_DART]) : - gate_iommus_set(cs, display, nodes[T8132_HDMI_DISP_DART]); - for (i = 0; !ret && i < T8132_HDMI_NR; i++) - ret = of_changeset_update_prop_string(cs, nodes[i], "status", "okay"); - if (!ret) - ret = of_changeset_apply(cs); - if (ret) { - gate_cs_free(cs); - staged_err("%pOF: could not enable the HDMI chain: %d\n", dcp, ret); - } else { - staged_info("%pOF enabled for HDMI; display subsystem %s %pOF\n", dcp, - append_dart ? "appended" : "on", - nodes[T8132_HDMI_DISP_DART]); - append_dart = true; - enabled = true; - } - gate_t8132_put_nodes(nodes); + if (!cs) + return; + ret = gate_t8132_prepare(cs, display, internal, false, false, false); } - of_node_put(display); - if (!enabled) - gate_t8132_display_off(); + if (!ret && !list_empty(&cs->entries)) + ret = of_changeset_apply(cs); + if (ret) + pr_err("apple-t8132-display: could not apply display handoff: %d\n", ret); + if (ret || list_empty(&cs->entries)) + gate_cs_free(cs); } static void __init apple_display_gate_soc(void) @@ -4135,6 +3845,7 @@ static void __init apple_display_gate_soc(void) if (apple_t8132_firmware_path()) { gate_j713_dcpext_routes(); + gate_t8132_run(); return; } @@ -4157,19 +3868,13 @@ static void __init apple_display_gate_soc(void) if (gate_soc->run) gate_soc->run(); else - gate_run(); + gate_run(IS_ENABLED(CONFIG_DRM_APPLE)); } /* Runs before of_platform_default_populate_init() at arch_initcall_sync. */ static int __init apple_display_gate(void) { apple_display_gate_soc(); - /* - * After the SoC's own gate, which may set the display subsystem's - * iommus (the J773g's HDMI chain): the 27.2 Type-C dcpexts' display - * DARTs are appended to whatever it left. - */ - gate_t8132_dcpext_v27(); return 0; } arch_initcall(apple_display_gate); diff --git a/drivers/soc/apple/t8132-gate-test.dtso b/drivers/soc/apple/t8132-gate-test.dtso new file mode 100644 index 0000000000000..dadba02f23cad --- /dev/null +++ b/drivers/soc/apple/t8132-gate-test.dtso @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/dts-v1/; +/plugin/; + +&{/} { + t8132-gate-test { + status = "disabled"; + + display { + iommus = <&m4_internal_dart 0>; + }; + + panel { + compatible = "apple,t8132-dcp"; + apple,clock-ids = <1>; + status = "disabled"; + }; + + m4_internal_dart: internal-dart { + #iommu-cells = <1>; + }; + + m4_fixed_phy: fixed-phy { + #phy-cells = <0>; + status = "disabled"; + }; + + m4_text: text { compatible = "apple,asc-mem"; }; + m4_data: data { compatible = "apple,asc-mem"; }; + m4_heap: heap { compatible = "apple,asc-mem"; }; + + m4_fixed_fw: fixed-fw { + compatible = "apple,t8132-dart", "apple,t8110-dart"; + #iommu-cells = <1>; + status = "disabled"; + }; + + m4_fixed_dart: fixed-dart { + compatible = "apple,t8132-dart", "apple,t8110-dart"; + #iommu-cells = <1>; + status = "disabled"; + }; + + m4_fixed_mailbox: fixed-mailbox { + #mbox-cells = <0>; + status = "disabled"; + }; + + hdmi { + compatible = "apple,t8132-dcpext"; + mboxes = <&m4_fixed_mailbox>; + iommus = <&m4_fixed_fw 23>; + memory-region = <&m4_text>, <&m4_data>, <&m4_heap>; + apple,clock-ids = <2>; + phy-names = "dp-phy"; + phys = <&m4_fixed_phy>; + status = "disabled"; + + piodma { + iommus = <&m4_fixed_dart 16>; + status = "disabled"; + }; + }; + + m4_typec_fw: typec-fw { + compatible = "apple,t8132-dart", "apple,t8110-dart"; + #iommu-cells = <1>; + status = "disabled"; + }; + + m4_typec_dart: typec-dart { + compatible = "apple,t8132-dart", "apple,t8110-dart"; + #iommu-cells = <1>; + status = "disabled"; + }; + + m4_typec_mailbox: typec-mailbox { + #mbox-cells = <0>; + status = "disabled"; + }; + + typec { + compatible = "apple,t8132-dcpext"; + mboxes = <&m4_typec_mailbox>; + iommus = <&m4_typec_fw 23>; + memory-region = <&m4_text>, <&m4_data>, <&m4_heap>; + apple,clock-ids = <2>; + status = "disabled"; + + piodma { + iommus = <&m4_typec_dart 16>; + status = "disabled"; + }; + + typec-routes { + route { + mode-switch; + status = "disabled"; + }; + }; + }; + + /* Alternative wiring of the first external pipe on a laptop. */ + typec0 { + compatible = "apple,t8132-dcpext"; + mboxes = <&m4_fixed_mailbox>; + iommus = <&m4_fixed_fw 23>; + memory-region = <&m4_text>, <&m4_data>, <&m4_heap>; + apple,clock-ids = <2>; + status = "disabled"; + + piodma { + iommus = <&m4_fixed_dart 16>; + status = "disabled"; + }; + + typec-routes { + route { + mode-switch; + status = "disabled"; + }; + }; + }; + }; +}; diff --git a/tools/asahi/t8132-display-gate-tests.py b/tools/asahi/t8132-display-gate-tests.py index 01fb832783e50..8b742bfc6eaba 100755 --- a/tools/asahi/t8132-display-gate-tests.py +++ b/tools/asahi/t8132-display-gate-tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only OR MIT -"""Host tests for the T8132 fixed-DP display gate (drivers/soc/apple/display-gate.c).""" +"""Host tests for the T8132 external display gate (drivers/soc/apple/display-gate.c).""" import os from pathlib import Path import re @@ -35,9 +35,8 @@ def main(): gate_src = (ROOT / 'drivers/soc/apple/display-gate.c').read_text() disp_hdr = (ROOT / 'include/linux/soc/apple/display.h').read_text() t8132_hdr = (ROOT / 'include/linux/soc/apple/t8132.h').read_text() - dart_hdr = (ROOT / 'include/linux/soc/apple/dart.h').read_text() - # Enforce at source level that T8132 fixed-DP gate matches the SoC, not a board name, + # Enforce at source level that T8132 display gate matches the SoC, not a board name, # and carries no hard-coded board node paths. soc_block = extract_block(gate_src, r'^static const struct gate_soc gate_t8132\b') assert '.machine = "apple,t8132"' in soc_block, soc_block @@ -51,19 +50,17 @@ def main(): helpers = '\n'.join([ uuid_lines, extract_block(disp_hdr, r'^static inline bool apple_dcp_image_v27_2\('), + extract_block(disp_hdr, r'^static inline bool apple_t8132_dcp_v27_2\('), extract_block(t8132_hdr, r'^static inline bool apple_t8132_dcpext_v27_2\('), - extract_block(dart_hdr, r'^static inline bool apple_dart_keeps_locked_roots\('), - extract_block(gate_src, r'^static int gate_iommus_append\('), + extract_block(gate_src, r'^static struct device_node \*__init gate_target\('), extract_block(gate_src, r'^static struct of_changeset \*__init gate_cs_alloc\('), extract_block(gate_src, r'^static void __init gate_cs_free\('), - extract_block(gate_src, r'^static int __init gate_iommus_set\('), - extract_block(gate_src, r'^enum \{\n\tT8132_HDMI_PHY,'), - extract_block(gate_src, r'^static bool __init staged_node_firmware_memory\('), - extract_block(gate_src, r'^static bool __init gate_t8132_dcp_v27_2\('), - extract_block(gate_src, r'^static void __init gate_t8132_put_nodes\('), - extract_block(gate_src, r'^static int __init gate_t8132_resolve_fixed_dp\('), - extract_block(gate_src, r'^static bool __init gate_t8132_fixed_dp_ready\('), - extract_block(gate_src, r'^static void __init gate_t8132_display_off\('), + extract_block(gate_src, r'^static int __init gate_ext_routes\('), + extract_block(gate_src, r'^static bool __init gate_t8132_v27_memory\('), + extract_block(gate_src, r'^static bool __init gate_has_typec_routes\('), + extract_block(gate_src, r'^static int __init gate_t8132_v27_display_iommus\('), + extract_block(gate_src, r'^static int __init gate_t8132_pipe\('), + extract_block(gate_src, r'^static int __init gate_t8132_prepare\('), extract_block(gate_src, r'^static void __init gate_t8132_run\('), ]) @@ -82,10 +79,12 @@ def main(): #define __initconst #define GFP_KERNEL 0 #define CONFIG_VIDEO 1 +#define CONFIG_DRM_APPLE 1 +#define CONFIG_DRM_APPLE_DCP_T8132 1 #define IS_ENABLED(x) (x) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define kzalloc_obj(x) calloc(1, sizeof(x)) -#define kmalloc(n, g) malloc(n) +#define kmalloc_array(n, sz, g) calloc((n), (sz)) #define kfree(p) free(p) static __be32 cpu_to_be32(u32 v) { return __builtin_bswap32(v); } @@ -99,22 +98,28 @@ def main(): const char *display_compat; }; -static const struct gate_soc test_soc = { +static const struct gate_soc gate_t8132 = { .machine = "apple,t8132", .prefix = "apple-t8132-display: ", .name = "T8132", .dcp_compat = "apple,t8132-dcp", .display_compat = "apple,t8132-display-subsystem", }; -static const struct gate_soc *gate_soc = &test_soc; -static const char *staged_prefix; static bool nomodeset; +static bool legacy_fw_path; static unsigned int err_count, info_count; -#define staged_info(...) do { (void)staged_prefix; info_count++; } while (0) -#define staged_err(...) do { (void)staged_prefix; err_count++; } while (0) +static void count_log(unsigned int *cnt, const char *fmt, ...) +{ + (void)fmt; + (*cnt)++; +} + +#define pr_info(fmt, ...) count_log(&info_count, fmt, ##__VA_ARGS__) +#define pr_err(fmt, ...) count_log(&err_count, fmt, ##__VA_ARGS__) static bool video_firmware_drivers_only(void) { return nomodeset; } +static bool apple_t8132_firmware_path(void) { return legacy_fw_path; } struct property { const char *name; @@ -127,6 +132,7 @@ def main(): const char *alias; const char *name; const char *compatible; + const char *status; u32 phandle; bool available; int refcount; @@ -158,6 +164,9 @@ def main(): int mem_region_count; struct device_node *piodma_child; + struct device_node *typec_routes_child; + struct device_node *children[4]; + int child_count; }; struct of_phandle_args { @@ -173,18 +182,37 @@ def main(): struct property *prop; }; +struct list_head { + unsigned int *nops; +}; + struct of_changeset { - struct cs_op ops[16]; + struct list_head entries; + struct cs_op ops[32]; unsigned int nops; bool applied; }; +static bool list_empty(const struct list_head *h) +{ + return !h->nops || *h->nops == 0; +} + #define MAX_NODES 32 static struct device_node *all_nodes[MAX_NODES]; static unsigned int nr_nodes; static struct of_changeset *applied_cs[8]; static unsigned int nr_applied_cs; +static const char *node_status(const struct device_node *np) +{ + if (!np) + return NULL; + if (np->status) + return np->status; + return np->available ? "okay" : "disabled"; +} + static void sync_iommus_prop(struct device_node *np) { int i; @@ -219,6 +247,13 @@ def main(): } } +static void __free_device_node(struct device_node **p) +{ + of_node_put(*p); +} + +#define __free(name) __attribute__((cleanup(__free_##name))) + static bool of_device_is_compatible(const struct device_node *np, const char *compat) { return np && np->compatible && !strcmp(np->compatible, compat); @@ -248,11 +283,19 @@ def main(): 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->fw_uuid_count < 1 || !np->fw_uuid) + if (!np) return -EINVAL; - *out = np->fw_uuid; - return 0; + if (!strcmp(name, "apple,firmware-uuid")) { + if (np->fw_uuid_count < 1 || !np->fw_uuid) + return -EINVAL; + *out = np->fw_uuid; + return 0; + } + if (!strcmp(name, "status")) { + *out = node_status(np); + return *out ? 0 : -EINVAL; + } + return -EINVAL; } static int of_property_count_u32_elems(const struct device_node *np, const char *name) @@ -286,9 +329,11 @@ def main(): { int i; - assert(!strcmp(prop, "phy-names")); if (!np) return -EINVAL; + if (!strcmp(prop, "status")) + return !strcmp(node_status(np), val) ? 0 : -ENODATA; + assert(!strcmp(prop, "phy-names")); for (i = 0; i < np->phy_name_count; i++) { if (np->phy_names[i] && !strcmp(np->phy_names[i], val)) return i; @@ -316,6 +361,8 @@ def main(): return np->mem_region_count; if (!strcmp(list, "iommus")) return np->iommu_count; + if (!strcmp(list, "mboxes")) + return np->mbox_count; return -EINVAL; } @@ -360,22 +407,43 @@ def main(): static struct device_node *of_get_child_by_name(const struct device_node *np, const char *name) { - assert(!strcmp(name, "piodma")); - return (np && np->piodma_child) ? of_node_get(np->piodma_child) : NULL; + if (!np) + return NULL; + if (!strcmp(name, "piodma")) + return np->piodma_child ? of_node_get(np->piodma_child) : NULL; + if (!strcmp(name, "typec-routes")) + return np->typec_routes_child ? of_node_get(np->typec_routes_child) : NULL; + return NULL; } -static struct device_node *of_find_node_by_path(const char *path) +static int of_get_child_count(const struct device_node *np) { - unsigned int i; + return np ? np->child_count : 0; +} - for (i = 0; i < nr_nodes; i++) { - if ((all_nodes[i]->path && !strcmp(all_nodes[i]->path, path)) || - (all_nodes[i]->alias && !strcmp(all_nodes[i]->alias, path))) - return of_node_get(all_nodes[i]); +static struct device_node *of_get_next_child(const struct device_node *parent, + struct device_node *prev) +{ + int i = 0; + + if (prev) { + if (parent) { + while (i < parent->child_count && parent->children[i] != prev) + i++; + if (i < parent->child_count) + i++; + } + of_node_put(prev); } - return NULL; + if (!parent || i >= parent->child_count || !parent->children[i]) + return NULL; + return of_node_get(parent->children[i]); } +#define for_each_child_of_node(parent, child) \ + for (child = of_get_next_child(parent, NULL); child; \ + child = of_get_next_child(parent, child)) + static struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compat) { @@ -396,8 +464,9 @@ def main(): return NULL; } -#define for_each_compatible_node(dn, type, compatible) \ - for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ +#define for_each_compatible_node_scoped(dn, type, compatible) \ + for (struct device_node *dn __free(device_node) = \ + of_find_compatible_node(NULL, type, compatible); dn; \ dn = of_find_compatible_node(dn, type, compatible)) static struct device_node *find_by_phandle(u32 phandle) @@ -414,6 +483,7 @@ def main(): static void of_changeset_init(struct of_changeset *cs) { memset(cs, 0, sizeof(*cs)); + cs->entries.nops = &cs->nops; } static void of_changeset_destroy(struct of_changeset *cs) @@ -454,6 +524,7 @@ def main(): struct cs_op *op = &cs->ops[i]; if (op->is_status) { + op->np->status = op->status; op->np->available = !strcmp(op->status, "okay"); } else { const __be32 *vals = op->prop->value; @@ -477,18 +548,12 @@ def main(): return 0; } ''' + helpers + r''' -/* - * A DART kind whose locked firmware roots apple-dart keeps - * (apple_dart_keeps_locked_roots()). The J773g's own, apple,t8132-dart, is not - * one in this tree: see j773g_darts(). - */ -#define KEPT_DART "apple,t6041-dart" - struct fixture { struct device_node display, disp0_dart, main_dcp; struct device_node phy, fw_dart, disp_dart, mbox, piodma, dcpext0; struct device_node mem_text, mem_data, mem_heap; - struct device_node dcpext1; + struct device_node tc_fw_dart, tc_disp_dart, tc_mbox, tc_piodma; + struct device_node tc_routes, tc_route0, tc_route1, dcpext1; }; static void register_node(struct device_node *np) @@ -526,17 +591,27 @@ def main(): np->fw_compat_cells = 3; } +static void clear_fw(struct device_node *np) +{ + np->fw_uuid = NULL; + np->fw_uuid_count = 0; + np->fw_ver_cells = 0; + np->fw_compat_cells = 0; +} + static void init_fixture(struct fixture *f) { cleanup_applied(); memset(f, 0, sizeof(*f)); nr_nodes = 0; nomodeset = false; + legacy_fw_path = false; err_count = info_count = 0; /* Deliberately use non-J773g paths to prove resolution is phandle-driven. */ f->disp0_dart = (struct device_node){ - .path = "/soc/iommu@111100000", .phandle = 10, .available = false, + .path = "/soc/iommu@111100000", .compatible = "apple,t8132-dart", + .phandle = 10, .available = false, }; f->display = (struct device_node){ .path = "/soc/display-subsystem", .alias = "disp0", @@ -555,11 +630,11 @@ def main(): .path = "/soc/phy@999700000", .phandle = 20, .available = false, }; f->fw_dart = (struct device_node){ - .path = "/soc/iommu@999340000", .compatible = KEPT_DART, + .path = "/soc/iommu@999340000", .compatible = "apple,t8132-dart", .phandle = 21, .available = false, }; f->disp_dart = (struct device_node){ - .path = "/soc/iommu@999300000", .compatible = KEPT_DART, + .path = "/soc/iommu@999300000", .compatible = "apple,t8132-dart", .phandle = 22, .available = false, }; f->mbox = (struct device_node){ @@ -584,7 +659,7 @@ def main(): f->dcpext0 = (struct device_node){ .path = "/soc/dcp@999e00000", .compatible = "apple,t8132-dcpext", - .phandle = 25, .available = false, + .phandle = 25, .available = false, .has_clock_ids = true, .phy_names = { "dp-phy" }, .phy_name_count = 1, .phys = { &f->phy }, .iommus = { &f->fw_dart }, .iommu_args = { 23 }, .iommu_count = 1, .mboxes = { &f->mbox }, .mbox_count = 1, @@ -595,13 +670,45 @@ def main(): sync_iommus_prop(&f->dcpext0); set_v27_2(&f->dcpext0); - /* Second dcpext without dp-phy (Type-C only): must stay untouched. */ + /* Second dcpext on Type-C routes (not handed over by default). */ + f->tc_fw_dart = (struct device_node){ + .path = "/soc/iommu@888340000", .compatible = "apple,t8132-dart", + .phandle = 31, .available = false, + }; + f->tc_disp_dart = (struct device_node){ + .path = "/soc/iommu@888300000", .compatible = "apple,t8132-dart", + .phandle = 32, .available = false, + }; + f->tc_mbox = (struct device_node){ + .path = "/soc/mailbox@888e08000", .phandle = 33, .available = false, + }; + f->tc_piodma = (struct device_node){ + .path = "/soc/dcp@888e00000/piodma", .name = "piodma", + .phandle = 34, .available = false, + .iommus = { &f->tc_disp_dart }, .iommu_args = { 16 }, .iommu_count = 1, + }; + sync_iommus_prop(&f->tc_piodma); + f->tc_route0 = (struct device_node){ + .path = "/soc/dcp@888e00000/typec-routes/route@0", .available = false, + }; + f->tc_route1 = (struct device_node){ + .path = "/soc/dcp@888e00000/typec-routes/route@1", .available = false, + }; + f->tc_routes = (struct device_node){ + .path = "/soc/dcp@888e00000/typec-routes", .available = true, + .children = { &f->tc_route0, &f->tc_route1 }, .child_count = 2, + }; f->dcpext1 = (struct device_node){ .path = "/soc/dcp@888e00000", .compatible = "apple,t8132-dcpext", - .phandle = 30, .available = false, - .phy_names = { "typec0" }, .phy_name_count = 1, .phys = { &f->phy }, + .phandle = 35, .available = false, .has_clock_ids = true, + .iommus = { &f->tc_fw_dart }, .iommu_args = { 23 }, .iommu_count = 1, + .mboxes = { &f->tc_mbox }, .mbox_count = 1, + .mem_regions = { &f->mem_text, &f->mem_data, &f->mem_heap }, + .mem_region_count = 3, + .piodma_child = &f->tc_piodma, + .typec_routes_child = &f->tc_routes, }; - set_v27_2(&f->dcpext1); + sync_iommus_prop(&f->dcpext1); register_node(&f->disp0_dart); register_node(&f->display); @@ -615,28 +722,21 @@ def main(): register_node(&f->mem_data); register_node(&f->mem_heap); register_node(&f->dcpext0); + register_node(&f->tc_fw_dart); + register_node(&f->tc_disp_dart); + register_node(&f->tc_mbox); + register_node(&f->tc_piodma); + register_node(&f->tc_route0); + register_node(&f->tc_route1); + register_node(&f->tc_routes); register_node(&f->dcpext1); } -/* The J773g's dcpext0 DARTs, which this tree's apple-dart does not keep the locked roots of. */ -static void j773g_darts(struct fixture *f) -{ - f->fw_dart.compatible = "apple,t8132-dart"; - f->disp_dart.compatible = "apple,t8132-dart"; -} - /* Stage 2 published nothing for the dcpexts: no image, placeholders, no display. */ static void no_handover(struct fixture *f) { - struct device_node *dcps[] = { &f->dcpext0, &f->dcpext1 }; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(dcps); i++) { - dcps[i]->fw_uuid = NULL; - dcps[i]->fw_uuid_count = 0; - dcps[i]->fw_ver_cells = 0; - dcps[i]->fw_compat_cells = 0; - } + clear_fw(&f->dcpext0); + clear_fw(&f->dcpext1); f->mem_text.available = f->mem_data.available = f->mem_heap.available = false; f->display.available = false; } @@ -679,7 +779,7 @@ def main(): assert(f->display.iommu_count == 1 && f->display.iommus[0] == &f->disp0_dart); } -static void expect_chain(struct fixture *f, bool enabled) +static void expect_fixed_chain(struct fixture *f, bool enabled) { assert(f->phy.available == enabled); assert(f->fw_dart.available == enabled); @@ -687,7 +787,17 @@ def main(): assert(f->mbox.available == enabled); assert(f->piodma.available == enabled); assert(f->dcpext0.available == enabled); - assert(!f->dcpext1.available); +} + +static void expect_typec_chain(struct fixture *f, bool enabled) +{ + assert(f->tc_fw_dart.available == enabled); + assert(f->tc_disp_dart.available == enabled); + assert(f->tc_mbox.available == enabled); + assert(f->tc_piodma.available == enabled); + assert(f->tc_route0.available == enabled); + assert(f->tc_route1.available == enabled); + assert(f->dcpext1.available == enabled); } int main(void) @@ -695,67 +805,135 @@ def main(): struct snapshot snap; struct fixture f; - /* 1. Headless T8132 (J773g-like): phandle-derived chain enabled; disp0 iommus replaced. */ + /* 1. Headless T8132 HDMI only: phandle-derived chain enabled; disp0 iommus replaced. */ init_fixture(&f); gate_t8132_run(); - expect_chain(&f, true); + expect_fixed_chain(&f, true); + expect_typec_chain(&f, false); + assert(f.display.available); assert(f.display.iommu_count == 1); assert(f.display.iommus[0] == &f.disp_dart && f.display.iommu_args[0] == 0); + assert(err_count == 0); check_refs_zero(); - /* 2. Laptop T8132 (14" MBP-like): main DCP handed over on 27.2 -> disp0 iommus appended. */ + /* 2. Headless T8132 Type-C only: dcpext1 admitted without retiring display subsystem. */ + init_fixture(&f); + clear_fw(&f.dcpext0); + set_v27_2(&f.dcpext1); + gate_t8132_run(); + expect_fixed_chain(&f, false); + expect_typec_chain(&f, true); + assert(f.display.available); + assert(f.display.iommu_count == 1); + assert(f.display.iommus[0] == &f.tc_disp_dart && f.display.iommu_args[0] == 0); + assert(err_count == 0); + check_refs_zero(); + + /* 3. Headless T8132 HDMI + Type-C: both chains enabled and both display DARTs mapped. */ + init_fixture(&f); + set_v27_2(&f.dcpext1); + gate_t8132_run(); + expect_fixed_chain(&f, true); + expect_typec_chain(&f, true); + assert(f.display.available); + assert(f.display.iommu_count == 2); + assert(f.display.iommus[0] == &f.disp_dart && f.display.iommu_args[0] == 0); + assert(f.display.iommus[1] == &f.tc_disp_dart && f.display.iommu_args[1] == 0); + assert(err_count == 0); + check_refs_zero(); + + /* 4. Laptop T8132: main DCP available on 27.2 -> disp0 iommus appended. */ init_fixture(&f); set_v27_2(&f.main_dcp); f.main_dcp.has_clock_ids = true; + f.main_dcp.available = true; + f.disp0_dart.available = true; gate_t8132_run(); - expect_chain(&f, true); + expect_fixed_chain(&f, true); + expect_typec_chain(&f, false); assert(f.display.iommu_count == 2); assert(f.display.iommus[0] == &f.disp0_dart && f.display.iommu_args[0] == 0); assert(f.display.iommus[1] == &f.disp_dart && f.display.iommu_args[1] == 0); + assert(err_count == 0); check_refs_zero(); - /* 3. Main DCP with 27.2 image but no apple,clock-ids (idle) -> replaced, not appended. */ + /* 5. Main DCP with 27.2 image but no apple,clock-ids (idle) -> replaced, not appended. */ init_fixture(&f); set_v27_2(&f.main_dcp); f.main_dcp.has_clock_ids = false; + f.main_dcp.available = true; gate_t8132_run(); - expect_chain(&f, true); + expect_fixed_chain(&f, true); assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp_dart); + assert(err_count == 0); check_refs_zero(); /* - * 4-7: a refused chain on a headless T8132 leaves the display subsystem the + * 6-11: a refused chain on a headless T8132 leaves the display subsystem the * boot loader enabled, and its DART, disabled: the GPU starts on the boot * framebuffer. */ - /* 4. Unapproved firmware UUID on dcpext0 -> chain stays disabled, disp0 unchanged. */ + /* 6. Unapproved firmware UUID on dcpext0 -> chain stays disabled, disp0 disabled. */ init_fixture(&f); f.disp0_dart.available = true; f.dcpext0.fw_uuid = "00000000-0000-0000-0000-000000000000"; gate_t8132_run(); - expect_chain(&f, false); + expect_fixed_chain(&f, false); expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0); check_refs_zero(); - /* 5. Placeholder (disabled) memory-region -> refused whole. */ + /* 7. Placeholder (disabled) memory-region -> refused whole. */ init_fixture(&f); f.disp0_dart.available = true; f.mem_heap.available = false; gate_t8132_run(); - expect_chain(&f, false); + expect_fixed_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0 && info_count == 1); + check_refs_zero(); + + /* 8. Missing apple,clock-ids on dcpext0 -> refused whole. */ + init_fixture(&f); + f.disp0_dart.available = true; + f.dcpext0.has_clock_ids = false; + gate_t8132_run(); + expect_fixed_chain(&f, false); expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0 && info_count == 1); check_refs_zero(); - /* 6. Missing phandle (e.g. no piodma child) -> refused whole. */ + /* 9. Missing phandle (no piodma child) -> refused whole. */ init_fixture(&f); f.disp0_dart.available = true; f.dcpext0.piodma_child = NULL; gate_t8132_run(); - expect_chain(&f, false); + expect_fixed_chain(&f, false); expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0 && info_count == 1); check_refs_zero(); - /* 7. Any chain node already enabled -> refused whole, DART not modified. */ + /* 10. Wrong DART compatible or stream ID -> refused whole. */ + init_fixture(&f); + f.disp0_dart.available = true; + f.fw_dart.compatible = "apple,t6041-dart"; + gate_t8132_run(); + expect_fixed_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0 && info_count == 1); + check_refs_zero(); + + init_fixture(&f); + f.disp0_dart.available = true; + f.piodma.iommu_args[0] = 15; + sync_iommus_prop(&f.piodma); + gate_t8132_run(); + expect_fixed_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0 && info_count == 1); + check_refs_zero(); + + /* 11. Any fixed-DP chain node already enabled -> refused whole. */ init_fixture(&f); f.disp0_dart.available = true; f.phy.available = true; @@ -764,118 +942,131 @@ def main(): assert(!f.fw_dart.available && !f.disp_dart.available && !f.mbox.available && !f.piodma.available && !f.dcpext0.available); expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0 && info_count == 1); check_refs_zero(); - /* 8. Disabled display subsystem -> chain stays disabled. */ + /* 12. Disabled display subsystem -> chain stays disabled, no changeset. */ init_fixture(&f); f.display.available = false; + take_snapshot(&f, &snap); gate_t8132_run(); - expect_chain(&f, false); - assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + expect_unchanged(&f, &snap); + assert(err_count == 0 && info_count == 0); check_refs_zero(); - /* - * 9. No fixed dp-phy on any dcpext -> no chain, no error; the display - * subsystem has nothing to bind and goes. - */ + /* 13. No fixed dp-phy and no typec-routes -> incomplete handoff, display goes. */ init_fixture(&f); f.disp0_dart.available = true; f.dcpext0.phy_names[0] = "typec1"; gate_t8132_run(); - expect_chain(&f, false); + expect_fixed_chain(&f, false); expect_gpu_on_boot_framebuffer(&f); assert(err_count == 0 && info_count == 1); check_refs_zero(); - /* 10. nomodeset -> no chain; drm/apple does not register, so neither does the display. */ + /* 14. nomodeset -> no chain; drm/apple does not register, so neither does display. */ init_fixture(&f); f.disp0_dart.available = true; + set_v27_2(&f.dcpext1); nomodeset = true; gate_t8132_run(); - expect_chain(&f, false); + expect_fixed_chain(&f, false); + expect_typec_chain(&f, false); expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0); check_refs_zero(); - /* - * 11. No handover (Stage 2 published nothing for the dcpexts): no change - * from a tree without this gate. Nothing is enabled or disabled, disp0's - * iommus stay, and nothing is logged. - */ + /* 15. No handover (display already disabled) -> untouched, nothing logged. */ init_fixture(&f); no_handover(&f); take_snapshot(&f, &snap); gate_t8132_run(); expect_unchanged(&f, &snap); + nomodeset = true; + gate_t8132_run(); + expect_unchanged(&f, &snap); assert(err_count == 0 && info_count == 0); check_refs_zero(); - /* 11b. The same with the J773g's DARTs, and under nomodeset. */ + /* 16. Laptop with no external handoff: display subsystem and disp0 DART stay. */ init_fixture(&f); - no_handover(&f); - j773g_darts(&f); + clear_fw(&f.dcpext0); + set_v27_2(&f.main_dcp); + f.main_dcp.has_clock_ids = true; + f.main_dcp.available = true; + f.disp0_dart.available = true; take_snapshot(&f, &snap); gate_t8132_run(); expect_unchanged(&f, &snap); - nomodeset = true; - gate_t8132_run(); - expect_unchanged(&f, &snap); + assert(err_count == 0); check_refs_zero(); - /* - * 12. The J773g on 27.2 with this tree: Stage 2 handed dcpext0 over and - * enabled the display subsystem and disp0's DART, but apple-dart keeps no - * locked roots of a T8132 DART. The chain stays off and the display goes, - * so the GPU starts on the boot framebuffer as without the handover. - */ + /* 17. Headless, main DCP enabled (no 27.2): display goes, disp0 DART stays. */ init_fixture(&f); - j773g_darts(&f); + clear_fw(&f.dcpext0); + f.main_dcp.available = true; f.disp0_dart.available = true; gate_t8132_run(); - expect_chain(&f, false); - expect_gpu_on_boot_framebuffer(&f); + expect_fixed_chain(&f, false); + assert(!f.display.available && f.disp0_dart.available); assert(err_count == 0); check_refs_zero(); - /* 13. Either DART of the chain alone not kept -> the same. */ - init_fixture(&f); - f.disp0_dart.available = true; - f.fw_dart.compatible = "apple,t8132-dart"; - gate_t8132_run(); - expect_chain(&f, false); - expect_gpu_on_boot_framebuffer(&f); + /* + * 18. Legacy M4 path (Air on 27.2): pre-enabled Type-C dcpext enables its + * disabled piodma and routes and appends its display DART; disabled fixed + * dcpext0 is skipped and display stays on. + */ init_fixture(&f); + legacy_fw_path = true; f.disp0_dart.available = true; - f.disp_dart.compatible = "apple,t8132-dart"; + set_v27_2(&f.dcpext1); + f.dcpext1.available = true; + f.tc_fw_dart.available = true; + f.tc_disp_dart.available = true; + f.tc_mbox.available = true; gate_t8132_run(); - expect_chain(&f, false); - expect_gpu_on_boot_framebuffer(&f); + expect_fixed_chain(&f, false); + expect_typec_chain(&f, true); + assert(f.display.available); + assert(f.display.iommu_count == 2); + assert(f.display.iommus[0] == &f.disp0_dart && f.display.iommu_args[0] == 0); + assert(f.display.iommus[1] == &f.tc_disp_dart && f.display.iommu_args[1] == 0); + assert(err_count == 0); check_refs_zero(); - /* 14. Laptop: main DCP handed over on 27.2 -> its display subsystem and DART stay. */ + /* 19. Without T8132 Type-C driver: Type-C pipe is skipped and headless display retires. */ init_fixture(&f); - j773g_darts(&f); - set_v27_2(&f.main_dcp); - f.main_dcp.has_clock_ids = true; - f.main_dcp.available = true; + clear_fw(&f.dcpext0); + set_v27_2(&f.dcpext1); f.disp0_dart.available = true; - take_snapshot(&f, &snap); - gate_t8132_run(); - expect_unchanged(&f, &snap); + { + struct of_changeset *cs = gate_cs_alloc(); + + assert(cs); + assert(gate_t8132_prepare(cs, &f.display, &f.main_dcp, false, true, false) == 0); + assert(!list_empty(&cs->entries)); + assert(of_changeset_apply(cs) == 0); + } + expect_typec_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0); check_refs_zero(); - /* 15. Headless, but the main DCP enabled: the display goes, disp0's DART (its piodma's) stays. */ + /* 20. Malformed display iommus on panel-less T8132 -> error logged, display retired. */ init_fixture(&f); - j773g_darts(&f); - f.main_dcp.available = true; f.disp0_dart.available = true; + f.display.iommus_prop.length = 4; gate_t8132_run(); - expect_chain(&f, false); - assert(!f.display.available && f.disp0_dart.available); + expect_fixed_chain(&f, false); + expect_typec_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 1); check_refs_zero(); cleanup_applied(); - puts("PASS T8132 fixed-DP display gate: phandle chain, replace vs append disp0 iommus, fail-closed controls"); - puts("PASS T8132 display gate: no handover or no kept DART roots boots as without the gate, GPU on the boot framebuffer"); + puts("PASS T8132 external display gate: fixed-DP and Type-C chains, scanout iommus, fail-closed controls"); + puts("PASS T8132 display gate: legacy Air path, nomodeset, and headless boot-framebuffer fallback"); return 0; } '''