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, diff --git a/tools/asahi/tiled-split-tests.py b/tools/asahi/tiled-split-tests.py index 921741be6b1e9..7ee72aa18bf5c 100644 --- a/tools/asahi/tiled-split-tests.py +++ b/tools/asahi/tiled-split-tests.py @@ -17,18 +17,18 @@ ROOT = Path(__file__).resolve().parents[2] FUNCTIONS = { - 'drivers/gpu/drm/apple/dcp-fabric-core.h': ['dcp_fabric_dpin_slot'], + 'drivers/gpu/drm/apple/dcp-fabric-core.h': ['dcp_fabric_dpin_slot', 'dcp_fabric_tunnel_owner'], 'drivers/gpu/drm/apple/dcp-fabric-session.h': ['dcp_fabric_binding_request'], 'drivers/gpu/drm/apple/dcp-fabric-core.c': ['dcp_fabric_tunnel_slot'], 'drivers/gpu/drm/apple/dcp-fabric.c': [ 'dcp_typec_route_no_dp_alt', 'dcp_is_t8132_ext', 'dcp_typec_port_untileable', - 'dcp_tb_split_locked', 'dcp_tb_dispatch_request'], + 'dcp_tb_slot', 'dcp_tb_split_locked', 'dcp_tb_dispatch_request'], } CASES = ['t6030-dpin1-alone', 't6030-dpin1-alone-before-services', 't6030-dpin1-with-external-owner', 't6030-dpin1-then-dpin0', 't6030-dpin0-then-dpin1', 't6030-split-off', 't6030-inactive-dpin1', 't6050-dpin1-alone', 't6050-dpin1-with-tile-hint', 't6050-dpin3-alone', - 't6050-dpin3-shares-slot', + 't6050-dpin-own-slots', 't6030-dpin3-shares-slot', 'internal-dpin1-alone-waits', 'internal-not-ready-waits', 'mixed-routes-wait', 'no-routes-wait', 'internal-tile-hint-pending', 'internal-tiled-join', 'internal-owner-without-port1', @@ -56,9 +56,12 @@ ('dcpext-tileable', '!dcp_is_t8132_ext(route->dcp) &&\n', ''), # Firmware 27 pipelines drive one DP IN each: never a tile. ('fw27-tileable', ' &&\n\t\t route->dcp->fw_compat != DCP_FIRMWARE_V_27_0)', ')'), - # DP IN 3 is a second stream, in DP IN 1's slot. - ('dpin3-primary-slot', 'slot = dcp_fabric_dpin_slot(dpin) ? &port->secondary_owner : &port->owner;', - 'slot = dpin == 1 ? &port->secondary_owner : &port->owner;'), + # Without fixed CRTCs DP IN 3 is a second stream, in DP IN 1's slot. + ('dpin3-primary-slot', 'return dpin & 1;', 'return dpin == 1;'), + # With fixed CRTCs every DP IN has a slot of its own, in the driver and in the core. + ('driver-shared-slots', 'bool per_dpin = dpin < DCP_FABRIC_DPIN_MAX && dcp_typec_fixed_crtcs();', + 'bool per_dpin = false;'), + ('core-shared-slots', 'dcp_typec_fixed_crtcs());', 'false);'), ('gate-always', 'if (dcp_typec_port_untileable(port))', 'if (true || dcp_typec_port_untileable(port))'), ] @@ -70,12 +73,16 @@ def function(source, name): source, re.M | re.S) if not match: raise ValueError(name) + start = match.start() + # The return type on the line above, kernel style. + if source.startswith(name + '(', start): + start = source.rindex('\n', 0, start - 1) + 1 pos = source.index('{', match.start()) + 1 depth = 1 while depth: depth += (source[pos] == '{') - (source[pos] == '}') pos += 1 - return source[match.start():pos] + '\n' + return source[start:pos] + '\n' def build(out, bodies, tag): diff --git a/tools/asahi/tiled-split/fixture.c b/tools/asahi/tiled-split/fixture.c index dfd4805a89cde..30f4ca0a79726 100644 --- a/tools/asahi/tiled-split/fixture.c +++ b/tools/asahi/tiled-split/fixture.c @@ -3,8 +3,9 @@ * Host fixture for the Thunderbolt DPIN1 dispatch and tiled-display split * admission. The production bodies of dcp_tb_dispatch_request(), * dcp_tb_split_locked(), dcp_typec_port_untileable(), - * dcp_typec_route_no_dp_alt(), dcp_fabric_tunnel_slot(), - * dcp_fabric_dpin_slot() and dcp_fabric_binding_request() are pasted in, + * dcp_typec_route_no_dp_alt(), dcp_tb_slot(), dcp_fabric_tunnel_slot(), + * dcp_fabric_dpin_slot(), dcp_fabric_tunnel_owner() and + * dcp_fabric_binding_request() are pasted in, * after DCP_FABRIC_DPIN_MAX and enum dcp_firmware_version; * only what lies below them (join, connect, teardown, release, attach, * rebalance) is stubbed, and every stub call is recorded. @@ -29,6 +30,7 @@ typedef uint8_t u8; #define time_before(a, b) ((long)((a) - (b)) < 0) #define dev_warn(dev, ...) fprintf(stderr, __VA_ARGS__) #define EXPORT_SYMBOL_GPL(x) +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) /* FABRIC_DEFINES */ static inline unsigned int dcp_fabric_dpin_slot(unsigned int dpin); @@ -94,7 +96,7 @@ struct dcp_fabric_port { unsigned long key; struct dcp_fabric_port *next; struct dcp_fabric_route *routes; - struct dcp_fabric_route *owner[2]; + struct dcp_fabric_route *owner[DCP_FABRIC_DPIN_MAX]; struct dcp_fabric_route *preferred; u32 candidate_crtcs[2]; bool wanted, hpd; @@ -114,7 +116,14 @@ struct apple_dcp_typec_route { struct apple_dcp_typec_port { struct dcp_fabric_port core; struct list_head routes; - struct apple_dcp_typec_route *owner, *secondary_owner; + /* The owner slots, laid out as in production (see dcp_tb_slot()). */ + union { + struct { + struct apple_dcp_typec_route *owner, *secondary_owner; + struct apple_dcp_typec_route *dpin_owner[2]; + }; + struct apple_dcp_typec_route *slots[DCP_FABRIC_DPIN_MAX]; + }; struct apple_dcp *split_dcp; unsigned long tile_hint_deadline; }; @@ -131,6 +140,11 @@ struct dcp_tb_attach_context { struct dcp_fabric_attach_ops { int unused; }; static bool tiled_split = true; +/* T6050: every pipeline drives one DP IN (production: the SoC compatible). */ +static bool fixed_crtcs; +static bool dcp_typec_fixed_crtcs(void) { return fixed_crtcs; } +static struct apple_dcp_typec_route ** +dcp_tb_slot(struct apple_dcp_typec_port *port, unsigned int dpin); static unsigned long jiffies = 1000; static int dcp_typec_fabric_lock; static const struct dcp_fabric_attach_ops dcp_tb_attach_ops; @@ -180,10 +194,7 @@ static int dcp_dptx_connect(struct apple_dcp *dcp, unsigned int port) static int dcp_tb_release_locked(struct apple_dcp_typec_port *port, unsigned int dpin) { st.release++; - if (dcp_fabric_dpin_slot(dpin)) - port->secondary_owner = NULL; - else - port->owner = NULL; + *dcp_tb_slot(port, dpin) = NULL; return 0; } @@ -244,6 +255,7 @@ static void topology(enum kind kind, bool port1_ready) /* T6050: pipelines on the AP's own display fabric, firmware 27 */ if (kind == T6050_FW27) dcp_a.fw_compat = dcp_b.fw_compat = DCP_FIRMWARE_V_27_0; + fixed_crtcs = kind == T6050_FW27; /* A T8132 dcpext is no external processor: only its compatible says so. */ np_a.compatible = np_b.compatible = kind == T8132_DCPEXT ? "apple,t8132-dcpext" : "apple,dcp"; @@ -384,26 +396,45 @@ static void t6050_dpin1_with_tile_hint(void) CHECK(st.attach == 1 && st.attach_dpin[0] == 1 && !st.join); } -/* DP IN n and n + 2 share a stream slot: DP IN 3 is a second stream. */ +/* With fixed CRTCs every DP IN has an owner slot of its own: DP IN 3 is not a second stream. */ static void t6050_dpin3_alone(void) { topology(T6050_FW27, true); CHECK(request(3, true, 9) == 0); CHECK(st.attach == 1 && st.attach_dpin[0] == 3); - CHECK(port.secondary_owner == &attach_route[3] && !port.owner); + CHECK(port.dpin_owner[1] == &attach_route[3] && !port.owner && !port.secondary_owner); CHECK(!st.join && !st.teardown); } -static void t6050_dpin3_shares_slot(void) +/* A dock's four tunnels each take their DP IN's slot, whatever the order. */ +static void t6050_dpin_own_slots(void) { topology(T6050_FW27, true); + CHECK(request(1, true, 9) == 0); + CHECK(request(3, true, 10) == 0); + CHECK(request(2, true, 11) == 0); + CHECK(request(0, true, 12) == 0); + CHECK(st.attach == 4); + for (unsigned int i = 0; i < DCP_FABRIC_DPIN_MAX; i++) + CHECK(port.slots[i] == &attach_route[i] && attach_route[i].tunnel_dpin == i); + /* Ending DP IN 3's stream frees its slot only. */ + CHECK(request(3, false, 10) == 0); + CHECK(st.release == 1 && !port.dpin_owner[1] && port.secondary_owner == &attach_route[1]); + CHECK(!st.join && !st.teardown); +} + +/* Elsewhere DP IN n and n + 2 share a stream slot: DP IN 3 is a second stream. */ +static void t6030_dpin3_shares_slot(void) +{ + topology(ALL_EXTERNAL, true); CHECK(request(3, true, 9) == 0); + CHECK(port.secondary_owner == &attach_route[3] && !port.dpin_owner[1]); CHECK(request(1, true, 10) == -EADDRINUSE); CHECK(st.attach == 1 && port.secondary_owner == &attach_route[3]); /* DP IN 2 takes the primary slot beside it. */ CHECK(request(2, true, 11) == 0); CHECK(st.attach == 2 && st.attach_dpin[1] == 2 && port.owner == &attach_route[2]); - CHECK(!st.join && !st.teardown); + CHECK(!port.dpin_owner[0] && !st.join && !st.teardown); } /* M1/M2: pipelines that can host a tile keep the dpin0 wait. */ @@ -535,7 +566,8 @@ static const struct { const char *name; void (*fn)(void); } cases[] = { { "t6050-dpin1-alone", t6050_dpin1_alone }, { "t6050-dpin1-with-tile-hint", t6050_dpin1_with_tile_hint }, { "t6050-dpin3-alone", t6050_dpin3_alone }, - { "t6050-dpin3-shares-slot", t6050_dpin3_shares_slot }, + { "t6050-dpin-own-slots", t6050_dpin_own_slots }, + { "t6030-dpin3-shares-slot", t6030_dpin3_shares_slot }, { "internal-dpin1-alone-waits", internal_dpin1_alone_waits }, { "internal-not-ready-waits", internal_not_ready_waits }, { "mixed-routes-wait", mixed_routes_wait }, diff --git a/tools/asahi/tunnel-route-tests.py b/tools/asahi/tunnel-route-tests.py index c3c126657dadd..b18d7e8543ac5 100644 --- a/tools/asahi/tunnel-route-tests.py +++ b/tools/asahi/tunnel-route-tests.py @@ -22,6 +22,8 @@ MUTATIONS = { 'clock-ignored': ('& BIT(dpin)))', '& 0))'), 'snapshot-ignores-yield': ('port->dp_wanted && !port->typec_yielded;', 'port->dp_wanted;'), + 'snapshot-two-slots': ('i < ARRAY_SIZE(port->slots); i++)\n\t\tport->core.owner[i]', + 'i < 2; i++)\n\t\tport->core.owner[i]'), } diff --git a/tools/asahi/tunnel-route/fixture.c b/tools/asahi/tunnel-route/fixture.c index 5ee97e3d183f1..2bcb8e713e5be 100644 --- a/tools/asahi/tunnel-route/fixture.c +++ b/tools/asahi/tunnel-route/fixture.c @@ -10,6 +10,7 @@ typedef uint32_t u32; typedef uint64_t u64; #define READ_ONCE(x) (x) #define BIT(n) (1U << (n)) +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define lockdep_assert_held(x) ((void)0) #define list_for_each_entry(r, head, link) \ for ((r) = *(head); (r); (r) = (r)->next) @@ -48,8 +49,15 @@ struct apple_dcp_typec_route { struct apple_dcp_typec_port { struct dcp_fabric_port core; struct dcp_fabric_plan plan; - struct apple_dcp_typec_route *routes, *owner, *secondary_owner, - *preferred_route; + struct apple_dcp_typec_route *routes, *preferred_route; + /* The owner slots, laid out as in production (one per DP IN with fixed CRTCs). */ + union { + struct { + struct apple_dcp_typec_route *owner, *secondary_owner; + struct apple_dcp_typec_route *dpin_owner[2]; + }; + struct apple_dcp_typec_route *slots[DCP_FABRIC_DPIN_MAX]; + }; struct apple_connector *connector, *secondary_connector; bool dp_wanted, dp_hpd, typec_yielded; }; @@ -196,6 +204,15 @@ int main(void) assert(!dcp_typec_tunnel_ctl(&r, DCP_FABRIC_DPIN_MAX)); } } + /* The snapshot carries every owner slot, DP IN 2 and 3's own included. */ + for (unsigned int slot = 0; slot < DCP_FABRIC_DPIN_MAX; slot++) { + memset(port.slots, 0, sizeof(port.slots)); + port.slots[slot] = &source2; + dcp_fabric_snapshot_port(&port, true); + for (unsigned int i = 0; i < DCP_FABRIC_DPIN_MAX; i++) + assert(port.core.owner[i] == (i == slot ? &source2.core : NULL)); + } + memset(port.slots, 0, sizeof(port.slots)); /* A display that yielded both pipes to an HDMI display wants none. */ for (unsigned int yielded = 0; yielded < 2; yielded++) { port.dp_wanted = true; @@ -203,6 +220,6 @@ int main(void) dcp_fabric_snapshot_port(&port, true); assert(port.core.wanted == !yielded); } - puts("PASS: DCP snapshot, named/legacy controls, invalid DP IN, stale snapshot, T8132 dcpext sources, T6050 four DP INs, yielded port"); + puts("PASS: DCP snapshot, named/legacy controls, invalid DP IN, stale snapshot, T8132 dcpext sources, T6050 four DP INs, owner slots, yielded port"); return 0; } diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py index f70e13245e35d..999c47798d776 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py @@ -54,6 +54,9 @@ def check(name, unit, cases=((),), negative=False, flags=()): ''',1) # The hybrid hand-over walks a port's routes; the only route is this port's. actual=actual.replace('struct apple_dcp_typec_port { int link;', 'struct apple_dcp_typec_port { int link,routes; bool typec_yielded;',1) + # A port's owner slots are one array, as in production (one per DP IN with fixed + # CRTCs): the model's owner is slot 0, and the others stay NULL on this port. + actual=actual.replace('struct apple_dcp_typec_route *owner,*target,', 'union { struct apple_dcp_typec_route *owner; struct apple_dcp_typec_route *slots[DCP_FABRIC_DPIN_MAX]; }; struct apple_dcp_typec_route *target,',1) actual=actual.replace('#define list_for_each_entry(p,h,m) for((void)(h),(p)=sole_port();(p);(p)=NULL)', '#define list_for_each_entry(p,h,m) for((void)(h),(p)=_Generic((p),struct apple_dcp_typec_route *:sole_route(),default:sole_port());(p);(p)=NULL)',1) actual=actual.replace('static struct apple_dcp_typec_port *sole_port(void) { return &port; }', @@ -158,7 +161,9 @@ def check(name, unit, cases=((),), negative=False, flags=()): actual=actual.replace(block(actual,'static bool dcp_typec_route_available('), 'static bool dcp_typec_route_fixed_output_busy(struct apple_dcp_typec_route *r) { (void)r;return false; }\n'+available+block(dcp,'static bool dcp_typec_route_available('),1) actual=actual.replace(block(actual,'static int dcp_typec_route_deactivate('),block(dcp,dcp.rindex('static int dcp_typec_route_deactivate(')),1) pos=actual.index('static struct typec_mux_dev phy_provider') - actual=actual[:pos]+block(dcp,'static bool dcp_typec_route_is_dp(')+'\n'+block(dcp,'static int dcp_typec_route_set(')+'\n'+actual[pos:] + # route_set asks whether a tunnel holds any of the port's slots: the real helper. + tunneled='#ifndef ARRAY_SIZE\n#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))\n#endif\n'+apple_function(ROOT,'dcp_typec_port_tunneled') + actual=actual[:pos]+tunneled+block(dcp,'static bool dcp_typec_route_is_dp(')+'\n'+block(dcp,'static int dcp_typec_route_set(')+'\n'+actual[pos:] actual=actual.replace(block(actual,'static int display_set('),'''static int display_set(struct typec_mux_dev *m,struct typec_mux_state *s) { event('S');return dcp_typec_route_set(m,s); }''',1) actual=actual.replace("(void)m;assert(s->mode==TYPEC_STATE_SAFE);event('L');", "(void)m;(void)s;event('L');",1) actual=actual.replace('connector=(struct connector){.connected=true};','connector=(struct connector){.connected=true};',1)