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 <[email protected]>
---
 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

Reply via email to