blob: 329e4a3d8ae7b3b9444e0accd135a94179ed9fd8 [file] [log] [blame]
Terje Bergstrom62364512013-03-22 16:34:04 +02001/*
2 * Copyright (C) 2010 Google, Inc.
3 * Author: Erik Gilling <konkers@android.com>
4 *
5 * Copyright (C) 2011-2013 NVIDIA Corporation
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
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 */
17
18#include <linux/debugfs.h>
19#include <linux/seq_file.h>
20#include <linux/uaccess.h>
21
22#include <linux/io.h>
23
24#include "dev.h"
25#include "debug.h"
26#include "channel.h"
27
28unsigned int host1x_debug_trace_cmdbuf;
29
30static pid_t host1x_debug_force_timeout_pid;
31static u32 host1x_debug_force_timeout_val;
32static u32 host1x_debug_force_timeout_channel;
33
34void host1x_debug_output(struct output *o, const char *fmt, ...)
35{
36 va_list args;
37 int len;
38
39 va_start(args, fmt);
40 len = vsnprintf(o->buf, sizeof(o->buf), fmt, args);
41 va_end(args);
Thierry Reding0b8070d12016-06-23 11:35:50 +020042
Mikko Perttuneneb2ee1a2017-09-28 15:50:41 +030043 o->fn(o->ctx, o->buf, len, false);
44}
45
46void host1x_debug_cont(struct output *o, const char *fmt, ...)
47{
48 va_list args;
49 int len;
50
51 va_start(args, fmt);
52 len = vsnprintf(o->buf, sizeof(o->buf), fmt, args);
53 va_end(args);
54
55 o->fn(o->ctx, o->buf, len, true);
Terje Bergstrom62364512013-03-22 16:34:04 +020056}
57
Mikko Perttunen8474b022017-06-15 02:18:42 +030058static int show_channel(struct host1x_channel *ch, void *data, bool show_fifo)
Terje Bergstrom62364512013-03-22 16:34:04 +020059{
60 struct host1x *m = dev_get_drvdata(ch->dev->parent);
61 struct output *o = data;
62
Mikko Perttunen8474b022017-06-15 02:18:42 +030063 mutex_lock(&ch->cdma.lock);
Thierry Reding0b8070d12016-06-23 11:35:50 +020064
Mikko Perttunen8474b022017-06-15 02:18:42 +030065 if (show_fifo)
66 host1x_hw_show_channel_fifo(m, ch, o);
Thierry Reding0b8070d12016-06-23 11:35:50 +020067
Mikko Perttunen8474b022017-06-15 02:18:42 +030068 host1x_hw_show_channel_cdma(m, ch, o);
Thierry Reding0b8070d12016-06-23 11:35:50 +020069
Mikko Perttunen8474b022017-06-15 02:18:42 +030070 mutex_unlock(&ch->cdma.lock);
Terje Bergstrom62364512013-03-22 16:34:04 +020071
72 return 0;
73}
74
75static void show_syncpts(struct host1x *m, struct output *o)
76{
Thierry Reding14c95fc2016-06-22 16:44:07 +020077 unsigned int i;
Thierry Reding6df633d2016-06-23 11:33:31 +020078
Terje Bergstrom62364512013-03-22 16:34:04 +020079 host1x_debug_output(o, "---- syncpts ----\n");
Thierry Reding0b8070d12016-06-23 11:35:50 +020080
Terje Bergstrom62364512013-03-22 16:34:04 +020081 for (i = 0; i < host1x_syncpt_nb_pts(m); i++) {
82 u32 max = host1x_syncpt_read_max(m->syncpt + i);
83 u32 min = host1x_syncpt_load(m->syncpt + i);
Thierry Reding6df633d2016-06-23 11:33:31 +020084
Terje Bergstrom62364512013-03-22 16:34:04 +020085 if (!min && !max)
86 continue;
Thierry Reding14c95fc2016-06-22 16:44:07 +020087
88 host1x_debug_output(o, "id %u (%s) min %d max %d\n",
Terje Bergstrom62364512013-03-22 16:34:04 +020089 i, m->syncpt[i].name, min, max);
90 }
91
92 for (i = 0; i < host1x_syncpt_nb_bases(m); i++) {
93 u32 base_val;
Thierry Reding6df633d2016-06-23 11:33:31 +020094
Terje Bergstrom62364512013-03-22 16:34:04 +020095 base_val = host1x_syncpt_load_wait_base(m->syncpt + i);
96 if (base_val)
Thierry Reding14c95fc2016-06-22 16:44:07 +020097 host1x_debug_output(o, "waitbase id %u val %d\n", i,
Terje Bergstrom62364512013-03-22 16:34:04 +020098 base_val);
99 }
100
101 host1x_debug_output(o, "\n");
102}
103
Mikko Perttunen8474b022017-06-15 02:18:42 +0300104static void show_all(struct host1x *m, struct output *o, bool show_fifo)
Terje Bergstrom62364512013-03-22 16:34:04 +0200105{
Thierry Redingd4ad3ad2018-03-23 13:31:24 +0100106 unsigned int i;
Terje Bergstrom62364512013-03-22 16:34:04 +0200107
108 host1x_hw_show_mlocks(m, o);
109 show_syncpts(m, o);
110 host1x_debug_output(o, "---- channels ----\n");
111
Mikko Perttunen8474b022017-06-15 02:18:42 +0300112 for (i = 0; i < m->info->nb_channels; ++i) {
113 struct host1x_channel *ch = host1x_channel_get_index(m, i);
Terje Bergstrom62364512013-03-22 16:34:04 +0200114
Mikko Perttunen8474b022017-06-15 02:18:42 +0300115 if (ch) {
116 show_channel(ch, o, show_fifo);
117 host1x_channel_put(ch);
118 }
119 }
Terje Bergstrom62364512013-03-22 16:34:04 +0200120}
121
122static int host1x_debug_show_all(struct seq_file *s, void *unused)
123{
124 struct output o = {
125 .fn = write_to_seqfile,
126 .ctx = s
127 };
Thierry Reding0b8070d12016-06-23 11:35:50 +0200128
Mikko Perttunen8474b022017-06-15 02:18:42 +0300129 show_all(s->private, &o, true);
Thierry Reding0b8070d12016-06-23 11:35:50 +0200130
Terje Bergstrom62364512013-03-22 16:34:04 +0200131 return 0;
132}
133
134static int host1x_debug_show(struct seq_file *s, void *unused)
135{
136 struct output o = {
137 .fn = write_to_seqfile,
138 .ctx = s
139 };
Thierry Reding0b8070d12016-06-23 11:35:50 +0200140
Mikko Perttunen8474b022017-06-15 02:18:42 +0300141 show_all(s->private, &o, false);
Thierry Reding0b8070d12016-06-23 11:35:50 +0200142
Terje Bergstrom62364512013-03-22 16:34:04 +0200143 return 0;
144}
145
146static int host1x_debug_open_all(struct inode *inode, struct file *file)
147{
148 return single_open(file, host1x_debug_show_all, inode->i_private);
149}
150
151static const struct file_operations host1x_debug_all_fops = {
Thierry Reding0b8070d12016-06-23 11:35:50 +0200152 .open = host1x_debug_open_all,
153 .read = seq_read,
154 .llseek = seq_lseek,
155 .release = single_release,
Terje Bergstrom62364512013-03-22 16:34:04 +0200156};
157
158static int host1x_debug_open(struct inode *inode, struct file *file)
159{
160 return single_open(file, host1x_debug_show, inode->i_private);
161}
162
163static const struct file_operations host1x_debug_fops = {
Thierry Reding0b8070d12016-06-23 11:35:50 +0200164 .open = host1x_debug_open,
165 .read = seq_read,
166 .llseek = seq_lseek,
167 .release = single_release,
Terje Bergstrom62364512013-03-22 16:34:04 +0200168};
169
Thierry Reding8e0d7882013-12-03 11:44:48 +0100170static void host1x_debugfs_init(struct host1x *host1x)
Terje Bergstrom62364512013-03-22 16:34:04 +0200171{
172 struct dentry *de = debugfs_create_dir("tegra-host1x", NULL);
173
174 if (!de)
175 return;
176
177 /* Store the created entry */
178 host1x->debugfs = de;
179
180 debugfs_create_file("status", S_IRUGO, de, host1x, &host1x_debug_fops);
181 debugfs_create_file("status_all", S_IRUGO, de, host1x,
182 &host1x_debug_all_fops);
183
184 debugfs_create_u32("trace_cmdbuf", S_IRUGO|S_IWUSR, de,
185 &host1x_debug_trace_cmdbuf);
186
187 host1x_hw_debug_init(host1x, de);
188
189 debugfs_create_u32("force_timeout_pid", S_IRUGO|S_IWUSR, de,
190 &host1x_debug_force_timeout_pid);
191 debugfs_create_u32("force_timeout_val", S_IRUGO|S_IWUSR, de,
192 &host1x_debug_force_timeout_val);
193 debugfs_create_u32("force_timeout_channel", S_IRUGO|S_IWUSR, de,
194 &host1x_debug_force_timeout_channel);
195}
196
Thierry Reding8e0d7882013-12-03 11:44:48 +0100197static void host1x_debugfs_exit(struct host1x *host1x)
Terje Bergstrom62364512013-03-22 16:34:04 +0200198{
199 debugfs_remove_recursive(host1x->debugfs);
200}
Thierry Reding8e0d7882013-12-03 11:44:48 +0100201
Terje Bergstrom62364512013-03-22 16:34:04 +0200202void host1x_debug_init(struct host1x *host1x)
203{
Thierry Reding8e0d7882013-12-03 11:44:48 +0100204 if (IS_ENABLED(CONFIG_DEBUG_FS))
205 host1x_debugfs_init(host1x);
Terje Bergstrom62364512013-03-22 16:34:04 +0200206}
Thierry Reding8e0d7882013-12-03 11:44:48 +0100207
Terje Bergstrom62364512013-03-22 16:34:04 +0200208void host1x_debug_deinit(struct host1x *host1x)
209{
Thierry Reding8e0d7882013-12-03 11:44:48 +0100210 if (IS_ENABLED(CONFIG_DEBUG_FS))
211 host1x_debugfs_exit(host1x);
Terje Bergstrom62364512013-03-22 16:34:04 +0200212}
Terje Bergstrom62364512013-03-22 16:34:04 +0200213
214void host1x_debug_dump(struct host1x *host1x)
215{
216 struct output o = {
217 .fn = write_to_printk
218 };
Thierry Reding0b8070d12016-06-23 11:35:50 +0200219
Mikko Perttunen8474b022017-06-15 02:18:42 +0300220 show_all(host1x, &o, true);
Terje Bergstrom62364512013-03-22 16:34:04 +0200221}
222
223void host1x_debug_dump_syncpts(struct host1x *host1x)
224{
225 struct output o = {
226 .fn = write_to_printk
227 };
Thierry Reding0b8070d12016-06-23 11:35:50 +0200228
Terje Bergstrom62364512013-03-22 16:34:04 +0200229 show_syncpts(host1x, &o);
230}