18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright © 2014 Broadcom
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
78c2ecf20Sopenharmony_ci#include <linux/circ_buf.h>
88c2ecf20Sopenharmony_ci#include <linux/ctype.h>
98c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "vc4_drv.h"
128c2ecf20Sopenharmony_ci#include "vc4_regs.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct vc4_debugfs_info_entry {
158c2ecf20Sopenharmony_ci	struct list_head link;
168c2ecf20Sopenharmony_ci	struct drm_info_list info;
178c2ecf20Sopenharmony_ci};
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/**
208c2ecf20Sopenharmony_ci * Called at drm_dev_register() time on each of the minors registered
218c2ecf20Sopenharmony_ci * by the DRM device, to attach the debugfs files.
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_civoid
248c2ecf20Sopenharmony_civc4_debugfs_init(struct drm_minor *minor)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	struct vc4_dev *vc4 = to_vc4_dev(minor->dev);
278c2ecf20Sopenharmony_ci	struct vc4_debugfs_info_entry *entry;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	debugfs_create_bool("hvs_load_tracker", S_IRUGO | S_IWUSR,
308c2ecf20Sopenharmony_ci			    minor->debugfs_root, &vc4->load_tracker_enabled);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	list_for_each_entry(entry, &vc4->debugfs_list, link) {
338c2ecf20Sopenharmony_ci		drm_debugfs_create_files(&entry->info, 1,
348c2ecf20Sopenharmony_ci					 minor->debugfs_root, minor);
358c2ecf20Sopenharmony_ci	}
368c2ecf20Sopenharmony_ci}
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic int vc4_debugfs_regset32(struct seq_file *m, void *unused)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci	struct drm_info_node *node = (struct drm_info_node *)m->private;
418c2ecf20Sopenharmony_ci	struct debugfs_regset32 *regset = node->info_ent->data;
428c2ecf20Sopenharmony_ci	struct drm_printer p = drm_seq_file_printer(m);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	drm_print_regset32(&p, regset);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	return 0;
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/**
508c2ecf20Sopenharmony_ci * Registers a debugfs file with a callback function for a vc4 component.
518c2ecf20Sopenharmony_ci *
528c2ecf20Sopenharmony_ci * This is like drm_debugfs_create_files(), but that can only be
538c2ecf20Sopenharmony_ci * called a given DRM minor, while the various VC4 components want to
548c2ecf20Sopenharmony_ci * register their debugfs files during the component bind process.  We
558c2ecf20Sopenharmony_ci * track the request and delay it to be called on each minor during
568c2ecf20Sopenharmony_ci * vc4_debugfs_init().
578c2ecf20Sopenharmony_ci */
588c2ecf20Sopenharmony_civoid vc4_debugfs_add_file(struct drm_device *dev,
598c2ecf20Sopenharmony_ci			  const char *name,
608c2ecf20Sopenharmony_ci			  int (*show)(struct seq_file*, void*),
618c2ecf20Sopenharmony_ci			  void *data)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	struct vc4_dev *vc4 = to_vc4_dev(dev);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	struct vc4_debugfs_info_entry *entry =
668c2ecf20Sopenharmony_ci		devm_kzalloc(dev->dev, sizeof(*entry), GFP_KERNEL);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	if (!entry)
698c2ecf20Sopenharmony_ci		return;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	entry->info.name = name;
728c2ecf20Sopenharmony_ci	entry->info.show = show;
738c2ecf20Sopenharmony_ci	entry->info.data = data;
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	list_add(&entry->link, &vc4->debugfs_list);
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_civoid vc4_debugfs_add_regset32(struct drm_device *drm,
798c2ecf20Sopenharmony_ci			      const char *name,
808c2ecf20Sopenharmony_ci			      struct debugfs_regset32 *regset)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	vc4_debugfs_add_file(drm, name, vc4_debugfs_regset32, regset);
838c2ecf20Sopenharmony_ci}
84