1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 *  Copyright �� 2014 Broadcom
4 */
5
6#include <linux/seq_file.h>
7#include <linux/circ_buf.h>
8#include <linux/ctype.h>
9#include <linux/debugfs.h>
10#include <linux/platform_device.h>
11
12#include "vc4_drv.h"
13#include "vc4_regs.h"
14
15struct vc4_debugfs_info_entry {
16	struct list_head link;
17	struct drm_info_list info;
18};
19
20/*
21 * Called at drm_dev_register() time on each of the minors registered
22 * by the DRM device, to attach the debugfs files.
23 */
24void
25vc4_debugfs_init(struct drm_minor *minor)
26{
27	struct vc4_dev *vc4 = to_vc4_dev(minor->dev);
28	struct vc4_debugfs_info_entry *entry;
29
30	if (!of_device_is_compatible(vc4->hvs->pdev->dev.of_node,
31				     "brcm,bcm2711-vc5"))
32		debugfs_create_bool("hvs_load_tracker", S_IRUGO | S_IWUSR,
33				    minor->debugfs_root, &vc4->load_tracker_enabled);
34
35	list_for_each_entry(entry, &vc4->debugfs_list, link) {
36		drm_debugfs_create_files(&entry->info, 1,
37					 minor->debugfs_root, minor);
38	}
39}
40
41static int vc4_debugfs_regset32(struct seq_file *m, void *unused)
42{
43	struct drm_info_node *node = (struct drm_info_node *)m->private;
44	struct debugfs_regset32 *regset = node->info_ent->data;
45	struct drm_printer p = drm_seq_file_printer(m);
46
47	drm_print_regset32(&p, regset);
48
49	return 0;
50}
51
52/*
53 * Registers a debugfs file with a callback function for a vc4 component.
54 *
55 * This is like drm_debugfs_create_files(), but that can only be
56 * called a given DRM minor, while the various VC4 components want to
57 * register their debugfs files during the component bind process.  We
58 * track the request and delay it to be called on each minor during
59 * vc4_debugfs_init().
60 */
61void vc4_debugfs_add_file(struct drm_device *dev,
62			  const char *name,
63			  int (*show)(struct seq_file*, void*),
64			  void *data)
65{
66	struct vc4_dev *vc4 = to_vc4_dev(dev);
67
68	struct vc4_debugfs_info_entry *entry =
69		devm_kzalloc(dev->dev, sizeof(*entry), GFP_KERNEL);
70
71	if (!entry)
72		return;
73
74	entry->info.name = name;
75	entry->info.show = show;
76	entry->info.data = data;
77
78	list_add(&entry->link, &vc4->debugfs_list);
79}
80
81void vc4_debugfs_add_regset32(struct drm_device *drm,
82			      const char *name,
83			      struct debugfs_regset32 *regset)
84{
85	vc4_debugfs_add_file(drm, name, vc4_debugfs_regset32, regset);
86}
87