6 #include "intel_driver.h"
7 #include "intel_batchbuffer_dump.h"
9 #define BUFFER_FAIL(_count, _len, _name) do { \
10 fprintf(gout, "Buffer size too small in %s (%d < %d)\n", \
11 (_name), (_count), (_len)); \
19 instr_out(unsigned int *data, unsigned int offset, unsigned int index, char *fmt, ...)
23 fprintf(gout, "0x%08x: 0x%08x:%s ", offset + index * 4, data[index],
24 index == 0 ? "" : " ");
26 vfprintf(gout, fmt, va);
32 dump_mi(unsigned int *data, unsigned int offset, int count, unsigned int device, int *failures)
44 { 0x00, 0, 1, 1, "MI_NOOP" },
45 { 0x04, 0, 1, 1, "MI_FLUSH" },
46 { 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" },
49 opcode = ((data[0] & MASK_MI_OPCODE) >> SHIFT_MI_OPCODE);
51 for (i = 0; i < sizeof(mi_commands) / sizeof(mi_commands[0]); i++) {
52 if (opcode == mi_commands[i].opcode) {
56 instr_out(data, offset, 0, "%s\n", mi_commands[i].name);
58 if (mi_commands[i].max_len > 1) {
59 length = (data[0] & mi_commands[i].mask_length) + 2;
61 if (length < mi_commands[i].min_len ||
62 length > mi_commands[i].max_len) {
63 fprintf(gout, "Bad length (%d) in %s, [%d, %d]\n",
64 length, mi_commands[i].name,
65 mi_commands[i].min_len,
66 mi_commands[i].max_len);
70 for (index = 1; index < length; index++) {
72 BUFFER_FAIL(count, length, mi_commands[i].name);
74 instr_out(data, offset, index, "dword %d\n", index);
81 instr_out(data, offset, 0, "UNKNOWN MI COMMAND\n");
87 dump_gfxpipe_3d(unsigned int *data, unsigned int offset, int count, unsigned int device, int *failures)
89 instr_out(data, offset, 0, "UNKNOWN 3D COMMAND\n");
96 dump_avc_bsd_img_state(unsigned int *data, unsigned int offset, unsigned int device, int *failures)
98 int img_struct = ((data[3] >> 8) & 0x3);
100 instr_out(data, offset, 1, "frame size: %d\n", (data[1] & 0xffff));
101 instr_out(data, offset, 2, "width: %d, height: %d\n", (data[2] & 0xff), (data[2] >> 16) & 0xff);
102 instr_out(data, offset, 3,
103 "second_chroma_qp_offset: %d,"
104 "chroma_qp_offset: %d,"
105 "QM present flag: %d,"
107 "img_dec_fs_idc: %d,"
109 (data[3] >> 24) & 0x1f,
110 (data[3] >> 16) & 0x1f,
111 (data[3] >> 10) & 0x1,
112 (img_struct == 0) ? "frame" : (img_struct == 2) ? "invalid" : (img_struct == 1) ? "top field" : "bottom field",
114 instr_out(data, offset, 4,
115 "residual off: 0x%x,"
120 "constrained intra: %d,"
126 (data[4] >> 24) & 0xff,
127 (data[4] >> 12) & 0x1,
128 (data[4] >> 10) & 0x3,
129 (data[4] >> 7) & 0x1,
130 (data[4] >> 6) & 0x1,
131 (data[4] >> 5) & 0x1,
132 (data[4] >> 4) & 0x1,
133 (data[4] >> 3) & 0x1,
134 (data[4] >> 2) & 0x1,
135 (data[4] >> 1) & 0x1);
136 instr_out(data, offset, 5, "AVC-IT Command Header\n");
140 dump_avc_bsd_qm_state(unsigned int *data, unsigned int offset, unsigned int device, int *failures)
142 unsigned int length = ((data[0] & MASK_GFXPIPE_LENGTH) >> SHIFT_GFXPIPE_LENGTH) + 2;
145 instr_out(data, offset, 1, "user default: %02x, QM list present: %02x\n",
146 (data[1] >> 8) & 0xff, data[1] & 0xff);
148 for (i = 2; i < length; i++) {
149 instr_out(data, offset, i, "dword %d\n", i);
154 dump_avc_bsd_slice_state(unsigned int *data, unsigned int offset, unsigned int device, int *failures)
160 dump_avc_bsd_buf_base_state(unsigned int *data, unsigned int offset, unsigned int device, int *failures)
164 instr_out(data, offset, 1, "BSD row store base address\n");
165 instr_out(data, offset, 2, "MPR row store base address\n");
166 instr_out(data, offset, 3, "AVC-IT command buffer base address\n");
167 instr_out(data, offset, 4, "AVC-IT data buffer: 0x%08x, write offset: 0x%x\n",
168 data[4] & 0xFFFFF000, data[4] & 0xFC0);
169 instr_out(data, offset, 5, "ILDB data buffer\n");
171 for (i = 6; i < 38; i++) {
172 instr_out(data, offset, i, "Direct MV read base address for reference frame %d\n", i - 6);
175 instr_out(data, offset, 38, "direct mv wr0 top\n");
176 instr_out(data, offset, 39, "direct mv wr0 bottom\n");
178 for (i = 40; i < 74; i++) {
179 instr_out(data, offset, i, "POC List %d\n", i - 40);
184 dump_bsd_ind_obj_base_addr(unsigned int *data, unsigned int offset, unsigned int device, int *failures)
186 instr_out(data, offset, 1, "AVC indirect object base address\n");
187 instr_out(data, offset, 2, "AVC Indirect Object Access Upper Bound\n");
191 dump_ironlake_avc_bsd_object(unsigned int *data, unsigned int offset, int *failures)
193 int slice_type = data[3] & 0xf;
194 int i, is_phantom = ((data[1] & 0x3fffff) == 0);
197 instr_out(data, offset, 1, "Encrypted: %d, bitsteam length: %d\n", data[1] >> 31, data[1] & 0x3fffff);
198 instr_out(data, offset, 2, "Indirect Data Start Address: %d\n", data[2] & 0x1fffffff);
199 instr_out(data, offset, 3, "%s Slice\n", slice_type == 0 ? "P" : slice_type == 1 ? "B" : "I");
200 instr_out(data, offset, 4,
201 "Num_Ref_Idx_L1: %d,"
202 "Num_Ref_Idx_L0: %d,"
203 "Log2WeightDenomChroma: %d,"
204 "Log2WeightDenomLuma: %d"
206 (data[4] >> 24) & 0x3f,
207 (data[4] >> 16) & 0x3f,
208 (data[4] >> 8) & 0x3,
209 (data[4] >> 0) & 0x3);
210 instr_out(data, offset, 5,
211 "WeightedPredIdc: %d,"
212 "DirectPredType: %d,"
213 "DisableDeblockingFilter: %d,"
216 "SliceBetaOffsetDiv2: %d,"
217 "SliceAlphaC0OffsetDiv2: %d"
219 (data[5] >> 30) & 0x3,
220 (data[5] >> 29) & 0x1,
221 (data[5] >> 27) & 0x3,
222 (data[5] >> 24) & 0x3,
223 (data[5] >> 16) & 0x3f,
224 (data[5] >> 8) & 0xf,
225 (data[5] >> 0) & 0xf);
226 instr_out(data, offset, 6,
227 "Slice_MB_Start_Vert_Pos: %d,"
228 "Slice_MB_Start_Hor_Pos: %d,"
229 "Slice_Start_Mb_Num: %d"
231 (data[6] >> 24) & 0xff,
232 (data[6] >> 16) & 0xff,
233 (data[6] >> 0) & 0x7fff);
234 instr_out(data, offset, 7,
235 "Fix_Prev_Mb_Skipped: %d,"
236 "First_MB_Bit_Offset: %d"
238 (data[7] >> 7) & 0x1,
239 (data[7] >> 0) & 0x7);
241 for (i = 8; i < 16; i++)
242 instr_out(data, offset, i, "dword %d\n", i);
244 instr_out(data, offset, 1, "phantom slice\n");
246 for (i = 2; i < 6; i++)
247 instr_out(data, offset, i, "dword %d\n", i);
249 instr_out(data, offset, 6,
250 "Slice_Start_Mb_Num: %d"
252 (data[6] >> 0) & 0x7fff);
254 for (i = 7; i < 16; i++)
255 instr_out(data, offset, i, "dword %d\n", i);
261 dump_g4x_avc_bsd_object(unsigned int *data, unsigned int offset, int *failures)
267 dump_avc_bsd_object(unsigned int *data, unsigned int offset, unsigned int device, int *failures)
269 if (IS_IRONLAKE(device))
270 dump_ironlake_avc_bsd_object(data, offset, failures);
272 dump_g4x_avc_bsd_object(data, offset, failures);
276 dump_bsd_avc(unsigned int *data, unsigned int offset, int count, unsigned int device, int *failures)
278 unsigned int subopcode;
282 unsigned int subopcode;
286 void (*detail)(unsigned int *data, unsigned int offset, unsigned int device, int *failures);
288 { 0x00, 0x06, 0x06, "AVC_BSD_IMG_STATE", dump_avc_bsd_img_state },
289 { 0x01, 0x02, 0x3a, "AVC_BSD_QM_STATE", dump_avc_bsd_qm_state },
290 { 0x02, 0x02, 0xd2, "AVC_BSD_SLICE_STATE", NULL },
291 { 0x03, 0x4a, 0x4a, "AVC_BSD_BUF_BASE_STATE", dump_avc_bsd_buf_base_state },
292 { 0x04, 0x03, 0x03, "BSD_IND_OBJ_BASE_ADDR", dump_bsd_ind_obj_base_addr },
293 { 0x08, 0x08, 0x10, "AVC_BSD_OBJECT", dump_avc_bsd_object },
296 subopcode = ((data[0] & MASK_GFXPIPE_SUBOPCODE) >> SHIFT_GFXPIPE_SUBOPCODE);
298 for (i = 0; i < sizeof(avc_commands) / sizeof(avc_commands[0]); i++) {
299 if (subopcode == avc_commands[i].subopcode) {
302 length = (data[0] & MASK_GFXPIPE_LENGTH) >> SHIFT_GFXPIPE_LENGTH;
304 instr_out(data, offset, 0, "%s\n", avc_commands[i].name);
306 if (length < avc_commands[i].min_len ||
307 length > avc_commands[i].max_len) {
308 fprintf(gout, "Bad length(%d) in %s [%d, %d]\n",
309 length, avc_commands[i].name,
310 avc_commands[i].min_len,
311 avc_commands[i].max_len);
314 if (length - 1 >= count)
315 BUFFER_FAIL(count, length, avc_commands[i].name);
317 if (avc_commands[i].detail)
318 avc_commands[i].detail(data, offset, device, failures);
320 for (index = 1; index < length; index++)
321 instr_out(data, offset, index, "dword %d\n", index);
328 instr_out(data, offset, 0, "UNKNOWN AVC COMMAND\n");
334 dump_gfxpipe_bsd(unsigned int *data, unsigned int offset, int count, unsigned int device, int *failures)
338 switch ((data[0] & MASK_GFXPIPE_OPCODE) >> SHIFT_GFXPIPE_OPCODE) {
340 length = dump_bsd_avc(data, offset, count, device, failures);
346 instr_out(data, offset, 0, "UNKNOWN BSD OPCODE\n");
354 dump_gfxpipe(unsigned int *data, unsigned int offset, int count, unsigned int device, int *failures)
358 switch ((data[0] & MASK_GFXPIPE_SUBTYPE) >> SHIFT_GFXPIPE_SUBTYPE) {
360 length = dump_gfxpipe_3d(data, offset, count, device, failures);
364 length = dump_gfxpipe_bsd(data, offset, count, device, failures);
370 instr_out(data, offset, 0, "UNKNOWN GFXPIPE COMMAND\n");
377 int intel_batchbuffer_dump(unsigned int *data, unsigned int offset, int count, unsigned int device)
382 gout = fopen("/tmp/bsd_command_dump.txt", "w+");
384 while (index < count) {
385 switch ((data[index] & MASK_CMD_TYPE) >> SHIFT_CMD_TYPE) {
387 index += dump_mi(data + index, offset + index * 4,
388 count - index, device, &failures);
391 case CMD_TYPE_GFXPIPE:
392 index += dump_gfxpipe(data + index, offset + index * 4,
393 count - index, device, &failures);
397 instr_out(data, offset, index, "UNKNOWN COMMAND\n");