diff --git a/Documentation/devicetree/bindings/display/apple,dcp-typec-routes.yaml b/Documentation/devicetree/bindings/display/apple,dcp-typec-routes.yaml index 7b2e28ac3dca7..9bd123527b2c8 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp-typec-routes.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp-typec-routes.yaml @@ -24,7 +24,9 @@ description: | mux cells 0, 1 and 2 describe the DP PHY, DP IN 0 and DP IN 1 outputs, respectively. The per-port prefix distinguishes multiple ATCs on one DCP. Dual-stream wiring requires these two named controls and two port@3 - endpoints. It does not describe SoC handshake or retry policy. + endpoints. It does not describe SoC handshake or retry policy. T6050 host + routers have four DP IN adapters; their crossbars add typecN-dpin2 and + typecN-dpin3 (cells 3 and 4). Legacy typecN-usb4 names describe cell 1 on old j414/j416 DTBs. With two port@3 endpoints they retain the existing dual-stream wiring; cell 2 is @@ -56,12 +58,12 @@ properties: mux-controls: minItems: 1 - maxItems: 13 + maxItems: 21 description: Fixed, DP Alt Mode and wired DP IN crossbar output controls. mux-control-names: minItems: 1 - maxItems: 13 + maxItems: 21 items: anyOf: - enum: @@ -72,12 +74,20 @@ properties: - typec3 - typec0-dpin0 - typec0-dpin1 + - typec0-dpin2 + - typec0-dpin3 - typec1-dpin0 - typec1-dpin1 + - typec1-dpin2 + - typec1-dpin3 - typec2-dpin0 - typec2-dpin1 + - typec2-dpin2 + - typec2-dpin3 - typec3-dpin0 - typec3-dpin1 + - typec3-dpin2 + - typec3-dpin3 - enum: [typec0-usb4, typec1-usb4, typec2-usb4, typec3-usb4] deprecated: true @@ -113,12 +123,26 @@ properties: - maximum: 3 mode-switch: type: boolean + apple,tunnel-only: + type: boolean + description: | + The route carries USB4 DP tunnels only and is never given a DP + Alt Mode display. It is not a Type-C mode-switch, so a port + whose connector already has as many mode-switch providers as + the Type-C class allows can still offer another tunnel + pipeline. port: $ref: /schemas/graph.yaml#/properties/port required: - reg - - mode-switch - port + if: + not: + required: + - apple,tunnel-only + then: + required: + - mode-switch required: - '#address-cells' - '#size-cells' diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index d0bc33404c24f..97da243b79c4e 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -426,12 +426,23 @@ properties: maxItems: 1 mode-switch: type: boolean + apple,tunnel-only: + type: boolean + description: + The route carries USB4 DP tunnels only, never a DP Alt Mode + display. It is not a Type-C mode-switch. port: $ref: /schemas/graph.yaml#/properties/port required: - reg - - mode-switch - port + if: + not: + required: + - apple,tunnel-only + then: + required: + - mode-switch additionalProperties: false required: - '#address-cells' diff --git a/arch/arm64/boot/dts/apple/t6050-j714s-display.dtsi b/arch/arm64/boot/dts/apple/t6050-j714s-display.dtsi index f14c7ab163e31..003b229e26409 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714s-display.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-j714s-display.dtsi @@ -1,17 +1,54 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT /* * J714s external displays: DisplayPort alt mode on the left-front and right ports and USB4 - * DisplayPort tunnels on the right port. dcpext0 and dcpext2 drive the routes; dcpext1 and - * dcpext3 are their pairs for modes that need two pipelines. The left-back port (ATC0) is the - * debug port and is not described. Addresses and interrupts are from the J714sAP ADT. The boot - * loader hands each engine over: it enables the engine, its mailbox and DARTs, publishes its - * bandwidth scratch and adds its display DART to the display subsystem. + * DisplayPort tunnels on the right port. dcpext0 and dcpext2 drive the DP alt mode and tunnel + * routes, dcpext1 a third tunnel on the right port only; dcpext3 is the pair for modes that + * need two pipelines. The left-back port (ATC0) is the debug port and is not described. + * Addresses and interrupts are from the J714sAP ADT. The boot loader hands each engine over: it + * enables the engine, its mailbox and DARTs, publishes its bandwidth scratch and adds its + * display DART to the display subsystem. */ &dcpext1 { apple,dcp-index = <2>; apple,connector-type = "USB-C"; apple,dptx-die = <0>; + /* + * A third pipeline for USB4 DP tunnels on the right port, so a dock can + * drive three displays as on macOS. Routing dcpext1 stops it being a + * merged-mode peer; dcpext0, dcpext1 and dcpext2 then pair with dcpext3, + * so only one display wider than one pipeline runs at a time. + * Crossbar source 2 (dispext1 port 0) follows the 2 * dispext pattern of + * dcpext0 (0) and dcpext2 (4), and the T6040 dcpext1 (2). + * No mode-switch: hpm2 already has TYPEC_MUX_MAX_DEVS (3) mode-switch + * providers; tunnels find the port through the endpoint, not the mux. + * apple,tunnel-only keeps DP alt mode displays off it: only tunnels + * have been driven through it. + */ + apple,typec-dptx-phys = <2>; + apple,typec-mux-indices = <2>; + phys = <&atc2_phy 6>; + phy-names = "typec0"; + mux-controls = <&atc2_xbar 0>, <&atc2_xbar 1>, <&atc2_xbar 2>, <&atc2_xbar 3>, + <&atc2_xbar 4>; + mux-control-names = "typec0", "typec0-dpin0", "typec0-dpin1", "typec0-dpin2", + "typec0-dpin3"; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + apple,tunnel-only; + + port { + dcpext1_right: endpoint { + remote-endpoint = <&hpm2_dp2>; + }; + }; + }; + }; }; &dcpext2 { @@ -111,6 +148,11 @@ reg = <1>; remote-endpoint = <&dcpext2_right>; }; + + hpm2_dp2: endpoint@2 { + reg = <2>; + remote-endpoint = <&dcpext1_right>; + }; }; }; }; diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 9959f24170e91..bd57a279537cb 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1234,22 +1234,28 @@ static int apple_probe_per_dcp(struct device *dev, * connector per port for a dock's second DP tunnel, preserving primary * connector names. T6050 instead exposes one connector per port/pipeline * pair: tunnel allocation chooses which connector is connected, without - * changing any encoder's advertised CRTC mask after registration. + * changing any encoder's advertised CRTC mask after registration. Pairs + * whose route carries DP tunnels only come last, so adding such a route + * does not renumber the connectors that existed before it. */ static int apple_probe_typec_ports(struct drm_device *drm, struct platform_device **dcp, u32 *crtc_mask, int num_dcp) { - unsigned int idx, nr_ports = dcp_typec_nr_ports(); + unsigned int n, nr_ports = dcp_typec_nr_ports(); bool fixed = dcp_typec_fixed_crtcs(); unsigned int slots = fixed ? num_dcp : (dcp_typec_dual_stream() ? 2 : 1); + /* T6050 creates its tunnel-only port/pipeline pairs in a second pass. */ + unsigned int passes = fixed ? 2 : 1; int i, ret; /* Keep the existing physical-port connector numbers stable. On the * M2 Pro/Max laptops, append one more connector per port for a second * USB4 DP tunnel. */ - for (idx = 0; idx < nr_ports * slots; idx++) { + for (n = 0; n < passes * nr_ports * slots; n++) { + unsigned int pass = n / (nr_ports * slots); + unsigned int idx = n % (nr_ports * slots); struct apple_connector *connector; struct apple_encoder *enc; struct platform_device *pipeline = fixed ? dcp[idx / nr_ports] : NULL; @@ -1259,14 +1265,18 @@ static int apple_probe_typec_ports(struct drm_device *drm, /* Only a failed T8122 dcpext could drive it: no connector. */ if (dcp_typec_port_unusable(port_idx)) { - drm_warn(drm, "Type-C port %u: its display pipeline is unusable\n", - port_idx); + if (!pass) + drm_warn(drm, "Type-C port %u: its display pipeline is unusable\n", + port_idx); continue; } if (fixed) { if (!dcp_typec_port_has_candidate(port_idx, pipeline)) continue; + /* T6050: tunnel-only pairs in the second pass */ + if (dcp_typec_port_tunnel_only(port_idx, pipeline) != pass) + continue; mask = crtc_mask[idx / nr_ports]; if (!mask) continue; diff --git a/drivers/gpu/drm/apple/dcp-fabric-core.c b/drivers/gpu/drm/apple/dcp-fabric-core.c index 6a7fab89c1908..74328af75a7bd 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-core.c +++ b/drivers/gpu/drm/apple/dcp-fabric-core.c @@ -186,7 +186,8 @@ dcp_fabric_free_route(const struct dcp_fabric_port *port, for (route = port->routes; route; route = route->next) { unsigned int score; - if (!dcp_fabric_available(route->pipeline, policy)) + if (route->tunnel_only || + !dcp_fabric_available(route->pipeline, policy)) continue; score = dcp_fabric_score(route->pipeline, policy); if (score < best_score) { @@ -194,7 +195,8 @@ dcp_fabric_free_route(const struct dcp_fabric_port *port, best_score = score; } } - if (!last || !dcp_fabric_available(last->pipeline, policy)) + if (!last || last->tunnel_only || + !dcp_fabric_available(last->pipeline, policy)) return best; if (!policy->dual_stream && best && best_score < dcp_fabric_score(last->pipeline, policy)) @@ -215,6 +217,17 @@ dcp_fabric_port_route(const struct dcp_fabric_port *port, return NULL; } +/* Does a DP tunnel hold any of @port's owner slots? */ +static bool dcp_fabric_port_tunneled(const struct dcp_fabric_port *port) +{ + unsigned int i; + + for (i = 0; i < DCP_FABRIC_DPIN_MAX; i++) + if (port->owner[i] && port->owner[i]->tunnel) + return true; + return false; +} + static void dcp_fabric_plan_pipeline(struct dcp_fabric_pipeline *pipeline, const struct dcp_fabric_port *ports, const struct dcp_fabric_port *arriving, @@ -242,10 +255,11 @@ static void dcp_fabric_plan_pipeline(struct dcp_fabric_pipeline *pipeline, BIT(pipeline->crtc_index))) continue; route = dcp_fabric_port_route(port, pipeline); - tunnel = stream || (port->owner[0] && port->owner[0]->tunnel) || + tunnel = stream || dcp_fabric_port_tunneled(port) || (port == arriving && dpin == 0); if (!route || (tunnel && - (route->tunnel_clock_blocked & BIT(stream)))) + (route->tunnel_clock_blocked & BIT(stream))) || + (!tunnel && route->tunnel_only)) continue; port->plan->target[stream] = route; return; @@ -288,11 +302,18 @@ void dcp_fabric_plan(struct dcp_fabric_pipeline *pipelines, } EXPORT_SYMBOL_GPL(dcp_fabric_plan); -/* 1 means an already handed, matching stream; zero admits allocation. */ +/* + * 1 means an already handed, matching stream; zero admits allocation. + * @per_dpin: DP IN 2 and 3 have owner slots of their own. + */ int dcp_fabric_tunnel_slot(const struct dcp_fabric_port *port, - unsigned int dpin) + unsigned int dpin, bool per_dpin) { - const struct dcp_fabric_route *slot = port->owner[dcp_fabric_dpin_slot(dpin)]; + const struct dcp_fabric_route *slot; + + if (dpin >= DCP_FABRIC_DPIN_MAX) + return -EINVAL; + slot = port->owner[dcp_fabric_tunnel_owner(dpin, per_dpin)]; if (slot) return slot->tunnel && slot->dpin == dpin ? 1 : -EADDRINUSE; @@ -391,6 +412,10 @@ dcp_fabric_follow(const struct dcp_fabric_route *from, (holder->dpin >= DCP_FABRIC_DPIN_MAX || (holder_back->tunnel_clock_blocked & BIT(holder->dpin))))) return DCP_FABRIC_FOLLOW_REFUSE; + /* A direct stream never moves onto a tunnel-only route. */ + if ((!from->tunnel && to->tunnel_only) || + (holder && !holder->tunnel && holder_back && holder_back->tunnel_only)) + return DCP_FABRIC_FOLLOW_REFUSE; pipeline = to->pipeline; if (!pipeline->bound || pipeline->fixed_busy || pipeline->terminal || !pipeline->services_ready) diff --git a/drivers/gpu/drm/apple/dcp-fabric-core.h b/drivers/gpu/drm/apple/dcp-fabric-core.h index 602e7b2efb7f6..8ee2f535dfe6a 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-core.h +++ b/drivers/gpu/drm/apple/dcp-fabric-core.h @@ -8,8 +8,10 @@ /* * A Thunderbolt DP tunnel enters through one of up to four DP IN adapters of * the port's host router, each behind a crossbar output of its own. A port - * carries at most two streams, primary and secondary: DP IN n and n + 2 share - * a stream slot. + * carries two streams, primary and secondary: DP IN n and n + 2 share a + * stream slot. Where every pipeline drives one DP IN of its own (T6050, fixed + * CRTCs), DP IN 2 and 3 have owner slots of their own as well; see + * dcp_fabric_tunnel_owner(). */ #define DCP_FABRIC_DPIN_MAX 4 @@ -18,6 +20,16 @@ static inline unsigned int dcp_fabric_dpin_slot(unsigned int dpin) return dpin & 1; } +/* + * The owner slot (dcp_fabric_port.owner[]) of DP IN @dpin: its stream slot, + * or the DP IN itself when @per_dpin, each pipeline taking one DP IN. + */ +static inline unsigned int dcp_fabric_tunnel_owner(unsigned int dpin, + bool per_dpin) +{ + return per_dpin ? dpin : dcp_fabric_dpin_slot(dpin); +} + enum dcp_fabric_presence_state { DCP_FABRIC_ABSENT, DCP_FABRIC_SETTLING, @@ -53,6 +65,8 @@ struct dcp_fabric_route { unsigned int dpin; /* DP IN adapters this source cannot clock; direct DP is unaffected. */ u8 tunnel_clock_blocked; + /* Carries DP tunnels only, never a direct DP-alt stream. */ + bool tunnel_only; }; struct dcp_fabric_plan { @@ -65,7 +79,13 @@ struct dcp_fabric_port { unsigned long key; struct dcp_fabric_port *next; struct dcp_fabric_route *routes; - struct dcp_fabric_route *owner[2]; + /* + * Indexed by dcp_fabric_tunnel_owner(): [0] the primary stream (direct + * DP, DP IN 0, and DP IN 2 unless per-DP IN), [1] the secondary (DP + * IN 1, and 3 unless per-DP IN), [2] and [3] DP IN 2 and 3 with per-DP + * IN slots. + */ + struct dcp_fabric_route *owner[DCP_FABRIC_DPIN_MAX]; struct dcp_fabric_route *preferred; u32 candidate_crtcs[2]; bool wanted; @@ -196,7 +216,7 @@ void dcp_fabric_plan(struct dcp_fabric_pipeline *pipelines, const struct dcp_fabric_port *ports, const struct dcp_fabric_port *arriving, unsigned int dpin); int dcp_fabric_tunnel_slot(const struct dcp_fabric_port *port, - unsigned int dpin); + unsigned int dpin, bool per_dpin); struct dcp_fabric_route * dcp_fabric_tunnel_candidate(const struct dcp_fabric_port *port, const struct dcp_fabric_policy *policy, diff --git a/drivers/gpu/drm/apple/dcp-fabric-test.c b/drivers/gpu/drm/apple/dcp-fabric-test.c index ef6381b159073..542852e4409c3 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-test.c +++ b/drivers/gpu/drm/apple/dcp-fabric-test.c @@ -69,7 +69,7 @@ static int fabric_tunnel(struct fabric_fixture *f, unsigned int p, struct dcp_fabric_route *route; int error; - error = dcp_fabric_tunnel_slot(&f->port[p], dpin); + error = dcp_fabric_tunnel_slot(&f->port[p], dpin, false); if (error) return error > 0 ? 0 : error; route = dcp_fabric_tunnel_candidate(&f->port[p], &f->policy, NULL, @@ -370,14 +370,14 @@ static void fabric_scenario_test(struct kunit *test) case 17: KUNIT_ASSERT_EQ(test, fabric_tunnel(&f, 0, 0), 0); f.route[0][1].dpin = 1; - KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&f.port[0], 0), + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&f.port[0], 0, false), -EADDRINUSE); fabric_init(&f, false); KUNIT_ASSERT_EQ(test, fabric_direct(&f, 0), 0); - KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&f.port[0], 1), + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&f.port[0], 1, false), -EBUSY); /* Preserve the original occupied-primary errno in this extraction. */ - KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&f.port[0], 0), + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&f.port[0], 0, false), -EADDRINUSE); break; case 18: @@ -2063,6 +2063,122 @@ static void fabric_t6030_plan_test(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, f.plan[0].target[1], NULL); } +/* T6050: each pipeline takes one DP IN, so DP IN 2 and 3 own slots of their own. */ +static void fabric_per_dpin_slot_test(struct kunit *test) +{ + struct dcp_fabric_pipeline pipeline[3] = {}; + struct dcp_fabric_route route[3] = {}; + struct dcp_fabric_port port = {}; + unsigned int i; + + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_owner(0, false), 0); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_owner(2, false), 0); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_owner(3, false), 1); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_owner(1, true), 1); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_owner(2, true), 2); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_owner(3, true), 3); + + for (i = 0; i < 3; i++) { + route[i].pipeline = &pipeline[i]; + route[i].tunnel = true; + route[i].dpin = i; + } + + /* A dock's three displays: DP IN 0, 1 and 2 each get a slot. */ + for (i = 0; i < 3; i++) { + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, i, true), 0); + port.owner[dcp_fabric_tunnel_owner(i, true)] = &route[i]; + } + KUNIT_EXPECT_PTR_EQ(test, port.owner[2], &route[2]); + /* the handed stream repeats; DP IN 3 is still free */ + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, 2, true), 1); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, 3, true), 0); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, DCP_FABRIC_DPIN_MAX, true), + -EINVAL); + + /* Elsewhere DP IN 2 shares DP IN 0's occupied slot. */ + port.owner[2] = NULL; + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, 2, false), -EADDRINUSE); + + /* A direct DP-alt display holds the port against every DP IN. */ + memset(&port, 0, sizeof(port)); + route[0].tunnel = false; + port.owner[0] = &route[0]; + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, 2, true), -EBUSY); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, 3, true), -EBUSY); +} + +/* A tunnel-only route never takes a direct DP-alt stream. */ +static void fabric_tunnel_only_test(struct kunit *test) +{ + struct fabric_fixture f; + int error; + + /* Pipeline 1 would win: the hybrid pipeline 0 is kept for HDMI. */ + fabric_init(&f, false); + f.route[0][1].tunnel_only = true; + KUNIT_EXPECT_PTR_EQ(test, dcp_fabric_free_route(&f.port[0], &f.policy), + &f.route[0][0]); + /* not even as the port's last route */ + f.port[0].preferred = &f.route[0][1]; + KUNIT_EXPECT_PTR_EQ(test, dcp_fabric_free_route(&f.port[0], &f.policy), + &f.route[0][0]); + /* It still carries a tunnel. */ + KUNIT_EXPECT_PTR_EQ(test, + dcp_fabric_tunnel_candidate(&f.port[0], &f.policy, NULL, + false, 0, true, &error), + &f.route[0][1]); + f.route[0][0].tunnel_only = true; + KUNIT_EXPECT_PTR_EQ(test, dcp_fabric_free_route(&f.port[0], &f.policy), + NULL); + + /* The pairing plan passes it over for a direct stream only. */ + fabric_init(&f, true); + f.route[0][0].tunnel_only = true; + f.port[0].wanted = true; + f.port[0].hpd = true; + dcp_fabric_plan(f.pipeline, f.port, NULL, 0); + KUNIT_EXPECT_PTR_EQ(test, f.plan[0].target[0], &f.route[0][1]); + f.port[0].wanted = false; + dcp_fabric_plan(f.pipeline, f.port, &f.port[0], 0); + KUNIT_EXPECT_PTR_EQ(test, f.plan[0].target[0], &f.route[0][0]); + + /* A tunnel in a per-DP IN slot makes the port's stream a tunnel. */ + fabric_init(&f, true); + f.route[0][0].tunnel_only = true; + f.port[0].wanted = true; + f.port[0].hpd = true; + f.route[1][1].tunnel = true; + f.port[0].owner[2] = &f.route[1][1]; + dcp_fabric_plan(f.pipeline, f.port, NULL, 0); + KUNIT_EXPECT_PTR_EQ(test, f.plan[0].target[0], &f.route[0][0]); + + /* A direct stream does not follow its CRTC onto it; a tunnel does. */ + fabric_init(&f, false); + f.route[0][1].tunnel_only = true; + KUNIT_EXPECT_EQ(test, dcp_fabric_follow(&f.route[0][0], &f.route[0][1], + NULL, NULL, false, &f.policy), + DCP_FABRIC_FOLLOW_REFUSE); + f.route[0][0].tunnel = true; + KUNIT_EXPECT_EQ(test, dcp_fabric_follow(&f.route[0][0], &f.route[0][1], + NULL, NULL, false, &f.policy), + DCP_FABRIC_FOLLOW_MOVE); + /* nor is a direct holder swapped onto one */ + f.route[1][0].tunnel_only = true; + f.pipeline[1].owned = true; + f.route[0][0].tunnel_only = false; + f.route[0][1].tunnel_only = false; + KUNIT_EXPECT_EQ(test, dcp_fabric_follow(&f.route[0][0], &f.route[0][1], + &f.route[1][1], &f.route[1][0], true, + &f.policy), + DCP_FABRIC_FOLLOW_REFUSE); + f.route[1][0].tunnel_only = false; + KUNIT_EXPECT_EQ(test, dcp_fabric_follow(&f.route[0][0], &f.route[0][1], + &f.route[1][1], &f.route[1][0], true, + &f.policy), + DCP_FABRIC_FOLLOW_SWAP); +} + static void fabric_t6030_follow_test(struct kunit *test) { struct fabric_fixture f; @@ -2387,6 +2503,8 @@ static struct kunit_case fabric_tests[] = { KUNIT_CASE(fabric_t6030_clock_header_parity_test), KUNIT_CASE(fabric_t6030_plan_test), KUNIT_CASE(fabric_t6030_follow_test), + KUNIT_CASE(fabric_per_dpin_slot_test), + KUNIT_CASE(fabric_tunnel_only_test), KUNIT_CASE(fabric_reclaim_transaction_test), KUNIT_CASE_PARAM(fabric_shared_wiring_test, fabric_wiring_gen_params), KUNIT_CASE(fabric_binding_cookie_test), diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 1e057d87c7822..a2dc9f701a8f0 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -96,8 +96,21 @@ struct apple_dcp_typec_port { struct list_head link; struct list_head routes; struct device_node *connector_np; - struct apple_dcp_typec_route *owner; - struct apple_dcp_typec_route *secondary_owner; + /* The owner slots, as core.owner[] (see dcp_fabric_tunnel_owner()). */ + union { + struct { + struct apple_dcp_typec_route *owner; + struct apple_dcp_typec_route *secondary_owner; + /* + * T6050 (fixed CRTCs): each pipeline drives one DP IN, + * so DP IN 2 and 3 get slots of their own instead of + * sharing DP IN 0/1's (see dcp_tb_slot()). Always NULL + * elsewhere. + */ + struct apple_dcp_typec_route *dpin_owner[2]; + }; + struct apple_dcp_typec_route *slots[DCP_FABRIC_DPIN_MAX]; + }; /* Keep a port on its last DCP while that pipeline remains free. */ struct apple_dcp_typec_route *preferred_route; /* DRM connector for this physical port, driven by whichever DCP owns it */ @@ -361,6 +374,52 @@ bool dcp_typec_fixed_crtcs(void) return of_machine_is_compatible("apple,t6050"); } +static_assert(offsetof(struct apple_dcp_typec_port, dpin_owner[1]) == + offsetof(struct apple_dcp_typec_port, slots[DCP_FABRIC_DPIN_MAX - 1])); + +/* + * The owner slot of a Thunderbolt DP IN. Elsewhere a port carries two + * streams and DP IN n and n + 2 share a slot (dcp_fabric_dpin_slot()). With + * fixed CRTCs every pipeline takes one DP IN of its own, so DP IN 2 and 3 get + * separate slots and a third or fourth dock display can claim a free pipeline. + */ +static struct apple_dcp_typec_route ** +dcp_tb_slot(struct apple_dcp_typec_port *port, unsigned int dpin) +{ + bool per_dpin = dpin < DCP_FABRIC_DPIN_MAX && dcp_typec_fixed_crtcs(); + + return &port->slots[dcp_fabric_tunnel_owner(dpin, per_dpin)]; +} + +static bool dcp_typec_port_owned(const struct apple_dcp_typec_port *port) +{ + for (unsigned int i = 0; i < ARRAY_SIZE(port->slots); i++) + if (port->slots[i]) + return true; + return false; +} + +static bool dcp_typec_port_owner_is(const struct apple_dcp_typec_port *port, + const struct apple_dcp_typec_route *route) +{ + for (unsigned int i = 0; i < ARRAY_SIZE(port->slots); i++) + if (port->slots[i] == route) + return true; + return false; +} + +/* + * Does a Thunderbolt DP tunnel hold any of @port's slots? Its teardown is + * its own path's, whichever DP IN went first. + */ +static bool dcp_typec_port_tunneled(const struct apple_dcp_typec_port *port) +{ + for (unsigned int i = 0; i < ARRAY_SIZE(port->slots); i++) + if (port->slots[i] && port->slots[i]->tunnel) + return true; + return false; +} + static struct apple_connector * dcp_typec_route_connector(struct apple_dcp_typec_route *route, bool tunnel) { @@ -1032,6 +1091,7 @@ static bool dcp_typec_move_starved_locked(void) continue; list_for_each_entry(route, &port->routes, port_link) { if (route != owner && route->dcp->fixed_phy && + !route->core.tunnel_only && dcp_typec_route_available(route)) { to = route; break; @@ -1079,6 +1139,7 @@ static bool dcp_typec_move_off_hybrid_locked(struct apple_dcp_typec_port *port, return false; list_for_each_entry(route, &port->routes, port_link) { if (route != owner && !route->dcp->fixed_phy && route->dcp->crtc && + !route->core.tunnel_only && dcp_typec_route_available(route)) { to = route; break; @@ -1316,9 +1377,9 @@ static void dcp_fabric_snapshot_port(struct apple_dcp_typec_port *port, struct dcp_fabric_route **tail = &port->core.routes; lockdep_assert_held(&dcp_typec_fabric_lock); - port->core.owner[0] = port->owner ? &port->owner->core : NULL; - port->core.owner[1] = - port->secondary_owner ? &port->secondary_owner->core : NULL; + for (unsigned int i = 0; i < ARRAY_SIZE(port->slots); i++) + port->core.owner[i] = + port->slots[i] ? &port->slots[i]->core : NULL; port->core.preferred = port->preferred_route ? &port->preferred_route->core : NULL; port->core.wanted = port->dp_wanted && !port->typec_yielded; @@ -1939,7 +2000,7 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, } /* a Thunderbolt/USB4 DP tunnel is torn down by its own path */ - if (port->owner && port->owner->tunnel) { + if (dcp_typec_port_tunneled(port)) { port->applied_valid = true; return 0; } @@ -1973,7 +2034,7 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, * way): don't act on or remember this state; the tunnel teardown drops * what was recorded so the next update is applied. */ - if (port->owner && port->owner->tunnel) { + if (dcp_typec_port_tunneled(port)) { port->applied_valid = false; return 0; } @@ -2720,6 +2781,12 @@ static int dcp_tb_candidate(void *data) struct apple_dcp_typec_route *best, *planned = NULL; struct mux_control *ctl; unsigned int dpin = ctx->dpin; + /* + * The stream picks the pairing order's connector and CRTC mask. Only + * the dual-stream policy reads them, which fixed-CRTC machines, the + * ones with per-DP IN owner slots, never run (see + * dcp_typec_ordered_dual_stream()). + */ unsigned int stream = dcp_fabric_dpin_slot(dpin); bool ordered; int ret; @@ -3116,8 +3183,7 @@ static int dcp_tb_split_locked(struct apple_dcp_typec_port *port, static int dcp_tb_release_locked(struct apple_dcp_typec_port *port, unsigned int dpin) { - struct apple_dcp_typec_route **slot = dcp_fabric_dpin_slot(dpin) ? - &port->secondary_owner : &port->owner; + struct apple_dcp_typec_route **slot = dcp_tb_slot(port, dpin); struct apple_dcp *dcp; int ret; @@ -3158,7 +3224,7 @@ static int dcp_tb_release_locked(struct apple_dcp_typec_port *port, return ret; } *slot = NULL; - port->hpd = !!(port->owner || port->secondary_owner); + port->hpd = dcp_typec_port_owned(port); /* re-apply the next Type-C mux state in full */ port->applied_valid = false; if (dcp->hdmi_hpd && dcp->active && @@ -3178,7 +3244,7 @@ static int dcp_tb_dispatch_request(void *data, const struct dcp_fabric_port *fou unsigned int dpin = ctx->dpin; int ret; - slot = dcp_fabric_dpin_slot(dpin) ? &port->secondary_owner : &port->owner; + slot = dcp_tb_slot(port, dpin); if (dpin == 1 && (tiled_split || port->split_dcp)) { ret = dcp_tb_split_locked(port, ctx); @@ -3215,24 +3281,19 @@ static int dcp_tb_dispatch_request(void *data, const struct dcp_fabric_port *fou return dcp_tb_release_locked(port, dpin); { - struct dcp_fabric_port state = { - .owner[0] = port->owner ? &port->owner->core : NULL, - .owner[1] = port->secondary_owner ? - &port->secondary_owner->core : - NULL, - }; + struct dcp_fabric_port state = {}; - if (port->owner) { - port->owner->core.tunnel = port->owner->tunnel; - port->owner->core.dpin = port->owner->tunnel_dpin; - } - if (port->secondary_owner) { - port->secondary_owner->core.tunnel = - port->secondary_owner->tunnel; - port->secondary_owner->core.dpin = - port->secondary_owner->tunnel_dpin; + for (unsigned int i = 0; i < ARRAY_SIZE(port->slots); i++) { + struct apple_dcp_typec_route *owner = port->slots[i]; + + if (!owner) + continue; + owner->core.tunnel = owner->tunnel; + owner->core.dpin = owner->tunnel_dpin; + state.owner[i] = &owner->core; } - ret = dcp_fabric_tunnel_slot(&state, dpin); + ret = dcp_fabric_tunnel_slot(&state, dpin, + dcp_typec_fixed_crtcs()); if (ret > 0) return 0; if (ret) { @@ -3262,8 +3323,7 @@ static int dcp_tb_dispatch_request(void *data, const struct dcp_fabric_port *fou static void dcp_tb_finish_request(struct apple_dcp_typec_port *port, const struct dcp_tb_attach_context *request) { - struct apple_dcp_typec_route *route = dcp_fabric_dpin_slot(request->dpin) ? - port->secondary_owner : port->owner; + struct apple_dcp_typec_route *route = *dcp_tb_slot(port, request->dpin); struct apple_dcp *dcp; bool matching; @@ -3417,7 +3477,7 @@ int apple_dcp_tb_dp_event(struct device_node *connector_np, unsigned int dpin, if (pos->connector_np != connector_np) continue; - route = dcp_fabric_dpin_slot(dpin) ? pos->secondary_owner : pos->owner; + route = *dcp_tb_slot(pos, dpin); if (route && route->tunnel && route->tunnel_dpin == dpin && route->tunnel_generation == generation) { dcp = route->dcp; @@ -4234,6 +4294,25 @@ bool dcp_typec_port_has_candidate(unsigned int idx, struct platform_device *pdev return false; } +/* Is @pdev's route to port @idx for DP tunnels only (apple,tunnel-only)? */ +bool dcp_typec_port_tunnel_only(unsigned int idx, struct platform_device *pdev) +{ + struct apple_dcp_typec_port *port; + struct apple_dcp_typec_route *route; + + guard(mutex)(&dcp_typec_fabric_lock); + + port = dcp_typec_port_by_index(idx); + if (!port) + return false; + + list_for_each_entry(route, &port->routes, port_link) + if (route->dcp->dev == &pdev->dev) + return route->core.tunnel_only; + + return false; +} + /* * Is every pipeline that can drive port @idx unusable (a failed T8122 * dcpext, or a T8132 dcpext, whose DRM outputs are its own, see @@ -4274,8 +4353,7 @@ static void dcp_typec_port_bind_connector(struct apple_dcp_typec_port *port, if (WARN_ON(!route)) return; route->connector = connector; - owner = route == port->owner || route == port->secondary_owner ? - route : NULL; + owner = dcp_typec_port_owner_is(port, route) ? route : NULL; } else if (secondary) { port->secondary_connector = connector; owner = port->secondary_owner; @@ -4331,30 +4409,23 @@ static void dcp_typec_route_unregister(void *data) port->preferred_route = NULL; if (port->split_dcp == route->dcp) dcp_tb_split_teardown_locked(port, true); - if (port->owner == route) { - struct apple_dcp *dcp = route->dcp; - - if (route->tunnel) - dcp_tb_binding_retire(dcp, route); - if (port->hpd || dcp->typec_cable_connected) - dcp_dptx_disconnect_oob(to_platform_device(dcp->dev), 0); - port->hpd = false; - if (dcp_typec_route_deactivate(route) && dcp_is_external_h17p(dcp)) - return; - port->owner = NULL; - } - if (port->secondary_owner == route) { + for (unsigned int i = 0; i < ARRAY_SIZE(port->slots); i++) { struct apple_dcp *dcp = route->dcp; + if (port->slots[i] != route) + continue; if (route->tunnel) dcp_tb_binding_retire(dcp, route); if (port->hpd || dcp->typec_cable_connected) dcp_dptx_disconnect_oob(to_platform_device(dcp->dev), 0); + /* The primary stream's going drops the port's HPD, as before. */ + if (!i) + port->hpd = false; if (dcp_typec_route_deactivate(route) && dcp_is_external_h17p(dcp)) return; - port->secondary_owner = NULL; + port->slots[i] = NULL; } - port->hpd = !!(port->owner || port->secondary_owner); + port->hpd = dcp_typec_port_owned(port); list_del(&route->port_link); if (route->dual_stream) atomic_dec(&dcp_dual_stream_routes); @@ -4503,6 +4574,10 @@ static int dcp_register_typec_routes_present(void *data) return dev_err_probe(dev, ret, "%pOF: missing crossbar state\n", route_np); + /* A route for USB4 DP tunnels only is never given a DP-alt stream. */ + route->core.tunnel_only = + of_property_read_bool(route_np, "apple,tunnel-only"); + ret = of_property_read_u32_index(dev->of_node, "apple,typec-dptx-phys", route_index, &route->dptx_phy); if (ret) @@ -4940,6 +5015,7 @@ static bool dcp_typec_hdmi_reclaim(struct apple_dcp *dcp) return false; list_for_each_entry(route, &port->routes, port_link) { if (route == owner || !route->dcp->crtc || + (!owner->tunnel && route->core.tunnel_only) || !dcp_typec_route_available(route) || (owner->tunnel && !dcp_typec_tunnel_ctl(route, owner->tunnel_dpin)) || (port->split_dcp == dcp && !dcp_follow_split_fits(route))) diff --git a/drivers/gpu/drm/apple/dcp-fabric.h b/drivers/gpu/drm/apple/dcp-fabric.h index edca8065bd21a..98f9d893c5680 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.h +++ b/drivers/gpu/drm/apple/dcp-fabric.h @@ -76,6 +76,7 @@ bool dcp_has_typec_routes(struct platform_device *pdev); unsigned int dcp_typec_nr_ports(void); struct device_node *dcp_typec_port_of_node(unsigned int idx); bool dcp_typec_port_has_candidate(unsigned int idx, struct platform_device *pdev); +bool dcp_typec_port_tunnel_only(unsigned int idx, struct platform_device *pdev); bool dcp_typec_port_unusable(unsigned int idx); void dcp_typec_port_set_connector(unsigned int idx, bool secondary, struct apple_connector *connector,