[PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder()

Maxime Ripard mripard at kernel.org
Tue Dec 1 07:19:49 PST 2026


On Wed, Nov 25, 2026 at 06:50:40PM +0100, Luca Ceresoli wrote:
> To support bridge hotplug we need to stop the components of a card that are
> affected by the removal of a bridge: the connector, the encoder and
> possibly the CRTC (unless it is still in use after the removal due to
> cloning).
> 
> drm_atomic_helper_shutdown() does it, but it disables the entire card,
> including unrelated CRTCs for multi-CRTC cards. Moreover it is in the
> drm_kms_helper module, which makes it unaccessible from the core code where
> we need this.
> 
> Add drm_atomic_shutdown_encoder() to drm_atomic code, doing what we need.
> 
> Signed-off-by: Luca Ceresoli <luca.ceresoli at bootlin.com>
> 
> ---
> 
> New patch in v3
> ---
>  drivers/gpu/drm/drm_atomic.c | 145 +++++++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_atomic.h     |   1 +
>  2 files changed, 146 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 096f85419b36..536813562f6f 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -2207,6 +2207,151 @@ int __drm_atomic_helper_set_config(struct drm_mode_set *set,
>  }
>  EXPORT_SYMBOL(__drm_atomic_helper_set_config);
>  
> +static int drm_atomic_disable_encoder(struct drm_device *drm,
> +				      struct drm_encoder *encoder,
> +				      struct drm_modeset_acquire_ctx *ctx)
> +{
> +	struct drm_connector_list_iter conn_iter;
> +	struct drm_connector *connector;
> +	struct drm_crtc *crtc = NULL;
> +	struct drm_atomic_commit *commit;
> +	struct drm_crtc_state *crtc_state;
> +	bool crtc_still_used = false;
> +	int ret;
> +
> +	drm_connector_list_iter_begin(drm, &conn_iter);
> +	drm_for_each_connector_iter(connector, &conn_iter) {
> +		if (!connector->state ||
> +		    connector->state->best_encoder != encoder ||
> +		    !connector->state->crtc)
> +			continue;
> +
> +		crtc = connector->state->crtc;
> +		break;
> +	}
> +	drm_connector_list_iter_end(&conn_iter);

You should use drm_atomic_get_connector_for_encoder.

> +	if (!crtc)
> +		return 0;
> +
> +	commit = drm_atomic_commit_alloc(drm);
> +	if (!commit)
> +		return -ENOMEM;
> +
> +	commit->acquire_ctx = ctx;
> +
> +	crtc_state = drm_atomic_get_crtc_state(commit, crtc);
> +	if (IS_ERR(crtc_state)) {
> +		ret = PTR_ERR(crtc_state);
> +		goto free;
> +	}
> +
> +	drm_connector_list_iter_begin(drm, &conn_iter);
> +	drm_for_each_connector_iter(connector, &conn_iter) {
> +		struct drm_connector_state *conn_state;
> +
> +		if (!connector->state || connector->state->crtc != crtc)
> +			continue;
> +
> +		if (connector->state->best_encoder != encoder) {
> +			crtc_still_used = true;
> +			continue;
> +		}

To access connector->state, you need to hold
drm_mode_config.connection_mutex, how is it enforced here?

> +
> +		conn_state = drm_atomic_get_connector_state(commit, connector);
> +		if (IS_ERR(conn_state)) {
> +			ret = PTR_ERR(conn_state);
> +			drm_connector_list_iter_end(&conn_iter);
> +			goto free;
> +		}
> +	}
> +	drm_connector_list_iter_end(&conn_iter);
> +
> +	if (crtc_still_used) {
> +		struct drm_connector_state *conn_state;
> +		int i;
> +
> +		/* Some connector still uses @crtc, keep it and its planes enabled */
> +		for_each_new_connector_in_state(commit, connector, conn_state, i) {
> +			ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
> +			if (ret < 0)
> +				goto free;
> +		}
> +	} else {
> +		struct drm_connector_state *conn_state;
> +		struct drm_plane_state *plane_state;
> +		struct drm_plane *plane;
> +		int i;
> +
> +		crtc_state->active = false;

Same story here.

Maxime
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20261201/ac08792f/attachment.sig>


More information about the linux-arm-kernel mailing list