1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 /*
3 *
4 * (C) COPYRIGHT 2014-2022 ARM Limited. All rights reserved.
5 *
6 * This program is free software and is provided to you under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation, and any use by you of this program is subject to the terms
9 * of such GNU license.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you can access it online at
18 * http://www.gnu.org/licenses/gpl-2.0.html.
19 *
20 */
21
22 #if IS_ENABLED(CONFIG_DEBUG_FS)
23
24 #include <linux/seq_file.h>
25 #include <mali_kbase.h>
26 #include <mali_kbase_jd_debugfs.h>
27 #if IS_ENABLED(CONFIG_SYNC_FILE)
28 #include <mali_kbase_sync.h>
29 #endif
30 #include <uapi/gpu/arm/bifrost/mali_kbase_ioctl.h>
31
32 struct kbase_jd_debugfs_depinfo {
33 u8 id;
34 char type;
35 };
36
kbase_jd_debugfs_fence_info(struct kbase_jd_atom * atom,struct seq_file * sfile)37 static void kbase_jd_debugfs_fence_info(struct kbase_jd_atom *atom,
38 struct seq_file *sfile)
39 {
40 #if IS_ENABLED(CONFIG_SYNC_FILE)
41 struct kbase_sync_fence_info info;
42 int res;
43
44 switch (atom->core_req & BASE_JD_REQ_SOFT_JOB_TYPE) {
45 case BASE_JD_REQ_SOFT_FENCE_TRIGGER:
46 res = kbase_sync_fence_out_info_get(atom, &info);
47 if (res == 0)
48 seq_printf(sfile, "Sa([%pK]%d) ",
49 info.fence, info.status);
50 break;
51 case BASE_JD_REQ_SOFT_FENCE_WAIT:
52 res = kbase_sync_fence_in_info_get(atom, &info);
53 if (res == 0)
54 seq_printf(sfile, "Wa([%pK]%d) ",
55 info.fence, info.status);
56 break;
57 default:
58 break;
59 }
60 #endif /* CONFIG_SYNC_FILE */
61 }
62
kbasep_jd_debugfs_atom_deps(struct kbase_jd_debugfs_depinfo * deps,struct kbase_jd_atom * atom)63 static void kbasep_jd_debugfs_atom_deps(
64 struct kbase_jd_debugfs_depinfo *deps,
65 struct kbase_jd_atom *atom)
66 {
67 struct kbase_context *kctx = atom->kctx;
68 int i;
69
70 for (i = 0; i < 2; i++) {
71 deps[i].id = (unsigned int)(atom->dep[i].atom ?
72 kbase_jd_atom_id(kctx, atom->dep[i].atom) : 0);
73
74 switch (atom->dep[i].dep_type) {
75 case BASE_JD_DEP_TYPE_INVALID:
76 deps[i].type = ' ';
77 break;
78 case BASE_JD_DEP_TYPE_DATA:
79 deps[i].type = 'D';
80 break;
81 case BASE_JD_DEP_TYPE_ORDER:
82 deps[i].type = '>';
83 break;
84 default:
85 deps[i].type = '?';
86 break;
87 }
88 }
89 }
90 /**
91 * kbasep_jd_debugfs_atoms_show - Show callback for the JD atoms debugfs file.
92 * @sfile: The debugfs entry
93 * @data: Data associated with the entry
94 *
95 * This function is called to get the contents of the JD atoms debugfs file.
96 * This is a report of all atoms managed by kbase_jd_context.atoms
97 *
98 * Return: 0 if successfully prints data in debugfs entry file, failure
99 * otherwise
100 */
kbasep_jd_debugfs_atoms_show(struct seq_file * sfile,void * data)101 static int kbasep_jd_debugfs_atoms_show(struct seq_file *sfile, void *data)
102 {
103 struct kbase_context *kctx = sfile->private;
104 struct kbase_jd_atom *atoms;
105 unsigned long irq_flags;
106 int i;
107
108 KBASE_DEBUG_ASSERT(kctx != NULL);
109
110 /* Print version */
111 seq_printf(sfile, "v%u\n", MALI_JD_DEBUGFS_VERSION);
112
113 /* Print U/K API version */
114 seq_printf(sfile, "ukv%u.%u\n", BASE_UK_VERSION_MAJOR,
115 BASE_UK_VERSION_MINOR);
116
117 /* Print table heading */
118 seq_puts(sfile, " ID, Core req, St, Predeps, Start time, Additional info...\n");
119
120 atoms = kctx->jctx.atoms;
121 /* General atom states */
122 mutex_lock(&kctx->jctx.lock);
123 /* JS-related states */
124 spin_lock_irqsave(&kctx->kbdev->hwaccess_lock, irq_flags);
125 for (i = 0; i != BASE_JD_ATOM_COUNT; ++i) {
126 struct kbase_jd_atom *atom = &atoms[i];
127 s64 start_timestamp = 0;
128 struct kbase_jd_debugfs_depinfo deps[2];
129
130 if (atom->status == KBASE_JD_ATOM_STATE_UNUSED)
131 continue;
132
133 /* start_timestamp is cleared as soon as the atom leaves UNUSED state
134 * and set before a job is submitted to the h/w, a non-zero value means
135 * it is valid
136 */
137 if (ktime_to_ns(atom->start_timestamp))
138 start_timestamp =
139 ktime_to_ns(ktime_sub(ktime_get_raw(), atom->start_timestamp));
140
141 kbasep_jd_debugfs_atom_deps(deps, atom);
142
143 seq_printf(sfile,
144 "%3u, %8x, %2u, %c%3u %c%3u, %20lld, ",
145 i, atom->core_req, atom->status,
146 deps[0].type, deps[0].id,
147 deps[1].type, deps[1].id,
148 start_timestamp);
149
150
151 kbase_jd_debugfs_fence_info(atom, sfile);
152
153 seq_puts(sfile, "\n");
154 }
155 spin_unlock_irqrestore(&kctx->kbdev->hwaccess_lock, irq_flags);
156 mutex_unlock(&kctx->jctx.lock);
157
158 return 0;
159 }
160
161
162 /**
163 * kbasep_jd_debugfs_atoms_open - open operation for atom debugfs file
164 * @in: &struct inode pointer
165 * @file: &struct file pointer
166 *
167 * Return: file descriptor
168 */
kbasep_jd_debugfs_atoms_open(struct inode * in,struct file * file)169 static int kbasep_jd_debugfs_atoms_open(struct inode *in, struct file *file)
170 {
171 return single_open(file, kbasep_jd_debugfs_atoms_show, in->i_private);
172 }
173
174 static const struct file_operations kbasep_jd_debugfs_atoms_fops = {
175 .owner = THIS_MODULE,
176 .open = kbasep_jd_debugfs_atoms_open,
177 .read = seq_read,
178 .llseek = seq_lseek,
179 .release = single_release,
180 };
181
kbasep_jd_debugfs_ctx_init(struct kbase_context * kctx)182 void kbasep_jd_debugfs_ctx_init(struct kbase_context *kctx)
183 {
184 const mode_t mode = 0444;
185
186 /* Caller already ensures this, but we keep the pattern for
187 * maintenance safety.
188 */
189 if (WARN_ON(!kctx) ||
190 WARN_ON(IS_ERR_OR_NULL(kctx->kctx_dentry)))
191 return;
192
193 /* Expose all atoms */
194 debugfs_create_file("atoms", mode, kctx->kctx_dentry, kctx,
195 &kbasep_jd_debugfs_atoms_fops);
196
197 }
198
199 #endif /* CONFIG_DEBUG_FS */
200