Skip to contentSkip to conversation

drm/atomic: Rework initial state allocation

PATCH Superseded Maxime Ripard 4 participants 49 messages Mar 20 – Apr 24

Subsystems (10)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Maxime Ripard

author maintainer
#0 lore raw

v2 cover drm/atomic: Rework initial state allocation

Hi,

This series started from my work on the hardware state readout[1], and more specifically a discussion with Thomas[2].

This series expands the work that has been merged recently to make drm_private_obj and drm_private_state allocation a bit more consistent and ended up creating a new atomic_create_state callback to allocate a new state with no side effect.

The first patches are a documentation of the existing behaviour and some random cleanups.

Then, we add the new atomic_create_state callback to every other DRM object. Next, we leverage those new callbacks to create a new helper, drm_mode_config_create_state() to create the initial state for all the objects of a driver.

Finally, we hook that new helper in drm_dev_register and start converting a few drivers.

This was tested on a TI SK-AM62, with the tidss driver.

Let me know what you think,
Maxime

1: https://lore.kernel.org/dri-devel/[email protected]/
2: https://lore.kernel.org/dri-devel/[email protected]/

---
Changes in v2:
- Change the _state_reset function names to _state_init
- Change the colorop too
- Various doc improvements
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Maxime Ripard (20):
drm/colorop: Fix typos in the doc
drm/atomic: Drop drm_private_state.obj assignment from create_state drm/mode-config: Mention drm_mode_config_reset() culprits drm/colorop: Rename __drm_colorop_state_reset()
drm/colorop: Create drm_atomic_helper_colorop_create_state() drm/atomic-state-helper: Fix __drm_atomic_helper_plane_reset() doc typo drm/atomic-state-helper: Rename __drm_atomic_helper_plane_state_reset() drm/plane: Add new atomic_create_state callback drm/atomic-state-helper: Rename __drm_atomic_helper_crtc_state_reset() drm/crtc: Add new atomic_create_state callback drm/atomic-state-helper: Rename __drm_atomic_helper_connector_state_reset() drm/hdmi: Rename __drm_atomic_helper_connector_hdmi_reset() drm/connector: Add new atomic_create_state callback drm/mode-config: Create drm_mode_config_create_state() drm/drv: Call drm_mode_config_create_state() by default drm/atomic: Drop private obj state allocation
drm/drv: Drop drm_mode_config_reset() from our skeleton drm/tidss: Drop call to drm_mode_config_reset at probe time drm/tidss: Convert to atomic_create_state drm/bridge_connector: Convert to atomic_create_state

 drivers/gpu/drm/display/drm_bridge_connector.c     |  17 ++-
 drivers/gpu/drm/display/drm_hdmi_state_helper.c    |  14 +-
 drivers/gpu/drm/drm_atomic.c                       |  19 +--
 drivers/gpu/drm/drm_atomic_state_helper.c          | 170 ++++++++++++++++++---
 drivers/gpu/drm/drm_colorop.c                      |  41 +++--
 drivers/gpu/drm/drm_drv.c                          |   6 +-
 drivers/gpu/drm/drm_mode_config.c                  | 154 ++++++++++++++++++-
 drivers/gpu/drm/i915/display/intel_crtc.c          |   2 +-
 drivers/gpu/drm/i915/display/intel_plane.c         |   2 +-
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c             |   2 +-
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c |   2 +-
 drivers/gpu/drm/tidss/tidss_crtc.c                 |  17 +--
 drivers/gpu/drm/tidss/tidss_drv.c                  |   2 -
 drivers/gpu/drm/tidss/tidss_kms.c                  |   2 -
 drivers/gpu/drm/tidss/tidss_plane.c                |   2 +-
 drivers/gpu/drm/vc4/vc4_hdmi.c                     |   2 +-
 include/drm/display/drm_hdmi_state_helper.h        |   4 +-
 include/drm/drm_atomic_state_helper.h              |  18 ++-
 include/drm/drm_colorop.h                          |   2 +
 include/drm/drm_connector.h                        |  13 ++
 include/drm/drm_crtc.h                             |  13 ++
 include/drm/drm_mode_config.h                      |   1 +
 include/drm/drm_plane.h                            |  13 ++
 23 files changed, 441 insertions(+), 77 deletions(-)

---
base-commit: cd5c40f745f10f082f75520ebc9deae3ea37b185
change-id: 20260310-drm-mode-config-init-1e1f52b745d0
prerequisite-change-id: 20251008-drm-private-obj-reset-ae1e2741027a:v5
prerequisite-patch-id: 9684f0ca4b16455c1340409561e8fb32f98b327a
prerequisite-patch-id: e177eb92b269436a94d7ef603d44436799be7469
prerequisite-patch-id: fef6d20ab33358c1db6cd9d21aa8ec0990cae758
prerequisite-patch-id: 2dcc96d43f34d8f6237829ed29d0087c092954d1

Best regards,

Signature · 1 line
Maxime Ripard <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/20 drm/colorop: Fix typos in the doc

In the documentation of drm_colorop introduced by commit cfc27680ee20 ("drm/colorop: Introduce new drm_colorop mode object"), the documentation of __drm_colorop_state_reset() and __drm_colorop_reset() were mentioning CRTC when they really meant colorop, probably due to copy and paste.

Fixes cfc27680ee20 ("drm/colorop: Introduce new drm_colorop mode object")
---
 drivers/gpu/drm/drm_colorop.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_colorop.c +5 -5
index 566816e3c6f0c7d172534966fcfe56982e6505f3..373cd0ddb8fd4478874509ed12c95451c1f66203 100644
@@ -503,11 +503,11 @@ void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
  * __drm_colorop_state_reset - resets colorop state to default values
  * @colorop_state: atomic colorop state, must not be NULL
  * @colorop: colorop object, must not be NULL
  *
  * Initializes the newly allocated @colorop_state with default
- * values. This is useful for drivers that subclass the CRTC state.
+ * values. This is useful for drivers that subclass the colorop state.
  */
 static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
 				      struct drm_colorop *colorop)
 {
 	u64 val;
@@ -526,14 +526,14 @@ static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
 /**
  * __drm_colorop_reset - reset state on colorop
  * @colorop: drm colorop
  * @colorop_state: colorop state to assign
  *
- * Initializes the newly allocated @colorop_state and assigns it to
- * the &drm_crtc->state pointer of @colorop, usually required when
- * initializing the drivers or when called from the &drm_colorop_funcs.reset
- * hook.
+ * Initializes the newly allocated @colorop_state and assigns it to the
+ * &drm_colorop->state pointer of @colorop, usually required when
+ * initializing the drivers or when called from the
+ * &drm_colorop_funcs.reset hook.
  *
  * This is useful for drivers that subclass the colorop state.
  */
 static void __drm_colorop_reset(struct drm_colorop *colorop,
 				struct drm_colorop_state *colorop_state)
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 1/20
#2 lore raw

Re: [PATCH v2 01/20] drm/colorop: Fix typos in the doc

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 8 lines

In the documentation of drm_colorop introduced by commit cfc27680ee20 ("drm/colorop: Introduce new drm_colorop mode object"), the documentation of __drm_colorop_state_reset() and __drm_colorop_reset() were mentioning CRTC when they really meant colorop, probably due to copy and paste.

Fixes cfc27680ee20 ("drm/colorop: Introduce new drm_colorop mode object")
Quoted 41 lines
---
  drivers/gpu/drm/drm_colorop.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_colorop.c +5 -5
index 566816e3c6f0c7d172534966fcfe56982e6505f3..373cd0ddb8fd4478874509ed12c95451c1f66203 100644
@@ -503,11 +503,11 @@ void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
   * __drm_colorop_state_reset - resets colorop state to default values
   * @colorop_state: atomic colorop state, must not be NULL
   * @colorop: colorop object, must not be NULL
   *
   * Initializes the newly allocated @colorop_state with default
- * values. This is useful for drivers that subclass the CRTC state.
+ * values. This is useful for drivers that subclass the colorop state.
   */
  static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
  				      struct drm_colorop *colorop)
  {
  	u64 val;
@@ -526,14 +526,14 @@ static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
  /**
   * __drm_colorop_reset - reset state on colorop
   * @colorop: drm colorop
   * @colorop_state: colorop state to assign
   *
- * Initializes the newly allocated @colorop_state and assigns it to
- * the &drm_crtc->state pointer of @colorop, usually required when
- * initializing the drivers or when called from the &drm_colorop_funcs.reset
- * hook.
+ * Initializes the newly allocated @colorop_state and assigns it to the
+ * &drm_colorop->state pointer of @colorop, usually required when
+ * initializing the drivers or when called from the
+ * &drm_colorop_funcs.reset hook.
   *
   * This is useful for drivers that subclass the colorop state.
   */
  static void __drm_colorop_reset(struct drm_colorop *colorop,
  				struct drm_colorop_state *colorop_state)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#3 lore raw

PATCH v2 2/20 drm/atomic: Drop drm_private_state.obj assignment from create_state

In reply to Maxime Ripard

The initial intent of the atomic_create_state helper was to simply allocate a proper drm_private_state and returning it, without any side effect.

However, the __drm_atomic_helper_private_obj_create_state() introduces a side effect by setting the drm_private_obj.state to the newly allocated state.

This assignment defeats the purpose, but is also redundant since the only caller, drm_atomic_private_obj_init(), will also set this pointer to the newly allocated state.

Let's drop the assignment in __drm_atomic_helper_private_obj_create_state().

Fixes e7be39ed1716 ("drm/atomic-helper: Add private_obj atomic_create_state helper")
---
 drivers/gpu/drm/drm_atomic_state_helper.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_atomic_state_helper.c +0 -2
index 76746ad4a1bbb7142c067c93dd05fbec5d2f98eb..875149494b00e1eb7481e87d7d7038103b72b7e3 100644
@@ -729,12 +729,10 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
 void __drm_atomic_helper_private_obj_create_state(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_create_state);
 
 /**
  * __drm_atomic_helper_private_obj_duplicate_state - copy atomic private state
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH v2 02/20] drm/atomic: Drop drm_private_state.obj assignment from create_state

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 11 lines

The initial intent of the atomic_create_state helper was to simply allocate a proper drm_private_state and returning it, without any side effect.

However, the __drm_atomic_helper_private_obj_create_state() introduces a side effect by setting the drm_private_obj.state to the newly allocated state.

This assignment defeats the purpose, but is also redundant since the only caller, drm_atomic_private_obj_init(), will also set this pointer to the newly allocated state.

Is this paragraph no longer up to date? Grepping for __drm_atomic_helper_private_obj_create_state returns plenty of callers. Best regards Thomas

Quoted 27 lines

Let's drop the assignment in __drm_atomic_helper_private_obj_create_state().

Fixes e7be39ed1716 ("drm/atomic-helper: Add private_obj atomic_create_state helper")
---
  drivers/gpu/drm/drm_atomic_state_helper.c | 2 --
  1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_atomic_state_helper.c +0 -2
index 76746ad4a1bbb7142c067c93dd05fbec5d2f98eb..875149494b00e1eb7481e87d7d7038103b72b7e3 100644
@@ -729,12 +729,10 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
  void __drm_atomic_helper_private_obj_create_state(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_create_state);
 
  /**
   * __drm_atomic_helper_private_obj_duplicate_state - copy atomic private state
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#5 lore raw

Re: [PATCH v2 02/20] drm/atomic: Drop drm_private_state.obj assignment from create_state

Quoted 11 lines · Thomas Zimmermann

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 8 lines

The initial intent of the atomic_create_state helper was to simply allocate a proper drm_private_state and returning it, without any side effect.

However, the __drm_atomic_helper_private_obj_create_state() introduces a side effect by setting the drm_private_obj.state to the newly allocated state.

Quoted 6 lines
Quoted 3 lines

This assignment defeats the purpose, but is also redundant since the only caller, drm_atomic_private_obj_init(), will also set this pointer to the newly allocated state.

Is this paragraph no longer up to date? Grepping for __drm_atomic_helper_private_obj_create_state returns plenty of callers.

No, it's still up to date but super confusing. I didn't mean that there wase one single caller of __drm_atomic_helper_private_obj_create_state() that would set obj->state, but rather that the drm_private_state_funcs.atomic_create_state hook is called only by drm_atomic_private_obj_init() and it will set obj->state.

So, you're right, there's plenty of drivers calling __drm_atomic_helper_private_obj_create_state() but we always end up there through drm_atomic_private_obj_init().

Maxime

author maintainer
#6 lore raw

PATCH v2 3/20 drm/mode-config: Mention drm_mode_config_reset() culprits

In reply to Maxime Ripard

drm_mode_config_reset() does not reset drm_private_states by design.

This is especially significant for the DP MST and tunneling code that expect to be preserved across a suspend/resume cycle, where drm_mode_config_reset() is also used.

Let's document this expectation.

---
 drivers/gpu/drm/drm_mode_config.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_mode_config.c +4 -0
index 66f7dc37b5970c0a08f8dde008aef56376c59f37..cba527571ca66d3aa6dc652c87e03a19815d1d41 100644
@@ -187,10 +187,14 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
  * @dev: drm device
  *
  * This functions calls all the crtc's, encoder's and connector's ->reset
  * callback. Drivers can use this in e.g. their driver load or resume code to
  * reset hardware and software state.
+ *
+ * Note that @drm_private_obj structures are expected to be stable across
+ * suspend/resume cycles, and @drm_mode_config_reset() does not affect these
+ * structures.
  */
 void drm_mode_config_reset(struct drm_device *dev)
 {
 	struct drm_crtc *crtc;
 	struct drm_colorop *colorop;
Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH v2 03/20] drm/mode-config: Mention drm_mode_config_reset() culprits

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 5 lines

drm_mode_config_reset() does not reset drm_private_states by design.

This is especially significant for the DP MST and tunneling code that expect to be preserved across a suspend/resume cycle, where drm_mode_config_reset() is also used.

Do we really? There's drm_mode_config_helper_suspend/resume(). Why would drivers do a drm_mode_config_reset().

Best regards
Thomas

Quoted 30 lines

Let's document this expectation.

---
  drivers/gpu/drm/drm_mode_config.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_mode_config.c +4 -0
index 66f7dc37b5970c0a08f8dde008aef56376c59f37..cba527571ca66d3aa6dc652c87e03a19815d1d41 100644
@@ -187,10 +187,14 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
   * @dev: drm device
   *
   * This functions calls all the crtc's, encoder's and connector's ->reset
   * callback. Drivers can use this in e.g. their driver load or resume code to
   * reset hardware and software state.
+ *
+ * Note that @drm_private_obj structures are expected to be stable across
+ * suspend/resume cycles, and @drm_mode_config_reset() does not affect these
+ * structures.
   */
  void drm_mode_config_reset(struct drm_device *dev)
  {
  	struct drm_crtc *crtc;
  	struct drm_colorop *colorop;
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#8 lore raw

Re: [PATCH v2 03/20] drm/mode-config: Mention drm_mode_config_reset() culprits

Hi Thomas,

Quoted 11 lines · Thomas Zimmermann

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 5 lines

drm_mode_config_reset() does not reset drm_private_states by design.

This is especially significant for the DP MST and tunneling code that expect to be preserved across a suspend/resume cycle, where drm_mode_config_reset() is also used.

Do we really? There's drm_mode_config_helper_suspend/resume(). Why would drivers do a drm_mode_config_reset().

drm_mode_config_helper_resume() will call drm_atomic_helper_resume() that call drm_mode_config_reset(). So (most) drivers will not directly call it, but it is going to be called still.

Maxime

#9 lore raw

Re: [PATCH v2 03/20] drm/mode-config: Mention drm_mode_config_reset() culprits

Hi

Am 21.04.26 um 15:18 schrieb Maxime Ripard:

Quoted 8 lines

Hi Thomas,

Quoted 5 lines · Thomas Zimmermann

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 2 lines

drm_mode_config_reset() does not reset drm_private_states by design.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

This is especially significant for the DP MST and tunneling code that expect to be preserved across a suspend/resume cycle, where drm_mode_config_reset() is also used.

Do we really? There's drm_mode_config_helper_suspend/resume(). Why would drivers do a drm_mode_config_reset().

drm_mode_config_helper_resume() will call drm_atomic_helper_resume() that call drm_mode_config_reset(). So (most) drivers will not directly call it, but it is going to be called still.

I see, thanks. I guess you're right when you say that drm_mode_config_reset() is overloaded. LOL.

Best regards
Thomas

Quoted 2 lines

Maxime

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#10 lore raw

PATCH v2 4/20 drm/colorop: Rename __drm_colorop_state_reset()

In reply to Maxime Ripard

__drm_colorop_state_reset() is used to initialize a newly allocated drm_colorop_state, and is being typically called by drm_colorop_reset().

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_colorop_state instance, we will need to call __drm_colorop_state_reset() from both the reset and atomic_create paths.

To avoid any confusion, we can thus rename __drm_colorop_state_reset() to __drm_colorop_state_init().

---
 drivers/gpu/drm/drm_colorop.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_colorop.c +4 -4
index 373cd0ddb8fd4478874509ed12c95451c1f66203..6a26b83b260e8d8e83c703ecde490a7a8740ebfb 100644
@@ -498,19 +498,19 @@ void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
 	__drm_atomic_helper_colorop_destroy_state(state);
 	kfree(state);
 }
 
 /**
- * __drm_colorop_state_reset - resets colorop state to default values
+ * __drm_colorop_state_init - Initializes colorop state to default values
  * @colorop_state: atomic colorop state, must not be NULL
  * @colorop: colorop object, must not be NULL
  *
  * Initializes the newly allocated @colorop_state with default
  * values. This is useful for drivers that subclass the colorop state.
  */
-static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
-				      struct drm_colorop *colorop)
+static void __drm_colorop_state_init(struct drm_colorop_state *colorop_state,
+				     struct drm_colorop *colorop)
 {
 	u64 val;
 
 	colorop_state->colorop = colorop;
 	colorop_state->bypass = true;
@@ -537,11 +537,11 @@ static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
  */
 static void __drm_colorop_reset(struct drm_colorop *colorop,
 				struct drm_colorop_state *colorop_state)
 {
 	if (colorop_state)
-		__drm_colorop_state_reset(colorop_state, colorop);
+		__drm_colorop_state_init(colorop_state, colorop);
 
 	colorop->state = colorop_state;
 }
 
 void drm_colorop_reset(struct drm_colorop *colorop)
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 4/20
#11 lore raw

Re: [PATCH v2 04/20] drm/colorop: Rename __drm_colorop_state_reset()

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 8 lines

__drm_colorop_state_reset() is used to initialize a newly allocated drm_colorop_state, and is being typically called by drm_colorop_reset().

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_colorop_state instance, we will need to call __drm_colorop_state_reset() from both the reset and atomic_create paths.

Quoted 4 lines

To avoid any confusion, we can thus rename __drm_colorop_state_reset() to __drm_colorop_state_init().

This makes sense considering the next patch

Quoted 45 lines
---
  drivers/gpu/drm/drm_colorop.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_colorop.c +4 -4
index 373cd0ddb8fd4478874509ed12c95451c1f66203..6a26b83b260e8d8e83c703ecde490a7a8740ebfb 100644
@@ -498,19 +498,19 @@ void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
  	__drm_atomic_helper_colorop_destroy_state(state);
  	kfree(state);
  }
 
  /**
- * __drm_colorop_state_reset - resets colorop state to default values
+ * __drm_colorop_state_init - Initializes colorop state to default values
   * @colorop_state: atomic colorop state, must not be NULL
   * @colorop: colorop object, must not be NULL
   *
   * Initializes the newly allocated @colorop_state with default
   * values. This is useful for drivers that subclass the colorop state.
   */
-static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
-				      struct drm_colorop *colorop)
+static void __drm_colorop_state_init(struct drm_colorop_state *colorop_state,
+				     struct drm_colorop *colorop)
  {
  	u64 val;
 
  	colorop_state->colorop = colorop;
  	colorop_state->bypass = true;
@@ -537,11 +537,11 @@ static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
   */
  static void __drm_colorop_reset(struct drm_colorop *colorop,
  				struct drm_colorop_state *colorop_state)
  {
  	if (colorop_state)
-		__drm_colorop_state_reset(colorop_state, colorop);
+		__drm_colorop_state_init(colorop_state, colorop);
 
  	colorop->state = colorop_state;
  }
 
  void drm_colorop_reset(struct drm_colorop *colorop)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#12 lore raw

PATCH v2 5/20 drm/colorop: Create drm_atomic_helper_colorop_create_state()

In reply to Maxime Ripard

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software state, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

It's also only relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect: atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with drm_colorop.

---
 drivers/gpu/drm/drm_colorop.c | 23 +++++++++++++++++++++++
 include/drm/drm_colorop.h     |  2 ++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/drm_colorop.c +23 -0
index 6a26b83b260e8d8e83c703ecde490a7a8740ebfb..7bfaf2617ec315f42d80ac72a5eaaef868e65657 100644
@@ -521,10 +521,33 @@ static void __drm_colorop_state_init(struct drm_colorop_state *colorop_state,
 						      &val);
 		colorop_state->curve_1d_type = val;
 	}
 }
 
+/**
+ * drm_atomic_helper_colorop_create_state - Allocates and initializes colorop atomic state
+ * @colorop: drm colorop
+ *
+ * Initializes a pristine @drm_colorop_state.
+ *
+ * RETURNS:
+ * Pointer to new colorop state, or ERR_PTR on failure.
+ */
+struct drm_colorop_state *
+drm_atomic_helper_colorop_create_state(struct drm_colorop *colorop)
+{
+	struct drm_colorop_state *state;
+
+	state = kzalloc_obj(*state);
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	__drm_colorop_state_init(state, colorop);
+
+	return state;
+}
+
 /**
  * __drm_colorop_reset - reset state on colorop
  * @colorop: drm colorop
  * @colorop_state: colorop state to assign
  *
include/drm/drm_colorop.h +2 -0
index bd082854ca74cac90b42020b09206a8516687666..874ed693329c0ecf94567c094744fe86fd08e382 100644
@@ -423,10 +423,12 @@ int drm_plane_colorop_3dlut_init(struct drm_device *dev, struct drm_colorop *col
 				 struct drm_plane *plane, const struct drm_colorop_funcs *funcs,
 				 uint32_t lut_size,
 				 enum drm_colorop_lut3d_interpolation_type interpolation,
 				 uint32_t flags);
 
+struct drm_colorop_state *
+drm_atomic_helper_colorop_create_state(struct drm_colorop *colorop);
 struct drm_colorop_state *
 drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colorop);
 
 void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
 				      struct drm_colorop_state *state);
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 5/20
#13 lore raw

Re: [PATCH v2 05/20] drm/colorop: Create drm_atomic_helper_colorop_create_state()

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 30 lines

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software state, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

It's also only relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect: atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Quoted 3 lines

Let's continue the transition to the new pattern with drm_colorop.

Quoted 61 lines
---
  drivers/gpu/drm/drm_colorop.c | 23 +++++++++++++++++++++++
  include/drm/drm_colorop.h     |  2 ++
  2 files changed, 25 insertions(+)
drivers/gpu/drm/drm_colorop.c +23 -0
index 6a26b83b260e8d8e83c703ecde490a7a8740ebfb..7bfaf2617ec315f42d80ac72a5eaaef868e65657 100644
@@ -521,10 +521,33 @@ static void __drm_colorop_state_init(struct drm_colorop_state *colorop_state,
  						      &val);
  		colorop_state->curve_1d_type = val;
  	}
  }
 
+/**
+ * drm_atomic_helper_colorop_create_state - Allocates and initializes colorop atomic state
+ * @colorop: drm colorop
+ *
+ * Initializes a pristine @drm_colorop_state.
+ *
+ * RETURNS:
+ * Pointer to new colorop state, or ERR_PTR on failure.
+ */
+struct drm_colorop_state *
+drm_atomic_helper_colorop_create_state(struct drm_colorop *colorop)
+{
+	struct drm_colorop_state *state;
+
+	state = kzalloc_obj(*state);
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	__drm_colorop_state_init(state, colorop);
+
+	return state;
+}
+
  /**
   * __drm_colorop_reset - reset state on colorop
   * @colorop: drm colorop
   * @colorop_state: colorop state to assign
   *
include/drm/drm_colorop.h +2 -0
index bd082854ca74cac90b42020b09206a8516687666..874ed693329c0ecf94567c094744fe86fd08e382 100644
@@ -423,10 +423,12 @@ int drm_plane_colorop_3dlut_init(struct drm_device *dev, struct drm_colorop *col
  				 struct drm_plane *plane, const struct drm_colorop_funcs *funcs,
  				 uint32_t lut_size,
  				 enum drm_colorop_lut3d_interpolation_type interpolation,
  				 uint32_t flags);
 
+struct drm_colorop_state *
+drm_atomic_helper_colorop_create_state(struct drm_colorop *colorop);
  struct drm_colorop_state *
  drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colorop);
 
  void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
  				      struct drm_colorop_state *state);
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#14 lore raw

PATCH v2 6/20 drm/atomic-state-helper: Fix __drm_atomic_helper_plane_reset() doc typo

In reply to Maxime Ripard

A typo has slipped through in the __drm_atomic_helper_plane_reset() documentation, probably due to copy and paste. It will not assign drm_crtc state pointer, but rather the drm_plane's.

---
 drivers/gpu/drm/drm_atomic_state_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +1 -1
index 875149494b00e1eb7481e87d7d7038103b72b7e3..e1f3d05ad3470154a6be01423979a4deb8617441 100644
@@ -303,11 +303,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
  * __drm_atomic_helper_plane_reset - reset state on plane
  * @plane: drm plane
  * @plane_state: plane state to assign
  *
  * Initializes the newly allocated @plane_state and assigns it to
- * the &drm_crtc->state pointer of @plane, usually required when
+ * the &drm_plane->state pointer of @plane, usually required when
  * initializing the drivers or when called from the &drm_plane_funcs.reset
  * hook.
  *
  * This is useful for drivers that subclass the plane state.
  */
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 6/20
#15 lore raw

Re: [PATCH v2 06/20] drm/atomic-state-helper: Fix __drm_atomic_helper_plane_reset() doc typo

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 7 lines

A typo has slipped through in the __drm_atomic_helper_plane_reset() documentation, probably due to copy and paste. It will not assign drm_crtc state pointer, but rather the drm_plane's.

Quoted 22 lines
---
  drivers/gpu/drm/drm_atomic_state_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +1 -1
index 875149494b00e1eb7481e87d7d7038103b72b7e3..e1f3d05ad3470154a6be01423979a4deb8617441 100644
@@ -303,11 +303,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
   * __drm_atomic_helper_plane_reset - reset state on plane
   * @plane: drm plane
   * @plane_state: plane state to assign
   *
   * Initializes the newly allocated @plane_state and assigns it to
- * the &drm_crtc->state pointer of @plane, usually required when
+ * the &drm_plane->state pointer of @plane, usually required when
   * initializing the drivers or when called from the &drm_plane_funcs.reset
   * hook.
   *
   * This is useful for drivers that subclass the plane state.
   */
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#16 lore raw

PATCH v2 7/20 drm/atomic-state-helper: Rename __drm_atomic_helper_plane_state_reset()

In reply to Maxime Ripard

__drm_atomic_helper_plane_state_reset() is used to initialize a newly allocated drm_plane_state, and is being typically called by the drm_plane_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_plane_state instance, we will need to call __drm_atomic_helper_plane_state_reset() from both the reset and atomic_create hooks.

To avoid any confusion, we can thus rename
__drm_atomic_helper_plane_state_reset() to
__drm_atomic_helper_plane_state_init().

---
 drivers/gpu/drm/drm_atomic_state_helper.c  | 10 +++++-----
 drivers/gpu/drm/i915/display/intel_plane.c |  2 +-
 include/drm/drm_atomic_state_helper.h      |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_atomic_state_helper.c +5 -5
index e1f3d05ad3470154a6be01423979a4deb8617441..2548d6da13675f63304dc92423c5d225de0447a8 100644
@@ -235,19 +235,19 @@ void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
 	kfree(state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
 
 /**
- * __drm_atomic_helper_plane_state_reset - resets plane state to default values
+ * __drm_atomic_helper_plane_state_init - Init plane state to default values
  * @plane_state: atomic plane state, must not be NULL
  * @plane: plane object, must not be NULL
  *
  * Initializes the newly allocated @plane_state with default
  * values. This is useful for drivers that subclass the CRTC state.
  */
-void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
-					   struct drm_plane *plane)
+void __drm_atomic_helper_plane_state_init(struct drm_plane_state *plane_state,
+					  struct drm_plane *plane)
 {
 	u64 val;
 
 	plane_state->plane = plane;
 	plane_state->rotation = DRM_MODE_ROTATE_0;
@@ -295,11 +295,11 @@ void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
 							   plane->hotspot_y_property,
 							   &val))
 			plane_state->hotspot_y = val;
 	}
 }
-EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_plane_state_init);
 
 /**
  * __drm_atomic_helper_plane_reset - reset state on plane
  * @plane: drm plane
  * @plane_state: plane state to assign
@@ -313,11 +313,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
  */
 void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
 				     struct drm_plane_state *plane_state)
 {
 	if (plane_state)
-		__drm_atomic_helper_plane_state_reset(plane_state, plane);
+		__drm_atomic_helper_plane_state_init(plane_state, plane);
 
 	plane->state = plane_state;
 }
 EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
 
drivers/gpu/drm/i915/display/intel_plane.c +1 -1
index e06a0618b4c6cd3b4d13752f604006b525118193..705367fef836663e50fe9bbfb1fcc83abf1fb249 100644
@@ -65,11 +65,11 @@
 static void intel_plane_state_reset(struct intel_plane_state *plane_state,
 				    struct intel_plane *plane)
 {
 	memset(plane_state, 0, sizeof(*plane_state));
 
-	__drm_atomic_helper_plane_state_reset(&plane_state->uapi, &plane->base);
+	__drm_atomic_helper_plane_state_init(&plane_state->uapi, &plane->base);
 
 	plane_state->scaler_id = -1;
 }
 
 struct intel_plane *intel_plane_alloc(void)
include/drm/drm_atomic_state_helper.h +1 -1
index 900672c6ea90ba9cb87e38a7c84225972aee43c5..44e8850aae7fd6390f4b58188a9c677b8389702f 100644
@@ -51,11 +51,11 @@ struct drm_crtc_state *
 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc);
 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state);
 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
 					  struct drm_crtc_state *state);
 
-void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *state,
+void __drm_atomic_helper_plane_state_init(struct drm_plane_state *state,
 					   struct drm_plane *plane);
 void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
 				     struct drm_plane_state *state);
 void drm_atomic_helper_plane_reset(struct drm_plane *plane);
 void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 7/20
#17 lore raw

Re: [PATCH v2 07/20] drm/atomic-state-helper: Rename __drm_atomic_helper_plane_state_reset()

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 10 lines

__drm_atomic_helper_plane_state_reset() is used to initialize a newly allocated drm_plane_state, and is being typically called by the drm_plane_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_plane_state instance, we will need to call __drm_atomic_helper_plane_state_reset() from both the reset and atomic_create hooks.

Quoted 6 lines

To avoid any confusion, we can thus rename
__drm_atomic_helper_plane_state_reset() to
__drm_atomic_helper_plane_state_init().

I think the renaming makes sense even without the atomic_create_state callbacks.

drivers/gpu/drm/drm_atomic_state_helper.c void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, · line 248

Quoted 7 lines

* Initializes the newly allocated @plane_state with default
* values. This is useful for drivers that subclass the CRTC state. */

drivers/gpu/drm/drm_atomic_state_helper.c +2 -2
-void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
-					   struct drm_plane *plane)
+void __drm_atomic_helper_plane_state_init(struct drm_plane_state *plane_state,
+					  struct drm_plane *plane)

All such helpers are now just common init functions and you could drop the double-underscores from the name, I think.

Best regards
Thomas

Quoted 66 lines
  {
  	u64 val;
  
  	plane_state->plane = plane;
  	plane_state->rotation = DRM_MODE_ROTATE_0;
drivers/gpu/drm/drm_atomic_state_helper.c +2 -2
@@ -295,11 +295,11 @@ void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
  							   plane->hotspot_y_property,
  							   &val))
  			plane_state->hotspot_y = val;
  	}
  }
-EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_plane_state_init);
 
  /**
   * __drm_atomic_helper_plane_reset - reset state on plane
   * @plane: drm plane
   * @plane_state: plane state to assign
@@ -313,11 +313,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
   */
  void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
  				     struct drm_plane_state *plane_state)
  {
  	if (plane_state)
-		__drm_atomic_helper_plane_state_reset(plane_state, plane);
+		__drm_atomic_helper_plane_state_init(plane_state, plane);
 
  	plane->state = plane_state;
  }
  EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
 
drivers/gpu/drm/i915/display/intel_plane.c +1 -1
index e06a0618b4c6cd3b4d13752f604006b525118193..705367fef836663e50fe9bbfb1fcc83abf1fb249 100644
@@ -65,11 +65,11 @@
  static void intel_plane_state_reset(struct intel_plane_state *plane_state,
  				    struct intel_plane *plane)
  {
  	memset(plane_state, 0, sizeof(*plane_state));
 
-	__drm_atomic_helper_plane_state_reset(&plane_state->uapi, &plane->base);
+	__drm_atomic_helper_plane_state_init(&plane_state->uapi, &plane->base);
 
  	plane_state->scaler_id = -1;
  }
 
  struct intel_plane *intel_plane_alloc(void)
include/drm/drm_atomic_state_helper.h +1 -1
index 900672c6ea90ba9cb87e38a7c84225972aee43c5..44e8850aae7fd6390f4b58188a9c677b8389702f 100644
@@ -51,11 +51,11 @@ struct drm_crtc_state *
  drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc);
  void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state);
  void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
  					  struct drm_crtc_state *state);
 
-void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *state,
+void __drm_atomic_helper_plane_state_init(struct drm_plane_state *state,
  					   struct drm_plane *plane);
  void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
  				     struct drm_plane_state *state);
  void drm_atomic_helper_plane_reset(struct drm_plane *plane);
  void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#18 lore raw

PATCH v2 8/20 drm/plane: Add new atomic_create_state callback

In reply to Maxime Ripard

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software state, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect:
atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with planes.

---
 drivers/gpu/drm/drm_atomic_state_helper.c | 44 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_mode_config.c         | 21 ++++++++++++++-
 include/drm/drm_atomic_state_helper.h     |  4 +++
 include/drm/drm_plane.h                   | 13 +++++++++
 4 files changed, 81 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +44 -0
index 2548d6da13675f63304dc92423c5d225de0447a8..f4ce9d3573cbecf216904db54335e0cf84a01c39 100644
@@ -319,10 +319,29 @@ void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
 
 	plane->state = plane_state;
 }
 EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
 
+/**
+ * __drm_atomic_helper_plane_create_state - initializes plane state
+ * @plane: plane object
+ * @state: new state to initialize
+ *
+ * Initializes the newly allocated @state, usually required when
+ * initializing the drivers.
+ *
+ * @state is assumed to be zeroed.
+ *
+ * This is useful for drivers that subclass @drm_plane_state.
+ */
+void __drm_atomic_helper_plane_create_state(struct drm_plane *plane,
+					    struct drm_plane_state *state)
+{
+	__drm_atomic_helper_plane_state_init(state, plane);
+}
+EXPORT_SYMBOL(__drm_atomic_helper_plane_create_state);
+
 /**
  * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes
  * @plane: drm plane
  *
  * Resets the atomic state for @plane by freeing the state pointer (which might
@@ -338,10 +357,35 @@ void drm_atomic_helper_plane_reset(struct drm_plane *plane)
 	if (plane->state)
 		__drm_atomic_helper_plane_reset(plane, plane->state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
 
+/**
+ * drm_atomic_helper_plane_create_state - default &drm_plane_funcs.atomic_create_state hook for planes
+ * @plane: plane object
+ *
+ * Initializes a pristine @drm_plane_state.
+ *
+ * This is useful for drivers that don't subclass @drm_plane_state.
+ *
+ * RETURNS:
+ * Pointer to new plane state, or ERR_PTR on failure.
+ */
+struct drm_plane_state *drm_atomic_helper_plane_create_state(struct drm_plane *plane)
+{
+	struct drm_plane_state *state;
+
+	state = kzalloc_obj(*state);
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	__drm_atomic_helper_plane_create_state(plane, state);
+
+	return state;
+}
+EXPORT_SYMBOL(drm_atomic_helper_plane_create_state);
+
 /**
  * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
  * @plane: plane object
  * @state: atomic plane state
  *
drivers/gpu/drm/drm_mode_config.c +20 -1
index cba527571ca66d3aa6dc652c87e03a19815d1d41..09b8292195ba5eb5d96735aee5506407bd32ade3 100644
@@ -180,10 +180,26 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
 	drm_connector_list_iter_end(&conn_iter);
 
 	return ret;
 }
 
+static int drm_mode_config_plane_create_state(struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state;
+
+	if (!plane->funcs->atomic_create_state)
+		return 0;
+
+	plane_state = plane->funcs->atomic_create_state(plane);
+	if (IS_ERR(plane_state))
+		return PTR_ERR(plane_state);
+
+	plane->state = plane_state;
+
+	return 0;
+}
+
 /**
  * drm_mode_config_reset - call ->reset callbacks
  * @dev: drm device
  *
  * This functions calls all the crtc's, encoder's and connector's ->reset
@@ -204,13 +220,16 @@ void drm_mode_config_reset(struct drm_device *dev)
 	struct drm_connector_list_iter conn_iter;
 
 	drm_for_each_colorop(colorop, dev)
 		drm_colorop_reset(colorop);
 
-	drm_for_each_plane(plane, dev)
+	drm_for_each_plane(plane, dev) {
 		if (plane->funcs->reset)
 			plane->funcs->reset(plane);
+		else if (plane->funcs->atomic_create_state)
+			drm_mode_config_plane_create_state(plane);
+	}
 
 	drm_for_each_crtc(crtc, dev)
 		if (crtc->funcs->reset)
 			crtc->funcs->reset(crtc);
 
include/drm/drm_atomic_state_helper.h +4 -0
index 44e8850aae7fd6390f4b58188a9c677b8389702f..6a3a2feb3dff1f2fbdf2a6e63d8d7317c7d6ead6 100644
@@ -53,10 +53,14 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state);
 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
 					  struct drm_crtc_state *state);
 
 void __drm_atomic_helper_plane_state_init(struct drm_plane_state *state,
 					   struct drm_plane *plane);
+void __drm_atomic_helper_plane_create_state(struct drm_plane *plane,
+					    struct drm_plane_state *state);
+struct drm_plane_state *
+drm_atomic_helper_plane_create_state(struct drm_plane *plane);
 void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
 				     struct drm_plane_state *state);
 void drm_atomic_helper_plane_reset(struct drm_plane *plane);
 void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
 					       struct drm_plane_state *state);
include/drm/drm_plane.h +13 -0
index 703ef4d1bbbcf084c43aa5e127d28691878061c4..4d4d511b681d50c17fbc593cce9f706d63e04a52 100644
@@ -386,10 +386,23 @@ struct drm_plane_funcs {
 	 * 0 on success or a negative error code on failure.
 	 */
 	int (*set_property)(struct drm_plane *plane,
 			    struct drm_property *property, uint64_t val);
 
+	/**
+	 * @atomic_create_state:
+	 *
+	 * Allocates a pristine, initialized, state for the plane object
+	 * and returns it.
+	 *
+	 * RETURNS:
+	 *
+	 * A new, pristine, plane state instance or an error pointer
+	 * on failure.
+	 */
+	struct drm_plane_state *(*atomic_create_state)(struct drm_plane *plane);
+
 	/**
 	 * @atomic_duplicate_state:
 	 *
 	 * Duplicate the current atomic state for this plane and return it.
 	 * The core and helpers guarantee that any atomic state duplicated with
Signature · 1 line
2.53.0
#19 lore raw

Re: [PATCH v2 08/20] drm/plane: Add new atomic_create_state callback

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 58 lines

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software state, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect:
atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with planes.

---
  drivers/gpu/drm/drm_atomic_state_helper.c | 44 +++++++++++++++++++++++++++++++
  drivers/gpu/drm/drm_mode_config.c         | 21 ++++++++++++++-
  include/drm/drm_atomic_state_helper.h     |  4 +++
  include/drm/drm_plane.h                   | 13 +++++++++
  4 files changed, 81 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +8 -0
index 2548d6da13675f63304dc92423c5d225de0447a8..f4ce9d3573cbecf216904db54335e0cf84a01c39 100644
@@ -319,10 +319,29 @@ void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
 
  	plane->state = plane_state;
  }
  EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
 
+/**
+ * __drm_atomic_helper_plane_create_state - initializes plane state
+ * @plane: plane object
+ * @state: new state to initialize
+ *
+ * Initializes the newly allocated @state, usually required when
+ * initializing the drivers.
+ *

drivers/gpu/drm/drm_atomic_state_helper.c void __drm_atomic_helper_plane_reset(struct drm_plane *plane, · line 341

Quoted 10 lines
drivers/gpu/drm/drm_atomic_state_helper.c +10 -0
+ * @state is assumed to be zeroed.
+ *
+ * This is useful for drivers that subclass @drm_plane_state.
+ */
+void __drm_atomic_helper_plane_create_state(struct drm_plane *plane,
+					    struct drm_plane_state *state)
+{
+	__drm_atomic_helper_plane_state_init(state, plane);
+}
+EXPORT_SYMBOL(__drm_atomic_helper_plane_create_state);

Will this function have another purpuse?  Could we just call _plane_state_init() directly from anywhere?

Best regards
Thomas

Quoted 139 lines
drivers/gpu/drm/drm_atomic_state_helper.c +26 -0
+
  /**
   * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes
   * @plane: drm plane
   *
   * Resets the atomic state for @plane by freeing the state pointer (which might
@@ -338,10 +357,35 @@ void drm_atomic_helper_plane_reset(struct drm_plane *plane)
  	if (plane->state)
  		__drm_atomic_helper_plane_reset(plane, plane->state);
  }
  EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
 
+/**
+ * drm_atomic_helper_plane_create_state - default &drm_plane_funcs.atomic_create_state hook for planes
+ * @plane: plane object
+ *
+ * Initializes a pristine @drm_plane_state.
+ *
+ * This is useful for drivers that don't subclass @drm_plane_state.
+ *
+ * RETURNS:
+ * Pointer to new plane state, or ERR_PTR on failure.
+ */
+struct drm_plane_state *drm_atomic_helper_plane_create_state(struct drm_plane *plane)
+{
+	struct drm_plane_state *state;
+
+	state = kzalloc_obj(*state);
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	__drm_atomic_helper_plane_create_state(plane, state);
+
+	return state;
+}
+EXPORT_SYMBOL(drm_atomic_helper_plane_create_state);
+
  /**
   * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
   * @plane: plane object
   * @state: atomic plane state
   *
drivers/gpu/drm/drm_mode_config.c +20 -1
index cba527571ca66d3aa6dc652c87e03a19815d1d41..09b8292195ba5eb5d96735aee5506407bd32ade3 100644
@@ -180,10 +180,26 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
  	drm_connector_list_iter_end(&conn_iter);
 
  	return ret;
  }
 
+static int drm_mode_config_plane_create_state(struct drm_plane *plane)
+{
+	struct drm_plane_state *plane_state;
+
+	if (!plane->funcs->atomic_create_state)
+		return 0;
+
+	plane_state = plane->funcs->atomic_create_state(plane);
+	if (IS_ERR(plane_state))
+		return PTR_ERR(plane_state);
+
+	plane->state = plane_state;
+
+	return 0;
+}
+
  /**
   * drm_mode_config_reset - call ->reset callbacks
   * @dev: drm device
   *
   * This functions calls all the crtc's, encoder's and connector's ->reset
@@ -204,13 +220,16 @@ void drm_mode_config_reset(struct drm_device *dev)
  	struct drm_connector_list_iter conn_iter;
 
  	drm_for_each_colorop(colorop, dev)
  		drm_colorop_reset(colorop);
 
-	drm_for_each_plane(plane, dev)
+	drm_for_each_plane(plane, dev) {
  		if (plane->funcs->reset)
  			plane->funcs->reset(plane);
+		else if (plane->funcs->atomic_create_state)
+			drm_mode_config_plane_create_state(plane);
+	}
 
  	drm_for_each_crtc(crtc, dev)
  		if (crtc->funcs->reset)
  			crtc->funcs->reset(crtc);
 
include/drm/drm_atomic_state_helper.h +4 -0
index 44e8850aae7fd6390f4b58188a9c677b8389702f..6a3a2feb3dff1f2fbdf2a6e63d8d7317c7d6ead6 100644
@@ -53,10 +53,14 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state);
  void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
  					  struct drm_crtc_state *state);
 
  void __drm_atomic_helper_plane_state_init(struct drm_plane_state *state,
  					   struct drm_plane *plane);
+void __drm_atomic_helper_plane_create_state(struct drm_plane *plane,
+					    struct drm_plane_state *state);
+struct drm_plane_state *
+drm_atomic_helper_plane_create_state(struct drm_plane *plane);
  void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
  				     struct drm_plane_state *state);
  void drm_atomic_helper_plane_reset(struct drm_plane *plane);
  void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
  					       struct drm_plane_state *state);
include/drm/drm_plane.h +13 -0
index 703ef4d1bbbcf084c43aa5e127d28691878061c4..4d4d511b681d50c17fbc593cce9f706d63e04a52 100644
@@ -386,10 +386,23 @@ struct drm_plane_funcs {
  	 * 0 on success or a negative error code on failure.
  	 */
  	int (*set_property)(struct drm_plane *plane,
  			    struct drm_property *property, uint64_t val);
 
+	/**
+	 * @atomic_create_state:
+	 *
+	 * Allocates a pristine, initialized, state for the plane object
+	 * and returns it.
+	 *
+	 * RETURNS:
+	 *
+	 * A new, pristine, plane state instance or an error pointer
+	 * on failure.
+	 */
+	struct drm_plane_state *(*atomic_create_state)(struct drm_plane *plane);
+
  	/**
  	 * @atomic_duplicate_state:
  	 *
  	 * Duplicate the current atomic state for this plane and return it.
  	 * The core and helpers guarantee that any atomic state duplicated with
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#20 lore raw

Re: [PATCH v2 08/20] drm/plane: Add new atomic_create_state callback

Quoted 64 lines · Thomas Zimmermann

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 61 lines

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software state, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect:
atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with planes.

---
  drivers/gpu/drm/drm_atomic_state_helper.c | 44 +++++++++++++++++++++++++++++++
  drivers/gpu/drm/drm_mode_config.c         | 21 ++++++++++++++-
  include/drm/drm_atomic_state_helper.h     |  4 +++
  include/drm/drm_plane.h                   | 13 +++++++++
  4 files changed, 81 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +13 -0
index 2548d6da13675f63304dc92423c5d225de0447a8..f4ce9d3573cbecf216904db54335e0cf84a01c39 100644
@@ -319,10 +319,29 @@ void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
  	plane->state = plane_state;
  }
  EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
+/**
+ * __drm_atomic_helper_plane_create_state - initializes plane state
+ * @plane: plane object
+ * @state: new state to initialize
+ *
+ * Initializes the newly allocated @state, usually required when
+ * initializing the drivers.
+ *
+ * @state is assumed to be zeroed.
+ *
+ * This is useful for drivers that subclass @drm_plane_state.
+ */
+void __drm_atomic_helper_plane_create_state(struct drm_plane *plane,
Quoted 8 lines

drivers/gpu/drm/drm_atomic_state_helper.c void __drm_atomic_helper_plane_reset(struct drm_plane *plane, · line 341

Quoted 5 lines
drivers/gpu/drm/drm_atomic_state_helper.c +5 -0
+					    struct drm_plane_state *state)
+{
+	__drm_atomic_helper_plane_state_init(state, plane);
+}
+EXPORT_SYMBOL(__drm_atomic_helper_plane_create_state);

Will this function have another purpuse?  Could we just call _plane_state_init() directly from anywhere?

Yeah, I guess that makes sense. I'll drop that patch and the similar ones.

Thanks!
Maxime

author maintainer
#21 lore raw

PATCH v2 9/20 drm/atomic-state-helper: Rename __drm_atomic_helper_crtc_state_reset()

In reply to Maxime Ripard

__drm_atomic_helper_crtc_state_reset() is used to initialize a newly allocated drm_crtc_state, and is being typically called by the drm_crtc_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_crtc_state instance, we will need to call __drm_atomic_helper_crtc_state_reset() from both the reset and atomic_create hooks.

To avoid any confusion, we can thus rename
__drm_atomic_helper_crtc_state_reset() to
__drm_atomic_helper_crtc_state_init().

---
 drivers/gpu/drm/drm_atomic_state_helper.c | 10 +++++-----
 drivers/gpu/drm/i915/display/intel_crtc.c |  2 +-
 include/drm/drm_atomic_state_helper.h     |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_atomic_state_helper.c +5 -5
index f4ce9d3573cbecf216904db54335e0cf84a01c39..b87cc3cd5b0021699ac57a33739d172a5706e2e1 100644
@@ -61,25 +61,25 @@
  * For other drivers the building blocks are split out, see the documentation
  * for these functions.
  */
 
 /**
- * __drm_atomic_helper_crtc_state_reset - reset the CRTC state
+ * __drm_atomic_helper_crtc_state_init - Initializes the CRTC state
  * @crtc_state: atomic CRTC state, must not be NULL
  * @crtc: CRTC object, must not be NULL
  *
  * Initializes the newly allocated @crtc_state with default
  * values. This is useful for drivers that subclass the CRTC state.
  */
 void
-__drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state,
-				     struct drm_crtc *crtc)
+__drm_atomic_helper_crtc_state_init(struct drm_crtc_state *crtc_state,
+				    struct drm_crtc *crtc)
 {
 	crtc_state->crtc = crtc;
 	crtc_state->background_color = DRM_ARGB64_PREP(0xffff, 0, 0, 0);
 }
-EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_init);
 
 /**
  * __drm_atomic_helper_crtc_reset - reset state on CRTC
  * @crtc: drm CRTC
  * @crtc_state: CRTC state to assign
@@ -94,11 +94,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);
 void
 __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
 			       struct drm_crtc_state *crtc_state)
 {
 	if (crtc_state)
-		__drm_atomic_helper_crtc_state_reset(crtc_state, crtc);
+		__drm_atomic_helper_crtc_state_init(crtc_state, crtc);
 
 	if (drm_dev_has_vblank(crtc->dev))
 		drm_crtc_vblank_reset(crtc);
 
 	crtc->state = crtc_state;
drivers/gpu/drm/i915/display/intel_crtc.c +1 -1
index 53378d2dcbec867e7973cb3b874802f2ada01d41..b57a59a5f7786f1029d576b0f3d564e77b7060e4 100644
@@ -179,11 +179,11 @@ struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
 void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
 			    struct intel_crtc *crtc)
 {
 	memset(crtc_state, 0, sizeof(*crtc_state));
 
-	__drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
+	__drm_atomic_helper_crtc_state_init(&crtc_state->uapi, &crtc->base);
 
 	crtc_state->cpu_transcoder = INVALID_TRANSCODER;
 	crtc_state->master_transcoder = INVALID_TRANSCODER;
 	crtc_state->hsw_workaround_pipe = INVALID_PIPE;
 	crtc_state->scaler_state.scaler_id = -1;
include/drm/drm_atomic_state_helper.h +1 -1
index 6a3a2feb3dff1f2fbdf2a6e63d8d7317c7d6ead6..161cd1f6b8266e882eb1fd128b403cba350be3d2 100644
@@ -38,11 +38,11 @@ struct drm_connector_state;
 struct drm_private_obj;
 struct drm_private_state;
 struct drm_modeset_acquire_ctx;
 struct drm_device;
 
-void __drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *state,
+void __drm_atomic_helper_crtc_state_init(struct drm_crtc_state *state,
 					  struct drm_crtc *crtc);
 void __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
 				    struct drm_crtc_state *state);
 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc);
 void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 9/20
#22 lore raw

Re: [PATCH v2 09/20] drm/atomic-state-helper: Rename __drm_atomic_helper_crtc_state_reset()

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 10 lines

__drm_atomic_helper_crtc_state_reset() is used to initialize a newly allocated drm_crtc_state, and is being typically called by the drm_crtc_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_crtc_state instance, we will need to call __drm_atomic_helper_crtc_state_reset() from both the reset and atomic_create hooks.

Quoted 6 lines

To avoid any confusion, we can thus rename
__drm_atomic_helper_crtc_state_reset() to
__drm_atomic_helper_crtc_state_init().

with similar comments as for the other case.

Quoted 88 lines
---
  drivers/gpu/drm/drm_atomic_state_helper.c | 10 +++++-----
  drivers/gpu/drm/i915/display/intel_crtc.c |  2 +-
  include/drm/drm_atomic_state_helper.h     |  2 +-
  3 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_atomic_state_helper.c +5 -5
index f4ce9d3573cbecf216904db54335e0cf84a01c39..b87cc3cd5b0021699ac57a33739d172a5706e2e1 100644
@@ -61,25 +61,25 @@
   * For other drivers the building blocks are split out, see the documentation
   * for these functions.
   */
 
  /**
- * __drm_atomic_helper_crtc_state_reset - reset the CRTC state
+ * __drm_atomic_helper_crtc_state_init - Initializes the CRTC state
   * @crtc_state: atomic CRTC state, must not be NULL
   * @crtc: CRTC object, must not be NULL
   *
   * Initializes the newly allocated @crtc_state with default
   * values. This is useful for drivers that subclass the CRTC state.
   */
  void
-__drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state,
-				     struct drm_crtc *crtc)
+__drm_atomic_helper_crtc_state_init(struct drm_crtc_state *crtc_state,
+				    struct drm_crtc *crtc)
  {
  	crtc_state->crtc = crtc;
  	crtc_state->background_color = DRM_ARGB64_PREP(0xffff, 0, 0, 0);
  }
-EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_init);
 
  /**
   * __drm_atomic_helper_crtc_reset - reset state on CRTC
   * @crtc: drm CRTC
   * @crtc_state: CRTC state to assign
@@ -94,11 +94,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);
  void
  __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
  			       struct drm_crtc_state *crtc_state)
  {
  	if (crtc_state)
-		__drm_atomic_helper_crtc_state_reset(crtc_state, crtc);
+		__drm_atomic_helper_crtc_state_init(crtc_state, crtc);
 
  	if (drm_dev_has_vblank(crtc->dev))
  		drm_crtc_vblank_reset(crtc);
 
  	crtc->state = crtc_state;
drivers/gpu/drm/i915/display/intel_crtc.c +1 -1
index 53378d2dcbec867e7973cb3b874802f2ada01d41..b57a59a5f7786f1029d576b0f3d564e77b7060e4 100644
@@ -179,11 +179,11 @@ struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
  void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
  			    struct intel_crtc *crtc)
  {
  	memset(crtc_state, 0, sizeof(*crtc_state));
 
-	__drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
+	__drm_atomic_helper_crtc_state_init(&crtc_state->uapi, &crtc->base);
 
  	crtc_state->cpu_transcoder = INVALID_TRANSCODER;
  	crtc_state->master_transcoder = INVALID_TRANSCODER;
  	crtc_state->hsw_workaround_pipe = INVALID_PIPE;
  	crtc_state->scaler_state.scaler_id = -1;
include/drm/drm_atomic_state_helper.h +1 -1
index 6a3a2feb3dff1f2fbdf2a6e63d8d7317c7d6ead6..161cd1f6b8266e882eb1fd128b403cba350be3d2 100644
@@ -38,11 +38,11 @@ struct drm_connector_state;
  struct drm_private_obj;
  struct drm_private_state;
  struct drm_modeset_acquire_ctx;
  struct drm_device;
 
-void __drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *state,
+void __drm_atomic_helper_crtc_state_init(struct drm_crtc_state *state,
  					  struct drm_crtc *crtc);
  void __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
  				    struct drm_crtc_state *state);
  void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc);
  void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#23 lore raw

PATCH v2 10/20 drm/crtc: Add new atomic_create_state callback

In reply to Maxime Ripard

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software tate, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect:
atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with crtcs.

---
 drivers/gpu/drm/drm_atomic_state_helper.c | 47 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_mode_config.c         | 21 +++++++++++++-
 include/drm/drm_atomic_state_helper.h     |  4 +++
 include/drm/drm_crtc.h                    | 13 +++++++++
 4 files changed, 84 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +47 -0
index b87cc3cd5b0021699ac57a33739d172a5706e2e1..f1fc2edc6e6e35fbac5ef82437f3cb7485afc412 100644
@@ -103,10 +103,32 @@ __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
 
 	crtc->state = crtc_state;
 }
 EXPORT_SYMBOL(__drm_atomic_helper_crtc_reset);
 
+/**
+ * __drm_atomic_helper_crtc_create_state - initializes crtc state
+ * @crtc: crtc object
+ * @state: new state to initialize
+ *
+ * Initializes the newly allocated @state, usually required when
+ * initializing the drivers.
+ *
+ * @state is assumed to be zeroed.
+ *
+ * This is useful for drivers that subclass @drm_crtc_state.
+ */
+void __drm_atomic_helper_crtc_create_state(struct drm_crtc *crtc,
+					   struct drm_crtc_state *state)
+{
+	__drm_atomic_helper_crtc_state_init(state, crtc);
+
+	if (drm_dev_has_vblank(crtc->dev))
+		drm_crtc_vblank_reset(crtc);
+}
+EXPORT_SYMBOL(__drm_atomic_helper_crtc_create_state);
+
 /**
  * drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs
  * @crtc: drm CRTC
  *
  * Resets the atomic state for @crtc by freeing the state pointer (which might
@@ -122,10 +144,35 @@ void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
 
 	__drm_atomic_helper_crtc_reset(crtc, crtc_state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
 
+/**
+ * drm_atomic_helper_crtc_create_state - default &drm_crtc_funcs.atomic_create_state hook for crtcs
+ * @crtc: crtc object
+ *
+ * Initializes a pristine @drm_crtc_state.
+ *
+ * This is useful for drivers that don't subclass @drm_crtc_state.
+ *
+ * RETURNS:
+ * Pointer to new crtc state, or ERR_PTR on failure.
+ */
+struct drm_crtc_state *drm_atomic_helper_crtc_create_state(struct drm_crtc *crtc)
+{
+	struct drm_crtc_state *state;
+
+	state = kzalloc_obj(*state);
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	__drm_atomic_helper_crtc_create_state(crtc, state);
+
+	return state;
+}
+EXPORT_SYMBOL(drm_atomic_helper_crtc_create_state);
+
 /**
  * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state
  * @crtc: CRTC object
  * @state: atomic CRTC state
  *
drivers/gpu/drm/drm_mode_config.c +20 -1
index 09b8292195ba5eb5d96735aee5506407bd32ade3..f5092d03b168bb114a199b1dbcaeb770983c9749 100644
@@ -196,10 +196,26 @@ static int drm_mode_config_plane_create_state(struct drm_plane *plane)
 	plane->state = plane_state;
 
 	return 0;
 }
 
+static int drm_mode_config_crtc_create_state(struct drm_crtc *crtc)
+{
+	struct drm_crtc_state *crtc_state;
+
+	if (!crtc->funcs->atomic_create_state)
+		return 0;
+
+	crtc_state = crtc->funcs->atomic_create_state(crtc);
+	if (IS_ERR(crtc_state))
+		return PTR_ERR(crtc_state);
+
+	crtc->state = crtc_state;
+
+	return 0;
+}
+
 /**
  * drm_mode_config_reset - call ->reset callbacks
  * @dev: drm device
  *
  * This functions calls all the crtc's, encoder's and connector's ->reset
@@ -227,13 +243,16 @@ void drm_mode_config_reset(struct drm_device *dev)
 			plane->funcs->reset(plane);
 		else if (plane->funcs->atomic_create_state)
 			drm_mode_config_plane_create_state(plane);
 	}
 
-	drm_for_each_crtc(crtc, dev)
+	drm_for_each_crtc(crtc, dev) {
 		if (crtc->funcs->reset)
 			crtc->funcs->reset(crtc);
+		else if (crtc->funcs->atomic_create_state)
+			drm_mode_config_crtc_create_state(crtc);
+	}
 
 	drm_for_each_encoder(encoder, dev)
 		if (encoder->funcs && encoder->funcs->reset)
 			encoder->funcs->reset(encoder);
 
include/drm/drm_atomic_state_helper.h +4 -0
index 161cd1f6b8266e882eb1fd128b403cba350be3d2..bc83094dfb78f0f3699ca7956a8a666ca09b2d1a 100644
@@ -43,10 +43,14 @@ struct drm_device;
 void __drm_atomic_helper_crtc_state_init(struct drm_crtc_state *state,
 					  struct drm_crtc *crtc);
 void __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
 				    struct drm_crtc_state *state);
 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc);
+void __drm_atomic_helper_crtc_create_state(struct drm_crtc *crtc,
+					   struct drm_crtc_state *state);
+struct drm_crtc_state *
+drm_atomic_helper_crtc_create_state(struct drm_crtc *crtc);
 void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
 					      struct drm_crtc_state *state);
 struct drm_crtc_state *
 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc);
 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state);
include/drm/drm_crtc.h +13 -0
index 312fc1e745d226adec787cd5f1b7c923fe629670..9e410191683c4cb978d759e3b734afdd3bb8aa76 100644
@@ -636,10 +636,23 @@ struct drm_crtc_funcs {
 	 * 0 on success or a negative error code on failure.
 	 */
 	int (*set_property)(struct drm_crtc *crtc,
 			    struct drm_property *property, uint64_t val);
 
+	/**
+	 * @atomic_create_state:
+	 *
+	 * Allocates a pristine, initialized, state for the crtc object
+	 * and returns it.
+	 *
+	 * RETURNS:
+	 *
+	 * A new, pristine, crtc state instance or an error pointer
+	 * on failure.
+	 */
+	struct drm_crtc_state *(*atomic_create_state)(struct drm_crtc *crtc);
+
 	/**
 	 * @atomic_duplicate_state:
 	 *
 	 * Duplicate the current atomic state for this CRTC and return it.
 	 * The core and helpers guarantee that any atomic state duplicated with
Signature · 1 line
2.53.0
Reviewed-by on v2 10/20
#24 lore raw

Re: [PATCH v2 10/20] drm/crtc: Add new atomic_create_state callback

Quoted 32 lines · Maxime Ripard

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software tate, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect:
atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with crtcs.

Quoted 8 lines
---
 drivers/gpu/drm/drm_atomic_state_helper.c | 47 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_mode_config.c         | 21 +++++++++++++-
 include/drm/drm_atomic_state_helper.h     |  4 +++
 include/drm/drm_crtc.h                    | 13 +++++++++
 4 files changed, 84 insertions(+), 1 deletion(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#25 lore raw

PATCH v2 11/20 drm/atomic-state-helper: Rename __drm_atomic_helper_connector_state_reset()

In reply to Maxime Ripard

__drm_atomic_helper_connector_state_reset() is used to initialize a newly allocated drm_connector_state, and is being typically called by the drm_connector_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_connector_state instance, we will need to call __drm_atomic_helper_connector_state_reset() from both the reset and atomic_create hooks.

To avoid any confusion, we can thus rename
__drm_atomic_helper_connector_state_reset() to
__drm_atomic_helper_connector_state_init().

---
 drivers/gpu/drm/drm_atomic_state_helper.c | 10 +++++-----
 include/drm/drm_atomic_state_helper.h     |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_atomic_state_helper.c +5 -5
index f1fc2edc6e6e35fbac5ef82437f3cb7485afc412..8ed8cb8a9048e8fd89fa22d20985c84af1672135 100644
@@ -515,24 +515,24 @@ void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
 	kfree(state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
 
 /**
- * __drm_atomic_helper_connector_state_reset - reset the connector state
+ * __drm_atomic_helper_connector_state_init - Initializes the connector state
  * @conn_state: atomic connector state, must not be NULL
  * @connector: connectotr object, must not be NULL
  *
  * Initializes the newly allocated @conn_state with default
  * values. This is useful for drivers that subclass the connector state.
  */
 void
-__drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,
-					  struct drm_connector *connector)
+__drm_atomic_helper_connector_state_init(struct drm_connector_state *conn_state,
+					 struct drm_connector *connector)
 {
 	conn_state->connector = connector;
 }
-EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_connector_state_init);
 
 /**
  * __drm_atomic_helper_connector_reset - reset state on connector
  * @connector: drm connector
  * @conn_state: connector state to assign
@@ -547,11 +547,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);
 void
 __drm_atomic_helper_connector_reset(struct drm_connector *connector,
 				    struct drm_connector_state *conn_state)
 {
 	if (conn_state)
-		__drm_atomic_helper_connector_state_reset(conn_state, connector);
+		__drm_atomic_helper_connector_state_init(conn_state, connector);
 
 	connector->state = conn_state;
 }
 EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
 
include/drm/drm_atomic_state_helper.h +1 -1
index bc83094dfb78f0f3699ca7956a8a666ca09b2d1a..259a39a0f41ddb2b7d6c1fe7c1a2b0b51774254c 100644
@@ -72,11 +72,11 @@ struct drm_plane_state *
 drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane);
 void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state);
 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
 					  struct drm_plane_state *state);
 
-void __drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,
+void __drm_atomic_helper_connector_state_init(struct drm_connector_state *conn_state,
 					       struct drm_connector *connector);
 void __drm_atomic_helper_connector_reset(struct drm_connector *connector,
 					 struct drm_connector_state *conn_state);
 void drm_atomic_helper_connector_reset(struct drm_connector *connector);
 void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector);
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 11/20
#26 lore raw

Re: [PATCH v2 11/20] drm/atomic-state-helper: Rename __drm_atomic_helper_connector_state_reset()

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 10 lines

__drm_atomic_helper_connector_state_reset() is used to initialize a newly allocated drm_connector_state, and is being typically called by the drm_connector_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_connector_state instance, we will need to call __drm_atomic_helper_connector_state_reset() from both the reset and atomic_create hooks.

Quoted 6 lines

To avoid any confusion, we can thus rename
__drm_atomic_helper_connector_state_reset() to
__drm_atomic_helper_connector_state_init().

Quoted 69 lines
---
  drivers/gpu/drm/drm_atomic_state_helper.c | 10 +++++-----
  include/drm/drm_atomic_state_helper.h     |  2 +-
  2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_atomic_state_helper.c +5 -5
index f1fc2edc6e6e35fbac5ef82437f3cb7485afc412..8ed8cb8a9048e8fd89fa22d20985c84af1672135 100644
@@ -515,24 +515,24 @@ void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
  	kfree(state);
  }
  EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
 
  /**
- * __drm_atomic_helper_connector_state_reset - reset the connector state
+ * __drm_atomic_helper_connector_state_init - Initializes the connector state
   * @conn_state: atomic connector state, must not be NULL
   * @connector: connectotr object, must not be NULL
   *
   * Initializes the newly allocated @conn_state with default
   * values. This is useful for drivers that subclass the connector state.
   */
  void
-__drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,
-					  struct drm_connector *connector)
+__drm_atomic_helper_connector_state_init(struct drm_connector_state *conn_state,
+					 struct drm_connector *connector)
  {
  	conn_state->connector = connector;
  }
-EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_connector_state_init);
 
  /**
   * __drm_atomic_helper_connector_reset - reset state on connector
   * @connector: drm connector
   * @conn_state: connector state to assign
@@ -547,11 +547,11 @@ EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);
  void
  __drm_atomic_helper_connector_reset(struct drm_connector *connector,
  				    struct drm_connector_state *conn_state)
  {
  	if (conn_state)
-		__drm_atomic_helper_connector_state_reset(conn_state, connector);
+		__drm_atomic_helper_connector_state_init(conn_state, connector);
 
  	connector->state = conn_state;
  }
  EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
 
include/drm/drm_atomic_state_helper.h +1 -1
index bc83094dfb78f0f3699ca7956a8a666ca09b2d1a..259a39a0f41ddb2b7d6c1fe7c1a2b0b51774254c 100644
@@ -72,11 +72,11 @@ struct drm_plane_state *
  drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane);
  void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state);
  void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
  					  struct drm_plane_state *state);
 
-void __drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,
+void __drm_atomic_helper_connector_state_init(struct drm_connector_state *conn_state,
  					       struct drm_connector *connector);
  void __drm_atomic_helper_connector_reset(struct drm_connector *connector,
  					 struct drm_connector_state *conn_state);
  void drm_atomic_helper_connector_reset(struct drm_connector *connector);
  void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector);
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Reviewed-by on v2 11/20
#27 lore raw

Re: [PATCH v2 11/20] drm/atomic-state-helper: Rename __drm_atomic_helper_connector_state_reset()

In reply to Maxime Ripard
Quoted 14 lines · Maxime Ripard

__drm_atomic_helper_connector_state_reset() is used to initialize a newly allocated drm_connector_state, and is being typically called by the drm_connector_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_connector_state instance, we will need to call __drm_atomic_helper_connector_state_reset() from both the reset and atomic_create hooks.

To avoid any confusion, we can thus rename
__drm_atomic_helper_connector_state_reset() to
__drm_atomic_helper_connector_state_init().

Quoted 7 lines
---
 drivers/gpu/drm/drm_atomic_state_helper.c | 10 +++++-----
 include/drm/drm_atomic_state_helper.h     |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#28 lore raw

PATCH v2 12/20 drm/hdmi: Rename __drm_atomic_helper_connector_hdmi_reset()

In reply to Maxime Ripard

__drm_atomic_helper_connector_hdmi_reset() is typically used to initialize a newly allocated drm_connector_state when the connector is using the HDMI helpers, and is being called by the drm_connector_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_connector_state instance, we will need to call __drm_atomic_helper_connector_hdmi_reset() from both the reset and atomic_create hooks.

To avoid any confusion, we can thus rename
__drm_atomic_helper_connector_hdmi_reset() to
__drm_atomic_helper_connector_hdmi_state_init().

---
 drivers/gpu/drm/display/drm_bridge_connector.c     |  4 ++--
 drivers/gpu/drm/display/drm_hdmi_state_helper.c    | 14 ++++++++------
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c             |  2 +-
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c |  2 +-
 drivers/gpu/drm/vc4/vc4_hdmi.c                     |  2 +-
 include/drm/display/drm_hdmi_state_helper.h        |  4 ++--
 6 files changed, 15 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +2 -2
index f686aa5c0ed9b84dbe5e0957df22d08aff2f1945..929f06b290626d2091418a6377a5230e3c264b60 100644
@@ -270,12 +270,12 @@ static void drm_bridge_connector_reset(struct drm_connector *connector)
 	struct drm_bridge_connector *bridge_connector =
 		to_drm_bridge_connector(connector);
 
 	drm_atomic_helper_connector_reset(connector);
 	if (bridge_connector->bridge_hdmi)
-		__drm_atomic_helper_connector_hdmi_reset(connector,
-							 connector->state);
+		__drm_atomic_helper_connector_hdmi_state_init(connector,
+							      connector->state);
 }
 
 static const struct drm_connector_funcs drm_bridge_connector_funcs = {
 	.reset = drm_bridge_connector_reset,
 	.detect = drm_bridge_connector_detect,
drivers/gpu/drm/display/drm_hdmi_state_helper.c +8 -6
index a1d16762ac7a9ebdc48f081c5d2f5e200d406099..cdd6df37c04a4b2073004ea08a3f5283a56692df 100644
@@ -304,29 +304,31 @@
  *		--kunitconfig=drivers/gpu/drm/tests \
  *		drm_atomic_helper_connector_hdmi_*
  */
 
 /**
- * __drm_atomic_helper_connector_hdmi_reset() - Initializes all HDMI @drm_connector_state resources
+ * __drm_atomic_helper_connector_hdmi_state_init() - Initializes all HDMI @drm_connector_state resources
  * @connector: DRM connector
  * @new_conn_state: connector state to reset
  *
  * Initializes all HDMI resources from a @drm_connector_state without
  * actually allocating it. This is useful for HDMI drivers, in
- * combination with __drm_atomic_helper_connector_reset() or
- * drm_atomic_helper_connector_reset().
+ * combination with __drm_atomic_helper_connector_reset(),
+ * drm_atomic_helper_connector_reset(),
+ * __drm_atomic_helper_connector_create_state() or
+ * drm_atomic_helper_connector_create_state() .
  */
-void __drm_atomic_helper_connector_hdmi_reset(struct drm_connector *connector,
-					      struct drm_connector_state *new_conn_state)
+void __drm_atomic_helper_connector_hdmi_state_init(struct drm_connector *connector,
+						   struct drm_connector_state *new_conn_state)
 {
 	unsigned int max_bpc = connector->max_bpc;
 
 	new_conn_state->max_bpc = max_bpc;
 	new_conn_state->max_requested_bpc = max_bpc;
 	new_conn_state->hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
 }
-EXPORT_SYMBOL(__drm_atomic_helper_connector_hdmi_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_connector_hdmi_state_init);
 
 static const struct drm_display_mode *
 connector_state_get_mode(const struct drm_connector_state *conn_state)
 {
 	struct drm_atomic_state *state;
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +1 -1
index a50f260c73e41493528e545591aaad0e3f138be2..0ebebb04e68fab5b7938a604f85ad9b756fe33f6 100644
@@ -283,11 +283,11 @@ sun4i_hdmi_connector_detect(struct drm_connector *connector, bool force)
 }
 
 static void sun4i_hdmi_connector_reset(struct drm_connector *connector)
 {
 	drm_atomic_helper_connector_reset(connector);
-	__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
+	__drm_atomic_helper_connector_hdmi_state_init(connector, connector->state);
 }
 
 static const struct drm_connector_funcs sun4i_hdmi_connector_funcs = {
 	.detect			= sun4i_hdmi_connector_detect,
 	.fill_modes		= drm_helper_probe_single_connector_modes,
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +1 -1
index 4bdcea3c7435146aebb1716f38d7302ddb7c6296..aaa73b75f3ce5010147f48afc365d074bb2ec7a7 100644
@@ -166,11 +166,11 @@ static const struct drm_connector_helper_funcs dummy_connector_helper_funcs = {
 };
 
 static void dummy_hdmi_connector_reset(struct drm_connector *connector)
 {
 	drm_atomic_helper_connector_reset(connector);
-	__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
+	__drm_atomic_helper_connector_hdmi_state_init(connector, connector->state);
 }
 
 static const struct drm_connector_funcs dummy_connector_funcs = {
 	.atomic_destroy_state	= drm_atomic_helper_connector_destroy_state,
 	.atomic_duplicate_state	= drm_atomic_helper_connector_duplicate_state,
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index 9898e5451a07a1dca809fb6db3fec59d07485b95..f59d0877a5f48bed6b421775da7ddd008d68f9d9 100644
@@ -506,11 +506,11 @@ static int vc4_hdmi_connector_atomic_check(struct drm_connector *connector,
 }
 
 static void vc4_hdmi_connector_reset(struct drm_connector *connector)
 {
 	drm_atomic_helper_connector_reset(connector);
-	__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
+	__drm_atomic_helper_connector_hdmi_state_init(connector, connector->state);
 	drm_atomic_helper_connector_tv_margins_reset(connector);
 }
 
 static const struct drm_connector_funcs vc4_hdmi_connector_funcs = {
 	.force = drm_atomic_helper_connector_hdmi_force,
include/drm/display/drm_hdmi_state_helper.h +2 -2
index 2349c0d0f00fb468167023d4db2055c70e603bcd..f7600aabdd5f066772a9a82a1fa8a00be7a48396 100644
@@ -9,12 +9,12 @@ struct drm_connector_state;
 struct drm_display_mode;
 struct hdmi_audio_infoframe;
 
 enum drm_connector_status;
 
-void __drm_atomic_helper_connector_hdmi_reset(struct drm_connector *connector,
-					      struct drm_connector_state *new_conn_state);
+void __drm_atomic_helper_connector_hdmi_state_init(struct drm_connector *connector,
+						   struct drm_connector_state *new_conn_state);
 
 int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector,
 					   struct drm_atomic_state *state);
 
 int drm_atomic_helper_connector_hdmi_update_audio_infoframe(struct drm_connector *connector,
Signature · 1 line
2.53.0
maintainer Reviewed-by on v2 12/20
#29 lore raw

Re: [PATCH v2 12/20] drm/hdmi: Rename __drm_atomic_helper_connector_hdmi_reset()

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 11 lines

__drm_atomic_helper_connector_hdmi_reset() is typically used to initialize a newly allocated drm_connector_state when the connector is using the HDMI helpers, and is being called by the drm_connector_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_connector_state instance, we will need to call __drm_atomic_helper_connector_hdmi_reset() from both the reset and atomic_create hooks.

Quoted 6 lines

To avoid any confusion, we can thus rename
__drm_atomic_helper_connector_hdmi_reset() to
__drm_atomic_helper_connector_hdmi_state_init().

Quoted 141 lines
---
  drivers/gpu/drm/display/drm_bridge_connector.c     |  4 ++--
  drivers/gpu/drm/display/drm_hdmi_state_helper.c    | 14 ++++++++------
  drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c             |  2 +-
  drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c |  2 +-
  drivers/gpu/drm/vc4/vc4_hdmi.c                     |  2 +-
  include/drm/display/drm_hdmi_state_helper.h        |  4 ++--
  6 files changed, 15 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +2 -2
index f686aa5c0ed9b84dbe5e0957df22d08aff2f1945..929f06b290626d2091418a6377a5230e3c264b60 100644
@@ -270,12 +270,12 @@ static void drm_bridge_connector_reset(struct drm_connector *connector)
  	struct drm_bridge_connector *bridge_connector =
  		to_drm_bridge_connector(connector);
 
  	drm_atomic_helper_connector_reset(connector);
  	if (bridge_connector->bridge_hdmi)
-		__drm_atomic_helper_connector_hdmi_reset(connector,
-							 connector->state);
+		__drm_atomic_helper_connector_hdmi_state_init(connector,
+							      connector->state);
  }
 
  static const struct drm_connector_funcs drm_bridge_connector_funcs = {
  	.reset = drm_bridge_connector_reset,
  	.detect = drm_bridge_connector_detect,
drivers/gpu/drm/display/drm_hdmi_state_helper.c +8 -6
index a1d16762ac7a9ebdc48f081c5d2f5e200d406099..cdd6df37c04a4b2073004ea08a3f5283a56692df 100644
@@ -304,29 +304,31 @@
   *		--kunitconfig=drivers/gpu/drm/tests \
   *		drm_atomic_helper_connector_hdmi_*
   */
 
  /**
- * __drm_atomic_helper_connector_hdmi_reset() - Initializes all HDMI @drm_connector_state resources
+ * __drm_atomic_helper_connector_hdmi_state_init() - Initializes all HDMI @drm_connector_state resources
   * @connector: DRM connector
   * @new_conn_state: connector state to reset
   *
   * Initializes all HDMI resources from a @drm_connector_state without
   * actually allocating it. This is useful for HDMI drivers, in
- * combination with __drm_atomic_helper_connector_reset() or
- * drm_atomic_helper_connector_reset().
+ * combination with __drm_atomic_helper_connector_reset(),
+ * drm_atomic_helper_connector_reset(),
+ * __drm_atomic_helper_connector_create_state() or
+ * drm_atomic_helper_connector_create_state() .
   */
-void __drm_atomic_helper_connector_hdmi_reset(struct drm_connector *connector,
-					      struct drm_connector_state *new_conn_state)
+void __drm_atomic_helper_connector_hdmi_state_init(struct drm_connector *connector,
+						   struct drm_connector_state *new_conn_state)
  {
  	unsigned int max_bpc = connector->max_bpc;
 
  	new_conn_state->max_bpc = max_bpc;
  	new_conn_state->max_requested_bpc = max_bpc;
  	new_conn_state->hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
  }
-EXPORT_SYMBOL(__drm_atomic_helper_connector_hdmi_reset);
+EXPORT_SYMBOL(__drm_atomic_helper_connector_hdmi_state_init);
 
  static const struct drm_display_mode *
  connector_state_get_mode(const struct drm_connector_state *conn_state)
  {
  	struct drm_atomic_state *state;
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +1 -1
index a50f260c73e41493528e545591aaad0e3f138be2..0ebebb04e68fab5b7938a604f85ad9b756fe33f6 100644
@@ -283,11 +283,11 @@ sun4i_hdmi_connector_detect(struct drm_connector *connector, bool force)
  }
 
  static void sun4i_hdmi_connector_reset(struct drm_connector *connector)
  {
  	drm_atomic_helper_connector_reset(connector);
-	__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
+	__drm_atomic_helper_connector_hdmi_state_init(connector, connector->state);
  }
 
  static const struct drm_connector_funcs sun4i_hdmi_connector_funcs = {
  	.detect			= sun4i_hdmi_connector_detect,
  	.fill_modes		= drm_helper_probe_single_connector_modes,
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +1 -1
index 4bdcea3c7435146aebb1716f38d7302ddb7c6296..aaa73b75f3ce5010147f48afc365d074bb2ec7a7 100644
@@ -166,11 +166,11 @@ static const struct drm_connector_helper_funcs dummy_connector_helper_funcs = {
  };
 
  static void dummy_hdmi_connector_reset(struct drm_connector *connector)
  {
  	drm_atomic_helper_connector_reset(connector);
-	__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
+	__drm_atomic_helper_connector_hdmi_state_init(connector, connector->state);
  }
 
  static const struct drm_connector_funcs dummy_connector_funcs = {
  	.atomic_destroy_state	= drm_atomic_helper_connector_destroy_state,
  	.atomic_duplicate_state	= drm_atomic_helper_connector_duplicate_state,
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index 9898e5451a07a1dca809fb6db3fec59d07485b95..f59d0877a5f48bed6b421775da7ddd008d68f9d9 100644
@@ -506,11 +506,11 @@ static int vc4_hdmi_connector_atomic_check(struct drm_connector *connector,
  }
 
  static void vc4_hdmi_connector_reset(struct drm_connector *connector)
  {
  	drm_atomic_helper_connector_reset(connector);
-	__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
+	__drm_atomic_helper_connector_hdmi_state_init(connector, connector->state);
  	drm_atomic_helper_connector_tv_margins_reset(connector);
  }
 
  static const struct drm_connector_funcs vc4_hdmi_connector_funcs = {
  	.force = drm_atomic_helper_connector_hdmi_force,
include/drm/display/drm_hdmi_state_helper.h +2 -2
index 2349c0d0f00fb468167023d4db2055c70e603bcd..f7600aabdd5f066772a9a82a1fa8a00be7a48396 100644
@@ -9,12 +9,12 @@ struct drm_connector_state;
  struct drm_display_mode;
  struct hdmi_audio_infoframe;
 
  enum drm_connector_status;
 
-void __drm_atomic_helper_connector_hdmi_reset(struct drm_connector *connector,
-					      struct drm_connector_state *new_conn_state);
+void __drm_atomic_helper_connector_hdmi_state_init(struct drm_connector *connector,
+						   struct drm_connector_state *new_conn_state);
 
  int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector,
  					   struct drm_atomic_state *state);
 
  int drm_atomic_helper_connector_hdmi_update_audio_infoframe(struct drm_connector *connector,
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Reviewed-by on v2 12/20
#30 lore raw

Re: [PATCH v2 12/20] drm/hdmi: Rename __drm_atomic_helper_connector_hdmi_reset()

In reply to Maxime Ripard
Quoted 17 lines · Maxime Ripard

__drm_atomic_helper_connector_hdmi_reset() is typically used to initialize a newly allocated drm_connector_state when the connector is using the HDMI helpers, and is being called by the drm_connector_funcs.reset implementation.

Since we want to consolidate DRM objects state allocation around the atomic_create_state callback that will only allocate and initialize a new drm_connector_state instance, we will need to call __drm_atomic_helper_connector_hdmi_reset() from both the reset and atomic_create hooks.

To avoid any confusion, we can thus rename
__drm_atomic_helper_connector_hdmi_reset() to
__drm_atomic_helper_connector_hdmi_state_init().

Quoted 9 lines
---
 drivers/gpu/drm/display/drm_bridge_connector.c     |  4 ++--
 drivers/gpu/drm/display/drm_hdmi_state_helper.c    | 14 ++++++++------
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c             |  2 +-
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c |  2 +-
 drivers/gpu/drm/vc4/vc4_hdmi.c                     |  2 +-
 include/drm/display/drm_hdmi_state_helper.h        |  4 ++--
 6 files changed, 15 insertions(+), 13 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#31 lore raw

PATCH v2 13/20 drm/connector: Add new atomic_create_state callback

In reply to Maxime Ripard

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software tate, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect:
atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with connectors.

---
 drivers/gpu/drm/drm_atomic_state_helper.c | 45 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_mode_config.c         | 21 ++++++++++++++-
 include/drm/drm_atomic_state_helper.h     |  4 +++
 include/drm/drm_connector.h               | 13 +++++++++
 4 files changed, 82 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +45 -0
index 8ed8cb8a9048e8fd89fa22d20985c84af1672135..c7eb3ce8c282a0d1099bdb840653baa9f2005db5 100644
@@ -553,10 +553,29 @@ __drm_atomic_helper_connector_reset(struct drm_connector *connector,
 
 	connector->state = conn_state;
 }
 EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
 
+/**
+ * __drm_atomic_helper_connector_create_state - initializes connector state
+ * @connector: connector object
+ * @state: new state to initialize
+ *
+ * Initializes the newly allocated @state, usually required when
+ * initializing the drivers.
+ *
+ * @state is assumed to be zeroed.
+ *
+ * This is useful for drivers that subclass @drm_connector_state.
+ */
+void __drm_atomic_helper_connector_create_state(struct drm_connector *connector,
+						struct drm_connector_state *state)
+{
+	__drm_atomic_helper_connector_state_init(state, connector);
+}
+EXPORT_SYMBOL(__drm_atomic_helper_connector_create_state);
+
 /**
  * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors
  * @connector: drm connector
  *
  * Resets the atomic state for @connector by freeing the state pointer (which
@@ -573,10 +592,36 @@ void drm_atomic_helper_connector_reset(struct drm_connector *connector)
 	kfree(connector->state);
 	__drm_atomic_helper_connector_reset(connector, conn_state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
 
+/**
+ * drm_atomic_helper_connector_create_state - default &drm_connector_funcs.atomic_create_state hook for connectors
+ * @connector: connector object
+ *
+ * Initializes a pristine @drm_connector_state.
+ *
+ * This is useful for drivers that don't subclass @drm_connector_state.
+ *
+ * RETURNS:
+ * Pointer to new connector state, or ERR_PTR on failure.
+ */
+struct drm_connector_state *
+drm_atomic_helper_connector_create_state(struct drm_connector *connector)
+{
+	struct drm_connector_state *state;
+
+	state = kzalloc_obj(*state);
+	if (!state)
+		return ERR_PTR(-ENOMEM);
+
+	__drm_atomic_helper_connector_create_state(connector, state);
+
+	return state;
+}
+EXPORT_SYMBOL(drm_atomic_helper_connector_create_state);
+
 /**
  * drm_atomic_helper_connector_tv_margins_reset - Resets TV connector properties
  * @connector: DRM connector
  *
  * Resets the TV-related properties attached to a connector.
drivers/gpu/drm/drm_mode_config.c +20 -1
index f5092d03b168bb114a199b1dbcaeb770983c9749..124cef8f0c6eb15c9fde4cf7cee2936cbf2b902f 100644
@@ -212,10 +212,26 @@ static int drm_mode_config_crtc_create_state(struct drm_crtc *crtc)
 	crtc->state = crtc_state;
 
 	return 0;
 }
 
+static int drm_mode_config_connector_create_state(struct drm_connector *connector)
+{
+	struct drm_connector_state *conn_state;
+
+	if (!connector->funcs->atomic_create_state)
+		return 0;
+
+	conn_state = connector->funcs->atomic_create_state(connector);
+	if (IS_ERR(conn_state))
+		return PTR_ERR(conn_state);
+
+	connector->state = conn_state;
+
+	return 0;
+}
+
 /**
  * drm_mode_config_reset - call ->reset callbacks
  * @dev: drm device
  *
  * This functions calls all the crtc's, encoder's and connector's ->reset
@@ -255,13 +271,16 @@ void drm_mode_config_reset(struct drm_device *dev)
 	drm_for_each_encoder(encoder, dev)
 		if (encoder->funcs && encoder->funcs->reset)
 			encoder->funcs->reset(encoder);
 
 	drm_connector_list_iter_begin(dev, &conn_iter);
-	drm_for_each_connector_iter(connector, &conn_iter)
+	drm_for_each_connector_iter(connector, &conn_iter) {
 		if (connector->funcs->reset)
 			connector->funcs->reset(connector);
+		else if (connector->funcs->atomic_create_state)
+			drm_mode_config_connector_create_state(connector);
+	}
 	drm_connector_list_iter_end(&conn_iter);
 }
 EXPORT_SYMBOL(drm_mode_config_reset);
 
 /*
include/drm/drm_atomic_state_helper.h +4 -0
index 259a39a0f41ddb2b7d6c1fe7c1a2b0b51774254c..96a058ba698203c023e54c2b3d908c13cfa2d23b 100644
@@ -76,11 +76,15 @@ void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
 
 void __drm_atomic_helper_connector_state_init(struct drm_connector_state *conn_state,
 					       struct drm_connector *connector);
 void __drm_atomic_helper_connector_reset(struct drm_connector *connector,
 					 struct drm_connector_state *conn_state);
+void __drm_atomic_helper_connector_create_state(struct drm_connector *connector,
+						struct drm_connector_state *state);
 void drm_atomic_helper_connector_reset(struct drm_connector *connector);
+struct drm_connector_state *
+drm_atomic_helper_connector_create_state(struct drm_connector *connector);
 void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector);
 int drm_atomic_helper_connector_tv_check(struct drm_connector *connector,
 					 struct drm_atomic_state *state);
 void drm_atomic_helper_connector_tv_margins_reset(struct drm_connector *connector);
 void
include/drm/drm_connector.h +13 -0
index c18be8c19de0ab1e02e7d7b1fcd9f2ab5ef1dd15..6d73068de157144770931c64ce3f91e6f15ef0e4 100644
@@ -1509,10 +1509,23 @@ struct drm_connector_funcs {
 	 * when a connector is being hot-unplugged for drivers that support
 	 * connector hotplugging (e.g. DisplayPort MST).
 	 */
 	void (*destroy)(struct drm_connector *connector);
 
+	/**
+	 * @atomic_create_state:
+	 *
+	 * Allocates a pristine, initialized, state for the connector object
+	 * and returns it.
+	 *
+	 * RETURNS:
+	 *
+	 * A new, pristine, connector state instance or an error pointer
+	 * on failure.
+	 */
+	struct drm_connector_state *(*atomic_create_state)(struct drm_connector *connector);
+
 	/**
 	 * @atomic_duplicate_state:
 	 *
 	 * Duplicate the current atomic state for this connector and return it.
 	 * The core and helpers guarantee that any atomic state duplicated with
Signature · 1 line
2.53.0
Reviewed-by on v2 13/20
#32 lore raw

Re: [PATCH v2 13/20] drm/connector: Add new atomic_create_state callback

Quoted 32 lines · Maxime Ripard

Commit 47b5ac7daa46 ("drm/atomic: Add new atomic_create_state callback to drm_private_obj") introduced a new pattern for allocating drm object states.

Instead of relying on the reset() callback, it created a new atomic_create_state hook. This is helpful because reset is a bit
overloaded: it's used to create the initial software tate, reset it, but also reset the hardware.

It can also be used either at probe time, to create the initial state and possibly reset the hardware to an expected default, but also during suspend/resume.

Both these cases come with different expectations too: during the initialization, we want to initialize all states, but during suspend/resume, drm_private_states for example are expected to be kept around.

And reset() isn't fallible, which makes it harder to handle initialization errors properly.

And this is only really relevant for some drivers, since all the helpers for reset only create a new state, and don't touch the hardware at all.

It was thus decided to create a new hook that would allocate and initialize a pristine state without any side effect:
atomic_create_state to untangle a bit some of it, and to separate the initialization with the actual reset one might need during a suspend/resume.

Let's continue the transition to the new pattern with connectors.

Quoted 8 lines
---
 drivers/gpu/drm/drm_atomic_state_helper.c | 45 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_mode_config.c         | 21 ++++++++++++++-
 include/drm/drm_atomic_state_helper.h     |  4 +++
 include/drm/drm_connector.h               | 13 +++++++++
 4 files changed, 82 insertions(+), 1 deletion(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#33 lore raw

PATCH v2 14/20 drm/mode-config: Create drm_mode_config_create_state()

In reply to Maxime Ripard

drm_mode_config_reset() can be used to create the initial state, but also to return to the initial state, when doing a suspend/resume cycle for example.

It also affects both the software and the hardware, and drivers can choose to reset the hardware as well. Most will just create an empty state and the synchronisation between hardware and software states will effectively be done when the first commit is done.

That dual role can be harmful, since some objects do need to be initialized but also need to be preserved across a suspend/resume cycle. drm_private_obj are such objects for example.

Thus, let's create another helper for drivers to call to initialize their state when the driver is loaded, so we can make drm_mode_config_reset() only about handling suspend/resume and similar.

---
 drivers/gpu/drm/drm_atomic.c      | 12 +++++-
 drivers/gpu/drm/drm_mode_config.c | 87 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_mode_config.h     |  1 +
 3 files changed, 98 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic.c +10 -2
index 253a00f450b0fb1b7eb6ea42b3235fbf9ee78376..5aa3f9f0620bd155dd53023e6c76e3883ffaadef 100644
@@ -59,12 +59,20 @@
  * when preparing the update and kept alive as long as they are active
  * in the device.
  *
  * Their respective lifetimes are:
  *
- * - at reset time, the object reset implementation will allocate a new
- *   default state and will store it in the object state pointer.
+ * - at driver initialization time, the driver will allocate an initial,
+ *   pristine, state and will store it using
+ *   drm_mode_config_create_state(). Historically, this was one of
+ *   drm_mode_config_reset() job, so one might still encounter it in a
+ *   driver.
+ *
+ * - at reset time, for example during suspend/resume,
+ *   drm_mode_config_reset() will reset the software and hardware state
+ *   to a known default and will store it in the object's state pointer.
+ *   Not all objects are affected by drm_mode_config_reset() though.
  *
  * - whenever a new update is needed:
  *
  *   + A new &struct drm_atomic_state is allocated using
  *     drm_atomic_state_alloc().
drivers/gpu/drm/drm_mode_config.c +87 -0

107 lines not on this page · raw message

include/drm/drm_mode_config.h +1 -0
index 687c0ee163d25dfa7cf563e77209dd33e349800b..22c7e767a2e98f99fff9311eb590f62bd4c9c8a9 100644
@@ -1005,9 +1005,10 @@ int __must_check drmm_mode_config_init(struct drm_device *dev);
 static inline int drm_mode_config_init(struct drm_device *dev)
 {
 	return drmm_mode_config_init(dev);
 }
 
+int drm_mode_config_create_state(struct drm_device *dev);
 void drm_mode_config_reset(struct drm_device *dev);
 void drm_mode_config_cleanup(struct drm_device *dev);
 
 #endif
Signature · 1 line
2.53.0
Reviewed-by on v2 14/20
#34 lore raw

Re: [PATCH v2 14/20] drm/mode-config: Create drm_mode_config_create_state()

Quoted 17 lines · Maxime Ripard

drm_mode_config_reset() can be used to create the initial state, but also to return to the initial state, when doing a suspend/resume cycle for example.

It also affects both the software and the hardware, and drivers can choose to reset the hardware as well. Most will just create an empty state and the synchronisation between hardware and software states will effectively be done when the first commit is done.

That dual role can be harmful, since some objects do need to be initialized but also need to be preserved across a suspend/resume cycle. drm_private_obj are such objects for example.

Thus, let's create another helper for drivers to call to initialize their state when the driver is loaded, so we can make drm_mode_config_reset() only about handling suspend/resume and similar.

Quoted 7 lines
---
 drivers/gpu/drm/drm_atomic.c      | 12 +++++-
 drivers/gpu/drm/drm_mode_config.c | 87 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_mode_config.h     |  1 +
 3 files changed, 98 insertions(+), 2 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#35 lore raw

PATCH v2 15/20 drm/drv: Call drm_mode_config_create_state() by default

In reply to Maxime Ripard

Almost all drivers, and our documented skeleton, call drm_mode_config_reset() prior to calling drm_dev_register() to initialize its DRM object states.

Now that we have drm_mode_config_create_state() to create that initial state if it doesn't exist, we can call it directly in drm_dev_register(). That way, we know that the initial atomic state will always be allocated without any boilerplate.

---
 drivers/gpu/drm/drm_drv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_drv.c +4 -0
index 2915118436ce8a6640cfb0c59936031990727ed1..820106d56ab399a39cac56d98662b5ddbcae8ded 100644
@@ -1097,10 +1097,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 
 	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
 		ret = drm_modeset_register_all(dev);
 		if (ret)
 			goto err_unload;
+
+		ret = drm_mode_config_create_state(dev);
+		if (ret)
+			goto err_unload;
 	}
 	drm_panic_register(dev);
 	drm_client_sysrq_register(dev);
 
 	DRM_INFO("Initialized %s %d.%d.%d for %s on minor %d\n",
Signature · 1 line
2.53.0
#36 lore raw

Re: [PATCH v2 15/20] drm/drv: Call drm_mode_config_create_state() by default

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 19 lines

Almost all drivers, and our documented skeleton, call drm_mode_config_reset() prior to calling drm_dev_register() to initialize its DRM object states.

Now that we have drm_mode_config_create_state() to create that initial state if it doesn't exist, we can call it directly in drm_dev_register(). That way, we know that the initial atomic state will always be allocated without any boilerplate.

---
  drivers/gpu/drm/drm_drv.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_drv.c +0 -0
index 2915118436ce8a6640cfb0c59936031990727ed1..820106d56ab399a39cac56d98662b5ddbcae8ded 100644

drivers/gpu/drm/drm_drv.c int drm_dev_register(struct drm_device *dev, unsigned long flags) · line 1105

Quoted 9 lines
drivers/gpu/drm/drm_drv.c +4 -0
@@ -1097,10 +1097,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 
  	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  		ret = drm_modeset_register_all(dev);
  		if (ret)
  			goto err_unload;
+
+		ret = drm_mode_config_create_state(dev);
+		if (ret)
+			goto err_unload;

Way too late. Lets rather go through drivers and call this where they currently call drm_mode_config_reset() for initialization. This can be a single-patch mass conversion IMHO.

Best regards
Thomas

Quoted 6 lines
drivers/gpu/drm/drm_drv.c +0 -0
  	}
  	drm_panic_register(dev);
  	drm_client_sysrq_register(dev);
 
  	DRM_INFO("Initialized %s %d.%d.%d for %s on minor %d\n",
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#37 lore raw

Re: [PATCH v2 15/20] drm/drv: Call drm_mode_config_create_state() by default

Am 21.04.26 um 15:38 schrieb Thomas Zimmermann:

Quoted 17 lines

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 14 lines

Almost all drivers, and our documented skeleton, call drm_mode_config_reset() prior to calling drm_dev_register() to initialize its DRM object states.

Now that we have drm_mode_config_create_state() to create that initial state if it doesn't exist, we can call it directly in drm_dev_register(). That way, we know that the initial atomic state will always be allocated without any boilerplate.

---
  drivers/gpu/drm/drm_drv.c | 4 ++++

  1 file changed, 4 insertions(+)
Quoted 16 lines
Quoted 5 lines
drivers/gpu/drm/drm_drv.c +0 -0
index 2915118436ce8a6640cfb0c59936031990727ed1..820106d56ab399a39cac56d98662b5ddbcae8ded 100644

drivers/gpu/drm/drm_drv.c int drm_dev_register(struct drm_device *dev, · line 1105

Quoted 9 lines
drivers/gpu/drm/drm_drv.c +4 -0
@@ -1097,10 +1097,14 @@ int drm_dev_register(struct drm_device *dev, 
 unsigned long flags)
         if (drm_core_check_feature(dev, DRIVER_MODESET)) {
           ret = drm_modeset_register_all(dev);
           if (ret)
               goto err_unload;
+
+        ret = drm_mode_config_create_state(dev);
+        if (ret)
+            goto err_unload;

Way too late. Lets rather go through drivers and call this where they currently call drm_mode_config_reset() for initialization. This can be a single-patch mass conversion IMHO.

On a second thought, can't we modify the suspend code and leave the reset as-is for now?  I'd still be interested to use reset as a means of initializing the hardware or loading state on probe. So keeping the _reset() calls in place might be helpful for that.

What's the long-term plan here?

Best regards
Thomas

Quoted 10 lines

Best regards
Thomas

Quoted 5 lines
drivers/gpu/drm/drm_drv.c +0 -0
       }
       drm_panic_register(dev);
       drm_client_sysrq_register(dev);
         DRM_INFO("Initialized %s %d.%d.%d for %s on minor %d\n",
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#38 lore raw

Re: [PATCH v2 15/20] drm/drv: Call drm_mode_config_create_state() by default

Quoted 40 lines · Thomas Zimmermann

Am 21.04.26 um 15:38 schrieb Thomas Zimmermann:

Quoted 28 lines

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 25 lines

Almost all drivers, and our documented skeleton, call drm_mode_config_reset() prior to calling drm_dev_register() to initialize its DRM object states.

Now that we have drm_mode_config_create_state() to create that initial state if it doesn't exist, we can call it directly in drm_dev_register(). That way, we know that the initial atomic state will always be allocated without any boilerplate.

---
  drivers/gpu/drm/drm_drv.c | 4 ++++

  1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_drv.c +0 -0
index 2915118436ce8a6640cfb0c59936031990727ed1..820106d56ab399a39cac56d98662b5ddbcae8ded

100644

drivers/gpu/drm/drm_drv.c +0 -0
@@ -1097,10 +1097,14 @@ int drm_dev_register(struct drm_device *dev,
 unsigned long flags)
         if (drm_core_check_feature(dev, DRIVER_MODESET)) {
           ret = drm_modeset_register_all(dev);
           if (ret)
               goto err_unload;
Quoted 8 lines

drivers/gpu/drm/drm_drv.c int drm_dev_register(struct drm_device *dev, unsigned long flags) · line 1105

Quoted 4 lines
drivers/gpu/drm/drm_drv.c +4 -0
+
+        ret = drm_mode_config_create_state(dev);
+        if (ret)
+            goto err_unload;

Way too late. Lets rather go through drivers and call this where they currently call drm_mode_config_reset() for initialization. This can be a single-patch mass conversion IMHO.

Quoted 4 lines

On a second thought, can't we modify the suspend code and leave the reset as-is for now?  I'd still be interested to use reset as a means of initializing the hardware or loading state on probe. So keeping the _reset() calls in place might be helpful for that.

But isn't it the expected behaviour? The driver can reset(), but if it didn't, the default would be to create empty working state. In the end, the drivers also can call this function to create the state, don't they (and then perform the readout logic)?

Quoted 26 lines

What's the long-term plan here?

Best regards
Thomas

Quoted 10 lines

Best regards
Thomas

Quoted 5 lines
drivers/gpu/drm/drm_drv.c +0 -0
       }
       drm_panic_register(dev);
       drm_client_sysrq_register(dev);
         DRM_INFO("Initialized %s %d.%d.%d for %s on minor %d\n",
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#39 lore raw

Re: [PATCH v2 15/20] drm/drv: Call drm_mode_config_create_state() by default

In reply to Thomas Zimmermann

Hi Thomas,

Quoted 37 lines · Thomas Zimmermann

Am 21.04.26 um 15:38 schrieb Thomas Zimmermann:

Quoted 36 lines

Hi

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 20 lines

Almost all drivers, and our documented skeleton, call drm_mode_config_reset() prior to calling drm_dev_register() to initialize its DRM object states.

Now that we have drm_mode_config_create_state() to create that initial state if it doesn't exist, we can call it directly in drm_dev_register(). That way, we know that the initial atomic state will always be allocated without any boilerplate.

---
  drivers/gpu/drm/drm_drv.c | 4 ++++

  1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_drv.c +0 -0
index 2915118436ce8a6640cfb0c59936031990727ed1..820106d56ab399a39cac56d98662b5ddbcae8ded

100644

drivers/gpu/drm/drm_drv.c int drm_dev_register(struct drm_device *dev, · line 1105

Quoted 9 lines
drivers/gpu/drm/drm_drv.c +4 -0
@@ -1097,10 +1097,14 @@ int drm_dev_register(struct drm_device *dev,
 unsigned long flags)
         if (drm_core_check_feature(dev, DRIVER_MODESET)) {
           ret = drm_modeset_register_all(dev);
           if (ret)
               goto err_unload;
+
+        ret = drm_mode_config_create_state(dev);
+        if (ret)
+            goto err_unload;

Way too late. Lets rather go through drivers and call this where they currently call drm_mode_config_reset() for initialization. This can be a single-patch mass conversion IMHO.

I think that was Ville's main objection too. He suggested to do it in the object initialization instead, but I believe it would be too early.

Quoted 6 lines

On a second thought, can't we modify the suspend code and leave the reset as-is for now?  I'd still be interested to use reset as a means of initializing the hardware or loading state on probe. So keeping the _reset() calls in place might be helpful for that.

What's the long-term plan here?

So, the way I was thinking about this is reset is done for several things right now: initial state creation and software reset, and hardware reset.

The latter isn't really commonly used. Most drivers, basically all drivers that use the reset helpers, will not perform the hardware reset as part of drm_mode_config_reset but will do it in probe or similar.

This is also a concern for hardware state read-out, since you don't want that reset to happen.

So, eventually, I wanted to have something like try a readout, and if it fails for any reason (disabled, unsupported, or failing to perform the readout), we fallback to allocating a pristine state + resetting the hardware.

To do that, we need create_state introduced here both for the readout and non-readout paths, but also a (possibly device wide?) hw_reset hook that will *only* reset the device without affecting the software state.

So:
- probe with readout would be create_state + readout_state for all objects
- probe without readout would be create_state + hw_reset for all objects
- resume would be create_state + hw_reset for a limited number of objects

And then we don't need .reset at all anymore and / or can implement drm_mode_config_reset() on top of that.

I wanted to work on that next when done with this series.

Maxime

author maintainer
#40 lore raw

Re: [PATCH v2 15/20] drm/drv: Call drm_mode_config_create_state() by default

In reply to Thomas Zimmermann

Hi,

Quoted 15 lines · Thomas Zimmermann

Am 20.03.26 um 17:27 schrieb Maxime Ripard:

Quoted 14 lines

Almost all drivers, and our documented skeleton, call drm_mode_config_reset() prior to calling drm_dev_register() to initialize its DRM object states.

Now that we have drm_mode_config_create_state() to create that initial state if it doesn't exist, we can call it directly in drm_dev_register(). That way, we know that the initial atomic state will always be allocated without any boilerplate.

---
  drivers/gpu/drm/drm_drv.c | 4 ++++
  1 file changed, 4 insertions(+)
Quoted 15 lines

drivers/gpu/drm/drm_drv.c int drm_dev_register(struct drm_device *dev, unsigned long flags) · line 1104

Quoted 13 lines
drivers/gpu/drm/drm_drv.c +4 -0
index 2915118436ce8a6640cfb0c59936031990727ed1..820106d56ab399a39cac56d98662b5ddbcae8ded 100644
@@ -1097,10 +1097,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
  	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  		ret = drm_modeset_register_all(dev);
  		if (ret)
  			goto err_unload;
+
+		ret = drm_mode_config_create_state(dev);
+		if (ret)
+			goto err_unload;

Way too late.

Yeah... I think that was Ville's main objection too.

Quoted 2 lines

Lets rather go through drivers and call this where they currently call drm_mode_config_reset() for initialization.

I was really hoping to remove the boilerplate from drivers, but I don't really see a good place for it then. drm_mode_config_init() could be another candidate, but it looks weird to put it there too.

I'll drop that then.

Quoted 1 line

This can be a single-patch mass conversion IMHO.

I'm not really sure? For it to work we'd need to convert these drivers objects from reset to atomic_create_state too. I absolutely want to do it next, but I don't think it will be as trivial as a sed call, and it would probably be best done by driver to allow reverts if we screw up.

Maxime

author maintainer
#41 lore raw

PATCH v2 16/20 drm/atomic: Drop private obj state allocation

In reply to Maxime Ripard

Now that drm_dev_register() calls drm_mode_config_create_state() for every modeset driver, the private obj states will be initialized at driver registration automatically if they haven't already.

Thus, the explicit initial allocation we have in drm_atomic_private_obj_init() is now redundant, and we can remove it.

---
 drivers/gpu/drm/drm_atomic.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/drm_atomic.c +0 -7
index 5aa3f9f0620bd155dd53023e6c76e3883ffaadef..3bd52602fe307a1b82a3b68d82b458e1da8a4f6d 100644
@@ -995,25 +995,18 @@ static void drm_atomic_plane_print_state(struct drm_printer *p,
  */
 int drm_atomic_private_obj_init(struct drm_device *dev,
 				struct drm_private_obj *obj,
 				const struct drm_private_state_funcs *funcs)
 {
-	struct drm_private_state *state;
 	memset(obj, 0, sizeof(*obj));
 
 	drm_modeset_lock_init(&obj->lock);
 
 	obj->dev = dev;
 	obj->funcs = funcs;
 	list_add_tail(&obj->head, &dev->mode_config.privobj_list);
 
-	state = obj->funcs->atomic_create_state(obj);
-	if (IS_ERR(state))
-		return PTR_ERR(state);
-
-	obj->state = state;
-
 	return 0;
 }
 EXPORT_SYMBOL(drm_atomic_private_obj_init);
 
 /**
Signature · 1 line
2.53.0
Reviewed-by on v2 16/20
#42 lore raw

Re: [PATCH v2 16/20] drm/atomic: Drop private obj state allocation

Quoted 4 lines · Maxime Ripard

Now that drm_dev_register() calls drm_mode_config_create_state() for every modeset driver, the private obj states will be initialized at driver registration automatically if they haven't already.

Quoted 9 lines

Thus, the explicit initial allocation we have in drm_atomic_private_obj_init() is now redundant, and we can remove it.

---
 drivers/gpu/drm/drm_atomic.c | 7 -------
 1 file changed, 7 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
author maintainer
#43 lore raw

PATCH v2 17/20 drm/drv: Drop drm_mode_config_reset() from our skeleton

In reply to Maxime Ripard

Now that we have drm_mode_config_create_state() to create the initial state called as part of drm_dev_register(), we can stop recommending calling drm_mode_config_reset() to perform that initialization in our skeleton.

---
 drivers/gpu/drm/drm_drv.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -2
index 820106d56ab399a39cac56d98662b5ddbcae8ded..83752725f7c63364880225ec1083f19bd00ddcef 100644
@@ -339,12 +339,10 @@ void drm_minor_release(struct drm_minor *minor)
  *
  *		// Further setup, display pipeline etc
  *
  *		platform_set_drvdata(pdev, drm);
  *
- *		drm_mode_config_reset(drm);
- *
  *		ret = drm_dev_register(drm);
  *		if (ret)
  *			return ret;
  *
  *		drm_fbdev_{...}_setup(drm, 32);
Signature · 1 line
2.53.0
author maintainer
#44 lore raw

PATCH v2 18/20 drm/tidss: Drop call to drm_mode_config_reset at probe time

In reply to Maxime Ripard

Now that we have drm_mode_config_create_state() to create the initial state called as part of drm_dev_register(), we don't need to call drm_mode_config_reset() during the driver probe.

---
 drivers/gpu/drm/tidss/tidss_drv.c | 2 --
 drivers/gpu/drm/tidss/tidss_kms.c | 2 --
 2 files changed, 4 deletions(-)
drivers/gpu/drm/tidss/tidss_drv.c +0 -2
index 1c8cc18bc53c3ea3c50368b9f55ab02a0a02fc77..ddd9f428c2a96557ee02040320cbe5f6f0fd6052 100644
@@ -169,12 +169,10 @@ static int tidss_probe(struct platform_device *pdev)
 		goto err_runtime_suspend;
 	}
 
 	drm_kms_helper_poll_init(ddev);
 
-	drm_mode_config_reset(ddev);
-
 	ret = drm_dev_register(ddev, 0);
 	if (ret) {
 		dev_err(dev, "failed to register DRM device\n");
 		goto err_irq_uninstall;
 	}
drivers/gpu/drm/tidss/tidss_kms.c +0 -2
index 8bb93194e5ac686050c47f986b8cb6063eae22d3..b4779c09a1bfa5be7010bcd7d4f1379362996d2e 100644
@@ -285,11 +285,9 @@ int tidss_modeset_init(struct tidss_device *tidss)
 
 	ret = drm_vblank_init(ddev, tidss->num_crtcs);
 	if (ret)
 		return ret;
 
-	drm_mode_config_reset(ddev);
-
 	dev_dbg(tidss->dev, "%s done\n", __func__);
 
 	return 0;
 }
Signature · 1 line
2.53.0
author maintainer
#45 lore raw

PATCH v2 19/20 drm/tidss: Convert to atomic_create_state

In reply to Maxime Ripard

Our driver uses reset to create the various object states, but only calls the helper that allocate a new state. They are thus strictly equivalent to the new atomic_create_state helpers, so let's switch to these.

---
 drivers/gpu/drm/tidss/tidss_crtc.c  | 17 +++++++----------
 drivers/gpu/drm/tidss/tidss_plane.c |  2 +-
 2 files changed, 8 insertions(+), 11 deletions(-)
drivers/gpu/drm/tidss/tidss_crtc.c +7 -10
index a31c21c5f855ac8a94089dd3908e2510193b7d67..66e3d161c60bc14b2982cff4cdd43030d4086798 100644
@@ -355,24 +355,21 @@ static void tidss_crtc_destroy_state(struct drm_crtc *crtc,
 
 	__drm_atomic_helper_crtc_destroy_state(&tstate->base);
 	kfree(tstate);
 }
 
-static void tidss_crtc_reset(struct drm_crtc *crtc)
+static struct drm_crtc_state *tidss_crtc_create_state(struct drm_crtc *crtc)
 {
 	struct tidss_crtc_state *tstate;
 
-	if (crtc->state)
-		tidss_crtc_destroy_state(crtc, crtc->state);
-
 	tstate = kzalloc_obj(*tstate);
-	if (!tstate) {
-		crtc->state = NULL;
-		return;
-	}
+	if (!tstate)
+		return ERR_PTR(-ENOMEM);
 
-	__drm_atomic_helper_crtc_reset(crtc, &tstate->base);
+	__drm_atomic_helper_crtc_create_state(crtc, &tstate->base);
+
+	return &tstate->base;
 }
 
 static struct drm_crtc_state *tidss_crtc_duplicate_state(struct drm_crtc *crtc)
 {
 	struct tidss_crtc_state *state, *current_state;
@@ -403,14 +400,14 @@ static void tidss_crtc_destroy(struct drm_crtc *crtc)
 	drm_crtc_cleanup(crtc);
 	kfree(tcrtc);
 }
 
 static const struct drm_crtc_funcs tidss_crtc_funcs = {
-	.reset = tidss_crtc_reset,
 	.destroy = tidss_crtc_destroy,
 	.set_config = drm_atomic_helper_set_config,
 	.page_flip = drm_atomic_helper_page_flip,
+	.atomic_create_state = tidss_crtc_create_state,
 	.atomic_duplicate_state = tidss_crtc_duplicate_state,
 	.atomic_destroy_state = tidss_crtc_destroy_state,
 	.enable_vblank = tidss_crtc_enable_vblank,
 	.disable_vblank = tidss_crtc_disable_vblank,
 };
drivers/gpu/drm/tidss/tidss_plane.c +1 -1
index aaa02c851c595aa3781ec2e6741af1999092aa40..518498d4576528a0ec59fd03cf27a87b1b3f1e6e 100644
@@ -176,12 +176,12 @@ static const struct drm_plane_helper_funcs tidss_primary_plane_helper_funcs = {
 };
 
 static const struct drm_plane_funcs tidss_plane_funcs = {
 	.update_plane = drm_atomic_helper_update_plane,
 	.disable_plane = drm_atomic_helper_disable_plane,
-	.reset = drm_atomic_helper_plane_reset,
 	.destroy = drm_plane_destroy,
+	.atomic_create_state = drm_atomic_helper_plane_create_state,
 	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
 struct tidss_plane *tidss_plane_create(struct tidss_device *tidss,
Signature · 1 line
2.53.0
author maintainer
#46 lore raw

PATCH v2 20/20 drm/bridge_connector: Convert to atomic_create_state

In reply to Maxime Ripard

The connector created by drm_bridge_connector only initializes a pristine state in reset, which is equivalent to that atomic_create_state would expect. Let's convert to it.

---
 drivers/gpu/drm/display/drm_bridge_connector.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +11 -4
index 929f06b290626d2091418a6377a5230e3c264b60..b640e7d5a065d165a901bd73fc836afaab967dac 100644
@@ -263,26 +263,33 @@ static void drm_bridge_connector_debugfs_init(struct drm_connector *connector,
 		if (bridge->funcs->debugfs_init)
 			bridge->funcs->debugfs_init(bridge, root);
 	}
 }
 
-static void drm_bridge_connector_reset(struct drm_connector *connector)
+static struct drm_connector_state *
+drm_bridge_connector_create_state(struct drm_connector *connector)
 {
 	struct drm_bridge_connector *bridge_connector =
 		to_drm_bridge_connector(connector);
+	struct drm_connector_state *conn_state;
+
+	conn_state = drm_atomic_helper_connector_create_state(connector);
+	if (IS_ERR(conn_state))
+		return conn_state;
 
-	drm_atomic_helper_connector_reset(connector);
 	if (bridge_connector->bridge_hdmi)
 		__drm_atomic_helper_connector_hdmi_state_init(connector,
-							      connector->state);
+							      conn_state);
+
+	return conn_state;
 }
 
 static const struct drm_connector_funcs drm_bridge_connector_funcs = {
-	.reset = drm_bridge_connector_reset,
 	.detect = drm_bridge_connector_detect,
 	.force = drm_bridge_connector_force,
 	.fill_modes = drm_helper_probe_single_connector_modes,
+	.atomic_create_state = drm_bridge_connector_create_state,
 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 	.debugfs_init = drm_bridge_connector_debugfs_init,
 	.oob_hotplug_event = drm_bridge_connector_oob_hotplug_event,
 };
Signature · 1 line
2.53.0
Reviewed-by on v2 20/20
#47 lore raw

Re: [PATCH v2 20/20] drm/bridge_connector: Convert to atomic_create_state

Quoted 10 lines · Maxime Ripard

The connector created by drm_bridge_connector only initializes a pristine state in reset, which is equivalent to that atomic_create_state would expect. Let's convert to it.

---
 drivers/gpu/drm/display/drm_bridge_connector.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#48 lore raw

✗ Fi.CI.BUILD: failure for drm/atomic: Rework initial state allocation

In reply to Maxime Ripard
== Series Details ==

== Series Details ==

Series: drm/atomic: Rework initial state allocation
URL : https://patchwork.freedesktop.org/series/163608/
State : failure

== Summary ==

Error: patch https://patchwork.freedesktop.org/api/1.0/series/163608/revisions/1/mbox/ not applied
Applying: drm/colorop: Fix typos in the doc
Applying: drm/atomic: Drop drm_private_state.obj assignment from create_state
Applying: drm/mode-config: Mention drm_mode_config_reset() culprits
Applying: drm/colorop: Rename __drm_colorop_state_reset()
Applying: drm/colorop: Create drm_atomic_helper_colorop_create_state()
Applying: drm/atomic-state-helper: Fix __drm_atomic_helper_plane_reset() doc typo
Applying: drm/atomic-state-helper: Rename __drm_atomic_helper_plane_state_reset()
Applying: drm/plane: Add new atomic_create_state callback
Applying: drm/atomic-state-helper: Rename __drm_atomic_helper_crtc_state_reset()
Applying: drm/crtc: Add new atomic_create_state callback
Applying: drm/atomic-state-helper: Rename __drm_atomic_helper_connector_state_reset()
Applying: drm/hdmi: Rename __drm_atomic_helper_connector_hdmi_reset()
Applying: drm/connector: Add new atomic_create_state callback
Applying: drm/mode-config: Create drm_mode_config_create_state()
error: invalid object 100644 253a00f450b0fb1b7eb6ea42b3235fbf9ee78376 for 'drivers/gpu/drm/drm_atomic.c'
error: Repository lacks necessary blobs to fall back on 3-way merge.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0014 drm/mode-config: Create drm_mode_config_create_state()
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Build failed, no error log produced