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 |
Damien Lespiau | 1d2ef95 | 2013-12-16 11:28:39 +0000 | [diff] [blame] | 42 | #include <stdbool.h> |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 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> |
Imre Deak | 5efd3d3 | 2012-10-10 16:04:39 +0300 | [diff] [blame] | 52 | #include <assert.h> |
Daniel Vetter | 7ee9f16 | 2012-01-09 23:38:17 +0100 | [diff] [blame] | 53 | #include <intel_bufmgr.h> |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 54 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 55 | #include "intel_chipset.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 56 | #include "intel_io.h" |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 57 | #include "instdone.h" |
Daniel Vetter | 6cfcd71 | 2014-03-22 20:07:35 +0100 | [diff] [blame] | 58 | #include "intel_reg.h" |
Zhao Yakui | f04bf00 | 2014-01-22 09:37:20 +0800 | [diff] [blame] | 59 | #include "drmtest.h" |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 60 | |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 61 | static uint32_t |
| 62 | print_head(unsigned int reg) |
| 63 | { |
| 64 | printf(" head = 0x%08x, wraps = %d\n", reg & (0x7ffff<<2), reg >> 21); |
| 65 | return reg & (0x7ffff<<2); |
| 66 | } |
| 67 | |
Mika Kuoppala | edee952 | 2013-07-12 17:02:04 +0300 | [diff] [blame] | 68 | static uint32_t |
| 69 | print_ctl(unsigned int reg) |
| 70 | { |
| 71 | uint32_t ring_length = (((reg & (0x1ff << 12)) >> 12) + 1) * 4096; |
| 72 | |
| 73 | #define BIT_STR(reg, x, on, off) ((1 << (x)) & reg) ? on : off |
| 74 | |
| 75 | printf(" len=%d%s%s%s\n", ring_length, |
| 76 | BIT_STR(reg, 0, ", enabled", ", disabled"), |
| 77 | BIT_STR(reg, 10, ", semaphore wait ", ""), |
| 78 | BIT_STR(reg, 11, ", rb wait ", "") |
| 79 | ); |
| 80 | #undef BIT_STR |
| 81 | return ring_length; |
| 82 | } |
| 83 | |
| 84 | static void |
| 85 | print_acthd(unsigned int reg, unsigned int ring_length) |
| 86 | { |
| 87 | if ((reg & (0x7ffff << 2)) < ring_length) |
| 88 | printf(" at ring: 0x%08x\n", reg & (0x7ffff << 2)); |
| 89 | else |
| 90 | printf(" at batch: 0x%08x\n", reg); |
| 91 | } |
| 92 | |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 93 | static void |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 94 | print_instdone(uint32_t devid, unsigned int instdone, unsigned int instdone1) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 95 | { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 96 | int i; |
| 97 | static int once; |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 98 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 99 | if (!once) { |
| 100 | init_instdone_definitions(devid); |
| 101 | once = 1; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 104 | for (i = 0; i < num_instdone_bits; i++) { |
| 105 | int busy = 0; |
| 106 | |
Damien Lespiau | d8b1dee | 2013-06-04 05:41:36 +0100 | [diff] [blame] | 107 | if (instdone_bits[i].reg == INSTDONE_1) { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 108 | if (!(instdone1 & instdone_bits[i].bit)) |
| 109 | busy = 1; |
| 110 | } else { |
| 111 | if (!(instdone & instdone_bits[i].bit)) |
| 112 | busy = 1; |
| 113 | } |
| 114 | |
| 115 | if (busy) |
| 116 | printf(" busy: %s\n", instdone_bits[i].name); |
| 117 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static void |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 121 | print_i830_pgtbl_err(unsigned int reg) |
| 122 | { |
| 123 | const char *str; |
| 124 | |
| 125 | switch((reg >> 3) & 0xf) { |
| 126 | case 0x1: str = "Overlay TLB"; break; |
| 127 | case 0x2: str = "Display A TLB"; break; |
| 128 | case 0x3: str = "Host TLB"; break; |
| 129 | case 0x4: str = "Render TLB"; break; |
| 130 | case 0x5: str = "Display C TLB"; break; |
| 131 | case 0x6: str = "Mapping TLB"; break; |
| 132 | case 0x7: str = "Command Stream TLB"; break; |
| 133 | case 0x8: str = "Vertex Buffer TLB"; break; |
| 134 | case 0x9: str = "Display B TLB"; break; |
| 135 | case 0xa: str = "Reserved System Memory"; break; |
| 136 | case 0xb: str = "Compressor TLB"; break; |
| 137 | case 0xc: str = "Binner TLB"; break; |
| 138 | default: str = "unknown"; break; |
| 139 | } |
| 140 | |
| 141 | if (str) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 142 | printf(" source = %s\n", str); |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 143 | |
| 144 | switch(reg & 0x7) { |
| 145 | case 0x0: str = "Invalid GTT"; break; |
| 146 | case 0x1: str = "Invalid GTT PTE"; break; |
| 147 | case 0x2: str = "Invalid Memory"; break; |
| 148 | case 0x3: str = "Invalid TLB miss"; break; |
| 149 | case 0x4: str = "Invalid PTE data"; break; |
| 150 | case 0x5: str = "Invalid LocalMemory not present"; break; |
| 151 | case 0x6: str = "Invalid Tiling"; break; |
| 152 | case 0x7: str = "Host to CAM"; break; |
| 153 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 154 | printf(" error = %s\n", str); |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static void |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 158 | print_i915_pgtbl_err(unsigned int reg) |
| 159 | { |
| 160 | if (reg & (1 << 29)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 161 | printf(" Cursor A: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 162 | if (reg & (1 << 28)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 163 | printf(" Cursor B: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 164 | if (reg & (1 << 27)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 165 | printf(" MT: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 166 | if (reg & (1 << 26)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 167 | printf(" MT: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 168 | if (reg & (1 << 25)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 169 | printf(" LC: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 170 | if (reg & (1 << 24)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 171 | printf(" LC: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 172 | if (reg & (1 << 23)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 173 | printf(" BIN VertexData: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 174 | if (reg & (1 << 22)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 175 | printf(" BIN Instruction: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 176 | if (reg & (1 << 21)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 177 | printf(" CS VertexData: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 178 | if (reg & (1 << 20)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 179 | printf(" CS Instruction: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 180 | if (reg & (1 << 19)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 181 | printf(" CS: Invalid GTT\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 182 | if (reg & (1 << 18)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 183 | printf(" Overlay: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 184 | if (reg & (1 << 16)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 185 | printf(" Overlay: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 186 | if (reg & (1 << 14)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 187 | printf(" Display C: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 188 | if (reg & (1 << 12)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 189 | printf(" Display C: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 190 | if (reg & (1 << 10)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 191 | printf(" Display B: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 192 | if (reg & (1 << 8)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 193 | printf(" Display B: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 194 | if (reg & (1 << 6)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 195 | printf(" Display A: Invalid tiling\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 196 | if (reg & (1 << 4)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 197 | printf(" Display A: Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 198 | if (reg & (1 << 1)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 199 | printf(" Host Invalid PTE data\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 200 | if (reg & (1 << 0)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 201 | printf(" Host Invalid GTT PTE\n"); |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static void |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 205 | print_i965_pgtbl_err(unsigned int reg) |
| 206 | { |
| 207 | if (reg & (1 << 26)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 208 | printf(" Invalid Sampler Cache GTT entry\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 209 | if (reg & (1 << 24)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 210 | printf(" Invalid Render Cache GTT entry\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 211 | if (reg & (1 << 23)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 212 | printf(" Invalid Instruction/State Cache GTT entry\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 213 | if (reg & (1 << 22)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 214 | printf(" There is no ROC, this cannot occur!\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 215 | if (reg & (1 << 21)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 216 | printf(" Invalid GTT entry during Vertex Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 217 | if (reg & (1 << 20)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 218 | printf(" Invalid GTT entry during Command Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 219 | if (reg & (1 << 19)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 220 | printf(" Invalid GTT entry during CS\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 221 | if (reg & (1 << 18)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 222 | printf(" Invalid GTT entry during Cursor Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 223 | if (reg & (1 << 17)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 224 | printf(" Invalid GTT entry during Overlay Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 225 | if (reg & (1 << 8)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 226 | printf(" Invalid GTT entry during Display B Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 227 | if (reg & (1 << 4)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 228 | printf(" Invalid GTT entry during Display A Fetch\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 229 | if (reg & (1 << 1)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 230 | printf(" Valid PTE references illegal memory\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 231 | if (reg & (1 << 0)) |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 232 | printf(" Invalid GTT entry during fetch for host\n"); |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 236 | print_pgtbl_err(unsigned int reg, unsigned int devid) |
| 237 | { |
| 238 | if (IS_965(devid)) { |
Chris Wilson | 8934395 | 2010-10-22 11:33:08 +0100 | [diff] [blame] | 239 | return print_i965_pgtbl_err(reg); |
Chris Wilson | 41570d9 | 2011-02-14 15:56:14 +0000 | [diff] [blame] | 240 | } else if (IS_GEN3(devid)) { |
Chris Wilson | 2d1ad95 | 2010-07-15 19:18:39 +0100 | [diff] [blame] | 241 | return print_i915_pgtbl_err(reg); |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 242 | } else { |
| 243 | return print_i830_pgtbl_err(reg); |
| 244 | } |
| 245 | } |
| 246 | |
Chris Wilson | b647046 | 2014-12-05 11:04:42 +0000 | [diff] [blame] | 247 | static void print_ivb_error(unsigned int reg, unsigned int devid) |
| 248 | { |
| 249 | if (reg & (1 << 0)) |
| 250 | printf(" TLB page fault error (GTT entry not valid)\n"); |
| 251 | if (reg & (1 << 1)) |
| 252 | printf(" Invalid physical address in RSTRM interface (PAVP)\n"); |
| 253 | if (reg & (1 << 2)) |
| 254 | printf(" Invalid page directory entry error\n"); |
| 255 | if (reg & (1 << 3)) |
| 256 | printf(" Invalid physical address in ROSTRM interface (PAVP)\n"); |
| 257 | if (reg & (1 << 4)) |
| 258 | printf(" TLB page VTD translation generated an error\n"); |
| 259 | if (reg & (1 << 5)) |
| 260 | printf(" Invalid physical address in WRITE interface (PAVP)\n"); |
| 261 | if (reg & (1 << 6)) |
| 262 | printf(" Page directory VTD translation generated error\n"); |
| 263 | if (reg & (1 << 8)) |
| 264 | printf(" Cacheline containing a PD was marked as invalid\n"); |
| 265 | if (IS_HASWELL(devid) && (reg >> 10) & 0x1f) |
| 266 | printf(" %d pending page faults\n", (reg >> 10) & 0x1f); |
| 267 | } |
| 268 | |
| 269 | static void print_snb_error(unsigned int reg) |
| 270 | { |
| 271 | if (reg & (1 << 0)) |
| 272 | printf(" TLB page fault error (GTT entry not valid)\n"); |
| 273 | if (reg & (1 << 1)) |
| 274 | printf(" Context page GTT translation generated a fault (GTT entry not valid)\n"); |
| 275 | if (reg & (1 << 2)) |
| 276 | printf(" Invalid page directory entry error\n"); |
| 277 | if (reg & (1 << 3)) |
| 278 | printf(" HWS page GTT translation generated a page fault (GTT entry not valid)\n"); |
| 279 | if (reg & (1 << 4)) |
| 280 | printf(" TLB page VTD translation generated an error\n"); |
| 281 | if (reg & (1 << 5)) |
| 282 | printf(" Context page VTD translation generated an error\n"); |
| 283 | if (reg & (1 << 6)) |
| 284 | printf(" Page directory VTD translation generated error\n"); |
| 285 | if (reg & (1 << 7)) |
| 286 | printf(" HWS page VTD translation generated an error\n"); |
| 287 | if (reg & (1 << 8)) |
| 288 | printf(" Cacheline containing a PD was marked as invalid\n"); |
| 289 | } |
| 290 | |
Mika Kuoppala | 0a2ef9c | 2015-03-23 11:35:14 +0200 | [diff] [blame] | 291 | static void print_bdw_error(unsigned int reg, unsigned int devid) |
| 292 | { |
| 293 | print_ivb_error(reg, devid); |
| 294 | |
| 295 | if (reg & (1 << 10)) |
| 296 | printf(" Non WB memory type for Advanced Context\n"); |
| 297 | if (reg & (1 << 11)) |
| 298 | printf(" PASID not enabled\n"); |
| 299 | if (reg & (1 << 12)) |
| 300 | printf(" PASID boundary violation\n"); |
| 301 | if (reg & (1 << 13)) |
| 302 | printf(" PASID not valid\n"); |
| 303 | if (reg & (1 << 14)) |
| 304 | printf(" PASID was zero for untranslated request\n"); |
| 305 | if (reg & (1 << 15)) |
| 306 | printf(" Context was not marked as present when doing DMA\n"); |
| 307 | } |
| 308 | |
Chris Wilson | b647046 | 2014-12-05 11:04:42 +0000 | [diff] [blame] | 309 | static void |
| 310 | print_error(unsigned int reg, unsigned int devid) |
| 311 | { |
| 312 | switch (intel_gen(devid)) { |
Mika Kuoppala | 0a2ef9c | 2015-03-23 11:35:14 +0200 | [diff] [blame] | 313 | case 8: return print_bdw_error(reg, devid); |
Chris Wilson | b647046 | 2014-12-05 11:04:42 +0000 | [diff] [blame] | 314 | case 7: return print_ivb_error(reg, devid); |
| 315 | case 6: return print_snb_error(reg); |
| 316 | } |
| 317 | } |
| 318 | |
Chris Wilson | bfc2b53 | 2010-03-04 21:56:04 +0000 | [diff] [blame] | 319 | static void |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame] | 320 | print_snb_fence(unsigned int devid, uint64_t fence) |
| 321 | { |
| 322 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %u\n", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 323 | fence & 1 ? "" : "in", |
| 324 | fence & (1<<1) ? 'y' : 'x', |
| 325 | (int)(((fence>>32)&0xfff)+1)*128, |
| 326 | (uint32_t)fence & 0xfffff000, |
| 327 | (uint32_t)(((fence>>32)&0xfffff000) - (fence&0xfffff000) + 4096)); |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static void |
| 331 | print_i965_fence(unsigned int devid, uint64_t fence) |
| 332 | { |
| 333 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %u\n", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 334 | fence & 1 ? "" : "in", |
| 335 | fence & (1<<1) ? 'y' : 'x', |
| 336 | (int)(((fence>>2)&0x1ff)+1)*128, |
| 337 | (uint32_t)fence & 0xfffff000, |
| 338 | (uint32_t)(((fence>>32)&0xfffff000) - (fence&0xfffff000) + 4096)); |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 342 | print_i915_fence(unsigned int devid, uint64_t fence) |
| 343 | { |
| 344 | unsigned tile_width; |
| 345 | if ((fence & 12) && !IS_915(devid)) |
| 346 | tile_width = 128; |
| 347 | else |
| 348 | tile_width = 512; |
| 349 | |
| 350 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %i\n", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 351 | fence & 1 ? "" : "in", |
Chris Wilson | 58ac17d | 2013-10-21 09:31:18 +0100 | [diff] [blame] | 352 | fence & (1<<12) ? 'y' : 'x', |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 353 | (1<<((fence>>4)&0xf))*tile_width, |
| 354 | (uint32_t)fence & 0xff00000, |
| 355 | 1<<(20 + ((fence>>8)&0xf))); |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void |
| 359 | print_i830_fence(unsigned int devid, uint64_t fence) |
| 360 | { |
| 361 | printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %i\n", |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 362 | fence & 1 ? "" : "in", |
Chris Wilson | 58ac17d | 2013-10-21 09:31:18 +0100 | [diff] [blame] | 363 | fence & (1<<12) ? 'y' : 'x', |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 364 | (1<<((fence>>4)&0xf))*128, |
| 365 | (uint32_t)fence & 0x7f80000, |
| 366 | 1<<(19 + ((fence>>8)&0xf))); |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static void |
| 370 | print_fence(unsigned int devid, uint64_t fence) |
| 371 | { |
Daniel Vetter | d510953 | 2011-10-21 19:06:08 +0200 | [diff] [blame] | 372 | if (IS_GEN6(devid) || IS_GEN7(devid)) { |
| 373 | return print_snb_fence(devid, fence); |
| 374 | } else if (IS_GEN4(devid) || IS_GEN5(devid)) { |
| 375 | return print_i965_fence(devid, fence); |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 376 | } else if (IS_GEN3(devid)) { |
| 377 | return print_i915_fence(devid, fence); |
| 378 | } else { |
| 379 | return print_i830_fence(devid, fence); |
| 380 | } |
| 381 | } |
| 382 | |
Mika Kuoppala | f96bfb8 | 2015-03-23 11:33:37 +0200 | [diff] [blame^] | 383 | static void |
| 384 | print_fault_reg(unsigned devid, uint32_t reg) |
| 385 | { |
| 386 | const char *gen7_types[] = { "Page", |
| 387 | "Invalid PD", |
| 388 | "Unloaded PD", |
| 389 | "Invalid and Unloaded PD" }; |
| 390 | |
| 391 | const char *gen8_types[] = { "PTE", |
| 392 | "PDE", |
| 393 | "PDPE", |
| 394 | "PML4E" }; |
| 395 | |
| 396 | const char *engine[] = { "GFX", "MFX0", "MFX1", "VEBX", |
| 397 | "BLT", "Unknown", "Unknown", "Unknown" }; |
| 398 | |
| 399 | if (intel_gen(devid) < 7) |
| 400 | return; |
| 401 | |
| 402 | if (reg & (1 << 0)) |
| 403 | printf(" Valid\n"); |
| 404 | else |
| 405 | return; |
| 406 | |
| 407 | if (intel_gen(devid) < 8) |
| 408 | printf(" %s Fault (%s)\n", gen7_types[reg >> 1 & 0x3], |
| 409 | reg & (1 << 11) ? "GGTT" : "PPGTT"); |
| 410 | else |
| 411 | printf(" Invalid %s Fault\n", gen8_types[reg >> 1 & 0x3]); |
| 412 | |
| 413 | if (intel_gen(devid) < 8) |
| 414 | printf(" Address 0x%08x\n", reg & ~((1 << 12)-1)); |
| 415 | else |
| 416 | printf(" Engine %s\n", engine[reg >> 12 & 0x7]); |
| 417 | |
| 418 | printf(" Source ID %d\n", reg >> 3 & 0xff); |
| 419 | } |
| 420 | |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 421 | #define MAX_RINGS 10 /* I really hope this never... */ |
| 422 | uint32_t head[MAX_RINGS]; |
| 423 | int head_ndx = 0; |
Chris Wilson | b5109e6 | 2014-01-23 21:50:36 +0000 | [diff] [blame] | 424 | int num_rings = 0; |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 425 | static void print_batch(int is_batch, const char *ring_name, uint32_t gtt_offset) |
| 426 | { |
| 427 | const char *buffer_type[2] = { "ringbuffer", "batchbuffer" }; |
Chris Wilson | b5109e6 | 2014-01-23 21:50:36 +0000 | [diff] [blame] | 428 | if (is_batch || !num_rings) |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 429 | printf("%s (%s) at 0x%08x\n", buffer_type[is_batch], ring_name, gtt_offset); |
Chris Wilson | b5109e6 | 2014-01-23 21:50:36 +0000 | [diff] [blame] | 430 | else |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 431 | printf("%s (%s) at 0x%08x; HEAD points to: 0x%08x\n", buffer_type[is_batch], ring_name, gtt_offset, head[head_ndx++ % num_rings] + gtt_offset); |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Damien Lespiau | 1d2ef95 | 2013-12-16 11:28:39 +0000 | [diff] [blame] | 434 | static void decode(struct drm_intel_decode *ctx, bool is_batch, |
| 435 | const char *ring_name, uint32_t gtt_offset, uint32_t *data, |
| 436 | int *count) |
| 437 | { |
| 438 | if (!*count) |
| 439 | return; |
| 440 | |
| 441 | print_batch(is_batch, ring_name, gtt_offset); |
| 442 | drm_intel_decode_set_batch_pointer(ctx, data, gtt_offset, *count); |
| 443 | drm_intel_decode(ctx); |
| 444 | *count = 0; |
| 445 | } |
| 446 | |
Daniel Vetter | cf5db11 | 2011-03-14 11:20:17 +0100 | [diff] [blame] | 447 | static void |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 448 | read_data_file(FILE *file) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 449 | { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 450 | struct drm_intel_decode *decode_ctx = NULL; |
| 451 | uint32_t devid = PCI_CHIP_I855_GM; |
| 452 | uint32_t *data = NULL; |
| 453 | long long unsigned fence; |
| 454 | int data_size = 0, count = 0, line_number = 0, matched; |
| 455 | char *line = NULL; |
| 456 | size_t line_size; |
Mika Kuoppala | edee952 | 2013-07-12 17:02:04 +0300 | [diff] [blame] | 457 | uint32_t offset, value, ring_length = 0; |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 458 | uint32_t gtt_offset = 0, new_gtt_offset; |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 459 | char *ring_name = NULL; |
| 460 | int is_batch = 1; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 461 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 462 | while (getline(&line, &line_size, file) > 0) { |
| 463 | char *dashes; |
| 464 | line_number++; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 465 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 466 | dashes = strstr(line, "---"); |
| 467 | if (dashes) { |
| 468 | char *new_ring_name = malloc(dashes - line); |
| 469 | strncpy(new_ring_name, line, dashes - line); |
| 470 | new_ring_name[dashes - line - 1] = '\0'; |
Daniel Vetter | 73c2104 | 2011-10-11 13:14:02 +0200 | [diff] [blame] | 471 | |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 472 | if (num_rings == -1) |
| 473 | num_rings = head_ndx; |
| 474 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 475 | matched = sscanf(dashes, "--- gtt_offset = 0x%08x\n", |
| 476 | &new_gtt_offset); |
| 477 | if (matched == 1) { |
Damien Lespiau | 1d2ef95 | 2013-12-16 11:28:39 +0000 | [diff] [blame] | 478 | decode(decode_ctx, is_batch, ring_name, |
| 479 | gtt_offset, data, &count); |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 480 | gtt_offset = new_gtt_offset; |
| 481 | is_batch = 1; |
| 482 | free(ring_name); |
| 483 | ring_name = new_ring_name; |
| 484 | continue; |
| 485 | } |
| 486 | |
| 487 | matched = sscanf(dashes, "--- ringbuffer = 0x%08x\n", |
| 488 | &new_gtt_offset); |
| 489 | if (matched == 1) { |
Damien Lespiau | 1d2ef95 | 2013-12-16 11:28:39 +0000 | [diff] [blame] | 490 | decode(decode_ctx, is_batch, ring_name, |
| 491 | gtt_offset, data, &count); |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 492 | gtt_offset = new_gtt_offset; |
| 493 | is_batch = 0; |
| 494 | free(ring_name); |
| 495 | ring_name = new_ring_name; |
| 496 | continue; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | matched = sscanf(line, "%08x : %08x", &offset, &value); |
| 501 | if (matched != 2) { |
| 502 | unsigned int reg; |
| 503 | |
| 504 | /* display reg section is after the ringbuffers, don't mix them */ |
Damien Lespiau | 1d2ef95 | 2013-12-16 11:28:39 +0000 | [diff] [blame] | 505 | decode(decode_ctx, is_batch, ring_name, gtt_offset, |
| 506 | data, &count); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 507 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 508 | printf("%s", line); |
| 509 | |
| 510 | matched = sscanf(line, "PCI ID: 0x%04x\n", ®); |
| 511 | if (matched == 0) |
| 512 | matched = sscanf(line, " PCI ID: 0x%04x\n", ®); |
| 513 | if (matched == 0) { |
| 514 | const char *pci_id_start = strstr(line, "PCI ID"); |
| 515 | if (pci_id_start) |
| 516 | matched = sscanf(pci_id_start, "PCI ID: 0x%04x\n", ®); |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 517 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 518 | if (matched == 1) { |
| 519 | devid = reg; |
| 520 | printf("Detected GEN%i chipset\n", |
| 521 | intel_gen(devid)); |
| 522 | |
| 523 | decode_ctx = drm_intel_decode_context_alloc(devid); |
| 524 | } |
| 525 | |
Mika Kuoppala | edee952 | 2013-07-12 17:02:04 +0300 | [diff] [blame] | 526 | matched = sscanf(line, " CTL: 0x%08x\n", ®); |
| 527 | if (matched == 1) |
| 528 | ring_length = print_ctl(reg); |
| 529 | |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 530 | matched = sscanf(line, " HEAD: 0x%08x\n", ®); |
| 531 | if (matched == 1) { |
Chris Wilson | b5109e6 | 2014-01-23 21:50:36 +0000 | [diff] [blame] | 532 | head[num_rings++] = print_head(reg); |
Ben Widawsky | afeb431 | 2013-04-22 11:36:03 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 535 | matched = sscanf(line, " ACTHD: 0x%08x\n", ®); |
Mika Kuoppala | edee952 | 2013-07-12 17:02:04 +0300 | [diff] [blame] | 536 | if (matched == 1) { |
| 537 | print_acthd(reg, ring_length); |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 538 | drm_intel_decode_set_head_tail(decode_ctx, reg, 0xffffffff); |
Mika Kuoppala | edee952 | 2013-07-12 17:02:04 +0300 | [diff] [blame] | 539 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 540 | |
| 541 | matched = sscanf(line, " PGTBL_ER: 0x%08x\n", ®); |
| 542 | if (matched == 1 && reg) |
| 543 | print_pgtbl_err(reg, devid); |
| 544 | |
Chris Wilson | b647046 | 2014-12-05 11:04:42 +0000 | [diff] [blame] | 545 | matched = sscanf(line, " ERROR: 0x%08x\n", ®); |
| 546 | if (matched == 1 && reg) |
| 547 | print_error(reg, devid); |
| 548 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 549 | matched = sscanf(line, " INSTDONE: 0x%08x\n", ®); |
| 550 | if (matched == 1) |
| 551 | print_instdone(devid, reg, -1); |
| 552 | |
| 553 | matched = sscanf(line, " INSTDONE1: 0x%08x\n", ®); |
| 554 | if (matched == 1) |
| 555 | print_instdone(devid, -1, reg); |
| 556 | |
| 557 | matched = sscanf(line, " fence[%i] = %Lx\n", ®, &fence); |
| 558 | if (matched == 2) |
| 559 | print_fence(devid, fence); |
| 560 | |
Mika Kuoppala | f96bfb8 | 2015-03-23 11:33:37 +0200 | [diff] [blame^] | 561 | matched = sscanf(line, " FAULT_REG: 0x%08x\n", ®); |
| 562 | if (matched == 1 && reg) |
| 563 | print_fault_reg(devid, reg); |
| 564 | |
Chris Wilson | 98eb5a5 | 2011-01-09 13:26:50 +0000 | [diff] [blame] | 565 | continue; |
| 566 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 567 | |
| 568 | count++; |
| 569 | |
| 570 | if (count > data_size) { |
| 571 | data_size = data_size ? data_size * 2 : 1024; |
| 572 | data = realloc(data, data_size * sizeof (uint32_t)); |
| 573 | if (data == NULL) { |
| 574 | fprintf(stderr, "Out of memory.\n"); |
| 575 | exit(1); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | data[count-1] = value; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Damien Lespiau | 1d2ef95 | 2013-12-16 11:28:39 +0000 | [diff] [blame] | 582 | decode(decode_ctx, is_batch, ring_name, gtt_offset, data, &count); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 583 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 584 | free(data); |
| 585 | free(line); |
| 586 | free(ring_name); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | int |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 590 | main(int argc, char *argv[]) |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 591 | { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 592 | FILE *file; |
| 593 | const char *path; |
| 594 | char *filename = NULL; |
| 595 | struct stat st; |
| 596 | int error; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 597 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 598 | if (argc > 2) { |
| 599 | fprintf(stderr, |
| 600 | "intel_gpu_decode: Parse an Intel GPU i915_error_state\n" |
| 601 | "Usage:\n" |
| 602 | "\t%s [<file>]\n" |
| 603 | "\n" |
| 604 | "With no arguments, debugfs-dri-directory is probed for in " |
| 605 | "/debug and \n" |
| 606 | "/sys/kernel/debug. Otherwise, it may be " |
| 607 | "specified. If a file is given,\n" |
| 608 | "it is parsed as an GPU dump in the format of " |
| 609 | "/debug/dri/0/i915_error_state.\n", |
| 610 | argv[0]); |
| 611 | return 1; |
| 612 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 613 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 614 | if (argc == 1) { |
| 615 | if (isatty(0)) { |
Chris Wilson | dbbf2e9 | 2013-08-07 23:41:54 +0100 | [diff] [blame] | 616 | path = "/sys/class/drm/card0/error"; |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 617 | error = stat(path, &st); |
| 618 | if (error != 0) { |
Chris Wilson | dbbf2e9 | 2013-08-07 23:41:54 +0100 | [diff] [blame] | 619 | path = "/debug/dri"; |
| 620 | error = stat(path, &st); |
| 621 | } |
| 622 | if (error != 0) { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 623 | path = "/sys/kernel/debug/dri"; |
| 624 | error = stat(path, &st); |
Chris Wilson | dbbf2e9 | 2013-08-07 23:41:54 +0100 | [diff] [blame] | 625 | } |
| 626 | if (error != 0) { |
| 627 | errx(1, |
| 628 | "Couldn't find i915 debugfs directory.\n\n" |
| 629 | "Is debugfs mounted? You might try mounting it with a command such as:\n\n" |
| 630 | "\tsudo mount -t debugfs debugfs /sys/kernel/debug\n"); |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 631 | } |
| 632 | } else { |
| 633 | read_data_file(stdin); |
| 634 | exit(0); |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 635 | } |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 636 | } else { |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 637 | path = argv[1]; |
| 638 | error = stat(path, &st); |
| 639 | if (error != 0) { |
| 640 | fprintf(stderr, "Error opening %s: %s\n", |
| 641 | path, strerror(errno)); |
| 642 | exit(1); |
| 643 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 644 | } |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 645 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 646 | if (S_ISDIR(st.st_mode)) { |
| 647 | int ret; |
Imre Deak | 5efd3d3 | 2012-10-10 16:04:39 +0300 | [diff] [blame] | 648 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 649 | ret = asprintf(&filename, "%s/i915_error_state", path); |
Imre Deak | 5efd3d3 | 2012-10-10 16:04:39 +0300 | [diff] [blame] | 650 | assert(ret > 0); |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 651 | file = fopen(filename, "r"); |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 652 | if (!file) { |
| 653 | int minor; |
| 654 | for (minor = 0; minor < 64; minor++) { |
| 655 | free(filename); |
| 656 | ret = asprintf(&filename, "%s/%d/i915_error_state", path, minor); |
| 657 | assert(ret > 0); |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 658 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 659 | file = fopen(filename, "r"); |
| 660 | if (file) |
| 661 | break; |
| 662 | } |
| 663 | } |
| 664 | if (!file) { |
| 665 | fprintf(stderr, "Failed to find i915_error_state beneath %s\n", |
| 666 | path); |
| 667 | exit (1); |
| 668 | } |
| 669 | } else { |
| 670 | file = fopen(path, "r"); |
| 671 | if (!file) { |
| 672 | fprintf(stderr, "Failed to open %s: %s\n", |
| 673 | path, strerror(errno)); |
| 674 | exit (1); |
| 675 | } |
| 676 | } |
Chris Wilson | 68a95f0 | 2011-01-25 16:34:08 +0000 | [diff] [blame] | 677 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 678 | read_data_file(file); |
| 679 | fclose(file); |
Chris Wilson | a3a7863 | 2010-12-01 21:51:59 +0000 | [diff] [blame] | 680 | |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 681 | if (filename != path) |
| 682 | free(filename); |
| 683 | |
| 684 | return 0; |
Chris Wilson | 9eb4de1 | 2010-02-12 13:28:40 +0000 | [diff] [blame] | 685 | } |
Ben Widawsky | 155aa1e | 2013-04-22 11:07:35 -0700 | [diff] [blame] | 686 | |
| 687 | /* vim: set ts=8 sw=8 tw=0 noet :*/ |