MALI: rockchip: upgrade midgard DDK to r14p0-01rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_regs_history_debugfs.c
1 /*
2  *
3  * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
4  *
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
8  * of such GNU licence.
9  *
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.
13  *
14  */
15
16
17
18 #include "mali_kbase.h"
19
20 #include "mali_kbase_regs_history_debugfs.h"
21
22 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_NO_MALI)
23
24 #include <linux/debugfs.h>
25
26
27 static int regs_history_size_get(void *data, u64 *val)
28 {
29         struct kbase_io_history *const h = data;
30
31         *val = h->size;
32
33         return 0;
34 }
35
36 static int regs_history_size_set(void *data, u64 val)
37 {
38         struct kbase_io_history *const h = data;
39
40         return kbase_io_history_resize(h, (u16)val);
41 }
42
43
44 DEFINE_SIMPLE_ATTRIBUTE(regs_history_size_fops,
45                 regs_history_size_get,
46                 regs_history_size_set,
47                 "%llu\n");
48
49
50 /**
51  * regs_history_show - show callback for the register access history file.
52  *
53  * @sfile: The debugfs entry
54  * @data: Data associated with the entry
55  *
56  * This function is called to dump all recent accesses to the GPU registers.
57  *
58  * @return 0 if successfully prints data in debugfs entry file, failure
59  * otherwise
60  */
61 static int regs_history_show(struct seq_file *sfile, void *data)
62 {
63         struct kbase_io_history *const h = sfile->private;
64         u16 i;
65         size_t iters;
66         unsigned long flags;
67
68         if (!h->enabled) {
69                 seq_puts(sfile, "The register access history is disabled\n");
70                 goto out;
71         }
72
73         spin_lock_irqsave(&h->lock, flags);
74
75         iters = (h->size > h->count) ? h->count : h->size;
76         seq_printf(sfile, "Last %zu register accesses of %zu total:\n", iters,
77                         h->count);
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';
82
83                 seq_printf(sfile, "%6i: %c: reg 0x%p val %08x\n", i, access,
84                                 (void *)(io->addr & ~0x1), io->value);
85         }
86
87         spin_unlock_irqrestore(&h->lock, flags);
88
89 out:
90         return 0;
91 }
92
93
94 /**
95  * regs_history_open - open operation for regs_history debugfs file
96  *
97  * @in: &struct inode pointer
98  * @file: &struct file pointer
99  *
100  * @return file descriptor
101  */
102 static int regs_history_open(struct inode *in, struct file *file)
103 {
104         return single_open(file, &regs_history_show, in->i_private);
105 }
106
107
108 static const struct file_operations regs_history_fops = {
109         .open = &regs_history_open,
110         .read = seq_read,
111         .llseek = seq_lseek,
112         .release = single_release,
113 };
114
115
116 void kbasep_regs_history_debugfs_init(struct kbase_device *kbdev)
117 {
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, &regs_history_size_fops);
124         debugfs_create_file("regs_history", S_IRUGO,
125                         kbdev->mali_debugfs_directory, &kbdev->io_history,
126                         &regs_history_fops);
127 }
128
129
130 #endif /* CONFIG_DEBUG_FS */