Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions drivers/gpu/drm/apple/apple_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@ apple_connector_detect(struct drm_connector *connector, bool force)
connector_status_connected : connector_status_disconnected;
}

void apple_connector_queue_release_crtc(struct apple_connector *apple_connector)
{
if (!apple_connector->port_encoder)
return;
schedule_work(&apple_connector->release_crtc_wq);
}

static void apple_connector_oob_hotplug(struct drm_connector *connector,
enum drm_connector_status status)
{
Expand Down Expand Up @@ -1251,6 +1258,7 @@ static void appledrm_connector_cleanup(struct drm_connector *connector)
struct apple_connector *apple_connector = to_apple_connector(connector);

/* Queued by the last disconnect at shutdown; they use the connector. */
cancel_work_sync(&apple_connector->release_crtc_wq);
cancel_work_sync(&apple_connector->hotplug_wq);
cancel_work_sync(&apple_connector->bl_sync_wq);
cancel_work_sync(&apple_connector->bl_commit_wq);
Expand Down Expand Up @@ -1767,6 +1775,7 @@ static int apple_connector_create(struct drm_device *drm,
apple_connector_backlight_init(connector);
/* before anything can fail: cleanup cancels it */
INIT_WORK(&connector->hotplug_wq, dcp_hotplug);
INIT_WORK(&connector->release_crtc_wq, apple_connector_release_crtc);
drm_connector_helper_add(&connector->base,
&apple_connector_helper_funcs);
if (attach_fwnode)
Expand Down Expand Up @@ -2126,6 +2135,7 @@ static int apple_probe_typec_ports(struct drm_device *drm,
apple_connector_backlight_init(connector);
/* before anything can fail: cleanup cancels it */
INIT_WORK(&connector->hotplug_wq, dcp_hotplug);
INIT_WORK(&connector->release_crtc_wq, apple_connector_release_crtc);
drm_connector_helper_add(&connector->base,
&apple_connector_helper_funcs);

Expand Down Expand Up @@ -2327,6 +2337,7 @@ static void apple_drm_quiesce_connectors(struct drm_device *drm)
* has drained RTKit. Stop their users before releasing endpoints,
* clocks and IOMMUs, and reject enqueues during that release.
*/
disable_work_sync(&apple_connector->release_crtc_wq);
disable_work_sync(&apple_connector->hotplug_wq);
disable_work_sync(&apple_connector->bl_sync_wq);
disable_work_sync(&apple_connector->bl_commit_wq);
Expand Down
9 changes: 9 additions & 0 deletions drivers/gpu/drm/apple/connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ struct apple_connector {
struct work_struct hotplug_wq;
atomic_t hotplug_reasons;

/*
* Dropping this connector's CRTC after its Type-C cable is gone. Out
* of line because the cable path cannot take the modeset locks.
*/
struct work_struct release_crtc_wq;

struct mutex chunk_lock;

struct dcp_chunks color_elements;
Expand Down Expand Up @@ -112,4 +118,7 @@ void apple_connector_debugfs_init(struct drm_connector *connector, struct dentry

void dcp_connector_update_dict(struct apple_connector *connector, const char *key,
struct dcp_chunks *chunks);
void apple_connector_release_crtc(struct work_struct *work);
void apple_connector_queue_release_crtc(struct apple_connector *apple_connector);

#endif
8 changes: 8 additions & 0 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4438,6 +4438,14 @@ int dcp_dptx_disconnect_oob(struct platform_device *pdev, u32 port)

disconnected_hpd_event(dcp->connector);

/*
* Userspace has been told; make sure the CRTC comes back even when it
* does not act, or the next port routed to this pipeline is rejected
* by the atomic helper's clone check and stays dark.
*/
if (dcp->connector)
apple_connector_queue_release_crtc(dcp->connector);

if (dcp->avep)
av_service_disconnect(dcp);

Expand Down
44 changes: 41 additions & 3 deletions drivers/gpu/drm/apple/iomfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,13 @@ static int dcp_set_crtc_active(struct drm_crtc *crtc,
static bool dcp_mode_settable(struct apple_dcp *dcp,
const struct drm_display_mode *mode);

static int dcp_release_crtc(struct drm_crtc *crtc, struct drm_modeset_acquire_ctx *ctx)
{
struct drm_mode_set set = { .crtc = crtc };

return drm_atomic_helper_set_config(&set, ctx);
}

/*
* @power_cycle: the firmware powered the pipe down with the lost link, so a
* modeset alone cannot bring it back. Turn the CRTC off and on instead, which
Expand Down Expand Up @@ -1582,9 +1589,7 @@ static int dcp_retrain_active_crtc(struct apple_connector *connector,
* with the pipeline that now drives it, and this pipeline's
* own display with this CRTC.
*/
struct drm_mode_set set = { .crtc = crtc };

ret = drm_atomic_helper_set_config(&set, &ctx);
ret = dcp_release_crtc(crtc, &ctx);
} else if (dcp_is_ext26(dcp) && crtc && crtc->state &&
(READ_ONCE(dcp->mode_state.valid) ||
!dcp_has_mode(dcp, &crtc->state->mode))) {
Expand Down Expand Up @@ -1966,6 +1971,39 @@ static void dcp_notify_hotplug(struct apple_connector *connector)
drm_kms_helper_connector_hotplug_event(&connector->base);
}

void apple_connector_release_crtc(struct work_struct *work)
{
struct apple_connector *connector =
container_of(work, struct apple_connector, release_crtc_wq);
struct drm_connector *conn = &connector->base;
struct drm_device *dev = conn->dev;
struct drm_modeset_acquire_ctx ctx;
struct drm_crtc *crtc = NULL;
struct platform_device *pdev;
struct apple_dcp *dcp;
int ret;

DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);

pdev = READ_ONCE(connector->dcp);
dcp = pdev ? platform_get_drvdata(pdev) : NULL;
crtc = NULL;
if (!READ_ONCE(connector->connected) &&
!(dcp && READ_ONCE(dcp->connector) == connector &&
READ_ONCE(dcp->typec_cable_connected)) && conn->state)
crtc = conn->state->crtc;
if (crtc)
ret = dcp_release_crtc(crtc, &ctx);

DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);

if (ret)
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] could not release its CRTC: %d\n",
conn->base.id, conn->name, ret);
else if (crtc)
dcp_notify_hotplug(connector);
}

enum dcp_hotplug_reason {
DCP_HOTPLUG_READY = BIT(0),
DCP_HOTPLUG_ROUTE_FAILURE = BIT(1),
Expand Down
2 changes: 1 addition & 1 deletion tools/asahi/dcpext26-retrain-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

root = Path(__file__).resolve().parents[2]
s = (root / 'drivers/gpu/drm/apple/iomfb.c').read_text()
a = s.index('static int dcp_retrain_active_crtc(')
a = s.index('static int dcp_release_crtc(')
b = s.index('\nvoid dcp_handle_hotplug_actions', a)
body = s[a:b]
if '--negative-control' in sys.argv:
Expand Down
Loading