From b1dcc099d97cedf827a61fa82a717f9fab12e2fd Mon Sep 17 00:00:00 2001 From: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:26:53 -0700 Subject: [PATCH 1/5] arm64: dts: apple: t6022-j475d: enable DP alt mode on the rear USB-C ports On the Mac Studio (M2 Ultra) no display controller is wired to the four rear USB-C ports, so a USB-C DisplayPort display there never lights up. The dcpext1 routes in t602x-j474-j475.dtsi sit inside the APPLE_T602X_NON_ULTRA block together with the USB4/PCIe-C wiring, and t6022 does not define it. The die-0 half of the t6022 keeps the plain labels and the same rear-port wiring as the M2 Max Studio. macOS on a J475d drives a DP alt mode display on rear ports 1 and 2 from DCPEXT1 through the display crossbar (ADT display-crossbar0, "display-crossbar,t602x"), the same controller the non-Ultra boards use. Keep only the USB4 aliases, the PCIe-C tunnels and the non-Ultra display iommus under the guard. The dcpext1 display routes, dpaudio2, the ATC crossbars and the always-on ATC common power domains now apply to J475d too. t6022-jxxxd.dtsi points the display subsystem at the die-1 HDMI DART only, so add dispext1_dart to it on J475d for the framebuffers of the new pipe. J474s and J475c keep the same nodes and properties; only the position of the dcpext1 alias within /aliases changes. Signed-off-by: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6022-j475d.dts | 9 +++++++++ arch/arm64/boot/dts/apple/t602x-j474-j475.dtsi | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6022-j475d.dts b/arch/arm64/boot/dts/apple/t6022-j475d.dts index 6c09afcffc9a69..35f002d23d6e8d 100644 --- a/arch/arm64/boot/dts/apple/t6022-j475d.dts +++ b/arch/arm64/boot/dts/apple/t6022-j475d.dts @@ -45,6 +45,15 @@ power-domains = <&ps_dispext0_cpu0_die1>, <&ps_dptx_phy_ps_die1>; }; +/* + * HDMI scans out through dispext0 on die 1, and the rear USB-C ports through + * dcpext1/dispext1 on die 0 (see t602x-j474-j475.dtsi). + */ +&display { + iommus = <&dispext0_dart_die1 0 0x100 0x0 0x10 0x0>, + <&dispext1_dart 0 0x100 0x0 0x10 0x0>; +}; + &dcpext0_die1 { // J180 misses "function-dp2hdmi_pwr_en" dp2hdmi-pwren-gpios = <&smc_gpio 25 GPIO_ACTIVE_HIGH>; diff --git a/arch/arm64/boot/dts/apple/t602x-j474-j475.dtsi b/arch/arm64/boot/dts/apple/t602x-j474-j475.dtsi index 822760c80ae598..22827a0ffab38f 100644 --- a/arch/arm64/boot/dts/apple/t602x-j474-j475.dtsi +++ b/arch/arm64/boot/dts/apple/t602x-j474-j475.dtsi @@ -24,7 +24,6 @@ #ifdef APPLE_T602X_NON_ULTRA / { aliases { - dcpext1 = &dcpext1; /* Same Thunderbolt aliases as the 14/16-inch boards. This mini * brings up a fourth controller. */ @@ -67,6 +66,19 @@ iommus = <&dispext0_dart 0 0x100 0x0 0x10 0x0>, <&dispext1_dart 0 0x100 0x0 0x10 0x0>; }; +#endif + +/* + * dcpext1 on die 0 drives the rear USB-C ports through the display crossbar + * on all of these boards, M2 Ultra included: macOS routes a DP alt mode + * display on the J475d's rear ports to DCPEXT1 as well. Only the USB4 and + * PCIe-C wiring below stays non-Ultra. + */ +/ { + aliases { + dcpext1 = &dcpext1; + }; +}; &dispext1_dart { status = "okay"; @@ -229,6 +241,7 @@ apple,always-on; }; +#ifdef APPLE_T602X_NON_ULTRA &usb4_0_acio { apple,pcie-tunnel = <&usb4_0_pcie_tunnel>; }; From 5831614759c15d5908b93335edfe744e63f05c75 Mon Sep 17 00:00:00 2001 From: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:06:57 -0700 Subject: [PATCH 2/5] thunderbolt: apple: qualify the M2 Ultra (t6022) for DP tunnels The M2 Ultra is two t6021 dies. Its die-0 ACIO, ATC and display crossbar are the ones the M2 Pro/Max laptops use, and the DCPs are the same apple,t6020-dcpext. With t6022 missing from apple_dpin_qualified_soc, a Thunderbolt display on a J475d enumerates, but the DP IN adapter never asks for a pipeline and the tunnel is torn down after the DPRX timeout: thunderbolt-apple-nhi f01f00000.nhi: 0:5 <-> 1:13 (DP): not active, tearing down Qualify t6022 with the same M2 (pre/post) flow. That flow still requires dual-stream connector wiring, so nothing changes until a board's DT describes it. Tested on a Mac Studio (M2 Ultra, J475d) with an LG 40WP95C on rear ports 1 and 2: 5120x2160@72, hotplug, and DPMS off/on. Signed-off-by: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> --- drivers/thunderbolt/apple-dpin-test.c | 3 ++- drivers/thunderbolt/apple.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/apple-dpin-test.c b/drivers/thunderbolt/apple-dpin-test.c index c22da168bd8bc9..2417768ebd0ea9 100644 --- a/drivers/thunderbolt/apple-dpin-test.c +++ b/drivers/thunderbolt/apple-dpin-test.c @@ -355,7 +355,8 @@ static void apple_dpin_qualification_profiles(struct kunit *test) { "apple,t6021", &apple_dpin_m2, true, &apple_dpin_m2 }, { "apple,t6020", &apple_dpin_m2, false, &apple_dpin_disabled }, { "apple,t6021", &apple_dpin_m2, false, &apple_dpin_disabled }, - { "apple,t6022", &apple_dpin_m2, true, &apple_dpin_disabled }, + { "apple,t6022", &apple_dpin_m2, true, &apple_dpin_m2 }, + { "apple,t6022", &apple_dpin_m2, false, &apple_dpin_disabled }, { "apple,t6030", &apple_dpin_m3, true, &apple_dpin_m3 }, { "apple,t6031", &apple_dpin_m3, true, &apple_dpin_disabled }, { "apple,unknown", &apple_dpin_m1, true, &apple_dpin_disabled }, diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index c6625c5cbb5d3f..8e7df5aa30f874 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -375,6 +375,8 @@ static const struct of_device_id apple_dpin_qualified_soc[] = { { .compatible = "apple,t6001" }, { .compatible = "apple,t6020" }, { .compatible = "apple,t6021" }, + /* The M2 Ultra's die-0 ACIO, ATC and display crossbar are t6021's. */ + { .compatible = "apple,t6022" }, { .compatible = "apple,t6030" }, {}, }; From 5cb2ccf77011076388cbf5feaf0a75b1cdec5ad6 Mon Sep 17 00:00:00 2001 From: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:06:57 -0700 Subject: [PATCH 3/5] phy: apple: atc: qualify the M2 Ultra and the fourth die-0 ATC for DP tunnels Qualify t6022 for the T602x tunnel clock sequence, as for the Thunderbolt side, and accept the ATC3 core at 0x1303000000. The 14/16-inch boards only have ATC0-2, so ATC3 was never listed, but the Mac mini and Mac Studio use it for their fourth rear port. The wiring gate still applies. Tested on a Mac Studio (M2 Ultra, J475d): a DP tunnel on rear port 1 (phy@1303000000) runs 5120x2160@72. Signed-off-by: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> --- drivers/phy/apple/atc-tunnel-test.c | 4 ++-- drivers/phy/apple/atc-tunnel.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/phy/apple/atc-tunnel-test.c b/drivers/phy/apple/atc-tunnel-test.c index 15f10557073328..4e1a33474ec5f3 100644 --- a/drivers/phy/apple/atc-tunnel-test.c +++ b/drivers/phy/apple/atc-tunnel-test.c @@ -12,7 +12,7 @@ static void atc_tunnel_soc_qualification(struct kunit *test) } cases[] = { { "apple,t6020", true }, { "apple,t6021", true }, - { "apple,t6022", false }, + { "apple,t6022", true }, { "apple,t8103", false }, { "apple,t6000", false }, { "apple,t6001", false }, @@ -47,7 +47,7 @@ static void atc_tunnel_core_qualification(struct kunit *test) { "apple,t6020-atcphy", 0xb03000000ULL, 0x7048, true }, { "apple,t6020-atcphy", 0xf03000000ULL, 0x7048, true }, { "apple,t6020-atcphy", 0x703000000ULL, 0x7047, false }, - { "apple,t6020-atcphy", 0x1303000000ULL, 0x4c000, false }, + { "apple,t6020-atcphy", 0x1303000000ULL, 0x4c000, true }, { "apple,t6020-atcphy", 0x2703000000ULL, 0x4c000, false }, { "apple,t8103-atcphy", 0x703000000ULL, 0x4c000, false }, }; diff --git a/drivers/phy/apple/atc-tunnel.h b/drivers/phy/apple/atc-tunnel.h index e06d10b4a3e3d4..2bc4dae3425a85 100644 --- a/drivers/phy/apple/atc-tunnel.h +++ b/drivers/phy/apple/atc-tunnel.h @@ -9,13 +9,15 @@ static inline bool apple_atc_t602x_qualified(const struct device_node *root) { return of_device_is_compatible(root, "apple,t6020") || - of_device_is_compatible(root, "apple,t6021"); + of_device_is_compatible(root, "apple,t6021") || + of_device_is_compatible(root, "apple,t6022"); } static inline bool apple_atc_t602x_core_valid(const struct device_node *np, u64 base, u64 size) { return of_device_is_compatible(np, "apple,t6020-atcphy") && - (base == 0x703000000ULL || base == 0xb03000000ULL || base == 0xf03000000ULL) && + (base == 0x703000000ULL || base == 0xb03000000ULL || base == 0xf03000000ULL || + base == 0x1303000000ULL) && size >= 0x7048; } From 5cb9b740287ac212c21b637629221ee739b049d7 Mon Sep 17 00:00:00 2001 From: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:06:57 -0700 Subject: [PATCH 4/5] arm64: dts: apple: t6022-j475d: wire Thunderbolt DP tunnels on the rear ports On M2, Thunderbolt DP tunnels need dual-stream connector wiring: two DCPs per Type-C connector, each with typecN-dpin0/1 controls on cells 1 and 2 of the port's crossbar, as on the 14/16-inch boards. The J475d's HDMI runs from die 1, so die-0 dcpext0 is free. Enable it as a USB-C-only pipeline for the rear ports (crossbar state 0, dcpext1 state 2), give both die-0 DCPs the DPIN controls, add the second endpoint to each rear connector, and add dispext0_dart to the display iommus. m1n1 fills apple,firmware-compat only through the ADT-indexed dcpextN aliases. Without "dcpext0" here, probe fails with "Could not read 'apple,firmware-compat': -22" and the whole apple-drm aggregate stays down, HDMI included. Tested on a Mac Studio (M2 Ultra, J475d), together with the two previous patches: HDMI (dcpext4), a DP alt mode display on rear port 4 (dcpext0) and a Thunderbolt display on rear port 2 (dcpext1, dpin0) all run at once. Signed-off-by: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6022-j475d.dts | 202 ++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6022-j475d.dts b/arch/arm64/boot/dts/apple/t6022-j475d.dts index 35f002d23d6e8d..724b5dbac699a2 100644 --- a/arch/arm64/boot/dts/apple/t6022-j475d.dts +++ b/arch/arm64/boot/dts/apple/t6022-j475d.dts @@ -51,9 +51,211 @@ */ &display { iommus = <&dispext0_dart_die1 0 0x100 0x0 0x10 0x0>, + <&dispext0_dart 0 0x100 0x0 0x10 0x0>, <&dispext1_dart 0 0x100 0x0 0x10 0x0>; }; +/* + * Thunderbolt DP tunnels on M2 need two pipelines per port with named DPIN + * crossbar controls, as on the 14/16-inch boards. HDMI uses die 1 here, so + * die-0 dcpext0 is free to be the second rear-port pipeline (crossbar state + * 0, dcpext1 state 2). + */ +/ { + aliases { + /* m1n1 fills apple,firmware-compat through the ADT-indexed alias */ + dcpext0 = &dcpext0; + }; +}; + +&dispext0_dart { + status = "okay"; +}; + +&dcpext0_dart { + status = "okay"; +}; + +&dcpext0_mbox { + status = "okay"; +}; + +&dpaudio1 { + status = "okay"; +}; + +&dcpext0 { + status = "okay"; + apple,connector-type = "USB-C"; + phys = <&atcphy0 PHY_TYPE_DP>, <&atcphy1 PHY_TYPE_DP>, + <&atcphy2 PHY_TYPE_DP>, <&atcphy3 PHY_TYPE_DP>; + phy-names = "typec0", "typec1", "typec2", "typec3"; + mux-controls = <&atcphy0_xbar 0>, + <&atcphy1_xbar 0>, + <&atcphy2_xbar 0>, + <&atcphy3_xbar 0>, + <&atcphy0_xbar 1>, + <&atcphy1_xbar 1>, + <&atcphy2_xbar 1>, + <&atcphy3_xbar 1>, + <&atcphy0_xbar 2>, + <&atcphy1_xbar 2>, + <&atcphy2_xbar 2>, + <&atcphy3_xbar 2>; + mux-control-names = "typec0", "typec1", "typec2", "typec3", + "typec0-dpin0", "typec1-dpin0", "typec2-dpin0", "typec3-dpin0", + "typec0-dpin1", "typec1-dpin1", "typec2-dpin1", "typec3-dpin1"; + apple,typec-mux-indices = <0 0 0 0>; + apple,typec-dptx-phys = <0 1 2 3>; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + + port { + dcpext0_typec0: endpoint { + remote-endpoint = <&typec0_dcpext0>; + }; + }; + }; + + route@1 { + reg = <1>; + mode-switch; + + port { + dcpext0_typec1: endpoint { + remote-endpoint = <&typec1_dcpext0>; + }; + }; + }; + + route@2 { + reg = <2>; + mode-switch; + + port { + dcpext0_typec2: endpoint { + remote-endpoint = <&typec2_dcpext0>; + }; + }; + }; + + route@3 { + reg = <3>; + mode-switch; + + port { + dcpext0_typec3: endpoint { + remote-endpoint = <&typec3_dcpext0>; + }; + }; + }; + }; +}; + +&dcpext1 { + mux-controls = <&atcphy0_xbar 0>, + <&atcphy1_xbar 0>, + <&atcphy2_xbar 0>, + <&atcphy3_xbar 0>, + <&atcphy0_xbar 1>, + <&atcphy1_xbar 1>, + <&atcphy2_xbar 1>, + <&atcphy3_xbar 1>, + <&atcphy0_xbar 2>, + <&atcphy1_xbar 2>, + <&atcphy2_xbar 2>, + <&atcphy3_xbar 2>; + mux-control-names = "typec0", "typec1", "typec2", "typec3", + "typec0-dpin0", "typec1-dpin0", "typec2-dpin0", "typec3-dpin0", + "typec0-dpin1", "typec1-dpin1", "typec2-dpin1", "typec3-dpin1"; +}; + +&typec0 { + ports { + port@3 { + #address-cells = <1>; + #size-cells = <0>; + /delete-node/ endpoint; + + typec0_dcp: endpoint@0 { + reg = <0>; + remote-endpoint = <&dcpext1_typec0>; + }; + + typec0_dcpext0: endpoint@1 { + reg = <1>; + remote-endpoint = <&dcpext0_typec0>; + }; + }; + }; +}; + +&typec1 { + ports { + port@3 { + #address-cells = <1>; + #size-cells = <0>; + /delete-node/ endpoint; + + typec1_dcp: endpoint@0 { + reg = <0>; + remote-endpoint = <&dcpext1_typec1>; + }; + + typec1_dcpext0: endpoint@1 { + reg = <1>; + remote-endpoint = <&dcpext0_typec1>; + }; + }; + }; +}; + +&typec2 { + ports { + port@3 { + #address-cells = <1>; + #size-cells = <0>; + /delete-node/ endpoint; + + typec2_dcp: endpoint@0 { + reg = <0>; + remote-endpoint = <&dcpext1_typec2>; + }; + + typec2_dcpext0: endpoint@1 { + reg = <1>; + remote-endpoint = <&dcpext0_typec2>; + }; + }; + }; +}; + +&typec3 { + ports { + port@3 { + #address-cells = <1>; + #size-cells = <0>; + /delete-node/ endpoint; + + typec3_dcp: endpoint@0 { + reg = <0>; + remote-endpoint = <&dcpext1_typec3>; + }; + + typec3_dcpext0: endpoint@1 { + reg = <1>; + remote-endpoint = <&dcpext0_typec3>; + }; + }; + }; +}; + &dcpext0_die1 { // J180 misses "function-dp2hdmi_pwr_en" dp2hdmi-pwren-gpios = <&smc_gpio 25 GPIO_ACTIVE_HIGH>; From df41192ecdbafd5bee4de73fdb33968f37277d1f Mon Sep 17 00:00:00 2001 From: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:22:41 -0700 Subject: [PATCH 5/5] drm: apple: don't fix a port's second DP tunnel to its first stream's pipeline On an ordered dual-stream machine each Type-C port gets a second connector for a dock's DPIN1 stream, fixed to the lowest-indexed Type-C-only pipeline. On the M2 Pro/Max laptops that is dcpext1, since dcpext0 also drives HDMI, and the pairing pass gives the first stream the lowest-indexed pipeline, dcpext0. On the M2 Ultra Mac Studio (J475d) HDMI runs from die 1, so every rear-port pipeline is Type-C-only. Both streams then want dcpext0, and a display daisy-chained behind a Thunderbolt monitor is refused while dcpext1 sits idle: thunderbolt-apple-acio 701ac0000.cio: dpin1: DP tunnel setup failed: -16 Fix the second stream to the lowest-indexed Type-C-only pipeline other than the port's lowest-indexed pipeline, which the first stream takes. A port with a single Type-C-only pipeline keeps it. The laptops still get dcpext1. Tested on a J475d with an LG 40WP95C and a monitor daisy-chained behind it: dpin0 on dcpext0, dpin1 on dcpext1, both displays up. Signed-off-by: Jacob Crowther <3944151+jcrowthe@users.noreply.github.com> --- drivers/gpu/drm/apple/apple_drv.c | 36 +++++++---- drivers/gpu/drm/apple/dcp-fabric-core.c | 30 +++++++++ drivers/gpu/drm/apple/dcp-fabric-core.h | 2 + drivers/gpu/drm/apple/dcp-fabric-test.c | 81 +++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 9028388b33915b..fc502ec01490a4 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -816,21 +816,35 @@ static int apple_probe_typec_ports(struct drm_device *drm, connector->connected = false; connector->dcp = NULL; - for (i = 0; i < num_dcp; i++) { - if (!dcp_typec_port_has_candidate(port_idx, dcp[i])) - continue; + if (secondary && dcp_typec_ordered_dual_stream()) { + u32 candidates[MAX_COPROCESSORS]; + bool typec_only[MAX_COPROCESSORS]; + unsigned int count = 0; + /* - * A dock's second stream (DPIN1) always runs on the - * lowest-indexed Type-C-only pipeline (dcpext1). Fix the + * A dock's second stream (DPIN1) always runs on one + * Type-C-only pipeline, not the one the first stream + * takes (see dcp_fabric_secondary_crtc()). Fix the * connector to it: compositors read possible_crtcs once * and would otherwise pair it with a pipeline the stream - * can never be routed to. T6030 instead narrows both - * connectors to the native processor holding their route. + * can never be routed to. + */ + for (i = 0; i < num_dcp; i++) { + if (!dcp_typec_port_has_candidate(port_idx, dcp[i])) + continue; + candidates[count] = crtc_mask[i]; + typec_only[count++] = dcp_is_typec_only(dcp[i]); + } + mask = dcp_fabric_secondary_crtc(candidates, typec_only, + count); + } else { + /* + * Every pipeline that can drive the port; a routed port + * may be narrowed later (see dcp_typec_narrows()). */ - mask = dcp_fabric_port_crtc_mask(secondary, - dcp_typec_ordered_dual_stream(), - dcp_is_typec_only(dcp[i]), - mask, crtc_mask[i]); + for (i = 0; i < num_dcp; i++) + if (dcp_typec_port_has_candidate(port_idx, dcp[i])) + mask |= crtc_mask[i]; } if (!mask) { diff --git a/drivers/gpu/drm/apple/dcp-fabric-core.c b/drivers/gpu/drm/apple/dcp-fabric-core.c index 8c952dc0245605..21e686fc556209 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-core.c +++ b/drivers/gpu/drm/apple/dcp-fabric-core.c @@ -518,6 +518,36 @@ u32 dcp_fabric_port_crtc_mask(bool secondary, bool ordered_dual, bool typec_only } EXPORT_SYMBOL_GPL(dcp_fabric_port_crtc_mask); +/* + * The CRTC an ordered dual-stream port's second stream (DPIN1) is fixed to. + * dcp_fabric_plan() walks pipelines in CRTC order, so the first stream takes + * the port's lowest-indexed pipeline: skip it. On the M2 Pro/Max laptops + * that is the HDMI hybrid, never a candidate here, which leaves dcpext1. On + * the M2 Ultra Mac Studio every rear-port pipeline is Type-C-only, and the + * second stream would otherwise be fixed to the first stream's dcpext0. A + * port with a single Type-C-only pipeline keeps it. + */ +u32 dcp_fabric_secondary_crtc(const u32 *candidates, const bool *typec_only, + unsigned int count) +{ + u32 first = 0, mask = 0, fallback = 0; + unsigned int i; + + for (i = 0; i < count; i++) + if (!first || candidates[i] < first) + first = candidates[i]; + for (i = 0; i < count; i++) { + if (!typec_only[i]) + continue; + if (!fallback || candidates[i] < fallback) + fallback = candidates[i]; + if (candidates[i] != first && (!mask || candidates[i] < mask)) + mask = candidates[i]; + } + return mask ?: fallback; +} +EXPORT_SYMBOL_GPL(dcp_fabric_secondary_crtc); + enum dcp_fabric_attach_action dcp_fabric_attach_action(bool external) { return external ? DCP_FABRIC_ATTACH_WORK : DCP_FABRIC_ATTACH_OOB; diff --git a/drivers/gpu/drm/apple/dcp-fabric-core.h b/drivers/gpu/drm/apple/dcp-fabric-core.h index 1b8c59ac15a540..9216125cd3f508 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-core.h +++ b/drivers/gpu/drm/apple/dcp-fabric-core.h @@ -194,6 +194,8 @@ u32 dcp_fabric_connector_mask(bool dual_stream, bool bound, bool routed, unsigned int index, u32 candidates); u32 dcp_fabric_port_crtc_mask(bool secondary, bool ordered_dual, bool typec_only, u32 mask, u32 candidate); +u32 dcp_fabric_secondary_crtc(const u32 *candidates, const bool *typec_only, + unsigned int count); enum dcp_fabric_attach_action dcp_fabric_attach_action(bool external); bool dcp_fabric_t6030_link(bool tunnel, bool has_xbar, bool t6030_dpin); diff --git a/drivers/gpu/drm/apple/dcp-fabric-test.c b/drivers/gpu/drm/apple/dcp-fabric-test.c index 2d2fab58136b6b..03e9db8599afde 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-test.c +++ b/drivers/gpu/drm/apple/dcp-fabric-test.c @@ -1961,6 +1961,86 @@ static void fabric_t6030_dual_policy_test(struct kunit *test) KUNIT_EXPECT_EQ(test, mask, (u32)(BIT(1) | BIT(2))); } +/* + * M2 Ultra Mac Studio: HDMI runs from die 1, so all four die-0 pipelines on a + * rear port are Type-C-only. The second stream of a daisy chain or dock must + * not be fixed to the first stream's pipeline. + */ +static void fabric_secondary_crtc_test(struct kunit *test) +{ + static const u32 ultra[] = { BIT(0), BIT(1), BIT(2), BIT(3) }; + static const bool ultra_tc[] = { true, true, true, true }; + static const u32 laptop[] = { BIT(1), BIT(2), BIT(3), BIT(4) }; + static const bool laptop_tc[] = { false, true, true, true }; + static const u32 unsorted[] = { BIT(3), BIT(2), BIT(0), BIT(1) }; + static const bool single_tc[] = { true }; + static const bool none_tc[] = { false, false }; + struct dcp_fabric_pipeline pipeline[4] = {}; + struct dcp_fabric_route route[4] = {}; + struct dcp_fabric_plan plan = {}; + struct dcp_fabric_port port = {}; + struct dcp_fabric_policy policy = { .dual_stream = true }; + struct dcp_fabric_route *chosen; + unsigned int i; + int error; + + /* Laptops (hybrid dcpext0 lowest) keep dcpext1, with or without dcpext2/3. */ + KUNIT_EXPECT_EQ(test, dcp_fabric_secondary_crtc(laptop, laptop_tc, 2), (u32)BIT(2)); + KUNIT_EXPECT_EQ(test, dcp_fabric_secondary_crtc(laptop, laptop_tc, 4), (u32)BIT(2)); + /* All Type-C-only: skip the first stream's pipeline, in any order. */ + KUNIT_EXPECT_EQ(test, dcp_fabric_secondary_crtc(ultra, ultra_tc, 2), (u32)BIT(1)); + KUNIT_EXPECT_EQ(test, dcp_fabric_secondary_crtc(ultra, ultra_tc, 4), (u32)BIT(1)); + KUNIT_EXPECT_EQ(test, dcp_fabric_secondary_crtc(unsorted, ultra_tc, 4), (u32)BIT(1)); + /* One Type-C-only pipeline keeps it; none gives no candidate. */ + KUNIT_EXPECT_EQ(test, dcp_fabric_secondary_crtc(ultra, single_tc, 1), (u32)BIT(0)); + KUNIT_EXPECT_EQ(test, dcp_fabric_secondary_crtc(laptop, none_tc, 2), 0U); + + for (i = 0; i < 4; i++) { + pipeline[i].bound = true; + pipeline[i].crtc_index = i; + pipeline[i].services_ready = true; + if (i < 3) { + pipeline[i].next = &pipeline[i + 1]; + route[i].next = &route[i + 1]; + } + route[i].pipeline = &pipeline[i]; + } + port.key = 1; + port.routes = &route[0]; + port.plan = &plan; + port.candidate_crtcs[0] = BIT(0) | BIT(1) | BIT(2) | BIT(3); + port.candidate_crtcs[1] = dcp_fabric_secondary_crtc(ultra, ultra_tc, 4); + + /* The first stream takes dcpext0 (CRTC 0), as on the hardware. */ + chosen = dcp_fabric_tunnel_candidate(&port, &policy, NULL, false, 0, + true, &error); + KUNIT_ASSERT_PTR_EQ(test, chosen, &route[0]); + pipeline[0].owned = true; + pipeline[0].tunnel_held = true; + route[0].tunnel = true; + port.owner[0] = &route[0]; + + /* The second stream gets dcpext1 instead of -EBUSY. */ + chosen = dcp_fabric_tunnel_candidate(&port, &policy, NULL, false, 1, + true, &error); + KUNIT_EXPECT_PTR_EQ(test, chosen, &route[1]); + KUNIT_EXPECT_EQ(test, error, 0); + + /* So does the ordered pairing pass. */ + dcp_fabric_plan(&pipeline[0], &port, &port, 1); + KUNIT_EXPECT_PTR_EQ(test, plan.target[0], &route[0]); + KUNIT_EXPECT_PTR_EQ(test, plan.target[1], &route[1]); + + /* The old rule fixed it to the first stream's CRTC: nothing fits. */ + port.candidate_crtcs[1] = BIT(0); + chosen = dcp_fabric_tunnel_candidate(&port, &policy, NULL, false, 1, + true, &error); + KUNIT_EXPECT_NULL(test, chosen); + KUNIT_EXPECT_EQ(test, error, -EBUSY); + dcp_fabric_plan(&pipeline[0], &port, &port, 1); + KUNIT_EXPECT_NULL(test, plan.target[1]); +} + static void fabric_t6030_clock_header_parity_test(struct kunit *test) { static const struct { @@ -2352,6 +2432,7 @@ static struct kunit_case fabric_tests[] = { KUNIT_CASE(relink_stamp_test), KUNIT_CASE(fabric_t6030_dual_policy_test), KUNIT_CASE(fabric_t6030_clock_routes_test), + KUNIT_CASE(fabric_secondary_crtc_test), KUNIT_CASE(fabric_t6030_clock_header_parity_test), KUNIT_CASE(fabric_t6030_plan_test), KUNIT_CASE(fabric_t6030_follow_test),