gpu: update midgard r21p0 kernel driver
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_mali-driver.git] / midgard / r16p0 / kernel / drivers / gpu / arm / midgard / mali_kbase_jd_debugfs.c
1 /*
2 *
3 * (C) COPYRIGHT 2014-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 <linux/seq_file.h>
19
20 #include <mali_kbase.h>
21
22 #include <mali_kbase_jd_debugfs.h>
23 #include <mali_kbase_dma_fence.h>
24
25 #ifdef CONFIG_DEBUG_FS
26
27 struct kbase_jd_debugfs_depinfo {
28 u8 id;
29 char type;
30 };
31
32 #ifdef CONFIG_SYNC
33 #include <mali_kbase_sync.h>
34 #include "sync.h"
35 #endif /* CONFIG_SYNC */
36
37
38 static void kbase_jd_debugfs_fence_info(struct kbase_jd_atom *atom,
39 struct seq_file *sfile)
40 {
41 #ifdef CONFIG_SYNC
42 struct sync_fence *fence = atom->fence;
43 int status;
44
45 switch (atom->core_req & BASE_JD_REQ_SOFT_JOB_TYPE) {
46 case BASE_JD_REQ_SOFT_FENCE_TRIGGER:
47 if (!fence)
48 break;
49
50 status = kbase_fence_get_status(fence);
51
52 seq_printf(sfile, "Sa([%p]%d) ",
53 fence, status);
54 break;
55 case BASE_JD_REQ_SOFT_FENCE_WAIT:
56 if (!fence)
57 break;
58
59 status = kbase_fence_get_status(fence);
60
61 seq_printf(sfile, "Wa([%p]%d) ",
62 fence, status);
63 break;
64 default:
65 break;
66 }
67 #endif /* CONFIG_SYNC */
68
69 #ifdef CONFIG_MALI_DMA_FENCE
70 if (atom->core_req & BASE_JD_REQ_EXTERNAL_RESOURCES) {
71 struct kbase_dma_fence_cb *cb;
72
73 if (atom->dma_fence.fence) {
74 struct fence *fence = atom->dma_fence.fence;
75
76 seq_printf(sfile,
77 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0))
78 "Sd(%u#%u: %s) ",
79 #else
80 "Sd(%llu#%u: %s) ",
81 #endif
82 fence->context,
83 fence->seqno,
84 fence_is_signaled(fence) ?
85 "signaled" : "active");
86 }
87
88 list_for_each_entry(cb, &atom->dma_fence.callbacks,
89 node) {
90 struct fence *fence = cb->fence;
91
92 seq_printf(sfile,
93 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0))
94 "Wd(%u#%u: %s) ",
95 #else
96 "Wd(%llu#%u: %s) ",
97 #endif
98 fence->context,
99 fence->seqno,
100 fence_is_signaled(fence) ?
101 "signaled" : "active");
102 }
103 }
104 #endif /* CONFIG_MALI_DMA_FENCE */
105
106 }
107
108 static void kbasep_jd_debugfs_atom_deps(
109 struct kbase_jd_debugfs_depinfo *deps,
110 struct kbase_jd_atom *atom)
111 {
112 struct kbase_context *kctx = atom->kctx;
113 int i;
114
115 for (i = 0; i < 2; i++) {
116 deps[i].id = (unsigned)(atom->dep[i].atom ?
117 kbase_jd_atom_id(kctx, atom->dep[i].atom) : 0);
118
119 switch (atom->dep[i].dep_type) {
120 case BASE_JD_DEP_TYPE_INVALID:
121 deps[i].type = ' ';
122 break;
123 case BASE_JD_DEP_TYPE_DATA:
124 deps[i].type = 'D';
125 break;
126 case BASE_JD_DEP_TYPE_ORDER:
127 deps[i].type = '>';
128 break;
129 default:
130 deps[i].type = '?';
131 break;
132 }
133 }
134 }
135 /**
136 * kbasep_jd_debugfs_atoms_show - Show callback for the JD atoms debugfs file.
137 * @sfile: The debugfs entry
138 * @data: Data associated with the entry
139 *
140 * This function is called to get the contents of the JD atoms debugfs file.
141 * This is a report of all atoms managed by kbase_jd_context.atoms
142 *
143 * Return: 0 if successfully prints data in debugfs entry file, failure
144 * otherwise
145 */
146 static int kbasep_jd_debugfs_atoms_show(struct seq_file *sfile, void *data)
147 {
148 struct kbase_context *kctx = sfile->private;
149 struct kbase_jd_atom *atoms;
150 unsigned long irq_flags;
151 int i;
152
153 KBASE_DEBUG_ASSERT(kctx != NULL);
154
155 /* Print version */
156 seq_printf(sfile, "v%u\n", MALI_JD_DEBUGFS_VERSION);
157
158 /* Print U/K API version */
159 seq_printf(sfile, "ukv%u.%u\n", BASE_UK_VERSION_MAJOR,
160 BASE_UK_VERSION_MINOR);
161
162 /* Print table heading */
163 seq_puts(sfile, " ID, Core req, St, CR, Predeps, Start time, Additional info...\n");
164
165 atoms = kctx->jctx.atoms;
166 /* General atom states */
167 mutex_lock(&kctx->jctx.lock);
168 /* JS-related states */
169 spin_lock_irqsave(&kctx->kbdev->hwaccess_lock, irq_flags);
170 for (i = 0; i != BASE_JD_ATOM_COUNT; ++i) {
171 struct kbase_jd_atom *atom = &atoms[i];
172 s64 start_timestamp = 0;
173 struct kbase_jd_debugfs_depinfo deps[2];
174
175 if (atom->status == KBASE_JD_ATOM_STATE_UNUSED)
176 continue;
177
178 /* start_timestamp is cleared as soon as the atom leaves UNUSED state
179 * and set before a job is submitted to the h/w, a non-zero value means
180 * it is valid */
181 if (ktime_to_ns(atom->start_timestamp))
182 start_timestamp = ktime_to_ns(
183 ktime_sub(ktime_get(), atom->start_timestamp));
184
185 kbasep_jd_debugfs_atom_deps(deps, atom);
186
187 seq_printf(sfile,
188 "%3u, %8x, %2u, %2u, %c%3u %c%3u, %20lld, ",
189 i, atom->core_req, atom->status,
190 atom->coreref_state,
191 deps[0].type, deps[0].id,
192 deps[1].type, deps[1].id,
193 start_timestamp);
194
195
196 kbase_jd_debugfs_fence_info(atom, sfile);
197
198 seq_puts(sfile, "\n");
199 }
200 spin_unlock_irqrestore(&kctx->kbdev->hwaccess_lock, irq_flags);
201 mutex_unlock(&kctx->jctx.lock);
202
203 return 0;
204 }
205
206
207 /**
208 * kbasep_jd_debugfs_atoms_open - open operation for atom debugfs file
209 * @in: &struct inode pointer
210 * @file: &struct file pointer
211 *
212 * Return: file descriptor
213 */
214 static int kbasep_jd_debugfs_atoms_open(struct inode *in, struct file *file)
215 {
216 return single_open(file, kbasep_jd_debugfs_atoms_show, in->i_private);
217 }
218
219 static const struct file_operations kbasep_jd_debugfs_atoms_fops = {
220 .open = kbasep_jd_debugfs_atoms_open,
221 .read = seq_read,
222 .llseek = seq_lseek,
223 .release = single_release,
224 };
225
226 void kbasep_jd_debugfs_ctx_init(struct kbase_context *kctx)
227 {
228 KBASE_DEBUG_ASSERT(kctx != NULL);
229
230 /* Expose all atoms */
231 debugfs_create_file("atoms", S_IRUGO, kctx->kctx_dentry, kctx,
232 &kbasep_jd_debugfs_atoms_fops);
233
234 }
235
236 #endif /* CONFIG_DEBUG_FS */