2 * Copyright © 2016 Intel Corporation
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:
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 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
34 #include <sys/types.h>
40 #include "intel_aub.h"
41 #include "gen_disasm.h"
43 /* Below is the only command missing from intel_aub.h in libdrm
44 * So, reuse intel_aub.h from libdrm and #define the
45 * AUB_MI_BATCH_BUFFER_END as below
47 #define AUB_MI_BATCH_BUFFER_END (0x0500 << 16)
50 #define HEADER CSI "37;44m"
51 #define NORMAL CSI "0m"
52 #define CLEAR_TO_EOL CSI "0K"
56 static bool option_full_decode
= true;
57 static bool option_print_offsets
= true;
58 static enum { COLOR_AUTO
, COLOR_ALWAYS
, COLOR_NEVER
} option_color
;
62 struct gen_disasm
*disasm
;
64 uint64_t gtt_size
, gtt_end
;
66 uint64_t general_state_base
;
67 uint64_t surface_state_base
;
68 uint64_t dynamic_state_base
;
69 uint64_t instruction_base
;
70 uint64_t instruction_bound
;
72 static inline uint32_t
73 field(uint32_t value
, int start
, int end
)
77 mask
= ~0U >> (31 - end
+ start
);
79 return (value
>> start
) & mask
;
82 struct brw_instruction
;
85 valid_offset(uint32_t offset
)
87 return offset
< gtt_end
;
91 print_dword_val(struct gen_field_iterator
*iter
, uint64_t offset
,
100 f
= iter
->group
->fields
[iter
->i
- 1];
101 v
.dw
= iter
->p
[f
->start
/ 32];
103 if (*dword_num
!= (f
->start
/ 32)) {
104 printf("0x%08lx: 0x%08x : Dword %d\n",
105 offset
+ 4 * (f
->start
/ 32), v
.dw
, f
->start
/ 32);
106 *dword_num
= (f
->start
/ 32);
111 print_iterator_values(struct gen_field_iterator
*iter
, int *idx
)
114 if (strstr(iter
->value
, "struct") == NULL
) {
115 printf(" %s: %s\n", iter
->name
, iter
->value
);
117 token
= strtok(iter
->value
, " ");
119 token
= strtok(NULL
, " ");
120 *idx
= atoi(strtok(NULL
, ">"));
124 printf(" %s:<struct %s>\n", iter
->name
, token
);
130 decode_structure(struct gen_spec
*spec
, struct gen_group
*strct
,
133 struct gen_field_iterator iter
;
135 int idx
= 0, dword_num
= 0;
138 if (option_print_offsets
)
139 offset
= (void *) p
- gtt
;
143 gen_field_iterator_init(&iter
, strct
, p
);
144 while (gen_field_iterator_next(&iter
)) {
146 print_dword_val(&iter
, offset
, &dword_num
);
147 token
= print_iterator_values(&iter
, &idx
);
149 struct gen_group
*struct_val
= gen_spec_find_struct(spec
, token
);
150 decode_structure(spec
, struct_val
, &p
[idx
]);
157 handle_struct_decode(struct gen_spec
*spec
, char *struct_name
, uint32_t *p
)
159 if (struct_name
== NULL
)
161 struct gen_group
*struct_val
= gen_spec_find_struct(spec
, struct_name
);
162 decode_structure(spec
, struct_val
, p
);
166 dump_binding_table(struct gen_spec
*spec
, uint32_t offset
)
168 uint32_t *pointers
, i
;
170 struct gen_group
*surface_state
;
172 surface_state
= gen_spec_find_struct(spec
, "RENDER_SURFACE_STATE");
173 if (surface_state
== NULL
) {
174 printf("did not find RENDER_SURFACE_STATE info\n");
178 start
= surface_state_base
+ offset
;
179 pointers
= gtt
+ start
;
180 for (i
= 0; i
< 16; i
++) {
181 if (pointers
[i
] == 0)
183 start
= pointers
[i
] + surface_state_base
;
184 if (!valid_offset(start
)) {
185 printf("pointer %u: %08x <not valid>\n",
189 printf("pointer %u: %08x\n", i
, pointers
[i
]);
192 decode_structure(spec
, surface_state
, gtt
+ start
);
197 handle_3dstate_index_buffer(struct gen_spec
*spec
, uint32_t *p
)
200 uint32_t length
, i
, type
, size
;
203 type
= (p
[1] >> 8) & 3;
205 length
= p
[4] / size
;
211 for (i
= 0; i
< length
; i
++) {
214 printf("%3d ", ((uint8_t *)start
)[i
]);
217 printf("%3d ", ((uint16_t *)start
)[i
]);
220 printf("%3d ", ((uint32_t *)start
)[i
]);
224 if (length
< p
[4] / size
)
230 static inline uint64_t
231 get_qword(uint32_t *p
)
233 return ((uint64_t) p
[1] << 32) | p
[0];
237 handle_state_base_address(struct gen_spec
*spec
, uint32_t *p
)
239 uint64_t mask
= ~((1 << 12) - 1);
241 if (gen_spec_get_gen(spec
) >= gen_make_gen(8,0)) {
243 general_state_base
= get_qword(&p
[1]) & mask
;
245 surface_state_base
= get_qword(&p
[4]) & mask
;
247 dynamic_state_base
= get_qword(&p
[6]) & mask
;
249 instruction_base
= get_qword(&p
[10]) & mask
;
251 instruction_bound
= p
[15] & mask
;
254 surface_state_base
= p
[2] & mask
;
256 dynamic_state_base
= p
[3] & mask
;
258 instruction_base
= p
[5] & mask
;
260 instruction_bound
= p
[9] & mask
;
265 dump_samplers(struct gen_spec
*spec
, uint32_t offset
)
269 struct gen_group
*sampler_state
;
271 sampler_state
= gen_spec_find_struct(spec
, "SAMPLER_STATE");
273 start
= dynamic_state_base
+ offset
;
274 for (i
= 0; i
< 4; i
++) {
275 printf("sampler state %d\n", i
);
276 decode_structure(spec
, sampler_state
, gtt
+ start
+ i
* 16);
281 handle_media_interface_descriptor_load(struct gen_spec
*spec
, uint32_t *p
)
283 int i
, length
= p
[2] / 32;
284 struct gen_group
*descriptor_structure
;
285 uint32_t *descriptors
;
287 struct brw_instruction
*insns
;
289 descriptor_structure
=
290 gen_spec_find_struct(spec
, "INTERFACE_DESCRIPTOR_DATA");
291 if (descriptor_structure
== NULL
) {
292 printf("did not find INTERFACE_DESCRIPTOR_DATA info\n");
296 start
= dynamic_state_base
+ p
[3];
297 descriptors
= gtt
+ start
;
298 for (i
= 0; i
< length
; i
++, descriptors
+= 8) {
299 printf("descriptor %u: %08x\n", i
, *descriptors
);
300 decode_structure(spec
, descriptor_structure
, descriptors
);
302 start
= instruction_base
+ descriptors
[0];
303 if (!valid_offset(start
)) {
304 printf("kernel: %08lx <not valid>\n", start
);
307 printf("kernel: %08lx\n", start
);
310 insns
= (struct brw_instruction
*) (gtt
+ start
);
311 gen_disasm_disassemble(disasm
, insns
, 0, 8192, stdout
);
313 dump_samplers(spec
, descriptors
[3] & ~0x1f);
314 dump_binding_table(spec
, descriptors
[4] & ~0x1f);
318 /* Heuristic to determine whether a uint32_t is probably actually a float
319 * (http://stackoverflow.com/a/2953466)
323 probably_float(uint32_t bits
)
325 int exp
= ((bits
& 0x7f800000U
) >> 23) - 127;
326 uint32_t mant
= bits
& 0x007fffff;
329 if (exp
== -127 && mant
== 0)
332 /* +- 1 billionth to 1 billion */
333 if (-30 <= exp
&& exp
<= 30)
336 /* some value with only a few binary digits */
337 if ((mant
& 0x0000ffff) == 0)
344 handle_3dstate_vertex_buffers(struct gen_spec
*spec
, uint32_t *p
)
346 uint32_t *end
, *s
, *dw
, *dwend
;
348 int n
, i
, count
, stride
;
350 end
= (p
[0] & 0xff) + p
+ 2;
351 for (s
= &p
[1], n
= 0; s
< end
; s
+= 4, n
++) {
352 if (gen_spec_get_gen(spec
) >= gen_make_gen(8, 0)) {
353 offset
= *(uint64_t *) &s
[1];
354 dwend
= gtt
+ offset
+ s
[3];
357 dwend
= gtt
+ s
[2] + 1;
360 stride
= field(s
[0], 0, 11);
362 printf("vertex buffer %d, size %d\n", n
, s
[3]);
363 for (dw
= gtt
+ offset
, i
= 0; dw
< dwend
&& i
< 256; dw
++) {
364 if (count
== 0 && count
% (8 * 4) == 0)
367 if (probably_float(*dw
))
368 printf(" %8.2f", *(float *) dw
);
370 printf(" 0x%08x", *dw
);
375 if (count
== stride
) {
378 } else if (count
% (8 * 4) == 0) {
384 if (count
> 0 && count
% (8 * 4) != 0)
390 handle_3dstate_vs(struct gen_spec
*spec
, uint32_t *p
)
393 struct brw_instruction
*insns
;
396 if (gen_spec_get_gen(spec
) >= gen_make_gen(8, 0)) {
397 start
= get_qword(&p
[1]);
398 vs_enable
= p
[7] & 1;
401 vs_enable
= p
[5] & 1;
405 printf("instruction_base %08lx, start %08lx\n",
406 instruction_base
, start
);
408 insns
= (struct brw_instruction
*) (gtt
+ instruction_base
+ start
);
409 gen_disasm_disassemble(disasm
, insns
, 0, 8192, stdout
);
414 handle_3dstate_hs(struct gen_spec
*spec
, uint32_t *p
)
417 struct brw_instruction
*insns
;
420 if (gen_spec_get_gen(spec
) >= gen_make_gen(8, 0)) {
421 start
= get_qword(&p
[4]);
426 hs_enable
= p
[2] & 0x80000000;
429 printf("instruction_base %08lx, start %08lx\n",
430 instruction_base
, start
);
432 insns
= (struct brw_instruction
*) (gtt
+ instruction_base
+ start
);
433 gen_disasm_disassemble(disasm
, insns
, 0, 8192, stdout
);
438 handle_3dstate_constant(struct gen_spec
*spec
, uint32_t *p
)
444 for (i
= 0; i
< 4; i
++) {
445 length
= (p
[1 + i
/ 2] >> (i
& 1) * 16) & 0xffff;
446 f
= (float *) (gtt
+ p
[3 + i
* 2] + dynamic_state_base
);
448 for (j
= 0; j
< length
* 8; j
++) {
449 if (probably_float(dw
[j
]))
450 printf(" %04.3f", f
[j
]);
452 printf(" 0x%08x", dw
[j
]);
461 handle_3dstate_ps(struct gen_spec
*spec
, uint32_t *p
)
463 uint32_t mask
= ~((1 << 6) - 1);
465 struct brw_instruction
*insns
;
466 static const char unused
[] = "unused";
467 static const char *pixel_type
[3] = {"8 pixel", "16 pixel", "32 pixel"};
468 const char *k0
, *k1
, *k2
;
469 uint32_t k_mask
, k1_offset
, k2_offset
;
471 if (gen_spec_get_gen(spec
) >= gen_make_gen(8, 0)) {
482 #define DISPATCH_16 2
483 #define DISPATCH_32 4
496 case DISPATCH_8
| DISPATCH_16
:
506 case DISPATCH_16
| DISPATCH_32
:
511 case DISPATCH_8
| DISPATCH_16
| DISPATCH_32
:
523 start
= instruction_base
+ (p
[1] & mask
);
524 printf(" Kernel[0] %s\n", k0
);
526 insns
= (struct brw_instruction
*) (gtt
+ start
);
527 gen_disasm_disassemble(disasm
, insns
, 0, 8192, stdout
);
530 start
= instruction_base
+ (p
[k1_offset
] & mask
);
531 printf(" Kernel[1] %s\n", k1
);
533 insns
= (struct brw_instruction
*) (gtt
+ start
);
534 gen_disasm_disassemble(disasm
, insns
, 0, 8192, stdout
);
537 start
= instruction_base
+ (p
[k2_offset
] & mask
);
538 printf(" Kernel[2] %s\n", k2
);
540 insns
= (struct brw_instruction
*) (gtt
+ start
);
541 gen_disasm_disassemble(disasm
, insns
, 0, 8192, stdout
);
546 handle_3dstate_binding_table_pointers(struct gen_spec
*spec
, uint32_t *p
)
548 dump_binding_table(spec
, p
[1]);
552 handle_3dstate_sampler_state_pointers(struct gen_spec
*spec
, uint32_t *p
)
554 dump_samplers(spec
, p
[1]);
558 handle_3dstate_viewport_state_pointers_cc(struct gen_spec
*spec
, uint32_t *p
)
561 struct gen_group
*cc_viewport
;
563 cc_viewport
= gen_spec_find_struct(spec
, "CC_VIEWPORT");
565 start
= dynamic_state_base
+ (p
[1] & ~0x1fu
);
566 for (uint32_t i
= 0; i
< 4; i
++) {
567 printf("viewport %d\n", i
);
568 decode_structure(spec
, cc_viewport
, gtt
+ start
+ i
* 8);
573 handle_3dstate_viewport_state_pointers_sf_clip(struct gen_spec
*spec
,
577 struct gen_group
*sf_clip_viewport
;
579 sf_clip_viewport
= gen_spec_find_struct(spec
, "SF_CLIP_VIEWPORT");
581 start
= dynamic_state_base
+ (p
[1] & ~0x3fu
);
582 for (uint32_t i
= 0; i
< 4; i
++) {
583 printf("viewport %d\n", i
);
584 decode_structure(spec
, sf_clip_viewport
, gtt
+ start
+ i
* 64);
589 handle_3dstate_blend_state_pointers(struct gen_spec
*spec
, uint32_t *p
)
592 struct gen_group
*blend_state
;
594 blend_state
= gen_spec_find_struct(spec
, "BLEND_STATE");
596 start
= dynamic_state_base
+ (p
[1] & ~0x3fu
);
597 decode_structure(spec
, blend_state
, gtt
+ start
);
601 handle_3dstate_cc_state_pointers(struct gen_spec
*spec
, uint32_t *p
)
604 struct gen_group
*cc_state
;
606 cc_state
= gen_spec_find_struct(spec
, "COLOR_CALC_STATE");
608 start
= dynamic_state_base
+ (p
[1] & ~0x3fu
);
609 decode_structure(spec
, cc_state
, gtt
+ start
);
613 handle_3dstate_scissor_state_pointers(struct gen_spec
*spec
, uint32_t *p
)
616 struct gen_group
*scissor_rect
;
618 scissor_rect
= gen_spec_find_struct(spec
, "SCISSOR_RECT");
620 start
= dynamic_state_base
+ (p
[1] & ~0x1fu
);
621 decode_structure(spec
, scissor_rect
, gtt
+ start
);
624 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
626 #define STATE_BASE_ADDRESS 0x61010000
628 #define MEDIA_INTERFACE_DESCRIPTOR_LOAD 0x70020000
630 #define _3DSTATE_INDEX_BUFFER 0x780a0000
631 #define _3DSTATE_VERTEX_BUFFERS 0x78080000
633 #define _3DSTATE_VS 0x78100000
634 #define _3DSTATE_GS 0x78110000
635 #define _3DSTATE_HS 0x781b0000
636 #define _3DSTATE_DS 0x781d0000
638 #define _3DSTATE_CONSTANT_VS 0x78150000
639 #define _3DSTATE_CONSTANT_GS 0x78160000
640 #define _3DSTATE_CONSTANT_PS 0x78170000
641 #define _3DSTATE_CONSTANT_HS 0x78190000
642 #define _3DSTATE_CONSTANT_DS 0x781A0000
644 #define _3DSTATE_PS 0x78200000
646 #define _3DSTATE_BINDING_TABLE_POINTERS_VS 0x78260000
647 #define _3DSTATE_BINDING_TABLE_POINTERS_HS 0x78270000
648 #define _3DSTATE_BINDING_TABLE_POINTERS_DS 0x78280000
649 #define _3DSTATE_BINDING_TABLE_POINTERS_GS 0x78290000
650 #define _3DSTATE_BINDING_TABLE_POINTERS_PS 0x782a0000
652 #define _3DSTATE_SAMPLER_STATE_POINTERS_VS 0x782b0000
653 #define _3DSTATE_SAMPLER_STATE_POINTERS_GS 0x782e0000
654 #define _3DSTATE_SAMPLER_STATE_POINTERS_PS 0x782f0000
656 #define _3DSTATE_VIEWPORT_STATE_POINTERS_CC 0x78230000
657 #define _3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP 0x78210000
658 #define _3DSTATE_BLEND_STATE_POINTERS 0x78240000
659 #define _3DSTATE_CC_STATE_POINTERS 0x780e0000
660 #define _3DSTATE_SCISSOR_STATE_POINTERS 0x780f0000
662 struct custom_handler
{
664 void (*handle
)(struct gen_spec
*spec
, uint32_t *p
);
665 } custom_handlers
[] = {
666 { STATE_BASE_ADDRESS
, handle_state_base_address
},
667 { MEDIA_INTERFACE_DESCRIPTOR_LOAD
, handle_media_interface_descriptor_load
},
668 { _3DSTATE_VERTEX_BUFFERS
, handle_3dstate_vertex_buffers
},
669 { _3DSTATE_INDEX_BUFFER
, handle_3dstate_index_buffer
},
670 { _3DSTATE_VS
, handle_3dstate_vs
},
671 { _3DSTATE_GS
, handle_3dstate_vs
},
672 { _3DSTATE_DS
, handle_3dstate_vs
},
673 { _3DSTATE_HS
, handle_3dstate_hs
},
674 { _3DSTATE_CONSTANT_VS
, handle_3dstate_constant
},
675 { _3DSTATE_CONSTANT_GS
, handle_3dstate_constant
},
676 { _3DSTATE_CONSTANT_PS
, handle_3dstate_constant
},
677 { _3DSTATE_CONSTANT_HS
, handle_3dstate_constant
},
678 { _3DSTATE_CONSTANT_DS
, handle_3dstate_constant
},
679 { _3DSTATE_PS
, handle_3dstate_ps
},
681 { _3DSTATE_BINDING_TABLE_POINTERS_VS
, handle_3dstate_binding_table_pointers
},
682 { _3DSTATE_BINDING_TABLE_POINTERS_HS
, handle_3dstate_binding_table_pointers
},
683 { _3DSTATE_BINDING_TABLE_POINTERS_DS
, handle_3dstate_binding_table_pointers
},
684 { _3DSTATE_BINDING_TABLE_POINTERS_GS
, handle_3dstate_binding_table_pointers
},
685 { _3DSTATE_BINDING_TABLE_POINTERS_PS
, handle_3dstate_binding_table_pointers
},
687 { _3DSTATE_SAMPLER_STATE_POINTERS_VS
, handle_3dstate_sampler_state_pointers
},
688 { _3DSTATE_SAMPLER_STATE_POINTERS_GS
, handle_3dstate_sampler_state_pointers
},
689 { _3DSTATE_SAMPLER_STATE_POINTERS_PS
, handle_3dstate_sampler_state_pointers
},
691 { _3DSTATE_VIEWPORT_STATE_POINTERS_CC
, handle_3dstate_viewport_state_pointers_cc
},
692 { _3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
, handle_3dstate_viewport_state_pointers_sf_clip
},
693 { _3DSTATE_BLEND_STATE_POINTERS
, handle_3dstate_blend_state_pointers
},
694 { _3DSTATE_CC_STATE_POINTERS
, handle_3dstate_cc_state_pointers
},
695 { _3DSTATE_SCISSOR_STATE_POINTERS
, handle_3dstate_scissor_state_pointers
}
699 parse_commands(struct gen_spec
*spec
, uint32_t *cmds
, int size
, int engine
)
701 uint32_t *p
, *end
= cmds
+ size
/ 4;
702 unsigned int length
, i
;
703 struct gen_group
*inst
;
705 for (p
= cmds
; p
< end
; p
+= length
) {
706 inst
= gen_spec_find_instruction(spec
, p
);
708 printf("unknown instruction %08x\n", p
[0]);
709 length
= (p
[0] & 0xff) + 2;
712 length
= gen_group_get_length(inst
, p
);
714 const char *color
, *reset_color
= CLEAR_TO_EOL NORMAL
;
717 if (option_full_decode
)
722 if (option_color
== COLOR_NEVER
) {
727 if (option_print_offsets
)
728 offset
= (void *) p
- gtt
;
732 printf("%s0x%08lx: 0x%08x: %s%s\n",
734 gen_group_get_name(inst
), reset_color
);
736 if (option_full_decode
) {
737 struct gen_field_iterator iter
;
739 int idx
= 0, dword_num
= 0;
740 gen_field_iterator_init(&iter
, inst
, p
);
741 while (gen_field_iterator_next(&iter
)) {
743 print_dword_val(&iter
, offset
, &dword_num
);
745 token
= print_iterator_values(&iter
, &idx
);
747 printf("0x%08lx: 0x%08x : Dword %d\n",
748 offset
+ 4 * idx
, p
[idx
], idx
);
749 handle_struct_decode(spec
,token
, &p
[idx
]);
754 for (i
= 0; i
< ARRAY_LENGTH(custom_handlers
); i
++) {
755 if (gen_group_get_opcode(inst
) ==
756 custom_handlers
[i
].opcode
)
757 custom_handlers
[i
].handle(spec
, p
);
761 if ((p
[0] & 0xffff0000) == AUB_MI_BATCH_BUFFER_START
) {
763 if (gen_spec_get_gen(spec
) >= gen_make_gen(8,0))
764 start
= get_qword(&p
[1]);
768 parse_commands(spec
, gtt
+ start
, 1 << 20, engine
);
769 } else if ((p
[0] & 0xffff0000) == AUB_MI_BATCH_BUFFER_END
) {
775 #define GEN_ENGINE_RENDER 1
776 #define GEN_ENGINE_BLITTER 2
779 handle_trace_block(struct gen_spec
*spec
, uint32_t *p
)
781 int operation
= p
[1] & AUB_TRACE_OPERATION_MASK
;
782 int type
= p
[1] & AUB_TRACE_TYPE_MASK
;
783 int address_space
= p
[1] & AUB_TRACE_ADDRESS_SPACE_MASK
;
784 uint64_t offset
= p
[3];
785 uint32_t size
= p
[4];
786 int header_length
= p
[0] & 0xffff;
787 uint32_t *data
= p
+ header_length
+ 2;
788 int engine
= GEN_ENGINE_RENDER
;
790 if (gen_spec_get_gen(spec
) >= gen_make_gen(8,0))
791 offset
+= (uint64_t) p
[5] << 32;
794 case AUB_TRACE_OP_DATA_WRITE
:
795 if (address_space
!= AUB_TRACE_MEMTYPE_GTT
)
797 if (gtt_size
< offset
+ size
) {
798 fprintf(stderr
, "overflow gtt space: %s", strerror(errno
));
801 memcpy((char *) gtt
+ offset
, data
, size
);
802 if (gtt_end
< offset
+ size
)
803 gtt_end
= offset
+ size
;
805 case AUB_TRACE_OP_COMMAND_WRITE
:
807 case AUB_TRACE_TYPE_RING_PRB0
:
808 engine
= GEN_ENGINE_RENDER
;
810 case AUB_TRACE_TYPE_RING_PRB2
:
811 engine
= GEN_ENGINE_BLITTER
;
814 printf("command write to unknown ring %d\n", type
);
818 parse_commands(spec
, data
, size
, engine
);
828 uint32_t *map
, *end
, *cursor
;
831 static struct aub_file
*
832 aub_file_open(const char *filename
)
834 struct aub_file
*file
;
836 file
= malloc(sizeof *file
);
837 file
->filename
= strdup(filename
);
838 file
->fd
= open(file
->filename
, O_RDONLY
);
839 if (file
->fd
== -1) {
840 fprintf(stderr
, "open %s failed: %s", file
->filename
, strerror(errno
));
844 if (fstat(file
->fd
, &file
->sb
) == -1) {
845 fprintf(stderr
, "stat failed: %s", strerror(errno
));
849 file
->map
= mmap(NULL
, file
->sb
.st_size
,
850 PROT_READ
, MAP_SHARED
, file
->fd
, 0);
851 if (file
->map
== MAP_FAILED
) {
852 fprintf(stderr
, "mmap failed: %s", strerror(errno
));
856 file
->cursor
= file
->map
;
857 file
->end
= file
->map
+ file
->sb
.st_size
/ 4;
859 /* mmap a terabyte for our gtt space. */
860 gtt_size
= 1ul << 40;
861 gtt
= mmap(NULL
, gtt_size
, PROT_READ
| PROT_WRITE
,
862 MAP_PRIVATE
| MAP_ANONYMOUS
| MAP_NORESERVE
, -1, 0);
863 if (gtt
== MAP_FAILED
) {
864 fprintf(stderr
, "failed to alloc gtt space: %s", strerror(errno
));
871 #define TYPE(dw) (((dw) >> 29) & 7)
872 #define OPCODE(dw) (((dw) >> 23) & 0x3f)
873 #define SUBOPCODE(dw) (((dw) >> 16) & 0x7f)
875 #define MAKE_HEADER(type, opcode, subopcode) \
876 (((type) << 29) | ((opcode) << 23) | ((subopcode) << 16))
880 /* Classic AUB opcodes */
881 #define OPCODE_AUB 0x01
882 #define SUBOPCODE_HEADER 0x05
883 #define SUBOPCODE_BLOCK 0x41
884 #define SUBOPCODE_BMP 0x1e
886 /* Newer version AUB opcode */
887 #define OPCODE_NEW_AUB 0x2e
888 #define SUBOPCODE_VERSION 0x00
889 #define SUBOPCODE_REG_WRITE 0x03
890 #define SUBOPCODE_MEM_POLL 0x05
891 #define SUBOPCODE_MEM_WRITE 0x06
893 #define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) )
899 { "bwr", MAKE_GEN(4, 0) },
900 { "cln", MAKE_GEN(4, 0) },
901 { "blc", MAKE_GEN(4, 0) },
902 { "ctg", MAKE_GEN(4, 0) },
903 { "el", MAKE_GEN(4, 0) },
904 { "il", MAKE_GEN(4, 0) },
905 { "sbr", MAKE_GEN(6, 0) },
906 { "ivb", MAKE_GEN(7, 0) },
907 { "lrb2", MAKE_GEN(0, 0) },
908 { "hsw", MAKE_GEN(7, 5) },
909 { "vlv", MAKE_GEN(7, 0) },
910 { "bdw", MAKE_GEN(8, 0) },
911 { "skl", MAKE_GEN(9, 0) },
912 { "chv", MAKE_GEN(8, 0) },
913 { "bxt", MAKE_GEN(9, 0) }
917 aub_file_decode_batch(struct aub_file
*file
, struct gen_spec
*spec
)
919 uint32_t *p
, h
, device
, data_type
;
920 int header_length
, payload_size
, bias
;
924 header_length
= h
& 0xffff;
934 printf("unknown opcode %d at %ld/%ld\n",
935 OPCODE(h
), file
->cursor
- file
->map
,
936 file
->end
- file
->map
);
937 file
->cursor
= file
->end
;
942 switch (h
& 0xffff0000) {
943 case MAKE_HEADER(TYPE_AUB
, OPCODE_AUB
, SUBOPCODE_HEADER
):
944 payload_size
= p
[12];
946 case MAKE_HEADER(TYPE_AUB
, OPCODE_AUB
, SUBOPCODE_BLOCK
):
948 handle_trace_block(spec
, p
);
950 case MAKE_HEADER(TYPE_AUB
, OPCODE_AUB
, SUBOPCODE_BMP
):
953 case MAKE_HEADER(TYPE_AUB
, OPCODE_NEW_AUB
, SUBOPCODE_VERSION
):
954 printf("version block: dw1 %08x\n", p
[1]);
955 device
= (p
[1] >> 8) & 0xff;
956 printf(" device %s\n", device_map
[device
].name
);
958 case MAKE_HEADER(TYPE_AUB
, OPCODE_NEW_AUB
, SUBOPCODE_REG_WRITE
):
959 printf("register write block: (dwords %d)\n", h
& 0xffff);
960 printf(" reg 0x%x, data 0x%x\n", p
[1], p
[5]);
962 case MAKE_HEADER(TYPE_AUB
, OPCODE_NEW_AUB
, SUBOPCODE_MEM_WRITE
):
963 printf("memory write block (dwords %d):\n", h
& 0xffff);
964 printf(" address 0x%lx\n", *(uint64_t *) &p
[1]);
965 data_type
= (p
[3] >> 20) & 0xff;
967 printf(" data type 0x%x\n", data_type
);
968 printf(" address space 0x%x\n", (p
[3] >> 28) & 0xf);
970 case MAKE_HEADER(TYPE_AUB
, OPCODE_NEW_AUB
, SUBOPCODE_MEM_POLL
):
971 printf("memory poll block (dwords %d):\n", h
& 0xffff);
974 printf("unknown block type=0x%x, opcode=0x%x, "
975 "subopcode=0x%x (%08x)\n", TYPE(h
), OPCODE(h
), SUBOPCODE(h
), h
);
978 file
->cursor
= p
+ header_length
+ bias
+ payload_size
/ 4;
982 aub_file_more_stuff(struct aub_file
*file
)
984 return file
->cursor
< file
->end
;
1006 execlp("less", "less", "-rFi", NULL
);
1015 print_help(FILE *file
)
1017 const char *progname
;
1018 #if defined(__GLIBC__) || defined(__CYGWIN__)
1019 progname
= program_invocation_short_name
;
1021 progname
= getprogname();
1024 "Usage: %s [OPTION]... FILE\n"
1025 "Decode aub file contents.\n\n"
1026 "A valid --gen option must be provided.\n\n"
1027 " --help display this help and exit\n"
1028 " --gen=platform decode for given platform (ivb, byt, hsw, bdw, chv, skl, kbl or bxt)\n"
1029 " --headers decode only command headers\n"
1030 " --color[=WHEN] colorize the output; WHEN can be 'auto' (default\n"
1031 " if omitted), 'always', or 'never'\n"
1032 " --no-pager don't launch pager\n"
1033 " --no-offsets don't print instruction offsets\n",
1034 basename(progname
));
1038 is_prefix(const char *arg
, const char *prefix
, const char **value
)
1040 int l
= strlen(prefix
);
1042 if (strncmp(arg
, prefix
, l
) == 0 && (arg
[l
] == '\0' || arg
[l
] == '=')) {
1044 *value
= arg
+ l
+ 1;
1054 int main(int argc
, char *argv
[])
1056 struct gen_spec
*spec
;
1057 struct aub_file
*file
;
1059 bool found_arg_gen
= false, pager
= true;
1060 int gen_major
, gen_minor
;
1062 char gen_file
[256], gen_val
[24];
1069 for (i
= 1; i
< argc
; ++i
) {
1070 if (strcmp(argv
[i
], "--no-pager") == 0) {
1072 } else if (strcmp(argv
[i
], "--no-offsets") == 0) {
1073 option_print_offsets
= false;
1074 } else if (is_prefix(argv
[i
], "--gen", &value
)) {
1075 if (value
== NULL
) {
1076 fprintf(stderr
, "option '--gen' requires an argument\n");
1079 found_arg_gen
= true;
1082 snprintf(gen_val
, sizeof(gen_val
), "%s", value
);
1083 } else if (strcmp(argv
[i
], "--headers") == 0) {
1084 option_full_decode
= false;
1085 } else if (is_prefix(argv
[i
], "--color", &value
)) {
1086 if (value
== NULL
|| strcmp(value
, "always") == 0)
1087 option_color
= COLOR_ALWAYS
;
1088 else if (strcmp(value
, "never") == 0)
1089 option_color
= COLOR_NEVER
;
1090 else if (strcmp(value
, "auto") == 0)
1091 option_color
= COLOR_AUTO
;
1093 fprintf(stderr
, "invalid value for --color: %s", value
);
1096 } else if (strcmp(argv
[i
], "--help") == 0) {
1100 if (argv
[i
][0] == '-') {
1101 fprintf(stderr
, "unknown option %s\n", argv
[i
]);
1108 if (!found_arg_gen
) {
1109 fprintf(stderr
, "argument --gen is required\n");
1113 if (strstr(gen_val
, "ivb") != NULL
) {
1114 /* Intel(R) Ivybridge Mobile GT2 */
1118 } else if (strstr(gen_val
, "hsw") != NULL
) {
1119 /* Intel(R) Haswell Mobile GT2 */
1123 } else if (strstr(gen_val
, "byt") != NULL
) {
1124 /* Intel(R) Bay Trail */
1128 } else if (strstr(gen_val
, "bdw") != NULL
) {
1129 /* Intel(R) HD Graphics 5500 (Broadwell GT2) */
1133 } else if (strstr(gen_val
, "chv") != NULL
) {
1134 /* Intel(R) HD Graphics (Cherryview) */
1138 } else if (strstr(gen_val
, "skl") != NULL
) {
1139 /* Intel(R) HD Graphics 530 (Skylake GT2) */
1143 } else if (strstr(gen_val
, "kbl") != NULL
) {
1144 /* Intel(R) Kabylake GT2 */
1148 } else if (strstr(gen_val
, "bxt") != NULL
) {
1149 /* Intel(R) HD Graphics (Broxton) */
1154 fprintf(stderr
, "can't parse gen: %s, expected ivb, byt, hsw, "
1155 "bdw, chv, skl, kbl or bxt\n", gen_val
);
1159 /* Do this before we redirect stdout to pager. */
1160 if (option_color
== COLOR_AUTO
)
1161 option_color
= isatty(1) ? COLOR_ALWAYS
: COLOR_NEVER
;
1163 if (isatty(1) && pager
)
1166 if (gen_minor
> 0) {
1167 snprintf(gen_file
, sizeof(gen_file
), "../genxml/gen%d%d.xml",
1168 gen_major
, gen_minor
);
1170 snprintf(gen_file
, sizeof(gen_file
), "../genxml/gen%d.xml", gen_major
);
1173 spec
= gen_spec_load(gen_file
);
1174 disasm
= gen_disasm_create(pci_id
);
1176 if (argv
[i
] == NULL
) {
1180 file
= aub_file_open(argv
[i
]);
1183 while (aub_file_more_stuff(file
))
1184 aub_file_decode_batch(file
, spec
);
1187 /* close the stdout which is opened to write the output */
1192 return EXIT_SUCCESS
;