linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components.
@ 2019-04-01 18:35 Eric Anholt
  2019-04-01 18:35 ` [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe Eric Anholt
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Eric Anholt @ 2019-04-01 18:35 UTC (permalink / raw)
  To: dri-devel; +Cc: linux-kernel, Paul Kocialkowski, Maxime Ripard, Eric Anholt

The global list of all debugfs entries for the driver was painful: the
list couldn't see into the components' structs, so each component had
its own debugs show function to find the component, then find the
regset and dump it.  The components also had to be careful to check
that they were actually registered in vc4 before dereferencing
themselves, in case they weren't probed on a particular platform.
They routinely failed at that.

Instead, we can have the components add their debugfs callbacks to a
little list in vc4 to be registered at drm_dev_register() time, which
gets vc4_debugfs.c out of the business of knowing the whole list of
components.

Thanks to this change, dsi0 (if it existed) would register its node.

v2: Rebase on hvs_underrun addition.

Signed-off-by: Eric Anholt <eric@anholt.net>
---
 drivers/gpu/drm/vc4/vc4_bo.c      |  6 +--
 drivers/gpu/drm/vc4/vc4_crtc.c    | 33 +++----------
 drivers/gpu/drm/vc4/vc4_debugfs.c | 82 ++++++++++++++++++++++++-------
 drivers/gpu/drm/vc4/vc4_dpi.c     | 20 +-------
 drivers/gpu/drm/vc4/vc4_drv.c     |  1 +
 drivers/gpu/drm/vc4/vc4_drv.h     | 41 +++++++++++-----
 drivers/gpu/drm/vc4/vc4_dsi.c     | 24 ++-------
 drivers/gpu/drm/vc4/vc4_hdmi.c    |  6 +--
 drivers/gpu/drm/vc4/vc4_hvs.c     | 20 ++------
 drivers/gpu/drm/vc4/vc4_txp.c     | 20 +-------
 drivers/gpu/drm/vc4/vc4_v3d.c     | 19 ++-----
 drivers/gpu/drm/vc4/vc4_vec.c     | 20 +-------
 12 files changed, 126 insertions(+), 166 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
index 276ea9c550c0..88ebd681d7eb 100644
--- a/drivers/gpu/drm/vc4/vc4_bo.c
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
@@ -66,8 +66,7 @@ static void vc4_bo_stats_print(struct drm_printer *p, struct vc4_dev *vc4)
 	mutex_unlock(&vc4->purgeable.lock);
 }
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
+static int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
 {
 	struct drm_info_node *node = (struct drm_info_node *)m->private;
 	struct drm_device *dev = node->minor->dev;
@@ -78,7 +77,6 @@ int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
 
 	return 0;
 }
-#endif
 
 /* Takes ownership of *name and returns the appropriate slot for it in
  * the bo_labels[] array, extending it as necessary.
@@ -1005,6 +1003,8 @@ int vc4_bo_cache_init(struct drm_device *dev)
 
 	mutex_init(&vc4->bo_lock);
 
+	vc4_debugfs_add_file(dev, "bo_stats", vc4_bo_stats_debugfs, NULL);
+
 	INIT_LIST_HEAD(&vc4->bo_cache.time_list);
 
 	INIT_WORK(&vc4->bo_cache.time_work, vc4_bo_cache_time_work);
diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c
index 6e564783ba94..b2891ca0e7f4 100644
--- a/drivers/gpu/drm/vc4/vc4_crtc.c
+++ b/drivers/gpu/drm/vc4/vc4_crtc.c
@@ -84,33 +84,6 @@ static const struct debugfs_reg32 crtc_regs[] = {
 	VC4_REG32(PV_HACT_ACT),
 };
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_crtc_debugfs_regs(struct seq_file *m, void *unused)
-{
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	int crtc_index = (uintptr_t)node->info_ent->data;
-	struct drm_printer p = drm_seq_file_printer(m);
-	struct drm_crtc *crtc;
-	struct vc4_crtc *vc4_crtc;
-	int i;
-
-	i = 0;
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		if (i == crtc_index)
-			break;
-		i++;
-	}
-	if (!crtc)
-		return 0;
-	vc4_crtc = to_vc4_crtc(crtc);
-
-	drm_print_regset32(&p, &vc4_crtc->regset);
-
-	return 0;
-}
-#endif
-
 bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
 			     bool in_vblank_irq, int *vpos, int *hpos,
 			     ktime_t *stime, ktime_t *etime,
@@ -1070,6 +1043,7 @@ static const struct drm_crtc_helper_funcs vc4_crtc_helper_funcs = {
 
 static const struct vc4_crtc_data pv0_data = {
 	.hvs_channel = 0,
+	.debugfs_name = "crtc0_regs",
 	.encoder_types = {
 		[PV_CONTROL_CLK_SELECT_DSI] = VC4_ENCODER_TYPE_DSI0,
 		[PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_DPI,
@@ -1078,6 +1052,7 @@ static const struct vc4_crtc_data pv0_data = {
 
 static const struct vc4_crtc_data pv1_data = {
 	.hvs_channel = 2,
+	.debugfs_name = "crtc1_regs",
 	.encoder_types = {
 		[PV_CONTROL_CLK_SELECT_DSI] = VC4_ENCODER_TYPE_DSI1,
 		[PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_SMI,
@@ -1086,6 +1061,7 @@ static const struct vc4_crtc_data pv1_data = {
 
 static const struct vc4_crtc_data pv2_data = {
 	.hvs_channel = 1,
+	.debugfs_name = "crtc2_regs",
 	.encoder_types = {
 		[PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_HDMI,
 		[PV_CONTROL_CLK_SELECT_VEC] = VC4_ENCODER_TYPE_VEC,
@@ -1247,6 +1223,9 @@ static int vc4_crtc_bind(struct device *dev, struct device *master, void *data)
 
 	platform_set_drvdata(pdev, vc4_crtc);
 
+	vc4_debugfs_add_regset32(drm, vc4_crtc->data->debugfs_name,
+				 &vc4_crtc->regset);
+
 	return 0;
 
 err_destroy_planes:
diff --git a/drivers/gpu/drm/vc4/vc4_debugfs.c b/drivers/gpu/drm/vc4/vc4_debugfs.c
index 59cdad89f844..69df84bdf904 100644
--- a/drivers/gpu/drm/vc4/vc4_debugfs.c
+++ b/drivers/gpu/drm/vc4/vc4_debugfs.c
@@ -15,28 +15,20 @@
 #include "vc4_drv.h"
 #include "vc4_regs.h"
 
-static const struct drm_info_list vc4_debugfs_list[] = {
-	{"bo_stats", vc4_bo_stats_debugfs, 0},
-	{"dpi_regs", vc4_dpi_debugfs_regs, 0},
-	{"dsi1_regs", vc4_dsi_debugfs_regs, 0, (void *)(uintptr_t)1},
-	{"hdmi_regs", vc4_hdmi_debugfs_regs, 0},
-	{"vec_regs", vc4_vec_debugfs_regs, 0},
-	{"txp_regs", vc4_txp_debugfs_regs, 0},
-	{"hvs_regs", vc4_hvs_debugfs_regs, 0},
-	{"hvs_underrun",  vc4_hvs_debugfs_underrun, 0},
-	{"crtc0_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)0},
-	{"crtc1_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)1},
-	{"crtc2_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)2},
-	{"v3d_ident", vc4_v3d_debugfs_ident, 0},
-	{"v3d_regs", vc4_v3d_debugfs_regs, 0},
+struct vc4_debugfs_info_entry {
+	struct list_head link;
+	struct drm_info_list info;
 };
 
-#define VC4_DEBUGFS_ENTRIES ARRAY_SIZE(vc4_debugfs_list)
-
+/**
+ * Called at drm_dev_register() time on each of the minors registered
+ * by the DRM device, to attach the debugfs files.
+ */
 int
 vc4_debugfs_init(struct drm_minor *minor)
 {
 	struct vc4_dev *vc4 = to_vc4_dev(minor->dev);
+	struct vc4_debugfs_info_entry *entry;
 	struct dentry *dentry;
 
 	dentry = debugfs_create_bool("hvs_load_tracker", S_IRUGO | S_IWUSR,
@@ -45,6 +37,60 @@ vc4_debugfs_init(struct drm_minor *minor)
 	if (!dentry)
 		return -ENOMEM;
 
-	return drm_debugfs_create_files(vc4_debugfs_list, VC4_DEBUGFS_ENTRIES,
-					minor->debugfs_root, minor);
+	list_for_each_entry(entry, &vc4->debugfs_list, link) {
+		int ret = drm_debugfs_create_files(&entry->info, 1,
+						   minor->debugfs_root, minor);
+
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+int vc4_debugfs_regset32(struct seq_file *m, void *unused)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct debugfs_regset32 *regset = node->info_ent->data;
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	drm_print_regset32(&p, regset);
+
+	return 0;
+}
+
+/**
+ * Registers a debugfs file with a callback function for a vc4 component.
+ *
+ * This is like drm_debugfs_create_files(), but that can only be
+ * called a given DRM minor, while the various VC4 components want to
+ * register their debugfs files during the component bind process.  We
+ * track the request and delay it to be called on each minor during
+ * vc4_debugfs_init().
+ */
+void vc4_debugfs_add_file(struct drm_device *dev,
+			  const char *name,
+			  int (*show)(struct seq_file*, void*),
+			  void *data)
+{
+	struct vc4_dev *vc4 = to_vc4_dev(dev);
+
+	struct vc4_debugfs_info_entry *entry =
+		devm_kzalloc(dev->dev, sizeof(*entry), GFP_KERNEL);
+
+	if (!entry)
+		return;
+
+	entry->info.name = name;
+	entry->info.show = show;
+	entry->info.data = data;
+
+	list_add(&entry->link, &vc4->debugfs_list);
+}
+
+void vc4_debugfs_add_regset32(struct drm_device *drm,
+			      const char *name,
+			      struct debugfs_regset32 *regset)
+{
+	vc4_debugfs_add_file(drm, name, vc4_debugfs_regset32, regset);
 }
diff --git a/drivers/gpu/drm/vc4/vc4_dpi.c b/drivers/gpu/drm/vc4/vc4_dpi.c
index 8be2264f496a..34f90ca8f479 100644
--- a/drivers/gpu/drm/vc4/vc4_dpi.c
+++ b/drivers/gpu/drm/vc4/vc4_dpi.c
@@ -125,24 +125,6 @@ static const struct debugfs_reg32 dpi_regs[] = {
 	VC4_REG32(DPI_ID),
 };
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused)
-{
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct vc4_dev *vc4 = to_vc4_dev(dev);
-	struct vc4_dpi *dpi = vc4->dpi;
-	struct drm_printer p = drm_seq_file_printer(m);
-
-	if (!dpi)
-		return 0;
-
-	drm_print_regset32(&p, &dpi->regset);
-
-	return 0;
-}
-#endif
-
 static const struct drm_encoder_funcs vc4_dpi_encoder_funcs = {
 	.destroy = drm_encoder_cleanup,
 };
@@ -349,6 +331,8 @@ static int vc4_dpi_bind(struct device *dev, struct device *master, void *data)
 
 	vc4->dpi = dpi;
 
+	vc4_debugfs_add_regset32(drm, "dpi_regs", &dpi->regset);
+
 	return 0;
 
 err_destroy_encoder:
diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index f2d0fb3aa729..3d6fccea5080 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -262,6 +262,7 @@ static int vc4_drm_bind(struct device *dev)
 	platform_set_drvdata(pdev, drm);
 	vc4->dev = drm;
 	drm->dev_private = vc4;
+	INIT_LIST_HEAD(&vc4->debugfs_list);
 
 	ret = vc4_bo_cache_init(drm);
 	if (ret)
diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index f6c9de75d465..be85656024fa 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -210,7 +210,12 @@ struct vc4_dev {
 
 	struct drm_modeset_lock ctm_state_lock;
 	struct drm_private_obj ctm_manager;
-	struct drm_private_obj load_tracker;
+ 	struct drm_private_obj load_tracker;
+
+	/* List of vc4_debugfs_info_entry for adding to debugfs once
+	 * the minor is available (after drm_dev_register()).
+	 */
+	struct list_head debugfs_list;
 };
 
 static inline struct vc4_dev *
@@ -429,6 +434,7 @@ struct vc4_crtc_data {
 	int hvs_channel;
 
 	enum vc4_encoder_type encoder_types[4];
+	const char *debugfs_name;
 };
 
 struct vc4_crtc {
@@ -715,7 +721,6 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
 void *vc4_prime_vmap(struct drm_gem_object *obj);
 int vc4_bo_cache_init(struct drm_device *dev);
 void vc4_bo_cache_destroy(struct drm_device *dev);
-int vc4_bo_stats_debugfs(struct seq_file *m, void *arg);
 int vc4_bo_inc_usecnt(struct vc4_bo *bo);
 void vc4_bo_dec_usecnt(struct vc4_bo *bo);
 void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
@@ -723,7 +728,6 @@ void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
 
 /* vc4_crtc.c */
 extern struct platform_driver vc4_crtc_driver;
-int vc4_crtc_debugfs_regs(struct seq_file *m, void *arg);
 bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
 			     bool in_vblank_irq, int *vpos, int *hpos,
 			     ktime_t *stime, ktime_t *etime,
@@ -736,17 +740,37 @@ void vc4_crtc_get_margins(struct drm_crtc_state *state,
 
 /* vc4_debugfs.c */
 int vc4_debugfs_init(struct drm_minor *minor);
+#ifdef CONFIG_DEBUG_FS
+void vc4_debugfs_add_file(struct drm_device *drm,
+			  const char *filename,
+			  int (*show)(struct seq_file*, void*),
+			  void *data);
+void vc4_debugfs_add_regset32(struct drm_device *drm,
+			      const char *filename,
+			      struct debugfs_regset32 *regset);
+#else
+static inline void vc4_debugfs_add_file(struct drm_device *drm,
+					const char *filename,
+					int (*show)(struct seq_file*, void*),
+					void *data)
+{
+}
+
+static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
+					    const char *filename,
+					    struct debugfs_regset32 *regset)
+{
+}
+#endif
 
 /* vc4_drv.c */
 void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
 
 /* vc4_dpi.c */
 extern struct platform_driver vc4_dpi_driver;
-int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused);
 
 /* vc4_dsi.c */
 extern struct platform_driver vc4_dsi_driver;
-int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused);
 
 /* vc4_fence.c */
 extern const struct dma_fence_ops vc4_fence_ops;
@@ -774,15 +798,12 @@ int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
 
 /* vc4_hdmi.c */
 extern struct platform_driver vc4_hdmi_driver;
-int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused);
 
 /* vc4_vec.c */
 extern struct platform_driver vc4_vec_driver;
-int vc4_vec_debugfs_regs(struct seq_file *m, void *unused);
 
 /* vc4_txp.c */
 extern struct platform_driver vc4_txp_driver;
-int vc4_txp_debugfs_regs(struct seq_file *m, void *unused);
 
 /* vc4_irq.c */
 irqreturn_t vc4_irq(int irq, void *arg);
@@ -794,8 +815,6 @@ void vc4_irq_reset(struct drm_device *dev);
 /* vc4_hvs.c */
 extern struct platform_driver vc4_hvs_driver;
 void vc4_hvs_dump_state(struct drm_device *dev);
-int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused);
-int vc4_hvs_debugfs_underrun(struct seq_file *m, void *unused);
 void vc4_hvs_unmask_underrun(struct drm_device *dev, int channel);
 void vc4_hvs_mask_underrun(struct drm_device *dev, int channel);
 
@@ -812,8 +831,6 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
 
 /* vc4_v3d.c */
 extern struct platform_driver vc4_v3d_driver;
-int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
-int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
 int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
 int vc4_v3d_pm_get(struct vc4_dev *vc4);
 void vc4_v3d_pm_put(struct vc4_dev *vc4);
diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index 806cfaa2a6a7..9412709067f5 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -657,25 +657,6 @@ static const struct debugfs_reg32 dsi1_regs[] = {
 	VC4_REG32(DSI1_ID),
 };
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused)
-{
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *drm = node->minor->dev;
-	struct vc4_dev *vc4 = to_vc4_dev(drm);
-	int dsi_index = (uintptr_t)node->info_ent->data;
-	struct vc4_dsi *dsi = (dsi_index == 1 ? vc4->dsi1 : NULL);
-	struct drm_printer p = drm_seq_file_printer(m);
-
-	if (!dsi)
-		return 0;
-
-	drm_print_regset32(&p, &dsi->regset);
-
-	return 0;
-}
-#endif
-
 static void vc4_dsi_encoder_destroy(struct drm_encoder *encoder)
 {
 	drm_encoder_cleanup(encoder);
@@ -1637,6 +1618,11 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
 	 */
 	dsi->encoder->bridge = NULL;
 
+	if (dsi->port == 0)
+		vc4_debugfs_add_regset32(drm, "dsi0_regs", &dsi->regset);
+	else
+		vc4_debugfs_add_regset32(drm, "dsi1_regs", &dsi->regset);
+
 	pm_runtime_enable(dev);
 
 	return 0;
diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index 38c9172cfe52..99fc8569e0f5 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -187,8 +187,7 @@ static const struct debugfs_reg32 hd_regs[] = {
 	VC4_REG32(VC4_HD_FRAME_COUNT),
 };
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
+static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
 {
 	struct drm_info_node *node = (struct drm_info_node *)m->private;
 	struct drm_device *dev = node->minor->dev;
@@ -201,7 +200,6 @@ int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
 
 	return 0;
 }
-#endif /* CONFIG_DEBUG_FS */
 
 static enum drm_connector_status
 vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
@@ -1432,6 +1430,8 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 	if (ret)
 		goto err_destroy_encoder;
 
+	vc4_debugfs_add_file(drm, "hdmi_regs", vc4_hdmi_debugfs_regs, hdmi);
+
 	return 0;
 
 #ifdef CONFIG_DRM_VC4_HDMI_CEC
diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
index c463453f941b..f746e9a7a88c 100644
--- a/drivers/gpu/drm/vc4/vc4_hvs.c
+++ b/drivers/gpu/drm/vc4/vc4_hvs.c
@@ -80,20 +80,7 @@ void vc4_hvs_dump_state(struct drm_device *dev)
 	}
 }
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused)
-{
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct vc4_dev *vc4 = to_vc4_dev(dev);
-	struct drm_printer p = drm_seq_file_printer(m);
-
-	drm_print_regset32(&p, &vc4->hvs->regset);
-
-	return 0;
-}
-
-int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
+static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = m->private;
 	struct drm_device *dev = node->minor->dev;
@@ -104,7 +91,6 @@ int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
 
 	return 0;
 }
-#endif
 
 /* The filter kernel is composed of dwords each containing 3 9-bit
  * signed integers packed next to each other.
@@ -316,6 +302,10 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
 	if (ret)
 		return ret;
 
+	vc4_debugfs_add_regset32(drm, "hvs_regs", &hvs->regset);
+	vc4_debugfs_add_file(drm, "hvs_underrun", vc4_hvs_debugfs_underrun,
+			     NULL);
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/vc4/vc4_txp.c b/drivers/gpu/drm/vc4/vc4_txp.c
index c8f80064c179..1220f4a5aac4 100644
--- a/drivers/gpu/drm/vc4/vc4_txp.c
+++ b/drivers/gpu/drm/vc4/vc4_txp.c
@@ -169,24 +169,6 @@ static const struct debugfs_reg32 txp_regs[] = {
 	VC4_REG32(TXP_PROGRESS),
 };
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_txp_debugfs_regs(struct seq_file *m, void *unused)
-{
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct vc4_dev *vc4 = to_vc4_dev(dev);
-	struct vc4_txp *txp = vc4->txp;
-	struct drm_printer p = drm_seq_file_printer(m);
-
-	if (!txp)
-		return 0;
-
-	drm_print_regset32(&p, &txp->regset);
-
-	return 0;
-}
-#endif
-
 static int vc4_txp_connector_get_modes(struct drm_connector *connector)
 {
 	struct drm_device *dev = connector->dev;
@@ -424,6 +406,8 @@ static int vc4_txp_bind(struct device *dev, struct device *master, void *data)
 	dev_set_drvdata(dev, txp);
 	vc4->txp = txp;
 
+	vc4_debugfs_add_regset32(drm, "txp_regs", &txp->regset);
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
index 27c70eb52405..36e6c7086ecf 100644
--- a/drivers/gpu/drm/vc4/vc4_v3d.c
+++ b/drivers/gpu/drm/vc4/vc4_v3d.c
@@ -22,7 +22,6 @@
 #include "vc4_drv.h"
 #include "vc4_regs.h"
 
-#ifdef CONFIG_DEBUG_FS
 static const struct debugfs_reg32 v3d_regs[] = {
 	VC4_REG32(V3D_IDENT0),
 	VC4_REG32(V3D_IDENT1),
@@ -104,19 +103,7 @@ static const struct debugfs_reg32 v3d_regs[] = {
 	VC4_REG32(V3D_ERRSTAT),
 };
 
-int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused)
-{
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct vc4_dev *vc4 = to_vc4_dev(dev);
-	struct drm_printer p = drm_seq_file_printer(m);
-
-	drm_print_regset32(&p, &vc4->v3d->regset);
-
-	return 0;
-}
-
-int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
+static int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
 {
 	struct drm_info_node *node = (struct drm_info_node *)m->private;
 	struct drm_device *dev = node->minor->dev;
@@ -141,7 +128,6 @@ int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
 
 	return 0;
 }
-#endif /* CONFIG_DEBUG_FS */
 
 /**
  * Wraps pm_runtime_get_sync() in a refcount, so that we can reliably
@@ -442,6 +428,9 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
 	pm_runtime_set_autosuspend_delay(dev, 40); /* a little over 2 frames. */
 	pm_runtime_enable(dev);
 
+	vc4_debugfs_add_file(drm, "v3d_ident", vc4_v3d_debugfs_ident, NULL);
+	vc4_debugfs_add_regset32(drm, "v3d_regs", &v3d->regset);
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/vc4/vc4_vec.c b/drivers/gpu/drm/vc4/vc4_vec.c
index 83227d2440aa..0a27e48fab31 100644
--- a/drivers/gpu/drm/vc4/vc4_vec.c
+++ b/drivers/gpu/drm/vc4/vc4_vec.c
@@ -252,24 +252,6 @@ static const struct debugfs_reg32 vec_regs[] = {
 	VC4_REG32(VEC_DAC_MISC),
 };
 
-#ifdef CONFIG_DEBUG_FS
-int vc4_vec_debugfs_regs(struct seq_file *m, void *unused)
-{
-	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_device *dev = node->minor->dev;
-	struct vc4_dev *vc4 = to_vc4_dev(dev);
-	struct vc4_vec *vec = vc4->vec;
-	struct drm_printer p = drm_seq_file_printer(m);
-
-	if (!vec)
-		return 0;
-
-	drm_print_regset32(&p, &vec->regset);
-
-	return 0;
-}
-#endif
-
 static void vc4_vec_ntsc_mode_set(struct vc4_vec *vec)
 {
 	VEC_WRITE(VEC_CONFIG0, VEC_CONFIG0_NTSC_STD | VEC_CONFIG0_PDEN);
@@ -609,6 +591,8 @@ static int vc4_vec_bind(struct device *dev, struct device *master, void *data)
 
 	vc4->vec = vec;
 
+	vc4_debugfs_add_regset32(drm, "vec_regs", &vec->regset);
+
 	return 0;
 
 err_destroy_encoder:
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe.
  2019-04-01 18:35 [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components Eric Anholt
@ 2019-04-01 18:35 ` Eric Anholt
  2019-04-02 14:27   ` Paul Kocialkowski
  2019-04-03 13:30   ` Paul Kocialkowski
  2019-04-02 14:38 ` [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components Paul Kocialkowski
  2019-04-03  9:17 ` Paul Kocialkowski
  2 siblings, 2 replies; 7+ messages in thread
From: Eric Anholt @ 2019-04-01 18:35 UTC (permalink / raw)
  To: dri-devel; +Cc: linux-kernel, Paul Kocialkowski, Maxime Ripard, Eric Anholt

One might want to use the VC4 display stack without using Mesa.
Similar to the debugfs fixes for not having all of the possible
display bits enabled, make sure you can't oops in vc4 if v3d isn't
enabled.

v2: Fix matching against other v3d variants (review by Paul), don't
    forget to set irq_enabled so that the vblank uapi works

Signed-off-by: Eric Anholt <eric@anholt.net>
---
 drivers/gpu/drm/vc4/vc4_drv.c     | 10 ++++++++++
 drivers/gpu/drm/vc4/vc4_drv.h     |  1 +
 drivers/gpu/drm/vc4/vc4_gem.c     | 10 ++++++++++
 drivers/gpu/drm/vc4/vc4_irq.c     |  9 +++++++++
 drivers/gpu/drm/vc4/vc4_kms.c     |  1 +
 drivers/gpu/drm/vc4/vc4_perfmon.c | 18 ++++++++++++++++++
 drivers/gpu/drm/vc4/vc4_v3d.c     |  2 +-
 7 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index 3d6fccea5080..d840b52b9805 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -72,6 +72,9 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
 	if (args->pad != 0)
 		return -EINVAL;
 
+	if (!vc4->v3d)
+		return -EINVAL;
+
 	switch (args->param) {
 	case DRM_VC4_PARAM_V3D_IDENT0:
 		ret = vc4_v3d_pm_get(vc4);
@@ -248,6 +251,7 @@ static int vc4_drm_bind(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct drm_device *drm;
 	struct vc4_dev *vc4;
+	struct device_node *node;
 	int ret = 0;
 
 	dev->coherent_dma_mask = DMA_BIT_MASK(32);
@@ -256,6 +260,12 @@ static int vc4_drm_bind(struct device *dev)
 	if (!vc4)
 		return -ENOMEM;
 
+	/* If VC4 V3D is missing, don't advertise render nodes. */
+	node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
+	if (!node || !of_device_is_available(node))
+		vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
+	of_node_put(node);
+
 	drm = drm_dev_alloc(&vc4_drm_driver, dev);
 	if (IS_ERR(drm))
 		return PTR_ERR(drm);
diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index be85656024fa..e61734af059b 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -831,6 +831,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
 
 /* vc4_v3d.c */
 extern struct platform_driver vc4_v3d_driver;
+extern const struct of_device_id vc4_v3d_dt_match[];
 int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
 int vc4_v3d_pm_get(struct vc4_dev *vc4);
 void vc4_v3d_pm_put(struct vc4_dev *vc4);
diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
index 5e9496d477bf..4544a478f106 100644
--- a/drivers/gpu/drm/vc4/vc4_gem.c
+++ b/drivers/gpu/drm/vc4/vc4_gem.c
@@ -74,6 +74,11 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
 	u32 i;
 	int ret = 0;
 
+	if (!vc4->v3d) {
+		DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
+		return -EINVAL;
+	}
+
 	spin_lock_irqsave(&vc4->job_lock, irqflags);
 	kernel_state = vc4->hang_state;
 	if (!kernel_state) {
@@ -1119,6 +1124,11 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
 	struct dma_fence *in_fence;
 	int ret = 0;
 
+	if (!vc4->v3d) {
+		DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
+		return -EINVAL;
+	}
+
 	if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
 			     VC4_SUBMIT_CL_FIXED_RCL_ORDER |
 			     VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
diff --git a/drivers/gpu/drm/vc4/vc4_irq.c b/drivers/gpu/drm/vc4/vc4_irq.c
index 4cd2ccfe15f4..ffd0a4388752 100644
--- a/drivers/gpu/drm/vc4/vc4_irq.c
+++ b/drivers/gpu/drm/vc4/vc4_irq.c
@@ -229,6 +229,9 @@ vc4_irq_preinstall(struct drm_device *dev)
 {
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
+	if (!vc4->v3d)
+		return;
+
 	init_waitqueue_head(&vc4->job_wait_queue);
 	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
 
@@ -243,6 +246,9 @@ vc4_irq_postinstall(struct drm_device *dev)
 {
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
+	if (!vc4->v3d)
+		return 0;
+
 	/* Enable both the render done and out of memory interrupts. */
 	V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
 
@@ -254,6 +260,9 @@ vc4_irq_uninstall(struct drm_device *dev)
 {
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 
+	if (!vc4->v3d)
+		return;
+
 	/* Disable sending interrupts for our driver's IRQs. */
 	V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS);
 
diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c
index 5160cad25fce..295dacc8bcb9 100644
--- a/drivers/gpu/drm/vc4/vc4_kms.c
+++ b/drivers/gpu/drm/vc4/vc4_kms.c
@@ -525,6 +525,7 @@ int vc4_kms_load(struct drm_device *dev)
 	/* Set support for vblank irq fast disable, before drm_vblank_init() */
 	dev->vblank_disable_immediate = true;
 
+	dev->irq_enabled = true;
 	ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
 	if (ret < 0) {
 		dev_err(dev->dev, "failed to initialize vblank\n");
diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
index 495150415020..6562d3d30b20 100644
--- a/drivers/gpu/drm/vc4/vc4_perfmon.c
+++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
@@ -100,12 +100,18 @@ void vc4_perfmon_close_file(struct vc4_file *vc4file)
 int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
 			     struct drm_file *file_priv)
 {
+	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct vc4_file *vc4file = file_priv->driver_priv;
 	struct drm_vc4_perfmon_create *req = data;
 	struct vc4_perfmon *perfmon;
 	unsigned int i;
 	int ret;
 
+	if (!vc4->v3d) {
+		DRM_DEBUG("Creating perfmon no VC4 V3D probed\n");
+		return -EINVAL;
+	}
+
 	/* Number of monitored counters cannot exceed HW limits. */
 	if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS ||
 	    !req->ncounters)
@@ -146,10 +152,16 @@ int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
 int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
 			      struct drm_file *file_priv)
 {
+	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct vc4_file *vc4file = file_priv->driver_priv;
 	struct drm_vc4_perfmon_destroy *req = data;
 	struct vc4_perfmon *perfmon;
 
+	if (!vc4->v3d) {
+		DRM_DEBUG("Destroying perfmon no VC4 V3D probed\n");
+		return -EINVAL;
+	}
+
 	mutex_lock(&vc4file->perfmon.lock);
 	perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
 	mutex_unlock(&vc4file->perfmon.lock);
@@ -164,11 +176,17 @@ int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
 int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
 				 struct drm_file *file_priv)
 {
+	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct vc4_file *vc4file = file_priv->driver_priv;
 	struct drm_vc4_perfmon_get_values *req = data;
 	struct vc4_perfmon *perfmon;
 	int ret;
 
+	if (!vc4->v3d) {
+		DRM_DEBUG("Getting perfmon no VC4 V3D probed\n");
+		return -EINVAL;
+	}
+
 	mutex_lock(&vc4file->perfmon.lock);
 	perfmon = idr_find(&vc4file->perfmon.idr, req->id);
 	vc4_perfmon_get(perfmon);
diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
index 36e6c7086ecf..a4b6859e3af6 100644
--- a/drivers/gpu/drm/vc4/vc4_v3d.c
+++ b/drivers/gpu/drm/vc4/vc4_v3d.c
@@ -474,7 +474,7 @@ static int vc4_v3d_dev_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static const struct of_device_id vc4_v3d_dt_match[] = {
+const struct of_device_id vc4_v3d_dt_match[] = {
 	{ .compatible = "brcm,bcm2835-v3d" },
 	{ .compatible = "brcm,cygnus-v3d" },
 	{ .compatible = "brcm,vc4-v3d" },
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe.
  2019-04-01 18:35 ` [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe Eric Anholt
@ 2019-04-02 14:27   ` Paul Kocialkowski
  2019-04-03 13:30   ` Paul Kocialkowski
  1 sibling, 0 replies; 7+ messages in thread
From: Paul Kocialkowski @ 2019-04-02 14:27 UTC (permalink / raw)
  To: Eric Anholt, dri-devel; +Cc: linux-kernel, Maxime Ripard

Hi,

On Mon, 2019-04-01 at 11:35 -0700, Eric Anholt wrote:
> One might want to use the VC4 display stack without using Mesa.
> Similar to the debugfs fixes for not having all of the possible
> display bits enabled, make sure you can't oops in vc4 if v3d isn't
> enabled.
> 
> v2: Fix matching against other v3d variants (review by Paul), don't
>     forget to set irq_enabled so that the vblank uapi works

Looks good to me!

Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>

Cheers,

Paul

> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>  drivers/gpu/drm/vc4/vc4_drv.c     | 10 ++++++++++
>  drivers/gpu/drm/vc4/vc4_drv.h     |  1 +
>  drivers/gpu/drm/vc4/vc4_gem.c     | 10 ++++++++++
>  drivers/gpu/drm/vc4/vc4_irq.c     |  9 +++++++++
>  drivers/gpu/drm/vc4/vc4_kms.c     |  1 +
>  drivers/gpu/drm/vc4/vc4_perfmon.c | 18 ++++++++++++++++++
>  drivers/gpu/drm/vc4/vc4_v3d.c     |  2 +-
>  7 files changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
> index 3d6fccea5080..d840b52b9805 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.c
> +++ b/drivers/gpu/drm/vc4/vc4_drv.c
> @@ -72,6 +72,9 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
>  	if (args->pad != 0)
>  		return -EINVAL;
>  
> +	if (!vc4->v3d)
> +		return -EINVAL;
> +
>  	switch (args->param) {
>  	case DRM_VC4_PARAM_V3D_IDENT0:
>  		ret = vc4_v3d_pm_get(vc4);
> @@ -248,6 +251,7 @@ static int vc4_drm_bind(struct device *dev)
>  	struct platform_device *pdev = to_platform_device(dev);
>  	struct drm_device *drm;
>  	struct vc4_dev *vc4;
> +	struct device_node *node;
>  	int ret = 0;
>  
>  	dev->coherent_dma_mask = DMA_BIT_MASK(32);
> @@ -256,6 +260,12 @@ static int vc4_drm_bind(struct device *dev)
>  	if (!vc4)
>  		return -ENOMEM;
>  
> +	/* If VC4 V3D is missing, don't advertise render nodes. */
> +	node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
> +	if (!node || !of_device_is_available(node))
> +		vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
> +	of_node_put(node);
> +
>  	drm = drm_dev_alloc(&vc4_drm_driver, dev);
>  	if (IS_ERR(drm))
>  		return PTR_ERR(drm);
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
> index be85656024fa..e61734af059b 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.h
> +++ b/drivers/gpu/drm/vc4/vc4_drv.h
> @@ -831,6 +831,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
>  
>  /* vc4_v3d.c */
>  extern struct platform_driver vc4_v3d_driver;
> +extern const struct of_device_id vc4_v3d_dt_match[];
>  int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
>  int vc4_v3d_pm_get(struct vc4_dev *vc4);
>  void vc4_v3d_pm_put(struct vc4_dev *vc4);
> diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
> index 5e9496d477bf..4544a478f106 100644
> --- a/drivers/gpu/drm/vc4/vc4_gem.c
> +++ b/drivers/gpu/drm/vc4/vc4_gem.c
> @@ -74,6 +74,11 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
>  	u32 i;
>  	int ret = 0;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	spin_lock_irqsave(&vc4->job_lock, irqflags);
>  	kernel_state = vc4->hang_state;
>  	if (!kernel_state) {
> @@ -1119,6 +1124,11 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
>  	struct dma_fence *in_fence;
>  	int ret = 0;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
>  			     VC4_SUBMIT_CL_FIXED_RCL_ORDER |
>  			     VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
> diff --git a/drivers/gpu/drm/vc4/vc4_irq.c b/drivers/gpu/drm/vc4/vc4_irq.c
> index 4cd2ccfe15f4..ffd0a4388752 100644
> --- a/drivers/gpu/drm/vc4/vc4_irq.c
> +++ b/drivers/gpu/drm/vc4/vc4_irq.c
> @@ -229,6 +229,9 @@ vc4_irq_preinstall(struct drm_device *dev)
>  {
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  
> +	if (!vc4->v3d)
> +		return;
> +
>  	init_waitqueue_head(&vc4->job_wait_queue);
>  	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
>  
> @@ -243,6 +246,9 @@ vc4_irq_postinstall(struct drm_device *dev)
>  {
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  
> +	if (!vc4->v3d)
> +		return 0;
> +
>  	/* Enable both the render done and out of memory interrupts. */
>  	V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
>  
> @@ -254,6 +260,9 @@ vc4_irq_uninstall(struct drm_device *dev)
>  {
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  
> +	if (!vc4->v3d)
> +		return;
> +
>  	/* Disable sending interrupts for our driver's IRQs. */
>  	V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS);
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c
> index 5160cad25fce..295dacc8bcb9 100644
> --- a/drivers/gpu/drm/vc4/vc4_kms.c
> +++ b/drivers/gpu/drm/vc4/vc4_kms.c
> @@ -525,6 +525,7 @@ int vc4_kms_load(struct drm_device *dev)
>  	/* Set support for vblank irq fast disable, before drm_vblank_init() */
>  	dev->vblank_disable_immediate = true;
>  
> +	dev->irq_enabled = true;
>  	ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
>  	if (ret < 0) {
>  		dev_err(dev->dev, "failed to initialize vblank\n");
> diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
> index 495150415020..6562d3d30b20 100644
> --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
> +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
> @@ -100,12 +100,18 @@ void vc4_perfmon_close_file(struct vc4_file *vc4file)
>  int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
>  			     struct drm_file *file_priv)
>  {
> +	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct vc4_file *vc4file = file_priv->driver_priv;
>  	struct drm_vc4_perfmon_create *req = data;
>  	struct vc4_perfmon *perfmon;
>  	unsigned int i;
>  	int ret;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("Creating perfmon no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	/* Number of monitored counters cannot exceed HW limits. */
>  	if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS ||
>  	    !req->ncounters)
> @@ -146,10 +152,16 @@ int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
>  int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
>  			      struct drm_file *file_priv)
>  {
> +	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct vc4_file *vc4file = file_priv->driver_priv;
>  	struct drm_vc4_perfmon_destroy *req = data;
>  	struct vc4_perfmon *perfmon;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("Destroying perfmon no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	mutex_lock(&vc4file->perfmon.lock);
>  	perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
>  	mutex_unlock(&vc4file->perfmon.lock);
> @@ -164,11 +176,17 @@ int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
>  int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
>  				 struct drm_file *file_priv)
>  {
> +	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct vc4_file *vc4file = file_priv->driver_priv;
>  	struct drm_vc4_perfmon_get_values *req = data;
>  	struct vc4_perfmon *perfmon;
>  	int ret;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("Getting perfmon no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	mutex_lock(&vc4file->perfmon.lock);
>  	perfmon = idr_find(&vc4file->perfmon.idr, req->id);
>  	vc4_perfmon_get(perfmon);
> diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
> index 36e6c7086ecf..a4b6859e3af6 100644
> --- a/drivers/gpu/drm/vc4/vc4_v3d.c
> +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
> @@ -474,7 +474,7 @@ static int vc4_v3d_dev_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -static const struct of_device_id vc4_v3d_dt_match[] = {
> +const struct of_device_id vc4_v3d_dt_match[] = {
>  	{ .compatible = "brcm,bcm2835-v3d" },
>  	{ .compatible = "brcm,cygnus-v3d" },
>  	{ .compatible = "brcm,vc4-v3d" },
-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components.
  2019-04-01 18:35 [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components Eric Anholt
  2019-04-01 18:35 ` [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe Eric Anholt
@ 2019-04-02 14:38 ` Paul Kocialkowski
  2019-04-03  9:17 ` Paul Kocialkowski
  2 siblings, 0 replies; 7+ messages in thread
From: Paul Kocialkowski @ 2019-04-02 14:38 UTC (permalink / raw)
  To: Eric Anholt, dri-devel; +Cc: linux-kernel, Maxime Ripard

Hi,

Le lundi 01 avril 2019 à 11:35 -0700, Eric Anholt a écrit :
> The global list of all debugfs entries for the driver was painful: the
> list couldn't see into the components' structs, so each component had
> its own debugs show function to find the component, then find the
> regset and dump it.  The components also had to be careful to check
> that they were actually registered in vc4 before dereferencing
> themselves, in case they weren't probed on a particular platform.
> They routinely failed at that.
> 
> Instead, we can have the components add their debugfs callbacks to a
> little list in vc4 to be registered at drm_dev_register() time, which
> gets vc4_debugfs.c out of the business of knowing the whole list of
> components.
> 
> Thanks to this change, dsi0 (if it existed) would register its node.
> 
> v2: Rebase on hvs_underrun addition.

Glad that we have a unified and relatively painless approach for
debugfs with this change. Looks good to me so this is:

Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>

Cheers,

Paul1`

> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>  drivers/gpu/drm/vc4/vc4_bo.c      |  6 +--
>  drivers/gpu/drm/vc4/vc4_crtc.c    | 33 +++----------
>  drivers/gpu/drm/vc4/vc4_debugfs.c | 82 ++++++++++++++++++++++++-------
>  drivers/gpu/drm/vc4/vc4_dpi.c     | 20 +-------
>  drivers/gpu/drm/vc4/vc4_drv.c     |  1 +
>  drivers/gpu/drm/vc4/vc4_drv.h     | 41 +++++++++++-----
>  drivers/gpu/drm/vc4/vc4_dsi.c     | 24 ++-------
>  drivers/gpu/drm/vc4/vc4_hdmi.c    |  6 +--
>  drivers/gpu/drm/vc4/vc4_hvs.c     | 20 ++------
>  drivers/gpu/drm/vc4/vc4_txp.c     | 20 +-------
>  drivers/gpu/drm/vc4/vc4_v3d.c     | 19 ++-----
>  drivers/gpu/drm/vc4/vc4_vec.c     | 20 +-------
>  12 files changed, 126 insertions(+), 166 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
> index 276ea9c550c0..88ebd681d7eb 100644
> --- a/drivers/gpu/drm/vc4/vc4_bo.c
> +++ b/drivers/gpu/drm/vc4/vc4_bo.c
> @@ -66,8 +66,7 @@ static void vc4_bo_stats_print(struct drm_printer *p, struct vc4_dev *vc4)
>  	mutex_unlock(&vc4->purgeable.lock);
>  }
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
> +static int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
>  {
>  	struct drm_info_node *node = (struct drm_info_node *)m->private;
>  	struct drm_device *dev = node->minor->dev;
> @@ -78,7 +77,6 @@ int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
>  
>  	return 0;
>  }
> -#endif
>  
>  /* Takes ownership of *name and returns the appropriate slot for it in
>   * the bo_labels[] array, extending it as necessary.
> @@ -1005,6 +1003,8 @@ int vc4_bo_cache_init(struct drm_device *dev)
>  
>  	mutex_init(&vc4->bo_lock);
>  
> +	vc4_debugfs_add_file(dev, "bo_stats", vc4_bo_stats_debugfs, NULL);
> +
>  	INIT_LIST_HEAD(&vc4->bo_cache.time_list);
>  
>  	INIT_WORK(&vc4->bo_cache.time_work, vc4_bo_cache_time_work);
> diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c
> index 6e564783ba94..b2891ca0e7f4 100644
> --- a/drivers/gpu/drm/vc4/vc4_crtc.c
> +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
> @@ -84,33 +84,6 @@ static const struct debugfs_reg32 crtc_regs[] = {
>  	VC4_REG32(PV_HACT_ACT),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_crtc_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	int crtc_index = (uintptr_t)node->info_ent->data;
> -	struct drm_printer p = drm_seq_file_printer(m);
> -	struct drm_crtc *crtc;
> -	struct vc4_crtc *vc4_crtc;
> -	int i;
> -
> -	i = 0;
> -	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
> -		if (i == crtc_index)
> -			break;
> -		i++;
> -	}
> -	if (!crtc)
> -		return 0;
> -	vc4_crtc = to_vc4_crtc(crtc);
> -
> -	drm_print_regset32(&p, &vc4_crtc->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
>  			     bool in_vblank_irq, int *vpos, int *hpos,
>  			     ktime_t *stime, ktime_t *etime,
> @@ -1070,6 +1043,7 @@ static const struct drm_crtc_helper_funcs vc4_crtc_helper_funcs = {
>  
>  static const struct vc4_crtc_data pv0_data = {
>  	.hvs_channel = 0,
> +	.debugfs_name = "crtc0_regs",
>  	.encoder_types = {
>  		[PV_CONTROL_CLK_SELECT_DSI] = VC4_ENCODER_TYPE_DSI0,
>  		[PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_DPI,
> @@ -1078,6 +1052,7 @@ static const struct vc4_crtc_data pv0_data = {
>  
>  static const struct vc4_crtc_data pv1_data = {
>  	.hvs_channel = 2,
> +	.debugfs_name = "crtc1_regs",
>  	.encoder_types = {
>  		[PV_CONTROL_CLK_SELECT_DSI] = VC4_ENCODER_TYPE_DSI1,
>  		[PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_SMI,
> @@ -1086,6 +1061,7 @@ static const struct vc4_crtc_data pv1_data = {
>  
>  static const struct vc4_crtc_data pv2_data = {
>  	.hvs_channel = 1,
> +	.debugfs_name = "crtc2_regs",
>  	.encoder_types = {
>  		[PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_HDMI,
>  		[PV_CONTROL_CLK_SELECT_VEC] = VC4_ENCODER_TYPE_VEC,
> @@ -1247,6 +1223,9 @@ static int vc4_crtc_bind(struct device *dev, struct device *master, void *data)
>  
>  	platform_set_drvdata(pdev, vc4_crtc);
>  
> +	vc4_debugfs_add_regset32(drm, vc4_crtc->data->debugfs_name,
> +				 &vc4_crtc->regset);
> +
>  	return 0;
>  
>  err_destroy_planes:
> diff --git a/drivers/gpu/drm/vc4/vc4_debugfs.c b/drivers/gpu/drm/vc4/vc4_debugfs.c
> index 59cdad89f844..69df84bdf904 100644
> --- a/drivers/gpu/drm/vc4/vc4_debugfs.c
> +++ b/drivers/gpu/drm/vc4/vc4_debugfs.c
> @@ -15,28 +15,20 @@
>  #include "vc4_drv.h"
>  #include "vc4_regs.h"
>  
> -static const struct drm_info_list vc4_debugfs_list[] = {
> -	{"bo_stats", vc4_bo_stats_debugfs, 0},
> -	{"dpi_regs", vc4_dpi_debugfs_regs, 0},
> -	{"dsi1_regs", vc4_dsi_debugfs_regs, 0, (void *)(uintptr_t)1},
> -	{"hdmi_regs", vc4_hdmi_debugfs_regs, 0},
> -	{"vec_regs", vc4_vec_debugfs_regs, 0},
> -	{"txp_regs", vc4_txp_debugfs_regs, 0},
> -	{"hvs_regs", vc4_hvs_debugfs_regs, 0},
> -	{"hvs_underrun",  vc4_hvs_debugfs_underrun, 0},
> -	{"crtc0_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)0},
> -	{"crtc1_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)1},
> -	{"crtc2_regs", vc4_crtc_debugfs_regs, 0, (void *)(uintptr_t)2},
> -	{"v3d_ident", vc4_v3d_debugfs_ident, 0},
> -	{"v3d_regs", vc4_v3d_debugfs_regs, 0},
> +struct vc4_debugfs_info_entry {
> +	struct list_head link;
> +	struct drm_info_list info;
>  };
>  
> -#define VC4_DEBUGFS_ENTRIES ARRAY_SIZE(vc4_debugfs_list)
> -
> +/**
> + * Called at drm_dev_register() time on each of the minors registered
> + * by the DRM device, to attach the debugfs files.
> + */
>  int
>  vc4_debugfs_init(struct drm_minor *minor)
>  {
>  	struct vc4_dev *vc4 = to_vc4_dev(minor->dev);
> +	struct vc4_debugfs_info_entry *entry;
>  	struct dentry *dentry;
>  
>  	dentry = debugfs_create_bool("hvs_load_tracker", S_IRUGO | S_IWUSR,
> @@ -45,6 +37,60 @@ vc4_debugfs_init(struct drm_minor *minor)
>  	if (!dentry)
>  		return -ENOMEM;
>  
> -	return drm_debugfs_create_files(vc4_debugfs_list, VC4_DEBUGFS_ENTRIES,
> -					minor->debugfs_root, minor);
> +	list_for_each_entry(entry, &vc4->debugfs_list, link) {
> +		int ret = drm_debugfs_create_files(&entry->info, 1,
> +						   minor->debugfs_root, minor);
> +
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +int vc4_debugfs_regset32(struct seq_file *m, void *unused)
> +{
> +	struct drm_info_node *node = (struct drm_info_node *)m->private;
> +	struct debugfs_regset32 *regset = node->info_ent->data;
> +	struct drm_printer p = drm_seq_file_printer(m);
> +
> +	drm_print_regset32(&p, regset);
> +
> +	return 0;
> +}
> +
> +/**
> + * Registers a debugfs file with a callback function for a vc4 component.
> + *
> + * This is like drm_debugfs_create_files(), but that can only be
> + * called a given DRM minor, while the various VC4 components want to
> + * register their debugfs files during the component bind process.  We
> + * track the request and delay it to be called on each minor during
> + * vc4_debugfs_init().
> + */
> +void vc4_debugfs_add_file(struct drm_device *dev,
> +			  const char *name,
> +			  int (*show)(struct seq_file*, void*),
> +			  void *data)
> +{
> +	struct vc4_dev *vc4 = to_vc4_dev(dev);
> +
> +	struct vc4_debugfs_info_entry *entry =
> +		devm_kzalloc(dev->dev, sizeof(*entry), GFP_KERNEL);
> +
> +	if (!entry)
> +		return;
> +
> +	entry->info.name = name;
> +	entry->info.show = show;
> +	entry->info.data = data;
> +
> +	list_add(&entry->link, &vc4->debugfs_list);
> +}
> +
> +void vc4_debugfs_add_regset32(struct drm_device *drm,
> +			      const char *name,
> +			      struct debugfs_regset32 *regset)
> +{
> +	vc4_debugfs_add_file(drm, name, vc4_debugfs_regset32, regset);
>  }
> diff --git a/drivers/gpu/drm/vc4/vc4_dpi.c b/drivers/gpu/drm/vc4/vc4_dpi.c
> index 8be2264f496a..34f90ca8f479 100644
> --- a/drivers/gpu/drm/vc4/vc4_dpi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dpi.c
> @@ -125,24 +125,6 @@ static const struct debugfs_reg32 dpi_regs[] = {
>  	VC4_REG32(DPI_ID),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct vc4_dpi *dpi = vc4->dpi;
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	if (!dpi)
> -		return 0;
> -
> -	drm_print_regset32(&p, &dpi->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  static const struct drm_encoder_funcs vc4_dpi_encoder_funcs = {
>  	.destroy = drm_encoder_cleanup,
>  };
> @@ -349,6 +331,8 @@ static int vc4_dpi_bind(struct device *dev, struct device *master, void *data)
>  
>  	vc4->dpi = dpi;
>  
> +	vc4_debugfs_add_regset32(drm, "dpi_regs", &dpi->regset);
> +
>  	return 0;
>  
>  err_destroy_encoder:
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
> index f2d0fb3aa729..3d6fccea5080 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.c
> +++ b/drivers/gpu/drm/vc4/vc4_drv.c
> @@ -262,6 +262,7 @@ static int vc4_drm_bind(struct device *dev)
>  	platform_set_drvdata(pdev, drm);
>  	vc4->dev = drm;
>  	drm->dev_private = vc4;
> +	INIT_LIST_HEAD(&vc4->debugfs_list);
>  
>  	ret = vc4_bo_cache_init(drm);
>  	if (ret)
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
> index f6c9de75d465..be85656024fa 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.h
> +++ b/drivers/gpu/drm/vc4/vc4_drv.h
> @@ -210,7 +210,12 @@ struct vc4_dev {
>  
>  	struct drm_modeset_lock ctm_state_lock;
>  	struct drm_private_obj ctm_manager;
> -	struct drm_private_obj load_tracker;
> + 	struct drm_private_obj load_tracker;
> +
> +	/* List of vc4_debugfs_info_entry for adding to debugfs once
> +	 * the minor is available (after drm_dev_register()).
> +	 */
> +	struct list_head debugfs_list;
>  };
>  
>  static inline struct vc4_dev *
> @@ -429,6 +434,7 @@ struct vc4_crtc_data {
>  	int hvs_channel;
>  
>  	enum vc4_encoder_type encoder_types[4];
> +	const char *debugfs_name;
>  };
>  
>  struct vc4_crtc {
> @@ -715,7 +721,6 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
>  void *vc4_prime_vmap(struct drm_gem_object *obj);
>  int vc4_bo_cache_init(struct drm_device *dev);
>  void vc4_bo_cache_destroy(struct drm_device *dev);
> -int vc4_bo_stats_debugfs(struct seq_file *m, void *arg);
>  int vc4_bo_inc_usecnt(struct vc4_bo *bo);
>  void vc4_bo_dec_usecnt(struct vc4_bo *bo);
>  void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
> @@ -723,7 +728,6 @@ void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
>  
>  /* vc4_crtc.c */
>  extern struct platform_driver vc4_crtc_driver;
> -int vc4_crtc_debugfs_regs(struct seq_file *m, void *arg);
>  bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
>  			     bool in_vblank_irq, int *vpos, int *hpos,
>  			     ktime_t *stime, ktime_t *etime,
> @@ -736,17 +740,37 @@ void vc4_crtc_get_margins(struct drm_crtc_state *state,
>  
>  /* vc4_debugfs.c */
>  int vc4_debugfs_init(struct drm_minor *minor);
> +#ifdef CONFIG_DEBUG_FS
> +void vc4_debugfs_add_file(struct drm_device *drm,
> +			  const char *filename,
> +			  int (*show)(struct seq_file*, void*),
> +			  void *data);
> +void vc4_debugfs_add_regset32(struct drm_device *drm,
> +			      const char *filename,
> +			      struct debugfs_regset32 *regset);
> +#else
> +static inline void vc4_debugfs_add_file(struct drm_device *drm,
> +					const char *filename,
> +					int (*show)(struct seq_file*, void*),
> +					void *data)
> +{
> +}
> +
> +static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
> +					    const char *filename,
> +					    struct debugfs_regset32 *regset)
> +{
> +}
> +#endif
>  
>  /* vc4_drv.c */
>  void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
>  
>  /* vc4_dpi.c */
>  extern struct platform_driver vc4_dpi_driver;
> -int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_dsi.c */
>  extern struct platform_driver vc4_dsi_driver;
> -int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_fence.c */
>  extern const struct dma_fence_ops vc4_fence_ops;
> @@ -774,15 +798,12 @@ int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
>  
>  /* vc4_hdmi.c */
>  extern struct platform_driver vc4_hdmi_driver;
> -int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_vec.c */
>  extern struct platform_driver vc4_vec_driver;
> -int vc4_vec_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_txp.c */
>  extern struct platform_driver vc4_txp_driver;
> -int vc4_txp_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_irq.c */
>  irqreturn_t vc4_irq(int irq, void *arg);
> @@ -794,8 +815,6 @@ void vc4_irq_reset(struct drm_device *dev);
>  /* vc4_hvs.c */
>  extern struct platform_driver vc4_hvs_driver;
>  void vc4_hvs_dump_state(struct drm_device *dev);
> -int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused);
> -int vc4_hvs_debugfs_underrun(struct seq_file *m, void *unused);
>  void vc4_hvs_unmask_underrun(struct drm_device *dev, int channel);
>  void vc4_hvs_mask_underrun(struct drm_device *dev, int channel);
>  
> @@ -812,8 +831,6 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
>  
>  /* vc4_v3d.c */
>  extern struct platform_driver vc4_v3d_driver;
> -int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
> -int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
>  int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
>  int vc4_v3d_pm_get(struct vc4_dev *vc4);
>  void vc4_v3d_pm_put(struct vc4_dev *vc4);
> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> index 806cfaa2a6a7..9412709067f5 100644
> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> @@ -657,25 +657,6 @@ static const struct debugfs_reg32 dsi1_regs[] = {
>  	VC4_REG32(DSI1_ID),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *drm = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(drm);
> -	int dsi_index = (uintptr_t)node->info_ent->data;
> -	struct vc4_dsi *dsi = (dsi_index == 1 ? vc4->dsi1 : NULL);
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	if (!dsi)
> -		return 0;
> -
> -	drm_print_regset32(&p, &dsi->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  static void vc4_dsi_encoder_destroy(struct drm_encoder *encoder)
>  {
>  	drm_encoder_cleanup(encoder);
> @@ -1637,6 +1618,11 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
>  	 */
>  	dsi->encoder->bridge = NULL;
>  
> +	if (dsi->port == 0)
> +		vc4_debugfs_add_regset32(drm, "dsi0_regs", &dsi->regset);
> +	else
> +		vc4_debugfs_add_regset32(drm, "dsi1_regs", &dsi->regset);
> +
>  	pm_runtime_enable(dev);
>  
>  	return 0;
> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
> index 38c9172cfe52..99fc8569e0f5 100644
> --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
> +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
> @@ -187,8 +187,7 @@ static const struct debugfs_reg32 hd_regs[] = {
>  	VC4_REG32(VC4_HD_FRAME_COUNT),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
> +static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
>  {
>  	struct drm_info_node *node = (struct drm_info_node *)m->private;
>  	struct drm_device *dev = node->minor->dev;
> @@ -201,7 +200,6 @@ int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
>  
>  	return 0;
>  }
> -#endif /* CONFIG_DEBUG_FS */
>  
>  static enum drm_connector_status
>  vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
> @@ -1432,6 +1430,8 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
>  	if (ret)
>  		goto err_destroy_encoder;
>  
> +	vc4_debugfs_add_file(drm, "hdmi_regs", vc4_hdmi_debugfs_regs, hdmi);
> +
>  	return 0;
>  
>  #ifdef CONFIG_DRM_VC4_HDMI_CEC
> diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
> index c463453f941b..f746e9a7a88c 100644
> --- a/drivers/gpu/drm/vc4/vc4_hvs.c
> +++ b/drivers/gpu/drm/vc4/vc4_hvs.c
> @@ -80,20 +80,7 @@ void vc4_hvs_dump_state(struct drm_device *dev)
>  	}
>  }
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	drm_print_regset32(&p, &vc4->hvs->regset);
> -
> -	return 0;
> -}
> -
> -int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
> +static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
>  {
>  	struct drm_info_node *node = m->private;
>  	struct drm_device *dev = node->minor->dev;
> @@ -104,7 +91,6 @@ int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
>  
>  	return 0;
>  }
> -#endif
>  
>  /* The filter kernel is composed of dwords each containing 3 9-bit
>   * signed integers packed next to each other.
> @@ -316,6 +302,10 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
>  	if (ret)
>  		return ret;
>  
> +	vc4_debugfs_add_regset32(drm, "hvs_regs", &hvs->regset);
> +	vc4_debugfs_add_file(drm, "hvs_underrun", vc4_hvs_debugfs_underrun,
> +			     NULL);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_txp.c b/drivers/gpu/drm/vc4/vc4_txp.c
> index c8f80064c179..1220f4a5aac4 100644
> --- a/drivers/gpu/drm/vc4/vc4_txp.c
> +++ b/drivers/gpu/drm/vc4/vc4_txp.c
> @@ -169,24 +169,6 @@ static const struct debugfs_reg32 txp_regs[] = {
>  	VC4_REG32(TXP_PROGRESS),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_txp_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct vc4_txp *txp = vc4->txp;
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	if (!txp)
> -		return 0;
> -
> -	drm_print_regset32(&p, &txp->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  static int vc4_txp_connector_get_modes(struct drm_connector *connector)
>  {
>  	struct drm_device *dev = connector->dev;
> @@ -424,6 +406,8 @@ static int vc4_txp_bind(struct device *dev, struct device *master, void *data)
>  	dev_set_drvdata(dev, txp);
>  	vc4->txp = txp;
>  
> +	vc4_debugfs_add_regset32(drm, "txp_regs", &txp->regset);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
> index 27c70eb52405..36e6c7086ecf 100644
> --- a/drivers/gpu/drm/vc4/vc4_v3d.c
> +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
> @@ -22,7 +22,6 @@
>  #include "vc4_drv.h"
>  #include "vc4_regs.h"
>  
> -#ifdef CONFIG_DEBUG_FS
>  static const struct debugfs_reg32 v3d_regs[] = {
>  	VC4_REG32(V3D_IDENT0),
>  	VC4_REG32(V3D_IDENT1),
> @@ -104,19 +103,7 @@ static const struct debugfs_reg32 v3d_regs[] = {
>  	VC4_REG32(V3D_ERRSTAT),
>  };
>  
> -int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	drm_print_regset32(&p, &vc4->v3d->regset);
> -
> -	return 0;
> -}
> -
> -int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
> +static int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
>  {
>  	struct drm_info_node *node = (struct drm_info_node *)m->private;
>  	struct drm_device *dev = node->minor->dev;
> @@ -141,7 +128,6 @@ int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
>  
>  	return 0;
>  }
> -#endif /* CONFIG_DEBUG_FS */
>  
>  /**
>   * Wraps pm_runtime_get_sync() in a refcount, so that we can reliably
> @@ -442,6 +428,9 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
>  	pm_runtime_set_autosuspend_delay(dev, 40); /* a little over 2 frames. */
>  	pm_runtime_enable(dev);
>  
> +	vc4_debugfs_add_file(drm, "v3d_ident", vc4_v3d_debugfs_ident, NULL);
> +	vc4_debugfs_add_regset32(drm, "v3d_regs", &v3d->regset);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_vec.c b/drivers/gpu/drm/vc4/vc4_vec.c
> index 83227d2440aa..0a27e48fab31 100644
> --- a/drivers/gpu/drm/vc4/vc4_vec.c
> +++ b/drivers/gpu/drm/vc4/vc4_vec.c
> @@ -252,24 +252,6 @@ static const struct debugfs_reg32 vec_regs[] = {
>  	VC4_REG32(VEC_DAC_MISC),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_vec_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct vc4_vec *vec = vc4->vec;
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	if (!vec)
> -		return 0;
> -
> -	drm_print_regset32(&p, &vec->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  static void vc4_vec_ntsc_mode_set(struct vc4_vec *vec)
>  {
>  	VEC_WRITE(VEC_CONFIG0, VEC_CONFIG0_NTSC_STD | VEC_CONFIG0_PDEN);
> @@ -609,6 +591,8 @@ static int vc4_vec_bind(struct device *dev, struct device *master, void *data)
>  
>  	vc4->vec = vec;
>  
> +	vc4_debugfs_add_regset32(drm, "vec_regs", &vec->regset);
> +
>  	return 0;
>  
>  err_destroy_encoder:
-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components.
  2019-04-01 18:35 [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components Eric Anholt
  2019-04-01 18:35 ` [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe Eric Anholt
  2019-04-02 14:38 ` [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components Paul Kocialkowski
@ 2019-04-03  9:17 ` Paul Kocialkowski
  2 siblings, 0 replies; 7+ messages in thread
From: Paul Kocialkowski @ 2019-04-03  9:17 UTC (permalink / raw)
  To: Eric Anholt, dri-devel; +Cc: linux-kernel, Maxime Ripard

Hi,

Le lundi 01 avril 2019 à 11:35 -0700, Eric Anholt a écrit :
> The global list of all debugfs entries for the driver was painful: the
> list couldn't see into the components' structs, so each component had
> its own debugs show function to find the component, then find the
> regset and dump it.  The components also had to be careful to check
> that they were actually registered in vc4 before dereferencing
> themselves, in case they weren't probed on a particular platform.
> They routinely failed at that.
> 
> Instead, we can have the components add their debugfs callbacks to a
> little list in vc4 to be registered at drm_dev_register() time, which
> gets vc4_debugfs.c out of the business of knowing the whole list of
> components.
> 
> Thanks to this change, dsi0 (if it existed) would register its node.
> 
> v2: Rebase on hvs_underrun addition.
> 
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>  drivers/gpu/drm/vc4/vc4_bo.c      |  6 +--
>  drivers/gpu/drm/vc4/vc4_crtc.c    | 33 +++----------
>  drivers/gpu/drm/vc4/vc4_debugfs.c | 82 ++++++++++++++++++++++++-------
>  drivers/gpu/drm/vc4/vc4_dpi.c     | 20 +-------
>  drivers/gpu/drm/vc4/vc4_drv.c     |  1 +
>  drivers/gpu/drm/vc4/vc4_drv.h     | 41 +++++++++++-----
>  drivers/gpu/drm/vc4/vc4_dsi.c     | 24 ++-------
>  drivers/gpu/drm/vc4/vc4_hdmi.c    |  6 +--
>  drivers/gpu/drm/vc4/vc4_hvs.c     | 20 ++------
>  drivers/gpu/drm/vc4/vc4_txp.c     | 20 +-------
>  drivers/gpu/drm/vc4/vc4_v3d.c     | 19 ++-----
>  drivers/gpu/drm/vc4/vc4_vec.c     | 20 +-------
>  12 files changed, 126 insertions(+), 166 deletions(-)

[...]

> diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
> index f6c9de75d465..be85656024fa 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.h
> +++ b/drivers/gpu/drm/vc4/vc4_drv.h
> @@ -210,7 +210,12 @@ struct vc4_dev {
>  
>  	struct drm_modeset_lock ctm_state_lock;
>  	struct drm_private_obj ctm_manager;
> -	struct drm_private_obj load_tracker;
> + 	struct drm_private_obj load_tracker;

FYI git am tells me you have a space-before-tab here :)

Cheers,

Paul

> +
> +	/* List of vc4_debugfs_info_entry for adding to debugfs once
> +	 * the minor is available (after drm_dev_register()).
> +	 */
> +	struct list_head debugfs_list;
>  };
>  
>  static inline struct vc4_dev *
> @@ -429,6 +434,7 @@ struct vc4_crtc_data {
>  	int hvs_channel;
>  
>  	enum vc4_encoder_type encoder_types[4];
> +	const char *debugfs_name;
>  };
>  
>  struct vc4_crtc {
> @@ -715,7 +721,6 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
>  void *vc4_prime_vmap(struct drm_gem_object *obj);
>  int vc4_bo_cache_init(struct drm_device *dev);
>  void vc4_bo_cache_destroy(struct drm_device *dev);
> -int vc4_bo_stats_debugfs(struct seq_file *m, void *arg);
>  int vc4_bo_inc_usecnt(struct vc4_bo *bo);
>  void vc4_bo_dec_usecnt(struct vc4_bo *bo);
>  void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
> @@ -723,7 +728,6 @@ void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
>  
>  /* vc4_crtc.c */
>  extern struct platform_driver vc4_crtc_driver;
> -int vc4_crtc_debugfs_regs(struct seq_file *m, void *arg);
>  bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
>  			     bool in_vblank_irq, int *vpos, int *hpos,
>  			     ktime_t *stime, ktime_t *etime,
> @@ -736,17 +740,37 @@ void vc4_crtc_get_margins(struct drm_crtc_state *state,
>  
>  /* vc4_debugfs.c */
>  int vc4_debugfs_init(struct drm_minor *minor);
> +#ifdef CONFIG_DEBUG_FS
> +void vc4_debugfs_add_file(struct drm_device *drm,
> +			  const char *filename,
> +			  int (*show)(struct seq_file*, void*),
> +			  void *data);
> +void vc4_debugfs_add_regset32(struct drm_device *drm,
> +			      const char *filename,
> +			      struct debugfs_regset32 *regset);
> +#else
> +static inline void vc4_debugfs_add_file(struct drm_device *drm,
> +					const char *filename,
> +					int (*show)(struct seq_file*, void*),
> +					void *data)
> +{
> +}
> +
> +static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
> +					    const char *filename,
> +					    struct debugfs_regset32 *regset)
> +{
> +}
> +#endif
>  
>  /* vc4_drv.c */
>  void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
>  
>  /* vc4_dpi.c */
>  extern struct platform_driver vc4_dpi_driver;
> -int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_dsi.c */
>  extern struct platform_driver vc4_dsi_driver;
> -int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_fence.c */
>  extern const struct dma_fence_ops vc4_fence_ops;
> @@ -774,15 +798,12 @@ int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
>  
>  /* vc4_hdmi.c */
>  extern struct platform_driver vc4_hdmi_driver;
> -int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_vec.c */
>  extern struct platform_driver vc4_vec_driver;
> -int vc4_vec_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_txp.c */
>  extern struct platform_driver vc4_txp_driver;
> -int vc4_txp_debugfs_regs(struct seq_file *m, void *unused);
>  
>  /* vc4_irq.c */
>  irqreturn_t vc4_irq(int irq, void *arg);
> @@ -794,8 +815,6 @@ void vc4_irq_reset(struct drm_device *dev);
>  /* vc4_hvs.c */
>  extern struct platform_driver vc4_hvs_driver;
>  void vc4_hvs_dump_state(struct drm_device *dev);
> -int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused);
> -int vc4_hvs_debugfs_underrun(struct seq_file *m, void *unused);
>  void vc4_hvs_unmask_underrun(struct drm_device *dev, int channel);
>  void vc4_hvs_mask_underrun(struct drm_device *dev, int channel);
>  
> @@ -812,8 +831,6 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
>  
>  /* vc4_v3d.c */
>  extern struct platform_driver vc4_v3d_driver;
> -int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
> -int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
>  int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
>  int vc4_v3d_pm_get(struct vc4_dev *vc4);
>  void vc4_v3d_pm_put(struct vc4_dev *vc4);
> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> index 806cfaa2a6a7..9412709067f5 100644
> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> @@ -657,25 +657,6 @@ static const struct debugfs_reg32 dsi1_regs[] = {
>  	VC4_REG32(DSI1_ID),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *drm = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(drm);
> -	int dsi_index = (uintptr_t)node->info_ent->data;
> -	struct vc4_dsi *dsi = (dsi_index == 1 ? vc4->dsi1 : NULL);
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	if (!dsi)
> -		return 0;
> -
> -	drm_print_regset32(&p, &dsi->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  static void vc4_dsi_encoder_destroy(struct drm_encoder *encoder)
>  {
>  	drm_encoder_cleanup(encoder);
> @@ -1637,6 +1618,11 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
>  	 */
>  	dsi->encoder->bridge = NULL;
>  
> +	if (dsi->port == 0)
> +		vc4_debugfs_add_regset32(drm, "dsi0_regs", &dsi->regset);
> +	else
> +		vc4_debugfs_add_regset32(drm, "dsi1_regs", &dsi->regset);
> +
>  	pm_runtime_enable(dev);
>  
>  	return 0;
> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
> index 38c9172cfe52..99fc8569e0f5 100644
> --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
> +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
> @@ -187,8 +187,7 @@ static const struct debugfs_reg32 hd_regs[] = {
>  	VC4_REG32(VC4_HD_FRAME_COUNT),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
> +static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
>  {
>  	struct drm_info_node *node = (struct drm_info_node *)m->private;
>  	struct drm_device *dev = node->minor->dev;
> @@ -201,7 +200,6 @@ int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
>  
>  	return 0;
>  }
> -#endif /* CONFIG_DEBUG_FS */
>  
>  static enum drm_connector_status
>  vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
> @@ -1432,6 +1430,8 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
>  	if (ret)
>  		goto err_destroy_encoder;
>  
> +	vc4_debugfs_add_file(drm, "hdmi_regs", vc4_hdmi_debugfs_regs, hdmi);
> +
>  	return 0;
>  
>  #ifdef CONFIG_DRM_VC4_HDMI_CEC
> diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
> index c463453f941b..f746e9a7a88c 100644
> --- a/drivers/gpu/drm/vc4/vc4_hvs.c
> +++ b/drivers/gpu/drm/vc4/vc4_hvs.c
> @@ -80,20 +80,7 @@ void vc4_hvs_dump_state(struct drm_device *dev)
>  	}
>  }
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	drm_print_regset32(&p, &vc4->hvs->regset);
> -
> -	return 0;
> -}
> -
> -int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
> +static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
>  {
>  	struct drm_info_node *node = m->private;
>  	struct drm_device *dev = node->minor->dev;
> @@ -104,7 +91,6 @@ int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
>  
>  	return 0;
>  }
> -#endif
>  
>  /* The filter kernel is composed of dwords each containing 3 9-bit
>   * signed integers packed next to each other.
> @@ -316,6 +302,10 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
>  	if (ret)
>  		return ret;
>  
> +	vc4_debugfs_add_regset32(drm, "hvs_regs", &hvs->regset);
> +	vc4_debugfs_add_file(drm, "hvs_underrun", vc4_hvs_debugfs_underrun,
> +			     NULL);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_txp.c b/drivers/gpu/drm/vc4/vc4_txp.c
> index c8f80064c179..1220f4a5aac4 100644
> --- a/drivers/gpu/drm/vc4/vc4_txp.c
> +++ b/drivers/gpu/drm/vc4/vc4_txp.c
> @@ -169,24 +169,6 @@ static const struct debugfs_reg32 txp_regs[] = {
>  	VC4_REG32(TXP_PROGRESS),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_txp_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct vc4_txp *txp = vc4->txp;
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	if (!txp)
> -		return 0;
> -
> -	drm_print_regset32(&p, &txp->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  static int vc4_txp_connector_get_modes(struct drm_connector *connector)
>  {
>  	struct drm_device *dev = connector->dev;
> @@ -424,6 +406,8 @@ static int vc4_txp_bind(struct device *dev, struct device *master, void *data)
>  	dev_set_drvdata(dev, txp);
>  	vc4->txp = txp;
>  
> +	vc4_debugfs_add_regset32(drm, "txp_regs", &txp->regset);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
> index 27c70eb52405..36e6c7086ecf 100644
> --- a/drivers/gpu/drm/vc4/vc4_v3d.c
> +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
> @@ -22,7 +22,6 @@
>  #include "vc4_drv.h"
>  #include "vc4_regs.h"
>  
> -#ifdef CONFIG_DEBUG_FS
>  static const struct debugfs_reg32 v3d_regs[] = {
>  	VC4_REG32(V3D_IDENT0),
>  	VC4_REG32(V3D_IDENT1),
> @@ -104,19 +103,7 @@ static const struct debugfs_reg32 v3d_regs[] = {
>  	VC4_REG32(V3D_ERRSTAT),
>  };
>  
> -int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	drm_print_regset32(&p, &vc4->v3d->regset);
> -
> -	return 0;
> -}
> -
> -int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
> +static int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
>  {
>  	struct drm_info_node *node = (struct drm_info_node *)m->private;
>  	struct drm_device *dev = node->minor->dev;
> @@ -141,7 +128,6 @@ int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
>  
>  	return 0;
>  }
> -#endif /* CONFIG_DEBUG_FS */
>  
>  /**
>   * Wraps pm_runtime_get_sync() in a refcount, so that we can reliably
> @@ -442,6 +428,9 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
>  	pm_runtime_set_autosuspend_delay(dev, 40); /* a little over 2 frames. */
>  	pm_runtime_enable(dev);
>  
> +	vc4_debugfs_add_file(drm, "v3d_ident", vc4_v3d_debugfs_ident, NULL);
> +	vc4_debugfs_add_regset32(drm, "v3d_regs", &v3d->regset);
> +
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_vec.c b/drivers/gpu/drm/vc4/vc4_vec.c
> index 83227d2440aa..0a27e48fab31 100644
> --- a/drivers/gpu/drm/vc4/vc4_vec.c
> +++ b/drivers/gpu/drm/vc4/vc4_vec.c
> @@ -252,24 +252,6 @@ static const struct debugfs_reg32 vec_regs[] = {
>  	VC4_REG32(VEC_DAC_MISC),
>  };
>  
> -#ifdef CONFIG_DEBUG_FS
> -int vc4_vec_debugfs_regs(struct seq_file *m, void *unused)
> -{
> -	struct drm_info_node *node = (struct drm_info_node *)m->private;
> -	struct drm_device *dev = node->minor->dev;
> -	struct vc4_dev *vc4 = to_vc4_dev(dev);
> -	struct vc4_vec *vec = vc4->vec;
> -	struct drm_printer p = drm_seq_file_printer(m);
> -
> -	if (!vec)
> -		return 0;
> -
> -	drm_print_regset32(&p, &vec->regset);
> -
> -	return 0;
> -}
> -#endif
> -
>  static void vc4_vec_ntsc_mode_set(struct vc4_vec *vec)
>  {
>  	VEC_WRITE(VEC_CONFIG0, VEC_CONFIG0_NTSC_STD | VEC_CONFIG0_PDEN);
> @@ -609,6 +591,8 @@ static int vc4_vec_bind(struct device *dev, struct device *master, void *data)
>  
>  	vc4->vec = vec;
>  
> +	vc4_debugfs_add_regset32(drm, "vec_regs", &vec->regset);
> +
>  	return 0;
>  
>  err_destroy_encoder:
-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe.
  2019-04-01 18:35 ` [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe Eric Anholt
  2019-04-02 14:27   ` Paul Kocialkowski
@ 2019-04-03 13:30   ` Paul Kocialkowski
  2019-04-03 19:15     ` Eric Anholt
  1 sibling, 1 reply; 7+ messages in thread
From: Paul Kocialkowski @ 2019-04-03 13:30 UTC (permalink / raw)
  To: Eric Anholt, dri-devel; +Cc: linux-kernel, Maxime Ripard

Hi,

On Mon, 2019-04-01 at 11:35 -0700, Eric Anholt wrote:
> One might want to use the VC4 display stack without using Mesa.
> Similar to the debugfs fixes for not having all of the possible
> display bits enabled, make sure you can't oops in vc4 if v3d isn't
> enabled.

Just thought about this: perhaps we should be returning -ENODEV instead
of -EINVAL when !vc4->v3d, just so that the error is a bit more
explicit to userspace?

Cheers,

Paul

> v2: Fix matching against other v3d variants (review by Paul), don't
>     forget to set irq_enabled so that the vblank uapi works
> 
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>  drivers/gpu/drm/vc4/vc4_drv.c     | 10 ++++++++++
>  drivers/gpu/drm/vc4/vc4_drv.h     |  1 +
>  drivers/gpu/drm/vc4/vc4_gem.c     | 10 ++++++++++
>  drivers/gpu/drm/vc4/vc4_irq.c     |  9 +++++++++
>  drivers/gpu/drm/vc4/vc4_kms.c     |  1 +
>  drivers/gpu/drm/vc4/vc4_perfmon.c | 18 ++++++++++++++++++
>  drivers/gpu/drm/vc4/vc4_v3d.c     |  2 +-
>  7 files changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
> index 3d6fccea5080..d840b52b9805 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.c
> +++ b/drivers/gpu/drm/vc4/vc4_drv.c
> @@ -72,6 +72,9 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
>  	if (args->pad != 0)
>  		return -EINVAL;
>  
> +	if (!vc4->v3d)
> +		return -EINVAL;
> +
>  	switch (args->param) {
>  	case DRM_VC4_PARAM_V3D_IDENT0:
>  		ret = vc4_v3d_pm_get(vc4);
> @@ -248,6 +251,7 @@ static int vc4_drm_bind(struct device *dev)
>  	struct platform_device *pdev = to_platform_device(dev);
>  	struct drm_device *drm;
>  	struct vc4_dev *vc4;
> +	struct device_node *node;
>  	int ret = 0;
>  
>  	dev->coherent_dma_mask = DMA_BIT_MASK(32);
> @@ -256,6 +260,12 @@ static int vc4_drm_bind(struct device *dev)
>  	if (!vc4)
>  		return -ENOMEM;
>  
> +	/* If VC4 V3D is missing, don't advertise render nodes. */
> +	node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
> +	if (!node || !of_device_is_available(node))
> +		vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
> +	of_node_put(node);
> +
>  	drm = drm_dev_alloc(&vc4_drm_driver, dev);
>  	if (IS_ERR(drm))
>  		return PTR_ERR(drm);
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
> index be85656024fa..e61734af059b 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.h
> +++ b/drivers/gpu/drm/vc4/vc4_drv.h
> @@ -831,6 +831,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
>  
>  /* vc4_v3d.c */
>  extern struct platform_driver vc4_v3d_driver;
> +extern const struct of_device_id vc4_v3d_dt_match[];
>  int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
>  int vc4_v3d_pm_get(struct vc4_dev *vc4);
>  void vc4_v3d_pm_put(struct vc4_dev *vc4);
> diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
> index 5e9496d477bf..4544a478f106 100644
> --- a/drivers/gpu/drm/vc4/vc4_gem.c
> +++ b/drivers/gpu/drm/vc4/vc4_gem.c
> @@ -74,6 +74,11 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
>  	u32 i;
>  	int ret = 0;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	spin_lock_irqsave(&vc4->job_lock, irqflags);
>  	kernel_state = vc4->hang_state;
>  	if (!kernel_state) {
> @@ -1119,6 +1124,11 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
>  	struct dma_fence *in_fence;
>  	int ret = 0;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
>  			     VC4_SUBMIT_CL_FIXED_RCL_ORDER |
>  			     VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
> diff --git a/drivers/gpu/drm/vc4/vc4_irq.c b/drivers/gpu/drm/vc4/vc4_irq.c
> index 4cd2ccfe15f4..ffd0a4388752 100644
> --- a/drivers/gpu/drm/vc4/vc4_irq.c
> +++ b/drivers/gpu/drm/vc4/vc4_irq.c
> @@ -229,6 +229,9 @@ vc4_irq_preinstall(struct drm_device *dev)
>  {
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  
> +	if (!vc4->v3d)
> +		return;
> +
>  	init_waitqueue_head(&vc4->job_wait_queue);
>  	INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
>  
> @@ -243,6 +246,9 @@ vc4_irq_postinstall(struct drm_device *dev)
>  {
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  
> +	if (!vc4->v3d)
> +		return 0;
> +
>  	/* Enable both the render done and out of memory interrupts. */
>  	V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
>  
> @@ -254,6 +260,9 @@ vc4_irq_uninstall(struct drm_device *dev)
>  {
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  
> +	if (!vc4->v3d)
> +		return;
> +
>  	/* Disable sending interrupts for our driver's IRQs. */
>  	V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS);
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c
> index 5160cad25fce..295dacc8bcb9 100644
> --- a/drivers/gpu/drm/vc4/vc4_kms.c
> +++ b/drivers/gpu/drm/vc4/vc4_kms.c
> @@ -525,6 +525,7 @@ int vc4_kms_load(struct drm_device *dev)
>  	/* Set support for vblank irq fast disable, before drm_vblank_init() */
>  	dev->vblank_disable_immediate = true;
>  
> +	dev->irq_enabled = true;
>  	ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
>  	if (ret < 0) {
>  		dev_err(dev->dev, "failed to initialize vblank\n");
> diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
> index 495150415020..6562d3d30b20 100644
> --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
> +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
> @@ -100,12 +100,18 @@ void vc4_perfmon_close_file(struct vc4_file *vc4file)
>  int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
>  			     struct drm_file *file_priv)
>  {
> +	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct vc4_file *vc4file = file_priv->driver_priv;
>  	struct drm_vc4_perfmon_create *req = data;
>  	struct vc4_perfmon *perfmon;
>  	unsigned int i;
>  	int ret;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("Creating perfmon no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	/* Number of monitored counters cannot exceed HW limits. */
>  	if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS ||
>  	    !req->ncounters)
> @@ -146,10 +152,16 @@ int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
>  int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
>  			      struct drm_file *file_priv)
>  {
> +	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct vc4_file *vc4file = file_priv->driver_priv;
>  	struct drm_vc4_perfmon_destroy *req = data;
>  	struct vc4_perfmon *perfmon;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("Destroying perfmon no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	mutex_lock(&vc4file->perfmon.lock);
>  	perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
>  	mutex_unlock(&vc4file->perfmon.lock);
> @@ -164,11 +176,17 @@ int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
>  int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
>  				 struct drm_file *file_priv)
>  {
> +	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct vc4_file *vc4file = file_priv->driver_priv;
>  	struct drm_vc4_perfmon_get_values *req = data;
>  	struct vc4_perfmon *perfmon;
>  	int ret;
>  
> +	if (!vc4->v3d) {
> +		DRM_DEBUG("Getting perfmon no VC4 V3D probed\n");
> +		return -EINVAL;
> +	}
> +
>  	mutex_lock(&vc4file->perfmon.lock);
>  	perfmon = idr_find(&vc4file->perfmon.idr, req->id);
>  	vc4_perfmon_get(perfmon);
> diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
> index 36e6c7086ecf..a4b6859e3af6 100644
> --- a/drivers/gpu/drm/vc4/vc4_v3d.c
> +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
> @@ -474,7 +474,7 @@ static int vc4_v3d_dev_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -static const struct of_device_id vc4_v3d_dt_match[] = {
> +const struct of_device_id vc4_v3d_dt_match[] = {
>  	{ .compatible = "brcm,bcm2835-v3d" },
>  	{ .compatible = "brcm,cygnus-v3d" },
>  	{ .compatible = "brcm,vc4-v3d" },
-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe.
  2019-04-03 13:30   ` Paul Kocialkowski
@ 2019-04-03 19:15     ` Eric Anholt
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Anholt @ 2019-04-03 19:15 UTC (permalink / raw)
  To: Paul Kocialkowski, dri-devel; +Cc: linux-kernel, Maxime Ripard

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

Paul Kocialkowski <paul.kocialkowski@bootlin.com> writes:

> Hi,
>
> On Mon, 2019-04-01 at 11:35 -0700, Eric Anholt wrote:
>> One might want to use the VC4 display stack without using Mesa.
>> Similar to the debugfs fixes for not having all of the possible
>> display bits enabled, make sure you can't oops in vc4 if v3d isn't
>> enabled.
>
> Just thought about this: perhaps we should be returning -ENODEV instead
> of -EINVAL when !vc4->v3d, just so that the error is a bit more
> explicit to userspace?

I like it.  Doing that while applying the series.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-04-03 19:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-01 18:35 [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components Eric Anholt
2019-04-01 18:35 ` [PATCH v2 2/2] drm/vc4: Disable V3D interactions if the v3d component didn't probe Eric Anholt
2019-04-02 14:27   ` Paul Kocialkowski
2019-04-03 13:30   ` Paul Kocialkowski
2019-04-03 19:15     ` Eric Anholt
2019-04-02 14:38 ` [PATCH v2 1/2] drm/vc4: Use common helpers for debugfs setup by the driver components Paul Kocialkowski
2019-04-03  9:17 ` Paul Kocialkowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).