diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/debug.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/debug.c | 413 |
1 files changed, 413 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/debug.c b/drivers/gpu/nvgpu/common/linux/debug.c new file mode 100644 index 00000000..7a4e4e9f --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/debug.c | |||
@@ -0,0 +1,413 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 NVIDIA Corporation. All rights reserved. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include "debug_cde.h" | ||
16 | #include "debug_ce.h" | ||
17 | #include "debug_fifo.h" | ||
18 | #include "debug_gr.h" | ||
19 | #include "debug_mm.h" | ||
20 | #include "debug_allocator.h" | ||
21 | #include "debug_kmem.h" | ||
22 | #include "debug_pmu.h" | ||
23 | #include "debug_sched.h" | ||
24 | #include "debug_hal.h" | ||
25 | #include "debug_xve.h" | ||
26 | #include "os_linux.h" | ||
27 | #include "platform_gk20a.h" | ||
28 | |||
29 | #include "gk20a/gk20a.h" | ||
30 | |||
31 | #include <linux/debugfs.h> | ||
32 | #include <linux/seq_file.h> | ||
33 | #include <linux/uaccess.h> | ||
34 | |||
35 | #include <nvgpu/debug.h> | ||
36 | |||
37 | unsigned int gk20a_debug_trace_cmdbuf; | ||
38 | |||
39 | static inline void gk20a_debug_write_printk(void *ctx, const char *str, | ||
40 | size_t len) | ||
41 | { | ||
42 | pr_info("%s", str); | ||
43 | } | ||
44 | |||
45 | static inline void gk20a_debug_write_to_seqfile(void *ctx, const char *str, | ||
46 | size_t len) | ||
47 | { | ||
48 | seq_write((struct seq_file *)ctx, str, len); | ||
49 | } | ||
50 | |||
51 | void gk20a_debug_output(struct gk20a_debug_output *o, | ||
52 | const char *fmt, ...) | ||
53 | { | ||
54 | va_list args; | ||
55 | int len; | ||
56 | |||
57 | va_start(args, fmt); | ||
58 | len = vsnprintf(o->buf, sizeof(o->buf), fmt, args); | ||
59 | va_end(args); | ||
60 | o->fn(o->ctx, o->buf, len); | ||
61 | } | ||
62 | |||
63 | static int gk20a_gr_dump_regs(struct gk20a *g, | ||
64 | struct gk20a_debug_output *o) | ||
65 | { | ||
66 | if (g->ops.gr.dump_gr_regs) | ||
67 | gr_gk20a_elpg_protected_call(g, g->ops.gr.dump_gr_regs(g, o)); | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | int gk20a_gr_debug_dump(struct gk20a *g) | ||
73 | { | ||
74 | struct gk20a_debug_output o = { | ||
75 | .fn = gk20a_debug_write_printk | ||
76 | }; | ||
77 | |||
78 | gk20a_gr_dump_regs(g, &o); | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | static int gk20a_gr_debug_show(struct seq_file *s, void *unused) | ||
84 | { | ||
85 | struct device *dev = s->private; | ||
86 | struct gk20a *g = gk20a_get_platform(dev)->g; | ||
87 | struct gk20a_debug_output o = { | ||
88 | .fn = gk20a_debug_write_to_seqfile, | ||
89 | .ctx = s, | ||
90 | }; | ||
91 | int err; | ||
92 | |||
93 | err = gk20a_busy(g); | ||
94 | if (err) { | ||
95 | nvgpu_err(g, "failed to power on gpu: %d", err); | ||
96 | return -EINVAL; | ||
97 | } | ||
98 | |||
99 | gk20a_gr_dump_regs(g, &o); | ||
100 | |||
101 | gk20a_idle(g); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | void gk20a_debug_dump(struct gk20a *g) | ||
107 | { | ||
108 | struct gk20a_platform *platform = gk20a_get_platform(dev_from_gk20a(g)); | ||
109 | struct gk20a_debug_output o = { | ||
110 | .fn = gk20a_debug_write_printk | ||
111 | }; | ||
112 | |||
113 | if (platform->dump_platform_dependencies) | ||
114 | platform->dump_platform_dependencies(dev_from_gk20a(g)); | ||
115 | |||
116 | /* HAL only initialized after 1st power-on */ | ||
117 | if (g->ops.debug.show_dump) | ||
118 | g->ops.debug.show_dump(g, &o); | ||
119 | } | ||
120 | |||
121 | static int gk20a_debug_show(struct seq_file *s, void *unused) | ||
122 | { | ||
123 | struct device *dev = s->private; | ||
124 | struct gk20a_debug_output o = { | ||
125 | .fn = gk20a_debug_write_to_seqfile, | ||
126 | .ctx = s, | ||
127 | }; | ||
128 | struct gk20a *g; | ||
129 | int err; | ||
130 | |||
131 | g = gk20a_get_platform(dev)->g; | ||
132 | |||
133 | err = gk20a_busy(g); | ||
134 | if (err) { | ||
135 | nvgpu_err(g, "failed to power on gpu: %d", err); | ||
136 | return -EFAULT; | ||
137 | } | ||
138 | |||
139 | /* HAL only initialized after 1st power-on */ | ||
140 | if (g->ops.debug.show_dump) | ||
141 | g->ops.debug.show_dump(g, &o); | ||
142 | |||
143 | gk20a_idle(g); | ||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | static int gk20a_gr_debug_open(struct inode *inode, struct file *file) | ||
148 | { | ||
149 | return single_open(file, gk20a_gr_debug_show, inode->i_private); | ||
150 | } | ||
151 | |||
152 | static int gk20a_debug_open(struct inode *inode, struct file *file) | ||
153 | { | ||
154 | return single_open(file, gk20a_debug_show, inode->i_private); | ||
155 | } | ||
156 | |||
157 | static const struct file_operations gk20a_gr_debug_fops = { | ||
158 | .open = gk20a_gr_debug_open, | ||
159 | .read = seq_read, | ||
160 | .llseek = seq_lseek, | ||
161 | .release = single_release, | ||
162 | }; | ||
163 | |||
164 | static const struct file_operations gk20a_debug_fops = { | ||
165 | .open = gk20a_debug_open, | ||
166 | .read = seq_read, | ||
167 | .llseek = seq_lseek, | ||
168 | .release = single_release, | ||
169 | }; | ||
170 | |||
171 | void gk20a_debug_show_dump(struct gk20a *g, struct gk20a_debug_output *o) | ||
172 | { | ||
173 | g->ops.fifo.dump_pbdma_status(g, o); | ||
174 | g->ops.fifo.dump_eng_status(g, o); | ||
175 | |||
176 | gk20a_debug_dump_all_channel_status_ramfc(g, o); | ||
177 | } | ||
178 | |||
179 | static ssize_t disable_bigpage_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) | ||
180 | { | ||
181 | char buf[3]; | ||
182 | struct gk20a *g = file->private_data; | ||
183 | |||
184 | if (g->mm.disable_bigpage) | ||
185 | buf[0] = 'Y'; | ||
186 | else | ||
187 | buf[0] = 'N'; | ||
188 | buf[1] = '\n'; | ||
189 | buf[2] = 0x00; | ||
190 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); | ||
191 | } | ||
192 | |||
193 | static ssize_t disable_bigpage_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) | ||
194 | { | ||
195 | char buf[32]; | ||
196 | int buf_size; | ||
197 | bool bv; | ||
198 | struct gk20a *g = file->private_data; | ||
199 | |||
200 | buf_size = min(count, (sizeof(buf)-1)); | ||
201 | if (copy_from_user(buf, user_buf, buf_size)) | ||
202 | return -EFAULT; | ||
203 | |||
204 | if (strtobool(buf, &bv) == 0) { | ||
205 | g->mm.disable_bigpage = bv; | ||
206 | gk20a_init_gpu_characteristics(g); | ||
207 | } | ||
208 | |||
209 | return count; | ||
210 | } | ||
211 | |||
212 | static struct file_operations disable_bigpage_fops = { | ||
213 | .open = simple_open, | ||
214 | .read = disable_bigpage_read, | ||
215 | .write = disable_bigpage_write, | ||
216 | }; | ||
217 | |||
218 | static int railgate_residency_show(struct seq_file *s, void *data) | ||
219 | { | ||
220 | struct gk20a *g = s->private; | ||
221 | struct gk20a_platform *platform = dev_get_drvdata(dev_from_gk20a(g)); | ||
222 | unsigned long time_since_last_state_transition_ms; | ||
223 | unsigned long total_rail_gate_time_ms; | ||
224 | unsigned long total_rail_ungate_time_ms; | ||
225 | |||
226 | if (platform->is_railgated(dev_from_gk20a(g))) { | ||
227 | time_since_last_state_transition_ms = | ||
228 | jiffies_to_msecs(jiffies - | ||
229 | g->pstats.last_rail_gate_complete); | ||
230 | total_rail_ungate_time_ms = g->pstats.total_rail_ungate_time_ms; | ||
231 | total_rail_gate_time_ms = | ||
232 | g->pstats.total_rail_gate_time_ms + | ||
233 | time_since_last_state_transition_ms; | ||
234 | } else { | ||
235 | time_since_last_state_transition_ms = | ||
236 | jiffies_to_msecs(jiffies - | ||
237 | g->pstats.last_rail_ungate_complete); | ||
238 | total_rail_gate_time_ms = g->pstats.total_rail_gate_time_ms; | ||
239 | total_rail_ungate_time_ms = | ||
240 | g->pstats.total_rail_ungate_time_ms + | ||
241 | time_since_last_state_transition_ms; | ||
242 | } | ||
243 | |||
244 | seq_printf(s, "Time with Rails Gated: %lu ms\n" | ||
245 | "Time with Rails UnGated: %lu ms\n" | ||
246 | "Total railgating cycles: %lu\n", | ||
247 | total_rail_gate_time_ms, | ||
248 | total_rail_ungate_time_ms, | ||
249 | g->pstats.railgating_cycle_count - 1); | ||
250 | return 0; | ||
251 | |||
252 | } | ||
253 | |||
254 | static int railgate_residency_open(struct inode *inode, struct file *file) | ||
255 | { | ||
256 | return single_open(file, railgate_residency_show, inode->i_private); | ||
257 | } | ||
258 | |||
259 | static const struct file_operations railgate_residency_fops = { | ||
260 | .open = railgate_residency_open, | ||
261 | .read = seq_read, | ||
262 | .llseek = seq_lseek, | ||
263 | .release = single_release, | ||
264 | }; | ||
265 | |||
266 | static int gk20a_railgating_debugfs_init(struct gk20a *g) | ||
267 | { | ||
268 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
269 | struct dentry *d; | ||
270 | |||
271 | if (!g->can_railgate) | ||
272 | return 0; | ||
273 | |||
274 | d = debugfs_create_file( | ||
275 | "railgate_residency", S_IRUGO|S_IWUSR, l->debugfs, g, | ||
276 | &railgate_residency_fops); | ||
277 | if (!d) | ||
278 | return -ENOMEM; | ||
279 | |||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | void gk20a_debug_init(struct gk20a *g, const char *debugfs_symlink) | ||
284 | { | ||
285 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
286 | struct device *dev = dev_from_gk20a(g); | ||
287 | |||
288 | l->debugfs = debugfs_create_dir(dev_name(dev), NULL); | ||
289 | if (!l->debugfs) | ||
290 | return; | ||
291 | |||
292 | if (debugfs_symlink) | ||
293 | l->debugfs_alias = | ||
294 | debugfs_create_symlink(debugfs_symlink, | ||
295 | NULL, dev_name(dev)); | ||
296 | |||
297 | debugfs_create_file("status", S_IRUGO, l->debugfs, | ||
298 | dev, &gk20a_debug_fops); | ||
299 | debugfs_create_file("gr_status", S_IRUGO, l->debugfs, | ||
300 | dev, &gk20a_gr_debug_fops); | ||
301 | debugfs_create_u32("trace_cmdbuf", S_IRUGO|S_IWUSR, | ||
302 | l->debugfs, &gk20a_debug_trace_cmdbuf); | ||
303 | |||
304 | debugfs_create_u32("ch_wdt_timeout_ms", S_IRUGO|S_IWUSR, | ||
305 | l->debugfs, &g->ch_wdt_timeout_ms); | ||
306 | |||
307 | debugfs_create_u32("disable_syncpoints", S_IRUGO|S_IWUSR, | ||
308 | l->debugfs, &g->disable_syncpoints); | ||
309 | |||
310 | /* Legacy debugging API. */ | ||
311 | debugfs_create_u32("dbg_mask", S_IRUGO|S_IWUSR, | ||
312 | l->debugfs, &nvgpu_dbg_mask); | ||
313 | |||
314 | /* New debug logging API. */ | ||
315 | debugfs_create_u32("log_mask", S_IRUGO|S_IWUSR, | ||
316 | l->debugfs, &g->log_mask); | ||
317 | debugfs_create_u32("log_trace", S_IRUGO|S_IWUSR, | ||
318 | l->debugfs, &g->log_trace); | ||
319 | |||
320 | l->debugfs_ltc_enabled = | ||
321 | debugfs_create_bool("ltc_enabled", S_IRUGO|S_IWUSR, | ||
322 | l->debugfs, | ||
323 | &g->mm.ltc_enabled_target); | ||
324 | |||
325 | l->debugfs_gr_idle_timeout_default = | ||
326 | debugfs_create_u32("gr_idle_timeout_default_us", | ||
327 | S_IRUGO|S_IWUSR, l->debugfs, | ||
328 | &g->gr_idle_timeout_default); | ||
329 | l->debugfs_timeouts_enabled = | ||
330 | debugfs_create_bool("timeouts_enabled", | ||
331 | S_IRUGO|S_IWUSR, | ||
332 | l->debugfs, | ||
333 | &g->timeouts_enabled); | ||
334 | |||
335 | l->debugfs_bypass_smmu = | ||
336 | debugfs_create_bool("bypass_smmu", | ||
337 | S_IRUGO|S_IWUSR, | ||
338 | l->debugfs, | ||
339 | &g->mm.bypass_smmu); | ||
340 | l->debugfs_disable_bigpage = | ||
341 | debugfs_create_file("disable_bigpage", | ||
342 | S_IRUGO|S_IWUSR, | ||
343 | l->debugfs, | ||
344 | g, | ||
345 | &disable_bigpage_fops); | ||
346 | |||
347 | l->debugfs_timeslice_low_priority_us = | ||
348 | debugfs_create_u32("timeslice_low_priority_us", | ||
349 | S_IRUGO|S_IWUSR, | ||
350 | l->debugfs, | ||
351 | &g->timeslice_low_priority_us); | ||
352 | l->debugfs_timeslice_medium_priority_us = | ||
353 | debugfs_create_u32("timeslice_medium_priority_us", | ||
354 | S_IRUGO|S_IWUSR, | ||
355 | l->debugfs, | ||
356 | &g->timeslice_medium_priority_us); | ||
357 | l->debugfs_timeslice_high_priority_us = | ||
358 | debugfs_create_u32("timeslice_high_priority_us", | ||
359 | S_IRUGO|S_IWUSR, | ||
360 | l->debugfs, | ||
361 | &g->timeslice_high_priority_us); | ||
362 | l->debugfs_runlist_interleave = | ||
363 | debugfs_create_bool("runlist_interleave", | ||
364 | S_IRUGO|S_IWUSR, | ||
365 | l->debugfs, | ||
366 | &g->runlist_interleave); | ||
367 | #ifdef CONFIG_ARCH_TEGRA_18x_SOC | ||
368 | l->debugfs_force_preemption_gfxp = | ||
369 | debugfs_create_bool("force_preemption_gfxp", S_IRUGO|S_IWUSR, | ||
370 | l->debugfs, | ||
371 | &g->gr.t18x.ctx_vars.force_preemption_gfxp); | ||
372 | |||
373 | l->debugfs_force_preemption_cilp = | ||
374 | debugfs_create_bool("force_preemption_cilp", S_IRUGO|S_IWUSR, | ||
375 | l->debugfs, | ||
376 | &g->gr.t18x.ctx_vars.force_preemption_cilp); | ||
377 | |||
378 | l->debugfs_dump_ctxsw_stats = | ||
379 | debugfs_create_bool("dump_ctxsw_stats_on_channel_close", | ||
380 | S_IRUGO|S_IWUSR, l->debugfs, | ||
381 | &g->gr.t18x. | ||
382 | ctx_vars.dump_ctxsw_stats_on_channel_close); | ||
383 | #endif | ||
384 | |||
385 | gr_gk20a_debugfs_init(g); | ||
386 | gk20a_pmu_debugfs_init(g); | ||
387 | gk20a_railgating_debugfs_init(g); | ||
388 | gk20a_cde_debugfs_init(g); | ||
389 | gk20a_ce_debugfs_init(g); | ||
390 | nvgpu_alloc_debugfs_init(g); | ||
391 | nvgpu_hal_debugfs_init(g); | ||
392 | gk20a_mm_debugfs_init(g); | ||
393 | gk20a_fifo_debugfs_init(g); | ||
394 | gk20a_sched_debugfs_init(g); | ||
395 | #ifdef CONFIG_NVGPU_TRACK_MEM_USAGE | ||
396 | nvgpu_kmem_debugfs_init(g); | ||
397 | #endif | ||
398 | if (g->pci_vendor_id) | ||
399 | nvgpu_xve_debugfs_init(g); | ||
400 | } | ||
401 | |||
402 | void gk20a_debug_deinit(struct gk20a *g) | ||
403 | { | ||
404 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
405 | |||
406 | if (!l->debugfs) | ||
407 | return; | ||
408 | |||
409 | gk20a_fifo_debugfs_deinit(g); | ||
410 | |||
411 | debugfs_remove_recursive(l->debugfs); | ||
412 | debugfs_remove(l->debugfs_alias); | ||
413 | } | ||