~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/amd/common/ac_debug.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright 2015 Advanced Micro Devices, Inc.
3
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
 
 * on the rights to use, copy, modify, merge, publish, distribute, sub
8
 
 * license, and/or sell copies of the Software, and to permit persons to whom
9
 
 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18
 
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19
 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
 
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 
4
 * SPDX-License-Identifier: MIT
22
5
 */
23
6
 
24
7
#include "ac_debug.h"
52
35
#define COLOR_GREEN  "\033[1;32m"
53
36
#define COLOR_YELLOW "\033[1;33m"
54
37
#define COLOR_CYAN   "\033[1;36m"
 
38
#define COLOR_PURPLE "\033[1;35m"
55
39
 
56
40
#define O_COLOR_RESET  (debug_get_option_color() ? COLOR_RESET : "")
57
41
#define O_COLOR_RED    (debug_get_option_color() ? COLOR_RED : "")
58
42
#define O_COLOR_GREEN  (debug_get_option_color() ? COLOR_GREEN : "")
59
43
#define O_COLOR_YELLOW (debug_get_option_color() ? COLOR_YELLOW : "")
60
44
#define O_COLOR_CYAN   (debug_get_option_color() ? COLOR_CYAN : "")
 
45
#define O_COLOR_PURPLE (debug_get_option_color() ? COLOR_PURPLE : "")
61
46
 
62
47
#define INDENT_PKT 8
63
48
 
101
86
   }
102
87
}
103
88
 
 
89
static void print_reserved_dword(FILE *file, uint32_t value)
 
90
{
 
91
   print_spaces(file, INDENT_PKT);
 
92
   fprintf(file, "(reserved)\n");
 
93
}
 
94
 
104
95
static void print_named_value(FILE *file, const char *name, uint32_t value, int bits)
105
96
{
106
97
   print_spaces(file, INDENT_PKT);
110
101
   print_value(file, value, bits);
111
102
}
112
103
 
 
104
static void print_string_value(FILE *file, const char *name, const char *value)
 
105
{
 
106
   print_spaces(file, INDENT_PKT);
 
107
   fprintf(file, "%s%s%s <- ",
 
108
           O_COLOR_YELLOW, name,
 
109
           O_COLOR_RESET);
 
110
   fprintf(file, "%s\n", value);
 
111
}
 
112
 
113
113
static const struct si_reg *find_register(enum amd_gfx_level gfx_level, enum radeon_family family,
114
114
                                          unsigned offset)
115
115
{
174
174
   return reg ? sid_strings + reg->name_offset : "(no name)";
175
175
}
176
176
 
 
177
bool ac_register_exists(enum amd_gfx_level gfx_level, enum radeon_family family,
 
178
                        unsigned offset)
 
179
{
 
180
   return find_register(gfx_level, family, offset) != NULL;
 
181
}
 
182
 
177
183
void ac_dump_reg(FILE *file, enum amd_gfx_level gfx_level, enum radeon_family family,
178
184
                 unsigned offset, uint32_t value, uint32_t field_mask)
179
185
{
259
265
   unsigned index = reg_dw >> 28;
260
266
   int i;
261
267
 
262
 
   if (index != 0) {
263
 
      print_spaces(f, INDENT_PKT);
264
 
      fprintf(f, "INDEX = %u\n", index);
265
 
   }
 
268
   if (index != 0)
 
269
      print_named_value(f, "INDEX", index, 32);
266
270
 
267
271
   for (i = 0; i < count; i++)
268
272
      ac_dump_reg(f, ib->gfx_level, ib->family, reg + i * 4, ac_ib_get(ib), ~0);
269
273
}
270
274
 
 
275
static void ac_parse_set_reg_pairs_packed_packet(FILE *f, unsigned count, unsigned reg_base,
 
276
                                                 struct ac_ib_parser *ib)
 
277
{
 
278
   unsigned reg_offset0 = 0, reg_offset1 = 0;
 
279
 
 
280
   print_named_value(f, "REG_COUNT", ac_ib_get(ib), 32);
 
281
 
 
282
   for (unsigned i = 0; i < count; i++) {
 
283
      if (i % 3 == 0) {
 
284
         unsigned tmp = ac_ib_get(ib);
 
285
         reg_offset0 = ((tmp & 0xffff) << 2) + reg_base;
 
286
         reg_offset1 = ((tmp >> 16) << 2) + reg_base;
 
287
      } else if (i % 3 == 1) {
 
288
         ac_dump_reg(f, ib->gfx_level, ib->family, reg_offset0, ac_ib_get(ib), ~0);
 
289
      } else {
 
290
         ac_dump_reg(f, ib->gfx_level, ib->family, reg_offset1, ac_ib_get(ib), ~0);
 
291
      }
 
292
   }
 
293
}
 
294
 
271
295
static void ac_parse_packet3(FILE *f, uint32_t header, struct ac_ib_parser *ib,
272
296
                             int *current_trace_id)
273
297
{
274
298
   unsigned first_dw = ib->cur_dw;
275
299
   int count = PKT_COUNT_G(header);
276
300
   unsigned op = PKT3_IT_OPCODE_G(header);
277
 
   const char *predicate = PKT3_PREDICATE(header) ? "(predicate)" : "";
 
301
   const char *shader_type = PKT3_SHADER_TYPE_G(header) ? "(shader_type=compute)" : "";
 
302
   const char *predicated = PKT3_PREDICATE(header) ? "(predicated)" : "";
 
303
   const char *reset_filter_cam = PKT3_RESET_FILTER_CAM_G(header) ? "(reset_filter_cam)" : "";
278
304
   int i;
 
305
   unsigned tmp;
279
306
 
280
307
   /* Print the name first. */
281
308
   for (i = 0; i < ARRAY_SIZE(packet3_table); i++)
282
309
      if (packet3_table[i].op == op)
283
310
         break;
284
311
 
285
 
   if (i < ARRAY_SIZE(packet3_table)) {
286
 
      const char *name = sid_strings + packet3_table[i].name_offset;
287
 
 
288
 
      if (op == PKT3_SET_CONTEXT_REG || op == PKT3_SET_CONFIG_REG || op == PKT3_SET_UCONFIG_REG ||
289
 
          op == PKT3_SET_UCONFIG_REG_INDEX || op == PKT3_SET_SH_REG || op == PKT3_SET_SH_REG_INDEX)
290
 
         fprintf(f, "%s%s%s%s:\n", O_COLOR_CYAN, name, predicate, O_COLOR_RESET);
291
 
      else
292
 
         fprintf(f, "%s%s%s%s:\n", O_COLOR_GREEN, name, predicate, O_COLOR_RESET);
293
 
   } else
294
 
      fprintf(f, "%sPKT3_UNKNOWN 0x%x%s%s:\n", O_COLOR_RED, op, predicate, O_COLOR_RESET);
 
312
   const char *pkt_name = i < ARRAY_SIZE(packet3_table) ? sid_strings + packet3_table[i].name_offset
 
313
                                                        : "UNKNOWN";
 
314
   const char *color;
 
315
 
 
316
   if (strstr(pkt_name, "DRAW") || strstr(pkt_name, "DISPATCH"))
 
317
      color = O_COLOR_PURPLE;
 
318
   else if (strstr(pkt_name, "SET") == pkt_name && strstr(pkt_name, "REG"))
 
319
      color = O_COLOR_CYAN;
 
320
   else if (i >= ARRAY_SIZE(packet3_table))
 
321
      color = O_COLOR_RED;
 
322
   else
 
323
      color = O_COLOR_GREEN;
 
324
 
 
325
   fprintf(f, "%s%s%s%s%s%s:\n", color, pkt_name, O_COLOR_RESET,
 
326
           shader_type, predicated, reset_filter_cam);
295
327
 
296
328
   /* Print the contents. */
297
329
   switch (op) {
309
341
   case PKT3_SET_SH_REG_INDEX:
310
342
      ac_parse_set_reg_packet(f, count, SI_SH_REG_OFFSET, ib);
311
343
      break;
 
344
   case PKT3_SET_CONTEXT_REG_PAIRS_PACKED:
 
345
      ac_parse_set_reg_pairs_packed_packet(f, count, SI_CONTEXT_REG_OFFSET, ib);
 
346
      break;
 
347
   case PKT3_SET_SH_REG_PAIRS_PACKED:
 
348
   case PKT3_SET_SH_REG_PAIRS_PACKED_N:
 
349
      ac_parse_set_reg_pairs_packed_packet(f, count, SI_SH_REG_OFFSET, ib);
 
350
      break;
312
351
   case PKT3_ACQUIRE_MEM:
313
 
      if (ib->gfx_level >= GFX11 && G_585_PWS_ENA(ib->ib[ib->cur_dw + 5])) {
314
 
         ac_dump_reg(f, ib->gfx_level, ib->family, R_580_ACQUIRE_MEM_PWS_2, ac_ib_get(ib), ~0);
315
 
         print_named_value(f, "GCR_SIZE", ac_ib_get(ib), 32);
316
 
         print_named_value(f, "GCR_SIZE_HI", ac_ib_get(ib), 25);
317
 
         print_named_value(f, "GCR_BASE_LO", ac_ib_get(ib), 32);
318
 
         print_named_value(f, "GCR_BASE_HI", ac_ib_get(ib), 32);
319
 
         ac_dump_reg(f, ib->gfx_level, ib->family, R_585_ACQUIRE_MEM_PWS_7, ac_ib_get(ib), ~0);
320
 
         ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
321
 
         break;
 
352
      if (ib->gfx_level >= GFX11) {
 
353
         if (G_585_PWS_ENA(ib->ib[ib->cur_dw + 5])) {
 
354
            ac_dump_reg(f, ib->gfx_level, ib->family, R_580_ACQUIRE_MEM_PWS_2, ac_ib_get(ib), ~0);
 
355
            print_named_value(f, "GCR_SIZE", ac_ib_get(ib), 32);
 
356
            print_named_value(f, "GCR_SIZE_HI", ac_ib_get(ib), 25);
 
357
            print_named_value(f, "GCR_BASE_LO", ac_ib_get(ib), 32);
 
358
            print_named_value(f, "GCR_BASE_HI", ac_ib_get(ib), 32);
 
359
            ac_dump_reg(f, ib->gfx_level, ib->family, R_585_ACQUIRE_MEM_PWS_7, ac_ib_get(ib), ~0);
 
360
            ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
 
361
         } else {
 
362
            print_string_value(f, "ENGINE_SEL", ac_ib_get(ib) & 0x80000000 ? "ME" : "PFP");
 
363
            print_named_value(f, "GCR_SIZE", ac_ib_get(ib), 32);
 
364
            print_named_value(f, "GCR_SIZE_HI", ac_ib_get(ib), 25);
 
365
            print_named_value(f, "GCR_BASE_LO", ac_ib_get(ib), 32);
 
366
            print_named_value(f, "GCR_BASE_HI", ac_ib_get(ib), 32);
 
367
            print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
 
368
            ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
 
369
         }
 
370
      } else {
 
371
         tmp = ac_ib_get(ib);
 
372
         ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F0_CP_COHER_CNTL, tmp, 0x7fffffff);
 
373
         print_string_value(f, "ENGINE_SEL", tmp & 0x80000000 ? "ME" : "PFP");
 
374
         ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
 
375
         ac_dump_reg(f, ib->gfx_level, ib->family, R_030230_CP_COHER_SIZE_HI, ac_ib_get(ib), ~0);
 
376
         ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
 
377
         ac_dump_reg(f, ib->gfx_level, ib->family, R_0301E4_CP_COHER_BASE_HI, ac_ib_get(ib), ~0);
 
378
         print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
 
379
         if (ib->gfx_level >= GFX10)
 
380
            ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
322
381
      }
323
 
      ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F0_CP_COHER_CNTL, ac_ib_get(ib), ~0);
324
 
      ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
325
 
      ac_dump_reg(f, ib->gfx_level, ib->family, R_030230_CP_COHER_SIZE_HI, ac_ib_get(ib), ~0);
326
 
      ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
327
 
      ac_dump_reg(f, ib->gfx_level, ib->family, R_0301E4_CP_COHER_BASE_HI, ac_ib_get(ib), ~0);
328
 
      print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
329
 
      if (ib->gfx_level >= GFX10)
330
 
         ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
331
382
      break;
332
383
   case PKT3_SURFACE_SYNC:
333
384
      if (ib->gfx_level >= GFX7) {
449
500
      break;
450
501
   case PKT3_INDIRECT_BUFFER_SI:
451
502
   case PKT3_INDIRECT_BUFFER_CONST:
452
 
   case PKT3_INDIRECT_BUFFER_CIK: {
 
503
   case PKT3_INDIRECT_BUFFER: {
453
504
      uint32_t base_lo_dw = ac_ib_get(ib);
454
505
      ac_dump_reg(f, ib->gfx_level, ib->family, R_3F0_IB_BASE_LO, base_lo_dw, ~0);
455
506
      uint32_t base_hi_dw = ac_ib_get(ib);
494
545
   case PKT3_CLEAR_STATE:
495
546
   case PKT3_INCREMENT_DE_COUNTER:
496
547
   case PKT3_PFP_SYNC_ME:
 
548
      print_reserved_dword(f, ac_ib_get(ib));
497
549
      break;
498
550
   case PKT3_NOP:
499
551
      if (header == PKT3_NOP_PAD) {
529
581
         break;
530
582
      }
531
583
      break;
 
584
   case PKT3_DISPATCH_DIRECT:
 
585
      ac_dump_reg(f, ib->gfx_level, ib->family, R_00B804_COMPUTE_DIM_X, ac_ib_get(ib), ~0);
 
586
      ac_dump_reg(f, ib->gfx_level, ib->family, R_00B808_COMPUTE_DIM_Y, ac_ib_get(ib), ~0);
 
587
      ac_dump_reg(f, ib->gfx_level, ib->family, R_00B80C_COMPUTE_DIM_Z, ac_ib_get(ib), ~0);
 
588
      ac_dump_reg(f, ib->gfx_level, ib->family, R_00B800_COMPUTE_DISPATCH_INITIATOR,
 
589
                  ac_ib_get(ib), ~0);
 
590
      break;
 
591
   case PKT3_DISPATCH_INDIRECT:
 
592
      print_named_value(f, "DATA_OFFSET", ac_ib_get(ib), 32);
 
593
      ac_dump_reg(f, ib->gfx_level, ib->family, R_00B800_COMPUTE_DISPATCH_INITIATOR,
 
594
                  ac_ib_get(ib), ~0);
 
595
      break;
 
596
   case PKT3_SET_BASE:
 
597
      tmp = ac_ib_get(ib);
 
598
      print_string_value(f, "BASE_INDEX", tmp == 1 ? "INDIRECT_BASE" : COLOR_RED "UNKNOWN" COLOR_RESET);
 
599
      break;
532
600
   }
533
601
 
534
602
   /* print additional dwords */
689
757
 * \param old_dmesg_timestamp   previous dmesg timestamp parsed at init time
690
758
 * \param out_addr              detected VM fault addr
691
759
 */
692
 
bool ac_vm_fault_occured(enum amd_gfx_level gfx_level, uint64_t *old_dmesg_timestamp,
 
760
bool ac_vm_fault_occurred(enum amd_gfx_level gfx_level, uint64_t *old_dmesg_timestamp,
693
761
                         uint64_t *out_addr)
694
762
{
695
763
#ifdef _WIN32