xref: /titanic_41/usr/src/uts/intel/io/drm/i915_gem_debug.c (revision 8528fe16977bc782796e5b44702e9cc3aaa636de)
1 /* BEGIN CSTYLED */
2 
3 /*
4  * Copyright (c) 2009, Intel Corporation.
5  * All Rights Reserved.
6  *
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:
13  *
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
16  * Software.
17  *
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
24  * IN THE SOFTWARE.
25  *
26  * Authors:
27  *    Keith Packard <keithp@keithp.com>
28  *
29  */
30 
31 /*
32  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
33  * Use is subject to license terms.
34  */
35 
36 #include "drmP.h"
37 #include "drm.h"
38 #include "i915_drm.h"
39 #include "i915_drv.h"
40 
41 #define BUFFER_FAIL(_count, _len, _name) { 			\
42 	DRM_ERROR("Buffer size too small in %s (%d < %d)\n",	\
43 	    (_name), (_count), (_len));				\
44 	(*failures)++;						\
45 	return count;						\
46 }
47 
48 
49 static uint32_t saved_s2 = 0, saved_s4 = 0;
50 static char saved_s2_set = 0, saved_s4_set = 0;
51 
52 static void
instr_out(uint32_t * data,uint32_t hw_offset,unsigned int index,const char * fmt,...)53 instr_out(uint32_t *data, uint32_t hw_offset, unsigned int index,
54 	  const char *fmt, ...)
55 {
56 
57     DRM_ERROR("0x%08x: 0x%08x:%s ", hw_offset + index * 4, data[index],
58 	    index == 0 ? "" : "  ");
59         va_list ap;
60 
61         va_start(ap, fmt);
62         vcmn_err(CE_WARN, fmt, ap);
63         va_end(ap);
64 
65 }
66 
67 static int
decode_mi(uint32_t * data,int count,uint32_t hw_offset,int * failures)68 decode_mi(uint32_t *data, int count, uint32_t hw_offset, int *failures)
69 {
70     unsigned int opcode;
71 
72     struct {
73 	uint32_t opcode;
74 	int min_len;
75 	int max_len;
76 	char *name;
77     } opcodes_mi[] = {
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" },
95     };
96 
97 
98     for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
99 	 opcode++) {
100 	if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
101 	    unsigned int len = 1, i;
102 
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)
108 		{
109 		    DRM_ERROR("Bad length in %s\n",
110 			    opcodes_mi[opcode].name);
111 		}
112 	    }
113 
114 	    for (i = 1; i < len; i++) {
115 		if (i >= count)
116 		    BUFFER_FAIL(count, len, opcodes_mi[opcode].name);
117 		instr_out(data, hw_offset, i, "dword %d\n", i);
118 	    }
119 
120 	    return len;
121 	}
122     }
123 
124     instr_out(data, hw_offset, 0, "MI UNKNOWN\n");
125     (*failures)++;
126     return 1;
127 }
128 
129 static int
decode_2d(uint32_t * data,int count,uint32_t hw_offset,int * failures)130 decode_2d(uint32_t *data, int count, uint32_t hw_offset, int *failures)
131 {
132     unsigned int opcode, len;
133     char *format = NULL;
134 
135     struct {
136 	uint32_t opcode;
137 	int min_len;
138 	int max_len;
139 	char *name;
140     } opcodes_2d[] = {
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" },
166     };
167 
168     switch ((data[0] & 0x1fc00000) >> 22) {
169     case 0x50:
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);
175 
176 	len = (data[0] & 0x000000ff) + 2;
177 	if (len != 6)
178 	    DRM_ERROR("Bad count in XY_COLOR_BLT\n");
179 	if (count < 6)
180 	    BUFFER_FAIL(count, len, "XY_COLOR_BLT");
181 
182 	switch ((data[1] >> 24) & 0x3) {
183 	case 0:
184 	    format="8";
185 	    break;
186 	case 1:
187 	    format="565";
188 	    break;
189 	case 2:
190 	    format="1555";
191 	    break;
192 	case 3:
193 	    format="8888";
194 	    break;
195 	}
196 
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");
207 	return len;
208     case 0x53:
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",
214 		  (data[0] >> 15) & 1,
215 		  (data[0] >> 11) & 1);
216 
217 	len = (data[0] & 0x000000ff) + 2;
218 	if (len != 8)
219 	    DRM_ERROR("Bad count in XY_SRC_COPY_BLT\n");
220 	if (count < 8)
221 	    BUFFER_FAIL(count, len, "XY_SRC_COPY_BLT");
222 
223 	switch ((data[1] >> 24) & 0x3) {
224 	case 0:
225 	    format="8";
226 	    break;
227 	case 1:
228 	    format="565";
229 	    break;
230 	case 2:
231 	    format="1555";
232 	    break;
233 	case 3:
234 	    format="8888";
235 	    break;
236 	}
237 
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]);
252 	return len;
253     }
254 
255     for (opcode = 0; opcode < sizeof(opcodes_2d) / sizeof(opcodes_2d[0]);
256 	 opcode++) {
257 	if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) {
258 	    unsigned int i;
259 
260 	    len = 1;
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)
266 		{
267 		    DRM_ERROR("Bad count in %s\n", opcodes_2d[opcode].name);
268 		}
269 	    }
270 
271 	    for (i = 1; i < len; i++) {
272 		if (i >= count)
273 		    BUFFER_FAIL(count, len, opcodes_2d[opcode].name);
274 		instr_out(data, hw_offset, i, "dword %d\n", i);
275 	    }
276 
277 	    return len;
278 	}
279     }
280 
281     instr_out(data, hw_offset, 0, "2D UNKNOWN\n");
282     (*failures)++;
283     return 1;
284 }
285 
286 /*ARGSUSED*/
287 static int
decode_3d_1c(uint32_t * data,int count,uint32_t hw_offset,int * failures)288 decode_3d_1c(uint32_t *data, int count, uint32_t hw_offset, int *failures)
289 {
290     switch ((data[0] & 0x00f80000) >> 19) {
291     case 0x11:
292 	instr_out(data, hw_offset, 0, "3DSTATE_DEPTH_SUBRECTANGLE_DISALBE\n");
293 	return 1;
294     case 0x10:
295 	instr_out(data, hw_offset, 0, "3DSTATE_SCISSOR_ENABLE\n");
296 	return 1;
297     case 0x01:
298 	instr_out(data, hw_offset, 0, "3DSTATE_MAP_COORD_SET_I830\n");
299 	return 1;
300     case 0x0a:
301 	instr_out(data, hw_offset, 0, "3DSTATE_MAP_CUBE_I830\n");
302 	return 1;
303     case 0x05:
304 	instr_out(data, hw_offset, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
305 	return 1;
306     }
307 
308     instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
309     (*failures)++;
310     return 1;
311 }
312 
313 static int
decode_3d_1d(uint32_t * data,int count,uint32_t hw_offset,int * failures,int i830)314 decode_3d_1d(uint32_t *data, int count, uint32_t hw_offset, int *failures, int i830)
315 {
316     unsigned int len, i, c, opcode, word, map, sampler, instr;
317 
318     struct {
319 	uint32_t opcode;
320 	int i830_only;
321 	int min_len;
322 	int max_len;
323 	char *name;
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" },
347     };
348 
349     switch ((data[0] & 0x00ff0000) >> 16) {
350     case 0x07:
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.
355 	 */
356 	instr_out(data, hw_offset, 0, "3DSTATE_LOAD_INDIRECT\n");
357 	len = (data[0] & 0x000000ff) + 1;
358 	i = 1;
359 	if (data[0] & (0x01 << 8)) {
360 	    if (i + 2 >= count)
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");
364 	}
365 	if (data[0] & (0x02 << 8)) {
366 	    if (i + 1 >= count)
367 		BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT");
368 	    instr_out(data, hw_offset, i++, "DIS.0\n");
369 	}
370 	if (data[0] & (0x04 << 8)) {
371 	    if (i + 2 >= count)
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");
375 	}
376 	if (data[0] & (0x08 << 8)) {
377 	    if (i + 2 >= count)
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");
381 	}
382 	if (data[0] & (0x10 << 8)) {
383 	    if (i + 2 >= count)
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");
387 	}
388 	if (data[0] & (0x20 << 8)) {
389 	    if (i + 2 >= count)
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");
393 	}
394 	if (len != i) {
395 	    DRM_ERROR("Bad count in 3DSTATE_LOAD_INDIRECT\n");
396 	    (*failures)++;
397 	    return len;
398 	}
399 	return len;
400     case 0x04:
401 	instr_out(data, hw_offset, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
402 	len = (data[0] & 0x0000000f) + 2;
403 	i = 1;
404 	for (word = 0; word <= 7; word++) {
405 	    if (data[0] & (1 << (4 + word))) {
406 		if (i >= count)
407 		    BUFFER_FAIL(count, len, "3DSTATE_LOAD_STATE_IMMEDIATE_1");
408 
409 		/* save vertex state for decode */
410 		if (word == 2) {
411 		    saved_s2_set = 1;
412 		    saved_s2 = data[i];
413 		}
414 		if (word == 4) {
415 		    saved_s4_set = 1;
416 		    saved_s4 = data[i];
417 		}
418 
419 		instr_out(data, hw_offset, i++, "S%d\n", word);
420 	    }
421 	}
422 	if (len != i) {
423 	    DRM_ERROR("Bad count in 3DSTATE_LOAD_INDIRECT\n");
424 	    (*failures)++;
425 	}
426 	return len;
427     case 0x00:
428 	instr_out(data, hw_offset, 0, "3DSTATE_MAP_STATE\n");
429 	len = (data[0] & 0x0000003f) + 2;
430 
431 	i = 1;
432 	for (map = 0; map <= 15; map++) {
433 	    if (data[1] & (1 << map)) {
434 		if (i + 3 >= count)
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);
439 	    }
440 	}
441 	if (len != i) {
442 	    DRM_ERROR("Bad count in 3DSTATE_MAP_STATE\n");
443 	    (*failures)++;
444 	    return len;
445 	}
446 	return len;
447     case 0x06:
448 	instr_out(data, hw_offset, 0, "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
449 	len = (data[0] & 0x000000ff) + 2;
450 
451 	i = 1;
452 	for (c = 0; c <= 31; c++) {
453 	    if (data[1] & (1 << c)) {
454 		if (i + 4 >= count)
455 		    BUFFER_FAIL(count, len, "3DSTATE_PIXEL_SHADER_CONSTANTS");
456 		instr_out(data, hw_offset, i, "C%d.X = %x float\n",
457 			  c, data[i]);
458 		i++;
459 		instr_out(data, hw_offset, i, "C%d.Y = %x float\n",
460 			  c, data[i]);
461 		i++;
462 		instr_out(data, hw_offset, i, "C%d.Z = %x float\n",
463 			  c, data[i]);
464 		i++;
465 		instr_out(data, hw_offset, i, "C%d.W = %x float\n",
466 			  c, data[i]);
467 		i++;
468 	    }
469 	}
470 	if (len != i) {
471 	    DRM_ERROR("Bad count in 3DSTATE_MAP_STATE\n");
472 	    (*failures)++;
473 	}
474 	return len;
475     case 0x05:
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");
480 	    (*failures)++;
481 	}
482 	i = 1;
483 	for (instr = 0; instr < (len - 1) / 3; instr++) {
484 	    if (i + 3 >= count)
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);
489 	}
490 	return len;
491     case 0x01:
492 	if (i830)
493 	    break;
494 	instr_out(data, hw_offset, 0, "3DSTATE_SAMPLER_STATE\n");
495 	len = (data[0] & 0x0000003f) + 2;
496 	i = 1;
497 	for (sampler = 0; sampler <= 15; sampler++) {
498 	    if (data[1] & (1 << sampler)) {
499 		if (i + 3 >= count)
500 		    BUFFER_FAIL(count, len, "3DSTATE_SAMPLER_STATE");
501 		instr_out(data, hw_offset, i++, "sampler %d SS2\n",
502 			  sampler);
503 		instr_out(data, hw_offset, i++, "sampler %d SS3\n",
504 			  sampler);
505 		instr_out(data, hw_offset, i++, "sampler %d SS4\n",
506 			  sampler);
507 	    }
508 	}
509 	if (len != i) {
510 	    DRM_ERROR("Bad count in 3DSTATE_SAMPLER_STATE\n");
511 	    (*failures)++;
512 	}
513 	return len;
514     }
515 
516     for (opcode = 0; opcode < sizeof(opcodes_3d_1d) / sizeof(opcodes_3d_1d[0]);
517 	 opcode++)
518     {
519 	if (opcodes_3d_1d[opcode].i830_only && !i830)
520 	    continue;
521 
522 	if (((data[0] & 0x00ff0000) >> 16) == opcodes_3d_1d[opcode].opcode) {
523 	    len = 1;
524 
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)
530 		{
531 		    DRM_ERROR("Bad count in %s\n",
532 			    opcodes_3d_1d[opcode].name);
533 		    (*failures)++;
534 		}
535 	    }
536 
537 	    for (i = 1; i < len; i++) {
538 		if (i >= count)
539 		    BUFFER_FAIL(count, len,  opcodes_3d_1d[opcode].name);
540 		instr_out(data, hw_offset, i, "dword %d\n", i);
541 	    }
542 
543 	    return len;
544 	}
545     }
546 
547     instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
548     (*failures)++;
549     return 1;
550 }
551 
552 static int
decode_3d_primitive(uint32_t * data,int count,uint32_t hw_offset,int * failures)553 decode_3d_primitive(uint32_t *data, int count, uint32_t hw_offset,
554 		    int *failures)
555 {
556     char immediate = (data[0] & (1 << 23)) == 0;
557     unsigned int len, i;
558     char *primtype;
559 
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;
573     }
574 
575     /* XXX: 3DPRIM_DIB not supported */
576     if (immediate) {
577 	len = (data[0] & 0x0003ffff) + 2;
578 	instr_out(data, hw_offset, 0, "3DPRIMITIVE inline %s\n", primtype);
579 	if (count < len)
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",
586 			  data[i]);
587 	    }
588 	} else {
589 	    unsigned int vertex = 0;
590 	    for (i = 1; i < len;) {
591 		unsigned int tc;
592 
593 #define VERTEX_OUT(fmt, ...) {					\
594     if (i < len)							\
595 	instr_out(data, hw_offset, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
596     else								\
597 	DRM_ERROR(" missing data in V%d\n", vertex);			\
598     i++;								\
599 }
600 
601 		VERTEX_OUT("X = %x float", data[i]);
602 		VERTEX_OUT("Y = %x float", data[i]);
603 	        switch (saved_s4 >> 6 & 0x7) {
604 		case 0x1:
605 		    VERTEX_OUT("Z = %x float", data[i]);
606 		    break;
607 		case 0x2:
608 		    VERTEX_OUT("Z = %x float", data[i]);
609 		    VERTEX_OUT("W = %x float", data[i]);
610 		    break;
611 		case 0x3:
612 		    break;
613 		case 0x4:
614 		    VERTEX_OUT("W = %x float", data[i]);
615 		    break;
616 		default:
617 		    DRM_ERROR("bad S4 position mask\n");
618 		}
619 
620 		if (saved_s4 & (1 << 10)) {
621 		    VERTEX_OUT("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
622 			       "B=0x%02x)",
623 			       data[i] >> 24,
624 			       (data[i] >> 16) & 0xff,
625 			       (data[i] >> 8) & 0xff,
626 			       data[i] & 0xff);
627 		}
628 		if (saved_s4 & (1 << 11)) {
629 		    VERTEX_OUT("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
630 			       "B=0x%02x)",
631 			       data[i] >> 24,
632 			       (data[i] >> 16) & 0xff,
633 			       (data[i] >> 8) & 0xff,
634 			       data[i] & 0xff);
635 		}
636 		if (saved_s4 & (1 << 12))
637 		    VERTEX_OUT("width = 0x%08x)", data[i]);
638 
639 		for (tc = 0; tc <= 7; tc++) {
640 		    switch ((saved_s2 >> (tc * 4)) & 0xf) {
641 		    case 0x0:
642 			VERTEX_OUT("T%d.X = %x float", tc, data[i]);
643 			VERTEX_OUT("T%d.Y = %x float", tc, data[i]);
644 			break;
645 		    case 0x1:
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]);
649 			break;
650 		    case 0x2:
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]);
655 			break;
656 		    case 0x3:
657 			VERTEX_OUT("T%d.X = %x float", tc, data[i]);
658 			break;
659 		    case 0x4:
660 			VERTEX_OUT("T%d.XY = 0x%08x half-float", tc, data[i]);
661 			break;
662 		    case 0x5:
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]);
665 			break;
666 		    case 0xf:
667 			break;
668 		    default:
669 			DRM_ERROR("bad S2.T%d format\n", tc);
670 		    }
671 		}
672 		vertex++;
673 	    }
674 	}
675     } else {
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);
684 	    if (len == 0) {
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");
690 			return i;
691 		    } else if ((data[i] >> 16) == 0xffff) {
692 			instr_out(data, hw_offset, i,
693 				  "            indices: 0x%04x, "
694 				  "(terminator)\n",
695 				  data[i] & 0xffff);
696 			return i;
697 		    } else {
698 			instr_out(data, hw_offset, i,
699 				  "            indices: 0x%04x, 0x%04x\n",
700 				  data[i] & 0xffff, data[i] >> 16);
701 		    }
702 		}
703 		DRM_ERROR("3DPRIMITIVE: no terminator found in index buffer\n");
704 		(*failures)++;
705 		return count;
706 	    } else {
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",
712 				  data[i] & 0xffff);
713 		    } else {
714 			instr_out(data, hw_offset, i,
715 				  "            indices: 0x%04x, 0x%04x\n",
716 				  data[i] & 0xffff, data[i] >> 16);
717 		    }
718 		}
719 	    }
720 	    return (len + 1) / 2 + 1;
721 	} else {
722 	    /* sequential vertex access */
723 	    if (count < 2)
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");
729 	    return 2;
730 	}
731     }
732 
733     return len;
734 }
735 
736 static int
decode_3d(uint32_t * data,int count,uint32_t hw_offset,int * failures)737 decode_3d(uint32_t *data, int count, uint32_t hw_offset, int *failures)
738 {
739     unsigned int opcode;
740 
741     struct {
742 	uint32_t opcode;
743 	int min_len;
744 	int max_len;
745 	char *name;
746     } opcodes_3d[] = {
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" },
756     };
757 
758     switch ((data[0] & 0x1f000000) >> 24) {
759     case 0x1f:
760 	return decode_3d_primitive(data, count, hw_offset, failures);
761     case 0x1d:
762 	return decode_3d_1d(data, count, hw_offset, failures, 0);
763     case 0x1c:
764 	return decode_3d_1c(data, count, hw_offset, failures);
765     }
766 
767     for (opcode = 0; opcode < sizeof(opcodes_3d) / sizeof(opcodes_3d[0]);
768 	 opcode++) {
769 	if ((data[0] & 0x1f000000) >> 24 == opcodes_3d[opcode].opcode) {
770 	    unsigned int len = 1, i;
771 
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)
777 		{
778 		    DRM_ERROR("Bad count in %s\n", opcodes_3d[opcode].name);
779 		}
780 	    }
781 
782 	    for (i = 1; i < len; i++) {
783 		if (i >= count)
784 		    BUFFER_FAIL(count, len, opcodes_3d[opcode].name);
785 		instr_out(data, hw_offset, i, "dword %d\n", i);
786 	    }
787 	    return len;
788 	}
789     }
790 
791     instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
792     (*failures)++;
793     return 1;
794 }
795 
796 static const char *
get_965_surfacetype(unsigned int surfacetype)797 get_965_surfacetype(unsigned int surfacetype)
798 {
799     switch (surfacetype) {
800     case 0: return "1D";
801     case 1: return "2D";
802     case 2: return "3D";
803     case 3: return "CUBE";
804     case 4: return "BUFFER";
805     case 7: return "NULL";
806     default: return "unknown";
807     }
808 }
809 
810 static const char *
get_965_depthformat(unsigned int depthformat)811 get_965_depthformat(unsigned int depthformat)
812 {
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";
819     }
820 }
821 
822 static int
decode_3d_965(uint32_t * data,int count,uint32_t hw_offset,int * failures)823 decode_3d_965(uint32_t *data, int count, uint32_t hw_offset, int *failures)
824 {
825     unsigned int opcode, len;
826 
827     struct {
828 	uint32_t opcode;
829 	int min_len;
830 	int max_len;
831 	char *name;
832     } opcodes_3d[] = {
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" },
857     };
858 
859     len = (data[0] & 0x0000ffff) + 2;
860 
861     switch ((data[0] & 0xffff0000) >> 16) {
862     case 0x6101:
863 	if (len != 6)
864 	    DRM_ERROR("Bad count in STATE_BASE_ADDRESS\n");
865 	if (count < 6)
866 	    BUFFER_FAIL(count, len, "STATE_BASE_ADDRESS");
867 
868 	instr_out(data, hw_offset, 0,
869 		  "STATE_BASE_ADDRESS\n");
870 
871 	if (data[1] & 1) {
872 	    instr_out(data, hw_offset, 1, "General state at 0x%08x\n",
873 		      data[1] & ~1);
874 	} else
875 	    instr_out(data, hw_offset, 1, "General state not updated\n");
876 
877 	if (data[2] & 1) {
878 	    instr_out(data, hw_offset, 2, "Surface state at 0x%08x\n",
879 		      data[2] & ~1);
880 	} else
881 	    instr_out(data, hw_offset, 2, "Surface state not updated\n");
882 
883 	if (data[3] & 1) {
884 	    instr_out(data, hw_offset, 3, "Indirect state at 0x%08x\n",
885 		      data[3] & ~1);
886 	} else
887 	    instr_out(data, hw_offset, 3, "Indirect state not updated\n");
888 
889 	if (data[4] & 1) {
890 	    instr_out(data, hw_offset, 4, "General state upper bound 0x%08x\n",
891 		      data[4] & ~1);
892 	} else
893 	    instr_out(data, hw_offset, 4, "General state not updated\n");
894 
895 	if (data[5] & 1) {
896 	    instr_out(data, hw_offset, 5, "Indirect state upper bound 0x%08x\n",
897 		      data[5] & ~1);
898 	} else
899 	    instr_out(data, hw_offset, 5, "Indirect state not updated\n");
900 
901 	return len;
902     case 0x7800:
903 	if (len != 7)
904 	    DRM_ERROR("Bad count in 3DSTATE_PIPELINED_POINTERS\n");
905 	if (count < 7)
906 	    BUFFER_FAIL(count, len, "3DSTATE_PIPELINED_POINTERS");
907 
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");
916 	return len;
917     case 0x7801:
918 	if (len != 6)
919 	    DRM_ERROR("Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
920 	if (count < 6)
921 	    BUFFER_FAIL(count, len, "3DSTATE_BINDING_TABLE_POINTERS");
922 
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");
930 
931 	return len;
932 
933     case 0x7900:
934 	if (len != 4)
935 	    DRM_ERROR("Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
936 	if (count < 4)
937 	    BUFFER_FAIL(count, len, "3DSTATE_DRAWING_RECTANGLE");
938 
939 	instr_out(data, hw_offset, 0,
940 		  "3DSTATE_DRAWING_RECTANGLE\n");
941 	instr_out(data, hw_offset, 1, "top left: %d,%d\n",
942 		  data[1] & 0xffff,
943 		  (data[1] >> 16) & 0xffff);
944 	instr_out(data, hw_offset, 2, "bottom right: %d,%d\n",
945 		  data[2] & 0xffff,
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);
950 
951 	return len;
952 
953     case 0x7905:
954 	if (len != 5)
955 	    DRM_ERROR("Bad count in 3DSTATE_DEPTH_BUFFER\n");
956 	if (count < 5)
957 	    BUFFER_FAIL(count, len, "3DSTATE_DEPTH_BUFFER");
958 
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");
971 
972 	return len;
973     }
974 
975     for (opcode = 0; opcode < sizeof(opcodes_3d) / sizeof(opcodes_3d[0]);
976 	 opcode++) {
977 	if ((data[0] & 0xffff0000) >> 16 == opcodes_3d[opcode].opcode) {
978 	    unsigned int i;
979 	    len = 1;
980 
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)
986 		{
987 		    DRM_ERROR("Bad count in %s\n", opcodes_3d[opcode].name);
988 		}
989 	    }
990 
991 	    for (i = 1; i < len; i++) {
992 		if (i >= count)
993 		    BUFFER_FAIL(count, len, opcodes_3d[opcode].name);
994 		instr_out(data, hw_offset, i, "dword %d\n", i);
995 	    }
996 	    return len;
997 	}
998     }
999 
1000     instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
1001     (*failures)++;
1002     return 1;
1003 }
1004 
1005 
1006 static int
decode_3d_i830(uint32_t * data,int count,uint32_t hw_offset,int * failures)1007 decode_3d_i830(uint32_t *data, int count, uint32_t hw_offset, int *failures)
1008 {
1009     unsigned int opcode;
1010 
1011     struct {
1012 	uint32_t opcode;
1013 	int min_len;
1014 	int max_len;
1015 	char *name;
1016     } opcodes_3d[] = {
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" },
1033     };
1034 
1035     switch ((data[0] & 0x1f000000) >> 24) {
1036     case 0x1f:
1037 	return decode_3d_primitive(data, count, hw_offset, failures);
1038     case 0x1d:
1039 	return decode_3d_1d(data, count, hw_offset, failures, 1);
1040     case 0x1c:
1041 	return decode_3d_1c(data, count, hw_offset, failures);
1042     }
1043 
1044     for (opcode = 0; opcode < sizeof(opcodes_3d) / sizeof(opcodes_3d[0]);
1045 	 opcode++) {
1046 	if ((data[0] & 0x1f000000) >> 24 == opcodes_3d[opcode].opcode) {
1047 	    unsigned int len = 1, i;
1048 
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)
1054 		{
1055 		    DRM_ERROR("Bad count in %s\n", opcodes_3d[opcode].name);
1056 		}
1057 	    }
1058 
1059 	    for (i = 1; i < len; i++) {
1060 		if (i >= count)
1061 		    BUFFER_FAIL(count, len, opcodes_3d[opcode].name);
1062 		instr_out(data, hw_offset, i, "dword %d\n", i);
1063 	    }
1064 	    return len;
1065 	}
1066     }
1067 
1068     instr_out(data, hw_offset, 0, "3D UNKNOWN\n");
1069     (*failures)++;
1070     return 1;
1071 }
1072 
i915_gem_command_decode(uint32_t * data,int count,uint32_t hw_offset,struct drm_device * dev)1073 void i915_gem_command_decode(uint32_t *data, int count, uint32_t hw_offset, struct drm_device *dev)
1074 {
1075     int index = 0;
1076     int failures = 0;
1077 
1078    while (index < count) {
1079 	switch ((data[index] & 0xe0000000) >> 29) {
1080 	case 0x0:
1081 	    index += decode_mi(data + index, count - index,
1082 			       hw_offset + index * 4, &failures);
1083 	    break;
1084 	case 0x2:
1085 	    index += decode_2d(data + index, count - index,
1086 			       hw_offset + index * 4, &failures);
1087 	    break;
1088 	case 0x3:
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);
1095 	    } else {
1096 		index += decode_3d_i830(data + index, count - index,
1097 					hw_offset + index * 4, &failures);
1098 	    }
1099 	    break;
1100 	default:
1101 	    instr_out(data, hw_offset, index, "UNKNOWN\n");
1102 	    failures++;
1103 	    index++;
1104 	    break;
1105 	}
1106     }
1107 }
1108 
1109