1d722e3fbSopenharmony_ci/*
2d722e3fbSopenharmony_ci * Copyright © 2009-2011 Intel Corporation
3d722e3fbSopenharmony_ci *
4d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation
7d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10d722e3fbSopenharmony_ci *
11d722e3fbSopenharmony_ci * The above copyright notice and this permission notice (including the next
12d722e3fbSopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13d722e3fbSopenharmony_ci * Software.
14d722e3fbSopenharmony_ci *
15d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18d722e3fbSopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20d722e3fbSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21d722e3fbSopenharmony_ci * IN THE SOFTWARE.
22d722e3fbSopenharmony_ci */
23d722e3fbSopenharmony_ci
24d722e3fbSopenharmony_ci#include <assert.h>
25d722e3fbSopenharmony_ci#include <stdint.h>
26d722e3fbSopenharmony_ci#include <stdlib.h>
27d722e3fbSopenharmony_ci#include <stdio.h>
28d722e3fbSopenharmony_ci#include <stdbool.h>
29d722e3fbSopenharmony_ci#include <stdarg.h>
30d722e3fbSopenharmony_ci#include <string.h>
31d722e3fbSopenharmony_ci
32d722e3fbSopenharmony_ci#include "libdrm_macros.h"
33d722e3fbSopenharmony_ci#include "xf86drm.h"
34d722e3fbSopenharmony_ci#include "intel_chipset.h"
35d722e3fbSopenharmony_ci#include "intel_bufmgr.h"
36d722e3fbSopenharmony_ci
37d722e3fbSopenharmony_ci
38d722e3fbSopenharmony_ci/* Struct for tracking drm_intel_decode state. */
39d722e3fbSopenharmony_cistruct drm_intel_decode {
40d722e3fbSopenharmony_ci	/** stdio file where the output should land.  Defaults to stdout. */
41d722e3fbSopenharmony_ci	FILE *out;
42d722e3fbSopenharmony_ci
43d722e3fbSopenharmony_ci	/** PCI device ID. */
44d722e3fbSopenharmony_ci	uint32_t devid;
45d722e3fbSopenharmony_ci
46d722e3fbSopenharmony_ci	/**
47d722e3fbSopenharmony_ci	 * Shorthand device identifier: 3 is 915, 4 is 965, 5 is
48d722e3fbSopenharmony_ci	 * Ironlake, etc.
49d722e3fbSopenharmony_ci	 */
50d722e3fbSopenharmony_ci	int gen;
51d722e3fbSopenharmony_ci
52d722e3fbSopenharmony_ci	/** GPU address of the start of the current packet. */
53d722e3fbSopenharmony_ci	uint32_t hw_offset;
54d722e3fbSopenharmony_ci	/** CPU virtual address of the start of the current packet. */
55d722e3fbSopenharmony_ci	uint32_t *data;
56d722e3fbSopenharmony_ci	/** DWORDs of remaining batchbuffer data starting from the packet. */
57d722e3fbSopenharmony_ci	uint32_t count;
58d722e3fbSopenharmony_ci
59d722e3fbSopenharmony_ci	/** GPU address of the start of the batchbuffer data. */
60d722e3fbSopenharmony_ci	uint32_t base_hw_offset;
61d722e3fbSopenharmony_ci	/** CPU Virtual address of the start of the batchbuffer data. */
62d722e3fbSopenharmony_ci	uint32_t *base_data;
63d722e3fbSopenharmony_ci	/** Number of DWORDs of batchbuffer data. */
64d722e3fbSopenharmony_ci	uint32_t base_count;
65d722e3fbSopenharmony_ci
66d722e3fbSopenharmony_ci	/** @{
67d722e3fbSopenharmony_ci	 * GPU head and tail pointers, which will be noted in the dump, or ~0.
68d722e3fbSopenharmony_ci	 */
69d722e3fbSopenharmony_ci	uint32_t head, tail;
70d722e3fbSopenharmony_ci	/** @} */
71d722e3fbSopenharmony_ci
72d722e3fbSopenharmony_ci	/**
73d722e3fbSopenharmony_ci	 * Whether to dump the dwords after MI_BATCHBUFFER_END.
74d722e3fbSopenharmony_ci	 *
75d722e3fbSopenharmony_ci	 * This sometimes provides clues in corrupted batchbuffers,
76d722e3fbSopenharmony_ci	 * and is used by the intel-gpu-tools.
77d722e3fbSopenharmony_ci	 */
78d722e3fbSopenharmony_ci	bool dump_past_end;
79d722e3fbSopenharmony_ci
80d722e3fbSopenharmony_ci	bool overflowed;
81d722e3fbSopenharmony_ci};
82d722e3fbSopenharmony_ci
83d722e3fbSopenharmony_cistatic FILE *out;
84d722e3fbSopenharmony_cistatic uint32_t saved_s2 = 0, saved_s4 = 0;
85d722e3fbSopenharmony_cistatic char saved_s2_set = 0, saved_s4_set = 0;
86d722e3fbSopenharmony_cistatic uint32_t head_offset = 0xffffffff;	/* undefined */
87d722e3fbSopenharmony_cistatic uint32_t tail_offset = 0xffffffff;	/* undefined */
88d722e3fbSopenharmony_ci
89d722e3fbSopenharmony_ci#ifndef ARRAY_SIZE
90d722e3fbSopenharmony_ci#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
91d722e3fbSopenharmony_ci#endif
92d722e3fbSopenharmony_ci
93d722e3fbSopenharmony_ci#define BUFFER_FAIL(_count, _len, _name) do {			\
94d722e3fbSopenharmony_ci    fprintf(out, "Buffer size too small in %s (%d < %d)\n",	\
95d722e3fbSopenharmony_ci	    (_name), (_count), (_len));				\
96d722e3fbSopenharmony_ci    return _count;						\
97d722e3fbSopenharmony_ci} while (0)
98d722e3fbSopenharmony_ci
99d722e3fbSopenharmony_cistatic float int_as_float(uint32_t intval)
100d722e3fbSopenharmony_ci{
101d722e3fbSopenharmony_ci	union intfloat {
102d722e3fbSopenharmony_ci		uint32_t i;
103d722e3fbSopenharmony_ci		float f;
104d722e3fbSopenharmony_ci	} uval;
105d722e3fbSopenharmony_ci
106d722e3fbSopenharmony_ci	uval.i = intval;
107d722e3fbSopenharmony_ci	return uval.f;
108d722e3fbSopenharmony_ci}
109d722e3fbSopenharmony_ci
110d722e3fbSopenharmony_cistatic void DRM_PRINTFLIKE(3, 4)
111d722e3fbSopenharmony_ciinstr_out(struct drm_intel_decode *ctx, unsigned int index,
112d722e3fbSopenharmony_ci	  const char *fmt, ...)
113d722e3fbSopenharmony_ci{
114d722e3fbSopenharmony_ci	va_list va;
115d722e3fbSopenharmony_ci	const char *parseinfo;
116d722e3fbSopenharmony_ci	uint32_t offset = ctx->hw_offset + index * 4;
117d722e3fbSopenharmony_ci
118d722e3fbSopenharmony_ci	if (index > ctx->count) {
119d722e3fbSopenharmony_ci		if (!ctx->overflowed) {
120d722e3fbSopenharmony_ci			fprintf(out, "ERROR: Decode attempted to continue beyond end of batchbuffer\n");
121d722e3fbSopenharmony_ci			ctx->overflowed = true;
122d722e3fbSopenharmony_ci		}
123d722e3fbSopenharmony_ci		return;
124d722e3fbSopenharmony_ci	}
125d722e3fbSopenharmony_ci
126d722e3fbSopenharmony_ci	if (offset == head_offset)
127d722e3fbSopenharmony_ci		parseinfo = "HEAD";
128d722e3fbSopenharmony_ci	else if (offset == tail_offset)
129d722e3fbSopenharmony_ci		parseinfo = "TAIL";
130d722e3fbSopenharmony_ci	else
131d722e3fbSopenharmony_ci		parseinfo = "    ";
132d722e3fbSopenharmony_ci
133d722e3fbSopenharmony_ci	fprintf(out, "0x%08x: %s 0x%08x: %s", offset, parseinfo,
134d722e3fbSopenharmony_ci		ctx->data[index], index == 0 ? "" : "   ");
135d722e3fbSopenharmony_ci	va_start(va, fmt);
136d722e3fbSopenharmony_ci	vfprintf(out, fmt, va);
137d722e3fbSopenharmony_ci	va_end(va);
138d722e3fbSopenharmony_ci}
139d722e3fbSopenharmony_ci
140d722e3fbSopenharmony_cistatic int
141d722e3fbSopenharmony_cidecode_MI_SET_CONTEXT(struct drm_intel_decode *ctx)
142d722e3fbSopenharmony_ci{
143d722e3fbSopenharmony_ci	uint32_t data = ctx->data[1];
144d722e3fbSopenharmony_ci	if (ctx->gen > 7)
145d722e3fbSopenharmony_ci		return 1;
146d722e3fbSopenharmony_ci
147d722e3fbSopenharmony_ci	instr_out(ctx, 0, "MI_SET_CONTEXT\n");
148d722e3fbSopenharmony_ci	instr_out(ctx, 1, "gtt offset = 0x%x%s%s\n",
149d722e3fbSopenharmony_ci		  data & ~0xfff,
150d722e3fbSopenharmony_ci		  data & (1<<1)? ", Force Restore": "",
151d722e3fbSopenharmony_ci		  data & (1<<0)? ", Restore Inhibit": "");
152d722e3fbSopenharmony_ci
153d722e3fbSopenharmony_ci	return 2;
154d722e3fbSopenharmony_ci}
155d722e3fbSopenharmony_ci
156d722e3fbSopenharmony_cistatic int
157d722e3fbSopenharmony_cidecode_MI_WAIT_FOR_EVENT(struct drm_intel_decode *ctx)
158d722e3fbSopenharmony_ci{
159d722e3fbSopenharmony_ci	const char *cc_wait;
160d722e3fbSopenharmony_ci	int cc_shift = 0;
161d722e3fbSopenharmony_ci	uint32_t data = ctx->data[0];
162d722e3fbSopenharmony_ci
163d722e3fbSopenharmony_ci	if (ctx->gen <= 5)
164d722e3fbSopenharmony_ci		cc_shift = 9;
165d722e3fbSopenharmony_ci	else
166d722e3fbSopenharmony_ci		cc_shift = 16;
167d722e3fbSopenharmony_ci
168d722e3fbSopenharmony_ci	switch ((data >> cc_shift) & 0x1f) {
169d722e3fbSopenharmony_ci	case 1:
170d722e3fbSopenharmony_ci		cc_wait = ", cc wait 1";
171d722e3fbSopenharmony_ci		break;
172d722e3fbSopenharmony_ci	case 2:
173d722e3fbSopenharmony_ci		cc_wait = ", cc wait 2";
174d722e3fbSopenharmony_ci		break;
175d722e3fbSopenharmony_ci	case 3:
176d722e3fbSopenharmony_ci		cc_wait = ", cc wait 3";
177d722e3fbSopenharmony_ci		break;
178d722e3fbSopenharmony_ci	case 4:
179d722e3fbSopenharmony_ci		cc_wait = ", cc wait 4";
180d722e3fbSopenharmony_ci		break;
181d722e3fbSopenharmony_ci	case 5:
182d722e3fbSopenharmony_ci		cc_wait = ", cc wait 4";
183d722e3fbSopenharmony_ci		break;
184d722e3fbSopenharmony_ci	default:
185d722e3fbSopenharmony_ci		cc_wait = "";
186d722e3fbSopenharmony_ci		break;
187d722e3fbSopenharmony_ci	}
188d722e3fbSopenharmony_ci
189d722e3fbSopenharmony_ci	if (ctx->gen <= 5) {
190d722e3fbSopenharmony_ci		instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
191d722e3fbSopenharmony_ci			  data & (1<<18)? ", pipe B start vblank wait": "",
192d722e3fbSopenharmony_ci			  data & (1<<17)? ", pipe A start vblank wait": "",
193d722e3fbSopenharmony_ci			  data & (1<<16)? ", overlay flip pending wait": "",
194d722e3fbSopenharmony_ci			  data & (1<<14)? ", pipe B hblank wait": "",
195d722e3fbSopenharmony_ci			  data & (1<<13)? ", pipe A hblank wait": "",
196d722e3fbSopenharmony_ci			  cc_wait,
197d722e3fbSopenharmony_ci			  data & (1<<8)? ", plane C pending flip wait": "",
198d722e3fbSopenharmony_ci			  data & (1<<7)? ", pipe B vblank wait": "",
199d722e3fbSopenharmony_ci			  data & (1<<6)? ", plane B pending flip wait": "",
200d722e3fbSopenharmony_ci			  data & (1<<5)? ", pipe B scan line wait": "",
201d722e3fbSopenharmony_ci			  data & (1<<4)? ", fbc idle wait": "",
202d722e3fbSopenharmony_ci			  data & (1<<3)? ", pipe A vblank wait": "",
203d722e3fbSopenharmony_ci			  data & (1<<2)? ", plane A pending flip wait": "",
204d722e3fbSopenharmony_ci			  data & (1<<1)? ", plane A scan line wait": "");
205d722e3fbSopenharmony_ci	} else {
206d722e3fbSopenharmony_ci		instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s\n",
207d722e3fbSopenharmony_ci			  data & (1<<20)? ", sprite C pending flip wait": "", /* ivb */
208d722e3fbSopenharmony_ci			  cc_wait,
209d722e3fbSopenharmony_ci			  data & (1<<13)? ", pipe B hblank wait": "",
210d722e3fbSopenharmony_ci			  data & (1<<11)? ", pipe B vblank wait": "",
211d722e3fbSopenharmony_ci			  data & (1<<10)? ", sprite B pending flip wait": "",
212d722e3fbSopenharmony_ci			  data & (1<<9)? ", plane B pending flip wait": "",
213d722e3fbSopenharmony_ci			  data & (1<<8)? ", plane B scan line wait": "",
214d722e3fbSopenharmony_ci			  data & (1<<5)? ", pipe A hblank wait": "",
215d722e3fbSopenharmony_ci			  data & (1<<3)? ", pipe A vblank wait": "",
216d722e3fbSopenharmony_ci			  data & (1<<2)? ", sprite A pending flip wait": "",
217d722e3fbSopenharmony_ci			  data & (1<<1)? ", plane A pending flip wait": "",
218d722e3fbSopenharmony_ci			  data & (1<<0)? ", plane A scan line wait": "");
219d722e3fbSopenharmony_ci	}
220d722e3fbSopenharmony_ci
221d722e3fbSopenharmony_ci	return 1;
222d722e3fbSopenharmony_ci}
223d722e3fbSopenharmony_ci
224d722e3fbSopenharmony_cistatic int
225d722e3fbSopenharmony_cidecode_mi(struct drm_intel_decode *ctx)
226d722e3fbSopenharmony_ci{
227d722e3fbSopenharmony_ci	unsigned int opcode, len = -1;
228d722e3fbSopenharmony_ci	const char *post_sync_op = "";
229d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
230d722e3fbSopenharmony_ci
231d722e3fbSopenharmony_ci	struct {
232d722e3fbSopenharmony_ci		uint32_t opcode;
233d722e3fbSopenharmony_ci		int len_mask;
234d722e3fbSopenharmony_ci		unsigned int min_len;
235d722e3fbSopenharmony_ci		unsigned int max_len;
236d722e3fbSopenharmony_ci		const char *name;
237d722e3fbSopenharmony_ci		int (*func)(struct drm_intel_decode *ctx);
238d722e3fbSopenharmony_ci	} opcodes_mi[] = {
239d722e3fbSopenharmony_ci		{ 0x08, 0, 1, 1, "MI_ARB_ON_OFF" },
240d722e3fbSopenharmony_ci		{ 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" },
241d722e3fbSopenharmony_ci		{ 0x30, 0x3f, 3, 3, "MI_BATCH_BUFFER" },
242d722e3fbSopenharmony_ci		{ 0x31, 0x3f, 2, 2, "MI_BATCH_BUFFER_START" },
243d722e3fbSopenharmony_ci		{ 0x14, 0x3f, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
244d722e3fbSopenharmony_ci		{ 0x04, 0, 1, 1, "MI_FLUSH" },
245d722e3fbSopenharmony_ci		{ 0x22, 0x1f, 3, 3, "MI_LOAD_REGISTER_IMM" },
246d722e3fbSopenharmony_ci		{ 0x13, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
247d722e3fbSopenharmony_ci		{ 0x12, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
248d722e3fbSopenharmony_ci		{ 0x00, 0, 1, 1, "MI_NOOP" },
249d722e3fbSopenharmony_ci		{ 0x11, 0x3f, 2, 2, "MI_OVERLAY_FLIP" },
250d722e3fbSopenharmony_ci		{ 0x07, 0, 1, 1, "MI_REPORT_HEAD" },
251d722e3fbSopenharmony_ci		{ 0x18, 0x3f, 2, 2, "MI_SET_CONTEXT", decode_MI_SET_CONTEXT },
252d722e3fbSopenharmony_ci		{ 0x20, 0x3f, 3, 4, "MI_STORE_DATA_IMM" },
253d722e3fbSopenharmony_ci		{ 0x21, 0x3f, 3, 4, "MI_STORE_DATA_INDEX" },
254d722e3fbSopenharmony_ci		{ 0x24, 0x3f, 3, 3, "MI_STORE_REGISTER_MEM" },
255d722e3fbSopenharmony_ci		{ 0x02, 0, 1, 1, "MI_USER_INTERRUPT" },
256d722e3fbSopenharmony_ci		{ 0x03, 0, 1, 1, "MI_WAIT_FOR_EVENT", decode_MI_WAIT_FOR_EVENT },
257d722e3fbSopenharmony_ci		{ 0x16, 0x7f, 3, 3, "MI_SEMAPHORE_MBOX" },
258d722e3fbSopenharmony_ci		{ 0x26, 0x1f, 3, 4, "MI_FLUSH_DW" },
259d722e3fbSopenharmony_ci		{ 0x28, 0x3f, 3, 3, "MI_REPORT_PERF_COUNT" },
260d722e3fbSopenharmony_ci		{ 0x29, 0xff, 3, 3, "MI_LOAD_REGISTER_MEM" },
261d722e3fbSopenharmony_ci		{ 0x0b, 0, 1, 1, "MI_SUSPEND_FLUSH"},
262d722e3fbSopenharmony_ci	}, *opcode_mi = NULL;
263d722e3fbSopenharmony_ci
264d722e3fbSopenharmony_ci	/* check instruction length */
265d722e3fbSopenharmony_ci	for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
266d722e3fbSopenharmony_ci	     opcode++) {
267d722e3fbSopenharmony_ci		if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
268d722e3fbSopenharmony_ci			len = 1;
269d722e3fbSopenharmony_ci			if (opcodes_mi[opcode].max_len > 1) {
270d722e3fbSopenharmony_ci				len =
271d722e3fbSopenharmony_ci				    (data[0] & opcodes_mi[opcode].len_mask) + 2;
272d722e3fbSopenharmony_ci				if (len < opcodes_mi[opcode].min_len
273d722e3fbSopenharmony_ci				    || len > opcodes_mi[opcode].max_len) {
274d722e3fbSopenharmony_ci					fprintf(out,
275d722e3fbSopenharmony_ci						"Bad length (%d) in %s, [%d, %d]\n",
276d722e3fbSopenharmony_ci						len, opcodes_mi[opcode].name,
277d722e3fbSopenharmony_ci						opcodes_mi[opcode].min_len,
278d722e3fbSopenharmony_ci						opcodes_mi[opcode].max_len);
279d722e3fbSopenharmony_ci				}
280d722e3fbSopenharmony_ci			}
281d722e3fbSopenharmony_ci			opcode_mi = &opcodes_mi[opcode];
282d722e3fbSopenharmony_ci			break;
283d722e3fbSopenharmony_ci		}
284d722e3fbSopenharmony_ci	}
285d722e3fbSopenharmony_ci
286d722e3fbSopenharmony_ci	if (opcode_mi && opcode_mi->func)
287d722e3fbSopenharmony_ci		return opcode_mi->func(ctx);
288d722e3fbSopenharmony_ci
289d722e3fbSopenharmony_ci	switch ((data[0] & 0x1f800000) >> 23) {
290d722e3fbSopenharmony_ci	case 0x0a:
291d722e3fbSopenharmony_ci		instr_out(ctx, 0, "MI_BATCH_BUFFER_END\n");
292d722e3fbSopenharmony_ci		return -1;
293d722e3fbSopenharmony_ci	case 0x16:
294d722e3fbSopenharmony_ci		instr_out(ctx, 0, "MI_SEMAPHORE_MBOX%s%s%s%s %u\n",
295d722e3fbSopenharmony_ci			  data[0] & (1 << 22) ? " global gtt," : "",
296d722e3fbSopenharmony_ci			  data[0] & (1 << 21) ? " update semaphore," : "",
297d722e3fbSopenharmony_ci			  data[0] & (1 << 20) ? " compare semaphore," : "",
298d722e3fbSopenharmony_ci			  data[0] & (1 << 18) ? " use compare reg" : "",
299d722e3fbSopenharmony_ci			  (data[0] & (0x3 << 16)) >> 16);
300d722e3fbSopenharmony_ci		instr_out(ctx, 1, "value\n");
301d722e3fbSopenharmony_ci		instr_out(ctx, 2, "address\n");
302d722e3fbSopenharmony_ci		return len;
303d722e3fbSopenharmony_ci	case 0x21:
304d722e3fbSopenharmony_ci		instr_out(ctx, 0, "MI_STORE_DATA_INDEX%s\n",
305d722e3fbSopenharmony_ci			  data[0] & (1 << 21) ? " use per-process HWS," : "");
306d722e3fbSopenharmony_ci		instr_out(ctx, 1, "index\n");
307d722e3fbSopenharmony_ci		instr_out(ctx, 2, "dword\n");
308d722e3fbSopenharmony_ci		if (len == 4)
309d722e3fbSopenharmony_ci			instr_out(ctx, 3, "upper dword\n");
310d722e3fbSopenharmony_ci		return len;
311d722e3fbSopenharmony_ci	case 0x00:
312d722e3fbSopenharmony_ci		if (data[0] & (1 << 22))
313d722e3fbSopenharmony_ci			instr_out(ctx, 0,
314d722e3fbSopenharmony_ci				  "MI_NOOP write NOPID reg, val=0x%x\n",
315d722e3fbSopenharmony_ci				  data[0] & ((1 << 22) - 1));
316d722e3fbSopenharmony_ci		else
317d722e3fbSopenharmony_ci			instr_out(ctx, 0, "MI_NOOP\n");
318d722e3fbSopenharmony_ci		return len;
319d722e3fbSopenharmony_ci	case 0x26:
320d722e3fbSopenharmony_ci		switch (data[0] & (0x3 << 14)) {
321d722e3fbSopenharmony_ci		case (0 << 14):
322d722e3fbSopenharmony_ci			post_sync_op = "no write";
323d722e3fbSopenharmony_ci			break;
324d722e3fbSopenharmony_ci		case (1 << 14):
325d722e3fbSopenharmony_ci			post_sync_op = "write data";
326d722e3fbSopenharmony_ci			break;
327d722e3fbSopenharmony_ci		case (2 << 14):
328d722e3fbSopenharmony_ci			post_sync_op = "reserved";
329d722e3fbSopenharmony_ci			break;
330d722e3fbSopenharmony_ci		case (3 << 14):
331d722e3fbSopenharmony_ci			post_sync_op = "write TIMESTAMP";
332d722e3fbSopenharmony_ci			break;
333d722e3fbSopenharmony_ci		}
334d722e3fbSopenharmony_ci		instr_out(ctx, 0,
335d722e3fbSopenharmony_ci			  "MI_FLUSH_DW%s%s%s%s post_sync_op='%s' %s%s\n",
336d722e3fbSopenharmony_ci			  data[0] & (1 << 22) ?
337d722e3fbSopenharmony_ci			  " enable protected mem (BCS-only)," : "",
338d722e3fbSopenharmony_ci			  data[0] & (1 << 21) ? " store in hws," : "",
339d722e3fbSopenharmony_ci			  data[0] & (1 << 18) ? " invalidate tlb," : "",
340d722e3fbSopenharmony_ci			  data[0] & (1 << 17) ? " flush gfdt," : "",
341d722e3fbSopenharmony_ci			  post_sync_op,
342d722e3fbSopenharmony_ci			  data[0] & (1 << 8) ? " enable notify interrupt," : "",
343d722e3fbSopenharmony_ci			  data[0] & (1 << 7) ?
344d722e3fbSopenharmony_ci			  " invalidate video state (BCS-only)," : "");
345d722e3fbSopenharmony_ci		if (data[0] & (1 << 21))
346d722e3fbSopenharmony_ci			instr_out(ctx, 1, "hws index\n");
347d722e3fbSopenharmony_ci		else
348d722e3fbSopenharmony_ci			instr_out(ctx, 1, "address\n");
349d722e3fbSopenharmony_ci		instr_out(ctx, 2, "dword\n");
350d722e3fbSopenharmony_ci		if (len == 4)
351d722e3fbSopenharmony_ci			instr_out(ctx, 3, "upper dword\n");
352d722e3fbSopenharmony_ci		return len;
353d722e3fbSopenharmony_ci	}
354d722e3fbSopenharmony_ci
355d722e3fbSopenharmony_ci	for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
356d722e3fbSopenharmony_ci	     opcode++) {
357d722e3fbSopenharmony_ci		if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
358d722e3fbSopenharmony_ci			unsigned int i;
359d722e3fbSopenharmony_ci
360d722e3fbSopenharmony_ci			instr_out(ctx, 0, "%s\n",
361d722e3fbSopenharmony_ci				  opcodes_mi[opcode].name);
362d722e3fbSopenharmony_ci			for (i = 1; i < len; i++) {
363d722e3fbSopenharmony_ci				instr_out(ctx, i, "dword %d\n", i);
364d722e3fbSopenharmony_ci			}
365d722e3fbSopenharmony_ci
366d722e3fbSopenharmony_ci			return len;
367d722e3fbSopenharmony_ci		}
368d722e3fbSopenharmony_ci	}
369d722e3fbSopenharmony_ci
370d722e3fbSopenharmony_ci	instr_out(ctx, 0, "MI UNKNOWN\n");
371d722e3fbSopenharmony_ci	return 1;
372d722e3fbSopenharmony_ci}
373d722e3fbSopenharmony_ci
374d722e3fbSopenharmony_cistatic void
375d722e3fbSopenharmony_cidecode_2d_br00(struct drm_intel_decode *ctx, const char *cmd)
376d722e3fbSopenharmony_ci{
377d722e3fbSopenharmony_ci	instr_out(ctx, 0,
378d722e3fbSopenharmony_ci		  "%s (rgb %sabled, alpha %sabled, src tile %d, dst tile %d)\n",
379d722e3fbSopenharmony_ci		  cmd,
380d722e3fbSopenharmony_ci		  (ctx->data[0] & (1 << 20)) ? "en" : "dis",
381d722e3fbSopenharmony_ci		  (ctx->data[0] & (1 << 21)) ? "en" : "dis",
382d722e3fbSopenharmony_ci		  (ctx->data[0] >> 15) & 1,
383d722e3fbSopenharmony_ci		  (ctx->data[0] >> 11) & 1);
384d722e3fbSopenharmony_ci}
385d722e3fbSopenharmony_ci
386d722e3fbSopenharmony_cistatic void
387d722e3fbSopenharmony_cidecode_2d_br01(struct drm_intel_decode *ctx)
388d722e3fbSopenharmony_ci{
389d722e3fbSopenharmony_ci	const char *format;
390d722e3fbSopenharmony_ci	switch ((ctx->data[1] >> 24) & 0x3) {
391d722e3fbSopenharmony_ci	case 0:
392d722e3fbSopenharmony_ci		format = "8";
393d722e3fbSopenharmony_ci		break;
394d722e3fbSopenharmony_ci	case 1:
395d722e3fbSopenharmony_ci		format = "565";
396d722e3fbSopenharmony_ci		break;
397d722e3fbSopenharmony_ci	case 2:
398d722e3fbSopenharmony_ci		format = "1555";
399d722e3fbSopenharmony_ci		break;
400d722e3fbSopenharmony_ci	case 3:
401d722e3fbSopenharmony_ci		format = "8888";
402d722e3fbSopenharmony_ci		break;
403d722e3fbSopenharmony_ci	}
404d722e3fbSopenharmony_ci
405d722e3fbSopenharmony_ci	instr_out(ctx, 1,
406d722e3fbSopenharmony_ci		  "format %s, pitch %d, rop 0x%02x, "
407d722e3fbSopenharmony_ci		  "clipping %sabled, %s%s \n",
408d722e3fbSopenharmony_ci		  format,
409d722e3fbSopenharmony_ci		  (short)(ctx->data[1] & 0xffff),
410d722e3fbSopenharmony_ci		  (ctx->data[1] >> 16) & 0xff,
411d722e3fbSopenharmony_ci		  ctx->data[1] & (1 << 30) ? "en" : "dis",
412d722e3fbSopenharmony_ci		  ctx->data[1] & (1 << 31) ? "solid pattern enabled, " : "",
413d722e3fbSopenharmony_ci		  ctx->data[1] & (1 << 31) ?
414d722e3fbSopenharmony_ci		  "mono pattern transparency enabled, " : "");
415d722e3fbSopenharmony_ci
416d722e3fbSopenharmony_ci}
417d722e3fbSopenharmony_ci
418d722e3fbSopenharmony_cistatic int
419d722e3fbSopenharmony_cidecode_2d(struct drm_intel_decode *ctx)
420d722e3fbSopenharmony_ci{
421d722e3fbSopenharmony_ci	unsigned int opcode, len;
422d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
423d722e3fbSopenharmony_ci
424d722e3fbSopenharmony_ci	struct {
425d722e3fbSopenharmony_ci		uint32_t opcode;
426d722e3fbSopenharmony_ci		unsigned int min_len;
427d722e3fbSopenharmony_ci		unsigned int max_len;
428d722e3fbSopenharmony_ci		const char *name;
429d722e3fbSopenharmony_ci	} opcodes_2d[] = {
430d722e3fbSopenharmony_ci		{ 0x40, 5, 5, "COLOR_BLT" },
431d722e3fbSopenharmony_ci		{ 0x43, 6, 6, "SRC_COPY_BLT" },
432d722e3fbSopenharmony_ci		{ 0x01, 8, 8, "XY_SETUP_BLT" },
433d722e3fbSopenharmony_ci		{ 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
434d722e3fbSopenharmony_ci		{ 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
435d722e3fbSopenharmony_ci		{ 0x24, 2, 2, "XY_PIXEL_BLT" },
436d722e3fbSopenharmony_ci		{ 0x25, 3, 3, "XY_SCANLINES_BLT" },
437d722e3fbSopenharmony_ci		{ 0x26, 4, 4, "Y_TEXT_BLT" },
438d722e3fbSopenharmony_ci		{ 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
439d722e3fbSopenharmony_ci		{ 0x50, 6, 6, "XY_COLOR_BLT" },
440d722e3fbSopenharmony_ci		{ 0x51, 6, 6, "XY_PAT_BLT" },
441d722e3fbSopenharmony_ci		{ 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
442d722e3fbSopenharmony_ci		{ 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
443d722e3fbSopenharmony_ci		{ 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
444d722e3fbSopenharmony_ci		{ 0x52, 9, 9, "XY_MONO_PAT_BLT" },
445d722e3fbSopenharmony_ci		{ 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
446d722e3fbSopenharmony_ci		{ 0x53, 8, 8, "XY_SRC_COPY_BLT" },
447d722e3fbSopenharmony_ci		{ 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
448d722e3fbSopenharmony_ci		{ 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
449d722e3fbSopenharmony_ci		{ 0x55, 9, 9, "XY_FULL_BLT" },
450d722e3fbSopenharmony_ci		{ 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
451d722e3fbSopenharmony_ci		{ 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
452d722e3fbSopenharmony_ci		{ 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
453d722e3fbSopenharmony_ci		{ 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
454d722e3fbSopenharmony_ci		{ 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT"},
455d722e3fbSopenharmony_ci	};
456d722e3fbSopenharmony_ci
457d722e3fbSopenharmony_ci	switch ((data[0] & 0x1fc00000) >> 22) {
458d722e3fbSopenharmony_ci	case 0x25:
459d722e3fbSopenharmony_ci		instr_out(ctx, 0,
460d722e3fbSopenharmony_ci			  "XY_SCANLINES_BLT (pattern seed (%d, %d), dst tile %d)\n",
461d722e3fbSopenharmony_ci			  (data[0] >> 12) & 0x8,
462d722e3fbSopenharmony_ci			  (data[0] >> 8) & 0x8, (data[0] >> 11) & 1);
463d722e3fbSopenharmony_ci
464d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
465d722e3fbSopenharmony_ci		if (len != 3)
466d722e3fbSopenharmony_ci			fprintf(out, "Bad count in XY_SCANLINES_BLT\n");
467d722e3fbSopenharmony_ci
468d722e3fbSopenharmony_ci		instr_out(ctx, 1, "dest (%d,%d)\n",
469d722e3fbSopenharmony_ci			  data[1] & 0xffff, data[1] >> 16);
470d722e3fbSopenharmony_ci		instr_out(ctx, 2, "dest (%d,%d)\n",
471d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[2] >> 16);
472d722e3fbSopenharmony_ci		return len;
473d722e3fbSopenharmony_ci	case 0x01:
474d722e3fbSopenharmony_ci		decode_2d_br00(ctx, "XY_SETUP_BLT");
475d722e3fbSopenharmony_ci
476d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
477d722e3fbSopenharmony_ci		if (len != 8)
478d722e3fbSopenharmony_ci			fprintf(out, "Bad count in XY_SETUP_BLT\n");
479d722e3fbSopenharmony_ci
480d722e3fbSopenharmony_ci		decode_2d_br01(ctx);
481d722e3fbSopenharmony_ci		instr_out(ctx, 2, "cliprect (%d,%d)\n",
482d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[2] >> 16);
483d722e3fbSopenharmony_ci		instr_out(ctx, 3, "cliprect (%d,%d)\n",
484d722e3fbSopenharmony_ci			  data[3] & 0xffff, data[3] >> 16);
485d722e3fbSopenharmony_ci		instr_out(ctx, 4, "setup dst offset 0x%08x\n",
486d722e3fbSopenharmony_ci			  data[4]);
487d722e3fbSopenharmony_ci		instr_out(ctx, 5, "setup background color\n");
488d722e3fbSopenharmony_ci		instr_out(ctx, 6, "setup foreground color\n");
489d722e3fbSopenharmony_ci		instr_out(ctx, 7, "color pattern offset\n");
490d722e3fbSopenharmony_ci		return len;
491d722e3fbSopenharmony_ci	case 0x03:
492d722e3fbSopenharmony_ci		decode_2d_br00(ctx, "XY_SETUP_CLIP_BLT");
493d722e3fbSopenharmony_ci
494d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
495d722e3fbSopenharmony_ci		if (len != 3)
496d722e3fbSopenharmony_ci			fprintf(out, "Bad count in XY_SETUP_CLIP_BLT\n");
497d722e3fbSopenharmony_ci
498d722e3fbSopenharmony_ci		instr_out(ctx, 1, "cliprect (%d,%d)\n",
499d722e3fbSopenharmony_ci			  data[1] & 0xffff, data[2] >> 16);
500d722e3fbSopenharmony_ci		instr_out(ctx, 2, "cliprect (%d,%d)\n",
501d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[3] >> 16);
502d722e3fbSopenharmony_ci		return len;
503d722e3fbSopenharmony_ci	case 0x11:
504d722e3fbSopenharmony_ci		decode_2d_br00(ctx, "XY_SETUP_MONO_PATTERN_SL_BLT");
505d722e3fbSopenharmony_ci
506d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
507d722e3fbSopenharmony_ci		if (len != 9)
508d722e3fbSopenharmony_ci			fprintf(out,
509d722e3fbSopenharmony_ci				"Bad count in XY_SETUP_MONO_PATTERN_SL_BLT\n");
510d722e3fbSopenharmony_ci
511d722e3fbSopenharmony_ci		decode_2d_br01(ctx);
512d722e3fbSopenharmony_ci		instr_out(ctx, 2, "cliprect (%d,%d)\n",
513d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[2] >> 16);
514d722e3fbSopenharmony_ci		instr_out(ctx, 3, "cliprect (%d,%d)\n",
515d722e3fbSopenharmony_ci			  data[3] & 0xffff, data[3] >> 16);
516d722e3fbSopenharmony_ci		instr_out(ctx, 4, "setup dst offset 0x%08x\n",
517d722e3fbSopenharmony_ci			  data[4]);
518d722e3fbSopenharmony_ci		instr_out(ctx, 5, "setup background color\n");
519d722e3fbSopenharmony_ci		instr_out(ctx, 6, "setup foreground color\n");
520d722e3fbSopenharmony_ci		instr_out(ctx, 7, "mono pattern dw0\n");
521d722e3fbSopenharmony_ci		instr_out(ctx, 8, "mono pattern dw1\n");
522d722e3fbSopenharmony_ci		return len;
523d722e3fbSopenharmony_ci	case 0x50:
524d722e3fbSopenharmony_ci		decode_2d_br00(ctx, "XY_COLOR_BLT");
525d722e3fbSopenharmony_ci
526d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
527d722e3fbSopenharmony_ci		if (len != 6)
528d722e3fbSopenharmony_ci			fprintf(out, "Bad count in XY_COLOR_BLT\n");
529d722e3fbSopenharmony_ci
530d722e3fbSopenharmony_ci		decode_2d_br01(ctx);
531d722e3fbSopenharmony_ci		instr_out(ctx, 2, "(%d,%d)\n",
532d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[2] >> 16);
533d722e3fbSopenharmony_ci		instr_out(ctx, 3, "(%d,%d)\n",
534d722e3fbSopenharmony_ci			  data[3] & 0xffff, data[3] >> 16);
535d722e3fbSopenharmony_ci		instr_out(ctx, 4, "offset 0x%08x\n", data[4]);
536d722e3fbSopenharmony_ci		instr_out(ctx, 5, "color\n");
537d722e3fbSopenharmony_ci		return len;
538d722e3fbSopenharmony_ci	case 0x53:
539d722e3fbSopenharmony_ci		decode_2d_br00(ctx, "XY_SRC_COPY_BLT");
540d722e3fbSopenharmony_ci
541d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
542d722e3fbSopenharmony_ci		if (len != 8)
543d722e3fbSopenharmony_ci			fprintf(out, "Bad count in XY_SRC_COPY_BLT\n");
544d722e3fbSopenharmony_ci
545d722e3fbSopenharmony_ci		decode_2d_br01(ctx);
546d722e3fbSopenharmony_ci		instr_out(ctx, 2, "dst (%d,%d)\n",
547d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[2] >> 16);
548d722e3fbSopenharmony_ci		instr_out(ctx, 3, "dst (%d,%d)\n",
549d722e3fbSopenharmony_ci			  data[3] & 0xffff, data[3] >> 16);
550d722e3fbSopenharmony_ci		instr_out(ctx, 4, "dst offset 0x%08x\n", data[4]);
551d722e3fbSopenharmony_ci		instr_out(ctx, 5, "src (%d,%d)\n",
552d722e3fbSopenharmony_ci			  data[5] & 0xffff, data[5] >> 16);
553d722e3fbSopenharmony_ci		instr_out(ctx, 6, "src pitch %d\n",
554d722e3fbSopenharmony_ci			  (short)(data[6] & 0xffff));
555d722e3fbSopenharmony_ci		instr_out(ctx, 7, "src offset 0x%08x\n", data[7]);
556d722e3fbSopenharmony_ci		return len;
557d722e3fbSopenharmony_ci	}
558d722e3fbSopenharmony_ci
559d722e3fbSopenharmony_ci	for (opcode = 0; opcode < sizeof(opcodes_2d) / sizeof(opcodes_2d[0]);
560d722e3fbSopenharmony_ci	     opcode++) {
561d722e3fbSopenharmony_ci		if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) {
562d722e3fbSopenharmony_ci			unsigned int i;
563d722e3fbSopenharmony_ci
564d722e3fbSopenharmony_ci			len = 1;
565d722e3fbSopenharmony_ci			instr_out(ctx, 0, "%s\n",
566d722e3fbSopenharmony_ci				  opcodes_2d[opcode].name);
567d722e3fbSopenharmony_ci			if (opcodes_2d[opcode].max_len > 1) {
568d722e3fbSopenharmony_ci				len = (data[0] & 0x000000ff) + 2;
569d722e3fbSopenharmony_ci				if (len < opcodes_2d[opcode].min_len ||
570d722e3fbSopenharmony_ci				    len > opcodes_2d[opcode].max_len) {
571d722e3fbSopenharmony_ci					fprintf(out, "Bad count in %s\n",
572d722e3fbSopenharmony_ci						opcodes_2d[opcode].name);
573d722e3fbSopenharmony_ci				}
574d722e3fbSopenharmony_ci			}
575d722e3fbSopenharmony_ci
576d722e3fbSopenharmony_ci			for (i = 1; i < len; i++) {
577d722e3fbSopenharmony_ci				instr_out(ctx, i, "dword %d\n", i);
578d722e3fbSopenharmony_ci			}
579d722e3fbSopenharmony_ci
580d722e3fbSopenharmony_ci			return len;
581d722e3fbSopenharmony_ci		}
582d722e3fbSopenharmony_ci	}
583d722e3fbSopenharmony_ci
584d722e3fbSopenharmony_ci	instr_out(ctx, 0, "2D UNKNOWN\n");
585d722e3fbSopenharmony_ci	return 1;
586d722e3fbSopenharmony_ci}
587d722e3fbSopenharmony_ci
588d722e3fbSopenharmony_cistatic int
589d722e3fbSopenharmony_cidecode_3d_1c(struct drm_intel_decode *ctx)
590d722e3fbSopenharmony_ci{
591d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
592d722e3fbSopenharmony_ci	uint32_t opcode;
593d722e3fbSopenharmony_ci
594d722e3fbSopenharmony_ci	opcode = (data[0] & 0x00f80000) >> 19;
595d722e3fbSopenharmony_ci
596d722e3fbSopenharmony_ci	switch (opcode) {
597d722e3fbSopenharmony_ci	case 0x11:
598d722e3fbSopenharmony_ci		instr_out(ctx, 0,
599d722e3fbSopenharmony_ci			  "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE\n");
600d722e3fbSopenharmony_ci		return 1;
601d722e3fbSopenharmony_ci	case 0x10:
602d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_SCISSOR_ENABLE %s\n",
603d722e3fbSopenharmony_ci			  data[0] & 1 ? "enabled" : "disabled");
604d722e3fbSopenharmony_ci		return 1;
605d722e3fbSopenharmony_ci	case 0x01:
606d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_MAP_COORD_SET_I830\n");
607d722e3fbSopenharmony_ci		return 1;
608d722e3fbSopenharmony_ci	case 0x0a:
609d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_MAP_CUBE_I830\n");
610d722e3fbSopenharmony_ci		return 1;
611d722e3fbSopenharmony_ci	case 0x05:
612d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
613d722e3fbSopenharmony_ci		return 1;
614d722e3fbSopenharmony_ci	}
615d722e3fbSopenharmony_ci
616d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3D UNKNOWN: 3d_1c opcode = 0x%x\n",
617d722e3fbSopenharmony_ci		  opcode);
618d722e3fbSopenharmony_ci	return 1;
619d722e3fbSopenharmony_ci}
620d722e3fbSopenharmony_ci
621d722e3fbSopenharmony_ci/** Sets the string dstname to describe the destination of the PS instruction */
622d722e3fbSopenharmony_cistatic void
623d722e3fbSopenharmony_cii915_get_instruction_dst(uint32_t *data, int i, char *dstname, int do_mask)
624d722e3fbSopenharmony_ci{
625d722e3fbSopenharmony_ci	uint32_t a0 = data[i];
626d722e3fbSopenharmony_ci	int dst_nr = (a0 >> 14) & 0xf;
627d722e3fbSopenharmony_ci	char dstmask[8];
628d722e3fbSopenharmony_ci	const char *sat;
629d722e3fbSopenharmony_ci
630d722e3fbSopenharmony_ci	if (do_mask) {
631d722e3fbSopenharmony_ci		if (((a0 >> 10) & 0xf) == 0xf) {
632d722e3fbSopenharmony_ci			dstmask[0] = 0;
633d722e3fbSopenharmony_ci		} else {
634d722e3fbSopenharmony_ci			int dstmask_index = 0;
635d722e3fbSopenharmony_ci
636d722e3fbSopenharmony_ci			dstmask[dstmask_index++] = '.';
637d722e3fbSopenharmony_ci			if (a0 & (1 << 10))
638d722e3fbSopenharmony_ci				dstmask[dstmask_index++] = 'x';
639d722e3fbSopenharmony_ci			if (a0 & (1 << 11))
640d722e3fbSopenharmony_ci				dstmask[dstmask_index++] = 'y';
641d722e3fbSopenharmony_ci			if (a0 & (1 << 12))
642d722e3fbSopenharmony_ci				dstmask[dstmask_index++] = 'z';
643d722e3fbSopenharmony_ci			if (a0 & (1 << 13))
644d722e3fbSopenharmony_ci				dstmask[dstmask_index++] = 'w';
645d722e3fbSopenharmony_ci			dstmask[dstmask_index++] = 0;
646d722e3fbSopenharmony_ci		}
647d722e3fbSopenharmony_ci
648d722e3fbSopenharmony_ci		if (a0 & (1 << 22))
649d722e3fbSopenharmony_ci			sat = ".sat";
650d722e3fbSopenharmony_ci		else
651d722e3fbSopenharmony_ci			sat = "";
652d722e3fbSopenharmony_ci	} else {
653d722e3fbSopenharmony_ci		dstmask[0] = 0;
654d722e3fbSopenharmony_ci		sat = "";
655d722e3fbSopenharmony_ci	}
656d722e3fbSopenharmony_ci
657d722e3fbSopenharmony_ci	switch ((a0 >> 19) & 0x7) {
658d722e3fbSopenharmony_ci	case 0:
659d722e3fbSopenharmony_ci		if (dst_nr > 15)
660d722e3fbSopenharmony_ci			fprintf(out, "bad destination reg R%d\n", dst_nr);
661d722e3fbSopenharmony_ci		sprintf(dstname, "R%d%s%s", dst_nr, dstmask, sat);
662d722e3fbSopenharmony_ci		break;
663d722e3fbSopenharmony_ci	case 4:
664d722e3fbSopenharmony_ci		if (dst_nr > 0)
665d722e3fbSopenharmony_ci			fprintf(out, "bad destination reg oC%d\n", dst_nr);
666d722e3fbSopenharmony_ci		sprintf(dstname, "oC%s%s", dstmask, sat);
667d722e3fbSopenharmony_ci		break;
668d722e3fbSopenharmony_ci	case 5:
669d722e3fbSopenharmony_ci		if (dst_nr > 0)
670d722e3fbSopenharmony_ci			fprintf(out, "bad destination reg oD%d\n", dst_nr);
671d722e3fbSopenharmony_ci		sprintf(dstname, "oD%s%s", dstmask, sat);
672d722e3fbSopenharmony_ci		break;
673d722e3fbSopenharmony_ci	case 6:
674d722e3fbSopenharmony_ci		if (dst_nr > 3)
675d722e3fbSopenharmony_ci			fprintf(out, "bad destination reg U%d\n", dst_nr);
676d722e3fbSopenharmony_ci		sprintf(dstname, "U%d%s%s", dst_nr, dstmask, sat);
677d722e3fbSopenharmony_ci		break;
678d722e3fbSopenharmony_ci	default:
679d722e3fbSopenharmony_ci		sprintf(dstname, "RESERVED");
680d722e3fbSopenharmony_ci		break;
681d722e3fbSopenharmony_ci	}
682d722e3fbSopenharmony_ci}
683d722e3fbSopenharmony_ci
684d722e3fbSopenharmony_cistatic const char *
685d722e3fbSopenharmony_cii915_get_channel_swizzle(uint32_t select)
686d722e3fbSopenharmony_ci{
687d722e3fbSopenharmony_ci	switch (select & 0x7) {
688d722e3fbSopenharmony_ci	case 0:
689d722e3fbSopenharmony_ci		return (select & 8) ? "-x" : "x";
690d722e3fbSopenharmony_ci	case 1:
691d722e3fbSopenharmony_ci		return (select & 8) ? "-y" : "y";
692d722e3fbSopenharmony_ci	case 2:
693d722e3fbSopenharmony_ci		return (select & 8) ? "-z" : "z";
694d722e3fbSopenharmony_ci	case 3:
695d722e3fbSopenharmony_ci		return (select & 8) ? "-w" : "w";
696d722e3fbSopenharmony_ci	case 4:
697d722e3fbSopenharmony_ci		return (select & 8) ? "-0" : "0";
698d722e3fbSopenharmony_ci	case 5:
699d722e3fbSopenharmony_ci		return (select & 8) ? "-1" : "1";
700d722e3fbSopenharmony_ci	default:
701d722e3fbSopenharmony_ci		return (select & 8) ? "-bad" : "bad";
702d722e3fbSopenharmony_ci	}
703d722e3fbSopenharmony_ci}
704d722e3fbSopenharmony_ci
705d722e3fbSopenharmony_cistatic void
706d722e3fbSopenharmony_cii915_get_instruction_src_name(uint32_t src_type, uint32_t src_nr, char *name)
707d722e3fbSopenharmony_ci{
708d722e3fbSopenharmony_ci	switch (src_type) {
709d722e3fbSopenharmony_ci	case 0:
710d722e3fbSopenharmony_ci		sprintf(name, "R%d", src_nr);
711d722e3fbSopenharmony_ci		if (src_nr > 15)
712d722e3fbSopenharmony_ci			fprintf(out, "bad src reg %s\n", name);
713d722e3fbSopenharmony_ci		break;
714d722e3fbSopenharmony_ci	case 1:
715d722e3fbSopenharmony_ci		if (src_nr < 8)
716d722e3fbSopenharmony_ci			sprintf(name, "T%d", src_nr);
717d722e3fbSopenharmony_ci		else if (src_nr == 8)
718d722e3fbSopenharmony_ci			sprintf(name, "DIFFUSE");
719d722e3fbSopenharmony_ci		else if (src_nr == 9)
720d722e3fbSopenharmony_ci			sprintf(name, "SPECULAR");
721d722e3fbSopenharmony_ci		else if (src_nr == 10)
722d722e3fbSopenharmony_ci			sprintf(name, "FOG");
723d722e3fbSopenharmony_ci		else {
724d722e3fbSopenharmony_ci			fprintf(out, "bad src reg T%d\n", src_nr);
725d722e3fbSopenharmony_ci			sprintf(name, "RESERVED");
726d722e3fbSopenharmony_ci		}
727d722e3fbSopenharmony_ci		break;
728d722e3fbSopenharmony_ci	case 2:
729d722e3fbSopenharmony_ci		sprintf(name, "C%d", src_nr);
730d722e3fbSopenharmony_ci		if (src_nr > 31)
731d722e3fbSopenharmony_ci			fprintf(out, "bad src reg %s\n", name);
732d722e3fbSopenharmony_ci		break;
733d722e3fbSopenharmony_ci	case 4:
734d722e3fbSopenharmony_ci		sprintf(name, "oC");
735d722e3fbSopenharmony_ci		if (src_nr > 0)
736d722e3fbSopenharmony_ci			fprintf(out, "bad src reg oC%d\n", src_nr);
737d722e3fbSopenharmony_ci		break;
738d722e3fbSopenharmony_ci	case 5:
739d722e3fbSopenharmony_ci		sprintf(name, "oD");
740d722e3fbSopenharmony_ci		if (src_nr > 0)
741d722e3fbSopenharmony_ci			fprintf(out, "bad src reg oD%d\n", src_nr);
742d722e3fbSopenharmony_ci		break;
743d722e3fbSopenharmony_ci	case 6:
744d722e3fbSopenharmony_ci		sprintf(name, "U%d", src_nr);
745d722e3fbSopenharmony_ci		if (src_nr > 3)
746d722e3fbSopenharmony_ci			fprintf(out, "bad src reg %s\n", name);
747d722e3fbSopenharmony_ci		break;
748d722e3fbSopenharmony_ci	default:
749d722e3fbSopenharmony_ci		fprintf(out, "bad src reg type %d\n", src_type);
750d722e3fbSopenharmony_ci		sprintf(name, "RESERVED");
751d722e3fbSopenharmony_ci		break;
752d722e3fbSopenharmony_ci	}
753d722e3fbSopenharmony_ci}
754d722e3fbSopenharmony_ci
755d722e3fbSopenharmony_cistatic void i915_get_instruction_src0(uint32_t *data, int i, char *srcname)
756d722e3fbSopenharmony_ci{
757d722e3fbSopenharmony_ci	uint32_t a0 = data[i];
758d722e3fbSopenharmony_ci	uint32_t a1 = data[i + 1];
759d722e3fbSopenharmony_ci	int src_nr = (a0 >> 2) & 0x1f;
760d722e3fbSopenharmony_ci	const char *swizzle_x = i915_get_channel_swizzle((a1 >> 28) & 0xf);
761d722e3fbSopenharmony_ci	const char *swizzle_y = i915_get_channel_swizzle((a1 >> 24) & 0xf);
762d722e3fbSopenharmony_ci	const char *swizzle_z = i915_get_channel_swizzle((a1 >> 20) & 0xf);
763d722e3fbSopenharmony_ci	const char *swizzle_w = i915_get_channel_swizzle((a1 >> 16) & 0xf);
764d722e3fbSopenharmony_ci	char swizzle[100];
765d722e3fbSopenharmony_ci
766d722e3fbSopenharmony_ci	i915_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname);
767d722e3fbSopenharmony_ci	sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
768d722e3fbSopenharmony_ci		swizzle_w);
769d722e3fbSopenharmony_ci	if (strcmp(swizzle, ".xyzw") != 0)
770d722e3fbSopenharmony_ci		strcat(srcname, swizzle);
771d722e3fbSopenharmony_ci}
772d722e3fbSopenharmony_ci
773d722e3fbSopenharmony_cistatic void i915_get_instruction_src1(uint32_t *data, int i, char *srcname)
774d722e3fbSopenharmony_ci{
775d722e3fbSopenharmony_ci	uint32_t a1 = data[i + 1];
776d722e3fbSopenharmony_ci	uint32_t a2 = data[i + 2];
777d722e3fbSopenharmony_ci	int src_nr = (a1 >> 8) & 0x1f;
778d722e3fbSopenharmony_ci	const char *swizzle_x = i915_get_channel_swizzle((a1 >> 4) & 0xf);
779d722e3fbSopenharmony_ci	const char *swizzle_y = i915_get_channel_swizzle((a1 >> 0) & 0xf);
780d722e3fbSopenharmony_ci	const char *swizzle_z = i915_get_channel_swizzle((a2 >> 28) & 0xf);
781d722e3fbSopenharmony_ci	const char *swizzle_w = i915_get_channel_swizzle((a2 >> 24) & 0xf);
782d722e3fbSopenharmony_ci	char swizzle[100];
783d722e3fbSopenharmony_ci
784d722e3fbSopenharmony_ci	i915_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname);
785d722e3fbSopenharmony_ci	sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
786d722e3fbSopenharmony_ci		swizzle_w);
787d722e3fbSopenharmony_ci	if (strcmp(swizzle, ".xyzw") != 0)
788d722e3fbSopenharmony_ci		strcat(srcname, swizzle);
789d722e3fbSopenharmony_ci}
790d722e3fbSopenharmony_ci
791d722e3fbSopenharmony_cistatic void i915_get_instruction_src2(uint32_t *data, int i, char *srcname)
792d722e3fbSopenharmony_ci{
793d722e3fbSopenharmony_ci	uint32_t a2 = data[i + 2];
794d722e3fbSopenharmony_ci	int src_nr = (a2 >> 16) & 0x1f;
795d722e3fbSopenharmony_ci	const char *swizzle_x = i915_get_channel_swizzle((a2 >> 12) & 0xf);
796d722e3fbSopenharmony_ci	const char *swizzle_y = i915_get_channel_swizzle((a2 >> 8) & 0xf);
797d722e3fbSopenharmony_ci	const char *swizzle_z = i915_get_channel_swizzle((a2 >> 4) & 0xf);
798d722e3fbSopenharmony_ci	const char *swizzle_w = i915_get_channel_swizzle((a2 >> 0) & 0xf);
799d722e3fbSopenharmony_ci	char swizzle[100];
800d722e3fbSopenharmony_ci
801d722e3fbSopenharmony_ci	i915_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname);
802d722e3fbSopenharmony_ci	sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
803d722e3fbSopenharmony_ci		swizzle_w);
804d722e3fbSopenharmony_ci	if (strcmp(swizzle, ".xyzw") != 0)
805d722e3fbSopenharmony_ci		strcat(srcname, swizzle);
806d722e3fbSopenharmony_ci}
807d722e3fbSopenharmony_ci
808d722e3fbSopenharmony_cistatic void
809d722e3fbSopenharmony_cii915_get_instruction_addr(uint32_t src_type, uint32_t src_nr, char *name)
810d722e3fbSopenharmony_ci{
811d722e3fbSopenharmony_ci	switch (src_type) {
812d722e3fbSopenharmony_ci	case 0:
813d722e3fbSopenharmony_ci		sprintf(name, "R%d", src_nr);
814d722e3fbSopenharmony_ci		if (src_nr > 15)
815d722e3fbSopenharmony_ci			fprintf(out, "bad src reg %s\n", name);
816d722e3fbSopenharmony_ci		break;
817d722e3fbSopenharmony_ci	case 1:
818d722e3fbSopenharmony_ci		if (src_nr < 8)
819d722e3fbSopenharmony_ci			sprintf(name, "T%d", src_nr);
820d722e3fbSopenharmony_ci		else if (src_nr == 8)
821d722e3fbSopenharmony_ci			sprintf(name, "DIFFUSE");
822d722e3fbSopenharmony_ci		else if (src_nr == 9)
823d722e3fbSopenharmony_ci			sprintf(name, "SPECULAR");
824d722e3fbSopenharmony_ci		else if (src_nr == 10)
825d722e3fbSopenharmony_ci			sprintf(name, "FOG");
826d722e3fbSopenharmony_ci		else {
827d722e3fbSopenharmony_ci			fprintf(out, "bad src reg T%d\n", src_nr);
828d722e3fbSopenharmony_ci			sprintf(name, "RESERVED");
829d722e3fbSopenharmony_ci		}
830d722e3fbSopenharmony_ci		break;
831d722e3fbSopenharmony_ci	case 4:
832d722e3fbSopenharmony_ci		sprintf(name, "oC");
833d722e3fbSopenharmony_ci		if (src_nr > 0)
834d722e3fbSopenharmony_ci			fprintf(out, "bad src reg oC%d\n", src_nr);
835d722e3fbSopenharmony_ci		break;
836d722e3fbSopenharmony_ci	case 5:
837d722e3fbSopenharmony_ci		sprintf(name, "oD");
838d722e3fbSopenharmony_ci		if (src_nr > 0)
839d722e3fbSopenharmony_ci			fprintf(out, "bad src reg oD%d\n", src_nr);
840d722e3fbSopenharmony_ci		break;
841d722e3fbSopenharmony_ci	default:
842d722e3fbSopenharmony_ci		fprintf(out, "bad src reg type %d\n", src_type);
843d722e3fbSopenharmony_ci		sprintf(name, "RESERVED");
844d722e3fbSopenharmony_ci		break;
845d722e3fbSopenharmony_ci	}
846d722e3fbSopenharmony_ci}
847d722e3fbSopenharmony_ci
848d722e3fbSopenharmony_cistatic void
849d722e3fbSopenharmony_cii915_decode_alu1(struct drm_intel_decode *ctx,
850d722e3fbSopenharmony_ci		 int i, char *instr_prefix, const char *op_name)
851d722e3fbSopenharmony_ci{
852d722e3fbSopenharmony_ci	char dst[100], src0[100];
853d722e3fbSopenharmony_ci
854d722e3fbSopenharmony_ci	i915_get_instruction_dst(ctx->data, i, dst, 1);
855d722e3fbSopenharmony_ci	i915_get_instruction_src0(ctx->data, i, src0);
856d722e3fbSopenharmony_ci
857d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s: %s %s, %s\n", instr_prefix,
858d722e3fbSopenharmony_ci		  op_name, dst, src0);
859d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
860d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
861d722e3fbSopenharmony_ci}
862d722e3fbSopenharmony_ci
863d722e3fbSopenharmony_cistatic void
864d722e3fbSopenharmony_cii915_decode_alu2(struct drm_intel_decode *ctx,
865d722e3fbSopenharmony_ci		 int i, char *instr_prefix, const char *op_name)
866d722e3fbSopenharmony_ci{
867d722e3fbSopenharmony_ci	char dst[100], src0[100], src1[100];
868d722e3fbSopenharmony_ci
869d722e3fbSopenharmony_ci	i915_get_instruction_dst(ctx->data, i, dst, 1);
870d722e3fbSopenharmony_ci	i915_get_instruction_src0(ctx->data, i, src0);
871d722e3fbSopenharmony_ci	i915_get_instruction_src1(ctx->data, i, src1);
872d722e3fbSopenharmony_ci
873d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s: %s %s, %s, %s\n", instr_prefix,
874d722e3fbSopenharmony_ci		  op_name, dst, src0, src1);
875d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
876d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
877d722e3fbSopenharmony_ci}
878d722e3fbSopenharmony_ci
879d722e3fbSopenharmony_cistatic void
880d722e3fbSopenharmony_cii915_decode_alu3(struct drm_intel_decode *ctx,
881d722e3fbSopenharmony_ci		 int i, char *instr_prefix, const char *op_name)
882d722e3fbSopenharmony_ci{
883d722e3fbSopenharmony_ci	char dst[100], src0[100], src1[100], src2[100];
884d722e3fbSopenharmony_ci
885d722e3fbSopenharmony_ci	i915_get_instruction_dst(ctx->data, i, dst, 1);
886d722e3fbSopenharmony_ci	i915_get_instruction_src0(ctx->data, i, src0);
887d722e3fbSopenharmony_ci	i915_get_instruction_src1(ctx->data, i, src1);
888d722e3fbSopenharmony_ci	i915_get_instruction_src2(ctx->data, i, src2);
889d722e3fbSopenharmony_ci
890d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s: %s %s, %s, %s, %s\n", instr_prefix,
891d722e3fbSopenharmony_ci		  op_name, dst, src0, src1, src2);
892d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
893d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
894d722e3fbSopenharmony_ci}
895d722e3fbSopenharmony_ci
896d722e3fbSopenharmony_cistatic void
897d722e3fbSopenharmony_cii915_decode_tex(struct drm_intel_decode *ctx, int i,
898d722e3fbSopenharmony_ci		const char *instr_prefix, const char *tex_name)
899d722e3fbSopenharmony_ci{
900d722e3fbSopenharmony_ci	uint32_t t0 = ctx->data[i];
901d722e3fbSopenharmony_ci	uint32_t t1 = ctx->data[i + 1];
902d722e3fbSopenharmony_ci	char dst_name[100];
903d722e3fbSopenharmony_ci	char addr_name[100];
904d722e3fbSopenharmony_ci	int sampler_nr;
905d722e3fbSopenharmony_ci
906d722e3fbSopenharmony_ci	i915_get_instruction_dst(ctx->data, i, dst_name, 0);
907d722e3fbSopenharmony_ci	i915_get_instruction_addr((t1 >> 24) & 0x7,
908d722e3fbSopenharmony_ci				  (t1 >> 17) & 0xf, addr_name);
909d722e3fbSopenharmony_ci	sampler_nr = t0 & 0xf;
910d722e3fbSopenharmony_ci
911d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s: %s %s, S%d, %s\n", instr_prefix,
912d722e3fbSopenharmony_ci		  tex_name, dst_name, sampler_nr, addr_name);
913d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
914d722e3fbSopenharmony_ci	instr_out(ctx, i++, "%s\n", instr_prefix);
915d722e3fbSopenharmony_ci}
916d722e3fbSopenharmony_ci
917d722e3fbSopenharmony_cistatic void
918d722e3fbSopenharmony_cii915_decode_dcl(struct drm_intel_decode *ctx, int i, char *instr_prefix)
919d722e3fbSopenharmony_ci{
920d722e3fbSopenharmony_ci	uint32_t d0 = ctx->data[i];
921d722e3fbSopenharmony_ci	const char *sampletype;
922d722e3fbSopenharmony_ci	int dcl_nr = (d0 >> 14) & 0xf;
923d722e3fbSopenharmony_ci	const char *dcl_x = d0 & (1 << 10) ? "x" : "";
924d722e3fbSopenharmony_ci	const char *dcl_y = d0 & (1 << 11) ? "y" : "";
925d722e3fbSopenharmony_ci	const char *dcl_z = d0 & (1 << 12) ? "z" : "";
926d722e3fbSopenharmony_ci	const char *dcl_w = d0 & (1 << 13) ? "w" : "";
927d722e3fbSopenharmony_ci	char dcl_mask[10];
928d722e3fbSopenharmony_ci
929d722e3fbSopenharmony_ci	switch ((d0 >> 19) & 0x3) {
930d722e3fbSopenharmony_ci	case 1:
931d722e3fbSopenharmony_ci		sprintf(dcl_mask, ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
932d722e3fbSopenharmony_ci		if (strcmp(dcl_mask, ".") == 0)
933d722e3fbSopenharmony_ci			fprintf(out, "bad (empty) dcl mask\n");
934d722e3fbSopenharmony_ci
935d722e3fbSopenharmony_ci		if (dcl_nr > 10)
936d722e3fbSopenharmony_ci			fprintf(out, "bad T%d dcl register number\n", dcl_nr);
937d722e3fbSopenharmony_ci		if (dcl_nr < 8) {
938d722e3fbSopenharmony_ci			if (strcmp(dcl_mask, ".x") != 0 &&
939d722e3fbSopenharmony_ci			    strcmp(dcl_mask, ".xy") != 0 &&
940d722e3fbSopenharmony_ci			    strcmp(dcl_mask, ".xz") != 0 &&
941d722e3fbSopenharmony_ci			    strcmp(dcl_mask, ".w") != 0 &&
942d722e3fbSopenharmony_ci			    strcmp(dcl_mask, ".xyzw") != 0) {
943d722e3fbSopenharmony_ci				fprintf(out, "bad T%d.%s dcl mask\n", dcl_nr,
944d722e3fbSopenharmony_ci					dcl_mask);
945d722e3fbSopenharmony_ci			}
946d722e3fbSopenharmony_ci			instr_out(ctx, i++, "%s: DCL T%d%s\n",
947d722e3fbSopenharmony_ci				  instr_prefix, dcl_nr, dcl_mask);
948d722e3fbSopenharmony_ci		} else {
949d722e3fbSopenharmony_ci			if (strcmp(dcl_mask, ".xz") == 0)
950d722e3fbSopenharmony_ci				fprintf(out, "errataed bad dcl mask %s\n",
951d722e3fbSopenharmony_ci					dcl_mask);
952d722e3fbSopenharmony_ci			else if (strcmp(dcl_mask, ".xw") == 0)
953d722e3fbSopenharmony_ci				fprintf(out, "errataed bad dcl mask %s\n",
954d722e3fbSopenharmony_ci					dcl_mask);
955d722e3fbSopenharmony_ci			else if (strcmp(dcl_mask, ".xzw") == 0)
956d722e3fbSopenharmony_ci				fprintf(out, "errataed bad dcl mask %s\n",
957d722e3fbSopenharmony_ci					dcl_mask);
958d722e3fbSopenharmony_ci
959d722e3fbSopenharmony_ci			if (dcl_nr == 8) {
960d722e3fbSopenharmony_ci				instr_out(ctx, i++,
961d722e3fbSopenharmony_ci					  "%s: DCL DIFFUSE%s\n", instr_prefix,
962d722e3fbSopenharmony_ci					  dcl_mask);
963d722e3fbSopenharmony_ci			} else if (dcl_nr == 9) {
964d722e3fbSopenharmony_ci				instr_out(ctx, i++,
965d722e3fbSopenharmony_ci					  "%s: DCL SPECULAR%s\n", instr_prefix,
966d722e3fbSopenharmony_ci					  dcl_mask);
967d722e3fbSopenharmony_ci			} else if (dcl_nr == 10) {
968d722e3fbSopenharmony_ci				instr_out(ctx, i++,
969d722e3fbSopenharmony_ci					  "%s: DCL FOG%s\n", instr_prefix,
970d722e3fbSopenharmony_ci					  dcl_mask);
971d722e3fbSopenharmony_ci			}
972d722e3fbSopenharmony_ci		}
973d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
974d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
975d722e3fbSopenharmony_ci		break;
976d722e3fbSopenharmony_ci	case 3:
977d722e3fbSopenharmony_ci		switch ((d0 >> 22) & 0x3) {
978d722e3fbSopenharmony_ci		case 0:
979d722e3fbSopenharmony_ci			sampletype = "2D";
980d722e3fbSopenharmony_ci			break;
981d722e3fbSopenharmony_ci		case 1:
982d722e3fbSopenharmony_ci			sampletype = "CUBE";
983d722e3fbSopenharmony_ci			break;
984d722e3fbSopenharmony_ci		case 2:
985d722e3fbSopenharmony_ci			sampletype = "3D";
986d722e3fbSopenharmony_ci			break;
987d722e3fbSopenharmony_ci		default:
988d722e3fbSopenharmony_ci			sampletype = "RESERVED";
989d722e3fbSopenharmony_ci			break;
990d722e3fbSopenharmony_ci		}
991d722e3fbSopenharmony_ci		if (dcl_nr > 15)
992d722e3fbSopenharmony_ci			fprintf(out, "bad S%d dcl register number\n", dcl_nr);
993d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s: DCL S%d %s\n",
994d722e3fbSopenharmony_ci			  instr_prefix, dcl_nr, sampletype);
995d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
996d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
997d722e3fbSopenharmony_ci		break;
998d722e3fbSopenharmony_ci	default:
999d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s: DCL RESERVED%d\n",
1000d722e3fbSopenharmony_ci			  instr_prefix, dcl_nr);
1001d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
1002d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
1003d722e3fbSopenharmony_ci	}
1004d722e3fbSopenharmony_ci}
1005d722e3fbSopenharmony_ci
1006d722e3fbSopenharmony_cistatic void
1007d722e3fbSopenharmony_cii915_decode_instruction(struct drm_intel_decode *ctx,
1008d722e3fbSopenharmony_ci			int i, char *instr_prefix)
1009d722e3fbSopenharmony_ci{
1010d722e3fbSopenharmony_ci	switch ((ctx->data[i] >> 24) & 0x1f) {
1011d722e3fbSopenharmony_ci	case 0x0:
1012d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s: NOP\n", instr_prefix);
1013d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
1014d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
1015d722e3fbSopenharmony_ci		break;
1016d722e3fbSopenharmony_ci	case 0x01:
1017d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "ADD");
1018d722e3fbSopenharmony_ci		break;
1019d722e3fbSopenharmony_ci	case 0x02:
1020d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "MOV");
1021d722e3fbSopenharmony_ci		break;
1022d722e3fbSopenharmony_ci	case 0x03:
1023d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "MUL");
1024d722e3fbSopenharmony_ci		break;
1025d722e3fbSopenharmony_ci	case 0x04:
1026d722e3fbSopenharmony_ci		i915_decode_alu3(ctx, i, instr_prefix, "MAD");
1027d722e3fbSopenharmony_ci		break;
1028d722e3fbSopenharmony_ci	case 0x05:
1029d722e3fbSopenharmony_ci		i915_decode_alu3(ctx, i, instr_prefix, "DP2ADD");
1030d722e3fbSopenharmony_ci		break;
1031d722e3fbSopenharmony_ci	case 0x06:
1032d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "DP3");
1033d722e3fbSopenharmony_ci		break;
1034d722e3fbSopenharmony_ci	case 0x07:
1035d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "DP4");
1036d722e3fbSopenharmony_ci		break;
1037d722e3fbSopenharmony_ci	case 0x08:
1038d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "FRC");
1039d722e3fbSopenharmony_ci		break;
1040d722e3fbSopenharmony_ci	case 0x09:
1041d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "RCP");
1042d722e3fbSopenharmony_ci		break;
1043d722e3fbSopenharmony_ci	case 0x0a:
1044d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "RSQ");
1045d722e3fbSopenharmony_ci		break;
1046d722e3fbSopenharmony_ci	case 0x0b:
1047d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "EXP");
1048d722e3fbSopenharmony_ci		break;
1049d722e3fbSopenharmony_ci	case 0x0c:
1050d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "LOG");
1051d722e3fbSopenharmony_ci		break;
1052d722e3fbSopenharmony_ci	case 0x0d:
1053d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "CMP");
1054d722e3fbSopenharmony_ci		break;
1055d722e3fbSopenharmony_ci	case 0x0e:
1056d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "MIN");
1057d722e3fbSopenharmony_ci		break;
1058d722e3fbSopenharmony_ci	case 0x0f:
1059d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "MAX");
1060d722e3fbSopenharmony_ci		break;
1061d722e3fbSopenharmony_ci	case 0x10:
1062d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "FLR");
1063d722e3fbSopenharmony_ci		break;
1064d722e3fbSopenharmony_ci	case 0x11:
1065d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "MOD");
1066d722e3fbSopenharmony_ci		break;
1067d722e3fbSopenharmony_ci	case 0x12:
1068d722e3fbSopenharmony_ci		i915_decode_alu1(ctx, i, instr_prefix, "TRC");
1069d722e3fbSopenharmony_ci		break;
1070d722e3fbSopenharmony_ci	case 0x13:
1071d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "SGE");
1072d722e3fbSopenharmony_ci		break;
1073d722e3fbSopenharmony_ci	case 0x14:
1074d722e3fbSopenharmony_ci		i915_decode_alu2(ctx, i, instr_prefix, "SLT");
1075d722e3fbSopenharmony_ci		break;
1076d722e3fbSopenharmony_ci	case 0x15:
1077d722e3fbSopenharmony_ci		i915_decode_tex(ctx, i, instr_prefix, "TEXLD");
1078d722e3fbSopenharmony_ci		break;
1079d722e3fbSopenharmony_ci	case 0x16:
1080d722e3fbSopenharmony_ci		i915_decode_tex(ctx, i, instr_prefix, "TEXLDP");
1081d722e3fbSopenharmony_ci		break;
1082d722e3fbSopenharmony_ci	case 0x17:
1083d722e3fbSopenharmony_ci		i915_decode_tex(ctx, i, instr_prefix, "TEXLDB");
1084d722e3fbSopenharmony_ci		break;
1085d722e3fbSopenharmony_ci	case 0x19:
1086d722e3fbSopenharmony_ci		i915_decode_dcl(ctx, i, instr_prefix);
1087d722e3fbSopenharmony_ci		break;
1088d722e3fbSopenharmony_ci	default:
1089d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s: unknown\n", instr_prefix);
1090d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
1091d722e3fbSopenharmony_ci		instr_out(ctx, i++, "%s\n", instr_prefix);
1092d722e3fbSopenharmony_ci		break;
1093d722e3fbSopenharmony_ci	}
1094d722e3fbSopenharmony_ci}
1095d722e3fbSopenharmony_ci
1096d722e3fbSopenharmony_cistatic const char *
1097d722e3fbSopenharmony_cidecode_compare_func(uint32_t op)
1098d722e3fbSopenharmony_ci{
1099d722e3fbSopenharmony_ci	switch (op & 0x7) {
1100d722e3fbSopenharmony_ci	case 0:
1101d722e3fbSopenharmony_ci		return "always";
1102d722e3fbSopenharmony_ci	case 1:
1103d722e3fbSopenharmony_ci		return "never";
1104d722e3fbSopenharmony_ci	case 2:
1105d722e3fbSopenharmony_ci		return "less";
1106d722e3fbSopenharmony_ci	case 3:
1107d722e3fbSopenharmony_ci		return "equal";
1108d722e3fbSopenharmony_ci	case 4:
1109d722e3fbSopenharmony_ci		return "lequal";
1110d722e3fbSopenharmony_ci	case 5:
1111d722e3fbSopenharmony_ci		return "greater";
1112d722e3fbSopenharmony_ci	case 6:
1113d722e3fbSopenharmony_ci		return "notequal";
1114d722e3fbSopenharmony_ci	case 7:
1115d722e3fbSopenharmony_ci		return "gequal";
1116d722e3fbSopenharmony_ci	}
1117d722e3fbSopenharmony_ci	return "";
1118d722e3fbSopenharmony_ci}
1119d722e3fbSopenharmony_ci
1120d722e3fbSopenharmony_cistatic const char *
1121d722e3fbSopenharmony_cidecode_stencil_op(uint32_t op)
1122d722e3fbSopenharmony_ci{
1123d722e3fbSopenharmony_ci	switch (op & 0x7) {
1124d722e3fbSopenharmony_ci	case 0:
1125d722e3fbSopenharmony_ci		return "keep";
1126d722e3fbSopenharmony_ci	case 1:
1127d722e3fbSopenharmony_ci		return "zero";
1128d722e3fbSopenharmony_ci	case 2:
1129d722e3fbSopenharmony_ci		return "replace";
1130d722e3fbSopenharmony_ci	case 3:
1131d722e3fbSopenharmony_ci		return "incr_sat";
1132d722e3fbSopenharmony_ci	case 4:
1133d722e3fbSopenharmony_ci		return "decr_sat";
1134d722e3fbSopenharmony_ci	case 5:
1135d722e3fbSopenharmony_ci		return "greater";
1136d722e3fbSopenharmony_ci	case 6:
1137d722e3fbSopenharmony_ci		return "incr";
1138d722e3fbSopenharmony_ci	case 7:
1139d722e3fbSopenharmony_ci		return "decr";
1140d722e3fbSopenharmony_ci	}
1141d722e3fbSopenharmony_ci	return "";
1142d722e3fbSopenharmony_ci}
1143d722e3fbSopenharmony_ci
1144d722e3fbSopenharmony_ci#if 0
1145d722e3fbSopenharmony_cistatic const char *
1146d722e3fbSopenharmony_cidecode_logic_op(uint32_t op)
1147d722e3fbSopenharmony_ci{
1148d722e3fbSopenharmony_ci	switch (op & 0xf) {
1149d722e3fbSopenharmony_ci	case 0:
1150d722e3fbSopenharmony_ci		return "clear";
1151d722e3fbSopenharmony_ci	case 1:
1152d722e3fbSopenharmony_ci		return "nor";
1153d722e3fbSopenharmony_ci	case 2:
1154d722e3fbSopenharmony_ci		return "and_inv";
1155d722e3fbSopenharmony_ci	case 3:
1156d722e3fbSopenharmony_ci		return "copy_inv";
1157d722e3fbSopenharmony_ci	case 4:
1158d722e3fbSopenharmony_ci		return "and_rvrse";
1159d722e3fbSopenharmony_ci	case 5:
1160d722e3fbSopenharmony_ci		return "inv";
1161d722e3fbSopenharmony_ci	case 6:
1162d722e3fbSopenharmony_ci		return "xor";
1163d722e3fbSopenharmony_ci	case 7:
1164d722e3fbSopenharmony_ci		return "nand";
1165d722e3fbSopenharmony_ci	case 8:
1166d722e3fbSopenharmony_ci		return "and";
1167d722e3fbSopenharmony_ci	case 9:
1168d722e3fbSopenharmony_ci		return "equiv";
1169d722e3fbSopenharmony_ci	case 10:
1170d722e3fbSopenharmony_ci		return "noop";
1171d722e3fbSopenharmony_ci	case 11:
1172d722e3fbSopenharmony_ci		return "or_inv";
1173d722e3fbSopenharmony_ci	case 12:
1174d722e3fbSopenharmony_ci		return "copy";
1175d722e3fbSopenharmony_ci	case 13:
1176d722e3fbSopenharmony_ci		return "or_rvrse";
1177d722e3fbSopenharmony_ci	case 14:
1178d722e3fbSopenharmony_ci		return "or";
1179d722e3fbSopenharmony_ci	case 15:
1180d722e3fbSopenharmony_ci		return "set";
1181d722e3fbSopenharmony_ci	}
1182d722e3fbSopenharmony_ci	return "";
1183d722e3fbSopenharmony_ci}
1184d722e3fbSopenharmony_ci#endif
1185d722e3fbSopenharmony_ci
1186d722e3fbSopenharmony_cistatic const char *
1187d722e3fbSopenharmony_cidecode_blend_fact(uint32_t op)
1188d722e3fbSopenharmony_ci{
1189d722e3fbSopenharmony_ci	switch (op & 0xf) {
1190d722e3fbSopenharmony_ci	case 1:
1191d722e3fbSopenharmony_ci		return "zero";
1192d722e3fbSopenharmony_ci	case 2:
1193d722e3fbSopenharmony_ci		return "one";
1194d722e3fbSopenharmony_ci	case 3:
1195d722e3fbSopenharmony_ci		return "src_colr";
1196d722e3fbSopenharmony_ci	case 4:
1197d722e3fbSopenharmony_ci		return "inv_src_colr";
1198d722e3fbSopenharmony_ci	case 5:
1199d722e3fbSopenharmony_ci		return "src_alpha";
1200d722e3fbSopenharmony_ci	case 6:
1201d722e3fbSopenharmony_ci		return "inv_src_alpha";
1202d722e3fbSopenharmony_ci	case 7:
1203d722e3fbSopenharmony_ci		return "dst_alpha";
1204d722e3fbSopenharmony_ci	case 8:
1205d722e3fbSopenharmony_ci		return "inv_dst_alpha";
1206d722e3fbSopenharmony_ci	case 9:
1207d722e3fbSopenharmony_ci		return "dst_colr";
1208d722e3fbSopenharmony_ci	case 10:
1209d722e3fbSopenharmony_ci		return "inv_dst_colr";
1210d722e3fbSopenharmony_ci	case 11:
1211d722e3fbSopenharmony_ci		return "src_alpha_sat";
1212d722e3fbSopenharmony_ci	case 12:
1213d722e3fbSopenharmony_ci		return "cnst_colr";
1214d722e3fbSopenharmony_ci	case 13:
1215d722e3fbSopenharmony_ci		return "inv_cnst_colr";
1216d722e3fbSopenharmony_ci	case 14:
1217d722e3fbSopenharmony_ci		return "cnst_alpha";
1218d722e3fbSopenharmony_ci	case 15:
1219d722e3fbSopenharmony_ci		return "inv_const_alpha";
1220d722e3fbSopenharmony_ci	}
1221d722e3fbSopenharmony_ci	return "";
1222d722e3fbSopenharmony_ci}
1223d722e3fbSopenharmony_ci
1224d722e3fbSopenharmony_cistatic const char *
1225d722e3fbSopenharmony_cidecode_tex_coord_mode(uint32_t mode)
1226d722e3fbSopenharmony_ci{
1227d722e3fbSopenharmony_ci	switch (mode & 0x7) {
1228d722e3fbSopenharmony_ci	case 0:
1229d722e3fbSopenharmony_ci		return "wrap";
1230d722e3fbSopenharmony_ci	case 1:
1231d722e3fbSopenharmony_ci		return "mirror";
1232d722e3fbSopenharmony_ci	case 2:
1233d722e3fbSopenharmony_ci		return "clamp_edge";
1234d722e3fbSopenharmony_ci	case 3:
1235d722e3fbSopenharmony_ci		return "cube";
1236d722e3fbSopenharmony_ci	case 4:
1237d722e3fbSopenharmony_ci		return "clamp_border";
1238d722e3fbSopenharmony_ci	case 5:
1239d722e3fbSopenharmony_ci		return "mirror_once";
1240d722e3fbSopenharmony_ci	}
1241d722e3fbSopenharmony_ci	return "";
1242d722e3fbSopenharmony_ci}
1243d722e3fbSopenharmony_ci
1244d722e3fbSopenharmony_cistatic const char *
1245d722e3fbSopenharmony_cidecode_sample_filter(uint32_t mode)
1246d722e3fbSopenharmony_ci{
1247d722e3fbSopenharmony_ci	switch (mode & 0x7) {
1248d722e3fbSopenharmony_ci	case 0:
1249d722e3fbSopenharmony_ci		return "nearest";
1250d722e3fbSopenharmony_ci	case 1:
1251d722e3fbSopenharmony_ci		return "linear";
1252d722e3fbSopenharmony_ci	case 2:
1253d722e3fbSopenharmony_ci		return "anisotropic";
1254d722e3fbSopenharmony_ci	case 3:
1255d722e3fbSopenharmony_ci		return "4x4_1";
1256d722e3fbSopenharmony_ci	case 4:
1257d722e3fbSopenharmony_ci		return "4x4_2";
1258d722e3fbSopenharmony_ci	case 5:
1259d722e3fbSopenharmony_ci		return "4x4_flat";
1260d722e3fbSopenharmony_ci	case 6:
1261d722e3fbSopenharmony_ci		return "6x5_mono";
1262d722e3fbSopenharmony_ci	}
1263d722e3fbSopenharmony_ci	return "";
1264d722e3fbSopenharmony_ci}
1265d722e3fbSopenharmony_ci
1266d722e3fbSopenharmony_cistatic int
1267d722e3fbSopenharmony_cidecode_3d_1d(struct drm_intel_decode *ctx)
1268d722e3fbSopenharmony_ci{
1269d722e3fbSopenharmony_ci	unsigned int len, i, c, idx, word, map, sampler, instr;
1270d722e3fbSopenharmony_ci	const char *format, *zformat, *type;
1271d722e3fbSopenharmony_ci	uint32_t opcode;
1272d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
1273d722e3fbSopenharmony_ci	uint32_t devid = ctx->devid;
1274d722e3fbSopenharmony_ci
1275d722e3fbSopenharmony_ci	struct {
1276d722e3fbSopenharmony_ci		uint32_t opcode;
1277d722e3fbSopenharmony_ci		int i830_only;
1278d722e3fbSopenharmony_ci		unsigned int min_len;
1279d722e3fbSopenharmony_ci		unsigned int max_len;
1280d722e3fbSopenharmony_ci		const char *name;
1281d722e3fbSopenharmony_ci	} opcodes_3d_1d[] = {
1282d722e3fbSopenharmony_ci		{ 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" },
1283d722e3fbSopenharmony_ci		{ 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
1284d722e3fbSopenharmony_ci		{ 0x99, 0, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
1285d722e3fbSopenharmony_ci		{ 0x9a, 0, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
1286d722e3fbSopenharmony_ci		{ 0x98, 0, 2, 2, "3DSTATE_DEFAULT_Z" },
1287d722e3fbSopenharmony_ci		{ 0x97, 0, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
1288d722e3fbSopenharmony_ci		{ 0x9d, 0, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
1289d722e3fbSopenharmony_ci		{ 0x9e, 0, 4, 4, "3DSTATE_MONO_FILTER" },
1290d722e3fbSopenharmony_ci		{ 0x89, 0, 4, 4, "3DSTATE_FOG_MODE" },
1291d722e3fbSopenharmony_ci		{ 0x8f, 0, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
1292d722e3fbSopenharmony_ci		{ 0x83, 0, 2, 2, "3DSTATE_SPAN_STIPPLE" },
1293d722e3fbSopenharmony_ci		{ 0x8c, 1, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM_I830" },
1294d722e3fbSopenharmony_ci		{ 0x8b, 1, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM_I830" },
1295d722e3fbSopenharmony_ci		{ 0x8d, 1, 3, 3, "3DSTATE_W_STATE_I830" },
1296d722e3fbSopenharmony_ci		{ 0x01, 1, 2, 2, "3DSTATE_COLOR_FACTOR_I830" },
1297d722e3fbSopenharmony_ci		{ 0x02, 1, 2, 2, "3DSTATE_MAP_COORD_SETBIND_I830"},
1298d722e3fbSopenharmony_ci	}, *opcode_3d_1d;
1299d722e3fbSopenharmony_ci
1300d722e3fbSopenharmony_ci	opcode = (data[0] & 0x00ff0000) >> 16;
1301d722e3fbSopenharmony_ci
1302d722e3fbSopenharmony_ci	switch (opcode) {
1303d722e3fbSopenharmony_ci	case 0x07:
1304d722e3fbSopenharmony_ci		/* This instruction is unusual.  A 0 length means just
1305d722e3fbSopenharmony_ci		 * 1 DWORD instead of 2.  The 0 length is specified in
1306d722e3fbSopenharmony_ci		 * one place to be unsupported, but stated to be
1307d722e3fbSopenharmony_ci		 * required in another, and 0 length LOAD_INDIRECTs
1308d722e3fbSopenharmony_ci		 * appear to cause no harm at least.
1309d722e3fbSopenharmony_ci		 */
1310d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_LOAD_INDIRECT\n");
1311d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 1;
1312d722e3fbSopenharmony_ci		i = 1;
1313d722e3fbSopenharmony_ci		if (data[0] & (0x01 << 8)) {
1314d722e3fbSopenharmony_ci			instr_out(ctx, i++, "SIS.0\n");
1315d722e3fbSopenharmony_ci			instr_out(ctx, i++, "SIS.1\n");
1316d722e3fbSopenharmony_ci		}
1317d722e3fbSopenharmony_ci		if (data[0] & (0x02 << 8)) {
1318d722e3fbSopenharmony_ci			instr_out(ctx, i++, "DIS.0\n");
1319d722e3fbSopenharmony_ci		}
1320d722e3fbSopenharmony_ci		if (data[0] & (0x04 << 8)) {
1321d722e3fbSopenharmony_ci			instr_out(ctx, i++, "SSB.0\n");
1322d722e3fbSopenharmony_ci			instr_out(ctx, i++, "SSB.1\n");
1323d722e3fbSopenharmony_ci		}
1324d722e3fbSopenharmony_ci		if (data[0] & (0x08 << 8)) {
1325d722e3fbSopenharmony_ci			instr_out(ctx, i++, "MSB.0\n");
1326d722e3fbSopenharmony_ci			instr_out(ctx, i++, "MSB.1\n");
1327d722e3fbSopenharmony_ci		}
1328d722e3fbSopenharmony_ci		if (data[0] & (0x10 << 8)) {
1329d722e3fbSopenharmony_ci			instr_out(ctx, i++, "PSP.0\n");
1330d722e3fbSopenharmony_ci			instr_out(ctx, i++, "PSP.1\n");
1331d722e3fbSopenharmony_ci		}
1332d722e3fbSopenharmony_ci		if (data[0] & (0x20 << 8)) {
1333d722e3fbSopenharmony_ci			instr_out(ctx, i++, "PSC.0\n");
1334d722e3fbSopenharmony_ci			instr_out(ctx, i++, "PSC.1\n");
1335d722e3fbSopenharmony_ci		}
1336d722e3fbSopenharmony_ci		if (len != i) {
1337d722e3fbSopenharmony_ci			fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
1338d722e3fbSopenharmony_ci			return len;
1339d722e3fbSopenharmony_ci		}
1340d722e3fbSopenharmony_ci		return len;
1341d722e3fbSopenharmony_ci	case 0x04:
1342d722e3fbSopenharmony_ci		instr_out(ctx, 0,
1343d722e3fbSopenharmony_ci			  "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
1344d722e3fbSopenharmony_ci		len = (data[0] & 0x0000000f) + 2;
1345d722e3fbSopenharmony_ci		i = 1;
1346d722e3fbSopenharmony_ci		for (word = 0; word <= 8; word++) {
1347d722e3fbSopenharmony_ci			if (data[0] & (1 << (4 + word))) {
1348d722e3fbSopenharmony_ci				/* save vertex state for decode */
1349d722e3fbSopenharmony_ci				if (!IS_GEN2(devid)) {
1350d722e3fbSopenharmony_ci					int tex_num;
1351d722e3fbSopenharmony_ci
1352d722e3fbSopenharmony_ci					if (word == 2) {
1353d722e3fbSopenharmony_ci						saved_s2_set = 1;
1354d722e3fbSopenharmony_ci						saved_s2 = data[i];
1355d722e3fbSopenharmony_ci					}
1356d722e3fbSopenharmony_ci					if (word == 4) {
1357d722e3fbSopenharmony_ci						saved_s4_set = 1;
1358d722e3fbSopenharmony_ci						saved_s4 = data[i];
1359d722e3fbSopenharmony_ci					}
1360d722e3fbSopenharmony_ci
1361d722e3fbSopenharmony_ci					switch (word) {
1362d722e3fbSopenharmony_ci					case 0:
1363d722e3fbSopenharmony_ci						instr_out(ctx, i,
1364d722e3fbSopenharmony_ci							  "S0: vbo offset: 0x%08x%s\n",
1365d722e3fbSopenharmony_ci							  data[i] & (~1),
1366d722e3fbSopenharmony_ci							  data[i] & 1 ?
1367d722e3fbSopenharmony_ci							  ", auto cache invalidate disabled"
1368d722e3fbSopenharmony_ci							  : "");
1369d722e3fbSopenharmony_ci						break;
1370d722e3fbSopenharmony_ci					case 1:
1371d722e3fbSopenharmony_ci						instr_out(ctx, i,
1372d722e3fbSopenharmony_ci							  "S1: vertex width: %i, vertex pitch: %i\n",
1373d722e3fbSopenharmony_ci							  (data[i] >> 24) &
1374d722e3fbSopenharmony_ci							  0x3f,
1375d722e3fbSopenharmony_ci							  (data[i] >> 16) &
1376d722e3fbSopenharmony_ci							  0x3f);
1377d722e3fbSopenharmony_ci						break;
1378d722e3fbSopenharmony_ci					case 2:
1379d722e3fbSopenharmony_ci						instr_out(ctx, i,
1380d722e3fbSopenharmony_ci							  "S2: texcoord formats: ");
1381d722e3fbSopenharmony_ci						for (tex_num = 0;
1382d722e3fbSopenharmony_ci						     tex_num < 8; tex_num++) {
1383d722e3fbSopenharmony_ci							switch ((data[i] >>
1384d722e3fbSopenharmony_ci								 tex_num *
1385d722e3fbSopenharmony_ci								 4) & 0xf) {
1386d722e3fbSopenharmony_ci							case 0:
1387d722e3fbSopenharmony_ci								fprintf(out,
1388d722e3fbSopenharmony_ci									"%i=2D ",
1389d722e3fbSopenharmony_ci									tex_num);
1390d722e3fbSopenharmony_ci								break;
1391d722e3fbSopenharmony_ci							case 1:
1392d722e3fbSopenharmony_ci								fprintf(out,
1393d722e3fbSopenharmony_ci									"%i=3D ",
1394d722e3fbSopenharmony_ci									tex_num);
1395d722e3fbSopenharmony_ci								break;
1396d722e3fbSopenharmony_ci							case 2:
1397d722e3fbSopenharmony_ci								fprintf(out,
1398d722e3fbSopenharmony_ci									"%i=4D ",
1399d722e3fbSopenharmony_ci									tex_num);
1400d722e3fbSopenharmony_ci								break;
1401d722e3fbSopenharmony_ci							case 3:
1402d722e3fbSopenharmony_ci								fprintf(out,
1403d722e3fbSopenharmony_ci									"%i=1D ",
1404d722e3fbSopenharmony_ci									tex_num);
1405d722e3fbSopenharmony_ci								break;
1406d722e3fbSopenharmony_ci							case 4:
1407d722e3fbSopenharmony_ci								fprintf(out,
1408d722e3fbSopenharmony_ci									"%i=2D_16 ",
1409d722e3fbSopenharmony_ci									tex_num);
1410d722e3fbSopenharmony_ci								break;
1411d722e3fbSopenharmony_ci							case 5:
1412d722e3fbSopenharmony_ci								fprintf(out,
1413d722e3fbSopenharmony_ci									"%i=4D_16 ",
1414d722e3fbSopenharmony_ci									tex_num);
1415d722e3fbSopenharmony_ci								break;
1416d722e3fbSopenharmony_ci							case 0xf:
1417d722e3fbSopenharmony_ci								fprintf(out,
1418d722e3fbSopenharmony_ci									"%i=NP ",
1419d722e3fbSopenharmony_ci									tex_num);
1420d722e3fbSopenharmony_ci								break;
1421d722e3fbSopenharmony_ci							}
1422d722e3fbSopenharmony_ci						}
1423d722e3fbSopenharmony_ci						fprintf(out, "\n");
1424d722e3fbSopenharmony_ci
1425d722e3fbSopenharmony_ci						break;
1426d722e3fbSopenharmony_ci					case 3:
1427d722e3fbSopenharmony_ci						instr_out(ctx, i,
1428d722e3fbSopenharmony_ci							  "S3: not documented\n");
1429d722e3fbSopenharmony_ci						break;
1430d722e3fbSopenharmony_ci					case 4:
1431d722e3fbSopenharmony_ci						{
1432d722e3fbSopenharmony_ci							const char *cullmode = "";
1433d722e3fbSopenharmony_ci							const char *vfmt_xyzw = "";
1434d722e3fbSopenharmony_ci							switch ((data[i] >> 13)
1435d722e3fbSopenharmony_ci								& 0x3) {
1436d722e3fbSopenharmony_ci							case 0:
1437d722e3fbSopenharmony_ci								cullmode =
1438d722e3fbSopenharmony_ci								    "both";
1439d722e3fbSopenharmony_ci								break;
1440d722e3fbSopenharmony_ci							case 1:
1441d722e3fbSopenharmony_ci								cullmode =
1442d722e3fbSopenharmony_ci								    "none";
1443d722e3fbSopenharmony_ci								break;
1444d722e3fbSopenharmony_ci							case 2:
1445d722e3fbSopenharmony_ci								cullmode = "cw";
1446d722e3fbSopenharmony_ci								break;
1447d722e3fbSopenharmony_ci							case 3:
1448d722e3fbSopenharmony_ci								cullmode =
1449d722e3fbSopenharmony_ci								    "ccw";
1450d722e3fbSopenharmony_ci								break;
1451d722e3fbSopenharmony_ci							}
1452d722e3fbSopenharmony_ci							switch (data[i] &
1453d722e3fbSopenharmony_ci								(7 << 6 | 1 <<
1454d722e3fbSopenharmony_ci								 2)) {
1455d722e3fbSopenharmony_ci							case 1 << 6:
1456d722e3fbSopenharmony_ci								vfmt_xyzw =
1457d722e3fbSopenharmony_ci								    "XYZ,";
1458d722e3fbSopenharmony_ci								break;
1459d722e3fbSopenharmony_ci							case 2 << 6:
1460d722e3fbSopenharmony_ci								vfmt_xyzw =
1461d722e3fbSopenharmony_ci								    "XYZW,";
1462d722e3fbSopenharmony_ci								break;
1463d722e3fbSopenharmony_ci							case 3 << 6:
1464d722e3fbSopenharmony_ci								vfmt_xyzw =
1465d722e3fbSopenharmony_ci								    "XY,";
1466d722e3fbSopenharmony_ci								break;
1467d722e3fbSopenharmony_ci							case 4 << 6:
1468d722e3fbSopenharmony_ci								vfmt_xyzw =
1469d722e3fbSopenharmony_ci								    "XYW,";
1470d722e3fbSopenharmony_ci								break;
1471d722e3fbSopenharmony_ci							case 1 << 6 | 1 << 2:
1472d722e3fbSopenharmony_ci								vfmt_xyzw =
1473d722e3fbSopenharmony_ci								    "XYZF,";
1474d722e3fbSopenharmony_ci								break;
1475d722e3fbSopenharmony_ci							case 2 << 6 | 1 << 2:
1476d722e3fbSopenharmony_ci								vfmt_xyzw =
1477d722e3fbSopenharmony_ci								    "XYZWF,";
1478d722e3fbSopenharmony_ci								break;
1479d722e3fbSopenharmony_ci							case 3 << 6 | 1 << 2:
1480d722e3fbSopenharmony_ci								vfmt_xyzw =
1481d722e3fbSopenharmony_ci								    "XYF,";
1482d722e3fbSopenharmony_ci								break;
1483d722e3fbSopenharmony_ci							case 4 << 6 | 1 << 2:
1484d722e3fbSopenharmony_ci								vfmt_xyzw =
1485d722e3fbSopenharmony_ci								    "XYWF,";
1486d722e3fbSopenharmony_ci								break;
1487d722e3fbSopenharmony_ci							}
1488d722e3fbSopenharmony_ci							instr_out(ctx, i,
1489d722e3fbSopenharmony_ci								  "S4: point_width=%i, line_width=%.1f,"
1490d722e3fbSopenharmony_ci								  "%s%s%s%s%s cullmode=%s, vfmt=%s%s%s%s%s%s "
1491d722e3fbSopenharmony_ci								  "%s%s%s%s%s\n",
1492d722e3fbSopenharmony_ci								  (data[i] >>
1493d722e3fbSopenharmony_ci								   23) & 0x1ff,
1494d722e3fbSopenharmony_ci								  ((data[i] >>
1495d722e3fbSopenharmony_ci								    19) & 0xf) /
1496d722e3fbSopenharmony_ci								  2.0,
1497d722e3fbSopenharmony_ci								  data[i] & (0xf
1498d722e3fbSopenharmony_ci									     <<
1499d722e3fbSopenharmony_ci									     15)
1500d722e3fbSopenharmony_ci								  ?
1501d722e3fbSopenharmony_ci								  " flatshade="
1502d722e3fbSopenharmony_ci								  : "",
1503d722e3fbSopenharmony_ci								  data[i] & (1
1504d722e3fbSopenharmony_ci									     <<
1505d722e3fbSopenharmony_ci									     18)
1506d722e3fbSopenharmony_ci								  ? "Alpha," :
1507d722e3fbSopenharmony_ci								  "",
1508d722e3fbSopenharmony_ci								  data[i] & (1
1509d722e3fbSopenharmony_ci									     <<
1510d722e3fbSopenharmony_ci									     17)
1511d722e3fbSopenharmony_ci								  ? "Fog," : "",
1512d722e3fbSopenharmony_ci								  data[i] & (1
1513d722e3fbSopenharmony_ci									     <<
1514d722e3fbSopenharmony_ci									     16)
1515d722e3fbSopenharmony_ci								  ? "Specular,"
1516d722e3fbSopenharmony_ci								  : "",
1517d722e3fbSopenharmony_ci								  data[i] & (1
1518d722e3fbSopenharmony_ci									     <<
1519d722e3fbSopenharmony_ci									     15)
1520d722e3fbSopenharmony_ci								  ? "Color," :
1521d722e3fbSopenharmony_ci								  "", cullmode,
1522d722e3fbSopenharmony_ci								  data[i] & (1
1523d722e3fbSopenharmony_ci									     <<
1524d722e3fbSopenharmony_ci									     12)
1525d722e3fbSopenharmony_ci								  ?
1526d722e3fbSopenharmony_ci								  "PointWidth,"
1527d722e3fbSopenharmony_ci								  : "",
1528d722e3fbSopenharmony_ci								  data[i] & (1
1529d722e3fbSopenharmony_ci									     <<
1530d722e3fbSopenharmony_ci									     11)
1531d722e3fbSopenharmony_ci								  ? "SpecFog," :
1532d722e3fbSopenharmony_ci								  "",
1533d722e3fbSopenharmony_ci								  data[i] & (1
1534d722e3fbSopenharmony_ci									     <<
1535d722e3fbSopenharmony_ci									     10)
1536d722e3fbSopenharmony_ci								  ? "Color," :
1537d722e3fbSopenharmony_ci								  "",
1538d722e3fbSopenharmony_ci								  data[i] & (1
1539d722e3fbSopenharmony_ci									     <<
1540d722e3fbSopenharmony_ci									     9)
1541d722e3fbSopenharmony_ci								  ? "DepthOfs,"
1542d722e3fbSopenharmony_ci								  : "",
1543d722e3fbSopenharmony_ci								  vfmt_xyzw,
1544d722e3fbSopenharmony_ci								  data[i] & (1
1545d722e3fbSopenharmony_ci									     <<
1546d722e3fbSopenharmony_ci									     9)
1547d722e3fbSopenharmony_ci								  ? "FogParam,"
1548d722e3fbSopenharmony_ci								  : "",
1549d722e3fbSopenharmony_ci								  data[i] & (1
1550d722e3fbSopenharmony_ci									     <<
1551d722e3fbSopenharmony_ci									     5)
1552d722e3fbSopenharmony_ci								  ?
1553d722e3fbSopenharmony_ci								  "force default diffuse, "
1554d722e3fbSopenharmony_ci								  : "",
1555d722e3fbSopenharmony_ci								  data[i] & (1
1556d722e3fbSopenharmony_ci									     <<
1557d722e3fbSopenharmony_ci									     4)
1558d722e3fbSopenharmony_ci								  ?
1559d722e3fbSopenharmony_ci								  "force default specular, "
1560d722e3fbSopenharmony_ci								  : "",
1561d722e3fbSopenharmony_ci								  data[i] & (1
1562d722e3fbSopenharmony_ci									     <<
1563d722e3fbSopenharmony_ci									     3)
1564d722e3fbSopenharmony_ci								  ?
1565d722e3fbSopenharmony_ci								  "local depth ofs enable, "
1566d722e3fbSopenharmony_ci								  : "",
1567d722e3fbSopenharmony_ci								  data[i] & (1
1568d722e3fbSopenharmony_ci									     <<
1569d722e3fbSopenharmony_ci									     1)
1570d722e3fbSopenharmony_ci								  ?
1571d722e3fbSopenharmony_ci								  "point sprite enable, "
1572d722e3fbSopenharmony_ci								  : "",
1573d722e3fbSopenharmony_ci								  data[i] & (1
1574d722e3fbSopenharmony_ci									     <<
1575d722e3fbSopenharmony_ci									     0)
1576d722e3fbSopenharmony_ci								  ?
1577d722e3fbSopenharmony_ci								  "line AA enable, "
1578d722e3fbSopenharmony_ci								  : "");
1579d722e3fbSopenharmony_ci							break;
1580d722e3fbSopenharmony_ci						}
1581d722e3fbSopenharmony_ci					case 5:
1582d722e3fbSopenharmony_ci						{
1583d722e3fbSopenharmony_ci							instr_out(ctx, i,
1584d722e3fbSopenharmony_ci								  "S5:%s%s%s%s%s"
1585d722e3fbSopenharmony_ci								  "%s%s%s%s stencil_ref=0x%x, stencil_test=%s, "
1586d722e3fbSopenharmony_ci								  "stencil_fail=%s, stencil_pass_z_fail=%s, "
1587d722e3fbSopenharmony_ci								  "stencil_pass_z_pass=%s, %s%s%s%s\n",
1588d722e3fbSopenharmony_ci								  data[i] & (0xf
1589d722e3fbSopenharmony_ci									     <<
1590d722e3fbSopenharmony_ci									     28)
1591d722e3fbSopenharmony_ci								  ?
1592d722e3fbSopenharmony_ci								  " write_disable="
1593d722e3fbSopenharmony_ci								  : "",
1594d722e3fbSopenharmony_ci								  data[i] & (1
1595d722e3fbSopenharmony_ci									     <<
1596d722e3fbSopenharmony_ci									     31)
1597d722e3fbSopenharmony_ci								  ? "Alpha," :
1598d722e3fbSopenharmony_ci								  "",
1599d722e3fbSopenharmony_ci								  data[i] & (1
1600d722e3fbSopenharmony_ci									     <<
1601d722e3fbSopenharmony_ci									     30)
1602d722e3fbSopenharmony_ci								  ? "Red," : "",
1603d722e3fbSopenharmony_ci								  data[i] & (1
1604d722e3fbSopenharmony_ci									     <<
1605d722e3fbSopenharmony_ci									     29)
1606d722e3fbSopenharmony_ci								  ? "Green," :
1607d722e3fbSopenharmony_ci								  "",
1608d722e3fbSopenharmony_ci								  data[i] & (1
1609d722e3fbSopenharmony_ci									     <<
1610d722e3fbSopenharmony_ci									     28)
1611d722e3fbSopenharmony_ci								  ? "Blue," :
1612d722e3fbSopenharmony_ci								  "",
1613d722e3fbSopenharmony_ci								  data[i] & (1
1614d722e3fbSopenharmony_ci									     <<
1615d722e3fbSopenharmony_ci									     27)
1616d722e3fbSopenharmony_ci								  ?
1617d722e3fbSopenharmony_ci								  " force default point size,"
1618d722e3fbSopenharmony_ci								  : "",
1619d722e3fbSopenharmony_ci								  data[i] & (1
1620d722e3fbSopenharmony_ci									     <<
1621d722e3fbSopenharmony_ci									     26)
1622d722e3fbSopenharmony_ci								  ?
1623d722e3fbSopenharmony_ci								  " last pixel enable,"
1624d722e3fbSopenharmony_ci								  : "",
1625d722e3fbSopenharmony_ci								  data[i] & (1
1626d722e3fbSopenharmony_ci									     <<
1627d722e3fbSopenharmony_ci									     25)
1628d722e3fbSopenharmony_ci								  ?
1629d722e3fbSopenharmony_ci								  " global depth ofs enable,"
1630d722e3fbSopenharmony_ci								  : "",
1631d722e3fbSopenharmony_ci								  data[i] & (1
1632d722e3fbSopenharmony_ci									     <<
1633d722e3fbSopenharmony_ci									     24)
1634d722e3fbSopenharmony_ci								  ?
1635d722e3fbSopenharmony_ci								  " fog enable,"
1636d722e3fbSopenharmony_ci								  : "",
1637d722e3fbSopenharmony_ci								  (data[i] >>
1638d722e3fbSopenharmony_ci								   16) & 0xff,
1639d722e3fbSopenharmony_ci								  decode_compare_func
1640d722e3fbSopenharmony_ci								  (data[i] >>
1641d722e3fbSopenharmony_ci								   13),
1642d722e3fbSopenharmony_ci								  decode_stencil_op
1643d722e3fbSopenharmony_ci								  (data[i] >>
1644d722e3fbSopenharmony_ci								   10),
1645d722e3fbSopenharmony_ci								  decode_stencil_op
1646d722e3fbSopenharmony_ci								  (data[i] >>
1647d722e3fbSopenharmony_ci								   7),
1648d722e3fbSopenharmony_ci								  decode_stencil_op
1649d722e3fbSopenharmony_ci								  (data[i] >>
1650d722e3fbSopenharmony_ci								   4),
1651d722e3fbSopenharmony_ci								  data[i] & (1
1652d722e3fbSopenharmony_ci									     <<
1653d722e3fbSopenharmony_ci									     3)
1654d722e3fbSopenharmony_ci								  ?
1655d722e3fbSopenharmony_ci								  "stencil write enable, "
1656d722e3fbSopenharmony_ci								  : "",
1657d722e3fbSopenharmony_ci								  data[i] & (1
1658d722e3fbSopenharmony_ci									     <<
1659d722e3fbSopenharmony_ci									     2)
1660d722e3fbSopenharmony_ci								  ?
1661d722e3fbSopenharmony_ci								  "stencil test enable, "
1662d722e3fbSopenharmony_ci								  : "",
1663d722e3fbSopenharmony_ci								  data[i] & (1
1664d722e3fbSopenharmony_ci									     <<
1665d722e3fbSopenharmony_ci									     1)
1666d722e3fbSopenharmony_ci								  ?
1667d722e3fbSopenharmony_ci								  "color dither enable, "
1668d722e3fbSopenharmony_ci								  : "",
1669d722e3fbSopenharmony_ci								  data[i] & (1
1670d722e3fbSopenharmony_ci									     <<
1671d722e3fbSopenharmony_ci									     0)
1672d722e3fbSopenharmony_ci								  ?
1673d722e3fbSopenharmony_ci								  "logicop enable, "
1674d722e3fbSopenharmony_ci								  : "");
1675d722e3fbSopenharmony_ci						}
1676d722e3fbSopenharmony_ci						break;
1677d722e3fbSopenharmony_ci					case 6:
1678d722e3fbSopenharmony_ci						instr_out(ctx, i,
1679d722e3fbSopenharmony_ci							  "S6: %salpha_test=%s, alpha_ref=0x%x, "
1680d722e3fbSopenharmony_ci							  "depth_test=%s, %ssrc_blnd_fct=%s, dst_blnd_fct=%s, "
1681d722e3fbSopenharmony_ci							  "%s%stristrip_provoking_vertex=%i\n",
1682d722e3fbSopenharmony_ci							  data[i] & (1 << 31) ?
1683d722e3fbSopenharmony_ci							  "alpha test enable, "
1684d722e3fbSopenharmony_ci							  : "",
1685d722e3fbSopenharmony_ci							  decode_compare_func
1686d722e3fbSopenharmony_ci							  (data[i] >> 28),
1687d722e3fbSopenharmony_ci							  data[i] & (0xff <<
1688d722e3fbSopenharmony_ci								     20),
1689d722e3fbSopenharmony_ci							  decode_compare_func
1690d722e3fbSopenharmony_ci							  (data[i] >> 16),
1691d722e3fbSopenharmony_ci							  data[i] & (1 << 15) ?
1692d722e3fbSopenharmony_ci							  "cbuf blend enable, "
1693d722e3fbSopenharmony_ci							  : "",
1694d722e3fbSopenharmony_ci							  decode_blend_fact(data
1695d722e3fbSopenharmony_ci									    [i]
1696d722e3fbSopenharmony_ci									    >>
1697d722e3fbSopenharmony_ci									    8),
1698d722e3fbSopenharmony_ci							  decode_blend_fact(data
1699d722e3fbSopenharmony_ci									    [i]
1700d722e3fbSopenharmony_ci									    >>
1701d722e3fbSopenharmony_ci									    4),
1702d722e3fbSopenharmony_ci							  data[i] & (1 << 3) ?
1703d722e3fbSopenharmony_ci							  "depth write enable, "
1704d722e3fbSopenharmony_ci							  : "",
1705d722e3fbSopenharmony_ci							  data[i] & (1 << 2) ?
1706d722e3fbSopenharmony_ci							  "cbuf write enable, "
1707d722e3fbSopenharmony_ci							  : "",
1708d722e3fbSopenharmony_ci							  data[i] & (0x3));
1709d722e3fbSopenharmony_ci						break;
1710d722e3fbSopenharmony_ci					case 7:
1711d722e3fbSopenharmony_ci						instr_out(ctx, i,
1712d722e3fbSopenharmony_ci							  "S7: depth offset constant: 0x%08x\n",
1713d722e3fbSopenharmony_ci							  data[i]);
1714d722e3fbSopenharmony_ci						break;
1715d722e3fbSopenharmony_ci					}
1716d722e3fbSopenharmony_ci				} else {
1717d722e3fbSopenharmony_ci					instr_out(ctx, i,
1718d722e3fbSopenharmony_ci						  "S%d: 0x%08x\n", word, data[i]);
1719d722e3fbSopenharmony_ci				}
1720d722e3fbSopenharmony_ci				i++;
1721d722e3fbSopenharmony_ci			}
1722d722e3fbSopenharmony_ci		}
1723d722e3fbSopenharmony_ci		if (len != i) {
1724d722e3fbSopenharmony_ci			fprintf(out,
1725d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
1726d722e3fbSopenharmony_ci		}
1727d722e3fbSopenharmony_ci		return len;
1728d722e3fbSopenharmony_ci	case 0x03:
1729d722e3fbSopenharmony_ci		instr_out(ctx, 0,
1730d722e3fbSopenharmony_ci			  "3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
1731d722e3fbSopenharmony_ci		len = (data[0] & 0x0000000f) + 2;
1732d722e3fbSopenharmony_ci		i = 1;
1733d722e3fbSopenharmony_ci		for (word = 6; word <= 14; word++) {
1734d722e3fbSopenharmony_ci			if (data[0] & (1 << word)) {
1735d722e3fbSopenharmony_ci				if (word == 6)
1736d722e3fbSopenharmony_ci					instr_out(ctx, i++,
1737d722e3fbSopenharmony_ci						  "TBCF\n");
1738d722e3fbSopenharmony_ci				else if (word >= 7 && word <= 10) {
1739d722e3fbSopenharmony_ci					instr_out(ctx, i++,
1740d722e3fbSopenharmony_ci						  "TB%dC\n", word - 7);
1741d722e3fbSopenharmony_ci					instr_out(ctx, i++,
1742d722e3fbSopenharmony_ci						  "TB%dA\n", word - 7);
1743d722e3fbSopenharmony_ci				} else if (word >= 11 && word <= 14) {
1744d722e3fbSopenharmony_ci					instr_out(ctx, i,
1745d722e3fbSopenharmony_ci						  "TM%dS0: offset=0x%08x, %s\n",
1746d722e3fbSopenharmony_ci						  word - 11,
1747d722e3fbSopenharmony_ci						  data[i] & 0xfffffffe,
1748d722e3fbSopenharmony_ci						  data[i] & 1 ? "use fence" :
1749d722e3fbSopenharmony_ci						  "");
1750d722e3fbSopenharmony_ci					i++;
1751d722e3fbSopenharmony_ci					instr_out(ctx, i,
1752d722e3fbSopenharmony_ci						  "TM%dS1: height=%i, width=%i, %s\n",
1753d722e3fbSopenharmony_ci						  word - 11, data[i] >> 21,
1754d722e3fbSopenharmony_ci						  (data[i] >> 10) & 0x3ff,
1755d722e3fbSopenharmony_ci						  data[i] & 2 ? (data[i] & 1 ?
1756d722e3fbSopenharmony_ci								 "y-tiled" :
1757d722e3fbSopenharmony_ci								 "x-tiled") :
1758d722e3fbSopenharmony_ci						  "");
1759d722e3fbSopenharmony_ci					i++;
1760d722e3fbSopenharmony_ci					instr_out(ctx, i,
1761d722e3fbSopenharmony_ci						  "TM%dS2: pitch=%i, \n",
1762d722e3fbSopenharmony_ci						  word - 11,
1763d722e3fbSopenharmony_ci						  ((data[i] >> 21) + 1) * 4);
1764d722e3fbSopenharmony_ci					i++;
1765d722e3fbSopenharmony_ci					instr_out(ctx, i++,
1766d722e3fbSopenharmony_ci						  "TM%dS3\n", word - 11);
1767d722e3fbSopenharmony_ci					instr_out(ctx, i++,
1768d722e3fbSopenharmony_ci						  "TM%dS4: dflt color\n",
1769d722e3fbSopenharmony_ci						  word - 11);
1770d722e3fbSopenharmony_ci				}
1771d722e3fbSopenharmony_ci			}
1772d722e3fbSopenharmony_ci		}
1773d722e3fbSopenharmony_ci		if (len != i) {
1774d722e3fbSopenharmony_ci			fprintf(out,
1775d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
1776d722e3fbSopenharmony_ci		}
1777d722e3fbSopenharmony_ci		return len;
1778d722e3fbSopenharmony_ci	case 0x00:
1779d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_MAP_STATE\n");
1780d722e3fbSopenharmony_ci		len = (data[0] & 0x0000003f) + 2;
1781d722e3fbSopenharmony_ci		instr_out(ctx, 1, "mask\n");
1782d722e3fbSopenharmony_ci
1783d722e3fbSopenharmony_ci		i = 2;
1784d722e3fbSopenharmony_ci		for (map = 0; map <= 15; map++) {
1785d722e3fbSopenharmony_ci			if (data[1] & (1 << map)) {
1786d722e3fbSopenharmony_ci				int width, height, pitch, dword;
1787d722e3fbSopenharmony_ci				const char *tiling;
1788d722e3fbSopenharmony_ci
1789d722e3fbSopenharmony_ci				dword = data[i];
1790d722e3fbSopenharmony_ci				instr_out(ctx, i++,
1791d722e3fbSopenharmony_ci					  "map %d MS2 %s%s%s\n", map,
1792d722e3fbSopenharmony_ci					  dword & (1 << 31) ?
1793d722e3fbSopenharmony_ci					  "untrusted surface, " : "",
1794d722e3fbSopenharmony_ci					  dword & (1 << 1) ?
1795d722e3fbSopenharmony_ci					  "vertical line stride enable, " : "",
1796d722e3fbSopenharmony_ci					  dword & (1 << 0) ?
1797d722e3fbSopenharmony_ci					  "vertical ofs enable, " : "");
1798d722e3fbSopenharmony_ci
1799d722e3fbSopenharmony_ci				dword = data[i];
1800d722e3fbSopenharmony_ci				width = ((dword >> 10) & ((1 << 11) - 1)) + 1;
1801d722e3fbSopenharmony_ci				height = ((dword >> 21) & ((1 << 11) - 1)) + 1;
1802d722e3fbSopenharmony_ci
1803d722e3fbSopenharmony_ci				tiling = "none";
1804d722e3fbSopenharmony_ci				if (dword & (1 << 2))
1805d722e3fbSopenharmony_ci					tiling = "fenced";
1806d722e3fbSopenharmony_ci				else if (dword & (1 << 1))
1807d722e3fbSopenharmony_ci					tiling = dword & (1 << 0) ? "Y" : "X";
1808d722e3fbSopenharmony_ci				type = " BAD";
1809d722e3fbSopenharmony_ci				format = "BAD";
1810d722e3fbSopenharmony_ci				switch ((dword >> 7) & 0x7) {
1811d722e3fbSopenharmony_ci				case 1:
1812d722e3fbSopenharmony_ci					type = "8b";
1813d722e3fbSopenharmony_ci					switch ((dword >> 3) & 0xf) {
1814d722e3fbSopenharmony_ci					case 0:
1815d722e3fbSopenharmony_ci						format = "I";
1816d722e3fbSopenharmony_ci						break;
1817d722e3fbSopenharmony_ci					case 1:
1818d722e3fbSopenharmony_ci						format = "L";
1819d722e3fbSopenharmony_ci						break;
1820d722e3fbSopenharmony_ci					case 4:
1821d722e3fbSopenharmony_ci						format = "A";
1822d722e3fbSopenharmony_ci						break;
1823d722e3fbSopenharmony_ci					case 5:
1824d722e3fbSopenharmony_ci						format = " mono";
1825d722e3fbSopenharmony_ci						break;
1826d722e3fbSopenharmony_ci					}
1827d722e3fbSopenharmony_ci					break;
1828d722e3fbSopenharmony_ci				case 2:
1829d722e3fbSopenharmony_ci					type = "16b";
1830d722e3fbSopenharmony_ci					switch ((dword >> 3) & 0xf) {
1831d722e3fbSopenharmony_ci					case 0:
1832d722e3fbSopenharmony_ci						format = " rgb565";
1833d722e3fbSopenharmony_ci						break;
1834d722e3fbSopenharmony_ci					case 1:
1835d722e3fbSopenharmony_ci						format = " argb1555";
1836d722e3fbSopenharmony_ci						break;
1837d722e3fbSopenharmony_ci					case 2:
1838d722e3fbSopenharmony_ci						format = " argb4444";
1839d722e3fbSopenharmony_ci						break;
1840d722e3fbSopenharmony_ci					case 5:
1841d722e3fbSopenharmony_ci						format = " ay88";
1842d722e3fbSopenharmony_ci						break;
1843d722e3fbSopenharmony_ci					case 6:
1844d722e3fbSopenharmony_ci						format = " bump655";
1845d722e3fbSopenharmony_ci						break;
1846d722e3fbSopenharmony_ci					case 7:
1847d722e3fbSopenharmony_ci						format = "I";
1848d722e3fbSopenharmony_ci						break;
1849d722e3fbSopenharmony_ci					case 8:
1850d722e3fbSopenharmony_ci						format = "L";
1851d722e3fbSopenharmony_ci						break;
1852d722e3fbSopenharmony_ci					case 9:
1853d722e3fbSopenharmony_ci						format = "A";
1854d722e3fbSopenharmony_ci						break;
1855d722e3fbSopenharmony_ci					}
1856d722e3fbSopenharmony_ci					break;
1857d722e3fbSopenharmony_ci				case 3:
1858d722e3fbSopenharmony_ci					type = "32b";
1859d722e3fbSopenharmony_ci					switch ((dword >> 3) & 0xf) {
1860d722e3fbSopenharmony_ci					case 0:
1861d722e3fbSopenharmony_ci						format = " argb8888";
1862d722e3fbSopenharmony_ci						break;
1863d722e3fbSopenharmony_ci					case 1:
1864d722e3fbSopenharmony_ci						format = " abgr8888";
1865d722e3fbSopenharmony_ci						break;
1866d722e3fbSopenharmony_ci					case 2:
1867d722e3fbSopenharmony_ci						format = " xrgb8888";
1868d722e3fbSopenharmony_ci						break;
1869d722e3fbSopenharmony_ci					case 3:
1870d722e3fbSopenharmony_ci						format = " xbgr8888";
1871d722e3fbSopenharmony_ci						break;
1872d722e3fbSopenharmony_ci					case 4:
1873d722e3fbSopenharmony_ci						format = " qwvu8888";
1874d722e3fbSopenharmony_ci						break;
1875d722e3fbSopenharmony_ci					case 5:
1876d722e3fbSopenharmony_ci						format = " axvu8888";
1877d722e3fbSopenharmony_ci						break;
1878d722e3fbSopenharmony_ci					case 6:
1879d722e3fbSopenharmony_ci						format = " lxvu8888";
1880d722e3fbSopenharmony_ci						break;
1881d722e3fbSopenharmony_ci					case 7:
1882d722e3fbSopenharmony_ci						format = " xlvu8888";
1883d722e3fbSopenharmony_ci						break;
1884d722e3fbSopenharmony_ci					case 8:
1885d722e3fbSopenharmony_ci						format = " argb2101010";
1886d722e3fbSopenharmony_ci						break;
1887d722e3fbSopenharmony_ci					case 9:
1888d722e3fbSopenharmony_ci						format = " abgr2101010";
1889d722e3fbSopenharmony_ci						break;
1890d722e3fbSopenharmony_ci					case 10:
1891d722e3fbSopenharmony_ci						format = " awvu2101010";
1892d722e3fbSopenharmony_ci						break;
1893d722e3fbSopenharmony_ci					case 11:
1894d722e3fbSopenharmony_ci						format = " gr1616";
1895d722e3fbSopenharmony_ci						break;
1896d722e3fbSopenharmony_ci					case 12:
1897d722e3fbSopenharmony_ci						format = " vu1616";
1898d722e3fbSopenharmony_ci						break;
1899d722e3fbSopenharmony_ci					case 13:
1900d722e3fbSopenharmony_ci						format = " xI824";
1901d722e3fbSopenharmony_ci						break;
1902d722e3fbSopenharmony_ci					case 14:
1903d722e3fbSopenharmony_ci						format = " xA824";
1904d722e3fbSopenharmony_ci						break;
1905d722e3fbSopenharmony_ci					case 15:
1906d722e3fbSopenharmony_ci						format = " xL824";
1907d722e3fbSopenharmony_ci						break;
1908d722e3fbSopenharmony_ci					}
1909d722e3fbSopenharmony_ci					break;
1910d722e3fbSopenharmony_ci				case 5:
1911d722e3fbSopenharmony_ci					type = "422";
1912d722e3fbSopenharmony_ci					switch ((dword >> 3) & 0xf) {
1913d722e3fbSopenharmony_ci					case 0:
1914d722e3fbSopenharmony_ci						format = " yuv_swapy";
1915d722e3fbSopenharmony_ci						break;
1916d722e3fbSopenharmony_ci					case 1:
1917d722e3fbSopenharmony_ci						format = " yuv";
1918d722e3fbSopenharmony_ci						break;
1919d722e3fbSopenharmony_ci					case 2:
1920d722e3fbSopenharmony_ci						format = " yuv_swapuv";
1921d722e3fbSopenharmony_ci						break;
1922d722e3fbSopenharmony_ci					case 3:
1923d722e3fbSopenharmony_ci						format = " yuv_swapuvy";
1924d722e3fbSopenharmony_ci						break;
1925d722e3fbSopenharmony_ci					}
1926d722e3fbSopenharmony_ci					break;
1927d722e3fbSopenharmony_ci				case 6:
1928d722e3fbSopenharmony_ci					type = "compressed";
1929d722e3fbSopenharmony_ci					switch ((dword >> 3) & 0x7) {
1930d722e3fbSopenharmony_ci					case 0:
1931d722e3fbSopenharmony_ci						format = " dxt1";
1932d722e3fbSopenharmony_ci						break;
1933d722e3fbSopenharmony_ci					case 1:
1934d722e3fbSopenharmony_ci						format = " dxt2_3";
1935d722e3fbSopenharmony_ci						break;
1936d722e3fbSopenharmony_ci					case 2:
1937d722e3fbSopenharmony_ci						format = " dxt4_5";
1938d722e3fbSopenharmony_ci						break;
1939d722e3fbSopenharmony_ci					case 3:
1940d722e3fbSopenharmony_ci						format = " fxt1";
1941d722e3fbSopenharmony_ci						break;
1942d722e3fbSopenharmony_ci					case 4:
1943d722e3fbSopenharmony_ci						format = " dxt1_rb";
1944d722e3fbSopenharmony_ci						break;
1945d722e3fbSopenharmony_ci					}
1946d722e3fbSopenharmony_ci					break;
1947d722e3fbSopenharmony_ci				case 7:
1948d722e3fbSopenharmony_ci					type = "4b indexed";
1949d722e3fbSopenharmony_ci					switch ((dword >> 3) & 0xf) {
1950d722e3fbSopenharmony_ci					case 7:
1951d722e3fbSopenharmony_ci						format = " argb8888";
1952d722e3fbSopenharmony_ci						break;
1953d722e3fbSopenharmony_ci					}
1954d722e3fbSopenharmony_ci					break;
1955d722e3fbSopenharmony_ci				}
1956d722e3fbSopenharmony_ci				dword = data[i];
1957d722e3fbSopenharmony_ci				instr_out(ctx, i++,
1958d722e3fbSopenharmony_ci					  "map %d MS3 [width=%d, height=%d, format=%s%s, tiling=%s%s]\n",
1959d722e3fbSopenharmony_ci					  map, width, height, type, format,
1960d722e3fbSopenharmony_ci					  tiling,
1961d722e3fbSopenharmony_ci					  dword & (1 << 9) ? " palette select" :
1962d722e3fbSopenharmony_ci					  "");
1963d722e3fbSopenharmony_ci
1964d722e3fbSopenharmony_ci				dword = data[i];
1965d722e3fbSopenharmony_ci				pitch =
1966d722e3fbSopenharmony_ci				    4 * (((dword >> 21) & ((1 << 11) - 1)) + 1);
1967d722e3fbSopenharmony_ci				instr_out(ctx, i++,
1968d722e3fbSopenharmony_ci					  "map %d MS4 [pitch=%d, max_lod=%i, vol_depth=%i, cube_face_ena=%x, %s]\n",
1969d722e3fbSopenharmony_ci					  map, pitch, (dword >> 9) & 0x3f,
1970d722e3fbSopenharmony_ci					  dword & 0xff, (dword >> 15) & 0x3f,
1971d722e3fbSopenharmony_ci					  dword & (1 << 8) ? "miplayout legacy"
1972d722e3fbSopenharmony_ci					  : "miplayout right");
1973d722e3fbSopenharmony_ci			}
1974d722e3fbSopenharmony_ci		}
1975d722e3fbSopenharmony_ci		if (len != i) {
1976d722e3fbSopenharmony_ci			fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n");
1977d722e3fbSopenharmony_ci			return len;
1978d722e3fbSopenharmony_ci		}
1979d722e3fbSopenharmony_ci		return len;
1980d722e3fbSopenharmony_ci	case 0x06:
1981d722e3fbSopenharmony_ci		instr_out(ctx, 0,
1982d722e3fbSopenharmony_ci			  "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
1983d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
1984d722e3fbSopenharmony_ci
1985d722e3fbSopenharmony_ci		i = 2;
1986d722e3fbSopenharmony_ci		for (c = 0; c <= 31; c++) {
1987d722e3fbSopenharmony_ci			if (data[1] & (1 << c)) {
1988d722e3fbSopenharmony_ci				instr_out(ctx, i, "C%d.X = %f\n", c,
1989d722e3fbSopenharmony_ci					  int_as_float(data[i]));
1990d722e3fbSopenharmony_ci				i++;
1991d722e3fbSopenharmony_ci				instr_out(ctx, i, "C%d.Y = %f\n",
1992d722e3fbSopenharmony_ci					  c, int_as_float(data[i]));
1993d722e3fbSopenharmony_ci				i++;
1994d722e3fbSopenharmony_ci				instr_out(ctx, i, "C%d.Z = %f\n",
1995d722e3fbSopenharmony_ci					  c, int_as_float(data[i]));
1996d722e3fbSopenharmony_ci				i++;
1997d722e3fbSopenharmony_ci				instr_out(ctx, i, "C%d.W = %f\n",
1998d722e3fbSopenharmony_ci					  c, int_as_float(data[i]));
1999d722e3fbSopenharmony_ci				i++;
2000d722e3fbSopenharmony_ci			}
2001d722e3fbSopenharmony_ci		}
2002d722e3fbSopenharmony_ci		if (len != i) {
2003d722e3fbSopenharmony_ci			fprintf(out,
2004d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_PIXEL_SHADER_CONSTANTS\n");
2005d722e3fbSopenharmony_ci		}
2006d722e3fbSopenharmony_ci		return len;
2007d722e3fbSopenharmony_ci	case 0x05:
2008d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
2009d722e3fbSopenharmony_ci		len = (data[0] & 0x000000ff) + 2;
2010d722e3fbSopenharmony_ci		if ((len - 1) % 3 != 0 || len > 370) {
2011d722e3fbSopenharmony_ci			fprintf(out,
2012d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
2013d722e3fbSopenharmony_ci		}
2014d722e3fbSopenharmony_ci		i = 1;
2015d722e3fbSopenharmony_ci		for (instr = 0; instr < (len - 1) / 3; instr++) {
2016d722e3fbSopenharmony_ci			char instr_prefix[10];
2017d722e3fbSopenharmony_ci
2018d722e3fbSopenharmony_ci			sprintf(instr_prefix, "PS%03d", instr);
2019d722e3fbSopenharmony_ci			i915_decode_instruction(ctx, i,
2020d722e3fbSopenharmony_ci						instr_prefix);
2021d722e3fbSopenharmony_ci			i += 3;
2022d722e3fbSopenharmony_ci		}
2023d722e3fbSopenharmony_ci		return len;
2024d722e3fbSopenharmony_ci	case 0x01:
2025d722e3fbSopenharmony_ci		if (IS_GEN2(devid))
2026d722e3fbSopenharmony_ci			break;
2027d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_SAMPLER_STATE\n");
2028d722e3fbSopenharmony_ci		instr_out(ctx, 1, "mask\n");
2029d722e3fbSopenharmony_ci		len = (data[0] & 0x0000003f) + 2;
2030d722e3fbSopenharmony_ci		i = 2;
2031d722e3fbSopenharmony_ci		for (sampler = 0; sampler <= 15; sampler++) {
2032d722e3fbSopenharmony_ci			if (data[1] & (1 << sampler)) {
2033d722e3fbSopenharmony_ci				uint32_t dword;
2034d722e3fbSopenharmony_ci				const char *mip_filter = "";
2035d722e3fbSopenharmony_ci
2036d722e3fbSopenharmony_ci				dword = data[i];
2037d722e3fbSopenharmony_ci				switch ((dword >> 20) & 0x3) {
2038d722e3fbSopenharmony_ci				case 0:
2039d722e3fbSopenharmony_ci					mip_filter = "none";
2040d722e3fbSopenharmony_ci					break;
2041d722e3fbSopenharmony_ci				case 1:
2042d722e3fbSopenharmony_ci					mip_filter = "nearest";
2043d722e3fbSopenharmony_ci					break;
2044d722e3fbSopenharmony_ci				case 3:
2045d722e3fbSopenharmony_ci					mip_filter = "linear";
2046d722e3fbSopenharmony_ci					break;
2047d722e3fbSopenharmony_ci				}
2048d722e3fbSopenharmony_ci				instr_out(ctx, i++,
2049d722e3fbSopenharmony_ci					  "sampler %d SS2:%s%s%s "
2050d722e3fbSopenharmony_ci					  "base_mip_level=%i, mip_filter=%s, mag_filter=%s, min_filter=%s "
2051d722e3fbSopenharmony_ci					  "lod_bias=%.2f,%s max_aniso=%i, shadow_func=%s\n",
2052d722e3fbSopenharmony_ci					  sampler,
2053d722e3fbSopenharmony_ci					  dword & (1 << 31) ? " reverse gamma,"
2054d722e3fbSopenharmony_ci					  : "",
2055d722e3fbSopenharmony_ci					  dword & (1 << 30) ? " packed2planar,"
2056d722e3fbSopenharmony_ci					  : "",
2057d722e3fbSopenharmony_ci					  dword & (1 << 29) ?
2058d722e3fbSopenharmony_ci					  " colorspace conversion," : "",
2059d722e3fbSopenharmony_ci					  (dword >> 22) & 0x1f, mip_filter,
2060d722e3fbSopenharmony_ci					  decode_sample_filter(dword >> 17),
2061d722e3fbSopenharmony_ci					  decode_sample_filter(dword >> 14),
2062d722e3fbSopenharmony_ci					  ((dword >> 5) & 0x1ff) / (0x10 * 1.0),
2063d722e3fbSopenharmony_ci					  dword & (1 << 4) ? " shadow," : "",
2064d722e3fbSopenharmony_ci					  dword & (1 << 3) ? 4 : 2,
2065d722e3fbSopenharmony_ci					  decode_compare_func(dword));
2066d722e3fbSopenharmony_ci				dword = data[i];
2067d722e3fbSopenharmony_ci				instr_out(ctx, i++,
2068d722e3fbSopenharmony_ci					  "sampler %d SS3: min_lod=%.2f,%s "
2069d722e3fbSopenharmony_ci					  "tcmode_x=%s, tcmode_y=%s, tcmode_z=%s,%s texmap_idx=%i,%s\n",
2070d722e3fbSopenharmony_ci					  sampler,
2071d722e3fbSopenharmony_ci					  ((dword >> 24) & 0xff) / (0x10 * 1.0),
2072d722e3fbSopenharmony_ci					  dword & (1 << 17) ?
2073d722e3fbSopenharmony_ci					  " kill pixel enable," : "",
2074d722e3fbSopenharmony_ci					  decode_tex_coord_mode(dword >> 12),
2075d722e3fbSopenharmony_ci					  decode_tex_coord_mode(dword >> 9),
2076d722e3fbSopenharmony_ci					  decode_tex_coord_mode(dword >> 6),
2077d722e3fbSopenharmony_ci					  dword & (1 << 5) ?
2078d722e3fbSopenharmony_ci					  " normalized coords," : "",
2079d722e3fbSopenharmony_ci					  (dword >> 1) & 0xf,
2080d722e3fbSopenharmony_ci					  dword & (1 << 0) ? " deinterlacer," :
2081d722e3fbSopenharmony_ci					  "");
2082d722e3fbSopenharmony_ci				dword = data[i];
2083d722e3fbSopenharmony_ci				instr_out(ctx, i++,
2084d722e3fbSopenharmony_ci					  "sampler %d SS4: border color\n",
2085d722e3fbSopenharmony_ci					  sampler);
2086d722e3fbSopenharmony_ci			}
2087d722e3fbSopenharmony_ci		}
2088d722e3fbSopenharmony_ci		if (len != i) {
2089d722e3fbSopenharmony_ci			fprintf(out, "Bad count in 3DSTATE_SAMPLER_STATE\n");
2090d722e3fbSopenharmony_ci		}
2091d722e3fbSopenharmony_ci		return len;
2092d722e3fbSopenharmony_ci	case 0x85:
2093d722e3fbSopenharmony_ci		len = (data[0] & 0x0000000f) + 2;
2094d722e3fbSopenharmony_ci
2095d722e3fbSopenharmony_ci		if (len != 2)
2096d722e3fbSopenharmony_ci			fprintf(out,
2097d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_DEST_BUFFER_VARIABLES\n");
2098d722e3fbSopenharmony_ci
2099d722e3fbSopenharmony_ci		instr_out(ctx, 0,
2100d722e3fbSopenharmony_ci			  "3DSTATE_DEST_BUFFER_VARIABLES\n");
2101d722e3fbSopenharmony_ci
2102d722e3fbSopenharmony_ci		switch ((data[1] >> 8) & 0xf) {
2103d722e3fbSopenharmony_ci		case 0x0:
2104d722e3fbSopenharmony_ci			format = "g8";
2105d722e3fbSopenharmony_ci			break;
2106d722e3fbSopenharmony_ci		case 0x1:
2107d722e3fbSopenharmony_ci			format = "x1r5g5b5";
2108d722e3fbSopenharmony_ci			break;
2109d722e3fbSopenharmony_ci		case 0x2:
2110d722e3fbSopenharmony_ci			format = "r5g6b5";
2111d722e3fbSopenharmony_ci			break;
2112d722e3fbSopenharmony_ci		case 0x3:
2113d722e3fbSopenharmony_ci			format = "a8r8g8b8";
2114d722e3fbSopenharmony_ci			break;
2115d722e3fbSopenharmony_ci		case 0x4:
2116d722e3fbSopenharmony_ci			format = "ycrcb_swapy";
2117d722e3fbSopenharmony_ci			break;
2118d722e3fbSopenharmony_ci		case 0x5:
2119d722e3fbSopenharmony_ci			format = "ycrcb_normal";
2120d722e3fbSopenharmony_ci			break;
2121d722e3fbSopenharmony_ci		case 0x6:
2122d722e3fbSopenharmony_ci			format = "ycrcb_swapuv";
2123d722e3fbSopenharmony_ci			break;
2124d722e3fbSopenharmony_ci		case 0x7:
2125d722e3fbSopenharmony_ci			format = "ycrcb_swapuvy";
2126d722e3fbSopenharmony_ci			break;
2127d722e3fbSopenharmony_ci		case 0x8:
2128d722e3fbSopenharmony_ci			format = "a4r4g4b4";
2129d722e3fbSopenharmony_ci			break;
2130d722e3fbSopenharmony_ci		case 0x9:
2131d722e3fbSopenharmony_ci			format = "a1r5g5b5";
2132d722e3fbSopenharmony_ci			break;
2133d722e3fbSopenharmony_ci		case 0xa:
2134d722e3fbSopenharmony_ci			format = "a2r10g10b10";
2135d722e3fbSopenharmony_ci			break;
2136d722e3fbSopenharmony_ci		default:
2137d722e3fbSopenharmony_ci			format = "BAD";
2138d722e3fbSopenharmony_ci			break;
2139d722e3fbSopenharmony_ci		}
2140d722e3fbSopenharmony_ci		switch ((data[1] >> 2) & 0x3) {
2141d722e3fbSopenharmony_ci		case 0x0:
2142d722e3fbSopenharmony_ci			zformat = "u16";
2143d722e3fbSopenharmony_ci			break;
2144d722e3fbSopenharmony_ci		case 0x1:
2145d722e3fbSopenharmony_ci			zformat = "f16";
2146d722e3fbSopenharmony_ci			break;
2147d722e3fbSopenharmony_ci		case 0x2:
2148d722e3fbSopenharmony_ci			zformat = "u24x8";
2149d722e3fbSopenharmony_ci			break;
2150d722e3fbSopenharmony_ci		default:
2151d722e3fbSopenharmony_ci			zformat = "BAD";
2152d722e3fbSopenharmony_ci			break;
2153d722e3fbSopenharmony_ci		}
2154d722e3fbSopenharmony_ci		instr_out(ctx, 1,
2155d722e3fbSopenharmony_ci			  "%s format, %s depth format, early Z %sabled\n",
2156d722e3fbSopenharmony_ci			  format, zformat,
2157d722e3fbSopenharmony_ci			  (data[1] & (1 << 31)) ? "en" : "dis");
2158d722e3fbSopenharmony_ci		return len;
2159d722e3fbSopenharmony_ci
2160d722e3fbSopenharmony_ci	case 0x8e:
2161d722e3fbSopenharmony_ci		{
2162d722e3fbSopenharmony_ci			const char *name, *tiling;
2163d722e3fbSopenharmony_ci
2164d722e3fbSopenharmony_ci			len = (data[0] & 0x0000000f) + 2;
2165d722e3fbSopenharmony_ci			if (len != 3)
2166d722e3fbSopenharmony_ci				fprintf(out,
2167d722e3fbSopenharmony_ci					"Bad count in 3DSTATE_BUFFER_INFO\n");
2168d722e3fbSopenharmony_ci
2169d722e3fbSopenharmony_ci			switch ((data[1] >> 24) & 0x7) {
2170d722e3fbSopenharmony_ci			case 0x3:
2171d722e3fbSopenharmony_ci				name = "color";
2172d722e3fbSopenharmony_ci				break;
2173d722e3fbSopenharmony_ci			case 0x7:
2174d722e3fbSopenharmony_ci				name = "depth";
2175d722e3fbSopenharmony_ci				break;
2176d722e3fbSopenharmony_ci			default:
2177d722e3fbSopenharmony_ci				name = "unknown";
2178d722e3fbSopenharmony_ci				break;
2179d722e3fbSopenharmony_ci			}
2180d722e3fbSopenharmony_ci
2181d722e3fbSopenharmony_ci			tiling = "none";
2182d722e3fbSopenharmony_ci			if (data[1] & (1 << 23))
2183d722e3fbSopenharmony_ci				tiling = "fenced";
2184d722e3fbSopenharmony_ci			else if (data[1] & (1 << 22))
2185d722e3fbSopenharmony_ci				tiling = data[1] & (1 << 21) ? "Y" : "X";
2186d722e3fbSopenharmony_ci
2187d722e3fbSopenharmony_ci			instr_out(ctx, 0, "3DSTATE_BUFFER_INFO\n");
2188d722e3fbSopenharmony_ci			instr_out(ctx, 1,
2189d722e3fbSopenharmony_ci				  "%s, tiling = %s, pitch=%d\n", name, tiling,
2190d722e3fbSopenharmony_ci				  data[1] & 0xffff);
2191d722e3fbSopenharmony_ci
2192d722e3fbSopenharmony_ci			instr_out(ctx, 2, "address\n");
2193d722e3fbSopenharmony_ci			return len;
2194d722e3fbSopenharmony_ci		}
2195d722e3fbSopenharmony_ci	case 0x81:
2196d722e3fbSopenharmony_ci		len = (data[0] & 0x0000000f) + 2;
2197d722e3fbSopenharmony_ci
2198d722e3fbSopenharmony_ci		if (len != 3)
2199d722e3fbSopenharmony_ci			fprintf(out,
2200d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_SCISSOR_RECTANGLE\n");
2201d722e3fbSopenharmony_ci
2202d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_SCISSOR_RECTANGLE\n");
2203d722e3fbSopenharmony_ci		instr_out(ctx, 1, "(%d,%d)\n",
2204d722e3fbSopenharmony_ci			  data[1] & 0xffff, data[1] >> 16);
2205d722e3fbSopenharmony_ci		instr_out(ctx, 2, "(%d,%d)\n",
2206d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[2] >> 16);
2207d722e3fbSopenharmony_ci
2208d722e3fbSopenharmony_ci		return len;
2209d722e3fbSopenharmony_ci	case 0x80:
2210d722e3fbSopenharmony_ci		len = (data[0] & 0x0000000f) + 2;
2211d722e3fbSopenharmony_ci
2212d722e3fbSopenharmony_ci		if (len != 5)
2213d722e3fbSopenharmony_ci			fprintf(out,
2214d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
2215d722e3fbSopenharmony_ci
2216d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
2217d722e3fbSopenharmony_ci		instr_out(ctx, 1, "%s\n",
2218d722e3fbSopenharmony_ci			  data[1] & (1 << 30) ? "depth ofs disabled " : "");
2219d722e3fbSopenharmony_ci		instr_out(ctx, 2, "(%d,%d)\n",
2220d722e3fbSopenharmony_ci			  data[2] & 0xffff, data[2] >> 16);
2221d722e3fbSopenharmony_ci		instr_out(ctx, 3, "(%d,%d)\n",
2222d722e3fbSopenharmony_ci			  data[3] & 0xffff, data[3] >> 16);
2223d722e3fbSopenharmony_ci		instr_out(ctx, 4, "(%d,%d)\n",
2224d722e3fbSopenharmony_ci			  data[4] & 0xffff, data[4] >> 16);
2225d722e3fbSopenharmony_ci
2226d722e3fbSopenharmony_ci		return len;
2227d722e3fbSopenharmony_ci	case 0x9c:
2228d722e3fbSopenharmony_ci		len = (data[0] & 0x0000000f) + 2;
2229d722e3fbSopenharmony_ci
2230d722e3fbSopenharmony_ci		if (len != 7)
2231d722e3fbSopenharmony_ci			fprintf(out, "Bad count in 3DSTATE_CLEAR_PARAMETERS\n");
2232d722e3fbSopenharmony_ci
2233d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_CLEAR_PARAMETERS\n");
2234d722e3fbSopenharmony_ci		instr_out(ctx, 1, "prim_type=%s, clear=%s%s%s\n",
2235d722e3fbSopenharmony_ci			  data[1] & (1 << 16) ? "CLEAR_RECT" : "ZONE_INIT",
2236d722e3fbSopenharmony_ci			  data[1] & (1 << 2) ? "color," : "",
2237d722e3fbSopenharmony_ci			  data[1] & (1 << 1) ? "depth," : "",
2238d722e3fbSopenharmony_ci			  data[1] & (1 << 0) ? "stencil," : "");
2239d722e3fbSopenharmony_ci		instr_out(ctx, 2, "clear color\n");
2240d722e3fbSopenharmony_ci		instr_out(ctx, 3, "clear depth/stencil\n");
2241d722e3fbSopenharmony_ci		instr_out(ctx, 4, "color value (rgba8888)\n");
2242d722e3fbSopenharmony_ci		instr_out(ctx, 5, "depth value %f\n",
2243d722e3fbSopenharmony_ci			  int_as_float(data[5]));
2244d722e3fbSopenharmony_ci		instr_out(ctx, 6, "clear stencil\n");
2245d722e3fbSopenharmony_ci		return len;
2246d722e3fbSopenharmony_ci	}
2247d722e3fbSopenharmony_ci
2248d722e3fbSopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(opcodes_3d_1d); idx++) {
2249d722e3fbSopenharmony_ci		opcode_3d_1d = &opcodes_3d_1d[idx];
2250d722e3fbSopenharmony_ci		if (opcode_3d_1d->i830_only && !IS_GEN2(devid))
2251d722e3fbSopenharmony_ci			continue;
2252d722e3fbSopenharmony_ci
2253d722e3fbSopenharmony_ci		if (((data[0] & 0x00ff0000) >> 16) == opcode_3d_1d->opcode) {
2254d722e3fbSopenharmony_ci			len = 1;
2255d722e3fbSopenharmony_ci
2256d722e3fbSopenharmony_ci			instr_out(ctx, 0, "%s\n",
2257d722e3fbSopenharmony_ci				  opcode_3d_1d->name);
2258d722e3fbSopenharmony_ci			if (opcode_3d_1d->max_len > 1) {
2259d722e3fbSopenharmony_ci				len = (data[0] & 0x0000ffff) + 2;
2260d722e3fbSopenharmony_ci				if (len < opcode_3d_1d->min_len ||
2261d722e3fbSopenharmony_ci				    len > opcode_3d_1d->max_len) {
2262d722e3fbSopenharmony_ci					fprintf(out, "Bad count in %s\n",
2263d722e3fbSopenharmony_ci						opcode_3d_1d->name);
2264d722e3fbSopenharmony_ci				}
2265d722e3fbSopenharmony_ci			}
2266d722e3fbSopenharmony_ci
2267d722e3fbSopenharmony_ci			for (i = 1; i < len; i++) {
2268d722e3fbSopenharmony_ci				instr_out(ctx, i, "dword %d\n", i);
2269d722e3fbSopenharmony_ci			}
2270d722e3fbSopenharmony_ci
2271d722e3fbSopenharmony_ci			return len;
2272d722e3fbSopenharmony_ci		}
2273d722e3fbSopenharmony_ci	}
2274d722e3fbSopenharmony_ci
2275d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3D UNKNOWN: 3d_1d opcode = 0x%x\n",
2276d722e3fbSopenharmony_ci		  opcode);
2277d722e3fbSopenharmony_ci	return 1;
2278d722e3fbSopenharmony_ci}
2279d722e3fbSopenharmony_ci
2280d722e3fbSopenharmony_cistatic int
2281d722e3fbSopenharmony_cidecode_3d_primitive(struct drm_intel_decode *ctx)
2282d722e3fbSopenharmony_ci{
2283d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
2284d722e3fbSopenharmony_ci	uint32_t count = ctx->count;
2285d722e3fbSopenharmony_ci	char immediate = (data[0] & (1 << 23)) == 0;
2286d722e3fbSopenharmony_ci	unsigned int len, i, j, ret;
2287d722e3fbSopenharmony_ci	const char *primtype;
2288d722e3fbSopenharmony_ci	int original_s2 = saved_s2;
2289d722e3fbSopenharmony_ci	int original_s4 = saved_s4;
2290d722e3fbSopenharmony_ci
2291d722e3fbSopenharmony_ci	switch ((data[0] >> 18) & 0xf) {
2292d722e3fbSopenharmony_ci	case 0x0:
2293d722e3fbSopenharmony_ci		primtype = "TRILIST";
2294d722e3fbSopenharmony_ci		break;
2295d722e3fbSopenharmony_ci	case 0x1:
2296d722e3fbSopenharmony_ci		primtype = "TRISTRIP";
2297d722e3fbSopenharmony_ci		break;
2298d722e3fbSopenharmony_ci	case 0x2:
2299d722e3fbSopenharmony_ci		primtype = "TRISTRIP_REVERSE";
2300d722e3fbSopenharmony_ci		break;
2301d722e3fbSopenharmony_ci	case 0x3:
2302d722e3fbSopenharmony_ci		primtype = "TRIFAN";
2303d722e3fbSopenharmony_ci		break;
2304d722e3fbSopenharmony_ci	case 0x4:
2305d722e3fbSopenharmony_ci		primtype = "POLYGON";
2306d722e3fbSopenharmony_ci		break;
2307d722e3fbSopenharmony_ci	case 0x5:
2308d722e3fbSopenharmony_ci		primtype = "LINELIST";
2309d722e3fbSopenharmony_ci		break;
2310d722e3fbSopenharmony_ci	case 0x6:
2311d722e3fbSopenharmony_ci		primtype = "LINESTRIP";
2312d722e3fbSopenharmony_ci		break;
2313d722e3fbSopenharmony_ci	case 0x7:
2314d722e3fbSopenharmony_ci		primtype = "RECTLIST";
2315d722e3fbSopenharmony_ci		break;
2316d722e3fbSopenharmony_ci	case 0x8:
2317d722e3fbSopenharmony_ci		primtype = "POINTLIST";
2318d722e3fbSopenharmony_ci		break;
2319d722e3fbSopenharmony_ci	case 0x9:
2320d722e3fbSopenharmony_ci		primtype = "DIB";
2321d722e3fbSopenharmony_ci		break;
2322d722e3fbSopenharmony_ci	case 0xa:
2323d722e3fbSopenharmony_ci		primtype = "CLEAR_RECT";
2324d722e3fbSopenharmony_ci		saved_s4 = 3 << 6;
2325d722e3fbSopenharmony_ci		saved_s2 = ~0;
2326d722e3fbSopenharmony_ci		break;
2327d722e3fbSopenharmony_ci	default:
2328d722e3fbSopenharmony_ci		primtype = "unknown";
2329d722e3fbSopenharmony_ci		break;
2330d722e3fbSopenharmony_ci	}
2331d722e3fbSopenharmony_ci
2332d722e3fbSopenharmony_ci	/* XXX: 3DPRIM_DIB not supported */
2333d722e3fbSopenharmony_ci	if (immediate) {
2334d722e3fbSopenharmony_ci		len = (data[0] & 0x0003ffff) + 2;
2335d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DPRIMITIVE inline %s\n",
2336d722e3fbSopenharmony_ci			  primtype);
2337d722e3fbSopenharmony_ci		if (count < len)
2338d722e3fbSopenharmony_ci			BUFFER_FAIL(count, len, "3DPRIMITIVE inline");
2339d722e3fbSopenharmony_ci		if (!saved_s2_set || !saved_s4_set) {
2340d722e3fbSopenharmony_ci			fprintf(out, "unknown vertex format\n");
2341d722e3fbSopenharmony_ci			for (i = 1; i < len; i++) {
2342d722e3fbSopenharmony_ci				instr_out(ctx, i,
2343d722e3fbSopenharmony_ci					  "           vertex data (%f float)\n",
2344d722e3fbSopenharmony_ci					  int_as_float(data[i]));
2345d722e3fbSopenharmony_ci			}
2346d722e3fbSopenharmony_ci		} else {
2347d722e3fbSopenharmony_ci			unsigned int vertex = 0;
2348d722e3fbSopenharmony_ci			for (i = 1; i < len;) {
2349d722e3fbSopenharmony_ci				unsigned int tc;
2350d722e3fbSopenharmony_ci
2351d722e3fbSopenharmony_ci#define VERTEX_OUT(fmt, ...) do {					\
2352d722e3fbSopenharmony_ci    if (i < len)							\
2353d722e3fbSopenharmony_ci	instr_out(ctx, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
2354d722e3fbSopenharmony_ci    else								\
2355d722e3fbSopenharmony_ci	fprintf(out, " missing data in V%d\n", vertex);			\
2356d722e3fbSopenharmony_ci    i++;								\
2357d722e3fbSopenharmony_ci} while (0)
2358d722e3fbSopenharmony_ci
2359d722e3fbSopenharmony_ci				VERTEX_OUT("X = %f", int_as_float(data[i]));
2360d722e3fbSopenharmony_ci				VERTEX_OUT("Y = %f", int_as_float(data[i]));
2361d722e3fbSopenharmony_ci				switch (saved_s4 >> 6 & 0x7) {
2362d722e3fbSopenharmony_ci				case 0x1:
2363d722e3fbSopenharmony_ci					VERTEX_OUT("Z = %f",
2364d722e3fbSopenharmony_ci						   int_as_float(data[i]));
2365d722e3fbSopenharmony_ci					break;
2366d722e3fbSopenharmony_ci				case 0x2:
2367d722e3fbSopenharmony_ci					VERTEX_OUT("Z = %f",
2368d722e3fbSopenharmony_ci						   int_as_float(data[i]));
2369d722e3fbSopenharmony_ci					VERTEX_OUT("W = %f",
2370d722e3fbSopenharmony_ci						   int_as_float(data[i]));
2371d722e3fbSopenharmony_ci					break;
2372d722e3fbSopenharmony_ci				case 0x3:
2373d722e3fbSopenharmony_ci					break;
2374d722e3fbSopenharmony_ci				case 0x4:
2375d722e3fbSopenharmony_ci					VERTEX_OUT("W = %f",
2376d722e3fbSopenharmony_ci						   int_as_float(data[i]));
2377d722e3fbSopenharmony_ci					break;
2378d722e3fbSopenharmony_ci				default:
2379d722e3fbSopenharmony_ci					fprintf(out, "bad S4 position mask\n");
2380d722e3fbSopenharmony_ci				}
2381d722e3fbSopenharmony_ci
2382d722e3fbSopenharmony_ci				if (saved_s4 & (1 << 10)) {
2383d722e3fbSopenharmony_ci					VERTEX_OUT
2384d722e3fbSopenharmony_ci					    ("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
2385d722e3fbSopenharmony_ci					     "B=0x%02x)", data[i] >> 24,
2386d722e3fbSopenharmony_ci					     (data[i] >> 16) & 0xff,
2387d722e3fbSopenharmony_ci					     (data[i] >> 8) & 0xff,
2388d722e3fbSopenharmony_ci					     data[i] & 0xff);
2389d722e3fbSopenharmony_ci				}
2390d722e3fbSopenharmony_ci				if (saved_s4 & (1 << 11)) {
2391d722e3fbSopenharmony_ci					VERTEX_OUT
2392d722e3fbSopenharmony_ci					    ("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
2393d722e3fbSopenharmony_ci					     "B=0x%02x)", data[i] >> 24,
2394d722e3fbSopenharmony_ci					     (data[i] >> 16) & 0xff,
2395d722e3fbSopenharmony_ci					     (data[i] >> 8) & 0xff,
2396d722e3fbSopenharmony_ci					     data[i] & 0xff);
2397d722e3fbSopenharmony_ci				}
2398d722e3fbSopenharmony_ci				if (saved_s4 & (1 << 12))
2399d722e3fbSopenharmony_ci					VERTEX_OUT("width = 0x%08x)", data[i]);
2400d722e3fbSopenharmony_ci
2401d722e3fbSopenharmony_ci				for (tc = 0; tc <= 7; tc++) {
2402d722e3fbSopenharmony_ci					switch ((saved_s2 >> (tc * 4)) & 0xf) {
2403d722e3fbSopenharmony_ci					case 0x0:
2404d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.X = %f", tc,
2405d722e3fbSopenharmony_ci							   int_as_float(data
2406d722e3fbSopenharmony_ci									[i]));
2407d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.Y = %f", tc,
2408d722e3fbSopenharmony_ci							   int_as_float(data
2409d722e3fbSopenharmony_ci									[i]));
2410d722e3fbSopenharmony_ci						break;
2411d722e3fbSopenharmony_ci					case 0x1:
2412d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.X = %f", tc,
2413d722e3fbSopenharmony_ci							   int_as_float(data
2414d722e3fbSopenharmony_ci									[i]));
2415d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.Y = %f", tc,
2416d722e3fbSopenharmony_ci							   int_as_float(data
2417d722e3fbSopenharmony_ci									[i]));
2418d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.Z = %f", tc,
2419d722e3fbSopenharmony_ci							   int_as_float(data
2420d722e3fbSopenharmony_ci									[i]));
2421d722e3fbSopenharmony_ci						break;
2422d722e3fbSopenharmony_ci					case 0x2:
2423d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.X = %f", tc,
2424d722e3fbSopenharmony_ci							   int_as_float(data
2425d722e3fbSopenharmony_ci									[i]));
2426d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.Y = %f", tc,
2427d722e3fbSopenharmony_ci							   int_as_float(data
2428d722e3fbSopenharmony_ci									[i]));
2429d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.Z = %f", tc,
2430d722e3fbSopenharmony_ci							   int_as_float(data
2431d722e3fbSopenharmony_ci									[i]));
2432d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.W = %f", tc,
2433d722e3fbSopenharmony_ci							   int_as_float(data
2434d722e3fbSopenharmony_ci									[i]));
2435d722e3fbSopenharmony_ci						break;
2436d722e3fbSopenharmony_ci					case 0x3:
2437d722e3fbSopenharmony_ci						VERTEX_OUT("T%d.X = %f", tc,
2438d722e3fbSopenharmony_ci							   int_as_float(data
2439d722e3fbSopenharmony_ci									[i]));
2440d722e3fbSopenharmony_ci						break;
2441d722e3fbSopenharmony_ci					case 0x4:
2442d722e3fbSopenharmony_ci						VERTEX_OUT
2443d722e3fbSopenharmony_ci						    ("T%d.XY = 0x%08x half-float",
2444d722e3fbSopenharmony_ci						     tc, data[i]);
2445d722e3fbSopenharmony_ci						break;
2446d722e3fbSopenharmony_ci					case 0x5:
2447d722e3fbSopenharmony_ci						VERTEX_OUT
2448d722e3fbSopenharmony_ci						    ("T%d.XY = 0x%08x half-float",
2449d722e3fbSopenharmony_ci						     tc, data[i]);
2450d722e3fbSopenharmony_ci						VERTEX_OUT
2451d722e3fbSopenharmony_ci						    ("T%d.ZW = 0x%08x half-float",
2452d722e3fbSopenharmony_ci						     tc, data[i]);
2453d722e3fbSopenharmony_ci						break;
2454d722e3fbSopenharmony_ci					case 0xf:
2455d722e3fbSopenharmony_ci						break;
2456d722e3fbSopenharmony_ci					default:
2457d722e3fbSopenharmony_ci						fprintf(out,
2458d722e3fbSopenharmony_ci							"bad S2.T%d format\n",
2459d722e3fbSopenharmony_ci							tc);
2460d722e3fbSopenharmony_ci					}
2461d722e3fbSopenharmony_ci				}
2462d722e3fbSopenharmony_ci				vertex++;
2463d722e3fbSopenharmony_ci			}
2464d722e3fbSopenharmony_ci		}
2465d722e3fbSopenharmony_ci
2466d722e3fbSopenharmony_ci		ret = len;
2467d722e3fbSopenharmony_ci	} else {
2468d722e3fbSopenharmony_ci		/* indirect vertices */
2469d722e3fbSopenharmony_ci		len = data[0] & 0x0000ffff;	/* index count */
2470d722e3fbSopenharmony_ci		if (data[0] & (1 << 17)) {
2471d722e3fbSopenharmony_ci			/* random vertex access */
2472d722e3fbSopenharmony_ci			if (count < (len + 1) / 2 + 1) {
2473d722e3fbSopenharmony_ci				BUFFER_FAIL(count, (len + 1) / 2 + 1,
2474d722e3fbSopenharmony_ci					    "3DPRIMITIVE random indirect");
2475d722e3fbSopenharmony_ci			}
2476d722e3fbSopenharmony_ci			instr_out(ctx, 0,
2477d722e3fbSopenharmony_ci				  "3DPRIMITIVE random indirect %s (%d)\n",
2478d722e3fbSopenharmony_ci				  primtype, len);
2479d722e3fbSopenharmony_ci			if (len == 0) {
2480d722e3fbSopenharmony_ci				/* vertex indices continue until 0xffff is
2481d722e3fbSopenharmony_ci				 * found
2482d722e3fbSopenharmony_ci				 */
2483d722e3fbSopenharmony_ci				for (i = 1; i < count; i++) {
2484d722e3fbSopenharmony_ci					if ((data[i] & 0xffff) == 0xffff) {
2485d722e3fbSopenharmony_ci						instr_out(ctx, i,
2486d722e3fbSopenharmony_ci							  "    indices: (terminator)\n");
2487d722e3fbSopenharmony_ci						ret = i;
2488d722e3fbSopenharmony_ci						goto out;
2489d722e3fbSopenharmony_ci					} else if ((data[i] >> 16) == 0xffff) {
2490d722e3fbSopenharmony_ci						instr_out(ctx, i,
2491d722e3fbSopenharmony_ci							  "    indices: 0x%04x, (terminator)\n",
2492d722e3fbSopenharmony_ci							  data[i] & 0xffff);
2493d722e3fbSopenharmony_ci						ret = i;
2494d722e3fbSopenharmony_ci						goto out;
2495d722e3fbSopenharmony_ci					} else {
2496d722e3fbSopenharmony_ci						instr_out(ctx, i,
2497d722e3fbSopenharmony_ci							  "    indices: 0x%04x, 0x%04x\n",
2498d722e3fbSopenharmony_ci							  data[i] & 0xffff,
2499d722e3fbSopenharmony_ci							  data[i] >> 16);
2500d722e3fbSopenharmony_ci					}
2501d722e3fbSopenharmony_ci				}
2502d722e3fbSopenharmony_ci				fprintf(out,
2503d722e3fbSopenharmony_ci					"3DPRIMITIVE: no terminator found in index buffer\n");
2504d722e3fbSopenharmony_ci				ret = count;
2505d722e3fbSopenharmony_ci				goto out;
2506d722e3fbSopenharmony_ci			} else {
2507d722e3fbSopenharmony_ci				/* fixed size vertex index buffer */
2508d722e3fbSopenharmony_ci				for (j = 1, i = 0; i < len; i += 2, j++) {
2509d722e3fbSopenharmony_ci					if (i * 2 == len - 1) {
2510d722e3fbSopenharmony_ci						instr_out(ctx, j,
2511d722e3fbSopenharmony_ci							  "    indices: 0x%04x\n",
2512d722e3fbSopenharmony_ci							  data[j] & 0xffff);
2513d722e3fbSopenharmony_ci					} else {
2514d722e3fbSopenharmony_ci						instr_out(ctx, j,
2515d722e3fbSopenharmony_ci							  "    indices: 0x%04x, 0x%04x\n",
2516d722e3fbSopenharmony_ci							  data[j] & 0xffff,
2517d722e3fbSopenharmony_ci							  data[j] >> 16);
2518d722e3fbSopenharmony_ci					}
2519d722e3fbSopenharmony_ci				}
2520d722e3fbSopenharmony_ci			}
2521d722e3fbSopenharmony_ci			ret = (len + 1) / 2 + 1;
2522d722e3fbSopenharmony_ci			goto out;
2523d722e3fbSopenharmony_ci		} else {
2524d722e3fbSopenharmony_ci			/* sequential vertex access */
2525d722e3fbSopenharmony_ci			instr_out(ctx, 0,
2526d722e3fbSopenharmony_ci				  "3DPRIMITIVE sequential indirect %s, %d starting from "
2527d722e3fbSopenharmony_ci				  "%d\n", primtype, len, data[1] & 0xffff);
2528d722e3fbSopenharmony_ci			instr_out(ctx, 1, "           start\n");
2529d722e3fbSopenharmony_ci			ret = 2;
2530d722e3fbSopenharmony_ci			goto out;
2531d722e3fbSopenharmony_ci		}
2532d722e3fbSopenharmony_ci	}
2533d722e3fbSopenharmony_ci
2534d722e3fbSopenharmony_ciout:
2535d722e3fbSopenharmony_ci	saved_s2 = original_s2;
2536d722e3fbSopenharmony_ci	saved_s4 = original_s4;
2537d722e3fbSopenharmony_ci	return ret;
2538d722e3fbSopenharmony_ci}
2539d722e3fbSopenharmony_ci
2540d722e3fbSopenharmony_cistatic int
2541d722e3fbSopenharmony_cidecode_3d(struct drm_intel_decode *ctx)
2542d722e3fbSopenharmony_ci{
2543d722e3fbSopenharmony_ci	uint32_t opcode;
2544d722e3fbSopenharmony_ci	unsigned int idx;
2545d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
2546d722e3fbSopenharmony_ci
2547d722e3fbSopenharmony_ci	struct {
2548d722e3fbSopenharmony_ci		uint32_t opcode;
2549d722e3fbSopenharmony_ci		unsigned int min_len;
2550d722e3fbSopenharmony_ci		unsigned int max_len;
2551d722e3fbSopenharmony_ci		const char *name;
2552d722e3fbSopenharmony_ci	} opcodes_3d[] = {
2553d722e3fbSopenharmony_ci		{ 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
2554d722e3fbSopenharmony_ci		{ 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
2555d722e3fbSopenharmony_ci		{ 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
2556d722e3fbSopenharmony_ci		{ 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
2557d722e3fbSopenharmony_ci		{ 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
2558d722e3fbSopenharmony_ci		{ 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
2559d722e3fbSopenharmony_ci		{ 0x0d, 1, 1, "3DSTATE_MODES_4" },
2560d722e3fbSopenharmony_ci		{ 0x0c, 1, 1, "3DSTATE_MODES_5" },
2561d722e3fbSopenharmony_ci		{ 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES"},
2562d722e3fbSopenharmony_ci	}, *opcode_3d;
2563d722e3fbSopenharmony_ci
2564d722e3fbSopenharmony_ci	opcode = (data[0] & 0x1f000000) >> 24;
2565d722e3fbSopenharmony_ci
2566d722e3fbSopenharmony_ci	switch (opcode) {
2567d722e3fbSopenharmony_ci	case 0x1f:
2568d722e3fbSopenharmony_ci		return decode_3d_primitive(ctx);
2569d722e3fbSopenharmony_ci	case 0x1d:
2570d722e3fbSopenharmony_ci		return decode_3d_1d(ctx);
2571d722e3fbSopenharmony_ci	case 0x1c:
2572d722e3fbSopenharmony_ci		return decode_3d_1c(ctx);
2573d722e3fbSopenharmony_ci	}
2574d722e3fbSopenharmony_ci
2575d722e3fbSopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
2576d722e3fbSopenharmony_ci		opcode_3d = &opcodes_3d[idx];
2577d722e3fbSopenharmony_ci		if (opcode == opcode_3d->opcode) {
2578d722e3fbSopenharmony_ci			unsigned int len = 1, i;
2579d722e3fbSopenharmony_ci
2580d722e3fbSopenharmony_ci			instr_out(ctx, 0, "%s\n", opcode_3d->name);
2581d722e3fbSopenharmony_ci			if (opcode_3d->max_len > 1) {
2582d722e3fbSopenharmony_ci				len = (data[0] & 0xff) + 2;
2583d722e3fbSopenharmony_ci				if (len < opcode_3d->min_len ||
2584d722e3fbSopenharmony_ci				    len > opcode_3d->max_len) {
2585d722e3fbSopenharmony_ci					fprintf(out, "Bad count in %s\n",
2586d722e3fbSopenharmony_ci						opcode_3d->name);
2587d722e3fbSopenharmony_ci				}
2588d722e3fbSopenharmony_ci			}
2589d722e3fbSopenharmony_ci
2590d722e3fbSopenharmony_ci			for (i = 1; i < len; i++) {
2591d722e3fbSopenharmony_ci				instr_out(ctx, i, "dword %d\n", i);
2592d722e3fbSopenharmony_ci			}
2593d722e3fbSopenharmony_ci			return len;
2594d722e3fbSopenharmony_ci		}
2595d722e3fbSopenharmony_ci	}
2596d722e3fbSopenharmony_ci
2597d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3D UNKNOWN: 3d opcode = 0x%x\n", opcode);
2598d722e3fbSopenharmony_ci	return 1;
2599d722e3fbSopenharmony_ci}
2600d722e3fbSopenharmony_ci
2601d722e3fbSopenharmony_cistatic const char *get_965_surfacetype(unsigned int surfacetype)
2602d722e3fbSopenharmony_ci{
2603d722e3fbSopenharmony_ci	switch (surfacetype) {
2604d722e3fbSopenharmony_ci	case 0:
2605d722e3fbSopenharmony_ci		return "1D";
2606d722e3fbSopenharmony_ci	case 1:
2607d722e3fbSopenharmony_ci		return "2D";
2608d722e3fbSopenharmony_ci	case 2:
2609d722e3fbSopenharmony_ci		return "3D";
2610d722e3fbSopenharmony_ci	case 3:
2611d722e3fbSopenharmony_ci		return "CUBE";
2612d722e3fbSopenharmony_ci	case 4:
2613d722e3fbSopenharmony_ci		return "BUFFER";
2614d722e3fbSopenharmony_ci	case 7:
2615d722e3fbSopenharmony_ci		return "NULL";
2616d722e3fbSopenharmony_ci	default:
2617d722e3fbSopenharmony_ci		return "unknown";
2618d722e3fbSopenharmony_ci	}
2619d722e3fbSopenharmony_ci}
2620d722e3fbSopenharmony_ci
2621d722e3fbSopenharmony_cistatic const char *get_965_depthformat(unsigned int depthformat)
2622d722e3fbSopenharmony_ci{
2623d722e3fbSopenharmony_ci	switch (depthformat) {
2624d722e3fbSopenharmony_ci	case 0:
2625d722e3fbSopenharmony_ci		return "s8_z24float";
2626d722e3fbSopenharmony_ci	case 1:
2627d722e3fbSopenharmony_ci		return "z32float";
2628d722e3fbSopenharmony_ci	case 2:
2629d722e3fbSopenharmony_ci		return "z24s8";
2630d722e3fbSopenharmony_ci	case 5:
2631d722e3fbSopenharmony_ci		return "z16";
2632d722e3fbSopenharmony_ci	default:
2633d722e3fbSopenharmony_ci		return "unknown";
2634d722e3fbSopenharmony_ci	}
2635d722e3fbSopenharmony_ci}
2636d722e3fbSopenharmony_ci
2637d722e3fbSopenharmony_cistatic const char *get_965_element_component(uint32_t data, int component)
2638d722e3fbSopenharmony_ci{
2639d722e3fbSopenharmony_ci	uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
2640d722e3fbSopenharmony_ci
2641d722e3fbSopenharmony_ci	switch (component_control) {
2642d722e3fbSopenharmony_ci	case 0:
2643d722e3fbSopenharmony_ci		return "nostore";
2644d722e3fbSopenharmony_ci	case 1:
2645d722e3fbSopenharmony_ci		switch (component) {
2646d722e3fbSopenharmony_ci		case 0:
2647d722e3fbSopenharmony_ci			return "X";
2648d722e3fbSopenharmony_ci		case 1:
2649d722e3fbSopenharmony_ci			return "Y";
2650d722e3fbSopenharmony_ci		case 2:
2651d722e3fbSopenharmony_ci			return "Z";
2652d722e3fbSopenharmony_ci		case 3:
2653d722e3fbSopenharmony_ci			return "W";
2654d722e3fbSopenharmony_ci		default:
2655d722e3fbSopenharmony_ci			return "fail";
2656d722e3fbSopenharmony_ci		}
2657d722e3fbSopenharmony_ci	case 2:
2658d722e3fbSopenharmony_ci		return "0.0";
2659d722e3fbSopenharmony_ci	case 3:
2660d722e3fbSopenharmony_ci		return "1.0";
2661d722e3fbSopenharmony_ci	case 4:
2662d722e3fbSopenharmony_ci		return "0x1";
2663d722e3fbSopenharmony_ci	case 5:
2664d722e3fbSopenharmony_ci		return "VID";
2665d722e3fbSopenharmony_ci	default:
2666d722e3fbSopenharmony_ci		return "fail";
2667d722e3fbSopenharmony_ci	}
2668d722e3fbSopenharmony_ci}
2669d722e3fbSopenharmony_ci
2670d722e3fbSopenharmony_cistatic const char *get_965_prim_type(uint32_t primtype)
2671d722e3fbSopenharmony_ci{
2672d722e3fbSopenharmony_ci	switch (primtype) {
2673d722e3fbSopenharmony_ci	case 0x01:
2674d722e3fbSopenharmony_ci		return "point list";
2675d722e3fbSopenharmony_ci	case 0x02:
2676d722e3fbSopenharmony_ci		return "line list";
2677d722e3fbSopenharmony_ci	case 0x03:
2678d722e3fbSopenharmony_ci		return "line strip";
2679d722e3fbSopenharmony_ci	case 0x04:
2680d722e3fbSopenharmony_ci		return "tri list";
2681d722e3fbSopenharmony_ci	case 0x05:
2682d722e3fbSopenharmony_ci		return "tri strip";
2683d722e3fbSopenharmony_ci	case 0x06:
2684d722e3fbSopenharmony_ci		return "tri fan";
2685d722e3fbSopenharmony_ci	case 0x07:
2686d722e3fbSopenharmony_ci		return "quad list";
2687d722e3fbSopenharmony_ci	case 0x08:
2688d722e3fbSopenharmony_ci		return "quad strip";
2689d722e3fbSopenharmony_ci	case 0x09:
2690d722e3fbSopenharmony_ci		return "line list adj";
2691d722e3fbSopenharmony_ci	case 0x0a:
2692d722e3fbSopenharmony_ci		return "line strip adj";
2693d722e3fbSopenharmony_ci	case 0x0b:
2694d722e3fbSopenharmony_ci		return "tri list adj";
2695d722e3fbSopenharmony_ci	case 0x0c:
2696d722e3fbSopenharmony_ci		return "tri strip adj";
2697d722e3fbSopenharmony_ci	case 0x0d:
2698d722e3fbSopenharmony_ci		return "tri strip reverse";
2699d722e3fbSopenharmony_ci	case 0x0e:
2700d722e3fbSopenharmony_ci		return "polygon";
2701d722e3fbSopenharmony_ci	case 0x0f:
2702d722e3fbSopenharmony_ci		return "rect list";
2703d722e3fbSopenharmony_ci	case 0x10:
2704d722e3fbSopenharmony_ci		return "line loop";
2705d722e3fbSopenharmony_ci	case 0x11:
2706d722e3fbSopenharmony_ci		return "point list bf";
2707d722e3fbSopenharmony_ci	case 0x12:
2708d722e3fbSopenharmony_ci		return "line strip cont";
2709d722e3fbSopenharmony_ci	case 0x13:
2710d722e3fbSopenharmony_ci		return "line strip bf";
2711d722e3fbSopenharmony_ci	case 0x14:
2712d722e3fbSopenharmony_ci		return "line strip cont bf";
2713d722e3fbSopenharmony_ci	case 0x15:
2714d722e3fbSopenharmony_ci		return "tri fan no stipple";
2715d722e3fbSopenharmony_ci	default:
2716d722e3fbSopenharmony_ci		return "fail";
2717d722e3fbSopenharmony_ci	}
2718d722e3fbSopenharmony_ci}
2719d722e3fbSopenharmony_ci
2720d722e3fbSopenharmony_cistatic int
2721d722e3fbSopenharmony_cii965_decode_urb_fence(struct drm_intel_decode *ctx, int len)
2722d722e3fbSopenharmony_ci{
2723d722e3fbSopenharmony_ci	uint32_t vs_fence, clip_fence, gs_fence, sf_fence, vfe_fence, cs_fence;
2724d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
2725d722e3fbSopenharmony_ci
2726d722e3fbSopenharmony_ci	if (len != 3)
2727d722e3fbSopenharmony_ci		fprintf(out, "Bad count in URB_FENCE\n");
2728d722e3fbSopenharmony_ci
2729d722e3fbSopenharmony_ci	vs_fence = data[1] & 0x3ff;
2730d722e3fbSopenharmony_ci	gs_fence = (data[1] >> 10) & 0x3ff;
2731d722e3fbSopenharmony_ci	clip_fence = (data[1] >> 20) & 0x3ff;
2732d722e3fbSopenharmony_ci	sf_fence = data[2] & 0x3ff;
2733d722e3fbSopenharmony_ci	vfe_fence = (data[2] >> 10) & 0x3ff;
2734d722e3fbSopenharmony_ci	cs_fence = (data[2] >> 20) & 0x7ff;
2735d722e3fbSopenharmony_ci
2736d722e3fbSopenharmony_ci	instr_out(ctx, 0, "URB_FENCE: %s%s%s%s%s%s\n",
2737d722e3fbSopenharmony_ci		  (data[0] >> 13) & 1 ? "cs " : "",
2738d722e3fbSopenharmony_ci		  (data[0] >> 12) & 1 ? "vfe " : "",
2739d722e3fbSopenharmony_ci		  (data[0] >> 11) & 1 ? "sf " : "",
2740d722e3fbSopenharmony_ci		  (data[0] >> 10) & 1 ? "clip " : "",
2741d722e3fbSopenharmony_ci		  (data[0] >> 9) & 1 ? "gs " : "",
2742d722e3fbSopenharmony_ci		  (data[0] >> 8) & 1 ? "vs " : "");
2743d722e3fbSopenharmony_ci	instr_out(ctx, 1,
2744d722e3fbSopenharmony_ci		  "vs fence: %d, clip_fence: %d, gs_fence: %d\n",
2745d722e3fbSopenharmony_ci		  vs_fence, clip_fence, gs_fence);
2746d722e3fbSopenharmony_ci	instr_out(ctx, 2,
2747d722e3fbSopenharmony_ci		  "sf fence: %d, vfe_fence: %d, cs_fence: %d\n",
2748d722e3fbSopenharmony_ci		  sf_fence, vfe_fence, cs_fence);
2749d722e3fbSopenharmony_ci	if (gs_fence < vs_fence)
2750d722e3fbSopenharmony_ci		fprintf(out, "gs fence < vs fence!\n");
2751d722e3fbSopenharmony_ci	if (clip_fence < gs_fence)
2752d722e3fbSopenharmony_ci		fprintf(out, "clip fence < gs fence!\n");
2753d722e3fbSopenharmony_ci	if (sf_fence < clip_fence)
2754d722e3fbSopenharmony_ci		fprintf(out, "sf fence < clip fence!\n");
2755d722e3fbSopenharmony_ci	if (cs_fence < sf_fence)
2756d722e3fbSopenharmony_ci		fprintf(out, "cs fence < sf fence!\n");
2757d722e3fbSopenharmony_ci
2758d722e3fbSopenharmony_ci	return len;
2759d722e3fbSopenharmony_ci}
2760d722e3fbSopenharmony_ci
2761d722e3fbSopenharmony_cistatic void
2762d722e3fbSopenharmony_cistate_base_out(struct drm_intel_decode *ctx, unsigned int index,
2763d722e3fbSopenharmony_ci	       const char *name)
2764d722e3fbSopenharmony_ci{
2765d722e3fbSopenharmony_ci	if (ctx->data[index] & 1) {
2766d722e3fbSopenharmony_ci		instr_out(ctx, index,
2767d722e3fbSopenharmony_ci			  "%s state base address 0x%08x\n", name,
2768d722e3fbSopenharmony_ci			  ctx->data[index] & ~1);
2769d722e3fbSopenharmony_ci	} else {
2770d722e3fbSopenharmony_ci		instr_out(ctx, index, "%s state base not updated\n",
2771d722e3fbSopenharmony_ci			  name);
2772d722e3fbSopenharmony_ci	}
2773d722e3fbSopenharmony_ci}
2774d722e3fbSopenharmony_ci
2775d722e3fbSopenharmony_cistatic void
2776d722e3fbSopenharmony_cistate_max_out(struct drm_intel_decode *ctx, unsigned int index,
2777d722e3fbSopenharmony_ci	      const char *name)
2778d722e3fbSopenharmony_ci{
2779d722e3fbSopenharmony_ci	if (ctx->data[index] & 1) {
2780d722e3fbSopenharmony_ci		if (ctx->data[index] == 1) {
2781d722e3fbSopenharmony_ci			instr_out(ctx, index,
2782d722e3fbSopenharmony_ci				  "%s state upper bound disabled\n", name);
2783d722e3fbSopenharmony_ci		} else {
2784d722e3fbSopenharmony_ci			instr_out(ctx, index,
2785d722e3fbSopenharmony_ci				  "%s state upper bound 0x%08x\n", name,
2786d722e3fbSopenharmony_ci				  ctx->data[index] & ~1);
2787d722e3fbSopenharmony_ci		}
2788d722e3fbSopenharmony_ci	} else {
2789d722e3fbSopenharmony_ci		instr_out(ctx, index,
2790d722e3fbSopenharmony_ci			  "%s state upper bound not updated\n", name);
2791d722e3fbSopenharmony_ci	}
2792d722e3fbSopenharmony_ci}
2793d722e3fbSopenharmony_ci
2794d722e3fbSopenharmony_cistatic int
2795d722e3fbSopenharmony_cigen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(struct drm_intel_decode *ctx)
2796d722e3fbSopenharmony_ci{
2797d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_CC\n");
2798d722e3fbSopenharmony_ci	instr_out(ctx, 1, "pointer to CC viewport\n");
2799d722e3fbSopenharmony_ci
2800d722e3fbSopenharmony_ci	return 2;
2801d722e3fbSopenharmony_ci}
2802d722e3fbSopenharmony_ci
2803d722e3fbSopenharmony_cistatic int
2804d722e3fbSopenharmony_cigen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(struct drm_intel_decode *ctx)
2805d722e3fbSopenharmony_ci{
2806d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP\n");
2807d722e3fbSopenharmony_ci	instr_out(ctx, 1, "pointer to SF_CLIP viewport\n");
2808d722e3fbSopenharmony_ci
2809d722e3fbSopenharmony_ci	return 2;
2810d722e3fbSopenharmony_ci}
2811d722e3fbSopenharmony_ci
2812d722e3fbSopenharmony_cistatic int
2813d722e3fbSopenharmony_cigen7_3DSTATE_BLEND_STATE_POINTERS(struct drm_intel_decode *ctx)
2814d722e3fbSopenharmony_ci{
2815d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_BLEND_STATE_POINTERS\n");
2816d722e3fbSopenharmony_ci	instr_out(ctx, 1, "pointer to BLEND_STATE at 0x%08x (%s)\n",
2817d722e3fbSopenharmony_ci		  ctx->data[1] & ~1,
2818d722e3fbSopenharmony_ci		  (ctx->data[1] & 1) ? "changed" : "unchanged");
2819d722e3fbSopenharmony_ci
2820d722e3fbSopenharmony_ci	return 2;
2821d722e3fbSopenharmony_ci}
2822d722e3fbSopenharmony_ci
2823d722e3fbSopenharmony_cistatic int
2824d722e3fbSopenharmony_cigen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(struct drm_intel_decode *ctx)
2825d722e3fbSopenharmony_ci{
2826d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_DEPTH_STENCIL_STATE_POINTERS\n");
2827d722e3fbSopenharmony_ci	instr_out(ctx, 1,
2828d722e3fbSopenharmony_ci		  "pointer to DEPTH_STENCIL_STATE at 0x%08x (%s)\n",
2829d722e3fbSopenharmony_ci		  ctx->data[1] & ~1,
2830d722e3fbSopenharmony_ci		  (ctx->data[1] & 1) ? "changed" : "unchanged");
2831d722e3fbSopenharmony_ci
2832d722e3fbSopenharmony_ci	return 2;
2833d722e3fbSopenharmony_ci}
2834d722e3fbSopenharmony_ci
2835d722e3fbSopenharmony_cistatic int
2836d722e3fbSopenharmony_cigen7_3DSTATE_HIER_DEPTH_BUFFER(struct drm_intel_decode *ctx)
2837d722e3fbSopenharmony_ci{
2838d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_HIER_DEPTH_BUFFER\n");
2839d722e3fbSopenharmony_ci	instr_out(ctx, 1, "pitch %db\n",
2840d722e3fbSopenharmony_ci		  (ctx->data[1] & 0x1ffff) + 1);
2841d722e3fbSopenharmony_ci	instr_out(ctx, 2, "pointer to HiZ buffer\n");
2842d722e3fbSopenharmony_ci
2843d722e3fbSopenharmony_ci	return 3;
2844d722e3fbSopenharmony_ci}
2845d722e3fbSopenharmony_ci
2846d722e3fbSopenharmony_cistatic int
2847d722e3fbSopenharmony_cigen6_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
2848d722e3fbSopenharmony_ci{
2849d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
2850d722e3fbSopenharmony_ci	instr_out(ctx, 1, "blend change %d\n", ctx->data[1] & 1);
2851d722e3fbSopenharmony_ci	instr_out(ctx, 2, "depth stencil change %d\n",
2852d722e3fbSopenharmony_ci		  ctx->data[2] & 1);
2853d722e3fbSopenharmony_ci	instr_out(ctx, 3, "cc change %d\n", ctx->data[3] & 1);
2854d722e3fbSopenharmony_ci
2855d722e3fbSopenharmony_ci	return 4;
2856d722e3fbSopenharmony_ci}
2857d722e3fbSopenharmony_ci
2858d722e3fbSopenharmony_cistatic int
2859d722e3fbSopenharmony_cigen7_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
2860d722e3fbSopenharmony_ci{
2861d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
2862d722e3fbSopenharmony_ci	instr_out(ctx, 1, "pointer to COLOR_CALC_STATE at 0x%08x "
2863d722e3fbSopenharmony_ci		  "(%s)\n",
2864d722e3fbSopenharmony_ci		  ctx->data[1] & ~1,
2865d722e3fbSopenharmony_ci		  (ctx->data[1] & 1) ? "changed" : "unchanged");
2866d722e3fbSopenharmony_ci
2867d722e3fbSopenharmony_ci	return 2;
2868d722e3fbSopenharmony_ci}
2869d722e3fbSopenharmony_ci
2870d722e3fbSopenharmony_cistatic int
2871d722e3fbSopenharmony_cigen7_3DSTATE_URB_unit(struct drm_intel_decode *ctx, const char *unit)
2872d722e3fbSopenharmony_ci{
2873d722e3fbSopenharmony_ci    int start_kb = ((ctx->data[1] >> 25) & 0x3f) * 8;
2874d722e3fbSopenharmony_ci    /* the field is # of 512-bit rows - 1, we print bytes */
2875d722e3fbSopenharmony_ci    int entry_size = (((ctx->data[1] >> 16) & 0x1ff) + 1);
2876d722e3fbSopenharmony_ci    int nr_entries = ctx->data[1] & 0xffff;
2877d722e3fbSopenharmony_ci
2878d722e3fbSopenharmony_ci    instr_out(ctx, 0, "3DSTATE_URB_%s\n", unit);
2879d722e3fbSopenharmony_ci    instr_out(ctx, 1,
2880d722e3fbSopenharmony_ci	      "%dKB start, size=%d 64B rows, nr_entries=%d, total size %dB\n",
2881d722e3fbSopenharmony_ci	      start_kb, entry_size, nr_entries, nr_entries * 64 * entry_size);
2882d722e3fbSopenharmony_ci
2883d722e3fbSopenharmony_ci    return 2;
2884d722e3fbSopenharmony_ci}
2885d722e3fbSopenharmony_ci
2886d722e3fbSopenharmony_cistatic int
2887d722e3fbSopenharmony_cigen7_3DSTATE_URB_VS(struct drm_intel_decode *ctx)
2888d722e3fbSopenharmony_ci{
2889d722e3fbSopenharmony_ci	return gen7_3DSTATE_URB_unit(ctx, "VS");
2890d722e3fbSopenharmony_ci}
2891d722e3fbSopenharmony_ci
2892d722e3fbSopenharmony_cistatic int
2893d722e3fbSopenharmony_cigen7_3DSTATE_URB_HS(struct drm_intel_decode *ctx)
2894d722e3fbSopenharmony_ci{
2895d722e3fbSopenharmony_ci	return gen7_3DSTATE_URB_unit(ctx, "HS");
2896d722e3fbSopenharmony_ci}
2897d722e3fbSopenharmony_ci
2898d722e3fbSopenharmony_cistatic int
2899d722e3fbSopenharmony_cigen7_3DSTATE_URB_DS(struct drm_intel_decode *ctx)
2900d722e3fbSopenharmony_ci{
2901d722e3fbSopenharmony_ci	return gen7_3DSTATE_URB_unit(ctx, "DS");
2902d722e3fbSopenharmony_ci}
2903d722e3fbSopenharmony_ci
2904d722e3fbSopenharmony_cistatic int
2905d722e3fbSopenharmony_cigen7_3DSTATE_URB_GS(struct drm_intel_decode *ctx)
2906d722e3fbSopenharmony_ci{
2907d722e3fbSopenharmony_ci	return gen7_3DSTATE_URB_unit(ctx, "GS");
2908d722e3fbSopenharmony_ci}
2909d722e3fbSopenharmony_ci
2910d722e3fbSopenharmony_cistatic int
2911d722e3fbSopenharmony_cigen7_3DSTATE_CONSTANT(struct drm_intel_decode *ctx, const char *unit)
2912d722e3fbSopenharmony_ci{
2913d722e3fbSopenharmony_ci	int rlen[4];
2914d722e3fbSopenharmony_ci
2915d722e3fbSopenharmony_ci	rlen[0] = (ctx->data[1] >> 0) & 0xffff;
2916d722e3fbSopenharmony_ci	rlen[1] = (ctx->data[1] >> 16) & 0xffff;
2917d722e3fbSopenharmony_ci	rlen[2] = (ctx->data[2] >> 0) & 0xffff;
2918d722e3fbSopenharmony_ci	rlen[3] = (ctx->data[2] >> 16) & 0xffff;
2919d722e3fbSopenharmony_ci
2920d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_CONSTANT_%s\n", unit);
2921d722e3fbSopenharmony_ci	instr_out(ctx, 1, "len 0 = %d, len 1 = %d\n", rlen[0], rlen[1]);
2922d722e3fbSopenharmony_ci	instr_out(ctx, 2, "len 2 = %d, len 3 = %d\n", rlen[2], rlen[3]);
2923d722e3fbSopenharmony_ci	instr_out(ctx, 3, "pointer to constbuf 0\n");
2924d722e3fbSopenharmony_ci	instr_out(ctx, 4, "pointer to constbuf 1\n");
2925d722e3fbSopenharmony_ci	instr_out(ctx, 5, "pointer to constbuf 2\n");
2926d722e3fbSopenharmony_ci	instr_out(ctx, 6, "pointer to constbuf 3\n");
2927d722e3fbSopenharmony_ci
2928d722e3fbSopenharmony_ci	return 7;
2929d722e3fbSopenharmony_ci}
2930d722e3fbSopenharmony_ci
2931d722e3fbSopenharmony_cistatic int
2932d722e3fbSopenharmony_cigen7_3DSTATE_CONSTANT_VS(struct drm_intel_decode *ctx)
2933d722e3fbSopenharmony_ci{
2934d722e3fbSopenharmony_ci	return gen7_3DSTATE_CONSTANT(ctx, "VS");
2935d722e3fbSopenharmony_ci}
2936d722e3fbSopenharmony_ci
2937d722e3fbSopenharmony_cistatic int
2938d722e3fbSopenharmony_cigen7_3DSTATE_CONSTANT_GS(struct drm_intel_decode *ctx)
2939d722e3fbSopenharmony_ci{
2940d722e3fbSopenharmony_ci	return gen7_3DSTATE_CONSTANT(ctx, "GS");
2941d722e3fbSopenharmony_ci}
2942d722e3fbSopenharmony_ci
2943d722e3fbSopenharmony_cistatic int
2944d722e3fbSopenharmony_cigen7_3DSTATE_CONSTANT_PS(struct drm_intel_decode *ctx)
2945d722e3fbSopenharmony_ci{
2946d722e3fbSopenharmony_ci	return gen7_3DSTATE_CONSTANT(ctx, "PS");
2947d722e3fbSopenharmony_ci}
2948d722e3fbSopenharmony_ci
2949d722e3fbSopenharmony_cistatic int
2950d722e3fbSopenharmony_cigen7_3DSTATE_CONSTANT_DS(struct drm_intel_decode *ctx)
2951d722e3fbSopenharmony_ci{
2952d722e3fbSopenharmony_ci	return gen7_3DSTATE_CONSTANT(ctx, "DS");
2953d722e3fbSopenharmony_ci}
2954d722e3fbSopenharmony_ci
2955d722e3fbSopenharmony_cistatic int
2956d722e3fbSopenharmony_cigen7_3DSTATE_CONSTANT_HS(struct drm_intel_decode *ctx)
2957d722e3fbSopenharmony_ci{
2958d722e3fbSopenharmony_ci	return gen7_3DSTATE_CONSTANT(ctx, "HS");
2959d722e3fbSopenharmony_ci}
2960d722e3fbSopenharmony_ci
2961d722e3fbSopenharmony_ci
2962d722e3fbSopenharmony_cistatic int
2963d722e3fbSopenharmony_cigen6_3DSTATE_WM(struct drm_intel_decode *ctx)
2964d722e3fbSopenharmony_ci{
2965d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_WM\n");
2966d722e3fbSopenharmony_ci	instr_out(ctx, 1, "kernel start pointer 0\n");
2967d722e3fbSopenharmony_ci	instr_out(ctx, 2,
2968d722e3fbSopenharmony_ci		  "SPF=%d, VME=%d, Sampler Count %d, "
2969d722e3fbSopenharmony_ci		  "Binding table count %d\n",
2970d722e3fbSopenharmony_ci		  (ctx->data[2] >> 31) & 1,
2971d722e3fbSopenharmony_ci		  (ctx->data[2] >> 30) & 1,
2972d722e3fbSopenharmony_ci		  (ctx->data[2] >> 27) & 7,
2973d722e3fbSopenharmony_ci		  (ctx->data[2] >> 18) & 0xff);
2974d722e3fbSopenharmony_ci	instr_out(ctx, 3, "scratch offset\n");
2975d722e3fbSopenharmony_ci	instr_out(ctx, 4,
2976d722e3fbSopenharmony_ci		  "Depth Clear %d, Depth Resolve %d, HiZ Resolve %d, "
2977d722e3fbSopenharmony_ci		  "Dispatch GRF start[0] %d, start[1] %d, start[2] %d\n",
2978d722e3fbSopenharmony_ci		  (ctx->data[4] & (1 << 30)) != 0,
2979d722e3fbSopenharmony_ci		  (ctx->data[4] & (1 << 28)) != 0,
2980d722e3fbSopenharmony_ci		  (ctx->data[4] & (1 << 27)) != 0,
2981d722e3fbSopenharmony_ci		  (ctx->data[4] >> 16) & 0x7f,
2982d722e3fbSopenharmony_ci		  (ctx->data[4] >> 8) & 0x7f,
2983d722e3fbSopenharmony_ci		  (ctx->data[4] & 0x7f));
2984d722e3fbSopenharmony_ci	instr_out(ctx, 5,
2985d722e3fbSopenharmony_ci		  "MaxThreads %d, PS KillPixel %d, PS computed Z %d, "
2986d722e3fbSopenharmony_ci		  "PS use sourceZ %d, Thread Dispatch %d, PS use sourceW %d, "
2987d722e3fbSopenharmony_ci		  "Dispatch32 %d, Dispatch16 %d, Dispatch8 %d\n",
2988d722e3fbSopenharmony_ci		  ((ctx->data[5] >> 25) & 0x7f) + 1,
2989d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 22)) != 0,
2990d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 21)) != 0,
2991d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 20)) != 0,
2992d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 19)) != 0,
2993d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 8)) != 0,
2994d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 2)) != 0,
2995d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 1)) != 0,
2996d722e3fbSopenharmony_ci		  (ctx->data[5] & (1 << 0)) != 0);
2997d722e3fbSopenharmony_ci	instr_out(ctx, 6,
2998d722e3fbSopenharmony_ci		  "Num SF output %d, Pos XY offset %d, ZW interp mode %d , "
2999d722e3fbSopenharmony_ci		  "Barycentric interp mode 0x%x, Point raster rule %d, "
3000d722e3fbSopenharmony_ci		  "Multisample mode %d, "
3001d722e3fbSopenharmony_ci		  "Multisample Dispatch mode %d\n",
3002d722e3fbSopenharmony_ci		  (ctx->data[6] >> 20) & 0x3f,
3003d722e3fbSopenharmony_ci		  (ctx->data[6] >> 18) & 3,
3004d722e3fbSopenharmony_ci		  (ctx->data[6] >> 16) & 3,
3005d722e3fbSopenharmony_ci		  (ctx->data[6] >> 10) & 0x3f,
3006d722e3fbSopenharmony_ci		  (ctx->data[6] & (1 << 9)) != 0,
3007d722e3fbSopenharmony_ci		  (ctx->data[6] >> 1) & 3,
3008d722e3fbSopenharmony_ci		  (ctx->data[6] & 1));
3009d722e3fbSopenharmony_ci	instr_out(ctx, 7, "kernel start pointer 1\n");
3010d722e3fbSopenharmony_ci	instr_out(ctx, 8, "kernel start pointer 2\n");
3011d722e3fbSopenharmony_ci
3012d722e3fbSopenharmony_ci	return 9;
3013d722e3fbSopenharmony_ci}
3014d722e3fbSopenharmony_ci
3015d722e3fbSopenharmony_cistatic int
3016d722e3fbSopenharmony_cigen7_3DSTATE_WM(struct drm_intel_decode *ctx)
3017d722e3fbSopenharmony_ci{
3018d722e3fbSopenharmony_ci	const char *computed_depth = "";
3019d722e3fbSopenharmony_ci	const char *early_depth = "";
3020d722e3fbSopenharmony_ci	const char *zw_interp = "";
3021d722e3fbSopenharmony_ci
3022d722e3fbSopenharmony_ci	switch ((ctx->data[1] >> 23) & 0x3) {
3023d722e3fbSopenharmony_ci	case 0:
3024d722e3fbSopenharmony_ci		computed_depth = "";
3025d722e3fbSopenharmony_ci		break;
3026d722e3fbSopenharmony_ci	case 1:
3027d722e3fbSopenharmony_ci		computed_depth = "computed depth";
3028d722e3fbSopenharmony_ci		break;
3029d722e3fbSopenharmony_ci	case 2:
3030d722e3fbSopenharmony_ci		computed_depth = "computed depth >=";
3031d722e3fbSopenharmony_ci		break;
3032d722e3fbSopenharmony_ci	case 3:
3033d722e3fbSopenharmony_ci		computed_depth = "computed depth <=";
3034d722e3fbSopenharmony_ci		break;
3035d722e3fbSopenharmony_ci	}
3036d722e3fbSopenharmony_ci
3037d722e3fbSopenharmony_ci	switch ((ctx->data[1] >> 21) & 0x3) {
3038d722e3fbSopenharmony_ci	case 0:
3039d722e3fbSopenharmony_ci		early_depth = "";
3040d722e3fbSopenharmony_ci		break;
3041d722e3fbSopenharmony_ci	case 1:
3042d722e3fbSopenharmony_ci		early_depth = ", EDSC_PSEXEC";
3043d722e3fbSopenharmony_ci		break;
3044d722e3fbSopenharmony_ci	case 2:
3045d722e3fbSopenharmony_ci		early_depth = ", EDSC_PREPS";
3046d722e3fbSopenharmony_ci		break;
3047d722e3fbSopenharmony_ci	case 3:
3048d722e3fbSopenharmony_ci		early_depth = ", BAD EDSC";
3049d722e3fbSopenharmony_ci		break;
3050d722e3fbSopenharmony_ci	}
3051d722e3fbSopenharmony_ci
3052d722e3fbSopenharmony_ci	switch ((ctx->data[1] >> 17) & 0x3) {
3053d722e3fbSopenharmony_ci	case 0:
3054d722e3fbSopenharmony_ci		early_depth = "";
3055d722e3fbSopenharmony_ci		break;
3056d722e3fbSopenharmony_ci	case 1:
3057d722e3fbSopenharmony_ci		early_depth = ", BAD ZW interp";
3058d722e3fbSopenharmony_ci		break;
3059d722e3fbSopenharmony_ci	case 2:
3060d722e3fbSopenharmony_ci		early_depth = ", ZW centroid";
3061d722e3fbSopenharmony_ci		break;
3062d722e3fbSopenharmony_ci	case 3:
3063d722e3fbSopenharmony_ci		early_depth = ", ZW sample";
3064d722e3fbSopenharmony_ci		break;
3065d722e3fbSopenharmony_ci	}
3066d722e3fbSopenharmony_ci
3067d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3DSTATE_WM\n");
3068d722e3fbSopenharmony_ci	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",
3069d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 11)) ? "PP " : "",
3070d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 12)) ? "PC " : "",
3071d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 13)) ? "PS " : "",
3072d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 14)) ? "NPP " : "",
3073d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 15)) ? "NPC " : "",
3074d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 16)) ? "NPS " : "",
3075d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 30)) ? ", depth clear" : "",
3076d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 29)) ? "" : ", disabled",
3077d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 28)) ? ", depth resolve" : "",
3078d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 27)) ? ", hiz resolve" : "",
3079d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 25)) ? ", kill" : "",
3080d722e3fbSopenharmony_ci		  computed_depth,
3081d722e3fbSopenharmony_ci		  early_depth,
3082d722e3fbSopenharmony_ci		  zw_interp,
3083d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 20)) ? ", source depth" : "",
3084d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 19)) ? ", source W" : "",
3085d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 10)) ? ", coverage" : "",
3086d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 4)) ? ", poly stipple" : "",
3087d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 3)) ? ", line stipple" : "",
3088d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 2)) ? ", point UL" : ", point UR"
3089d722e3fbSopenharmony_ci		  );
3090d722e3fbSopenharmony_ci	instr_out(ctx, 2, "MS\n");
3091d722e3fbSopenharmony_ci
3092d722e3fbSopenharmony_ci	return 3;
3093d722e3fbSopenharmony_ci}
3094d722e3fbSopenharmony_ci
3095d722e3fbSopenharmony_cistatic int
3096d722e3fbSopenharmony_cigen4_3DPRIMITIVE(struct drm_intel_decode *ctx)
3097d722e3fbSopenharmony_ci{
3098d722e3fbSopenharmony_ci	instr_out(ctx, 0,
3099d722e3fbSopenharmony_ci		  "3DPRIMITIVE: %s %s\n",
3100d722e3fbSopenharmony_ci		  get_965_prim_type((ctx->data[0] >> 10) & 0x1f),
3101d722e3fbSopenharmony_ci		  (ctx->data[0] & (1 << 15)) ? "random" : "sequential");
3102d722e3fbSopenharmony_ci	instr_out(ctx, 1, "vertex count\n");
3103d722e3fbSopenharmony_ci	instr_out(ctx, 2, "start vertex\n");
3104d722e3fbSopenharmony_ci	instr_out(ctx, 3, "instance count\n");
3105d722e3fbSopenharmony_ci	instr_out(ctx, 4, "start instance\n");
3106d722e3fbSopenharmony_ci	instr_out(ctx, 5, "index bias\n");
3107d722e3fbSopenharmony_ci
3108d722e3fbSopenharmony_ci	return 6;
3109d722e3fbSopenharmony_ci}
3110d722e3fbSopenharmony_ci
3111d722e3fbSopenharmony_cistatic int
3112d722e3fbSopenharmony_cigen7_3DPRIMITIVE(struct drm_intel_decode *ctx)
3113d722e3fbSopenharmony_ci{
3114d722e3fbSopenharmony_ci	bool indirect = !!(ctx->data[0] & (1 << 10));
3115d722e3fbSopenharmony_ci
3116d722e3fbSopenharmony_ci	instr_out(ctx, 0,
3117d722e3fbSopenharmony_ci		  "3DPRIMITIVE: %s%s\n",
3118d722e3fbSopenharmony_ci		  indirect ? " indirect" : "",
3119d722e3fbSopenharmony_ci		  (ctx->data[0] & (1 << 8)) ? " predicated" : "");
3120d722e3fbSopenharmony_ci	instr_out(ctx, 1, "%s %s\n",
3121d722e3fbSopenharmony_ci		  get_965_prim_type(ctx->data[1] & 0x3f),
3122d722e3fbSopenharmony_ci		  (ctx->data[1] & (1 << 8)) ? "random" : "sequential");
3123d722e3fbSopenharmony_ci	instr_out(ctx, 2, indirect ? "ignored" : "vertex count\n");
3124d722e3fbSopenharmony_ci	instr_out(ctx, 3, indirect ? "ignored" : "start vertex\n");
3125d722e3fbSopenharmony_ci	instr_out(ctx, 4, indirect ? "ignored" : "instance count\n");
3126d722e3fbSopenharmony_ci	instr_out(ctx, 5, indirect ? "ignored" : "start instance\n");
3127d722e3fbSopenharmony_ci	instr_out(ctx, 6, indirect ? "ignored" : "index bias\n");
3128d722e3fbSopenharmony_ci
3129d722e3fbSopenharmony_ci	return 7;
3130d722e3fbSopenharmony_ci}
3131d722e3fbSopenharmony_ci
3132d722e3fbSopenharmony_cistatic int
3133d722e3fbSopenharmony_cidecode_3d_965(struct drm_intel_decode *ctx)
3134d722e3fbSopenharmony_ci{
3135d722e3fbSopenharmony_ci	uint32_t opcode;
3136d722e3fbSopenharmony_ci	unsigned int len;
3137d722e3fbSopenharmony_ci	unsigned int i, j, sba_len;
3138d722e3fbSopenharmony_ci	const char *desc1 = NULL;
3139d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
3140d722e3fbSopenharmony_ci	uint32_t devid = ctx->devid;
3141d722e3fbSopenharmony_ci
3142d722e3fbSopenharmony_ci	struct {
3143d722e3fbSopenharmony_ci		uint32_t opcode;
3144d722e3fbSopenharmony_ci		uint32_t len_mask;
3145d722e3fbSopenharmony_ci		int unsigned min_len;
3146d722e3fbSopenharmony_ci		int unsigned max_len;
3147d722e3fbSopenharmony_ci		const char *name;
3148d722e3fbSopenharmony_ci		int gen;
3149d722e3fbSopenharmony_ci		int (*func)(struct drm_intel_decode *ctx);
3150d722e3fbSopenharmony_ci	} opcodes_3d[] = {
3151d722e3fbSopenharmony_ci		{ 0x6000, 0x00ff, 3, 3, "URB_FENCE" },
3152d722e3fbSopenharmony_ci		{ 0x6001, 0xffff, 2, 2, "CS_URB_STATE" },
3153d722e3fbSopenharmony_ci		{ 0x6002, 0x00ff, 2, 2, "CONSTANT_BUFFER" },
3154d722e3fbSopenharmony_ci		{ 0x6101, 0xffff, 6, 10, "STATE_BASE_ADDRESS" },
3155d722e3fbSopenharmony_ci		{ 0x6102, 0xffff, 2, 2, "STATE_SIP" },
3156d722e3fbSopenharmony_ci		{ 0x6104, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
3157d722e3fbSopenharmony_ci		{ 0x680b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
3158d722e3fbSopenharmony_ci		{ 0x6904, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
3159d722e3fbSopenharmony_ci		{ 0x7800, 0xffff, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
3160d722e3fbSopenharmony_ci		{ 0x7801, 0x00ff, 4, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
3161d722e3fbSopenharmony_ci		{ 0x7802, 0x00ff, 4, 4, "3DSTATE_SAMPLER_STATE_POINTERS" },
3162d722e3fbSopenharmony_ci		{ 0x7805, 0x00ff, 7, 7, "3DSTATE_DEPTH_BUFFER", 7 },
3163d722e3fbSopenharmony_ci		{ 0x7805, 0x00ff, 3, 3, "3DSTATE_URB" },
3164d722e3fbSopenharmony_ci		{ 0x7804, 0x00ff, 3, 3, "3DSTATE_CLEAR_PARAMS" },
3165d722e3fbSopenharmony_ci		{ 0x7806, 0x00ff, 3, 3, "3DSTATE_STENCIL_BUFFER" },
3166d722e3fbSopenharmony_ci		{ 0x790f, 0x00ff, 3, 3, "3DSTATE_HIER_DEPTH_BUFFER", 6 },
3167d722e3fbSopenharmony_ci		{ 0x7807, 0x00ff, 3, 3, "3DSTATE_HIER_DEPTH_BUFFER", 7, gen7_3DSTATE_HIER_DEPTH_BUFFER },
3168d722e3fbSopenharmony_ci		{ 0x7808, 0x00ff, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
3169d722e3fbSopenharmony_ci		{ 0x7809, 0x00ff, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
3170d722e3fbSopenharmony_ci		{ 0x780a, 0x00ff, 3, 3, "3DSTATE_INDEX_BUFFER" },
3171d722e3fbSopenharmony_ci		{ 0x780b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
3172d722e3fbSopenharmony_ci		{ 0x780d, 0x00ff, 4, 4, "3DSTATE_VIEWPORT_STATE_POINTERS" },
3173d722e3fbSopenharmony_ci		{ 0x780e, 0xffff, 4, 4, NULL, 6, gen6_3DSTATE_CC_STATE_POINTERS },
3174d722e3fbSopenharmony_ci		{ 0x780e, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_CC_STATE_POINTERS },
3175d722e3fbSopenharmony_ci		{ 0x780f, 0x00ff, 2, 2, "3DSTATE_SCISSOR_POINTERS" },
3176d722e3fbSopenharmony_ci		{ 0x7810, 0x00ff, 6, 6, "3DSTATE_VS" },
3177d722e3fbSopenharmony_ci		{ 0x7811, 0x00ff, 7, 7, "3DSTATE_GS" },
3178d722e3fbSopenharmony_ci		{ 0x7812, 0x00ff, 4, 4, "3DSTATE_CLIP" },
3179d722e3fbSopenharmony_ci		{ 0x7813, 0x00ff, 20, 20, "3DSTATE_SF", 6 },
3180d722e3fbSopenharmony_ci		{ 0x7813, 0x00ff, 7, 7, "3DSTATE_SF", 7 },
3181d722e3fbSopenharmony_ci		{ 0x7814, 0x00ff, 3, 3, "3DSTATE_WM", 7, gen7_3DSTATE_WM },
3182d722e3fbSopenharmony_ci		{ 0x7814, 0x00ff, 9, 9, "3DSTATE_WM", 6, gen6_3DSTATE_WM },
3183d722e3fbSopenharmony_ci		{ 0x7815, 0x00ff, 5, 5, "3DSTATE_CONSTANT_VS_STATE", 6 },
3184d722e3fbSopenharmony_ci		{ 0x7815, 0x00ff, 7, 7, "3DSTATE_CONSTANT_VS", 7, gen7_3DSTATE_CONSTANT_VS },
3185d722e3fbSopenharmony_ci		{ 0x7816, 0x00ff, 5, 5, "3DSTATE_CONSTANT_GS_STATE", 6 },
3186d722e3fbSopenharmony_ci		{ 0x7816, 0x00ff, 7, 7, "3DSTATE_CONSTANT_GS", 7, gen7_3DSTATE_CONSTANT_GS },
3187d722e3fbSopenharmony_ci		{ 0x7817, 0x00ff, 5, 5, "3DSTATE_CONSTANT_PS_STATE", 6 },
3188d722e3fbSopenharmony_ci		{ 0x7817, 0x00ff, 7, 7, "3DSTATE_CONSTANT_PS", 7, gen7_3DSTATE_CONSTANT_PS },
3189d722e3fbSopenharmony_ci		{ 0x7818, 0xffff, 2, 2, "3DSTATE_SAMPLE_MASK" },
3190d722e3fbSopenharmony_ci		{ 0x7819, 0x00ff, 7, 7, "3DSTATE_CONSTANT_HS", 7, gen7_3DSTATE_CONSTANT_HS },
3191d722e3fbSopenharmony_ci		{ 0x781a, 0x00ff, 7, 7, "3DSTATE_CONSTANT_DS", 7, gen7_3DSTATE_CONSTANT_DS },
3192d722e3fbSopenharmony_ci		{ 0x781b, 0x00ff, 7, 7, "3DSTATE_HS" },
3193d722e3fbSopenharmony_ci		{ 0x781c, 0x00ff, 4, 4, "3DSTATE_TE" },
3194d722e3fbSopenharmony_ci		{ 0x781d, 0x00ff, 6, 6, "3DSTATE_DS" },
3195d722e3fbSopenharmony_ci		{ 0x781e, 0x00ff, 3, 3, "3DSTATE_STREAMOUT" },
3196d722e3fbSopenharmony_ci		{ 0x781f, 0x00ff, 14, 14, "3DSTATE_SBE" },
3197d722e3fbSopenharmony_ci		{ 0x7820, 0x00ff, 8, 8, "3DSTATE_PS" },
3198d722e3fbSopenharmony_ci		{ 0x7821, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP },
3199d722e3fbSopenharmony_ci		{ 0x7823, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC },
3200d722e3fbSopenharmony_ci		{ 0x7824, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_BLEND_STATE_POINTERS },
3201d722e3fbSopenharmony_ci		{ 0x7825, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS },
3202d722e3fbSopenharmony_ci		{ 0x7826, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_VS" },
3203d722e3fbSopenharmony_ci		{ 0x7827, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_HS" },
3204d722e3fbSopenharmony_ci		{ 0x7828, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_DS" },
3205d722e3fbSopenharmony_ci		{ 0x7829, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_GS" },
3206d722e3fbSopenharmony_ci		{ 0x782a, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_PS" },
3207d722e3fbSopenharmony_ci		{ 0x782b, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_VS" },
3208d722e3fbSopenharmony_ci		{ 0x782c, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_HS" },
3209d722e3fbSopenharmony_ci		{ 0x782d, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_DS" },
3210d722e3fbSopenharmony_ci		{ 0x782e, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_GS" },
3211d722e3fbSopenharmony_ci		{ 0x782f, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_PS" },
3212d722e3fbSopenharmony_ci		{ 0x7830, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_VS },
3213d722e3fbSopenharmony_ci		{ 0x7831, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_HS },
3214d722e3fbSopenharmony_ci		{ 0x7832, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_DS },
3215d722e3fbSopenharmony_ci		{ 0x7833, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_GS },
3216d722e3fbSopenharmony_ci		{ 0x7900, 0xffff, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
3217d722e3fbSopenharmony_ci		{ 0x7901, 0xffff, 5, 5, "3DSTATE_CONSTANT_COLOR" },
3218d722e3fbSopenharmony_ci		{ 0x7905, 0xffff, 5, 7, "3DSTATE_DEPTH_BUFFER" },
3219d722e3fbSopenharmony_ci		{ 0x7906, 0xffff, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
3220d722e3fbSopenharmony_ci		{ 0x7907, 0xffff, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
3221d722e3fbSopenharmony_ci		{ 0x7908, 0xffff, 3, 3, "3DSTATE_LINE_STIPPLE" },
3222d722e3fbSopenharmony_ci		{ 0x7909, 0xffff, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
3223d722e3fbSopenharmony_ci		{ 0x7909, 0xffff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
3224d722e3fbSopenharmony_ci		{ 0x790a, 0xffff, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
3225d722e3fbSopenharmony_ci		{ 0x790b, 0xffff, 4, 4, "3DSTATE_GS_SVB_INDEX" },
3226d722e3fbSopenharmony_ci		{ 0x790d, 0xffff, 3, 3, "3DSTATE_MULTISAMPLE", 6 },
3227d722e3fbSopenharmony_ci		{ 0x790d, 0xffff, 4, 4, "3DSTATE_MULTISAMPLE", 7 },
3228d722e3fbSopenharmony_ci		{ 0x7910, 0x00ff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
3229d722e3fbSopenharmony_ci		{ 0x7912, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_VS" },
3230d722e3fbSopenharmony_ci		{ 0x7913, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_HS" },
3231d722e3fbSopenharmony_ci		{ 0x7914, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_DS" },
3232d722e3fbSopenharmony_ci		{ 0x7915, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_GS" },
3233d722e3fbSopenharmony_ci		{ 0x7916, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_PS" },
3234d722e3fbSopenharmony_ci		{ 0x7917, 0x00ff, 2, 2+128*2, "3DSTATE_SO_DECL_LIST" },
3235d722e3fbSopenharmony_ci		{ 0x7918, 0x00ff, 4, 4, "3DSTATE_SO_BUFFER" },
3236d722e3fbSopenharmony_ci		{ 0x7a00, 0x00ff, 4, 6, "PIPE_CONTROL" },
3237d722e3fbSopenharmony_ci		{ 0x7b00, 0x00ff, 7, 7, NULL, 7, gen7_3DPRIMITIVE },
3238d722e3fbSopenharmony_ci		{ 0x7b00, 0x00ff, 6, 6, NULL, 0, gen4_3DPRIMITIVE },
3239d722e3fbSopenharmony_ci	}, *opcode_3d = NULL;
3240d722e3fbSopenharmony_ci
3241d722e3fbSopenharmony_ci	opcode = (data[0] & 0xffff0000) >> 16;
3242d722e3fbSopenharmony_ci
3243d722e3fbSopenharmony_ci	for (i = 0; i < ARRAY_SIZE(opcodes_3d); i++) {
3244d722e3fbSopenharmony_ci		if (opcode != opcodes_3d[i].opcode)
3245d722e3fbSopenharmony_ci			continue;
3246d722e3fbSopenharmony_ci
3247d722e3fbSopenharmony_ci		/* If it's marked as not our gen, skip. */
3248d722e3fbSopenharmony_ci		if (opcodes_3d[i].gen && opcodes_3d[i].gen != ctx->gen)
3249d722e3fbSopenharmony_ci			continue;
3250d722e3fbSopenharmony_ci
3251d722e3fbSopenharmony_ci		opcode_3d = &opcodes_3d[i];
3252d722e3fbSopenharmony_ci		break;
3253d722e3fbSopenharmony_ci	}
3254d722e3fbSopenharmony_ci
3255d722e3fbSopenharmony_ci	if (opcode_3d) {
3256d722e3fbSopenharmony_ci		if (opcode_3d->max_len == 1)
3257d722e3fbSopenharmony_ci			len = 1;
3258d722e3fbSopenharmony_ci		else
3259d722e3fbSopenharmony_ci			len = (data[0] & opcode_3d->len_mask) + 2;
3260d722e3fbSopenharmony_ci
3261d722e3fbSopenharmony_ci		if (len < opcode_3d->min_len ||
3262d722e3fbSopenharmony_ci		    len > opcode_3d->max_len) {
3263d722e3fbSopenharmony_ci			fprintf(out, "Bad length %d in %s, expected %d-%d\n",
3264d722e3fbSopenharmony_ci				len, opcode_3d->name,
3265d722e3fbSopenharmony_ci				opcode_3d->min_len, opcode_3d->max_len);
3266d722e3fbSopenharmony_ci		}
3267d722e3fbSopenharmony_ci	} else {
3268d722e3fbSopenharmony_ci		len = (data[0] & 0x0000ffff) + 2;
3269d722e3fbSopenharmony_ci	}
3270d722e3fbSopenharmony_ci
3271d722e3fbSopenharmony_ci	switch (opcode) {
3272d722e3fbSopenharmony_ci	case 0x6000:
3273d722e3fbSopenharmony_ci		return i965_decode_urb_fence(ctx, len);
3274d722e3fbSopenharmony_ci	case 0x6001:
3275d722e3fbSopenharmony_ci		instr_out(ctx, 0, "CS_URB_STATE\n");
3276d722e3fbSopenharmony_ci		instr_out(ctx, 1,
3277d722e3fbSopenharmony_ci			  "entry_size: %d [%d bytes], n_entries: %d\n",
3278d722e3fbSopenharmony_ci			  (data[1] >> 4) & 0x1f,
3279d722e3fbSopenharmony_ci			  (((data[1] >> 4) & 0x1f) + 1) * 64, data[1] & 0x7);
3280d722e3fbSopenharmony_ci		return len;
3281d722e3fbSopenharmony_ci	case 0x6002:
3282d722e3fbSopenharmony_ci		instr_out(ctx, 0, "CONSTANT_BUFFER: %s\n",
3283d722e3fbSopenharmony_ci			  (data[0] >> 8) & 1 ? "valid" : "invalid");
3284d722e3fbSopenharmony_ci		instr_out(ctx, 1,
3285d722e3fbSopenharmony_ci			  "offset: 0x%08x, length: %d bytes\n", data[1] & ~0x3f,
3286d722e3fbSopenharmony_ci			  ((data[1] & 0x3f) + 1) * 64);
3287d722e3fbSopenharmony_ci		return len;
3288d722e3fbSopenharmony_ci	case 0x6101:
3289d722e3fbSopenharmony_ci		i = 0;
3290d722e3fbSopenharmony_ci		instr_out(ctx, 0, "STATE_BASE_ADDRESS\n");
3291d722e3fbSopenharmony_ci		i++;
3292d722e3fbSopenharmony_ci
3293d722e3fbSopenharmony_ci		if (IS_GEN6(devid) || IS_GEN7(devid))
3294d722e3fbSopenharmony_ci			sba_len = 10;
3295d722e3fbSopenharmony_ci		else if (IS_GEN5(devid))
3296d722e3fbSopenharmony_ci			sba_len = 8;
3297d722e3fbSopenharmony_ci		else
3298d722e3fbSopenharmony_ci			sba_len = 6;
3299d722e3fbSopenharmony_ci		if (len != sba_len)
3300d722e3fbSopenharmony_ci			fprintf(out, "Bad count in STATE_BASE_ADDRESS\n");
3301d722e3fbSopenharmony_ci
3302d722e3fbSopenharmony_ci		state_base_out(ctx, i++, "general");
3303d722e3fbSopenharmony_ci		state_base_out(ctx, i++, "surface");
3304d722e3fbSopenharmony_ci		if (IS_GEN6(devid) || IS_GEN7(devid))
3305d722e3fbSopenharmony_ci			state_base_out(ctx, i++, "dynamic");
3306d722e3fbSopenharmony_ci		state_base_out(ctx, i++, "indirect");
3307d722e3fbSopenharmony_ci		if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
3308d722e3fbSopenharmony_ci			state_base_out(ctx, i++, "instruction");
3309d722e3fbSopenharmony_ci
3310d722e3fbSopenharmony_ci		state_max_out(ctx, i++, "general");
3311d722e3fbSopenharmony_ci		if (IS_GEN6(devid) || IS_GEN7(devid))
3312d722e3fbSopenharmony_ci			state_max_out(ctx, i++, "dynamic");
3313d722e3fbSopenharmony_ci		state_max_out(ctx, i++, "indirect");
3314d722e3fbSopenharmony_ci		if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
3315d722e3fbSopenharmony_ci			state_max_out(ctx, i++, "instruction");
3316d722e3fbSopenharmony_ci
3317d722e3fbSopenharmony_ci		return len;
3318d722e3fbSopenharmony_ci	case 0x7800:
3319d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_PIPELINED_POINTERS\n");
3320d722e3fbSopenharmony_ci		instr_out(ctx, 1, "VS state\n");
3321d722e3fbSopenharmony_ci		instr_out(ctx, 2, "GS state\n");
3322d722e3fbSopenharmony_ci		instr_out(ctx, 3, "Clip state\n");
3323d722e3fbSopenharmony_ci		instr_out(ctx, 4, "SF state\n");
3324d722e3fbSopenharmony_ci		instr_out(ctx, 5, "WM state\n");
3325d722e3fbSopenharmony_ci		instr_out(ctx, 6, "CC state\n");
3326d722e3fbSopenharmony_ci		return len;
3327d722e3fbSopenharmony_ci	case 0x7801:
3328d722e3fbSopenharmony_ci		if (len != 6 && len != 4)
3329d722e3fbSopenharmony_ci			fprintf(out,
3330d722e3fbSopenharmony_ci				"Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
3331d722e3fbSopenharmony_ci		if (len == 6) {
3332d722e3fbSopenharmony_ci			instr_out(ctx, 0,
3333d722e3fbSopenharmony_ci				  "3DSTATE_BINDING_TABLE_POINTERS\n");
3334d722e3fbSopenharmony_ci			instr_out(ctx, 1, "VS binding table\n");
3335d722e3fbSopenharmony_ci			instr_out(ctx, 2, "GS binding table\n");
3336d722e3fbSopenharmony_ci			instr_out(ctx, 3, "Clip binding table\n");
3337d722e3fbSopenharmony_ci			instr_out(ctx, 4, "SF binding table\n");
3338d722e3fbSopenharmony_ci			instr_out(ctx, 5, "WM binding table\n");
3339d722e3fbSopenharmony_ci		} else {
3340d722e3fbSopenharmony_ci			instr_out(ctx, 0,
3341d722e3fbSopenharmony_ci				  "3DSTATE_BINDING_TABLE_POINTERS: VS mod %d, "
3342d722e3fbSopenharmony_ci				  "GS mod %d, PS mod %d\n",
3343d722e3fbSopenharmony_ci				  (data[0] & (1 << 8)) != 0,
3344d722e3fbSopenharmony_ci				  (data[0] & (1 << 9)) != 0,
3345d722e3fbSopenharmony_ci				  (data[0] & (1 << 12)) != 0);
3346d722e3fbSopenharmony_ci			instr_out(ctx, 1, "VS binding table\n");
3347d722e3fbSopenharmony_ci			instr_out(ctx, 2, "GS binding table\n");
3348d722e3fbSopenharmony_ci			instr_out(ctx, 3, "WM binding table\n");
3349d722e3fbSopenharmony_ci		}
3350d722e3fbSopenharmony_ci
3351d722e3fbSopenharmony_ci		return len;
3352d722e3fbSopenharmony_ci	case 0x7802:
3353d722e3fbSopenharmony_ci		instr_out(ctx, 0,
3354d722e3fbSopenharmony_ci			  "3DSTATE_SAMPLER_STATE_POINTERS: VS mod %d, "
3355d722e3fbSopenharmony_ci			  "GS mod %d, PS mod %d\n", (data[0] & (1 << 8)) != 0,
3356d722e3fbSopenharmony_ci			  (data[0] & (1 << 9)) != 0,
3357d722e3fbSopenharmony_ci			  (data[0] & (1 << 12)) != 0);
3358d722e3fbSopenharmony_ci		instr_out(ctx, 1, "VS sampler state\n");
3359d722e3fbSopenharmony_ci		instr_out(ctx, 2, "GS sampler state\n");
3360d722e3fbSopenharmony_ci		instr_out(ctx, 3, "WM sampler state\n");
3361d722e3fbSopenharmony_ci		return len;
3362d722e3fbSopenharmony_ci	case 0x7805:
3363d722e3fbSopenharmony_ci		/* Actually 3DSTATE_DEPTH_BUFFER on gen7. */
3364d722e3fbSopenharmony_ci		if (ctx->gen == 7)
3365d722e3fbSopenharmony_ci			break;
3366d722e3fbSopenharmony_ci
3367d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_URB\n");
3368d722e3fbSopenharmony_ci		instr_out(ctx, 1,
3369d722e3fbSopenharmony_ci			  "VS entries %d, alloc size %d (1024bit row)\n",
3370d722e3fbSopenharmony_ci			  data[1] & 0xffff, ((data[1] >> 16) & 0x07f) + 1);
3371d722e3fbSopenharmony_ci		instr_out(ctx, 2,
3372d722e3fbSopenharmony_ci			  "GS entries %d, alloc size %d (1024bit row)\n",
3373d722e3fbSopenharmony_ci			  (data[2] >> 8) & 0x3ff, (data[2] & 7) + 1);
3374d722e3fbSopenharmony_ci		return len;
3375d722e3fbSopenharmony_ci
3376d722e3fbSopenharmony_ci	case 0x7808:
3377d722e3fbSopenharmony_ci		if ((len - 1) % 4 != 0)
3378d722e3fbSopenharmony_ci			fprintf(out, "Bad count in 3DSTATE_VERTEX_BUFFERS\n");
3379d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_VERTEX_BUFFERS\n");
3380d722e3fbSopenharmony_ci
3381d722e3fbSopenharmony_ci		for (i = 1; i < len;) {
3382d722e3fbSopenharmony_ci			int idx, access;
3383d722e3fbSopenharmony_ci			if (IS_GEN6(devid)) {
3384d722e3fbSopenharmony_ci				idx = 26;
3385d722e3fbSopenharmony_ci				access = 20;
3386d722e3fbSopenharmony_ci			} else {
3387d722e3fbSopenharmony_ci				idx = 27;
3388d722e3fbSopenharmony_ci				access = 26;
3389d722e3fbSopenharmony_ci			}
3390d722e3fbSopenharmony_ci			instr_out(ctx, i,
3391d722e3fbSopenharmony_ci				  "buffer %d: %s, pitch %db\n", data[i] >> idx,
3392d722e3fbSopenharmony_ci				  data[i] & (1 << access) ? "random" :
3393d722e3fbSopenharmony_ci				  "sequential", data[i] & 0x07ff);
3394d722e3fbSopenharmony_ci			i++;
3395d722e3fbSopenharmony_ci			instr_out(ctx, i++, "buffer address\n");
3396d722e3fbSopenharmony_ci			instr_out(ctx, i++, "max index\n");
3397d722e3fbSopenharmony_ci			instr_out(ctx, i++, "mbz\n");
3398d722e3fbSopenharmony_ci		}
3399d722e3fbSopenharmony_ci		return len;
3400d722e3fbSopenharmony_ci
3401d722e3fbSopenharmony_ci	case 0x7809:
3402d722e3fbSopenharmony_ci		if ((len + 1) % 2 != 0)
3403d722e3fbSopenharmony_ci			fprintf(out, "Bad count in 3DSTATE_VERTEX_ELEMENTS\n");
3404d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_VERTEX_ELEMENTS\n");
3405d722e3fbSopenharmony_ci
3406d722e3fbSopenharmony_ci		for (i = 1; i < len;) {
3407d722e3fbSopenharmony_ci			instr_out(ctx, i,
3408d722e3fbSopenharmony_ci				  "buffer %d: %svalid, type 0x%04x, "
3409d722e3fbSopenharmony_ci				  "src offset 0x%04x bytes\n",
3410d722e3fbSopenharmony_ci				  data[i] >> ((IS_GEN6(devid) || IS_GEN7(devid)) ? 26 : 27),
3411d722e3fbSopenharmony_ci				  data[i] & (1 << ((IS_GEN6(devid) || IS_GEN7(devid)) ? 25 : 26)) ?
3412d722e3fbSopenharmony_ci				  "" : "in", (data[i] >> 16) & 0x1ff,
3413d722e3fbSopenharmony_ci				  data[i] & 0x07ff);
3414d722e3fbSopenharmony_ci			i++;
3415d722e3fbSopenharmony_ci			instr_out(ctx, i, "(%s, %s, %s, %s), "
3416d722e3fbSopenharmony_ci				  "dst offset 0x%02x bytes\n",
3417d722e3fbSopenharmony_ci				  get_965_element_component(data[i], 0),
3418d722e3fbSopenharmony_ci				  get_965_element_component(data[i], 1),
3419d722e3fbSopenharmony_ci				  get_965_element_component(data[i], 2),
3420d722e3fbSopenharmony_ci				  get_965_element_component(data[i], 3),
3421d722e3fbSopenharmony_ci				  (data[i] & 0xff) * 4);
3422d722e3fbSopenharmony_ci			i++;
3423d722e3fbSopenharmony_ci		}
3424d722e3fbSopenharmony_ci		return len;
3425d722e3fbSopenharmony_ci
3426d722e3fbSopenharmony_ci	case 0x780d:
3427d722e3fbSopenharmony_ci		instr_out(ctx, 0,
3428d722e3fbSopenharmony_ci			  "3DSTATE_VIEWPORT_STATE_POINTERS\n");
3429d722e3fbSopenharmony_ci		instr_out(ctx, 1, "clip\n");
3430d722e3fbSopenharmony_ci		instr_out(ctx, 2, "sf\n");
3431d722e3fbSopenharmony_ci		instr_out(ctx, 3, "cc\n");
3432d722e3fbSopenharmony_ci		return len;
3433d722e3fbSopenharmony_ci
3434d722e3fbSopenharmony_ci	case 0x780a:
3435d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_INDEX_BUFFER\n");
3436d722e3fbSopenharmony_ci		instr_out(ctx, 1, "beginning buffer address\n");
3437d722e3fbSopenharmony_ci		instr_out(ctx, 2, "ending buffer address\n");
3438d722e3fbSopenharmony_ci		return len;
3439d722e3fbSopenharmony_ci
3440d722e3fbSopenharmony_ci	case 0x780f:
3441d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_SCISSOR_POINTERS\n");
3442d722e3fbSopenharmony_ci		instr_out(ctx, 1, "scissor rect offset\n");
3443d722e3fbSopenharmony_ci		return len;
3444d722e3fbSopenharmony_ci
3445d722e3fbSopenharmony_ci	case 0x7810:
3446d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_VS\n");
3447d722e3fbSopenharmony_ci		instr_out(ctx, 1, "kernel pointer\n");
3448d722e3fbSopenharmony_ci		instr_out(ctx, 2,
3449d722e3fbSopenharmony_ci			  "SPF=%d, VME=%d, Sampler Count %d, "
3450d722e3fbSopenharmony_ci			  "Binding table count %d\n", (data[2] >> 31) & 1,
3451d722e3fbSopenharmony_ci			  (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3452d722e3fbSopenharmony_ci			  (data[2] >> 18) & 0xff);
3453d722e3fbSopenharmony_ci		instr_out(ctx, 3, "scratch offset\n");
3454d722e3fbSopenharmony_ci		instr_out(ctx, 4,
3455d722e3fbSopenharmony_ci			  "Dispatch GRF start %d, VUE read length %d, "
3456d722e3fbSopenharmony_ci			  "VUE read offset %d\n", (data[4] >> 20) & 0x1f,
3457d722e3fbSopenharmony_ci			  (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
3458d722e3fbSopenharmony_ci		instr_out(ctx, 5,
3459d722e3fbSopenharmony_ci			  "Max Threads %d, Vertex Cache %sable, "
3460d722e3fbSopenharmony_ci			  "VS func %sable\n", ((data[5] >> 25) & 0x7f) + 1,
3461d722e3fbSopenharmony_ci			  (data[5] & (1 << 1)) != 0 ? "dis" : "en",
3462d722e3fbSopenharmony_ci			  (data[5] & 1) != 0 ? "en" : "dis");
3463d722e3fbSopenharmony_ci		return len;
3464d722e3fbSopenharmony_ci
3465d722e3fbSopenharmony_ci	case 0x7811:
3466d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_GS\n");
3467d722e3fbSopenharmony_ci		instr_out(ctx, 1, "kernel pointer\n");
3468d722e3fbSopenharmony_ci		instr_out(ctx, 2,
3469d722e3fbSopenharmony_ci			  "SPF=%d, VME=%d, Sampler Count %d, "
3470d722e3fbSopenharmony_ci			  "Binding table count %d\n", (data[2] >> 31) & 1,
3471d722e3fbSopenharmony_ci			  (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3472d722e3fbSopenharmony_ci			  (data[2] >> 18) & 0xff);
3473d722e3fbSopenharmony_ci		instr_out(ctx, 3, "scratch offset\n");
3474d722e3fbSopenharmony_ci		instr_out(ctx, 4,
3475d722e3fbSopenharmony_ci			  "Dispatch GRF start %d, VUE read length %d, "
3476d722e3fbSopenharmony_ci			  "VUE read offset %d\n", (data[4] & 0xf),
3477d722e3fbSopenharmony_ci			  (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
3478d722e3fbSopenharmony_ci		instr_out(ctx, 5,
3479d722e3fbSopenharmony_ci			  "Max Threads %d, Rendering %sable\n",
3480d722e3fbSopenharmony_ci			  ((data[5] >> 25) & 0x7f) + 1,
3481d722e3fbSopenharmony_ci			  (data[5] & (1 << 8)) != 0 ? "en" : "dis");
3482d722e3fbSopenharmony_ci		instr_out(ctx, 6,
3483d722e3fbSopenharmony_ci			  "Reorder %sable, Discard Adjaceny %sable, "
3484d722e3fbSopenharmony_ci			  "GS %sable\n",
3485d722e3fbSopenharmony_ci			  (data[6] & (1 << 30)) != 0 ? "en" : "dis",
3486d722e3fbSopenharmony_ci			  (data[6] & (1 << 29)) != 0 ? "en" : "dis",
3487d722e3fbSopenharmony_ci			  (data[6] & (1 << 15)) != 0 ? "en" : "dis");
3488d722e3fbSopenharmony_ci		return len;
3489d722e3fbSopenharmony_ci
3490d722e3fbSopenharmony_ci	case 0x7812:
3491d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_CLIP\n");
3492d722e3fbSopenharmony_ci		instr_out(ctx, 1,
3493d722e3fbSopenharmony_ci			  "UserClip distance cull test mask 0x%x\n",
3494d722e3fbSopenharmony_ci			  data[1] & 0xff);
3495d722e3fbSopenharmony_ci		instr_out(ctx, 2,
3496d722e3fbSopenharmony_ci			  "Clip %sable, API mode %s, Viewport XY test %sable, "
3497d722e3fbSopenharmony_ci			  "Viewport Z test %sable, Guardband test %sable, Clip mode %d, "
3498d722e3fbSopenharmony_ci			  "Perspective Divide %sable, Non-Perspective Barycentric %sable, "
3499d722e3fbSopenharmony_ci			  "Tri Provoking %d, Line Provoking %d, Trifan Provoking %d\n",
3500d722e3fbSopenharmony_ci			  (data[2] & (1 << 31)) != 0 ? "en" : "dis",
3501d722e3fbSopenharmony_ci			  (data[2] & (1 << 30)) != 0 ? "D3D" : "OGL",
3502d722e3fbSopenharmony_ci			  (data[2] & (1 << 28)) != 0 ? "en" : "dis",
3503d722e3fbSopenharmony_ci			  (data[2] & (1 << 27)) != 0 ? "en" : "dis",
3504d722e3fbSopenharmony_ci			  (data[2] & (1 << 26)) != 0 ? "en" : "dis",
3505d722e3fbSopenharmony_ci			  (data[2] >> 13) & 7,
3506d722e3fbSopenharmony_ci			  (data[2] & (1 << 9)) != 0 ? "dis" : "en",
3507d722e3fbSopenharmony_ci			  (data[2] & (1 << 8)) != 0 ? "en" : "dis",
3508d722e3fbSopenharmony_ci			  (data[2] >> 4) & 3, (data[2] >> 2) & 3,
3509d722e3fbSopenharmony_ci			  (data[2] & 3));
3510d722e3fbSopenharmony_ci		instr_out(ctx, 3,
3511d722e3fbSopenharmony_ci			  "Min PointWidth %d, Max PointWidth %d, "
3512d722e3fbSopenharmony_ci			  "Force Zero RTAIndex %sable, Max VPIndex %d\n",
3513d722e3fbSopenharmony_ci			  (data[3] >> 17) & 0x7ff, (data[3] >> 6) & 0x7ff,
3514d722e3fbSopenharmony_ci			  (data[3] & (1 << 5)) != 0 ? "en" : "dis",
3515d722e3fbSopenharmony_ci			  (data[3] & 0xf));
3516d722e3fbSopenharmony_ci		return len;
3517d722e3fbSopenharmony_ci
3518d722e3fbSopenharmony_ci	case 0x7813:
3519d722e3fbSopenharmony_ci		if (ctx->gen == 7)
3520d722e3fbSopenharmony_ci			break;
3521d722e3fbSopenharmony_ci
3522d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_SF\n");
3523d722e3fbSopenharmony_ci		instr_out(ctx, 1,
3524d722e3fbSopenharmony_ci			  "Attrib Out %d, Attrib Swizzle %sable, VUE read length %d, "
3525d722e3fbSopenharmony_ci			  "VUE read offset %d\n", (data[1] >> 22) & 0x3f,
3526d722e3fbSopenharmony_ci			  (data[1] & (1 << 21)) != 0 ? "en" : "dis",
3527d722e3fbSopenharmony_ci			  (data[1] >> 11) & 0x1f, (data[1] >> 4) & 0x3f);
3528d722e3fbSopenharmony_ci		instr_out(ctx, 2,
3529d722e3fbSopenharmony_ci			  "Legacy Global DepthBias %sable, FrontFace fill %d, BF fill %d, "
3530d722e3fbSopenharmony_ci			  "VP transform %sable, FrontWinding_%s\n",
3531d722e3fbSopenharmony_ci			  (data[2] & (1 << 11)) != 0 ? "en" : "dis",
3532d722e3fbSopenharmony_ci			  (data[2] >> 5) & 3, (data[2] >> 3) & 3,
3533d722e3fbSopenharmony_ci			  (data[2] & (1 << 1)) != 0 ? "en" : "dis",
3534d722e3fbSopenharmony_ci			  (data[2] & 1) != 0 ? "CCW" : "CW");
3535d722e3fbSopenharmony_ci		instr_out(ctx, 3,
3536d722e3fbSopenharmony_ci			  "AA %sable, CullMode %d, Scissor %sable, Multisample m ode %d\n",
3537d722e3fbSopenharmony_ci			  (data[3] & (1 << 31)) != 0 ? "en" : "dis",
3538d722e3fbSopenharmony_ci			  (data[3] >> 29) & 3,
3539d722e3fbSopenharmony_ci			  (data[3] & (1 << 11)) != 0 ? "en" : "dis",
3540d722e3fbSopenharmony_ci			  (data[3] >> 8) & 3);
3541d722e3fbSopenharmony_ci		instr_out(ctx, 4,
3542d722e3fbSopenharmony_ci			  "Last Pixel %sable, SubPixel Precision %d, Use PixelWidth %d\n",
3543d722e3fbSopenharmony_ci			  (data[4] & (1 << 31)) != 0 ? "en" : "dis",
3544d722e3fbSopenharmony_ci			  (data[4] & (1 << 12)) != 0 ? 4 : 8,
3545d722e3fbSopenharmony_ci			  (data[4] & (1 << 11)) != 0);
3546d722e3fbSopenharmony_ci		instr_out(ctx, 5,
3547d722e3fbSopenharmony_ci			  "Global Depth Offset Constant %f\n",
3548d722e3fbSopenharmony_ci			  *(float *)(&data[5]));
3549d722e3fbSopenharmony_ci		instr_out(ctx, 6, "Global Depth Offset Scale %f\n",
3550d722e3fbSopenharmony_ci			  *(float *)(&data[6]));
3551d722e3fbSopenharmony_ci		instr_out(ctx, 7, "Global Depth Offset Clamp %f\n",
3552d722e3fbSopenharmony_ci			  *(float *)(&data[7]));
3553d722e3fbSopenharmony_ci
3554d722e3fbSopenharmony_ci		for (i = 0, j = 0; i < 8; i++, j += 2)
3555d722e3fbSopenharmony_ci			instr_out(ctx, i + 8,
3556d722e3fbSopenharmony_ci				  "Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, "
3557d722e3fbSopenharmony_ci				  "Source %d); Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, Source %d)\n",
3558d722e3fbSopenharmony_ci				  j + 1,
3559d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 31)) != 0 ? "W" : "",
3560d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 30)) != 0 ? "Z" : "",
3561d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 29)) != 0 ? "Y" : "",
3562d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 28)) != 0 ? "X" : "",
3563d722e3fbSopenharmony_ci				  (data[8 + i] >> 25) & 3,
3564d722e3fbSopenharmony_ci				  (data[8 + i] >> 22) & 3,
3565d722e3fbSopenharmony_ci				  (data[8 + i] >> 16) & 0x1f, j,
3566d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 15)) != 0 ? "W" : "",
3567d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 14)) != 0 ? "Z" : "",
3568d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 13)) != 0 ? "Y" : "",
3569d722e3fbSopenharmony_ci				  (data[8 + i] & (1 << 12)) != 0 ? "X" : "",
3570d722e3fbSopenharmony_ci				  (data[8 + i] >> 9) & 3,
3571d722e3fbSopenharmony_ci				  (data[8 + i] >> 6) & 3, (data[8 + i] & 0x1f));
3572d722e3fbSopenharmony_ci		instr_out(ctx, 16,
3573d722e3fbSopenharmony_ci			  "Point Sprite TexCoord Enable\n");
3574d722e3fbSopenharmony_ci		instr_out(ctx, 17, "Const Interp Enable\n");
3575d722e3fbSopenharmony_ci		instr_out(ctx, 18,
3576d722e3fbSopenharmony_ci			  "Attrib 7-0 WrapShortest Enable\n");
3577d722e3fbSopenharmony_ci		instr_out(ctx, 19,
3578d722e3fbSopenharmony_ci			  "Attrib 15-8 WrapShortest Enable\n");
3579d722e3fbSopenharmony_ci
3580d722e3fbSopenharmony_ci		return len;
3581d722e3fbSopenharmony_ci
3582d722e3fbSopenharmony_ci	case 0x7900:
3583d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
3584d722e3fbSopenharmony_ci		instr_out(ctx, 1, "top left: %d,%d\n",
3585d722e3fbSopenharmony_ci			  data[1] & 0xffff, (data[1] >> 16) & 0xffff);
3586d722e3fbSopenharmony_ci		instr_out(ctx, 2, "bottom right: %d,%d\n",
3587d722e3fbSopenharmony_ci			  data[2] & 0xffff, (data[2] >> 16) & 0xffff);
3588d722e3fbSopenharmony_ci		instr_out(ctx, 3, "origin: %d,%d\n",
3589d722e3fbSopenharmony_ci			  (int)data[3] & 0xffff, ((int)data[3] >> 16) & 0xffff);
3590d722e3fbSopenharmony_ci
3591d722e3fbSopenharmony_ci		return len;
3592d722e3fbSopenharmony_ci
3593d722e3fbSopenharmony_ci	case 0x7905:
3594d722e3fbSopenharmony_ci		instr_out(ctx, 0, "3DSTATE_DEPTH_BUFFER\n");
3595d722e3fbSopenharmony_ci		if (IS_GEN5(devid) || IS_GEN6(devid))
3596d722e3fbSopenharmony_ci			instr_out(ctx, 1,
3597d722e3fbSopenharmony_ci				  "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Separate Stencil %d\n",
3598d722e3fbSopenharmony_ci				  get_965_surfacetype(data[1] >> 29),
3599d722e3fbSopenharmony_ci				  get_965_depthformat((data[1] >> 18) & 0x7),
3600d722e3fbSopenharmony_ci				  (data[1] & 0x0001ffff) + 1,
3601d722e3fbSopenharmony_ci				  data[1] & (1 << 27) ? "" : "not ",
3602d722e3fbSopenharmony_ci				  (data[1] & (1 << 22)) != 0,
3603d722e3fbSopenharmony_ci				  (data[1] & (1 << 21)) != 0);
3604d722e3fbSopenharmony_ci		else
3605d722e3fbSopenharmony_ci			instr_out(ctx, 1,
3606d722e3fbSopenharmony_ci				  "%s, %s, pitch = %d bytes, %stiled\n",
3607d722e3fbSopenharmony_ci				  get_965_surfacetype(data[1] >> 29),
3608d722e3fbSopenharmony_ci				  get_965_depthformat((data[1] >> 18) & 0x7),
3609d722e3fbSopenharmony_ci				  (data[1] & 0x0001ffff) + 1,
3610d722e3fbSopenharmony_ci				  data[1] & (1 << 27) ? "" : "not ");
3611d722e3fbSopenharmony_ci		instr_out(ctx, 2, "depth offset\n");
3612d722e3fbSopenharmony_ci		instr_out(ctx, 3, "%dx%d\n",
3613d722e3fbSopenharmony_ci			  ((data[3] & 0x0007ffc0) >> 6) + 1,
3614d722e3fbSopenharmony_ci			  ((data[3] & 0xfff80000) >> 19) + 1);
3615d722e3fbSopenharmony_ci		instr_out(ctx, 4, "volume depth\n");
3616d722e3fbSopenharmony_ci		if (len >= 6)
3617d722e3fbSopenharmony_ci			instr_out(ctx, 5, "\n");
3618d722e3fbSopenharmony_ci		if (len >= 7) {
3619d722e3fbSopenharmony_ci			if (IS_GEN6(devid))
3620d722e3fbSopenharmony_ci				instr_out(ctx, 6, "\n");
3621d722e3fbSopenharmony_ci			else
3622d722e3fbSopenharmony_ci				instr_out(ctx, 6,
3623d722e3fbSopenharmony_ci					  "render target view extent\n");
3624d722e3fbSopenharmony_ci		}
3625d722e3fbSopenharmony_ci
3626d722e3fbSopenharmony_ci		return len;
3627d722e3fbSopenharmony_ci
3628d722e3fbSopenharmony_ci	case 0x7a00:
3629d722e3fbSopenharmony_ci		if (IS_GEN6(devid) || IS_GEN7(devid)) {
3630d722e3fbSopenharmony_ci			if (len != 4 && len != 5)
3631d722e3fbSopenharmony_ci				fprintf(out, "Bad count in PIPE_CONTROL\n");
3632d722e3fbSopenharmony_ci
3633d722e3fbSopenharmony_ci			switch ((data[1] >> 14) & 0x3) {
3634d722e3fbSopenharmony_ci			case 0:
3635d722e3fbSopenharmony_ci				desc1 = "no write";
3636d722e3fbSopenharmony_ci				break;
3637d722e3fbSopenharmony_ci			case 1:
3638d722e3fbSopenharmony_ci				desc1 = "qword write";
3639d722e3fbSopenharmony_ci				break;
3640d722e3fbSopenharmony_ci			case 2:
3641d722e3fbSopenharmony_ci				desc1 = "PS_DEPTH_COUNT write";
3642d722e3fbSopenharmony_ci				break;
3643d722e3fbSopenharmony_ci			case 3:
3644d722e3fbSopenharmony_ci				desc1 = "TIMESTAMP write";
3645d722e3fbSopenharmony_ci				break;
3646d722e3fbSopenharmony_ci			}
3647d722e3fbSopenharmony_ci			instr_out(ctx, 0, "PIPE_CONTROL\n");
3648d722e3fbSopenharmony_ci			instr_out(ctx, 1,
3649d722e3fbSopenharmony_ci				  "%s, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
3650d722e3fbSopenharmony_ci				  desc1,
3651d722e3fbSopenharmony_ci				  data[1] & (1 << 20) ? "cs stall, " : "",
3652d722e3fbSopenharmony_ci				  data[1] & (1 << 19) ?
3653d722e3fbSopenharmony_ci				  "global snapshot count reset, " : "",
3654d722e3fbSopenharmony_ci				  data[1] & (1 << 18) ? "tlb invalidate, " : "",
3655d722e3fbSopenharmony_ci				  data[1] & (1 << 17) ? "gfdt flush, " : "",
3656d722e3fbSopenharmony_ci				  data[1] & (1 << 17) ? "media state clear, " :
3657d722e3fbSopenharmony_ci				  "",
3658d722e3fbSopenharmony_ci				  data[1] & (1 << 13) ? "depth stall, " : "",
3659d722e3fbSopenharmony_ci				  data[1] & (1 << 12) ?
3660d722e3fbSopenharmony_ci				  "render target cache flush, " : "",
3661d722e3fbSopenharmony_ci				  data[1] & (1 << 11) ?
3662d722e3fbSopenharmony_ci				  "instruction cache invalidate, " : "",
3663d722e3fbSopenharmony_ci				  data[1] & (1 << 10) ?
3664d722e3fbSopenharmony_ci				  "texture cache invalidate, " : "",
3665d722e3fbSopenharmony_ci				  data[1] & (1 << 9) ?
3666d722e3fbSopenharmony_ci				  "indirect state invalidate, " : "",
3667d722e3fbSopenharmony_ci				  data[1] & (1 << 8) ? "notify irq, " : "",
3668d722e3fbSopenharmony_ci				  data[1] & (1 << 7) ? "PIPE_CONTROL flush, " :
3669d722e3fbSopenharmony_ci				  "",
3670d722e3fbSopenharmony_ci				  data[1] & (1 << 6) ? "protect mem app_id, " :
3671d722e3fbSopenharmony_ci				  "", data[1] & (1 << 5) ? "DC flush, " : "",
3672d722e3fbSopenharmony_ci				  data[1] & (1 << 4) ? "vf fetch invalidate, " :
3673d722e3fbSopenharmony_ci				  "",
3674d722e3fbSopenharmony_ci				  data[1] & (1 << 3) ?
3675d722e3fbSopenharmony_ci				  "constant cache invalidate, " : "",
3676d722e3fbSopenharmony_ci				  data[1] & (1 << 2) ?
3677d722e3fbSopenharmony_ci				  "state cache invalidate, " : "",
3678d722e3fbSopenharmony_ci				  data[1] & (1 << 1) ? "stall at scoreboard, " :
3679d722e3fbSopenharmony_ci				  "",
3680d722e3fbSopenharmony_ci				  data[1] & (1 << 0) ? "depth cache flush, " :
3681d722e3fbSopenharmony_ci				  "");
3682d722e3fbSopenharmony_ci			if (len == 5) {
3683d722e3fbSopenharmony_ci				instr_out(ctx, 2,
3684d722e3fbSopenharmony_ci					  "destination address\n");
3685d722e3fbSopenharmony_ci				instr_out(ctx, 3,
3686d722e3fbSopenharmony_ci					  "immediate dword low\n");
3687d722e3fbSopenharmony_ci				instr_out(ctx, 4,
3688d722e3fbSopenharmony_ci					  "immediate dword high\n");
3689d722e3fbSopenharmony_ci			} else {
3690d722e3fbSopenharmony_ci				for (i = 2; i < len; i++) {
3691d722e3fbSopenharmony_ci					instr_out(ctx, i, "\n");
3692d722e3fbSopenharmony_ci				}
3693d722e3fbSopenharmony_ci			}
3694d722e3fbSopenharmony_ci			return len;
3695d722e3fbSopenharmony_ci		} else {
3696d722e3fbSopenharmony_ci			if (len != 4)
3697d722e3fbSopenharmony_ci				fprintf(out, "Bad count in PIPE_CONTROL\n");
3698d722e3fbSopenharmony_ci
3699d722e3fbSopenharmony_ci			switch ((data[0] >> 14) & 0x3) {
3700d722e3fbSopenharmony_ci			case 0:
3701d722e3fbSopenharmony_ci				desc1 = "no write";
3702d722e3fbSopenharmony_ci				break;
3703d722e3fbSopenharmony_ci			case 1:
3704d722e3fbSopenharmony_ci				desc1 = "qword write";
3705d722e3fbSopenharmony_ci				break;
3706d722e3fbSopenharmony_ci			case 2:
3707d722e3fbSopenharmony_ci				desc1 = "PS_DEPTH_COUNT write";
3708d722e3fbSopenharmony_ci				break;
3709d722e3fbSopenharmony_ci			case 3:
3710d722e3fbSopenharmony_ci				desc1 = "TIMESTAMP write";
3711d722e3fbSopenharmony_ci				break;
3712d722e3fbSopenharmony_ci			}
3713d722e3fbSopenharmony_ci			instr_out(ctx, 0,
3714d722e3fbSopenharmony_ci				  "PIPE_CONTROL: %s, %sdepth stall, %sRC write flush, "
3715d722e3fbSopenharmony_ci				  "%sinst flush\n",
3716d722e3fbSopenharmony_ci				  desc1,
3717d722e3fbSopenharmony_ci				  data[0] & (1 << 13) ? "" : "no ",
3718d722e3fbSopenharmony_ci				  data[0] & (1 << 12) ? "" : "no ",
3719d722e3fbSopenharmony_ci				  data[0] & (1 << 11) ? "" : "no ");
3720d722e3fbSopenharmony_ci			instr_out(ctx, 1, "destination address\n");
3721d722e3fbSopenharmony_ci			instr_out(ctx, 2, "immediate dword low\n");
3722d722e3fbSopenharmony_ci			instr_out(ctx, 3, "immediate dword high\n");
3723d722e3fbSopenharmony_ci			return len;
3724d722e3fbSopenharmony_ci		}
3725d722e3fbSopenharmony_ci	}
3726d722e3fbSopenharmony_ci
3727d722e3fbSopenharmony_ci	if (opcode_3d) {
3728d722e3fbSopenharmony_ci		if (opcode_3d->func) {
3729d722e3fbSopenharmony_ci			return opcode_3d->func(ctx);
3730d722e3fbSopenharmony_ci		} else {
3731d722e3fbSopenharmony_ci			instr_out(ctx, 0, "%s\n", opcode_3d->name);
3732d722e3fbSopenharmony_ci
3733d722e3fbSopenharmony_ci			for (i = 1; i < len; i++) {
3734d722e3fbSopenharmony_ci				instr_out(ctx, i, "dword %d\n", i);
3735d722e3fbSopenharmony_ci			}
3736d722e3fbSopenharmony_ci			return len;
3737d722e3fbSopenharmony_ci		}
3738d722e3fbSopenharmony_ci	}
3739d722e3fbSopenharmony_ci
3740d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3D UNKNOWN: 3d_965 opcode = 0x%x\n",
3741d722e3fbSopenharmony_ci		  opcode);
3742d722e3fbSopenharmony_ci	return 1;
3743d722e3fbSopenharmony_ci}
3744d722e3fbSopenharmony_ci
3745d722e3fbSopenharmony_cistatic int
3746d722e3fbSopenharmony_cidecode_3d_i830(struct drm_intel_decode *ctx)
3747d722e3fbSopenharmony_ci{
3748d722e3fbSopenharmony_ci	unsigned int idx;
3749d722e3fbSopenharmony_ci	uint32_t opcode;
3750d722e3fbSopenharmony_ci	uint32_t *data = ctx->data;
3751d722e3fbSopenharmony_ci
3752d722e3fbSopenharmony_ci	struct {
3753d722e3fbSopenharmony_ci		uint32_t opcode;
3754d722e3fbSopenharmony_ci		unsigned int min_len;
3755d722e3fbSopenharmony_ci		unsigned int max_len;
3756d722e3fbSopenharmony_ci		const char *name;
3757d722e3fbSopenharmony_ci	} opcodes_3d[] = {
3758d722e3fbSopenharmony_ci		{ 0x02, 1, 1, "3DSTATE_MODES_3" },
3759d722e3fbSopenharmony_ci		{ 0x03, 1, 1, "3DSTATE_ENABLES_1" },
3760d722e3fbSopenharmony_ci		{ 0x04, 1, 1, "3DSTATE_ENABLES_2" },
3761d722e3fbSopenharmony_ci		{ 0x05, 1, 1, "3DSTATE_VFT0" },
3762d722e3fbSopenharmony_ci		{ 0x06, 1, 1, "3DSTATE_AA" },
3763d722e3fbSopenharmony_ci		{ 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
3764d722e3fbSopenharmony_ci		{ 0x08, 1, 1, "3DSTATE_MODES_1" },
3765d722e3fbSopenharmony_ci		{ 0x09, 1, 1, "3DSTATE_STENCIL_TEST" },
3766d722e3fbSopenharmony_ci		{ 0x0a, 1, 1, "3DSTATE_VFT1" },
3767d722e3fbSopenharmony_ci		{ 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" },
3768d722e3fbSopenharmony_ci		{ 0x0c, 1, 1, "3DSTATE_MODES_5" },
3769d722e3fbSopenharmony_ci		{ 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" },
3770d722e3fbSopenharmony_ci		{ 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" },
3771d722e3fbSopenharmony_ci		{ 0x0f, 1, 1, "3DSTATE_MODES_2" },
3772d722e3fbSopenharmony_ci		{ 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
3773d722e3fbSopenharmony_ci		{ 0x16, 1, 1, "3DSTATE_MODES_4"},
3774d722e3fbSopenharmony_ci	}, *opcode_3d;
3775d722e3fbSopenharmony_ci
3776d722e3fbSopenharmony_ci	opcode = (data[0] & 0x1f000000) >> 24;
3777d722e3fbSopenharmony_ci
3778d722e3fbSopenharmony_ci	switch (opcode) {
3779d722e3fbSopenharmony_ci	case 0x1f:
3780d722e3fbSopenharmony_ci		return decode_3d_primitive(ctx);
3781d722e3fbSopenharmony_ci	case 0x1d:
3782d722e3fbSopenharmony_ci		return decode_3d_1d(ctx);
3783d722e3fbSopenharmony_ci	case 0x1c:
3784d722e3fbSopenharmony_ci		return decode_3d_1c(ctx);
3785d722e3fbSopenharmony_ci	}
3786d722e3fbSopenharmony_ci
3787d722e3fbSopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
3788d722e3fbSopenharmony_ci		opcode_3d = &opcodes_3d[idx];
3789d722e3fbSopenharmony_ci		if ((data[0] & 0x1f000000) >> 24 == opcode_3d->opcode) {
3790d722e3fbSopenharmony_ci			unsigned int len = 1, i;
3791d722e3fbSopenharmony_ci
3792d722e3fbSopenharmony_ci			instr_out(ctx, 0, "%s\n", opcode_3d->name);
3793d722e3fbSopenharmony_ci			if (opcode_3d->max_len > 1) {
3794d722e3fbSopenharmony_ci				len = (data[0] & 0xff) + 2;
3795d722e3fbSopenharmony_ci				if (len < opcode_3d->min_len ||
3796d722e3fbSopenharmony_ci				    len > opcode_3d->max_len) {
3797d722e3fbSopenharmony_ci					fprintf(out, "Bad count in %s\n",
3798d722e3fbSopenharmony_ci						opcode_3d->name);
3799d722e3fbSopenharmony_ci				}
3800d722e3fbSopenharmony_ci			}
3801d722e3fbSopenharmony_ci
3802d722e3fbSopenharmony_ci			for (i = 1; i < len; i++) {
3803d722e3fbSopenharmony_ci				instr_out(ctx, i, "dword %d\n", i);
3804d722e3fbSopenharmony_ci			}
3805d722e3fbSopenharmony_ci			return len;
3806d722e3fbSopenharmony_ci		}
3807d722e3fbSopenharmony_ci	}
3808d722e3fbSopenharmony_ci
3809d722e3fbSopenharmony_ci	instr_out(ctx, 0, "3D UNKNOWN: 3d_i830 opcode = 0x%x\n",
3810d722e3fbSopenharmony_ci		  opcode);
3811d722e3fbSopenharmony_ci	return 1;
3812d722e3fbSopenharmony_ci}
3813d722e3fbSopenharmony_ci
3814d722e3fbSopenharmony_cidrm_public struct drm_intel_decode *
3815d722e3fbSopenharmony_cidrm_intel_decode_context_alloc(uint32_t devid)
3816d722e3fbSopenharmony_ci{
3817d722e3fbSopenharmony_ci	struct drm_intel_decode *ctx;
3818d722e3fbSopenharmony_ci	int gen = 0;
3819d722e3fbSopenharmony_ci
3820d722e3fbSopenharmony_ci	if (intel_get_genx(devid, &gen))
3821d722e3fbSopenharmony_ci		;
3822d722e3fbSopenharmony_ci	else if (IS_GEN8(devid))
3823d722e3fbSopenharmony_ci		gen = 8;
3824d722e3fbSopenharmony_ci	else if (IS_GEN7(devid))
3825d722e3fbSopenharmony_ci		gen = 7;
3826d722e3fbSopenharmony_ci	else if (IS_GEN6(devid))
3827d722e3fbSopenharmony_ci		gen = 6;
3828d722e3fbSopenharmony_ci	else if (IS_GEN5(devid))
3829d722e3fbSopenharmony_ci		gen = 5;
3830d722e3fbSopenharmony_ci	else if (IS_GEN4(devid))
3831d722e3fbSopenharmony_ci		gen = 4;
3832d722e3fbSopenharmony_ci	else if (IS_9XX(devid))
3833d722e3fbSopenharmony_ci		gen = 3;
3834d722e3fbSopenharmony_ci	else if (IS_GEN2(devid))
3835d722e3fbSopenharmony_ci		gen = 2;
3836d722e3fbSopenharmony_ci
3837d722e3fbSopenharmony_ci	if (!gen)
3838d722e3fbSopenharmony_ci		return NULL;
3839d722e3fbSopenharmony_ci
3840d722e3fbSopenharmony_ci	ctx = calloc(1, sizeof(struct drm_intel_decode));
3841d722e3fbSopenharmony_ci	if (!ctx)
3842d722e3fbSopenharmony_ci		return NULL;
3843d722e3fbSopenharmony_ci
3844d722e3fbSopenharmony_ci	ctx->devid = devid;
3845d722e3fbSopenharmony_ci	ctx->gen = gen;
3846d722e3fbSopenharmony_ci	ctx->out = stdout;
3847d722e3fbSopenharmony_ci
3848d722e3fbSopenharmony_ci	return ctx;
3849d722e3fbSopenharmony_ci}
3850d722e3fbSopenharmony_ci
3851d722e3fbSopenharmony_cidrm_public void
3852d722e3fbSopenharmony_cidrm_intel_decode_context_free(struct drm_intel_decode *ctx)
3853d722e3fbSopenharmony_ci{
3854d722e3fbSopenharmony_ci	free(ctx);
3855d722e3fbSopenharmony_ci}
3856d722e3fbSopenharmony_ci
3857d722e3fbSopenharmony_cidrm_public void
3858d722e3fbSopenharmony_cidrm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx,
3859d722e3fbSopenharmony_ci				   int dump_past_end)
3860d722e3fbSopenharmony_ci{
3861d722e3fbSopenharmony_ci	ctx->dump_past_end = !!dump_past_end;
3862d722e3fbSopenharmony_ci}
3863d722e3fbSopenharmony_ci
3864d722e3fbSopenharmony_cidrm_public void
3865d722e3fbSopenharmony_cidrm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx,
3866d722e3fbSopenharmony_ci				   void *data, uint32_t hw_offset, int count)
3867d722e3fbSopenharmony_ci{
3868d722e3fbSopenharmony_ci	ctx->base_data = data;
3869d722e3fbSopenharmony_ci	ctx->base_hw_offset = hw_offset;
3870d722e3fbSopenharmony_ci	ctx->base_count = count;
3871d722e3fbSopenharmony_ci}
3872d722e3fbSopenharmony_ci
3873d722e3fbSopenharmony_cidrm_public void
3874d722e3fbSopenharmony_cidrm_intel_decode_set_head_tail(struct drm_intel_decode *ctx,
3875d722e3fbSopenharmony_ci			       uint32_t head, uint32_t tail)
3876d722e3fbSopenharmony_ci{
3877d722e3fbSopenharmony_ci	ctx->head = head;
3878d722e3fbSopenharmony_ci	ctx->tail = tail;
3879d722e3fbSopenharmony_ci}
3880d722e3fbSopenharmony_ci
3881d722e3fbSopenharmony_cidrm_public void
3882d722e3fbSopenharmony_cidrm_intel_decode_set_output_file(struct drm_intel_decode *ctx,
3883d722e3fbSopenharmony_ci				 FILE *output)
3884d722e3fbSopenharmony_ci{
3885d722e3fbSopenharmony_ci	ctx->out = output;
3886d722e3fbSopenharmony_ci}
3887d722e3fbSopenharmony_ci
3888d722e3fbSopenharmony_ci/**
3889d722e3fbSopenharmony_ci * Decodes an i830-i915 batch buffer, writing the output to stdout.
3890d722e3fbSopenharmony_ci *
3891d722e3fbSopenharmony_ci * \param data batch buffer contents
3892d722e3fbSopenharmony_ci * \param count number of DWORDs to decode in the batch buffer
3893d722e3fbSopenharmony_ci * \param hw_offset hardware address for the buffer
3894d722e3fbSopenharmony_ci */
3895d722e3fbSopenharmony_cidrm_public void
3896d722e3fbSopenharmony_cidrm_intel_decode(struct drm_intel_decode *ctx)
3897d722e3fbSopenharmony_ci{
3898d722e3fbSopenharmony_ci	int ret;
3899d722e3fbSopenharmony_ci	unsigned int index = 0;
3900d722e3fbSopenharmony_ci	uint32_t devid;
3901d722e3fbSopenharmony_ci	int size;
3902d722e3fbSopenharmony_ci	void *temp;
3903d722e3fbSopenharmony_ci
3904d722e3fbSopenharmony_ci	if (!ctx)
3905d722e3fbSopenharmony_ci		return;
3906d722e3fbSopenharmony_ci
3907d722e3fbSopenharmony_ci	/* Put a scratch page full of obviously undefined data after
3908d722e3fbSopenharmony_ci	 * the batchbuffer.  This lets us avoid a bunch of length
3909d722e3fbSopenharmony_ci	 * checking in statically sized packets.
3910d722e3fbSopenharmony_ci	 */
3911d722e3fbSopenharmony_ci	size = ctx->base_count * 4;
3912d722e3fbSopenharmony_ci	temp = malloc(size + 4096);
3913d722e3fbSopenharmony_ci	memcpy(temp, ctx->base_data, size);
3914d722e3fbSopenharmony_ci	memset((char *)temp + size, 0xd0, 4096);
3915d722e3fbSopenharmony_ci	ctx->data = temp;
3916d722e3fbSopenharmony_ci
3917d722e3fbSopenharmony_ci	ctx->hw_offset = ctx->base_hw_offset;
3918d722e3fbSopenharmony_ci	ctx->count = ctx->base_count;
3919d722e3fbSopenharmony_ci
3920d722e3fbSopenharmony_ci	devid = ctx->devid;
3921d722e3fbSopenharmony_ci	head_offset = ctx->head;
3922d722e3fbSopenharmony_ci	tail_offset = ctx->tail;
3923d722e3fbSopenharmony_ci	out = ctx->out;
3924d722e3fbSopenharmony_ci
3925d722e3fbSopenharmony_ci	saved_s2_set = 0;
3926d722e3fbSopenharmony_ci	saved_s4_set = 1;
3927d722e3fbSopenharmony_ci
3928d722e3fbSopenharmony_ci	while (ctx->count > 0) {
3929d722e3fbSopenharmony_ci		index = 0;
3930d722e3fbSopenharmony_ci
3931d722e3fbSopenharmony_ci		switch ((ctx->data[index] & 0xe0000000) >> 29) {
3932d722e3fbSopenharmony_ci		case 0x0:
3933d722e3fbSopenharmony_ci			ret = decode_mi(ctx);
3934d722e3fbSopenharmony_ci
3935d722e3fbSopenharmony_ci			/* If MI_BATCHBUFFER_END happened, then dump
3936d722e3fbSopenharmony_ci			 * the rest of the output in case we some day
3937d722e3fbSopenharmony_ci			 * want it in debugging, but don't decode it
3938d722e3fbSopenharmony_ci			 * since it'll just confuse in the common
3939d722e3fbSopenharmony_ci			 * case.
3940d722e3fbSopenharmony_ci			 */
3941d722e3fbSopenharmony_ci			if (ret == -1) {
3942d722e3fbSopenharmony_ci				if (ctx->dump_past_end) {
3943d722e3fbSopenharmony_ci					index++;
3944d722e3fbSopenharmony_ci				} else {
3945d722e3fbSopenharmony_ci					for (index = index + 1; index < ctx->count;
3946d722e3fbSopenharmony_ci					     index++) {
3947d722e3fbSopenharmony_ci						instr_out(ctx, index, "\n");
3948d722e3fbSopenharmony_ci					}
3949d722e3fbSopenharmony_ci				}
3950d722e3fbSopenharmony_ci			} else
3951d722e3fbSopenharmony_ci				index += ret;
3952d722e3fbSopenharmony_ci			break;
3953d722e3fbSopenharmony_ci		case 0x2:
3954d722e3fbSopenharmony_ci			index += decode_2d(ctx);
3955d722e3fbSopenharmony_ci			break;
3956d722e3fbSopenharmony_ci		case 0x3:
3957d722e3fbSopenharmony_ci			if (IS_9XX(devid) && !IS_GEN3(devid)) {
3958d722e3fbSopenharmony_ci				index +=
3959d722e3fbSopenharmony_ci				    decode_3d_965(ctx);
3960d722e3fbSopenharmony_ci			} else if (IS_GEN3(devid)) {
3961d722e3fbSopenharmony_ci				index += decode_3d(ctx);
3962d722e3fbSopenharmony_ci			} else {
3963d722e3fbSopenharmony_ci				index +=
3964d722e3fbSopenharmony_ci				    decode_3d_i830(ctx);
3965d722e3fbSopenharmony_ci			}
3966d722e3fbSopenharmony_ci			break;
3967d722e3fbSopenharmony_ci		default:
3968d722e3fbSopenharmony_ci			instr_out(ctx, index, "UNKNOWN\n");
3969d722e3fbSopenharmony_ci			index++;
3970d722e3fbSopenharmony_ci			break;
3971d722e3fbSopenharmony_ci		}
3972d722e3fbSopenharmony_ci		fflush(out);
3973d722e3fbSopenharmony_ci
3974d722e3fbSopenharmony_ci		if (ctx->count < index)
3975d722e3fbSopenharmony_ci			break;
3976d722e3fbSopenharmony_ci
3977d722e3fbSopenharmony_ci		ctx->count -= index;
3978d722e3fbSopenharmony_ci		ctx->data += index;
3979d722e3fbSopenharmony_ci		ctx->hw_offset += 4 * index;
3980d722e3fbSopenharmony_ci	}
3981d722e3fbSopenharmony_ci
3982d722e3fbSopenharmony_ci	free(temp);
3983d722e3fbSopenharmony_ci}
3984