Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 1 | /* -*- 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 | |
| 57 | static void |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 58 | print_instdone (uint32_t devid, unsigned int instdone, unsigned int instdone1) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 59 | { |
| 60 | int i; |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 61 | static int once; |
| 62 | |
| 63 | if (!once) { |
| 64 | init_instdone_definitions(devid); |
| 65 | once = 1; |
| 66 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 67 | |
| 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 | |
| 84 | static void |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 85 | print_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 | |
| 121 | static void |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame^] | 122 | print_i915_pgtbl_err(unsigned int reg) |
| 123 | { |
| 124 | if (reg & (1 << 29)) |
| 125 | printf (" Cursor A: Invalid GTT PTE\n"); |
| 126 | if (reg & (1 << 28)) |
| 127 | printf (" Cursor B: Invalid GTT PTE\n"); |
| 128 | if (reg & (1 << 27)) |
| 129 | printf (" MT: Invalid tiling\n"); |
| 130 | if (reg & (1 << 26)) |
| 131 | printf (" MT: Invalid GTT PTE\n"); |
| 132 | if (reg & (1 << 25)) |
| 133 | printf (" LC: Invalid tiling\n"); |
| 134 | if (reg & (1 << 24)) |
| 135 | printf (" LC: Invalid GTT PTE\n"); |
| 136 | if (reg & (1 << 23)) |
| 137 | printf (" BIN VertexData: Invalid GTT PTE\n"); |
| 138 | if (reg & (1 << 22)) |
| 139 | printf (" BIN Instruction: Invalid GTT PTE\n"); |
| 140 | if (reg & (1 << 21)) |
| 141 | printf (" CS VertexData: Invalid GTT PTE\n"); |
| 142 | if (reg & (1 << 20)) |
| 143 | printf (" CS Instruction: Invalid GTT PTE\n"); |
| 144 | if (reg & (1 << 19)) |
| 145 | printf (" CS: Invalid GTT\n"); |
| 146 | if (reg & (1 << 18)) |
| 147 | printf (" Overlay: Invalid tiling\n"); |
| 148 | if (reg & (1 << 16)) |
| 149 | printf (" Overlay: Invalid GTT PTE\n"); |
| 150 | if (reg & (1 << 14)) |
| 151 | printf (" Display C: Invalid tiling\n"); |
| 152 | if (reg & (1 << 12)) |
| 153 | printf (" Display C: Invalid GTT PTE\n"); |
| 154 | if (reg & (1 << 10)) |
| 155 | printf (" Display B: Invalid tiling\n"); |
| 156 | if (reg & (1 << 8)) |
| 157 | printf (" Display B: Invalid GTT PTE\n"); |
| 158 | if (reg & (1 << 6)) |
| 159 | printf (" Display A: Invalid tiling\n"); |
| 160 | if (reg & (1 << 4)) |
| 161 | printf (" Display A: Invalid GTT PTE\n"); |
| 162 | if (reg & (1 << 1)) |
| 163 | printf (" Host Invalid PTE data\n"); |
| 164 | if (reg & (1 << 0)) |
| 165 | printf (" Host Invalid GTT PTE\n"); |
| 166 | } |
| 167 | |
| 168 | static void |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 169 | print_pgtbl_err(unsigned int reg, unsigned int devid) |
| 170 | { |
| 171 | if (IS_965(devid)) { |
| 172 | } else if (IS_9XX(devid)) { |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame^] | 173 | return print_i915_pgtbl_err(reg); |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 174 | } else { |
| 175 | return print_i830_pgtbl_err(reg); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | static void |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 180 | read_data_file (const char * filename) |
| 181 | { |
| 182 | FILE *file; |
| 183 | int devid = PCI_CHIP_I855_GM; |
| 184 | uint32_t *data = NULL; |
| 185 | int data_size = 0, count = 0, line_number = 0, matched; |
| 186 | char *line = NULL; |
| 187 | size_t line_size; |
| 188 | uint32_t offset, value; |
| 189 | uint32_t gtt_offset = 0, new_gtt_offset; |
| 190 | char *buffer_type[2] = { "ringbuffer", "batchbuffer" }; |
| 191 | int is_batch = 1; |
| 192 | |
| 193 | file = fopen (filename, "r"); |
| 194 | if (file == NULL) { |
| 195 | fprintf (stderr, "Failed to open %s: %s\n", |
| 196 | filename, strerror (errno)); |
| 197 | exit (1); |
| 198 | } |
| 199 | |
| 200 | while (getline (&line, &line_size, file) > 0) { |
| 201 | line_number++; |
| 202 | |
| 203 | matched = sscanf (line, "--- gtt_offset = 0x%08x\n", &new_gtt_offset); |
| 204 | if (matched == 1) { |
| 205 | if (count) { |
| 206 | printf("%s at 0x%08x:\n", buffer_type[is_batch], gtt_offset); |
| 207 | intel_decode (data, count, gtt_offset, devid, 0); |
| 208 | count = 0; |
| 209 | } |
| 210 | gtt_offset = new_gtt_offset; |
| 211 | is_batch = 1; |
| 212 | continue; |
| 213 | } |
| 214 | |
| 215 | matched = sscanf (line, "--- ringbuffer = 0x%08x\n", &new_gtt_offset); |
| 216 | if (matched == 1) { |
| 217 | if (count) { |
| 218 | printf("%s at 0x%08x:\n", buffer_type[is_batch], gtt_offset); |
| 219 | intel_decode (data, count, gtt_offset, devid, 0); |
| 220 | count = 0; |
| 221 | } |
| 222 | gtt_offset = new_gtt_offset; |
| 223 | is_batch = 0; |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | matched = sscanf (line, "%08x : %08x", &offset, &value); |
| 228 | if (matched != 2) { |
| 229 | unsigned int reg; |
| 230 | |
| 231 | printf("%s", line); |
| 232 | |
| 233 | matched = sscanf (line, "PCI ID: 0x%04x\n", ®); |
| 234 | if (matched) |
| 235 | devid = reg; |
| 236 | |
| 237 | matched = sscanf (line, " ACTHD: 0x%08x\n", ®); |
| 238 | if (matched) |
| 239 | intel_decode_context_set_head_tail(reg, 0xffffffff); |
| 240 | |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 241 | matched = sscanf (line, " PGTBL_ER: 0x%08x\n", ®); |
| 242 | if (matched && reg) |
| 243 | print_pgtbl_err(reg, devid); |
| 244 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 245 | matched = sscanf (line, " INSTDONE: 0x%08x\n", ®); |
| 246 | if (matched) |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 247 | print_instdone (devid, reg, -1); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 248 | |
| 249 | matched = sscanf (line, " INSTDONE1: 0x%08x\n", ®); |
| 250 | if (matched) |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 251 | print_instdone (devid, -1, reg); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 252 | |
| 253 | continue; |
| 254 | } |
| 255 | |
| 256 | count++; |
| 257 | |
| 258 | if (count > data_size) { |
| 259 | data_size = data_size ? data_size * 2 : 1024; |
| 260 | data = realloc (data, data_size * sizeof (uint32_t)); |
| 261 | if (data == NULL) { |
| 262 | fprintf (stderr, "Out of memory.\n"); |
| 263 | exit (1); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | data[count-1] = value; |
| 268 | } |
| 269 | |
| 270 | if (count) { |
| 271 | printf("%s at 0x%08x:\n", buffer_type[is_batch], gtt_offset); |
| 272 | intel_decode (data, count, gtt_offset, devid, 0); |
| 273 | } |
| 274 | |
| 275 | free (data); |
| 276 | free (line); |
| 277 | |
| 278 | fclose (file); |
| 279 | } |
| 280 | |
| 281 | int |
| 282 | main (int argc, char *argv[]) |
| 283 | { |
| 284 | const char *path; |
| 285 | struct stat st; |
| 286 | int err; |
| 287 | |
| 288 | if (argc > 2) { |
| 289 | fprintf (stderr, |
| 290 | "intel_gpu_decode: Parse an Intel GPU i915_error_state\n" |
| 291 | "Usage:\n" |
| 292 | "\t%s [<file>]\n" |
| 293 | "\n" |
| 294 | "With no arguments, debugfs-dri-directory is probed for in " |
| 295 | "/debug and \n" |
| 296 | "/sys/kernel/debug. Otherwise, it may be " |
| 297 | "specified. If a file is given,\n" |
| 298 | "it is parsed as an GPU dump in the format of " |
| 299 | "/debug/dri/0/i915_error_state.\n", |
| 300 | argv[0]); |
| 301 | return 1; |
| 302 | } |
| 303 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 304 | if (argc == 1) { |
| 305 | path = "/debug/dri/0"; |
| 306 | err = stat (path, &st); |
| 307 | if (err != 0) { |
| 308 | path = "/sys/kernel/debug/dri/0"; |
| 309 | err = stat (path, &st); |
| 310 | if (err != 0) { |
| 311 | errx(1, |
| 312 | "Couldn't find i915 debugfs directory.\n\n" |
| 313 | "Is debugfs mounted? You might try mounting it with a command such as:\n\n" |
| 314 | "\tsudo mount -t debugfs debugfs /sys/kernel/debug\n"); |
| 315 | } |
| 316 | } |
| 317 | } else { |
| 318 | path = argv[1]; |
| 319 | err = stat (path, &st); |
| 320 | if (err != 0) { |
| 321 | fprintf (stderr, "Error opening %s: %s\n", |
| 322 | path, strerror (errno)); |
| 323 | exit (1); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | if (S_ISDIR (st.st_mode)) { |
| 328 | char *filename; |
| 329 | |
| 330 | asprintf (&filename, "%s/i915_error_state", path); |
| 331 | read_data_file (filename); |
| 332 | free (filename); |
| 333 | } else { |
| 334 | read_data_file (path); |
| 335 | } |
| 336 | |
| 337 | return 0; |
| 338 | } |