ac/debug: invoke valgrind checks while parsing IBs
[mesa.git] / src / amd / common / ac_debug.c
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
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.
22 *
23 * Authors:
24 * Marek Olšák <maraeo@gmail.com>
25 */
26
27 #include "ac_debug.h"
28
29 #ifdef HAVE_VALGRIND
30 #include <valgrind.h>
31 #include <memcheck.h>
32 #define VG(x) x
33 #else
34 #define VG(x)
35 #endif
36
37 #include "sid.h"
38 #include "gfx9d.h"
39 #include "sid_tables.h"
40 #include "util/u_math.h"
41 #include "util/u_memory.h"
42
43 /* Parsed IBs are difficult to read without colors. Use "less -R file" to
44 * read them, or use "aha -b -f file" to convert them to html.
45 */
46 #define COLOR_RESET "\033[0m"
47 #define COLOR_RED "\033[31m"
48 #define COLOR_GREEN "\033[1;32m"
49 #define COLOR_YELLOW "\033[1;33m"
50 #define COLOR_CYAN "\033[1;36m"
51
52 #define INDENT_PKT 8
53
54 struct ac_ib_parser {
55 FILE *f;
56 uint32_t *ib;
57 unsigned num_dw;
58 int trace_id;
59 enum chip_class chip_class;
60 ac_debug_addr_callback addr_callback;
61 void *addr_callback_data;
62
63 unsigned cur_dw;
64 };
65
66 static void ac_do_parse_ib(FILE *f, struct ac_ib_parser *ib);
67
68 static void print_spaces(FILE *f, unsigned num)
69 {
70 fprintf(f, "%*s", num, "");
71 }
72
73 static void print_value(FILE *file, uint32_t value, int bits)
74 {
75 /* Guess if it's int or float */
76 if (value <= (1 << 15)) {
77 if (value <= 9)
78 fprintf(file, "%u\n", value);
79 else
80 fprintf(file, "%u (0x%0*x)\n", value, bits / 4, value);
81 } else {
82 float f = uif(value);
83
84 if (fabs(f) < 100000 && f*10 == floor(f*10))
85 fprintf(file, "%.1ff (0x%0*x)\n", f, bits / 4, value);
86 else
87 /* Don't print more leading zeros than there are bits. */
88 fprintf(file, "0x%0*x\n", bits / 4, value);
89 }
90 }
91
92 static void print_named_value(FILE *file, const char *name, uint32_t value,
93 int bits)
94 {
95 print_spaces(file, INDENT_PKT);
96 fprintf(file, COLOR_YELLOW "%s" COLOR_RESET " <- ", name);
97 print_value(file, value, bits);
98 }
99
100 void ac_dump_reg(FILE *file, unsigned offset, uint32_t value,
101 uint32_t field_mask)
102 {
103 int r, f;
104
105 for (r = 0; r < ARRAY_SIZE(sid_reg_table); r++) {
106 const struct si_reg *reg = &sid_reg_table[r];
107 const char *reg_name = sid_strings + reg->name_offset;
108
109 if (reg->offset == offset) {
110 bool first_field = true;
111
112 print_spaces(file, INDENT_PKT);
113 fprintf(file, COLOR_YELLOW "%s" COLOR_RESET " <- ",
114 reg_name);
115
116 if (!reg->num_fields) {
117 print_value(file, value, 32);
118 return;
119 }
120
121 for (f = 0; f < reg->num_fields; f++) {
122 const struct si_field *field = sid_fields_table + reg->fields_offset + f;
123 const int *values_offsets = sid_strings_offsets + field->values_offset;
124 uint32_t val = (value & field->mask) >>
125 (ffs(field->mask) - 1);
126
127 if (!(field->mask & field_mask))
128 continue;
129
130 /* Indent the field. */
131 if (!first_field)
132 print_spaces(file,
133 INDENT_PKT + strlen(reg_name) + 4);
134
135 /* Print the field. */
136 fprintf(file, "%s = ", sid_strings + field->name_offset);
137
138 if (val < field->num_values && values_offsets[val] >= 0)
139 fprintf(file, "%s\n", sid_strings + values_offsets[val]);
140 else
141 print_value(file, val,
142 util_bitcount(field->mask));
143
144 first_field = false;
145 }
146 return;
147 }
148 }
149
150 print_spaces(file, INDENT_PKT);
151 fprintf(file, COLOR_YELLOW "0x%05x" COLOR_RESET " <- 0x%08x\n", offset, value);
152 }
153
154 static uint32_t ac_ib_get(struct ac_ib_parser *ib)
155 {
156 uint32_t v = 0;
157
158 if (ib->cur_dw < ib->num_dw) {
159 v = ib->ib[ib->cur_dw];
160 #ifdef HAVE_VALGRIND
161 /* Help figure out where garbage data is written to IBs.
162 *
163 * Arguably we should do this already when the IBs are written,
164 * see RADEON_VALGRIND. The problem is that client-requests to
165 * Valgrind have an overhead even when Valgrind isn't running,
166 * and radeon_emit is performance sensitive...
167 */
168 if (VALGRIND_CHECK_VALUE_IS_DEFINED(v))
169 fprintf(ib->f, COLOR_RED "Valgrind: The next DWORD is garbage"
170 COLOR_RESET "\n");
171 #endif
172 fprintf(ib->f, "\n\035#%08x ", v);
173 } else {
174 fprintf(ib->f, "\n\035#???????? ");
175 }
176
177 ib->cur_dw++;
178 return v;
179 }
180
181 static void ac_parse_set_reg_packet(FILE *f, unsigned count, unsigned reg_offset,
182 struct ac_ib_parser *ib)
183 {
184 unsigned reg_dw = ac_ib_get(ib);
185 unsigned reg = ((reg_dw & 0xFFFF) << 2) + reg_offset;
186 unsigned index = reg_dw >> 28;
187 int i;
188
189 if (index != 0) {
190 print_spaces(f, INDENT_PKT);
191 fprintf(f, "INDEX = %u\n", index);
192 }
193
194 for (i = 0; i < count; i++)
195 ac_dump_reg(f, reg + i*4, ac_ib_get(ib), ~0);
196 }
197
198 static void ac_parse_packet3(FILE *f, uint32_t header, struct ac_ib_parser *ib)
199 {
200 unsigned first_dw = ib->cur_dw;
201 int count = PKT_COUNT_G(header);
202 unsigned op = PKT3_IT_OPCODE_G(header);
203 const char *predicate = PKT3_PREDICATE(header) ? "(predicate)" : "";
204 int i;
205
206 /* Print the name first. */
207 for (i = 0; i < ARRAY_SIZE(packet3_table); i++)
208 if (packet3_table[i].op == op)
209 break;
210
211 if (i < ARRAY_SIZE(packet3_table)) {
212 const char *name = sid_strings + packet3_table[i].name_offset;
213
214 if (op == PKT3_SET_CONTEXT_REG ||
215 op == PKT3_SET_CONFIG_REG ||
216 op == PKT3_SET_UCONFIG_REG ||
217 op == PKT3_SET_SH_REG)
218 fprintf(f, COLOR_CYAN "%s%s" COLOR_CYAN ":\n",
219 name, predicate);
220 else
221 fprintf(f, COLOR_GREEN "%s%s" COLOR_RESET ":\n",
222 name, predicate);
223 } else
224 fprintf(f, COLOR_RED "PKT3_UNKNOWN 0x%x%s" COLOR_RESET ":\n",
225 op, predicate);
226
227 /* Print the contents. */
228 switch (op) {
229 case PKT3_SET_CONTEXT_REG:
230 ac_parse_set_reg_packet(f, count, SI_CONTEXT_REG_OFFSET, ib);
231 break;
232 case PKT3_SET_CONFIG_REG:
233 ac_parse_set_reg_packet(f, count, SI_CONFIG_REG_OFFSET, ib);
234 break;
235 case PKT3_SET_UCONFIG_REG:
236 ac_parse_set_reg_packet(f, count, CIK_UCONFIG_REG_OFFSET, ib);
237 break;
238 case PKT3_SET_SH_REG:
239 ac_parse_set_reg_packet(f, count, SI_SH_REG_OFFSET, ib);
240 break;
241 case PKT3_ACQUIRE_MEM:
242 ac_dump_reg(f, R_0301F0_CP_COHER_CNTL, ac_ib_get(ib), ~0);
243 ac_dump_reg(f, R_0301F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
244 ac_dump_reg(f, R_030230_CP_COHER_SIZE_HI, ac_ib_get(ib), ~0);
245 ac_dump_reg(f, R_0301F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
246 ac_dump_reg(f, R_0301E4_CP_COHER_BASE_HI, ac_ib_get(ib), ~0);
247 print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
248 break;
249 case PKT3_SURFACE_SYNC:
250 if (ib->chip_class >= CIK) {
251 ac_dump_reg(f, R_0301F0_CP_COHER_CNTL, ac_ib_get(ib), ~0);
252 ac_dump_reg(f, R_0301F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
253 ac_dump_reg(f, R_0301F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
254 } else {
255 ac_dump_reg(f, R_0085F0_CP_COHER_CNTL, ac_ib_get(ib), ~0);
256 ac_dump_reg(f, R_0085F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
257 ac_dump_reg(f, R_0085F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
258 }
259 print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
260 break;
261 case PKT3_EVENT_WRITE: {
262 uint32_t event_dw = ac_ib_get(ib);
263 ac_dump_reg(f, R_028A90_VGT_EVENT_INITIATOR, event_dw,
264 S_028A90_EVENT_TYPE(~0));
265 print_named_value(f, "EVENT_INDEX", (event_dw >> 8) & 0xf, 4);
266 print_named_value(f, "INV_L2", (event_dw >> 20) & 0x1, 1);
267 if (count > 0) {
268 print_named_value(f, "ADDRESS_LO", ac_ib_get(ib), 32);
269 print_named_value(f, "ADDRESS_HI", ac_ib_get(ib), 16);
270 }
271 break;
272 }
273 case PKT3_EVENT_WRITE_EOP: {
274 uint32_t event_dw = ac_ib_get(ib);
275 ac_dump_reg(f, R_028A90_VGT_EVENT_INITIATOR, event_dw,
276 S_028A90_EVENT_TYPE(~0));
277 print_named_value(f, "EVENT_INDEX", (event_dw >> 8) & 0xf, 4);
278 print_named_value(f, "TCL1_VOL_ACTION_ENA", (event_dw >> 12) & 0x1, 1);
279 print_named_value(f, "TC_VOL_ACTION_ENA", (event_dw >> 13) & 0x1, 1);
280 print_named_value(f, "TC_WB_ACTION_ENA", (event_dw >> 15) & 0x1, 1);
281 print_named_value(f, "TCL1_ACTION_ENA", (event_dw >> 16) & 0x1, 1);
282 print_named_value(f, "TC_ACTION_ENA", (event_dw >> 17) & 0x1, 1);
283 print_named_value(f, "ADDRESS_LO", ac_ib_get(ib), 32);
284 uint32_t addr_hi_dw = ac_ib_get(ib);
285 print_named_value(f, "ADDRESS_HI", addr_hi_dw, 16);
286 print_named_value(f, "DST_SEL", (addr_hi_dw >> 16) & 0x3, 2);
287 print_named_value(f, "INT_SEL", (addr_hi_dw >> 24) & 0x7, 3);
288 print_named_value(f, "DATA_SEL", addr_hi_dw >> 29, 3);
289 print_named_value(f, "DATA_LO", ac_ib_get(ib), 32);
290 print_named_value(f, "DATA_HI", ac_ib_get(ib), 32);
291 break;
292 }
293 case PKT3_RELEASE_MEM: {
294 uint32_t event_dw = ac_ib_get(ib);
295 ac_dump_reg(f, R_028A90_VGT_EVENT_INITIATOR, event_dw,
296 S_028A90_EVENT_TYPE(~0));
297 print_named_value(f, "EVENT_INDEX", (event_dw >> 8) & 0xf, 4);
298 print_named_value(f, "TCL1_VOL_ACTION_ENA", (event_dw >> 12) & 0x1, 1);
299 print_named_value(f, "TC_VOL_ACTION_ENA", (event_dw >> 13) & 0x1, 1);
300 print_named_value(f, "TC_WB_ACTION_ENA", (event_dw >> 15) & 0x1, 1);
301 print_named_value(f, "TCL1_ACTION_ENA", (event_dw >> 16) & 0x1, 1);
302 print_named_value(f, "TC_ACTION_ENA", (event_dw >> 17) & 0x1, 1);
303 print_named_value(f, "TC_NC_ACTION_ENA", (event_dw >> 19) & 0x1, 1);
304 print_named_value(f, "TC_WC_ACTION_ENA", (event_dw >> 20) & 0x1, 1);
305 print_named_value(f, "TC_MD_ACTION_ENA", (event_dw >> 21) & 0x1, 1);
306 uint32_t sel_dw = ac_ib_get(ib);
307 print_named_value(f, "DST_SEL", (sel_dw >> 16) & 0x3, 2);
308 print_named_value(f, "INT_SEL", (sel_dw >> 24) & 0x7, 3);
309 print_named_value(f, "DATA_SEL", sel_dw >> 29, 3);
310 print_named_value(f, "ADDRESS_LO", ac_ib_get(ib), 32);
311 print_named_value(f, "ADDRESS_HI", ac_ib_get(ib), 32);
312 print_named_value(f, "DATA_LO", ac_ib_get(ib), 32);
313 print_named_value(f, "DATA_HI", ac_ib_get(ib), 32);
314 print_named_value(f, "CTXID", ac_ib_get(ib), 32);
315 break;
316 }
317 case PKT3_WAIT_REG_MEM:
318 print_named_value(f, "OP", ac_ib_get(ib), 32);
319 print_named_value(f, "ADDRESS_LO", ac_ib_get(ib), 32);
320 print_named_value(f, "ADDRESS_HI", ac_ib_get(ib), 32);
321 print_named_value(f, "REF", ac_ib_get(ib), 32);
322 print_named_value(f, "MASK", ac_ib_get(ib), 32);
323 print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
324 break;
325 case PKT3_DRAW_INDEX_AUTO:
326 ac_dump_reg(f, R_030930_VGT_NUM_INDICES, ac_ib_get(ib), ~0);
327 ac_dump_reg(f, R_0287F0_VGT_DRAW_INITIATOR, ac_ib_get(ib), ~0);
328 break;
329 case PKT3_DRAW_INDEX_2:
330 ac_dump_reg(f, R_028A78_VGT_DMA_MAX_SIZE, ac_ib_get(ib), ~0);
331 ac_dump_reg(f, R_0287E8_VGT_DMA_BASE, ac_ib_get(ib), ~0);
332 ac_dump_reg(f, R_0287E4_VGT_DMA_BASE_HI, ac_ib_get(ib), ~0);
333 ac_dump_reg(f, R_030930_VGT_NUM_INDICES, ac_ib_get(ib), ~0);
334 ac_dump_reg(f, R_0287F0_VGT_DRAW_INITIATOR, ac_ib_get(ib), ~0);
335 break;
336 case PKT3_INDEX_TYPE:
337 ac_dump_reg(f, R_028A7C_VGT_DMA_INDEX_TYPE, ac_ib_get(ib), ~0);
338 break;
339 case PKT3_NUM_INSTANCES:
340 ac_dump_reg(f, R_030934_VGT_NUM_INSTANCES, ac_ib_get(ib), ~0);
341 break;
342 case PKT3_WRITE_DATA:
343 ac_dump_reg(f, R_370_CONTROL, ac_ib_get(ib), ~0);
344 ac_dump_reg(f, R_371_DST_ADDR_LO, ac_ib_get(ib), ~0);
345 ac_dump_reg(f, R_372_DST_ADDR_HI, ac_ib_get(ib), ~0);
346 /* The payload is written automatically */
347 break;
348 case PKT3_CP_DMA:
349 ac_dump_reg(f, R_410_CP_DMA_WORD0, ac_ib_get(ib), ~0);
350 ac_dump_reg(f, R_411_CP_DMA_WORD1, ac_ib_get(ib), ~0);
351 ac_dump_reg(f, R_412_CP_DMA_WORD2, ac_ib_get(ib), ~0);
352 ac_dump_reg(f, R_413_CP_DMA_WORD3, ac_ib_get(ib), ~0);
353 ac_dump_reg(f, R_414_COMMAND, ac_ib_get(ib), ~0);
354 break;
355 case PKT3_DMA_DATA:
356 ac_dump_reg(f, R_500_DMA_DATA_WORD0, ac_ib_get(ib), ~0);
357 ac_dump_reg(f, R_501_SRC_ADDR_LO, ac_ib_get(ib), ~0);
358 ac_dump_reg(f, R_502_SRC_ADDR_HI, ac_ib_get(ib), ~0);
359 ac_dump_reg(f, R_503_DST_ADDR_LO, ac_ib_get(ib), ~0);
360 ac_dump_reg(f, R_504_DST_ADDR_HI, ac_ib_get(ib), ~0);
361 ac_dump_reg(f, R_414_COMMAND, ac_ib_get(ib), ~0);
362 break;
363 case PKT3_INDIRECT_BUFFER_SI:
364 case PKT3_INDIRECT_BUFFER_CONST:
365 case PKT3_INDIRECT_BUFFER_CIK: {
366 uint32_t base_lo_dw = ac_ib_get(ib);
367 ac_dump_reg(f, R_3F0_IB_BASE_LO, base_lo_dw, ~0);
368 uint32_t base_hi_dw = ac_ib_get(ib);
369 ac_dump_reg(f, R_3F1_IB_BASE_HI, base_hi_dw, ~0);
370 uint32_t control_dw = ac_ib_get(ib);
371 ac_dump_reg(f, R_3F2_CONTROL, control_dw, ~0);
372
373 if (!ib->addr_callback)
374 break;
375
376 uint64_t addr = ((uint64_t)base_hi_dw << 32) | base_lo_dw;
377 void *data = ib->addr_callback(ib->addr_callback_data, addr);
378 if (!data)
379 break;
380
381 if (G_3F2_CHAIN(control_dw)) {
382 ib->ib = data;
383 ib->num_dw = G_3F2_IB_SIZE(control_dw);
384 ib->cur_dw = 0;
385 return;
386 }
387
388 struct ac_ib_parser ib_recurse;
389 memcpy(&ib_recurse, ib, sizeof(ib_recurse));
390 ib_recurse.ib = data;
391 ib_recurse.num_dw = G_3F2_IB_SIZE(control_dw);
392 ib_recurse.cur_dw = 0;
393
394 fprintf(f, "\n\035>------------------ nested begin ------------------\n");
395 ac_do_parse_ib(f, &ib_recurse);
396 fprintf(f, "\n\035<------------------- nested end -------------------\n");
397 break;
398 }
399 case PKT3_CLEAR_STATE:
400 case PKT3_INCREMENT_DE_COUNTER:
401 case PKT3_PFP_SYNC_ME:
402 break;
403 case PKT3_NOP:
404 if (header == 0xffff1000) {
405 count = -1; /* One dword NOP. */
406 } else if (count == 0 && ib->cur_dw < ib->num_dw &&
407 AC_IS_TRACE_POINT(ib->ib[ib->cur_dw])) {
408 unsigned packet_id = AC_GET_TRACE_POINT_ID(ib->ib[ib->cur_dw]);
409
410 print_spaces(f, INDENT_PKT);
411 fprintf(f, COLOR_RED "Trace point ID: %u\n", packet_id);
412
413 if (ib->trace_id == -1)
414 break; /* tracing was disabled */
415
416 print_spaces(f, INDENT_PKT);
417 if (packet_id < ib->trace_id)
418 fprintf(f, COLOR_RED
419 "This trace point was reached by the CP."
420 COLOR_RESET "\n");
421 else if (packet_id == ib->trace_id)
422 fprintf(f, COLOR_RED
423 "!!!!! This is the last trace point that "
424 "was reached by the CP !!!!!"
425 COLOR_RESET "\n");
426 else if (packet_id+1 == ib->trace_id)
427 fprintf(f, COLOR_RED
428 "!!!!! This is the first trace point that "
429 "was NOT been reached by the CP !!!!!"
430 COLOR_RESET "\n");
431 else
432 fprintf(f, COLOR_RED
433 "!!!!! This trace point was NOT reached "
434 "by the CP !!!!!"
435 COLOR_RESET "\n");
436 break;
437 }
438 break;
439 }
440
441 /* print additional dwords */
442 while (ib->cur_dw <= first_dw + count)
443 ac_ib_get(ib);
444
445 if (ib->cur_dw > first_dw + count + 1)
446 fprintf(f, COLOR_RED "\n!!!!! count in header too low !!!!!"
447 COLOR_RESET "\n");
448 }
449
450 /**
451 * Parse and print an IB into a file.
452 */
453 static void ac_do_parse_ib(FILE *f, struct ac_ib_parser *ib)
454 {
455 while (ib->cur_dw < ib->num_dw) {
456 uint32_t header = ac_ib_get(ib);
457 unsigned type = PKT_TYPE_G(header);
458
459 switch (type) {
460 case 3:
461 ac_parse_packet3(f, header, ib);
462 break;
463 case 2:
464 /* type-2 nop */
465 if (header == 0x80000000) {
466 fprintf(f, COLOR_GREEN "NOP (type 2)" COLOR_RESET "\n");
467 break;
468 }
469 /* fall through */
470 default:
471 fprintf(f, "Unknown packet type %i\n", type);
472 break;
473 }
474 }
475 }
476
477 static void format_ib_output(FILE *f, char *out)
478 {
479 unsigned depth = 0;
480
481 for (;;) {
482 char op = 0;
483
484 if (out[0] == '\n' && out[1] == '\035')
485 out++;
486 if (out[0] == '\035') {
487 op = out[1];
488 out += 2;
489 }
490
491 if (op == '<')
492 depth--;
493
494 unsigned indent = 4 * depth;
495 if (op != '#')
496 indent += 9;
497
498 if (indent)
499 print_spaces(f, indent);
500
501 char *end = strchrnul(out, '\n');
502 fwrite(out, end - out, 1, f);
503 fputc('\n', f); /* always end with a new line */
504 if (!*end)
505 break;
506
507 out = end + 1;
508
509 if (op == '>')
510 depth++;
511 }
512 }
513
514 /**
515 * Parse and print an IB into a file.
516 *
517 * \param f file
518 * \param ib_ptr IB
519 * \param num_dw size of the IB
520 * \param chip_class chip class
521 * \param trace_id the last trace ID that is known to have been reached
522 * and executed by the CP, typically read from a buffer
523 * \param addr_callback Get a mapped pointer of the IB at a given address. Can
524 * be NULL.
525 * \param addr_callback_data user data for addr_callback
526 */
527 void ac_parse_ib_chunk(FILE *f, uint32_t *ib_ptr, int num_dw, int trace_id,
528 enum chip_class chip_class,
529 ac_debug_addr_callback addr_callback, void *addr_callback_data)
530 {
531 struct ac_ib_parser ib = {};
532 ib.ib = ib_ptr;
533 ib.num_dw = num_dw;
534 ib.trace_id = trace_id;
535 ib.chip_class = chip_class;
536 ib.addr_callback = addr_callback;
537 ib.addr_callback_data = addr_callback_data;
538
539 char *out;
540 size_t outsize;
541 FILE *memf = open_memstream(&out, &outsize);
542 ib.f = memf;
543 ac_do_parse_ib(memf, &ib);
544 fclose(memf);
545
546 if (out) {
547 format_ib_output(f, out);
548 free(out);
549 }
550
551 if (ib.cur_dw > ib.num_dw) {
552 printf("\nPacket ends after the end of IB.\n");
553 exit(1);
554 }
555 }
556
557 /**
558 * Parse and print an IB into a file.
559 *
560 * \param f file
561 * \param ib IB
562 * \param num_dw size of the IB
563 * \param chip_class chip class
564 * \param trace_id the last trace ID that is known to have been reached
565 * and executed by the CP, typically read from a buffer
566 * \param addr_callback Get a mapped pointer of the IB at a given address. Can
567 * be NULL.
568 * \param addr_callback_data user data for addr_callback
569 */
570 void ac_parse_ib(FILE *f, uint32_t *ib, int num_dw, int trace_id,
571 const char *name, enum chip_class chip_class,
572 ac_debug_addr_callback addr_callback, void *addr_callback_data)
573 {
574 fprintf(f, "------------------ %s begin ------------------\n", name);
575
576 ac_parse_ib_chunk(f, ib, num_dw, trace_id, chip_class, addr_callback,
577 addr_callback_data);
578
579 fprintf(f, "------------------- %s end -------------------\n\n", name);
580 }