Now that we have a reset callback for drm_private_objs, we can provide a
helper for it.

It's somewhat different from the other similar helpers though, because
we definitely expect drm_private_obj to be subclassed. It wouldn't make
sense for a driver to use it as-is.

So we can't provide a straight implementation of the reset callback, but
rather we provide the parts that will deal with the drm_private_obj
initialization, and we will leave the allocation and initialization of
the subclass to drivers.

Signed-off-by: Maxime Ripard <[email protected]>
---
 drivers/gpu/drm/drm_atomic_state_helper.c | 24 ++++++++++++++++++++++++
 include/drm/drm_atomic_state_helper.h     |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c 
b/drivers/gpu/drm/drm_atomic_state_helper.c
index 
7142e163e618ea0d7d9d828e1bd9ff2a6ec0dfeb..f88007fe8dba2e79d5942deec3cfdd7757c1a460
 100644
--- a/drivers/gpu/drm/drm_atomic_state_helper.c
+++ b/drivers/gpu/drm/drm_atomic_state_helper.c
@@ -707,10 +707,34 @@ void drm_atomic_helper_connector_destroy_state(struct 
drm_connector *connector,
        __drm_atomic_helper_connector_destroy_state(state);
        kfree(state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
 
+/**
+ * __drm_atomic_helper_private_obj_reset - reset state on private objects
+ * @obj: private object
+ * @state: new state to initialize
+ *
+ * Initializes the newly allocated @state and assigns it to the
+ * &drm_private_obj->state pointer of @obj, usually required when
+ * initializing the drivers or when called from the
+ * &drm_private_state_funcs.reset hook.
+ *
+ * @obj is assumed to be zeroed.
+ *
+ * This is useful for drivers that use private states.
+ */
+void __drm_atomic_helper_private_obj_reset(struct drm_private_obj *obj,
+                                          struct drm_private_state *state)
+{
+       if (state)
+               state->obj = obj;
+
+       obj->state = state;
+}
+EXPORT_SYMBOL(__drm_atomic_helper_private_obj_reset);
+
 /**
  * __drm_atomic_helper_private_obj_duplicate_state - copy atomic private state
  * @obj: CRTC object
  * @state: new private object state
  *
diff --git a/include/drm/drm_atomic_state_helper.h 
b/include/drm/drm_atomic_state_helper.h
index 
b9740edb26586d58f99a5223902bb8e333ac75a2..150ea227c595eab8c45b106baf09ce5b27a89a5a
 100644
--- a/include/drm/drm_atomic_state_helper.h
+++ b/include/drm/drm_atomic_state_helper.h
@@ -82,10 +82,13 @@ struct drm_connector_state *
 drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);
 void
 __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state);
 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
                                          struct drm_connector_state *state);
+
+void __drm_atomic_helper_private_obj_reset(struct drm_private_obj *obj,
+                                          struct drm_private_state *state);
 void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj 
*obj,
                                                     struct drm_private_state 
*state);
 
 void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge,
                                                struct drm_bridge_state *state);

-- 
2.51.0

Reply via email to