[PATCH 06/29] drm/bridge: Implement atomic_print_state

Maxime Ripard posted 29 patches 1 month ago
[PATCH 06/29] drm/bridge: Implement atomic_print_state
Posted by Maxime Ripard 1 month ago
Bridges have some fields in their state worth printing, but we don't
provide an atomic_print_state implementation to show those fields.

Let's do so.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/drm_bridge.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index dd439d55177a867acb7ab73c02182bada44d93c9..e803dfd8fd5aae9c16931445213df04d8715b9f6 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -370,13 +370,31 @@ drm_bridge_atomic_destroy_priv_state(struct drm_private_obj *obj,
 	struct drm_bridge *bridge = drm_priv_to_bridge(obj);
 
 	bridge->funcs->atomic_destroy_state(bridge, 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 =
+		container_of_const(s, struct drm_bridge_state, base);
+	struct drm_bridge *bridge = drm_priv_to_bridge(s->obj);
+
+	drm_printf(p, "bridge: %s", drm_get_connector_type_name(bridge->type));
+	drm_printf(p, "\tinput bus configuration:");
+	drm_printf(p, "\t\tcode: %04x", state->input_bus_cfg.format);
+	drm_printf(p, "\t\tflags: %08x", state->input_bus_cfg.flags);
+	drm_printf(p, "\toutput bus configuration:");
+	drm_printf(p, "\t\tcode: %04x", state->output_bus_cfg.format);
+	drm_printf(p, "\t\tflags: %08x", state->output_bus_cfg.flags);
+}
+
 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 bool drm_bridge_is_atomic(struct drm_bridge *bridge)
 {
 	return bridge->funcs->atomic_reset != NULL;

-- 
2.50.1
Re: [PATCH 06/29] drm/bridge: Implement atomic_print_state
Posted by Thomas Zimmermann 1 month ago
Hi

Am 02.09.25 um 10:32 schrieb Maxime Ripard:
> Bridges have some fields in their state worth printing, but we don't
> provide an atomic_print_state implementation to show those fields.
>
> Let's do so.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> ---
>   drivers/gpu/drm/drm_bridge.c | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index dd439d55177a867acb7ab73c02182bada44d93c9..e803dfd8fd5aae9c16931445213df04d8715b9f6 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
> @@ -370,13 +370,31 @@ drm_bridge_atomic_destroy_priv_state(struct drm_private_obj *obj,
>   	struct drm_bridge *bridge = drm_priv_to_bridge(obj);
>   
>   	bridge->funcs->atomic_destroy_state(bridge, 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 =
> +		container_of_const(s, struct drm_bridge_state, base);

Maybe adopt drm_priv_to_bridge_state() to accept const pointers?

https://elixir.bootlin.com/linux/v6.16.4/source/include/drm/drm_atomic.h#L1236



> +	struct drm_bridge *bridge = drm_priv_to_bridge(s->obj);
> +
> +	drm_printf(p, "bridge: %s", drm_get_connector_type_name(bridge->type));
> +	drm_printf(p, "\tinput bus configuration:");
> +	drm_printf(p, "\t\tcode: %04x", state->input_bus_cfg.format);
> +	drm_printf(p, "\t\tflags: %08x", state->input_bus_cfg.flags);
> +	drm_printf(p, "\toutput bus configuration:");
> +	drm_printf(p, "\t\tcode: %04x", state->output_bus_cfg.format);
> +	drm_printf(p, "\t\tflags: %08x", state->output_bus_cfg.flags);
> +}
> +
>   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 bool drm_bridge_is_atomic(struct drm_bridge *bridge)
>   {
>   	return bridge->funcs->atomic_reset != NULL;
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
Re: [PATCH 06/29] drm/bridge: Implement atomic_print_state
Posted by Laurent Pinchart 1 month ago
On Tue, Sep 02, 2025 at 03:22:40PM +0200, Thomas Zimmermann wrote:
> Am 02.09.25 um 10:32 schrieb Maxime Ripard:
> > Bridges have some fields in their state worth printing, but we don't
> > provide an atomic_print_state implementation to show those fields.
> >
> > Let's do so.
> >
> > Signed-off-by: Maxime Ripard <mripard@kernel.org>
> > ---
> >   drivers/gpu/drm/drm_bridge.c | 18 ++++++++++++++++++
> >   1 file changed, 18 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> > index dd439d55177a867acb7ab73c02182bada44d93c9..e803dfd8fd5aae9c16931445213df04d8715b9f6 100644
> > --- a/drivers/gpu/drm/drm_bridge.c
> > +++ b/drivers/gpu/drm/drm_bridge.c
> > @@ -370,13 +370,31 @@ drm_bridge_atomic_destroy_priv_state(struct drm_private_obj *obj,
> >   	struct drm_bridge *bridge = drm_priv_to_bridge(obj);
> >   
> >   	bridge->funcs->atomic_destroy_state(bridge, 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 =
> > +		container_of_const(s, struct drm_bridge_state, base);
> 
> Maybe adopt drm_priv_to_bridge_state() to accept const pointers?
> 
> https://elixir.bootlin.com/linux/v6.16.4/source/include/drm/drm_atomic.h#L1236

container_of_const() can helper, but drm_priv_to_bridge_state() will
need to be turned into a macro.

> > +	struct drm_bridge *bridge = drm_priv_to_bridge(s->obj);
> > +
> > +	drm_printf(p, "bridge: %s", drm_get_connector_type_name(bridge->type));

It would be nice to identify the bridge more precisely, but bridges have
no object ID :-/ The raw pointer may not be very useful. I wonder if we
should give an object ID to drm_private_obj instances, even if we don't
expose them to userspace. That's not a topic for this series of course.

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

> > +	drm_printf(p, "\tinput bus configuration:");
> > +	drm_printf(p, "\t\tcode: %04x", state->input_bus_cfg.format);
> > +	drm_printf(p, "\t\tflags: %08x", state->input_bus_cfg.flags);
> > +	drm_printf(p, "\toutput bus configuration:");
> > +	drm_printf(p, "\t\tcode: %04x", state->output_bus_cfg.format);
> > +	drm_printf(p, "\t\tflags: %08x", state->output_bus_cfg.flags);
> > +}
> > +
> >   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 bool drm_bridge_is_atomic(struct drm_bridge *bridge)
> >   {
> >   	return bridge->funcs->atomic_reset != NULL;
> >

-- 
Regards,

Laurent Pinchart
Re: [PATCH 06/29] drm/bridge: Implement atomic_print_state
Posted by Maxime Ripard 2 weeks, 3 days ago
On Tue, Sep 02, 2025 at 10:22:12PM +0200, Laurent Pinchart wrote:
> > > +	struct drm_bridge *bridge = drm_priv_to_bridge(s->obj);
> > > +
> > > +	drm_printf(p, "bridge: %s", drm_get_connector_type_name(bridge->type));
> 
> It would be nice to identify the bridge more precisely, but bridges have
> no object ID :-/ The raw pointer may not be very useful. I wonder if we
> should give an object ID to drm_private_obj instances, even if we don't
> expose them to userspace. That's not a topic for this series of course.

I agree, and would have liked to have something a bit more descriptive
indeed. But bridges have neither a name or an ID, so I couldn't come up
with anything better :/

> Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Thanks!
Maxime
Re: [PATCH 06/29] drm/bridge: Implement atomic_print_state
Posted by Dmitry Baryshkov 2 weeks, 3 days ago
On Mon, Sep 15, 2025 at 01:28:46PM +0200, Maxime Ripard wrote:
> On Tue, Sep 02, 2025 at 10:22:12PM +0200, Laurent Pinchart wrote:
> > > > +	struct drm_bridge *bridge = drm_priv_to_bridge(s->obj);
> > > > +
> > > > +	drm_printf(p, "bridge: %s", drm_get_connector_type_name(bridge->type));
> > 
> > It would be nice to identify the bridge more precisely, but bridges have
> > no object ID :-/ The raw pointer may not be very useful. I wonder if we
> > should give an object ID to drm_private_obj instances, even if we don't
> > expose them to userspace. That's not a topic for this series of course.
> 
> I agree, and would have liked to have something a bit more descriptive
> indeed. But bridges have neither a name or an ID, so I couldn't come up
> with anything better :/

For debugfs we ended up printing the symbol for the bridge->funcs and
the OF node path in order to identify the bridge.

> 
> > Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> 
> Thanks!
> Maxime



-- 
With best wishes
Dmitry