1 /* -*- c-basic-offset: 4 -*- */
3 * Copyright © 2007 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Eric Anholt <eric@anholt.net>
29 /** @file intel_decode.c
30 * This file contains code to print out batchbuffer contents in a
31 * human-readable format.
33 * The current version only supports i915 packets, and only pretty-prints a
34 * subset of them. The intention is for it to make just a best attempt to
35 * decode, but never crash in the process.
42 #include "intel_decode.h"
43 #include "intel_chipset.h"
45 #define BUFFER_FAIL(_count, _len, _name) do { \
46 fprintf(out, "Buffer size too small in %s (%d < %d)\n", \
47 (_name), (_count), (_len)); \
53 static uint32_t saved_s2 = 0, saved_s4 = 0;
54 static char saved_s2_set = 0, saved_s4_set = 0;
57 int_as_float(uint32_t intval)
69 instr_out(uint32_t *data, uint32_t hw_offset, unsigned int index,
74 fprintf(out, "0x%08x: 0x%08x:%s ", hw_offset + index * 4, data[index],
75 index == 0 ? "" : " ");
77 vfprintf(out, fmt, va);
83 decode_mi(uint32_t *data, int count, uint32_t hw_offset, int *failures)
93 { 0x08, 1, 1, "MI_ARB_ON_OFF" },
94 { 0x0a, 1, 1, "MI_BATCH_BUFFER_END" },
95 { 0x31, 2, 2, "MI_BATCH_BUFFER_START" },
96 { 0x14, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
97 { 0x04, 1, 1, "MI_FLUSH" },
98 { 0x22, 3, 3, "MI_LOAD_REGISTER_IMM" },
99 { 0x13, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
100 { 0x12, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
101 { 0x00, 1, 1, "MI_NOOP" },
102 { 0x11, 2, 2, "MI_OVERLAY_FLIP" },
103 { 0x07, 1, 1, "MI_REPORT_HEAD" },
104 { 0x18, 2, 2, "MI_SET_CONTEXT" },
105 { 0x20, 3, 4, "MI_STORE_DATA_IMM" },
106 { 0x21, 3, 4, "MI_STORE_DATA_INDEX" },
107 { 0x24, 3, 3, "MI_STORE_REGISTER_MEM" },
108 { 0x02, 1, 1, "MI_USER_INTERRUPT" },
109 { 0x03, 1, 1, "MI_WAIT_FOR_EVENT" },
113 for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
115 if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
116 unsigned int len = 1, i;
118 instr_out(data, hw_offset, 0, "%s\n", opcodes_mi[opcode].name);
119 if (opcodes_mi[opcode].max_len > 1) {
120 len = (data[0] & 0x000000ff) + 2;
121 if (len < opcodes_mi[opcode].min_len ||
122 len > opcodes_mi[opcode].max_len)
124 fprintf(out, "Bad length in %s\n",
125 opcodes_mi[opcode].name);
129 for (i = 1; i < len; i++) {
131 BUFFER_FAIL(count, len, opcodes_mi[opcode].name);
132 instr_out(data, hw_offset, i, "dword %d\n", i);
139 instr_out(data, hw_offset, 0, "MI UNKNOWN\n");
145 decode_2d(uint32_t *data, int count, uint32_t hw_offset, int *failures)
147 unsigned int opcode, len;
156 { 0x40, 5, 5, "COLOR_BLT" },
157 { 0x43, 6, 6, "SRC_COPY_BLT" },
158 { 0x01, 8, 8, "XY_SETUP_BLT" },
159 { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
160 { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
161 { 0x24, 2, 2, "XY_PIXEL_BLT" },
162 { 0x25, 3, 3, "XY_SCANLINES_BLT" },
163 { 0x26, 4, 4, "Y_TEXT_BLT" },
164 { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
165 { 0x50, 6, 6, "XY_COLOR_BLT" },
166 { 0x51, 6, 6, "XY_PAT_BLT" },
167 { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
168 { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
169 { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
170 { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
171 { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
172 { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
173 { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
174 { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
175 { 0x55, 9, 9, "XY_FULL_BLT" },
176 { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
177 { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
178 { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
179 { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
180 { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT" },
183 switch ((data[0] & 0x1fc00000) >> 22) {
185 instr_out(data, hw_offset, 0,
186 "XY_COLOR_BLT (rgb %sabled, alpha %sabled)\n",
187 (data[0] & (1 << 20)) ? "en" : "dis",
188 (data[0] & (1 << 21)) ? "en" : "dis");
190 len = (data[0] & 0x000000ff) + 2;
192 fprintf(out, "Bad count in XY_COLOR_BLT\n");
194 BUFFER_FAIL(count, len, "XY_COLOR_BLT");
196 switch ((data[1] >> 24) & 0x3) {
211 instr_out(data, hw_offset, 1, "format %s, pitch %d, "
212 "clipping %sabled\n", format,
213 data[1] & 0xffff, data[1] & (1 << 30) ? "en" : "dis");
214 instr_out(data, hw_offset, 2, "(%d,%d)\n",
215 data[2] & 0xffff, data[2] >> 16);
216 instr_out(data, hw_offset, 3, "(%d,%d)\n",
217 data[3] & 0xffff, data[3] >> 16);
218 instr_out(data, hw_offset, 4, "offset 0x%08x\n", data[4]);
219 instr_out(data, hw_offset, 5, "color\n");
222 instr_out(data, hw_offset, 0,
223 "XY_SRC_COPY_BLT (rgb %sabled, alpha %sabled)\n",
224 (data[0] & (1 << 20)) ? "en" : "dis",
225 (data[0] & (1 << 21)) ? "en" : "dis");
227 len = (data[0] & 0x000000ff) + 2;
229 fprintf(out, "Bad count in XY_SRC_COPY_BLT\n");
231 BUFFER_FAIL(count, len, "XY_SRC_COPY_BLT");
233 switch ((data[1] >> 24) & 0x3) {
248 instr_out(data, hw_offset, 1, "format %s, dst pitch %d, "
249 "clipping %sabled\n", format,
250 data[1] & 0xffff, data[1] & (1 << 30) ? "en" : "dis");
251 instr_out(data, hw_offset, 2, "dst (%d,%d)\n",
252 data[2] & 0xffff, data[2] >> 16);
253 instr_out(data, hw_offset, 3, "dst (%d,%d)\n",
254 data[2] & 0xffff, data[2] >> 16);
255 instr_out(data, hw_offset, 4, "dst offset 0x%08x\n", data[4]);
256 instr_out(data, hw_offset, 5, "src (%d,%d)\n",
257 data[5] & 0xffff, data[5] >> 16);
258 instr_out(data, hw_offset, 6, "src pitch %d\n",
260 instr_out(data, hw_offset, 7, "src offset 0x%08x\n", data[7]);
264 for (opcode = 0; opcode < sizeof(opcodes_2d) / sizeof(opcodes_2d[0]);
266 if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) {
270 instr_out(data, hw_offset, 0, "%s\n", opcodes_2d[opcode].name);
271 if (opcodes_2d[opcode].max_len > 1) {
272 len = (data[0] & 0x000000ff) + 2;
273 if (len < opcodes_2d[opcode].min_len ||
274 len > opcodes_2d[opcode].max_len)
276 fprintf(out, "Bad count in %s\n", opcodes_2d[opcode].name);
280 for (i = 1; i < len; i++) {
282 BUFFER_FAIL(count, len, opcodes_2d[opcode].name);
283 instr_out(data, hw_offset, i, "dword %d\n", i);
290 instr_out(data, hw_offset, 0, "2D UNKNOWN\n");
296 decode_3d_1c(uint32_t *data, int count, uint32_t hw_offset, int *failures)
298 switch ((data[0] & 0x00f80000) >> 19) {
300 instr_out(data, hw_offset, 0, "3DSTATE_DEPTH_SUBRECTANGLE_DISALBE\n");
303 instr_out(data, hw_offset, 0, "3DSTATE_SCISSOR_ENABLE\n");
307 instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
313 decode_3d_1d(uint32_t *data, int count, uint32_t hw_offset, int *failures)
315 unsigned int len, i, c, opcode, word, map, sampler, instr;
322 } opcodes_3d_1d[] = {
323 { 0x8e, 3, 3, "3DSTATE_BUFFER_INFO" },
324 { 0x86, 4, 4, "3DSTATE_CHROMA_KEY" },
325 { 0x9c, 1, 1, "3DSTATE_CLEAR_PARAMETERS" },
326 { 0x88, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
327 { 0x99, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
328 { 0x9a, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
329 { 0x98, 2, 2, "3DSTATE_DEFAULT_Z" },
330 { 0x97, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
331 { 0x85, 2, 2, "3DSTATE_DEST_BUFFER_VARIABLES" },
332 { 0x80, 5, 5, "3DSTATE_DRAWING_RECTANGLE" },
333 { 0x8e, 3, 3, "3DSTATE_BUFFER_INFO" },
334 { 0x9d, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
335 { 0x9e, 4, 4, "3DSTATE_MONO_FILTER" },
336 { 0x89, 4, 4, "3DSTATE_FOG_MODE" },
337 { 0x8f, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
338 { 0x81, 3, 3, "3DSTATE_SCISSOR_RECTANGLE" },
339 { 0x83, 2, 2, "3DSTATE_SPAN_STIPPLE" },
342 switch ((data[0] & 0x00ff0000) >> 16) {
344 /* This instruction is unusual. A 0 length means just 1 DWORD instead of
345 * 2. The 0 length is specified in one place to be unsupported, but
346 * stated to be required in another, and 0 length LOAD_INDIRECTs appear
347 * to cause no harm at least.
349 instr_out(data, hw_offset, 0, "3DSTATE_LOAD_INDIRECT\n");
350 len = (data[0] & 0x000000ff) + 1;
352 if (data[0] & (0x01 << 8)) {
354 BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT");
355 instr_out(data, hw_offset, i++, "SIS.0\n");
356 instr_out(data, hw_offset, i++, "SIS.1\n");
358 if (data[0] & (0x02 << 8)) {
360 BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT");
361 instr_out(data, hw_offset, i++, "DIS.0\n");
363 if (data[0] & (0x04 << 8)) {
365 BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT");
366 instr_out(data, hw_offset, i++, "SSB.0\n");
367 instr_out(data, hw_offset, i++, "SSB.1\n");
369 if (data[0] & (0x08 << 8)) {
371 BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT");
372 instr_out(data, hw_offset, i++, "MSB.0\n");
373 instr_out(data, hw_offset, i++, "MSB.1\n");
375 if (data[0] & (0x10 << 8)) {
377 BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT");
378 instr_out(data, hw_offset, i++, "PSP.0\n");
379 instr_out(data, hw_offset, i++, "PSP.1\n");
381 if (data[0] & (0x20 << 8)) {
383 BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT");
384 instr_out(data, hw_offset, i++, "PSC.0\n");
385 instr_out(data, hw_offset, i++, "PSC.1\n");
388 fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
394 instr_out(data, hw_offset, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
395 len = (data[0] & 0x0000000f) + 2;
397 for (word = 0; word <= 7; word++) {
398 if (data[0] & (1 << (4 + word))) {
400 BUFFER_FAIL(count, len, "3DSTATE_LOAD_STATE_IMMEDIATE_1");
402 /* save vertex state for decode */
412 instr_out(data, hw_offset, i++, "S%d\n", word);
416 fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
421 instr_out(data, hw_offset, 0, "3DSTATE_MAP_STATE\n");
422 len = (data[0] & 0x0000003f) + 2;
425 for (map = 0; map <= 15; map++) {
426 if (data[1] & (1 << map)) {
428 BUFFER_FAIL(count, len, "3DSTATE_MAP_STATE");
429 instr_out(data, hw_offset, i++, "map %d MS2\n", map);
430 instr_out(data, hw_offset, i++, "map %d MS3\n", map);
431 instr_out(data, hw_offset, i++, "map %d MS4\n", map);
435 fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n");
441 instr_out(data, hw_offset, 0, "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
442 len = (data[0] & 0x000000ff) + 2;
445 for (c = 0; c <= 31; c++) {
446 if (data[1] & (1 << c)) {
448 BUFFER_FAIL(count, len, "3DSTATE_PIXEL_SHADER_CONSTANTS");
449 instr_out(data, hw_offset, i, "C%d.X = %f\n",
450 c, int_as_float(data[i]));
452 instr_out(data, hw_offset, i, "C%d.Y = %f\n",
453 c, int_as_float(data[i]));
455 instr_out(data, hw_offset, i, "C%d.Z = %f\n",
456 c, int_as_float(data[i]));
458 instr_out(data, hw_offset, i, "C%d.W = %f\n",
459 c, int_as_float(data[i]));
464 fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n");
469 instr_out(data, hw_offset, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
470 len = (data[0] & 0x000000ff) + 2;
471 if ((len - 1) % 3 != 0 || len > 370) {
472 fprintf(out, "Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
476 for (instr = 0; instr < (len - 1) / 3; instr++) {
478 BUFFER_FAIL(count, len, "3DSTATE_MAP_STATE");
479 instr_out(data, hw_offset, i++, "PS%03x\n", instr);
480 instr_out(data, hw_offset, i++, "PS%03x\n", instr);
481 instr_out(data, hw_offset, i++, "PS%03x\n", instr);
485 instr_out(data, hw_offset, 0, "3DSTATE_SAMPLER_STATE\n");
486 len = (data[0] & 0x0000003f) + 2;
488 for (sampler = 0; sampler <= 15; sampler++) {
489 if (data[1] & (1 << sampler)) {
491 BUFFER_FAIL(count, len, "3DSTATE_SAMPLER_STATE");
492 instr_out(data, hw_offset, i++, "sampler %d SS2\n",
494 instr_out(data, hw_offset, i++, "sampler %d SS3\n",
496 instr_out(data, hw_offset, i++, "sampler %d SS4\n",
501 fprintf(out, "Bad count in 3DSTATE_SAMPLER_STATE\n");
507 for (opcode = 0; opcode < sizeof(opcodes_3d_1d) / sizeof(opcodes_3d_1d[0]);
510 if (((data[0] & 0x00ff0000) >> 16) == opcodes_3d_1d[opcode].opcode) {
513 instr_out(data, hw_offset, 0, "%s\n", opcodes_3d_1d[opcode].name);
514 if (opcodes_3d_1d[opcode].max_len > 1) {
515 len = (data[0] & 0x0000ffff) + 2;
516 if (len < opcodes_3d_1d[opcode].min_len ||
517 len > opcodes_3d_1d[opcode].max_len)
519 fprintf(out, "Bad count in %s\n",
520 opcodes_3d_1d[opcode].name);
525 for (i = 1; i < len; i++) {
527 BUFFER_FAIL(count, len, opcodes_3d_1d[opcode].name);
528 instr_out(data, hw_offset, i, "dword %d\n", i);
535 instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
541 decode_3d_primitive(uint32_t *data, int count, uint32_t hw_offset,
544 char immediate = (data[0] & (1 << 23)) == 0;
548 switch ((data[0] >> 18) & 0xf) {
549 case 0x0: primtype = "TRILIST"; break;
550 case 0x1: primtype = "TRISTRIP"; break;
551 case 0x2: primtype = "TRISTRIP_REVERSE"; break;
552 case 0x3: primtype = "TRIFAN"; break;
553 case 0x4: primtype = "POLYGON"; break;
554 case 0x5: primtype = "LINELIST"; break;
555 case 0x6: primtype = "LINESTRIP"; break;
556 case 0x7: primtype = "RECTLIST"; break;
557 case 0x8: primtype = "POINTLIST"; break;
558 case 0x9: primtype = "DIB"; break;
559 case 0xa: primtype = "CLEAR_RECT"; break;
560 default: primtype = "unknown"; break;
563 /* XXX: 3DPRIM_DIB not supported */
565 len = (data[0] & 0x0003ffff) + 2;
566 instr_out(data, hw_offset, 0, "3DPRIMITIVE inline %s\n", primtype);
568 BUFFER_FAIL(count, len, "3DPRIMITIVE inline");
569 if (!saved_s2_set || !saved_s4_set) {
570 fprintf(out, "unknown vertex format\n");
571 for (i = 1; i < len; i++) {
572 instr_out(data, hw_offset, i,
573 " vertex data (%f float)\n",
574 int_as_float(data[i]));
577 unsigned int vertex = 0;
578 for (i = 1; i < len;) {
581 #define VERTEX_OUT(fmt, ...) do { \
583 instr_out(data, hw_offset, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
585 fprintf(out, " missing data in V%d\n", vertex); \
589 VERTEX_OUT("X = %f", int_as_float(data[i]));
590 VERTEX_OUT("Y = %f", int_as_float(data[i]));
591 switch (saved_s4 >> 6 & 0x7) {
593 VERTEX_OUT("Z = %f", int_as_float(data[i]));
596 VERTEX_OUT("Z = %f", int_as_float(data[i]));
597 VERTEX_OUT("W = %f", int_as_float(data[i]));
602 VERTEX_OUT("W = %f", int_as_float(data[i]));
605 fprintf(out, "bad S4 position mask\n");
608 if (saved_s4 & (1 << 10)) {
609 VERTEX_OUT("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
612 (data[i] >> 16) & 0xff,
613 (data[i] >> 8) & 0xff,
616 if (saved_s4 & (1 << 11)) {
617 VERTEX_OUT("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
620 (data[i] >> 16) & 0xff,
621 (data[i] >> 8) & 0xff,
624 if (saved_s4 & (1 << 12))
625 VERTEX_OUT("width = 0x%08x)", data[i]);
627 for (tc = 0; tc <= 7; tc++) {
628 switch ((saved_s2 >> (tc * 4)) & 0xf) {
630 VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
631 VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i]));
634 VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
635 VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i]));
636 VERTEX_OUT("T%d.Z = %f", tc, int_as_float(data[i]));
639 VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
640 VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i]));
641 VERTEX_OUT("T%d.Z = %f", tc, int_as_float(data[i]));
642 VERTEX_OUT("T%d.W = %f", tc, int_as_float(data[i]));
645 VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
648 VERTEX_OUT("T%d.XY = 0x%08x half-float", tc, data[i]);
651 VERTEX_OUT("T%d.XY = 0x%08x half-float", tc, data[i]);
652 VERTEX_OUT("T%d.ZW = 0x%08x half-float", tc, data[i]);
657 fprintf(out, "bad S2.T%d format\n", tc);
664 /* indirect vertices */
665 len = data[0] & 0x0000ffff; /* index count */
666 if (data[0] & (1 << 17)) {
667 /* random vertex access */
668 if (count < (len + 1) / 2 + 1) {
669 BUFFER_FAIL(count, (len + 1) / 2 + 1,
670 "3DPRIMITIVE random indirect");
672 instr_out(data, hw_offset, 0,
673 "3DPRIMITIVE random indirect %s (%d)\n", primtype, len);
675 /* vertex indices continue until 0xffff is found */
676 for (i = 1; i < count; i++) {
677 if ((data[i] & 0xffff) == 0xffff) {
678 instr_out(data, hw_offset, i,
679 " indices: (terminator)\n");
681 } else if ((data[i] >> 16) == 0xffff) {
682 instr_out(data, hw_offset, i,
688 instr_out(data, hw_offset, i,
689 " indices: 0x%04x, 0x%04x\n",
690 data[i] & 0xffff, data[i] >> 16);
694 "3DPRIMITIVE: no terminator found in index buffer\n");
698 /* fixed size vertex index buffer */
699 for (i = 0; i < len; i += 2) {
700 if (i * 2 == len - 1) {
701 instr_out(data, hw_offset, i,
702 " indices: 0x%04x\n",
705 instr_out(data, hw_offset, i,
706 " indices: 0x%04x, 0x%04x\n",
707 data[i] & 0xffff, data[i] >> 16);
711 return (len + 1) / 2 + 1;
713 /* sequential vertex access */
715 BUFFER_FAIL(count, 2, "3DPRIMITIVE seq indirect");
716 instr_out(data, hw_offset, 0,
717 "3DPRIMITIVE sequential indirect %s, %d starting from "
718 "%d\n", primtype, len, data[1] & 0xffff);
719 instr_out(data, hw_offset, 1, " start\n");
728 decode_3d(uint32_t *data, int count, uint32_t hw_offset, int *failures)
738 { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
739 { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
740 { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
741 { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
742 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
743 { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
744 { 0x0d, 1, 1, "3DSTATE_MODES_4" },
745 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
746 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
749 switch ((data[0] & 0x1f000000) >> 24) {
751 return decode_3d_primitive(data, count, hw_offset, failures);
753 return decode_3d_1d(data, count, hw_offset, failures);
755 return decode_3d_1c(data, count, hw_offset, failures);
758 for (opcode = 0; opcode < sizeof(opcodes_3d) / sizeof(opcodes_3d[0]);
760 if ((data[0] & 0x1f000000) >> 24 == opcodes_3d[opcode].opcode) {
761 unsigned int len = 1, i;
763 instr_out(data, hw_offset, 0, "%s\n", opcodes_3d[opcode].name);
764 if (opcodes_3d[opcode].max_len > 1) {
765 len = (data[0] & 0xff) + 2;
766 if (len < opcodes_3d[opcode].min_len ||
767 len > opcodes_3d[opcode].max_len)
769 fprintf(out, "Bad count in %s\n", opcodes_3d[opcode].name);
773 for (i = 1; i < len; i++) {
775 BUFFER_FAIL(count, len, opcodes_3d[opcode].name);
776 instr_out(data, hw_offset, i, "dword %d\n", i);
782 instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
788 get_965_surfacetype(unsigned int surfacetype)
790 switch (surfacetype) {
794 case 3: return "CUBE";
795 case 4: return "BUFFER";
796 case 7: return "NULL";
797 default: return "unknown";
802 get_965_depthformat(unsigned int depthformat)
804 switch (depthformat) {
805 case 0: return "s8_z24float";
806 case 1: return "z32float";
807 case 2: return "z24s8";
808 case 5: return "z16";
809 default: return "unknown";
814 decode_3d_965(uint32_t *data, int count, uint32_t hw_offset, int *failures)
816 unsigned int opcode, len;
824 { 0x6000, 3, 3, "URB_FENCE" },
825 { 0x6001, 2, 2, "CS_URB_STATE" },
826 { 0x6002, 2, 2, "CONSTANT_BUFFER" },
827 { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
828 { 0x6102, 2, 2 , "STATE_SIP" },
829 { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
830 { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" },
831 { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" },
832 { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
833 { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
834 { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" },
835 { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
836 { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
837 /* 0x7808: 3DSTATE_VERTEX_BUFFERS */
838 /* 0x7809: 3DSTATE_VERTEX_ELEMENTS */
839 { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
840 { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" },
841 { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" },
842 { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
843 { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
844 { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" },
845 { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
846 { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
847 { 0x7b00, 6, 6, "3DPRIMITIVE" },
850 len = (data[0] & 0x0000ffff) + 2;
852 switch ((data[0] & 0xffff0000) >> 16) {
855 fprintf(out, "Bad count in STATE_BASE_ADDRESS\n");
857 BUFFER_FAIL(count, len, "STATE_BASE_ADDRESS");
859 instr_out(data, hw_offset, 0,
860 "STATE_BASE_ADDRESS\n");
863 instr_out(data, hw_offset, 1, "General state at 0x%08x\n",
866 instr_out(data, hw_offset, 1, "General state not updated\n");
869 instr_out(data, hw_offset, 2, "Surface state at 0x%08x\n",
872 instr_out(data, hw_offset, 2, "Surface state not updated\n");
875 instr_out(data, hw_offset, 3, "Indirect state at 0x%08x\n",
878 instr_out(data, hw_offset, 3, "Indirect state not updated\n");
881 instr_out(data, hw_offset, 4, "General state upper bound 0x%08x\n",
884 instr_out(data, hw_offset, 4, "General state not updated\n");
887 instr_out(data, hw_offset, 5, "Indirect state upper bound 0x%08x\n",
890 instr_out(data, hw_offset, 5, "Indirect state not updated\n");
895 fprintf(out, "Bad count in 3DSTATE_PIPELINED_POINTERS\n");
897 BUFFER_FAIL(count, len, "3DSTATE_PIPELINED_POINTERS");
899 instr_out(data, hw_offset, 0,
900 "3DSTATE_PIPELINED_POINTERS\n");
901 instr_out(data, hw_offset, 1, "VS state\n");
902 instr_out(data, hw_offset, 2, "GS state\n");
903 instr_out(data, hw_offset, 3, "Clip state\n");
904 instr_out(data, hw_offset, 4, "SF state\n");
905 instr_out(data, hw_offset, 5, "WM state\n");
906 instr_out(data, hw_offset, 6, "CC state\n");
910 fprintf(out, "Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
912 BUFFER_FAIL(count, len, "3DSTATE_BINDING_TABLE_POINTERS");
914 instr_out(data, hw_offset, 0,
915 "3DSTATE_BINDING_TABLE_POINTERS\n");
916 instr_out(data, hw_offset, 1, "VS binding table\n");
917 instr_out(data, hw_offset, 2, "GS binding table\n");
918 instr_out(data, hw_offset, 3, "Clip binding table\n");
919 instr_out(data, hw_offset, 4, "SF binding table\n");
920 instr_out(data, hw_offset, 5, "WM binding table\n");
926 fprintf(out, "Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
928 BUFFER_FAIL(count, len, "3DSTATE_DRAWING_RECTANGLE");
930 instr_out(data, hw_offset, 0,
931 "3DSTATE_DRAWING_RECTANGLE\n");
932 instr_out(data, hw_offset, 1, "top left: %d,%d\n",
934 (data[1] >> 16) & 0xffff);
935 instr_out(data, hw_offset, 2, "bottom right: %d,%d\n",
937 (data[2] >> 16) & 0xffff);
938 instr_out(data, hw_offset, 3, "origin: %d,%d\n",
939 (int)data[3] & 0xffff,
940 ((int)data[3] >> 16) & 0xffff);
946 fprintf(out, "Bad count in 3DSTATE_DEPTH_BUFFER\n");
948 BUFFER_FAIL(count, len, "3DSTATE_DEPTH_BUFFER");
950 instr_out(data, hw_offset, 0,
951 "3DSTATE_DEPTH_BUFFER\n");
952 instr_out(data, hw_offset, 1, "%s, %s, pitch = %d bytes, %stiled\n",
953 get_965_surfacetype(data[1] >> 29),
954 get_965_depthformat((data[1] >> 18) & 0x7),
955 (data[1] & 0x0001ffff) + 1,
956 data[1] & (1 << 27) ? "" : "not ");
957 instr_out(data, hw_offset, 2, "depth offset\n");
958 instr_out(data, hw_offset, 3, "%dx%d\n",
959 ((data[3] & 0x0007ffc0) >> 6) + 1,
960 ((data[3] & 0xfff80000) >> 19) + 1);
961 instr_out(data, hw_offset, 4, "volume depth\n");
966 for (opcode = 0; opcode < sizeof(opcodes_3d) / sizeof(opcodes_3d[0]);
968 if ((data[0] & 0xffff0000) >> 16 == opcodes_3d[opcode].opcode) {
972 instr_out(data, hw_offset, 0, "%s\n", opcodes_3d[opcode].name);
973 if (opcodes_3d[opcode].max_len > 1) {
974 len = (data[0] & 0xff) + 2;
975 if (len < opcodes_3d[opcode].min_len ||
976 len > opcodes_3d[opcode].max_len)
978 fprintf(out, "Bad count in %s\n", opcodes_3d[opcode].name);
982 for (i = 1; i < len; i++) {
984 BUFFER_FAIL(count, len, opcodes_3d[opcode].name);
985 instr_out(data, hw_offset, i, "dword %d\n", i);
991 instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
997 * Decodes an i830-i915 batch buffer, writing the output to stdout.
999 * \param data batch buffer contents
1000 * \param count number of DWORDs to decode in the batch buffer
1001 * \param hw_offset hardware address for the buffer
1004 intel_decode(uint32_t *data, int count, uint32_t hw_offset, uint32_t devid)
1011 while (index < count) {
1012 switch ((data[index] & 0xe0000000) >> 29) {
1014 index += decode_mi(data + index, count - index,
1015 hw_offset + index * 4, &failures);
1018 index += decode_2d(data + index, count - index,
1019 hw_offset + index * 4, &failures);
1022 if (IS_965(devid)) {
1023 index += decode_3d_965(data + index, count - index,
1024 hw_offset + index * 4, &failures);
1026 index += decode_3d(data + index, count - index,
1027 hw_offset + index * 4, &failures);
1031 instr_out(data, hw_offset, index, "UNKNOWN\n");
1042 void intel_decode_context_reset(void)