Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2007 Intel Corporation |
| 3 | * Copyright © 2009 Intel Corporation |
| 4 | * Copyright © 2010 Intel Corporation |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 23 | * IN THE SOFTWARE. |
| 24 | * |
| 25 | * Authors: |
| 26 | * Eric Anholt <eric@anholt.net> |
| 27 | * Carl Worth <cworth@cworth.org> |
| 28 | * Chris Wilson <chris@chris-wilson.co.uk> |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | /** @file intel_decode.c |
| 33 | * This file contains code to print out batchbuffer contents in a |
| 34 | * human-readable format. |
| 35 | * |
| 36 | * The current version only supports i915 packets, and only pretty-prints a |
| 37 | * subset of them. The intention is for it to make just a best attempt to |
| 38 | * decode, but never crash in the process. |
| 39 | */ |
| 40 | |
| 41 | #define _GNU_SOURCE |
| 42 | #include <stdio.h> |
| 43 | #include <stdlib.h> |
| 44 | #include <stdarg.h> |
| 45 | #include <string.h> |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 46 | #include <unistd.h> |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 47 | #include <inttypes.h> |
| 48 | #include <errno.h> |
| 49 | #include <sys/stat.h> |
| 50 | #include <err.h> |
Imre Deak | 5efd3d3 | 2012-10-10 16:04:39 +0300 | [diff] [blame] | 51 | #include <assert.h> |
Daniel Vetter | 7ee9f16 | 2012-01-09 23:38:17 +0100 | [diff] [blame] | 52 | #include <intel_bufmgr.h> |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 53 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 54 | #include "intel_chipset.h" |
| 55 | #include "intel_gpu_tools.h" |
| 56 | #include "instdone.h" |
| 57 | |
| 58 | static void |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [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 | { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 61 | int i; |
| 62 | static int once; |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 63 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 64 | if (!once) { |
| 65 | init_instdone_definitions(devid); |
| 66 | once = 1; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 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 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 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) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 107 | printf(" source = %s\n", str); |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 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 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 119 | printf(" error = %s\n", str); |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 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)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 126 | printf(" Cursor A: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 127 | if (reg & (1 << 28)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 128 | printf(" Cursor B: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 129 | if (reg & (1 << 27)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 130 | printf(" MT: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 131 | if (reg & (1 << 26)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 132 | printf(" MT: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 133 | if (reg & (1 << 25)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 134 | printf(" LC: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 135 | if (reg & (1 << 24)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 136 | printf(" LC: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 137 | if (reg & (1 << 23)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 138 | printf(" BIN VertexData: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 139 | if (reg & (1 << 22)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 140 | printf(" BIN Instruction: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 141 | if (reg & (1 << 21)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 142 | printf(" CS VertexData: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 143 | if (reg & (1 << 20)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 144 | printf(" CS Instruction: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 145 | if (reg & (1 << 19)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 146 | printf(" CS: Invalid GTT\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 147 | if (reg & (1 << 18)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 148 | printf(" Overlay: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 149 | if (reg & (1 << 16)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 150 | printf(" Overlay: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 151 | if (reg & (1 << 14)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 152 | printf(" Display C: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 153 | if (reg & (1 << 12)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 154 | printf(" Display C: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 155 | if (reg & (1 << 10)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 156 | printf(" Display B: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 157 | if (reg & (1 << 8)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 158 | printf(" Display B: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 159 | if (reg & (1 << 6)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 160 | printf(" Display A: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 161 | if (reg & (1 << 4)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 162 | printf(" Display A: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 163 | if (reg & (1 << 1)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 164 | printf(" Host Invalid PTE data\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 165 | if (reg & (1 << 0)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 166 | printf(" Host Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 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)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 173 | printf(" Invalid Sampler Cache GTT entry\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 174 | if (reg & (1 << 24)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 175 | printf(" Invalid Render Cache GTT entry\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 176 | if (reg & (1 << 23)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 177 | printf(" Invalid Instruction/State Cache GTT entry\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 178 | if (reg & (1 << 22)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 179 | printf(" There is no ROC, this cannot occur!\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 180 | if (reg & (1 << 21)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 181 | printf(" Invalid GTT entry during Vertex Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 182 | if (reg & (1 << 20)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 183 | printf(" Invalid GTT entry during Command Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 184 | if (reg & (1 << 19)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 185 | printf(" Invalid GTT entry during CS\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 186 | if (reg & (1 << 18)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 187 | printf(" Invalid GTT entry during Cursor Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 188 | if (reg & (1 << 17)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 189 | printf(" Invalid GTT entry during Overlay Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 190 | if (reg & (1 << 8)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 191 | printf(" Invalid GTT entry during Display B Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 192 | if (reg & (1 << 4)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 193 | printf(" Invalid GTT entry during Display A Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 194 | if (reg & (1 << 1)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 195 | printf(" Valid PTE references illegal memory\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 196 | if (reg & (1 << 0)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 197 | printf(" Invalid GTT entry during fetch for host\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 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", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 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)); |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame] | 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", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 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)); |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame] | 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", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 244 | fence & 1 ? "" : "in", |
| 245 | fence & 12 ? 'y' : 'x', |
| 246 | (1<<((fence>>4)&0xf))*tile_width, |
| 247 | (uint32_t)fence & 0xff00000, |
| 248 | 1<<(20 + ((fence>>8)&0xf))); |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 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", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 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))); |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 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 |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 277 | read_data_file(FILE *file) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 278 | { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 279 | struct drm_intel_decode *decode_ctx = NULL; |
| 280 | uint32_t devid = PCI_CHIP_I855_GM; |
| 281 | uint32_t *data = NULL; |
| 282 | long long unsigned fence; |
| 283 | int data_size = 0, count = 0, line_number = 0, matched; |
| 284 | char *line = NULL; |
| 285 | size_t line_size; |
| 286 | uint32_t offset, value; |
| 287 | uint32_t gtt_offset = 0, new_gtt_offset; |
| 288 | const char *buffer_type[2] = { "ringbuffer", "batchbuffer" }; |
| 289 | char *ring_name = NULL; |
| 290 | int is_batch = 1; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 291 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 292 | while (getline(&line, &line_size, file) > 0) { |
| 293 | char *dashes; |
| 294 | line_number++; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 295 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 296 | dashes = strstr(line, "---"); |
| 297 | if (dashes) { |
| 298 | char *new_ring_name = malloc(dashes - line); |
| 299 | strncpy(new_ring_name, line, dashes - line); |
| 300 | new_ring_name[dashes - line - 1] = '\0'; |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 301 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 302 | matched = sscanf(dashes, "--- gtt_offset = 0x%08x\n", |
| 303 | &new_gtt_offset); |
| 304 | if (matched == 1) { |
| 305 | if (count) { |
| 306 | printf("%s (%s) at 0x%08x:\n", |
| 307 | buffer_type[is_batch], |
| 308 | ring_name, |
| 309 | gtt_offset); |
| 310 | drm_intel_decode_set_batch_pointer(decode_ctx, |
| 311 | data, gtt_offset, |
| 312 | count); |
| 313 | drm_intel_decode(decode_ctx); |
| 314 | count = 0; |
| 315 | } |
| 316 | gtt_offset = new_gtt_offset; |
| 317 | is_batch = 1; |
| 318 | free(ring_name); |
| 319 | ring_name = new_ring_name; |
| 320 | continue; |
| 321 | } |
| 322 | |
| 323 | matched = sscanf(dashes, "--- ringbuffer = 0x%08x\n", |
| 324 | &new_gtt_offset); |
| 325 | if (matched == 1) { |
| 326 | if (count) { |
| 327 | printf("%s (%s) at 0x%08x:\n", |
| 328 | buffer_type[is_batch], |
| 329 | ring_name, |
| 330 | gtt_offset); |
| 331 | drm_intel_decode_set_batch_pointer(decode_ctx, |
| 332 | data, gtt_offset, |
| 333 | count); |
| 334 | drm_intel_decode(decode_ctx); |
| 335 | count = 0; |
| 336 | } |
| 337 | gtt_offset = new_gtt_offset; |
| 338 | is_batch = 0; |
| 339 | free(ring_name); |
| 340 | ring_name = new_ring_name; |
| 341 | continue; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | matched = sscanf(line, "%08x : %08x", &offset, &value); |
| 346 | if (matched != 2) { |
| 347 | unsigned int reg; |
| 348 | |
| 349 | /* display reg section is after the ringbuffers, don't mix them */ |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 350 | if (count) { |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 351 | printf("%s (%s) at 0x%08x:\n", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 352 | buffer_type[is_batch], |
| 353 | ring_name, |
| 354 | gtt_offset); |
Daniel Vetter | 7ee9f16 | 2012-01-09 23:38:17 +0100 | [diff] [blame] | 355 | drm_intel_decode_set_batch_pointer(decode_ctx, |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 356 | data, gtt_offset, |
| 357 | count); |
Daniel Vetter | 7ee9f16 | 2012-01-09 23:38:17 +0100 | [diff] [blame] | 358 | drm_intel_decode(decode_ctx); |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 359 | count = 0; |
| 360 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 361 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 362 | printf("%s", line); |
| 363 | |
| 364 | matched = sscanf(line, "PCI ID: 0x%04x\n", ®); |
| 365 | if (matched == 0) |
| 366 | matched = sscanf(line, " PCI ID: 0x%04x\n", ®); |
| 367 | if (matched == 0) { |
| 368 | const char *pci_id_start = strstr(line, "PCI ID"); |
| 369 | if (pci_id_start) |
| 370 | matched = sscanf(pci_id_start, "PCI ID: 0x%04x\n", ®); |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 371 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 372 | if (matched == 1) { |
| 373 | devid = reg; |
| 374 | printf("Detected GEN%i chipset\n", |
| 375 | intel_gen(devid)); |
| 376 | |
| 377 | decode_ctx = drm_intel_decode_context_alloc(devid); |
| 378 | } |
| 379 | |
| 380 | matched = sscanf(line, " ACTHD: 0x%08x\n", ®); |
| 381 | if (matched == 1) |
| 382 | drm_intel_decode_set_head_tail(decode_ctx, reg, 0xffffffff); |
| 383 | |
| 384 | matched = sscanf(line, " PGTBL_ER: 0x%08x\n", ®); |
| 385 | if (matched == 1 && reg) |
| 386 | print_pgtbl_err(reg, devid); |
| 387 | |
| 388 | matched = sscanf(line, " INSTDONE: 0x%08x\n", ®); |
| 389 | if (matched == 1) |
| 390 | print_instdone(devid, reg, -1); |
| 391 | |
| 392 | matched = sscanf(line, " INSTDONE1: 0x%08x\n", ®); |
| 393 | if (matched == 1) |
| 394 | print_instdone(devid, -1, reg); |
| 395 | |
| 396 | matched = sscanf(line, " fence[%i] = %Lx\n", ®, &fence); |
| 397 | if (matched == 2) |
| 398 | print_fence(devid, fence); |
| 399 | |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 400 | continue; |
| 401 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 402 | |
| 403 | count++; |
| 404 | |
| 405 | if (count > data_size) { |
| 406 | data_size = data_size ? data_size * 2 : 1024; |
| 407 | data = realloc(data, data_size * sizeof (uint32_t)); |
| 408 | if (data == NULL) { |
| 409 | fprintf(stderr, "Out of memory.\n"); |
| 410 | exit(1); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | data[count-1] = value; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 417 | if (count) { |
| 418 | printf("%s (%s) at 0x%08x:\n", |
| 419 | buffer_type[is_batch], |
| 420 | ring_name, |
| 421 | gtt_offset); |
| 422 | drm_intel_decode_set_batch_pointer(decode_ctx, |
| 423 | data, gtt_offset, |
| 424 | count); |
| 425 | drm_intel_decode(decode_ctx); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 428 | free(data); |
| 429 | free(line); |
| 430 | free(ring_name); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | int |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 434 | main(int argc, char *argv[]) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 435 | { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 436 | FILE *file; |
| 437 | const char *path; |
| 438 | char *filename = NULL; |
| 439 | struct stat st; |
| 440 | int error; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 441 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 442 | if (argc > 2) { |
| 443 | fprintf(stderr, |
| 444 | "intel_gpu_decode: Parse an Intel GPU i915_error_state\n" |
| 445 | "Usage:\n" |
| 446 | "\t%s [<file>]\n" |
| 447 | "\n" |
| 448 | "With no arguments, debugfs-dri-directory is probed for in " |
| 449 | "/debug and \n" |
| 450 | "/sys/kernel/debug. Otherwise, it may be " |
| 451 | "specified. If a file is given,\n" |
| 452 | "it is parsed as an GPU dump in the format of " |
| 453 | "/debug/dri/0/i915_error_state.\n", |
| 454 | argv[0]); |
| 455 | return 1; |
| 456 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 457 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 458 | if (argc == 1) { |
| 459 | if (isatty(0)) { |
| 460 | path = "/debug/dri"; |
| 461 | error = stat(path, &st); |
| 462 | if (error != 0) { |
| 463 | path = "/sys/kernel/debug/dri"; |
| 464 | error = stat(path, &st); |
| 465 | if (error != 0) { |
| 466 | errx(1, |
| 467 | "Couldn't find i915 debugfs directory.\n\n" |
| 468 | "Is debugfs mounted? You might try mounting it with a command such as:\n\n" |
| 469 | "\tsudo mount -t debugfs debugfs /sys/kernel/debug\n"); |
| 470 | } |
| 471 | } |
| 472 | } else { |
| 473 | read_data_file(stdin); |
| 474 | exit(0); |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 475 | } |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 476 | } else { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 477 | path = argv[1]; |
| 478 | error = stat(path, &st); |
| 479 | if (error != 0) { |
| 480 | fprintf(stderr, "Error opening %s: %s\n", |
| 481 | path, strerror(errno)); |
| 482 | exit(1); |
| 483 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 484 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 485 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 486 | if (S_ISDIR(st.st_mode)) { |
| 487 | int ret; |
Imre Deak | 5efd3d3 | 2012-10-10 16:04:39 +0300 | [diff] [blame] | 488 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 489 | ret = asprintf(&filename, "%s/i915_error_state", path); |
Imre Deak | 5efd3d3 | 2012-10-10 16:04:39 +0300 | [diff] [blame] | 490 | assert(ret > 0); |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 491 | file = fopen(filename, "r"); |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 492 | if (!file) { |
| 493 | int minor; |
| 494 | for (minor = 0; minor < 64; minor++) { |
| 495 | free(filename); |
| 496 | ret = asprintf(&filename, "%s/%d/i915_error_state", path, minor); |
| 497 | assert(ret > 0); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 498 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 499 | file = fopen(filename, "r"); |
| 500 | if (file) |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | if (!file) { |
| 505 | fprintf(stderr, "Failed to find i915_error_state beneath %s\n", |
| 506 | path); |
| 507 | exit (1); |
| 508 | } |
| 509 | } else { |
| 510 | file = fopen(path, "r"); |
| 511 | if (!file) { |
| 512 | fprintf(stderr, "Failed to open %s: %s\n", |
| 513 | path, strerror(errno)); |
| 514 | exit (1); |
| 515 | } |
| 516 | } |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 517 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 518 | read_data_file(file); |
| 519 | fclose(file); |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 520 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 521 | if (filename != path) |
| 522 | free(filename); |
| 523 | |
| 524 | return 0; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 525 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame^] | 526 | |
| 527 | /* vim: set ts=8 sw=8 tw=0 noet :*/ |