[RFC,1/8] drm/bridge: Add atomic_sro_install_state hook

Message ID 20261122153032.2782768-2-dario.binacchi@amarulasolutions.com
State New
Headers
Series drm: State readout for the i.MX8MN display pipeline |

Commit Message

Dario Binacchi Nov. 22, 2026, 3:30 p.m. UTC
The CRTCs, planes, connectors and private objects can acquire the
resources needed to keep the hardware state active when a state read
out from the hardware is installed. Bridges can't, even though they
usually hold a runtime PM reference and track their enable state
while the pipeline is active.

Add the atomic_sro_install_state hook to the bridge funcs. It is
called only for the bridges of a pipeline that was read out as active.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 drivers/gpu/drm/drm_bridge.c | 41 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_bridge.h     | 20 ++++++++++++++++++
 2 files changed, 61 insertions(+)

-- 
2.43.0
  

Comments

Maxime Ripard Nov. 23, 2026, 10:45 a.m. UTC | #1
Hi,

Thanks a lot for looking into it :)

On Sun, Nov 22, 2026 at 04:30:01PM +0100, Dario Binacchi wrote:
> The CRTCs, planes, connectors and private objects can acquire the
> resources needed to keep the hardware state active when a state read
> out from the hardware is installed. Bridges can't, even though they
> usually hold a runtime PM reference and track their enable state
> while the pipeline is active.
> 
> Add the atomic_sro_install_state hook to the bridge funcs. It is
> called only for the bridges of a pipeline that was read out as active.
> 
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>

This is now part of the v9, so you won't need it

Maxime
  

Patch

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 81174015309f..f4b66a3b38fc 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -637,6 +637,46 @@  drm_bridge_atomic_readout_priv_state(struct drm_private_obj *obj,
 	return 0;
 }
 
+/* The connector and CRTC states are installed before the bridge ones */
+static bool drm_bridge_sro_pipeline_is_active(struct drm_bridge *bridge)
+{
+	struct drm_connector_list_iter conn_iter;
+	struct drm_connector *connector;
+	bool active = false;
+
+	drm_connector_list_iter_begin(bridge->dev, &conn_iter);
+	drm_for_each_connector_iter(connector, &conn_iter) {
+		struct drm_connector_state *conn_state = connector->state;
+
+		if (!conn_state || conn_state->best_encoder != bridge->encoder)
+			continue;
+
+		if (conn_state->crtc && conn_state->crtc->state)
+			active = conn_state->crtc->state->active;
+
+		break;
+	}
+	drm_connector_list_iter_end(&conn_iter);
+
+	return active;
+}
+
+static void
+drm_bridge_atomic_install_priv_state(struct drm_private_obj *obj,
+				     struct drm_private_state *priv_state)
+{
+	struct drm_bridge *bridge = drm_priv_to_bridge(obj);
+
+	if (!bridge->funcs->atomic_sro_install_state)
+		return;
+
+	if (!drm_bridge_sro_pipeline_is_active(bridge))
+		return;
+
+	bridge->funcs->atomic_sro_install_state(bridge,
+						drm_priv_to_bridge_state(priv_state));
+}
+
 static bool drm_bridge_atomic_compare_priv_state(struct drm_private_obj *obj,
 						 struct drm_printer *p,
 						 struct drm_private_state *a,
@@ -682,6 +722,7 @@  static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = {
 static const struct drm_private_state_funcs drm_bridge_priv_state_funcs_with_sro = {
 	.atomic_sro_compare_state = drm_bridge_atomic_compare_priv_state,
 	.atomic_sro_readout_state = drm_bridge_atomic_readout_priv_state,
+	.atomic_sro_install_state = drm_bridge_atomic_install_priv_state,
 	.atomic_create_state = drm_bridge_atomic_create_priv_state,
 	.atomic_duplicate_state = drm_bridge_atomic_duplicate_priv_state,
 	.atomic_destroy_state = drm_bridge_atomic_destroy_priv_state,
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index b73f3424ed62..eb65e1807410 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -341,6 +341,26 @@  struct drm_bridge_funcs {
 					 struct drm_bridge_state *a,
 					 struct drm_bridge_state *b);
 
+	/**
+	 * @atomic_sro_install_state:
+	 *
+	 * This optional hook is called when a state read out from
+	 * hardware is about to be installed as the bridge's current
+	 * state, and the pipeline the bridge is part of was read out
+	 * as active.
+	 *
+	 * It allows drivers to acquire the resources needed to keep
+	 * the current hardware state active, such as power domains,
+	 * clocks, or interrupts, and to align their internal state
+	 * with what a regular enable sequence would have left.
+	 *
+	 * This hook cannot fail. It is called during
+	 * drm_atomic_sro_install_state(), which is part of the
+	 * hardware state readout initialization sequence.
+	 */
+	void (*atomic_sro_install_state)(struct drm_bridge *bridge,
+					 struct drm_bridge_state *bridge_state);
+
 	/**
 	 * @atomic_duplicate_state:
 	 *