[PATCH v5 15/19] drm/connector: Add new atomic_create_state callback

Thomas Zimmermann tzimmermann at suse.de
Tue May 26 02:28:17 PDT 2026



Am 19.05.26 um 11:01 schrieb Maxime Ripard:
> Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback
> to drm_private_obj") introduced a new pattern for allocating drm object
> states.
>
> Instead of relying on the reset() callback, it created a new
> atomic_create_state hook. This is helpful because reset is a bit
> overloaded: it's used to create the initial software state, reset it,
> but also reset the hardware.
>
> It can also be used either at probe time, to create the initial state
> and possibly reset the hardware to an expected default, but also during
> suspend/resume.
>
> Both these cases come with different expectations too: during the
> initialization, we want to initialize all states, but during
> suspend/resume, drm_private_states for example are expected to be kept
> around.
>
> reset() also isn't fallible, which makes it harder to handle
> initialization errors properly. This is only really relevant for some
> drivers though, since all the helpers for reset only create a new
> state, and don't touch the hardware at all.
>
> It was thus decided to create a new hook that would allocate and
> initialize a pristine state without any side effect:
> atomic_create_state to untangle a bit some of it, and to separate the
> initialization with the actual reset one might need during a
> suspend/resume.
>
> Continue the transition to the new pattern with connectors.
>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov at oss.qualcomm.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas at ideasonboard.com>
> Signed-off-by: Maxime Ripard <mripard at kernel.org>

Reviewed-by: Thomas Zimmermann <tzimmermann at suse.de>

> ---
>   drivers/gpu/drm/drm_atomic_state_helper.c | 26 ++++++++++++++++++++++++++
>   drivers/gpu/drm/drm_connector.c           | 10 +++++++++-
>   drivers/gpu/drm/drm_mode_config.c         | 31 ++++++++++++++++++++++++++++++-
>   include/drm/drm_atomic_state_helper.h     |  2 ++
>   include/drm/drm_connector.h               | 16 ++++++++++++++++
>   5 files changed, 83 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c
> index e2e5a1b8a820..07686e94aae0 100644
> --- a/drivers/gpu/drm/drm_atomic_state_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_state_helper.c
> @@ -532,10 +532,36 @@ void drm_atomic_helper_connector_reset(struct drm_connector *connector)
>   	kfree(connector->state);
>   	__drm_atomic_helper_connector_reset(connector, conn_state);
>   }
>   EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
>   
> +/**
> + * drm_atomic_helper_connector_create_state - default &drm_connector_funcs.atomic_create_state hook for connectors
> + * @connector: connector object
> + *
> + * Allocates and  initializes pristine @drm_connector_state.
> + *
> + * This is useful for drivers that don't subclass @drm_connector_state.
> + *
> + * RETURNS:
> + * Pointer to new connector state, or ERR_PTR on failure.
> + */
> +struct drm_connector_state *
> +drm_atomic_helper_connector_create_state(struct drm_connector *connector)
> +{
> +	struct drm_connector_state *state;
> +
> +	state = kzalloc_obj(*state);
> +	if (!state)
> +		return ERR_PTR(-ENOMEM);
> +
> +	__drm_atomic_helper_connector_state_init(state, connector);
> +
> +	return state;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_connector_create_state);
> +
>   /**
>    * drm_atomic_helper_connector_tv_margins_reset - Resets TV connector properties
>    * @connector: DRM connector
>    *
>    * Resets the TV-related properties attached to a connector.
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index 3fa4d2082cd7..a0b132c658a1 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -616,11 +616,19 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
>   
>   	/*
>   	 * drm_connector_attach_max_bpc_property() requires the
>   	 * connector to have a state.
>   	 */
> -	if (connector->funcs->reset)
> +	if (connector->funcs->atomic_create_state) {
> +		struct drm_connector_state *state;
> +
> +		state = connector->funcs->atomic_create_state(connector);
> +		if (IS_ERR(state))
> +			return PTR_ERR(state);
> +
> +		connector->state = state;
> +	} else if (connector->funcs->reset)
>   		connector->funcs->reset(connector);
>   
>   	drm_connector_attach_max_bpc_property(connector, 8, max_bpc);
>   	connector->max_bpc = max_bpc;
>   
> diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c
> index 2e2cd18a14b4..9d240817f8b6 100644
> --- a/drivers/gpu/drm/drm_mode_config.c
> +++ b/drivers/gpu/drm/drm_mode_config.c
> @@ -235,10 +235,36 @@ static int drm_mode_config_crtc_reset_with_create_state(struct drm_crtc *crtc)
>   	}
>   
>   	return drm_mode_config_crtc_create_state(crtc);
>   }
>   
> +static int drm_mode_config_connector_create_state(struct drm_connector *connector)
> +{
> +	struct drm_connector_state *conn_state;
> +
> +	if (!connector->funcs->atomic_create_state)
> +		return 0;
> +
> +	conn_state = connector->funcs->atomic_create_state(connector);
> +	if (IS_ERR(conn_state))
> +		return PTR_ERR(conn_state);
> +
> +	connector->state = conn_state;
> +
> +	return 0;
> +}
> +
> +static int drm_mode_config_connector_reset_with_create_state(struct drm_connector *connector)
> +{
> +	if (connector->state) {
> +		connector->funcs->atomic_destroy_state(connector, connector->state);
> +		connector->state = NULL;
> +	}
> +
> +	return drm_mode_config_connector_create_state(connector);
> +}
> +
>   /**
>    * drm_mode_config_reset - call ->reset callbacks
>    * @dev: drm device
>    *
>    * This functions calls all the crtc's, encoder's and connector's ->reset
> @@ -278,13 +304,16 @@ void drm_mode_config_reset(struct drm_device *dev)
>   	drm_for_each_encoder(encoder, dev)
>   		if (encoder->funcs && encoder->funcs->reset)
>   			encoder->funcs->reset(encoder);
>   
>   	drm_connector_list_iter_begin(dev, &conn_iter);
> -	drm_for_each_connector_iter(connector, &conn_iter)
> +	drm_for_each_connector_iter(connector, &conn_iter) {
>   		if (connector->funcs->reset)
>   			connector->funcs->reset(connector);
> +		else if (connector->funcs->atomic_create_state)
> +			drm_mode_config_connector_reset_with_create_state(connector);
> +	}
>   	drm_connector_list_iter_end(&conn_iter);
>   }
>   EXPORT_SYMBOL(drm_mode_config_reset);
>   
>   /*
> diff --git a/include/drm/drm_atomic_state_helper.h b/include/drm/drm_atomic_state_helper.h
> index 9634a70e0401..f4b6d8833bc2 100644
> --- a/include/drm/drm_atomic_state_helper.h
> +++ b/include/drm/drm_atomic_state_helper.h
> @@ -73,10 +73,12 @@ void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
>   void __drm_atomic_helper_connector_state_init(struct drm_connector_state *conn_state,
>   					       struct drm_connector *connector);
>   void __drm_atomic_helper_connector_reset(struct drm_connector *connector,
>   					 struct drm_connector_state *conn_state);
>   void drm_atomic_helper_connector_reset(struct drm_connector *connector);
> +struct drm_connector_state *
> +drm_atomic_helper_connector_create_state(struct drm_connector *connector);
>   void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector);
>   int drm_atomic_helper_connector_tv_check(struct drm_connector *connector,
>   					 struct drm_atomic_commit *state);
>   void drm_atomic_helper_connector_tv_margins_reset(struct drm_connector *connector);
>   void
> diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
> index 5ad62c207d00..529755c2e862 100644
> --- a/include/drm/drm_connector.h
> +++ b/include/drm/drm_connector.h
> @@ -1569,10 +1569,26 @@ struct drm_connector_funcs {
>   	 * when a connector is being hot-unplugged for drivers that support
>   	 * connector hotplugging (e.g. DisplayPort MST).
>   	 */
>   	void (*destroy)(struct drm_connector *connector);
>   
> +	/**
> +	 * @atomic_create_state:
> +	 *
> +	 * Allocate a pristine, initialized, state for the connector
> +	 * object and return it. This callback must have no side
> +	 * effects: in particular, the returned state must not be
> +	 * assigned to the object's state pointer and it must not affect
> +	 * the hardware state.
> +	 *
> +	 * RETURNS:
> +	 *
> +	 * A new, pristine, connector state instance or an error pointer
> +	 * on failure.
> +	 */
> +	struct drm_connector_state *(*atomic_create_state)(struct drm_connector *connector);
> +
>   	/**
>   	 * @atomic_duplicate_state:
>   	 *
>   	 * Duplicate the current atomic state for this connector and return it.
>   	 * The core and helpers guarantee that any atomic state duplicated with
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)





More information about the linux-arm-kernel mailing list