blob: a27ade9b7af9a93c9b34322ad34c2468f898265f [file] [log] [blame]
Chris Wilson9eb4de12010-02-12 13:28:40 +00001/* -*- c-basic-offset: 4 -*- */
2/*
3 * Copyright © 2007 Intel Corporation
4 * Copyright © 2009 Intel Corporation
5 * Copyright © 2010 Intel Corporation
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * IN THE SOFTWARE.
25 *
26 * Authors:
27 * Eric Anholt <eric@anholt.net>
28 * Carl Worth <cworth@cworth.org>
29 * Chris Wilson <chris@chris-wilson.co.uk>
30 *
31 */
32
33/** @file intel_decode.c
34 * This file contains code to print out batchbuffer contents in a
35 * human-readable format.
36 *
37 * The current version only supports i915 packets, and only pretty-prints a
38 * subset of them. The intention is for it to make just a best attempt to
39 * decode, but never crash in the process.
40 */
41
42#define _GNU_SOURCE
43#include <stdio.h>
44#include <stdlib.h>
45#include <stdarg.h>
46#include <string.h>
Chris Wilsona3a78632010-12-01 21:51:59 +000047#include <unistd.h>
Chris Wilson9eb4de12010-02-12 13:28:40 +000048#include <inttypes.h>
49#include <errno.h>
50#include <sys/stat.h>
51#include <err.h>
52
53#include "intel_decode.h"
54#include "intel_chipset.h"
55#include "intel_gpu_tools.h"
56#include "instdone.h"
57
58static void
Chris Wilson95374222010-04-08 11:56:57 +010059print_instdone (uint32_t devid, unsigned int instdone, unsigned int instdone1)
Chris Wilson9eb4de12010-02-12 13:28:40 +000060{
61 int i;
Chris Wilson95374222010-04-08 11:56:57 +010062 static int once;
63
64 if (!once) {
65 init_instdone_definitions(devid);
66 once = 1;
67 }
Chris Wilson9eb4de12010-02-12 13:28:40 +000068
69 for (i = 0; i < num_instdone_bits; i++) {
70 int busy = 0;
71
72 if (instdone_bits[i].reg == INST_DONE_1) {
73 if (!(instdone1 & instdone_bits[i].bit))
74 busy = 1;
75 } else {
76 if (!(instdone & instdone_bits[i].bit))
77 busy = 1;
78 }
79
80 if (busy)
81 printf(" busy: %s\n", instdone_bits[i].name);
82 }
83}
84
85static void
Chris Wilsonbfc2b532010-03-04 21:56:04 +000086print_i830_pgtbl_err(unsigned int reg)
87{
88 const char *str;
89
90 switch((reg >> 3) & 0xf) {
91 case 0x1: str = "Overlay TLB"; break;
92 case 0x2: str = "Display A TLB"; break;
93 case 0x3: str = "Host TLB"; break;
94 case 0x4: str = "Render TLB"; break;
95 case 0x5: str = "Display C TLB"; break;
96 case 0x6: str = "Mapping TLB"; break;
97 case 0x7: str = "Command Stream TLB"; break;
98 case 0x8: str = "Vertex Buffer TLB"; break;
99 case 0x9: str = "Display B TLB"; break;
100 case 0xa: str = "Reserved System Memory"; break;
101 case 0xb: str = "Compressor TLB"; break;
102 case 0xc: str = "Binner TLB"; break;
103 default: str = "unknown"; break;
104 }
105
106 if (str)
107 printf (" source = %s\n", str);
108
109 switch(reg & 0x7) {
110 case 0x0: str = "Invalid GTT"; break;
111 case 0x1: str = "Invalid GTT PTE"; break;
112 case 0x2: str = "Invalid Memory"; break;
113 case 0x3: str = "Invalid TLB miss"; break;
114 case 0x4: str = "Invalid PTE data"; break;
115 case 0x5: str = "Invalid LocalMemory not present"; break;
116 case 0x6: str = "Invalid Tiling"; break;
117 case 0x7: str = "Host to CAM"; break;
118 }
119 printf (" error = %s\n", str);
120}
121
122static void
Chris Wilson2d1ad952010-07-15 19:18:39 +0100123print_i915_pgtbl_err(unsigned int reg)
124{
125 if (reg & (1 << 29))
126 printf (" Cursor A: Invalid GTT PTE\n");
127 if (reg & (1 << 28))
128 printf (" Cursor B: Invalid GTT PTE\n");
129 if (reg & (1 << 27))
130 printf (" MT: Invalid tiling\n");
131 if (reg & (1 << 26))
132 printf (" MT: Invalid GTT PTE\n");
133 if (reg & (1 << 25))
134 printf (" LC: Invalid tiling\n");
135 if (reg & (1 << 24))
136 printf (" LC: Invalid GTT PTE\n");
137 if (reg & (1 << 23))
138 printf (" BIN VertexData: Invalid GTT PTE\n");
139 if (reg & (1 << 22))
140 printf (" BIN Instruction: Invalid GTT PTE\n");
141 if (reg & (1 << 21))
142 printf (" CS VertexData: Invalid GTT PTE\n");
143 if (reg & (1 << 20))
144 printf (" CS Instruction: Invalid GTT PTE\n");
145 if (reg & (1 << 19))
146 printf (" CS: Invalid GTT\n");
147 if (reg & (1 << 18))
148 printf (" Overlay: Invalid tiling\n");
149 if (reg & (1 << 16))
150 printf (" Overlay: Invalid GTT PTE\n");
151 if (reg & (1 << 14))
152 printf (" Display C: Invalid tiling\n");
153 if (reg & (1 << 12))
154 printf (" Display C: Invalid GTT PTE\n");
155 if (reg & (1 << 10))
156 printf (" Display B: Invalid tiling\n");
157 if (reg & (1 << 8))
158 printf (" Display B: Invalid GTT PTE\n");
159 if (reg & (1 << 6))
160 printf (" Display A: Invalid tiling\n");
161 if (reg & (1 << 4))
162 printf (" Display A: Invalid GTT PTE\n");
163 if (reg & (1 << 1))
164 printf (" Host Invalid PTE data\n");
165 if (reg & (1 << 0))
166 printf (" Host Invalid GTT PTE\n");
167}
168
169static void
Chris Wilson89343952010-10-22 11:33:08 +0100170print_i965_pgtbl_err(unsigned int reg)
171{
172 if (reg & (1 << 26))
173 printf (" Invalid Sampler Cache GTT entry\n");
174 if (reg & (1 << 24))
175 printf (" Invalid Render Cache GTT entry\n");
176 if (reg & (1 << 23))
177 printf (" Invalid Instruction/State Cache GTT entry\n");
178 if (reg & (1 << 22))
179 printf (" There is no ROC, this cannot occur!\n");
180 if (reg & (1 << 21))
181 printf (" Invalid GTT entry during Vertex Fetch\n");
182 if (reg & (1 << 20))
183 printf (" Invalid GTT entry during Command Fetch\n");
184 if (reg & (1 << 19))
185 printf (" Invalid GTT entry during CS\n");
186 if (reg & (1 << 18))
187 printf (" Invalid GTT entry during Cursor Fetch\n");
188 if (reg & (1 << 17))
189 printf (" Invalid GTT entry during Overlay Fetch\n");
190 if (reg & (1 << 8))
191 printf (" Invalid GTT entry during Display B Fetch\n");
192 if (reg & (1 << 4))
193 printf (" Invalid GTT entry during Display A Fetch\n");
194 if (reg & (1 << 1))
195 printf (" Valid PTE references illegal memory\n");
196 if (reg & (1 << 0))
197 printf (" Invalid GTT entry during fetch for host\n");
198}
199
200static void
Chris Wilsonbfc2b532010-03-04 21:56:04 +0000201print_pgtbl_err(unsigned int reg, unsigned int devid)
202{
203 if (IS_965(devid)) {
Chris Wilson89343952010-10-22 11:33:08 +0100204 return print_i965_pgtbl_err(reg);
Chris Wilsonbfc2b532010-03-04 21:56:04 +0000205 } else if (IS_9XX(devid)) {
Chris Wilson2d1ad952010-07-15 19:18:39 +0100206 return print_i915_pgtbl_err(reg);
Chris Wilsonbfc2b532010-03-04 21:56:04 +0000207 } else {
208 return print_i830_pgtbl_err(reg);
209 }
210}
211
212static void
Chris Wilsona3a78632010-12-01 21:51:59 +0000213read_data_file (FILE *file)
Chris Wilson9eb4de12010-02-12 13:28:40 +0000214{
Chris Wilson9eb4de12010-02-12 13:28:40 +0000215 int devid = PCI_CHIP_I855_GM;
216 uint32_t *data = NULL;
217 int data_size = 0, count = 0, line_number = 0, matched;
218 char *line = NULL;
219 size_t line_size;
220 uint32_t offset, value;
221 uint32_t gtt_offset = 0, new_gtt_offset;
222 char *buffer_type[2] = { "ringbuffer", "batchbuffer" };
223 int is_batch = 1;
224
Chris Wilson9eb4de12010-02-12 13:28:40 +0000225 while (getline (&line, &line_size, file) > 0) {
Chris Wilson98eb5a52011-01-09 13:26:50 +0000226 char *dashes;
Chris Wilson9eb4de12010-02-12 13:28:40 +0000227 line_number++;
228
Chris Wilson98eb5a52011-01-09 13:26:50 +0000229 dashes = strstr(line, "---");
230 if (dashes) {
231 matched = sscanf (dashes, "--- gtt_offset = 0x%08x\n",
232 &new_gtt_offset);
233 if (matched == 1) {
234 if (count) {
235 printf("%s at 0x%08x:\n",
236 buffer_type[is_batch], gtt_offset);
237 intel_decode (data, count, gtt_offset, devid, 0);
238 count = 0;
239 }
240 gtt_offset = new_gtt_offset;
241 is_batch = 1;
242 continue;
243 }
Chris Wilson9eb4de12010-02-12 13:28:40 +0000244
Chris Wilson98eb5a52011-01-09 13:26:50 +0000245 matched = sscanf (dashes, "--- ringbuffer = 0x%08x\n",
246 &new_gtt_offset);
247 if (matched == 1) {
248 if (count) {
249 printf("%s at 0x%08x:\n",
250 buffer_type[is_batch], gtt_offset);
251 intel_decode (data, count, gtt_offset, devid, 0);
252 count = 0;
253 }
254 gtt_offset = new_gtt_offset;
255 is_batch = 0;
256 continue;
257 }
Chris Wilson9eb4de12010-02-12 13:28:40 +0000258 }
259
260 matched = sscanf (line, "%08x : %08x", &offset, &value);
261 if (matched != 2) {
262 unsigned int reg;
263
264 printf("%s", line);
265
266 matched = sscanf (line, "PCI ID: 0x%04x\n", &reg);
Chris Wilson4f208442010-12-23 19:44:14 +0000267 if (matched == 1) {
Chris Wilson9eb4de12010-02-12 13:28:40 +0000268 devid = reg;
Chris Wilson4f208442010-12-23 19:44:14 +0000269 if (IS_965(devid)) {
270 printf("Detected i965+ chipset\n");
271 } else if (IS_9XX(devid)) {
272 printf("Detected i9xx chipset\n");
273 } else {
274 printf("Detected i8xx chipset\n");
275 }
276 }
Chris Wilson9eb4de12010-02-12 13:28:40 +0000277
278 matched = sscanf (line, " ACTHD: 0x%08x\n", &reg);
Chris Wilson14618622010-08-25 11:55:25 +0100279 if (matched == 1)
Chris Wilson9eb4de12010-02-12 13:28:40 +0000280 intel_decode_context_set_head_tail(reg, 0xffffffff);
281
Chris Wilsonbfc2b532010-03-04 21:56:04 +0000282 matched = sscanf (line, " PGTBL_ER: 0x%08x\n", &reg);
Chris Wilson14618622010-08-25 11:55:25 +0100283 if (matched == 1 && reg)
Chris Wilsonbfc2b532010-03-04 21:56:04 +0000284 print_pgtbl_err(reg, devid);
285
Chris Wilson9eb4de12010-02-12 13:28:40 +0000286 matched = sscanf (line, " INSTDONE: 0x%08x\n", &reg);
Chris Wilson14618622010-08-25 11:55:25 +0100287 if (matched == 1)
Chris Wilson95374222010-04-08 11:56:57 +0100288 print_instdone (devid, reg, -1);
Chris Wilson9eb4de12010-02-12 13:28:40 +0000289
290 matched = sscanf (line, " INSTDONE1: 0x%08x\n", &reg);
Chris Wilson14618622010-08-25 11:55:25 +0100291 if (matched == 1)
Chris Wilson95374222010-04-08 11:56:57 +0100292 print_instdone (devid, -1, reg);
Chris Wilson9eb4de12010-02-12 13:28:40 +0000293
294 continue;
295 }
296
297 count++;
298
299 if (count > data_size) {
300 data_size = data_size ? data_size * 2 : 1024;
301 data = realloc (data, data_size * sizeof (uint32_t));
302 if (data == NULL) {
303 fprintf (stderr, "Out of memory.\n");
304 exit (1);
305 }
306 }
307
308 data[count-1] = value;
309 }
310
311 if (count) {
312 printf("%s at 0x%08x:\n", buffer_type[is_batch], gtt_offset);
313 intel_decode (data, count, gtt_offset, devid, 0);
314 }
315
316 free (data);
317 free (line);
Chris Wilson9eb4de12010-02-12 13:28:40 +0000318}
319
320int
321main (int argc, char *argv[])
322{
Chris Wilsona3a78632010-12-01 21:51:59 +0000323 FILE *file;
Chris Wilson9eb4de12010-02-12 13:28:40 +0000324 const char *path;
Chris Wilsona3a78632010-12-01 21:51:59 +0000325 char *filename;
Chris Wilson9eb4de12010-02-12 13:28:40 +0000326 struct stat st;
327 int err;
328
329 if (argc > 2) {
330 fprintf (stderr,
331 "intel_gpu_decode: Parse an Intel GPU i915_error_state\n"
332 "Usage:\n"
333 "\t%s [<file>]\n"
334 "\n"
335 "With no arguments, debugfs-dri-directory is probed for in "
336 "/debug and \n"
337 "/sys/kernel/debug. Otherwise, it may be "
338 "specified. If a file is given,\n"
339 "it is parsed as an GPU dump in the format of "
340 "/debug/dri/0/i915_error_state.\n",
341 argv[0]);
342 return 1;
343 }
344
Chris Wilson9eb4de12010-02-12 13:28:40 +0000345 if (argc == 1) {
Chris Wilson292ae452010-12-10 15:31:59 +0000346 if (isatty(0)) {
Chris Wilson68a95f02011-01-25 16:34:08 +0000347 path = "/debug/dri";
Chris Wilson9eb4de12010-02-12 13:28:40 +0000348 err = stat (path, &st);
349 if (err != 0) {
Chris Wilson68a95f02011-01-25 16:34:08 +0000350 path = "/sys/kernel/debug/dri";
Chris Wilsona3a78632010-12-01 21:51:59 +0000351 err = stat (path, &st);
352 if (err != 0) {
353 errx(1,
354 "Couldn't find i915 debugfs directory.\n\n"
355 "Is debugfs mounted? You might try mounting it with a command such as:\n\n"
356 "\tsudo mount -t debugfs debugfs /sys/kernel/debug\n");
357 }
Chris Wilson9eb4de12010-02-12 13:28:40 +0000358 }
Chris Wilsona3a78632010-12-01 21:51:59 +0000359 } else {
360 read_data_file(stdin);
361 exit(0);
Chris Wilson9eb4de12010-02-12 13:28:40 +0000362 }
363 } else {
364 path = argv[1];
365 err = stat (path, &st);
366 if (err != 0) {
367 fprintf (stderr, "Error opening %s: %s\n",
368 path, strerror (errno));
369 exit (1);
370 }
371 }
372
Chris Wilson68a95f02011-01-25 16:34:08 +0000373 if (S_ISDIR (st.st_mode)) {
Chris Wilson9eb4de12010-02-12 13:28:40 +0000374 asprintf (&filename, "%s/i915_error_state", path);
Chris Wilson68a95f02011-01-25 16:34:08 +0000375 file = fopen(filename, "r");
376 if (!file) {
377 int minor;
378 for (minor = 0; minor < 64; minor++) {
379 free(filename);
380 asprintf(&filename, "%s/%d/i915_error_state", path, minor);
381 file = fopen(filename, "r");
382 if (file)
383 break;
384 }
385 }
386 if (!file) {
387 fprintf (stderr, "Failed to find i915_error_state beneath %s\n",
388 path);
389 exit (1);
390 }
Chris Wilson9eb4de12010-02-12 13:28:40 +0000391 } else {
Chris Wilson68a95f02011-01-25 16:34:08 +0000392 filename = (char *) path;
393 file = fopen(filename, "r");
394 if (!file) {
395 fprintf (stderr, "Failed to open %s: %s\n",
396 filename, strerror (errno));
397 exit (1);
398 }
Chris Wilson9eb4de12010-02-12 13:28:40 +0000399 }
400
Chris Wilson68a95f02011-01-25 16:34:08 +0000401 read_data_file (file);
402 fclose (file);
403
Chris Wilsona3a78632010-12-01 21:51:59 +0000404 if (filename != path)
405 free (filename);
406
Chris Wilson9eb4de12010-02-12 13:28:40 +0000407 return 0;
408}