xref: /OK3568_Linux_fs/kernel/drivers/gpu/drm/i915/i915_cmd_parser.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright © 2013 Intel Corporation
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun  * Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*4882a593Smuzhiyun  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*4882a593Smuzhiyun  * IN THE SOFTWARE.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * Authors:
24*4882a593Smuzhiyun  *    Brad Volkin <bradley.d.volkin@intel.com>
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include "gt/intel_engine.h"
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include "i915_drv.h"
31*4882a593Smuzhiyun #include "i915_memcpy.h"
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /**
34*4882a593Smuzhiyun  * DOC: batch buffer command parser
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * Motivation:
37*4882a593Smuzhiyun  * Certain OpenGL features (e.g. transform feedback, performance monitoring)
38*4882a593Smuzhiyun  * require userspace code to submit batches containing commands such as
39*4882a593Smuzhiyun  * MI_LOAD_REGISTER_IMM to access various registers. Unfortunately, some
40*4882a593Smuzhiyun  * generations of the hardware will noop these commands in "unsecure" batches
41*4882a593Smuzhiyun  * (which includes all userspace batches submitted via i915) even though the
42*4882a593Smuzhiyun  * commands may be safe and represent the intended programming model of the
43*4882a593Smuzhiyun  * device.
44*4882a593Smuzhiyun  *
45*4882a593Smuzhiyun  * The software command parser is similar in operation to the command parsing
46*4882a593Smuzhiyun  * done in hardware for unsecure batches. However, the software parser allows
47*4882a593Smuzhiyun  * some operations that would be noop'd by hardware, if the parser determines
48*4882a593Smuzhiyun  * the operation is safe, and submits the batch as "secure" to prevent hardware
49*4882a593Smuzhiyun  * parsing.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * Threats:
52*4882a593Smuzhiyun  * At a high level, the hardware (and software) checks attempt to prevent
53*4882a593Smuzhiyun  * granting userspace undue privileges. There are three categories of privilege.
54*4882a593Smuzhiyun  *
55*4882a593Smuzhiyun  * First, commands which are explicitly defined as privileged or which should
56*4882a593Smuzhiyun  * only be used by the kernel driver. The parser rejects such commands
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  * Second, commands which access registers. To support correct/enhanced
59*4882a593Smuzhiyun  * userspace functionality, particularly certain OpenGL extensions, the parser
60*4882a593Smuzhiyun  * provides a whitelist of registers which userspace may safely access
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * Third, commands which access privileged memory (i.e. GGTT, HWS page, etc).
63*4882a593Smuzhiyun  * The parser always rejects such commands.
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  * The majority of the problematic commands fall in the MI_* range, with only a
66*4882a593Smuzhiyun  * few specific commands on each engine (e.g. PIPE_CONTROL and MI_FLUSH_DW).
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  * Implementation:
69*4882a593Smuzhiyun  * Each engine maintains tables of commands and registers which the parser
70*4882a593Smuzhiyun  * uses in scanning batch buffers submitted to that engine.
71*4882a593Smuzhiyun  *
72*4882a593Smuzhiyun  * Since the set of commands that the parser must check for is significantly
73*4882a593Smuzhiyun  * smaller than the number of commands supported, the parser tables contain only
74*4882a593Smuzhiyun  * those commands required by the parser. This generally works because command
75*4882a593Smuzhiyun  * opcode ranges have standard command length encodings. So for commands that
76*4882a593Smuzhiyun  * the parser does not need to check, it can easily skip them. This is
77*4882a593Smuzhiyun  * implemented via a per-engine length decoding vfunc.
78*4882a593Smuzhiyun  *
79*4882a593Smuzhiyun  * Unfortunately, there are a number of commands that do not follow the standard
80*4882a593Smuzhiyun  * length encoding for their opcode range, primarily amongst the MI_* commands.
81*4882a593Smuzhiyun  * To handle this, the parser provides a way to define explicit "skip" entries
82*4882a593Smuzhiyun  * in the per-engine command tables.
83*4882a593Smuzhiyun  *
84*4882a593Smuzhiyun  * Other command table entries map fairly directly to high level categories
85*4882a593Smuzhiyun  * mentioned above: rejected, register whitelist. The parser implements a number
86*4882a593Smuzhiyun  * of checks, including the privileged memory checks, via a general bitmasking
87*4882a593Smuzhiyun  * mechanism.
88*4882a593Smuzhiyun  */
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /*
91*4882a593Smuzhiyun  * A command that requires special handling by the command parser.
92*4882a593Smuzhiyun  */
93*4882a593Smuzhiyun struct drm_i915_cmd_descriptor {
94*4882a593Smuzhiyun 	/*
95*4882a593Smuzhiyun 	 * Flags describing how the command parser processes the command.
96*4882a593Smuzhiyun 	 *
97*4882a593Smuzhiyun 	 * CMD_DESC_FIXED: The command has a fixed length if this is set,
98*4882a593Smuzhiyun 	 *                 a length mask if not set
99*4882a593Smuzhiyun 	 * CMD_DESC_SKIP: The command is allowed but does not follow the
100*4882a593Smuzhiyun 	 *                standard length encoding for the opcode range in
101*4882a593Smuzhiyun 	 *                which it falls
102*4882a593Smuzhiyun 	 * CMD_DESC_REJECT: The command is never allowed
103*4882a593Smuzhiyun 	 * CMD_DESC_REGISTER: The command should be checked against the
104*4882a593Smuzhiyun 	 *                    register whitelist for the appropriate ring
105*4882a593Smuzhiyun 	 */
106*4882a593Smuzhiyun 	u32 flags;
107*4882a593Smuzhiyun #define CMD_DESC_FIXED    (1<<0)
108*4882a593Smuzhiyun #define CMD_DESC_SKIP     (1<<1)
109*4882a593Smuzhiyun #define CMD_DESC_REJECT   (1<<2)
110*4882a593Smuzhiyun #define CMD_DESC_REGISTER (1<<3)
111*4882a593Smuzhiyun #define CMD_DESC_BITMASK  (1<<4)
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	/*
114*4882a593Smuzhiyun 	 * The command's unique identification bits and the bitmask to get them.
115*4882a593Smuzhiyun 	 * This isn't strictly the opcode field as defined in the spec and may
116*4882a593Smuzhiyun 	 * also include type, subtype, and/or subop fields.
117*4882a593Smuzhiyun 	 */
118*4882a593Smuzhiyun 	struct {
119*4882a593Smuzhiyun 		u32 value;
120*4882a593Smuzhiyun 		u32 mask;
121*4882a593Smuzhiyun 	} cmd;
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	/*
124*4882a593Smuzhiyun 	 * The command's length. The command is either fixed length (i.e. does
125*4882a593Smuzhiyun 	 * not include a length field) or has a length field mask. The flag
126*4882a593Smuzhiyun 	 * CMD_DESC_FIXED indicates a fixed length. Otherwise, the command has
127*4882a593Smuzhiyun 	 * a length mask. All command entries in a command table must include
128*4882a593Smuzhiyun 	 * length information.
129*4882a593Smuzhiyun 	 */
130*4882a593Smuzhiyun 	union {
131*4882a593Smuzhiyun 		u32 fixed;
132*4882a593Smuzhiyun 		u32 mask;
133*4882a593Smuzhiyun 	} length;
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	/*
136*4882a593Smuzhiyun 	 * Describes where to find a register address in the command to check
137*4882a593Smuzhiyun 	 * against the ring's register whitelist. Only valid if flags has the
138*4882a593Smuzhiyun 	 * CMD_DESC_REGISTER bit set.
139*4882a593Smuzhiyun 	 *
140*4882a593Smuzhiyun 	 * A non-zero step value implies that the command may access multiple
141*4882a593Smuzhiyun 	 * registers in sequence (e.g. LRI), in that case step gives the
142*4882a593Smuzhiyun 	 * distance in dwords between individual offset fields.
143*4882a593Smuzhiyun 	 */
144*4882a593Smuzhiyun 	struct {
145*4882a593Smuzhiyun 		u32 offset;
146*4882a593Smuzhiyun 		u32 mask;
147*4882a593Smuzhiyun 		u32 step;
148*4882a593Smuzhiyun 	} reg;
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun #define MAX_CMD_DESC_BITMASKS 3
151*4882a593Smuzhiyun 	/*
152*4882a593Smuzhiyun 	 * Describes command checks where a particular dword is masked and
153*4882a593Smuzhiyun 	 * compared against an expected value. If the command does not match
154*4882a593Smuzhiyun 	 * the expected value, the parser rejects it. Only valid if flags has
155*4882a593Smuzhiyun 	 * the CMD_DESC_BITMASK bit set. Only entries where mask is non-zero
156*4882a593Smuzhiyun 	 * are valid.
157*4882a593Smuzhiyun 	 *
158*4882a593Smuzhiyun 	 * If the check specifies a non-zero condition_mask then the parser
159*4882a593Smuzhiyun 	 * only performs the check when the bits specified by condition_mask
160*4882a593Smuzhiyun 	 * are non-zero.
161*4882a593Smuzhiyun 	 */
162*4882a593Smuzhiyun 	struct {
163*4882a593Smuzhiyun 		u32 offset;
164*4882a593Smuzhiyun 		u32 mask;
165*4882a593Smuzhiyun 		u32 expected;
166*4882a593Smuzhiyun 		u32 condition_offset;
167*4882a593Smuzhiyun 		u32 condition_mask;
168*4882a593Smuzhiyun 	} bits[MAX_CMD_DESC_BITMASKS];
169*4882a593Smuzhiyun };
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun /*
172*4882a593Smuzhiyun  * A table of commands requiring special handling by the command parser.
173*4882a593Smuzhiyun  *
174*4882a593Smuzhiyun  * Each engine has an array of tables. Each table consists of an array of
175*4882a593Smuzhiyun  * command descriptors, which must be sorted with command opcodes in
176*4882a593Smuzhiyun  * ascending order.
177*4882a593Smuzhiyun  */
178*4882a593Smuzhiyun struct drm_i915_cmd_table {
179*4882a593Smuzhiyun 	const struct drm_i915_cmd_descriptor *table;
180*4882a593Smuzhiyun 	int count;
181*4882a593Smuzhiyun };
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun #define STD_MI_OPCODE_SHIFT  (32 - 9)
184*4882a593Smuzhiyun #define STD_3D_OPCODE_SHIFT  (32 - 16)
185*4882a593Smuzhiyun #define STD_2D_OPCODE_SHIFT  (32 - 10)
186*4882a593Smuzhiyun #define STD_MFX_OPCODE_SHIFT (32 - 16)
187*4882a593Smuzhiyun #define MIN_OPCODE_SHIFT 16
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun #define CMD(op, opm, f, lm, fl, ...)				\
190*4882a593Smuzhiyun 	{							\
191*4882a593Smuzhiyun 		.flags = (fl) | ((f) ? CMD_DESC_FIXED : 0),	\
192*4882a593Smuzhiyun 		.cmd = { (op & ~0u << (opm)), ~0u << (opm) },	\
193*4882a593Smuzhiyun 		.length = { (lm) },				\
194*4882a593Smuzhiyun 		__VA_ARGS__					\
195*4882a593Smuzhiyun 	}
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun /* Convenience macros to compress the tables */
198*4882a593Smuzhiyun #define SMI STD_MI_OPCODE_SHIFT
199*4882a593Smuzhiyun #define S3D STD_3D_OPCODE_SHIFT
200*4882a593Smuzhiyun #define S2D STD_2D_OPCODE_SHIFT
201*4882a593Smuzhiyun #define SMFX STD_MFX_OPCODE_SHIFT
202*4882a593Smuzhiyun #define F true
203*4882a593Smuzhiyun #define S CMD_DESC_SKIP
204*4882a593Smuzhiyun #define R CMD_DESC_REJECT
205*4882a593Smuzhiyun #define W CMD_DESC_REGISTER
206*4882a593Smuzhiyun #define B CMD_DESC_BITMASK
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun /*            Command                          Mask   Fixed Len   Action
209*4882a593Smuzhiyun 	      ---------------------------------------------------------- */
210*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor gen7_common_cmds[] = {
211*4882a593Smuzhiyun 	CMD(  MI_NOOP,                          SMI,    F,  1,      S  ),
212*4882a593Smuzhiyun 	CMD(  MI_USER_INTERRUPT,                SMI,    F,  1,      R  ),
213*4882a593Smuzhiyun 	CMD(  MI_WAIT_FOR_EVENT,                SMI,    F,  1,      R  ),
214*4882a593Smuzhiyun 	CMD(  MI_ARB_CHECK,                     SMI,    F,  1,      S  ),
215*4882a593Smuzhiyun 	CMD(  MI_REPORT_HEAD,                   SMI,    F,  1,      S  ),
216*4882a593Smuzhiyun 	CMD(  MI_SUSPEND_FLUSH,                 SMI,    F,  1,      S  ),
217*4882a593Smuzhiyun 	CMD(  MI_SEMAPHORE_MBOX,                SMI,   !F,  0xFF,   R  ),
218*4882a593Smuzhiyun 	CMD(  MI_STORE_DWORD_INDEX,             SMI,   !F,  0xFF,   R  ),
219*4882a593Smuzhiyun 	CMD(  MI_LOAD_REGISTER_IMM(1),          SMI,   !F,  0xFF,   W,
220*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC, .step = 2 }    ),
221*4882a593Smuzhiyun 	CMD(  MI_STORE_REGISTER_MEM,            SMI,    F,  3,     W | B,
222*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC },
223*4882a593Smuzhiyun 	      .bits = {{
224*4882a593Smuzhiyun 			.offset = 0,
225*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
226*4882a593Smuzhiyun 			.expected = 0,
227*4882a593Smuzhiyun 	      }},						       ),
228*4882a593Smuzhiyun 	CMD(  MI_LOAD_REGISTER_MEM,             SMI,    F,  3,     W | B,
229*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC },
230*4882a593Smuzhiyun 	      .bits = {{
231*4882a593Smuzhiyun 			.offset = 0,
232*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
233*4882a593Smuzhiyun 			.expected = 0,
234*4882a593Smuzhiyun 	      }},						       ),
235*4882a593Smuzhiyun 	/*
236*4882a593Smuzhiyun 	 * MI_BATCH_BUFFER_START requires some special handling. It's not
237*4882a593Smuzhiyun 	 * really a 'skip' action but it doesn't seem like it's worth adding
238*4882a593Smuzhiyun 	 * a new action. See intel_engine_cmd_parser().
239*4882a593Smuzhiyun 	 */
240*4882a593Smuzhiyun 	CMD(  MI_BATCH_BUFFER_START,            SMI,   !F,  0xFF,   S  ),
241*4882a593Smuzhiyun };
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor gen7_render_cmds[] = {
244*4882a593Smuzhiyun 	CMD(  MI_FLUSH,                         SMI,    F,  1,      S  ),
245*4882a593Smuzhiyun 	CMD(  MI_ARB_ON_OFF,                    SMI,    F,  1,      R  ),
246*4882a593Smuzhiyun 	CMD(  MI_PREDICATE,                     SMI,    F,  1,      S  ),
247*4882a593Smuzhiyun 	CMD(  MI_TOPOLOGY_FILTER,               SMI,    F,  1,      S  ),
248*4882a593Smuzhiyun 	CMD(  MI_SET_APPID,                     SMI,    F,  1,      S  ),
249*4882a593Smuzhiyun 	CMD(  MI_DISPLAY_FLIP,                  SMI,   !F,  0xFF,   R  ),
250*4882a593Smuzhiyun 	CMD(  MI_SET_CONTEXT,                   SMI,   !F,  0xFF,   R  ),
251*4882a593Smuzhiyun 	CMD(  MI_URB_CLEAR,                     SMI,   !F,  0xFF,   S  ),
252*4882a593Smuzhiyun 	CMD(  MI_STORE_DWORD_IMM,               SMI,   !F,  0x3F,   B,
253*4882a593Smuzhiyun 	      .bits = {{
254*4882a593Smuzhiyun 			.offset = 0,
255*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
256*4882a593Smuzhiyun 			.expected = 0,
257*4882a593Smuzhiyun 	      }},						       ),
258*4882a593Smuzhiyun 	CMD(  MI_UPDATE_GTT,                    SMI,   !F,  0xFF,   R  ),
259*4882a593Smuzhiyun 	CMD(  MI_CLFLUSH,                       SMI,   !F,  0x3FF,  B,
260*4882a593Smuzhiyun 	      .bits = {{
261*4882a593Smuzhiyun 			.offset = 0,
262*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
263*4882a593Smuzhiyun 			.expected = 0,
264*4882a593Smuzhiyun 	      }},						       ),
265*4882a593Smuzhiyun 	CMD(  MI_REPORT_PERF_COUNT,             SMI,   !F,  0x3F,   B,
266*4882a593Smuzhiyun 	      .bits = {{
267*4882a593Smuzhiyun 			.offset = 1,
268*4882a593Smuzhiyun 			.mask = MI_REPORT_PERF_COUNT_GGTT,
269*4882a593Smuzhiyun 			.expected = 0,
270*4882a593Smuzhiyun 	      }},						       ),
271*4882a593Smuzhiyun 	CMD(  MI_CONDITIONAL_BATCH_BUFFER_END,  SMI,   !F,  0xFF,   B,
272*4882a593Smuzhiyun 	      .bits = {{
273*4882a593Smuzhiyun 			.offset = 0,
274*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
275*4882a593Smuzhiyun 			.expected = 0,
276*4882a593Smuzhiyun 	      }},						       ),
277*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_VF_STATISTICS,     S3D,    F,  1,      S  ),
278*4882a593Smuzhiyun 	CMD(  PIPELINE_SELECT,                  S3D,    F,  1,      S  ),
279*4882a593Smuzhiyun 	CMD(  MEDIA_VFE_STATE,			S3D,   !F,  0xFFFF, B,
280*4882a593Smuzhiyun 	      .bits = {{
281*4882a593Smuzhiyun 			.offset = 2,
282*4882a593Smuzhiyun 			.mask = MEDIA_VFE_STATE_MMIO_ACCESS_MASK,
283*4882a593Smuzhiyun 			.expected = 0,
284*4882a593Smuzhiyun 	      }},						       ),
285*4882a593Smuzhiyun 	CMD(  GPGPU_OBJECT,                     S3D,   !F,  0xFF,   S  ),
286*4882a593Smuzhiyun 	CMD(  GPGPU_WALKER,                     S3D,   !F,  0xFF,   S  ),
287*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_SO_DECL_LIST,      S3D,   !F,  0x1FF,  S  ),
288*4882a593Smuzhiyun 	CMD(  GFX_OP_PIPE_CONTROL(5),           S3D,   !F,  0xFF,   B,
289*4882a593Smuzhiyun 	      .bits = {{
290*4882a593Smuzhiyun 			.offset = 1,
291*4882a593Smuzhiyun 			.mask = (PIPE_CONTROL_MMIO_WRITE | PIPE_CONTROL_NOTIFY),
292*4882a593Smuzhiyun 			.expected = 0,
293*4882a593Smuzhiyun 	      },
294*4882a593Smuzhiyun 	      {
295*4882a593Smuzhiyun 			.offset = 1,
296*4882a593Smuzhiyun 		        .mask = (PIPE_CONTROL_GLOBAL_GTT_IVB |
297*4882a593Smuzhiyun 				 PIPE_CONTROL_STORE_DATA_INDEX),
298*4882a593Smuzhiyun 			.expected = 0,
299*4882a593Smuzhiyun 			.condition_offset = 1,
300*4882a593Smuzhiyun 			.condition_mask = PIPE_CONTROL_POST_SYNC_OP_MASK,
301*4882a593Smuzhiyun 	      }},						       ),
302*4882a593Smuzhiyun };
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor hsw_render_cmds[] = {
305*4882a593Smuzhiyun 	CMD(  MI_SET_PREDICATE,                 SMI,    F,  1,      S  ),
306*4882a593Smuzhiyun 	CMD(  MI_RS_CONTROL,                    SMI,    F,  1,      S  ),
307*4882a593Smuzhiyun 	CMD(  MI_URB_ATOMIC_ALLOC,              SMI,    F,  1,      S  ),
308*4882a593Smuzhiyun 	CMD(  MI_SET_APPID,                     SMI,    F,  1,      S  ),
309*4882a593Smuzhiyun 	CMD(  MI_RS_CONTEXT,                    SMI,    F,  1,      S  ),
310*4882a593Smuzhiyun 	CMD(  MI_LOAD_SCAN_LINES_INCL,          SMI,   !F,  0x3F,   R  ),
311*4882a593Smuzhiyun 	CMD(  MI_LOAD_SCAN_LINES_EXCL,          SMI,   !F,  0x3F,   R  ),
312*4882a593Smuzhiyun 	CMD(  MI_LOAD_REGISTER_REG,             SMI,   !F,  0xFF,   W,
313*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC, .step = 1 }    ),
314*4882a593Smuzhiyun 	CMD(  MI_RS_STORE_DATA_IMM,             SMI,   !F,  0xFF,   S  ),
315*4882a593Smuzhiyun 	CMD(  MI_LOAD_URB_MEM,                  SMI,   !F,  0xFF,   S  ),
316*4882a593Smuzhiyun 	CMD(  MI_STORE_URB_MEM,                 SMI,   !F,  0xFF,   S  ),
317*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_DX9_CONSTANTF_VS,  S3D,   !F,  0x7FF,  S  ),
318*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_DX9_CONSTANTF_PS,  S3D,   !F,  0x7FF,  S  ),
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_BINDING_TABLE_EDIT_VS,  S3D,   !F,  0x1FF,  S  ),
321*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_BINDING_TABLE_EDIT_GS,  S3D,   !F,  0x1FF,  S  ),
322*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_BINDING_TABLE_EDIT_HS,  S3D,   !F,  0x1FF,  S  ),
323*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_BINDING_TABLE_EDIT_DS,  S3D,   !F,  0x1FF,  S  ),
324*4882a593Smuzhiyun 	CMD(  GFX_OP_3DSTATE_BINDING_TABLE_EDIT_PS,  S3D,   !F,  0x1FF,  S  ),
325*4882a593Smuzhiyun };
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor gen7_video_cmds[] = {
328*4882a593Smuzhiyun 	CMD(  MI_ARB_ON_OFF,                    SMI,    F,  1,      R  ),
329*4882a593Smuzhiyun 	CMD(  MI_SET_APPID,                     SMI,    F,  1,      S  ),
330*4882a593Smuzhiyun 	CMD(  MI_STORE_DWORD_IMM,               SMI,   !F,  0xFF,   B,
331*4882a593Smuzhiyun 	      .bits = {{
332*4882a593Smuzhiyun 			.offset = 0,
333*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
334*4882a593Smuzhiyun 			.expected = 0,
335*4882a593Smuzhiyun 	      }},						       ),
336*4882a593Smuzhiyun 	CMD(  MI_UPDATE_GTT,                    SMI,   !F,  0x3F,   R  ),
337*4882a593Smuzhiyun 	CMD(  MI_FLUSH_DW,                      SMI,   !F,  0x3F,   B,
338*4882a593Smuzhiyun 	      .bits = {{
339*4882a593Smuzhiyun 			.offset = 0,
340*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_NOTIFY,
341*4882a593Smuzhiyun 			.expected = 0,
342*4882a593Smuzhiyun 	      },
343*4882a593Smuzhiyun 	      {
344*4882a593Smuzhiyun 			.offset = 1,
345*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_USE_GTT,
346*4882a593Smuzhiyun 			.expected = 0,
347*4882a593Smuzhiyun 			.condition_offset = 0,
348*4882a593Smuzhiyun 			.condition_mask = MI_FLUSH_DW_OP_MASK,
349*4882a593Smuzhiyun 	      },
350*4882a593Smuzhiyun 	      {
351*4882a593Smuzhiyun 			.offset = 0,
352*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_STORE_INDEX,
353*4882a593Smuzhiyun 			.expected = 0,
354*4882a593Smuzhiyun 			.condition_offset = 0,
355*4882a593Smuzhiyun 			.condition_mask = MI_FLUSH_DW_OP_MASK,
356*4882a593Smuzhiyun 	      }},						       ),
357*4882a593Smuzhiyun 	CMD(  MI_CONDITIONAL_BATCH_BUFFER_END,  SMI,   !F,  0xFF,   B,
358*4882a593Smuzhiyun 	      .bits = {{
359*4882a593Smuzhiyun 			.offset = 0,
360*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
361*4882a593Smuzhiyun 			.expected = 0,
362*4882a593Smuzhiyun 	      }},						       ),
363*4882a593Smuzhiyun 	/*
364*4882a593Smuzhiyun 	 * MFX_WAIT doesn't fit the way we handle length for most commands.
365*4882a593Smuzhiyun 	 * It has a length field but it uses a non-standard length bias.
366*4882a593Smuzhiyun 	 * It is always 1 dword though, so just treat it as fixed length.
367*4882a593Smuzhiyun 	 */
368*4882a593Smuzhiyun 	CMD(  MFX_WAIT,                         SMFX,   F,  1,      S  ),
369*4882a593Smuzhiyun };
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor gen7_vecs_cmds[] = {
372*4882a593Smuzhiyun 	CMD(  MI_ARB_ON_OFF,                    SMI,    F,  1,      R  ),
373*4882a593Smuzhiyun 	CMD(  MI_SET_APPID,                     SMI,    F,  1,      S  ),
374*4882a593Smuzhiyun 	CMD(  MI_STORE_DWORD_IMM,               SMI,   !F,  0xFF,   B,
375*4882a593Smuzhiyun 	      .bits = {{
376*4882a593Smuzhiyun 			.offset = 0,
377*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
378*4882a593Smuzhiyun 			.expected = 0,
379*4882a593Smuzhiyun 	      }},						       ),
380*4882a593Smuzhiyun 	CMD(  MI_UPDATE_GTT,                    SMI,   !F,  0x3F,   R  ),
381*4882a593Smuzhiyun 	CMD(  MI_FLUSH_DW,                      SMI,   !F,  0x3F,   B,
382*4882a593Smuzhiyun 	      .bits = {{
383*4882a593Smuzhiyun 			.offset = 0,
384*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_NOTIFY,
385*4882a593Smuzhiyun 			.expected = 0,
386*4882a593Smuzhiyun 	      },
387*4882a593Smuzhiyun 	      {
388*4882a593Smuzhiyun 			.offset = 1,
389*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_USE_GTT,
390*4882a593Smuzhiyun 			.expected = 0,
391*4882a593Smuzhiyun 			.condition_offset = 0,
392*4882a593Smuzhiyun 			.condition_mask = MI_FLUSH_DW_OP_MASK,
393*4882a593Smuzhiyun 	      },
394*4882a593Smuzhiyun 	      {
395*4882a593Smuzhiyun 			.offset = 0,
396*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_STORE_INDEX,
397*4882a593Smuzhiyun 			.expected = 0,
398*4882a593Smuzhiyun 			.condition_offset = 0,
399*4882a593Smuzhiyun 			.condition_mask = MI_FLUSH_DW_OP_MASK,
400*4882a593Smuzhiyun 	      }},						       ),
401*4882a593Smuzhiyun 	CMD(  MI_CONDITIONAL_BATCH_BUFFER_END,  SMI,   !F,  0xFF,   B,
402*4882a593Smuzhiyun 	      .bits = {{
403*4882a593Smuzhiyun 			.offset = 0,
404*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
405*4882a593Smuzhiyun 			.expected = 0,
406*4882a593Smuzhiyun 	      }},						       ),
407*4882a593Smuzhiyun };
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor gen7_blt_cmds[] = {
410*4882a593Smuzhiyun 	CMD(  MI_DISPLAY_FLIP,                  SMI,   !F,  0xFF,   R  ),
411*4882a593Smuzhiyun 	CMD(  MI_STORE_DWORD_IMM,               SMI,   !F,  0x3FF,  B,
412*4882a593Smuzhiyun 	      .bits = {{
413*4882a593Smuzhiyun 			.offset = 0,
414*4882a593Smuzhiyun 			.mask = MI_GLOBAL_GTT,
415*4882a593Smuzhiyun 			.expected = 0,
416*4882a593Smuzhiyun 	      }},						       ),
417*4882a593Smuzhiyun 	CMD(  MI_UPDATE_GTT,                    SMI,   !F,  0x3F,   R  ),
418*4882a593Smuzhiyun 	CMD(  MI_FLUSH_DW,                      SMI,   !F,  0x3F,   B,
419*4882a593Smuzhiyun 	      .bits = {{
420*4882a593Smuzhiyun 			.offset = 0,
421*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_NOTIFY,
422*4882a593Smuzhiyun 			.expected = 0,
423*4882a593Smuzhiyun 	      },
424*4882a593Smuzhiyun 	      {
425*4882a593Smuzhiyun 			.offset = 1,
426*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_USE_GTT,
427*4882a593Smuzhiyun 			.expected = 0,
428*4882a593Smuzhiyun 			.condition_offset = 0,
429*4882a593Smuzhiyun 			.condition_mask = MI_FLUSH_DW_OP_MASK,
430*4882a593Smuzhiyun 	      },
431*4882a593Smuzhiyun 	      {
432*4882a593Smuzhiyun 			.offset = 0,
433*4882a593Smuzhiyun 			.mask = MI_FLUSH_DW_STORE_INDEX,
434*4882a593Smuzhiyun 			.expected = 0,
435*4882a593Smuzhiyun 			.condition_offset = 0,
436*4882a593Smuzhiyun 			.condition_mask = MI_FLUSH_DW_OP_MASK,
437*4882a593Smuzhiyun 	      }},						       ),
438*4882a593Smuzhiyun 	CMD(  COLOR_BLT,                        S2D,   !F,  0x3F,   S  ),
439*4882a593Smuzhiyun 	CMD(  SRC_COPY_BLT,                     S2D,   !F,  0x3F,   S  ),
440*4882a593Smuzhiyun };
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor hsw_blt_cmds[] = {
443*4882a593Smuzhiyun 	CMD(  MI_LOAD_SCAN_LINES_INCL,          SMI,   !F,  0x3F,   R  ),
444*4882a593Smuzhiyun 	CMD(  MI_LOAD_SCAN_LINES_EXCL,          SMI,   !F,  0x3F,   R  ),
445*4882a593Smuzhiyun };
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun /*
448*4882a593Smuzhiyun  * For Gen9 we can still rely on the h/w to enforce cmd security, and only
449*4882a593Smuzhiyun  * need to re-enforce the register access checks. We therefore only need to
450*4882a593Smuzhiyun  * teach the cmdparser how to find the end of each command, and identify
451*4882a593Smuzhiyun  * register accesses. The table doesn't need to reject any commands, and so
452*4882a593Smuzhiyun  * the only commands listed here are:
453*4882a593Smuzhiyun  *   1) Those that touch registers
454*4882a593Smuzhiyun  *   2) Those that do not have the default 8-bit length
455*4882a593Smuzhiyun  *
456*4882a593Smuzhiyun  * Note that the default MI length mask chosen for this table is 0xFF, not
457*4882a593Smuzhiyun  * the 0x3F used on older devices. This is because the vast majority of MI
458*4882a593Smuzhiyun  * cmds on Gen9 use a standard 8-bit Length field.
459*4882a593Smuzhiyun  * All the Gen9 blitter instructions are standard 0xFF length mask, and
460*4882a593Smuzhiyun  * none allow access to non-general registers, so in fact no BLT cmds are
461*4882a593Smuzhiyun  * included in the table at all.
462*4882a593Smuzhiyun  *
463*4882a593Smuzhiyun  */
464*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor gen9_blt_cmds[] = {
465*4882a593Smuzhiyun 	CMD(  MI_NOOP,                          SMI,    F,  1,      S  ),
466*4882a593Smuzhiyun 	CMD(  MI_USER_INTERRUPT,                SMI,    F,  1,      S  ),
467*4882a593Smuzhiyun 	CMD(  MI_WAIT_FOR_EVENT,                SMI,    F,  1,      S  ),
468*4882a593Smuzhiyun 	CMD(  MI_FLUSH,                         SMI,    F,  1,      S  ),
469*4882a593Smuzhiyun 	CMD(  MI_ARB_CHECK,                     SMI,    F,  1,      S  ),
470*4882a593Smuzhiyun 	CMD(  MI_REPORT_HEAD,                   SMI,    F,  1,      S  ),
471*4882a593Smuzhiyun 	CMD(  MI_ARB_ON_OFF,                    SMI,    F,  1,      S  ),
472*4882a593Smuzhiyun 	CMD(  MI_SUSPEND_FLUSH,                 SMI,    F,  1,      S  ),
473*4882a593Smuzhiyun 	CMD(  MI_LOAD_SCAN_LINES_INCL,          SMI,   !F,  0x3F,   S  ),
474*4882a593Smuzhiyun 	CMD(  MI_LOAD_SCAN_LINES_EXCL,          SMI,   !F,  0x3F,   S  ),
475*4882a593Smuzhiyun 	CMD(  MI_STORE_DWORD_IMM,               SMI,   !F,  0x3FF,  S  ),
476*4882a593Smuzhiyun 	CMD(  MI_LOAD_REGISTER_IMM(1),          SMI,   !F,  0xFF,   W,
477*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC, .step = 2 }    ),
478*4882a593Smuzhiyun 	CMD(  MI_UPDATE_GTT,                    SMI,   !F,  0x3FF,  S  ),
479*4882a593Smuzhiyun 	CMD(  MI_STORE_REGISTER_MEM_GEN8,       SMI,    F,  4,      W,
480*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC }               ),
481*4882a593Smuzhiyun 	CMD(  MI_FLUSH_DW,                      SMI,   !F,  0x3F,   S  ),
482*4882a593Smuzhiyun 	CMD(  MI_LOAD_REGISTER_MEM_GEN8,        SMI,    F,  4,      W,
483*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC }               ),
484*4882a593Smuzhiyun 	CMD(  MI_LOAD_REGISTER_REG,             SMI,    !F,  0xFF,  W,
485*4882a593Smuzhiyun 	      .reg = { .offset = 1, .mask = 0x007FFFFC, .step = 1 }    ),
486*4882a593Smuzhiyun 
487*4882a593Smuzhiyun 	/*
488*4882a593Smuzhiyun 	 * We allow BB_START but apply further checks. We just sanitize the
489*4882a593Smuzhiyun 	 * basic fields here.
490*4882a593Smuzhiyun 	 */
491*4882a593Smuzhiyun #define MI_BB_START_OPERAND_MASK   GENMASK(SMI-1, 0)
492*4882a593Smuzhiyun #define MI_BB_START_OPERAND_EXPECT (MI_BATCH_PPGTT_HSW | 1)
493*4882a593Smuzhiyun 	CMD(  MI_BATCH_BUFFER_START_GEN8,       SMI,    !F,  0xFF,  B,
494*4882a593Smuzhiyun 	      .bits = {{
495*4882a593Smuzhiyun 			.offset = 0,
496*4882a593Smuzhiyun 			.mask = MI_BB_START_OPERAND_MASK,
497*4882a593Smuzhiyun 			.expected = MI_BB_START_OPERAND_EXPECT,
498*4882a593Smuzhiyun 	      }},						       ),
499*4882a593Smuzhiyun };
500*4882a593Smuzhiyun 
501*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor noop_desc =
502*4882a593Smuzhiyun 	CMD(MI_NOOP, SMI, F, 1, S);
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun #undef CMD
505*4882a593Smuzhiyun #undef SMI
506*4882a593Smuzhiyun #undef S3D
507*4882a593Smuzhiyun #undef S2D
508*4882a593Smuzhiyun #undef SMFX
509*4882a593Smuzhiyun #undef F
510*4882a593Smuzhiyun #undef S
511*4882a593Smuzhiyun #undef R
512*4882a593Smuzhiyun #undef W
513*4882a593Smuzhiyun #undef B
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun static const struct drm_i915_cmd_table gen7_render_cmd_table[] = {
516*4882a593Smuzhiyun 	{ gen7_common_cmds, ARRAY_SIZE(gen7_common_cmds) },
517*4882a593Smuzhiyun 	{ gen7_render_cmds, ARRAY_SIZE(gen7_render_cmds) },
518*4882a593Smuzhiyun };
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun static const struct drm_i915_cmd_table hsw_render_ring_cmd_table[] = {
521*4882a593Smuzhiyun 	{ gen7_common_cmds, ARRAY_SIZE(gen7_common_cmds) },
522*4882a593Smuzhiyun 	{ gen7_render_cmds, ARRAY_SIZE(gen7_render_cmds) },
523*4882a593Smuzhiyun 	{ hsw_render_cmds, ARRAY_SIZE(hsw_render_cmds) },
524*4882a593Smuzhiyun };
525*4882a593Smuzhiyun 
526*4882a593Smuzhiyun static const struct drm_i915_cmd_table gen7_video_cmd_table[] = {
527*4882a593Smuzhiyun 	{ gen7_common_cmds, ARRAY_SIZE(gen7_common_cmds) },
528*4882a593Smuzhiyun 	{ gen7_video_cmds, ARRAY_SIZE(gen7_video_cmds) },
529*4882a593Smuzhiyun };
530*4882a593Smuzhiyun 
531*4882a593Smuzhiyun static const struct drm_i915_cmd_table hsw_vebox_cmd_table[] = {
532*4882a593Smuzhiyun 	{ gen7_common_cmds, ARRAY_SIZE(gen7_common_cmds) },
533*4882a593Smuzhiyun 	{ gen7_vecs_cmds, ARRAY_SIZE(gen7_vecs_cmds) },
534*4882a593Smuzhiyun };
535*4882a593Smuzhiyun 
536*4882a593Smuzhiyun static const struct drm_i915_cmd_table gen7_blt_cmd_table[] = {
537*4882a593Smuzhiyun 	{ gen7_common_cmds, ARRAY_SIZE(gen7_common_cmds) },
538*4882a593Smuzhiyun 	{ gen7_blt_cmds, ARRAY_SIZE(gen7_blt_cmds) },
539*4882a593Smuzhiyun };
540*4882a593Smuzhiyun 
541*4882a593Smuzhiyun static const struct drm_i915_cmd_table hsw_blt_ring_cmd_table[] = {
542*4882a593Smuzhiyun 	{ gen7_common_cmds, ARRAY_SIZE(gen7_common_cmds) },
543*4882a593Smuzhiyun 	{ gen7_blt_cmds, ARRAY_SIZE(gen7_blt_cmds) },
544*4882a593Smuzhiyun 	{ hsw_blt_cmds, ARRAY_SIZE(hsw_blt_cmds) },
545*4882a593Smuzhiyun };
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun static const struct drm_i915_cmd_table gen9_blt_cmd_table[] = {
548*4882a593Smuzhiyun 	{ gen9_blt_cmds, ARRAY_SIZE(gen9_blt_cmds) },
549*4882a593Smuzhiyun };
550*4882a593Smuzhiyun 
551*4882a593Smuzhiyun 
552*4882a593Smuzhiyun /*
553*4882a593Smuzhiyun  * Register whitelists, sorted by increasing register offset.
554*4882a593Smuzhiyun  */
555*4882a593Smuzhiyun 
556*4882a593Smuzhiyun /*
557*4882a593Smuzhiyun  * An individual whitelist entry granting access to register addr.  If
558*4882a593Smuzhiyun  * mask is non-zero the argument of immediate register writes will be
559*4882a593Smuzhiyun  * AND-ed with mask, and the command will be rejected if the result
560*4882a593Smuzhiyun  * doesn't match value.
561*4882a593Smuzhiyun  *
562*4882a593Smuzhiyun  * Registers with non-zero mask are only allowed to be written using
563*4882a593Smuzhiyun  * LRI.
564*4882a593Smuzhiyun  */
565*4882a593Smuzhiyun struct drm_i915_reg_descriptor {
566*4882a593Smuzhiyun 	i915_reg_t addr;
567*4882a593Smuzhiyun 	u32 mask;
568*4882a593Smuzhiyun 	u32 value;
569*4882a593Smuzhiyun };
570*4882a593Smuzhiyun 
571*4882a593Smuzhiyun /* Convenience macro for adding 32-bit registers. */
572*4882a593Smuzhiyun #define REG32(_reg, ...) \
573*4882a593Smuzhiyun 	{ .addr = (_reg), __VA_ARGS__ }
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun #define REG32_IDX(_reg, idx) \
576*4882a593Smuzhiyun 	{ .addr = _reg(idx) }
577*4882a593Smuzhiyun 
578*4882a593Smuzhiyun /*
579*4882a593Smuzhiyun  * Convenience macro for adding 64-bit registers.
580*4882a593Smuzhiyun  *
581*4882a593Smuzhiyun  * Some registers that userspace accesses are 64 bits. The register
582*4882a593Smuzhiyun  * access commands only allow 32-bit accesses. Hence, we have to include
583*4882a593Smuzhiyun  * entries for both halves of the 64-bit registers.
584*4882a593Smuzhiyun  */
585*4882a593Smuzhiyun #define REG64(_reg) \
586*4882a593Smuzhiyun 	{ .addr = _reg }, \
587*4882a593Smuzhiyun 	{ .addr = _reg ## _UDW }
588*4882a593Smuzhiyun 
589*4882a593Smuzhiyun #define REG64_IDX(_reg, idx) \
590*4882a593Smuzhiyun 	{ .addr = _reg(idx) }, \
591*4882a593Smuzhiyun 	{ .addr = _reg ## _UDW(idx) }
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun static const struct drm_i915_reg_descriptor gen7_render_regs[] = {
594*4882a593Smuzhiyun 	REG64(GPGPU_THREADS_DISPATCHED),
595*4882a593Smuzhiyun 	REG64(HS_INVOCATION_COUNT),
596*4882a593Smuzhiyun 	REG64(DS_INVOCATION_COUNT),
597*4882a593Smuzhiyun 	REG64(IA_VERTICES_COUNT),
598*4882a593Smuzhiyun 	REG64(IA_PRIMITIVES_COUNT),
599*4882a593Smuzhiyun 	REG64(VS_INVOCATION_COUNT),
600*4882a593Smuzhiyun 	REG64(GS_INVOCATION_COUNT),
601*4882a593Smuzhiyun 	REG64(GS_PRIMITIVES_COUNT),
602*4882a593Smuzhiyun 	REG64(CL_INVOCATION_COUNT),
603*4882a593Smuzhiyun 	REG64(CL_PRIMITIVES_COUNT),
604*4882a593Smuzhiyun 	REG64(PS_INVOCATION_COUNT),
605*4882a593Smuzhiyun 	REG64(PS_DEPTH_COUNT),
606*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, RENDER_RING_BASE),
607*4882a593Smuzhiyun 	REG64(MI_PREDICATE_SRC0),
608*4882a593Smuzhiyun 	REG64(MI_PREDICATE_SRC1),
609*4882a593Smuzhiyun 	REG32(GEN7_3DPRIM_END_OFFSET),
610*4882a593Smuzhiyun 	REG32(GEN7_3DPRIM_START_VERTEX),
611*4882a593Smuzhiyun 	REG32(GEN7_3DPRIM_VERTEX_COUNT),
612*4882a593Smuzhiyun 	REG32(GEN7_3DPRIM_INSTANCE_COUNT),
613*4882a593Smuzhiyun 	REG32(GEN7_3DPRIM_START_INSTANCE),
614*4882a593Smuzhiyun 	REG32(GEN7_3DPRIM_BASE_VERTEX),
615*4882a593Smuzhiyun 	REG32(GEN7_GPGPU_DISPATCHDIMX),
616*4882a593Smuzhiyun 	REG32(GEN7_GPGPU_DISPATCHDIMY),
617*4882a593Smuzhiyun 	REG32(GEN7_GPGPU_DISPATCHDIMZ),
618*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, BSD_RING_BASE),
619*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_NUM_PRIMS_WRITTEN, 0),
620*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_NUM_PRIMS_WRITTEN, 1),
621*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_NUM_PRIMS_WRITTEN, 2),
622*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_NUM_PRIMS_WRITTEN, 3),
623*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_PRIM_STORAGE_NEEDED, 0),
624*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_PRIM_STORAGE_NEEDED, 1),
625*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_PRIM_STORAGE_NEEDED, 2),
626*4882a593Smuzhiyun 	REG64_IDX(GEN7_SO_PRIM_STORAGE_NEEDED, 3),
627*4882a593Smuzhiyun 	REG32(GEN7_SO_WRITE_OFFSET(0)),
628*4882a593Smuzhiyun 	REG32(GEN7_SO_WRITE_OFFSET(1)),
629*4882a593Smuzhiyun 	REG32(GEN7_SO_WRITE_OFFSET(2)),
630*4882a593Smuzhiyun 	REG32(GEN7_SO_WRITE_OFFSET(3)),
631*4882a593Smuzhiyun 	REG32(GEN7_L3SQCREG1),
632*4882a593Smuzhiyun 	REG32(GEN7_L3CNTLREG2),
633*4882a593Smuzhiyun 	REG32(GEN7_L3CNTLREG3),
634*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, BLT_RING_BASE),
635*4882a593Smuzhiyun };
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun static const struct drm_i915_reg_descriptor hsw_render_regs[] = {
638*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 0),
639*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 1),
640*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 2),
641*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 3),
642*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 4),
643*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 5),
644*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 6),
645*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 7),
646*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 8),
647*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 9),
648*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 10),
649*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 11),
650*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 12),
651*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 13),
652*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 14),
653*4882a593Smuzhiyun 	REG64_IDX(HSW_CS_GPR, 15),
654*4882a593Smuzhiyun 	REG32(HSW_SCRATCH1,
655*4882a593Smuzhiyun 	      .mask = ~HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE,
656*4882a593Smuzhiyun 	      .value = 0),
657*4882a593Smuzhiyun 	REG32(HSW_ROW_CHICKEN3,
658*4882a593Smuzhiyun 	      .mask = ~(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE << 16 |
659*4882a593Smuzhiyun                         HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE),
660*4882a593Smuzhiyun 	      .value = 0),
661*4882a593Smuzhiyun };
662*4882a593Smuzhiyun 
663*4882a593Smuzhiyun static const struct drm_i915_reg_descriptor gen7_blt_regs[] = {
664*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, RENDER_RING_BASE),
665*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, BSD_RING_BASE),
666*4882a593Smuzhiyun 	REG32(BCS_SWCTRL),
667*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, BLT_RING_BASE),
668*4882a593Smuzhiyun };
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun static const struct drm_i915_reg_descriptor gen9_blt_regs[] = {
671*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, RENDER_RING_BASE),
672*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, BSD_RING_BASE),
673*4882a593Smuzhiyun 	REG32(BCS_SWCTRL),
674*4882a593Smuzhiyun 	REG64_IDX(RING_TIMESTAMP, BLT_RING_BASE),
675*4882a593Smuzhiyun 	REG32_IDX(RING_CTX_TIMESTAMP, BLT_RING_BASE),
676*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 0),
677*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 1),
678*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 2),
679*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 3),
680*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 4),
681*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 5),
682*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 6),
683*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 7),
684*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 8),
685*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 9),
686*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 10),
687*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 11),
688*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 12),
689*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 13),
690*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 14),
691*4882a593Smuzhiyun 	REG64_IDX(BCS_GPR, 15),
692*4882a593Smuzhiyun };
693*4882a593Smuzhiyun 
694*4882a593Smuzhiyun #undef REG64
695*4882a593Smuzhiyun #undef REG32
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun struct drm_i915_reg_table {
698*4882a593Smuzhiyun 	const struct drm_i915_reg_descriptor *regs;
699*4882a593Smuzhiyun 	int num_regs;
700*4882a593Smuzhiyun };
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun static const struct drm_i915_reg_table ivb_render_reg_tables[] = {
703*4882a593Smuzhiyun 	{ gen7_render_regs, ARRAY_SIZE(gen7_render_regs) },
704*4882a593Smuzhiyun };
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun static const struct drm_i915_reg_table ivb_blt_reg_tables[] = {
707*4882a593Smuzhiyun 	{ gen7_blt_regs, ARRAY_SIZE(gen7_blt_regs) },
708*4882a593Smuzhiyun };
709*4882a593Smuzhiyun 
710*4882a593Smuzhiyun static const struct drm_i915_reg_table hsw_render_reg_tables[] = {
711*4882a593Smuzhiyun 	{ gen7_render_regs, ARRAY_SIZE(gen7_render_regs) },
712*4882a593Smuzhiyun 	{ hsw_render_regs, ARRAY_SIZE(hsw_render_regs) },
713*4882a593Smuzhiyun };
714*4882a593Smuzhiyun 
715*4882a593Smuzhiyun static const struct drm_i915_reg_table hsw_blt_reg_tables[] = {
716*4882a593Smuzhiyun 	{ gen7_blt_regs, ARRAY_SIZE(gen7_blt_regs) },
717*4882a593Smuzhiyun };
718*4882a593Smuzhiyun 
719*4882a593Smuzhiyun static const struct drm_i915_reg_table gen9_blt_reg_tables[] = {
720*4882a593Smuzhiyun 	{ gen9_blt_regs, ARRAY_SIZE(gen9_blt_regs) },
721*4882a593Smuzhiyun };
722*4882a593Smuzhiyun 
gen7_render_get_cmd_length_mask(u32 cmd_header)723*4882a593Smuzhiyun static u32 gen7_render_get_cmd_length_mask(u32 cmd_header)
724*4882a593Smuzhiyun {
725*4882a593Smuzhiyun 	u32 client = cmd_header >> INSTR_CLIENT_SHIFT;
726*4882a593Smuzhiyun 	u32 subclient =
727*4882a593Smuzhiyun 		(cmd_header & INSTR_SUBCLIENT_MASK) >> INSTR_SUBCLIENT_SHIFT;
728*4882a593Smuzhiyun 
729*4882a593Smuzhiyun 	if (client == INSTR_MI_CLIENT)
730*4882a593Smuzhiyun 		return 0x3F;
731*4882a593Smuzhiyun 	else if (client == INSTR_RC_CLIENT) {
732*4882a593Smuzhiyun 		if (subclient == INSTR_MEDIA_SUBCLIENT)
733*4882a593Smuzhiyun 			return 0xFFFF;
734*4882a593Smuzhiyun 		else
735*4882a593Smuzhiyun 			return 0xFF;
736*4882a593Smuzhiyun 	}
737*4882a593Smuzhiyun 
738*4882a593Smuzhiyun 	DRM_DEBUG("CMD: Abnormal rcs cmd length! 0x%08X\n", cmd_header);
739*4882a593Smuzhiyun 	return 0;
740*4882a593Smuzhiyun }
741*4882a593Smuzhiyun 
gen7_bsd_get_cmd_length_mask(u32 cmd_header)742*4882a593Smuzhiyun static u32 gen7_bsd_get_cmd_length_mask(u32 cmd_header)
743*4882a593Smuzhiyun {
744*4882a593Smuzhiyun 	u32 client = cmd_header >> INSTR_CLIENT_SHIFT;
745*4882a593Smuzhiyun 	u32 subclient =
746*4882a593Smuzhiyun 		(cmd_header & INSTR_SUBCLIENT_MASK) >> INSTR_SUBCLIENT_SHIFT;
747*4882a593Smuzhiyun 	u32 op = (cmd_header & INSTR_26_TO_24_MASK) >> INSTR_26_TO_24_SHIFT;
748*4882a593Smuzhiyun 
749*4882a593Smuzhiyun 	if (client == INSTR_MI_CLIENT)
750*4882a593Smuzhiyun 		return 0x3F;
751*4882a593Smuzhiyun 	else if (client == INSTR_RC_CLIENT) {
752*4882a593Smuzhiyun 		if (subclient == INSTR_MEDIA_SUBCLIENT) {
753*4882a593Smuzhiyun 			if (op == 6)
754*4882a593Smuzhiyun 				return 0xFFFF;
755*4882a593Smuzhiyun 			else
756*4882a593Smuzhiyun 				return 0xFFF;
757*4882a593Smuzhiyun 		} else
758*4882a593Smuzhiyun 			return 0xFF;
759*4882a593Smuzhiyun 	}
760*4882a593Smuzhiyun 
761*4882a593Smuzhiyun 	DRM_DEBUG("CMD: Abnormal bsd cmd length! 0x%08X\n", cmd_header);
762*4882a593Smuzhiyun 	return 0;
763*4882a593Smuzhiyun }
764*4882a593Smuzhiyun 
gen7_blt_get_cmd_length_mask(u32 cmd_header)765*4882a593Smuzhiyun static u32 gen7_blt_get_cmd_length_mask(u32 cmd_header)
766*4882a593Smuzhiyun {
767*4882a593Smuzhiyun 	u32 client = cmd_header >> INSTR_CLIENT_SHIFT;
768*4882a593Smuzhiyun 
769*4882a593Smuzhiyun 	if (client == INSTR_MI_CLIENT)
770*4882a593Smuzhiyun 		return 0x3F;
771*4882a593Smuzhiyun 	else if (client == INSTR_BC_CLIENT)
772*4882a593Smuzhiyun 		return 0xFF;
773*4882a593Smuzhiyun 
774*4882a593Smuzhiyun 	DRM_DEBUG("CMD: Abnormal blt cmd length! 0x%08X\n", cmd_header);
775*4882a593Smuzhiyun 	return 0;
776*4882a593Smuzhiyun }
777*4882a593Smuzhiyun 
gen9_blt_get_cmd_length_mask(u32 cmd_header)778*4882a593Smuzhiyun static u32 gen9_blt_get_cmd_length_mask(u32 cmd_header)
779*4882a593Smuzhiyun {
780*4882a593Smuzhiyun 	u32 client = cmd_header >> INSTR_CLIENT_SHIFT;
781*4882a593Smuzhiyun 
782*4882a593Smuzhiyun 	if (client == INSTR_MI_CLIENT || client == INSTR_BC_CLIENT)
783*4882a593Smuzhiyun 		return 0xFF;
784*4882a593Smuzhiyun 
785*4882a593Smuzhiyun 	DRM_DEBUG("CMD: Abnormal blt cmd length! 0x%08X\n", cmd_header);
786*4882a593Smuzhiyun 	return 0;
787*4882a593Smuzhiyun }
788*4882a593Smuzhiyun 
validate_cmds_sorted(const struct intel_engine_cs * engine,const struct drm_i915_cmd_table * cmd_tables,int cmd_table_count)789*4882a593Smuzhiyun static bool validate_cmds_sorted(const struct intel_engine_cs *engine,
790*4882a593Smuzhiyun 				 const struct drm_i915_cmd_table *cmd_tables,
791*4882a593Smuzhiyun 				 int cmd_table_count)
792*4882a593Smuzhiyun {
793*4882a593Smuzhiyun 	int i;
794*4882a593Smuzhiyun 	bool ret = true;
795*4882a593Smuzhiyun 
796*4882a593Smuzhiyun 	if (!cmd_tables || cmd_table_count == 0)
797*4882a593Smuzhiyun 		return true;
798*4882a593Smuzhiyun 
799*4882a593Smuzhiyun 	for (i = 0; i < cmd_table_count; i++) {
800*4882a593Smuzhiyun 		const struct drm_i915_cmd_table *table = &cmd_tables[i];
801*4882a593Smuzhiyun 		u32 previous = 0;
802*4882a593Smuzhiyun 		int j;
803*4882a593Smuzhiyun 
804*4882a593Smuzhiyun 		for (j = 0; j < table->count; j++) {
805*4882a593Smuzhiyun 			const struct drm_i915_cmd_descriptor *desc =
806*4882a593Smuzhiyun 				&table->table[j];
807*4882a593Smuzhiyun 			u32 curr = desc->cmd.value & desc->cmd.mask;
808*4882a593Smuzhiyun 
809*4882a593Smuzhiyun 			if (curr < previous) {
810*4882a593Smuzhiyun 				drm_err(&engine->i915->drm,
811*4882a593Smuzhiyun 					"CMD: %s [%d] command table not sorted: "
812*4882a593Smuzhiyun 					"table=%d entry=%d cmd=0x%08X prev=0x%08X\n",
813*4882a593Smuzhiyun 					engine->name, engine->id,
814*4882a593Smuzhiyun 					i, j, curr, previous);
815*4882a593Smuzhiyun 				ret = false;
816*4882a593Smuzhiyun 			}
817*4882a593Smuzhiyun 
818*4882a593Smuzhiyun 			previous = curr;
819*4882a593Smuzhiyun 		}
820*4882a593Smuzhiyun 	}
821*4882a593Smuzhiyun 
822*4882a593Smuzhiyun 	return ret;
823*4882a593Smuzhiyun }
824*4882a593Smuzhiyun 
check_sorted(const struct intel_engine_cs * engine,const struct drm_i915_reg_descriptor * reg_table,int reg_count)825*4882a593Smuzhiyun static bool check_sorted(const struct intel_engine_cs *engine,
826*4882a593Smuzhiyun 			 const struct drm_i915_reg_descriptor *reg_table,
827*4882a593Smuzhiyun 			 int reg_count)
828*4882a593Smuzhiyun {
829*4882a593Smuzhiyun 	int i;
830*4882a593Smuzhiyun 	u32 previous = 0;
831*4882a593Smuzhiyun 	bool ret = true;
832*4882a593Smuzhiyun 
833*4882a593Smuzhiyun 	for (i = 0; i < reg_count; i++) {
834*4882a593Smuzhiyun 		u32 curr = i915_mmio_reg_offset(reg_table[i].addr);
835*4882a593Smuzhiyun 
836*4882a593Smuzhiyun 		if (curr < previous) {
837*4882a593Smuzhiyun 			drm_err(&engine->i915->drm,
838*4882a593Smuzhiyun 				"CMD: %s [%d] register table not sorted: "
839*4882a593Smuzhiyun 				"entry=%d reg=0x%08X prev=0x%08X\n",
840*4882a593Smuzhiyun 				engine->name, engine->id,
841*4882a593Smuzhiyun 				i, curr, previous);
842*4882a593Smuzhiyun 			ret = false;
843*4882a593Smuzhiyun 		}
844*4882a593Smuzhiyun 
845*4882a593Smuzhiyun 		previous = curr;
846*4882a593Smuzhiyun 	}
847*4882a593Smuzhiyun 
848*4882a593Smuzhiyun 	return ret;
849*4882a593Smuzhiyun }
850*4882a593Smuzhiyun 
validate_regs_sorted(struct intel_engine_cs * engine)851*4882a593Smuzhiyun static bool validate_regs_sorted(struct intel_engine_cs *engine)
852*4882a593Smuzhiyun {
853*4882a593Smuzhiyun 	int i;
854*4882a593Smuzhiyun 	const struct drm_i915_reg_table *table;
855*4882a593Smuzhiyun 
856*4882a593Smuzhiyun 	for (i = 0; i < engine->reg_table_count; i++) {
857*4882a593Smuzhiyun 		table = &engine->reg_tables[i];
858*4882a593Smuzhiyun 		if (!check_sorted(engine, table->regs, table->num_regs))
859*4882a593Smuzhiyun 			return false;
860*4882a593Smuzhiyun 	}
861*4882a593Smuzhiyun 
862*4882a593Smuzhiyun 	return true;
863*4882a593Smuzhiyun }
864*4882a593Smuzhiyun 
865*4882a593Smuzhiyun struct cmd_node {
866*4882a593Smuzhiyun 	const struct drm_i915_cmd_descriptor *desc;
867*4882a593Smuzhiyun 	struct hlist_node node;
868*4882a593Smuzhiyun };
869*4882a593Smuzhiyun 
870*4882a593Smuzhiyun /*
871*4882a593Smuzhiyun  * Different command ranges have different numbers of bits for the opcode. For
872*4882a593Smuzhiyun  * example, MI commands use bits 31:23 while 3D commands use bits 31:16. The
873*4882a593Smuzhiyun  * problem is that, for example, MI commands use bits 22:16 for other fields
874*4882a593Smuzhiyun  * such as GGTT vs PPGTT bits. If we include those bits in the mask then when
875*4882a593Smuzhiyun  * we mask a command from a batch it could hash to the wrong bucket due to
876*4882a593Smuzhiyun  * non-opcode bits being set. But if we don't include those bits, some 3D
877*4882a593Smuzhiyun  * commands may hash to the same bucket due to not including opcode bits that
878*4882a593Smuzhiyun  * make the command unique. For now, we will risk hashing to the same bucket.
879*4882a593Smuzhiyun  */
cmd_header_key(u32 x)880*4882a593Smuzhiyun static inline u32 cmd_header_key(u32 x)
881*4882a593Smuzhiyun {
882*4882a593Smuzhiyun 	switch (x >> INSTR_CLIENT_SHIFT) {
883*4882a593Smuzhiyun 	default:
884*4882a593Smuzhiyun 	case INSTR_MI_CLIENT:
885*4882a593Smuzhiyun 		return x >> STD_MI_OPCODE_SHIFT;
886*4882a593Smuzhiyun 	case INSTR_RC_CLIENT:
887*4882a593Smuzhiyun 		return x >> STD_3D_OPCODE_SHIFT;
888*4882a593Smuzhiyun 	case INSTR_BC_CLIENT:
889*4882a593Smuzhiyun 		return x >> STD_2D_OPCODE_SHIFT;
890*4882a593Smuzhiyun 	}
891*4882a593Smuzhiyun }
892*4882a593Smuzhiyun 
init_hash_table(struct intel_engine_cs * engine,const struct drm_i915_cmd_table * cmd_tables,int cmd_table_count)893*4882a593Smuzhiyun static int init_hash_table(struct intel_engine_cs *engine,
894*4882a593Smuzhiyun 			   const struct drm_i915_cmd_table *cmd_tables,
895*4882a593Smuzhiyun 			   int cmd_table_count)
896*4882a593Smuzhiyun {
897*4882a593Smuzhiyun 	int i, j;
898*4882a593Smuzhiyun 
899*4882a593Smuzhiyun 	hash_init(engine->cmd_hash);
900*4882a593Smuzhiyun 
901*4882a593Smuzhiyun 	for (i = 0; i < cmd_table_count; i++) {
902*4882a593Smuzhiyun 		const struct drm_i915_cmd_table *table = &cmd_tables[i];
903*4882a593Smuzhiyun 
904*4882a593Smuzhiyun 		for (j = 0; j < table->count; j++) {
905*4882a593Smuzhiyun 			const struct drm_i915_cmd_descriptor *desc =
906*4882a593Smuzhiyun 				&table->table[j];
907*4882a593Smuzhiyun 			struct cmd_node *desc_node =
908*4882a593Smuzhiyun 				kmalloc(sizeof(*desc_node), GFP_KERNEL);
909*4882a593Smuzhiyun 
910*4882a593Smuzhiyun 			if (!desc_node)
911*4882a593Smuzhiyun 				return -ENOMEM;
912*4882a593Smuzhiyun 
913*4882a593Smuzhiyun 			desc_node->desc = desc;
914*4882a593Smuzhiyun 			hash_add(engine->cmd_hash, &desc_node->node,
915*4882a593Smuzhiyun 				 cmd_header_key(desc->cmd.value));
916*4882a593Smuzhiyun 		}
917*4882a593Smuzhiyun 	}
918*4882a593Smuzhiyun 
919*4882a593Smuzhiyun 	return 0;
920*4882a593Smuzhiyun }
921*4882a593Smuzhiyun 
fini_hash_table(struct intel_engine_cs * engine)922*4882a593Smuzhiyun static void fini_hash_table(struct intel_engine_cs *engine)
923*4882a593Smuzhiyun {
924*4882a593Smuzhiyun 	struct hlist_node *tmp;
925*4882a593Smuzhiyun 	struct cmd_node *desc_node;
926*4882a593Smuzhiyun 	int i;
927*4882a593Smuzhiyun 
928*4882a593Smuzhiyun 	hash_for_each_safe(engine->cmd_hash, i, tmp, desc_node, node) {
929*4882a593Smuzhiyun 		hash_del(&desc_node->node);
930*4882a593Smuzhiyun 		kfree(desc_node);
931*4882a593Smuzhiyun 	}
932*4882a593Smuzhiyun }
933*4882a593Smuzhiyun 
934*4882a593Smuzhiyun /**
935*4882a593Smuzhiyun  * intel_engine_init_cmd_parser() - set cmd parser related fields for an engine
936*4882a593Smuzhiyun  * @engine: the engine to initialize
937*4882a593Smuzhiyun  *
938*4882a593Smuzhiyun  * Optionally initializes fields related to batch buffer command parsing in the
939*4882a593Smuzhiyun  * struct intel_engine_cs based on whether the platform requires software
940*4882a593Smuzhiyun  * command parsing.
941*4882a593Smuzhiyun  */
intel_engine_init_cmd_parser(struct intel_engine_cs * engine)942*4882a593Smuzhiyun int intel_engine_init_cmd_parser(struct intel_engine_cs *engine)
943*4882a593Smuzhiyun {
944*4882a593Smuzhiyun 	const struct drm_i915_cmd_table *cmd_tables;
945*4882a593Smuzhiyun 	int cmd_table_count;
946*4882a593Smuzhiyun 	int ret;
947*4882a593Smuzhiyun 
948*4882a593Smuzhiyun 	if (!IS_GEN(engine->i915, 7) && !(IS_GEN(engine->i915, 9) &&
949*4882a593Smuzhiyun 					  engine->class == COPY_ENGINE_CLASS))
950*4882a593Smuzhiyun 		return 0;
951*4882a593Smuzhiyun 
952*4882a593Smuzhiyun 	switch (engine->class) {
953*4882a593Smuzhiyun 	case RENDER_CLASS:
954*4882a593Smuzhiyun 		if (IS_HASWELL(engine->i915)) {
955*4882a593Smuzhiyun 			cmd_tables = hsw_render_ring_cmd_table;
956*4882a593Smuzhiyun 			cmd_table_count =
957*4882a593Smuzhiyun 				ARRAY_SIZE(hsw_render_ring_cmd_table);
958*4882a593Smuzhiyun 		} else {
959*4882a593Smuzhiyun 			cmd_tables = gen7_render_cmd_table;
960*4882a593Smuzhiyun 			cmd_table_count = ARRAY_SIZE(gen7_render_cmd_table);
961*4882a593Smuzhiyun 		}
962*4882a593Smuzhiyun 
963*4882a593Smuzhiyun 		if (IS_HASWELL(engine->i915)) {
964*4882a593Smuzhiyun 			engine->reg_tables = hsw_render_reg_tables;
965*4882a593Smuzhiyun 			engine->reg_table_count = ARRAY_SIZE(hsw_render_reg_tables);
966*4882a593Smuzhiyun 		} else {
967*4882a593Smuzhiyun 			engine->reg_tables = ivb_render_reg_tables;
968*4882a593Smuzhiyun 			engine->reg_table_count = ARRAY_SIZE(ivb_render_reg_tables);
969*4882a593Smuzhiyun 		}
970*4882a593Smuzhiyun 		engine->get_cmd_length_mask = gen7_render_get_cmd_length_mask;
971*4882a593Smuzhiyun 		break;
972*4882a593Smuzhiyun 	case VIDEO_DECODE_CLASS:
973*4882a593Smuzhiyun 		cmd_tables = gen7_video_cmd_table;
974*4882a593Smuzhiyun 		cmd_table_count = ARRAY_SIZE(gen7_video_cmd_table);
975*4882a593Smuzhiyun 		engine->get_cmd_length_mask = gen7_bsd_get_cmd_length_mask;
976*4882a593Smuzhiyun 		break;
977*4882a593Smuzhiyun 	case COPY_ENGINE_CLASS:
978*4882a593Smuzhiyun 		engine->get_cmd_length_mask = gen7_blt_get_cmd_length_mask;
979*4882a593Smuzhiyun 		if (IS_GEN(engine->i915, 9)) {
980*4882a593Smuzhiyun 			cmd_tables = gen9_blt_cmd_table;
981*4882a593Smuzhiyun 			cmd_table_count = ARRAY_SIZE(gen9_blt_cmd_table);
982*4882a593Smuzhiyun 			engine->get_cmd_length_mask =
983*4882a593Smuzhiyun 				gen9_blt_get_cmd_length_mask;
984*4882a593Smuzhiyun 
985*4882a593Smuzhiyun 			/* BCS Engine unsafe without parser */
986*4882a593Smuzhiyun 			engine->flags |= I915_ENGINE_REQUIRES_CMD_PARSER;
987*4882a593Smuzhiyun 		} else if (IS_HASWELL(engine->i915)) {
988*4882a593Smuzhiyun 			cmd_tables = hsw_blt_ring_cmd_table;
989*4882a593Smuzhiyun 			cmd_table_count = ARRAY_SIZE(hsw_blt_ring_cmd_table);
990*4882a593Smuzhiyun 		} else {
991*4882a593Smuzhiyun 			cmd_tables = gen7_blt_cmd_table;
992*4882a593Smuzhiyun 			cmd_table_count = ARRAY_SIZE(gen7_blt_cmd_table);
993*4882a593Smuzhiyun 		}
994*4882a593Smuzhiyun 
995*4882a593Smuzhiyun 		if (IS_GEN(engine->i915, 9)) {
996*4882a593Smuzhiyun 			engine->reg_tables = gen9_blt_reg_tables;
997*4882a593Smuzhiyun 			engine->reg_table_count =
998*4882a593Smuzhiyun 				ARRAY_SIZE(gen9_blt_reg_tables);
999*4882a593Smuzhiyun 		} else if (IS_HASWELL(engine->i915)) {
1000*4882a593Smuzhiyun 			engine->reg_tables = hsw_blt_reg_tables;
1001*4882a593Smuzhiyun 			engine->reg_table_count = ARRAY_SIZE(hsw_blt_reg_tables);
1002*4882a593Smuzhiyun 		} else {
1003*4882a593Smuzhiyun 			engine->reg_tables = ivb_blt_reg_tables;
1004*4882a593Smuzhiyun 			engine->reg_table_count = ARRAY_SIZE(ivb_blt_reg_tables);
1005*4882a593Smuzhiyun 		}
1006*4882a593Smuzhiyun 		break;
1007*4882a593Smuzhiyun 	case VIDEO_ENHANCEMENT_CLASS:
1008*4882a593Smuzhiyun 		cmd_tables = hsw_vebox_cmd_table;
1009*4882a593Smuzhiyun 		cmd_table_count = ARRAY_SIZE(hsw_vebox_cmd_table);
1010*4882a593Smuzhiyun 		/* VECS can use the same length_mask function as VCS */
1011*4882a593Smuzhiyun 		engine->get_cmd_length_mask = gen7_bsd_get_cmd_length_mask;
1012*4882a593Smuzhiyun 		break;
1013*4882a593Smuzhiyun 	default:
1014*4882a593Smuzhiyun 		MISSING_CASE(engine->class);
1015*4882a593Smuzhiyun 		goto out;
1016*4882a593Smuzhiyun 	}
1017*4882a593Smuzhiyun 
1018*4882a593Smuzhiyun 	if (!validate_cmds_sorted(engine, cmd_tables, cmd_table_count)) {
1019*4882a593Smuzhiyun 		drm_err(&engine->i915->drm,
1020*4882a593Smuzhiyun 			"%s: command descriptions are not sorted\n",
1021*4882a593Smuzhiyun 			engine->name);
1022*4882a593Smuzhiyun 		goto out;
1023*4882a593Smuzhiyun 	}
1024*4882a593Smuzhiyun 	if (!validate_regs_sorted(engine)) {
1025*4882a593Smuzhiyun 		drm_err(&engine->i915->drm,
1026*4882a593Smuzhiyun 			"%s: registers are not sorted\n", engine->name);
1027*4882a593Smuzhiyun 		goto out;
1028*4882a593Smuzhiyun 	}
1029*4882a593Smuzhiyun 
1030*4882a593Smuzhiyun 	ret = init_hash_table(engine, cmd_tables, cmd_table_count);
1031*4882a593Smuzhiyun 	if (ret) {
1032*4882a593Smuzhiyun 		drm_err(&engine->i915->drm,
1033*4882a593Smuzhiyun 			"%s: initialised failed!\n", engine->name);
1034*4882a593Smuzhiyun 		fini_hash_table(engine);
1035*4882a593Smuzhiyun 		goto out;
1036*4882a593Smuzhiyun 	}
1037*4882a593Smuzhiyun 
1038*4882a593Smuzhiyun 	engine->flags |= I915_ENGINE_USING_CMD_PARSER;
1039*4882a593Smuzhiyun 
1040*4882a593Smuzhiyun out:
1041*4882a593Smuzhiyun 	if (intel_engine_requires_cmd_parser(engine) &&
1042*4882a593Smuzhiyun 	    !intel_engine_using_cmd_parser(engine))
1043*4882a593Smuzhiyun 		return -EINVAL;
1044*4882a593Smuzhiyun 
1045*4882a593Smuzhiyun 	return 0;
1046*4882a593Smuzhiyun }
1047*4882a593Smuzhiyun 
1048*4882a593Smuzhiyun /**
1049*4882a593Smuzhiyun  * intel_engine_cleanup_cmd_parser() - clean up cmd parser related fields
1050*4882a593Smuzhiyun  * @engine: the engine to clean up
1051*4882a593Smuzhiyun  *
1052*4882a593Smuzhiyun  * Releases any resources related to command parsing that may have been
1053*4882a593Smuzhiyun  * initialized for the specified engine.
1054*4882a593Smuzhiyun  */
intel_engine_cleanup_cmd_parser(struct intel_engine_cs * engine)1055*4882a593Smuzhiyun void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine)
1056*4882a593Smuzhiyun {
1057*4882a593Smuzhiyun 	if (!intel_engine_using_cmd_parser(engine))
1058*4882a593Smuzhiyun 		return;
1059*4882a593Smuzhiyun 
1060*4882a593Smuzhiyun 	fini_hash_table(engine);
1061*4882a593Smuzhiyun }
1062*4882a593Smuzhiyun 
1063*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor*
find_cmd_in_table(struct intel_engine_cs * engine,u32 cmd_header)1064*4882a593Smuzhiyun find_cmd_in_table(struct intel_engine_cs *engine,
1065*4882a593Smuzhiyun 		  u32 cmd_header)
1066*4882a593Smuzhiyun {
1067*4882a593Smuzhiyun 	struct cmd_node *desc_node;
1068*4882a593Smuzhiyun 
1069*4882a593Smuzhiyun 	hash_for_each_possible(engine->cmd_hash, desc_node, node,
1070*4882a593Smuzhiyun 			       cmd_header_key(cmd_header)) {
1071*4882a593Smuzhiyun 		const struct drm_i915_cmd_descriptor *desc = desc_node->desc;
1072*4882a593Smuzhiyun 		if (((cmd_header ^ desc->cmd.value) & desc->cmd.mask) == 0)
1073*4882a593Smuzhiyun 			return desc;
1074*4882a593Smuzhiyun 	}
1075*4882a593Smuzhiyun 
1076*4882a593Smuzhiyun 	return NULL;
1077*4882a593Smuzhiyun }
1078*4882a593Smuzhiyun 
1079*4882a593Smuzhiyun /*
1080*4882a593Smuzhiyun  * Returns a pointer to a descriptor for the command specified by cmd_header.
1081*4882a593Smuzhiyun  *
1082*4882a593Smuzhiyun  * The caller must supply space for a default descriptor via the default_desc
1083*4882a593Smuzhiyun  * parameter. If no descriptor for the specified command exists in the engine's
1084*4882a593Smuzhiyun  * command parser tables, this function fills in default_desc based on the
1085*4882a593Smuzhiyun  * engine's default length encoding and returns default_desc.
1086*4882a593Smuzhiyun  */
1087*4882a593Smuzhiyun static const struct drm_i915_cmd_descriptor*
find_cmd(struct intel_engine_cs * engine,u32 cmd_header,const struct drm_i915_cmd_descriptor * desc,struct drm_i915_cmd_descriptor * default_desc)1088*4882a593Smuzhiyun find_cmd(struct intel_engine_cs *engine,
1089*4882a593Smuzhiyun 	 u32 cmd_header,
1090*4882a593Smuzhiyun 	 const struct drm_i915_cmd_descriptor *desc,
1091*4882a593Smuzhiyun 	 struct drm_i915_cmd_descriptor *default_desc)
1092*4882a593Smuzhiyun {
1093*4882a593Smuzhiyun 	u32 mask;
1094*4882a593Smuzhiyun 
1095*4882a593Smuzhiyun 	if (((cmd_header ^ desc->cmd.value) & desc->cmd.mask) == 0)
1096*4882a593Smuzhiyun 		return desc;
1097*4882a593Smuzhiyun 
1098*4882a593Smuzhiyun 	desc = find_cmd_in_table(engine, cmd_header);
1099*4882a593Smuzhiyun 	if (desc)
1100*4882a593Smuzhiyun 		return desc;
1101*4882a593Smuzhiyun 
1102*4882a593Smuzhiyun 	mask = engine->get_cmd_length_mask(cmd_header);
1103*4882a593Smuzhiyun 	if (!mask)
1104*4882a593Smuzhiyun 		return NULL;
1105*4882a593Smuzhiyun 
1106*4882a593Smuzhiyun 	default_desc->cmd.value = cmd_header;
1107*4882a593Smuzhiyun 	default_desc->cmd.mask = ~0u << MIN_OPCODE_SHIFT;
1108*4882a593Smuzhiyun 	default_desc->length.mask = mask;
1109*4882a593Smuzhiyun 	default_desc->flags = CMD_DESC_SKIP;
1110*4882a593Smuzhiyun 	return default_desc;
1111*4882a593Smuzhiyun }
1112*4882a593Smuzhiyun 
1113*4882a593Smuzhiyun static const struct drm_i915_reg_descriptor *
__find_reg(const struct drm_i915_reg_descriptor * table,int count,u32 addr)1114*4882a593Smuzhiyun __find_reg(const struct drm_i915_reg_descriptor *table, int count, u32 addr)
1115*4882a593Smuzhiyun {
1116*4882a593Smuzhiyun 	int start = 0, end = count;
1117*4882a593Smuzhiyun 	while (start < end) {
1118*4882a593Smuzhiyun 		int mid = start + (end - start) / 2;
1119*4882a593Smuzhiyun 		int ret = addr - i915_mmio_reg_offset(table[mid].addr);
1120*4882a593Smuzhiyun 		if (ret < 0)
1121*4882a593Smuzhiyun 			end = mid;
1122*4882a593Smuzhiyun 		else if (ret > 0)
1123*4882a593Smuzhiyun 			start = mid + 1;
1124*4882a593Smuzhiyun 		else
1125*4882a593Smuzhiyun 			return &table[mid];
1126*4882a593Smuzhiyun 	}
1127*4882a593Smuzhiyun 	return NULL;
1128*4882a593Smuzhiyun }
1129*4882a593Smuzhiyun 
1130*4882a593Smuzhiyun static const struct drm_i915_reg_descriptor *
find_reg(const struct intel_engine_cs * engine,u32 addr)1131*4882a593Smuzhiyun find_reg(const struct intel_engine_cs *engine, u32 addr)
1132*4882a593Smuzhiyun {
1133*4882a593Smuzhiyun 	const struct drm_i915_reg_table *table = engine->reg_tables;
1134*4882a593Smuzhiyun 	const struct drm_i915_reg_descriptor *reg = NULL;
1135*4882a593Smuzhiyun 	int count = engine->reg_table_count;
1136*4882a593Smuzhiyun 
1137*4882a593Smuzhiyun 	for (; !reg && (count > 0); ++table, --count)
1138*4882a593Smuzhiyun 		reg = __find_reg(table->regs, table->num_regs, addr);
1139*4882a593Smuzhiyun 
1140*4882a593Smuzhiyun 	return reg;
1141*4882a593Smuzhiyun }
1142*4882a593Smuzhiyun 
1143*4882a593Smuzhiyun /* Returns a vmap'd pointer to dst_obj, which the caller must unmap */
copy_batch(struct drm_i915_gem_object * dst_obj,struct drm_i915_gem_object * src_obj,u32 offset,u32 length)1144*4882a593Smuzhiyun static u32 *copy_batch(struct drm_i915_gem_object *dst_obj,
1145*4882a593Smuzhiyun 		       struct drm_i915_gem_object *src_obj,
1146*4882a593Smuzhiyun 		       u32 offset, u32 length)
1147*4882a593Smuzhiyun {
1148*4882a593Smuzhiyun 	unsigned int src_needs_clflush;
1149*4882a593Smuzhiyun 	unsigned int dst_needs_clflush;
1150*4882a593Smuzhiyun 	void *dst, *src;
1151*4882a593Smuzhiyun 	int ret;
1152*4882a593Smuzhiyun 
1153*4882a593Smuzhiyun 	ret = i915_gem_object_prepare_write(dst_obj, &dst_needs_clflush);
1154*4882a593Smuzhiyun 	if (ret)
1155*4882a593Smuzhiyun 		return ERR_PTR(ret);
1156*4882a593Smuzhiyun 
1157*4882a593Smuzhiyun 	dst = i915_gem_object_pin_map(dst_obj, I915_MAP_FORCE_WB);
1158*4882a593Smuzhiyun 	i915_gem_object_finish_access(dst_obj);
1159*4882a593Smuzhiyun 	if (IS_ERR(dst))
1160*4882a593Smuzhiyun 		return dst;
1161*4882a593Smuzhiyun 
1162*4882a593Smuzhiyun 	ret = i915_gem_object_prepare_read(src_obj, &src_needs_clflush);
1163*4882a593Smuzhiyun 	if (ret) {
1164*4882a593Smuzhiyun 		i915_gem_object_unpin_map(dst_obj);
1165*4882a593Smuzhiyun 		return ERR_PTR(ret);
1166*4882a593Smuzhiyun 	}
1167*4882a593Smuzhiyun 
1168*4882a593Smuzhiyun 	src = ERR_PTR(-ENODEV);
1169*4882a593Smuzhiyun 	if (src_needs_clflush && i915_has_memcpy_from_wc()) {
1170*4882a593Smuzhiyun 		src = i915_gem_object_pin_map(src_obj, I915_MAP_WC);
1171*4882a593Smuzhiyun 		if (!IS_ERR(src)) {
1172*4882a593Smuzhiyun 			i915_unaligned_memcpy_from_wc(dst,
1173*4882a593Smuzhiyun 						      src + offset,
1174*4882a593Smuzhiyun 						      length);
1175*4882a593Smuzhiyun 			i915_gem_object_unpin_map(src_obj);
1176*4882a593Smuzhiyun 		}
1177*4882a593Smuzhiyun 	}
1178*4882a593Smuzhiyun 	if (IS_ERR(src)) {
1179*4882a593Smuzhiyun 		unsigned long x, n, remain;
1180*4882a593Smuzhiyun 		void *ptr;
1181*4882a593Smuzhiyun 
1182*4882a593Smuzhiyun 		/*
1183*4882a593Smuzhiyun 		 * We can avoid clflushing partial cachelines before the write
1184*4882a593Smuzhiyun 		 * if we only every write full cache-lines. Since we know that
1185*4882a593Smuzhiyun 		 * both the source and destination are in multiples of
1186*4882a593Smuzhiyun 		 * PAGE_SIZE, we can simply round up to the next cacheline.
1187*4882a593Smuzhiyun 		 * We don't care about copying too much here as we only
1188*4882a593Smuzhiyun 		 * validate up to the end of the batch.
1189*4882a593Smuzhiyun 		 */
1190*4882a593Smuzhiyun 		remain = length;
1191*4882a593Smuzhiyun 		if (dst_needs_clflush & CLFLUSH_BEFORE)
1192*4882a593Smuzhiyun 			remain = round_up(remain,
1193*4882a593Smuzhiyun 					  boot_cpu_data.x86_clflush_size);
1194*4882a593Smuzhiyun 
1195*4882a593Smuzhiyun 		ptr = dst;
1196*4882a593Smuzhiyun 		x = offset_in_page(offset);
1197*4882a593Smuzhiyun 		for (n = offset >> PAGE_SHIFT; remain; n++) {
1198*4882a593Smuzhiyun 			int len = min(remain, PAGE_SIZE - x);
1199*4882a593Smuzhiyun 
1200*4882a593Smuzhiyun 			src = kmap_atomic(i915_gem_object_get_page(src_obj, n));
1201*4882a593Smuzhiyun 			if (src_needs_clflush)
1202*4882a593Smuzhiyun 				drm_clflush_virt_range(src + x, len);
1203*4882a593Smuzhiyun 			memcpy(ptr, src + x, len);
1204*4882a593Smuzhiyun 			kunmap_atomic(src);
1205*4882a593Smuzhiyun 
1206*4882a593Smuzhiyun 			ptr += len;
1207*4882a593Smuzhiyun 			remain -= len;
1208*4882a593Smuzhiyun 			x = 0;
1209*4882a593Smuzhiyun 		}
1210*4882a593Smuzhiyun 	}
1211*4882a593Smuzhiyun 
1212*4882a593Smuzhiyun 	i915_gem_object_finish_access(src_obj);
1213*4882a593Smuzhiyun 
1214*4882a593Smuzhiyun 	memset32(dst + length, 0, (dst_obj->base.size - length) / sizeof(u32));
1215*4882a593Smuzhiyun 
1216*4882a593Smuzhiyun 	return dst;
1217*4882a593Smuzhiyun }
1218*4882a593Smuzhiyun 
cmd_desc_is(const struct drm_i915_cmd_descriptor * const desc,const u32 cmd)1219*4882a593Smuzhiyun static inline bool cmd_desc_is(const struct drm_i915_cmd_descriptor * const desc,
1220*4882a593Smuzhiyun 			       const u32 cmd)
1221*4882a593Smuzhiyun {
1222*4882a593Smuzhiyun 	return desc->cmd.value == (cmd & desc->cmd.mask);
1223*4882a593Smuzhiyun }
1224*4882a593Smuzhiyun 
check_cmd(const struct intel_engine_cs * engine,const struct drm_i915_cmd_descriptor * desc,const u32 * cmd,u32 length)1225*4882a593Smuzhiyun static bool check_cmd(const struct intel_engine_cs *engine,
1226*4882a593Smuzhiyun 		      const struct drm_i915_cmd_descriptor *desc,
1227*4882a593Smuzhiyun 		      const u32 *cmd, u32 length)
1228*4882a593Smuzhiyun {
1229*4882a593Smuzhiyun 	if (desc->flags & CMD_DESC_SKIP)
1230*4882a593Smuzhiyun 		return true;
1231*4882a593Smuzhiyun 
1232*4882a593Smuzhiyun 	if (desc->flags & CMD_DESC_REJECT) {
1233*4882a593Smuzhiyun 		DRM_DEBUG("CMD: Rejected command: 0x%08X\n", *cmd);
1234*4882a593Smuzhiyun 		return false;
1235*4882a593Smuzhiyun 	}
1236*4882a593Smuzhiyun 
1237*4882a593Smuzhiyun 	if (desc->flags & CMD_DESC_REGISTER) {
1238*4882a593Smuzhiyun 		/*
1239*4882a593Smuzhiyun 		 * Get the distance between individual register offset
1240*4882a593Smuzhiyun 		 * fields if the command can perform more than one
1241*4882a593Smuzhiyun 		 * access at a time.
1242*4882a593Smuzhiyun 		 */
1243*4882a593Smuzhiyun 		const u32 step = desc->reg.step ? desc->reg.step : length;
1244*4882a593Smuzhiyun 		u32 offset;
1245*4882a593Smuzhiyun 
1246*4882a593Smuzhiyun 		for (offset = desc->reg.offset; offset < length;
1247*4882a593Smuzhiyun 		     offset += step) {
1248*4882a593Smuzhiyun 			const u32 reg_addr = cmd[offset] & desc->reg.mask;
1249*4882a593Smuzhiyun 			const struct drm_i915_reg_descriptor *reg =
1250*4882a593Smuzhiyun 				find_reg(engine, reg_addr);
1251*4882a593Smuzhiyun 
1252*4882a593Smuzhiyun 			if (!reg) {
1253*4882a593Smuzhiyun 				DRM_DEBUG("CMD: Rejected register 0x%08X in command: 0x%08X (%s)\n",
1254*4882a593Smuzhiyun 					  reg_addr, *cmd, engine->name);
1255*4882a593Smuzhiyun 				return false;
1256*4882a593Smuzhiyun 			}
1257*4882a593Smuzhiyun 
1258*4882a593Smuzhiyun 			/*
1259*4882a593Smuzhiyun 			 * Check the value written to the register against the
1260*4882a593Smuzhiyun 			 * allowed mask/value pair given in the whitelist entry.
1261*4882a593Smuzhiyun 			 */
1262*4882a593Smuzhiyun 			if (reg->mask) {
1263*4882a593Smuzhiyun 				if (cmd_desc_is(desc, MI_LOAD_REGISTER_MEM)) {
1264*4882a593Smuzhiyun 					DRM_DEBUG("CMD: Rejected LRM to masked register 0x%08X\n",
1265*4882a593Smuzhiyun 						  reg_addr);
1266*4882a593Smuzhiyun 					return false;
1267*4882a593Smuzhiyun 				}
1268*4882a593Smuzhiyun 
1269*4882a593Smuzhiyun 				if (cmd_desc_is(desc, MI_LOAD_REGISTER_REG)) {
1270*4882a593Smuzhiyun 					DRM_DEBUG("CMD: Rejected LRR to masked register 0x%08X\n",
1271*4882a593Smuzhiyun 						  reg_addr);
1272*4882a593Smuzhiyun 					return false;
1273*4882a593Smuzhiyun 				}
1274*4882a593Smuzhiyun 
1275*4882a593Smuzhiyun 				if (cmd_desc_is(desc, MI_LOAD_REGISTER_IMM(1)) &&
1276*4882a593Smuzhiyun 				    (offset + 2 > length ||
1277*4882a593Smuzhiyun 				     (cmd[offset + 1] & reg->mask) != reg->value)) {
1278*4882a593Smuzhiyun 					DRM_DEBUG("CMD: Rejected LRI to masked register 0x%08X\n",
1279*4882a593Smuzhiyun 						  reg_addr);
1280*4882a593Smuzhiyun 					return false;
1281*4882a593Smuzhiyun 				}
1282*4882a593Smuzhiyun 			}
1283*4882a593Smuzhiyun 		}
1284*4882a593Smuzhiyun 	}
1285*4882a593Smuzhiyun 
1286*4882a593Smuzhiyun 	if (desc->flags & CMD_DESC_BITMASK) {
1287*4882a593Smuzhiyun 		int i;
1288*4882a593Smuzhiyun 
1289*4882a593Smuzhiyun 		for (i = 0; i < MAX_CMD_DESC_BITMASKS; i++) {
1290*4882a593Smuzhiyun 			u32 dword;
1291*4882a593Smuzhiyun 
1292*4882a593Smuzhiyun 			if (desc->bits[i].mask == 0)
1293*4882a593Smuzhiyun 				break;
1294*4882a593Smuzhiyun 
1295*4882a593Smuzhiyun 			if (desc->bits[i].condition_mask != 0) {
1296*4882a593Smuzhiyun 				u32 offset =
1297*4882a593Smuzhiyun 					desc->bits[i].condition_offset;
1298*4882a593Smuzhiyun 				u32 condition = cmd[offset] &
1299*4882a593Smuzhiyun 					desc->bits[i].condition_mask;
1300*4882a593Smuzhiyun 
1301*4882a593Smuzhiyun 				if (condition == 0)
1302*4882a593Smuzhiyun 					continue;
1303*4882a593Smuzhiyun 			}
1304*4882a593Smuzhiyun 
1305*4882a593Smuzhiyun 			if (desc->bits[i].offset >= length) {
1306*4882a593Smuzhiyun 				DRM_DEBUG("CMD: Rejected command 0x%08X, too short to check bitmask (%s)\n",
1307*4882a593Smuzhiyun 					  *cmd, engine->name);
1308*4882a593Smuzhiyun 				return false;
1309*4882a593Smuzhiyun 			}
1310*4882a593Smuzhiyun 
1311*4882a593Smuzhiyun 			dword = cmd[desc->bits[i].offset] &
1312*4882a593Smuzhiyun 				desc->bits[i].mask;
1313*4882a593Smuzhiyun 
1314*4882a593Smuzhiyun 			if (dword != desc->bits[i].expected) {
1315*4882a593Smuzhiyun 				DRM_DEBUG("CMD: Rejected command 0x%08X for bitmask 0x%08X (exp=0x%08X act=0x%08X) (%s)\n",
1316*4882a593Smuzhiyun 					  *cmd,
1317*4882a593Smuzhiyun 					  desc->bits[i].mask,
1318*4882a593Smuzhiyun 					  desc->bits[i].expected,
1319*4882a593Smuzhiyun 					  dword, engine->name);
1320*4882a593Smuzhiyun 				return false;
1321*4882a593Smuzhiyun 			}
1322*4882a593Smuzhiyun 		}
1323*4882a593Smuzhiyun 	}
1324*4882a593Smuzhiyun 
1325*4882a593Smuzhiyun 	return true;
1326*4882a593Smuzhiyun }
1327*4882a593Smuzhiyun 
check_bbstart(u32 * cmd,u32 offset,u32 length,u32 batch_length,u64 batch_addr,u64 shadow_addr,const unsigned long * jump_whitelist)1328*4882a593Smuzhiyun static int check_bbstart(u32 *cmd, u32 offset, u32 length,
1329*4882a593Smuzhiyun 			 u32 batch_length,
1330*4882a593Smuzhiyun 			 u64 batch_addr,
1331*4882a593Smuzhiyun 			 u64 shadow_addr,
1332*4882a593Smuzhiyun 			 const unsigned long *jump_whitelist)
1333*4882a593Smuzhiyun {
1334*4882a593Smuzhiyun 	u64 jump_offset, jump_target;
1335*4882a593Smuzhiyun 	u32 target_cmd_offset, target_cmd_index;
1336*4882a593Smuzhiyun 
1337*4882a593Smuzhiyun 	/* For igt compatibility on older platforms */
1338*4882a593Smuzhiyun 	if (!jump_whitelist) {
1339*4882a593Smuzhiyun 		DRM_DEBUG("CMD: Rejecting BB_START for ggtt based submission\n");
1340*4882a593Smuzhiyun 		return -EACCES;
1341*4882a593Smuzhiyun 	}
1342*4882a593Smuzhiyun 
1343*4882a593Smuzhiyun 	if (length != 3) {
1344*4882a593Smuzhiyun 		DRM_DEBUG("CMD: Recursive BB_START with bad length(%u)\n",
1345*4882a593Smuzhiyun 			  length);
1346*4882a593Smuzhiyun 		return -EINVAL;
1347*4882a593Smuzhiyun 	}
1348*4882a593Smuzhiyun 
1349*4882a593Smuzhiyun 	jump_target = *(u64 *)(cmd + 1);
1350*4882a593Smuzhiyun 	jump_offset = jump_target - batch_addr;
1351*4882a593Smuzhiyun 
1352*4882a593Smuzhiyun 	/*
1353*4882a593Smuzhiyun 	 * Any underflow of jump_target is guaranteed to be outside the range
1354*4882a593Smuzhiyun 	 * of a u32, so >= test catches both too large and too small
1355*4882a593Smuzhiyun 	 */
1356*4882a593Smuzhiyun 	if (jump_offset >= batch_length) {
1357*4882a593Smuzhiyun 		DRM_DEBUG("CMD: BB_START to 0x%llx jumps out of BB\n",
1358*4882a593Smuzhiyun 			  jump_target);
1359*4882a593Smuzhiyun 		return -EINVAL;
1360*4882a593Smuzhiyun 	}
1361*4882a593Smuzhiyun 
1362*4882a593Smuzhiyun 	/*
1363*4882a593Smuzhiyun 	 * This cannot overflow a u32 because we already checked jump_offset
1364*4882a593Smuzhiyun 	 * is within the BB, and the batch_length is a u32
1365*4882a593Smuzhiyun 	 */
1366*4882a593Smuzhiyun 	target_cmd_offset = lower_32_bits(jump_offset);
1367*4882a593Smuzhiyun 	target_cmd_index = target_cmd_offset / sizeof(u32);
1368*4882a593Smuzhiyun 
1369*4882a593Smuzhiyun 	*(u64 *)(cmd + 1) = shadow_addr + target_cmd_offset;
1370*4882a593Smuzhiyun 
1371*4882a593Smuzhiyun 	if (target_cmd_index == offset)
1372*4882a593Smuzhiyun 		return 0;
1373*4882a593Smuzhiyun 
1374*4882a593Smuzhiyun 	if (IS_ERR(jump_whitelist))
1375*4882a593Smuzhiyun 		return PTR_ERR(jump_whitelist);
1376*4882a593Smuzhiyun 
1377*4882a593Smuzhiyun 	if (!test_bit(target_cmd_index, jump_whitelist)) {
1378*4882a593Smuzhiyun 		DRM_DEBUG("CMD: BB_START to 0x%llx not a previously executed cmd\n",
1379*4882a593Smuzhiyun 			  jump_target);
1380*4882a593Smuzhiyun 		return -EINVAL;
1381*4882a593Smuzhiyun 	}
1382*4882a593Smuzhiyun 
1383*4882a593Smuzhiyun 	return 0;
1384*4882a593Smuzhiyun }
1385*4882a593Smuzhiyun 
alloc_whitelist(u32 batch_length)1386*4882a593Smuzhiyun static unsigned long *alloc_whitelist(u32 batch_length)
1387*4882a593Smuzhiyun {
1388*4882a593Smuzhiyun 	unsigned long *jmp;
1389*4882a593Smuzhiyun 
1390*4882a593Smuzhiyun 	/*
1391*4882a593Smuzhiyun 	 * We expect batch_length to be less than 256KiB for known users,
1392*4882a593Smuzhiyun 	 * i.e. we need at most an 8KiB bitmap allocation which should be
1393*4882a593Smuzhiyun 	 * reasonably cheap due to kmalloc caches.
1394*4882a593Smuzhiyun 	 */
1395*4882a593Smuzhiyun 
1396*4882a593Smuzhiyun 	/* Prefer to report transient allocation failure rather than hit oom */
1397*4882a593Smuzhiyun 	jmp = bitmap_zalloc(DIV_ROUND_UP(batch_length, sizeof(u32)),
1398*4882a593Smuzhiyun 			    GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
1399*4882a593Smuzhiyun 	if (!jmp)
1400*4882a593Smuzhiyun 		return ERR_PTR(-ENOMEM);
1401*4882a593Smuzhiyun 
1402*4882a593Smuzhiyun 	return jmp;
1403*4882a593Smuzhiyun }
1404*4882a593Smuzhiyun 
1405*4882a593Smuzhiyun #define LENGTH_BIAS 2
1406*4882a593Smuzhiyun 
1407*4882a593Smuzhiyun /**
1408*4882a593Smuzhiyun  * intel_engine_cmd_parser() - parse a batch buffer for privilege violations
1409*4882a593Smuzhiyun  * @engine: the engine on which the batch is to execute
1410*4882a593Smuzhiyun  * @batch: the batch buffer in question
1411*4882a593Smuzhiyun  * @batch_offset: byte offset in the batch at which execution starts
1412*4882a593Smuzhiyun  * @batch_length: length of the commands in batch_obj
1413*4882a593Smuzhiyun  * @shadow: validated copy of the batch buffer in question
1414*4882a593Smuzhiyun  * @trampoline: whether to emit a conditional trampoline at the end of the batch
1415*4882a593Smuzhiyun  *
1416*4882a593Smuzhiyun  * Parses the specified batch buffer looking for privilege violations as
1417*4882a593Smuzhiyun  * described in the overview.
1418*4882a593Smuzhiyun  *
1419*4882a593Smuzhiyun  * Return: non-zero if the parser finds violations or otherwise fails; -EACCES
1420*4882a593Smuzhiyun  * if the batch appears legal but should use hardware parsing
1421*4882a593Smuzhiyun  */
1422*4882a593Smuzhiyun 
intel_engine_cmd_parser(struct intel_engine_cs * engine,struct i915_vma * batch,unsigned long batch_offset,unsigned long batch_length,struct i915_vma * shadow,bool trampoline)1423*4882a593Smuzhiyun int intel_engine_cmd_parser(struct intel_engine_cs *engine,
1424*4882a593Smuzhiyun 			    struct i915_vma *batch,
1425*4882a593Smuzhiyun 			    unsigned long batch_offset,
1426*4882a593Smuzhiyun 			    unsigned long batch_length,
1427*4882a593Smuzhiyun 			    struct i915_vma *shadow,
1428*4882a593Smuzhiyun 			    bool trampoline)
1429*4882a593Smuzhiyun {
1430*4882a593Smuzhiyun 	u32 *cmd, *batch_end, offset = 0;
1431*4882a593Smuzhiyun 	struct drm_i915_cmd_descriptor default_desc = noop_desc;
1432*4882a593Smuzhiyun 	const struct drm_i915_cmd_descriptor *desc = &default_desc;
1433*4882a593Smuzhiyun 	unsigned long *jump_whitelist;
1434*4882a593Smuzhiyun 	u64 batch_addr, shadow_addr;
1435*4882a593Smuzhiyun 	int ret = 0;
1436*4882a593Smuzhiyun 
1437*4882a593Smuzhiyun 	GEM_BUG_ON(!IS_ALIGNED(batch_offset, sizeof(*cmd)));
1438*4882a593Smuzhiyun 	GEM_BUG_ON(!IS_ALIGNED(batch_length, sizeof(*cmd)));
1439*4882a593Smuzhiyun 	GEM_BUG_ON(range_overflows_t(u64, batch_offset, batch_length,
1440*4882a593Smuzhiyun 				     batch->size));
1441*4882a593Smuzhiyun 	GEM_BUG_ON(!batch_length);
1442*4882a593Smuzhiyun 
1443*4882a593Smuzhiyun 	cmd = copy_batch(shadow->obj, batch->obj,
1444*4882a593Smuzhiyun 			 batch_offset, batch_length);
1445*4882a593Smuzhiyun 	if (IS_ERR(cmd)) {
1446*4882a593Smuzhiyun 		DRM_DEBUG("CMD: Failed to copy batch\n");
1447*4882a593Smuzhiyun 		return PTR_ERR(cmd);
1448*4882a593Smuzhiyun 	}
1449*4882a593Smuzhiyun 
1450*4882a593Smuzhiyun 	jump_whitelist = NULL;
1451*4882a593Smuzhiyun 	if (!trampoline)
1452*4882a593Smuzhiyun 		/* Defer failure until attempted use */
1453*4882a593Smuzhiyun 		jump_whitelist = alloc_whitelist(batch_length);
1454*4882a593Smuzhiyun 
1455*4882a593Smuzhiyun 	shadow_addr = gen8_canonical_addr(shadow->node.start);
1456*4882a593Smuzhiyun 	batch_addr = gen8_canonical_addr(batch->node.start + batch_offset);
1457*4882a593Smuzhiyun 
1458*4882a593Smuzhiyun 	/*
1459*4882a593Smuzhiyun 	 * We use the batch length as size because the shadow object is as
1460*4882a593Smuzhiyun 	 * large or larger and copy_batch() will write MI_NOPs to the extra
1461*4882a593Smuzhiyun 	 * space. Parsing should be faster in some cases this way.
1462*4882a593Smuzhiyun 	 */
1463*4882a593Smuzhiyun 	batch_end = cmd + batch_length / sizeof(*batch_end);
1464*4882a593Smuzhiyun 	do {
1465*4882a593Smuzhiyun 		u32 length;
1466*4882a593Smuzhiyun 
1467*4882a593Smuzhiyun 		if (*cmd == MI_BATCH_BUFFER_END)
1468*4882a593Smuzhiyun 			break;
1469*4882a593Smuzhiyun 
1470*4882a593Smuzhiyun 		desc = find_cmd(engine, *cmd, desc, &default_desc);
1471*4882a593Smuzhiyun 		if (!desc) {
1472*4882a593Smuzhiyun 			DRM_DEBUG("CMD: Unrecognized command: 0x%08X\n", *cmd);
1473*4882a593Smuzhiyun 			ret = -EINVAL;
1474*4882a593Smuzhiyun 			break;
1475*4882a593Smuzhiyun 		}
1476*4882a593Smuzhiyun 
1477*4882a593Smuzhiyun 		if (desc->flags & CMD_DESC_FIXED)
1478*4882a593Smuzhiyun 			length = desc->length.fixed;
1479*4882a593Smuzhiyun 		else
1480*4882a593Smuzhiyun 			length = (*cmd & desc->length.mask) + LENGTH_BIAS;
1481*4882a593Smuzhiyun 
1482*4882a593Smuzhiyun 		if ((batch_end - cmd) < length) {
1483*4882a593Smuzhiyun 			DRM_DEBUG("CMD: Command length exceeds batch length: 0x%08X length=%u batchlen=%td\n",
1484*4882a593Smuzhiyun 				  *cmd,
1485*4882a593Smuzhiyun 				  length,
1486*4882a593Smuzhiyun 				  batch_end - cmd);
1487*4882a593Smuzhiyun 			ret = -EINVAL;
1488*4882a593Smuzhiyun 			break;
1489*4882a593Smuzhiyun 		}
1490*4882a593Smuzhiyun 
1491*4882a593Smuzhiyun 		if (!check_cmd(engine, desc, cmd, length)) {
1492*4882a593Smuzhiyun 			ret = -EACCES;
1493*4882a593Smuzhiyun 			break;
1494*4882a593Smuzhiyun 		}
1495*4882a593Smuzhiyun 
1496*4882a593Smuzhiyun 		if (cmd_desc_is(desc, MI_BATCH_BUFFER_START)) {
1497*4882a593Smuzhiyun 			ret = check_bbstart(cmd, offset, length, batch_length,
1498*4882a593Smuzhiyun 					    batch_addr, shadow_addr,
1499*4882a593Smuzhiyun 					    jump_whitelist);
1500*4882a593Smuzhiyun 			break;
1501*4882a593Smuzhiyun 		}
1502*4882a593Smuzhiyun 
1503*4882a593Smuzhiyun 		if (!IS_ERR_OR_NULL(jump_whitelist))
1504*4882a593Smuzhiyun 			__set_bit(offset, jump_whitelist);
1505*4882a593Smuzhiyun 
1506*4882a593Smuzhiyun 		cmd += length;
1507*4882a593Smuzhiyun 		offset += length;
1508*4882a593Smuzhiyun 		if  (cmd >= batch_end) {
1509*4882a593Smuzhiyun 			DRM_DEBUG("CMD: Got to the end of the buffer w/o a BBE cmd!\n");
1510*4882a593Smuzhiyun 			ret = -EINVAL;
1511*4882a593Smuzhiyun 			break;
1512*4882a593Smuzhiyun 		}
1513*4882a593Smuzhiyun 	} while (1);
1514*4882a593Smuzhiyun 
1515*4882a593Smuzhiyun 	if (trampoline) {
1516*4882a593Smuzhiyun 		/*
1517*4882a593Smuzhiyun 		 * With the trampoline, the shadow is executed twice.
1518*4882a593Smuzhiyun 		 *
1519*4882a593Smuzhiyun 		 *   1 - starting at offset 0, in privileged mode
1520*4882a593Smuzhiyun 		 *   2 - starting at offset batch_len, as non-privileged
1521*4882a593Smuzhiyun 		 *
1522*4882a593Smuzhiyun 		 * Only if the batch is valid and safe to execute, do we
1523*4882a593Smuzhiyun 		 * allow the first privileged execution to proceed. If not,
1524*4882a593Smuzhiyun 		 * we terminate the first batch and use the second batchbuffer
1525*4882a593Smuzhiyun 		 * entry to chain to the original unsafe non-privileged batch,
1526*4882a593Smuzhiyun 		 * leaving it to the HW to validate.
1527*4882a593Smuzhiyun 		 */
1528*4882a593Smuzhiyun 		*batch_end = MI_BATCH_BUFFER_END;
1529*4882a593Smuzhiyun 
1530*4882a593Smuzhiyun 		if (ret) {
1531*4882a593Smuzhiyun 			/* Batch unsafe to execute with privileges, cancel! */
1532*4882a593Smuzhiyun 			cmd = page_mask_bits(shadow->obj->mm.mapping);
1533*4882a593Smuzhiyun 			*cmd = MI_BATCH_BUFFER_END;
1534*4882a593Smuzhiyun 
1535*4882a593Smuzhiyun 			/* If batch is unsafe but valid, jump to the original */
1536*4882a593Smuzhiyun 			if (ret == -EACCES) {
1537*4882a593Smuzhiyun 				unsigned int flags;
1538*4882a593Smuzhiyun 
1539*4882a593Smuzhiyun 				flags = MI_BATCH_NON_SECURE_I965;
1540*4882a593Smuzhiyun 				if (IS_HASWELL(engine->i915))
1541*4882a593Smuzhiyun 					flags = MI_BATCH_NON_SECURE_HSW;
1542*4882a593Smuzhiyun 
1543*4882a593Smuzhiyun 				GEM_BUG_ON(!IS_GEN_RANGE(engine->i915, 6, 7));
1544*4882a593Smuzhiyun 				__gen6_emit_bb_start(batch_end,
1545*4882a593Smuzhiyun 						     batch_addr,
1546*4882a593Smuzhiyun 						     flags);
1547*4882a593Smuzhiyun 
1548*4882a593Smuzhiyun 				ret = 0; /* allow execution */
1549*4882a593Smuzhiyun 			}
1550*4882a593Smuzhiyun 		}
1551*4882a593Smuzhiyun 	}
1552*4882a593Smuzhiyun 
1553*4882a593Smuzhiyun 	i915_gem_object_flush_map(shadow->obj);
1554*4882a593Smuzhiyun 
1555*4882a593Smuzhiyun 	if (!IS_ERR_OR_NULL(jump_whitelist))
1556*4882a593Smuzhiyun 		kfree(jump_whitelist);
1557*4882a593Smuzhiyun 	i915_gem_object_unpin_map(shadow->obj);
1558*4882a593Smuzhiyun 	return ret;
1559*4882a593Smuzhiyun }
1560*4882a593Smuzhiyun 
1561*4882a593Smuzhiyun /**
1562*4882a593Smuzhiyun  * i915_cmd_parser_get_version() - get the cmd parser version number
1563*4882a593Smuzhiyun  * @dev_priv: i915 device private
1564*4882a593Smuzhiyun  *
1565*4882a593Smuzhiyun  * The cmd parser maintains a simple increasing integer version number suitable
1566*4882a593Smuzhiyun  * for passing to userspace clients to determine what operations are permitted.
1567*4882a593Smuzhiyun  *
1568*4882a593Smuzhiyun  * Return: the current version number of the cmd parser
1569*4882a593Smuzhiyun  */
i915_cmd_parser_get_version(struct drm_i915_private * dev_priv)1570*4882a593Smuzhiyun int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv)
1571*4882a593Smuzhiyun {
1572*4882a593Smuzhiyun 	struct intel_engine_cs *engine;
1573*4882a593Smuzhiyun 	bool active = false;
1574*4882a593Smuzhiyun 
1575*4882a593Smuzhiyun 	/* If the command parser is not enabled, report 0 - unsupported */
1576*4882a593Smuzhiyun 	for_each_uabi_engine(engine, dev_priv) {
1577*4882a593Smuzhiyun 		if (intel_engine_using_cmd_parser(engine)) {
1578*4882a593Smuzhiyun 			active = true;
1579*4882a593Smuzhiyun 			break;
1580*4882a593Smuzhiyun 		}
1581*4882a593Smuzhiyun 	}
1582*4882a593Smuzhiyun 	if (!active)
1583*4882a593Smuzhiyun 		return 0;
1584*4882a593Smuzhiyun 
1585*4882a593Smuzhiyun 	/*
1586*4882a593Smuzhiyun 	 * Command parser version history
1587*4882a593Smuzhiyun 	 *
1588*4882a593Smuzhiyun 	 * 1. Initial version. Checks batches and reports violations, but leaves
1589*4882a593Smuzhiyun 	 *    hardware parsing enabled (so does not allow new use cases).
1590*4882a593Smuzhiyun 	 * 2. Allow access to the MI_PREDICATE_SRC0 and
1591*4882a593Smuzhiyun 	 *    MI_PREDICATE_SRC1 registers.
1592*4882a593Smuzhiyun 	 * 3. Allow access to the GPGPU_THREADS_DISPATCHED register.
1593*4882a593Smuzhiyun 	 * 4. L3 atomic chicken bits of HSW_SCRATCH1 and HSW_ROW_CHICKEN3.
1594*4882a593Smuzhiyun 	 * 5. GPGPU dispatch compute indirect registers.
1595*4882a593Smuzhiyun 	 * 6. TIMESTAMP register and Haswell CS GPR registers
1596*4882a593Smuzhiyun 	 * 7. Allow MI_LOAD_REGISTER_REG between whitelisted registers.
1597*4882a593Smuzhiyun 	 * 8. Don't report cmd_check() failures as EINVAL errors to userspace;
1598*4882a593Smuzhiyun 	 *    rely on the HW to NOOP disallowed commands as it would without
1599*4882a593Smuzhiyun 	 *    the parser enabled.
1600*4882a593Smuzhiyun 	 * 9. Don't whitelist or handle oacontrol specially, as ownership
1601*4882a593Smuzhiyun 	 *    for oacontrol state is moving to i915-perf.
1602*4882a593Smuzhiyun 	 * 10. Support for Gen9 BCS Parsing
1603*4882a593Smuzhiyun 	 */
1604*4882a593Smuzhiyun 	return 10;
1605*4882a593Smuzhiyun }
1606