1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2010 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Eric Anholt <eric@anholt.net>
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci */
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/** @file intel_aub.h
29bf215546Sopenharmony_ci *
30bf215546Sopenharmony_ci * The AUB file is a file format used by Intel's internal simulation
31bf215546Sopenharmony_ci * and other validation tools.  It can be used at various levels by a
32bf215546Sopenharmony_ci * driver to input state to the simulated hardware or a replaying
33bf215546Sopenharmony_ci * debugger.
34bf215546Sopenharmony_ci *
35bf215546Sopenharmony_ci * We choose to dump AUB files using the trace block format for ease
36bf215546Sopenharmony_ci * of implementation -- dump out the blocks of memory as plain blobs
37bf215546Sopenharmony_ci * and insert ring commands to execute the batchbuffer blob.
38bf215546Sopenharmony_ci */
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci#ifndef _INTEL_AUB_H
41bf215546Sopenharmony_ci#define _INTEL_AUB_H
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci#define AUB_MI_NOOP			(0)
44bf215546Sopenharmony_ci#define AUB_MI_BATCH_BUFFER_START 	(0x31 << 23)
45bf215546Sopenharmony_ci#define AUB_PIPE_CONTROL		(0x7a000002)
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci/* DW0: instruction type. */
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci#define CMD_AUB			(7 << 29)
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci#define CMD_AUB_HEADER		(CMD_AUB | (1 << 23) | (0x05 << 16))
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci#define CMD_MEM_TRACE_REGISTER_POLL	(CMD_AUB | (0x2e << 23) | (0x02 << 16))
54bf215546Sopenharmony_ci#define CMD_MEM_TRACE_REGISTER_WRITE	(CMD_AUB | (0x2e << 23) | (0x03 << 16))
55bf215546Sopenharmony_ci#define CMD_MEM_TRACE_MEMORY_WRITE	(CMD_AUB | (0x2e << 23) | (0x06 << 16))
56bf215546Sopenharmony_ci#define CMD_MEM_TRACE_VERSION		(CMD_AUB | (0x2e << 23) | (0x0e << 16))
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci/* DW1 */
59bf215546Sopenharmony_ci# define AUB_HEADER_MAJOR_SHIFT		24
60bf215546Sopenharmony_ci# define AUB_HEADER_MINOR_SHIFT		16
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci#define CMD_AUB_TRACE_HEADER_BLOCK (CMD_AUB | (1 << 23) | (0x41 << 16))
63bf215546Sopenharmony_ci#define CMD_AUB_DUMP_BMP           (CMD_AUB | (1 << 23) | (0x9e << 16))
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci/* DW1 */
66bf215546Sopenharmony_ci#define AUB_TRACE_OPERATION_MASK	0x000000ff
67bf215546Sopenharmony_ci#define AUB_TRACE_OP_COMMENT		0x00000000
68bf215546Sopenharmony_ci#define AUB_TRACE_OP_DATA_WRITE		0x00000001
69bf215546Sopenharmony_ci#define AUB_TRACE_OP_COMMAND_WRITE	0x00000002
70bf215546Sopenharmony_ci#define AUB_TRACE_OP_MMIO_WRITE		0x00000003
71bf215546Sopenharmony_ci// operation = TRACE_DATA_WRITE, Type
72bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_MASK		0x0000ff00
73bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_NOTYPE		(0 << 8)
74bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_BATCH		(1 << 8)
75bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_VERTEX_BUFFER	(5 << 8)
76bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_2D_MAP		(6 << 8)
77bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_CUBE_MAP		(7 << 8)
78bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_VOLUME_MAP	(9 << 8)
79bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_1D_MAP		(10 << 8)
80bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_CONSTANT_BUFFER	(11 << 8)
81bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_CONSTANT_URB	(12 << 8)
82bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_INDEX_BUFFER	(13 << 8)
83bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_GENERAL		(14 << 8)
84bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_SURFACE		(15 << 8)
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci// operation = TRACE_COMMAND_WRITE, Type =
88bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_RING_HWB		(1 << 8)
89bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_RING_PRB0	(2 << 8)
90bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_RING_PRB1	(3 << 8)
91bf215546Sopenharmony_ci#define AUB_TRACE_TYPE_RING_PRB2	(4 << 8)
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci// Address space
94bf215546Sopenharmony_ci#define AUB_TRACE_ADDRESS_SPACE_MASK	0x00ff0000
95bf215546Sopenharmony_ci#define AUB_TRACE_MEMTYPE_GTT		(0 << 16)
96bf215546Sopenharmony_ci#define AUB_TRACE_MEMTYPE_LOCAL		(1 << 16)
97bf215546Sopenharmony_ci#define AUB_TRACE_MEMTYPE_NONLOCAL	(2 << 16)
98bf215546Sopenharmony_ci#define AUB_TRACE_MEMTYPE_PCI		(3 << 16)
99bf215546Sopenharmony_ci#define AUB_TRACE_MEMTYPE_GTT_ENTRY     (4 << 16)
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci#define AUB_MEM_TRACE_VERSION_FILE_VERSION	1
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci/* DW2 */
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci#define AUB_MEM_TRACE_VERSION_DEVICE_MASK	0x0000ff00
106bf215546Sopenharmony_ci#define AUB_MEM_TRACE_VERSION_DEVICE_SHIFT      8
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci#define AUB_MEM_TRACE_VERSION_METHOD_MASK	0x000c0000
109bf215546Sopenharmony_ci#define AUB_MEM_TRACE_VERSION_METHOD_PHY	(1 << 18)
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci#define AUB_MEM_TRACE_REGISTER_SIZE_MASK	0x000f0000
112bf215546Sopenharmony_ci#define AUB_MEM_TRACE_REGISTER_SIZE_DWORD	(2 << 16)
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci#define AUB_MEM_TRACE_REGISTER_SPACE_MASK	0xf0000000
115bf215546Sopenharmony_ci#define AUB_MEM_TRACE_REGISTER_SPACE_MMIO	(0 << 28)
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci/* DW3 */
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_MASK		0xf0000000
120bf215546Sopenharmony_ci#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT		(0 << 28)
121bf215546Sopenharmony_ci#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_PHYSICAL	(2 << 28)
122bf215546Sopenharmony_ci#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT_ENTRY	(4 << 28)
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci/**
125bf215546Sopenharmony_ci * aub_state_struct_type enum values are encoded with the top 16 bits
126bf215546Sopenharmony_ci * representing the type to be delivered to the .aub file, and the bottom 16
127bf215546Sopenharmony_ci * bits representing the subtype.  This macro performs the encoding.
128bf215546Sopenharmony_ci */
129bf215546Sopenharmony_ci#define ENCODE_SS_TYPE(type, subtype) (((type) << 16) | (subtype))
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_cienum aub_state_struct_type {
132bf215546Sopenharmony_ci   AUB_TRACE_VS_STATE =			ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 1),
133bf215546Sopenharmony_ci   AUB_TRACE_GS_STATE =			ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 2),
134bf215546Sopenharmony_ci   AUB_TRACE_CLIP_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 3),
135bf215546Sopenharmony_ci   AUB_TRACE_SF_STATE =			ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 4),
136bf215546Sopenharmony_ci   AUB_TRACE_WM_STATE =			ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 5),
137bf215546Sopenharmony_ci   AUB_TRACE_CC_STATE =			ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 6),
138bf215546Sopenharmony_ci   AUB_TRACE_CLIP_VP_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 7),
139bf215546Sopenharmony_ci   AUB_TRACE_SF_VP_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 8),
140bf215546Sopenharmony_ci   AUB_TRACE_CC_VP_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0x9),
141bf215546Sopenharmony_ci   AUB_TRACE_SAMPLER_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0xa),
142bf215546Sopenharmony_ci   AUB_TRACE_KERNEL_INSTRUCTIONS =	ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0xb),
143bf215546Sopenharmony_ci   AUB_TRACE_SCRATCH_SPACE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0xc),
144bf215546Sopenharmony_ci   AUB_TRACE_SAMPLER_DEFAULT_COLOR =	ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0xd),
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci   AUB_TRACE_SCISSOR_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0x15),
147bf215546Sopenharmony_ci   AUB_TRACE_BLEND_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0x16),
148bf215546Sopenharmony_ci   AUB_TRACE_DEPTH_STENCIL_STATE =	ENCODE_SS_TYPE(AUB_TRACE_TYPE_GENERAL, 0x17),
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci   AUB_TRACE_VERTEX_BUFFER =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_VERTEX_BUFFER, 0),
151bf215546Sopenharmony_ci   AUB_TRACE_BINDING_TABLE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_SURFACE, 0x100),
152bf215546Sopenharmony_ci   AUB_TRACE_SURFACE_STATE =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_SURFACE, 0x200),
153bf215546Sopenharmony_ci   AUB_TRACE_VS_CONSTANTS =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_CONSTANT_BUFFER, 0),
154bf215546Sopenharmony_ci   AUB_TRACE_WM_CONSTANTS =		ENCODE_SS_TYPE(AUB_TRACE_TYPE_CONSTANT_BUFFER, 1),
155bf215546Sopenharmony_ci};
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci#undef ENCODE_SS_TYPE
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci/**
160bf215546Sopenharmony_ci * Decode a aub_state_struct_type value to determine the type that should be
161bf215546Sopenharmony_ci * stored in the .aub file.
162bf215546Sopenharmony_ci */
163bf215546Sopenharmony_cistatic inline uint32_t AUB_TRACE_TYPE(enum aub_state_struct_type ss_type)
164bf215546Sopenharmony_ci{
165bf215546Sopenharmony_ci   return (ss_type & 0xFFFF0000) >> 16;
166bf215546Sopenharmony_ci}
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci/**
169bf215546Sopenharmony_ci * Decode a state_struct_type value to determine the subtype that should be
170bf215546Sopenharmony_ci * stored in the .aub file.
171bf215546Sopenharmony_ci */
172bf215546Sopenharmony_cistatic inline uint32_t AUB_TRACE_SUBTYPE(enum aub_state_struct_type ss_type)
173bf215546Sopenharmony_ci{
174bf215546Sopenharmony_ci   return ss_type & 0xFFFF;
175bf215546Sopenharmony_ci}
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci/* DW3: address */
178bf215546Sopenharmony_ci/* DW4: len */
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci#endif /* _INTEL_AUB_H */
181