radeonsi/gfx10: use the correct register for image descriptor dumping
[mesa.git] / src / gallium / drivers / radeonsi / si_debug.c
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "si_pipe.h"
26 #include "si_compute.h"
27 #include "sid.h"
28 #include "sid_tables.h"
29 #include "driver_ddebug/dd_util.h"
30 #include "util/u_dump.h"
31 #include "util/u_log.h"
32 #include "util/u_memory.h"
33 #include "util/u_string.h"
34 #include "ac_debug.h"
35 #include "ac_rtld.h"
36
37 static void si_dump_bo_list(struct si_context *sctx,
38 const struct radeon_saved_cs *saved, FILE *f);
39
40 DEBUG_GET_ONCE_OPTION(replace_shaders, "RADEON_REPLACE_SHADERS", NULL)
41
42 /**
43 * Store a linearized copy of all chunks of \p cs together with the buffer
44 * list in \p saved.
45 */
46 void si_save_cs(struct radeon_winsys *ws, struct radeon_cmdbuf *cs,
47 struct radeon_saved_cs *saved, bool get_buffer_list)
48 {
49 uint32_t *buf;
50 unsigned i;
51
52 /* Save the IB chunks. */
53 saved->num_dw = cs->prev_dw + cs->current.cdw;
54 saved->ib = MALLOC(4 * saved->num_dw);
55 if (!saved->ib)
56 goto oom;
57
58 buf = saved->ib;
59 for (i = 0; i < cs->num_prev; ++i) {
60 memcpy(buf, cs->prev[i].buf, cs->prev[i].cdw * 4);
61 buf += cs->prev[i].cdw;
62 }
63 memcpy(buf, cs->current.buf, cs->current.cdw * 4);
64
65 if (!get_buffer_list)
66 return;
67
68 /* Save the buffer list. */
69 saved->bo_count = ws->cs_get_buffer_list(cs, NULL);
70 saved->bo_list = CALLOC(saved->bo_count,
71 sizeof(saved->bo_list[0]));
72 if (!saved->bo_list) {
73 FREE(saved->ib);
74 goto oom;
75 }
76 ws->cs_get_buffer_list(cs, saved->bo_list);
77
78 return;
79
80 oom:
81 fprintf(stderr, "%s: out of memory\n", __func__);
82 memset(saved, 0, sizeof(*saved));
83 }
84
85 void si_clear_saved_cs(struct radeon_saved_cs *saved)
86 {
87 FREE(saved->ib);
88 FREE(saved->bo_list);
89
90 memset(saved, 0, sizeof(*saved));
91 }
92
93 void si_destroy_saved_cs(struct si_saved_cs *scs)
94 {
95 si_clear_saved_cs(&scs->gfx);
96 si_resource_reference(&scs->trace_buf, NULL);
97 free(scs);
98 }
99
100 static void si_dump_shader(struct si_screen *sscreen,
101 enum pipe_shader_type processor,
102 struct si_shader *shader, FILE *f)
103 {
104 if (shader->shader_log)
105 fwrite(shader->shader_log, shader->shader_log_size, 1, f);
106 else
107 si_shader_dump(sscreen, shader, NULL, processor, f, false);
108
109 if (shader->bo && sscreen->options.dump_shader_binary) {
110 unsigned size = shader->bo->b.b.width0;
111 fprintf(f, "BO: VA=%"PRIx64" Size=%u\n", shader->bo->gpu_address, size);
112
113 const char *mapped = sscreen->ws->buffer_map(shader->bo->buf, NULL,
114 PIPE_TRANSFER_UNSYNCHRONIZED |
115 PIPE_TRANSFER_READ |
116 RADEON_TRANSFER_TEMPORARY);
117
118 for (unsigned i = 0; i < size; i += 4) {
119 fprintf(f, " %4x: %08x\n", i, *(uint32_t*)(mapped + i));
120 }
121
122 sscreen->ws->buffer_unmap(shader->bo->buf);
123
124 fprintf(f, "\n");
125 }
126 }
127
128 struct si_log_chunk_shader {
129 /* The shader destroy code assumes a current context for unlinking of
130 * PM4 packets etc.
131 *
132 * While we should be able to destroy shaders without a context, doing
133 * so would happen only very rarely and be therefore likely to fail
134 * just when you're trying to debug something. Let's just remember the
135 * current context in the chunk.
136 */
137 struct si_context *ctx;
138 struct si_shader *shader;
139 enum pipe_shader_type processor;
140
141 /* For keep-alive reference counts */
142 struct si_shader_selector *sel;
143 struct si_compute *program;
144 };
145
146 static void
147 si_log_chunk_shader_destroy(void *data)
148 {
149 struct si_log_chunk_shader *chunk = data;
150 si_shader_selector_reference(chunk->ctx, &chunk->sel, NULL);
151 si_compute_reference(&chunk->program, NULL);
152 FREE(chunk);
153 }
154
155 static void
156 si_log_chunk_shader_print(void *data, FILE *f)
157 {
158 struct si_log_chunk_shader *chunk = data;
159 struct si_screen *sscreen = chunk->ctx->screen;
160 si_dump_shader(sscreen, chunk->processor,
161 chunk->shader, f);
162 }
163
164 static struct u_log_chunk_type si_log_chunk_type_shader = {
165 .destroy = si_log_chunk_shader_destroy,
166 .print = si_log_chunk_shader_print,
167 };
168
169 static void si_dump_gfx_shader(struct si_context *ctx,
170 const struct si_shader_ctx_state *state,
171 struct u_log_context *log)
172 {
173 struct si_shader *current = state->current;
174
175 if (!state->cso || !current)
176 return;
177
178 struct si_log_chunk_shader *chunk = CALLOC_STRUCT(si_log_chunk_shader);
179 chunk->ctx = ctx;
180 chunk->processor = state->cso->info.processor;
181 chunk->shader = current;
182 si_shader_selector_reference(ctx, &chunk->sel, current->selector);
183 u_log_chunk(log, &si_log_chunk_type_shader, chunk);
184 }
185
186 static void si_dump_compute_shader(struct si_context *ctx,
187 struct u_log_context *log)
188 {
189 const struct si_cs_shader_state *state = &ctx->cs_shader_state;
190
191 if (!state->program)
192 return;
193
194 struct si_log_chunk_shader *chunk = CALLOC_STRUCT(si_log_chunk_shader);
195 chunk->ctx = ctx;
196 chunk->processor = PIPE_SHADER_COMPUTE;
197 chunk->shader = &state->program->shader;
198 si_compute_reference(&chunk->program, state->program);
199 u_log_chunk(log, &si_log_chunk_type_shader, chunk);
200 }
201
202 /**
203 * Shader compiles can be overridden with arbitrary ELF objects by setting
204 * the environment variable RADEON_REPLACE_SHADERS=num1:filename1[;num2:filename2]
205 *
206 * TODO: key this off some hash
207 */
208 bool si_replace_shader(unsigned num, struct si_shader_binary *binary)
209 {
210 const char *p = debug_get_option_replace_shaders();
211 const char *semicolon;
212 char *copy = NULL;
213 FILE *f;
214 long filesize, nread;
215 bool replaced = false;
216
217 if (!p)
218 return false;
219
220 while (*p) {
221 unsigned long i;
222 char *endp;
223 i = strtoul(p, &endp, 0);
224
225 p = endp;
226 if (*p != ':') {
227 fprintf(stderr, "RADEON_REPLACE_SHADERS formatted badly.\n");
228 exit(1);
229 }
230 ++p;
231
232 if (i == num)
233 break;
234
235 p = strchr(p, ';');
236 if (!p)
237 return false;
238 ++p;
239 }
240 if (!*p)
241 return false;
242
243 semicolon = strchr(p, ';');
244 if (semicolon) {
245 p = copy = strndup(p, semicolon - p);
246 if (!copy) {
247 fprintf(stderr, "out of memory\n");
248 return false;
249 }
250 }
251
252 fprintf(stderr, "radeonsi: replace shader %u by %s\n", num, p);
253
254 f = fopen(p, "r");
255 if (!f) {
256 perror("radeonsi: failed to open file");
257 goto out_free;
258 }
259
260 if (fseek(f, 0, SEEK_END) != 0)
261 goto file_error;
262
263 filesize = ftell(f);
264 if (filesize < 0)
265 goto file_error;
266
267 if (fseek(f, 0, SEEK_SET) != 0)
268 goto file_error;
269
270 binary->elf_buffer = MALLOC(filesize);
271 if (!binary->elf_buffer) {
272 fprintf(stderr, "out of memory\n");
273 goto out_close;
274 }
275
276 nread = fread((void*)binary->elf_buffer, 1, filesize, f);
277 if (nread != filesize) {
278 FREE((void*)binary->elf_buffer);
279 binary->elf_buffer = NULL;
280 goto file_error;
281 }
282
283 binary->elf_size = nread;
284 replaced = true;
285
286 out_close:
287 fclose(f);
288 out_free:
289 free(copy);
290 return replaced;
291
292 file_error:
293 perror("radeonsi: reading shader");
294 goto out_close;
295 }
296
297 /* Parsed IBs are difficult to read without colors. Use "less -R file" to
298 * read them, or use "aha -b -f file" to convert them to html.
299 */
300 #define COLOR_RESET "\033[0m"
301 #define COLOR_RED "\033[31m"
302 #define COLOR_GREEN "\033[1;32m"
303 #define COLOR_YELLOW "\033[1;33m"
304 #define COLOR_CYAN "\033[1;36m"
305
306 static void si_dump_mmapped_reg(struct si_context *sctx, FILE *f,
307 unsigned offset)
308 {
309 struct radeon_winsys *ws = sctx->ws;
310 uint32_t value;
311
312 if (ws->read_registers(ws, offset, 1, &value))
313 ac_dump_reg(f, sctx->chip_class, offset, value, ~0);
314 }
315
316 static void si_dump_debug_registers(struct si_context *sctx, FILE *f)
317 {
318 if (!sctx->screen->info.has_read_registers_query)
319 return;
320
321 fprintf(f, "Memory-mapped registers:\n");
322 si_dump_mmapped_reg(sctx, f, R_008010_GRBM_STATUS);
323
324 /* No other registers can be read on DRM < 3.1.0. */
325 if (!sctx->screen->info.is_amdgpu ||
326 sctx->screen->info.drm_minor < 1) {
327 fprintf(f, "\n");
328 return;
329 }
330
331 si_dump_mmapped_reg(sctx, f, R_008008_GRBM_STATUS2);
332 si_dump_mmapped_reg(sctx, f, R_008014_GRBM_STATUS_SE0);
333 si_dump_mmapped_reg(sctx, f, R_008018_GRBM_STATUS_SE1);
334 si_dump_mmapped_reg(sctx, f, R_008038_GRBM_STATUS_SE2);
335 si_dump_mmapped_reg(sctx, f, R_00803C_GRBM_STATUS_SE3);
336 si_dump_mmapped_reg(sctx, f, R_00D034_SDMA0_STATUS_REG);
337 si_dump_mmapped_reg(sctx, f, R_00D834_SDMA1_STATUS_REG);
338 if (sctx->chip_class <= GFX8) {
339 si_dump_mmapped_reg(sctx, f, R_000E50_SRBM_STATUS);
340 si_dump_mmapped_reg(sctx, f, R_000E4C_SRBM_STATUS2);
341 si_dump_mmapped_reg(sctx, f, R_000E54_SRBM_STATUS3);
342 }
343 si_dump_mmapped_reg(sctx, f, R_008680_CP_STAT);
344 si_dump_mmapped_reg(sctx, f, R_008674_CP_STALLED_STAT1);
345 si_dump_mmapped_reg(sctx, f, R_008678_CP_STALLED_STAT2);
346 si_dump_mmapped_reg(sctx, f, R_008670_CP_STALLED_STAT3);
347 si_dump_mmapped_reg(sctx, f, R_008210_CP_CPC_STATUS);
348 si_dump_mmapped_reg(sctx, f, R_008214_CP_CPC_BUSY_STAT);
349 si_dump_mmapped_reg(sctx, f, R_008218_CP_CPC_STALLED_STAT1);
350 si_dump_mmapped_reg(sctx, f, R_00821C_CP_CPF_STATUS);
351 si_dump_mmapped_reg(sctx, f, R_008220_CP_CPF_BUSY_STAT);
352 si_dump_mmapped_reg(sctx, f, R_008224_CP_CPF_STALLED_STAT1);
353 fprintf(f, "\n");
354 }
355
356 struct si_log_chunk_cs {
357 struct si_context *ctx;
358 struct si_saved_cs *cs;
359 bool dump_bo_list;
360 unsigned gfx_begin, gfx_end;
361 unsigned compute_begin, compute_end;
362 };
363
364 static void si_log_chunk_type_cs_destroy(void *data)
365 {
366 struct si_log_chunk_cs *chunk = data;
367 si_saved_cs_reference(&chunk->cs, NULL);
368 free(chunk);
369 }
370
371 static void si_parse_current_ib(FILE *f, struct radeon_cmdbuf *cs,
372 unsigned begin, unsigned end,
373 int *last_trace_id, unsigned trace_id_count,
374 const char *name, enum chip_class chip_class)
375 {
376 unsigned orig_end = end;
377
378 assert(begin <= end);
379
380 fprintf(f, "------------------ %s begin (dw = %u) ------------------\n",
381 name, begin);
382
383 for (unsigned prev_idx = 0; prev_idx < cs->num_prev; ++prev_idx) {
384 struct radeon_cmdbuf_chunk *chunk = &cs->prev[prev_idx];
385
386 if (begin < chunk->cdw) {
387 ac_parse_ib_chunk(f, chunk->buf + begin,
388 MIN2(end, chunk->cdw) - begin,
389 last_trace_id, trace_id_count,
390 chip_class, NULL, NULL);
391 }
392
393 if (end <= chunk->cdw)
394 return;
395
396 if (begin < chunk->cdw)
397 fprintf(f, "\n---------- Next %s Chunk ----------\n\n",
398 name);
399
400 begin -= MIN2(begin, chunk->cdw);
401 end -= chunk->cdw;
402 }
403
404 assert(end <= cs->current.cdw);
405
406 ac_parse_ib_chunk(f, cs->current.buf + begin, end - begin, last_trace_id,
407 trace_id_count, chip_class, NULL, NULL);
408
409 fprintf(f, "------------------- %s end (dw = %u) -------------------\n\n",
410 name, orig_end);
411 }
412
413 static void si_log_chunk_type_cs_print(void *data, FILE *f)
414 {
415 struct si_log_chunk_cs *chunk = data;
416 struct si_context *ctx = chunk->ctx;
417 struct si_saved_cs *scs = chunk->cs;
418 int last_trace_id = -1;
419 int last_compute_trace_id = -1;
420
421 /* We are expecting that the ddebug pipe has already
422 * waited for the context, so this buffer should be idle.
423 * If the GPU is hung, there is no point in waiting for it.
424 */
425 uint32_t *map = ctx->ws->buffer_map(scs->trace_buf->buf,
426 NULL,
427 PIPE_TRANSFER_UNSYNCHRONIZED |
428 PIPE_TRANSFER_READ);
429 if (map) {
430 last_trace_id = map[0];
431 last_compute_trace_id = map[1];
432 }
433
434 if (chunk->gfx_end != chunk->gfx_begin) {
435 if (chunk->gfx_begin == 0) {
436 if (ctx->init_config)
437 ac_parse_ib(f, ctx->init_config->pm4, ctx->init_config->ndw,
438 NULL, 0, "IB2: Init config", ctx->chip_class,
439 NULL, NULL);
440
441 if (ctx->init_config_gs_rings)
442 ac_parse_ib(f, ctx->init_config_gs_rings->pm4,
443 ctx->init_config_gs_rings->ndw,
444 NULL, 0, "IB2: Init GS rings", ctx->chip_class,
445 NULL, NULL);
446 }
447
448 if (scs->flushed) {
449 ac_parse_ib(f, scs->gfx.ib + chunk->gfx_begin,
450 chunk->gfx_end - chunk->gfx_begin,
451 &last_trace_id, map ? 1 : 0, "IB", ctx->chip_class,
452 NULL, NULL);
453 } else {
454 si_parse_current_ib(f, ctx->gfx_cs, chunk->gfx_begin,
455 chunk->gfx_end, &last_trace_id, map ? 1 : 0,
456 "IB", ctx->chip_class);
457 }
458 }
459
460 if (chunk->compute_end != chunk->compute_begin) {
461 assert(ctx->prim_discard_compute_cs);
462
463 if (scs->flushed) {
464 ac_parse_ib(f, scs->compute.ib + chunk->compute_begin,
465 chunk->compute_end - chunk->compute_begin,
466 &last_compute_trace_id, map ? 1 : 0, "Compute IB", ctx->chip_class,
467 NULL, NULL);
468 } else {
469 si_parse_current_ib(f, ctx->prim_discard_compute_cs, chunk->compute_begin,
470 chunk->compute_end, &last_compute_trace_id,
471 map ? 1 : 0, "Compute IB", ctx->chip_class);
472 }
473 }
474
475 if (chunk->dump_bo_list) {
476 fprintf(f, "Flushing. Time: ");
477 util_dump_ns(f, scs->time_flush);
478 fprintf(f, "\n\n");
479 si_dump_bo_list(ctx, &scs->gfx, f);
480 }
481 }
482
483 static const struct u_log_chunk_type si_log_chunk_type_cs = {
484 .destroy = si_log_chunk_type_cs_destroy,
485 .print = si_log_chunk_type_cs_print,
486 };
487
488 static void si_log_cs(struct si_context *ctx, struct u_log_context *log,
489 bool dump_bo_list)
490 {
491 assert(ctx->current_saved_cs);
492
493 struct si_saved_cs *scs = ctx->current_saved_cs;
494 unsigned gfx_cur = ctx->gfx_cs->prev_dw + ctx->gfx_cs->current.cdw;
495 unsigned compute_cur = 0;
496
497 if (ctx->prim_discard_compute_cs)
498 compute_cur = ctx->prim_discard_compute_cs->prev_dw + ctx->prim_discard_compute_cs->current.cdw;
499
500 if (!dump_bo_list &&
501 gfx_cur == scs->gfx_last_dw &&
502 compute_cur == scs->compute_last_dw)
503 return;
504
505 struct si_log_chunk_cs *chunk = calloc(1, sizeof(*chunk));
506
507 chunk->ctx = ctx;
508 si_saved_cs_reference(&chunk->cs, scs);
509 chunk->dump_bo_list = dump_bo_list;
510
511 chunk->gfx_begin = scs->gfx_last_dw;
512 chunk->gfx_end = gfx_cur;
513 scs->gfx_last_dw = gfx_cur;
514
515 chunk->compute_begin = scs->compute_last_dw;
516 chunk->compute_end = compute_cur;
517 scs->compute_last_dw = compute_cur;
518
519 u_log_chunk(log, &si_log_chunk_type_cs, chunk);
520 }
521
522 void si_auto_log_cs(void *data, struct u_log_context *log)
523 {
524 struct si_context *ctx = (struct si_context *)data;
525 si_log_cs(ctx, log, false);
526 }
527
528 void si_log_hw_flush(struct si_context *sctx)
529 {
530 if (!sctx->log)
531 return;
532
533 si_log_cs(sctx, sctx->log, true);
534
535 if (&sctx->b == sctx->screen->aux_context) {
536 /* The aux context isn't captured by the ddebug wrapper,
537 * so we dump it on a flush-by-flush basis here.
538 */
539 FILE *f = dd_get_debug_file(false);
540 if (!f) {
541 fprintf(stderr, "radeonsi: error opening aux context dump file.\n");
542 } else {
543 dd_write_header(f, &sctx->screen->b, 0);
544
545 fprintf(f, "Aux context dump:\n\n");
546 u_log_new_page_print(sctx->log, f);
547
548 fclose(f);
549 }
550 }
551 }
552
553 static const char *priority_to_string(enum radeon_bo_priority priority)
554 {
555 #define ITEM(x) [RADEON_PRIO_##x] = #x
556 static const char *table[64] = {
557 ITEM(FENCE),
558 ITEM(TRACE),
559 ITEM(SO_FILLED_SIZE),
560 ITEM(QUERY),
561 ITEM(IB1),
562 ITEM(IB2),
563 ITEM(DRAW_INDIRECT),
564 ITEM(INDEX_BUFFER),
565 ITEM(CP_DMA),
566 ITEM(CONST_BUFFER),
567 ITEM(DESCRIPTORS),
568 ITEM(BORDER_COLORS),
569 ITEM(SAMPLER_BUFFER),
570 ITEM(VERTEX_BUFFER),
571 ITEM(SHADER_RW_BUFFER),
572 ITEM(COMPUTE_GLOBAL),
573 ITEM(SAMPLER_TEXTURE),
574 ITEM(SHADER_RW_IMAGE),
575 ITEM(SAMPLER_TEXTURE_MSAA),
576 ITEM(COLOR_BUFFER),
577 ITEM(DEPTH_BUFFER),
578 ITEM(COLOR_BUFFER_MSAA),
579 ITEM(DEPTH_BUFFER_MSAA),
580 ITEM(SEPARATE_META),
581 ITEM(SHADER_BINARY),
582 ITEM(SHADER_RINGS),
583 ITEM(SCRATCH_BUFFER),
584 };
585 #undef ITEM
586
587 assert(priority < ARRAY_SIZE(table));
588 return table[priority];
589 }
590
591 static int bo_list_compare_va(const struct radeon_bo_list_item *a,
592 const struct radeon_bo_list_item *b)
593 {
594 return a->vm_address < b->vm_address ? -1 :
595 a->vm_address > b->vm_address ? 1 : 0;
596 }
597
598 static void si_dump_bo_list(struct si_context *sctx,
599 const struct radeon_saved_cs *saved, FILE *f)
600 {
601 unsigned i,j;
602
603 if (!saved->bo_list)
604 return;
605
606 /* Sort the list according to VM adddresses first. */
607 qsort(saved->bo_list, saved->bo_count,
608 sizeof(saved->bo_list[0]), (void*)bo_list_compare_va);
609
610 fprintf(f, "Buffer list (in units of pages = 4kB):\n"
611 COLOR_YELLOW " Size VM start page "
612 "VM end page Usage" COLOR_RESET "\n");
613
614 for (i = 0; i < saved->bo_count; i++) {
615 /* Note: Buffer sizes are expected to be aligned to 4k by the winsys. */
616 const unsigned page_size = sctx->screen->info.gart_page_size;
617 uint64_t va = saved->bo_list[i].vm_address;
618 uint64_t size = saved->bo_list[i].bo_size;
619 bool hit = false;
620
621 /* If there's unused virtual memory between 2 buffers, print it. */
622 if (i) {
623 uint64_t previous_va_end = saved->bo_list[i-1].vm_address +
624 saved->bo_list[i-1].bo_size;
625
626 if (va > previous_va_end) {
627 fprintf(f, " %10"PRIu64" -- hole --\n",
628 (va - previous_va_end) / page_size);
629 }
630 }
631
632 /* Print the buffer. */
633 fprintf(f, " %10"PRIu64" 0x%013"PRIX64" 0x%013"PRIX64" ",
634 size / page_size, va / page_size, (va + size) / page_size);
635
636 /* Print the usage. */
637 for (j = 0; j < 32; j++) {
638 if (!(saved->bo_list[i].priority_usage & (1u << j)))
639 continue;
640
641 fprintf(f, "%s%s", !hit ? "" : ", ", priority_to_string(j));
642 hit = true;
643 }
644 fprintf(f, "\n");
645 }
646 fprintf(f, "\nNote: The holes represent memory not used by the IB.\n"
647 " Other buffers can still be allocated there.\n\n");
648 }
649
650 static void si_dump_framebuffer(struct si_context *sctx, struct u_log_context *log)
651 {
652 struct pipe_framebuffer_state *state = &sctx->framebuffer.state;
653 struct si_texture *tex;
654 int i;
655
656 for (i = 0; i < state->nr_cbufs; i++) {
657 if (!state->cbufs[i])
658 continue;
659
660 tex = (struct si_texture*)state->cbufs[i]->texture;
661 u_log_printf(log, COLOR_YELLOW "Color buffer %i:" COLOR_RESET "\n", i);
662 si_print_texture_info(sctx->screen, tex, log);
663 u_log_printf(log, "\n");
664 }
665
666 if (state->zsbuf) {
667 tex = (struct si_texture*)state->zsbuf->texture;
668 u_log_printf(log, COLOR_YELLOW "Depth-stencil buffer:" COLOR_RESET "\n");
669 si_print_texture_info(sctx->screen, tex, log);
670 u_log_printf(log, "\n");
671 }
672 }
673
674 typedef unsigned (*slot_remap_func)(unsigned);
675
676 struct si_log_chunk_desc_list {
677 /** Pointer to memory map of buffer where the list is uploader */
678 uint32_t *gpu_list;
679 /** Reference of buffer where the list is uploaded, so that gpu_list
680 * is kept live. */
681 struct si_resource *buf;
682
683 const char *shader_name;
684 const char *elem_name;
685 slot_remap_func slot_remap;
686 enum chip_class chip_class;
687 unsigned element_dw_size;
688 unsigned num_elements;
689
690 uint32_t list[0];
691 };
692
693 static void
694 si_log_chunk_desc_list_destroy(void *data)
695 {
696 struct si_log_chunk_desc_list *chunk = data;
697 si_resource_reference(&chunk->buf, NULL);
698 FREE(chunk);
699 }
700
701 static void
702 si_log_chunk_desc_list_print(void *data, FILE *f)
703 {
704 struct si_log_chunk_desc_list *chunk = data;
705 unsigned sq_img_rsrc_word0 = chunk->chip_class >= GFX10 ? R_00A000_SQ_IMG_RSRC_WORD0
706 : R_008F10_SQ_IMG_RSRC_WORD0;
707
708 for (unsigned i = 0; i < chunk->num_elements; i++) {
709 unsigned cpu_dw_offset = i * chunk->element_dw_size;
710 unsigned gpu_dw_offset = chunk->slot_remap(i) * chunk->element_dw_size;
711 const char *list_note = chunk->gpu_list ? "GPU list" : "CPU list";
712 uint32_t *cpu_list = chunk->list + cpu_dw_offset;
713 uint32_t *gpu_list = chunk->gpu_list ? chunk->gpu_list + gpu_dw_offset : cpu_list;
714
715 fprintf(f, COLOR_GREEN "%s%s slot %u (%s):" COLOR_RESET "\n",
716 chunk->shader_name, chunk->elem_name, i, list_note);
717
718 switch (chunk->element_dw_size) {
719 case 4:
720 for (unsigned j = 0; j < 4; j++)
721 ac_dump_reg(f, chunk->chip_class,
722 R_008F00_SQ_BUF_RSRC_WORD0 + j*4,
723 gpu_list[j], 0xffffffff);
724 break;
725 case 8:
726 for (unsigned j = 0; j < 8; j++)
727 ac_dump_reg(f, chunk->chip_class,
728 sq_img_rsrc_word0 + j*4,
729 gpu_list[j], 0xffffffff);
730
731 fprintf(f, COLOR_CYAN " Buffer:" COLOR_RESET "\n");
732 for (unsigned j = 0; j < 4; j++)
733 ac_dump_reg(f, chunk->chip_class,
734 R_008F00_SQ_BUF_RSRC_WORD0 + j*4,
735 gpu_list[4+j], 0xffffffff);
736 break;
737 case 16:
738 for (unsigned j = 0; j < 8; j++)
739 ac_dump_reg(f, chunk->chip_class,
740 sq_img_rsrc_word0 + j*4,
741 gpu_list[j], 0xffffffff);
742
743 fprintf(f, COLOR_CYAN " Buffer:" COLOR_RESET "\n");
744 for (unsigned j = 0; j < 4; j++)
745 ac_dump_reg(f, chunk->chip_class,
746 R_008F00_SQ_BUF_RSRC_WORD0 + j*4,
747 gpu_list[4+j], 0xffffffff);
748
749 fprintf(f, COLOR_CYAN " FMASK:" COLOR_RESET "\n");
750 for (unsigned j = 0; j < 8; j++)
751 ac_dump_reg(f, chunk->chip_class,
752 sq_img_rsrc_word0 + j*4,
753 gpu_list[8+j], 0xffffffff);
754
755 fprintf(f, COLOR_CYAN " Sampler state:" COLOR_RESET "\n");
756 for (unsigned j = 0; j < 4; j++)
757 ac_dump_reg(f, chunk->chip_class,
758 R_008F30_SQ_IMG_SAMP_WORD0 + j*4,
759 gpu_list[12+j], 0xffffffff);
760 break;
761 }
762
763 if (memcmp(gpu_list, cpu_list, chunk->element_dw_size * 4) != 0) {
764 fprintf(f, COLOR_RED "!!!!! This slot was corrupted in GPU memory !!!!!"
765 COLOR_RESET "\n");
766 }
767
768 fprintf(f, "\n");
769 }
770
771 }
772
773 static const struct u_log_chunk_type si_log_chunk_type_descriptor_list = {
774 .destroy = si_log_chunk_desc_list_destroy,
775 .print = si_log_chunk_desc_list_print,
776 };
777
778 static void si_dump_descriptor_list(struct si_screen *screen,
779 struct si_descriptors *desc,
780 const char *shader_name,
781 const char *elem_name,
782 unsigned element_dw_size,
783 unsigned num_elements,
784 slot_remap_func slot_remap,
785 struct u_log_context *log)
786 {
787 if (!desc->list)
788 return;
789
790 /* In some cases, the caller doesn't know how many elements are really
791 * uploaded. Reduce num_elements to fit in the range of active slots. */
792 unsigned active_range_dw_begin =
793 desc->first_active_slot * desc->element_dw_size;
794 unsigned active_range_dw_end =
795 active_range_dw_begin + desc->num_active_slots * desc->element_dw_size;
796
797 while (num_elements > 0) {
798 int i = slot_remap(num_elements - 1);
799 unsigned dw_begin = i * element_dw_size;
800 unsigned dw_end = dw_begin + element_dw_size;
801
802 if (dw_begin >= active_range_dw_begin && dw_end <= active_range_dw_end)
803 break;
804
805 num_elements--;
806 }
807
808 struct si_log_chunk_desc_list *chunk =
809 CALLOC_VARIANT_LENGTH_STRUCT(si_log_chunk_desc_list,
810 4 * element_dw_size * num_elements);
811 chunk->shader_name = shader_name;
812 chunk->elem_name = elem_name;
813 chunk->element_dw_size = element_dw_size;
814 chunk->num_elements = num_elements;
815 chunk->slot_remap = slot_remap;
816 chunk->chip_class = screen->info.chip_class;
817
818 si_resource_reference(&chunk->buf, desc->buffer);
819 chunk->gpu_list = desc->gpu_list;
820
821 for (unsigned i = 0; i < num_elements; ++i) {
822 memcpy(&chunk->list[i * element_dw_size],
823 &desc->list[slot_remap(i) * element_dw_size],
824 4 * element_dw_size);
825 }
826
827 u_log_chunk(log, &si_log_chunk_type_descriptor_list, chunk);
828 }
829
830 static unsigned si_identity(unsigned slot)
831 {
832 return slot;
833 }
834
835 static void si_dump_descriptors(struct si_context *sctx,
836 enum pipe_shader_type processor,
837 const struct tgsi_shader_info *info,
838 struct u_log_context *log)
839 {
840 struct si_descriptors *descs =
841 &sctx->descriptors[SI_DESCS_FIRST_SHADER +
842 processor * SI_NUM_SHADER_DESCS];
843 static const char *shader_name[] = {"VS", "PS", "GS", "TCS", "TES", "CS"};
844 const char *name = shader_name[processor];
845 unsigned enabled_constbuf, enabled_shaderbuf, enabled_samplers;
846 unsigned enabled_images;
847
848 if (info) {
849 enabled_constbuf = info->const_buffers_declared;
850 enabled_shaderbuf = info->shader_buffers_declared;
851 enabled_samplers = info->samplers_declared;
852 enabled_images = info->images_declared;
853 } else {
854 enabled_constbuf = sctx->const_and_shader_buffers[processor].enabled_mask >>
855 SI_NUM_SHADER_BUFFERS;
856 enabled_shaderbuf = sctx->const_and_shader_buffers[processor].enabled_mask &
857 u_bit_consecutive(0, SI_NUM_SHADER_BUFFERS);
858 enabled_shaderbuf = util_bitreverse(enabled_shaderbuf) >>
859 (32 - SI_NUM_SHADER_BUFFERS);
860 enabled_samplers = sctx->samplers[processor].enabled_mask;
861 enabled_images = sctx->images[processor].enabled_mask;
862 }
863
864 if (processor == PIPE_SHADER_VERTEX &&
865 sctx->vb_descriptors_buffer &&
866 sctx->vb_descriptors_gpu_list &&
867 sctx->vertex_elements) {
868 assert(info); /* only CS may not have an info struct */
869 struct si_descriptors desc = {};
870
871 desc.buffer = sctx->vb_descriptors_buffer;
872 desc.list = sctx->vb_descriptors_gpu_list;
873 desc.gpu_list = sctx->vb_descriptors_gpu_list;
874 desc.element_dw_size = 4;
875 desc.num_active_slots = sctx->vertex_elements->desc_list_byte_size / 16;
876
877 si_dump_descriptor_list(sctx->screen, &desc, name,
878 " - Vertex buffer", 4, info->num_inputs,
879 si_identity, log);
880 }
881
882 si_dump_descriptor_list(sctx->screen,
883 &descs[SI_SHADER_DESCS_CONST_AND_SHADER_BUFFERS],
884 name, " - Constant buffer", 4,
885 util_last_bit(enabled_constbuf),
886 si_get_constbuf_slot, log);
887 si_dump_descriptor_list(sctx->screen,
888 &descs[SI_SHADER_DESCS_CONST_AND_SHADER_BUFFERS],
889 name, " - Shader buffer", 4,
890 util_last_bit(enabled_shaderbuf),
891 si_get_shaderbuf_slot, log);
892 si_dump_descriptor_list(sctx->screen,
893 &descs[SI_SHADER_DESCS_SAMPLERS_AND_IMAGES],
894 name, " - Sampler", 16,
895 util_last_bit(enabled_samplers),
896 si_get_sampler_slot, log);
897 si_dump_descriptor_list(sctx->screen,
898 &descs[SI_SHADER_DESCS_SAMPLERS_AND_IMAGES],
899 name, " - Image", 8,
900 util_last_bit(enabled_images),
901 si_get_image_slot, log);
902 }
903
904 static void si_dump_gfx_descriptors(struct si_context *sctx,
905 const struct si_shader_ctx_state *state,
906 struct u_log_context *log)
907 {
908 if (!state->cso || !state->current)
909 return;
910
911 si_dump_descriptors(sctx, state->cso->type, &state->cso->info, log);
912 }
913
914 static void si_dump_compute_descriptors(struct si_context *sctx,
915 struct u_log_context *log)
916 {
917 if (!sctx->cs_shader_state.program)
918 return;
919
920 si_dump_descriptors(sctx, PIPE_SHADER_COMPUTE, NULL, log);
921 }
922
923 struct si_shader_inst {
924 const char *text; /* start of disassembly for this instruction */
925 unsigned textlen;
926 unsigned size; /* instruction size = 4 or 8 */
927 uint64_t addr; /* instruction address */
928 };
929
930 /**
931 * Open the given \p binary as \p rtld_binary and split the contained
932 * disassembly string into instructions and add them to the array
933 * pointed to by \p instructions, which must be sufficiently large.
934 *
935 * Labels are considered to be part of the following instruction.
936 *
937 * The caller must keep \p rtld_binary alive as long as \p instructions are
938 * used and then close it afterwards.
939 */
940 static void si_add_split_disasm(struct si_screen *screen,
941 struct ac_rtld_binary *rtld_binary,
942 struct si_shader_binary *binary,
943 uint64_t *addr,
944 unsigned *num,
945 struct si_shader_inst *instructions)
946 {
947 if (!ac_rtld_open(rtld_binary, (struct ac_rtld_open_info){
948 .info = &screen->info,
949 .num_parts = 1,
950 .elf_ptrs = &binary->elf_buffer,
951 .elf_sizes = &binary->elf_size }))
952 return;
953
954 const char *disasm;
955 size_t nbytes;
956 if (!ac_rtld_get_section_by_name(rtld_binary, ".AMDGPU.disasm",
957 &disasm, &nbytes))
958 return;
959
960 const char *end = disasm + nbytes;
961 while (disasm < end) {
962 const char *semicolon = memchr(disasm, ';', end - disasm);
963 if (!semicolon)
964 break;
965
966 struct si_shader_inst *inst = &instructions[(*num)++];
967 const char *inst_end = memchr(semicolon + 1, '\n', end - semicolon - 1);
968 if (!inst_end)
969 inst_end = end;
970
971 inst->text = disasm;
972 inst->textlen = inst_end - disasm;
973
974 inst->addr = *addr;
975 /* More than 16 chars after ";" means the instruction is 8 bytes long. */
976 inst->size = inst_end - semicolon > 16 ? 8 : 4;
977 *addr += inst->size;
978
979 if (inst_end == end)
980 break;
981 disasm = inst_end + 1;
982 }
983 }
984
985 /* If the shader is being executed, print its asm instructions, and annotate
986 * those that are being executed right now with information about waves that
987 * execute them. This is most useful during a GPU hang.
988 */
989 static void si_print_annotated_shader(struct si_shader *shader,
990 struct ac_wave_info *waves,
991 unsigned num_waves,
992 FILE *f)
993 {
994 if (!shader)
995 return;
996
997 struct si_screen *screen = shader->selector->screen;
998 uint64_t start_addr = shader->bo->gpu_address;
999 uint64_t end_addr = start_addr + shader->bo->b.b.width0;
1000 unsigned i;
1001
1002 /* See if any wave executes the shader. */
1003 for (i = 0; i < num_waves; i++) {
1004 if (start_addr <= waves[i].pc && waves[i].pc <= end_addr)
1005 break;
1006 }
1007 if (i == num_waves)
1008 return; /* the shader is not being executed */
1009
1010 /* Remember the first found wave. The waves are sorted according to PC. */
1011 waves = &waves[i];
1012 num_waves -= i;
1013
1014 /* Get the list of instructions.
1015 * Buffer size / 4 is the upper bound of the instruction count.
1016 */
1017 unsigned num_inst = 0;
1018 uint64_t inst_addr = start_addr;
1019 struct ac_rtld_binary rtld_binaries[5] = {};
1020 struct si_shader_inst *instructions =
1021 calloc(shader->bo->b.b.width0 / 4, sizeof(struct si_shader_inst));
1022
1023 if (shader->prolog) {
1024 si_add_split_disasm(screen, &rtld_binaries[0], &shader->prolog->binary,
1025 &inst_addr, &num_inst, instructions);
1026 }
1027 if (shader->previous_stage) {
1028 si_add_split_disasm(screen, &rtld_binaries[1], &shader->previous_stage->binary,
1029 &inst_addr, &num_inst, instructions);
1030 }
1031 if (shader->prolog2) {
1032 si_add_split_disasm(screen, &rtld_binaries[2], &shader->prolog2->binary,
1033 &inst_addr, &num_inst, instructions);
1034 }
1035 si_add_split_disasm(screen, &rtld_binaries[3], &shader->binary,
1036 &inst_addr, &num_inst, instructions);
1037 if (shader->epilog) {
1038 si_add_split_disasm(screen, &rtld_binaries[4], &shader->epilog->binary,
1039 &inst_addr, &num_inst, instructions);
1040 }
1041
1042 fprintf(f, COLOR_YELLOW "%s - annotated disassembly:" COLOR_RESET "\n",
1043 si_get_shader_name(shader, shader->selector->type));
1044
1045 /* Print instructions with annotations. */
1046 for (i = 0; i < num_inst; i++) {
1047 struct si_shader_inst *inst = &instructions[i];
1048
1049 fprintf(f, "%.*s [PC=0x%"PRIx64", size=%u]\n",
1050 inst->textlen, inst->text, inst->addr, inst->size);
1051
1052 /* Print which waves execute the instruction right now. */
1053 while (num_waves && inst->addr == waves->pc) {
1054 fprintf(f,
1055 " " COLOR_GREEN "^ SE%u SH%u CU%u "
1056 "SIMD%u WAVE%u EXEC=%016"PRIx64 " ",
1057 waves->se, waves->sh, waves->cu, waves->simd,
1058 waves->wave, waves->exec);
1059
1060 if (inst->size == 4) {
1061 fprintf(f, "INST32=%08X" COLOR_RESET "\n",
1062 waves->inst_dw0);
1063 } else {
1064 fprintf(f, "INST64=%08X %08X" COLOR_RESET "\n",
1065 waves->inst_dw0, waves->inst_dw1);
1066 }
1067
1068 waves->matched = true;
1069 waves = &waves[1];
1070 num_waves--;
1071 }
1072 }
1073
1074 fprintf(f, "\n\n");
1075 free(instructions);
1076 for (unsigned i = 0; i < ARRAY_SIZE(rtld_binaries); ++i)
1077 ac_rtld_close(&rtld_binaries[i]);
1078 }
1079
1080 static void si_dump_annotated_shaders(struct si_context *sctx, FILE *f)
1081 {
1082 struct ac_wave_info waves[AC_MAX_WAVES_PER_CHIP];
1083 unsigned num_waves = ac_get_wave_info(waves);
1084
1085 fprintf(f, COLOR_CYAN "The number of active waves = %u" COLOR_RESET
1086 "\n\n", num_waves);
1087
1088 si_print_annotated_shader(sctx->vs_shader.current, waves, num_waves, f);
1089 si_print_annotated_shader(sctx->tcs_shader.current, waves, num_waves, f);
1090 si_print_annotated_shader(sctx->tes_shader.current, waves, num_waves, f);
1091 si_print_annotated_shader(sctx->gs_shader.current, waves, num_waves, f);
1092 si_print_annotated_shader(sctx->ps_shader.current, waves, num_waves, f);
1093
1094 /* Print waves executing shaders that are not currently bound. */
1095 unsigned i;
1096 bool found = false;
1097 for (i = 0; i < num_waves; i++) {
1098 if (waves[i].matched)
1099 continue;
1100
1101 if (!found) {
1102 fprintf(f, COLOR_CYAN
1103 "Waves not executing currently-bound shaders:"
1104 COLOR_RESET "\n");
1105 found = true;
1106 }
1107 fprintf(f, " SE%u SH%u CU%u SIMD%u WAVE%u EXEC=%016"PRIx64
1108 " INST=%08X %08X PC=%"PRIx64"\n",
1109 waves[i].se, waves[i].sh, waves[i].cu, waves[i].simd,
1110 waves[i].wave, waves[i].exec, waves[i].inst_dw0,
1111 waves[i].inst_dw1, waves[i].pc);
1112 }
1113 if (found)
1114 fprintf(f, "\n\n");
1115 }
1116
1117 static void si_dump_command(const char *title, const char *command, FILE *f)
1118 {
1119 char line[2000];
1120
1121 FILE *p = popen(command, "r");
1122 if (!p)
1123 return;
1124
1125 fprintf(f, COLOR_YELLOW "%s: " COLOR_RESET "\n", title);
1126 while (fgets(line, sizeof(line), p))
1127 fputs(line, f);
1128 fprintf(f, "\n\n");
1129 pclose(p);
1130 }
1131
1132 static void si_dump_debug_state(struct pipe_context *ctx, FILE *f,
1133 unsigned flags)
1134 {
1135 struct si_context *sctx = (struct si_context*)ctx;
1136
1137 if (sctx->log)
1138 u_log_flush(sctx->log);
1139
1140 if (flags & PIPE_DUMP_DEVICE_STATUS_REGISTERS) {
1141 si_dump_debug_registers(sctx, f);
1142
1143 si_dump_annotated_shaders(sctx, f);
1144 si_dump_command("Active waves (raw data)", "umr -O halt_waves -wa | column -t", f);
1145 si_dump_command("Wave information", "umr -O halt_waves,bits -wa", f);
1146 }
1147 }
1148
1149 void si_log_draw_state(struct si_context *sctx, struct u_log_context *log)
1150 {
1151 struct si_shader_ctx_state *tcs_shader;
1152
1153 if (!log)
1154 return;
1155
1156 tcs_shader = &sctx->tcs_shader;
1157 if (sctx->tes_shader.cso && !sctx->tcs_shader.cso)
1158 tcs_shader = &sctx->fixed_func_tcs_shader;
1159
1160 si_dump_framebuffer(sctx, log);
1161
1162 si_dump_gfx_shader(sctx, &sctx->vs_shader, log);
1163 si_dump_gfx_shader(sctx, tcs_shader, log);
1164 si_dump_gfx_shader(sctx, &sctx->tes_shader, log);
1165 si_dump_gfx_shader(sctx, &sctx->gs_shader, log);
1166 si_dump_gfx_shader(sctx, &sctx->ps_shader, log);
1167
1168 si_dump_descriptor_list(sctx->screen,
1169 &sctx->descriptors[SI_DESCS_RW_BUFFERS],
1170 "", "RW buffers", 4,
1171 sctx->descriptors[SI_DESCS_RW_BUFFERS].num_active_slots,
1172 si_identity, log);
1173 si_dump_gfx_descriptors(sctx, &sctx->vs_shader, log);
1174 si_dump_gfx_descriptors(sctx, tcs_shader, log);
1175 si_dump_gfx_descriptors(sctx, &sctx->tes_shader, log);
1176 si_dump_gfx_descriptors(sctx, &sctx->gs_shader, log);
1177 si_dump_gfx_descriptors(sctx, &sctx->ps_shader, log);
1178 }
1179
1180 void si_log_compute_state(struct si_context *sctx, struct u_log_context *log)
1181 {
1182 if (!log)
1183 return;
1184
1185 si_dump_compute_shader(sctx, log);
1186 si_dump_compute_descriptors(sctx, log);
1187 }
1188
1189 static void si_dump_dma(struct si_context *sctx,
1190 struct radeon_saved_cs *saved, FILE *f)
1191 {
1192 static const char ib_name[] = "sDMA IB";
1193 unsigned i;
1194
1195 si_dump_bo_list(sctx, saved, f);
1196
1197 fprintf(f, "------------------ %s begin ------------------\n", ib_name);
1198
1199 for (i = 0; i < saved->num_dw; ++i) {
1200 fprintf(f, " %08x\n", saved->ib[i]);
1201 }
1202
1203 fprintf(f, "------------------- %s end -------------------\n", ib_name);
1204 fprintf(f, "\n");
1205
1206 fprintf(f, "SDMA Dump Done.\n");
1207 }
1208
1209 void si_check_vm_faults(struct si_context *sctx,
1210 struct radeon_saved_cs *saved, enum ring_type ring)
1211 {
1212 struct pipe_screen *screen = sctx->b.screen;
1213 FILE *f;
1214 uint64_t addr;
1215 char cmd_line[4096];
1216
1217 if (!ac_vm_fault_occured(sctx->chip_class,
1218 &sctx->dmesg_timestamp, &addr))
1219 return;
1220
1221 f = dd_get_debug_file(false);
1222 if (!f)
1223 return;
1224
1225 fprintf(f, "VM fault report.\n\n");
1226 if (os_get_command_line(cmd_line, sizeof(cmd_line)))
1227 fprintf(f, "Command: %s\n", cmd_line);
1228 fprintf(f, "Driver vendor: %s\n", screen->get_vendor(screen));
1229 fprintf(f, "Device vendor: %s\n", screen->get_device_vendor(screen));
1230 fprintf(f, "Device name: %s\n\n", screen->get_name(screen));
1231 fprintf(f, "Failing VM page: 0x%08"PRIx64"\n\n", addr);
1232
1233 if (sctx->apitrace_call_number)
1234 fprintf(f, "Last apitrace call: %u\n\n",
1235 sctx->apitrace_call_number);
1236
1237 switch (ring) {
1238 case RING_GFX: {
1239 struct u_log_context log;
1240 u_log_context_init(&log);
1241
1242 si_log_draw_state(sctx, &log);
1243 si_log_compute_state(sctx, &log);
1244 si_log_cs(sctx, &log, true);
1245
1246 u_log_new_page_print(&log, f);
1247 u_log_context_destroy(&log);
1248 break;
1249 }
1250 case RING_DMA:
1251 si_dump_dma(sctx, saved, f);
1252 break;
1253
1254 default:
1255 break;
1256 }
1257
1258 fclose(f);
1259
1260 fprintf(stderr, "Detected a VM fault, exiting...\n");
1261 exit(0);
1262 }
1263
1264 void si_init_debug_functions(struct si_context *sctx)
1265 {
1266 sctx->b.dump_debug_state = si_dump_debug_state;
1267
1268 /* Set the initial dmesg timestamp for this context, so that
1269 * only new messages will be checked for VM faults.
1270 */
1271 if (sctx->screen->debug_flags & DBG(CHECK_VM))
1272 ac_vm_fault_occured(sctx->chip_class,
1273 &sctx->dmesg_timestamp, NULL);
1274 }