drm/bridge: Add debugfs print for bridge chains

Message ID 20230721-drm-bridge-chain-debugfs-v1-1-8614ff7e890d@ideasonboard.com
State New
Headers
Series drm/bridge: Add debugfs print for bridge chains |

Commit Message

Tomi Valkeinen July 21, 2023, 9:41 a.m. UTC
  DRM bridges are not visible to the userspace and it may not be
immediately clear if the chain is somehow constructed incorrectly. I
have had two separate instances of a bridge driver failing to do a
drm_bridge_attach() call, resulting in the bridge connector not being
part of the chain. In some situations this doesn't seem to cause issues,
but it will if DRM_BRIDGE_ATTACH_NO_CONNECTOR flag is used.

Add a debugfs file to print the bridge chains. For me, on this TI AM62
based platform, I get the following output:

encoder[39]
	bridge[0] type: 0, ops: 0x0
	bridge[1] type: 0, ops: 0x0, OF: /bus@f0000/i2c@20000000/dsi@e:toshiba,tc358778
	bridge[2] type: 0, ops: 0x3, OF: /bus@f0000/i2c@20010000/hdmi@48:lontium,lt8912b
	bridge[3] type: 11, ops: 0x7, OF: /hdmi-connector:hdmi-connector

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/gpu/drm/drm_bridge.c  | 48 +++++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_debugfs.c |  3 +++
 include/drm/drm_bridge.h      |  5 +++++
 3 files changed, 56 insertions(+)


---
base-commit: c7a472297169156252a50d76965eb36b081186e2
change-id: 20230721-drm-bridge-chain-debugfs-0bbc1522f57a

Best regards,
  

Comments

kernel test robot July 21, 2023, 1:28 p.m. UTC | #1
Hi Tomi,

kernel test robot noticed the following build errors:

[auto build test ERROR on c7a472297169156252a50d76965eb36b081186e2]

url:    https://github.com/intel-lab-lkp/linux/commits/Tomi-Valkeinen/drm-bridge-Add-debugfs-print-for-bridge-chains/20230721-174615
base:   c7a472297169156252a50d76965eb36b081186e2
patch link:    https://lore.kernel.org/r/20230721-drm-bridge-chain-debugfs-v1-1-8614ff7e890d%40ideasonboard.com
patch subject: [PATCH] drm/bridge: Add debugfs print for bridge chains
config: x86_64-randconfig-r032-20230720 (https://download.01.org/0day-ci/archive/20230721/202307212102.Fxrv1Ayx-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230721/202307212102.Fxrv1Ayx-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307212102.Fxrv1Ayx-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/gpu/drm/drm_bridge.c: In function 'drm_bridge_chains_info':
>> drivers/gpu/drm/drm_bridge.c:1371:35: error: 'struct drm_bridge' has no member named 'of_node'
    1371 |                         if (bridge->of_node)
         |                                   ^~
   drivers/gpu/drm/drm_bridge.c:1372:70: error: 'struct drm_bridge' has no member named 'of_node'
    1372 |                                 drm_printf(&p, ", OF: %pOFfc", bridge->of_node);
         |                                                                      ^~


vim +1371 drivers/gpu/drm/drm_bridge.c

  1349	
  1350	#ifdef CONFIG_DEBUG_FS
  1351	static int drm_bridge_chains_info(struct seq_file *m, void *data)
  1352	{
  1353		struct drm_debugfs_entry *entry = m->private;
  1354		struct drm_device *dev = entry->dev;
  1355		struct drm_printer p = drm_seq_file_printer(m);
  1356		struct drm_mode_config *config = &dev->mode_config;
  1357		struct drm_encoder *encoder;
  1358		unsigned int bridge_idx = 0;
  1359	
  1360		list_for_each_entry(encoder, &config->encoder_list, head) {
  1361			struct drm_bridge *bridge;
  1362	
  1363			drm_printf(&p, "encoder[%u]\n", encoder->base.id);
  1364	
  1365			bridge = drm_bridge_chain_get_first_bridge(encoder);
  1366	
  1367			while (bridge) {
  1368				drm_printf(&p, "\tbridge[%u] type: %u, ops: %#x",
  1369					   bridge_idx, bridge->type, bridge->ops);
  1370	
> 1371				if (bridge->of_node)
  1372					drm_printf(&p, ", OF: %pOFfc", bridge->of_node);
  1373	
  1374				drm_printf(&p, "\n");
  1375	
  1376				bridge_idx++;
  1377				bridge = drm_bridge_get_next_bridge(bridge);
  1378			}
  1379		}
  1380	
  1381		return 0;
  1382	}
  1383
  

Patch

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index c3d69af02e79..da3205aaed6b 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -27,8 +27,10 @@ 
 #include <linux/mutex.h>
 
 #include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_debugfs.h>
 #include <drm/drm_bridge.h>
 #include <drm/drm_encoder.h>
+#include <drm/drm_file.h>
 #include <drm/drm_of.h>
 #include <drm/drm_print.h>
 
@@ -1345,6 +1347,52 @@  struct drm_bridge *of_drm_find_bridge(struct device_node *np)
 EXPORT_SYMBOL(of_drm_find_bridge);
 #endif
 
+#ifdef CONFIG_DEBUG_FS
+static int drm_bridge_chains_info(struct seq_file *m, void *data)
+{
+	struct drm_debugfs_entry *entry = m->private;
+	struct drm_device *dev = entry->dev;
+	struct drm_printer p = drm_seq_file_printer(m);
+	struct drm_mode_config *config = &dev->mode_config;
+	struct drm_encoder *encoder;
+	unsigned int bridge_idx = 0;
+
+	list_for_each_entry(encoder, &config->encoder_list, head) {
+		struct drm_bridge *bridge;
+
+		drm_printf(&p, "encoder[%u]\n", encoder->base.id);
+
+		bridge = drm_bridge_chain_get_first_bridge(encoder);
+
+		while (bridge) {
+			drm_printf(&p, "\tbridge[%u] type: %u, ops: %#x",
+				   bridge_idx, bridge->type, bridge->ops);
+
+			if (bridge->of_node)
+				drm_printf(&p, ", OF: %pOFfc", bridge->of_node);
+
+			drm_printf(&p, "\n");
+
+			bridge_idx++;
+			bridge = drm_bridge_get_next_bridge(bridge);
+		}
+	}
+
+	return 0;
+}
+
+/* any use in debugfs files to dump individual planes/crtc/etc? */
+static const struct drm_debugfs_info drm_bridge_debugfs_list[] = {
+	{"bridge_chains", drm_bridge_chains_info, 0},
+};
+
+void drm_bridge_debugfs_init(struct drm_minor *minor)
+{
+	drm_debugfs_add_files(minor->dev, drm_bridge_debugfs_list,
+			      ARRAY_SIZE(drm_bridge_debugfs_list));
+}
+#endif
+
 MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@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 c90dbcffa0dc..3e89559d68cd 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -31,6 +31,7 @@ 
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_auth.h>
+#include <drm/drm_bridge.h>
 #include <drm/drm_client.h>
 #include <drm/drm_debugfs.h>
 #include <drm/drm_device.h>
@@ -272,6 +273,8 @@  int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 
 	drm_debugfs_add_files(minor->dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES);
 
+	drm_bridge_debugfs_init(minor);
+
 	if (drm_drv_uses_atomic_modeset(dev)) {
 		drm_atomic_debugfs_init(minor);
 	}
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index bf964cdfb330..60dbee6bd1e6 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -949,4 +949,9 @@  static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,
 }
 #endif
 
+#ifdef CONFIG_DEBUG_FS
+struct drm_minor;
+void drm_bridge_debugfs_init(struct drm_minor *minor);
+#endif
+
 #endif