2 * Copyright 2015 Advanced Micro Devices, Inc.
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:
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
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.
24 * Marek Olšák <maraeo@gmail.com>
30 #include "sid_tables.h"
31 #include "util/u_math.h"
32 #include "util/u_memory.h"
34 /* Parsed IBs are difficult to read without colors. Use "less -R file" to
35 * read them, or use "aha -b -f file" to convert them to html.
37 #define COLOR_RESET "\033[0m"
38 #define COLOR_RED "\033[31m"
39 #define COLOR_GREEN "\033[1;32m"
40 #define COLOR_YELLOW "\033[1;33m"
41 #define COLOR_CYAN "\033[1;36m"
45 static void print_spaces(FILE *f
, unsigned num
)
47 fprintf(f
, "%*s", num
, "");
50 static void print_value(FILE *file
, uint32_t value
, int bits
)
52 /* Guess if it's int or float */
53 if (value
<= (1 << 15)) {
55 fprintf(file
, "%u\n", value
);
57 fprintf(file
, "%u (0x%0*x)\n", value
, bits
/ 4, value
);
61 if (fabs(f
) < 100000 && f
*10 == floor(f
*10))
62 fprintf(file
, "%.1ff (0x%0*x)\n", f
, bits
/ 4, value
);
64 /* Don't print more leading zeros than there are bits. */
65 fprintf(file
, "0x%0*x\n", bits
/ 4, value
);
69 static void print_named_value(FILE *file
, const char *name
, uint32_t value
,
72 print_spaces(file
, INDENT_PKT
);
73 fprintf(file
, COLOR_YELLOW
"%s" COLOR_RESET
" <- ", name
);
74 print_value(file
, value
, bits
);
77 void ac_dump_reg(FILE *file
, unsigned offset
, uint32_t value
,
82 for (r
= 0; r
< ARRAY_SIZE(sid_reg_table
); r
++) {
83 const struct si_reg
*reg
= &sid_reg_table
[r
];
84 const char *reg_name
= sid_strings
+ reg
->name_offset
;
86 if (reg
->offset
== offset
) {
87 bool first_field
= true;
89 print_spaces(file
, INDENT_PKT
);
90 fprintf(file
, COLOR_YELLOW
"%s" COLOR_RESET
" <- ",
93 if (!reg
->num_fields
) {
94 print_value(file
, value
, 32);
98 for (f
= 0; f
< reg
->num_fields
; f
++) {
99 const struct si_field
*field
= sid_fields_table
+ reg
->fields_offset
+ f
;
100 const int *values_offsets
= sid_strings_offsets
+ field
->values_offset
;
101 uint32_t val
= (value
& field
->mask
) >>
102 (ffs(field
->mask
) - 1);
104 if (!(field
->mask
& field_mask
))
107 /* Indent the field. */
110 INDENT_PKT
+ strlen(reg_name
) + 4);
112 /* Print the field. */
113 fprintf(file
, "%s = ", sid_strings
+ field
->name_offset
);
115 if (val
< field
->num_values
&& values_offsets
[val
] >= 0)
116 fprintf(file
, "%s\n", sid_strings
+ values_offsets
[val
]);
118 print_value(file
, val
,
119 util_bitcount(field
->mask
));
127 print_spaces(file
, INDENT_PKT
);
128 fprintf(file
, COLOR_YELLOW
"0x%05x" COLOR_RESET
" <- 0x%08x\n", offset
, value
);
131 static void ac_parse_set_reg_packet(FILE *f
, uint32_t *ib
, unsigned count
,
134 unsigned reg
= (ib
[1] << 2) + reg_offset
;
137 for (i
= 0; i
< count
; i
++)
138 ac_dump_reg(f
, reg
+ i
*4, ib
[2+i
], ~0);
141 static uint32_t *ac_parse_packet3(FILE *f
, uint32_t *ib
, int *num_dw
,
142 int trace_id
, enum chip_class chip_class
)
144 unsigned count
= PKT_COUNT_G(ib
[0]);
145 unsigned op
= PKT3_IT_OPCODE_G(ib
[0]);
146 const char *predicate
= PKT3_PREDICATE(ib
[0]) ? "(predicate)" : "";
149 /* Print the name first. */
150 for (i
= 0; i
< ARRAY_SIZE(packet3_table
); i
++)
151 if (packet3_table
[i
].op
== op
)
154 if (i
< ARRAY_SIZE(packet3_table
)) {
155 const char *name
= sid_strings
+ packet3_table
[i
].name_offset
;
157 if (op
== PKT3_SET_CONTEXT_REG
||
158 op
== PKT3_SET_CONFIG_REG
||
159 op
== PKT3_SET_UCONFIG_REG
||
160 op
== PKT3_SET_SH_REG
)
161 fprintf(f
, COLOR_CYAN
"%s%s" COLOR_CYAN
":\n",
164 fprintf(f
, COLOR_GREEN
"%s%s" COLOR_RESET
":\n",
167 fprintf(f
, COLOR_RED
"PKT3_UNKNOWN 0x%x%s" COLOR_RESET
":\n",
170 /* Print the contents. */
172 case PKT3_SET_CONTEXT_REG
:
173 ac_parse_set_reg_packet(f
, ib
, count
, SI_CONTEXT_REG_OFFSET
);
175 case PKT3_SET_CONFIG_REG
:
176 ac_parse_set_reg_packet(f
, ib
, count
, SI_CONFIG_REG_OFFSET
);
178 case PKT3_SET_UCONFIG_REG
:
179 ac_parse_set_reg_packet(f
, ib
, count
, CIK_UCONFIG_REG_OFFSET
);
181 case PKT3_SET_SH_REG
:
182 ac_parse_set_reg_packet(f
, ib
, count
, SI_SH_REG_OFFSET
);
184 case PKT3_ACQUIRE_MEM
:
185 ac_dump_reg(f
, R_0301F0_CP_COHER_CNTL
, ib
[1], ~0);
186 ac_dump_reg(f
, R_0301F4_CP_COHER_SIZE
, ib
[2], ~0);
187 ac_dump_reg(f
, R_030230_CP_COHER_SIZE_HI
, ib
[3], ~0);
188 ac_dump_reg(f
, R_0301F8_CP_COHER_BASE
, ib
[4], ~0);
189 ac_dump_reg(f
, R_0301E4_CP_COHER_BASE_HI
, ib
[5], ~0);
190 print_named_value(f
, "POLL_INTERVAL", ib
[6], 16);
192 case PKT3_SURFACE_SYNC
:
193 if (chip_class
>= CIK
) {
194 ac_dump_reg(f
, R_0301F0_CP_COHER_CNTL
, ib
[1], ~0);
195 ac_dump_reg(f
, R_0301F4_CP_COHER_SIZE
, ib
[2], ~0);
196 ac_dump_reg(f
, R_0301F8_CP_COHER_BASE
, ib
[3], ~0);
198 ac_dump_reg(f
, R_0085F0_CP_COHER_CNTL
, ib
[1], ~0);
199 ac_dump_reg(f
, R_0085F4_CP_COHER_SIZE
, ib
[2], ~0);
200 ac_dump_reg(f
, R_0085F8_CP_COHER_BASE
, ib
[3], ~0);
202 print_named_value(f
, "POLL_INTERVAL", ib
[4], 16);
204 case PKT3_EVENT_WRITE
:
205 ac_dump_reg(f
, R_028A90_VGT_EVENT_INITIATOR
, ib
[1],
206 S_028A90_EVENT_TYPE(~0));
207 print_named_value(f
, "EVENT_INDEX", (ib
[1] >> 8) & 0xf, 4);
208 print_named_value(f
, "INV_L2", (ib
[1] >> 20) & 0x1, 1);
210 print_named_value(f
, "ADDRESS_LO", ib
[2], 32);
211 print_named_value(f
, "ADDRESS_HI", ib
[3], 16);
214 case PKT3_DRAW_INDEX_AUTO
:
215 ac_dump_reg(f
, R_030930_VGT_NUM_INDICES
, ib
[1], ~0);
216 ac_dump_reg(f
, R_0287F0_VGT_DRAW_INITIATOR
, ib
[2], ~0);
218 case PKT3_DRAW_INDEX_2
:
219 ac_dump_reg(f
, R_028A78_VGT_DMA_MAX_SIZE
, ib
[1], ~0);
220 ac_dump_reg(f
, R_0287E8_VGT_DMA_BASE
, ib
[2], ~0);
221 ac_dump_reg(f
, R_0287E4_VGT_DMA_BASE_HI
, ib
[3], ~0);
222 ac_dump_reg(f
, R_030930_VGT_NUM_INDICES
, ib
[4], ~0);
223 ac_dump_reg(f
, R_0287F0_VGT_DRAW_INITIATOR
, ib
[5], ~0);
225 case PKT3_INDEX_TYPE
:
226 ac_dump_reg(f
, R_028A7C_VGT_DMA_INDEX_TYPE
, ib
[1], ~0);
228 case PKT3_NUM_INSTANCES
:
229 ac_dump_reg(f
, R_030934_VGT_NUM_INSTANCES
, ib
[1], ~0);
231 case PKT3_WRITE_DATA
:
232 ac_dump_reg(f
, R_370_CONTROL
, ib
[1], ~0);
233 ac_dump_reg(f
, R_371_DST_ADDR_LO
, ib
[2], ~0);
234 ac_dump_reg(f
, R_372_DST_ADDR_HI
, ib
[3], ~0);
235 for (i
= 2; i
< count
; i
++) {
236 print_spaces(f
, INDENT_PKT
);
237 fprintf(f
, "0x%08x\n", ib
[2+i
]);
241 ac_dump_reg(f
, R_410_CP_DMA_WORD0
, ib
[1], ~0);
242 ac_dump_reg(f
, R_411_CP_DMA_WORD1
, ib
[2], ~0);
243 ac_dump_reg(f
, R_412_CP_DMA_WORD2
, ib
[3], ~0);
244 ac_dump_reg(f
, R_413_CP_DMA_WORD3
, ib
[4], ~0);
245 ac_dump_reg(f
, R_414_COMMAND
, ib
[5], ~0);
248 ac_dump_reg(f
, R_500_DMA_DATA_WORD0
, ib
[1], ~0);
249 ac_dump_reg(f
, R_501_SRC_ADDR_LO
, ib
[2], ~0);
250 ac_dump_reg(f
, R_502_SRC_ADDR_HI
, ib
[3], ~0);
251 ac_dump_reg(f
, R_503_DST_ADDR_LO
, ib
[4], ~0);
252 ac_dump_reg(f
, R_504_DST_ADDR_HI
, ib
[5], ~0);
253 ac_dump_reg(f
, R_414_COMMAND
, ib
[6], ~0);
255 case PKT3_INDIRECT_BUFFER_SI
:
256 case PKT3_INDIRECT_BUFFER_CONST
:
257 case PKT3_INDIRECT_BUFFER_CIK
:
258 ac_dump_reg(f
, R_3F0_IB_BASE_LO
, ib
[1], ~0);
259 ac_dump_reg(f
, R_3F1_IB_BASE_HI
, ib
[2], ~0);
260 ac_dump_reg(f
, R_3F2_CONTROL
, ib
[3], ~0);
262 case PKT3_CLEAR_STATE
:
263 case PKT3_INCREMENT_DE_COUNTER
:
264 case PKT3_PFP_SYNC_ME
:
267 if (ib
[0] == 0xffff1000) {
268 count
= -1; /* One dword NOP. */
270 } else if (count
== 0 && AC_IS_TRACE_POINT(ib
[1])) {
271 unsigned packet_id
= AC_GET_TRACE_POINT_ID(ib
[1]);
273 print_spaces(f
, INDENT_PKT
);
274 fprintf(f
, COLOR_RED
"Trace point ID: %u\n", packet_id
);
277 break; /* tracing was disabled */
279 print_spaces(f
, INDENT_PKT
);
280 if (packet_id
< trace_id
)
282 "This trace point was reached by the CP."
284 else if (packet_id
== trace_id
)
286 "!!!!! This is the last trace point that "
287 "was reached by the CP !!!!!"
289 else if (packet_id
+1 == trace_id
)
291 "!!!!! This is the first trace point that "
292 "was NOT been reached by the CP !!!!!"
296 "!!!!! This trace point was NOT reached "
301 /* fall through, print all dwords */
303 for (i
= 0; i
< count
+1; i
++) {
304 print_spaces(f
, INDENT_PKT
);
305 fprintf(f
, "0x%08x\n", ib
[1+i
]);
310 *num_dw
-= count
+ 2;
315 * Parse and print an IB into a file.
319 * \param num_dw size of the IB
320 * \param chip_class chip class
321 * \param trace_id the last trace ID that is known to have been reached
322 * and executed by the CP, typically read from a buffer
324 void ac_parse_ib(FILE *f
, uint32_t *ib
, int num_dw
, int trace_id
,
325 const char *name
, enum chip_class chip_class
)
327 fprintf(f
, "------------------ %s begin ------------------\n", name
);
330 unsigned type
= PKT_TYPE_G(ib
[0]);
334 ib
= ac_parse_packet3(f
, ib
, &num_dw
, trace_id
,
339 if (ib
[0] == 0x80000000) {
340 fprintf(f
, COLOR_GREEN
"NOP (type 2)" COLOR_RESET
"\n");
346 fprintf(f
, "Unknown packet type %i\n", type
);
351 fprintf(f
, "------------------- %s end -------------------\n", name
);
353 printf("Packet ends after the end of IB.\n");