On Tue, 25 Feb 2025, Luca Ceresoli <luca.ceres...@bootlin.com> wrote:
> In preparation to expose more info about bridges in debugfs, which will
> require more insight into drm_bridge data structures, move the bridges_show
> code to drm_bridge.c.
>
> Suggested-by: Dmitry Baryshkov <dmitry.barysh...@linaro.org>
> Signed-off-by: Luca Ceresoli <luca.ceres...@bootlin.com>

I hate myself for doing this on a patch that's at v7... but here goes.

Perhaps consider moving the bridges debugfs creation and fops to
drm_bridge.c instead of just adding
drm_bridge_debugfs_show_encoder_bridges().

For example, add drm_bridge_debugfs_add(struct drm_encoder *encoder),
which then contains the debugfs_create_file() call.

Interestingly, this lets you drop a lot of #ifdef CONFIG_DEBUG_FS. The
compiler optimizes the fops struct and the functions away when
debugfs_create_file() becomes a stub for CONFIG_DEBUG_FS=n. It becomes
all around cleaner.


BR,
Jani.


>
> ---
>
> This patch was added in v7.
> ---
>  drivers/gpu/drm/drm_bridge.c  | 33 +++++++++++++++++++++++++++++++++
>  drivers/gpu/drm/drm_debugfs.c | 27 ++-------------------------
>  include/drm/drm_bridge.h      |  8 ++++++++
>  3 files changed, 43 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index 
> 241a384ebce39b4a3db58c208af27960904fc662..6e1e02c1cf443fbaa764765ad369b7a34cc03f2d
>  100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
> @@ -1335,6 +1335,39 @@ struct drm_bridge *of_drm_find_bridge(struct 
> device_node *np)
>  EXPORT_SYMBOL(of_drm_find_bridge);
>  #endif
>  
> +#ifdef CONFIG_DEBUG_FS
> +void drm_bridge_debugfs_show_encoder_bridges(struct drm_printer *p,
> +                                          struct drm_encoder *encoder)
> +{
> +     struct drm_bridge *bridge;
> +     unsigned int idx = 0;
> +
> +     drm_for_each_bridge_in_chain(encoder, bridge) {
> +             drm_printf(p, "bridge[%u]: %ps\n", idx++, bridge->funcs);
> +             drm_printf(p, "\ttype: [%d] %s\n",
> +                        bridge->type,
> +                        drm_get_connector_type_name(bridge->type));
> +
> +             if (bridge->of_node)
> +                     drm_printf(p, "\tOF: %pOFfc\n", bridge->of_node);
> +
> +             drm_printf(p, "\tops: [0x%x]", bridge->ops);
> +             if (bridge->ops & DRM_BRIDGE_OP_DETECT)
> +                     drm_puts(p, " detect");
> +             if (bridge->ops & DRM_BRIDGE_OP_EDID)
> +                     drm_puts(p, " edid");
> +             if (bridge->ops & DRM_BRIDGE_OP_HPD)
> +                     drm_puts(p, " hpd");
> +             if (bridge->ops & DRM_BRIDGE_OP_MODES)
> +                     drm_puts(p, " modes");
> +             if (bridge->ops & DRM_BRIDGE_OP_HDMI)
> +                     drm_puts(p, " hdmi");
> +             drm_puts(p, "\n");
> +     }
> +}
> +EXPORT_SYMBOL(drm_bridge_debugfs_show_encoder_bridges);
> +#endif
> +
>  MODULE_AUTHOR("Ajay Kumar <ajaykumar...@samsung.com>");
>  MODULE_DESCRIPTION("DRM bridge infrastructure");
>  MODULE_LICENSE("GPL and additional rights");
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index 
> 6b2178864c7ee12db9aa1f562e106b2f604439f8..a625c0c9a9aa076af19c8ba47564dbb24ba71c9a
>  100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -744,31 +744,8 @@ static int bridges_show(struct seq_file *m, void *data)
>  {
>       struct drm_encoder *encoder = m->private;
>       struct drm_printer p = drm_seq_file_printer(m);
> -     struct drm_bridge *bridge;
> -     unsigned int idx = 0;
> -
> -     drm_for_each_bridge_in_chain(encoder, bridge) {
> -             drm_printf(&p, "bridge[%u]: %ps\n", idx++, bridge->funcs);
> -             drm_printf(&p, "\ttype: [%d] %s\n",
> -                        bridge->type,
> -                        drm_get_connector_type_name(bridge->type));
> -
> -             if (bridge->of_node)
> -                     drm_printf(&p, "\tOF: %pOFfc\n", bridge->of_node);
> -
> -             drm_printf(&p, "\tops: [0x%x]", bridge->ops);
> -             if (bridge->ops & DRM_BRIDGE_OP_DETECT)
> -                     drm_puts(&p, " detect");
> -             if (bridge->ops & DRM_BRIDGE_OP_EDID)
> -                     drm_puts(&p, " edid");
> -             if (bridge->ops & DRM_BRIDGE_OP_HPD)
> -                     drm_puts(&p, " hpd");
> -             if (bridge->ops & DRM_BRIDGE_OP_MODES)
> -                     drm_puts(&p, " modes");
> -             if (bridge->ops & DRM_BRIDGE_OP_HDMI)
> -                     drm_puts(&p, " hdmi");
> -             drm_puts(&p, "\n");
> -     }
> +
> +     drm_bridge_debugfs_show_encoder_bridges(&p, encoder);
>  
>       return 0;
>  }
> diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
> index 
> 496dbbd2ad7edff7f091adfbe62de1e33ef0cf07..23c062853e7bb42d8d73af35ef7f16fb37345a37
>  100644
> --- a/include/drm/drm_bridge.h
> +++ b/include/drm/drm_bridge.h
> @@ -1108,4 +1108,12 @@ static inline struct drm_bridge 
> *drmm_of_get_bridge(struct drm_device *drm,
>  }
>  #endif
>  
> +#ifdef CONFIG_DEBUG_FS
> +void drm_bridge_debugfs_show_encoder_bridges(struct drm_printer *p,
> +                                          struct drm_encoder *encoder);
> +#else
> +static inline void drm_bridge_debugfs_show_encoder_bridges(struct 
> drm_printer *p,
> +                                                        struct drm_encoder 
> *encoder) {}
> +#endif
> +
>  #endif

-- 
Jani Nikula, Intel

Reply via email to