blob: 2b902a39f352ea8aca2290e6adcdce1e0d8e271e [file] [log] [blame]
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001/*
2 * Copyright © 2009-2011 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
Maarten Lankhorst07fead42014-07-31 15:07:27 +020024#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
Eric Anholt9695eee2012-01-04 12:00:59 -080028#include <assert.h>
Eric Anholt8c4a2c82011-12-20 11:25:20 -080029#include <stdint.h>
Eric Anholt71066ab2011-12-20 13:06:16 -080030#include <stdlib.h>
Eric Anholt8c4a2c82011-12-20 11:25:20 -080031#include <stdio.h>
Eric Anholt71066ab2011-12-20 13:06:16 -080032#include <stdbool.h>
Eric Anholt8c4a2c82011-12-20 11:25:20 -080033#include <stdarg.h>
34#include <string.h>
35
Emil Velikov42465fe2015-04-05 15:51:59 +010036#include "libdrm_macros.h"
Thierry Reding44b08c02014-01-22 12:06:51 +010037#include "xf86drm.h"
Eric Anholt8c4a2c82011-12-20 11:25:20 -080038#include "intel_chipset.h"
Eric Anholt71066ab2011-12-20 13:06:16 -080039#include "intel_bufmgr.h"
40
41/* Struct for tracking drm_intel_decode state. */
42struct drm_intel_decode {
Eric Anholtea33a232012-01-03 13:05:57 -080043 /** stdio file where the output should land. Defaults to stdout. */
44 FILE *out;
45
Eric Anholt71066ab2011-12-20 13:06:16 -080046 /** PCI device ID. */
47 uint32_t devid;
48
Eric Anholt9695eee2012-01-04 12:00:59 -080049 /**
50 * Shorthand device identifier: 3 is 915, 4 is 965, 5 is
51 * Ironlake, etc.
52 */
53 int gen;
54
Eric Anholt8fb66a72011-12-20 14:59:38 -080055 /** GPU address of the start of the current packet. */
Eric Anholt71066ab2011-12-20 13:06:16 -080056 uint32_t hw_offset;
Eric Anholt8fb66a72011-12-20 14:59:38 -080057 /** CPU virtual address of the start of the current packet. */
Eric Anholt71066ab2011-12-20 13:06:16 -080058 uint32_t *data;
Eric Anholt8fb66a72011-12-20 14:59:38 -080059 /** DWORDs of remaining batchbuffer data starting from the packet. */
Eric Anholt71066ab2011-12-20 13:06:16 -080060 uint32_t count;
61
Eric Anholt8fb66a72011-12-20 14:59:38 -080062 /** GPU address of the start of the batchbuffer data. */
63 uint32_t base_hw_offset;
64 /** CPU Virtual address of the start of the batchbuffer data. */
65 uint32_t *base_data;
66 /** Number of DWORDs of batchbuffer data. */
67 uint32_t base_count;
68
Eric Anholt71066ab2011-12-20 13:06:16 -080069 /** @{
70 * GPU head and tail pointers, which will be noted in the dump, or ~0.
71 */
72 uint32_t head, tail;
73 /** @} */
74
75 /**
76 * Whether to dump the dwords after MI_BATCHBUFFER_END.
77 *
78 * This sometimes provides clues in corrupted batchbuffers,
79 * and is used by the intel-gpu-tools.
80 */
81 bool dump_past_end;
Eric Anholt028715e2012-01-04 12:31:40 -080082
83 bool overflowed;
Eric Anholt71066ab2011-12-20 13:06:16 -080084};
Eric Anholt8c4a2c82011-12-20 11:25:20 -080085
86static FILE *out;
87static uint32_t saved_s2 = 0, saved_s4 = 0;
88static char saved_s2_set = 0, saved_s4_set = 0;
Eric Anholt193fa132011-12-20 11:36:07 -080089static uint32_t head_offset = 0xffffffff; /* undefined */
90static uint32_t tail_offset = 0xffffffff; /* undefined */
Eric Anholt8c4a2c82011-12-20 11:25:20 -080091
92#ifndef ARRAY_SIZE
93#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
94#endif
95
96#define BUFFER_FAIL(_count, _len, _name) do { \
97 fprintf(out, "Buffer size too small in %s (%d < %d)\n", \
98 (_name), (_count), (_len)); \
Eric Anholtc1d29462011-12-20 15:29:03 -080099 return _count; \
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800100} while (0)
101
Eric Anholt193fa132011-12-20 11:36:07 -0800102static float int_as_float(uint32_t intval)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800103{
Eric Anholt193fa132011-12-20 11:36:07 -0800104 union intfloat {
105 uint32_t i;
106 float f;
107 } uval;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800108
Eric Anholt193fa132011-12-20 11:36:07 -0800109 uval.i = intval;
110 return uval.f;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800111}
112
Thierry Reding44b08c02014-01-22 12:06:51 +0100113static void DRM_PRINTFLIKE(3, 4)
Eric Anholtc1d29462011-12-20 15:29:03 -0800114instr_out(struct drm_intel_decode *ctx, unsigned int index,
Eric Anholt1db55a82011-12-20 12:00:28 -0800115 const char *fmt, ...)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800116{
Eric Anholt193fa132011-12-20 11:36:07 -0800117 va_list va;
Eric Anholt1db55a82011-12-20 12:00:28 -0800118 const char *parseinfo;
Eric Anholtc1d29462011-12-20 15:29:03 -0800119 uint32_t offset = ctx->hw_offset + index * 4;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800120
Eric Anholt028715e2012-01-04 12:31:40 -0800121 if (index > ctx->count) {
122 if (!ctx->overflowed) {
123 fprintf(out, "ERROR: Decode attempted to continue beyond end of batchbuffer\n");
124 ctx->overflowed = true;
125 }
126 return;
127 }
128
Eric Anholt193fa132011-12-20 11:36:07 -0800129 if (offset == head_offset)
130 parseinfo = "HEAD";
131 else if (offset == tail_offset)
132 parseinfo = "TAIL";
133 else
134 parseinfo = " ";
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800135
Eric Anholt193fa132011-12-20 11:36:07 -0800136 fprintf(out, "0x%08x: %s 0x%08x: %s", offset, parseinfo,
Eric Anholtc1d29462011-12-20 15:29:03 -0800137 ctx->data[index], index == 0 ? "" : " ");
Eric Anholt193fa132011-12-20 11:36:07 -0800138 va_start(va, fmt);
139 vfprintf(out, fmt, va);
140 va_end(va);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800141}
142
143static int
Ben Widawskyee2be4f2012-05-27 16:10:51 -0700144decode_MI_SET_CONTEXT(struct drm_intel_decode *ctx)
145{
146 uint32_t data = ctx->data[1];
147 if (ctx->gen > 7)
148 return 1;
149
150 instr_out(ctx, 0, "MI_SET_CONTEXT\n");
151 instr_out(ctx, 1, "gtt offset = 0x%x%s%s\n",
152 data & ~0xfff,
153 data & (1<<1)? ", Force Restore": "",
154 data & (1<<0)? ", Restore Inhibit": "");
155
156 return 2;
157}
158
159static int
Daniel Vetter43704252012-04-02 13:08:09 +0200160decode_MI_WAIT_FOR_EVENT(struct drm_intel_decode *ctx)
161{
162 const char *cc_wait;
163 int cc_shift = 0;
164 uint32_t data = ctx->data[0];
165
166 if (ctx->gen <= 5)
167 cc_shift = 9;
168 else
169 cc_shift = 16;
170
171 switch ((data >> cc_shift) & 0x1f) {
172 case 1:
173 cc_wait = ", cc wait 1";
174 break;
175 case 2:
176 cc_wait = ", cc wait 2";
177 break;
178 case 3:
179 cc_wait = ", cc wait 3";
180 break;
181 case 4:
182 cc_wait = ", cc wait 4";
183 break;
184 case 5:
185 cc_wait = ", cc wait 4";
186 break;
187 default:
188 cc_wait = "";
189 break;
190 }
191
192 if (ctx->gen <= 5) {
193 instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
194 data & (1<<18)? ", pipe B start vblank wait": "",
195 data & (1<<17)? ", pipe A start vblank wait": "",
196 data & (1<<16)? ", overlay flip pending wait": "",
197 data & (1<<14)? ", pipe B hblank wait": "",
198 data & (1<<13)? ", pipe A hblank wait": "",
199 cc_wait,
200 data & (1<<8)? ", plane C pending flip wait": "",
201 data & (1<<7)? ", pipe B vblank wait": "",
202 data & (1<<6)? ", plane B pending flip wait": "",
203 data & (1<<5)? ", pipe B scan line wait": "",
204 data & (1<<4)? ", fbc idle wait": "",
205 data & (1<<3)? ", pipe A vblank wait": "",
206 data & (1<<2)? ", plane A pending flip wait": "",
207 data & (1<<1)? ", plane A scan line wait": "");
208 } else {
209 instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s\n",
210 data & (1<<20)? ", sprite C pending flip wait": "", /* ivb */
211 cc_wait,
212 data & (1<<13)? ", pipe B hblank wait": "",
213 data & (1<<11)? ", pipe B vblank wait": "",
214 data & (1<<10)? ", sprite B pending flip wait": "",
215 data & (1<<9)? ", plane B pending flip wait": "",
216 data & (1<<8)? ", plane B scan line wait": "",
217 data & (1<<5)? ", pipe A hblank wait": "",
218 data & (1<<3)? ", pipe A vblank wait": "",
219 data & (1<<2)? ", sprite A pending flip wait": "",
220 data & (1<<1)? ", plane A pending flip wait": "",
221 data & (1<<0)? ", plane A scan line wait": "");
222 }
223
224 return 1;
225}
226
227static int
Eric Anholtde49fd42011-12-20 15:15:21 -0800228decode_mi(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800229{
Eric Anholt193fa132011-12-20 11:36:07 -0800230 unsigned int opcode, len = -1;
Eric Anholt1db55a82011-12-20 12:00:28 -0800231 const char *post_sync_op = "";
Eric Anholtde49fd42011-12-20 15:15:21 -0800232 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800233
Eric Anholt193fa132011-12-20 11:36:07 -0800234 struct {
235 uint32_t opcode;
236 int len_mask;
Eric Anholt07768ba2011-12-20 13:46:23 -0800237 unsigned int min_len;
238 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -0800239 const char *name;
Daniel Vetter43704252012-04-02 13:08:09 +0200240 int (*func)(struct drm_intel_decode *ctx);
Eric Anholt193fa132011-12-20 11:36:07 -0800241 } opcodes_mi[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -0800242 { 0x08, 0, 1, 1, "MI_ARB_ON_OFF" },
243 { 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" },
244 { 0x30, 0x3f, 3, 3, "MI_BATCH_BUFFER" },
245 { 0x31, 0x3f, 2, 2, "MI_BATCH_BUFFER_START" },
246 { 0x14, 0x3f, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
247 { 0x04, 0, 1, 1, "MI_FLUSH" },
248 { 0x22, 0x1f, 3, 3, "MI_LOAD_REGISTER_IMM" },
249 { 0x13, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
250 { 0x12, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
251 { 0x00, 0, 1, 1, "MI_NOOP" },
252 { 0x11, 0x3f, 2, 2, "MI_OVERLAY_FLIP" },
253 { 0x07, 0, 1, 1, "MI_REPORT_HEAD" },
Ben Widawskyee2be4f2012-05-27 16:10:51 -0700254 { 0x18, 0x3f, 2, 2, "MI_SET_CONTEXT", decode_MI_SET_CONTEXT },
Eric Anholtbbdda922011-12-20 11:44:36 -0800255 { 0x20, 0x3f, 3, 4, "MI_STORE_DATA_IMM" },
256 { 0x21, 0x3f, 3, 4, "MI_STORE_DATA_INDEX" },
257 { 0x24, 0x3f, 3, 3, "MI_STORE_REGISTER_MEM" },
258 { 0x02, 0, 1, 1, "MI_USER_INTERRUPT" },
Daniel Vetter43704252012-04-02 13:08:09 +0200259 { 0x03, 0, 1, 1, "MI_WAIT_FOR_EVENT", decode_MI_WAIT_FOR_EVENT },
Eric Anholtbbdda922011-12-20 11:44:36 -0800260 { 0x16, 0x7f, 3, 3, "MI_SEMAPHORE_MBOX" },
261 { 0x26, 0x1f, 3, 4, "MI_FLUSH_DW" },
Kenneth Graunke551aac42013-10-29 19:30:45 -0700262 { 0x28, 0x3f, 3, 3, "MI_REPORT_PERF_COUNT" },
Kenneth Graunke45810d32013-10-29 20:41:16 -0700263 { 0x29, 0xff, 3, 3, "MI_LOAD_REGISTER_MEM" },
Eric Anholtbbdda922011-12-20 11:44:36 -0800264 { 0x0b, 0, 1, 1, "MI_SUSPEND_FLUSH"},
Daniel Vetter43704252012-04-02 13:08:09 +0200265 }, *opcode_mi = NULL;
Eric Anholt193fa132011-12-20 11:36:07 -0800266
267 /* check instruction length */
268 for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
269 opcode++) {
270 if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
271 len = 1;
272 if (opcodes_mi[opcode].max_len > 1) {
273 len =
274 (data[0] & opcodes_mi[opcode].len_mask) + 2;
275 if (len < opcodes_mi[opcode].min_len
276 || len > opcodes_mi[opcode].max_len) {
277 fprintf(out,
278 "Bad length (%d) in %s, [%d, %d]\n",
279 len, opcodes_mi[opcode].name,
280 opcodes_mi[opcode].min_len,
281 opcodes_mi[opcode].max_len);
282 }
283 }
Daniel Vetter43704252012-04-02 13:08:09 +0200284 opcode_mi = &opcodes_mi[opcode];
Eric Anholt193fa132011-12-20 11:36:07 -0800285 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800286 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800287 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800288
Daniel Vetter43704252012-04-02 13:08:09 +0200289 if (opcode_mi && opcode_mi->func)
290 return opcode_mi->func(ctx);
291
Eric Anholt193fa132011-12-20 11:36:07 -0800292 switch ((data[0] & 0x1f800000) >> 23) {
293 case 0x0a:
Eric Anholtc1d29462011-12-20 15:29:03 -0800294 instr_out(ctx, 0, "MI_BATCH_BUFFER_END\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800295 return -1;
296 case 0x16:
Eric Anholtc1d29462011-12-20 15:29:03 -0800297 instr_out(ctx, 0, "MI_SEMAPHORE_MBOX%s%s%s%s %u\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800298 data[0] & (1 << 22) ? " global gtt," : "",
299 data[0] & (1 << 21) ? " update semaphore," : "",
300 data[0] & (1 << 20) ? " compare semaphore," : "",
301 data[0] & (1 << 18) ? " use compare reg" : "",
302 (data[0] & (0x3 << 16)) >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800303 instr_out(ctx, 1, "value\n");
304 instr_out(ctx, 2, "address\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800305 return len;
306 case 0x21:
Eric Anholtc1d29462011-12-20 15:29:03 -0800307 instr_out(ctx, 0, "MI_STORE_DATA_INDEX%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800308 data[0] & (1 << 21) ? " use per-process HWS," : "");
Eric Anholtc1d29462011-12-20 15:29:03 -0800309 instr_out(ctx, 1, "index\n");
310 instr_out(ctx, 2, "dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800311 if (len == 4)
Eric Anholtc1d29462011-12-20 15:29:03 -0800312 instr_out(ctx, 3, "upper dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800313 return len;
314 case 0x00:
315 if (data[0] & (1 << 22))
Eric Anholtc1d29462011-12-20 15:29:03 -0800316 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800317 "MI_NOOP write NOPID reg, val=0x%x\n",
318 data[0] & ((1 << 22) - 1));
319 else
Eric Anholtc1d29462011-12-20 15:29:03 -0800320 instr_out(ctx, 0, "MI_NOOP\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800321 return len;
322 case 0x26:
323 switch (data[0] & (0x3 << 14)) {
324 case (0 << 14):
325 post_sync_op = "no write";
326 break;
327 case (1 << 14):
328 post_sync_op = "write data";
329 break;
330 case (2 << 14):
331 post_sync_op = "reserved";
332 break;
333 case (3 << 14):
334 post_sync_op = "write TIMESTAMP";
335 break;
336 }
Eric Anholtc1d29462011-12-20 15:29:03 -0800337 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800338 "MI_FLUSH_DW%s%s%s%s post_sync_op='%s' %s%s\n",
339 data[0] & (1 << 22) ?
340 " enable protected mem (BCS-only)," : "",
341 data[0] & (1 << 21) ? " store in hws," : "",
342 data[0] & (1 << 18) ? " invalidate tlb," : "",
343 data[0] & (1 << 17) ? " flush gfdt," : "",
344 post_sync_op,
345 data[0] & (1 << 8) ? " enable notify interrupt," : "",
346 data[0] & (1 << 7) ?
347 " invalidate video state (BCS-only)," : "");
348 if (data[0] & (1 << 21))
Eric Anholtc1d29462011-12-20 15:29:03 -0800349 instr_out(ctx, 1, "hws index\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800350 else
Eric Anholtc1d29462011-12-20 15:29:03 -0800351 instr_out(ctx, 1, "address\n");
352 instr_out(ctx, 2, "dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800353 if (len == 4)
Eric Anholtc1d29462011-12-20 15:29:03 -0800354 instr_out(ctx, 3, "upper dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800355 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800356 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800357
Eric Anholt193fa132011-12-20 11:36:07 -0800358 for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
359 opcode++) {
360 if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
Eric Anholt07768ba2011-12-20 13:46:23 -0800361 unsigned int i;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800362
Eric Anholtc1d29462011-12-20 15:29:03 -0800363 instr_out(ctx, 0, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800364 opcodes_mi[opcode].name);
Eric Anholt07768ba2011-12-20 13:46:23 -0800365 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800366 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -0800367 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800368
Eric Anholt193fa132011-12-20 11:36:07 -0800369 return len;
370 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800371 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800372
Eric Anholtc1d29462011-12-20 15:29:03 -0800373 instr_out(ctx, 0, "MI UNKNOWN\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800374 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800375}
376
377static void
Eric Anholt62b41032011-12-20 15:17:24 -0800378decode_2d_br00(struct drm_intel_decode *ctx, const char *cmd)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800379{
Eric Anholtc1d29462011-12-20 15:29:03 -0800380 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800381 "%s (rgb %sabled, alpha %sabled, src tile %d, dst tile %d)\n",
382 cmd,
Eric Anholt62b41032011-12-20 15:17:24 -0800383 (ctx->data[0] & (1 << 20)) ? "en" : "dis",
384 (ctx->data[0] & (1 << 21)) ? "en" : "dis",
385 (ctx->data[0] >> 15) & 1,
386 (ctx->data[0] >> 11) & 1);
Eric Anholt193fa132011-12-20 11:36:07 -0800387}
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800388
Eric Anholtb0371612011-12-20 15:19:24 -0800389static void
390decode_2d_br01(struct drm_intel_decode *ctx)
Eric Anholt193fa132011-12-20 11:36:07 -0800391{
Eric Anholt1db55a82011-12-20 12:00:28 -0800392 const char *format;
Eric Anholtb0371612011-12-20 15:19:24 -0800393 switch ((ctx->data[1] >> 24) & 0x3) {
Eric Anholt193fa132011-12-20 11:36:07 -0800394 case 0:
395 format = "8";
396 break;
397 case 1:
398 format = "565";
399 break;
400 case 2:
401 format = "1555";
402 break;
403 case 3:
404 format = "8888";
405 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800406 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800407
Eric Anholtc1d29462011-12-20 15:29:03 -0800408 instr_out(ctx, 1,
Eric Anholtb0371612011-12-20 15:19:24 -0800409 "format %s, pitch %d, rop 0x%02x, "
Eric Anholt193fa132011-12-20 11:36:07 -0800410 "clipping %sabled, %s%s \n",
411 format,
Eric Anholtb0371612011-12-20 15:19:24 -0800412 (short)(ctx->data[1] & 0xffff),
413 (ctx->data[1] >> 16) & 0xff,
414 ctx->data[1] & (1 << 30) ? "en" : "dis",
415 ctx->data[1] & (1 << 31) ? "solid pattern enabled, " : "",
416 ctx->data[1] & (1 << 31) ?
Eric Anholt193fa132011-12-20 11:36:07 -0800417 "mono pattern transparency enabled, " : "");
418
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800419}
420
421static int
Eric Anholtde49fd42011-12-20 15:15:21 -0800422decode_2d(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800423{
Eric Anholt193fa132011-12-20 11:36:07 -0800424 unsigned int opcode, len;
Eric Anholtde49fd42011-12-20 15:15:21 -0800425 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800426
Eric Anholt193fa132011-12-20 11:36:07 -0800427 struct {
428 uint32_t opcode;
Eric Anholt07768ba2011-12-20 13:46:23 -0800429 unsigned int min_len;
430 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -0800431 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -0800432 } opcodes_2d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -0800433 { 0x40, 5, 5, "COLOR_BLT" },
434 { 0x43, 6, 6, "SRC_COPY_BLT" },
435 { 0x01, 8, 8, "XY_SETUP_BLT" },
436 { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
437 { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
438 { 0x24, 2, 2, "XY_PIXEL_BLT" },
439 { 0x25, 3, 3, "XY_SCANLINES_BLT" },
440 { 0x26, 4, 4, "Y_TEXT_BLT" },
441 { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
442 { 0x50, 6, 6, "XY_COLOR_BLT" },
443 { 0x51, 6, 6, "XY_PAT_BLT" },
444 { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
445 { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
446 { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
447 { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
448 { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
449 { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
450 { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
451 { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
452 { 0x55, 9, 9, "XY_FULL_BLT" },
453 { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
454 { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
455 { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
456 { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
457 { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT"},
458 };
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800459
Eric Anholt193fa132011-12-20 11:36:07 -0800460 switch ((data[0] & 0x1fc00000) >> 22) {
461 case 0x25:
Eric Anholtc1d29462011-12-20 15:29:03 -0800462 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800463 "XY_SCANLINES_BLT (pattern seed (%d, %d), dst tile %d)\n",
464 (data[0] >> 12) & 0x8,
465 (data[0] >> 8) & 0x8, (data[0] >> 11) & 1);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800466
Eric Anholt193fa132011-12-20 11:36:07 -0800467 len = (data[0] & 0x000000ff) + 2;
468 if (len != 3)
469 fprintf(out, "Bad count in XY_SCANLINES_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800470
Eric Anholtc1d29462011-12-20 15:29:03 -0800471 instr_out(ctx, 1, "dest (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800472 data[1] & 0xffff, data[1] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800473 instr_out(ctx, 2, "dest (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800474 data[2] & 0xffff, data[2] >> 16);
475 return len;
476 case 0x01:
Eric Anholt62b41032011-12-20 15:17:24 -0800477 decode_2d_br00(ctx, "XY_SETUP_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800478
479 len = (data[0] & 0x000000ff) + 2;
480 if (len != 8)
481 fprintf(out, "Bad count in XY_SETUP_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800482
Eric Anholtb0371612011-12-20 15:19:24 -0800483 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800484 instr_out(ctx, 2, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800485 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800486 instr_out(ctx, 3, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800487 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800488 instr_out(ctx, 4, "setup dst offset 0x%08x\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800489 data[4]);
Eric Anholtc1d29462011-12-20 15:29:03 -0800490 instr_out(ctx, 5, "setup background color\n");
491 instr_out(ctx, 6, "setup foreground color\n");
492 instr_out(ctx, 7, "color pattern offset\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800493 return len;
494 case 0x03:
Eric Anholt62b41032011-12-20 15:17:24 -0800495 decode_2d_br00(ctx, "XY_SETUP_CLIP_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800496
497 len = (data[0] & 0x000000ff) + 2;
498 if (len != 3)
499 fprintf(out, "Bad count in XY_SETUP_CLIP_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800500
Eric Anholtc1d29462011-12-20 15:29:03 -0800501 instr_out(ctx, 1, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800502 data[1] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800503 instr_out(ctx, 2, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800504 data[2] & 0xffff, data[3] >> 16);
505 return len;
506 case 0x11:
Eric Anholt62b41032011-12-20 15:17:24 -0800507 decode_2d_br00(ctx, "XY_SETUP_MONO_PATTERN_SL_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800508
509 len = (data[0] & 0x000000ff) + 2;
510 if (len != 9)
511 fprintf(out,
512 "Bad count in XY_SETUP_MONO_PATTERN_SL_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800513
Eric Anholtb0371612011-12-20 15:19:24 -0800514 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800515 instr_out(ctx, 2, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800516 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800517 instr_out(ctx, 3, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800518 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800519 instr_out(ctx, 4, "setup dst offset 0x%08x\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800520 data[4]);
Eric Anholtc1d29462011-12-20 15:29:03 -0800521 instr_out(ctx, 5, "setup background color\n");
522 instr_out(ctx, 6, "setup foreground color\n");
523 instr_out(ctx, 7, "mono pattern dw0\n");
524 instr_out(ctx, 8, "mono pattern dw1\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800525 return len;
526 case 0x50:
Eric Anholt62b41032011-12-20 15:17:24 -0800527 decode_2d_br00(ctx, "XY_COLOR_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800528
529 len = (data[0] & 0x000000ff) + 2;
530 if (len != 6)
531 fprintf(out, "Bad count in XY_COLOR_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800532
Eric Anholtb0371612011-12-20 15:19:24 -0800533 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800534 instr_out(ctx, 2, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800535 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800536 instr_out(ctx, 3, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800537 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800538 instr_out(ctx, 4, "offset 0x%08x\n", data[4]);
539 instr_out(ctx, 5, "color\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800540 return len;
541 case 0x53:
Eric Anholt62b41032011-12-20 15:17:24 -0800542 decode_2d_br00(ctx, "XY_SRC_COPY_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800543
544 len = (data[0] & 0x000000ff) + 2;
545 if (len != 8)
546 fprintf(out, "Bad count in XY_SRC_COPY_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800547
Eric Anholtb0371612011-12-20 15:19:24 -0800548 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800549 instr_out(ctx, 2, "dst (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800550 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800551 instr_out(ctx, 3, "dst (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800552 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800553 instr_out(ctx, 4, "dst offset 0x%08x\n", data[4]);
554 instr_out(ctx, 5, "src (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800555 data[5] & 0xffff, data[5] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800556 instr_out(ctx, 6, "src pitch %d\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800557 (short)(data[6] & 0xffff));
Eric Anholtc1d29462011-12-20 15:29:03 -0800558 instr_out(ctx, 7, "src offset 0x%08x\n", data[7]);
Eric Anholt193fa132011-12-20 11:36:07 -0800559 return len;
560 }
561
562 for (opcode = 0; opcode < sizeof(opcodes_2d) / sizeof(opcodes_2d[0]);
563 opcode++) {
564 if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) {
565 unsigned int i;
566
567 len = 1;
Eric Anholtc1d29462011-12-20 15:29:03 -0800568 instr_out(ctx, 0, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800569 opcodes_2d[opcode].name);
570 if (opcodes_2d[opcode].max_len > 1) {
571 len = (data[0] & 0x000000ff) + 2;
572 if (len < opcodes_2d[opcode].min_len ||
573 len > opcodes_2d[opcode].max_len) {
574 fprintf(out, "Bad count in %s\n",
575 opcodes_2d[opcode].name);
576 }
577 }
578
579 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800580 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -0800581 }
582
583 return len;
584 }
585 }
586
Eric Anholtc1d29462011-12-20 15:29:03 -0800587 instr_out(ctx, 0, "2D UNKNOWN\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800588 return 1;
589}
590
591static int
Eric Anholtde49fd42011-12-20 15:15:21 -0800592decode_3d_1c(struct drm_intel_decode *ctx)
Eric Anholt193fa132011-12-20 11:36:07 -0800593{
Eric Anholtde49fd42011-12-20 15:15:21 -0800594 uint32_t *data = ctx->data;
Eric Anholt193fa132011-12-20 11:36:07 -0800595 uint32_t opcode;
596
597 opcode = (data[0] & 0x00f80000) >> 19;
598
599 switch (opcode) {
600 case 0x11:
Eric Anholtc1d29462011-12-20 15:29:03 -0800601 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800602 "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE\n");
603 return 1;
604 case 0x10:
Eric Anholtc1d29462011-12-20 15:29:03 -0800605 instr_out(ctx, 0, "3DSTATE_SCISSOR_ENABLE %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800606 data[0] & 1 ? "enabled" : "disabled");
607 return 1;
608 case 0x01:
Eric Anholtc1d29462011-12-20 15:29:03 -0800609 instr_out(ctx, 0, "3DSTATE_MAP_COORD_SET_I830\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800610 return 1;
611 case 0x0a:
Eric Anholtc1d29462011-12-20 15:29:03 -0800612 instr_out(ctx, 0, "3DSTATE_MAP_CUBE_I830\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800613 return 1;
614 case 0x05:
Eric Anholtc1d29462011-12-20 15:29:03 -0800615 instr_out(ctx, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800616 return 1;
617 }
618
Eric Anholtc1d29462011-12-20 15:29:03 -0800619 instr_out(ctx, 0, "3D UNKNOWN: 3d_1c opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800620 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -0800621 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800622}
623
624/** Sets the string dstname to describe the destination of the PS instruction */
625static void
Eric Anholtbbdda922011-12-20 11:44:36 -0800626i915_get_instruction_dst(uint32_t *data, int i, char *dstname, int do_mask)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800627{
Eric Anholt193fa132011-12-20 11:36:07 -0800628 uint32_t a0 = data[i];
629 int dst_nr = (a0 >> 14) & 0xf;
630 char dstmask[8];
Eric Anholt1db55a82011-12-20 12:00:28 -0800631 const char *sat;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800632
Eric Anholt193fa132011-12-20 11:36:07 -0800633 if (do_mask) {
634 if (((a0 >> 10) & 0xf) == 0xf) {
635 dstmask[0] = 0;
636 } else {
637 int dstmask_index = 0;
638
639 dstmask[dstmask_index++] = '.';
640 if (a0 & (1 << 10))
641 dstmask[dstmask_index++] = 'x';
642 if (a0 & (1 << 11))
643 dstmask[dstmask_index++] = 'y';
644 if (a0 & (1 << 12))
645 dstmask[dstmask_index++] = 'z';
646 if (a0 & (1 << 13))
647 dstmask[dstmask_index++] = 'w';
648 dstmask[dstmask_index++] = 0;
649 }
650
651 if (a0 & (1 << 22))
652 sat = ".sat";
653 else
654 sat = "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800655 } else {
Eric Anholt193fa132011-12-20 11:36:07 -0800656 dstmask[0] = 0;
657 sat = "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800658 }
659
Eric Anholt193fa132011-12-20 11:36:07 -0800660 switch ((a0 >> 19) & 0x7) {
661 case 0:
662 if (dst_nr > 15)
663 fprintf(out, "bad destination reg R%d\n", dst_nr);
664 sprintf(dstname, "R%d%s%s", dst_nr, dstmask, sat);
665 break;
666 case 4:
667 if (dst_nr > 0)
668 fprintf(out, "bad destination reg oC%d\n", dst_nr);
669 sprintf(dstname, "oC%s%s", dstmask, sat);
670 break;
671 case 5:
672 if (dst_nr > 0)
673 fprintf(out, "bad destination reg oD%d\n", dst_nr);
674 sprintf(dstname, "oD%s%s", dstmask, sat);
675 break;
676 case 6:
677 if (dst_nr > 3)
678 fprintf(out, "bad destination reg U%d\n", dst_nr);
679 sprintf(dstname, "U%d%s%s", dst_nr, dstmask, sat);
680 break;
681 default:
682 sprintf(dstname, "RESERVED");
683 break;
684 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800685}
686
Eric Anholt1db55a82011-12-20 12:00:28 -0800687static const char *
688i915_get_channel_swizzle(uint32_t select)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800689{
Eric Anholt193fa132011-12-20 11:36:07 -0800690 switch (select & 0x7) {
691 case 0:
692 return (select & 8) ? "-x" : "x";
693 case 1:
694 return (select & 8) ? "-y" : "y";
695 case 2:
696 return (select & 8) ? "-z" : "z";
697 case 3:
698 return (select & 8) ? "-w" : "w";
699 case 4:
700 return (select & 8) ? "-0" : "0";
701 case 5:
702 return (select & 8) ? "-1" : "1";
703 default:
704 return (select & 8) ? "-bad" : "bad";
705 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800706}
707
708static void
709i915_get_instruction_src_name(uint32_t src_type, uint32_t src_nr, char *name)
710{
Eric Anholt193fa132011-12-20 11:36:07 -0800711 switch (src_type) {
712 case 0:
713 sprintf(name, "R%d", src_nr);
714 if (src_nr > 15)
715 fprintf(out, "bad src reg %s\n", name);
716 break;
717 case 1:
718 if (src_nr < 8)
719 sprintf(name, "T%d", src_nr);
720 else if (src_nr == 8)
721 sprintf(name, "DIFFUSE");
722 else if (src_nr == 9)
723 sprintf(name, "SPECULAR");
724 else if (src_nr == 10)
725 sprintf(name, "FOG");
726 else {
727 fprintf(out, "bad src reg T%d\n", src_nr);
728 sprintf(name, "RESERVED");
729 }
730 break;
731 case 2:
732 sprintf(name, "C%d", src_nr);
733 if (src_nr > 31)
734 fprintf(out, "bad src reg %s\n", name);
735 break;
736 case 4:
737 sprintf(name, "oC");
738 if (src_nr > 0)
739 fprintf(out, "bad src reg oC%d\n", src_nr);
740 break;
741 case 5:
742 sprintf(name, "oD");
743 if (src_nr > 0)
744 fprintf(out, "bad src reg oD%d\n", src_nr);
745 break;
746 case 6:
747 sprintf(name, "U%d", src_nr);
748 if (src_nr > 3)
749 fprintf(out, "bad src reg %s\n", name);
750 break;
751 default:
752 fprintf(out, "bad src reg type %d\n", src_type);
753 sprintf(name, "RESERVED");
754 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800755 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800756}
757
Eric Anholtbbdda922011-12-20 11:44:36 -0800758static void i915_get_instruction_src0(uint32_t *data, int i, char *srcname)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800759{
Eric Anholt193fa132011-12-20 11:36:07 -0800760 uint32_t a0 = data[i];
761 uint32_t a1 = data[i + 1];
762 int src_nr = (a0 >> 2) & 0x1f;
Eric Anholt1db55a82011-12-20 12:00:28 -0800763 const char *swizzle_x = i915_get_channel_swizzle((a1 >> 28) & 0xf);
764 const char *swizzle_y = i915_get_channel_swizzle((a1 >> 24) & 0xf);
765 const char *swizzle_z = i915_get_channel_swizzle((a1 >> 20) & 0xf);
766 const char *swizzle_w = i915_get_channel_swizzle((a1 >> 16) & 0xf);
Eric Anholt193fa132011-12-20 11:36:07 -0800767 char swizzle[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800768
Eric Anholt193fa132011-12-20 11:36:07 -0800769 i915_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname);
770 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
771 swizzle_w);
772 if (strcmp(swizzle, ".xyzw") != 0)
773 strcat(srcname, swizzle);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800774}
775
Eric Anholtbbdda922011-12-20 11:44:36 -0800776static void i915_get_instruction_src1(uint32_t *data, int i, char *srcname)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800777{
Eric Anholt193fa132011-12-20 11:36:07 -0800778 uint32_t a1 = data[i + 1];
779 uint32_t a2 = data[i + 2];
780 int src_nr = (a1 >> 8) & 0x1f;
Eric Anholt1db55a82011-12-20 12:00:28 -0800781 const char *swizzle_x = i915_get_channel_swizzle((a1 >> 4) & 0xf);
782 const char *swizzle_y = i915_get_channel_swizzle((a1 >> 0) & 0xf);
783 const char *swizzle_z = i915_get_channel_swizzle((a2 >> 28) & 0xf);
784 const char *swizzle_w = i915_get_channel_swizzle((a2 >> 24) & 0xf);
Eric Anholt193fa132011-12-20 11:36:07 -0800785 char swizzle[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800786
Eric Anholt193fa132011-12-20 11:36:07 -0800787 i915_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname);
788 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
789 swizzle_w);
790 if (strcmp(swizzle, ".xyzw") != 0)
791 strcat(srcname, swizzle);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800792}
793
Eric Anholtbbdda922011-12-20 11:44:36 -0800794static void i915_get_instruction_src2(uint32_t *data, int i, char *srcname)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800795{
Eric Anholt193fa132011-12-20 11:36:07 -0800796 uint32_t a2 = data[i + 2];
797 int src_nr = (a2 >> 16) & 0x1f;
Eric Anholt1db55a82011-12-20 12:00:28 -0800798 const char *swizzle_x = i915_get_channel_swizzle((a2 >> 12) & 0xf);
799 const char *swizzle_y = i915_get_channel_swizzle((a2 >> 8) & 0xf);
800 const char *swizzle_z = i915_get_channel_swizzle((a2 >> 4) & 0xf);
801 const char *swizzle_w = i915_get_channel_swizzle((a2 >> 0) & 0xf);
Eric Anholt193fa132011-12-20 11:36:07 -0800802 char swizzle[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800803
Eric Anholt193fa132011-12-20 11:36:07 -0800804 i915_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname);
805 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
806 swizzle_w);
807 if (strcmp(swizzle, ".xyzw") != 0)
808 strcat(srcname, swizzle);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800809}
810
811static void
812i915_get_instruction_addr(uint32_t src_type, uint32_t src_nr, char *name)
813{
Eric Anholt193fa132011-12-20 11:36:07 -0800814 switch (src_type) {
815 case 0:
816 sprintf(name, "R%d", src_nr);
817 if (src_nr > 15)
818 fprintf(out, "bad src reg %s\n", name);
819 break;
820 case 1:
821 if (src_nr < 8)
822 sprintf(name, "T%d", src_nr);
823 else if (src_nr == 8)
824 sprintf(name, "DIFFUSE");
825 else if (src_nr == 9)
826 sprintf(name, "SPECULAR");
827 else if (src_nr == 10)
828 sprintf(name, "FOG");
829 else {
830 fprintf(out, "bad src reg T%d\n", src_nr);
831 sprintf(name, "RESERVED");
832 }
833 break;
834 case 4:
835 sprintf(name, "oC");
836 if (src_nr > 0)
837 fprintf(out, "bad src reg oC%d\n", src_nr);
838 break;
839 case 5:
840 sprintf(name, "oD");
841 if (src_nr > 0)
842 fprintf(out, "bad src reg oD%d\n", src_nr);
843 break;
844 default:
845 fprintf(out, "bad src reg type %d\n", src_type);
846 sprintf(name, "RESERVED");
847 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800848 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800849}
850
851static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800852i915_decode_alu1(struct drm_intel_decode *ctx,
Eric Anholt1db55a82011-12-20 12:00:28 -0800853 int i, char *instr_prefix, const char *op_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800854{
Eric Anholt193fa132011-12-20 11:36:07 -0800855 char dst[100], src0[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800856
Eric Anholtc1d29462011-12-20 15:29:03 -0800857 i915_get_instruction_dst(ctx->data, i, dst, 1);
858 i915_get_instruction_src0(ctx->data, i, src0);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800859
Eric Anholtc1d29462011-12-20 15:29:03 -0800860 instr_out(ctx, i++, "%s: %s %s, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800861 op_name, dst, src0);
Eric Anholtc1d29462011-12-20 15:29:03 -0800862 instr_out(ctx, i++, "%s\n", instr_prefix);
863 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800864}
865
866static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800867i915_decode_alu2(struct drm_intel_decode *ctx,
Eric Anholt1db55a82011-12-20 12:00:28 -0800868 int i, char *instr_prefix, const char *op_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800869{
Eric Anholt193fa132011-12-20 11:36:07 -0800870 char dst[100], src0[100], src1[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800871
Eric Anholtc1d29462011-12-20 15:29:03 -0800872 i915_get_instruction_dst(ctx->data, i, dst, 1);
873 i915_get_instruction_src0(ctx->data, i, src0);
874 i915_get_instruction_src1(ctx->data, i, src1);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800875
Eric Anholtc1d29462011-12-20 15:29:03 -0800876 instr_out(ctx, i++, "%s: %s %s, %s, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800877 op_name, dst, src0, src1);
Eric Anholtc1d29462011-12-20 15:29:03 -0800878 instr_out(ctx, i++, "%s\n", instr_prefix);
879 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800880}
881
882static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800883i915_decode_alu3(struct drm_intel_decode *ctx,
Eric Anholt1db55a82011-12-20 12:00:28 -0800884 int i, char *instr_prefix, const char *op_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800885{
Eric Anholt193fa132011-12-20 11:36:07 -0800886 char dst[100], src0[100], src1[100], src2[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800887
Eric Anholtc1d29462011-12-20 15:29:03 -0800888 i915_get_instruction_dst(ctx->data, i, dst, 1);
889 i915_get_instruction_src0(ctx->data, i, src0);
890 i915_get_instruction_src1(ctx->data, i, src1);
891 i915_get_instruction_src2(ctx->data, i, src2);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800892
Eric Anholtc1d29462011-12-20 15:29:03 -0800893 instr_out(ctx, i++, "%s: %s %s, %s, %s, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800894 op_name, dst, src0, src1, src2);
Eric Anholtc1d29462011-12-20 15:29:03 -0800895 instr_out(ctx, i++, "%s\n", instr_prefix);
896 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800897}
898
899static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800900i915_decode_tex(struct drm_intel_decode *ctx, int i,
Eric Anholt1db55a82011-12-20 12:00:28 -0800901 const char *instr_prefix, const char *tex_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800902{
Eric Anholtc1d29462011-12-20 15:29:03 -0800903 uint32_t t0 = ctx->data[i];
904 uint32_t t1 = ctx->data[i + 1];
Eric Anholt193fa132011-12-20 11:36:07 -0800905 char dst_name[100];
906 char addr_name[100];
907 int sampler_nr;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800908
Eric Anholtc1d29462011-12-20 15:29:03 -0800909 i915_get_instruction_dst(ctx->data, i, dst_name, 0);
Eric Anholt193fa132011-12-20 11:36:07 -0800910 i915_get_instruction_addr((t1 >> 24) & 0x7,
911 (t1 >> 17) & 0xf, addr_name);
912 sampler_nr = t0 & 0xf;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800913
Eric Anholtc1d29462011-12-20 15:29:03 -0800914 instr_out(ctx, i++, "%s: %s %s, S%d, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800915 tex_name, dst_name, sampler_nr, addr_name);
Eric Anholtc1d29462011-12-20 15:29:03 -0800916 instr_out(ctx, i++, "%s\n", instr_prefix);
917 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800918}
919
920static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800921i915_decode_dcl(struct drm_intel_decode *ctx, int i, char *instr_prefix)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800922{
Eric Anholtc1d29462011-12-20 15:29:03 -0800923 uint32_t d0 = ctx->data[i];
Eric Anholt1db55a82011-12-20 12:00:28 -0800924 const char *sampletype;
Eric Anholt193fa132011-12-20 11:36:07 -0800925 int dcl_nr = (d0 >> 14) & 0xf;
Eric Anholt1db55a82011-12-20 12:00:28 -0800926 const char *dcl_x = d0 & (1 << 10) ? "x" : "";
927 const char *dcl_y = d0 & (1 << 11) ? "y" : "";
928 const char *dcl_z = d0 & (1 << 12) ? "z" : "";
929 const char *dcl_w = d0 & (1 << 13) ? "w" : "";
Eric Anholt193fa132011-12-20 11:36:07 -0800930 char dcl_mask[10];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800931
Eric Anholt193fa132011-12-20 11:36:07 -0800932 switch ((d0 >> 19) & 0x3) {
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800933 case 1:
Eric Anholt193fa132011-12-20 11:36:07 -0800934 sprintf(dcl_mask, ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
935 if (strcmp(dcl_mask, ".") == 0)
936 fprintf(out, "bad (empty) dcl mask\n");
937
938 if (dcl_nr > 10)
939 fprintf(out, "bad T%d dcl register number\n", dcl_nr);
940 if (dcl_nr < 8) {
941 if (strcmp(dcl_mask, ".x") != 0 &&
942 strcmp(dcl_mask, ".xy") != 0 &&
943 strcmp(dcl_mask, ".xz") != 0 &&
944 strcmp(dcl_mask, ".w") != 0 &&
945 strcmp(dcl_mask, ".xyzw") != 0) {
946 fprintf(out, "bad T%d.%s dcl mask\n", dcl_nr,
947 dcl_mask);
948 }
Eric Anholtc1d29462011-12-20 15:29:03 -0800949 instr_out(ctx, i++, "%s: DCL T%d%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800950 instr_prefix, dcl_nr, dcl_mask);
951 } else {
952 if (strcmp(dcl_mask, ".xz") == 0)
953 fprintf(out, "errataed bad dcl mask %s\n",
954 dcl_mask);
955 else if (strcmp(dcl_mask, ".xw") == 0)
956 fprintf(out, "errataed bad dcl mask %s\n",
957 dcl_mask);
958 else if (strcmp(dcl_mask, ".xzw") == 0)
959 fprintf(out, "errataed bad dcl mask %s\n",
960 dcl_mask);
961
962 if (dcl_nr == 8) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800963 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -0800964 "%s: DCL DIFFUSE%s\n", instr_prefix,
965 dcl_mask);
966 } else if (dcl_nr == 9) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800967 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -0800968 "%s: DCL SPECULAR%s\n", instr_prefix,
969 dcl_mask);
970 } else if (dcl_nr == 10) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800971 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -0800972 "%s: DCL FOG%s\n", instr_prefix,
973 dcl_mask);
974 }
975 }
Eric Anholtc1d29462011-12-20 15:29:03 -0800976 instr_out(ctx, i++, "%s\n", instr_prefix);
977 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -0800978 break;
979 case 3:
980 switch ((d0 >> 22) & 0x3) {
981 case 0:
982 sampletype = "2D";
983 break;
984 case 1:
985 sampletype = "CUBE";
986 break;
987 case 2:
988 sampletype = "3D";
989 break;
990 default:
991 sampletype = "RESERVED";
992 break;
993 }
994 if (dcl_nr > 15)
995 fprintf(out, "bad S%d dcl register number\n", dcl_nr);
Eric Anholtc1d29462011-12-20 15:29:03 -0800996 instr_out(ctx, i++, "%s: DCL S%d %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800997 instr_prefix, dcl_nr, sampletype);
Eric Anholtc1d29462011-12-20 15:29:03 -0800998 instr_out(ctx, i++, "%s\n", instr_prefix);
999 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -08001000 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001001 default:
Eric Anholtc1d29462011-12-20 15:29:03 -08001002 instr_out(ctx, i++, "%s: DCL RESERVED%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001003 instr_prefix, dcl_nr);
Eric Anholtc1d29462011-12-20 15:29:03 -08001004 instr_out(ctx, i++, "%s\n", instr_prefix);
1005 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001006 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001007}
1008
1009static void
Eric Anholtc1d29462011-12-20 15:29:03 -08001010i915_decode_instruction(struct drm_intel_decode *ctx,
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001011 int i, char *instr_prefix)
1012{
Eric Anholtc1d29462011-12-20 15:29:03 -08001013 switch ((ctx->data[i] >> 24) & 0x1f) {
Eric Anholt193fa132011-12-20 11:36:07 -08001014 case 0x0:
Eric Anholtc1d29462011-12-20 15:29:03 -08001015 instr_out(ctx, i++, "%s: NOP\n", instr_prefix);
1016 instr_out(ctx, i++, "%s\n", instr_prefix);
1017 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -08001018 break;
1019 case 0x01:
Eric Anholtc1d29462011-12-20 15:29:03 -08001020 i915_decode_alu2(ctx, i, instr_prefix, "ADD");
Eric Anholt193fa132011-12-20 11:36:07 -08001021 break;
1022 case 0x02:
Eric Anholtc1d29462011-12-20 15:29:03 -08001023 i915_decode_alu1(ctx, i, instr_prefix, "MOV");
Eric Anholt193fa132011-12-20 11:36:07 -08001024 break;
1025 case 0x03:
Eric Anholtc1d29462011-12-20 15:29:03 -08001026 i915_decode_alu2(ctx, i, instr_prefix, "MUL");
Eric Anholt193fa132011-12-20 11:36:07 -08001027 break;
1028 case 0x04:
Eric Anholtc1d29462011-12-20 15:29:03 -08001029 i915_decode_alu3(ctx, i, instr_prefix, "MAD");
Eric Anholt193fa132011-12-20 11:36:07 -08001030 break;
1031 case 0x05:
Eric Anholtc1d29462011-12-20 15:29:03 -08001032 i915_decode_alu3(ctx, i, instr_prefix, "DP2ADD");
Eric Anholt193fa132011-12-20 11:36:07 -08001033 break;
1034 case 0x06:
Eric Anholtc1d29462011-12-20 15:29:03 -08001035 i915_decode_alu2(ctx, i, instr_prefix, "DP3");
Eric Anholt193fa132011-12-20 11:36:07 -08001036 break;
1037 case 0x07:
Eric Anholtc1d29462011-12-20 15:29:03 -08001038 i915_decode_alu2(ctx, i, instr_prefix, "DP4");
Eric Anholt193fa132011-12-20 11:36:07 -08001039 break;
1040 case 0x08:
Eric Anholtc1d29462011-12-20 15:29:03 -08001041 i915_decode_alu1(ctx, i, instr_prefix, "FRC");
Eric Anholt193fa132011-12-20 11:36:07 -08001042 break;
1043 case 0x09:
Eric Anholtc1d29462011-12-20 15:29:03 -08001044 i915_decode_alu1(ctx, i, instr_prefix, "RCP");
Eric Anholt193fa132011-12-20 11:36:07 -08001045 break;
1046 case 0x0a:
Eric Anholtc1d29462011-12-20 15:29:03 -08001047 i915_decode_alu1(ctx, i, instr_prefix, "RSQ");
Eric Anholt193fa132011-12-20 11:36:07 -08001048 break;
1049 case 0x0b:
Eric Anholtc1d29462011-12-20 15:29:03 -08001050 i915_decode_alu1(ctx, i, instr_prefix, "EXP");
Eric Anholt193fa132011-12-20 11:36:07 -08001051 break;
1052 case 0x0c:
Eric Anholtc1d29462011-12-20 15:29:03 -08001053 i915_decode_alu1(ctx, i, instr_prefix, "LOG");
Eric Anholt193fa132011-12-20 11:36:07 -08001054 break;
1055 case 0x0d:
Eric Anholtc1d29462011-12-20 15:29:03 -08001056 i915_decode_alu2(ctx, i, instr_prefix, "CMP");
Eric Anholt193fa132011-12-20 11:36:07 -08001057 break;
1058 case 0x0e:
Eric Anholtc1d29462011-12-20 15:29:03 -08001059 i915_decode_alu2(ctx, i, instr_prefix, "MIN");
Eric Anholt193fa132011-12-20 11:36:07 -08001060 break;
1061 case 0x0f:
Eric Anholtc1d29462011-12-20 15:29:03 -08001062 i915_decode_alu2(ctx, i, instr_prefix, "MAX");
Eric Anholt193fa132011-12-20 11:36:07 -08001063 break;
1064 case 0x10:
Eric Anholtc1d29462011-12-20 15:29:03 -08001065 i915_decode_alu1(ctx, i, instr_prefix, "FLR");
Eric Anholt193fa132011-12-20 11:36:07 -08001066 break;
1067 case 0x11:
Eric Anholtc1d29462011-12-20 15:29:03 -08001068 i915_decode_alu1(ctx, i, instr_prefix, "MOD");
Eric Anholt193fa132011-12-20 11:36:07 -08001069 break;
1070 case 0x12:
Eric Anholtc1d29462011-12-20 15:29:03 -08001071 i915_decode_alu1(ctx, i, instr_prefix, "TRC");
Eric Anholt193fa132011-12-20 11:36:07 -08001072 break;
1073 case 0x13:
Eric Anholtc1d29462011-12-20 15:29:03 -08001074 i915_decode_alu2(ctx, i, instr_prefix, "SGE");
Eric Anholt193fa132011-12-20 11:36:07 -08001075 break;
1076 case 0x14:
Eric Anholtc1d29462011-12-20 15:29:03 -08001077 i915_decode_alu2(ctx, i, instr_prefix, "SLT");
Eric Anholt193fa132011-12-20 11:36:07 -08001078 break;
1079 case 0x15:
Eric Anholtc1d29462011-12-20 15:29:03 -08001080 i915_decode_tex(ctx, i, instr_prefix, "TEXLD");
Eric Anholt193fa132011-12-20 11:36:07 -08001081 break;
1082 case 0x16:
Eric Anholtc1d29462011-12-20 15:29:03 -08001083 i915_decode_tex(ctx, i, instr_prefix, "TEXLDP");
Eric Anholt193fa132011-12-20 11:36:07 -08001084 break;
1085 case 0x17:
Eric Anholtc1d29462011-12-20 15:29:03 -08001086 i915_decode_tex(ctx, i, instr_prefix, "TEXLDB");
Eric Anholt193fa132011-12-20 11:36:07 -08001087 break;
1088 case 0x19:
Eric Anholtc1d29462011-12-20 15:29:03 -08001089 i915_decode_dcl(ctx, i, instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -08001090 break;
1091 default:
Eric Anholtc1d29462011-12-20 15:29:03 -08001092 instr_out(ctx, i++, "%s: unknown\n", instr_prefix);
1093 instr_out(ctx, i++, "%s\n", instr_prefix);
1094 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -08001095 break;
1096 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001097}
1098
Eric Anholt1db55a82011-12-20 12:00:28 -08001099static const char *
1100decode_compare_func(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001101{
Eric Anholt193fa132011-12-20 11:36:07 -08001102 switch (op & 0x7) {
1103 case 0:
1104 return "always";
1105 case 1:
1106 return "never";
1107 case 2:
1108 return "less";
1109 case 3:
1110 return "equal";
1111 case 4:
1112 return "lequal";
1113 case 5:
1114 return "greater";
1115 case 6:
1116 return "notequal";
1117 case 7:
1118 return "gequal";
1119 }
1120 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001121}
1122
Eric Anholt1db55a82011-12-20 12:00:28 -08001123static const char *
1124decode_stencil_op(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001125{
Eric Anholt193fa132011-12-20 11:36:07 -08001126 switch (op & 0x7) {
1127 case 0:
1128 return "keep";
1129 case 1:
1130 return "zero";
1131 case 2:
1132 return "replace";
1133 case 3:
1134 return "incr_sat";
1135 case 4:
1136 return "decr_sat";
1137 case 5:
1138 return "greater";
1139 case 6:
1140 return "incr";
1141 case 7:
1142 return "decr";
1143 }
1144 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001145}
1146
Eric Anholt4149faf2011-12-20 14:32:27 -08001147#if 0
Eric Anholt1db55a82011-12-20 12:00:28 -08001148static const char *
1149decode_logic_op(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001150{
Eric Anholt193fa132011-12-20 11:36:07 -08001151 switch (op & 0xf) {
1152 case 0:
1153 return "clear";
1154 case 1:
1155 return "nor";
1156 case 2:
1157 return "and_inv";
1158 case 3:
1159 return "copy_inv";
1160 case 4:
1161 return "and_rvrse";
1162 case 5:
1163 return "inv";
1164 case 6:
1165 return "xor";
1166 case 7:
1167 return "nand";
1168 case 8:
1169 return "and";
1170 case 9:
1171 return "equiv";
1172 case 10:
1173 return "noop";
1174 case 11:
1175 return "or_inv";
1176 case 12:
1177 return "copy";
1178 case 13:
1179 return "or_rvrse";
1180 case 14:
1181 return "or";
1182 case 15:
1183 return "set";
1184 }
1185 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001186}
Eric Anholt4149faf2011-12-20 14:32:27 -08001187#endif
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001188
Eric Anholt1db55a82011-12-20 12:00:28 -08001189static const char *
1190decode_blend_fact(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001191{
Eric Anholt193fa132011-12-20 11:36:07 -08001192 switch (op & 0xf) {
1193 case 1:
1194 return "zero";
1195 case 2:
1196 return "one";
1197 case 3:
1198 return "src_colr";
1199 case 4:
1200 return "inv_src_colr";
1201 case 5:
1202 return "src_alpha";
1203 case 6:
1204 return "inv_src_alpha";
1205 case 7:
1206 return "dst_alpha";
1207 case 8:
1208 return "inv_dst_alpha";
1209 case 9:
1210 return "dst_colr";
1211 case 10:
1212 return "inv_dst_colr";
1213 case 11:
1214 return "src_alpha_sat";
1215 case 12:
1216 return "cnst_colr";
1217 case 13:
1218 return "inv_cnst_colr";
1219 case 14:
1220 return "cnst_alpha";
1221 case 15:
1222 return "inv_const_alpha";
1223 }
1224 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001225}
1226
Eric Anholt1db55a82011-12-20 12:00:28 -08001227static const char *
1228decode_tex_coord_mode(uint32_t mode)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001229{
Eric Anholt193fa132011-12-20 11:36:07 -08001230 switch (mode & 0x7) {
1231 case 0:
1232 return "wrap";
1233 case 1:
1234 return "mirror";
1235 case 2:
1236 return "clamp_edge";
1237 case 3:
1238 return "cube";
1239 case 4:
1240 return "clamp_border";
1241 case 5:
1242 return "mirror_once";
1243 }
1244 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001245}
1246
Eric Anholt1db55a82011-12-20 12:00:28 -08001247static const char *
1248decode_sample_filter(uint32_t mode)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001249{
Eric Anholt193fa132011-12-20 11:36:07 -08001250 switch (mode & 0x7) {
1251 case 0:
1252 return "nearest";
1253 case 1:
1254 return "linear";
1255 case 2:
1256 return "anisotropic";
1257 case 3:
1258 return "4x4_1";
1259 case 4:
1260 return "4x4_2";
1261 case 5:
1262 return "4x4_flat";
1263 case 6:
1264 return "6x5_mono";
1265 }
1266 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001267}
1268
1269static int
Eric Anholtde49fd42011-12-20 15:15:21 -08001270decode_3d_1d(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001271{
Eric Anholt193fa132011-12-20 11:36:07 -08001272 unsigned int len, i, c, idx, word, map, sampler, instr;
Eric Anholt1db55a82011-12-20 12:00:28 -08001273 const char *format, *zformat, *type;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001274 uint32_t opcode;
Eric Anholtde49fd42011-12-20 15:15:21 -08001275 uint32_t *data = ctx->data;
Eric Anholtde49fd42011-12-20 15:15:21 -08001276 uint32_t devid = ctx->devid;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001277
Eric Anholt193fa132011-12-20 11:36:07 -08001278 struct {
1279 uint32_t opcode;
1280 int i830_only;
Eric Anholt07768ba2011-12-20 13:46:23 -08001281 unsigned int min_len;
1282 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08001283 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -08001284 } opcodes_3d_1d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -08001285 { 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" },
1286 { 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
1287 { 0x99, 0, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
1288 { 0x9a, 0, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
1289 { 0x98, 0, 2, 2, "3DSTATE_DEFAULT_Z" },
1290 { 0x97, 0, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
1291 { 0x9d, 0, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
1292 { 0x9e, 0, 4, 4, "3DSTATE_MONO_FILTER" },
1293 { 0x89, 0, 4, 4, "3DSTATE_FOG_MODE" },
1294 { 0x8f, 0, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
1295 { 0x83, 0, 2, 2, "3DSTATE_SPAN_STIPPLE" },
1296 { 0x8c, 1, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM_I830" },
1297 { 0x8b, 1, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM_I830" },
1298 { 0x8d, 1, 3, 3, "3DSTATE_W_STATE_I830" },
1299 { 0x01, 1, 2, 2, "3DSTATE_COLOR_FACTOR_I830" },
1300 { 0x02, 1, 2, 2, "3DSTATE_MAP_COORD_SETBIND_I830"},
1301 }, *opcode_3d_1d;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001302
Eric Anholt193fa132011-12-20 11:36:07 -08001303 opcode = (data[0] & 0x00ff0000) >> 16;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001304
Eric Anholt193fa132011-12-20 11:36:07 -08001305 switch (opcode) {
1306 case 0x07:
Eric Anholtbbdda922011-12-20 11:44:36 -08001307 /* This instruction is unusual. A 0 length means just
1308 * 1 DWORD instead of 2. The 0 length is specified in
1309 * one place to be unsupported, but stated to be
1310 * required in another, and 0 length LOAD_INDIRECTs
1311 * appear to cause no harm at least.
Eric Anholt193fa132011-12-20 11:36:07 -08001312 */
Eric Anholtc1d29462011-12-20 15:29:03 -08001313 instr_out(ctx, 0, "3DSTATE_LOAD_INDIRECT\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001314 len = (data[0] & 0x000000ff) + 1;
1315 i = 1;
1316 if (data[0] & (0x01 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001317 instr_out(ctx, i++, "SIS.0\n");
1318 instr_out(ctx, i++, "SIS.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001319 }
1320 if (data[0] & (0x02 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001321 instr_out(ctx, i++, "DIS.0\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001322 }
1323 if (data[0] & (0x04 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001324 instr_out(ctx, i++, "SSB.0\n");
1325 instr_out(ctx, i++, "SSB.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001326 }
1327 if (data[0] & (0x08 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001328 instr_out(ctx, i++, "MSB.0\n");
1329 instr_out(ctx, i++, "MSB.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001330 }
1331 if (data[0] & (0x10 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001332 instr_out(ctx, i++, "PSP.0\n");
1333 instr_out(ctx, i++, "PSP.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001334 }
1335 if (data[0] & (0x20 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001336 instr_out(ctx, i++, "PSC.0\n");
1337 instr_out(ctx, i++, "PSC.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001338 }
1339 if (len != i) {
1340 fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001341 return len;
1342 }
1343 return len;
1344 case 0x04:
Eric Anholtc1d29462011-12-20 15:29:03 -08001345 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08001346 "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
1347 len = (data[0] & 0x0000000f) + 2;
1348 i = 1;
1349 for (word = 0; word <= 8; word++) {
1350 if (data[0] & (1 << (4 + word))) {
Eric Anholt193fa132011-12-20 11:36:07 -08001351 /* save vertex state for decode */
1352 if (!IS_GEN2(devid)) {
Eric Anholt7b483182011-12-20 14:27:17 -08001353 int tex_num;
1354
Eric Anholt193fa132011-12-20 11:36:07 -08001355 if (word == 2) {
1356 saved_s2_set = 1;
1357 saved_s2 = data[i];
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001358 }
Eric Anholt193fa132011-12-20 11:36:07 -08001359 if (word == 4) {
1360 saved_s4_set = 1;
1361 saved_s4 = data[i];
1362 }
1363
1364 switch (word) {
1365 case 0:
Eric Anholtc1d29462011-12-20 15:29:03 -08001366 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001367 "S0: vbo offset: 0x%08x%s\n",
1368 data[i] & (~1),
1369 data[i] & 1 ?
1370 ", auto cache invalidate disabled"
1371 : "");
1372 break;
1373 case 1:
Eric Anholtc1d29462011-12-20 15:29:03 -08001374 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001375 "S1: vertex width: %i, vertex pitch: %i\n",
1376 (data[i] >> 24) &
1377 0x3f,
1378 (data[i] >> 16) &
1379 0x3f);
1380 break;
1381 case 2:
Eric Anholtc1d29462011-12-20 15:29:03 -08001382 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001383 "S2: texcoord formats: ");
Eric Anholt7b483182011-12-20 14:27:17 -08001384 for (tex_num = 0;
Eric Anholt193fa132011-12-20 11:36:07 -08001385 tex_num < 8; tex_num++) {
1386 switch ((data[i] >>
1387 tex_num *
1388 4) & 0xf) {
1389 case 0:
1390 fprintf(out,
1391 "%i=2D ",
1392 tex_num);
1393 break;
1394 case 1:
1395 fprintf(out,
1396 "%i=3D ",
1397 tex_num);
1398 break;
1399 case 2:
1400 fprintf(out,
1401 "%i=4D ",
1402 tex_num);
1403 break;
1404 case 3:
1405 fprintf(out,
1406 "%i=1D ",
1407 tex_num);
1408 break;
1409 case 4:
1410 fprintf(out,
1411 "%i=2D_16 ",
1412 tex_num);
1413 break;
1414 case 5:
1415 fprintf(out,
1416 "%i=4D_16 ",
1417 tex_num);
1418 break;
1419 case 0xf:
1420 fprintf(out,
1421 "%i=NP ",
1422 tex_num);
1423 break;
1424 }
1425 }
1426 fprintf(out, "\n");
1427
1428 break;
1429 case 3:
Eric Anholtc1d29462011-12-20 15:29:03 -08001430 instr_out(ctx, i,
Eric Anholt0c46f022011-12-20 14:23:15 -08001431 "S3: not documented\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001432 break;
1433 case 4:
1434 {
Eric Anholt1db55a82011-12-20 12:00:28 -08001435 const char *cullmode = "";
1436 const char *vfmt_xyzw = "";
Eric Anholt193fa132011-12-20 11:36:07 -08001437 switch ((data[i] >> 13)
1438 & 0x3) {
1439 case 0:
1440 cullmode =
1441 "both";
1442 break;
1443 case 1:
1444 cullmode =
1445 "none";
1446 break;
1447 case 2:
1448 cullmode = "cw";
1449 break;
1450 case 3:
1451 cullmode =
1452 "ccw";
1453 break;
1454 }
1455 switch (data[i] &
1456 (7 << 6 | 1 <<
1457 2)) {
1458 case 1 << 6:
1459 vfmt_xyzw =
1460 "XYZ,";
1461 break;
1462 case 2 << 6:
1463 vfmt_xyzw =
1464 "XYZW,";
1465 break;
1466 case 3 << 6:
1467 vfmt_xyzw =
1468 "XY,";
1469 break;
1470 case 4 << 6:
1471 vfmt_xyzw =
1472 "XYW,";
1473 break;
1474 case 1 << 6 | 1 << 2:
1475 vfmt_xyzw =
1476 "XYZF,";
1477 break;
1478 case 2 << 6 | 1 << 2:
1479 vfmt_xyzw =
1480 "XYZWF,";
1481 break;
1482 case 3 << 6 | 1 << 2:
1483 vfmt_xyzw =
1484 "XYF,";
1485 break;
1486 case 4 << 6 | 1 << 2:
1487 vfmt_xyzw =
1488 "XYWF,";
1489 break;
1490 }
Eric Anholtc1d29462011-12-20 15:29:03 -08001491 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001492 "S4: point_width=%i, line_width=%.1f,"
1493 "%s%s%s%s%s cullmode=%s, vfmt=%s%s%s%s%s%s "
Eric Anholt0c46f022011-12-20 14:23:15 -08001494 "%s%s%s%s%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001495 (data[i] >>
1496 23) & 0x1ff,
1497 ((data[i] >>
1498 19) & 0xf) /
1499 2.0,
1500 data[i] & (0xf
1501 <<
1502 15)
1503 ?
1504 " flatshade="
1505 : "",
1506 data[i] & (1
1507 <<
1508 18)
1509 ? "Alpha," :
1510 "",
1511 data[i] & (1
1512 <<
1513 17)
1514 ? "Fog," : "",
1515 data[i] & (1
1516 <<
1517 16)
1518 ? "Specular,"
1519 : "",
1520 data[i] & (1
1521 <<
1522 15)
1523 ? "Color," :
1524 "", cullmode,
1525 data[i] & (1
1526 <<
1527 12)
1528 ?
1529 "PointWidth,"
1530 : "",
1531 data[i] & (1
1532 <<
1533 11)
1534 ? "SpecFog," :
1535 "",
1536 data[i] & (1
1537 <<
1538 10)
1539 ? "Color," :
1540 "",
1541 data[i] & (1
1542 <<
1543 9)
1544 ? "DepthOfs,"
1545 : "",
1546 vfmt_xyzw,
1547 data[i] & (1
1548 <<
1549 9)
1550 ? "FogParam,"
1551 : "",
1552 data[i] & (1
1553 <<
1554 5)
1555 ?
1556 "force default diffuse, "
1557 : "",
1558 data[i] & (1
1559 <<
1560 4)
1561 ?
1562 "force default specular, "
1563 : "",
1564 data[i] & (1
1565 <<
1566 3)
1567 ?
1568 "local depth ofs enable, "
1569 : "",
1570 data[i] & (1
1571 <<
1572 1)
1573 ?
1574 "point sprite enable, "
1575 : "",
1576 data[i] & (1
1577 <<
1578 0)
1579 ?
1580 "line AA enable, "
1581 : "");
1582 break;
1583 }
1584 case 5:
1585 {
Eric Anholtc1d29462011-12-20 15:29:03 -08001586 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001587 "S5:%s%s%s%s%s"
1588 "%s%s%s%s stencil_ref=0x%x, stencil_test=%s, "
1589 "stencil_fail=%s, stencil_pass_z_fail=%s, "
1590 "stencil_pass_z_pass=%s, %s%s%s%s\n",
1591 data[i] & (0xf
1592 <<
1593 28)
1594 ?
1595 " write_disable="
1596 : "",
1597 data[i] & (1
1598 <<
1599 31)
1600 ? "Alpha," :
1601 "",
1602 data[i] & (1
1603 <<
1604 30)
1605 ? "Red," : "",
1606 data[i] & (1
1607 <<
1608 29)
1609 ? "Green," :
1610 "",
1611 data[i] & (1
1612 <<
1613 28)
1614 ? "Blue," :
1615 "",
1616 data[i] & (1
1617 <<
1618 27)
1619 ?
1620 " force default point size,"
1621 : "",
1622 data[i] & (1
1623 <<
1624 26)
1625 ?
1626 " last pixel enable,"
1627 : "",
1628 data[i] & (1
1629 <<
1630 25)
1631 ?
1632 " global depth ofs enable,"
1633 : "",
1634 data[i] & (1
1635 <<
1636 24)
1637 ?
1638 " fog enable,"
1639 : "",
1640 (data[i] >>
1641 16) & 0xff,
1642 decode_compare_func
1643 (data[i] >>
1644 13),
1645 decode_stencil_op
1646 (data[i] >>
1647 10),
1648 decode_stencil_op
1649 (data[i] >>
1650 7),
1651 decode_stencil_op
1652 (data[i] >>
1653 4),
1654 data[i] & (1
1655 <<
1656 3)
1657 ?
1658 "stencil write enable, "
1659 : "",
1660 data[i] & (1
1661 <<
1662 2)
1663 ?
1664 "stencil test enable, "
1665 : "",
1666 data[i] & (1
1667 <<
1668 1)
1669 ?
1670 "color dither enable, "
1671 : "",
1672 data[i] & (1
1673 <<
1674 0)
1675 ?
1676 "logicop enable, "
1677 : "");
1678 }
1679 break;
1680 case 6:
Eric Anholtc1d29462011-12-20 15:29:03 -08001681 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001682 "S6: %salpha_test=%s, alpha_ref=0x%x, "
1683 "depth_test=%s, %ssrc_blnd_fct=%s, dst_blnd_fct=%s, "
1684 "%s%stristrip_provoking_vertex=%i\n",
1685 data[i] & (1 << 31) ?
1686 "alpha test enable, "
1687 : "",
1688 decode_compare_func
1689 (data[i] >> 28),
1690 data[i] & (0xff <<
1691 20),
1692 decode_compare_func
1693 (data[i] >> 16),
1694 data[i] & (1 << 15) ?
1695 "cbuf blend enable, "
1696 : "",
1697 decode_blend_fact(data
1698 [i]
1699 >>
1700 8),
1701 decode_blend_fact(data
1702 [i]
1703 >>
1704 4),
1705 data[i] & (1 << 3) ?
1706 "depth write enable, "
1707 : "",
1708 data[i] & (1 << 2) ?
1709 "cbuf write enable, "
1710 : "",
1711 data[i] & (0x3));
1712 break;
1713 case 7:
Eric Anholtc1d29462011-12-20 15:29:03 -08001714 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001715 "S7: depth offset constant: 0x%08x\n",
1716 data[i]);
1717 break;
1718 }
1719 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08001720 instr_out(ctx, i,
Chris Wilson8cf34752012-10-07 10:07:23 +01001721 "S%d: 0x%08x\n", word, data[i]);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001722 }
Eric Anholt193fa132011-12-20 11:36:07 -08001723 i++;
1724 }
1725 }
1726 if (len != i) {
1727 fprintf(out,
1728 "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001729 }
1730 return len;
1731 case 0x03:
Eric Anholtc1d29462011-12-20 15:29:03 -08001732 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08001733 "3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
1734 len = (data[0] & 0x0000000f) + 2;
1735 i = 1;
1736 for (word = 6; word <= 14; word++) {
1737 if (data[0] & (1 << word)) {
Eric Anholt193fa132011-12-20 11:36:07 -08001738 if (word == 6)
Eric Anholtc1d29462011-12-20 15:29:03 -08001739 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001740 "TBCF\n");
1741 else if (word >= 7 && word <= 10) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001742 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001743 "TB%dC\n", word - 7);
Eric Anholtc1d29462011-12-20 15:29:03 -08001744 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001745 "TB%dA\n", word - 7);
1746 } else if (word >= 11 && word <= 14) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001747 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001748 "TM%dS0: offset=0x%08x, %s\n",
1749 word - 11,
1750 data[i] & 0xfffffffe,
1751 data[i] & 1 ? "use fence" :
1752 "");
1753 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001754 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001755 "TM%dS1: height=%i, width=%i, %s\n",
1756 word - 11, data[i] >> 21,
1757 (data[i] >> 10) & 0x3ff,
1758 data[i] & 2 ? (data[i] & 1 ?
1759 "y-tiled" :
1760 "x-tiled") :
1761 "");
1762 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001763 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001764 "TM%dS2: pitch=%i, \n",
1765 word - 11,
1766 ((data[i] >> 21) + 1) * 4);
1767 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001768 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001769 "TM%dS3\n", word - 11);
Eric Anholtc1d29462011-12-20 15:29:03 -08001770 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001771 "TM%dS4: dflt color\n",
1772 word - 11);
1773 }
1774 }
1775 }
1776 if (len != i) {
1777 fprintf(out,
1778 "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001779 }
1780 return len;
1781 case 0x00:
Eric Anholtc1d29462011-12-20 15:29:03 -08001782 instr_out(ctx, 0, "3DSTATE_MAP_STATE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001783 len = (data[0] & 0x0000003f) + 2;
Eric Anholtc1d29462011-12-20 15:29:03 -08001784 instr_out(ctx, 1, "mask\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001785
1786 i = 2;
1787 for (map = 0; map <= 15; map++) {
1788 if (data[1] & (1 << map)) {
1789 int width, height, pitch, dword;
1790 const char *tiling;
1791
Eric Anholt193fa132011-12-20 11:36:07 -08001792 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08001793 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001794 "map %d MS2 %s%s%s\n", map,
1795 dword & (1 << 31) ?
1796 "untrusted surface, " : "",
1797 dword & (1 << 1) ?
1798 "vertical line stride enable, " : "",
1799 dword & (1 << 0) ?
1800 "vertical ofs enable, " : "");
1801
1802 dword = data[i];
1803 width = ((dword >> 10) & ((1 << 11) - 1)) + 1;
1804 height = ((dword >> 21) & ((1 << 11) - 1)) + 1;
1805
1806 tiling = "none";
1807 if (dword & (1 << 2))
1808 tiling = "fenced";
1809 else if (dword & (1 << 1))
1810 tiling = dword & (1 << 0) ? "Y" : "X";
1811 type = " BAD";
1812 format = "BAD";
1813 switch ((dword >> 7) & 0x7) {
1814 case 1:
1815 type = "8b";
1816 switch ((dword >> 3) & 0xf) {
1817 case 0:
1818 format = "I";
1819 break;
1820 case 1:
1821 format = "L";
1822 break;
1823 case 4:
1824 format = "A";
1825 break;
1826 case 5:
1827 format = " mono";
1828 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001829 }
Eric Anholt193fa132011-12-20 11:36:07 -08001830 break;
1831 case 2:
1832 type = "16b";
1833 switch ((dword >> 3) & 0xf) {
1834 case 0:
1835 format = " rgb565";
1836 break;
1837 case 1:
1838 format = " argb1555";
1839 break;
1840 case 2:
1841 format = " argb4444";
1842 break;
1843 case 5:
1844 format = " ay88";
1845 break;
1846 case 6:
1847 format = " bump655";
1848 break;
1849 case 7:
1850 format = "I";
1851 break;
1852 case 8:
1853 format = "L";
1854 break;
1855 case 9:
1856 format = "A";
1857 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001858 }
Eric Anholt193fa132011-12-20 11:36:07 -08001859 break;
1860 case 3:
1861 type = "32b";
1862 switch ((dword >> 3) & 0xf) {
1863 case 0:
1864 format = " argb8888";
1865 break;
1866 case 1:
1867 format = " abgr8888";
1868 break;
1869 case 2:
1870 format = " xrgb8888";
1871 break;
1872 case 3:
1873 format = " xbgr8888";
1874 break;
1875 case 4:
1876 format = " qwvu8888";
1877 break;
1878 case 5:
1879 format = " axvu8888";
1880 break;
1881 case 6:
1882 format = " lxvu8888";
1883 break;
1884 case 7:
1885 format = " xlvu8888";
1886 break;
1887 case 8:
1888 format = " argb2101010";
1889 break;
1890 case 9:
1891 format = " abgr2101010";
1892 break;
1893 case 10:
1894 format = " awvu2101010";
1895 break;
1896 case 11:
1897 format = " gr1616";
1898 break;
1899 case 12:
1900 format = " vu1616";
1901 break;
1902 case 13:
1903 format = " xI824";
1904 break;
1905 case 14:
1906 format = " xA824";
1907 break;
1908 case 15:
1909 format = " xL824";
1910 break;
1911 }
1912 break;
1913 case 5:
1914 type = "422";
1915 switch ((dword >> 3) & 0xf) {
1916 case 0:
1917 format = " yuv_swapy";
1918 break;
1919 case 1:
1920 format = " yuv";
1921 break;
1922 case 2:
1923 format = " yuv_swapuv";
1924 break;
1925 case 3:
1926 format = " yuv_swapuvy";
1927 break;
1928 }
1929 break;
1930 case 6:
1931 type = "compressed";
1932 switch ((dword >> 3) & 0x7) {
1933 case 0:
1934 format = " dxt1";
1935 break;
1936 case 1:
1937 format = " dxt2_3";
1938 break;
1939 case 2:
1940 format = " dxt4_5";
1941 break;
1942 case 3:
1943 format = " fxt1";
1944 break;
1945 case 4:
1946 format = " dxt1_rb";
1947 break;
1948 }
1949 break;
1950 case 7:
1951 type = "4b indexed";
1952 switch ((dword >> 3) & 0xf) {
1953 case 7:
1954 format = " argb8888";
1955 break;
1956 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001957 break;
1958 }
Eric Anholt193fa132011-12-20 11:36:07 -08001959 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08001960 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001961 "map %d MS3 [width=%d, height=%d, format=%s%s, tiling=%s%s]\n",
1962 map, width, height, type, format,
1963 tiling,
1964 dword & (1 << 9) ? " palette select" :
1965 "");
1966
1967 dword = data[i];
1968 pitch =
1969 4 * (((dword >> 21) & ((1 << 11) - 1)) + 1);
Eric Anholtc1d29462011-12-20 15:29:03 -08001970 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001971 "map %d MS4 [pitch=%d, max_lod=%i, vol_depth=%i, cube_face_ena=%x, %s]\n",
1972 map, pitch, (dword >> 9) & 0x3f,
1973 dword & 0xff, (dword >> 15) & 0x3f,
1974 dword & (1 << 8) ? "miplayout legacy"
1975 : "miplayout right");
1976 }
1977 }
1978 if (len != i) {
1979 fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001980 return len;
1981 }
1982 return len;
1983 case 0x06:
Eric Anholtc1d29462011-12-20 15:29:03 -08001984 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08001985 "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
1986 len = (data[0] & 0x000000ff) + 2;
1987
1988 i = 2;
1989 for (c = 0; c <= 31; c++) {
1990 if (data[1] & (1 << c)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001991 instr_out(ctx, i, "C%d.X = %f\n", c,
Eric Anholt193fa132011-12-20 11:36:07 -08001992 int_as_float(data[i]));
1993 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001994 instr_out(ctx, i, "C%d.Y = %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001995 c, int_as_float(data[i]));
1996 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001997 instr_out(ctx, i, "C%d.Z = %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001998 c, int_as_float(data[i]));
1999 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08002000 instr_out(ctx, i, "C%d.W = %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002001 c, int_as_float(data[i]));
2002 i++;
2003 }
2004 }
2005 if (len != i) {
2006 fprintf(out,
2007 "Bad count in 3DSTATE_PIXEL_SHADER_CONSTANTS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002008 }
2009 return len;
2010 case 0x05:
Eric Anholtc1d29462011-12-20 15:29:03 -08002011 instr_out(ctx, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002012 len = (data[0] & 0x000000ff) + 2;
2013 if ((len - 1) % 3 != 0 || len > 370) {
2014 fprintf(out,
2015 "Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002016 }
2017 i = 1;
2018 for (instr = 0; instr < (len - 1) / 3; instr++) {
2019 char instr_prefix[10];
2020
Eric Anholt193fa132011-12-20 11:36:07 -08002021 sprintf(instr_prefix, "PS%03d", instr);
Eric Anholtc1d29462011-12-20 15:29:03 -08002022 i915_decode_instruction(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002023 instr_prefix);
2024 i += 3;
2025 }
2026 return len;
2027 case 0x01:
2028 if (IS_GEN2(devid))
2029 break;
Eric Anholtc1d29462011-12-20 15:29:03 -08002030 instr_out(ctx, 0, "3DSTATE_SAMPLER_STATE\n");
2031 instr_out(ctx, 1, "mask\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002032 len = (data[0] & 0x0000003f) + 2;
2033 i = 2;
2034 for (sampler = 0; sampler <= 15; sampler++) {
2035 if (data[1] & (1 << sampler)) {
2036 uint32_t dword;
Eric Anholt1db55a82011-12-20 12:00:28 -08002037 const char *mip_filter = "";
Eric Anholt028715e2012-01-04 12:31:40 -08002038
Eric Anholt193fa132011-12-20 11:36:07 -08002039 dword = data[i];
2040 switch ((dword >> 20) & 0x3) {
2041 case 0:
2042 mip_filter = "none";
2043 break;
2044 case 1:
2045 mip_filter = "nearest";
2046 break;
2047 case 3:
2048 mip_filter = "linear";
2049 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002050 }
Eric Anholtc1d29462011-12-20 15:29:03 -08002051 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08002052 "sampler %d SS2:%s%s%s "
2053 "base_mip_level=%i, mip_filter=%s, mag_filter=%s, min_filter=%s "
2054 "lod_bias=%.2f,%s max_aniso=%i, shadow_func=%s\n",
2055 sampler,
2056 dword & (1 << 31) ? " reverse gamma,"
2057 : "",
2058 dword & (1 << 30) ? " packed2planar,"
2059 : "",
2060 dword & (1 << 29) ?
2061 " colorspace conversion," : "",
2062 (dword >> 22) & 0x1f, mip_filter,
2063 decode_sample_filter(dword >> 17),
2064 decode_sample_filter(dword >> 14),
2065 ((dword >> 5) & 0x1ff) / (0x10 * 1.0),
2066 dword & (1 << 4) ? " shadow," : "",
2067 dword & (1 << 3) ? 4 : 2,
2068 decode_compare_func(dword));
2069 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08002070 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08002071 "sampler %d SS3: min_lod=%.2f,%s "
2072 "tcmode_x=%s, tcmode_y=%s, tcmode_z=%s,%s texmap_idx=%i,%s\n",
2073 sampler,
2074 ((dword >> 24) & 0xff) / (0x10 * 1.0),
2075 dword & (1 << 17) ?
2076 " kill pixel enable," : "",
2077 decode_tex_coord_mode(dword >> 12),
2078 decode_tex_coord_mode(dword >> 9),
2079 decode_tex_coord_mode(dword >> 6),
2080 dword & (1 << 5) ?
2081 " normalized coords," : "",
2082 (dword >> 1) & 0xf,
2083 dword & (1 << 0) ? " deinterlacer," :
2084 "");
2085 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08002086 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08002087 "sampler %d SS4: border color\n",
Eric Anholt0c46f022011-12-20 14:23:15 -08002088 sampler);
Eric Anholt193fa132011-12-20 11:36:07 -08002089 }
2090 }
2091 if (len != i) {
2092 fprintf(out, "Bad count in 3DSTATE_SAMPLER_STATE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002093 }
2094 return len;
2095 case 0x85:
2096 len = (data[0] & 0x0000000f) + 2;
2097
2098 if (len != 2)
2099 fprintf(out,
2100 "Bad count in 3DSTATE_DEST_BUFFER_VARIABLES\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002101
Eric Anholtc1d29462011-12-20 15:29:03 -08002102 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08002103 "3DSTATE_DEST_BUFFER_VARIABLES\n");
2104
2105 switch ((data[1] >> 8) & 0xf) {
2106 case 0x0:
2107 format = "g8";
2108 break;
2109 case 0x1:
2110 format = "x1r5g5b5";
2111 break;
2112 case 0x2:
2113 format = "r5g6b5";
2114 break;
2115 case 0x3:
2116 format = "a8r8g8b8";
2117 break;
2118 case 0x4:
2119 format = "ycrcb_swapy";
2120 break;
2121 case 0x5:
2122 format = "ycrcb_normal";
2123 break;
2124 case 0x6:
2125 format = "ycrcb_swapuv";
2126 break;
2127 case 0x7:
2128 format = "ycrcb_swapuvy";
2129 break;
2130 case 0x8:
2131 format = "a4r4g4b4";
2132 break;
2133 case 0x9:
2134 format = "a1r5g5b5";
2135 break;
2136 case 0xa:
2137 format = "a2r10g10b10";
2138 break;
2139 default:
2140 format = "BAD";
2141 break;
2142 }
2143 switch ((data[1] >> 2) & 0x3) {
2144 case 0x0:
2145 zformat = "u16";
2146 break;
2147 case 0x1:
2148 zformat = "f16";
2149 break;
2150 case 0x2:
2151 zformat = "u24x8";
2152 break;
2153 default:
2154 zformat = "BAD";
2155 break;
2156 }
Eric Anholtc1d29462011-12-20 15:29:03 -08002157 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08002158 "%s format, %s depth format, early Z %sabled\n",
2159 format, zformat,
2160 (data[1] & (1 << 31)) ? "en" : "dis");
2161 return len;
2162
2163 case 0x8e:
2164 {
2165 const char *name, *tiling;
2166
2167 len = (data[0] & 0x0000000f) + 2;
2168 if (len != 3)
2169 fprintf(out,
2170 "Bad count in 3DSTATE_BUFFER_INFO\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002171
2172 switch ((data[1] >> 24) & 0x7) {
2173 case 0x3:
2174 name = "color";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002175 break;
Eric Anholt193fa132011-12-20 11:36:07 -08002176 case 0x7:
2177 name = "depth";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002178 break;
Eric Anholt193fa132011-12-20 11:36:07 -08002179 default:
2180 name = "unknown";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002181 break;
2182 }
Eric Anholt193fa132011-12-20 11:36:07 -08002183
2184 tiling = "none";
2185 if (data[1] & (1 << 23))
2186 tiling = "fenced";
2187 else if (data[1] & (1 << 22))
2188 tiling = data[1] & (1 << 21) ? "Y" : "X";
2189
Eric Anholtc1d29462011-12-20 15:29:03 -08002190 instr_out(ctx, 0, "3DSTATE_BUFFER_INFO\n");
2191 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08002192 "%s, tiling = %s, pitch=%d\n", name, tiling,
2193 data[1] & 0xffff);
2194
Eric Anholtc1d29462011-12-20 15:29:03 -08002195 instr_out(ctx, 2, "address\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002196 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002197 }
Eric Anholt193fa132011-12-20 11:36:07 -08002198 case 0x81:
2199 len = (data[0] & 0x0000000f) + 2;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002200
Eric Anholt193fa132011-12-20 11:36:07 -08002201 if (len != 3)
2202 fprintf(out,
2203 "Bad count in 3DSTATE_SCISSOR_RECTANGLE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002204
Eric Anholtc1d29462011-12-20 15:29:03 -08002205 instr_out(ctx, 0, "3DSTATE_SCISSOR_RECTANGLE\n");
2206 instr_out(ctx, 1, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002207 data[1] & 0xffff, data[1] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -08002208 instr_out(ctx, 2, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002209 data[2] & 0xffff, data[2] >> 16);
2210
2211 return len;
2212 case 0x80:
2213 len = (data[0] & 0x0000000f) + 2;
2214
2215 if (len != 5)
2216 fprintf(out,
2217 "Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002218
Eric Anholtc1d29462011-12-20 15:29:03 -08002219 instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
2220 instr_out(ctx, 1, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002221 data[1] & (1 << 30) ? "depth ofs disabled " : "");
Eric Anholtc1d29462011-12-20 15:29:03 -08002222 instr_out(ctx, 2, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002223 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -08002224 instr_out(ctx, 3, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002225 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -08002226 instr_out(ctx, 4, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002227 data[4] & 0xffff, data[4] >> 16);
2228
2229 return len;
2230 case 0x9c:
2231 len = (data[0] & 0x0000000f) + 2;
2232
2233 if (len != 7)
2234 fprintf(out, "Bad count in 3DSTATE_CLEAR_PARAMETERS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002235
Eric Anholtc1d29462011-12-20 15:29:03 -08002236 instr_out(ctx, 0, "3DSTATE_CLEAR_PARAMETERS\n");
2237 instr_out(ctx, 1, "prim_type=%s, clear=%s%s%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002238 data[1] & (1 << 16) ? "CLEAR_RECT" : "ZONE_INIT",
2239 data[1] & (1 << 2) ? "color," : "",
2240 data[1] & (1 << 1) ? "depth," : "",
2241 data[1] & (1 << 0) ? "stencil," : "");
Eric Anholtc1d29462011-12-20 15:29:03 -08002242 instr_out(ctx, 2, "clear color\n");
2243 instr_out(ctx, 3, "clear depth/stencil\n");
2244 instr_out(ctx, 4, "color value (rgba8888)\n");
2245 instr_out(ctx, 5, "depth value %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002246 int_as_float(data[5]));
Eric Anholtc1d29462011-12-20 15:29:03 -08002247 instr_out(ctx, 6, "clear stencil\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002248 return len;
2249 }
2250
2251 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d_1d); idx++) {
2252 opcode_3d_1d = &opcodes_3d_1d[idx];
2253 if (opcode_3d_1d->i830_only && !IS_GEN2(devid))
2254 continue;
2255
2256 if (((data[0] & 0x00ff0000) >> 16) == opcode_3d_1d->opcode) {
2257 len = 1;
2258
Eric Anholtc1d29462011-12-20 15:29:03 -08002259 instr_out(ctx, 0, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002260 opcode_3d_1d->name);
2261 if (opcode_3d_1d->max_len > 1) {
2262 len = (data[0] & 0x0000ffff) + 2;
2263 if (len < opcode_3d_1d->min_len ||
2264 len > opcode_3d_1d->max_len) {
2265 fprintf(out, "Bad count in %s\n",
2266 opcode_3d_1d->name);
Eric Anholt193fa132011-12-20 11:36:07 -08002267 }
2268 }
2269
2270 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002271 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08002272 }
2273
2274 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002275 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002276 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002277
Eric Anholtc1d29462011-12-20 15:29:03 -08002278 instr_out(ctx, 0, "3D UNKNOWN: 3d_1d opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002279 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08002280 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002281}
2282
2283static int
Eric Anholtde49fd42011-12-20 15:15:21 -08002284decode_3d_primitive(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002285{
Eric Anholtde49fd42011-12-20 15:15:21 -08002286 uint32_t *data = ctx->data;
Eric Anholtde49fd42011-12-20 15:15:21 -08002287 uint32_t count = ctx->count;
Eric Anholt193fa132011-12-20 11:36:07 -08002288 char immediate = (data[0] & (1 << 23)) == 0;
2289 unsigned int len, i, j, ret;
Eric Anholt1db55a82011-12-20 12:00:28 -08002290 const char *primtype;
Eric Anholt193fa132011-12-20 11:36:07 -08002291 int original_s2 = saved_s2;
2292 int original_s4 = saved_s4;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002293
Eric Anholt193fa132011-12-20 11:36:07 -08002294 switch ((data[0] >> 18) & 0xf) {
2295 case 0x0:
2296 primtype = "TRILIST";
2297 break;
2298 case 0x1:
2299 primtype = "TRISTRIP";
2300 break;
2301 case 0x2:
2302 primtype = "TRISTRIP_REVERSE";
2303 break;
2304 case 0x3:
2305 primtype = "TRIFAN";
2306 break;
2307 case 0x4:
2308 primtype = "POLYGON";
2309 break;
2310 case 0x5:
2311 primtype = "LINELIST";
2312 break;
2313 case 0x6:
2314 primtype = "LINESTRIP";
2315 break;
2316 case 0x7:
2317 primtype = "RECTLIST";
2318 break;
2319 case 0x8:
2320 primtype = "POINTLIST";
2321 break;
2322 case 0x9:
2323 primtype = "DIB";
2324 break;
2325 case 0xa:
2326 primtype = "CLEAR_RECT";
2327 saved_s4 = 3 << 6;
2328 saved_s2 = ~0;
2329 break;
2330 default:
2331 primtype = "unknown";
2332 break;
2333 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002334
Eric Anholt193fa132011-12-20 11:36:07 -08002335 /* XXX: 3DPRIM_DIB not supported */
2336 if (immediate) {
2337 len = (data[0] & 0x0003ffff) + 2;
Eric Anholtc1d29462011-12-20 15:29:03 -08002338 instr_out(ctx, 0, "3DPRIMITIVE inline %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002339 primtype);
2340 if (count < len)
2341 BUFFER_FAIL(count, len, "3DPRIMITIVE inline");
2342 if (!saved_s2_set || !saved_s4_set) {
2343 fprintf(out, "unknown vertex format\n");
2344 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002345 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002346 " vertex data (%f float)\n",
2347 int_as_float(data[i]));
2348 }
2349 } else {
2350 unsigned int vertex = 0;
2351 for (i = 1; i < len;) {
2352 unsigned int tc;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002353
2354#define VERTEX_OUT(fmt, ...) do { \
2355 if (i < len) \
Eric Anholtc1d29462011-12-20 15:29:03 -08002356 instr_out(ctx, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002357 else \
2358 fprintf(out, " missing data in V%d\n", vertex); \
2359 i++; \
2360} while (0)
2361
Eric Anholt193fa132011-12-20 11:36:07 -08002362 VERTEX_OUT("X = %f", int_as_float(data[i]));
2363 VERTEX_OUT("Y = %f", int_as_float(data[i]));
2364 switch (saved_s4 >> 6 & 0x7) {
2365 case 0x1:
2366 VERTEX_OUT("Z = %f",
2367 int_as_float(data[i]));
2368 break;
2369 case 0x2:
2370 VERTEX_OUT("Z = %f",
2371 int_as_float(data[i]));
2372 VERTEX_OUT("W = %f",
2373 int_as_float(data[i]));
2374 break;
2375 case 0x3:
2376 break;
2377 case 0x4:
2378 VERTEX_OUT("W = %f",
2379 int_as_float(data[i]));
2380 break;
2381 default:
2382 fprintf(out, "bad S4 position mask\n");
2383 }
2384
2385 if (saved_s4 & (1 << 10)) {
2386 VERTEX_OUT
2387 ("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
2388 "B=0x%02x)", data[i] >> 24,
2389 (data[i] >> 16) & 0xff,
2390 (data[i] >> 8) & 0xff,
2391 data[i] & 0xff);
2392 }
2393 if (saved_s4 & (1 << 11)) {
2394 VERTEX_OUT
2395 ("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
2396 "B=0x%02x)", data[i] >> 24,
2397 (data[i] >> 16) & 0xff,
2398 (data[i] >> 8) & 0xff,
2399 data[i] & 0xff);
2400 }
2401 if (saved_s4 & (1 << 12))
2402 VERTEX_OUT("width = 0x%08x)", data[i]);
2403
2404 for (tc = 0; tc <= 7; tc++) {
2405 switch ((saved_s2 >> (tc * 4)) & 0xf) {
2406 case 0x0:
2407 VERTEX_OUT("T%d.X = %f", tc,
2408 int_as_float(data
2409 [i]));
2410 VERTEX_OUT("T%d.Y = %f", tc,
2411 int_as_float(data
2412 [i]));
2413 break;
2414 case 0x1:
2415 VERTEX_OUT("T%d.X = %f", tc,
2416 int_as_float(data
2417 [i]));
2418 VERTEX_OUT("T%d.Y = %f", tc,
2419 int_as_float(data
2420 [i]));
2421 VERTEX_OUT("T%d.Z = %f", tc,
2422 int_as_float(data
2423 [i]));
2424 break;
2425 case 0x2:
2426 VERTEX_OUT("T%d.X = %f", tc,
2427 int_as_float(data
2428 [i]));
2429 VERTEX_OUT("T%d.Y = %f", tc,
2430 int_as_float(data
2431 [i]));
2432 VERTEX_OUT("T%d.Z = %f", tc,
2433 int_as_float(data
2434 [i]));
2435 VERTEX_OUT("T%d.W = %f", tc,
2436 int_as_float(data
2437 [i]));
2438 break;
2439 case 0x3:
2440 VERTEX_OUT("T%d.X = %f", tc,
2441 int_as_float(data
2442 [i]));
2443 break;
2444 case 0x4:
2445 VERTEX_OUT
2446 ("T%d.XY = 0x%08x half-float",
2447 tc, data[i]);
2448 break;
2449 case 0x5:
2450 VERTEX_OUT
2451 ("T%d.XY = 0x%08x half-float",
2452 tc, data[i]);
2453 VERTEX_OUT
2454 ("T%d.ZW = 0x%08x half-float",
2455 tc, data[i]);
2456 break;
2457 case 0xf:
2458 break;
2459 default:
2460 fprintf(out,
2461 "bad S2.T%d format\n",
2462 tc);
2463 }
2464 }
2465 vertex++;
2466 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002467 }
2468
Eric Anholt193fa132011-12-20 11:36:07 -08002469 ret = len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002470 } else {
Eric Anholt193fa132011-12-20 11:36:07 -08002471 /* indirect vertices */
2472 len = data[0] & 0x0000ffff; /* index count */
2473 if (data[0] & (1 << 17)) {
2474 /* random vertex access */
2475 if (count < (len + 1) / 2 + 1) {
2476 BUFFER_FAIL(count, (len + 1) / 2 + 1,
2477 "3DPRIMITIVE random indirect");
2478 }
Eric Anholtc1d29462011-12-20 15:29:03 -08002479 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08002480 "3DPRIMITIVE random indirect %s (%d)\n",
2481 primtype, len);
2482 if (len == 0) {
Eric Anholtbbdda922011-12-20 11:44:36 -08002483 /* vertex indices continue until 0xffff is
2484 * found
2485 */
Eric Anholt193fa132011-12-20 11:36:07 -08002486 for (i = 1; i < count; i++) {
2487 if ((data[i] & 0xffff) == 0xffff) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002488 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002489 " indices: (terminator)\n");
2490 ret = i;
2491 goto out;
2492 } else if ((data[i] >> 16) == 0xffff) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002493 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002494 " indices: 0x%04x, (terminator)\n",
2495 data[i] & 0xffff);
2496 ret = i;
2497 goto out;
2498 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002499 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002500 " indices: 0x%04x, 0x%04x\n",
2501 data[i] & 0xffff,
2502 data[i] >> 16);
2503 }
2504 }
2505 fprintf(out,
2506 "3DPRIMITIVE: no terminator found in index buffer\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002507 ret = count;
2508 goto out;
2509 } else {
2510 /* fixed size vertex index buffer */
2511 for (j = 1, i = 0; i < len; i += 2, j++) {
2512 if (i * 2 == len - 1) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002513 instr_out(ctx, j,
Eric Anholt193fa132011-12-20 11:36:07 -08002514 " indices: 0x%04x\n",
2515 data[j] & 0xffff);
2516 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002517 instr_out(ctx, j,
Eric Anholt193fa132011-12-20 11:36:07 -08002518 " indices: 0x%04x, 0x%04x\n",
2519 data[j] & 0xffff,
2520 data[j] >> 16);
2521 }
2522 }
2523 }
2524 ret = (len + 1) / 2 + 1;
2525 goto out;
2526 } else {
2527 /* sequential vertex access */
Eric Anholtc1d29462011-12-20 15:29:03 -08002528 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08002529 "3DPRIMITIVE sequential indirect %s, %d starting from "
2530 "%d\n", primtype, len, data[1] & 0xffff);
Eric Anholtc1d29462011-12-20 15:29:03 -08002531 instr_out(ctx, 1, " start\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002532 ret = 2;
2533 goto out;
2534 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002535 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002536
2537out:
Eric Anholt193fa132011-12-20 11:36:07 -08002538 saved_s2 = original_s2;
2539 saved_s4 = original_s4;
2540 return ret;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002541}
2542
2543static int
Eric Anholtde49fd42011-12-20 15:15:21 -08002544decode_3d(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002545{
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002546 uint32_t opcode;
Eric Anholt193fa132011-12-20 11:36:07 -08002547 unsigned int idx;
Eric Anholtde49fd42011-12-20 15:15:21 -08002548 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002549
Eric Anholt193fa132011-12-20 11:36:07 -08002550 struct {
2551 uint32_t opcode;
Eric Anholt07768ba2011-12-20 13:46:23 -08002552 unsigned int min_len;
2553 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08002554 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -08002555 } opcodes_3d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -08002556 { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
2557 { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
2558 { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
2559 { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
2560 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
2561 { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
2562 { 0x0d, 1, 1, "3DSTATE_MODES_4" },
2563 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
2564 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES"},
2565 }, *opcode_3d;
Eric Anholt193fa132011-12-20 11:36:07 -08002566
2567 opcode = (data[0] & 0x1f000000) >> 24;
2568
2569 switch (opcode) {
2570 case 0x1f:
Eric Anholtde49fd42011-12-20 15:15:21 -08002571 return decode_3d_primitive(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08002572 case 0x1d:
Eric Anholtde49fd42011-12-20 15:15:21 -08002573 return decode_3d_1d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08002574 case 0x1c:
Eric Anholtde49fd42011-12-20 15:15:21 -08002575 return decode_3d_1c(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08002576 }
2577
2578 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
2579 opcode_3d = &opcodes_3d[idx];
2580 if (opcode == opcode_3d->opcode) {
2581 unsigned int len = 1, i;
2582
Eric Anholtc1d29462011-12-20 15:29:03 -08002583 instr_out(ctx, 0, "%s\n", opcode_3d->name);
Eric Anholt193fa132011-12-20 11:36:07 -08002584 if (opcode_3d->max_len > 1) {
2585 len = (data[0] & 0xff) + 2;
2586 if (len < opcode_3d->min_len ||
2587 len > opcode_3d->max_len) {
2588 fprintf(out, "Bad count in %s\n",
2589 opcode_3d->name);
2590 }
2591 }
2592
2593 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002594 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08002595 }
2596 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002597 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002598 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002599
Eric Anholtc1d29462011-12-20 15:29:03 -08002600 instr_out(ctx, 0, "3D UNKNOWN: 3d opcode = 0x%x\n", opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08002601 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002602}
2603
Eric Anholt193fa132011-12-20 11:36:07 -08002604static const char *get_965_surfacetype(unsigned int surfacetype)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002605{
Eric Anholt193fa132011-12-20 11:36:07 -08002606 switch (surfacetype) {
2607 case 0:
2608 return "1D";
2609 case 1:
2610 return "2D";
2611 case 2:
2612 return "3D";
2613 case 3:
2614 return "CUBE";
2615 case 4:
2616 return "BUFFER";
2617 case 7:
2618 return "NULL";
2619 default:
2620 return "unknown";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002621 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002622}
2623
Eric Anholt193fa132011-12-20 11:36:07 -08002624static const char *get_965_depthformat(unsigned int depthformat)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002625{
Eric Anholt193fa132011-12-20 11:36:07 -08002626 switch (depthformat) {
2627 case 0:
2628 return "s8_z24float";
2629 case 1:
2630 return "z32float";
2631 case 2:
2632 return "z24s8";
2633 case 5:
2634 return "z16";
2635 default:
2636 return "unknown";
2637 }
2638}
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002639
Eric Anholt193fa132011-12-20 11:36:07 -08002640static const char *get_965_element_component(uint32_t data, int component)
2641{
2642 uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
2643
2644 switch (component_control) {
2645 case 0:
2646 return "nostore";
2647 case 1:
2648 switch (component) {
2649 case 0:
2650 return "X";
2651 case 1:
2652 return "Y";
2653 case 2:
2654 return "Z";
2655 case 3:
2656 return "W";
2657 default:
2658 return "fail";
2659 }
2660 case 2:
2661 return "0.0";
2662 case 3:
2663 return "1.0";
2664 case 4:
2665 return "0x1";
2666 case 5:
2667 return "VID";
2668 default:
2669 return "fail";
2670 }
2671}
2672
Eric Anholt9d18ad22012-03-02 10:27:55 -08002673static const char *get_965_prim_type(uint32_t primtype)
Eric Anholt193fa132011-12-20 11:36:07 -08002674{
Eric Anholt193fa132011-12-20 11:36:07 -08002675 switch (primtype) {
2676 case 0x01:
2677 return "point list";
2678 case 0x02:
2679 return "line list";
2680 case 0x03:
2681 return "line strip";
2682 case 0x04:
2683 return "tri list";
2684 case 0x05:
2685 return "tri strip";
2686 case 0x06:
2687 return "tri fan";
2688 case 0x07:
2689 return "quad list";
2690 case 0x08:
2691 return "quad strip";
2692 case 0x09:
2693 return "line list adj";
2694 case 0x0a:
2695 return "line strip adj";
2696 case 0x0b:
2697 return "tri list adj";
2698 case 0x0c:
2699 return "tri strip adj";
2700 case 0x0d:
2701 return "tri strip reverse";
2702 case 0x0e:
2703 return "polygon";
2704 case 0x0f:
2705 return "rect list";
2706 case 0x10:
2707 return "line loop";
2708 case 0x11:
2709 return "point list bf";
2710 case 0x12:
2711 return "line strip cont";
2712 case 0x13:
2713 return "line strip bf";
2714 case 0x14:
2715 return "line strip cont bf";
2716 case 0x15:
2717 return "tri fan no stipple";
2718 default:
2719 return "fail";
2720 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002721}
2722
2723static int
Eric Anholtc1d29462011-12-20 15:29:03 -08002724i965_decode_urb_fence(struct drm_intel_decode *ctx, int len)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002725{
2726 uint32_t vs_fence, clip_fence, gs_fence, sf_fence, vfe_fence, cs_fence;
Eric Anholtc1d29462011-12-20 15:29:03 -08002727 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002728
2729 if (len != 3)
Eric Anholt193fa132011-12-20 11:36:07 -08002730 fprintf(out, "Bad count in URB_FENCE\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002731
2732 vs_fence = data[1] & 0x3ff;
2733 gs_fence = (data[1] >> 10) & 0x3ff;
2734 clip_fence = (data[1] >> 20) & 0x3ff;
2735 sf_fence = data[2] & 0x3ff;
2736 vfe_fence = (data[2] >> 10) & 0x3ff;
2737 cs_fence = (data[2] >> 20) & 0x7ff;
2738
Eric Anholtc1d29462011-12-20 15:29:03 -08002739 instr_out(ctx, 0, "URB_FENCE: %s%s%s%s%s%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002740 (data[0] >> 13) & 1 ? "cs " : "",
2741 (data[0] >> 12) & 1 ? "vfe " : "",
2742 (data[0] >> 11) & 1 ? "sf " : "",
2743 (data[0] >> 10) & 1 ? "clip " : "",
2744 (data[0] >> 9) & 1 ? "gs " : "",
2745 (data[0] >> 8) & 1 ? "vs " : "");
Eric Anholtc1d29462011-12-20 15:29:03 -08002746 instr_out(ctx, 1,
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002747 "vs fence: %d, clip_fence: %d, gs_fence: %d\n",
2748 vs_fence, clip_fence, gs_fence);
Eric Anholtc1d29462011-12-20 15:29:03 -08002749 instr_out(ctx, 2,
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002750 "sf fence: %d, vfe_fence: %d, cs_fence: %d\n",
2751 sf_fence, vfe_fence, cs_fence);
2752 if (gs_fence < vs_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002753 fprintf(out, "gs fence < vs fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002754 if (clip_fence < gs_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002755 fprintf(out, "clip fence < gs fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002756 if (sf_fence < clip_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002757 fprintf(out, "sf fence < clip fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002758 if (cs_fence < sf_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002759 fprintf(out, "cs fence < sf fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002760
2761 return len;
2762}
2763
2764static void
Eric Anholtc1d29462011-12-20 15:29:03 -08002765state_base_out(struct drm_intel_decode *ctx, unsigned int index,
Eric Anholt1db55a82011-12-20 12:00:28 -08002766 const char *name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002767{
Eric Anholtc1d29462011-12-20 15:29:03 -08002768 if (ctx->data[index] & 1) {
2769 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002770 "%s state base address 0x%08x\n", name,
Eric Anholtc1d29462011-12-20 15:29:03 -08002771 ctx->data[index] & ~1);
Eric Anholt193fa132011-12-20 11:36:07 -08002772 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002773 instr_out(ctx, index, "%s state base not updated\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002774 name);
2775 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002776}
2777
2778static void
Eric Anholtc1d29462011-12-20 15:29:03 -08002779state_max_out(struct drm_intel_decode *ctx, unsigned int index,
Eric Anholt1db55a82011-12-20 12:00:28 -08002780 const char *name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002781{
Eric Anholtc1d29462011-12-20 15:29:03 -08002782 if (ctx->data[index] & 1) {
2783 if (ctx->data[index] == 1) {
2784 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002785 "%s state upper bound disabled\n", name);
2786 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002787 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002788 "%s state upper bound 0x%08x\n", name,
Eric Anholtc1d29462011-12-20 15:29:03 -08002789 ctx->data[index] & ~1);
Eric Anholt193fa132011-12-20 11:36:07 -08002790 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002791 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002792 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002793 "%s state upper bound not updated\n", name);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002794 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002795}
2796
2797static int
Eric Anholt938df6b2012-01-04 12:23:42 -08002798gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(struct drm_intel_decode *ctx)
2799{
2800 instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_CC\n");
2801 instr_out(ctx, 1, "pointer to CC viewport\n");
2802
2803 return 2;
2804}
2805
2806static int
2807gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(struct drm_intel_decode *ctx)
2808{
2809 instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP\n");
2810 instr_out(ctx, 1, "pointer to SF_CLIP viewport\n");
2811
2812 return 2;
2813}
2814
2815static int
2816gen7_3DSTATE_BLEND_STATE_POINTERS(struct drm_intel_decode *ctx)
2817{
2818 instr_out(ctx, 0, "3DSTATE_BLEND_STATE_POINTERS\n");
2819 instr_out(ctx, 1, "pointer to BLEND_STATE at 0x%08x (%s)\n",
2820 ctx->data[1] & ~1,
2821 (ctx->data[1] & 1) ? "changed" : "unchanged");
2822
2823 return 2;
2824}
2825
2826static int
2827gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(struct drm_intel_decode *ctx)
2828{
2829 instr_out(ctx, 0, "3DSTATE_DEPTH_STENCIL_STATE_POINTERS\n");
2830 instr_out(ctx, 1,
2831 "pointer to DEPTH_STENCIL_STATE at 0x%08x (%s)\n",
2832 ctx->data[1] & ~1,
2833 (ctx->data[1] & 1) ? "changed" : "unchanged");
2834
2835 return 2;
2836}
2837
2838static int
Eric Anholtb395af02012-01-30 15:13:32 -08002839gen7_3DSTATE_HIER_DEPTH_BUFFER(struct drm_intel_decode *ctx)
2840{
2841 instr_out(ctx, 0, "3DSTATE_HIER_DEPTH_BUFFER\n");
2842 instr_out(ctx, 1, "pitch %db\n",
2843 (ctx->data[1] & 0x1ffff) + 1);
2844 instr_out(ctx, 2, "pointer to HiZ buffer\n");
2845
2846 return 3;
2847}
2848
2849static int
Eric Anholt938df6b2012-01-04 12:23:42 -08002850gen6_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
2851{
2852 instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
2853 instr_out(ctx, 1, "blend change %d\n", ctx->data[1] & 1);
2854 instr_out(ctx, 2, "depth stencil change %d\n",
2855 ctx->data[2] & 1);
2856 instr_out(ctx, 3, "cc change %d\n", ctx->data[3] & 1);
2857
2858 return 4;
2859}
2860
2861static int
2862gen7_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
2863{
2864 instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
2865 instr_out(ctx, 1, "pointer to COLOR_CALC_STATE at 0x%08x "
2866 "(%s)\n",
2867 ctx->data[1] & ~1,
2868 (ctx->data[1] & 1) ? "changed" : "unchanged");
2869
2870 return 2;
2871}
2872
2873static int
Eric Anholt6a0b25e2012-01-04 12:12:41 -08002874gen7_3DSTATE_URB_unit(struct drm_intel_decode *ctx, const char *unit)
2875{
2876 int start_kb = ((ctx->data[1] >> 25) & 0x3f) * 8;
2877 /* the field is # of 512-bit rows - 1, we print bytes */
2878 int entry_size = (((ctx->data[1] >> 16) & 0x1ff) + 1);
2879 int nr_entries = ctx->data[1] & 0xffff;
2880
2881 instr_out(ctx, 0, "3DSTATE_URB_%s\n", unit);
2882 instr_out(ctx, 1,
2883 "%dKB start, size=%d 64B rows, nr_entries=%d, total size %dB\n",
2884 start_kb, entry_size, nr_entries, nr_entries * 64 * entry_size);
2885
2886 return 2;
2887}
2888
2889static int
2890gen7_3DSTATE_URB_VS(struct drm_intel_decode *ctx)
2891{
2892 return gen7_3DSTATE_URB_unit(ctx, "VS");
2893}
2894
2895static int
2896gen7_3DSTATE_URB_HS(struct drm_intel_decode *ctx)
2897{
2898 return gen7_3DSTATE_URB_unit(ctx, "HS");
2899}
2900
2901static int
2902gen7_3DSTATE_URB_DS(struct drm_intel_decode *ctx)
2903{
2904 return gen7_3DSTATE_URB_unit(ctx, "DS");
2905}
2906
2907static int
2908gen7_3DSTATE_URB_GS(struct drm_intel_decode *ctx)
2909{
2910 return gen7_3DSTATE_URB_unit(ctx, "GS");
2911}
2912
2913static int
Eric Anholt54b12a02012-01-04 13:41:55 -08002914gen7_3DSTATE_CONSTANT(struct drm_intel_decode *ctx, const char *unit)
2915{
2916 int rlen[4];
2917
2918 rlen[0] = (ctx->data[1] >> 0) & 0xffff;
2919 rlen[1] = (ctx->data[1] >> 16) & 0xffff;
2920 rlen[2] = (ctx->data[2] >> 0) & 0xffff;
2921 rlen[3] = (ctx->data[2] >> 16) & 0xffff;
2922
2923 instr_out(ctx, 0, "3DSTATE_CONSTANT_%s\n", unit);
2924 instr_out(ctx, 1, "len 0 = %d, len 1 = %d\n", rlen[0], rlen[1]);
2925 instr_out(ctx, 2, "len 2 = %d, len 3 = %d\n", rlen[2], rlen[3]);
2926 instr_out(ctx, 3, "pointer to constbuf 0\n");
2927 instr_out(ctx, 4, "pointer to constbuf 1\n");
2928 instr_out(ctx, 5, "pointer to constbuf 2\n");
2929 instr_out(ctx, 6, "pointer to constbuf 3\n");
2930
2931 return 7;
2932}
2933
2934static int
2935gen7_3DSTATE_CONSTANT_VS(struct drm_intel_decode *ctx)
2936{
2937 return gen7_3DSTATE_CONSTANT(ctx, "VS");
2938}
2939
2940static int
2941gen7_3DSTATE_CONSTANT_GS(struct drm_intel_decode *ctx)
2942{
2943 return gen7_3DSTATE_CONSTANT(ctx, "GS");
2944}
2945
2946static int
2947gen7_3DSTATE_CONSTANT_PS(struct drm_intel_decode *ctx)
2948{
2949 return gen7_3DSTATE_CONSTANT(ctx, "PS");
2950}
2951
2952static int
2953gen7_3DSTATE_CONSTANT_DS(struct drm_intel_decode *ctx)
2954{
2955 return gen7_3DSTATE_CONSTANT(ctx, "DS");
2956}
2957
2958static int
2959gen7_3DSTATE_CONSTANT_HS(struct drm_intel_decode *ctx)
2960{
2961 return gen7_3DSTATE_CONSTANT(ctx, "HS");
2962}
2963
Eric Anholte6beaf82012-01-30 15:04:10 -08002964
2965static int
2966gen6_3DSTATE_WM(struct drm_intel_decode *ctx)
2967{
2968 instr_out(ctx, 0, "3DSTATE_WM\n");
2969 instr_out(ctx, 1, "kernel start pointer 0\n");
2970 instr_out(ctx, 2,
2971 "SPF=%d, VME=%d, Sampler Count %d, "
2972 "Binding table count %d\n",
2973 (ctx->data[2] >> 31) & 1,
2974 (ctx->data[2] >> 30) & 1,
2975 (ctx->data[2] >> 27) & 7,
2976 (ctx->data[2] >> 18) & 0xff);
2977 instr_out(ctx, 3, "scratch offset\n");
2978 instr_out(ctx, 4,
2979 "Depth Clear %d, Depth Resolve %d, HiZ Resolve %d, "
2980 "Dispatch GRF start[0] %d, start[1] %d, start[2] %d\n",
2981 (ctx->data[4] & (1 << 30)) != 0,
2982 (ctx->data[4] & (1 << 28)) != 0,
2983 (ctx->data[4] & (1 << 27)) != 0,
2984 (ctx->data[4] >> 16) & 0x7f,
2985 (ctx->data[4] >> 8) & 0x7f,
2986 (ctx->data[4] & 0x7f));
2987 instr_out(ctx, 5,
2988 "MaxThreads %d, PS KillPixel %d, PS computed Z %d, "
2989 "PS use sourceZ %d, Thread Dispatch %d, PS use sourceW %d, "
2990 "Dispatch32 %d, Dispatch16 %d, Dispatch8 %d\n",
2991 ((ctx->data[5] >> 25) & 0x7f) + 1,
2992 (ctx->data[5] & (1 << 22)) != 0,
2993 (ctx->data[5] & (1 << 21)) != 0,
2994 (ctx->data[5] & (1 << 20)) != 0,
2995 (ctx->data[5] & (1 << 19)) != 0,
2996 (ctx->data[5] & (1 << 8)) != 0,
2997 (ctx->data[5] & (1 << 2)) != 0,
2998 (ctx->data[5] & (1 << 1)) != 0,
2999 (ctx->data[5] & (1 << 0)) != 0);
3000 instr_out(ctx, 6,
3001 "Num SF output %d, Pos XY offset %d, ZW interp mode %d , "
3002 "Barycentric interp mode 0x%x, Point raster rule %d, "
3003 "Multisample mode %d, "
3004 "Multisample Dispatch mode %d\n",
3005 (ctx->data[6] >> 20) & 0x3f,
3006 (ctx->data[6] >> 18) & 3,
3007 (ctx->data[6] >> 16) & 3,
3008 (ctx->data[6] >> 10) & 0x3f,
3009 (ctx->data[6] & (1 << 9)) != 0,
3010 (ctx->data[6] >> 1) & 3,
3011 (ctx->data[6] & 1));
3012 instr_out(ctx, 7, "kernel start pointer 1\n");
3013 instr_out(ctx, 8, "kernel start pointer 2\n");
3014
3015 return 9;
3016}
3017
3018static int
3019gen7_3DSTATE_WM(struct drm_intel_decode *ctx)
3020{
3021 const char *computed_depth = "";
3022 const char *early_depth = "";
3023 const char *zw_interp = "";
3024
3025 switch ((ctx->data[1] >> 23) & 0x3) {
3026 case 0:
3027 computed_depth = "";
3028 break;
3029 case 1:
3030 computed_depth = "computed depth";
3031 break;
3032 case 2:
3033 computed_depth = "computed depth >=";
3034 break;
3035 case 3:
3036 computed_depth = "computed depth <=";
3037 break;
3038 }
3039
3040 switch ((ctx->data[1] >> 21) & 0x3) {
3041 case 0:
3042 early_depth = "";
3043 break;
3044 case 1:
3045 early_depth = ", EDSC_PSEXEC";
3046 break;
3047 case 2:
3048 early_depth = ", EDSC_PREPS";
3049 break;
3050 case 3:
3051 early_depth = ", BAD EDSC";
3052 break;
3053 }
3054
3055 switch ((ctx->data[1] >> 17) & 0x3) {
3056 case 0:
3057 early_depth = "";
3058 break;
3059 case 1:
3060 early_depth = ", BAD ZW interp";
3061 break;
3062 case 2:
3063 early_depth = ", ZW centroid";
3064 break;
3065 case 3:
3066 early_depth = ", ZW sample";
3067 break;
3068 }
3069
3070 instr_out(ctx, 0, "3DSTATE_WM\n");
3071 instr_out(ctx, 1, "(%s%s%s%s%s%s)%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
3072 (ctx->data[1] & (1 << 11)) ? "PP " : "",
3073 (ctx->data[1] & (1 << 12)) ? "PC " : "",
3074 (ctx->data[1] & (1 << 13)) ? "PS " : "",
3075 (ctx->data[1] & (1 << 14)) ? "NPP " : "",
3076 (ctx->data[1] & (1 << 15)) ? "NPC " : "",
3077 (ctx->data[1] & (1 << 16)) ? "NPS " : "",
3078 (ctx->data[1] & (1 << 30)) ? ", depth clear" : "",
3079 (ctx->data[1] & (1 << 29)) ? "" : ", disabled",
3080 (ctx->data[1] & (1 << 28)) ? ", depth resolve" : "",
3081 (ctx->data[1] & (1 << 27)) ? ", hiz resolve" : "",
3082 (ctx->data[1] & (1 << 25)) ? ", kill" : "",
3083 computed_depth,
3084 early_depth,
3085 zw_interp,
3086 (ctx->data[1] & (1 << 20)) ? ", source depth" : "",
3087 (ctx->data[1] & (1 << 19)) ? ", source W" : "",
3088 (ctx->data[1] & (1 << 10)) ? ", coverage" : "",
3089 (ctx->data[1] & (1 << 4)) ? ", poly stipple" : "",
3090 (ctx->data[1] & (1 << 3)) ? ", line stipple" : "",
3091 (ctx->data[1] & (1 << 2)) ? ", point UL" : ", point UR"
3092 );
3093 instr_out(ctx, 2, "MS\n");
3094
3095 return 3;
3096}
3097
Eric Anholt54b12a02012-01-04 13:41:55 -08003098static int
Eric Anholt9b87fd92012-03-02 10:18:51 -08003099gen4_3DPRIMITIVE(struct drm_intel_decode *ctx)
3100{
3101 instr_out(ctx, 0,
3102 "3DPRIMITIVE: %s %s\n",
Eric Anholt9d18ad22012-03-02 10:27:55 -08003103 get_965_prim_type((ctx->data[0] >> 10) & 0x1f),
Eric Anholt9b87fd92012-03-02 10:18:51 -08003104 (ctx->data[0] & (1 << 15)) ? "random" : "sequential");
3105 instr_out(ctx, 1, "vertex count\n");
3106 instr_out(ctx, 2, "start vertex\n");
3107 instr_out(ctx, 3, "instance count\n");
3108 instr_out(ctx, 4, "start instance\n");
3109 instr_out(ctx, 5, "index bias\n");
3110
3111 return 6;
3112}
3113
3114static int
Eric Anholt9d18ad22012-03-02 10:27:55 -08003115gen7_3DPRIMITIVE(struct drm_intel_decode *ctx)
3116{
3117 bool indirect = !!(ctx->data[0] & (1 << 10));
3118
3119 instr_out(ctx, 0,
3120 "3DPRIMITIVE: %s%s\n",
3121 indirect ? " indirect" : "",
3122 (ctx->data[0] & (1 << 8)) ? " predicated" : "");
3123 instr_out(ctx, 1, "%s %s\n",
3124 get_965_prim_type(ctx->data[1] & 0x3f),
3125 (ctx->data[1] & (1 << 8)) ? "random" : "sequential");
3126 instr_out(ctx, 2, indirect ? "ignored" : "vertex count\n");
3127 instr_out(ctx, 3, indirect ? "ignored" : "start vertex\n");
3128 instr_out(ctx, 4, indirect ? "ignored" : "instance count\n");
3129 instr_out(ctx, 5, indirect ? "ignored" : "start instance\n");
3130 instr_out(ctx, 6, indirect ? "ignored" : "index bias\n");
3131
3132 return 7;
3133}
3134
3135static int
Eric Anholtde49fd42011-12-20 15:15:21 -08003136decode_3d_965(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003137{
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003138 uint32_t opcode;
Eric Anholtb129e102012-01-04 13:00:29 -08003139 unsigned int len;
Eric Anholt7b483182011-12-20 14:27:17 -08003140 unsigned int i, j, sba_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08003141 const char *desc1 = NULL;
Eric Anholtde49fd42011-12-20 15:15:21 -08003142 uint32_t *data = ctx->data;
Eric Anholtde49fd42011-12-20 15:15:21 -08003143 uint32_t devid = ctx->devid;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003144
Eric Anholt193fa132011-12-20 11:36:07 -08003145 struct {
3146 uint32_t opcode;
Eric Anholtb129e102012-01-04 13:00:29 -08003147 uint32_t len_mask;
Eric Anholt07768ba2011-12-20 13:46:23 -08003148 int unsigned min_len;
3149 int unsigned max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08003150 const char *name;
Eric Anholt9695eee2012-01-04 12:00:59 -08003151 int gen;
Eric Anholt3dcb2d42012-01-04 12:06:44 -08003152 int (*func)(struct drm_intel_decode *ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003153 } opcodes_3d[] = {
Eric Anholtb129e102012-01-04 13:00:29 -08003154 { 0x6000, 0x00ff, 3, 3, "URB_FENCE" },
3155 { 0x6001, 0xffff, 2, 2, "CS_URB_STATE" },
3156 { 0x6002, 0x00ff, 2, 2, "CONSTANT_BUFFER" },
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003157 { 0x6101, 0xffff, 6, 10, "STATE_BASE_ADDRESS" },
Eric Anholtb129e102012-01-04 13:00:29 -08003158 { 0x6102, 0xffff, 2, 2, "STATE_SIP" },
3159 { 0x6104, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
3160 { 0x680b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
3161 { 0x6904, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
3162 { 0x7800, 0xffff, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003163 { 0x7801, 0x00ff, 4, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
Eric Anholtb129e102012-01-04 13:00:29 -08003164 { 0x7802, 0x00ff, 4, 4, "3DSTATE_SAMPLER_STATE_POINTERS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003165 { 0x7805, 0x00ff, 7, 7, "3DSTATE_DEPTH_BUFFER", 7 },
Eric Anholtb129e102012-01-04 13:00:29 -08003166 { 0x7805, 0x00ff, 3, 3, "3DSTATE_URB" },
Eric Anholtb643b072012-01-04 14:36:13 -08003167 { 0x7804, 0x00ff, 3, 3, "3DSTATE_CLEAR_PARAMS" },
3168 { 0x7806, 0x00ff, 3, 3, "3DSTATE_STENCIL_BUFFER" },
Daniel Vetterb7bb9e92013-04-03 18:25:12 +02003169 { 0x790f, 0x00ff, 3, 3, "3DSTATE_HIER_DEPTH_BUFFER", 6 },
Eric Anholtb395af02012-01-30 15:13:32 -08003170 { 0x7807, 0x00ff, 3, 3, "3DSTATE_HIER_DEPTH_BUFFER", 7, gen7_3DSTATE_HIER_DEPTH_BUFFER },
Eric Anholtb129e102012-01-04 13:00:29 -08003171 { 0x7808, 0x00ff, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
3172 { 0x7809, 0x00ff, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
3173 { 0x780a, 0x00ff, 3, 3, "3DSTATE_INDEX_BUFFER" },
3174 { 0x780b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
3175 { 0x780d, 0x00ff, 4, 4, "3DSTATE_VIEWPORT_STATE_POINTERS" },
Eric Anholt938df6b2012-01-04 12:23:42 -08003176 { 0x780e, 0xffff, 4, 4, NULL, 6, gen6_3DSTATE_CC_STATE_POINTERS },
3177 { 0x780e, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_CC_STATE_POINTERS },
Eric Anholtb129e102012-01-04 13:00:29 -08003178 { 0x780f, 0x00ff, 2, 2, "3DSTATE_SCISSOR_POINTERS" },
3179 { 0x7810, 0x00ff, 6, 6, "3DSTATE_VS" },
3180 { 0x7811, 0x00ff, 7, 7, "3DSTATE_GS" },
3181 { 0x7812, 0x00ff, 4, 4, "3DSTATE_CLIP" },
Eric Anholtb643b072012-01-04 14:36:13 -08003182 { 0x7813, 0x00ff, 20, 20, "3DSTATE_SF", 6 },
3183 { 0x7813, 0x00ff, 7, 7, "3DSTATE_SF", 7 },
Eric Anholte6beaf82012-01-30 15:04:10 -08003184 { 0x7814, 0x00ff, 3, 3, "3DSTATE_WM", 7, gen7_3DSTATE_WM },
3185 { 0x7814, 0x00ff, 9, 9, "3DSTATE_WM", 6, gen6_3DSTATE_WM },
Eric Anholt54b12a02012-01-04 13:41:55 -08003186 { 0x7815, 0x00ff, 5, 5, "3DSTATE_CONSTANT_VS_STATE", 6 },
3187 { 0x7815, 0x00ff, 7, 7, "3DSTATE_CONSTANT_VS", 7, gen7_3DSTATE_CONSTANT_VS },
3188 { 0x7816, 0x00ff, 5, 5, "3DSTATE_CONSTANT_GS_STATE", 6 },
3189 { 0x7816, 0x00ff, 7, 7, "3DSTATE_CONSTANT_GS", 7, gen7_3DSTATE_CONSTANT_GS },
3190 { 0x7817, 0x00ff, 5, 5, "3DSTATE_CONSTANT_PS_STATE", 6 },
3191 { 0x7817, 0x00ff, 7, 7, "3DSTATE_CONSTANT_PS", 7, gen7_3DSTATE_CONSTANT_PS },
Eric Anholtb129e102012-01-04 13:00:29 -08003192 { 0x7818, 0xffff, 2, 2, "3DSTATE_SAMPLE_MASK" },
Eric Anholt54b12a02012-01-04 13:41:55 -08003193 { 0x7819, 0x00ff, 7, 7, "3DSTATE_CONSTANT_HS", 7, gen7_3DSTATE_CONSTANT_HS },
3194 { 0x781a, 0x00ff, 7, 7, "3DSTATE_CONSTANT_DS", 7, gen7_3DSTATE_CONSTANT_DS },
Eric Anholtb643b072012-01-04 14:36:13 -08003195 { 0x781b, 0x00ff, 7, 7, "3DSTATE_HS" },
3196 { 0x781c, 0x00ff, 4, 4, "3DSTATE_TE" },
3197 { 0x781d, 0x00ff, 6, 6, "3DSTATE_DS" },
3198 { 0x781e, 0x00ff, 3, 3, "3DSTATE_STREAMOUT" },
3199 { 0x781f, 0x00ff, 14, 14, "3DSTATE_SBE" },
3200 { 0x7820, 0x00ff, 8, 8, "3DSTATE_PS" },
Eric Anholt938df6b2012-01-04 12:23:42 -08003201 { 0x7821, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP },
3202 { 0x7823, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC },
3203 { 0x7824, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_BLEND_STATE_POINTERS },
3204 { 0x7825, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS },
Eric Anholtb643b072012-01-04 14:36:13 -08003205 { 0x7826, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_VS" },
3206 { 0x7827, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_HS" },
3207 { 0x7828, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_DS" },
3208 { 0x7829, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_GS" },
3209 { 0x782a, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_PS" },
3210 { 0x782b, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_VS" },
Ben Widawskyeeedb0d2012-06-24 21:53:50 -07003211 { 0x782c, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_HS" },
3212 { 0x782d, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_DS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003213 { 0x782e, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_GS" },
3214 { 0x782f, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_PS" },
Eric Anholt6a0b25e2012-01-04 12:12:41 -08003215 { 0x7830, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_VS },
3216 { 0x7831, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_HS },
3217 { 0x7832, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_DS },
3218 { 0x7833, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_GS },
Eric Anholtb129e102012-01-04 13:00:29 -08003219 { 0x7900, 0xffff, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
3220 { 0x7901, 0xffff, 5, 5, "3DSTATE_CONSTANT_COLOR" },
3221 { 0x7905, 0xffff, 5, 7, "3DSTATE_DEPTH_BUFFER" },
3222 { 0x7906, 0xffff, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
3223 { 0x7907, 0xffff, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
3224 { 0x7908, 0xffff, 3, 3, "3DSTATE_LINE_STIPPLE" },
3225 { 0x7909, 0xffff, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
3226 { 0x7909, 0xffff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
3227 { 0x790a, 0xffff, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
3228 { 0x790b, 0xffff, 4, 4, "3DSTATE_GS_SVB_INDEX" },
3229 { 0x790d, 0xffff, 3, 3, "3DSTATE_MULTISAMPLE", 6 },
3230 { 0x790d, 0xffff, 4, 4, "3DSTATE_MULTISAMPLE", 7 },
Chris Forbes20c56072013-01-28 08:01:18 +00003231 { 0x7910, 0x00ff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003232 { 0x7912, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_VS" },
Ben Widawskyae137f42012-06-24 17:12:24 -07003233 { 0x7913, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_HS" },
3234 { 0x7914, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_DS" },
3235 { 0x7915, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_GS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003236 { 0x7916, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_PS" },
3237 { 0x7917, 0x00ff, 2, 2+128*2, "3DSTATE_SO_DECL_LIST" },
3238 { 0x7918, 0x00ff, 4, 4, "3DSTATE_SO_BUFFER" },
Eric Anholtb129e102012-01-04 13:00:29 -08003239 { 0x7a00, 0x00ff, 4, 6, "PIPE_CONTROL" },
Eric Anholt9d18ad22012-03-02 10:27:55 -08003240 { 0x7b00, 0x00ff, 7, 7, NULL, 7, gen7_3DPRIMITIVE },
Eric Anholt9b87fd92012-03-02 10:18:51 -08003241 { 0x7b00, 0x00ff, 6, 6, NULL, 0, gen4_3DPRIMITIVE },
Eric Anholtb129e102012-01-04 13:00:29 -08003242 }, *opcode_3d = NULL;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003243
Eric Anholt193fa132011-12-20 11:36:07 -08003244 opcode = (data[0] & 0xffff0000) >> 16;
Eric Anholtb129e102012-01-04 13:00:29 -08003245
3246 for (i = 0; i < ARRAY_SIZE(opcodes_3d); i++) {
3247 if (opcode != opcodes_3d[i].opcode)
3248 continue;
3249
3250 /* If it's marked as not our gen, skip. */
3251 if (opcodes_3d[i].gen && opcodes_3d[i].gen != ctx->gen)
3252 continue;
3253
3254 opcode_3d = &opcodes_3d[i];
3255 break;
3256 }
3257
3258 if (opcode_3d) {
3259 if (opcode_3d->max_len == 1)
3260 len = 1;
3261 else
3262 len = (data[0] & opcode_3d->len_mask) + 2;
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003263
3264 if (len < opcode_3d->min_len ||
3265 len > opcode_3d->max_len) {
Eric Anholt259e7b62012-01-27 13:27:56 -08003266 fprintf(out, "Bad length %d in %s, expected %d-%d\n",
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003267 len, opcode_3d->name,
3268 opcode_3d->min_len, opcode_3d->max_len);
3269 }
Eric Anholtb129e102012-01-04 13:00:29 -08003270 } else {
3271 len = (data[0] & 0x0000ffff) + 2;
3272 }
3273
Eric Anholt193fa132011-12-20 11:36:07 -08003274 switch (opcode) {
3275 case 0x6000:
Eric Anholtc1d29462011-12-20 15:29:03 -08003276 return i965_decode_urb_fence(ctx, len);
Eric Anholt193fa132011-12-20 11:36:07 -08003277 case 0x6001:
Eric Anholtc1d29462011-12-20 15:29:03 -08003278 instr_out(ctx, 0, "CS_URB_STATE\n");
3279 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003280 "entry_size: %d [%d bytes], n_entries: %d\n",
3281 (data[1] >> 4) & 0x1f,
3282 (((data[1] >> 4) & 0x1f) + 1) * 64, data[1] & 0x7);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003283 return len;
Eric Anholt193fa132011-12-20 11:36:07 -08003284 case 0x6002:
Eric Anholtc1d29462011-12-20 15:29:03 -08003285 instr_out(ctx, 0, "CONSTANT_BUFFER: %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003286 (data[0] >> 8) & 1 ? "valid" : "invalid");
Eric Anholtc1d29462011-12-20 15:29:03 -08003287 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003288 "offset: 0x%08x, length: %d bytes\n", data[1] & ~0x3f,
3289 ((data[1] & 0x3f) + 1) * 64);
3290 return len;
3291 case 0x6101:
3292 i = 0;
Eric Anholtc1d29462011-12-20 15:29:03 -08003293 instr_out(ctx, 0, "STATE_BASE_ADDRESS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003294 i++;
3295
3296 if (IS_GEN6(devid) || IS_GEN7(devid))
3297 sba_len = 10;
3298 else if (IS_GEN5(devid))
3299 sba_len = 8;
3300 else
3301 sba_len = 6;
3302 if (len != sba_len)
3303 fprintf(out, "Bad count in STATE_BASE_ADDRESS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003304
Eric Anholtc1d29462011-12-20 15:29:03 -08003305 state_base_out(ctx, i++, "general");
3306 state_base_out(ctx, i++, "surface");
Eric Anholt193fa132011-12-20 11:36:07 -08003307 if (IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003308 state_base_out(ctx, i++, "dynamic");
3309 state_base_out(ctx, i++, "indirect");
Eric Anholt193fa132011-12-20 11:36:07 -08003310 if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003311 state_base_out(ctx, i++, "instruction");
Eric Anholt193fa132011-12-20 11:36:07 -08003312
Eric Anholtc1d29462011-12-20 15:29:03 -08003313 state_max_out(ctx, i++, "general");
Eric Anholt193fa132011-12-20 11:36:07 -08003314 if (IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003315 state_max_out(ctx, i++, "dynamic");
3316 state_max_out(ctx, i++, "indirect");
Eric Anholt193fa132011-12-20 11:36:07 -08003317 if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003318 state_max_out(ctx, i++, "instruction");
Eric Anholt193fa132011-12-20 11:36:07 -08003319
3320 return len;
3321 case 0x7800:
Eric Anholtc1d29462011-12-20 15:29:03 -08003322 instr_out(ctx, 0, "3DSTATE_PIPELINED_POINTERS\n");
3323 instr_out(ctx, 1, "VS state\n");
3324 instr_out(ctx, 2, "GS state\n");
3325 instr_out(ctx, 3, "Clip state\n");
3326 instr_out(ctx, 4, "SF state\n");
3327 instr_out(ctx, 5, "WM state\n");
3328 instr_out(ctx, 6, "CC state\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003329 return len;
3330 case 0x7801:
Eric Anholt193fa132011-12-20 11:36:07 -08003331 if (len != 6 && len != 4)
3332 fprintf(out,
3333 "Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
3334 if (len == 6) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003335 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003336 "3DSTATE_BINDING_TABLE_POINTERS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003337 instr_out(ctx, 1, "VS binding table\n");
3338 instr_out(ctx, 2, "GS binding table\n");
3339 instr_out(ctx, 3, "Clip binding table\n");
3340 instr_out(ctx, 4, "SF binding table\n");
3341 instr_out(ctx, 5, "WM binding table\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003342 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08003343 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003344 "3DSTATE_BINDING_TABLE_POINTERS: VS mod %d, "
3345 "GS mod %d, PS mod %d\n",
3346 (data[0] & (1 << 8)) != 0,
3347 (data[0] & (1 << 9)) != 0,
3348 (data[0] & (1 << 12)) != 0);
Eric Anholtc1d29462011-12-20 15:29:03 -08003349 instr_out(ctx, 1, "VS binding table\n");
3350 instr_out(ctx, 2, "GS binding table\n");
3351 instr_out(ctx, 3, "WM binding table\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003352 }
3353
3354 return len;
3355 case 0x7802:
Eric Anholtc1d29462011-12-20 15:29:03 -08003356 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003357 "3DSTATE_SAMPLER_STATE_POINTERS: VS mod %d, "
3358 "GS mod %d, PS mod %d\n", (data[0] & (1 << 8)) != 0,
3359 (data[0] & (1 << 9)) != 0,
3360 (data[0] & (1 << 12)) != 0);
Eric Anholtc1d29462011-12-20 15:29:03 -08003361 instr_out(ctx, 1, "VS sampler state\n");
3362 instr_out(ctx, 2, "GS sampler state\n");
3363 instr_out(ctx, 3, "WM sampler state\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003364 return len;
3365 case 0x7805:
Eric Anholtb643b072012-01-04 14:36:13 -08003366 /* Actually 3DSTATE_DEPTH_BUFFER on gen7. */
3367 if (ctx->gen == 7)
3368 break;
3369
Eric Anholtc1d29462011-12-20 15:29:03 -08003370 instr_out(ctx, 0, "3DSTATE_URB\n");
3371 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003372 "VS entries %d, alloc size %d (1024bit row)\n",
3373 data[1] & 0xffff, ((data[1] >> 16) & 0x07f) + 1);
Eric Anholtc1d29462011-12-20 15:29:03 -08003374 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003375 "GS entries %d, alloc size %d (1024bit row)\n",
3376 (data[2] >> 8) & 0x3ff, (data[2] & 7) + 1);
3377 return len;
3378
3379 case 0x7808:
Eric Anholt193fa132011-12-20 11:36:07 -08003380 if ((len - 1) % 4 != 0)
3381 fprintf(out, "Bad count in 3DSTATE_VERTEX_BUFFERS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003382 instr_out(ctx, 0, "3DSTATE_VERTEX_BUFFERS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003383
3384 for (i = 1; i < len;) {
3385 int idx, access;
3386 if (IS_GEN6(devid)) {
3387 idx = 26;
3388 access = 20;
3389 } else {
3390 idx = 27;
3391 access = 26;
3392 }
Eric Anholtc1d29462011-12-20 15:29:03 -08003393 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08003394 "buffer %d: %s, pitch %db\n", data[i] >> idx,
3395 data[i] & (1 << access) ? "random" :
3396 "sequential", data[i] & 0x07ff);
3397 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08003398 instr_out(ctx, i++, "buffer address\n");
3399 instr_out(ctx, i++, "max index\n");
3400 instr_out(ctx, i++, "mbz\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003401 }
3402 return len;
3403
3404 case 0x7809:
Eric Anholt193fa132011-12-20 11:36:07 -08003405 if ((len + 1) % 2 != 0)
3406 fprintf(out, "Bad count in 3DSTATE_VERTEX_ELEMENTS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003407 instr_out(ctx, 0, "3DSTATE_VERTEX_ELEMENTS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003408
3409 for (i = 1; i < len;) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003410 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08003411 "buffer %d: %svalid, type 0x%04x, "
3412 "src offset 0x%04x bytes\n",
Ben Widawskya7805192012-06-27 10:10:53 -07003413 data[i] >> ((IS_GEN6(devid) || IS_GEN7(devid)) ? 26 : 27),
3414 data[i] & (1 << ((IS_GEN6(devid) || IS_GEN7(devid)) ? 25 : 26)) ?
Ben Widawskydf5cc692012-06-27 10:19:49 -07003415 "" : "in", (data[i] >> 16) & 0x1ff,
Eric Anholt193fa132011-12-20 11:36:07 -08003416 data[i] & 0x07ff);
3417 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08003418 instr_out(ctx, i, "(%s, %s, %s, %s), "
Eric Anholt193fa132011-12-20 11:36:07 -08003419 "dst offset 0x%02x bytes\n",
3420 get_965_element_component(data[i], 0),
3421 get_965_element_component(data[i], 1),
3422 get_965_element_component(data[i], 2),
3423 get_965_element_component(data[i], 3),
3424 (data[i] & 0xff) * 4);
3425 i++;
3426 }
3427 return len;
3428
3429 case 0x780d:
Eric Anholtc1d29462011-12-20 15:29:03 -08003430 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003431 "3DSTATE_VIEWPORT_STATE_POINTERS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003432 instr_out(ctx, 1, "clip\n");
3433 instr_out(ctx, 2, "sf\n");
3434 instr_out(ctx, 3, "cc\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003435 return len;
3436
3437 case 0x780a:
Eric Anholtc1d29462011-12-20 15:29:03 -08003438 instr_out(ctx, 0, "3DSTATE_INDEX_BUFFER\n");
3439 instr_out(ctx, 1, "beginning buffer address\n");
3440 instr_out(ctx, 2, "ending buffer address\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003441 return len;
3442
Eric Anholt193fa132011-12-20 11:36:07 -08003443 case 0x780f:
Eric Anholtc1d29462011-12-20 15:29:03 -08003444 instr_out(ctx, 0, "3DSTATE_SCISSOR_POINTERS\n");
3445 instr_out(ctx, 1, "scissor rect offset\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003446 return len;
3447
3448 case 0x7810:
Eric Anholtc1d29462011-12-20 15:29:03 -08003449 instr_out(ctx, 0, "3DSTATE_VS\n");
3450 instr_out(ctx, 1, "kernel pointer\n");
3451 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003452 "SPF=%d, VME=%d, Sampler Count %d, "
3453 "Binding table count %d\n", (data[2] >> 31) & 1,
3454 (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3455 (data[2] >> 18) & 0xff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003456 instr_out(ctx, 3, "scratch offset\n");
3457 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003458 "Dispatch GRF start %d, VUE read length %d, "
3459 "VUE read offset %d\n", (data[4] >> 20) & 0x1f,
3460 (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
Eric Anholtc1d29462011-12-20 15:29:03 -08003461 instr_out(ctx, 5,
Eric Anholt193fa132011-12-20 11:36:07 -08003462 "Max Threads %d, Vertex Cache %sable, "
3463 "VS func %sable\n", ((data[5] >> 25) & 0x7f) + 1,
3464 (data[5] & (1 << 1)) != 0 ? "dis" : "en",
3465 (data[5] & 1) != 0 ? "en" : "dis");
3466 return len;
3467
3468 case 0x7811:
Eric Anholtc1d29462011-12-20 15:29:03 -08003469 instr_out(ctx, 0, "3DSTATE_GS\n");
3470 instr_out(ctx, 1, "kernel pointer\n");
3471 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003472 "SPF=%d, VME=%d, Sampler Count %d, "
3473 "Binding table count %d\n", (data[2] >> 31) & 1,
3474 (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3475 (data[2] >> 18) & 0xff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003476 instr_out(ctx, 3, "scratch offset\n");
3477 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003478 "Dispatch GRF start %d, VUE read length %d, "
3479 "VUE read offset %d\n", (data[4] & 0xf),
3480 (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
Eric Anholtc1d29462011-12-20 15:29:03 -08003481 instr_out(ctx, 5,
Eric Anholt193fa132011-12-20 11:36:07 -08003482 "Max Threads %d, Rendering %sable\n",
3483 ((data[5] >> 25) & 0x7f) + 1,
3484 (data[5] & (1 << 8)) != 0 ? "en" : "dis");
Eric Anholtc1d29462011-12-20 15:29:03 -08003485 instr_out(ctx, 6,
Eric Anholt193fa132011-12-20 11:36:07 -08003486 "Reorder %sable, Discard Adjaceny %sable, "
3487 "GS %sable\n",
3488 (data[6] & (1 << 30)) != 0 ? "en" : "dis",
3489 (data[6] & (1 << 29)) != 0 ? "en" : "dis",
3490 (data[6] & (1 << 15)) != 0 ? "en" : "dis");
3491 return len;
3492
3493 case 0x7812:
Eric Anholtc1d29462011-12-20 15:29:03 -08003494 instr_out(ctx, 0, "3DSTATE_CLIP\n");
3495 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003496 "UserClip distance cull test mask 0x%x\n",
3497 data[1] & 0xff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003498 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003499 "Clip %sable, API mode %s, Viewport XY test %sable, "
3500 "Viewport Z test %sable, Guardband test %sable, Clip mode %d, "
3501 "Perspective Divide %sable, Non-Perspective Barycentric %sable, "
3502 "Tri Provoking %d, Line Provoking %d, Trifan Provoking %d\n",
3503 (data[2] & (1 << 31)) != 0 ? "en" : "dis",
3504 (data[2] & (1 << 30)) != 0 ? "D3D" : "OGL",
3505 (data[2] & (1 << 28)) != 0 ? "en" : "dis",
3506 (data[2] & (1 << 27)) != 0 ? "en" : "dis",
3507 (data[2] & (1 << 26)) != 0 ? "en" : "dis",
3508 (data[2] >> 13) & 7,
3509 (data[2] & (1 << 9)) != 0 ? "dis" : "en",
3510 (data[2] & (1 << 8)) != 0 ? "en" : "dis",
3511 (data[2] >> 4) & 3, (data[2] >> 2) & 3,
3512 (data[2] & 3));
Eric Anholtc1d29462011-12-20 15:29:03 -08003513 instr_out(ctx, 3,
Eric Anholt193fa132011-12-20 11:36:07 -08003514 "Min PointWidth %d, Max PointWidth %d, "
3515 "Force Zero RTAIndex %sable, Max VPIndex %d\n",
3516 (data[3] >> 17) & 0x7ff, (data[3] >> 6) & 0x7ff,
3517 (data[3] & (1 << 5)) != 0 ? "en" : "dis",
3518 (data[3] & 0xf));
3519 return len;
3520
3521 case 0x7813:
Eric Anholtb643b072012-01-04 14:36:13 -08003522 if (ctx->gen == 7)
3523 break;
3524
Eric Anholtc1d29462011-12-20 15:29:03 -08003525 instr_out(ctx, 0, "3DSTATE_SF\n");
3526 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003527 "Attrib Out %d, Attrib Swizzle %sable, VUE read length %d, "
3528 "VUE read offset %d\n", (data[1] >> 22) & 0x3f,
3529 (data[1] & (1 << 21)) != 0 ? "en" : "dis",
3530 (data[1] >> 11) & 0x1f, (data[1] >> 4) & 0x3f);
Eric Anholtc1d29462011-12-20 15:29:03 -08003531 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003532 "Legacy Global DepthBias %sable, FrontFace fill %d, BF fill %d, "
3533 "VP transform %sable, FrontWinding_%s\n",
3534 (data[2] & (1 << 11)) != 0 ? "en" : "dis",
3535 (data[2] >> 5) & 3, (data[2] >> 3) & 3,
3536 (data[2] & (1 << 1)) != 0 ? "en" : "dis",
3537 (data[2] & 1) != 0 ? "CCW" : "CW");
Eric Anholtc1d29462011-12-20 15:29:03 -08003538 instr_out(ctx, 3,
Eric Anholt193fa132011-12-20 11:36:07 -08003539 "AA %sable, CullMode %d, Scissor %sable, Multisample m ode %d\n",
3540 (data[3] & (1 << 31)) != 0 ? "en" : "dis",
3541 (data[3] >> 29) & 3,
3542 (data[3] & (1 << 11)) != 0 ? "en" : "dis",
3543 (data[3] >> 8) & 3);
Eric Anholtc1d29462011-12-20 15:29:03 -08003544 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003545 "Last Pixel %sable, SubPixel Precision %d, Use PixelWidth %d\n",
3546 (data[4] & (1 << 31)) != 0 ? "en" : "dis",
3547 (data[4] & (1 << 12)) != 0 ? 4 : 8,
3548 (data[4] & (1 << 11)) != 0);
Eric Anholtc1d29462011-12-20 15:29:03 -08003549 instr_out(ctx, 5,
Eric Anholt0c46f022011-12-20 14:23:15 -08003550 "Global Depth Offset Constant %f\n",
3551 *(float *)(&data[5]));
Eric Anholtc1d29462011-12-20 15:29:03 -08003552 instr_out(ctx, 6, "Global Depth Offset Scale %f\n",
Eric Anholt0c46f022011-12-20 14:23:15 -08003553 *(float *)(&data[6]));
Eric Anholtc1d29462011-12-20 15:29:03 -08003554 instr_out(ctx, 7, "Global Depth Offset Clamp %f\n",
Eric Anholt0c46f022011-12-20 14:23:15 -08003555 *(float *)(&data[7]));
Eric Anholt7b483182011-12-20 14:27:17 -08003556
Eric Anholt193fa132011-12-20 11:36:07 -08003557 for (i = 0, j = 0; i < 8; i++, j += 2)
Eric Anholtc1d29462011-12-20 15:29:03 -08003558 instr_out(ctx, i + 8,
Eric Anholt193fa132011-12-20 11:36:07 -08003559 "Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, "
3560 "Source %d); Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, Source %d)\n",
3561 j + 1,
3562 (data[8 + i] & (1 << 31)) != 0 ? "W" : "",
3563 (data[8 + i] & (1 << 30)) != 0 ? "Z" : "",
3564 (data[8 + i] & (1 << 29)) != 0 ? "Y" : "",
3565 (data[8 + i] & (1 << 28)) != 0 ? "X" : "",
3566 (data[8 + i] >> 25) & 3,
3567 (data[8 + i] >> 22) & 3,
3568 (data[8 + i] >> 16) & 0x1f, j,
3569 (data[8 + i] & (1 << 15)) != 0 ? "W" : "",
3570 (data[8 + i] & (1 << 14)) != 0 ? "Z" : "",
3571 (data[8 + i] & (1 << 13)) != 0 ? "Y" : "",
3572 (data[8 + i] & (1 << 12)) != 0 ? "X" : "",
3573 (data[8 + i] >> 9) & 3,
3574 (data[8 + i] >> 6) & 3, (data[8 + i] & 0x1f));
Eric Anholtc1d29462011-12-20 15:29:03 -08003575 instr_out(ctx, 16,
Eric Anholt193fa132011-12-20 11:36:07 -08003576 "Point Sprite TexCoord Enable\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003577 instr_out(ctx, 17, "Const Interp Enable\n");
3578 instr_out(ctx, 18,
Eric Anholt193fa132011-12-20 11:36:07 -08003579 "Attrib 7-0 WrapShortest Enable\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003580 instr_out(ctx, 19,
Eric Anholt193fa132011-12-20 11:36:07 -08003581 "Attrib 15-8 WrapShortest Enable\n");
3582
3583 return len;
3584
Eric Anholt193fa132011-12-20 11:36:07 -08003585 case 0x7900:
Eric Anholtc1d29462011-12-20 15:29:03 -08003586 instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
3587 instr_out(ctx, 1, "top left: %d,%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003588 data[1] & 0xffff, (data[1] >> 16) & 0xffff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003589 instr_out(ctx, 2, "bottom right: %d,%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003590 data[2] & 0xffff, (data[2] >> 16) & 0xffff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003591 instr_out(ctx, 3, "origin: %d,%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003592 (int)data[3] & 0xffff, ((int)data[3] >> 16) & 0xffff);
3593
3594 return len;
3595
3596 case 0x7905:
Eric Anholtc1d29462011-12-20 15:29:03 -08003597 instr_out(ctx, 0, "3DSTATE_DEPTH_BUFFER\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003598 if (IS_GEN5(devid) || IS_GEN6(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003599 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003600 "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Seperate Stencil %d\n",
3601 get_965_surfacetype(data[1] >> 29),
3602 get_965_depthformat((data[1] >> 18) & 0x7),
3603 (data[1] & 0x0001ffff) + 1,
3604 data[1] & (1 << 27) ? "" : "not ",
3605 (data[1] & (1 << 22)) != 0,
3606 (data[1] & (1 << 21)) != 0);
3607 else
Eric Anholtc1d29462011-12-20 15:29:03 -08003608 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003609 "%s, %s, pitch = %d bytes, %stiled\n",
3610 get_965_surfacetype(data[1] >> 29),
3611 get_965_depthformat((data[1] >> 18) & 0x7),
3612 (data[1] & 0x0001ffff) + 1,
3613 data[1] & (1 << 27) ? "" : "not ");
Eric Anholtc1d29462011-12-20 15:29:03 -08003614 instr_out(ctx, 2, "depth offset\n");
3615 instr_out(ctx, 3, "%dx%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003616 ((data[3] & 0x0007ffc0) >> 6) + 1,
3617 ((data[3] & 0xfff80000) >> 19) + 1);
Eric Anholtc1d29462011-12-20 15:29:03 -08003618 instr_out(ctx, 4, "volume depth\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003619 if (len >= 6)
Eric Anholtc1d29462011-12-20 15:29:03 -08003620 instr_out(ctx, 5, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003621 if (len >= 7) {
3622 if (IS_GEN6(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003623 instr_out(ctx, 6, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003624 else
Eric Anholtc1d29462011-12-20 15:29:03 -08003625 instr_out(ctx, 6,
Eric Anholt193fa132011-12-20 11:36:07 -08003626 "render target view extent\n");
3627 }
3628
3629 return len;
3630
3631 case 0x7a00:
Eric Anholt71066ab2011-12-20 13:06:16 -08003632 if (IS_GEN6(devid) || IS_GEN7(devid)) {
Eric Anholt07768ba2011-12-20 13:46:23 -08003633 unsigned int i;
Eric Anholt193fa132011-12-20 11:36:07 -08003634 if (len != 4 && len != 5)
3635 fprintf(out, "Bad count in PIPE_CONTROL\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003636
3637 switch ((data[1] >> 14) & 0x3) {
3638 case 0:
3639 desc1 = "no write";
3640 break;
3641 case 1:
3642 desc1 = "qword write";
3643 break;
3644 case 2:
3645 desc1 = "PS_DEPTH_COUNT write";
3646 break;
3647 case 3:
3648 desc1 = "TIMESTAMP write";
3649 break;
3650 }
Eric Anholtc1d29462011-12-20 15:29:03 -08003651 instr_out(ctx, 0, "PIPE_CONTROL\n");
3652 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003653 "%s, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
3654 desc1,
3655 data[1] & (1 << 20) ? "cs stall, " : "",
3656 data[1] & (1 << 19) ?
3657 "global snapshot count reset, " : "",
3658 data[1] & (1 << 18) ? "tlb invalidate, " : "",
3659 data[1] & (1 << 17) ? "gfdt flush, " : "",
3660 data[1] & (1 << 17) ? "media state clear, " :
3661 "",
3662 data[1] & (1 << 13) ? "depth stall, " : "",
3663 data[1] & (1 << 12) ?
3664 "render target cache flush, " : "",
3665 data[1] & (1 << 11) ?
3666 "instruction cache invalidate, " : "",
3667 data[1] & (1 << 10) ?
3668 "texture cache invalidate, " : "",
3669 data[1] & (1 << 9) ?
3670 "indirect state invalidate, " : "",
3671 data[1] & (1 << 8) ? "notify irq, " : "",
3672 data[1] & (1 << 7) ? "PIPE_CONTROL flush, " :
3673 "",
3674 data[1] & (1 << 6) ? "protect mem app_id, " :
3675 "", data[1] & (1 << 5) ? "DC flush, " : "",
3676 data[1] & (1 << 4) ? "vf fetch invalidate, " :
3677 "",
3678 data[1] & (1 << 3) ?
3679 "constant cache invalidate, " : "",
3680 data[1] & (1 << 2) ?
3681 "state cache invalidate, " : "",
3682 data[1] & (1 << 1) ? "stall at scoreboard, " :
3683 "",
3684 data[1] & (1 << 0) ? "depth cache flush, " :
3685 "");
3686 if (len == 5) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003687 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003688 "destination address\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003689 instr_out(ctx, 3,
Eric Anholt193fa132011-12-20 11:36:07 -08003690 "immediate dword low\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003691 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003692 "immediate dword high\n");
3693 } else {
3694 for (i = 2; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003695 instr_out(ctx, i, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003696 }
3697 }
3698 return len;
3699 } else {
Eric Anholt193fa132011-12-20 11:36:07 -08003700 if (len != 4)
3701 fprintf(out, "Bad count in PIPE_CONTROL\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003702
3703 switch ((data[0] >> 14) & 0x3) {
3704 case 0:
3705 desc1 = "no write";
3706 break;
3707 case 1:
3708 desc1 = "qword write";
3709 break;
3710 case 2:
3711 desc1 = "PS_DEPTH_COUNT write";
3712 break;
3713 case 3:
3714 desc1 = "TIMESTAMP write";
3715 break;
3716 }
Eric Anholtc1d29462011-12-20 15:29:03 -08003717 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003718 "PIPE_CONTROL: %s, %sdepth stall, %sRC write flush, "
3719 "%sinst flush\n",
3720 desc1,
3721 data[0] & (1 << 13) ? "" : "no ",
3722 data[0] & (1 << 12) ? "" : "no ",
3723 data[0] & (1 << 11) ? "" : "no ");
Eric Anholtc1d29462011-12-20 15:29:03 -08003724 instr_out(ctx, 1, "destination address\n");
3725 instr_out(ctx, 2, "immediate dword low\n");
3726 instr_out(ctx, 3, "immediate dword high\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003727 return len;
3728 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003729 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003730
Eric Anholtb129e102012-01-04 13:00:29 -08003731 if (opcode_3d) {
Eric Anholt3dcb2d42012-01-04 12:06:44 -08003732 if (opcode_3d->func) {
3733 return opcode_3d->func(ctx);
3734 } else {
Eric Anholt193fa132011-12-20 11:36:07 -08003735 unsigned int i;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003736
Eric Anholtc1d29462011-12-20 15:29:03 -08003737 instr_out(ctx, 0, "%s\n", opcode_3d->name);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003738
Eric Anholt193fa132011-12-20 11:36:07 -08003739 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003740 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08003741 }
3742 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003743 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003744 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003745
Eric Anholtc1d29462011-12-20 15:29:03 -08003746 instr_out(ctx, 0, "3D UNKNOWN: 3d_965 opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003747 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08003748 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003749}
3750
3751static int
Eric Anholtde49fd42011-12-20 15:15:21 -08003752decode_3d_i830(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003753{
Eric Anholt193fa132011-12-20 11:36:07 -08003754 unsigned int idx;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003755 uint32_t opcode;
Eric Anholtde49fd42011-12-20 15:15:21 -08003756 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003757
Eric Anholt193fa132011-12-20 11:36:07 -08003758 struct {
3759 uint32_t opcode;
Eric Anholt07768ba2011-12-20 13:46:23 -08003760 unsigned int min_len;
3761 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08003762 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -08003763 } opcodes_3d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -08003764 { 0x02, 1, 1, "3DSTATE_MODES_3" },
3765 { 0x03, 1, 1, "3DSTATE_ENABLES_1" },
3766 { 0x04, 1, 1, "3DSTATE_ENABLES_2" },
3767 { 0x05, 1, 1, "3DSTATE_VFT0" },
3768 { 0x06, 1, 1, "3DSTATE_AA" },
3769 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
3770 { 0x08, 1, 1, "3DSTATE_MODES_1" },
3771 { 0x09, 1, 1, "3DSTATE_STENCIL_TEST" },
3772 { 0x0a, 1, 1, "3DSTATE_VFT1" },
3773 { 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" },
3774 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
3775 { 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" },
3776 { 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" },
3777 { 0x0f, 1, 1, "3DSTATE_MODES_2" },
3778 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
3779 { 0x16, 1, 1, "3DSTATE_MODES_4"},
3780 }, *opcode_3d;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003781
Eric Anholt193fa132011-12-20 11:36:07 -08003782 opcode = (data[0] & 0x1f000000) >> 24;
3783
3784 switch (opcode) {
3785 case 0x1f:
Eric Anholtde49fd42011-12-20 15:15:21 -08003786 return decode_3d_primitive(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003787 case 0x1d:
Eric Anholtde49fd42011-12-20 15:15:21 -08003788 return decode_3d_1d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003789 case 0x1c:
Eric Anholtde49fd42011-12-20 15:15:21 -08003790 return decode_3d_1c(ctx);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003791 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003792
Eric Anholt193fa132011-12-20 11:36:07 -08003793 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
3794 opcode_3d = &opcodes_3d[idx];
3795 if ((data[0] & 0x1f000000) >> 24 == opcode_3d->opcode) {
3796 unsigned int len = 1, i;
3797
Eric Anholtc1d29462011-12-20 15:29:03 -08003798 instr_out(ctx, 0, "%s\n", opcode_3d->name);
Eric Anholt193fa132011-12-20 11:36:07 -08003799 if (opcode_3d->max_len > 1) {
3800 len = (data[0] & 0xff) + 2;
3801 if (len < opcode_3d->min_len ||
3802 len > opcode_3d->max_len) {
3803 fprintf(out, "Bad count in %s\n",
3804 opcode_3d->name);
3805 }
3806 }
3807
3808 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003809 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08003810 }
3811 return len;
3812 }
3813 }
3814
Eric Anholtc1d29462011-12-20 15:29:03 -08003815 instr_out(ctx, 0, "3D UNKNOWN: 3d_i830 opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003816 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08003817 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003818}
3819
Emil Velikov0f8da822015-03-31 22:32:11 +01003820struct drm_intel_decode *
Eric Anholt71066ab2011-12-20 13:06:16 -08003821drm_intel_decode_context_alloc(uint32_t devid)
3822{
3823 struct drm_intel_decode *ctx;
3824
3825 ctx = calloc(1, sizeof(struct drm_intel_decode));
3826 if (!ctx)
3827 return NULL;
3828
3829 ctx->devid = devid;
Eric Anholtea33a232012-01-03 13:05:57 -08003830 ctx->out = stdout;
Eric Anholt71066ab2011-12-20 13:06:16 -08003831
Damien Lespiau00847fa2013-02-13 16:09:38 +00003832 if (IS_GEN9(devid))
3833 ctx->gen = 9;
3834 else if (IS_GEN8(devid))
Damien Lespiau946f8472013-02-13 16:09:34 +00003835 ctx->gen = 8;
3836 else if (IS_GEN7(devid))
Eric Anholt9695eee2012-01-04 12:00:59 -08003837 ctx->gen = 7;
3838 else if (IS_GEN6(devid))
3839 ctx->gen = 6;
3840 else if (IS_GEN5(devid))
3841 ctx->gen = 5;
3842 else if (IS_GEN4(devid))
3843 ctx->gen = 4;
3844 else if (IS_9XX(devid))
3845 ctx->gen = 3;
3846 else {
3847 assert(IS_GEN2(devid));
3848 ctx->gen = 2;
3849 }
3850
Eric Anholt71066ab2011-12-20 13:06:16 -08003851 return ctx;
3852}
3853
Emil Velikov0f8da822015-03-31 22:32:11 +01003854void
Eric Anholt71066ab2011-12-20 13:06:16 -08003855drm_intel_decode_context_free(struct drm_intel_decode *ctx)
3856{
3857 free(ctx);
3858}
3859
Emil Velikov0f8da822015-03-31 22:32:11 +01003860void
Eric Anholt71066ab2011-12-20 13:06:16 -08003861drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx,
3862 int dump_past_end)
3863{
3864 ctx->dump_past_end = !!dump_past_end;
3865}
3866
Emil Velikov0f8da822015-03-31 22:32:11 +01003867void
Eric Anholt71066ab2011-12-20 13:06:16 -08003868drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx,
3869 void *data, uint32_t hw_offset, int count)
3870{
Eric Anholt8fb66a72011-12-20 14:59:38 -08003871 ctx->base_data = data;
3872 ctx->base_hw_offset = hw_offset;
3873 ctx->base_count = count;
Eric Anholt71066ab2011-12-20 13:06:16 -08003874}
3875
Emil Velikov0f8da822015-03-31 22:32:11 +01003876void
Eric Anholt71066ab2011-12-20 13:06:16 -08003877drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx,
3878 uint32_t head, uint32_t tail)
3879{
3880 ctx->head = head;
3881 ctx->tail = tail;
3882}
3883
Emil Velikov0f8da822015-03-31 22:32:11 +01003884void
Eric Anholtea33a232012-01-03 13:05:57 -08003885drm_intel_decode_set_output_file(struct drm_intel_decode *ctx,
3886 FILE *out)
3887{
3888 ctx->out = out;
3889}
3890
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003891/**
3892 * Decodes an i830-i915 batch buffer, writing the output to stdout.
3893 *
3894 * \param data batch buffer contents
3895 * \param count number of DWORDs to decode in the batch buffer
3896 * \param hw_offset hardware address for the buffer
3897 */
Emil Velikov0f8da822015-03-31 22:32:11 +01003898void
Eric Anholt71066ab2011-12-20 13:06:16 -08003899drm_intel_decode(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003900{
Eric Anholt193fa132011-12-20 11:36:07 -08003901 int ret;
Eric Anholt07768ba2011-12-20 13:46:23 -08003902 unsigned int index = 0;
Eric Anholt71066ab2011-12-20 13:06:16 -08003903 uint32_t devid;
Eric Anholt028715e2012-01-04 12:31:40 -08003904 int size = ctx->base_count * 4;
3905 void *temp;
Eric Anholt71066ab2011-12-20 13:06:16 -08003906
3907 if (!ctx)
3908 return;
3909
Eric Anholt028715e2012-01-04 12:31:40 -08003910 /* Put a scratch page full of obviously undefined data after
3911 * the batchbuffer. This lets us avoid a bunch of length
3912 * checking in statically sized packets.
3913 */
3914 temp = malloc(size + 4096);
3915 memcpy(temp, ctx->base_data, size);
3916 memset((char *)temp + size, 0xd0, 4096);
3917 ctx->data = temp;
3918
Eric Anholt8fb66a72011-12-20 14:59:38 -08003919 ctx->hw_offset = ctx->base_hw_offset;
3920 ctx->count = ctx->base_count;
3921
Eric Anholt71066ab2011-12-20 13:06:16 -08003922 devid = ctx->devid;
3923 head_offset = ctx->head;
3924 tail_offset = ctx->tail;
Eric Anholtea33a232012-01-03 13:05:57 -08003925 out = ctx->out;
Eric Anholt71066ab2011-12-20 13:06:16 -08003926
3927 saved_s2_set = 0;
3928 saved_s4_set = 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003929
Eric Anholt8fb66a72011-12-20 14:59:38 -08003930 while (ctx->count > 0) {
3931 index = 0;
3932
3933 switch ((ctx->data[index] & 0xe0000000) >> 29) {
Eric Anholt193fa132011-12-20 11:36:07 -08003934 case 0x0:
Eric Anholtde49fd42011-12-20 15:15:21 -08003935 ret = decode_mi(ctx);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003936
Eric Anholtbbdda922011-12-20 11:44:36 -08003937 /* If MI_BATCHBUFFER_END happened, then dump
3938 * the rest of the output in case we some day
3939 * want it in debugging, but don't decode it
3940 * since it'll just confuse in the common
3941 * case.
Eric Anholt193fa132011-12-20 11:36:07 -08003942 */
3943 if (ret == -1) {
Eric Anholt71066ab2011-12-20 13:06:16 -08003944 if (ctx->dump_past_end) {
Eric Anholt193fa132011-12-20 11:36:07 -08003945 index++;
3946 } else {
Eric Anholt8fb66a72011-12-20 14:59:38 -08003947 for (index = index + 1; index < ctx->count;
Eric Anholt193fa132011-12-20 11:36:07 -08003948 index++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003949 instr_out(ctx, index, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003950 }
3951 }
3952 } else
3953 index += ret;
3954 break;
3955 case 0x2:
Eric Anholtde49fd42011-12-20 15:15:21 -08003956 index += decode_2d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003957 break;
3958 case 0x3:
Eric Anholt71066ab2011-12-20 13:06:16 -08003959 if (IS_9XX(devid) && !IS_GEN3(devid)) {
Eric Anholt193fa132011-12-20 11:36:07 -08003960 index +=
Eric Anholtde49fd42011-12-20 15:15:21 -08003961 decode_3d_965(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003962 } else if (IS_GEN3(devid)) {
Eric Anholtde49fd42011-12-20 15:15:21 -08003963 index += decode_3d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003964 } else {
3965 index +=
Eric Anholtde49fd42011-12-20 15:15:21 -08003966 decode_3d_i830(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003967 }
3968 break;
3969 default:
Eric Anholtc1d29462011-12-20 15:29:03 -08003970 instr_out(ctx, index, "UNKNOWN\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003971 index++;
3972 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003973 }
Eric Anholt193fa132011-12-20 11:36:07 -08003974 fflush(out);
Eric Anholt8fb66a72011-12-20 14:59:38 -08003975
3976 if (ctx->count < index)
3977 break;
3978
3979 ctx->count -= index;
3980 ctx->data += index;
3981 ctx->hw_offset += 4 * index;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003982 }
Eric Anholt028715e2012-01-04 12:31:40 -08003983
3984 free(temp);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003985}