Skip to content

Commit 1a7c5aa

Browse files
committed
drm/apple: dcp-fabric: give an idle port's pipeline to a waiting display
A USB-C hub with a DP output enters DP alt mode with nothing behind it and takes the only T8122 external pipeline; a monitor on the other port then waits until the hub is unplugged. When a port with HPD up finds no free pipeline, take one from a direct DP-alt port whose sink has never asserted HPD during this DP-alt plug and that has no display connected. Latch dp_hpd_seen on the port once its sink asserts HPD and clear it only when leaving DP alt mode or committing SAFE, so a sleeping monitor that drops HPD keeps its pipeline. Skip pipelines whose fixed output is busy or failed, drop the reclaimed port's applied_valid so its next update is routed again once a pipeline is free, and return any deactivation error without reporting the waiting display as busy. Add the matching port field and helper stub to the apple-dcp transaction host selftest. Signed-off-by: Eric Juta <[email protected]>
1 parent 065904c commit 1a7c5aa

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

‎drivers/gpu/drm/apple/dcp-fabric.c‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ struct apple_dcp_typec_port {
139139
/* Direct DP-alt: the port is in DP mode, routed or not, and its HPD. */
140140
bool dp_wanted;
141141
bool dp_hpd;
142+
/* Latched per DP-alt plug: true once the sink has asserted HPD. */
143+
bool dp_hpd_seen;
142144
/* the wait for a pipeline was logged since the port entered DP mode */
143145
bool busy_noted;
144146
/* dcp_typec_rebalance_locked()'s plan for the port's two streams */
@@ -1930,6 +1932,7 @@ static void dcp_typec_route_commit(struct typec_mux_dev *mux,
19301932
if (port->owner)
19311933
port->preferred_route = port->owner;
19321934
port->owner = NULL;
1935+
port->dp_hpd_seen = false;
19331936
port->safe_pending = false;
19341937
port->safe_finish_ready = false;
19351938
port->applied_alt = state->alt;
@@ -1963,6 +1966,62 @@ static int dcp_typec_port_busy(struct apple_dcp_typec_port *port,
19631966
return -ENOSPC;
19641967
}
19651968

1969+
/*
1970+
* @waiting has a display (HPD up) but no pipeline. A direct DP-alt port that
1971+
* holds one of @waiting's pipelines with no display behind it (its sink has
1972+
* never asserted HPD during this DP-alt plug, as a USB-C hub with a DP output
1973+
* and nothing plugged in) gives it up: a pipeline goes to a display, not to
1974+
* whichever port entered DP mode first. A port whose monitor previously
1975+
* asserted HPD and then slept keeps its pipeline (dp_hpd_seen stays set until
1976+
* the port leaves DP mode or commits SAFE). The idle port keeps DP mode and is
1977+
* routed again when a pipeline is free and its own sink asserts HPD. Returns 1
1978+
* if one was released, 0 if no port holds one idle, or the error from a release
1979+
* that failed: the idle port then still owns its pipeline, and the caller must
1980+
* report that error and not that every pipeline drives a display.
1981+
*/
1982+
static int dcp_typec_reclaim_idle(struct apple_dcp_typec_port *waiting)
1983+
{
1984+
struct apple_dcp_typec_route *route;
1985+
struct apple_dcp_typec_port *idle;
1986+
1987+
lockdep_assert_held(&dcp_typec_fabric_lock);
1988+
1989+
list_for_each_entry(route, &waiting->routes, port_link) {
1990+
if (dcp_typec_route_busy(route))
1991+
continue;
1992+
list_for_each_entry(idle, &dcp_typec_ports, link) {
1993+
struct apple_dcp_typec_route *owner = idle->owner;
1994+
struct apple_dcp *dcp;
1995+
const char *from = NULL, *to = NULL;
1996+
int ret;
1997+
1998+
if (idle == waiting || !owner || owner->tunnel ||
1999+
owner->dcp != route->dcp || idle->safe_pending ||
2000+
idle->dp_hpd_seen || idle->dp_hpd || idle->hpd)
2001+
continue;
2002+
dcp = owner->dcp;
2003+
if (dcp->typec_cable_connected ||
2004+
(dcp->typec_connector &&
2005+
READ_ONCE(dcp->typec_connector->connected)))
2006+
continue;
2007+
ret = dcp_typec_route_deactivate(owner);
2008+
if (ret)
2009+
return ret;
2010+
idle->preferred_route = owner;
2011+
idle->owner = NULL;
2012+
idle->applied_valid = false;
2013+
idle->busy_noted = false;
2014+
of_property_read_string(idle->connector_np, "label", &from);
2015+
of_property_read_string(waiting->connector_np, "label", &to);
2016+
dev_info(dcp->dev,
2017+
"external display pipeline moves from %s (no display) to the display on %s\n",
2018+
from ?: "a USB-C port", to ?: "a USB-C port");
2019+
return 1;
2020+
}
2021+
}
2022+
return 0;
2023+
}
2024+
19662025
static int dcp_typec_route_apply(struct typec_mux_dev *mux,
19672026
struct typec_mux_state *state)
19682027
{
@@ -2077,6 +2136,7 @@ static int dcp_typec_route_apply(struct typec_mux_dev *mux,
20772136

20782137
port->dp_wanted = false;
20792138
port->dp_hpd = false;
2139+
port->dp_hpd_seen = false;
20802140
port->busy_noted = false;
20812141
/* The Type-C display is gone: a hybrid it took goes back to HDMI. */
20822142
dcp_hybrid_fails = 0;
@@ -2143,6 +2203,8 @@ static int dcp_typec_route_apply(struct typec_mux_dev *mux,
21432203

21442204
port->dp_wanted = true;
21452205
port->dp_hpd = hpd;
2206+
if (hpd)
2207+
port->dp_hpd_seen = true;
21462208

21472209
/*
21482210
* Until a compositor owns the display, a direct DP-alt stream has a
@@ -2191,6 +2253,14 @@ static int dcp_typec_route_apply(struct typec_mux_dev *mux,
21912253

21922254
if (!port->owner) {
21932255
best = dcp_typec_free_route(port);
2256+
/* A pipeline held by a port with no display goes to this one. */
2257+
if (!best && hpd) {
2258+
ret = dcp_typec_reclaim_idle(port);
2259+
if (ret < 0)
2260+
return ret;
2261+
if (ret)
2262+
best = dcp_typec_free_route(port);
2263+
}
21942264
/* Every pipeline is driving another port's display. */
21952265
if (!best)
21962266
return hpd ? dcp_typec_port_busy(port, route->dcp) : -ENOSPC;

‎tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def make_unit(source, parent=False, reference=None):
5858
struct connector { bool connected; };
5959
struct apple_dcp { int external_lock,external_error; bool external_cable,external_stopped; struct { bool connected; } dptxport[1]; void *hdmi_hpd; bool active; bool external,typec_cable_connected; void *dev; struct connector *typec_connector; bool ext_backlight; };
6060
struct apple_dcp_typec_route;
61-
struct apple_dcp_typec_port { int link; void *connector_np; struct apple_dcp_typec_route *owner,*target,*secondary_target,*preferred_route; void *applied_alt; unsigned long applied_mode; unsigned applied_status,applied_conf; bool applied_valid,safe_pending,safe_finish_ready,dp_wanted,dp_hpd,hpd,busy_noted;
61+
struct apple_dcp_typec_port { int link; void *connector_np; struct apple_dcp_typec_route *owner,*target,*secondary_target,*preferred_route; void *applied_alt; unsigned long applied_mode; unsigned applied_status,applied_conf; bool applied_valid,safe_pending,safe_finish_ready,dp_wanted,dp_hpd,dp_hpd_seen,hpd,busy_noted;
6262
/* Held for a J714s firmware 27 sleep (dcp_fabric_sleep_release()): never here. */
6363
bool sleep_held,sleep_withdrawn; };
6464
struct apple_dcp_typec_route { struct apple_dcp_typec_port *port; struct apple_dcp *dcp; void *xbar; bool deactivate_xbar_done; int deactivate_error; bool selected,tunnel; };

‎tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def check(name, unit, cases=((),), negative=False, flags=()):
100100
static bool dcp_typec_keep_order(void) { return false; }
101101
static struct apple_dcp_typec_route * __attribute__((unused)) dcp_typec_lowest_free(struct apple_dcp_typec_port *p) { (void)p;return &route; }
102102
static struct apple_dcp_typec_route * __attribute__((unused)) dcp_typec_free_route(struct apple_dcp_typec_port *p) { (void)p;return &route; }
103+
static int __attribute__((unused)) dcp_typec_reclaim_idle(struct apple_dcp_typec_port *p) { (void)p;return 0; }
103104
static int connect_calls;
104105
static int dcp_dptx_connect_oob(void *dev,unsigned n) { (void)dev;(void)n;connect_calls++;display.external_cable=true;display.dptxport[0].connected=true;display.typec_cable_connected=true;connector.connected=true;return 0; }
105106
static void dcp_retrain_oob(struct connector *c) { (void)c; }

0 commit comments

Comments
 (0)