Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright © 2014 Broadcom |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 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 <drm/drmP.h> |
| 11 | |
| 12 | #include "vc4_drv.h" |
| 13 | #include "vc4_regs.h" |
| 14 | |
Eric Anholt | c9be804 | 2019-04-01 11:35:58 -0700 | [diff] [blame] | 15 | struct vc4_debugfs_info_entry { |
| 16 | struct list_head link; |
| 17 | struct drm_info_list info; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 18 | }; |
| 19 | |
Eric Anholt | c9be804 | 2019-04-01 11:35:58 -0700 | [diff] [blame] | 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 | */ |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 24 | int |
| 25 | vc4_debugfs_init(struct drm_minor *minor) |
| 26 | { |
Paul Kocialkowski | 6b5c029 | 2019-02-20 16:51:24 +0100 | [diff] [blame] | 27 | struct vc4_dev *vc4 = to_vc4_dev(minor->dev); |
Eric Anholt | c9be804 | 2019-04-01 11:35:58 -0700 | [diff] [blame] | 28 | struct vc4_debugfs_info_entry *entry; |
Paul Kocialkowski | 6b5c029 | 2019-02-20 16:51:24 +0100 | [diff] [blame] | 29 | struct dentry *dentry; |
| 30 | |
| 31 | dentry = debugfs_create_bool("hvs_load_tracker", S_IRUGO | S_IWUSR, |
| 32 | minor->debugfs_root, |
| 33 | &vc4->load_tracker_enabled); |
| 34 | if (!dentry) |
| 35 | return -ENOMEM; |
| 36 | |
Eric Anholt | c9be804 | 2019-04-01 11:35:58 -0700 | [diff] [blame] | 37 | list_for_each_entry(entry, &vc4->debugfs_list, link) { |
| 38 | int ret = drm_debugfs_create_files(&entry->info, 1, |
| 39 | minor->debugfs_root, minor); |
| 40 | |
| 41 | if (ret) |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
kbuild test robot | e31b97e | 2019-04-04 05:36:29 +0800 | [diff] [blame] | 48 | static int vc4_debugfs_regset32(struct seq_file *m, void *unused) |
Eric Anholt | c9be804 | 2019-04-01 11:35:58 -0700 | [diff] [blame] | 49 | { |
| 50 | struct drm_info_node *node = (struct drm_info_node *)m->private; |
| 51 | struct debugfs_regset32 *regset = node->info_ent->data; |
| 52 | struct drm_printer p = drm_seq_file_printer(m); |
| 53 | |
| 54 | drm_print_regset32(&p, regset); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Registers a debugfs file with a callback function for a vc4 component. |
| 61 | * |
| 62 | * This is like drm_debugfs_create_files(), but that can only be |
| 63 | * called a given DRM minor, while the various VC4 components want to |
| 64 | * register their debugfs files during the component bind process. We |
| 65 | * track the request and delay it to be called on each minor during |
| 66 | * vc4_debugfs_init(). |
| 67 | */ |
| 68 | void vc4_debugfs_add_file(struct drm_device *dev, |
| 69 | const char *name, |
| 70 | int (*show)(struct seq_file*, void*), |
| 71 | void *data) |
| 72 | { |
| 73 | struct vc4_dev *vc4 = to_vc4_dev(dev); |
| 74 | |
| 75 | struct vc4_debugfs_info_entry *entry = |
| 76 | devm_kzalloc(dev->dev, sizeof(*entry), GFP_KERNEL); |
| 77 | |
| 78 | if (!entry) |
| 79 | return; |
| 80 | |
| 81 | entry->info.name = name; |
| 82 | entry->info.show = show; |
| 83 | entry->info.data = data; |
| 84 | |
| 85 | list_add(&entry->link, &vc4->debugfs_list); |
| 86 | } |
| 87 | |
| 88 | void vc4_debugfs_add_regset32(struct drm_device *drm, |
| 89 | const char *name, |
| 90 | struct debugfs_regset32 *regset) |
| 91 | { |
| 92 | vc4_debugfs_add_file(drm, name, vc4_debugfs_regset32, regset); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 93 | } |