dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>,
	 Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, Maxime Ripard <mripard@kernel.org>
Subject: [PATCH 02/16] drm/atomic: Add reset to drm_private_obj
Date: Wed, 08 Oct 2025 14:04:00 +0200	[thread overview]
Message-ID: <20251008-drm-private-obj-reset-v1-2-805ab43ae65a@kernel.org> (raw)
In-Reply-To: <20251008-drm-private-obj-reset-v1-0-805ab43ae65a@kernel.org>

The drm_private_obj initialization was inconsistent with the rest of the
KMS objects. Indeed, it required to pass a preallocated state in
drm_private_obj_init(), while all the others objects would have a reset
callback that would be called later on to create the state.

Let's prepare for the migration of all private objs implementation by
introducing a reset callback in drm_private_state_funcs, and by calling
it if the passed state is NULL.

The latter will be removed eventually, once every driver has been
converted.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/drm_atomic.c | 15 +++++++++++++--
 include/drm/drm_atomic.h     |  9 +++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 39cb1479ac4d58cd71cf41d27d0d2a8a58ef5791..45c26294e712fd36b43e87548072c3c0e9af1887 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -791,15 +791,26 @@ drm_atomic_private_obj_init(struct drm_device *dev,
 	memset(obj, 0, sizeof(*obj));
 
 	drm_modeset_lock_init(&obj->lock);
 
 	obj->dev = dev;
-	obj->state = state;
 	obj->funcs = funcs;
 	list_add_tail(&obj->head, &dev->mode_config.privobj_list);
 
-	state->obj = obj;
+	/*
+	 * Not all users of drm_atomic_private_obj_init have been
+	 * converted to using &drm_private_obj_funcs.reset yet. For the
+	 * time being, let's only call reset if the passed state is
+	 * NULL. Otherwise, we will fallback to the previous behaviour.
+	 */
+	if (!state) {
+		if (obj->funcs->reset)
+			obj->funcs->reset(obj);
+	} else {
+		obj->state = state;
+		state->obj = obj;
+	}
 }
 EXPORT_SYMBOL(drm_atomic_private_obj_init);
 
 /**
  * drm_atomic_private_obj_fini - finalize private object
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index dac70f685361d8d29844acd1b0cc2f04f43a9499..fbac6d4c75fc86535cf153745b6132f8705c808a 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -205,10 +205,19 @@ struct drm_private_state;
  * added to the atomic states is expected to have an implementation of these
  * hooks and pass a pointer to its drm_private_state_funcs struct to
  * drm_atomic_get_private_obj_state().
  */
 struct drm_private_state_funcs {
+	/**
+	 * @reset:
+	 *
+	 * Resets the private state to its default state, and the
+	 * hardware to off if any.. This function isn't called by the
+	 * core directly, only through drm_mode_config_reset().
+	 */
+	void (*reset)(struct drm_private_obj *obj);
+
 	/**
 	 * @atomic_duplicate_state:
 	 *
 	 * Duplicate the current state of the private object and return it. It
 	 * is an error to call this before obj->state has been initialized.

-- 
2.51.0


  parent reply	other threads:[~2025-10-08 12:04 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 12:03 [PATCH 00/16] drm/atomic: Switch drm_private_obj to reset Maxime Ripard
2025-10-08 12:03 ` [PATCH 01/16] drm/atomic: Add dev pointer to drm_private_obj Maxime Ripard
2025-10-08 13:21   ` Tomi Valkeinen
2025-10-08 15:48   ` Dmitry Baryshkov
2025-10-08 12:04 ` Maxime Ripard [this message]
2025-10-08 13:24   ` [PATCH 02/16] drm/atomic: Add reset " Tomi Valkeinen
2025-10-08 12:04 ` [PATCH 03/16] drm/atomic-helper: Add private_obj reset helper Maxime Ripard
2025-10-08 13:27   ` Tomi Valkeinen
2025-10-08 18:35   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 04/16] drm/bridge: Switch private_obj initialization to reset Maxime Ripard
2025-10-08 18:40   ` Dmitry Baryshkov
2025-10-10  9:47   ` kernel test robot
2025-10-08 12:04 ` [PATCH 05/16] drm/dp_mst: " Maxime Ripard
2025-10-08 14:06   ` Ville Syrjälä
2025-10-08 14:53     ` Maxime Ripard
2025-10-08 16:12       ` Ville Syrjälä
2025-10-09 14:42         ` Maxime Ripard
2025-10-09 16:03           ` Ville Syrjälä
2025-10-08 16:24     ` Imre Deak
2025-10-14 22:35       ` Dmitry Baryshkov
2025-10-16  6:36         ` Imre Deak
2025-10-08 12:04 ` [PATCH 06/16] drm/dp_tunnel: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 07/16] drm/amdgpu: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 08/16] drm/arm: komeda: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 09/16] drm/ingenic: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 10/16] drm/msm: mdp5: " Maxime Ripard
2025-10-08 18:48   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 11/16] drm/msm: dpu1: " Maxime Ripard
2025-10-08 18:47   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 12/16] drm/omapdrm: " Maxime Ripard
2025-10-08 13:29   ` Tomi Valkeinen
2025-10-08 12:04 ` [PATCH 13/16] drm/tegra: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 14/16] drm/vc4: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 15/16] drm/atomic: Remove state argument to drm_atomic_private_obj_init Maxime Ripard
2025-10-08 13:30   ` Tomi Valkeinen
2025-10-08 18:50   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 16/16] drm/mode_config: Call private obj reset with the other objects Maxime Ripard
2025-10-08 18:52   ` Dmitry Baryshkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251008-drm-private-obj-reset-v1-2-805ab43ae65a@kernel.org \
    --to=mripard@kernel.org \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).