summaryrefslogtreecommitdiff
path: root/drivers/video/tegra/host/host1x/host1x_debug.c
blob: 7de342298c4d24292a203bbd8a609d8fc671a6be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/*
 * drivers/video/tegra/host/host1x/host1x_debug.c
 *
 * Copyright (C) 2010 Google, Inc.
 * Author: Erik Gilling <konkers@android.com>
 *
 * Copyright (C) 2011 NVIDIA Corporation
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/mm.h>

#include <linux/io.h>

#include "dev.h"
#include "debug.h"
#include "host1x_hardware.h"
#include "nvhost_cdma.h"
#include "nvhost_channel.h"
#include "host1x_cdma.h"
#include "nvhost_job.h"

#define NVHOST_DEBUG_MAX_PAGE_OFFSET 102400

enum {
	NVHOST_DBG_STATE_CMD = 0,
	NVHOST_DBG_STATE_DATA = 1,
	NVHOST_DBG_STATE_GATHER = 2
};

static int show_channel_command(struct output *o, u32 addr, u32 val, int *count)
{
	unsigned mask;
	unsigned subop;

	switch (val >> 28) {
	case 0x0:
		mask = val & 0x3f;
		if (mask) {
			nvhost_debug_output(o,
				"SETCL(class=%03x, offset=%03x, mask=%02x, [",
				val >> 6 & 0x3ff, val >> 16 & 0xfff, mask);
			*count = hweight8(mask);
			return NVHOST_DBG_STATE_DATA;
		} else {
			nvhost_debug_output(o, "SETCL(class=%03x)\n",
				val >> 6 & 0x3ff);
			return NVHOST_DBG_STATE_CMD;
		}

	case 0x1:
		nvhost_debug_output(o, "INCR(offset=%03x, [",
			val >> 16 & 0xfff);
		*count = val & 0xffff;
		return NVHOST_DBG_STATE_DATA;

	case 0x2:
		nvhost_debug_output(o, "NONINCR(offset=%03x, [",
			val >> 16 & 0xfff);
		*count = val & 0xffff;
		return NVHOST_DBG_STATE_DATA;

	case 0x3:
		mask = val & 0xffff;
		nvhost_debug_output(o, "MASK(offset=%03x, mask=%03x, [",
			   val >> 16 & 0xfff, mask);
		*count = hweight16(mask);
		return NVHOST_DBG_STATE_DATA;

	case 0x4:
		nvhost_debug_output(o, "IMM(offset=%03x, data=%03x)\n",
			   val >> 16 & 0xfff, val & 0xffff);
		return NVHOST_DBG_STATE_CMD;

	case 0x5:
		nvhost_debug_output(o, "RESTART(offset=%08x)\n", val << 4);
		return NVHOST_DBG_STATE_CMD;

	case 0x6:
		nvhost_debug_output(o, "GATHER(offset=%03x, insert=%d, type=%d, count=%04x, addr=[",
			val >> 16 & 0xfff, val >> 15 & 0x1, val >> 14 & 0x1,
			val & 0x3fff);
		*count = val & 0x3fff; /* TODO: insert */
		return NVHOST_DBG_STATE_GATHER;

	case 0xe:
		subop = val >> 24 & 0xf;
		if (subop == 0)
			nvhost_debug_output(o, "ACQUIRE_MLOCK(index=%d)\n",
				val & 0xff);
		else if (subop == 1)
			nvhost_debug_output(o, "RELEASE_MLOCK(index=%d)\n",
				val & 0xff);
		else
			nvhost_debug_output(o, "EXTEND_UNKNOWN(%08x)\n", val);
		return NVHOST_DBG_STATE_CMD;

	default:
		return NVHOST_DBG_STATE_CMD;
	}
}

static void show_channel_gather(struct output *o, u32 addr,
		phys_addr_t phys_addr, u32 words, struct nvhost_cdma *cdma);

static void show_channel_word(struct output *o, int *state, int *count,
		u32 addr, u32 val, struct nvhost_cdma *cdma)
{
	static int start_count, dont_print;

	switch (*state) {
	case NVHOST_DBG_STATE_CMD:
		if (addr)
			nvhost_debug_output(o, "%08x: %08x:", addr, val);
		else
			nvhost_debug_output(o, "%08x:", val);

		*state = show_channel_command(o, addr, val, count);
		dont_print = 0;
		start_count = *count;
		if (*state == NVHOST_DBG_STATE_DATA && *count == 0) {
			*state = NVHOST_DBG_STATE_CMD;
			nvhost_debug_output(o, "])\n");
		}
		break;

	case NVHOST_DBG_STATE_DATA:
		(*count)--;
		if (start_count - *count < 64)
			nvhost_debug_output(o, "%08x%s",
				val, *count > 0 ? ", " : "])\n");
		else if (!dont_print && (*count > 0)) {
			nvhost_debug_output(o, "[truncated; %d more words]\n",
				*count);
			dont_print = 1;
		}
		if (*count == 0)
			*state = NVHOST_DBG_STATE_CMD;
		break;

	case NVHOST_DBG_STATE_GATHER:
		*state = NVHOST_DBG_STATE_CMD;
		nvhost_debug_output(o, "%08x]):\n", val);
		if (cdma) {
			show_channel_gather(o, addr, val,
					*count, cdma);
		}
		break;
	}
}

static void do_show_channel_gather(struct output *o,
		phys_addr_t phys_addr,
		u32 words, struct nvhost_cdma *cdma,
		phys_addr_t pin_addr, u32 *map_addr)
{
	/* Map dmaget cursor to corresponding nvmap_handle */
	u32 offset;
	int state, count, i;

	offset = phys_addr - pin_addr;
	/*
	 * Sometimes we're given different hardware address to the same
	 * page - in these cases the offset will get an invalid number and
	 * we just have to bail out.
	 */
	if (offset > NVHOST_DEBUG_MAX_PAGE_OFFSET) {
		nvhost_debug_output(o, "[address mismatch]\n");
	} else {
		/* GATHER buffer starts always with commands */
		state = NVHOST_DBG_STATE_CMD;
		for (i = 0; i < words; i++)
			show_channel_word(o, &state, &count,
					phys_addr + i * 4,
					*(map_addr + offset/4 + i),
					cdma);
	}
}

static void show_channel_gather(struct output *o, u32 addr,
		phys_addr_t phys_addr,
		u32 words, struct nvhost_cdma *cdma)
{
#if defined(CONFIG_TEGRA_NVMAP)
	/* Map dmaget cursor to corresponding nvmap_handle */
	struct push_buffer *pb = &cdma->push_buffer;
	u32 cur = addr - pb->phys;
	struct nvmap_client_handle *nvmap = &pb->nvmap[cur/8];
	u32 *map_addr, offset;
	phys_addr_t pin_addr;

	if (!nvmap || !nvmap->handle || !nvmap->client) {
		nvhost_debug_output(o, "[already deallocated]\n");
		return;
	}

	map_addr = nvmap_mmap(nvmap->handle);
	if (!map_addr) {
		nvhost_debug_output(o, "[could not mmap]\n");
		return;
	}

	/* Get base address from nvmap */
	pin_addr = nvmap_pin(nvmap->client, nvmap->handle);
	if (IS_ERR_VALUE(pin_addr)) {
		nvhost_debug_output(o, "[couldn't pin]\n");
		nvmap_munmap(nvmap->handle, map_addr);
		return;
	}

	offset = phys_addr - pin_addr;
	do_show_channel_gather(o, phys_addr, words, cdma,
			pin_addr, map_addr);
	nvmap_unpin(nvmap->client, nvmap->handle);
	nvmap_munmap(nvmap->handle, map_addr);
#endif
}

u32 previous_oppair(struct nvhost_cdma *cdma, u32 cur)
{
	u32 pb = cdma->push_buffer.phys;
	u32 prev = cur-8;
	if (prev < pb)
		prev += PUSH_BUFFER_SIZE;
	return prev;
}

void show_channel_gathers(struct output *o, struct nvhost_cdma *cdma)
{
	struct nvhost_job *job;

	list_for_each_entry(job, &cdma->sync_queue, list) {
		int i;
		nvhost_debug_output(o, "\n%p: JOB, syncpt_id=%d, syncpt_val=%d,"
				" first_get=%08x, timeout=%d, ctx=%p,"
				" num_slots=%d, num_handles=%d\n",
				job,
				job->syncpt_id,
				job->syncpt_end,
				job->first_get,
				job->timeout,
				job->hwctx,
				job->num_slots,
				job->num_unpins);

		for (i = 0; i < job->num_gathers; i++) {
			struct nvhost_job_gather *g = &job->gathers[i];
			u32 *mapped = nvmap_mmap(g->ref);
			if (!mapped) {
				nvhost_debug_output(o, "[could not mmap]\n");
				continue;
			}

			nvhost_debug_output(o, "    GATHER at %08x, %d words\n",
				g->mem, g->words);

			do_show_channel_gather(o, g->mem + g->offset,
					g->words, cdma, g->mem, mapped);
			nvmap_munmap(g->ref, mapped);
		}
	}
}

static void t20_debug_show_channel_cdma(struct nvhost_master *m,
	struct nvhost_channel *ch, struct output *o, int chid)
{
	struct nvhost_channel *channel = ch;
	struct nvhost_cdma *cdma = &channel->cdma;
	u32 dmaput, dmaget, dmactrl;
	u32 cbstat, cbread;
	u32 val, base, baseval;

	dmaput = readl(channel->aperture + HOST1X_CHANNEL_DMAPUT);
	dmaget = readl(channel->aperture + HOST1X_CHANNEL_DMAGET);
	dmactrl = readl(channel->aperture + HOST1X_CHANNEL_DMACTRL);
	cbread = readl(m->sync_aperture + HOST1X_SYNC_CBREAD_x(chid));
	cbstat = readl(m->sync_aperture + HOST1X_SYNC_CBSTAT_x(chid));

	nvhost_debug_output(o, "%d-%s (%d): ", chid,
			    channel->dev->name,
			    channel->dev->refcount);

	if (HOST1X_VAL(CHANNEL_DMACTRL, DMASTOP, dmactrl)
		|| !channel->cdma.push_buffer.mapped) {
		nvhost_debug_output(o, "inactive\n\n");
		return;
	}

	switch (cbstat) {
	case 0x00010008:
		nvhost_debug_output(o, "waiting on syncpt %d val %d\n",
			cbread >> 24, cbread & 0xffffff);
		break;

	case 0x00010009:
		base = (cbread >> 16) & 0xff;
		val = readl(m->sync_aperture +
				HOST1X_SYNC_SYNCPT_BASE_x(base));
		baseval = HOST1X_VAL(SYNC_SYNCPT_BASE_0, BASE, val);
		val = cbread & 0xffff;
		nvhost_debug_output(o, "waiting on syncpt %d val %d "
			  "(base %d = %d; offset = %d)\n",
			cbread >> 24, baseval + val,
			base, baseval, val);
		break;

	default:
		nvhost_debug_output(o,
				"active class %02x, offset %04x, val %08x\n",
				HOST1X_VAL(SYNC_CBSTAT_0, CBCLASS0, cbstat),
				HOST1X_VAL(SYNC_CBSTAT_0, CBOFFSET0, cbstat),
				cbread);
		break;
	}

	nvhost_debug_output(o, "DMAPUT %08x, DMAGET %08x, DMACTL %08x\n",
		dmaput, dmaget, dmactrl);
	nvhost_debug_output(o, "CBREAD %08x, CBSTAT %08x\n", cbread, cbstat);

	show_channel_gathers(o, cdma);
	nvhost_debug_output(o, "\n");
}

void t20_debug_show_channel_fifo(struct nvhost_master *m,
	struct nvhost_channel *ch, struct output *o, int chid)
{
	u32 val, rd_ptr, wr_ptr, start, end;
	struct nvhost_channel *channel = ch;
	int state, count;

	nvhost_debug_output(o, "%d: fifo:\n", chid);

	val = readl(channel->aperture + HOST1X_CHANNEL_FIFOSTAT);
	nvhost_debug_output(o, "FIFOSTAT %08x\n", val);
	if (HOST1X_VAL(CHANNEL_FIFOSTAT, CFEMPTY, val)) {
		nvhost_debug_output(o, "[empty]\n");
		return;
	}

	writel(0x0, m->sync_aperture + HOST1X_SYNC_CFPEEK_CTRL);
	writel(HOST1X_CREATE(SYNC_CFPEEK_CTRL, ENA, 1)
			| HOST1X_CREATE(SYNC_CFPEEK_CTRL, CHANNR, chid),
		m->sync_aperture + HOST1X_SYNC_CFPEEK_CTRL);

	val = readl(m->sync_aperture + HOST1X_SYNC_CFPEEK_PTRS);
	rd_ptr = HOST1X_VAL(SYNC_CFPEEK_PTRS, CF_RD_PTR, val);
	wr_ptr = HOST1X_VAL(SYNC_CFPEEK_PTRS, CF_WR_PTR, val);

	val = readl(m->sync_aperture + HOST1X_SYNC_CFx_SETUP(chid));
	start = HOST1X_VAL(SYNC_CF0_SETUP, BASE, val);
	end = HOST1X_VAL(SYNC_CF0_SETUP, LIMIT, val);

	state = NVHOST_DBG_STATE_CMD;

	do {
		writel(0x0, m->sync_aperture + HOST1X_SYNC_CFPEEK_CTRL);
		writel(HOST1X_CREATE(SYNC_CFPEEK_CTRL, ENA, 1)
				| HOST1X_CREATE(SYNC_CFPEEK_CTRL, CHANNR, chid)
				| HOST1X_CREATE(SYNC_CFPEEK_CTRL, ADDR, rd_ptr),
			m->sync_aperture + HOST1X_SYNC_CFPEEK_CTRL);
		val = readl(m->sync_aperture + HOST1X_SYNC_CFPEEK_READ);

		show_channel_word(o, &state, &count, 0, val, NULL);

		if (rd_ptr == end)
			rd_ptr = start;
		else
			rd_ptr++;
	} while (rd_ptr != wr_ptr);

	if (state == NVHOST_DBG_STATE_DATA)
		nvhost_debug_output(o, ", ...])\n");
	nvhost_debug_output(o, "\n");

	writel(0x0, m->sync_aperture + HOST1X_SYNC_CFPEEK_CTRL);
}

static void t20_debug_show_mlocks(struct nvhost_master *m, struct output *o)
{
	u32 __iomem *mlo_regs = m->sync_aperture + HOST1X_SYNC_MLOCK_OWNER_0;
	int i;

	nvhost_debug_output(o, "---- mlocks ----\n");
	for (i = 0; i < NV_HOST1X_NB_MLOCKS; i++) {
		u32 owner = readl(mlo_regs + i);
		if (HOST1X_VAL(SYNC_MLOCK_OWNER_0, CH_OWNS, owner))
			nvhost_debug_output(o, "%d: locked by channel %d\n",
				i, HOST1X_VAL(SYNC_MLOCK_OWNER_0, CHID, owner));
		else if (HOST1X_VAL(SYNC_MLOCK_OWNER_0, CPU_OWNS, owner))
			nvhost_debug_output(o, "%d: locked by cpu\n", i);
		else
			nvhost_debug_output(o, "%d: unlocked\n", i);
	}
	nvhost_debug_output(o, "\n");
}

int nvhost_init_t20_debug_support(struct nvhost_chip_support *op)
{
	op->debug.show_channel_cdma = t20_debug_show_channel_cdma;
	op->debug.show_channel_fifo = t20_debug_show_channel_fifo;
	op->debug.show_mlocks = t20_debug_show_mlocks;

	return 0;
}