4 * Copyright (c) 2009, Intel Corporation.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * Keith Packard <keithp@keithp.com>
32 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
33 * Use is subject to license terms.
41 #define BUFFER_FAIL(_count, _len, _name) { \
42 DRM_ERROR("Buffer size too small in %s (%d < %d)\n", \
43 (_name), (_count), (_len)); \
49 static uint32_t saved_s2
= 0, saved_s4
= 0;
50 static char saved_s2_set
= 0, saved_s4_set
= 0;
53 instr_out(uint32_t *data
, uint32_t hw_offset
, unsigned int index
,
57 DRM_ERROR("0x%08x: 0x%08x:%s ", hw_offset
+ index
* 4, data
[index
],
58 index
== 0 ? "" : " ");
62 vcmn_err(CE_WARN
, fmt
, ap
);
68 decode_mi(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
78 { 0x08, 1, 1, "MI_ARB_ON_OFF" },
79 { 0x0a, 1, 1, "MI_BATCH_BUFFER_END" },
80 { 0x31, 2, 2, "MI_BATCH_BUFFER_START" },
81 { 0x14, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
82 { 0x04, 1, 1, "MI_FLUSH" },
83 { 0x22, 3, 3, "MI_LOAD_REGISTER_IMM" },
84 { 0x13, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
85 { 0x12, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
86 { 0x00, 1, 1, "MI_NOOP" },
87 { 0x11, 2, 2, "MI_OVERLAY_FLIP" },
88 { 0x07, 1, 1, "MI_REPORT_HEAD" },
89 { 0x18, 2, 2, "MI_SET_CONTEXT" },
90 { 0x20, 3, 4, "MI_STORE_DATA_IMM" },
91 { 0x21, 3, 4, "MI_STORE_DATA_INDEX" },
92 { 0x24, 3, 3, "MI_STORE_REGISTER_MEM" },
93 { 0x02, 1, 1, "MI_USER_INTERRUPT" },
94 { 0x03, 1, 1, "MI_WAIT_FOR_EVENT" },
98 for (opcode
= 0; opcode
< sizeof(opcodes_mi
) / sizeof(opcodes_mi
[0]);
100 if ((data
[0] & 0x1f800000) >> 23 == opcodes_mi
[opcode
].opcode
) {
101 unsigned int len
= 1, i
;
103 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_mi
[opcode
].name
);
104 if (opcodes_mi
[opcode
].max_len
> 1) {
105 len
= (data
[0] & 0x000000ff) + 2;
106 if (len
< opcodes_mi
[opcode
].min_len
||
107 len
> opcodes_mi
[opcode
].max_len
)
109 DRM_ERROR("Bad length in %s\n",
110 opcodes_mi
[opcode
].name
);
114 for (i
= 1; i
< len
; i
++) {
116 BUFFER_FAIL(count
, len
, opcodes_mi
[opcode
].name
);
117 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
124 instr_out(data
, hw_offset
, 0, "MI UNKNOWN\n");
130 decode_2d(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
132 unsigned int opcode
, len
;
141 { 0x40, 5, 5, "COLOR_BLT" },
142 { 0x43, 6, 6, "SRC_COPY_BLT" },
143 { 0x01, 8, 8, "XY_SETUP_BLT" },
144 { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
145 { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
146 { 0x24, 2, 2, "XY_PIXEL_BLT" },
147 { 0x25, 3, 3, "XY_SCANLINES_BLT" },
148 { 0x26, 4, 4, "Y_TEXT_BLT" },
149 { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
150 { 0x50, 6, 6, "XY_COLOR_BLT" },
151 { 0x51, 6, 6, "XY_PAT_BLT" },
152 { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
153 { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
154 { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
155 { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
156 { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
157 { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
158 { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
159 { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
160 { 0x55, 9, 9, "XY_FULL_BLT" },
161 { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
162 { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
163 { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
164 { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
165 { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT" },
168 switch ((data
[0] & 0x1fc00000) >> 22) {
170 instr_out(data
, hw_offset
, 0,
171 "XY_COLOR_BLT (rgb %sabled, alpha %sabled, dst tile %d)\n",
172 (data
[0] & (1 << 20)) ? "en" : "dis",
173 (data
[0] & (1 << 21)) ? "en" : "dis",
174 (data
[0] >> 11) & 1);
176 len
= (data
[0] & 0x000000ff) + 2;
178 DRM_ERROR("Bad count in XY_COLOR_BLT\n");
180 BUFFER_FAIL(count
, len
, "XY_COLOR_BLT");
182 switch ((data
[1] >> 24) & 0x3) {
197 instr_out(data
, hw_offset
, 1, "format %s, pitch %d, "
198 "clipping %sabled\n", format
,
199 (short)(data
[1] & 0xffff),
200 data
[1] & (1 << 30) ? "en" : "dis");
201 instr_out(data
, hw_offset
, 2, "(%d,%d)\n",
202 data
[2] & 0xffff, data
[2] >> 16);
203 instr_out(data
, hw_offset
, 3, "(%d,%d)\n",
204 data
[3] & 0xffff, data
[3] >> 16);
205 instr_out(data
, hw_offset
, 4, "offset 0x%08x\n", data
[4]);
206 instr_out(data
, hw_offset
, 5, "color\n");
209 instr_out(data
, hw_offset
, 0,
210 "XY_SRC_COPY_BLT (rgb %sabled, alpha %sabled, "
211 "src tile %d, dst tile %d)\n",
212 (data
[0] & (1 << 20)) ? "en" : "dis",
213 (data
[0] & (1 << 21)) ? "en" : "dis",
215 (data
[0] >> 11) & 1);
217 len
= (data
[0] & 0x000000ff) + 2;
219 DRM_ERROR("Bad count in XY_SRC_COPY_BLT\n");
221 BUFFER_FAIL(count
, len
, "XY_SRC_COPY_BLT");
223 switch ((data
[1] >> 24) & 0x3) {
238 instr_out(data
, hw_offset
, 1, "format %s, dst pitch %d, "
239 "clipping %sabled\n", format
,
240 (short)(data
[1] & 0xffff),
241 data
[1] & (1 << 30) ? "en" : "dis");
242 instr_out(data
, hw_offset
, 2, "dst (%d,%d)\n",
243 data
[2] & 0xffff, data
[2] >> 16);
244 instr_out(data
, hw_offset
, 3, "dst (%d,%d)\n",
245 data
[3] & 0xffff, data
[3] >> 16);
246 instr_out(data
, hw_offset
, 4, "dst offset 0x%08x\n", data
[4]);
247 instr_out(data
, hw_offset
, 5, "src (%d,%d)\n",
248 data
[5] & 0xffff, data
[5] >> 16);
249 instr_out(data
, hw_offset
, 6, "src pitch %d\n",
250 (short)(data
[6] & 0xffff));
251 instr_out(data
, hw_offset
, 7, "src offset 0x%08x\n", data
[7]);
255 for (opcode
= 0; opcode
< sizeof(opcodes_2d
) / sizeof(opcodes_2d
[0]);
257 if ((data
[0] & 0x1fc00000) >> 22 == opcodes_2d
[opcode
].opcode
) {
261 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_2d
[opcode
].name
);
262 if (opcodes_2d
[opcode
].max_len
> 1) {
263 len
= (data
[0] & 0x000000ff) + 2;
264 if (len
< opcodes_2d
[opcode
].min_len
||
265 len
> opcodes_2d
[opcode
].max_len
)
267 DRM_ERROR("Bad count in %s\n", opcodes_2d
[opcode
].name
);
271 for (i
= 1; i
< len
; i
++) {
273 BUFFER_FAIL(count
, len
, opcodes_2d
[opcode
].name
);
274 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
281 instr_out(data
, hw_offset
, 0, "2D UNKNOWN\n");
288 decode_3d_1c(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
290 switch ((data
[0] & 0x00f80000) >> 19) {
292 instr_out(data
, hw_offset
, 0, "3DSTATE_DEPTH_SUBRECTANGLE_DISALBE\n");
295 instr_out(data
, hw_offset
, 0, "3DSTATE_SCISSOR_ENABLE\n");
298 instr_out(data
, hw_offset
, 0, "3DSTATE_MAP_COORD_SET_I830\n");
301 instr_out(data
, hw_offset
, 0, "3DSTATE_MAP_CUBE_I830\n");
304 instr_out(data
, hw_offset
, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
308 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
314 decode_3d_1d(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
, int i830
)
316 unsigned int len
, i
, c
, opcode
, word
, map
, sampler
, instr
;
324 } opcodes_3d_1d
[] = {
325 { 0x8e, 0, 3, 3, "3DSTATE_BUFFER_INFO" },
326 { 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" },
327 { 0x9c, 0, 1, 1, "3DSTATE_CLEAR_PARAMETERS" },
328 { 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
329 { 0x99, 0, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
330 { 0x9a, 0, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
331 { 0x98, 0, 2, 2, "3DSTATE_DEFAULT_Z" },
332 { 0x97, 0, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
333 { 0x85, 0, 2, 2, "3DSTATE_DEST_BUFFER_VARIABLES" },
334 { 0x80, 0, 5, 5, "3DSTATE_DRAWING_RECTANGLE" },
335 { 0x8e, 0, 3, 3, "3DSTATE_BUFFER_INFO" },
336 { 0x9d, 0, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
337 { 0x9e, 0, 4, 4, "3DSTATE_MONO_FILTER" },
338 { 0x89, 0, 4, 4, "3DSTATE_FOG_MODE" },
339 { 0x8f, 0, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
340 { 0x81, 0, 3, 3, "3DSTATE_SCISSOR_RECTANGLE" },
341 { 0x83, 0, 2, 2, "3DSTATE_SPAN_STIPPLE" },
342 { 0x8c, 1, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM_I830" },
343 { 0x8b, 1, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM_I830" },
344 { 0x8d, 1, 3, 3, "3DSTATE_W_STATE_I830" },
345 { 0x01, 1, 2, 2, "3DSTATE_COLOR_FACTOR_I830" },
346 { 0x02, 1, 2, 2, "3DSTATE_MAP_COORD_SETBIND_I830" },
349 switch ((data
[0] & 0x00ff0000) >> 16) {
351 /* This instruction is unusual. A 0 length means just 1 DWORD instead of
352 * 2. The 0 length is specified in one place to be unsupported, but
353 * stated to be required in another, and 0 length LOAD_INDIRECTs appear
354 * to cause no harm at least.
356 instr_out(data
, hw_offset
, 0, "3DSTATE_LOAD_INDIRECT\n");
357 len
= (data
[0] & 0x000000ff) + 1;
359 if (data
[0] & (0x01 << 8)) {
361 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
362 instr_out(data
, hw_offset
, i
++, "SIS.0\n");
363 instr_out(data
, hw_offset
, i
++, "SIS.1\n");
365 if (data
[0] & (0x02 << 8)) {
367 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
368 instr_out(data
, hw_offset
, i
++, "DIS.0\n");
370 if (data
[0] & (0x04 << 8)) {
372 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
373 instr_out(data
, hw_offset
, i
++, "SSB.0\n");
374 instr_out(data
, hw_offset
, i
++, "SSB.1\n");
376 if (data
[0] & (0x08 << 8)) {
378 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
379 instr_out(data
, hw_offset
, i
++, "MSB.0\n");
380 instr_out(data
, hw_offset
, i
++, "MSB.1\n");
382 if (data
[0] & (0x10 << 8)) {
384 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
385 instr_out(data
, hw_offset
, i
++, "PSP.0\n");
386 instr_out(data
, hw_offset
, i
++, "PSP.1\n");
388 if (data
[0] & (0x20 << 8)) {
390 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
391 instr_out(data
, hw_offset
, i
++, "PSC.0\n");
392 instr_out(data
, hw_offset
, i
++, "PSC.1\n");
395 DRM_ERROR("Bad count in 3DSTATE_LOAD_INDIRECT\n");
401 instr_out(data
, hw_offset
, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
402 len
= (data
[0] & 0x0000000f) + 2;
404 for (word
= 0; word
<= 7; word
++) {
405 if (data
[0] & (1 << (4 + word
))) {
407 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_STATE_IMMEDIATE_1");
409 /* save vertex state for decode */
419 instr_out(data
, hw_offset
, i
++, "S%d\n", word
);
423 DRM_ERROR("Bad count in 3DSTATE_LOAD_INDIRECT\n");
428 instr_out(data
, hw_offset
, 0, "3DSTATE_MAP_STATE\n");
429 len
= (data
[0] & 0x0000003f) + 2;
432 for (map
= 0; map
<= 15; map
++) {
433 if (data
[1] & (1 << map
)) {
435 BUFFER_FAIL(count
, len
, "3DSTATE_MAP_STATE");
436 instr_out(data
, hw_offset
, i
++, "map %d MS2\n", map
);
437 instr_out(data
, hw_offset
, i
++, "map %d MS3\n", map
);
438 instr_out(data
, hw_offset
, i
++, "map %d MS4\n", map
);
442 DRM_ERROR("Bad count in 3DSTATE_MAP_STATE\n");
448 instr_out(data
, hw_offset
, 0, "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
449 len
= (data
[0] & 0x000000ff) + 2;
452 for (c
= 0; c
<= 31; c
++) {
453 if (data
[1] & (1 << c
)) {
455 BUFFER_FAIL(count
, len
, "3DSTATE_PIXEL_SHADER_CONSTANTS");
456 instr_out(data
, hw_offset
, i
, "C%d.X = %x float\n",
459 instr_out(data
, hw_offset
, i
, "C%d.Y = %x float\n",
462 instr_out(data
, hw_offset
, i
, "C%d.Z = %x float\n",
465 instr_out(data
, hw_offset
, i
, "C%d.W = %x float\n",
471 DRM_ERROR("Bad count in 3DSTATE_MAP_STATE\n");
476 instr_out(data
, hw_offset
, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
477 len
= (data
[0] & 0x000000ff) + 2;
478 if ((len
- 1) % 3 != 0 || len
> 370) {
479 DRM_ERROR("Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
483 for (instr
= 0; instr
< (len
- 1) / 3; instr
++) {
485 BUFFER_FAIL(count
, len
, "3DSTATE_MAP_STATE");
486 instr_out(data
, hw_offset
, i
++, "PS%03x\n", instr
);
487 instr_out(data
, hw_offset
, i
++, "PS%03x\n", instr
);
488 instr_out(data
, hw_offset
, i
++, "PS%03x\n", instr
);
494 instr_out(data
, hw_offset
, 0, "3DSTATE_SAMPLER_STATE\n");
495 len
= (data
[0] & 0x0000003f) + 2;
497 for (sampler
= 0; sampler
<= 15; sampler
++) {
498 if (data
[1] & (1 << sampler
)) {
500 BUFFER_FAIL(count
, len
, "3DSTATE_SAMPLER_STATE");
501 instr_out(data
, hw_offset
, i
++, "sampler %d SS2\n",
503 instr_out(data
, hw_offset
, i
++, "sampler %d SS3\n",
505 instr_out(data
, hw_offset
, i
++, "sampler %d SS4\n",
510 DRM_ERROR("Bad count in 3DSTATE_SAMPLER_STATE\n");
516 for (opcode
= 0; opcode
< sizeof(opcodes_3d_1d
) / sizeof(opcodes_3d_1d
[0]);
519 if (opcodes_3d_1d
[opcode
].i830_only
&& !i830
)
522 if (((data
[0] & 0x00ff0000) >> 16) == opcodes_3d_1d
[opcode
].opcode
) {
525 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_3d_1d
[opcode
].name
);
526 if (opcodes_3d_1d
[opcode
].max_len
> 1) {
527 len
= (data
[0] & 0x0000ffff) + 2;
528 if (len
< opcodes_3d_1d
[opcode
].min_len
||
529 len
> opcodes_3d_1d
[opcode
].max_len
)
531 DRM_ERROR("Bad count in %s\n",
532 opcodes_3d_1d
[opcode
].name
);
537 for (i
= 1; i
< len
; i
++) {
539 BUFFER_FAIL(count
, len
, opcodes_3d_1d
[opcode
].name
);
540 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
547 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
553 decode_3d_primitive(uint32_t *data
, int count
, uint32_t hw_offset
,
556 char immediate
= (data
[0] & (1 << 23)) == 0;
560 switch ((data
[0] >> 18) & 0xf) {
561 case 0x0: primtype
= "TRILIST"; break;
562 case 0x1: primtype
= "TRISTRIP"; break;
563 case 0x2: primtype
= "TRISTRIP_REVERSE"; break;
564 case 0x3: primtype
= "TRIFAN"; break;
565 case 0x4: primtype
= "POLYGON"; break;
566 case 0x5: primtype
= "LINELIST"; break;
567 case 0x6: primtype
= "LINESTRIP"; break;
568 case 0x7: primtype
= "RECTLIST"; break;
569 case 0x8: primtype
= "POINTLIST"; break;
570 case 0x9: primtype
= "DIB"; break;
571 case 0xa: primtype
= "CLEAR_RECT"; break;
572 default: primtype
= "unknown"; break;
575 /* XXX: 3DPRIM_DIB not supported */
577 len
= (data
[0] & 0x0003ffff) + 2;
578 instr_out(data
, hw_offset
, 0, "3DPRIMITIVE inline %s\n", primtype
);
580 BUFFER_FAIL(count
, len
, "3DPRIMITIVE inline");
581 if (!saved_s2_set
|| !saved_s4_set
) {
582 DRM_ERROR("unknown vertex format\n");
583 for (i
= 1; i
< len
; i
++) {
584 instr_out(data
, hw_offset
, i
,
585 " vertex data (%x float)\n",
589 unsigned int vertex
= 0;
590 for (i
= 1; i
< len
;) {
593 #define VERTEX_OUT(fmt, ...) { \
595 instr_out(data, hw_offset, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
597 DRM_ERROR(" missing data in V%d\n", vertex); \
601 VERTEX_OUT("X = %x float", data
[i
]);
602 VERTEX_OUT("Y = %x float", data
[i
]);
603 switch (saved_s4
>> 6 & 0x7) {
605 VERTEX_OUT("Z = %x float", data
[i
]);
608 VERTEX_OUT("Z = %x float", data
[i
]);
609 VERTEX_OUT("W = %x float", data
[i
]);
614 VERTEX_OUT("W = %x float", data
[i
]);
617 DRM_ERROR("bad S4 position mask\n");
620 if (saved_s4
& (1 << 10)) {
621 VERTEX_OUT("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
624 (data
[i
] >> 16) & 0xff,
625 (data
[i
] >> 8) & 0xff,
628 if (saved_s4
& (1 << 11)) {
629 VERTEX_OUT("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
632 (data
[i
] >> 16) & 0xff,
633 (data
[i
] >> 8) & 0xff,
636 if (saved_s4
& (1 << 12))
637 VERTEX_OUT("width = 0x%08x)", data
[i
]);
639 for (tc
= 0; tc
<= 7; tc
++) {
640 switch ((saved_s2
>> (tc
* 4)) & 0xf) {
642 VERTEX_OUT("T%d.X = %x float", tc
, data
[i
]);
643 VERTEX_OUT("T%d.Y = %x float", tc
, data
[i
]);
646 VERTEX_OUT("T%d.X = %x float", tc
, data
[i
]);
647 VERTEX_OUT("T%d.Y = %x float", tc
, data
[i
]);
648 VERTEX_OUT("T%d.Z = %x float", tc
, data
[i
]);
651 VERTEX_OUT("T%d.X = %x float", tc
, data
[i
]);
652 VERTEX_OUT("T%d.Y = %x float", tc
, data
[i
]);
653 VERTEX_OUT("T%d.Z = %x float", tc
, data
[i
]);
654 VERTEX_OUT("T%d.W = %x float", tc
, data
[i
]);
657 VERTEX_OUT("T%d.X = %x float", tc
, data
[i
]);
660 VERTEX_OUT("T%d.XY = 0x%08x half-float", tc
, data
[i
]);
663 VERTEX_OUT("T%d.XY = 0x%08x half-float", tc
, data
[i
]);
664 VERTEX_OUT("T%d.ZW = 0x%08x half-float", tc
, data
[i
]);
669 DRM_ERROR("bad S2.T%d format\n", tc
);
676 /* indirect vertices */
677 len
= data
[0] & 0x0000ffff; /* index count */
678 if (data
[0] & (1 << 17)) {
679 /* random vertex access */
680 if (count
< (len
+ 1) / 2 + 1)
681 BUFFER_FAIL(count
, (len
+ 1) / 2 + 1, "3DPRIMITIVE random indirect");
682 instr_out(data
, hw_offset
, 0,
683 "3DPRIMITIVE random indirect %s (%d)\n", primtype
, len
);
685 /* vertex indices continue until 0xffff is found */
686 for (i
= 1; i
< count
; i
++) {
687 if ((data
[i
] & 0xffff) == 0xffff) {
688 instr_out(data
, hw_offset
, i
,
689 " indices: (terminator)\n");
691 } else if ((data
[i
] >> 16) == 0xffff) {
692 instr_out(data
, hw_offset
, i
,
698 instr_out(data
, hw_offset
, i
,
699 " indices: 0x%04x, 0x%04x\n",
700 data
[i
] & 0xffff, data
[i
] >> 16);
703 DRM_ERROR("3DPRIMITIVE: no terminator found in index buffer\n");
707 /* fixed size vertex index buffer */
708 for (i
= 0; i
< len
; i
+= 2) {
709 if (i
* 2 == len
- 1) {
710 instr_out(data
, hw_offset
, i
,
711 " indices: 0x%04x\n",
714 instr_out(data
, hw_offset
, i
,
715 " indices: 0x%04x, 0x%04x\n",
716 data
[i
] & 0xffff, data
[i
] >> 16);
720 return (len
+ 1) / 2 + 1;
722 /* sequential vertex access */
724 BUFFER_FAIL(count
, 2, "3DPRIMITIVE seq indirect");
725 instr_out(data
, hw_offset
, 0,
726 "3DPRIMITIVE sequential indirect %s, %d starting from "
727 "%d\n", primtype
, len
, data
[1] & 0xffff);
728 instr_out(data
, hw_offset
, 1, " start\n");
737 decode_3d(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
747 { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
748 { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
749 { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
750 { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
751 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
752 { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
753 { 0x0d, 1, 1, "3DSTATE_MODES_4" },
754 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
755 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
758 switch ((data
[0] & 0x1f000000) >> 24) {
760 return decode_3d_primitive(data
, count
, hw_offset
, failures
);
762 return decode_3d_1d(data
, count
, hw_offset
, failures
, 0);
764 return decode_3d_1c(data
, count
, hw_offset
, failures
);
767 for (opcode
= 0; opcode
< sizeof(opcodes_3d
) / sizeof(opcodes_3d
[0]);
769 if ((data
[0] & 0x1f000000) >> 24 == opcodes_3d
[opcode
].opcode
) {
770 unsigned int len
= 1, i
;
772 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_3d
[opcode
].name
);
773 if (opcodes_3d
[opcode
].max_len
> 1) {
774 len
= (data
[0] & 0xff) + 2;
775 if (len
< opcodes_3d
[opcode
].min_len
||
776 len
> opcodes_3d
[opcode
].max_len
)
778 DRM_ERROR("Bad count in %s\n", opcodes_3d
[opcode
].name
);
782 for (i
= 1; i
< len
; i
++) {
784 BUFFER_FAIL(count
, len
, opcodes_3d
[opcode
].name
);
785 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
791 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
797 get_965_surfacetype(unsigned int surfacetype
)
799 switch (surfacetype
) {
803 case 3: return "CUBE";
804 case 4: return "BUFFER";
805 case 7: return "NULL";
806 default: return "unknown";
811 get_965_depthformat(unsigned int depthformat
)
813 switch (depthformat
) {
814 case 0: return "s8_z24float";
815 case 1: return "z32float";
816 case 2: return "z24s8";
817 case 5: return "z16";
818 default: return "unknown";
823 decode_3d_965(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
825 unsigned int opcode
, len
;
833 { 0x6000, 3, 3, "URB_FENCE" },
834 { 0x6001, 2, 2, "CS_URB_STATE" },
835 { 0x6002, 2, 2, "CONSTANT_BUFFER" },
836 { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
837 { 0x6102, 2, 2 , "STATE_SIP" },
838 { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
839 { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" },
840 { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" },
841 { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
842 { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
843 { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" },
844 { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
845 { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
846 /* 0x7808: 3DSTATE_VERTEX_BUFFERS */
847 /* 0x7809: 3DSTATE_VERTEX_ELEMENTS */
848 { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
849 { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" },
850 { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" },
851 { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
852 { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
853 { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" },
854 { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
855 { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
856 { 0x7b00, 6, 6, "3DPRIMITIVE" },
859 len
= (data
[0] & 0x0000ffff) + 2;
861 switch ((data
[0] & 0xffff0000) >> 16) {
864 DRM_ERROR("Bad count in STATE_BASE_ADDRESS\n");
866 BUFFER_FAIL(count
, len
, "STATE_BASE_ADDRESS");
868 instr_out(data
, hw_offset
, 0,
869 "STATE_BASE_ADDRESS\n");
872 instr_out(data
, hw_offset
, 1, "General state at 0x%08x\n",
875 instr_out(data
, hw_offset
, 1, "General state not updated\n");
878 instr_out(data
, hw_offset
, 2, "Surface state at 0x%08x\n",
881 instr_out(data
, hw_offset
, 2, "Surface state not updated\n");
884 instr_out(data
, hw_offset
, 3, "Indirect state at 0x%08x\n",
887 instr_out(data
, hw_offset
, 3, "Indirect state not updated\n");
890 instr_out(data
, hw_offset
, 4, "General state upper bound 0x%08x\n",
893 instr_out(data
, hw_offset
, 4, "General state not updated\n");
896 instr_out(data
, hw_offset
, 5, "Indirect state upper bound 0x%08x\n",
899 instr_out(data
, hw_offset
, 5, "Indirect state not updated\n");
904 DRM_ERROR("Bad count in 3DSTATE_PIPELINED_POINTERS\n");
906 BUFFER_FAIL(count
, len
, "3DSTATE_PIPELINED_POINTERS");
908 instr_out(data
, hw_offset
, 0,
909 "3DSTATE_PIPELINED_POINTERS\n");
910 instr_out(data
, hw_offset
, 1, "VS state\n");
911 instr_out(data
, hw_offset
, 2, "GS state\n");
912 instr_out(data
, hw_offset
, 3, "Clip state\n");
913 instr_out(data
, hw_offset
, 4, "SF state\n");
914 instr_out(data
, hw_offset
, 5, "WM state\n");
915 instr_out(data
, hw_offset
, 6, "CC state\n");
919 DRM_ERROR("Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
921 BUFFER_FAIL(count
, len
, "3DSTATE_BINDING_TABLE_POINTERS");
923 instr_out(data
, hw_offset
, 0,
924 "3DSTATE_BINDING_TABLE_POINTERS\n");
925 instr_out(data
, hw_offset
, 1, "VS binding table\n");
926 instr_out(data
, hw_offset
, 2, "GS binding table\n");
927 instr_out(data
, hw_offset
, 3, "Clip binding table\n");
928 instr_out(data
, hw_offset
, 4, "SF binding table\n");
929 instr_out(data
, hw_offset
, 5, "WM binding table\n");
935 DRM_ERROR("Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
937 BUFFER_FAIL(count
, len
, "3DSTATE_DRAWING_RECTANGLE");
939 instr_out(data
, hw_offset
, 0,
940 "3DSTATE_DRAWING_RECTANGLE\n");
941 instr_out(data
, hw_offset
, 1, "top left: %d,%d\n",
943 (data
[1] >> 16) & 0xffff);
944 instr_out(data
, hw_offset
, 2, "bottom right: %d,%d\n",
946 (data
[2] >> 16) & 0xffff);
947 instr_out(data
, hw_offset
, 3, "origin: %d,%d\n",
948 (int)data
[3] & 0xffff,
949 ((int)data
[3] >> 16) & 0xffff);
955 DRM_ERROR("Bad count in 3DSTATE_DEPTH_BUFFER\n");
957 BUFFER_FAIL(count
, len
, "3DSTATE_DEPTH_BUFFER");
959 instr_out(data
, hw_offset
, 0,
960 "3DSTATE_DEPTH_BUFFER\n");
961 instr_out(data
, hw_offset
, 1, "%s, %s, pitch = %d bytes, %stiled\n",
962 get_965_surfacetype(data
[1] >> 29),
963 get_965_depthformat((data
[1] >> 18) & 0x7),
964 (data
[1] & 0x0001ffff) + 1,
965 data
[1] & (1 << 27) ? "" : "not ");
966 instr_out(data
, hw_offset
, 2, "depth offset\n");
967 instr_out(data
, hw_offset
, 3, "%dx%d\n",
968 ((data
[3] & 0x0007ffc0) >> 6) + 1,
969 ((data
[3] & 0xfff80000) >> 19) + 1);
970 instr_out(data
, hw_offset
, 4, "volume depth\n");
975 for (opcode
= 0; opcode
< sizeof(opcodes_3d
) / sizeof(opcodes_3d
[0]);
977 if ((data
[0] & 0xffff0000) >> 16 == opcodes_3d
[opcode
].opcode
) {
981 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_3d
[opcode
].name
);
982 if (opcodes_3d
[opcode
].max_len
> 1) {
983 len
= (data
[0] & 0xff) + 2;
984 if (len
< opcodes_3d
[opcode
].min_len
||
985 len
> opcodes_3d
[opcode
].max_len
)
987 DRM_ERROR("Bad count in %s\n", opcodes_3d
[opcode
].name
);
991 for (i
= 1; i
< len
; i
++) {
993 BUFFER_FAIL(count
, len
, opcodes_3d
[opcode
].name
);
994 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
1000 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
1007 decode_3d_i830(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
1009 unsigned int opcode
;
1017 { 0x02, 1, 1, "3DSTATE_MODES_3" },
1018 { 0x03, 1, 1, "3DSTATE_ENABLES_1"},
1019 { 0x04, 1, 1, "3DSTATE_ENABLES_2"},
1020 { 0x05, 1, 1, "3DSTATE_VFT0"},
1021 { 0x06, 1, 1, "3DSTATE_AA"},
1022 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
1023 { 0x08, 1, 1, "3DSTATE_MODES_1" },
1024 { 0x09, 1, 1, "3DSTATE_STENCIL_TEST" },
1025 { 0x0a, 1, 1, "3DSTATE_VFT1"},
1026 { 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" },
1027 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
1028 { 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" },
1029 { 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" },
1030 { 0x0f, 1, 1, "3DSTATE_MODES_2" },
1031 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
1032 { 0x16, 1, 1, "3DSTATE_MODES_4" },
1035 switch ((data
[0] & 0x1f000000) >> 24) {
1037 return decode_3d_primitive(data
, count
, hw_offset
, failures
);
1039 return decode_3d_1d(data
, count
, hw_offset
, failures
, 1);
1041 return decode_3d_1c(data
, count
, hw_offset
, failures
);
1044 for (opcode
= 0; opcode
< sizeof(opcodes_3d
) / sizeof(opcodes_3d
[0]);
1046 if ((data
[0] & 0x1f000000) >> 24 == opcodes_3d
[opcode
].opcode
) {
1047 unsigned int len
= 1, i
;
1049 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_3d
[opcode
].name
);
1050 if (opcodes_3d
[opcode
].max_len
> 1) {
1051 len
= (data
[0] & 0xff) + 2;
1052 if (len
< opcodes_3d
[opcode
].min_len
||
1053 len
> opcodes_3d
[opcode
].max_len
)
1055 DRM_ERROR("Bad count in %s\n", opcodes_3d
[opcode
].name
);
1059 for (i
= 1; i
< len
; i
++) {
1061 BUFFER_FAIL(count
, len
, opcodes_3d
[opcode
].name
);
1062 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
1068 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
1073 void i915_gem_command_decode(uint32_t *data
, int count
, uint32_t hw_offset
, struct drm_device
*dev
)
1078 while (index
< count
) {
1079 switch ((data
[index
] & 0xe0000000) >> 29) {
1081 index
+= decode_mi(data
+ index
, count
- index
,
1082 hw_offset
+ index
* 4, &failures
);
1085 index
+= decode_2d(data
+ index
, count
- index
,
1086 hw_offset
+ index
* 4, &failures
);
1089 if (IS_I965G(dev
)) {
1090 index
+= decode_3d_965(data
+ index
, count
- index
,
1091 hw_offset
+ index
* 4, &failures
);
1092 } else if (IS_I9XX(dev
)) {
1093 index
+= decode_3d(data
+ index
, count
- index
,
1094 hw_offset
+ index
* 4, &failures
);
1096 index
+= decode_3d_i830(data
+ index
, count
- index
,
1097 hw_offset
+ index
* 4, &failures
);
1101 instr_out(data
, hw_offset
, index
, "UNKNOWN\n");