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> |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 47 | #include <unistd.h> |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 48 | #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 | |
| 58 | static void |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 59 | print_instdone (uint32_t devid, unsigned int instdone, unsigned int instdone1) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 60 | { |
| 61 | int i; |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 62 | static int once; |
| 63 | |
| 64 | if (!once) { |
| 65 | init_instdone_definitions(devid); |
| 66 | once = 1; |
| 67 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 68 | |
| 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 | |
| 85 | static void |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 86 | print_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 | |
| 122 | static void |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 123 | print_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 | |
| 169 | static void |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 170 | print_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 | |
| 200 | static void |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 201 | print_pgtbl_err(unsigned int reg, unsigned int devid) |
| 202 | { |
| 203 | if (IS_965(devid)) { |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 204 | return print_i965_pgtbl_err(reg); |
Chris Wilson | 41570d9 | 2011-02-14 15:56:14 +0000 | [diff] [blame] | 205 | } else if (IS_GEN3(devid)) { |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 206 | return print_i915_pgtbl_err(reg); |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 207 | } else { |
| 208 | return print_i830_pgtbl_err(reg); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | static void |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame^] | 213 | print_snb_fence(unsigned int devid, uint64_t fence) |
| 214 | { |
| 215 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %u\n", |
| 216 | fence & 1 ? "" : "in", |
| 217 | fence & (1<<1) ? 'y' : 'x', |
| 218 | (int)(((fence>>32)&0xfff)+1)*128, |
| 219 | (uint32_t)fence & 0xfffff000, |
| 220 | (uint32_t)(((fence>>32)&0xfffff000) - (fence&0xfffff000) + 4096)); |
| 221 | } |
| 222 | |
| 223 | static void |
| 224 | print_i965_fence(unsigned int devid, uint64_t fence) |
| 225 | { |
| 226 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %u\n", |
| 227 | fence & 1 ? "" : "in", |
| 228 | fence & (1<<1) ? 'y' : 'x', |
| 229 | (int)(((fence>>2)&0x1ff)+1)*128, |
| 230 | (uint32_t)fence & 0xfffff000, |
| 231 | (uint32_t)(((fence>>32)&0xfffff000) - (fence&0xfffff000) + 4096)); |
| 232 | } |
| 233 | |
| 234 | static void |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 235 | print_i915_fence(unsigned int devid, uint64_t fence) |
| 236 | { |
| 237 | unsigned tile_width; |
| 238 | if ((fence & 12) && !IS_915(devid)) |
| 239 | tile_width = 128; |
| 240 | else |
| 241 | tile_width = 512; |
| 242 | |
| 243 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %i\n", |
| 244 | fence & 1 ? "" : "in", |
| 245 | fence & 12 ? 'y' : 'x', |
| 246 | (1<<((fence>>4)&0xf))*tile_width, |
| 247 | (uint32_t)fence & 0x7f80000, |
| 248 | 1<<(20 + ((fence>>8)&0xf))); |
| 249 | } |
| 250 | |
| 251 | static void |
| 252 | print_i830_fence(unsigned int devid, uint64_t fence) |
| 253 | { |
| 254 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %i\n", |
| 255 | fence & 1 ? "" : "in", |
| 256 | fence & 12 ? 'y' : 'x', |
| 257 | (1<<((fence>>4)&0xf))*128, |
| 258 | (uint32_t)fence & 0x7f80000, |
| 259 | 1<<(19 + ((fence>>8)&0xf))); |
| 260 | } |
| 261 | |
| 262 | static void |
| 263 | print_fence(unsigned int devid, uint64_t fence) |
| 264 | { |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame^] | 265 | if (IS_GEN6(devid) || IS_GEN7(devid)) { |
| 266 | return print_snb_fence(devid, fence); |
| 267 | } else if (IS_GEN4(devid) || IS_GEN5(devid)) { |
| 268 | return print_i965_fence(devid, fence); |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 269 | } else if (IS_GEN3(devid)) { |
| 270 | return print_i915_fence(devid, fence); |
| 271 | } else { |
| 272 | return print_i830_fence(devid, fence); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | static void |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 277 | read_data_file (FILE *file) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 278 | { |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 279 | int devid = PCI_CHIP_I855_GM; |
| 280 | uint32_t *data = NULL; |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 281 | long long unsigned fence; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 282 | int data_size = 0, count = 0, line_number = 0, matched; |
| 283 | char *line = NULL; |
| 284 | size_t line_size; |
| 285 | uint32_t offset, value; |
| 286 | uint32_t gtt_offset = 0, new_gtt_offset; |
| 287 | char *buffer_type[2] = { "ringbuffer", "batchbuffer" }; |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 288 | char *ring_name = NULL; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 289 | int is_batch = 1; |
| 290 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 291 | while (getline (&line, &line_size, file) > 0) { |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 292 | char *dashes; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 293 | line_number++; |
| 294 | |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 295 | dashes = strstr(line, "---"); |
| 296 | if (dashes) { |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 297 | char *new_ring_name = malloc(dashes - line); |
| 298 | strncpy(new_ring_name, line, dashes - line); |
| 299 | new_ring_name[dashes - line - 1] = '\0'; |
| 300 | |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 301 | matched = sscanf (dashes, "--- gtt_offset = 0x%08x\n", |
| 302 | &new_gtt_offset); |
| 303 | if (matched == 1) { |
| 304 | if (count) { |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 305 | printf("%s (%s) at 0x%08x:\n", |
| 306 | buffer_type[is_batch], |
| 307 | ring_name, |
| 308 | gtt_offset); |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 309 | intel_decode (data, count, gtt_offset, devid, 0); |
| 310 | count = 0; |
| 311 | } |
| 312 | gtt_offset = new_gtt_offset; |
| 313 | is_batch = 1; |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 314 | free(ring_name); |
| 315 | ring_name = new_ring_name; |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 316 | continue; |
| 317 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 318 | |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 319 | matched = sscanf (dashes, "--- ringbuffer = 0x%08x\n", |
| 320 | &new_gtt_offset); |
| 321 | if (matched == 1) { |
| 322 | if (count) { |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 323 | printf("%s (%s) at 0x%08x:\n", |
| 324 | buffer_type[is_batch], |
| 325 | ring_name, |
| 326 | gtt_offset); |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 327 | intel_decode (data, count, gtt_offset, devid, 0); |
| 328 | count = 0; |
| 329 | } |
| 330 | gtt_offset = new_gtt_offset; |
| 331 | is_batch = 0; |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 332 | free(ring_name); |
| 333 | ring_name = new_ring_name; |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 334 | continue; |
| 335 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | matched = sscanf (line, "%08x : %08x", &offset, &value); |
| 339 | if (matched != 2) { |
| 340 | unsigned int reg; |
| 341 | |
Daniel Vetter | 92b1f2c | 2011-10-18 15:54:31 +0200 | [diff] [blame] | 342 | /* display reg section is after the ringbuffers, don't mix them */ |
| 343 | if (count) { |
| 344 | printf("%s (%s) at 0x%08x:\n", |
| 345 | buffer_type[is_batch], |
| 346 | ring_name, |
| 347 | gtt_offset); |
| 348 | intel_decode (data, count, gtt_offset, devid, 0); |
| 349 | count = 0; |
| 350 | } |
| 351 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 352 | printf("%s", line); |
| 353 | |
| 354 | matched = sscanf (line, "PCI ID: 0x%04x\n", ®); |
Chris Wilson | 4f20844 | 2010-12-23 19:44:14 +0000 | [diff] [blame] | 355 | if (matched == 1) { |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 356 | devid = reg; |
Daniel Vetter | 5801e6b | 2011-10-18 16:30:56 +0200 | [diff] [blame] | 357 | printf("Detected GEN%i chipset\n", |
| 358 | intel_gen(devid)); |
Chris Wilson | 4f20844 | 2010-12-23 19:44:14 +0000 | [diff] [blame] | 359 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 360 | |
| 361 | matched = sscanf (line, " ACTHD: 0x%08x\n", ®); |
Chris Wilson | 1461862 | 2010-08-25 11:55:25 +0100 | [diff] [blame] | 362 | if (matched == 1) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 363 | intel_decode_context_set_head_tail(reg, 0xffffffff); |
| 364 | |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 365 | matched = sscanf (line, " PGTBL_ER: 0x%08x\n", ®); |
Chris Wilson | 1461862 | 2010-08-25 11:55:25 +0100 | [diff] [blame] | 366 | if (matched == 1 && reg) |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 367 | print_pgtbl_err(reg, devid); |
| 368 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 369 | matched = sscanf (line, " INSTDONE: 0x%08x\n", ®); |
Chris Wilson | 1461862 | 2010-08-25 11:55:25 +0100 | [diff] [blame] | 370 | if (matched == 1) |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 371 | print_instdone (devid, reg, -1); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 372 | |
| 373 | matched = sscanf (line, " INSTDONE1: 0x%08x\n", ®); |
Chris Wilson | 1461862 | 2010-08-25 11:55:25 +0100 | [diff] [blame] | 374 | if (matched == 1) |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 375 | print_instdone (devid, -1, reg); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 376 | |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame^] | 377 | matched = sscanf (line, " fence[%i] = %Lx\n", ®, &fence); |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 378 | if (matched == 2) |
| 379 | print_fence (devid, fence); |
| 380 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 381 | continue; |
| 382 | } |
| 383 | |
| 384 | count++; |
| 385 | |
| 386 | if (count > data_size) { |
| 387 | data_size = data_size ? data_size * 2 : 1024; |
| 388 | data = realloc (data, data_size * sizeof (uint32_t)); |
| 389 | if (data == NULL) { |
| 390 | fprintf (stderr, "Out of memory.\n"); |
| 391 | exit (1); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | data[count-1] = value; |
| 396 | } |
| 397 | |
| 398 | if (count) { |
Daniel Vetter | 6ed89f4 | 2011-10-18 15:49:41 +0200 | [diff] [blame] | 399 | printf("%s (%s) at 0x%08x:\n", |
| 400 | buffer_type[is_batch], |
| 401 | ring_name, |
| 402 | gtt_offset); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 403 | intel_decode (data, count, gtt_offset, devid, 0); |
| 404 | } |
| 405 | |
| 406 | free (data); |
| 407 | free (line); |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 408 | free (ring_name); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | int |
| 412 | main (int argc, char *argv[]) |
| 413 | { |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 414 | FILE *file; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 415 | const char *path; |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 416 | char *filename; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 417 | struct stat st; |
| 418 | int err; |
| 419 | |
| 420 | if (argc > 2) { |
| 421 | fprintf (stderr, |
| 422 | "intel_gpu_decode: Parse an Intel GPU i915_error_state\n" |
| 423 | "Usage:\n" |
| 424 | "\t%s [<file>]\n" |
| 425 | "\n" |
| 426 | "With no arguments, debugfs-dri-directory is probed for in " |
| 427 | "/debug and \n" |
| 428 | "/sys/kernel/debug. Otherwise, it may be " |
| 429 | "specified. If a file is given,\n" |
| 430 | "it is parsed as an GPU dump in the format of " |
| 431 | "/debug/dri/0/i915_error_state.\n", |
| 432 | argv[0]); |
| 433 | return 1; |
| 434 | } |
| 435 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 436 | if (argc == 1) { |
Chris Wilson | 292ae45 | 2010-12-10 15:31:59 +0000 | [diff] [blame] | 437 | if (isatty(0)) { |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 438 | path = "/debug/dri"; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 439 | err = stat (path, &st); |
| 440 | if (err != 0) { |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 441 | path = "/sys/kernel/debug/dri"; |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 442 | err = stat (path, &st); |
| 443 | if (err != 0) { |
| 444 | errx(1, |
| 445 | "Couldn't find i915 debugfs directory.\n\n" |
| 446 | "Is debugfs mounted? You might try mounting it with a command such as:\n\n" |
| 447 | "\tsudo mount -t debugfs debugfs /sys/kernel/debug\n"); |
| 448 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 449 | } |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 450 | } else { |
| 451 | read_data_file(stdin); |
| 452 | exit(0); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 453 | } |
| 454 | } else { |
| 455 | path = argv[1]; |
| 456 | err = stat (path, &st); |
| 457 | if (err != 0) { |
| 458 | fprintf (stderr, "Error opening %s: %s\n", |
| 459 | path, strerror (errno)); |
| 460 | exit (1); |
| 461 | } |
| 462 | } |
| 463 | |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 464 | if (S_ISDIR (st.st_mode)) { |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 465 | asprintf (&filename, "%s/i915_error_state", path); |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 466 | file = fopen(filename, "r"); |
| 467 | if (!file) { |
| 468 | int minor; |
| 469 | for (minor = 0; minor < 64; minor++) { |
| 470 | free(filename); |
| 471 | asprintf(&filename, "%s/%d/i915_error_state", path, minor); |
| 472 | file = fopen(filename, "r"); |
| 473 | if (file) |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | if (!file) { |
| 478 | fprintf (stderr, "Failed to find i915_error_state beneath %s\n", |
| 479 | path); |
| 480 | exit (1); |
| 481 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 482 | } else { |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 483 | filename = (char *) path; |
| 484 | file = fopen(filename, "r"); |
| 485 | if (!file) { |
| 486 | fprintf (stderr, "Failed to open %s: %s\n", |
| 487 | filename, strerror (errno)); |
| 488 | exit (1); |
| 489 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 492 | read_data_file (file); |
| 493 | fclose (file); |
| 494 | |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 495 | if (filename != path) |
| 496 | free (filename); |
| 497 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 498 | return 0; |
| 499 | } |