From 36f2fbe68bcb45c0043e9b8e74876b862470a3ea Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sun, 15 Nov 2026 19:33:59 -0500 Subject: [PATCH] drm/apple: dcp-fabric: keep DP alt mode pipelines free of a second tunnel On the J714s, dcpext0 and dcpext2 reach both USB-C ports for DP alt mode and for USB4 DP tunnels, dcpext1 has tunnel-only routes, and dcpext3 is the merged-mode peer. Three external displays fit: a DP alt mode display on the left-front port on dcpext0 or dcpext2, and a dock's two tunnels on the other two pipelines, one of them paired with dcpext3. A tunnel takes the free pipeline with the lowest CRTC index, dcpext0 before dcpext1. Once one tunnel sits on dcpext2 (it came while dcpext0 and dcpext1 were taken), the next one goes to dcpext0 even with dcpext1 free. For example, with a DP alt mode display on the left-front port and a dock on the right: left-front DP alt -> dcpext0, dock DP IN 0 -> dcpext1, dock DP IN 1 (4K240) -> dcpext2 + dcpext3 left-front display unplugged, dock DP IN 0 display re-plugged -> dock DP IN 0 -> dcpext0 left-front display plugged again: dcpext0 and dcpext2 drive tunnels, dcpext1 is idle, and the display waits for a free pipeline Once another pipeline a port reaches drives a display, have a tunnel take a tunnel-only route before one that can carry DP alt mode. A lone tunnel still takes the lowest pipeline, so a single dock display keeps its connector (DP-1), and ports without tunnel-only routes keep the CRTC order. Signed-off-by: Diljit Singh --- drivers/gpu/drm/apple/dcp-fabric-core.c | 24 +++++++++ drivers/gpu/drm/apple/dcp-fabric-test.c | 65 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp-fabric-core.c b/drivers/gpu/drm/apple/dcp-fabric-core.c index 8fd211427396d..4bc3884db5b14 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-core.c +++ b/drivers/gpu/drm/apple/dcp-fabric-core.c @@ -323,6 +323,25 @@ int dcp_fabric_tunnel_slot(const struct dcp_fabric_port *port, } EXPORT_SYMBOL_GPL(dcp_fabric_tunnel_slot); +/* + * Whether a tunnel should take one of @port's tunnel-only routes before a + * route that can carry a DP alt mode display: once another of the pipelines + * it reaches drives a display. A DP alt mode display can never use a + * tunnel-only pipeline, so tunnels on every other one would leave it none + * while that one stays idle. The first display keeps the lowest pipeline. + */ +static bool dcp_fabric_tunnel_keeps_direct(const struct dcp_fabric_port *port) +{ + const struct dcp_fabric_route *route; + bool tunnel_only = false, owned = false; + + for (route = port->routes; route; route = route->next) { + tunnel_only |= route->tunnel_only; + owned |= route->pipeline->owned; + } + return tunnel_only && owned; +} + struct dcp_fabric_route * dcp_fabric_tunnel_candidate(const struct dcp_fabric_port *port, const struct dcp_fabric_policy *policy, @@ -333,12 +352,14 @@ dcp_fabric_tunnel_candidate(const struct dcp_fabric_port *port, struct dcp_fabric_route *route, *best = NULL; unsigned int best_score = UINT_MAX; bool waiting = false, clock_blocked = false, clock_capable = false; + bool keep_direct; if (dpin >= DCP_FABRIC_DPIN_MAX) { *error = -EINVAL; return NULL; } + keep_direct = dcp_fabric_tunnel_keeps_direct(port); for (route = port->routes; route; route = route->next) { const struct dcp_fabric_pipeline *pipeline = route->pipeline; unsigned int score; @@ -368,6 +389,9 @@ dcp_fabric_tunnel_candidate(const struct dcp_fabric_port *port, !pipeline->has_fixed && score < UINT_MAX - 100) score += 100; + /* below the hybrid and stream penalties, above the CRTC order (indices < 50) */ + if (keep_direct && !route->tunnel_only && score < UINT_MAX - 100) + score += 50; if (score < best_score) { best = route; best_score = score; diff --git a/drivers/gpu/drm/apple/dcp-fabric-test.c b/drivers/gpu/drm/apple/dcp-fabric-test.c index b6864283f3ba6..c10c4a0e1e500 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-test.c +++ b/drivers/gpu/drm/apple/dcp-fabric-test.c @@ -2179,6 +2179,70 @@ static void fabric_tunnel_only_test(struct kunit *test) DCP_FABRIC_FOLLOW_SWAP); } +/* + * J714s: dcpext0 and dcpext2 carry DP alt mode and tunnels on both ports, + * dcpext1 tunnels only. With a display up, a tunnel takes dcpext1 before a + * pipeline that a DP alt mode display could have. + */ +static void fabric_tunnel_only_first_test(struct kunit *test) +{ + struct dcp_fabric_pipeline pipeline[3] = {}; + struct dcp_fabric_route route[3] = {}; + struct dcp_fabric_port port = {}; + struct dcp_fabric_policy policy = {}; + unsigned int i; + int error; + + for (i = 0; i < 3; i++) { + pipeline[i].bound = true; + pipeline[i].services_ready = true; + route[i].pipeline = &pipeline[i]; + if (i < 2) + route[i].next = &route[i + 1]; + } + /* CRTC order dcpext0, (internal panel), dcpext1, dcpext2 */ + pipeline[0].crtc_index = 0; + pipeline[1].crtc_index = 2; + pipeline[2].crtc_index = 3; + route[1].tunnel_only = true; + port.routes = &route[0]; + port.candidate_crtcs[0] = GENMASK(3, 0); + port.candidate_crtcs[1] = GENMASK(3, 0); + + /* The first display takes the lowest pipeline, as before. */ + KUNIT_EXPECT_PTR_EQ(test, + dcp_fabric_tunnel_candidate(&port, &policy, NULL, + false, 0, true, &error), + &route[0]); + + /* + * dcpext2 drives the dock's other display: the one coming back takes + * dcpext1, and a DP alt mode display still has dcpext0. + */ + pipeline[2].owned = true; + KUNIT_EXPECT_PTR_EQ(test, + dcp_fabric_tunnel_candidate(&port, &policy, NULL, + false, 0, true, &error), + &route[1]); + pipeline[1].owned = true; + KUNIT_EXPECT_PTR_EQ(test, dcp_fabric_free_route(&port, &policy), + &route[0]); + + /* With dcpext1 held too, a tunnel still gets dcpext0. */ + KUNIT_EXPECT_PTR_EQ(test, + dcp_fabric_tunnel_candidate(&port, &policy, NULL, + false, 2, true, &error), + &route[0]); + + /* Without a tunnel-only route the CRTC order decides alone. */ + route[1].tunnel_only = false; + pipeline[1].owned = false; + KUNIT_EXPECT_PTR_EQ(test, + dcp_fabric_tunnel_candidate(&port, &policy, NULL, + false, 0, true, &error), + &route[0]); +} + static void fabric_t6030_follow_test(struct kunit *test) { struct fabric_fixture f; @@ -2570,6 +2634,7 @@ static struct kunit_case fabric_tests[] = { KUNIT_CASE(fabric_t6030_follow_test), KUNIT_CASE(fabric_per_dpin_slot_test), KUNIT_CASE(fabric_tunnel_only_test), + KUNIT_CASE(fabric_tunnel_only_first_test), KUNIT_CASE(fabric_reclaim_transaction_test), KUNIT_CASE_PARAM(fabric_shared_wiring_test, fabric_wiring_gen_params), KUNIT_CASE(fabric_binding_cookie_test),