Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/intel/tools/aubinator_error_decode.c
4547 views
1
/*
2
* Copyright © 2007-2017 Intel Corporation
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
* IN THE SOFTWARE.
22
*
23
*/
24
25
#include <stdbool.h>
26
#include <stdio.h>
27
#include <stdlib.h>
28
#include <stdarg.h>
29
#include <string.h>
30
#include <unistd.h>
31
#include <inttypes.h>
32
#include <errno.h>
33
#include <sys/stat.h>
34
#include <sys/types.h>
35
#include <sys/wait.h>
36
#include <err.h>
37
#include <assert.h>
38
#include <getopt.h>
39
#include <zlib.h>
40
41
#include "common/intel_decoder.h"
42
#include "dev/intel_debug.h"
43
#include "util/macros.h"
44
45
#define MIN(a, b) ((a) < (b) ? (a) : (b))
46
47
/* options */
48
49
static bool option_full_decode = true;
50
static bool option_print_all_bb = false;
51
static bool option_print_offsets = true;
52
static enum { COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER } option_color;
53
static char *xml_path = NULL;
54
55
static uint32_t
56
print_head(unsigned int reg)
57
{
58
printf(" head = 0x%08x, wraps = %d\n", reg & (0x7ffff<<2), reg >> 21);
59
return reg & (0x7ffff<<2);
60
}
61
62
static void
63
print_register(struct intel_spec *spec, const char *name, uint32_t reg)
64
{
65
struct intel_group *reg_spec =
66
name ? intel_spec_find_register_by_name(spec, name) : NULL;
67
68
if (reg_spec) {
69
intel_print_group(stdout, reg_spec, 0, &reg, 0,
70
option_color == COLOR_ALWAYS);
71
}
72
}
73
74
struct ring_register_mapping {
75
enum drm_i915_gem_engine_class ring_class;
76
unsigned ring_instance;
77
const char *register_name;
78
};
79
80
static const struct ring_register_mapping acthd_registers[] = {
81
{ I915_ENGINE_CLASS_COPY, 0, "BCS_ACTHD_UDW" },
82
{ I915_ENGINE_CLASS_VIDEO, 0, "VCS_ACTHD_UDW" },
83
{ I915_ENGINE_CLASS_VIDEO, 1, "VCS2_ACTHD_UDW" },
84
{ I915_ENGINE_CLASS_RENDER, 0, "ACTHD_UDW" },
85
{ I915_ENGINE_CLASS_VIDEO_ENHANCE, 0, "VECS_ACTHD_UDW" },
86
};
87
88
static const struct ring_register_mapping ctl_registers[] = {
89
{ I915_ENGINE_CLASS_COPY, 0, "BCS_RING_BUFFER_CTL" },
90
{ I915_ENGINE_CLASS_VIDEO, 0, "VCS_RING_BUFFER_CTL" },
91
{ I915_ENGINE_CLASS_VIDEO, 1, "VCS2_RING_BUFFER_CTL" },
92
{ I915_ENGINE_CLASS_RENDER, 0, "RCS_RING_BUFFER_CTL" },
93
{ I915_ENGINE_CLASS_VIDEO_ENHANCE, 0, "VECS_RING_BUFFER_CTL" },
94
};
95
96
static const struct ring_register_mapping fault_registers[] = {
97
{ I915_ENGINE_CLASS_COPY, 0, "BCS_FAULT_REG" },
98
{ I915_ENGINE_CLASS_VIDEO, 0, "VCS_FAULT_REG" },
99
{ I915_ENGINE_CLASS_RENDER, 0, "RCS_FAULT_REG" },
100
{ I915_ENGINE_CLASS_VIDEO_ENHANCE, 0, "VECS_FAULT_REG" },
101
};
102
103
static int ring_name_to_class(const char *ring_name,
104
enum drm_i915_gem_engine_class *class)
105
{
106
static const char *class_names[] = {
107
[I915_ENGINE_CLASS_RENDER] = "rcs",
108
[I915_ENGINE_CLASS_COPY] = "bcs",
109
[I915_ENGINE_CLASS_VIDEO] = "vcs",
110
[I915_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs",
111
};
112
for (size_t i = 0; i < ARRAY_SIZE(class_names); i++) {
113
if (strncmp(ring_name, class_names[i], strlen(class_names[i])))
114
continue;
115
116
*class = i;
117
return atoi(ring_name + strlen(class_names[i]));
118
}
119
120
static const struct {
121
const char *name;
122
unsigned int class;
123
int instance;
124
} legacy_names[] = {
125
{ "render", I915_ENGINE_CLASS_RENDER, 0 },
126
{ "blt", I915_ENGINE_CLASS_COPY, 0 },
127
{ "bsd", I915_ENGINE_CLASS_VIDEO, 0 },
128
{ "bsd2", I915_ENGINE_CLASS_VIDEO, 1 },
129
{ "vebox", I915_ENGINE_CLASS_VIDEO_ENHANCE, 0 },
130
};
131
for (size_t i = 0; i < ARRAY_SIZE(legacy_names); i++) {
132
if (strcmp(ring_name, legacy_names[i].name))
133
continue;
134
135
*class = legacy_names[i].class;
136
return legacy_names[i].instance;
137
}
138
139
return -1;
140
}
141
142
static const char *
143
register_name_from_ring(const struct ring_register_mapping *mapping,
144
unsigned nb_mapping,
145
const char *ring_name)
146
{
147
enum drm_i915_gem_engine_class class;
148
int instance;
149
150
instance = ring_name_to_class(ring_name, &class);
151
if (instance < 0)
152
return NULL;
153
154
for (unsigned i = 0; i < nb_mapping; i++) {
155
if (mapping[i].ring_class == class &&
156
mapping[i].ring_instance == instance)
157
return mapping[i].register_name;
158
}
159
return NULL;
160
}
161
162
static const char *
163
instdone_register_for_ring(const struct intel_device_info *devinfo,
164
const char *ring_name)
165
{
166
enum drm_i915_gem_engine_class class;
167
int instance;
168
169
instance = ring_name_to_class(ring_name, &class);
170
if (instance < 0)
171
return NULL;
172
173
switch (class) {
174
case I915_ENGINE_CLASS_RENDER:
175
if (devinfo->ver == 6)
176
return "INSTDONE_2";
177
else
178
return "INSTDONE_1";
179
180
case I915_ENGINE_CLASS_COPY:
181
return "BCS_INSTDONE";
182
183
case I915_ENGINE_CLASS_VIDEO:
184
switch (instance) {
185
case 0:
186
return "VCS_INSTDONE";
187
case 1:
188
return "VCS2_INSTDONE";
189
default:
190
return NULL;
191
}
192
193
case I915_ENGINE_CLASS_VIDEO_ENHANCE:
194
return "VECS_INSTDONE";
195
196
default:
197
return NULL;
198
}
199
200
return NULL;
201
}
202
203
static void
204
print_pgtbl_err(unsigned int reg, struct intel_device_info *devinfo)
205
{
206
if (reg & (1 << 26))
207
printf(" Invalid Sampler Cache GTT entry\n");
208
if (reg & (1 << 24))
209
printf(" Invalid Render Cache GTT entry\n");
210
if (reg & (1 << 23))
211
printf(" Invalid Instruction/State Cache GTT entry\n");
212
if (reg & (1 << 22))
213
printf(" There is no ROC, this cannot occur!\n");
214
if (reg & (1 << 21))
215
printf(" Invalid GTT entry during Vertex Fetch\n");
216
if (reg & (1 << 20))
217
printf(" Invalid GTT entry during Command Fetch\n");
218
if (reg & (1 << 19))
219
printf(" Invalid GTT entry during CS\n");
220
if (reg & (1 << 18))
221
printf(" Invalid GTT entry during Cursor Fetch\n");
222
if (reg & (1 << 17))
223
printf(" Invalid GTT entry during Overlay Fetch\n");
224
if (reg & (1 << 8))
225
printf(" Invalid GTT entry during Display B Fetch\n");
226
if (reg & (1 << 4))
227
printf(" Invalid GTT entry during Display A Fetch\n");
228
if (reg & (1 << 1))
229
printf(" Valid PTE references illegal memory\n");
230
if (reg & (1 << 0))
231
printf(" Invalid GTT entry during fetch for host\n");
232
}
233
234
static void
235
print_snb_fence(struct intel_device_info *devinfo, uint64_t fence)
236
{
237
printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %u\n",
238
fence & 1 ? "" : "in",
239
fence & (1<<1) ? 'y' : 'x',
240
(int)(((fence>>32)&0xfff)+1)*128,
241
(uint32_t)fence & 0xfffff000,
242
(uint32_t)(((fence>>32)&0xfffff000) - (fence&0xfffff000) + 4096));
243
}
244
245
static void
246
print_i965_fence(struct intel_device_info *devinfo, uint64_t fence)
247
{
248
printf(" %svalid, %c-tiled, pitch: %i, start: 0x%08x, size: %u\n",
249
fence & 1 ? "" : "in",
250
fence & (1<<1) ? 'y' : 'x',
251
(int)(((fence>>2)&0x1ff)+1)*128,
252
(uint32_t)fence & 0xfffff000,
253
(uint32_t)(((fence>>32)&0xfffff000) - (fence&0xfffff000) + 4096));
254
}
255
256
static void
257
print_fence(struct intel_device_info *devinfo, uint64_t fence)
258
{
259
if (devinfo->ver == 6 || devinfo->ver == 7) {
260
return print_snb_fence(devinfo, fence);
261
} else if (devinfo->ver == 4 || devinfo->ver == 5) {
262
return print_i965_fence(devinfo, fence);
263
}
264
}
265
266
static void
267
print_fault_data(struct intel_device_info *devinfo, uint32_t data1, uint32_t data0)
268
{
269
uint64_t address;
270
271
if (devinfo->ver < 8)
272
return;
273
274
address = ((uint64_t)(data0) << 12) | ((uint64_t)data1 & 0xf) << 44;
275
printf(" Address 0x%016" PRIx64 " %s\n", address,
276
data1 & (1 << 4) ? "GGTT" : "PPGTT");
277
}
278
279
#define CSI "\e["
280
#define NORMAL CSI "0m"
281
282
struct section {
283
uint64_t gtt_offset;
284
char *ring_name;
285
const char *buffer_name;
286
uint32_t *data;
287
int dword_count;
288
size_t data_offset;
289
};
290
291
#define MAX_SECTIONS 256
292
static unsigned num_sections;
293
static struct section sections[MAX_SECTIONS];
294
295
static int zlib_inflate(uint32_t **ptr, int len)
296
{
297
struct z_stream_s zstream;
298
void *out;
299
const uint32_t out_size = 128*4096; /* approximate obj size */
300
301
memset(&zstream, 0, sizeof(zstream));
302
303
zstream.next_in = (unsigned char *)*ptr;
304
zstream.avail_in = 4*len;
305
306
if (inflateInit(&zstream) != Z_OK)
307
return 0;
308
309
out = malloc(out_size);
310
zstream.next_out = out;
311
zstream.avail_out = out_size;
312
313
do {
314
switch (inflate(&zstream, Z_SYNC_FLUSH)) {
315
case Z_STREAM_END:
316
goto end;
317
case Z_OK:
318
break;
319
default:
320
inflateEnd(&zstream);
321
return 0;
322
}
323
324
if (zstream.avail_out)
325
break;
326
327
out = realloc(out, 2*zstream.total_out);
328
if (out == NULL) {
329
inflateEnd(&zstream);
330
return 0;
331
}
332
333
zstream.next_out = (unsigned char *)out + zstream.total_out;
334
zstream.avail_out = zstream.total_out;
335
} while (1);
336
end:
337
inflateEnd(&zstream);
338
free(*ptr);
339
*ptr = out;
340
return zstream.total_out / 4;
341
}
342
343
static int ascii85_decode(const char *in, uint32_t **out, bool inflate)
344
{
345
int len = 0, size = 1024;
346
347
*out = realloc(*out, sizeof(uint32_t)*size);
348
if (*out == NULL)
349
return 0;
350
351
while (*in >= '!' && *in <= 'z') {
352
uint32_t v = 0;
353
354
if (len == size) {
355
size *= 2;
356
*out = realloc(*out, sizeof(uint32_t)*size);
357
if (*out == NULL)
358
return 0;
359
}
360
361
if (*in == 'z') {
362
in++;
363
} else {
364
v += in[0] - 33; v *= 85;
365
v += in[1] - 33; v *= 85;
366
v += in[2] - 33; v *= 85;
367
v += in[3] - 33; v *= 85;
368
v += in[4] - 33;
369
in += 5;
370
}
371
(*out)[len++] = v;
372
}
373
374
if (!inflate)
375
return len;
376
377
return zlib_inflate(out, len);
378
}
379
380
static int qsort_hw_context_first(const void *a, const void *b)
381
{
382
const struct section *sa = a, *sb = b;
383
if (strcmp(sa->buffer_name, "HW Context") == 0)
384
return -1;
385
if (strcmp(sb->buffer_name, "HW Context") == 0)
386
return 1;
387
else
388
return 0;
389
}
390
391
static struct intel_batch_decode_bo
392
get_intel_batch_bo(void *user_data, bool ppgtt, uint64_t address)
393
{
394
for (int s = 0; s < num_sections; s++) {
395
if (sections[s].gtt_offset <= address &&
396
address < sections[s].gtt_offset + sections[s].dword_count * 4) {
397
return (struct intel_batch_decode_bo) {
398
.addr = sections[s].gtt_offset,
399
.map = sections[s].data,
400
.size = sections[s].dword_count * 4,
401
};
402
}
403
}
404
405
return (struct intel_batch_decode_bo) { .map = NULL };
406
}
407
408
static void
409
read_data_file(FILE *file)
410
{
411
struct intel_spec *spec = NULL;
412
long long unsigned fence;
413
int matched;
414
char *line = NULL;
415
size_t line_size;
416
uint32_t offset, value;
417
uint32_t ring_head = UINT32_MAX, ring_tail = UINT32_MAX;
418
bool ring_wraps = false;
419
char *ring_name = NULL;
420
struct intel_device_info devinfo;
421
422
while (getline(&line, &line_size, file) > 0) {
423
char *new_ring_name = NULL;
424
char *dashes;
425
426
if (sscanf(line, "%m[^ ] command stream\n", &new_ring_name) > 0) {
427
free(ring_name);
428
ring_name = new_ring_name;
429
}
430
431
if (line[0] == ':' || line[0] == '~') {
432
uint32_t *data = NULL;
433
int dword_count = ascii85_decode(line+1, &data, line[0] == ':');
434
if (dword_count == 0) {
435
fprintf(stderr, "ASCII85 decode failed.\n");
436
exit(EXIT_FAILURE);
437
}
438
assert(num_sections < MAX_SECTIONS);
439
sections[num_sections].data = data;
440
sections[num_sections].dword_count = dword_count;
441
num_sections++;
442
continue;
443
}
444
445
dashes = strstr(line, "---");
446
if (dashes) {
447
const struct {
448
const char *match;
449
const char *name;
450
} buffers[] = {
451
{ "ringbuffer", "ring buffer" },
452
{ "ring", "ring buffer" },
453
{ "gtt_offset", "batch buffer" },
454
{ "batch", "batch buffer" },
455
{ "hw context", "HW Context" },
456
{ "hw status", "HW status" },
457
{ "wa context", "WA context" },
458
{ "wa batchbuffer", "WA batch" },
459
{ "NULL context", "Kernel context" },
460
{ "user", "user" },
461
{ "semaphores", "semaphores", },
462
{ "guc log buffer", "GuC log", },
463
{ NULL, "unknown" },
464
}, *b;
465
466
free(ring_name);
467
ring_name = malloc(dashes - line);
468
strncpy(ring_name, line, dashes - line);
469
ring_name[dashes - line - 1] = '\0';
470
471
dashes += 4;
472
for (b = buffers; b->match; b++) {
473
if (strncasecmp(dashes, b->match, strlen(b->match)) == 0)
474
break;
475
}
476
477
assert(num_sections < MAX_SECTIONS);
478
sections[num_sections].buffer_name = b->name;
479
sections[num_sections].ring_name = strdup(ring_name);
480
481
uint32_t hi, lo;
482
dashes = strchr(dashes, '=');
483
if (dashes && sscanf(dashes, "= 0x%08x %08x\n", &hi, &lo))
484
sections[num_sections].gtt_offset = ((uint64_t) hi) << 32 | lo;
485
486
continue;
487
}
488
489
matched = sscanf(line, "%08x : %08x", &offset, &value);
490
if (matched != 2) {
491
uint32_t reg, reg2;
492
493
/* display reg section is after the ringbuffers, don't mix them */
494
printf("%s", line);
495
496
matched = sscanf(line, "PCI ID: 0x%04x\n", &reg);
497
if (matched == 0)
498
matched = sscanf(line, " PCI ID: 0x%04x\n", &reg);
499
if (matched == 0) {
500
const char *pci_id_start = strstr(line, "PCI ID");
501
if (pci_id_start)
502
matched = sscanf(pci_id_start, "PCI ID: 0x%04x\n", &reg);
503
}
504
if (matched == 1) {
505
if (!intel_get_device_info_from_pci_id(reg, &devinfo)) {
506
printf("Unable to identify devid=%x\n", reg);
507
exit(EXIT_FAILURE);
508
}
509
510
printf("Detected GEN%i chipset\n", devinfo.ver);
511
512
if (xml_path == NULL)
513
spec = intel_spec_load(&devinfo);
514
else
515
spec = intel_spec_load_from_path(&devinfo, xml_path);
516
}
517
518
matched = sscanf(line, " CTL: 0x%08x\n", &reg);
519
if (matched == 1) {
520
print_register(spec,
521
register_name_from_ring(ctl_registers,
522
ARRAY_SIZE(ctl_registers),
523
ring_name), reg);
524
}
525
526
matched = sscanf(line, " HEAD: 0x%08x\n", &reg);
527
if (matched == 1)
528
print_head(reg);
529
530
sscanf(line, " HEAD: 0x%08x [0x%08X]\n", &reg, &ring_head);
531
sscanf(line, " TAIL: 0x%08x\n", &ring_tail);
532
533
matched = sscanf(line, " ACTHD: 0x%08x\n", &reg);
534
if (matched == 1) {
535
print_register(spec,
536
register_name_from_ring(acthd_registers,
537
ARRAY_SIZE(acthd_registers),
538
ring_name), reg);
539
}
540
541
matched = sscanf(line, " PGTBL_ER: 0x%08x\n", &reg);
542
if (matched == 1 && reg)
543
print_pgtbl_err(reg, &devinfo);
544
545
matched = sscanf(line, " ERROR: 0x%08x\n", &reg);
546
if (matched == 1 && reg) {
547
print_register(spec, "GFX_ARB_ERROR_RPT", reg);
548
}
549
550
matched = sscanf(line, " INSTDONE: 0x%08x\n", &reg);
551
if (matched == 1) {
552
const char *reg_name =
553
instdone_register_for_ring(&devinfo, ring_name);
554
if (reg_name)
555
print_register(spec, reg_name, reg);
556
}
557
558
matched = sscanf(line, " SC_INSTDONE: 0x%08x\n", &reg);
559
if (matched == 1)
560
print_register(spec, "SC_INSTDONE", reg);
561
562
matched = sscanf(line, " SAMPLER_INSTDONE[%*d][%*d]: 0x%08x\n", &reg);
563
if (matched == 1)
564
print_register(spec, "SAMPLER_INSTDONE", reg);
565
566
matched = sscanf(line, " ROW_INSTDONE[%*d][%*d]: 0x%08x\n", &reg);
567
if (matched == 1)
568
print_register(spec, "ROW_INSTDONE", reg);
569
570
matched = sscanf(line, " INSTDONE1: 0x%08x\n", &reg);
571
if (matched == 1)
572
print_register(spec, "INSTDONE_1", reg);
573
574
matched = sscanf(line, " fence[%i] = %Lx\n", &reg, &fence);
575
if (matched == 2)
576
print_fence(&devinfo, fence);
577
578
matched = sscanf(line, " FAULT_REG: 0x%08x\n", &reg);
579
if (matched == 1 && reg) {
580
const char *reg_name =
581
register_name_from_ring(fault_registers,
582
ARRAY_SIZE(fault_registers),
583
ring_name);
584
if (reg_name == NULL)
585
reg_name = "FAULT_REG";
586
print_register(spec, reg_name, reg);
587
}
588
589
matched = sscanf(line, " FAULT_TLB_DATA: 0x%08x 0x%08x\n", &reg, &reg2);
590
if (matched == 2)
591
print_fault_data(&devinfo, reg, reg2);
592
593
continue;
594
}
595
}
596
597
free(line);
598
free(ring_name);
599
600
/*
601
* Order sections so that the hardware context section is visited by the
602
* decoder before other command buffers. This will allow the decoder to see
603
* persistent state that was set before the current batch.
604
*/
605
qsort(sections, num_sections, sizeof(sections[0]), qsort_hw_context_first);
606
607
for (int s = 0; s < num_sections; s++) {
608
if (strcmp(sections[s].buffer_name, "ring buffer") != 0)
609
continue;
610
if (ring_head == UINT32_MAX) {
611
ring_head = 0;
612
ring_tail = UINT32_MAX;
613
}
614
if (ring_tail == UINT32_MAX)
615
ring_tail = (ring_head - sizeof(uint32_t)) %
616
(sections[s].dword_count * sizeof(uint32_t));
617
if (ring_head > ring_tail) {
618
size_t total_size = sections[s].dword_count * sizeof(uint32_t) -
619
ring_head + ring_tail;
620
size_t size1 = total_size - ring_tail;
621
uint32_t *new_data = calloc(total_size, 1);
622
memcpy(new_data, (uint8_t *)sections[s].data + ring_head, size1);
623
memcpy((uint8_t *)new_data + size1, sections[s].data, ring_tail);
624
free(sections[s].data);
625
sections[s].data = new_data;
626
ring_head = 0;
627
ring_tail = total_size;
628
ring_wraps = true;
629
}
630
sections[s].data_offset = ring_head;
631
sections[s].dword_count = (ring_tail - ring_head) / sizeof(uint32_t);
632
}
633
634
for (int s = 0; s < num_sections; s++) {
635
if (sections[s].dword_count * 4 > intel_debug_identifier_size() &&
636
memcmp(sections[s].data, intel_debug_identifier(),
637
intel_debug_identifier_size()) == 0) {
638
const struct intel_debug_block_driver *driver_desc =
639
intel_debug_get_identifier_block(sections[s].data,
640
sections[s].dword_count * 4,
641
INTEL_DEBUG_BLOCK_TYPE_DRIVER);
642
if (driver_desc) {
643
printf("Driver identifier: %s\n",
644
(const char *) driver_desc->description);
645
}
646
break;
647
}
648
}
649
650
enum intel_batch_decode_flags batch_flags = 0;
651
if (option_color == COLOR_ALWAYS)
652
batch_flags |= INTEL_BATCH_DECODE_IN_COLOR;
653
if (option_full_decode)
654
batch_flags |= INTEL_BATCH_DECODE_FULL;
655
if (option_print_offsets)
656
batch_flags |= INTEL_BATCH_DECODE_OFFSETS;
657
batch_flags |= INTEL_BATCH_DECODE_FLOATS;
658
659
struct intel_batch_decode_ctx batch_ctx;
660
intel_batch_decode_ctx_init(&batch_ctx, &devinfo, stdout, batch_flags,
661
xml_path, get_intel_batch_bo, NULL, NULL);
662
663
664
for (int s = 0; s < num_sections; s++) {
665
enum drm_i915_gem_engine_class class;
666
ring_name_to_class(sections[s].ring_name, &class);
667
668
printf("--- %s (%s) at 0x%08x %08x\n",
669
sections[s].buffer_name, sections[s].ring_name,
670
(unsigned) (sections[s].gtt_offset >> 32),
671
(unsigned) sections[s].gtt_offset);
672
673
bool is_ring_buffer = strcmp(sections[s].buffer_name, "ring buffer") == 0;
674
if (option_print_all_bb || is_ring_buffer ||
675
strcmp(sections[s].buffer_name, "batch buffer") == 0 ||
676
strcmp(sections[s].buffer_name, "HW Context") == 0) {
677
if (is_ring_buffer && ring_wraps)
678
batch_ctx.flags &= ~INTEL_BATCH_DECODE_OFFSETS;
679
batch_ctx.engine = class;
680
uint8_t *data = (uint8_t *)sections[s].data + sections[s].data_offset;
681
uint64_t batch_addr = sections[s].gtt_offset + sections[s].data_offset;
682
intel_print_batch(&batch_ctx, (uint32_t *)data,
683
sections[s].dword_count * 4, batch_addr,
684
is_ring_buffer);
685
batch_ctx.flags = batch_flags;
686
}
687
}
688
689
intel_batch_decode_ctx_finish(&batch_ctx);
690
691
for (int s = 0; s < num_sections; s++) {
692
free(sections[s].ring_name);
693
free(sections[s].data);
694
}
695
}
696
697
static void
698
setup_pager(void)
699
{
700
int fds[2];
701
pid_t pid;
702
703
if (!isatty(1))
704
return;
705
706
if (pipe(fds) == -1)
707
return;
708
709
pid = fork();
710
if (pid == -1)
711
return;
712
713
if (pid == 0) {
714
close(fds[1]);
715
dup2(fds[0], 0);
716
execlp("less", "less", "-FRSi", NULL);
717
}
718
719
close(fds[0]);
720
dup2(fds[1], 1);
721
close(fds[1]);
722
}
723
724
static void
725
print_help(const char *progname, FILE *file)
726
{
727
fprintf(file,
728
"Usage: %s [OPTION]... [FILE]\n"
729
"Parse an Intel GPU i915_error_state.\n"
730
"With no FILE, debugfs-dri-directory is probed for in /debug and \n"
731
"/sys/kernel/debug. Otherwise, it may be specified. If a file is given,\n"
732
"it is parsed as an GPU dump in the format of /debug/dri/0/i915_error_state.\n\n"
733
" --help display this help and exit\n"
734
" --headers decode only command headers\n"
735
" --color[=WHEN] colorize the output; WHEN can be 'auto' (default\n"
736
" if omitted), 'always', or 'never'\n"
737
" --no-pager don't launch pager\n"
738
" --no-offsets don't print instruction offsets\n"
739
" --xml=DIR load hardware xml description from directory DIR\n"
740
" --all-bb print out all batchbuffers\n",
741
progname);
742
}
743
744
static FILE *
745
open_error_state_file(const char *path)
746
{
747
FILE *file;
748
struct stat st;
749
750
if (stat(path, &st))
751
return NULL;
752
753
if (S_ISDIR(st.st_mode)) {
754
ASSERTED int ret;
755
char *filename;
756
757
ret = asprintf(&filename, "%s/i915_error_state", path);
758
assert(ret > 0);
759
file = fopen(filename, "r");
760
free(filename);
761
if (!file) {
762
int minor;
763
for (minor = 0; minor < 64; minor++) {
764
ret = asprintf(&filename, "%s/%d/i915_error_state", path, minor);
765
assert(ret > 0);
766
767
file = fopen(filename, "r");
768
free(filename);
769
if (file)
770
break;
771
}
772
}
773
if (!file) {
774
fprintf(stderr, "Failed to find i915_error_state beneath %s\n",
775
path);
776
exit(EXIT_FAILURE);
777
}
778
} else {
779
file = fopen(path, "r");
780
if (!file) {
781
fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
782
exit(EXIT_FAILURE);
783
}
784
}
785
786
return file;
787
}
788
789
int
790
main(int argc, char *argv[])
791
{
792
FILE *file;
793
int c, i;
794
bool help = false, pager = true;
795
const struct option aubinator_opts[] = {
796
{ "help", no_argument, (int *) &help, true },
797
{ "no-pager", no_argument, (int *) &pager, false },
798
{ "no-offsets", no_argument, (int *) &option_print_offsets, false },
799
{ "headers", no_argument, (int *) &option_full_decode, false },
800
{ "color", optional_argument, NULL, 'c' },
801
{ "xml", required_argument, NULL, 'x' },
802
{ "all-bb", no_argument, (int *) &option_print_all_bb, true },
803
{ NULL, 0, NULL, 0 }
804
};
805
806
i = 0;
807
while ((c = getopt_long(argc, argv, "", aubinator_opts, &i)) != -1) {
808
switch (c) {
809
case 'c':
810
if (optarg == NULL || strcmp(optarg, "always") == 0)
811
option_color = COLOR_ALWAYS;
812
else if (strcmp(optarg, "never") == 0)
813
option_color = COLOR_NEVER;
814
else if (strcmp(optarg, "auto") == 0)
815
option_color = COLOR_AUTO;
816
else {
817
fprintf(stderr, "invalid value for --color: %s", optarg);
818
exit(EXIT_FAILURE);
819
}
820
break;
821
case 'x':
822
xml_path = strdup(optarg);
823
break;
824
case '?':
825
print_help(argv[0], stderr);
826
exit(EXIT_FAILURE);
827
default:
828
break;
829
}
830
}
831
832
if (help) {
833
print_help(argv[0], stderr);
834
exit(EXIT_SUCCESS);
835
}
836
837
if (optind >= argc) {
838
if (isatty(0)) {
839
file = open_error_state_file("/sys/class/drm/card0/error");
840
if (!file)
841
file = open_error_state_file("/debug/dri");
842
if (!file)
843
file = open_error_state_file("/sys/kernel/debug/dri");
844
845
if (file == NULL) {
846
errx(1,
847
"Couldn't find i915 debugfs directory.\n\n"
848
"Is debugfs mounted? You might try mounting it with a command such as:\n\n"
849
"\tsudo mount -t debugfs debugfs /sys/kernel/debug\n");
850
}
851
} else {
852
file = stdin;
853
}
854
} else {
855
const char *path = argv[optind];
856
if (strcmp(path, "-") == 0) {
857
file = stdin;
858
} else {
859
file = open_error_state_file(path);
860
if (file == NULL) {
861
fprintf(stderr, "Error opening %s: %s\n", path, strerror(errno));
862
exit(EXIT_FAILURE);
863
}
864
}
865
}
866
867
if (option_color == COLOR_AUTO)
868
option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER;
869
870
if (isatty(1) && pager)
871
setup_pager();
872
873
read_data_file(file);
874
fclose(file);
875
876
/* close the stdout which is opened to write the output */
877
fflush(stdout);
878
close(1);
879
wait(NULL);
880
881
if (xml_path)
882
free(xml_path);
883
884
return EXIT_SUCCESS;
885
}
886
887
/* vim: set ts=8 sw=8 tw=0 cino=:0,(0 noet :*/
888
889