Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9be804c authored by Eric Anholt's avatar Eric Anholt
Browse files

drm/vc4: Use common helpers for debugfs setup by the driver components.



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.
v3: whitespace fixup

Signed-off-by: default avatarEric Anholt <eric@anholt.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20190401183559.3823-1-eric@anholt.net


Reviewed-by: default avatarPaul Kocialkowski <paul.kocialkowski@bootlin.com>
parent fc13d710
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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);
+6 −27
Original line number Diff line number Diff line
@@ -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:
+64 −18
Original line number Diff line number Diff line
@@ -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,
	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);
}
+2 −18
Original line number Diff line number Diff line
@@ -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:
+1 −0
Original line number Diff line number Diff line
@@ -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)
Loading