3 * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
18 #include "mali_kbase.h"
20 #include "mali_kbase_regs_history_debugfs.h"
22 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_NO_MALI)
24 #include <linux/debugfs.h>
27 static int regs_history_size_get(void *data, u64 *val)
29 struct kbase_io_history *const h = data;
36 static int regs_history_size_set(void *data, u64 val)
38 struct kbase_io_history *const h = data;
40 return kbase_io_history_resize(h, (u16)val);
44 DEFINE_SIMPLE_ATTRIBUTE(regs_history_size_fops,
45 regs_history_size_get,
46 regs_history_size_set,
51 * regs_history_show - show callback for the register access history file.
53 * @sfile: The debugfs entry
54 * @data: Data associated with the entry
56 * This function is called to dump all recent accesses to the GPU registers.
58 * @return 0 if successfully prints data in debugfs entry file, failure
61 static int regs_history_show(struct seq_file *sfile, void *data)
63 struct kbase_io_history *const h = sfile->private;
69 seq_puts(sfile, "The register access history is disabled\n");
73 spin_lock_irqsave(&h->lock, flags);
75 iters = (h->size > h->count) ? h->count : h->size;
76 seq_printf(sfile, "Last %zu register accesses of %zu total:\n", iters,
78 for (i = 0; i < iters; ++i) {
79 struct kbase_io_access *io =
80 &h->buf[(h->count - iters + i) % h->size];
81 char const access = (io->addr & 1) ? 'w' : 'r';
83 seq_printf(sfile, "%6i: %c: reg 0x%p val %08x\n", i, access,
84 (void *)(io->addr & ~0x1), io->value);
87 spin_unlock_irqrestore(&h->lock, flags);
95 * regs_history_open - open operation for regs_history debugfs file
97 * @in: &struct inode pointer
98 * @file: &struct file pointer
100 * @return file descriptor
102 static int regs_history_open(struct inode *in, struct file *file)
104 return single_open(file, ®s_history_show, in->i_private);
108 static const struct file_operations regs_history_fops = {
109 .open = ®s_history_open,
112 .release = single_release,
116 void kbasep_regs_history_debugfs_init(struct kbase_device *kbdev)
118 debugfs_create_bool("regs_history_enabled", S_IRUGO | S_IWUSR,
119 kbdev->mali_debugfs_directory,
120 &kbdev->io_history.enabled);
121 debugfs_create_file("regs_history_size", S_IRUGO | S_IWUSR,
122 kbdev->mali_debugfs_directory,
123 &kbdev->io_history, ®s_history_size_fops);
124 debugfs_create_file("regs_history", S_IRUGO,
125 kbdev->mali_debugfs_directory, &kbdev->io_history,
130 #endif /* CONFIG_DEBUG_FS */