* [PATCH v3 01/11] drm/atomic: colorop: Rename state to state_to_destroy
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 6:28 ` Thomas Zimmermann
2026-09-11 13:27 ` (subset) " Maxime Ripard
2026-09-08 14:35 ` [PATCH v3 02/11] drm/atomic: Create function to insert CRTC state into a commit Maxime Ripard
` (9 subsequent siblings)
10 siblings, 2 replies; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
The atomic state tracking structures used to have a generic state
field to track the state to free when tearing down the
drm_atomic_commit. It has since been renamed to state_to_destroy in
__drm_planes_state, __drm_crtcs_state, __drm_connnectors_state, and
__drm_private_objs_state to better describe its purpose.
The colorop support has been added after that rename, but
__drm_colorops_state still uses the old state name. Rename it to
state_to_destroy for consistency, and add the matching kerneldoc.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 6 +++---
drivers/gpu/drm/drm_atomic_helper.c | 2 +-
include/drm/drm_atomic.h | 18 +++++++++++++++++-
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 45df6376f408..5c0f7b7024d1 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -341,13 +341,13 @@ void drm_atomic_commit_default_clear(struct drm_atomic_commit *state)
if (!colorop)
continue;
drm_colorop_atomic_destroy_state(colorop,
- state->colorops[i].state);
+ state->colorops[i].state_to_destroy);
state->colorops[i].ptr = NULL;
- state->colorops[i].state = NULL;
+ state->colorops[i].state_to_destroy = NULL;
state->colorops[i].old_state = NULL;
state->colorops[i].new_state = NULL;
}
for (i = 0; i < state->num_private_objs; i++) {
@@ -706,11 +706,11 @@ drm_atomic_get_colorop_state(struct drm_atomic_commit *state,
colorop_state = drm_atomic_helper_colorop_duplicate_state(colorop);
if (!colorop_state)
return ERR_PTR(-ENOMEM);
- state->colorops[index].state = colorop_state;
+ state->colorops[index].state_to_destroy = colorop_state;
state->colorops[index].ptr = colorop;
state->colorops[index].old_state = colorop->state;
state->colorops[index].new_state = colorop_state;
colorop_state->state = state;
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 285aac3554df..c4752bd7d999 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -3349,11 +3349,11 @@ int drm_atomic_helper_swap_state(struct drm_atomic_commit *state,
WARN_ON(colorop->state != old_colorop_state);
old_colorop_state->state = state;
new_colorop_state->state = NULL;
- state->colorops[i].state = old_colorop_state;
+ state->colorops[i].state_to_destroy = old_colorop_state;
colorop->state = new_colorop_state;
}
drm_panic_lock(state->dev, flags);
for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 88087910ab1a..00b3e9fc429a 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -157,11 +157,27 @@ struct drm_crtc_commit {
bool abort_completion;
};
struct __drm_colorops_state {
struct drm_colorop *ptr;
- struct drm_colorop_state *state, *old_state, *new_state;
+
+ /**
+ * @state_to_destroy:
+ *
+ * Used to track the @drm_colorop_state we will need to free
+ * when tearing down the associated &drm_atomic_commit in
+ * $drm_mode_config_funcs.atomic_state_clear or
+ * drm_atomic_commit_default_clear().
+ *
+ * Before a commit, and the call to
+ * drm_atomic_helper_swap_state() in particular, it points to
+ * the same state than @new_state. After a commit, it points to
+ * the same state than @old_state.
+ */
+ struct drm_colorop_state *state_to_destroy;
+
+ struct drm_colorop_state *old_state, *new_state;
};
struct __drm_planes_state {
struct drm_plane *ptr;
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 01/11] drm/atomic: colorop: Rename state to state_to_destroy
2026-09-08 14:35 ` [PATCH v3 01/11] drm/atomic: colorop: Rename state to state_to_destroy Maxime Ripard
@ 2026-09-09 6:28 ` Thomas Zimmermann
2026-09-11 13:27 ` (subset) " Maxime Ripard
1 sibling, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 6:28 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> The atomic state tracking structures used to have a generic state
> field to track the state to free when tearing down the
> drm_atomic_commit. It has since been renamed to state_to_destroy in
> __drm_planes_state, __drm_crtcs_state, __drm_connnectors_state, and
> __drm_private_objs_state to better describe its purpose.
>
> The colorop support has been added after that rename, but
> __drm_colorops_state still uses the old state name. Rename it to
> state_to_destroy for consistency, and add the matching kerneldoc.
Makes sense. Please merge this as you see fit.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
> drivers/gpu/drm/drm_atomic.c | 6 +++---
> drivers/gpu/drm/drm_atomic_helper.c | 2 +-
> include/drm/drm_atomic.h | 18 +++++++++++++++++-
> 3 files changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 45df6376f408..5c0f7b7024d1 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -341,13 +341,13 @@ void drm_atomic_commit_default_clear(struct drm_atomic_commit *state)
>
> if (!colorop)
> continue;
>
> drm_colorop_atomic_destroy_state(colorop,
> - state->colorops[i].state);
> + state->colorops[i].state_to_destroy);
> state->colorops[i].ptr = NULL;
> - state->colorops[i].state = NULL;
> + state->colorops[i].state_to_destroy = NULL;
> state->colorops[i].old_state = NULL;
> state->colorops[i].new_state = NULL;
> }
>
> for (i = 0; i < state->num_private_objs; i++) {
> @@ -706,11 +706,11 @@ drm_atomic_get_colorop_state(struct drm_atomic_commit *state,
>
> colorop_state = drm_atomic_helper_colorop_duplicate_state(colorop);
> if (!colorop_state)
> return ERR_PTR(-ENOMEM);
>
> - state->colorops[index].state = colorop_state;
> + state->colorops[index].state_to_destroy = colorop_state;
> state->colorops[index].ptr = colorop;
> state->colorops[index].old_state = colorop->state;
> state->colorops[index].new_state = colorop_state;
> colorop_state->state = state;
>
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index 285aac3554df..c4752bd7d999 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -3349,11 +3349,11 @@ int drm_atomic_helper_swap_state(struct drm_atomic_commit *state,
> WARN_ON(colorop->state != old_colorop_state);
>
> old_colorop_state->state = state;
> new_colorop_state->state = NULL;
>
> - state->colorops[i].state = old_colorop_state;
> + state->colorops[i].state_to_destroy = old_colorop_state;
> colorop->state = new_colorop_state;
> }
>
> drm_panic_lock(state->dev, flags);
> for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> index 88087910ab1a..00b3e9fc429a 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -157,11 +157,27 @@ struct drm_crtc_commit {
> bool abort_completion;
> };
>
> struct __drm_colorops_state {
> struct drm_colorop *ptr;
> - struct drm_colorop_state *state, *old_state, *new_state;
> +
> + /**
> + * @state_to_destroy:
> + *
> + * Used to track the @drm_colorop_state we will need to free
> + * when tearing down the associated &drm_atomic_commit in
> + * $drm_mode_config_funcs.atomic_state_clear or
> + * drm_atomic_commit_default_clear().
> + *
> + * Before a commit, and the call to
> + * drm_atomic_helper_swap_state() in particular, it points to
> + * the same state than @new_state. After a commit, it points to
> + * the same state than @old_state.
> + */
> + struct drm_colorop_state *state_to_destroy;
> +
> + struct drm_colorop_state *old_state, *new_state;
> };
>
> struct __drm_planes_state {
> struct drm_plane *ptr;
>
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: (subset) [PATCH v3 01/11] drm/atomic: colorop: Rename state to state_to_destroy
2026-09-08 14:35 ` [PATCH v3 01/11] drm/atomic: colorop: Rename state to state_to_destroy Maxime Ripard
2026-09-09 6:28 ` Thomas Zimmermann
@ 2026-09-11 13:27 ` Maxime Ripard
1 sibling, 0 replies; 24+ messages in thread
From: Maxime Ripard @ 2026-09-11 13:27 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Simona Vetter, Maxime Ripard
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
On Tue, 08 Sep 2026 16:35:02 +0200, Maxime Ripard wrote:
> The atomic state tracking structures used to have a generic state
> field to track the state to free when tearing down the
> drm_atomic_commit. It has since been renamed to state_to_destroy in
> __drm_planes_state, __drm_crtcs_state, __drm_connnectors_state, and
> __drm_private_objs_state to better describe its purpose.
>
> The colorop support has been added after that rename, but
> __drm_colorops_state still uses the old state name. Rename it to
> state_to_destroy for consistency, and add the matching kerneldoc.
>
> [...]
Applied to misc/kernel.git (drm-misc-next)
[01/11] drm/atomic: colorop: Rename state to state_to_destroy
commit: 38d8b5a35367246dee147d48ea6d5cd6644de5d5
Thanks!
Maxime
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 02/11] drm/atomic: Create function to insert CRTC state into a commit
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-09-08 14:35 ` [PATCH v3 01/11] drm/atomic: colorop: Rename state to state_to_destroy Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 6:30 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 03/11] drm/atomic: Create function to insert plane " Maxime Ripard
` (8 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
drm_atomic_get_crtc_state() allocates a new CRTC state by duplicating
the current one and inserts it into the atomic commit as a single
operation.
However, a later change will need to insert a CRTC state into a
commit without going through the full allocation and duplication path
in drm_atomic_get_crtc_state().
Extract the state insertion logic into a new static
drm_atomic_commit_set_crtc_state() helper, and convert
drm_atomic_get_crtc_state() to use it.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 5c0f7b7024d1..153d959bd4ff 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -421,10 +421,27 @@ void __drm_atomic_commit_free(struct kref *ref)
drm_dev_put(dev);
}
EXPORT_SYMBOL(__drm_atomic_commit_free);
+static int drm_atomic_commit_set_crtc_state(struct drm_atomic_commit *commit,
+ struct drm_crtc *crtc,
+ struct drm_crtc_state *crtc_state)
+{
+ int index = drm_crtc_index(crtc);
+
+ drm_modeset_lock_assert_held(&crtc->mutex);
+
+ commit->crtcs[index].state_to_destroy = crtc_state;
+ commit->crtcs[index].old_state = crtc->state;
+ commit->crtcs[index].new_state = crtc_state;
+ commit->crtcs[index].ptr = crtc;
+ crtc_state->state = commit;
+
+ return 0;
+}
+
/**
* drm_atomic_get_crtc_state - get CRTC state
* @state: global atomic state object
* @crtc: CRTC to get state object for
*
@@ -443,11 +460,11 @@ EXPORT_SYMBOL(__drm_atomic_commit_free);
*/
struct drm_crtc_state *
drm_atomic_get_crtc_state(struct drm_atomic_commit *state,
struct drm_crtc *crtc)
{
- int ret, index = drm_crtc_index(crtc);
+ int ret;
struct drm_crtc_state *crtc_state;
WARN_ON(!state->acquire_ctx);
drm_WARN_ON(state->dev, state->checked);
@@ -461,15 +478,15 @@ drm_atomic_get_crtc_state(struct drm_atomic_commit *state,
crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
if (!crtc_state)
return ERR_PTR(-ENOMEM);
- state->crtcs[index].state_to_destroy = crtc_state;
- state->crtcs[index].old_state = crtc->state;
- state->crtcs[index].new_state = crtc_state;
- state->crtcs[index].ptr = crtc;
- crtc_state->state = state;
+ ret = drm_atomic_commit_set_crtc_state(state, crtc, crtc_state);
+ if (ret) {
+ crtc->funcs->atomic_destroy_state(crtc, crtc_state);
+ return ERR_PTR(ret);
+ }
drm_dbg_atomic(state->dev, "Added [CRTC:%d:%s] %p state to %p\n",
crtc->base.id, crtc->name, crtc_state, state);
return crtc_state;
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 02/11] drm/atomic: Create function to insert CRTC state into a commit
2026-09-08 14:35 ` [PATCH v3 02/11] drm/atomic: Create function to insert CRTC state into a commit Maxime Ripard
@ 2026-09-09 6:30 ` Thomas Zimmermann
0 siblings, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 6:30 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> drm_atomic_get_crtc_state() allocates a new CRTC state by duplicating
> the current one and inserts it into the atomic commit as a single
> operation.
>
> However, a later change will need to insert a CRTC state into a
> commit without going through the full allocation and duplication path
> in drm_atomic_get_crtc_state().
>
> Extract the state insertion logic into a new static
> drm_atomic_commit_set_crtc_state() helper, and convert
> drm_atomic_get_crtc_state() to use it.
Another change that makes sense on its own.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
> drivers/gpu/drm/drm_atomic.c | 29 +++++++++++++++++++++++------
> 1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 5c0f7b7024d1..153d959bd4ff 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -421,10 +421,27 @@ void __drm_atomic_commit_free(struct kref *ref)
>
> drm_dev_put(dev);
> }
> EXPORT_SYMBOL(__drm_atomic_commit_free);
>
> +static int drm_atomic_commit_set_crtc_state(struct drm_atomic_commit *commit,
> + struct drm_crtc *crtc,
> + struct drm_crtc_state *crtc_state)
> +{
> + int index = drm_crtc_index(crtc);
> +
> + drm_modeset_lock_assert_held(&crtc->mutex);
> +
> + commit->crtcs[index].state_to_destroy = crtc_state;
> + commit->crtcs[index].old_state = crtc->state;
> + commit->crtcs[index].new_state = crtc_state;
> + commit->crtcs[index].ptr = crtc;
> + crtc_state->state = commit;
> +
> + return 0;
> +}
> +
> /**
> * drm_atomic_get_crtc_state - get CRTC state
> * @state: global atomic state object
> * @crtc: CRTC to get state object for
> *
> @@ -443,11 +460,11 @@ EXPORT_SYMBOL(__drm_atomic_commit_free);
> */
> struct drm_crtc_state *
> drm_atomic_get_crtc_state(struct drm_atomic_commit *state,
> struct drm_crtc *crtc)
> {
> - int ret, index = drm_crtc_index(crtc);
> + int ret;
> struct drm_crtc_state *crtc_state;
>
> WARN_ON(!state->acquire_ctx);
> drm_WARN_ON(state->dev, state->checked);
>
> @@ -461,15 +478,15 @@ drm_atomic_get_crtc_state(struct drm_atomic_commit *state,
>
> crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
> if (!crtc_state)
> return ERR_PTR(-ENOMEM);
>
> - state->crtcs[index].state_to_destroy = crtc_state;
> - state->crtcs[index].old_state = crtc->state;
> - state->crtcs[index].new_state = crtc_state;
> - state->crtcs[index].ptr = crtc;
> - crtc_state->state = state;
> + ret = drm_atomic_commit_set_crtc_state(state, crtc, crtc_state);
> + if (ret) {
> + crtc->funcs->atomic_destroy_state(crtc, crtc_state);
> + return ERR_PTR(ret);
> + }
>
> drm_dbg_atomic(state->dev, "Added [CRTC:%d:%s] %p state to %p\n",
> crtc->base.id, crtc->name, crtc_state, state);
>
> return crtc_state;
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 03/11] drm/atomic: Create function to insert plane state into a commit
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-09-08 14:35 ` [PATCH v3 01/11] drm/atomic: colorop: Rename state to state_to_destroy Maxime Ripard
2026-09-08 14:35 ` [PATCH v3 02/11] drm/atomic: Create function to insert CRTC state into a commit Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 6:34 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 04/11] drm/atomic: Create function to insert colorop " Maxime Ripard
` (7 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
drm_atomic_get_plane_state() allocates a new plane state by
duplicating the current one and inserts it into the atomic commit as
a single operation.
However, a later change will need to insert a plane state into a
commit without going through the full allocation and duplication path
in drm_atomic_get_plane_state().
Extract the state insertion logic into a new static
drm_atomic_commit_set_plane_state() helper, and convert
drm_atomic_get_plane_state() to use it.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 153d959bd4ff..f62323679f44 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -624,10 +624,27 @@ static int drm_atomic_connector_check(struct drm_connector *connector,
}
return 0;
}
+static int drm_atomic_commit_set_plane_state(struct drm_atomic_commit *commit,
+ struct drm_plane *plane,
+ struct drm_plane_state *plane_state)
+{
+ int index = drm_plane_index(plane);
+
+ drm_modeset_lock_assert_held(&plane->mutex);
+
+ commit->planes[index].state_to_destroy = plane_state;
+ commit->planes[index].old_state = plane->state;
+ commit->planes[index].new_state = plane_state;
+ commit->planes[index].ptr = plane;
+ plane_state->state = commit;
+
+ return 0;
+}
+
/**
* drm_atomic_get_plane_state - get plane state
* @state: global atomic state object
* @plane: plane to get state object for
*
@@ -642,11 +659,11 @@ static int drm_atomic_connector_check(struct drm_connector *connector,
*/
struct drm_plane_state *
drm_atomic_get_plane_state(struct drm_atomic_commit *state,
struct drm_plane *plane)
{
- int ret, index = drm_plane_index(plane);
+ int ret;
struct drm_plane_state *plane_state;
WARN_ON(!state->acquire_ctx);
drm_WARN_ON(state->dev, state->checked);
@@ -665,15 +682,15 @@ drm_atomic_get_plane_state(struct drm_atomic_commit *state,
plane_state = plane->funcs->atomic_duplicate_state(plane);
if (!plane_state)
return ERR_PTR(-ENOMEM);
- state->planes[index].state_to_destroy = plane_state;
- state->planes[index].ptr = plane;
- state->planes[index].old_state = plane->state;
- state->planes[index].new_state = plane_state;
- plane_state->state = state;
+ ret = drm_atomic_commit_set_plane_state(state, plane, plane_state);
+ if (ret) {
+ plane->funcs->atomic_destroy_state(plane, plane_state);
+ return ERR_PTR(ret);
+ }
drm_dbg_atomic(plane->dev, "Added [PLANE:%d:%s] %p state to %p\n",
plane->base.id, plane->name, plane_state, state);
if (plane_state->crtc) {
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 03/11] drm/atomic: Create function to insert plane state into a commit
2026-09-08 14:35 ` [PATCH v3 03/11] drm/atomic: Create function to insert plane " Maxime Ripard
@ 2026-09-09 6:34 ` Thomas Zimmermann
0 siblings, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 6:34 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> drm_atomic_get_plane_state() allocates a new plane state by
> duplicating the current one and inserts it into the atomic commit as
> a single operation.
>
> However, a later change will need to insert a plane state into a
> commit without going through the full allocation and duplication path
> in drm_atomic_get_plane_state().
>
> Extract the state insertion logic into a new static
> drm_atomic_commit_set_plane_state() helper, and convert
> drm_atomic_get_plane_state() to use it.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
But there's a question below.
> ---
> drivers/gpu/drm/drm_atomic.c | 29 +++++++++++++++++++++++------
> 1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 153d959bd4ff..f62323679f44 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -624,10 +624,27 @@ static int drm_atomic_connector_check(struct drm_connector *connector,
> }
>
> return 0;
> }
>
> +static int drm_atomic_commit_set_plane_state(struct drm_atomic_commit *commit,
> + struct drm_plane *plane,
> + struct drm_plane_state *plane_state)
> +{
> + int index = drm_plane_index(plane);
> +
> + drm_modeset_lock_assert_held(&plane->mutex);
> +
> + commit->planes[index].state_to_destroy = plane_state;
> + commit->planes[index].old_state = plane->state;
> + commit->planes[index].new_state = plane_state;
> + commit->planes[index].ptr = plane;
> + plane_state->state = commit;
> +
> + return 0;
I've notices that in other commits as well: why does it have a return
value when the function cannot fail? If there isn't a need later on, it
should preferably by removed.
Best regards
Thomas
> +}
> +
> /**
> * drm_atomic_get_plane_state - get plane state
> * @state: global atomic state object
> * @plane: plane to get state object for
> *
> @@ -642,11 +659,11 @@ static int drm_atomic_connector_check(struct drm_connector *connector,
> */
> struct drm_plane_state *
> drm_atomic_get_plane_state(struct drm_atomic_commit *state,
> struct drm_plane *plane)
> {
> - int ret, index = drm_plane_index(plane);
> + int ret;
> struct drm_plane_state *plane_state;
>
> WARN_ON(!state->acquire_ctx);
> drm_WARN_ON(state->dev, state->checked);
>
> @@ -665,15 +682,15 @@ drm_atomic_get_plane_state(struct drm_atomic_commit *state,
>
> plane_state = plane->funcs->atomic_duplicate_state(plane);
> if (!plane_state)
> return ERR_PTR(-ENOMEM);
>
> - state->planes[index].state_to_destroy = plane_state;
> - state->planes[index].ptr = plane;
> - state->planes[index].old_state = plane->state;
> - state->planes[index].new_state = plane_state;
> - plane_state->state = state;
> + ret = drm_atomic_commit_set_plane_state(state, plane, plane_state);
> + if (ret) {
> + plane->funcs->atomic_destroy_state(plane, plane_state);
> + return ERR_PTR(ret);
> + }
>
> drm_dbg_atomic(plane->dev, "Added [PLANE:%d:%s] %p state to %p\n",
> plane->base.id, plane->name, plane_state, state);
>
> if (plane_state->crtc) {
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 04/11] drm/atomic: Create function to insert colorop state into a commit
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (2 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 03/11] drm/atomic: Create function to insert plane " Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 6:35 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 05/11] drm/atomic: Create function to insert private obj " Maxime Ripard
` (6 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
drm_atomic_get_colorop_state() allocates a new colorop state by
duplicating the current one and inserts it into the atomic commit as
a single operation.
However, a later change will need to insert a colorop state into a
commit without going through the full allocation and duplication path
in drm_atomic_get_colorop_state().
Extract the state insertion logic into a new static
drm_atomic_commit_set_colorop_state() helper, and convert
drm_atomic_get_colorop_state() to use it.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index f62323679f44..f6a31c9d477d 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -704,10 +704,27 @@ drm_atomic_get_plane_state(struct drm_atomic_commit *state,
return plane_state;
}
EXPORT_SYMBOL(drm_atomic_get_plane_state);
+static int drm_atomic_commit_set_colorop_state(struct drm_atomic_commit *commit,
+ struct drm_colorop *colorop,
+ struct drm_colorop_state *colorop_state)
+{
+ int index = drm_colorop_index(colorop);
+
+ drm_modeset_lock_assert_held(&colorop->plane->mutex);
+
+ commit->colorops[index].state_to_destroy = colorop_state;
+ commit->colorops[index].old_state = colorop->state;
+ commit->colorops[index].new_state = colorop_state;
+ commit->colorops[index].ptr = colorop;
+ colorop_state->state = commit;
+
+ return 0;
+}
+
/**
* drm_atomic_get_colorop_state - get colorop state
* @state: global atomic state object
* @colorop: colorop to get state object for
*
@@ -723,11 +740,11 @@ EXPORT_SYMBOL(drm_atomic_get_plane_state);
*/
struct drm_colorop_state *
drm_atomic_get_colorop_state(struct drm_atomic_commit *state,
struct drm_colorop *colorop)
{
- int ret, index = drm_colorop_index(colorop);
+ int ret;
struct drm_colorop_state *colorop_state;
WARN_ON(!state->acquire_ctx);
colorop_state = drm_atomic_get_new_colorop_state(state, colorop);
@@ -740,15 +757,15 @@ drm_atomic_get_colorop_state(struct drm_atomic_commit *state,
colorop_state = drm_atomic_helper_colorop_duplicate_state(colorop);
if (!colorop_state)
return ERR_PTR(-ENOMEM);
- state->colorops[index].state_to_destroy = colorop_state;
- state->colorops[index].ptr = colorop;
- state->colorops[index].old_state = colorop->state;
- state->colorops[index].new_state = colorop_state;
- colorop_state->state = state;
+ ret = drm_atomic_commit_set_colorop_state(state, colorop, colorop_state);
+ if (ret) {
+ drm_colorop_atomic_destroy_state(colorop, colorop_state);
+ return ERR_PTR(ret);
+ }
drm_dbg_atomic(colorop->dev, "Added [COLOROP:%d:%d] %p state to %p\n",
colorop->base.id, colorop->type, colorop_state, state);
return colorop_state;
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 04/11] drm/atomic: Create function to insert colorop state into a commit
2026-09-08 14:35 ` [PATCH v3 04/11] drm/atomic: Create function to insert colorop " Maxime Ripard
@ 2026-09-09 6:35 ` Thomas Zimmermann
0 siblings, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 6:35 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> drm_atomic_get_colorop_state() allocates a new colorop state by
> duplicating the current one and inserts it into the atomic commit as
> a single operation.
>
> However, a later change will need to insert a colorop state into a
> commit without going through the full allocation and duplication path
> in drm_atomic_get_colorop_state().
>
> Extract the state insertion logic into a new static
> drm_atomic_commit_set_colorop_state() helper, and convert
> drm_atomic_get_colorop_state() to use it.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
with the question of the return value again.
> ---
> drivers/gpu/drm/drm_atomic.c | 29 +++++++++++++++++++++++------
> 1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index f62323679f44..f6a31c9d477d 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -704,10 +704,27 @@ drm_atomic_get_plane_state(struct drm_atomic_commit *state,
>
> return plane_state;
> }
> EXPORT_SYMBOL(drm_atomic_get_plane_state);
>
> +static int drm_atomic_commit_set_colorop_state(struct drm_atomic_commit *commit,
> + struct drm_colorop *colorop,
> + struct drm_colorop_state *colorop_state)
> +{
> + int index = drm_colorop_index(colorop);
> +
> + drm_modeset_lock_assert_held(&colorop->plane->mutex);
> +
> + commit->colorops[index].state_to_destroy = colorop_state;
> + commit->colorops[index].old_state = colorop->state;
> + commit->colorops[index].new_state = colorop_state;
> + commit->colorops[index].ptr = colorop;
> + colorop_state->state = commit;
> +
> + return 0;
> +}
> +
> /**
> * drm_atomic_get_colorop_state - get colorop state
> * @state: global atomic state object
> * @colorop: colorop to get state object for
> *
> @@ -723,11 +740,11 @@ EXPORT_SYMBOL(drm_atomic_get_plane_state);
> */
> struct drm_colorop_state *
> drm_atomic_get_colorop_state(struct drm_atomic_commit *state,
> struct drm_colorop *colorop)
> {
> - int ret, index = drm_colorop_index(colorop);
> + int ret;
> struct drm_colorop_state *colorop_state;
>
> WARN_ON(!state->acquire_ctx);
>
> colorop_state = drm_atomic_get_new_colorop_state(state, colorop);
> @@ -740,15 +757,15 @@ drm_atomic_get_colorop_state(struct drm_atomic_commit *state,
>
> colorop_state = drm_atomic_helper_colorop_duplicate_state(colorop);
> if (!colorop_state)
> return ERR_PTR(-ENOMEM);
>
> - state->colorops[index].state_to_destroy = colorop_state;
> - state->colorops[index].ptr = colorop;
> - state->colorops[index].old_state = colorop->state;
> - state->colorops[index].new_state = colorop_state;
> - colorop_state->state = state;
> + ret = drm_atomic_commit_set_colorop_state(state, colorop, colorop_state);
> + if (ret) {
> + drm_colorop_atomic_destroy_state(colorop, colorop_state);
> + return ERR_PTR(ret);
> + }
>
> drm_dbg_atomic(colorop->dev, "Added [COLOROP:%d:%d] %p state to %p\n",
> colorop->base.id, colorop->type, colorop_state, state);
>
> return colorop_state;
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 05/11] drm/atomic: Create function to insert private obj state into a commit
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (3 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 04/11] drm/atomic: Create function to insert colorop " Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 6:46 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 06/11] drm/atomic: Create function to insert connector " Maxime Ripard
` (5 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
drm_atomic_get_private_obj_state() allocates a new private object
state by duplicating the current one and inserts it into the atomic
commit as a single operation.
However, a later change will need to insert a private object state
into a commit without going through the full allocation and
duplication path in drm_atomic_get_private_obj_state().
Extract the state insertion logic, including the array reallocation,
into a new static drm_atomic_commit_set_private_obj_state() helper,
and convert drm_atomic_get_private_obj_state() to use it.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 57 ++++++++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index f6a31c9d477d..1be4af940ed1 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1101,10 +1101,41 @@ drm_atomic_private_obj_fini(struct drm_private_obj *obj)
obj->funcs->atomic_destroy_state(obj, obj->state);
drm_modeset_lock_fini(&obj->lock);
}
EXPORT_SYMBOL(drm_atomic_private_obj_fini);
+static int drm_atomic_commit_set_private_obj_state(struct drm_atomic_commit *commit,
+ struct drm_private_obj *obj,
+ struct drm_private_state *obj_state)
+{
+ struct __drm_private_objs_state *arr;
+ int index, num_objs;
+ size_t size;
+
+ drm_modeset_lock_assert_held(&obj->lock);
+
+ num_objs = commit->num_private_objs + 1;
+ size = sizeof(*commit->private_objs) * num_objs;
+ arr = krealloc(commit->private_objs, size, GFP_KERNEL);
+ if (!arr)
+ return -ENOMEM;
+
+ commit->private_objs = arr;
+ index = commit->num_private_objs;
+ memset(&commit->private_objs[index], 0, sizeof(*commit->private_objs));
+
+ commit->private_objs[index].state_to_destroy = obj_state;
+ commit->private_objs[index].old_state = obj->state;
+ commit->private_objs[index].new_state = obj_state;
+ commit->private_objs[index].ptr = obj;
+ obj_state->state = commit;
+
+ commit->num_private_objs = num_objs;
+
+ return 0;
+}
+
/**
* drm_atomic_get_private_obj_state - get private object state
* @state: global atomic state
* @obj: private object to get the state for
*
@@ -1117,13 +1148,11 @@ EXPORT_SYMBOL(drm_atomic_private_obj_fini);
*/
struct drm_private_state *
drm_atomic_get_private_obj_state(struct drm_atomic_commit *state,
struct drm_private_obj *obj)
{
- int index, num_objs, ret;
- size_t size;
- struct __drm_private_objs_state *arr;
+ int ret;
struct drm_private_state *obj_state;
WARN_ON(!state->acquire_ctx);
drm_WARN_ON(state->dev, state->checked);
@@ -1133,31 +1162,19 @@ drm_atomic_get_private_obj_state(struct drm_atomic_commit *state,
ret = drm_modeset_lock(&obj->lock, state->acquire_ctx);
if (ret)
return ERR_PTR(ret);
- num_objs = state->num_private_objs + 1;
- size = sizeof(*state->private_objs) * num_objs;
- arr = krealloc(state->private_objs, size, GFP_KERNEL);
- if (!arr)
- return ERR_PTR(-ENOMEM);
-
- state->private_objs = arr;
- index = state->num_private_objs;
- memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
-
obj_state = obj->funcs->atomic_duplicate_state(obj);
if (!obj_state)
return ERR_PTR(-ENOMEM);
- state->private_objs[index].state_to_destroy = obj_state;
- state->private_objs[index].old_state = obj->state;
- state->private_objs[index].new_state = obj_state;
- state->private_objs[index].ptr = obj;
- obj_state->state = state;
-
- state->num_private_objs = num_objs;
+ ret = drm_atomic_commit_set_private_obj_state(state, obj, obj_state);
+ if (ret) {
+ obj->funcs->atomic_destroy_state(obj, obj_state);
+ return ERR_PTR(ret);
+ }
drm_dbg_atomic(state->dev,
"Added new private object %p state %p to %p\n",
obj, obj_state, state);
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 05/11] drm/atomic: Create function to insert private obj state into a commit
2026-09-08 14:35 ` [PATCH v3 05/11] drm/atomic: Create function to insert private obj " Maxime Ripard
@ 2026-09-09 6:46 ` Thomas Zimmermann
0 siblings, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 6:46 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Hi
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> drm_atomic_get_private_obj_state() allocates a new private object
> state by duplicating the current one and inserts it into the atomic
> commit as a single operation.
>
> However, a later change will need to insert a private object state
> into a commit without going through the full allocation and
> duplication path in drm_atomic_get_private_obj_state().
>
> Extract the state insertion logic, including the array reallocation,
> into a new static drm_atomic_commit_set_private_obj_state() helper,
> and convert drm_atomic_get_private_obj_state() to use it.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> ---
> drivers/gpu/drm/drm_atomic.c | 57 ++++++++++++++++++++++++++++----------------
> 1 file changed, 37 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index f6a31c9d477d..1be4af940ed1 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1101,10 +1101,41 @@ drm_atomic_private_obj_fini(struct drm_private_obj *obj)
> obj->funcs->atomic_destroy_state(obj, obj->state);
> drm_modeset_lock_fini(&obj->lock);
> }
> EXPORT_SYMBOL(drm_atomic_private_obj_fini);
>
> +static int drm_atomic_commit_set_private_obj_state(struct drm_atomic_commit *commit,
> + struct drm_private_obj *obj,
> + struct drm_private_state *obj_state)
> +{
> + struct __drm_private_objs_state *arr;
> + int index, num_objs;
> + size_t size;
> +
> + drm_modeset_lock_assert_held(&obj->lock);
> +
> + num_objs = commit->num_private_objs + 1;
> + size = sizeof(*commit->private_objs) * num_objs;
> + arr = krealloc(commit->private_objs, size, GFP_KERNEL);
> + if (!arr)
> + return -ENOMEM;
Just nitpicks: Would this be a candidate for krealloc_array() ? Could
you avoid the additional memset by allocating with __GFP_ZERO?
Best regards
Thomas
> +
> + commit->private_objs = arr;
> + index = commit->num_private_objs;
> + memset(&commit->private_objs[index], 0, sizeof(*commit->private_objs));
> +
> + commit->private_objs[index].state_to_destroy = obj_state;
> + commit->private_objs[index].old_state = obj->state;
> + commit->private_objs[index].new_state = obj_state;
> + commit->private_objs[index].ptr = obj;
> + obj_state->state = commit;
> +
> + commit->num_private_objs = num_objs;
> +
> + return 0;
> +}
> +
> /**
> * drm_atomic_get_private_obj_state - get private object state
> * @state: global atomic state
> * @obj: private object to get the state for
> *
> @@ -1117,13 +1148,11 @@ EXPORT_SYMBOL(drm_atomic_private_obj_fini);
> */
> struct drm_private_state *
> drm_atomic_get_private_obj_state(struct drm_atomic_commit *state,
> struct drm_private_obj *obj)
> {
> - int index, num_objs, ret;
> - size_t size;
> - struct __drm_private_objs_state *arr;
> + int ret;
> struct drm_private_state *obj_state;
>
> WARN_ON(!state->acquire_ctx);
> drm_WARN_ON(state->dev, state->checked);
>
> @@ -1133,31 +1162,19 @@ drm_atomic_get_private_obj_state(struct drm_atomic_commit *state,
>
> ret = drm_modeset_lock(&obj->lock, state->acquire_ctx);
> if (ret)
> return ERR_PTR(ret);
>
> - num_objs = state->num_private_objs + 1;
> - size = sizeof(*state->private_objs) * num_objs;
> - arr = krealloc(state->private_objs, size, GFP_KERNEL);
> - if (!arr)
> - return ERR_PTR(-ENOMEM);
> -
> - state->private_objs = arr;
> - index = state->num_private_objs;
> - memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
> -
> obj_state = obj->funcs->atomic_duplicate_state(obj);
> if (!obj_state)
> return ERR_PTR(-ENOMEM);
>
> - state->private_objs[index].state_to_destroy = obj_state;
> - state->private_objs[index].old_state = obj->state;
> - state->private_objs[index].new_state = obj_state;
> - state->private_objs[index].ptr = obj;
> - obj_state->state = state;
> -
> - state->num_private_objs = num_objs;
> + ret = drm_atomic_commit_set_private_obj_state(state, obj, obj_state);
> + if (ret) {
> + obj->funcs->atomic_destroy_state(obj, obj_state);
> + return ERR_PTR(ret);
> + }
>
> drm_dbg_atomic(state->dev,
> "Added new private object %p state %p to %p\n",
> obj, obj_state, state);
>
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 06/11] drm/atomic: Create function to insert connector state into a commit
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (4 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 05/11] drm/atomic: Create function to insert private obj " Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 6:52 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 07/11] drm/atomic: Add drm_atomic_can_create_state() helper Maxime Ripard
` (4 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
drm_atomic_get_connector_state() allocates a new connector state by
duplicating the current one and inserts it into the atomic commit as
a single operation.
However, a later change will need to insert a connector state into a
commit without going through the full allocation and duplication path
in drm_atomic_get_connector_state().
Extract the state insertion logic, including the dynamic array
reallocation, into a new static
drm_atomic_commit_set_connector_state() helper, and convert
drm_atomic_get_connector_state() to use it.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 67 +++++++++++++++++++++++++++-----------------
1 file changed, 42 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 1be4af940ed1..19678e8a2bd4 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1412,10 +1412,46 @@ drm_atomic_get_new_crtc_for_encoder(struct drm_atomic_commit *state,
return conn_state->crtc;
}
EXPORT_SYMBOL(drm_atomic_get_new_crtc_for_encoder);
+static int drm_atomic_commit_set_connector_state(struct drm_atomic_commit *commit,
+ struct drm_connector *connector,
+ struct drm_connector_state *connector_state)
+{
+ struct drm_mode_config *config = &connector->dev->mode_config;
+ int index;
+
+ drm_modeset_lock_assert_held(&config->connection_mutex);
+
+ index = drm_connector_index(connector);
+ if (index >= commit->num_connector) {
+ struct __drm_connnectors_state *c;
+ int alloc = max(index + 1, config->num_connector);
+
+ c = krealloc_array(commit->connectors, alloc,
+ sizeof(*commit->connectors), GFP_KERNEL);
+ if (!c)
+ return -ENOMEM;
+
+ commit->connectors = c;
+ memset(&commit->connectors[commit->num_connector], 0,
+ sizeof(*commit->connectors) * (alloc - commit->num_connector));
+
+ commit->num_connector = alloc;
+ }
+
+ drm_connector_get(connector);
+ commit->connectors[index].state_to_destroy = connector_state;
+ commit->connectors[index].old_state = connector->state;
+ commit->connectors[index].new_state = connector_state;
+ commit->connectors[index].ptr = connector;
+ connector_state->state = commit;
+
+ return 0;
+}
+
/**
* drm_atomic_get_connector_state - get connector state
* @state: global atomic state object
* @connector: connector to get state object for
*
@@ -1430,53 +1466,34 @@ EXPORT_SYMBOL(drm_atomic_get_new_crtc_for_encoder);
*/
struct drm_connector_state *
drm_atomic_get_connector_state(struct drm_atomic_commit *state,
struct drm_connector *connector)
{
- int ret, index;
+ int ret;
struct drm_mode_config *config = &connector->dev->mode_config;
struct drm_connector_state *connector_state;
WARN_ON(!state->acquire_ctx);
drm_WARN_ON(state->dev, state->checked);
ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
if (ret)
return ERR_PTR(ret);
- index = drm_connector_index(connector);
-
- if (index >= state->num_connector) {
- struct __drm_connnectors_state *c;
- int alloc = max(index + 1, config->num_connector);
-
- c = krealloc_array(state->connectors, alloc,
- sizeof(*state->connectors), GFP_KERNEL);
- if (!c)
- return ERR_PTR(-ENOMEM);
-
- state->connectors = c;
- memset(&state->connectors[state->num_connector], 0,
- sizeof(*state->connectors) * (alloc - state->num_connector));
-
- state->num_connector = alloc;
- }
-
connector_state = drm_atomic_get_new_connector_state(state, connector);
if (connector_state)
return connector_state;
connector_state = connector->funcs->atomic_duplicate_state(connector);
if (!connector_state)
return ERR_PTR(-ENOMEM);
- drm_connector_get(connector);
- state->connectors[index].state_to_destroy = connector_state;
- state->connectors[index].old_state = connector->state;
- state->connectors[index].new_state = connector_state;
- state->connectors[index].ptr = connector;
- connector_state->state = state;
+ ret = drm_atomic_commit_set_connector_state(state, connector, connector_state);
+ if (ret) {
+ connector->funcs->atomic_destroy_state(connector, connector_state);
+ return ERR_PTR(ret);
+ }
drm_dbg_atomic(connector->dev, "Added [CONNECTOR:%d:%s] %p state to %p\n",
connector->base.id, connector->name,
connector_state, state);
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 06/11] drm/atomic: Create function to insert connector state into a commit
2026-09-08 14:35 ` [PATCH v3 06/11] drm/atomic: Create function to insert connector " Maxime Ripard
@ 2026-09-09 6:52 ` Thomas Zimmermann
0 siblings, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 6:52 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> drm_atomic_get_connector_state() allocates a new connector state by
> duplicating the current one and inserts it into the atomic commit as
> a single operation.
>
> However, a later change will need to insert a connector state into a
> commit without going through the full allocation and duplication path
> in drm_atomic_get_connector_state().
>
> Extract the state insertion logic, including the dynamic array
> reallocation, into a new static
> drm_atomic_commit_set_connector_state() helper, and convert
> drm_atomic_get_connector_state() to use it.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> ---
> drivers/gpu/drm/drm_atomic.c | 67 +++++++++++++++++++++++++++-----------------
> 1 file changed, 42 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 1be4af940ed1..19678e8a2bd4 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1412,10 +1412,46 @@ drm_atomic_get_new_crtc_for_encoder(struct drm_atomic_commit *state,
>
> return conn_state->crtc;
> }
> EXPORT_SYMBOL(drm_atomic_get_new_crtc_for_encoder);
>
> +static int drm_atomic_commit_set_connector_state(struct drm_atomic_commit *commit,
> + struct drm_connector *connector,
> + struct drm_connector_state *connector_state)
> +{
> + struct drm_mode_config *config = &connector->dev->mode_config;
> + int index;
> +
> + drm_modeset_lock_assert_held(&config->connection_mutex);
> +
> + index = drm_connector_index(connector);
> + if (index >= commit->num_connector) {
> + struct __drm_connnectors_state *c;
> + int alloc = max(index + 1, config->num_connector);
> +
> + c = krealloc_array(commit->connectors, alloc,
> + sizeof(*commit->connectors), GFP_KERNEL);
This entire branch looks like it mostly open-codes the functionality of
krealloc_array(). If you can use __GFP_ZERO here, it appears that this
whole branching could be collapsed to a single unconditional
reallocation plus an update of num_connector.
Best regards
Thomas
> + if (!c)
> + return -ENOMEM;
> +
> + commit->connectors = c;
> + memset(&commit->connectors[commit->num_connector], 0,
> + sizeof(*commit->connectors) * (alloc - commit->num_connector));
> +
> + commit->num_connector = alloc;
> + }
> +
> + drm_connector_get(connector);
> + commit->connectors[index].state_to_destroy = connector_state;
> + commit->connectors[index].old_state = connector->state;
> + commit->connectors[index].new_state = connector_state;
> + commit->connectors[index].ptr = connector;
> + connector_state->state = commit;
> +
> + return 0;
> +}
> +
> /**
> * drm_atomic_get_connector_state - get connector state
> * @state: global atomic state object
> * @connector: connector to get state object for
> *
> @@ -1430,53 +1466,34 @@ EXPORT_SYMBOL(drm_atomic_get_new_crtc_for_encoder);
> */
> struct drm_connector_state *
> drm_atomic_get_connector_state(struct drm_atomic_commit *state,
> struct drm_connector *connector)
> {
> - int ret, index;
> + int ret;
> struct drm_mode_config *config = &connector->dev->mode_config;
> struct drm_connector_state *connector_state;
>
> WARN_ON(!state->acquire_ctx);
> drm_WARN_ON(state->dev, state->checked);
>
> ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
> if (ret)
> return ERR_PTR(ret);
>
> - index = drm_connector_index(connector);
> -
> - if (index >= state->num_connector) {
> - struct __drm_connnectors_state *c;
> - int alloc = max(index + 1, config->num_connector);
> -
> - c = krealloc_array(state->connectors, alloc,
> - sizeof(*state->connectors), GFP_KERNEL);
> - if (!c)
> - return ERR_PTR(-ENOMEM);
> -
> - state->connectors = c;
> - memset(&state->connectors[state->num_connector], 0,
> - sizeof(*state->connectors) * (alloc - state->num_connector));
> -
> - state->num_connector = alloc;
> - }
> -
> connector_state = drm_atomic_get_new_connector_state(state, connector);
> if (connector_state)
> return connector_state;
>
> connector_state = connector->funcs->atomic_duplicate_state(connector);
> if (!connector_state)
> return ERR_PTR(-ENOMEM);
>
> - drm_connector_get(connector);
> - state->connectors[index].state_to_destroy = connector_state;
> - state->connectors[index].old_state = connector->state;
> - state->connectors[index].new_state = connector_state;
> - state->connectors[index].ptr = connector;
> - connector_state->state = state;
> + ret = drm_atomic_commit_set_connector_state(state, connector, connector_state);
> + if (ret) {
> + connector->funcs->atomic_destroy_state(connector, connector_state);
> + return ERR_PTR(ret);
> + }
>
> drm_dbg_atomic(connector->dev, "Added [CONNECTOR:%d:%s] %p state to %p\n",
> connector->base.id, connector->name,
> connector_state, state);
>
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 07/11] drm/atomic: Add drm_atomic_can_create_state() helper
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (5 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 06/11] drm/atomic: Create function to insert connector " Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 6:58 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 08/11] drm/atomic: Allow filling a commit with pristine object states Maxime Ripard
` (3 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
The atomic reset path will need to create pristine default states from
scratch for every plane, CRTC, and connector. This requires all of them
to implement the atomic_create_state hook.
Introduce a drm_atomic_can_create_state() helper that iterates over all
planes, CRTCs, and connectors and returns whether they all provide the
hook. Color operations are excluded since they always use
drm_atomic_helper_colorop_create_state() directly.
This will be used both as a precondition before filling a commit with
default states, and to report the device capability to userspace.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
include/drm/drm_atomic.h | 2 ++
2 files changed, 51 insertions(+)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 19678e8a2bd4..508a027398af 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1612,10 +1612,59 @@ drm_atomic_get_new_bridge_state(const struct drm_atomic_commit *state,
return drm_priv_to_bridge_state(obj_state);
}
EXPORT_SYMBOL(drm_atomic_get_new_bridge_state);
+/**
+ * drm_atomic_can_create_state - check if a device supports creating pristine states
+ * @dev: DRM device
+ *
+ * Check whether every plane, CRTC, and connector in @dev implements the
+ * &drm_plane_funcs.atomic_create_state, &drm_crtc_funcs.atomic_create_state,
+ * and &drm_connector_funcs.atomic_create_state hooks respectively. These hooks
+ * are required to create default states from scratch rather than duplicating
+ * the current state.
+ *
+ * Color operations are not checked because they always use
+ * drm_atomic_helper_colorop_create_state() and do not have a per-driver hook.
+ *
+ * Returns:
+ * True if all objects implement atomic_create_state, false otherwise.
+ */
+bool drm_atomic_can_create_state(struct drm_device *dev)
+{
+ struct drm_connector_list_iter conn_iter;
+ struct drm_connector *connector;
+ struct drm_plane *plane;
+ struct drm_crtc *crtc;
+
+ /*
+ * colorops don't have an atomic_create_state hook but
+ * drm_atomic_helper_colorop_create_state()
+ */
+
+ drm_for_each_plane(plane, dev)
+ if (!plane->funcs->atomic_create_state)
+ return false;
+
+ drm_for_each_crtc(crtc, dev)
+ if (!crtc->funcs->atomic_create_state)
+ return false;
+
+ drm_connector_list_iter_begin(dev, &conn_iter);
+ drm_for_each_connector_iter(connector, &conn_iter) {
+ if (!connector->funcs->atomic_create_state) {
+ drm_connector_list_iter_end(&conn_iter);
+ return false;
+ }
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ return true;
+}
+EXPORT_SYMBOL(drm_atomic_can_create_state);
+
/**
* drm_atomic_add_encoder_bridges - add bridges attached to an encoder
* @state: atomic state
* @encoder: DRM encoder
*
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 00b3e9fc429a..7dc26e3da65c 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -700,10 +700,12 @@ int drm_crtc_commit_wait(struct drm_crtc_commit *commit);
struct drm_atomic_commit * __must_check
drm_atomic_commit_alloc(struct drm_device *dev);
void drm_atomic_commit_clear(struct drm_atomic_commit *state);
+bool drm_atomic_can_create_state(struct drm_device *dev);
+
/**
* drm_atomic_commit_get - acquire a reference to the atomic state
* @state: The atomic state
*
* Returns a new reference to the @state
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 07/11] drm/atomic: Add drm_atomic_can_create_state() helper
2026-09-08 14:35 ` [PATCH v3 07/11] drm/atomic: Add drm_atomic_can_create_state() helper Maxime Ripard
@ 2026-09-09 6:58 ` Thomas Zimmermann
0 siblings, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 6:58 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Hi
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> The atomic reset path will need to create pristine default states from
> scratch for every plane, CRTC, and connector. This requires all of them
> to implement the atomic_create_state hook.
>
> Introduce a drm_atomic_can_create_state() helper that iterates over all
> planes, CRTCs, and connectors and returns whether they all provide the
> hook. Color operations are excluded since they always use
> drm_atomic_helper_colorop_create_state() directly.
>
> This will be used both as a precondition before filling a commit with
> default states, and to report the device capability to userspace.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> ---
> drivers/gpu/drm/drm_atomic.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
> include/drm/drm_atomic.h | 2 ++
> 2 files changed, 51 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 19678e8a2bd4..508a027398af 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1612,10 +1612,59 @@ drm_atomic_get_new_bridge_state(const struct drm_atomic_commit *state,
>
> return drm_priv_to_bridge_state(obj_state);
> }
> EXPORT_SYMBOL(drm_atomic_get_new_bridge_state);
>
> +/**
> + * drm_atomic_can_create_state - check if a device supports creating pristine states
> + * @dev: DRM device
I find this name a bit vague, because all mode-setting pipelines can
create states in one way or another. Given how it is used, I suggest
naming this helper _can_create_default_states or _can_reset_state.
Best regards
Thomas
> + *
> + * Check whether every plane, CRTC, and connector in @dev implements the
> + * &drm_plane_funcs.atomic_create_state, &drm_crtc_funcs.atomic_create_state,
> + * and &drm_connector_funcs.atomic_create_state hooks respectively. These hooks
> + * are required to create default states from scratch rather than duplicating
> + * the current state.
> + *
> + * Color operations are not checked because they always use
> + * drm_atomic_helper_colorop_create_state() and do not have a per-driver hook.
> + *
> + * Returns:
> + * True if all objects implement atomic_create_state, false otherwise.
> + */
> +bool drm_atomic_can_create_state(struct drm_device *dev)
> +{
> + struct drm_connector_list_iter conn_iter;
> + struct drm_connector *connector;
> + struct drm_plane *plane;
> + struct drm_crtc *crtc;
> +
> + /*
> + * colorops don't have an atomic_create_state hook but
> + * drm_atomic_helper_colorop_create_state()
> + */
> +
> + drm_for_each_plane(plane, dev)
> + if (!plane->funcs->atomic_create_state)
> + return false;
> +
> + drm_for_each_crtc(crtc, dev)
> + if (!crtc->funcs->atomic_create_state)
> + return false;
> +
> + drm_connector_list_iter_begin(dev, &conn_iter);
> + drm_for_each_connector_iter(connector, &conn_iter) {
> + if (!connector->funcs->atomic_create_state) {
> + drm_connector_list_iter_end(&conn_iter);
> + return false;
> + }
> + }
> + drm_connector_list_iter_end(&conn_iter);
> +
> + return true;
> +}
> +EXPORT_SYMBOL(drm_atomic_can_create_state);
> +
> /**
> * drm_atomic_add_encoder_bridges - add bridges attached to an encoder
> * @state: atomic state
> * @encoder: DRM encoder
> *
> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> index 00b3e9fc429a..7dc26e3da65c 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -700,10 +700,12 @@ int drm_crtc_commit_wait(struct drm_crtc_commit *commit);
>
> struct drm_atomic_commit * __must_check
> drm_atomic_commit_alloc(struct drm_device *dev);
> void drm_atomic_commit_clear(struct drm_atomic_commit *state);
>
> +bool drm_atomic_can_create_state(struct drm_device *dev);
> +
> /**
> * drm_atomic_commit_get - acquire a reference to the atomic state
> * @state: The atomic state
> *
> * Returns a new reference to the @state
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 08/11] drm/atomic: Allow filling a commit with pristine object states
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (6 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 07/11] drm/atomic: Add drm_atomic_can_create_state() helper Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 7:11 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (2 subsequent siblings)
10 siblings, 1 reply; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
The upcoming DRM_MODE_ATOMIC_RESET flag will need to create an atomic
commit that brings the entire device back to a pristine state, as if
no configuration had ever been applied.
Create drm_atomic_commit_fill_with_defaults() which iterates over all
CRTCs, planes, connectors, and color operations in the device and
inserts a fresh default state for each one into the commit. This uses
the atomic_create_state() hooks rather than atomic_duplicate_state(),
since atomic_create_state() provides exactly this pristine state on a
per-object basis.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 123 +++++++++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/drm_ioctl.c | 1 +
include/drm/drm_atomic.h | 1 +
3 files changed, 125 insertions(+)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 508a027398af..4c15757308d6 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1661,10 +1661,133 @@ bool drm_atomic_can_create_state(struct drm_device *dev)
return true;
}
EXPORT_SYMBOL(drm_atomic_can_create_state);
+/**
+ * drm_atomic_commit_fill_with_defaults - populate a commit with pristine states
+ * @commit: atomic commit to fill
+ *
+ * Iterate over all CRTCs, planes, connectors, and color operations in
+ * the device and insert a freshly created default state for each one
+ * into @commit. The states are created through the atomic_create_state()
+ * hooks, producing the same initial state the driver starts with rather
+ * than a copy of the current hardware state.
+ *
+ * This is meant to be used with the %DRM_MODE_ATOMIC_RESET flag, which
+ * needs to bring the device back to a known baseline before applying
+ * userspace property changes on top.
+ *
+ * Returns:
+ * 0 on success, or a negative error code on failure.
+ */
+int drm_atomic_commit_fill_with_defaults(struct drm_atomic_commit *commit)
+{
+ struct drm_device *dev = commit->dev;
+ struct drm_mode_config *config = &dev->mode_config;
+ struct drm_crtc *crtc;
+ struct drm_plane *plane;
+ struct drm_connector *connector;
+ struct drm_connector_list_iter conn_iter;
+ struct drm_colorop *colorop;
+ int ret;
+
+ WARN_ON(!commit->acquire_ctx);
+
+ if (!drm_atomic_can_create_state(dev))
+ return -EOPNOTSUPP;
+
+ /*
+ * Private objects are ignored because none have userspace
+ * properties we might want to reset. atomic_check
+ * implementations will derive or infer their private obj state
+ * from the state that will end up being committed anyway.
+ */
+ drm_for_each_colorop(colorop, dev) {
+ struct drm_colorop_state *colorop_state;
+
+ ret = drm_modeset_lock(&colorop->plane->mutex, commit->acquire_ctx);
+ if (ret)
+ return ret;
+
+ colorop_state = drm_atomic_helper_colorop_create_state(colorop);
+ if (IS_ERR(colorop_state))
+ return PTR_ERR(colorop_state);
+
+ ret = drm_atomic_commit_set_colorop_state(commit, colorop, colorop_state);
+ if (ret) {
+ drm_colorop_atomic_destroy_state(colorop, colorop_state);
+ return ret;
+ }
+ }
+
+ drm_for_each_plane(plane, dev) {
+ struct drm_plane_state *plane_state;
+
+ ret = drm_modeset_lock(&plane->mutex, commit->acquire_ctx);
+ if (ret)
+ return ret;
+
+ plane_state = plane->funcs->atomic_create_state(plane);
+ if (IS_ERR(plane_state))
+ return PTR_ERR(plane_state);
+
+ ret = drm_atomic_commit_set_plane_state(commit, plane, plane_state);
+ if (ret) {
+ plane->funcs->atomic_destroy_state(plane, plane_state);
+ return ret;
+ }
+ }
+
+ drm_for_each_crtc(crtc, dev) {
+ struct drm_crtc_state *crtc_state;
+
+ ret = drm_modeset_lock(&crtc->mutex, commit->acquire_ctx);
+ if (ret)
+ return ret;
+
+ crtc_state = crtc->funcs->atomic_create_state(crtc);
+ if (IS_ERR(crtc_state))
+ return PTR_ERR(crtc_state);
+
+ ret = drm_atomic_commit_set_crtc_state(commit, crtc, crtc_state);
+ if (ret) {
+ crtc->funcs->atomic_destroy_state(crtc, crtc_state);
+ return ret;
+ }
+ }
+
+ drm_connector_list_iter_begin(dev, &conn_iter);
+ drm_for_each_connector_iter(connector, &conn_iter) {
+ struct drm_connector_state *connector_state;
+
+ ret = drm_modeset_lock(&config->connection_mutex, commit->acquire_ctx);
+ if (ret) {
+ drm_connector_list_iter_end(&conn_iter);
+ return ret;
+ }
+
+ connector_state = connector->funcs->atomic_create_state(connector);
+ if (IS_ERR(connector_state)) {
+ drm_connector_list_iter_end(&conn_iter);
+ ret = PTR_ERR(connector_state);
+ return ret;
+ }
+
+ ret = drm_atomic_commit_set_connector_state(commit, connector, connector_state);
+ if (ret) {
+ connector->funcs->atomic_destroy_state(connector, connector_state);
+ drm_connector_list_iter_end(&conn_iter);
+ return ret;
+ }
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ return 0;
+}
+EXPORT_SYMBOL(drm_atomic_commit_fill_with_defaults);
+
/**
* drm_atomic_add_encoder_bridges - add bridges attached to an encoder
* @state: atomic state
* @encoder: DRM encoder
*
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 9039a39c4324..0dbf04d4aa9e 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -31,10 +31,11 @@
#include <linux/export.h>
#include <linux/nospec.h>
#include <linux/pci.h>
#include <linux/uaccess.h>
+#include <drm/drm_atomic.h>
#include <drm/drm_auth.h>
#include <drm/drm_crtc.h>
#include <drm/drm_drv.h>
#include <drm/drm_file.h>
#include <drm/drm_ioctl.h>
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 7dc26e3da65c..b60f67619bfa 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -701,10 +701,11 @@ int drm_crtc_commit_wait(struct drm_crtc_commit *commit);
struct drm_atomic_commit * __must_check
drm_atomic_commit_alloc(struct drm_device *dev);
void drm_atomic_commit_clear(struct drm_atomic_commit *state);
bool drm_atomic_can_create_state(struct drm_device *dev);
+int drm_atomic_commit_fill_with_defaults(struct drm_atomic_commit *commit);
/**
* drm_atomic_commit_get - acquire a reference to the atomic state
* @state: The atomic state
*
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 08/11] drm/atomic: Allow filling a commit with pristine object states
2026-09-08 14:35 ` [PATCH v3 08/11] drm/atomic: Allow filling a commit with pristine object states Maxime Ripard
@ 2026-09-09 7:11 ` Thomas Zimmermann
0 siblings, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 7:11 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> The upcoming DRM_MODE_ATOMIC_RESET flag will need to create an atomic
> commit that brings the entire device back to a pristine state, as if
> no configuration had ever been applied.
>
> Create drm_atomic_commit_fill_with_defaults() which iterates over all
> CRTCs, planes, connectors, and color operations in the device and
> inserts a fresh default state for each one into the commit. This uses
> the atomic_create_state() hooks rather than atomic_duplicate_state(),
> since atomic_create_state() provides exactly this pristine state on a
> per-object basis.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> ---
> drivers/gpu/drm/drm_atomic.c | 123 +++++++++++++++++++++++++++++++++++++++++++
> drivers/gpu/drm/drm_ioctl.c | 1 +
> include/drm/drm_atomic.h | 1 +
> 3 files changed, 125 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 508a027398af..4c15757308d6 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1661,10 +1661,133 @@ bool drm_atomic_can_create_state(struct drm_device *dev)
>
> return true;
> }
> EXPORT_SYMBOL(drm_atomic_can_create_state);
>
> +/**
> + * drm_atomic_commit_fill_with_defaults - populate a commit with pristine states
> + * @commit: atomic commit to fill
> + *
> + * Iterate over all CRTCs, planes, connectors, and color operations in
> + * the device and insert a freshly created default state for each one
> + * into @commit. The states are created through the atomic_create_state()
> + * hooks, producing the same initial state the driver starts with rather
> + * than a copy of the current hardware state.
> + *
> + * This is meant to be used with the %DRM_MODE_ATOMIC_RESET flag, which
> + * needs to bring the device back to a known baseline before applying
> + * userspace property changes on top.
> + *
> + * Returns:
> + * 0 on success, or a negative error code on failure.
> + */
> +int drm_atomic_commit_fill_with_defaults(struct drm_atomic_commit *commit)
> +{
> + struct drm_device *dev = commit->dev;
> + struct drm_mode_config *config = &dev->mode_config;
> + struct drm_crtc *crtc;
> + struct drm_plane *plane;
> + struct drm_connector *connector;
> + struct drm_connector_list_iter conn_iter;
> + struct drm_colorop *colorop;
> + int ret;
> +
> + WARN_ON(!commit->acquire_ctx);
drm_WARN_ON
> +
> + if (!drm_atomic_can_create_state(dev))
> + return -EOPNOTSUPP;
I'd push this test into the caller and maybe do a
drm_WARN_ON(!_can_create_state) here. I think that this helper
shouldn't even be called if there's no reset support.
Best regards
Thomas
> +
> + /*
> + * Private objects are ignored because none have userspace
> + * properties we might want to reset. atomic_check
> + * implementations will derive or infer their private obj state
> + * from the state that will end up being committed anyway.
> + */
> + drm_for_each_colorop(colorop, dev) {
> + struct drm_colorop_state *colorop_state;
> +
> + ret = drm_modeset_lock(&colorop->plane->mutex, commit->acquire_ctx);
> + if (ret)
> + return ret;
> +
> + colorop_state = drm_atomic_helper_colorop_create_state(colorop);
> + if (IS_ERR(colorop_state))
> + return PTR_ERR(colorop_state);
> +
> + ret = drm_atomic_commit_set_colorop_state(commit, colorop, colorop_state);
> + if (ret) {
> + drm_colorop_atomic_destroy_state(colorop, colorop_state);
> + return ret;
> + }
> + }
> +
> + drm_for_each_plane(plane, dev) {
> + struct drm_plane_state *plane_state;
> +
> + ret = drm_modeset_lock(&plane->mutex, commit->acquire_ctx);
> + if (ret)
> + return ret;
> +
> + plane_state = plane->funcs->atomic_create_state(plane);
> + if (IS_ERR(plane_state))
> + return PTR_ERR(plane_state);
> +
> + ret = drm_atomic_commit_set_plane_state(commit, plane, plane_state);
> + if (ret) {
> + plane->funcs->atomic_destroy_state(plane, plane_state);
> + return ret;
> + }
> + }
> +
> + drm_for_each_crtc(crtc, dev) {
> + struct drm_crtc_state *crtc_state;
> +
> + ret = drm_modeset_lock(&crtc->mutex, commit->acquire_ctx);
> + if (ret)
> + return ret;
> +
> + crtc_state = crtc->funcs->atomic_create_state(crtc);
> + if (IS_ERR(crtc_state))
> + return PTR_ERR(crtc_state);
> +
> + ret = drm_atomic_commit_set_crtc_state(commit, crtc, crtc_state);
> + if (ret) {
> + crtc->funcs->atomic_destroy_state(crtc, crtc_state);
> + return ret;
> + }
> + }
> +
> + drm_connector_list_iter_begin(dev, &conn_iter);
> + drm_for_each_connector_iter(connector, &conn_iter) {
> + struct drm_connector_state *connector_state;
> +
> + ret = drm_modeset_lock(&config->connection_mutex, commit->acquire_ctx);
> + if (ret) {
> + drm_connector_list_iter_end(&conn_iter);
> + return ret;
> + }
> +
> + connector_state = connector->funcs->atomic_create_state(connector);
> + if (IS_ERR(connector_state)) {
> + drm_connector_list_iter_end(&conn_iter);
> + ret = PTR_ERR(connector_state);
> + return ret;
> + }
> +
> + ret = drm_atomic_commit_set_connector_state(commit, connector, connector_state);
> + if (ret) {
> + connector->funcs->atomic_destroy_state(connector, connector_state);
> + drm_connector_list_iter_end(&conn_iter);
> + return ret;
> + }
> + }
> + drm_connector_list_iter_end(&conn_iter);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(drm_atomic_commit_fill_with_defaults);
> +
> /**
> * drm_atomic_add_encoder_bridges - add bridges attached to an encoder
> * @state: atomic state
> * @encoder: DRM encoder
> *
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index 9039a39c4324..0dbf04d4aa9e 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -31,10 +31,11 @@
> #include <linux/export.h>
> #include <linux/nospec.h>
> #include <linux/pci.h>
> #include <linux/uaccess.h>
>
> +#include <drm/drm_atomic.h>
> #include <drm/drm_auth.h>
> #include <drm/drm_crtc.h>
> #include <drm/drm_drv.h>
> #include <drm/drm_file.h>
> #include <drm/drm_ioctl.h>
> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> index 7dc26e3da65c..b60f67619bfa 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -701,10 +701,11 @@ int drm_crtc_commit_wait(struct drm_crtc_commit *commit);
> struct drm_atomic_commit * __must_check
> drm_atomic_commit_alloc(struct drm_device *dev);
> void drm_atomic_commit_clear(struct drm_atomic_commit *state);
>
> bool drm_atomic_can_create_state(struct drm_device *dev);
> +int drm_atomic_commit_fill_with_defaults(struct drm_atomic_commit *commit);
>
> /**
> * drm_atomic_commit_get - acquire a reference to the atomic state
> * @state: The atomic state
> *
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (7 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 08/11] drm/atomic: Allow filling a commit with pristine object states Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-09 7:13 ` Thomas Zimmermann
2026-09-09 7:24 ` Thomas Zimmermann
2026-09-08 14:35 ` [PATCH v3 10/11] drm/vkms: Switch container_of helpers to container_of_const Maxime Ripard
2026-09-08 14:35 ` [PATCH v3 11/11] drm/vkms: Add driver-specific plane property for testing Maxime Ripard
10 siblings, 2 replies; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
From: Sebastian Wick <sebastian.wick@redhat.com>
Userspace currently has no atomic way to reset all KMS object states
to their defaults. To bring a display pipeline to a known state, a
compositor must explicitly set every property on every object, which
requires tracking which properties exist and what their defaults are.
Introduce DRM_MODE_ATOMIC_RESET (0x0800) which, when passed to the
atomic ioctl, fills the commit with default states for all KMS
objects before applying the properties supplied in the request.
Properties not explicitly included in the commit remain at their
defaults (CRTCs inactive, planes disabled, connectors unbound, and
so on).
The flag cannot be combined with DRM_MODE_PAGE_FLIP_ASYNC, since a
full state reset is incompatible with an async flip.
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
Co-developed-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_atomic.c | 3 +++
drivers/gpu/drm/drm_atomic_uapi.c | 13 +++++++++++++
drivers/gpu/drm/drm_ioctl.c | 3 +++
include/uapi/drm/drm.h | 10 ++++++++++
include/uapi/drm/drm_mode.h | 14 +++++++++++++-
5 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 4c15757308d6..d5b3a7d99239 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1625,10 +1625,13 @@ EXPORT_SYMBOL(drm_atomic_get_new_bridge_state);
* the current state.
*
* Color operations are not checked because they always use
* drm_atomic_helper_colorop_create_state() and do not have a per-driver hook.
*
+ * This is used to report the %DRM_CAP_ATOMIC_RESET capability to userspace,
+ * and as a precondition in drm_atomic_commit_fill_with_defaults().
+ *
* Returns:
* True if all objects implement atomic_create_state, false otherwise.
*/
bool drm_atomic_can_create_state(struct drm_device *dev)
{
diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c
index d52504d823bc..fe794a65a727 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -1665,10 +1665,17 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
drm_dbg_atomic(dev,
"commit failed: page-flip event requested with test-only commit\n");
return -EINVAL;
}
+ if ((arg->flags & DRM_MODE_ATOMIC_RESET) &&
+ (arg->flags & DRM_MODE_PAGE_FLIP_ASYNC)) {
+ drm_dbg_atomic(dev,
+ "commit failed: reset cannot be combined with async flip\n");
+ return -EINVAL;
+ }
+
state = drm_atomic_commit_alloc(dev);
if (!state)
return -ENOMEM;
drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
@@ -1680,10 +1687,16 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
copied_objs = 0;
copied_props = 0;
fence_state = NULL;
num_fences = 0;
+ if (arg->flags & DRM_MODE_ATOMIC_RESET) {
+ ret = drm_atomic_commit_fill_with_defaults(state);
+ if (ret)
+ goto out;
+ }
+
for (i = 0; i < arg->count_objs; i++) {
uint32_t obj_id, count_props;
struct drm_mode_object *obj;
if (get_user(obj_id, objs_ptr + copied_objs)) {
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 0dbf04d4aa9e..f13bb7c490c4 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -303,10 +303,13 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
break;
case DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP:
req->value = drm_core_check_feature(dev, DRIVER_ATOMIC) &&
dev->mode_config.async_page_flip;
break;
+ case DRM_CAP_ATOMIC_RESET:
+ req->value = drm_atomic_can_create_state(dev);
+ break;
default:
return -EINVAL;
}
return 0;
}
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index bc7ef7684099..b6e2f2edd122 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -793,10 +793,20 @@ struct drm_gem_change_handle {
* If set to 1, the driver supports &DRM_MODE_PAGE_FLIP_ASYNC for atomic
* commits.
*/
#define DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP 0x15
+/**
+ * DRM_CAP_ATOMIC_RESET
+ *
+ * If set to 1, the driver supports the &DRM_MODE_ATOMIC_RESET flag in
+ * &DRM_IOCTL_MODE_ATOMIC commits. When supported, userspace can pass that
+ * flag to reset all KMS object states to their defaults before applying
+ * property changes.
+ */
+#define DRM_CAP_ATOMIC_RESET 0x16
+
/* DRM_IOCTL_GET_CAP ioctl argument type */
struct drm_get_cap {
__u64 capability;
__u64 value;
};
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index ed1a660a3dfd..32eb3f650d7a 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -1326,10 +1326,21 @@ struct drm_mode_destroy_dumb {
* To the best of the driver's knowledge, visual artifacts are guaranteed to
* not appear when this flag is not set. Some sinks might display visual
* artifacts outside of the driver's control.
*/
#define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
+/**
+ * DRM_MODE_ATOMIC_RESET
+ *
+ * Reset all KMS object states (CRTCs, planes, connectors, color operations)
+ * to their default values before applying the properties in this commit.
+ * Properties not explicitly included in the commit will remain at their
+ * defaults (CRTCs inactive, planes disabled, connectors unbound, etc.).
+ *
+ * This flag cannot be combined with &DRM_MODE_PAGE_FLIP_ASYNC.
+ */
+#define DRM_MODE_ATOMIC_RESET 0x0800
/**
* DRM_MODE_ATOMIC_FLAGS
*
* Bitfield of flags accepted by the &DRM_IOCTL_MODE_ATOMIC IOCTL in
@@ -1338,11 +1349,12 @@ struct drm_mode_destroy_dumb {
#define DRM_MODE_ATOMIC_FLAGS (\
DRM_MODE_PAGE_FLIP_EVENT |\
DRM_MODE_PAGE_FLIP_ASYNC |\
DRM_MODE_ATOMIC_TEST_ONLY |\
DRM_MODE_ATOMIC_NONBLOCK |\
- DRM_MODE_ATOMIC_ALLOW_MODESET)
+ DRM_MODE_ATOMIC_ALLOW_MODESET |\
+ DRM_MODE_ATOMIC_RESET)
struct drm_mode_atomic {
__u32 flags;
__u32 count_objs;
__u64 objs_ptr;
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag
2026-09-08 14:35 ` [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
@ 2026-09-09 7:13 ` Thomas Zimmermann
2026-09-09 7:24 ` Thomas Zimmermann
1 sibling, 0 replies; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 7:13 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> From: Sebastian Wick <sebastian.wick@redhat.com>
>
> Userspace currently has no atomic way to reset all KMS object states
> to their defaults. To bring a display pipeline to a known state, a
> compositor must explicitly set every property on every object, which
> requires tracking which properties exist and what their defaults are.
>
> Introduce DRM_MODE_ATOMIC_RESET (0x0800) which, when passed to the
> atomic ioctl, fills the commit with default states for all KMS
> objects before applying the properties supplied in the request.
> Properties not explicitly included in the commit remain at their
> defaults (CRTCs inactive, planes disabled, connectors unbound, and
> so on).
>
> The flag cannot be combined with DRM_MODE_PAGE_FLIP_ASYNC, since a
> full state reset is incompatible with an async flip.
>
> Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
> Co-developed-by: Maxime Ripard <mripard@kernel.org>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
> drivers/gpu/drm/drm_atomic.c | 3 +++
> drivers/gpu/drm/drm_atomic_uapi.c | 13 +++++++++++++
> drivers/gpu/drm/drm_ioctl.c | 3 +++
> include/uapi/drm/drm.h | 10 ++++++++++
> include/uapi/drm/drm_mode.h | 14 +++++++++++++-
> 5 files changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 4c15757308d6..d5b3a7d99239 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1625,10 +1625,13 @@ EXPORT_SYMBOL(drm_atomic_get_new_bridge_state);
> * the current state.
> *
> * Color operations are not checked because they always use
> * drm_atomic_helper_colorop_create_state() and do not have a per-driver hook.
> *
> + * This is used to report the %DRM_CAP_ATOMIC_RESET capability to userspace,
> + * and as a precondition in drm_atomic_commit_fill_with_defaults().
> + *
> * Returns:
> * True if all objects implement atomic_create_state, false otherwise.
> */
> bool drm_atomic_can_create_state(struct drm_device *dev)
> {
> diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c
> index d52504d823bc..fe794a65a727 100644
> --- a/drivers/gpu/drm/drm_atomic_uapi.c
> +++ b/drivers/gpu/drm/drm_atomic_uapi.c
> @@ -1665,10 +1665,17 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
> drm_dbg_atomic(dev,
> "commit failed: page-flip event requested with test-only commit\n");
> return -EINVAL;
> }
>
> + if ((arg->flags & DRM_MODE_ATOMIC_RESET) &&
> + (arg->flags & DRM_MODE_PAGE_FLIP_ASYNC)) {
> + drm_dbg_atomic(dev,
> + "commit failed: reset cannot be combined with async flip\n");
> + return -EINVAL;
> + }
> +
> state = drm_atomic_commit_alloc(dev);
> if (!state)
> return -ENOMEM;
>
> drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
> @@ -1680,10 +1687,16 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
> copied_objs = 0;
> copied_props = 0;
> fence_state = NULL;
> num_fences = 0;
>
> + if (arg->flags & DRM_MODE_ATOMIC_RESET) {
> + ret = drm_atomic_commit_fill_with_defaults(state);
> + if (ret)
> + goto out;
> + }
> +
> for (i = 0; i < arg->count_objs; i++) {
> uint32_t obj_id, count_props;
> struct drm_mode_object *obj;
>
> if (get_user(obj_id, objs_ptr + copied_objs)) {
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index 0dbf04d4aa9e..f13bb7c490c4 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -303,10 +303,13 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
> break;
> case DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP:
> req->value = drm_core_check_feature(dev, DRIVER_ATOMIC) &&
> dev->mode_config.async_page_flip;
> break;
> + case DRM_CAP_ATOMIC_RESET:
> + req->value = drm_atomic_can_create_state(dev);
> + break;
> default:
> return -EINVAL;
> }
> return 0;
> }
> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> index bc7ef7684099..b6e2f2edd122 100644
> --- a/include/uapi/drm/drm.h
> +++ b/include/uapi/drm/drm.h
> @@ -793,10 +793,20 @@ struct drm_gem_change_handle {
> * If set to 1, the driver supports &DRM_MODE_PAGE_FLIP_ASYNC for atomic
> * commits.
> */
> #define DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP 0x15
>
> +/**
> + * DRM_CAP_ATOMIC_RESET
> + *
> + * If set to 1, the driver supports the &DRM_MODE_ATOMIC_RESET flag in
> + * &DRM_IOCTL_MODE_ATOMIC commits. When supported, userspace can pass that
> + * flag to reset all KMS object states to their defaults before applying
> + * property changes.
> + */
> +#define DRM_CAP_ATOMIC_RESET 0x16
> +
> /* DRM_IOCTL_GET_CAP ioctl argument type */
> struct drm_get_cap {
> __u64 capability;
> __u64 value;
> };
> diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
> index ed1a660a3dfd..32eb3f650d7a 100644
> --- a/include/uapi/drm/drm_mode.h
> +++ b/include/uapi/drm/drm_mode.h
> @@ -1326,10 +1326,21 @@ struct drm_mode_destroy_dumb {
> * To the best of the driver's knowledge, visual artifacts are guaranteed to
> * not appear when this flag is not set. Some sinks might display visual
> * artifacts outside of the driver's control.
> */
> #define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
> +/**
> + * DRM_MODE_ATOMIC_RESET
> + *
> + * Reset all KMS object states (CRTCs, planes, connectors, color operations)
> + * to their default values before applying the properties in this commit.
> + * Properties not explicitly included in the commit will remain at their
> + * defaults (CRTCs inactive, planes disabled, connectors unbound, etc.).
> + *
> + * This flag cannot be combined with &DRM_MODE_PAGE_FLIP_ASYNC.
> + */
> +#define DRM_MODE_ATOMIC_RESET 0x0800
>
> /**
> * DRM_MODE_ATOMIC_FLAGS
> *
> * Bitfield of flags accepted by the &DRM_IOCTL_MODE_ATOMIC IOCTL in
> @@ -1338,11 +1349,12 @@ struct drm_mode_destroy_dumb {
> #define DRM_MODE_ATOMIC_FLAGS (\
> DRM_MODE_PAGE_FLIP_EVENT |\
> DRM_MODE_PAGE_FLIP_ASYNC |\
> DRM_MODE_ATOMIC_TEST_ONLY |\
> DRM_MODE_ATOMIC_NONBLOCK |\
> - DRM_MODE_ATOMIC_ALLOW_MODESET)
> + DRM_MODE_ATOMIC_ALLOW_MODESET |\
> + DRM_MODE_ATOMIC_RESET)
>
> struct drm_mode_atomic {
> __u32 flags;
> __u32 count_objs;
> __u64 objs_ptr;
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag
2026-09-08 14:35 ` [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-09-09 7:13 ` Thomas Zimmermann
@ 2026-09-09 7:24 ` Thomas Zimmermann
2026-09-09 8:22 ` Maxime Ripard
1 sibling, 1 reply; 24+ messages in thread
From: Thomas Zimmermann @ 2026-09-09 7:24 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
Hi
Am 08.09.26 um 16:35 schrieb Maxime Ripard:
[...]
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index 0dbf04d4aa9e..f13bb7c490c4 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -303,10 +303,13 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
> break;
> case DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP:
> req->value = drm_core_check_feature(dev, DRIVER_ATOMIC) &&
> dev->mode_config.async_page_flip;
> break;
> + case DRM_CAP_ATOMIC_RESET:
> + req->value = drm_atomic_can_create_state(dev);
> + break;
Looking at this and the other places where _can_create_state is being
used, I'd like to present a different design.
Scratch the helper entirely and introduce a dedicated callback in
drm_mode_config_funcs that sets up the default state. Your current
helper drm_atomic_commit_fill_with_defaults would be the common
implementation. The DRM core could test for the existence of this
callback to see if default-reset is available. Sure, we'd have to modify
all drivers, but it would be architecturally cleaner IMHO and give full
control to the drivers. Best regards Thomas
> default:
> return -EINVAL;
> }
> return 0;
> }
> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> index bc7ef7684099..b6e2f2edd122 100644
> --- a/include/uapi/drm/drm.h
> +++ b/include/uapi/drm/drm.h
> @@ -793,10 +793,20 @@ struct drm_gem_change_handle {
> * If set to 1, the driver supports &DRM_MODE_PAGE_FLIP_ASYNC for atomic
> * commits.
> */
> #define DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP 0x15
>
> +/**
> + * DRM_CAP_ATOMIC_RESET
> + *
> + * If set to 1, the driver supports the &DRM_MODE_ATOMIC_RESET flag in
> + * &DRM_IOCTL_MODE_ATOMIC commits. When supported, userspace can pass that
> + * flag to reset all KMS object states to their defaults before applying
> + * property changes.
> + */
> +#define DRM_CAP_ATOMIC_RESET 0x16
> +
> /* DRM_IOCTL_GET_CAP ioctl argument type */
> struct drm_get_cap {
> __u64 capability;
> __u64 value;
> };
> diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
> index ed1a660a3dfd..32eb3f650d7a 100644
> --- a/include/uapi/drm/drm_mode.h
> +++ b/include/uapi/drm/drm_mode.h
> @@ -1326,10 +1326,21 @@ struct drm_mode_destroy_dumb {
> * To the best of the driver's knowledge, visual artifacts are guaranteed to
> * not appear when this flag is not set. Some sinks might display visual
> * artifacts outside of the driver's control.
> */
> #define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
> +/**
> + * DRM_MODE_ATOMIC_RESET
> + *
> + * Reset all KMS object states (CRTCs, planes, connectors, color operations)
> + * to their default values before applying the properties in this commit.
> + * Properties not explicitly included in the commit will remain at their
> + * defaults (CRTCs inactive, planes disabled, connectors unbound, etc.).
> + *
> + * This flag cannot be combined with &DRM_MODE_PAGE_FLIP_ASYNC.
> + */
> +#define DRM_MODE_ATOMIC_RESET 0x0800
>
> /**
> * DRM_MODE_ATOMIC_FLAGS
> *
> * Bitfield of flags accepted by the &DRM_IOCTL_MODE_ATOMIC IOCTL in
> @@ -1338,11 +1349,12 @@ struct drm_mode_destroy_dumb {
> #define DRM_MODE_ATOMIC_FLAGS (\
> DRM_MODE_PAGE_FLIP_EVENT |\
> DRM_MODE_PAGE_FLIP_ASYNC |\
> DRM_MODE_ATOMIC_TEST_ONLY |\
> DRM_MODE_ATOMIC_NONBLOCK |\
> - DRM_MODE_ATOMIC_ALLOW_MODESET)
> + DRM_MODE_ATOMIC_ALLOW_MODESET |\
> + DRM_MODE_ATOMIC_RESET)
>
> struct drm_mode_atomic {
> __u32 flags;
> __u32 count_objs;
> __u64 objs_ptr;
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag
2026-09-09 7:24 ` Thomas Zimmermann
@ 2026-09-09 8:22 ` Maxime Ripard
0 siblings, 0 replies; 24+ messages in thread
From: Maxime Ripard @ 2026-09-09 8:22 UTC (permalink / raw)
To: Thomas Zimmermann
Cc: Maarten Lankhorst, David Airlie, Simona Vetter, Daniel Stone,
Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2298 bytes --]
Hi Thomas,
Thanks for the review
On Wed, Sep 09, 2026 at 09:24:41AM +0200, Thomas Zimmermann wrote:
> Hi
>
> Am 08.09.26 um 16:35 schrieb Maxime Ripard:
> [...]
> > diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> > index 0dbf04d4aa9e..f13bb7c490c4 100644
> > --- a/drivers/gpu/drm/drm_ioctl.c
> > +++ b/drivers/gpu/drm/drm_ioctl.c
> > @@ -303,10 +303,13 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
> > break;
> > case DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP:
> > req->value = drm_core_check_feature(dev, DRIVER_ATOMIC) &&
> > dev->mode_config.async_page_flip;
> > break;
> > + case DRM_CAP_ATOMIC_RESET:
> > + req->value = drm_atomic_can_create_state(dev);
> > + break;
>
> Looking at this and the other places where _can_create_state is being used,
> I'd like to present a different design.
>
> Scratch the helper entirely and introduce a dedicated callback in
> drm_mode_config_funcs that sets up the default state. Your current helper
> drm_atomic_commit_fill_with_defaults would be the common implementation. The
> DRM core could test for the existence of this callback to see if
> default-reset is available. Sure, we'd have to modify all drivers, but it
> would be architecturally cleaner IMHO and give full control to the drivers.
There's also an interaction with the other big series relying on
atomic_create_state: state read-out.
If you're doing state read-out, you want to if possible create a blank
state, and make the hardware fill it. If not possible, then reset the
hardware and allocate a blank state. Either way, all objects are
affected, and that's what drm_mode_config_create_state() will do there.
In the DRM_MODE_ATOMIC_RESET case, we don't want to create a blank state
for *everything* but only to what's exposed to userspace (ie, everything
but drm_private_obj). In a way, it's more akin to
drm_mode_config_reset(), but without the hardware reset part.
I still feel like two functions are easier to reason about for this, and
I don't think a helper would help: we haven't needed it so far for
drm_mode_config_reset() / drm_atomic_commit_alloc(), so it's not clear
to me what the extra modularity would bring to the table.
Maxime
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 10/11] drm/vkms: Switch container_of helpers to container_of_const
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (8 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 09/11] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
2026-09-08 14:35 ` [PATCH v3 11/11] drm/vkms: Add driver-specific plane property for testing Maxime Ripard
10 siblings, 0 replies; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
The vkms container_of helpers use container_of() which discards the
const qualifier from the input pointer. This prevents passing a const
state pointer to to_vkms_plane_state() without a cast, for instance
in atomic_get_property which receives a const drm_plane_state.
Switch all four helpers to container_of_const() so the const qualifier
is properly propagated to the result type.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/vkms/vkms_drv.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 381483aa4fb0..dea6cad3f1b9 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -248,20 +248,20 @@ struct vkms_device {
/*
* The following helpers are used to convert a member of a struct into its parent.
*/
#define drm_crtc_to_vkms_output(target) \
- container_of(target, struct vkms_output, crtc)
+ container_of_const(target, struct vkms_output, crtc)
#define drm_device_to_vkms_device(target) \
- container_of(target, struct vkms_device, drm)
+ container_of_const(target, struct vkms_device, drm)
#define to_vkms_crtc_state(target)\
- container_of(target, struct vkms_crtc_state, base)
+ container_of_const(target, struct vkms_crtc_state, base)
#define to_vkms_plane_state(target)\
- container_of(target, struct vkms_plane_state, base.base)
+ container_of_const(target, struct vkms_plane_state, base.base)
/**
* vkms_create() - Create a device from a configuration
* @config: Config used to configure the new device
*
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread* [PATCH v3 11/11] drm/vkms: Add driver-specific plane property for testing
2026-09-08 14:35 [PATCH v3 00/11] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
` (9 preceding siblings ...)
2026-09-08 14:35 ` [PATCH v3 10/11] drm/vkms: Switch container_of helpers to container_of_const Maxime Ripard
@ 2026-09-08 14:35 ` Maxime Ripard
10 siblings, 0 replies; 24+ messages in thread
From: Maxime Ripard @ 2026-09-08 14:35 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard
The DRM_MODE_ATOMIC_RESET flag allows userspace to reset all object
states to their defaults before applying new property values. Testing
that this mechanism works correctly requires a property that the test
can set to a non-default value and then verify is properly reset.
Using a standard property for this is problematic: compositors like
Mutter enumerate and track all known properties, making it difficult
to isolate the reset behavior from the compositor's own property
management.
Add a "vkms-test-do-not-use-in-prod" range property to vkms planes.
The property is stored in vkms_plane_state, duplicated across state
copies, and initialized from its registered default in
atomic_create_state via drm_object_property_get_default_value().
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/vkms/vkms_drv.h | 3 ++
drivers/gpu/drm/vkms/vkms_plane.c | 61 +++++++++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index dea6cad3f1b9..384616095b45 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -144,20 +144,23 @@ struct conversion_matrix {
* @base: base plane state
* @frame_info: data required for composing computation
* @pixel_read_line: function to read a pixel line in this plane. The creator of a
* struct vkms_plane_state must ensure that this pointer is valid
* @conversion_matrix: matrix used for yuv formats to convert to rgb
+ * @vkms_test_do_not_use_value: driver-specific property for testing only
*/
struct vkms_plane_state {
struct drm_shadow_plane_state base;
struct vkms_frame_info frame_info;
pixel_read_line_t pixel_read_line;
struct conversion_matrix conversion_matrix;
+ unsigned int vkms_test_do_not_use_value;
};
struct vkms_plane {
struct drm_plane base;
+ struct drm_property *vkms_test_do_not_use_property;
};
struct vkms_color_lut {
struct drm_color_lut *base;
size_t lut_length;
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index fd3d34dcf0fe..0ebc131c2788 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -9,14 +9,18 @@
#include <drm/drm_colorop.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_print.h>
+#include <drm/drm_property.h>
#include "vkms_drv.h"
#include "vkms_formats.h"
+#define to_vkms_plane(target) \
+ container_of_const(target, struct vkms_plane, base)
+
static const u32 vkms_formats[] = {
DRM_FORMAT_ARGB8888,
DRM_FORMAT_ABGR8888,
DRM_FORMAT_BGRA8888,
DRM_FORMAT_RGBA8888,
@@ -52,16 +56,19 @@ static const u32 vkms_formats[] = {
};
static struct drm_plane_state *
vkms_plane_duplicate_state(struct drm_plane *plane)
{
+ struct vkms_plane_state *old_state = to_vkms_plane_state(plane->state);
struct vkms_plane_state *vkms_state;
vkms_state = kzalloc_obj(*vkms_state);
if (!vkms_state)
return NULL;
+ vkms_state->vkms_test_do_not_use_value = old_state->vkms_test_do_not_use_value;
+
__drm_gem_duplicate_shadow_plane_state(plane, &vkms_state->base);
return &vkms_state->base.base;
}
@@ -83,28 +90,69 @@ static void vkms_plane_destroy_state(struct drm_plane *plane,
kfree(vkms_state);
}
static struct drm_plane_state *vkms_plane_create_state(struct drm_plane *plane)
{
+ struct vkms_plane *vkms_plane = to_vkms_plane(plane);
struct vkms_plane_state *vkms_state;
+ u64 val;
vkms_state = kzalloc_obj(*vkms_state);
if (!vkms_state) {
DRM_ERROR("Cannot allocate vkms_plane_state\n");
return ERR_PTR(-ENOMEM);
}
__drm_gem_shadow_plane_state_init(plane, &vkms_state->base);
+ if (!drm_object_property_get_default_value(&plane->base,
+ vkms_plane->vkms_test_do_not_use_property,
+ &val))
+ vkms_state->vkms_test_do_not_use_value = val;
+
return &(&vkms_state->base)->base;
}
+static int vkms_plane_atomic_set_property(struct drm_plane *plane,
+ struct drm_plane_state *state,
+ struct drm_property *property,
+ uint64_t val)
+{
+ struct vkms_plane *vkms_plane = to_vkms_plane(plane);
+ struct vkms_plane_state *vkms_state = to_vkms_plane_state(state);
+
+ if (property == vkms_plane->vkms_test_do_not_use_property) {
+ vkms_state->vkms_test_do_not_use_value = val;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static int vkms_plane_atomic_get_property(struct drm_plane *plane,
+ const struct drm_plane_state *state,
+ struct drm_property *property,
+ uint64_t *val)
+{
+ const struct vkms_plane_state *vkms_state = to_vkms_plane_state(state);
+ const struct vkms_plane *vkms_plane = to_vkms_plane(plane);
+
+ if (property == vkms_plane->vkms_test_do_not_use_property) {
+ *val = vkms_state->vkms_test_do_not_use_value;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
static const struct drm_plane_funcs vkms_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
- .atomic_create_state = vkms_plane_create_state,
- .atomic_duplicate_state = vkms_plane_duplicate_state,
+ .atomic_set_property = vkms_plane_atomic_set_property,
+ .atomic_get_property = vkms_plane_atomic_get_property,
+ .atomic_create_state = vkms_plane_create_state,
+ .atomic_duplicate_state = vkms_plane_duplicate_state,
.atomic_destroy_state = vkms_plane_destroy_state,
};
static void vkms_plane_atomic_update(struct drm_plane *plane,
struct drm_atomic_commit *state)
@@ -281,10 +329,19 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
BIT(DRM_COLOR_YCBCR_FULL_RANGE),
DRM_COLOR_YCBCR_BT601,
DRM_COLOR_YCBCR_FULL_RANGE);
+ plane->vkms_test_do_not_use_property =
+ drm_property_create_range(dev, 0,
+ "vkms-test-do-not-use-in-prod",
+ 0, U32_MAX);
+ if (plane->vkms_test_do_not_use_property)
+ drm_object_attach_property(&plane->base.base,
+ plane->vkms_test_do_not_use_property,
+ 0);
+
if (vkms_config_plane_get_default_pipeline(plane_cfg))
vkms_initialize_colorops(&plane->base);
return plane;
}
--
2.55.0
^ permalink raw reply [flat|nested] 24+ messages in thread