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