blob: af205dc3abdf9e6f706e4f42d6abcdd15fae79c9 [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>
47#include <inttypes.h>
48#include <errno.h>
49#include <sys/stat.h>
50#include <err.h>
51
52#include "intel_decode.h"
53#include "intel_chipset.h"
54#include "intel_gpu_tools.h"
55#include "instdone.h"
56
57static void
Chris Wilson95374222010-04-08 11:56:57 +010058print_instdone (uint32_t devid, unsigned int instdone, unsigned int instdone1)
Chris Wilson9eb4de12010-02-12 13:28:40 +000059{
60 int i;
Chris Wilson95374222010-04-08 11:56:57 +010061 static int once;
62
63 if (!once) {
64 init_instdone_definitions(devid);
65 once = 1;
66 }
Chris Wilson9eb4de12010-02-12 13:28:40 +000067
68 for (i = 0; i < num_instdone_bits; i++) {
69 int busy = 0;
70
71 if (instdone_bits[i].reg == INST_DONE_1) {
72 if (!(instdone1 & instdone_bits[i].bit))
73 busy = 1;
74 } else {
75 if (!(instdone & instdone_bits[i].bit))
76 busy = 1;
77 }
78
79 if (busy)
80 printf(" busy: %s\n", instdone_bits[i].name);
81 }
82}
83
84static void
Chris Wilsonbfc2b532010-03-04 21:56:04 +000085print_i830_pgtbl_err(unsigned int reg)
86{
87 const char *str;
88
89 switch((reg >> 3) & 0xf) {
90 case 0x1: str = "Overlay TLB"; break;
91 case 0x2: str = "Display A TLB"; break;
92 case 0x3: str = "Host TLB"; break;
93 case 0x4: str = "Render TLB"; break;
94 case 0x5: str = "Display C TLB"; break;
95 case 0x6: str = "Mapping TLB"; break;
96 case 0x7: str = "Command Stream TLB"; break;
97 case 0x8: str = "Vertex Buffer TLB"; break;
98 case 0x9: str = "Display B TLB"; break;
99 case 0xa: str = "Reserved System Memory"; break;
100 case 0xb: str = "Compressor TLB"; break;
101 case 0xc: str = "Binner TLB"; break;
102 default: str = "unknown"; break;
103 }
104
105 if (str)
106 printf (" source = %s\n", str);
107
108 switch(reg & 0x7) {
109 case 0x0: str = "Invalid GTT"; break;
110 case 0x1: str = "Invalid GTT PTE"; break;
111 case 0x2: str = "Invalid Memory"; break;
112 case 0x3: str = "Invalid TLB miss"; break;
113 case 0x4: str = "Invalid PTE data"; break;
114 case 0x5: str = "Invalid LocalMemory not present"; break;
115 case 0x6: str = "Invalid Tiling"; break;
116 case 0x7: str = "Host to CAM"; break;
117 }
118 printf (" error = %s\n", str);
119}
120
121static void
122print_pgtbl_err(unsigned int reg, unsigned int devid)
123{
124 if (IS_965(devid)) {
125 } else if (IS_9XX(devid)) {
126 } else {
127 return print_i830_pgtbl_err(reg);
128 }
129}
130
131static void
Chris Wilson9eb4de12010-02-12 13:28:40 +0000132read_data_file (const char * filename)
133{
134 FILE *file;
135 int devid = PCI_CHIP_I855_GM;
136 uint32_t *data = NULL;
137 int data_size = 0, count = 0, line_number = 0, matched;
138 char *line = NULL;
139 size_t line_size;
140 uint32_t offset, value;
141 uint32_t gtt_offset = 0, new_gtt_offset;
142 char *buffer_type[2] = { "ringbuffer", "batchbuffer" };
143 int is_batch = 1;
144
145 file = fopen (filename, "r");
146 if (file == NULL) {
147 fprintf (stderr, "Failed to open %s: %s\n",
148 filename, strerror (errno));
149 exit (1);
150 }
151
152 while (getline (&line, &line_size, file) > 0) {
153 line_number++;
154
155 matched = sscanf (line, "--- gtt_offset = 0x%08x\n", &new_gtt_offset);
156 if (matched == 1) {
157 if (count) {
158 printf("%s at 0x%08x:\n", buffer_type[is_batch], gtt_offset);
159 intel_decode (data, count, gtt_offset, devid, 0);
160 count = 0;
161 }
162 gtt_offset = new_gtt_offset;
163 is_batch = 1;
164 continue;
165 }
166
167 matched = sscanf (line, "--- ringbuffer = 0x%08x\n", &new_gtt_offset);
168 if (matched == 1) {
169 if (count) {
170 printf("%s at 0x%08x:\n", buffer_type[is_batch], gtt_offset);
171 intel_decode (data, count, gtt_offset, devid, 0);
172 count = 0;
173 }
174 gtt_offset = new_gtt_offset;
175 is_batch = 0;
176 continue;
177 }
178
179 matched = sscanf (line, "%08x : %08x", &offset, &value);
180 if (matched != 2) {
181 unsigned int reg;
182
183 printf("%s", line);
184
185 matched = sscanf (line, "PCI ID: 0x%04x\n", &reg);
186 if (matched)
187 devid = reg;
188
189 matched = sscanf (line, " ACTHD: 0x%08x\n", &reg);
190 if (matched)
191 intel_decode_context_set_head_tail(reg, 0xffffffff);
192
Chris Wilsonbfc2b532010-03-04 21:56:04 +0000193 matched = sscanf (line, " PGTBL_ER: 0x%08x\n", &reg);
194 if (matched && reg)
195 print_pgtbl_err(reg, devid);
196
Chris Wilson9eb4de12010-02-12 13:28:40 +0000197 matched = sscanf (line, " INSTDONE: 0x%08x\n", &reg);
198 if (matched)
Chris Wilson95374222010-04-08 11:56:57 +0100199 print_instdone (devid, reg, -1);
Chris Wilson9eb4de12010-02-12 13:28:40 +0000200
201 matched = sscanf (line, " INSTDONE1: 0x%08x\n", &reg);
202 if (matched)
Chris Wilson95374222010-04-08 11:56:57 +0100203 print_instdone (devid, -1, reg);
Chris Wilson9eb4de12010-02-12 13:28:40 +0000204
205 continue;
206 }
207
208 count++;
209
210 if (count > data_size) {
211 data_size = data_size ? data_size * 2 : 1024;
212 data = realloc (data, data_size * sizeof (uint32_t));
213 if (data == NULL) {
214 fprintf (stderr, "Out of memory.\n");
215 exit (1);
216 }
217 }
218
219 data[count-1] = value;
220 }
221
222 if (count) {
223 printf("%s at 0x%08x:\n", buffer_type[is_batch], gtt_offset);
224 intel_decode (data, count, gtt_offset, devid, 0);
225 }
226
227 free (data);
228 free (line);
229
230 fclose (file);
231}
232
233int
234main (int argc, char *argv[])
235{
236 const char *path;
237 struct stat st;
238 int err;
239
240 if (argc > 2) {
241 fprintf (stderr,
242 "intel_gpu_decode: Parse an Intel GPU i915_error_state\n"
243 "Usage:\n"
244 "\t%s [<file>]\n"
245 "\n"
246 "With no arguments, debugfs-dri-directory is probed for in "
247 "/debug and \n"
248 "/sys/kernel/debug. Otherwise, it may be "
249 "specified. If a file is given,\n"
250 "it is parsed as an GPU dump in the format of "
251 "/debug/dri/0/i915_error_state.\n",
252 argv[0]);
253 return 1;
254 }
255
Chris Wilson9eb4de12010-02-12 13:28:40 +0000256 if (argc == 1) {
257 path = "/debug/dri/0";
258 err = stat (path, &st);
259 if (err != 0) {
260 path = "/sys/kernel/debug/dri/0";
261 err = stat (path, &st);
262 if (err != 0) {
263 errx(1,
264 "Couldn't find i915 debugfs directory.\n\n"
265 "Is debugfs mounted? You might try mounting it with a command such as:\n\n"
266 "\tsudo mount -t debugfs debugfs /sys/kernel/debug\n");
267 }
268 }
269 } else {
270 path = argv[1];
271 err = stat (path, &st);
272 if (err != 0) {
273 fprintf (stderr, "Error opening %s: %s\n",
274 path, strerror (errno));
275 exit (1);
276 }
277 }
278
279 if (S_ISDIR (st.st_mode)) {
280 char *filename;
281
282 asprintf (&filename, "%s/i915_error_state", path);
283 read_data_file (filename);
284 free (filename);
285 } else {
286 read_data_file (path);
287 }
288
289 return 0;
290}