From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Andrzej Hajda <andrzej.hajda@intel.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Jyri Sarha <jyri.sarha@iki.fi>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Devarsh Thakkar <devarsht@ti.com>,
dri-devel@lists.freedesktop.org,
Maxime Ripard <mripard@kernel.org>
Subject: [PATCH v9 17/42] drm/bridge: Handle bridges with hardware state readout
Date: Fri, 20 Nov 2026 13:55:09 +0100 [thread overview]
Message-ID: <20261120-drm-state-readout-v9-17-a67c2b45b8ec@kernel.org> (raw)
In-Reply-To: <20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org>
Bridges use drm_private_obj for their atomic state, but their readout
needs special handling compared to other private objects.
Bridge drivers need the CRTC and connector states for their pipeline
to properly read out their own state. Since bridge registration does
not guarantee ordering, the readout must traverse each encoder's
bridge chain to ensure each bridge can query the state of preceding
bridges.
Add a drm_bridge_atomic_readout_priv_state() wrapper that looks up
the connector and CRTC states for the bridge's encoder, then forwards
to the bridge's atomic_sro_readout_state hook. Create a separate
drm_private_state_funcs vtable for bridges that support SRO so that
drm_atomic_sro_device_can_readout() can properly discriminate bridges
with and without SRO support.
The same applies when installing the state. Add an
atomic_sro_install_state hook to drm_bridge_funcs, and a
drm_bridge_atomic_install_priv_state() wrapper in that vtable that
calls it before the state of the bridge is replaced. The wrapper looks
up the connector and CRTC states of the pipeline the bridge is part of,
and only calls the hook if the pipeline was read out as active.
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/drm_bridge.c | 138 ++++++++++++++++++++++++++++++++++++++++++-
include/drm/drm_bridge.h | 27 +++++++++
2 files changed, 162 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index b6cdbc172f68..868558a09f95 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -28,10 +28,11 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/srcu.h>
#include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_atomic_state_readout.h>
#include <drm/drm_bridge.h>
#include <drm/drm_debugfs.h>
#include <drm/drm_edid.h>
#include <drm/drm_encoder.h>
#include <drm/drm_file.h>
@@ -562,10 +563,118 @@ drm_bridge_atomic_create_priv_state(struct drm_private_obj *obj)
return ERR_CAST(state);
return &state->base;
}
+static struct drm_connector_state *
+find_connector_state_for_encoder(struct drm_atomic_sro_state *state,
+ struct drm_encoder *encoder)
+{
+ struct drm_connector_list_iter conn_iter;
+ struct drm_connector *connector;
+
+ drm_connector_list_iter_begin(drm_atomic_sro_state_get_device(state),
+ &conn_iter);
+ drm_for_each_connector_iter(connector, &conn_iter) {
+ struct drm_connector_state *conn_state =
+ drm_atomic_sro_get_connector_state(state, connector);
+
+ /*
+ * The connector may not have a state in the readout
+ * state: when the readout is limited to a commit, only
+ * the connectors of that commit are read out.
+ */
+ if (!conn_state)
+ continue;
+
+ if (encoder == conn_state->best_encoder) {
+ drm_connector_list_iter_end(&conn_iter);
+ return conn_state;
+ }
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ return NULL;
+}
+
+static int
+drm_bridge_atomic_readout_priv_state(struct drm_private_obj *obj,
+ struct drm_atomic_sro_state *state,
+ struct drm_private_state *priv_state)
+{
+ struct drm_bridge *bridge = drm_priv_to_bridge(obj);
+ struct drm_encoder *encoder = bridge->encoder;
+ const struct drm_bridge_funcs *bridge_funcs = bridge->funcs;
+ struct drm_crtc_state *crtc_state;
+ struct drm_bridge_state *bridge_state;
+ struct drm_connector_state *conn_state;
+ int ret;
+
+ /*
+ * If the bridge's encoder has no routed connector or no
+ * active CRTC, the pipeline is disabled and there is nothing
+ * to read out. Keep the pristine default state created by
+ * &drm_mode_config_helper_funcs.atomic_sro_build_state.
+ */
+ conn_state = find_connector_state_for_encoder(state, encoder);
+ if (!conn_state)
+ return 0;
+
+ if (!conn_state->crtc)
+ return 0;
+
+ crtc_state = drm_atomic_sro_get_crtc_state(state, conn_state->crtc);
+ if (!crtc_state)
+ return 0;
+
+ bridge_state = drm_priv_to_bridge_state(priv_state);
+ if (bridge_funcs->atomic_sro_readout_state) {
+ ret = bridge_funcs->atomic_sro_readout_state(
+ bridge, state, bridge_state, crtc_state, conn_state);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+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);
+ struct drm_connector_state *conn_state;
+ struct drm_crtc_state *crtc_state;
+ struct drm_connector *connector;
+
+ if (!bridge->funcs->atomic_sro_install_state)
+ return;
+
+ /*
+ * &drm_mode_config_helper_funcs.atomic_sro_install_state
+ * installs the connector and CRTC states before the private
+ * objects ones, so we can look up the pipeline through the
+ * current states. The state readout runs with all the modeset
+ * locks held, including the connection mutex.
+ */
+ connector = drm_atomic_get_connector_for_encoder_locked(bridge->encoder);
+ if (IS_ERR(connector))
+ return;
+
+ conn_state = connector->state;
+ if (!conn_state->crtc)
+ return;
+
+ crtc_state = conn_state->crtc->state;
+ if (!crtc_state || !crtc_state->active)
+ return;
+
+ bridge->funcs->atomic_sro_install_state(bridge,
+ drm_priv_to_bridge_state(priv_state),
+ crtc_state, conn_state);
+}
+
static void
drm_bridge_atomic_print_priv_state(struct drm_printer *p,
const struct drm_private_state *s)
{
const struct drm_bridge_state *state = drm_priv_to_bridge_state(s);
@@ -589,10 +698,19 @@ static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = {
.atomic_duplicate_state = drm_bridge_atomic_duplicate_priv_state,
.atomic_destroy_state = drm_bridge_atomic_destroy_priv_state,
.atomic_print_state = drm_bridge_atomic_print_priv_state,
};
+static const struct drm_private_state_funcs drm_bridge_priv_state_funcs_with_sro = {
+ .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,
+ .atomic_print_state = drm_bridge_atomic_print_priv_state,
+};
+
/**
* drm_private_obj_is_bridge - check if a private object backs a bridge
* @obj: private object to check
*
* RETURNS:
@@ -600,11 +718,13 @@ static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = {
* True if @obj is the &drm_private_obj embedded in a &struct drm_bridge,
* false otherwise.
*/
bool drm_private_obj_is_bridge(struct drm_private_obj *obj)
{
- return obj && obj->funcs == &drm_bridge_priv_state_funcs;
+ return obj &&
+ (obj->funcs == &drm_bridge_priv_state_funcs ||
+ obj->funcs == &drm_bridge_priv_state_funcs_with_sro);
}
EXPORT_SYMBOL(drm_private_obj_is_bridge);
/**
* drm_bridge_attach - attach the bridge to an encoder's chain
@@ -675,15 +795,27 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
ret = bridge->funcs->attach(bridge, encoder, flags);
if (ret < 0)
goto err_reset_bridge;
}
- drm_atomic_private_obj_init(bridge->dev, &bridge->base, bridge->name,
- &drm_bridge_priv_state_funcs);
+ if (bridge->funcs &&
+ bridge->funcs->atomic_sro_readout_state)
+ ret = drm_atomic_private_obj_init(bridge->dev, &bridge->base,
+ bridge->name,
+ &drm_bridge_priv_state_funcs_with_sro);
+ else
+ ret = drm_atomic_private_obj_init(bridge->dev, &bridge->base,
+ bridge->name,
+ &drm_bridge_priv_state_funcs);
+ if (ret)
+ goto err_detach_bridge;
return 0;
+err_detach_bridge:
+ if (bridge->funcs->detach)
+ bridge->funcs->detach(bridge);
err_reset_bridge:
bridge->dev = NULL;
bridge->encoder = NULL;
mutex_lock(&encoder->bridge_chain_mutex);
list_del(&bridge->chain_node);
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index ab0a6c03c8dd..7e30877a81cc 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -325,10 +325,37 @@ struct drm_bridge_funcs {
struct drm_atomic_sro_state *state,
struct drm_bridge_state *bridge_state,
struct drm_crtc_state *crtc_state,
struct drm_connector_state *conn_state);
+ /**
+ * @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 only if the bridge pipeline was read out as
+ * active.
+ *
+ * It allows drivers to acquire the resources needed to keep
+ * the current hardware state active, such as power supplies,
+ * clocks, or interrupts, so that the next disable of the
+ * pipeline releases resources that were actually acquired.
+ *
+ * The @crtc_state and @conn_state parameters point to the CRTC
+ * and connector states for the pipeline this bridge is part
+ * of, which have already been installed.
+ *
+ * This hook cannot fail. It is called by the
+ * &drm_mode_config_helper_funcs.atomic_sro_install_state
+ * implementation, 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,
+ struct drm_crtc_state *crtc_state,
+ struct drm_connector_state *conn_state);
+
/**
* @atomic_duplicate_state:
*
* Duplicate the current bridge state object (which is guaranteed to be
* non-NULL).
--
2.56.1
next prev parent reply other threads:[~2026-11-20 12:56 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 12:54 [PATCH v9 00/42] drm: Implement state readout support Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 01/42] drm/atomic: Add drm_atomic_get_connector_for_encoder_locked() Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 02/42] drm/bridge-helper: Don't unlock the connection mutex after a backoff Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 03/42] drm/tests: hdmi-state-helper: Handle EDEADLK in the 420-only test Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 04/42] drm/tests: hdmi-state-helper: Handle EDEADLK in the color format test Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 05/42] drm/colorop: Export drm_atomic_helper_colorop_create_state() Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 06/42] drm/atomic: Fix private obj error handling Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 07/42] drm/atomic: Add drm_private_obj name Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 08/42] drm/bridge: Switch print_state to use bridge name Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 09/42] drm/bridge: Add drm_private_obj_is_bridge() Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 10/42] drm/fb-dma-helper: Handle framebuffers without a GEM object Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 11/42] drm/gem-atomic-helper: " Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 12/42] drm/atomic: Export drm_atomic_*_print_state Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 13/42] drm/atomic_sro: Create drm_atomic_sro_state container Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 14/42] drm/atomic_sro: Create kernel parameter to force or disable readout Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 15/42] drm/atomic_sro: Add atomic state readout infrastructure Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 16/42] drm/atomic_sro: Create documentation Maxime Ripard
2026-11-20 12:55 ` Maxime Ripard [this message]
2026-11-20 13:18 ` [PATCH v9 17/42] drm/bridge: Handle bridges with hardware state readout sashiko-bot
2026-11-20 12:55 ` [PATCH v9 18/42] drm/mode-config: Read out hardware state in drm_mode_config_create_initial_state Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 19/42] drm/atomic_sro: Provide helpers to implement hardware state readout Maxime Ripard
2026-11-20 13:17 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 20/42] drm/mode-config: Introduce hw_reset hook Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 21/42] drm/modeset-helper: Add drm_mode_config_helper_hw_reset() Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 22/42] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2026-11-20 13:17 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 23/42] drm/atomic-state-helper: Provide comparison macros Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 24/42] drm/atomic-state-helper: Provide atomic_compare_state helpers Maxime Ripard
2026-11-20 13:14 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 25/42] drm/atomic-helper: Document State Read-Out as a state initialization approach Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 26/42] drm/tests: kunit: Add a drm_printer helper Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 27/42] drm/tests: Add tests for the atomic state readout Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 28/42] drm/encoder: Create atomic_sro_get_current_crtc hook Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 29/42] drm/bridge: display-connector: Implement readout support Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 30/42] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 31/42] drm/tidss: Implement hw_reset Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 32/42] drm/tidss: crtc: Implement hardware state readout Maxime Ripard
2026-11-20 13:14 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 33/42] drm/tidss: encoder: " Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 34/42] drm/tidss: kms: Hook up " Maxime Ripard
2026-11-20 13:25 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 35/42] drm/tidss: plane: Implement " Maxime Ripard
2026-11-20 13:28 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 36/42] drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-20 13:17 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 37/42] drm/tidss: encoder: Implement atomic_sro_get_current_crtc Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 38/42] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2026-11-20 13:26 ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 39/42] drm/panel: Implement state readout support Maxime Ripard
2026-11-20 12:55 ` [PATCH DO NOT MERGE v9 40/42] fixup! drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-20 12:55 ` [PATCH DO NOT MERGE v9 41/42] drm/tidss: oldi: Implement hardware state readout Maxime Ripard
2026-11-20 13:34 ` sashiko-bot
2026-11-20 12:55 ` [PATCH HACK v9 42/42] drm/panel: Prepare and enable panels read out as active Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120-drm-state-readout-v9-17-a67c2b45b8ec@kernel.org \
--to=mripard@kernel.org \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=devarsht@ti.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=jyri.sarha@iki.fi \
--cc=maarten.lankhorst@linux.intel.com \
--cc=neil.armstrong@linaro.org \
--cc=rfoss@kernel.org \
--cc=simona@ffwll.ch \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.