1 /* 2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Ke Yu 25 * Kevin Tian <kevin.tian@intel.com> 26 * Zhiyuan Lv <zhiyuan.lv@intel.com> 27 * 28 * Contributors: 29 * Min He <min.he@intel.com> 30 * Ping Gao <ping.a.gao@intel.com> 31 * Tina Zhang <tina.zhang@intel.com> 32 * Yulei Zhang <yulei.zhang@intel.com> 33 * Zhi Wang <zhi.a.wang@intel.com> 34 * 35 */ 36 37 #include <linux/slab.h> 38 39 #include "i915_drv.h" 40 #include "gt/intel_gpu_commands.h" 41 #include "gt/intel_lrc.h" 42 #include "gt/intel_ring.h" 43 #include "gt/intel_gt_requests.h" 44 #include "gt/shmem_utils.h" 45 #include "gvt.h" 46 #include "i915_pvinfo.h" 47 #include "trace.h" 48 49 #include "gem/i915_gem_context.h" 50 #include "gem/i915_gem_pm.h" 51 #include "gt/intel_context.h" 52 53 #define INVALID_OP (~0U) 54 55 #define OP_LEN_MI 9 56 #define OP_LEN_2D 10 57 #define OP_LEN_3D_MEDIA 16 58 #define OP_LEN_MFX_VC 16 59 #define OP_LEN_VEBOX 16 60 61 #define CMD_TYPE(cmd) (((cmd) >> 29) & 7) 62 63 struct sub_op_bits { 64 int hi; 65 int low; 66 }; 67 struct decode_info { 68 const char *name; 69 int op_len; 70 int nr_sub_op; 71 const struct sub_op_bits *sub_op; 72 }; 73 74 #define MAX_CMD_BUDGET 0x7fffffff 75 #define MI_WAIT_FOR_PLANE_C_FLIP_PENDING (1<<15) 76 #define MI_WAIT_FOR_PLANE_B_FLIP_PENDING (1<<9) 77 #define MI_WAIT_FOR_PLANE_A_FLIP_PENDING (1<<1) 78 79 #define MI_WAIT_FOR_SPRITE_C_FLIP_PENDING (1<<20) 80 #define MI_WAIT_FOR_SPRITE_B_FLIP_PENDING (1<<10) 81 #define MI_WAIT_FOR_SPRITE_A_FLIP_PENDING (1<<2) 82 83 /* Render Command Map */ 84 85 /* MI_* command Opcode (28:23) */ 86 #define OP_MI_NOOP 0x0 87 #define OP_MI_SET_PREDICATE 0x1 /* HSW+ */ 88 #define OP_MI_USER_INTERRUPT 0x2 89 #define OP_MI_WAIT_FOR_EVENT 0x3 90 #define OP_MI_FLUSH 0x4 91 #define OP_MI_ARB_CHECK 0x5 92 #define OP_MI_RS_CONTROL 0x6 /* HSW+ */ 93 #define OP_MI_REPORT_HEAD 0x7 94 #define OP_MI_ARB_ON_OFF 0x8 95 #define OP_MI_URB_ATOMIC_ALLOC 0x9 /* HSW+ */ 96 #define OP_MI_BATCH_BUFFER_END 0xA 97 #define OP_MI_SUSPEND_FLUSH 0xB 98 #define OP_MI_PREDICATE 0xC /* IVB+ */ 99 #define OP_MI_TOPOLOGY_FILTER 0xD /* IVB+ */ 100 #define OP_MI_SET_APPID 0xE /* IVB+ */ 101 #define OP_MI_RS_CONTEXT 0xF /* HSW+ */ 102 #define OP_MI_LOAD_SCAN_LINES_INCL 0x12 /* HSW+ */ 103 #define OP_MI_DISPLAY_FLIP 0x14 104 #define OP_MI_SEMAPHORE_MBOX 0x16 105 #define OP_MI_SET_CONTEXT 0x18 106 #define OP_MI_MATH 0x1A 107 #define OP_MI_URB_CLEAR 0x19 108 #define OP_MI_SEMAPHORE_SIGNAL 0x1B /* BDW+ */ 109 #define OP_MI_SEMAPHORE_WAIT 0x1C /* BDW+ */ 110 111 #define OP_MI_STORE_DATA_IMM 0x20 112 #define OP_MI_STORE_DATA_INDEX 0x21 113 #define OP_MI_LOAD_REGISTER_IMM 0x22 114 #define OP_MI_UPDATE_GTT 0x23 115 #define OP_MI_STORE_REGISTER_MEM 0x24 116 #define OP_MI_FLUSH_DW 0x26 117 #define OP_MI_CLFLUSH 0x27 118 #define OP_MI_REPORT_PERF_COUNT 0x28 119 #define OP_MI_LOAD_REGISTER_MEM 0x29 /* HSW+ */ 120 #define OP_MI_LOAD_REGISTER_REG 0x2A /* HSW+ */ 121 #define OP_MI_RS_STORE_DATA_IMM 0x2B /* HSW+ */ 122 #define OP_MI_LOAD_URB_MEM 0x2C /* HSW+ */ 123 #define OP_MI_STORE_URM_MEM 0x2D /* HSW+ */ 124 #define OP_MI_2E 0x2E /* BDW+ */ 125 #define OP_MI_2F 0x2F /* BDW+ */ 126 #define OP_MI_BATCH_BUFFER_START 0x31 127 128 /* Bit definition for dword 0 */ 129 #define _CMDBIT_BB_START_IN_PPGTT (1UL << 8) 130 131 #define OP_MI_CONDITIONAL_BATCH_BUFFER_END 0x36 132 133 #define BATCH_BUFFER_ADDR_MASK ((1UL << 32) - (1U << 2)) 134 #define BATCH_BUFFER_ADDR_HIGH_MASK ((1UL << 16) - (1U)) 135 #define BATCH_BUFFER_ADR_SPACE_BIT(x) (((x) >> 8) & 1U) 136 #define BATCH_BUFFER_2ND_LEVEL_BIT(x) ((x) >> 22 & 1U) 137 138 /* 2D command: Opcode (28:22) */ 139 #define OP_2D(x) ((2<<7) | x) 140 141 #define OP_XY_SETUP_BLT OP_2D(0x1) 142 #define OP_XY_SETUP_CLIP_BLT OP_2D(0x3) 143 #define OP_XY_SETUP_MONO_PATTERN_SL_BLT OP_2D(0x11) 144 #define OP_XY_PIXEL_BLT OP_2D(0x24) 145 #define OP_XY_SCANLINES_BLT OP_2D(0x25) 146 #define OP_XY_TEXT_BLT OP_2D(0x26) 147 #define OP_XY_TEXT_IMMEDIATE_BLT OP_2D(0x31) 148 #define OP_XY_COLOR_BLT OP_2D(0x50) 149 #define OP_XY_PAT_BLT OP_2D(0x51) 150 #define OP_XY_MONO_PAT_BLT OP_2D(0x52) 151 #define OP_XY_SRC_COPY_BLT OP_2D(0x53) 152 #define OP_XY_MONO_SRC_COPY_BLT OP_2D(0x54) 153 #define OP_XY_FULL_BLT OP_2D(0x55) 154 #define OP_XY_FULL_MONO_SRC_BLT OP_2D(0x56) 155 #define OP_XY_FULL_MONO_PATTERN_BLT OP_2D(0x57) 156 #define OP_XY_FULL_MONO_PATTERN_MONO_SRC_BLT OP_2D(0x58) 157 #define OP_XY_MONO_PAT_FIXED_BLT OP_2D(0x59) 158 #define OP_XY_MONO_SRC_COPY_IMMEDIATE_BLT OP_2D(0x71) 159 #define OP_XY_PAT_BLT_IMMEDIATE OP_2D(0x72) 160 #define OP_XY_SRC_COPY_CHROMA_BLT OP_2D(0x73) 161 #define OP_XY_FULL_IMMEDIATE_PATTERN_BLT OP_2D(0x74) 162 #define OP_XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT OP_2D(0x75) 163 #define OP_XY_PAT_CHROMA_BLT OP_2D(0x76) 164 #define OP_XY_PAT_CHROMA_BLT_IMMEDIATE OP_2D(0x77) 165 166 /* 3D/Media Command: Pipeline Type(28:27) Opcode(26:24) Sub Opcode(23:16) */ 167 #define OP_3D_MEDIA(sub_type, opcode, sub_opcode) \ 168 ((3 << 13) | ((sub_type) << 11) | ((opcode) << 8) | (sub_opcode)) 169 170 #define OP_STATE_PREFETCH OP_3D_MEDIA(0x0, 0x0, 0x03) 171 172 #define OP_STATE_BASE_ADDRESS OP_3D_MEDIA(0x0, 0x1, 0x01) 173 #define OP_STATE_SIP OP_3D_MEDIA(0x0, 0x1, 0x02) 174 #define OP_3D_MEDIA_0_1_4 OP_3D_MEDIA(0x0, 0x1, 0x04) 175 #define OP_SWTESS_BASE_ADDRESS OP_3D_MEDIA(0x0, 0x1, 0x03) 176 177 #define OP_3DSTATE_VF_STATISTICS_GM45 OP_3D_MEDIA(0x1, 0x0, 0x0B) 178 179 #define OP_PIPELINE_SELECT OP_3D_MEDIA(0x1, 0x1, 0x04) 180 181 #define OP_MEDIA_VFE_STATE OP_3D_MEDIA(0x2, 0x0, 0x0) 182 #define OP_MEDIA_CURBE_LOAD OP_3D_MEDIA(0x2, 0x0, 0x1) 183 #define OP_MEDIA_INTERFACE_DESCRIPTOR_LOAD OP_3D_MEDIA(0x2, 0x0, 0x2) 184 #define OP_MEDIA_GATEWAY_STATE OP_3D_MEDIA(0x2, 0x0, 0x3) 185 #define OP_MEDIA_STATE_FLUSH OP_3D_MEDIA(0x2, 0x0, 0x4) 186 #define OP_MEDIA_POOL_STATE OP_3D_MEDIA(0x2, 0x0, 0x5) 187 188 #define OP_MEDIA_OBJECT OP_3D_MEDIA(0x2, 0x1, 0x0) 189 #define OP_MEDIA_OBJECT_PRT OP_3D_MEDIA(0x2, 0x1, 0x2) 190 #define OP_MEDIA_OBJECT_WALKER OP_3D_MEDIA(0x2, 0x1, 0x3) 191 #define OP_GPGPU_WALKER OP_3D_MEDIA(0x2, 0x1, 0x5) 192 193 #define OP_3DSTATE_CLEAR_PARAMS OP_3D_MEDIA(0x3, 0x0, 0x04) /* IVB+ */ 194 #define OP_3DSTATE_DEPTH_BUFFER OP_3D_MEDIA(0x3, 0x0, 0x05) /* IVB+ */ 195 #define OP_3DSTATE_STENCIL_BUFFER OP_3D_MEDIA(0x3, 0x0, 0x06) /* IVB+ */ 196 #define OP_3DSTATE_HIER_DEPTH_BUFFER OP_3D_MEDIA(0x3, 0x0, 0x07) /* IVB+ */ 197 #define OP_3DSTATE_VERTEX_BUFFERS OP_3D_MEDIA(0x3, 0x0, 0x08) 198 #define OP_3DSTATE_VERTEX_ELEMENTS OP_3D_MEDIA(0x3, 0x0, 0x09) 199 #define OP_3DSTATE_INDEX_BUFFER OP_3D_MEDIA(0x3, 0x0, 0x0A) 200 #define OP_3DSTATE_VF_STATISTICS OP_3D_MEDIA(0x3, 0x0, 0x0B) 201 #define OP_3DSTATE_VF OP_3D_MEDIA(0x3, 0x0, 0x0C) /* HSW+ */ 202 #define OP_3DSTATE_CC_STATE_POINTERS OP_3D_MEDIA(0x3, 0x0, 0x0E) 203 #define OP_3DSTATE_SCISSOR_STATE_POINTERS OP_3D_MEDIA(0x3, 0x0, 0x0F) 204 #define OP_3DSTATE_VS OP_3D_MEDIA(0x3, 0x0, 0x10) 205 #define OP_3DSTATE_GS OP_3D_MEDIA(0x3, 0x0, 0x11) 206 #define OP_3DSTATE_CLIP OP_3D_MEDIA(0x3, 0x0, 0x12) 207 #define OP_3DSTATE_SF OP_3D_MEDIA(0x3, 0x0, 0x13) 208 #define OP_3DSTATE_WM OP_3D_MEDIA(0x3, 0x0, 0x14) 209 #define OP_3DSTATE_CONSTANT_VS OP_3D_MEDIA(0x3, 0x0, 0x15) 210 #define OP_3DSTATE_CONSTANT_GS OP_3D_MEDIA(0x3, 0x0, 0x16) 211 #define OP_3DSTATE_CONSTANT_PS OP_3D_MEDIA(0x3, 0x0, 0x17) 212 #define OP_3DSTATE_SAMPLE_MASK OP_3D_MEDIA(0x3, 0x0, 0x18) 213 #define OP_3DSTATE_CONSTANT_HS OP_3D_MEDIA(0x3, 0x0, 0x19) /* IVB+ */ 214 #define OP_3DSTATE_CONSTANT_DS OP_3D_MEDIA(0x3, 0x0, 0x1A) /* IVB+ */ 215 #define OP_3DSTATE_HS OP_3D_MEDIA(0x3, 0x0, 0x1B) /* IVB+ */ 216 #define OP_3DSTATE_TE OP_3D_MEDIA(0x3, 0x0, 0x1C) /* IVB+ */ 217 #define OP_3DSTATE_DS OP_3D_MEDIA(0x3, 0x0, 0x1D) /* IVB+ */ 218 #define OP_3DSTATE_STREAMOUT OP_3D_MEDIA(0x3, 0x0, 0x1E) /* IVB+ */ 219 #define OP_3DSTATE_SBE OP_3D_MEDIA(0x3, 0x0, 0x1F) /* IVB+ */ 220 #define OP_3DSTATE_PS OP_3D_MEDIA(0x3, 0x0, 0x20) /* IVB+ */ 221 #define OP_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP OP_3D_MEDIA(0x3, 0x0, 0x21) /* IVB+ */ 222 #define OP_3DSTATE_VIEWPORT_STATE_POINTERS_CC OP_3D_MEDIA(0x3, 0x0, 0x23) /* IVB+ */ 223 #define OP_3DSTATE_BLEND_STATE_POINTERS OP_3D_MEDIA(0x3, 0x0, 0x24) /* IVB+ */ 224 #define OP_3DSTATE_DEPTH_STENCIL_STATE_POINTERS OP_3D_MEDIA(0x3, 0x0, 0x25) /* IVB+ */ 225 #define OP_3DSTATE_BINDING_TABLE_POINTERS_VS OP_3D_MEDIA(0x3, 0x0, 0x26) /* IVB+ */ 226 #define OP_3DSTATE_BINDING_TABLE_POINTERS_HS OP_3D_MEDIA(0x3, 0x0, 0x27) /* IVB+ */ 227 #define OP_3DSTATE_BINDING_TABLE_POINTERS_DS OP_3D_MEDIA(0x3, 0x0, 0x28) /* IVB+ */ 228 #define OP_3DSTATE_BINDING_TABLE_POINTERS_GS OP_3D_MEDIA(0x3, 0x0, 0x29) /* IVB+ */ 229 #define OP_3DSTATE_BINDING_TABLE_POINTERS_PS OP_3D_MEDIA(0x3, 0x0, 0x2A) /* IVB+ */ 230 #define OP_3DSTATE_SAMPLER_STATE_POINTERS_VS OP_3D_MEDIA(0x3, 0x0, 0x2B) /* IVB+ */ 231 #define OP_3DSTATE_SAMPLER_STATE_POINTERS_HS OP_3D_MEDIA(0x3, 0x0, 0x2C) /* IVB+ */ 232 #define OP_3DSTATE_SAMPLER_STATE_POINTERS_DS OP_3D_MEDIA(0x3, 0x0, 0x2D) /* IVB+ */ 233 #define OP_3DSTATE_SAMPLER_STATE_POINTERS_GS OP_3D_MEDIA(0x3, 0x0, 0x2E) /* IVB+ */ 234 #define OP_3DSTATE_SAMPLER_STATE_POINTERS_PS OP_3D_MEDIA(0x3, 0x0, 0x2F) /* IVB+ */ 235 #define OP_3DSTATE_URB_VS OP_3D_MEDIA(0x3, 0x0, 0x30) /* IVB+ */ 236 #define OP_3DSTATE_URB_HS OP_3D_MEDIA(0x3, 0x0, 0x31) /* IVB+ */ 237 #define OP_3DSTATE_URB_DS OP_3D_MEDIA(0x3, 0x0, 0x32) /* IVB+ */ 238 #define OP_3DSTATE_URB_GS OP_3D_MEDIA(0x3, 0x0, 0x33) /* IVB+ */ 239 #define OP_3DSTATE_GATHER_CONSTANT_VS OP_3D_MEDIA(0x3, 0x0, 0x34) /* HSW+ */ 240 #define OP_3DSTATE_GATHER_CONSTANT_GS OP_3D_MEDIA(0x3, 0x0, 0x35) /* HSW+ */ 241 #define OP_3DSTATE_GATHER_CONSTANT_HS OP_3D_MEDIA(0x3, 0x0, 0x36) /* HSW+ */ 242 #define OP_3DSTATE_GATHER_CONSTANT_DS OP_3D_MEDIA(0x3, 0x0, 0x37) /* HSW+ */ 243 #define OP_3DSTATE_GATHER_CONSTANT_PS OP_3D_MEDIA(0x3, 0x0, 0x38) /* HSW+ */ 244 #define OP_3DSTATE_DX9_CONSTANTF_VS OP_3D_MEDIA(0x3, 0x0, 0x39) /* HSW+ */ 245 #define OP_3DSTATE_DX9_CONSTANTF_PS OP_3D_MEDIA(0x3, 0x0, 0x3A) /* HSW+ */ 246 #define OP_3DSTATE_DX9_CONSTANTI_VS OP_3D_MEDIA(0x3, 0x0, 0x3B) /* HSW+ */ 247 #define OP_3DSTATE_DX9_CONSTANTI_PS OP_3D_MEDIA(0x3, 0x0, 0x3C) /* HSW+ */ 248 #define OP_3DSTATE_DX9_CONSTANTB_VS OP_3D_MEDIA(0x3, 0x0, 0x3D) /* HSW+ */ 249 #define OP_3DSTATE_DX9_CONSTANTB_PS OP_3D_MEDIA(0x3, 0x0, 0x3E) /* HSW+ */ 250 #define OP_3DSTATE_DX9_LOCAL_VALID_VS OP_3D_MEDIA(0x3, 0x0, 0x3F) /* HSW+ */ 251 #define OP_3DSTATE_DX9_LOCAL_VALID_PS OP_3D_MEDIA(0x3, 0x0, 0x40) /* HSW+ */ 252 #define OP_3DSTATE_DX9_GENERATE_ACTIVE_VS OP_3D_MEDIA(0x3, 0x0, 0x41) /* HSW+ */ 253 #define OP_3DSTATE_DX9_GENERATE_ACTIVE_PS OP_3D_MEDIA(0x3, 0x0, 0x42) /* HSW+ */ 254 #define OP_3DSTATE_BINDING_TABLE_EDIT_VS OP_3D_MEDIA(0x3, 0x0, 0x43) /* HSW+ */ 255 #define OP_3DSTATE_BINDING_TABLE_EDIT_GS OP_3D_MEDIA(0x3, 0x0, 0x44) /* HSW+ */ 256 #define OP_3DSTATE_BINDING_TABLE_EDIT_HS OP_3D_MEDIA(0x3, 0x0, 0x45) /* HSW+ */ 257 #define OP_3DSTATE_BINDING_TABLE_EDIT_DS OP_3D_MEDIA(0x3, 0x0, 0x46) /* HSW+ */ 258 #define OP_3DSTATE_BINDING_TABLE_EDIT_PS OP_3D_MEDIA(0x3, 0x0, 0x47) /* HSW+ */ 259 260 #define OP_3DSTATE_VF_INSTANCING OP_3D_MEDIA(0x3, 0x0, 0x49) /* BDW+ */ 261 #define OP_3DSTATE_VF_SGVS OP_3D_MEDIA(0x3, 0x0, 0x4A) /* BDW+ */ 262 #define OP_3DSTATE_VF_TOPOLOGY OP_3D_MEDIA(0x3, 0x0, 0x4B) /* BDW+ */ 263 #define OP_3DSTATE_WM_CHROMAKEY OP_3D_MEDIA(0x3, 0x0, 0x4C) /* BDW+ */ 264 #define OP_3DSTATE_PS_BLEND OP_3D_MEDIA(0x3, 0x0, 0x4D) /* BDW+ */ 265 #define OP_3DSTATE_WM_DEPTH_STENCIL OP_3D_MEDIA(0x3, 0x0, 0x4E) /* BDW+ */ 266 #define OP_3DSTATE_PS_EXTRA OP_3D_MEDIA(0x3, 0x0, 0x4F) /* BDW+ */ 267 #define OP_3DSTATE_RASTER OP_3D_MEDIA(0x3, 0x0, 0x50) /* BDW+ */ 268 #define OP_3DSTATE_SBE_SWIZ OP_3D_MEDIA(0x3, 0x0, 0x51) /* BDW+ */ 269 #define OP_3DSTATE_WM_HZ_OP OP_3D_MEDIA(0x3, 0x0, 0x52) /* BDW+ */ 270 #define OP_3DSTATE_COMPONENT_PACKING OP_3D_MEDIA(0x3, 0x0, 0x55) /* SKL+ */ 271 272 #define OP_3DSTATE_DRAWING_RECTANGLE OP_3D_MEDIA(0x3, 0x1, 0x00) 273 #define OP_3DSTATE_SAMPLER_PALETTE_LOAD0 OP_3D_MEDIA(0x3, 0x1, 0x02) 274 #define OP_3DSTATE_CHROMA_KEY OP_3D_MEDIA(0x3, 0x1, 0x04) 275 #define OP_SNB_3DSTATE_DEPTH_BUFFER OP_3D_MEDIA(0x3, 0x1, 0x05) 276 #define OP_3DSTATE_POLY_STIPPLE_OFFSET OP_3D_MEDIA(0x3, 0x1, 0x06) 277 #define OP_3DSTATE_POLY_STIPPLE_PATTERN OP_3D_MEDIA(0x3, 0x1, 0x07) 278 #define OP_3DSTATE_LINE_STIPPLE OP_3D_MEDIA(0x3, 0x1, 0x08) 279 #define OP_3DSTATE_AA_LINE_PARAMS OP_3D_MEDIA(0x3, 0x1, 0x0A) 280 #define OP_3DSTATE_GS_SVB_INDEX OP_3D_MEDIA(0x3, 0x1, 0x0B) 281 #define OP_3DSTATE_SAMPLER_PALETTE_LOAD1 OP_3D_MEDIA(0x3, 0x1, 0x0C) 282 #define OP_3DSTATE_MULTISAMPLE_BDW OP_3D_MEDIA(0x3, 0x0, 0x0D) 283 #define OP_SNB_3DSTATE_STENCIL_BUFFER OP_3D_MEDIA(0x3, 0x1, 0x0E) 284 #define OP_SNB_3DSTATE_HIER_DEPTH_BUFFER OP_3D_MEDIA(0x3, 0x1, 0x0F) 285 #define OP_SNB_3DSTATE_CLEAR_PARAMS OP_3D_MEDIA(0x3, 0x1, 0x10) 286 #define OP_3DSTATE_MONOFILTER_SIZE OP_3D_MEDIA(0x3, 0x1, 0x11) 287 #define OP_3DSTATE_PUSH_CONSTANT_ALLOC_VS OP_3D_MEDIA(0x3, 0x1, 0x12) /* IVB+ */ 288 #define OP_3DSTATE_PUSH_CONSTANT_ALLOC_HS OP_3D_MEDIA(0x3, 0x1, 0x13) /* IVB+ */ 289 #define OP_3DSTATE_PUSH_CONSTANT_ALLOC_DS OP_3D_MEDIA(0x3, 0x1, 0x14) /* IVB+ */ 290 #define OP_3DSTATE_PUSH_CONSTANT_ALLOC_GS OP_3D_MEDIA(0x3, 0x1, 0x15) /* IVB+ */ 291 #define OP_3DSTATE_PUSH_CONSTANT_ALLOC_PS OP_3D_MEDIA(0x3, 0x1, 0x16) /* IVB+ */ 292 #define OP_3DSTATE_SO_DECL_LIST OP_3D_MEDIA(0x3, 0x1, 0x17) 293 #define OP_3DSTATE_SO_BUFFER OP_3D_MEDIA(0x3, 0x1, 0x18) 294 #define OP_3DSTATE_BINDING_TABLE_POOL_ALLOC OP_3D_MEDIA(0x3, 0x1, 0x19) /* HSW+ */ 295 #define OP_3DSTATE_GATHER_POOL_ALLOC OP_3D_MEDIA(0x3, 0x1, 0x1A) /* HSW+ */ 296 #define OP_3DSTATE_DX9_CONSTANT_BUFFER_POOL_ALLOC OP_3D_MEDIA(0x3, 0x1, 0x1B) /* HSW+ */ 297 #define OP_3DSTATE_SAMPLE_PATTERN OP_3D_MEDIA(0x3, 0x1, 0x1C) 298 #define OP_PIPE_CONTROL OP_3D_MEDIA(0x3, 0x2, 0x00) 299 #define OP_3DPRIMITIVE OP_3D_MEDIA(0x3, 0x3, 0x00) 300 301 /* VCCP Command Parser */ 302 303 /* 304 * Below MFX and VBE cmd definition is from vaapi intel driver project (BSD License) 305 * git://anongit.freedesktop.org/vaapi/intel-driver 306 * src/i965_defines.h 307 * 308 */ 309 310 #define OP_MFX(pipeline, op, sub_opa, sub_opb) \ 311 (3 << 13 | \ 312 (pipeline) << 11 | \ 313 (op) << 8 | \ 314 (sub_opa) << 5 | \ 315 (sub_opb)) 316 317 #define OP_MFX_PIPE_MODE_SELECT OP_MFX(2, 0, 0, 0) /* ALL */ 318 #define OP_MFX_SURFACE_STATE OP_MFX(2, 0, 0, 1) /* ALL */ 319 #define OP_MFX_PIPE_BUF_ADDR_STATE OP_MFX(2, 0, 0, 2) /* ALL */ 320 #define OP_MFX_IND_OBJ_BASE_ADDR_STATE OP_MFX(2, 0, 0, 3) /* ALL */ 321 #define OP_MFX_BSP_BUF_BASE_ADDR_STATE OP_MFX(2, 0, 0, 4) /* ALL */ 322 #define OP_2_0_0_5 OP_MFX(2, 0, 0, 5) /* ALL */ 323 #define OP_MFX_STATE_POINTER OP_MFX(2, 0, 0, 6) /* ALL */ 324 #define OP_MFX_QM_STATE OP_MFX(2, 0, 0, 7) /* IVB+ */ 325 #define OP_MFX_FQM_STATE OP_MFX(2, 0, 0, 8) /* IVB+ */ 326 #define OP_MFX_PAK_INSERT_OBJECT OP_MFX(2, 0, 2, 8) /* IVB+ */ 327 #define OP_MFX_STITCH_OBJECT OP_MFX(2, 0, 2, 0xA) /* IVB+ */ 328 329 #define OP_MFD_IT_OBJECT OP_MFX(2, 0, 1, 9) /* ALL */ 330 331 #define OP_MFX_WAIT OP_MFX(1, 0, 0, 0) /* IVB+ */ 332 #define OP_MFX_AVC_IMG_STATE OP_MFX(2, 1, 0, 0) /* ALL */ 333 #define OP_MFX_AVC_QM_STATE OP_MFX(2, 1, 0, 1) /* ALL */ 334 #define OP_MFX_AVC_DIRECTMODE_STATE OP_MFX(2, 1, 0, 2) /* ALL */ 335 #define OP_MFX_AVC_SLICE_STATE OP_MFX(2, 1, 0, 3) /* ALL */ 336 #define OP_MFX_AVC_REF_IDX_STATE OP_MFX(2, 1, 0, 4) /* ALL */ 337 #define OP_MFX_AVC_WEIGHTOFFSET_STATE OP_MFX(2, 1, 0, 5) /* ALL */ 338 #define OP_MFD_AVC_PICID_STATE OP_MFX(2, 1, 1, 5) /* HSW+ */ 339 #define OP_MFD_AVC_DPB_STATE OP_MFX(2, 1, 1, 6) /* IVB+ */ 340 #define OP_MFD_AVC_SLICEADDR OP_MFX(2, 1, 1, 7) /* IVB+ */ 341 #define OP_MFD_AVC_BSD_OBJECT OP_MFX(2, 1, 1, 8) /* ALL */ 342 #define OP_MFC_AVC_PAK_OBJECT OP_MFX(2, 1, 2, 9) /* ALL */ 343 344 #define OP_MFX_VC1_PRED_PIPE_STATE OP_MFX(2, 2, 0, 1) /* ALL */ 345 #define OP_MFX_VC1_DIRECTMODE_STATE OP_MFX(2, 2, 0, 2) /* ALL */ 346 #define OP_MFD_VC1_SHORT_PIC_STATE OP_MFX(2, 2, 1, 0) /* IVB+ */ 347 #define OP_MFD_VC1_LONG_PIC_STATE OP_MFX(2, 2, 1, 1) /* IVB+ */ 348 #define OP_MFD_VC1_BSD_OBJECT OP_MFX(2, 2, 1, 8) /* ALL */ 349 350 #define OP_MFX_MPEG2_PIC_STATE OP_MFX(2, 3, 0, 0) /* ALL */ 351 #define OP_MFX_MPEG2_QM_STATE OP_MFX(2, 3, 0, 1) /* ALL */ 352 #define OP_MFD_MPEG2_BSD_OBJECT OP_MFX(2, 3, 1, 8) /* ALL */ 353 #define OP_MFC_MPEG2_SLICEGROUP_STATE OP_MFX(2, 3, 2, 3) /* ALL */ 354 #define OP_MFC_MPEG2_PAK_OBJECT OP_MFX(2, 3, 2, 9) /* ALL */ 355 356 #define OP_MFX_2_6_0_0 OP_MFX(2, 6, 0, 0) /* IVB+ */ 357 #define OP_MFX_2_6_0_8 OP_MFX(2, 6, 0, 8) /* IVB+ */ 358 #define OP_MFX_2_6_0_9 OP_MFX(2, 6, 0, 9) /* IVB+ */ 359 360 #define OP_MFX_JPEG_PIC_STATE OP_MFX(2, 7, 0, 0) 361 #define OP_MFX_JPEG_HUFF_TABLE_STATE OP_MFX(2, 7, 0, 2) 362 #define OP_MFD_JPEG_BSD_OBJECT OP_MFX(2, 7, 1, 8) 363 364 #define OP_VEB(pipeline, op, sub_opa, sub_opb) \ 365 (3 << 13 | \ 366 (pipeline) << 11 | \ 367 (op) << 8 | \ 368 (sub_opa) << 5 | \ 369 (sub_opb)) 370 371 #define OP_VEB_SURFACE_STATE OP_VEB(2, 4, 0, 0) 372 #define OP_VEB_STATE OP_VEB(2, 4, 0, 2) 373 #define OP_VEB_DNDI_IECP_STATE OP_VEB(2, 4, 0, 3) 374 375 struct parser_exec_state; 376 377 typedef int (*parser_cmd_handler)(struct parser_exec_state *s); 378 379 #define GVT_CMD_HASH_BITS 7 380 381 /* which DWords need address fix */ 382 #define ADDR_FIX_1(x1) (1 << (x1)) 383 #define ADDR_FIX_2(x1, x2) (ADDR_FIX_1(x1) | ADDR_FIX_1(x2)) 384 #define ADDR_FIX_3(x1, x2, x3) (ADDR_FIX_1(x1) | ADDR_FIX_2(x2, x3)) 385 #define ADDR_FIX_4(x1, x2, x3, x4) (ADDR_FIX_1(x1) | ADDR_FIX_3(x2, x3, x4)) 386 #define ADDR_FIX_5(x1, x2, x3, x4, x5) (ADDR_FIX_1(x1) | ADDR_FIX_4(x2, x3, x4, x5)) 387 388 #define DWORD_FIELD(dword, end, start) \ 389 FIELD_GET(GENMASK(end, start), cmd_val(s, dword)) 390 391 #define OP_LENGTH_BIAS 2 392 #define CMD_LEN(value) (value + OP_LENGTH_BIAS) 393 394 static int gvt_check_valid_cmd_length(int len, int valid_len) 395 { 396 if (valid_len != len) { 397 gvt_err("len is not valid: len=%u valid_len=%u\n", 398 len, valid_len); 399 return -EFAULT; 400 } 401 return 0; 402 } 403 404 struct cmd_info { 405 const char *name; 406 u32 opcode; 407 408 #define F_LEN_MASK 3U 409 #define F_LEN_CONST 1U 410 #define F_LEN_VAR 0U 411 /* value is const although LEN maybe variable */ 412 #define F_LEN_VAR_FIXED (1<<1) 413 414 /* 415 * command has its own ip advance logic 416 * e.g. MI_BATCH_START, MI_BATCH_END 417 */ 418 #define F_IP_ADVANCE_CUSTOM (1<<2) 419 u32 flag; 420 421 #define R_RCS BIT(RCS0) 422 #define R_VCS1 BIT(VCS0) 423 #define R_VCS2 BIT(VCS1) 424 #define R_VCS (R_VCS1 | R_VCS2) 425 #define R_BCS BIT(BCS0) 426 #define R_VECS BIT(VECS0) 427 #define R_ALL (R_RCS | R_VCS | R_BCS | R_VECS) 428 /* rings that support this cmd: BLT/RCS/VCS/VECS */ 429 u16 rings; 430 431 /* devices that support this cmd: SNB/IVB/HSW/... */ 432 u16 devices; 433 434 /* which DWords are address that need fix up. 435 * bit 0 means a 32-bit non address operand in command 436 * bit 1 means address operand, which could be 32-bit 437 * or 64-bit depending on different architectures.( 438 * defined by "gmadr_bytes_in_cmd" in intel_gvt. 439 * No matter the address length, each address only takes 440 * one bit in the bitmap. 441 */ 442 u16 addr_bitmap; 443 444 /* flag == F_LEN_CONST : command length 445 * flag == F_LEN_VAR : length bias bits 446 * Note: length is in DWord 447 */ 448 u32 len; 449 450 parser_cmd_handler handler; 451 452 /* valid length in DWord */ 453 u32 valid_len; 454 }; 455 456 struct cmd_entry { 457 struct hlist_node hlist; 458 const struct cmd_info *info; 459 }; 460 461 enum { 462 RING_BUFFER_INSTRUCTION, 463 BATCH_BUFFER_INSTRUCTION, 464 BATCH_BUFFER_2ND_LEVEL, 465 RING_BUFFER_CTX, 466 }; 467 468 enum { 469 GTT_BUFFER, 470 PPGTT_BUFFER 471 }; 472 473 struct parser_exec_state { 474 struct intel_vgpu *vgpu; 475 const struct intel_engine_cs *engine; 476 477 int buf_type; 478 479 /* batch buffer address type */ 480 int buf_addr_type; 481 482 /* graphics memory address of ring buffer start */ 483 unsigned long ring_start; 484 unsigned long ring_size; 485 unsigned long ring_head; 486 unsigned long ring_tail; 487 488 /* instruction graphics memory address */ 489 unsigned long ip_gma; 490 491 /* mapped va of the instr_gma */ 492 void *ip_va; 493 void *rb_va; 494 495 void *ret_bb_va; 496 /* next instruction when return from batch buffer to ring buffer */ 497 unsigned long ret_ip_gma_ring; 498 499 /* next instruction when return from 2nd batch buffer to batch buffer */ 500 unsigned long ret_ip_gma_bb; 501 502 /* batch buffer address type (GTT or PPGTT) 503 * used when ret from 2nd level batch buffer 504 */ 505 int saved_buf_addr_type; 506 bool is_ctx_wa; 507 bool is_init_ctx; 508 509 const struct cmd_info *info; 510 511 struct intel_vgpu_workload *workload; 512 }; 513 514 #define gmadr_dw_number(s) \ 515 (s->vgpu->gvt->device_info.gmadr_bytes_in_cmd >> 2) 516 517 static unsigned long bypass_scan_mask = 0; 518 519 /* ring ALL, type = 0 */ 520 static const struct sub_op_bits sub_op_mi[] = { 521 {31, 29}, 522 {28, 23}, 523 }; 524 525 static const struct decode_info decode_info_mi = { 526 "MI", 527 OP_LEN_MI, 528 ARRAY_SIZE(sub_op_mi), 529 sub_op_mi, 530 }; 531 532 /* ring RCS, command type 2 */ 533 static const struct sub_op_bits sub_op_2d[] = { 534 {31, 29}, 535 {28, 22}, 536 }; 537 538 static const struct decode_info decode_info_2d = { 539 "2D", 540 OP_LEN_2D, 541 ARRAY_SIZE(sub_op_2d), 542 sub_op_2d, 543 }; 544 545 /* ring RCS, command type 3 */ 546 static const struct sub_op_bits sub_op_3d_media[] = { 547 {31, 29}, 548 {28, 27}, 549 {26, 24}, 550 {23, 16}, 551 }; 552 553 static const struct decode_info decode_info_3d_media = { 554 "3D_Media", 555 OP_LEN_3D_MEDIA, 556 ARRAY_SIZE(sub_op_3d_media), 557 sub_op_3d_media, 558 }; 559 560 /* ring VCS, command type 3 */ 561 static const struct sub_op_bits sub_op_mfx_vc[] = { 562 {31, 29}, 563 {28, 27}, 564 {26, 24}, 565 {23, 21}, 566 {20, 16}, 567 }; 568 569 static const struct decode_info decode_info_mfx_vc = { 570 "MFX_VC", 571 OP_LEN_MFX_VC, 572 ARRAY_SIZE(sub_op_mfx_vc), 573 sub_op_mfx_vc, 574 }; 575 576 /* ring VECS, command type 3 */ 577 static const struct sub_op_bits sub_op_vebox[] = { 578 {31, 29}, 579 {28, 27}, 580 {26, 24}, 581 {23, 21}, 582 {20, 16}, 583 }; 584 585 static const struct decode_info decode_info_vebox = { 586 "VEBOX", 587 OP_LEN_VEBOX, 588 ARRAY_SIZE(sub_op_vebox), 589 sub_op_vebox, 590 }; 591 592 static const struct decode_info *ring_decode_info[I915_NUM_ENGINES][8] = { 593 [RCS0] = { 594 &decode_info_mi, 595 NULL, 596 NULL, 597 &decode_info_3d_media, 598 NULL, 599 NULL, 600 NULL, 601 NULL, 602 }, 603 604 [VCS0] = { 605 &decode_info_mi, 606 NULL, 607 NULL, 608 &decode_info_mfx_vc, 609 NULL, 610 NULL, 611 NULL, 612 NULL, 613 }, 614 615 [BCS0] = { 616 &decode_info_mi, 617 NULL, 618 &decode_info_2d, 619 NULL, 620 NULL, 621 NULL, 622 NULL, 623 NULL, 624 }, 625 626 [VECS0] = { 627 &decode_info_mi, 628 NULL, 629 NULL, 630 &decode_info_vebox, 631 NULL, 632 NULL, 633 NULL, 634 NULL, 635 }, 636 637 [VCS1] = { 638 &decode_info_mi, 639 NULL, 640 NULL, 641 &decode_info_mfx_vc, 642 NULL, 643 NULL, 644 NULL, 645 NULL, 646 }, 647 }; 648 649 static inline u32 get_opcode(u32 cmd, const struct intel_engine_cs *engine) 650 { 651 const struct decode_info *d_info; 652 653 d_info = ring_decode_info[engine->id][CMD_TYPE(cmd)]; 654 if (d_info == NULL) 655 return INVALID_OP; 656 657 return cmd >> (32 - d_info->op_len); 658 } 659 660 static inline const struct cmd_info * 661 find_cmd_entry(struct intel_gvt *gvt, unsigned int opcode, 662 const struct intel_engine_cs *engine) 663 { 664 struct cmd_entry *e; 665 666 hash_for_each_possible(gvt->cmd_table, e, hlist, opcode) { 667 if (opcode == e->info->opcode && 668 e->info->rings & engine->mask) 669 return e->info; 670 } 671 return NULL; 672 } 673 674 static inline const struct cmd_info * 675 get_cmd_info(struct intel_gvt *gvt, u32 cmd, 676 const struct intel_engine_cs *engine) 677 { 678 u32 opcode; 679 680 opcode = get_opcode(cmd, engine); 681 if (opcode == INVALID_OP) 682 return NULL; 683 684 return find_cmd_entry(gvt, opcode, engine); 685 } 686 687 static inline u32 sub_op_val(u32 cmd, u32 hi, u32 low) 688 { 689 return (cmd >> low) & ((1U << (hi - low + 1)) - 1); 690 } 691 692 static inline void print_opcode(u32 cmd, const struct intel_engine_cs *engine) 693 { 694 const struct decode_info *d_info; 695 int i; 696 697 d_info = ring_decode_info[engine->id][CMD_TYPE(cmd)]; 698 if (d_info == NULL) 699 return; 700 701 gvt_dbg_cmd("opcode=0x%x %s sub_ops:", 702 cmd >> (32 - d_info->op_len), d_info->name); 703 704 for (i = 0; i < d_info->nr_sub_op; i++) 705 pr_err("0x%x ", sub_op_val(cmd, d_info->sub_op[i].hi, 706 d_info->sub_op[i].low)); 707 708 pr_err("\n"); 709 } 710 711 static inline u32 *cmd_ptr(struct parser_exec_state *s, int index) 712 { 713 return s->ip_va + (index << 2); 714 } 715 716 static inline u32 cmd_val(struct parser_exec_state *s, int index) 717 { 718 return *cmd_ptr(s, index); 719 } 720 721 static inline bool is_init_ctx(struct parser_exec_state *s) 722 { 723 return (s->buf_type == RING_BUFFER_CTX && s->is_init_ctx); 724 } 725 726 static void parser_exec_state_dump(struct parser_exec_state *s) 727 { 728 int cnt = 0; 729 int i; 730 731 gvt_dbg_cmd(" vgpu%d RING%s: ring_start(%08lx) ring_end(%08lx)" 732 " ring_head(%08lx) ring_tail(%08lx)\n", 733 s->vgpu->id, s->engine->name, 734 s->ring_start, s->ring_start + s->ring_size, 735 s->ring_head, s->ring_tail); 736 737 gvt_dbg_cmd(" %s %s ip_gma(%08lx) ", 738 s->buf_type == RING_BUFFER_INSTRUCTION ? 739 "RING_BUFFER" : ((s->buf_type == RING_BUFFER_CTX) ? 740 "CTX_BUFFER" : "BATCH_BUFFER"), 741 s->buf_addr_type == GTT_BUFFER ? 742 "GTT" : "PPGTT", s->ip_gma); 743 744 if (s->ip_va == NULL) { 745 gvt_dbg_cmd(" ip_va(NULL)"); 746 return; 747 } 748 749 gvt_dbg_cmd(" ip_va=%p: %08x %08x %08x %08x\n", 750 s->ip_va, cmd_val(s, 0), cmd_val(s, 1), 751 cmd_val(s, 2), cmd_val(s, 3)); 752 753 print_opcode(cmd_val(s, 0), s->engine); 754 755 s->ip_va = (u32 *)((((u64)s->ip_va) >> 12) << 12); 756 757 while (cnt < 1024) { 758 gvt_dbg_cmd("ip_va=%p: ", s->ip_va); 759 for (i = 0; i < 8; i++) 760 gvt_dbg_cmd("%08x ", cmd_val(s, i)); 761 gvt_dbg_cmd("\n"); 762 763 s->ip_va += 8 * sizeof(u32); 764 cnt += 8; 765 } 766 } 767 768 static inline void update_ip_va(struct parser_exec_state *s) 769 { 770 unsigned long len = 0; 771 772 if (WARN_ON(s->ring_head == s->ring_tail)) 773 return; 774 775 if (s->buf_type == RING_BUFFER_INSTRUCTION || 776 s->buf_type == RING_BUFFER_CTX) { 777 unsigned long ring_top = s->ring_start + s->ring_size; 778 779 if (s->ring_head > s->ring_tail) { 780 if (s->ip_gma >= s->ring_head && s->ip_gma < ring_top) 781 len = (s->ip_gma - s->ring_head); 782 else if (s->ip_gma >= s->ring_start && 783 s->ip_gma <= s->ring_tail) 784 len = (ring_top - s->ring_head) + 785 (s->ip_gma - s->ring_start); 786 } else 787 len = (s->ip_gma - s->ring_head); 788 789 s->ip_va = s->rb_va + len; 790 } else {/* shadow batch buffer */ 791 s->ip_va = s->ret_bb_va; 792 } 793 } 794 795 static inline int ip_gma_set(struct parser_exec_state *s, 796 unsigned long ip_gma) 797 { 798 WARN_ON(!IS_ALIGNED(ip_gma, 4)); 799 800 s->ip_gma = ip_gma; 801 update_ip_va(s); 802 return 0; 803 } 804 805 static inline int ip_gma_advance(struct parser_exec_state *s, 806 unsigned int dw_len) 807 { 808 s->ip_gma += (dw_len << 2); 809 810 if (s->buf_type == RING_BUFFER_INSTRUCTION) { 811 if (s->ip_gma >= s->ring_start + s->ring_size) 812 s->ip_gma -= s->ring_size; 813 update_ip_va(s); 814 } else { 815 s->ip_va += (dw_len << 2); 816 } 817 818 return 0; 819 } 820 821 static inline int get_cmd_length(const struct cmd_info *info, u32 cmd) 822 { 823 if ((info->flag & F_LEN_MASK) == F_LEN_CONST) 824 return info->len; 825 else 826 return (cmd & ((1U << info->len) - 1)) + 2; 827 return 0; 828 } 829 830 static inline int cmd_length(struct parser_exec_state *s) 831 { 832 return get_cmd_length(s->info, cmd_val(s, 0)); 833 } 834 835 /* do not remove this, some platform may need clflush here */ 836 #define patch_value(s, addr, val) do { \ 837 *addr = val; \ 838 } while (0) 839 840 static inline bool is_mocs_mmio(unsigned int offset) 841 { 842 return ((offset >= 0xc800) && (offset <= 0xcff8)) || 843 ((offset >= 0xb020) && (offset <= 0xb0a0)); 844 } 845 846 static int is_cmd_update_pdps(unsigned int offset, 847 struct parser_exec_state *s) 848 { 849 u32 base = s->workload->engine->mmio_base; 850 return i915_mmio_reg_equal(_MMIO(offset), GEN8_RING_PDP_UDW(base, 0)); 851 } 852 853 static int cmd_pdp_mmio_update_handler(struct parser_exec_state *s, 854 unsigned int offset, unsigned int index) 855 { 856 struct intel_vgpu *vgpu = s->vgpu; 857 struct intel_vgpu_mm *shadow_mm = s->workload->shadow_mm; 858 struct intel_vgpu_mm *mm; 859 u64 pdps[GEN8_3LVL_PDPES]; 860 861 if (shadow_mm->ppgtt_mm.root_entry_type == 862 GTT_TYPE_PPGTT_ROOT_L4_ENTRY) { 863 pdps[0] = (u64)cmd_val(s, 2) << 32; 864 pdps[0] |= cmd_val(s, 4); 865 866 mm = intel_vgpu_find_ppgtt_mm(vgpu, pdps); 867 if (!mm) { 868 gvt_vgpu_err("failed to get the 4-level shadow vm\n"); 869 return -EINVAL; 870 } 871 intel_vgpu_mm_get(mm); 872 list_add_tail(&mm->ppgtt_mm.link, 873 &s->workload->lri_shadow_mm); 874 *cmd_ptr(s, 2) = upper_32_bits(mm->ppgtt_mm.shadow_pdps[0]); 875 *cmd_ptr(s, 4) = lower_32_bits(mm->ppgtt_mm.shadow_pdps[0]); 876 } else { 877 /* Currently all guests use PML4 table and now can't 878 * have a guest with 3-level table but uses LRI for 879 * PPGTT update. So this is simply un-testable. */ 880 GEM_BUG_ON(1); 881 gvt_vgpu_err("invalid shared shadow vm type\n"); 882 return -EINVAL; 883 } 884 return 0; 885 } 886 887 static int cmd_reg_handler(struct parser_exec_state *s, 888 unsigned int offset, unsigned int index, char *cmd) 889 { 890 struct intel_vgpu *vgpu = s->vgpu; 891 struct intel_gvt *gvt = vgpu->gvt; 892 u32 ctx_sr_ctl; 893 u32 *vreg, vreg_old; 894 895 if (offset + 4 > gvt->device_info.mmio_size) { 896 gvt_vgpu_err("%s access to (%x) outside of MMIO range\n", 897 cmd, offset); 898 return -EFAULT; 899 } 900 901 if (is_init_ctx(s)) { 902 struct intel_gvt_mmio_info *mmio_info; 903 904 intel_gvt_mmio_set_cmd_accessible(gvt, offset); 905 mmio_info = intel_gvt_find_mmio_info(gvt, offset); 906 if (mmio_info && mmio_info->write) 907 intel_gvt_mmio_set_cmd_write_patch(gvt, offset); 908 return 0; 909 } 910 911 if (!intel_gvt_mmio_is_cmd_accessible(gvt, offset)) { 912 gvt_vgpu_err("%s access to non-render register (%x)\n", 913 cmd, offset); 914 return -EBADRQC; 915 } 916 917 if (!strncmp(cmd, "srm", 3) || 918 !strncmp(cmd, "lrm", 3)) { 919 if (offset != i915_mmio_reg_offset(GEN8_L3SQCREG4) && 920 offset != 0x21f0) { 921 gvt_vgpu_err("%s access to register (%x)\n", 922 cmd, offset); 923 return -EPERM; 924 } else 925 return 0; 926 } 927 928 if (!strncmp(cmd, "lrr-src", 7) || 929 !strncmp(cmd, "lrr-dst", 7)) { 930 gvt_vgpu_err("not allowed cmd %s\n", cmd); 931 return -EPERM; 932 } 933 934 if (!strncmp(cmd, "pipe_ctrl", 9)) { 935 /* TODO: add LRI POST logic here */ 936 return 0; 937 } 938 939 if (strncmp(cmd, "lri", 3)) 940 return -EPERM; 941 942 /* below are all lri handlers */ 943 vreg = &vgpu_vreg(s->vgpu, offset); 944 if (!intel_gvt_mmio_is_cmd_accessible(gvt, offset)) { 945 gvt_vgpu_err("%s access to non-render register (%x)\n", 946 cmd, offset); 947 return -EBADRQC; 948 } 949 950 if (is_cmd_update_pdps(offset, s) && 951 cmd_pdp_mmio_update_handler(s, offset, index)) 952 return -EINVAL; 953 954 if (offset == i915_mmio_reg_offset(DERRMR) || 955 offset == i915_mmio_reg_offset(FORCEWAKE_MT)) { 956 /* Writing to HW VGT_PVINFO_PAGE offset will be discarded */ 957 patch_value(s, cmd_ptr(s, index), VGT_PVINFO_PAGE); 958 } 959 960 if (is_mocs_mmio(offset)) 961 *vreg = cmd_val(s, index + 1); 962 963 vreg_old = *vreg; 964 965 if (intel_gvt_mmio_is_cmd_write_patch(gvt, offset)) { 966 u32 cmdval_new, cmdval; 967 struct intel_gvt_mmio_info *mmio_info; 968 969 cmdval = cmd_val(s, index + 1); 970 971 mmio_info = intel_gvt_find_mmio_info(gvt, offset); 972 if (!mmio_info) { 973 cmdval_new = cmdval; 974 } else { 975 u64 ro_mask = mmio_info->ro_mask; 976 int ret; 977 978 if (likely(!ro_mask)) 979 ret = mmio_info->write(s->vgpu, offset, 980 &cmdval, 4); 981 else { 982 gvt_vgpu_err("try to write RO reg %x\n", 983 offset); 984 ret = -EBADRQC; 985 } 986 if (ret) 987 return ret; 988 cmdval_new = *vreg; 989 } 990 if (cmdval_new != cmdval) 991 patch_value(s, cmd_ptr(s, index+1), cmdval_new); 992 } 993 994 /* only patch cmd. restore vreg value if changed in mmio write handler*/ 995 *vreg = vreg_old; 996 997 /* TODO 998 * In order to let workload with inhibit context to generate 999 * correct image data into memory, vregs values will be loaded to 1000 * hw via LRIs in the workload with inhibit context. But as 1001 * indirect context is loaded prior to LRIs in workload, we don't 1002 * want reg values specified in indirect context overwritten by 1003 * LRIs in workloads. So, when scanning an indirect context, we 1004 * update reg values in it into vregs, so LRIs in workload with 1005 * inhibit context will restore with correct values 1006 */ 1007 if (IS_GEN(s->engine->i915, 9) && 1008 intel_gvt_mmio_is_sr_in_ctx(gvt, offset) && 1009 !strncmp(cmd, "lri", 3)) { 1010 intel_gvt_hypervisor_read_gpa(s->vgpu, 1011 s->workload->ring_context_gpa + 12, &ctx_sr_ctl, 4); 1012 /* check inhibit context */ 1013 if (ctx_sr_ctl & 1) { 1014 u32 data = cmd_val(s, index + 1); 1015 1016 if (intel_gvt_mmio_has_mode_mask(s->vgpu->gvt, offset)) 1017 intel_vgpu_mask_mmio_write(vgpu, 1018 offset, &data, 4); 1019 else 1020 vgpu_vreg(vgpu, offset) = data; 1021 } 1022 } 1023 1024 return 0; 1025 } 1026 1027 #define cmd_reg(s, i) \ 1028 (cmd_val(s, i) & GENMASK(22, 2)) 1029 1030 #define cmd_reg_inhibit(s, i) \ 1031 (cmd_val(s, i) & GENMASK(22, 18)) 1032 1033 #define cmd_gma(s, i) \ 1034 (cmd_val(s, i) & GENMASK(31, 2)) 1035 1036 #define cmd_gma_hi(s, i) \ 1037 (cmd_val(s, i) & GENMASK(15, 0)) 1038 1039 static int cmd_handler_lri(struct parser_exec_state *s) 1040 { 1041 int i, ret = 0; 1042 int cmd_len = cmd_length(s); 1043 1044 for (i = 1; i < cmd_len; i += 2) { 1045 if (IS_BROADWELL(s->engine->i915) && s->engine->id != RCS0) { 1046 if (s->engine->id == BCS0 && 1047 cmd_reg(s, i) == i915_mmio_reg_offset(DERRMR)) 1048 ret |= 0; 1049 else 1050 ret |= cmd_reg_inhibit(s, i) ? -EBADRQC : 0; 1051 } 1052 if (ret) 1053 break; 1054 ret |= cmd_reg_handler(s, cmd_reg(s, i), i, "lri"); 1055 if (ret) 1056 break; 1057 } 1058 return ret; 1059 } 1060 1061 static int cmd_handler_lrr(struct parser_exec_state *s) 1062 { 1063 int i, ret = 0; 1064 int cmd_len = cmd_length(s); 1065 1066 for (i = 1; i < cmd_len; i += 2) { 1067 if (IS_BROADWELL(s->engine->i915)) 1068 ret |= ((cmd_reg_inhibit(s, i) || 1069 (cmd_reg_inhibit(s, i + 1)))) ? 1070 -EBADRQC : 0; 1071 if (ret) 1072 break; 1073 ret |= cmd_reg_handler(s, cmd_reg(s, i), i, "lrr-src"); 1074 if (ret) 1075 break; 1076 ret |= cmd_reg_handler(s, cmd_reg(s, i + 1), i, "lrr-dst"); 1077 if (ret) 1078 break; 1079 } 1080 return ret; 1081 } 1082 1083 static inline int cmd_address_audit(struct parser_exec_state *s, 1084 unsigned long guest_gma, int op_size, bool index_mode); 1085 1086 static int cmd_handler_lrm(struct parser_exec_state *s) 1087 { 1088 struct intel_gvt *gvt = s->vgpu->gvt; 1089 int gmadr_bytes = gvt->device_info.gmadr_bytes_in_cmd; 1090 unsigned long gma; 1091 int i, ret = 0; 1092 int cmd_len = cmd_length(s); 1093 1094 for (i = 1; i < cmd_len;) { 1095 if (IS_BROADWELL(s->engine->i915)) 1096 ret |= (cmd_reg_inhibit(s, i)) ? -EBADRQC : 0; 1097 if (ret) 1098 break; 1099 ret |= cmd_reg_handler(s, cmd_reg(s, i), i, "lrm"); 1100 if (ret) 1101 break; 1102 if (cmd_val(s, 0) & (1 << 22)) { 1103 gma = cmd_gma(s, i + 1); 1104 if (gmadr_bytes == 8) 1105 gma |= (cmd_gma_hi(s, i + 2)) << 32; 1106 ret |= cmd_address_audit(s, gma, sizeof(u32), false); 1107 if (ret) 1108 break; 1109 } 1110 i += gmadr_dw_number(s) + 1; 1111 } 1112 return ret; 1113 } 1114 1115 static int cmd_handler_srm(struct parser_exec_state *s) 1116 { 1117 int gmadr_bytes = s->vgpu->gvt->device_info.gmadr_bytes_in_cmd; 1118 unsigned long gma; 1119 int i, ret = 0; 1120 int cmd_len = cmd_length(s); 1121 1122 for (i = 1; i < cmd_len;) { 1123 ret |= cmd_reg_handler(s, cmd_reg(s, i), i, "srm"); 1124 if (ret) 1125 break; 1126 if (cmd_val(s, 0) & (1 << 22)) { 1127 gma = cmd_gma(s, i + 1); 1128 if (gmadr_bytes == 8) 1129 gma |= (cmd_gma_hi(s, i + 2)) << 32; 1130 ret |= cmd_address_audit(s, gma, sizeof(u32), false); 1131 if (ret) 1132 break; 1133 } 1134 i += gmadr_dw_number(s) + 1; 1135 } 1136 return ret; 1137 } 1138 1139 struct cmd_interrupt_event { 1140 int pipe_control_notify; 1141 int mi_flush_dw; 1142 int mi_user_interrupt; 1143 }; 1144 1145 static struct cmd_interrupt_event cmd_interrupt_events[] = { 1146 [RCS0] = { 1147 .pipe_control_notify = RCS_PIPE_CONTROL, 1148 .mi_flush_dw = INTEL_GVT_EVENT_RESERVED, 1149 .mi_user_interrupt = RCS_MI_USER_INTERRUPT, 1150 }, 1151 [BCS0] = { 1152 .pipe_control_notify = INTEL_GVT_EVENT_RESERVED, 1153 .mi_flush_dw = BCS_MI_FLUSH_DW, 1154 .mi_user_interrupt = BCS_MI_USER_INTERRUPT, 1155 }, 1156 [VCS0] = { 1157 .pipe_control_notify = INTEL_GVT_EVENT_RESERVED, 1158 .mi_flush_dw = VCS_MI_FLUSH_DW, 1159 .mi_user_interrupt = VCS_MI_USER_INTERRUPT, 1160 }, 1161 [VCS1] = { 1162 .pipe_control_notify = INTEL_GVT_EVENT_RESERVED, 1163 .mi_flush_dw = VCS2_MI_FLUSH_DW, 1164 .mi_user_interrupt = VCS2_MI_USER_INTERRUPT, 1165 }, 1166 [VECS0] = { 1167 .pipe_control_notify = INTEL_GVT_EVENT_RESERVED, 1168 .mi_flush_dw = VECS_MI_FLUSH_DW, 1169 .mi_user_interrupt = VECS_MI_USER_INTERRUPT, 1170 }, 1171 }; 1172 1173 static int cmd_handler_pipe_control(struct parser_exec_state *s) 1174 { 1175 int gmadr_bytes = s->vgpu->gvt->device_info.gmadr_bytes_in_cmd; 1176 unsigned long gma; 1177 bool index_mode = false; 1178 unsigned int post_sync; 1179 int ret = 0; 1180 u32 hws_pga, val; 1181 1182 post_sync = (cmd_val(s, 1) & PIPE_CONTROL_POST_SYNC_OP_MASK) >> 14; 1183 1184 /* LRI post sync */ 1185 if (cmd_val(s, 1) & PIPE_CONTROL_MMIO_WRITE) 1186 ret = cmd_reg_handler(s, cmd_reg(s, 2), 1, "pipe_ctrl"); 1187 /* post sync */ 1188 else if (post_sync) { 1189 if (post_sync == 2) 1190 ret = cmd_reg_handler(s, 0x2350, 1, "pipe_ctrl"); 1191 else if (post_sync == 3) 1192 ret = cmd_reg_handler(s, 0x2358, 1, "pipe_ctrl"); 1193 else if (post_sync == 1) { 1194 /* check ggtt*/ 1195 if ((cmd_val(s, 1) & PIPE_CONTROL_GLOBAL_GTT_IVB)) { 1196 gma = cmd_val(s, 2) & GENMASK(31, 3); 1197 if (gmadr_bytes == 8) 1198 gma |= (cmd_gma_hi(s, 3)) << 32; 1199 /* Store Data Index */ 1200 if (cmd_val(s, 1) & (1 << 21)) 1201 index_mode = true; 1202 ret |= cmd_address_audit(s, gma, sizeof(u64), 1203 index_mode); 1204 if (ret) 1205 return ret; 1206 if (index_mode) { 1207 hws_pga = s->vgpu->hws_pga[s->engine->id]; 1208 gma = hws_pga + gma; 1209 patch_value(s, cmd_ptr(s, 2), gma); 1210 val = cmd_val(s, 1) & (~(1 << 21)); 1211 patch_value(s, cmd_ptr(s, 1), val); 1212 } 1213 } 1214 } 1215 } 1216 1217 if (ret) 1218 return ret; 1219 1220 if (cmd_val(s, 1) & PIPE_CONTROL_NOTIFY) 1221 set_bit(cmd_interrupt_events[s->engine->id].pipe_control_notify, 1222 s->workload->pending_events); 1223 return 0; 1224 } 1225 1226 static int cmd_handler_mi_user_interrupt(struct parser_exec_state *s) 1227 { 1228 set_bit(cmd_interrupt_events[s->engine->id].mi_user_interrupt, 1229 s->workload->pending_events); 1230 patch_value(s, cmd_ptr(s, 0), MI_NOOP); 1231 return 0; 1232 } 1233 1234 static int cmd_advance_default(struct parser_exec_state *s) 1235 { 1236 return ip_gma_advance(s, cmd_length(s)); 1237 } 1238 1239 static int cmd_handler_mi_batch_buffer_end(struct parser_exec_state *s) 1240 { 1241 int ret; 1242 1243 if (s->buf_type == BATCH_BUFFER_2ND_LEVEL) { 1244 s->buf_type = BATCH_BUFFER_INSTRUCTION; 1245 ret = ip_gma_set(s, s->ret_ip_gma_bb); 1246 s->buf_addr_type = s->saved_buf_addr_type; 1247 } else if (s->buf_type == RING_BUFFER_CTX) { 1248 ret = ip_gma_set(s, s->ring_tail); 1249 } else { 1250 s->buf_type = RING_BUFFER_INSTRUCTION; 1251 s->buf_addr_type = GTT_BUFFER; 1252 if (s->ret_ip_gma_ring >= s->ring_start + s->ring_size) 1253 s->ret_ip_gma_ring -= s->ring_size; 1254 ret = ip_gma_set(s, s->ret_ip_gma_ring); 1255 } 1256 return ret; 1257 } 1258 1259 struct mi_display_flip_command_info { 1260 int pipe; 1261 int plane; 1262 int event; 1263 i915_reg_t stride_reg; 1264 i915_reg_t ctrl_reg; 1265 i915_reg_t surf_reg; 1266 u64 stride_val; 1267 u64 tile_val; 1268 u64 surf_val; 1269 bool async_flip; 1270 }; 1271 1272 struct plane_code_mapping { 1273 int pipe; 1274 int plane; 1275 int event; 1276 }; 1277 1278 static int gen8_decode_mi_display_flip(struct parser_exec_state *s, 1279 struct mi_display_flip_command_info *info) 1280 { 1281 struct drm_i915_private *dev_priv = s->engine->i915; 1282 struct plane_code_mapping gen8_plane_code[] = { 1283 [0] = {PIPE_A, PLANE_A, PRIMARY_A_FLIP_DONE}, 1284 [1] = {PIPE_B, PLANE_A, PRIMARY_B_FLIP_DONE}, 1285 [2] = {PIPE_A, PLANE_B, SPRITE_A_FLIP_DONE}, 1286 [3] = {PIPE_B, PLANE_B, SPRITE_B_FLIP_DONE}, 1287 [4] = {PIPE_C, PLANE_A, PRIMARY_C_FLIP_DONE}, 1288 [5] = {PIPE_C, PLANE_B, SPRITE_C_FLIP_DONE}, 1289 }; 1290 u32 dword0, dword1, dword2; 1291 u32 v; 1292 1293 dword0 = cmd_val(s, 0); 1294 dword1 = cmd_val(s, 1); 1295 dword2 = cmd_val(s, 2); 1296 1297 v = (dword0 & GENMASK(21, 19)) >> 19; 1298 if (drm_WARN_ON(&dev_priv->drm, v >= ARRAY_SIZE(gen8_plane_code))) 1299 return -EBADRQC; 1300 1301 info->pipe = gen8_plane_code[v].pipe; 1302 info->plane = gen8_plane_code[v].plane; 1303 info->event = gen8_plane_code[v].event; 1304 info->stride_val = (dword1 & GENMASK(15, 6)) >> 6; 1305 info->tile_val = (dword1 & 0x1); 1306 info->surf_val = (dword2 & GENMASK(31, 12)) >> 12; 1307 info->async_flip = ((dword2 & GENMASK(1, 0)) == 0x1); 1308 1309 if (info->plane == PLANE_A) { 1310 info->ctrl_reg = DSPCNTR(info->pipe); 1311 info->stride_reg = DSPSTRIDE(info->pipe); 1312 info->surf_reg = DSPSURF(info->pipe); 1313 } else if (info->plane == PLANE_B) { 1314 info->ctrl_reg = SPRCTL(info->pipe); 1315 info->stride_reg = SPRSTRIDE(info->pipe); 1316 info->surf_reg = SPRSURF(info->pipe); 1317 } else { 1318 drm_WARN_ON(&dev_priv->drm, 1); 1319 return -EBADRQC; 1320 } 1321 return 0; 1322 } 1323 1324 static int skl_decode_mi_display_flip(struct parser_exec_state *s, 1325 struct mi_display_flip_command_info *info) 1326 { 1327 struct drm_i915_private *dev_priv = s->engine->i915; 1328 struct intel_vgpu *vgpu = s->vgpu; 1329 u32 dword0 = cmd_val(s, 0); 1330 u32 dword1 = cmd_val(s, 1); 1331 u32 dword2 = cmd_val(s, 2); 1332 u32 plane = (dword0 & GENMASK(12, 8)) >> 8; 1333 1334 info->plane = PRIMARY_PLANE; 1335 1336 switch (plane) { 1337 case MI_DISPLAY_FLIP_SKL_PLANE_1_A: 1338 info->pipe = PIPE_A; 1339 info->event = PRIMARY_A_FLIP_DONE; 1340 break; 1341 case MI_DISPLAY_FLIP_SKL_PLANE_1_B: 1342 info->pipe = PIPE_B; 1343 info->event = PRIMARY_B_FLIP_DONE; 1344 break; 1345 case MI_DISPLAY_FLIP_SKL_PLANE_1_C: 1346 info->pipe = PIPE_C; 1347 info->event = PRIMARY_C_FLIP_DONE; 1348 break; 1349 1350 case MI_DISPLAY_FLIP_SKL_PLANE_2_A: 1351 info->pipe = PIPE_A; 1352 info->event = SPRITE_A_FLIP_DONE; 1353 info->plane = SPRITE_PLANE; 1354 break; 1355 case MI_DISPLAY_FLIP_SKL_PLANE_2_B: 1356 info->pipe = PIPE_B; 1357 info->event = SPRITE_B_FLIP_DONE; 1358 info->plane = SPRITE_PLANE; 1359 break; 1360 case MI_DISPLAY_FLIP_SKL_PLANE_2_C: 1361 info->pipe = PIPE_C; 1362 info->event = SPRITE_C_FLIP_DONE; 1363 info->plane = SPRITE_PLANE; 1364 break; 1365 1366 default: 1367 gvt_vgpu_err("unknown plane code %d\n", plane); 1368 return -EBADRQC; 1369 } 1370 1371 info->stride_val = (dword1 & GENMASK(15, 6)) >> 6; 1372 info->tile_val = (dword1 & GENMASK(2, 0)); 1373 info->surf_val = (dword2 & GENMASK(31, 12)) >> 12; 1374 info->async_flip = ((dword2 & GENMASK(1, 0)) == 0x1); 1375 1376 info->ctrl_reg = DSPCNTR(info->pipe); 1377 info->stride_reg = DSPSTRIDE(info->pipe); 1378 info->surf_reg = DSPSURF(info->pipe); 1379 1380 return 0; 1381 } 1382 1383 static int gen8_check_mi_display_flip(struct parser_exec_state *s, 1384 struct mi_display_flip_command_info *info) 1385 { 1386 u32 stride, tile; 1387 1388 if (!info->async_flip) 1389 return 0; 1390 1391 if (INTEL_GEN(s->engine->i915) >= 9) { 1392 stride = vgpu_vreg_t(s->vgpu, info->stride_reg) & GENMASK(9, 0); 1393 tile = (vgpu_vreg_t(s->vgpu, info->ctrl_reg) & 1394 GENMASK(12, 10)) >> 10; 1395 } else { 1396 stride = (vgpu_vreg_t(s->vgpu, info->stride_reg) & 1397 GENMASK(15, 6)) >> 6; 1398 tile = (vgpu_vreg_t(s->vgpu, info->ctrl_reg) & (1 << 10)) >> 10; 1399 } 1400 1401 if (stride != info->stride_val) 1402 gvt_dbg_cmd("cannot change stride during async flip\n"); 1403 1404 if (tile != info->tile_val) 1405 gvt_dbg_cmd("cannot change tile during async flip\n"); 1406 1407 return 0; 1408 } 1409 1410 static int gen8_update_plane_mmio_from_mi_display_flip( 1411 struct parser_exec_state *s, 1412 struct mi_display_flip_command_info *info) 1413 { 1414 struct drm_i915_private *dev_priv = s->engine->i915; 1415 struct intel_vgpu *vgpu = s->vgpu; 1416 1417 set_mask_bits(&vgpu_vreg_t(vgpu, info->surf_reg), GENMASK(31, 12), 1418 info->surf_val << 12); 1419 if (INTEL_GEN(dev_priv) >= 9) { 1420 set_mask_bits(&vgpu_vreg_t(vgpu, info->stride_reg), GENMASK(9, 0), 1421 info->stride_val); 1422 set_mask_bits(&vgpu_vreg_t(vgpu, info->ctrl_reg), GENMASK(12, 10), 1423 info->tile_val << 10); 1424 } else { 1425 set_mask_bits(&vgpu_vreg_t(vgpu, info->stride_reg), GENMASK(15, 6), 1426 info->stride_val << 6); 1427 set_mask_bits(&vgpu_vreg_t(vgpu, info->ctrl_reg), GENMASK(10, 10), 1428 info->tile_val << 10); 1429 } 1430 1431 if (info->plane == PLANE_PRIMARY) 1432 vgpu_vreg_t(vgpu, PIPE_FLIPCOUNT_G4X(info->pipe))++; 1433 1434 if (info->async_flip) 1435 intel_vgpu_trigger_virtual_event(vgpu, info->event); 1436 else 1437 set_bit(info->event, vgpu->irq.flip_done_event[info->pipe]); 1438 1439 return 0; 1440 } 1441 1442 static int decode_mi_display_flip(struct parser_exec_state *s, 1443 struct mi_display_flip_command_info *info) 1444 { 1445 if (IS_BROADWELL(s->engine->i915)) 1446 return gen8_decode_mi_display_flip(s, info); 1447 if (INTEL_GEN(s->engine->i915) >= 9) 1448 return skl_decode_mi_display_flip(s, info); 1449 1450 return -ENODEV; 1451 } 1452 1453 static int check_mi_display_flip(struct parser_exec_state *s, 1454 struct mi_display_flip_command_info *info) 1455 { 1456 return gen8_check_mi_display_flip(s, info); 1457 } 1458 1459 static int update_plane_mmio_from_mi_display_flip( 1460 struct parser_exec_state *s, 1461 struct mi_display_flip_command_info *info) 1462 { 1463 return gen8_update_plane_mmio_from_mi_display_flip(s, info); 1464 } 1465 1466 static int cmd_handler_mi_display_flip(struct parser_exec_state *s) 1467 { 1468 struct mi_display_flip_command_info info; 1469 struct intel_vgpu *vgpu = s->vgpu; 1470 int ret; 1471 int i; 1472 int len = cmd_length(s); 1473 u32 valid_len = CMD_LEN(1); 1474 1475 /* Flip Type == Stereo 3D Flip */ 1476 if (DWORD_FIELD(2, 1, 0) == 2) 1477 valid_len++; 1478 ret = gvt_check_valid_cmd_length(cmd_length(s), 1479 valid_len); 1480 if (ret) 1481 return ret; 1482 1483 ret = decode_mi_display_flip(s, &info); 1484 if (ret) { 1485 gvt_vgpu_err("fail to decode MI display flip command\n"); 1486 return ret; 1487 } 1488 1489 ret = check_mi_display_flip(s, &info); 1490 if (ret) { 1491 gvt_vgpu_err("invalid MI display flip command\n"); 1492 return ret; 1493 } 1494 1495 ret = update_plane_mmio_from_mi_display_flip(s, &info); 1496 if (ret) { 1497 gvt_vgpu_err("fail to update plane mmio\n"); 1498 return ret; 1499 } 1500 1501 for (i = 0; i < len; i++) 1502 patch_value(s, cmd_ptr(s, i), MI_NOOP); 1503 return 0; 1504 } 1505 1506 static bool is_wait_for_flip_pending(u32 cmd) 1507 { 1508 return cmd & (MI_WAIT_FOR_PLANE_A_FLIP_PENDING | 1509 MI_WAIT_FOR_PLANE_B_FLIP_PENDING | 1510 MI_WAIT_FOR_PLANE_C_FLIP_PENDING | 1511 MI_WAIT_FOR_SPRITE_A_FLIP_PENDING | 1512 MI_WAIT_FOR_SPRITE_B_FLIP_PENDING | 1513 MI_WAIT_FOR_SPRITE_C_FLIP_PENDING); 1514 } 1515 1516 static int cmd_handler_mi_wait_for_event(struct parser_exec_state *s) 1517 { 1518 u32 cmd = cmd_val(s, 0); 1519 1520 if (!is_wait_for_flip_pending(cmd)) 1521 return 0; 1522 1523 patch_value(s, cmd_ptr(s, 0), MI_NOOP); 1524 return 0; 1525 } 1526 1527 static unsigned long get_gma_bb_from_cmd(struct parser_exec_state *s, int index) 1528 { 1529 unsigned long addr; 1530 unsigned long gma_high, gma_low; 1531 struct intel_vgpu *vgpu = s->vgpu; 1532 int gmadr_bytes = vgpu->gvt->device_info.gmadr_bytes_in_cmd; 1533 1534 if (WARN_ON(gmadr_bytes != 4 && gmadr_bytes != 8)) { 1535 gvt_vgpu_err("invalid gma bytes %d\n", gmadr_bytes); 1536 return INTEL_GVT_INVALID_ADDR; 1537 } 1538 1539 gma_low = cmd_val(s, index) & BATCH_BUFFER_ADDR_MASK; 1540 if (gmadr_bytes == 4) { 1541 addr = gma_low; 1542 } else { 1543 gma_high = cmd_val(s, index + 1) & BATCH_BUFFER_ADDR_HIGH_MASK; 1544 addr = (((unsigned long)gma_high) << 32) | gma_low; 1545 } 1546 return addr; 1547 } 1548 1549 static inline int cmd_address_audit(struct parser_exec_state *s, 1550 unsigned long guest_gma, int op_size, bool index_mode) 1551 { 1552 struct intel_vgpu *vgpu = s->vgpu; 1553 u32 max_surface_size = vgpu->gvt->device_info.max_surface_size; 1554 int i; 1555 int ret; 1556 1557 if (op_size > max_surface_size) { 1558 gvt_vgpu_err("command address audit fail name %s\n", 1559 s->info->name); 1560 return -EFAULT; 1561 } 1562 1563 if (index_mode) { 1564 if (guest_gma >= I915_GTT_PAGE_SIZE) { 1565 ret = -EFAULT; 1566 goto err; 1567 } 1568 } else if (!intel_gvt_ggtt_validate_range(vgpu, guest_gma, op_size)) { 1569 ret = -EFAULT; 1570 goto err; 1571 } 1572 1573 return 0; 1574 1575 err: 1576 gvt_vgpu_err("cmd_parser: Malicious %s detected, addr=0x%lx, len=%d!\n", 1577 s->info->name, guest_gma, op_size); 1578 1579 pr_err("cmd dump: "); 1580 for (i = 0; i < cmd_length(s); i++) { 1581 if (!(i % 4)) 1582 pr_err("\n%08x ", cmd_val(s, i)); 1583 else 1584 pr_err("%08x ", cmd_val(s, i)); 1585 } 1586 pr_err("\nvgpu%d: aperture 0x%llx - 0x%llx, hidden 0x%llx - 0x%llx\n", 1587 vgpu->id, 1588 vgpu_aperture_gmadr_base(vgpu), 1589 vgpu_aperture_gmadr_end(vgpu), 1590 vgpu_hidden_gmadr_base(vgpu), 1591 vgpu_hidden_gmadr_end(vgpu)); 1592 return ret; 1593 } 1594 1595 static int cmd_handler_mi_store_data_imm(struct parser_exec_state *s) 1596 { 1597 int gmadr_bytes = s->vgpu->gvt->device_info.gmadr_bytes_in_cmd; 1598 int op_size = (cmd_length(s) - 3) * sizeof(u32); 1599 int core_id = (cmd_val(s, 2) & (1 << 0)) ? 1 : 0; 1600 unsigned long gma, gma_low, gma_high; 1601 u32 valid_len = CMD_LEN(2); 1602 int ret = 0; 1603 1604 /* check ppggt */ 1605 if (!(cmd_val(s, 0) & (1 << 22))) 1606 return 0; 1607 1608 /* check if QWORD */ 1609 if (DWORD_FIELD(0, 21, 21)) 1610 valid_len++; 1611 ret = gvt_check_valid_cmd_length(cmd_length(s), 1612 valid_len); 1613 if (ret) 1614 return ret; 1615 1616 gma = cmd_val(s, 2) & GENMASK(31, 2); 1617 1618 if (gmadr_bytes == 8) { 1619 gma_low = cmd_val(s, 1) & GENMASK(31, 2); 1620 gma_high = cmd_val(s, 2) & GENMASK(15, 0); 1621 gma = (gma_high << 32) | gma_low; 1622 core_id = (cmd_val(s, 1) & (1 << 0)) ? 1 : 0; 1623 } 1624 ret = cmd_address_audit(s, gma + op_size * core_id, op_size, false); 1625 return ret; 1626 } 1627 1628 static inline int unexpected_cmd(struct parser_exec_state *s) 1629 { 1630 struct intel_vgpu *vgpu = s->vgpu; 1631 1632 gvt_vgpu_err("Unexpected %s in command buffer!\n", s->info->name); 1633 1634 return -EBADRQC; 1635 } 1636 1637 static int cmd_handler_mi_semaphore_wait(struct parser_exec_state *s) 1638 { 1639 return unexpected_cmd(s); 1640 } 1641 1642 static int cmd_handler_mi_report_perf_count(struct parser_exec_state *s) 1643 { 1644 return unexpected_cmd(s); 1645 } 1646 1647 static int cmd_handler_mi_op_2e(struct parser_exec_state *s) 1648 { 1649 return unexpected_cmd(s); 1650 } 1651 1652 static int cmd_handler_mi_op_2f(struct parser_exec_state *s) 1653 { 1654 int gmadr_bytes = s->vgpu->gvt->device_info.gmadr_bytes_in_cmd; 1655 int op_size = (1 << ((cmd_val(s, 0) & GENMASK(20, 19)) >> 19)) * 1656 sizeof(u32); 1657 unsigned long gma, gma_high; 1658 u32 valid_len = CMD_LEN(1); 1659 int ret = 0; 1660 1661 if (!(cmd_val(s, 0) & (1 << 22))) 1662 return ret; 1663 1664 /* check inline data */ 1665 if (cmd_val(s, 0) & BIT(18)) 1666 valid_len = CMD_LEN(9); 1667 ret = gvt_check_valid_cmd_length(cmd_length(s), 1668 valid_len); 1669 if (ret) 1670 return ret; 1671 1672 gma = cmd_val(s, 1) & GENMASK(31, 2); 1673 if (gmadr_bytes == 8) { 1674 gma_high = cmd_val(s, 2) & GENMASK(15, 0); 1675 gma = (gma_high << 32) | gma; 1676 } 1677 ret = cmd_address_audit(s, gma, op_size, false); 1678 return ret; 1679 } 1680 1681 static int cmd_handler_mi_store_data_index(struct parser_exec_state *s) 1682 { 1683 return unexpected_cmd(s); 1684 } 1685 1686 static int cmd_handler_mi_clflush(struct parser_exec_state *s) 1687 { 1688 return unexpected_cmd(s); 1689 } 1690 1691 static int cmd_handler_mi_conditional_batch_buffer_end( 1692 struct parser_exec_state *s) 1693 { 1694 return unexpected_cmd(s); 1695 } 1696 1697 static int cmd_handler_mi_update_gtt(struct parser_exec_state *s) 1698 { 1699 return unexpected_cmd(s); 1700 } 1701 1702 static int cmd_handler_mi_flush_dw(struct parser_exec_state *s) 1703 { 1704 int gmadr_bytes = s->vgpu->gvt->device_info.gmadr_bytes_in_cmd; 1705 unsigned long gma; 1706 bool index_mode = false; 1707 int ret = 0; 1708 u32 hws_pga, val; 1709 u32 valid_len = CMD_LEN(2); 1710 1711 ret = gvt_check_valid_cmd_length(cmd_length(s), 1712 valid_len); 1713 if (ret) { 1714 /* Check again for Qword */ 1715 ret = gvt_check_valid_cmd_length(cmd_length(s), 1716 ++valid_len); 1717 return ret; 1718 } 1719 1720 /* Check post-sync and ppgtt bit */ 1721 if (((cmd_val(s, 0) >> 14) & 0x3) && (cmd_val(s, 1) & (1 << 2))) { 1722 gma = cmd_val(s, 1) & GENMASK(31, 3); 1723 if (gmadr_bytes == 8) 1724 gma |= (cmd_val(s, 2) & GENMASK(15, 0)) << 32; 1725 /* Store Data Index */ 1726 if (cmd_val(s, 0) & (1 << 21)) 1727 index_mode = true; 1728 ret = cmd_address_audit(s, gma, sizeof(u64), index_mode); 1729 if (ret) 1730 return ret; 1731 if (index_mode) { 1732 hws_pga = s->vgpu->hws_pga[s->engine->id]; 1733 gma = hws_pga + gma; 1734 patch_value(s, cmd_ptr(s, 1), gma); 1735 val = cmd_val(s, 0) & (~(1 << 21)); 1736 patch_value(s, cmd_ptr(s, 0), val); 1737 } 1738 } 1739 /* Check notify bit */ 1740 if ((cmd_val(s, 0) & (1 << 8))) 1741 set_bit(cmd_interrupt_events[s->engine->id].mi_flush_dw, 1742 s->workload->pending_events); 1743 return ret; 1744 } 1745 1746 static void addr_type_update_snb(struct parser_exec_state *s) 1747 { 1748 if ((s->buf_type == RING_BUFFER_INSTRUCTION) && 1749 (BATCH_BUFFER_ADR_SPACE_BIT(cmd_val(s, 0)) == 1)) { 1750 s->buf_addr_type = PPGTT_BUFFER; 1751 } 1752 } 1753 1754 1755 static int copy_gma_to_hva(struct intel_vgpu *vgpu, struct intel_vgpu_mm *mm, 1756 unsigned long gma, unsigned long end_gma, void *va) 1757 { 1758 unsigned long copy_len, offset; 1759 unsigned long len = 0; 1760 unsigned long gpa; 1761 1762 while (gma != end_gma) { 1763 gpa = intel_vgpu_gma_to_gpa(mm, gma); 1764 if (gpa == INTEL_GVT_INVALID_ADDR) { 1765 gvt_vgpu_err("invalid gma address: %lx\n", gma); 1766 return -EFAULT; 1767 } 1768 1769 offset = gma & (I915_GTT_PAGE_SIZE - 1); 1770 1771 copy_len = (end_gma - gma) >= (I915_GTT_PAGE_SIZE - offset) ? 1772 I915_GTT_PAGE_SIZE - offset : end_gma - gma; 1773 1774 intel_gvt_hypervisor_read_gpa(vgpu, gpa, va + len, copy_len); 1775 1776 len += copy_len; 1777 gma += copy_len; 1778 } 1779 return len; 1780 } 1781 1782 1783 /* 1784 * Check whether a batch buffer needs to be scanned. Currently 1785 * the only criteria is based on privilege. 1786 */ 1787 static int batch_buffer_needs_scan(struct parser_exec_state *s) 1788 { 1789 /* Decide privilege based on address space */ 1790 if (cmd_val(s, 0) & BIT(8) && 1791 !(s->vgpu->scan_nonprivbb & s->engine->mask)) 1792 return 0; 1793 1794 return 1; 1795 } 1796 1797 static const char *repr_addr_type(unsigned int type) 1798 { 1799 return type == PPGTT_BUFFER ? "ppgtt" : "ggtt"; 1800 } 1801 1802 static int find_bb_size(struct parser_exec_state *s, 1803 unsigned long *bb_size, 1804 unsigned long *bb_end_cmd_offset) 1805 { 1806 unsigned long gma = 0; 1807 const struct cmd_info *info; 1808 u32 cmd_len = 0; 1809 bool bb_end = false; 1810 struct intel_vgpu *vgpu = s->vgpu; 1811 u32 cmd; 1812 struct intel_vgpu_mm *mm = (s->buf_addr_type == GTT_BUFFER) ? 1813 s->vgpu->gtt.ggtt_mm : s->workload->shadow_mm; 1814 1815 *bb_size = 0; 1816 *bb_end_cmd_offset = 0; 1817 1818 /* get the start gm address of the batch buffer */ 1819 gma = get_gma_bb_from_cmd(s, 1); 1820 if (gma == INTEL_GVT_INVALID_ADDR) 1821 return -EFAULT; 1822 1823 cmd = cmd_val(s, 0); 1824 info = get_cmd_info(s->vgpu->gvt, cmd, s->engine); 1825 if (info == NULL) { 1826 gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x, addr_type=%s, ring %s, workload=%p\n", 1827 cmd, get_opcode(cmd, s->engine), 1828 repr_addr_type(s->buf_addr_type), 1829 s->engine->name, s->workload); 1830 return -EBADRQC; 1831 } 1832 do { 1833 if (copy_gma_to_hva(s->vgpu, mm, 1834 gma, gma + 4, &cmd) < 0) 1835 return -EFAULT; 1836 info = get_cmd_info(s->vgpu->gvt, cmd, s->engine); 1837 if (info == NULL) { 1838 gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x, addr_type=%s, ring %s, workload=%p\n", 1839 cmd, get_opcode(cmd, s->engine), 1840 repr_addr_type(s->buf_addr_type), 1841 s->engine->name, s->workload); 1842 return -EBADRQC; 1843 } 1844 1845 if (info->opcode == OP_MI_BATCH_BUFFER_END) { 1846 bb_end = true; 1847 } else if (info->opcode == OP_MI_BATCH_BUFFER_START) { 1848 if (BATCH_BUFFER_2ND_LEVEL_BIT(cmd) == 0) 1849 /* chained batch buffer */ 1850 bb_end = true; 1851 } 1852 1853 if (bb_end) 1854 *bb_end_cmd_offset = *bb_size; 1855 1856 cmd_len = get_cmd_length(info, cmd) << 2; 1857 *bb_size += cmd_len; 1858 gma += cmd_len; 1859 } while (!bb_end); 1860 1861 return 0; 1862 } 1863 1864 static int audit_bb_end(struct parser_exec_state *s, void *va) 1865 { 1866 struct intel_vgpu *vgpu = s->vgpu; 1867 u32 cmd = *(u32 *)va; 1868 const struct cmd_info *info; 1869 1870 info = get_cmd_info(s->vgpu->gvt, cmd, s->engine); 1871 if (info == NULL) { 1872 gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x, addr_type=%s, ring %s, workload=%p\n", 1873 cmd, get_opcode(cmd, s->engine), 1874 repr_addr_type(s->buf_addr_type), 1875 s->engine->name, s->workload); 1876 return -EBADRQC; 1877 } 1878 1879 if ((info->opcode == OP_MI_BATCH_BUFFER_END) || 1880 ((info->opcode == OP_MI_BATCH_BUFFER_START) && 1881 (BATCH_BUFFER_2ND_LEVEL_BIT(cmd) == 0))) 1882 return 0; 1883 1884 return -EBADRQC; 1885 } 1886 1887 static int perform_bb_shadow(struct parser_exec_state *s) 1888 { 1889 struct intel_vgpu *vgpu = s->vgpu; 1890 struct intel_vgpu_shadow_bb *bb; 1891 unsigned long gma = 0; 1892 unsigned long bb_size; 1893 unsigned long bb_end_cmd_offset; 1894 int ret = 0; 1895 struct intel_vgpu_mm *mm = (s->buf_addr_type == GTT_BUFFER) ? 1896 s->vgpu->gtt.ggtt_mm : s->workload->shadow_mm; 1897 unsigned long start_offset = 0; 1898 1899 /* get the start gm address of the batch buffer */ 1900 gma = get_gma_bb_from_cmd(s, 1); 1901 if (gma == INTEL_GVT_INVALID_ADDR) 1902 return -EFAULT; 1903 1904 ret = find_bb_size(s, &bb_size, &bb_end_cmd_offset); 1905 if (ret) 1906 return ret; 1907 1908 bb = kzalloc(sizeof(*bb), GFP_KERNEL); 1909 if (!bb) 1910 return -ENOMEM; 1911 1912 bb->ppgtt = (s->buf_addr_type == GTT_BUFFER) ? false : true; 1913 1914 /* the start_offset stores the batch buffer's start gma's 1915 * offset relative to page boundary. so for non-privileged batch 1916 * buffer, the shadowed gem object holds exactly the same page 1917 * layout as original gem object. This is for the convience of 1918 * replacing the whole non-privilged batch buffer page to this 1919 * shadowed one in PPGTT at the same gma address. (this replacing 1920 * action is not implemented yet now, but may be necessary in 1921 * future). 1922 * for prileged batch buffer, we just change start gma address to 1923 * that of shadowed page. 1924 */ 1925 if (bb->ppgtt) 1926 start_offset = gma & ~I915_GTT_PAGE_MASK; 1927 1928 bb->obj = i915_gem_object_create_shmem(s->engine->i915, 1929 round_up(bb_size + start_offset, 1930 PAGE_SIZE)); 1931 if (IS_ERR(bb->obj)) { 1932 ret = PTR_ERR(bb->obj); 1933 goto err_free_bb; 1934 } 1935 1936 bb->va = i915_gem_object_pin_map(bb->obj, I915_MAP_WB); 1937 if (IS_ERR(bb->va)) { 1938 ret = PTR_ERR(bb->va); 1939 goto err_free_obj; 1940 } 1941 1942 ret = copy_gma_to_hva(s->vgpu, mm, 1943 gma, gma + bb_size, 1944 bb->va + start_offset); 1945 if (ret < 0) { 1946 gvt_vgpu_err("fail to copy guest ring buffer\n"); 1947 ret = -EFAULT; 1948 goto err_unmap; 1949 } 1950 1951 ret = audit_bb_end(s, bb->va + start_offset + bb_end_cmd_offset); 1952 if (ret) 1953 goto err_unmap; 1954 1955 i915_gem_object_unlock(bb->obj); 1956 INIT_LIST_HEAD(&bb->list); 1957 list_add(&bb->list, &s->workload->shadow_bb); 1958 1959 bb->bb_start_cmd_va = s->ip_va; 1960 1961 if ((s->buf_type == BATCH_BUFFER_INSTRUCTION) && (!s->is_ctx_wa)) 1962 bb->bb_offset = s->ip_va - s->rb_va; 1963 else 1964 bb->bb_offset = 0; 1965 1966 /* 1967 * ip_va saves the virtual address of the shadow batch buffer, while 1968 * ip_gma saves the graphics address of the original batch buffer. 1969 * As the shadow batch buffer is just a copy from the originial one, 1970 * it should be right to use shadow batch buffer'va and original batch 1971 * buffer's gma in pair. After all, we don't want to pin the shadow 1972 * buffer here (too early). 1973 */ 1974 s->ip_va = bb->va + start_offset; 1975 s->ip_gma = gma; 1976 return 0; 1977 err_unmap: 1978 i915_gem_object_unpin_map(bb->obj); 1979 err_free_obj: 1980 i915_gem_object_put(bb->obj); 1981 err_free_bb: 1982 kfree(bb); 1983 return ret; 1984 } 1985 1986 static int cmd_handler_mi_batch_buffer_start(struct parser_exec_state *s) 1987 { 1988 bool second_level; 1989 int ret = 0; 1990 struct intel_vgpu *vgpu = s->vgpu; 1991 1992 if (s->buf_type == BATCH_BUFFER_2ND_LEVEL) { 1993 gvt_vgpu_err("Found MI_BATCH_BUFFER_START in 2nd level BB\n"); 1994 return -EFAULT; 1995 } 1996 1997 second_level = BATCH_BUFFER_2ND_LEVEL_BIT(cmd_val(s, 0)) == 1; 1998 if (second_level && (s->buf_type != BATCH_BUFFER_INSTRUCTION)) { 1999 gvt_vgpu_err("Jumping to 2nd level BB from RB is not allowed\n"); 2000 return -EFAULT; 2001 } 2002 2003 s->saved_buf_addr_type = s->buf_addr_type; 2004 addr_type_update_snb(s); 2005 if (s->buf_type == RING_BUFFER_INSTRUCTION) { 2006 s->ret_ip_gma_ring = s->ip_gma + cmd_length(s) * sizeof(u32); 2007 s->buf_type = BATCH_BUFFER_INSTRUCTION; 2008 } else if (second_level) { 2009 s->buf_type = BATCH_BUFFER_2ND_LEVEL; 2010 s->ret_ip_gma_bb = s->ip_gma + cmd_length(s) * sizeof(u32); 2011 s->ret_bb_va = s->ip_va + cmd_length(s) * sizeof(u32); 2012 } 2013 2014 if (batch_buffer_needs_scan(s)) { 2015 ret = perform_bb_shadow(s); 2016 if (ret < 0) 2017 gvt_vgpu_err("invalid shadow batch buffer\n"); 2018 } else { 2019 /* emulate a batch buffer end to do return right */ 2020 ret = cmd_handler_mi_batch_buffer_end(s); 2021 if (ret < 0) 2022 return ret; 2023 } 2024 return ret; 2025 } 2026 2027 static int mi_noop_index; 2028 2029 static const struct cmd_info cmd_info[] = { 2030 {"MI_NOOP", OP_MI_NOOP, F_LEN_CONST, R_ALL, D_ALL, 0, 1, NULL}, 2031 2032 {"MI_SET_PREDICATE", OP_MI_SET_PREDICATE, F_LEN_CONST, R_ALL, D_ALL, 2033 0, 1, NULL}, 2034 2035 {"MI_USER_INTERRUPT", OP_MI_USER_INTERRUPT, F_LEN_CONST, R_ALL, D_ALL, 2036 0, 1, cmd_handler_mi_user_interrupt}, 2037 2038 {"MI_WAIT_FOR_EVENT", OP_MI_WAIT_FOR_EVENT, F_LEN_CONST, R_RCS | R_BCS, 2039 D_ALL, 0, 1, cmd_handler_mi_wait_for_event}, 2040 2041 {"MI_FLUSH", OP_MI_FLUSH, F_LEN_CONST, R_ALL, D_ALL, 0, 1, NULL}, 2042 2043 {"MI_ARB_CHECK", OP_MI_ARB_CHECK, F_LEN_CONST, R_ALL, D_ALL, 0, 1, 2044 NULL}, 2045 2046 {"MI_RS_CONTROL", OP_MI_RS_CONTROL, F_LEN_CONST, R_RCS, D_ALL, 0, 1, 2047 NULL}, 2048 2049 {"MI_REPORT_HEAD", OP_MI_REPORT_HEAD, F_LEN_CONST, R_ALL, D_ALL, 0, 1, 2050 NULL}, 2051 2052 {"MI_ARB_ON_OFF", OP_MI_ARB_ON_OFF, F_LEN_CONST, R_ALL, D_ALL, 0, 1, 2053 NULL}, 2054 2055 {"MI_URB_ATOMIC_ALLOC", OP_MI_URB_ATOMIC_ALLOC, F_LEN_CONST, R_RCS, 2056 D_ALL, 0, 1, NULL}, 2057 2058 {"MI_BATCH_BUFFER_END", OP_MI_BATCH_BUFFER_END, 2059 F_IP_ADVANCE_CUSTOM | F_LEN_CONST, R_ALL, D_ALL, 0, 1, 2060 cmd_handler_mi_batch_buffer_end}, 2061 2062 {"MI_SUSPEND_FLUSH", OP_MI_SUSPEND_FLUSH, F_LEN_CONST, R_ALL, D_ALL, 2063 0, 1, NULL}, 2064 2065 {"MI_PREDICATE", OP_MI_PREDICATE, F_LEN_CONST, R_RCS, D_ALL, 0, 1, 2066 NULL}, 2067 2068 {"MI_TOPOLOGY_FILTER", OP_MI_TOPOLOGY_FILTER, F_LEN_CONST, R_ALL, 2069 D_ALL, 0, 1, NULL}, 2070 2071 {"MI_SET_APPID", OP_MI_SET_APPID, F_LEN_CONST, R_ALL, D_ALL, 0, 1, 2072 NULL}, 2073 2074 {"MI_RS_CONTEXT", OP_MI_RS_CONTEXT, F_LEN_CONST, R_RCS, D_ALL, 0, 1, 2075 NULL}, 2076 2077 {"MI_DISPLAY_FLIP", OP_MI_DISPLAY_FLIP, F_LEN_VAR, 2078 R_RCS | R_BCS, D_ALL, 0, 8, cmd_handler_mi_display_flip}, 2079 2080 {"MI_SEMAPHORE_MBOX", OP_MI_SEMAPHORE_MBOX, F_LEN_VAR | F_LEN_VAR_FIXED, 2081 R_ALL, D_ALL, 0, 8, NULL, CMD_LEN(1)}, 2082 2083 {"MI_MATH", OP_MI_MATH, F_LEN_VAR, R_ALL, D_ALL, 0, 8, NULL}, 2084 2085 {"MI_URB_CLEAR", OP_MI_URB_CLEAR, F_LEN_VAR | F_LEN_VAR_FIXED, R_RCS, 2086 D_ALL, 0, 8, NULL, CMD_LEN(0)}, 2087 2088 {"MI_SEMAPHORE_SIGNAL", OP_MI_SEMAPHORE_SIGNAL, 2089 F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_BDW_PLUS, 0, 8, 2090 NULL, CMD_LEN(0)}, 2091 2092 {"MI_SEMAPHORE_WAIT", OP_MI_SEMAPHORE_WAIT, 2093 F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_BDW_PLUS, ADDR_FIX_1(2), 2094 8, cmd_handler_mi_semaphore_wait, CMD_LEN(2)}, 2095 2096 {"MI_STORE_DATA_IMM", OP_MI_STORE_DATA_IMM, F_LEN_VAR, R_ALL, D_BDW_PLUS, 2097 ADDR_FIX_1(1), 10, cmd_handler_mi_store_data_imm}, 2098 2099 {"MI_STORE_DATA_INDEX", OP_MI_STORE_DATA_INDEX, F_LEN_VAR, R_ALL, D_ALL, 2100 0, 8, cmd_handler_mi_store_data_index}, 2101 2102 {"MI_LOAD_REGISTER_IMM", OP_MI_LOAD_REGISTER_IMM, F_LEN_VAR, R_ALL, 2103 D_ALL, 0, 8, cmd_handler_lri}, 2104 2105 {"MI_UPDATE_GTT", OP_MI_UPDATE_GTT, F_LEN_VAR, R_ALL, D_BDW_PLUS, 0, 10, 2106 cmd_handler_mi_update_gtt}, 2107 2108 {"MI_STORE_REGISTER_MEM", OP_MI_STORE_REGISTER_MEM, 2109 F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_ALL, ADDR_FIX_1(2), 8, 2110 cmd_handler_srm, CMD_LEN(2)}, 2111 2112 {"MI_FLUSH_DW", OP_MI_FLUSH_DW, F_LEN_VAR, R_ALL, D_ALL, 0, 6, 2113 cmd_handler_mi_flush_dw}, 2114 2115 {"MI_CLFLUSH", OP_MI_CLFLUSH, F_LEN_VAR, R_ALL, D_ALL, ADDR_FIX_1(1), 2116 10, cmd_handler_mi_clflush}, 2117 2118 {"MI_REPORT_PERF_COUNT", OP_MI_REPORT_PERF_COUNT, 2119 F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_ALL, ADDR_FIX_1(1), 6, 2120 cmd_handler_mi_report_perf_count, CMD_LEN(2)}, 2121 2122 {"MI_LOAD_REGISTER_MEM", OP_MI_LOAD_REGISTER_MEM, 2123 F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_ALL, ADDR_FIX_1(2), 8, 2124 cmd_handler_lrm, CMD_LEN(2)}, 2125 2126 {"MI_LOAD_REGISTER_REG", OP_MI_LOAD_REGISTER_REG, 2127 F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_ALL, 0, 8, 2128 cmd_handler_lrr, CMD_LEN(1)}, 2129 2130 {"MI_RS_STORE_DATA_IMM", OP_MI_RS_STORE_DATA_IMM, 2131 F_LEN_VAR | F_LEN_VAR_FIXED, R_RCS, D_ALL, 0, 2132 8, NULL, CMD_LEN(2)}, 2133 2134 {"MI_LOAD_URB_MEM", OP_MI_LOAD_URB_MEM, F_LEN_VAR | F_LEN_VAR_FIXED, 2135 R_RCS, D_ALL, ADDR_FIX_1(2), 8, NULL, CMD_LEN(2)}, 2136 2137 {"MI_STORE_URM_MEM", OP_MI_STORE_URM_MEM, F_LEN_VAR, R_RCS, D_ALL, 2138 ADDR_FIX_1(2), 8, NULL}, 2139 2140 {"MI_OP_2E", OP_MI_2E, F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_BDW_PLUS, 2141 ADDR_FIX_2(1, 2), 8, cmd_handler_mi_op_2e, CMD_LEN(3)}, 2142 2143 {"MI_OP_2F", OP_MI_2F, F_LEN_VAR, R_ALL, D_BDW_PLUS, ADDR_FIX_1(1), 2144 8, cmd_handler_mi_op_2f}, 2145 2146 {"MI_BATCH_BUFFER_START", OP_MI_BATCH_BUFFER_START, 2147 F_IP_ADVANCE_CUSTOM, R_ALL, D_ALL, 0, 8, 2148 cmd_handler_mi_batch_buffer_start}, 2149 2150 {"MI_CONDITIONAL_BATCH_BUFFER_END", OP_MI_CONDITIONAL_BATCH_BUFFER_END, 2151 F_LEN_VAR | F_LEN_VAR_FIXED, R_ALL, D_ALL, ADDR_FIX_1(2), 8, 2152 cmd_handler_mi_conditional_batch_buffer_end, CMD_LEN(2)}, 2153 2154 {"MI_LOAD_SCAN_LINES_INCL", OP_MI_LOAD_SCAN_LINES_INCL, F_LEN_CONST, 2155 R_RCS | R_BCS, D_ALL, 0, 2, NULL}, 2156 2157 {"XY_SETUP_BLT", OP_XY_SETUP_BLT, F_LEN_VAR, R_BCS, D_ALL, 2158 ADDR_FIX_2(4, 7), 8, NULL}, 2159 2160 {"XY_SETUP_CLIP_BLT", OP_XY_SETUP_CLIP_BLT, F_LEN_VAR, R_BCS, D_ALL, 2161 0, 8, NULL}, 2162 2163 {"XY_SETUP_MONO_PATTERN_SL_BLT", OP_XY_SETUP_MONO_PATTERN_SL_BLT, 2164 F_LEN_VAR, R_BCS, D_ALL, ADDR_FIX_1(4), 8, NULL}, 2165 2166 {"XY_PIXEL_BLT", OP_XY_PIXEL_BLT, F_LEN_VAR, R_BCS, D_ALL, 0, 8, NULL}, 2167 2168 {"XY_SCANLINES_BLT", OP_XY_SCANLINES_BLT, F_LEN_VAR, R_BCS, D_ALL, 2169 0, 8, NULL}, 2170 2171 {"XY_TEXT_BLT", OP_XY_TEXT_BLT, F_LEN_VAR, R_BCS, D_ALL, 2172 ADDR_FIX_1(3), 8, NULL}, 2173 2174 {"XY_TEXT_IMMEDIATE_BLT", OP_XY_TEXT_IMMEDIATE_BLT, F_LEN_VAR, R_BCS, 2175 D_ALL, 0, 8, NULL}, 2176 2177 {"XY_COLOR_BLT", OP_XY_COLOR_BLT, F_LEN_VAR, R_BCS, D_ALL, 2178 ADDR_FIX_1(4), 8, NULL}, 2179 2180 {"XY_PAT_BLT", OP_XY_PAT_BLT, F_LEN_VAR, R_BCS, D_ALL, 2181 ADDR_FIX_2(4, 5), 8, NULL}, 2182 2183 {"XY_MONO_PAT_BLT", OP_XY_MONO_PAT_BLT, F_LEN_VAR, R_BCS, D_ALL, 2184 ADDR_FIX_1(4), 8, NULL}, 2185 2186 {"XY_SRC_COPY_BLT", OP_XY_SRC_COPY_BLT, F_LEN_VAR, R_BCS, D_ALL, 2187 ADDR_FIX_2(4, 7), 8, NULL}, 2188 2189 {"XY_MONO_SRC_COPY_BLT", OP_XY_MONO_SRC_COPY_BLT, F_LEN_VAR, R_BCS, 2190 D_ALL, ADDR_FIX_2(4, 5), 8, NULL}, 2191 2192 {"XY_FULL_BLT", OP_XY_FULL_BLT, F_LEN_VAR, R_BCS, D_ALL, 0, 8, NULL}, 2193 2194 {"XY_FULL_MONO_SRC_BLT", OP_XY_FULL_MONO_SRC_BLT, F_LEN_VAR, R_BCS, 2195 D_ALL, ADDR_FIX_3(4, 5, 8), 8, NULL}, 2196 2197 {"XY_FULL_MONO_PATTERN_BLT", OP_XY_FULL_MONO_PATTERN_BLT, F_LEN_VAR, 2198 R_BCS, D_ALL, ADDR_FIX_2(4, 7), 8, NULL}, 2199 2200 {"XY_FULL_MONO_PATTERN_MONO_SRC_BLT", 2201 OP_XY_FULL_MONO_PATTERN_MONO_SRC_BLT, 2202 F_LEN_VAR, R_BCS, D_ALL, ADDR_FIX_2(4, 5), 8, NULL}, 2203 2204 {"XY_MONO_PAT_FIXED_BLT", OP_XY_MONO_PAT_FIXED_BLT, F_LEN_VAR, R_BCS, 2205 D_ALL, ADDR_FIX_1(4), 8, NULL}, 2206 2207 {"XY_MONO_SRC_COPY_IMMEDIATE_BLT", OP_XY_MONO_SRC_COPY_IMMEDIATE_BLT, 2208 F_LEN_VAR, R_BCS, D_ALL, ADDR_FIX_1(4), 8, NULL}, 2209 2210 {"XY_PAT_BLT_IMMEDIATE", OP_XY_PAT_BLT_IMMEDIATE, F_LEN_VAR, R_BCS, 2211 D_ALL, ADDR_FIX_1(4), 8, NULL}, 2212 2213 {"XY_SRC_COPY_CHROMA_BLT", OP_XY_SRC_COPY_CHROMA_BLT, F_LEN_VAR, R_BCS, 2214 D_ALL, ADDR_FIX_2(4, 7), 8, NULL}, 2215 2216 {"XY_FULL_IMMEDIATE_PATTERN_BLT", OP_XY_FULL_IMMEDIATE_PATTERN_BLT, 2217 F_LEN_VAR, R_BCS, D_ALL, ADDR_FIX_2(4, 7), 8, NULL}, 2218 2219 {"XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT", 2220 OP_XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT, 2221 F_LEN_VAR, R_BCS, D_ALL, ADDR_FIX_2(4, 5), 8, NULL}, 2222 2223 {"XY_PAT_CHROMA_BLT", OP_XY_PAT_CHROMA_BLT, F_LEN_VAR, R_BCS, D_ALL, 2224 ADDR_FIX_2(4, 5), 8, NULL}, 2225 2226 {"XY_PAT_CHROMA_BLT_IMMEDIATE", OP_XY_PAT_CHROMA_BLT_IMMEDIATE, 2227 F_LEN_VAR, R_BCS, D_ALL, ADDR_FIX_1(4), 8, NULL}, 2228 2229 {"3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP", 2230 OP_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, 2231 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2232 2233 {"3DSTATE_VIEWPORT_STATE_POINTERS_CC", 2234 OP_3DSTATE_VIEWPORT_STATE_POINTERS_CC, 2235 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2236 2237 {"3DSTATE_BLEND_STATE_POINTERS", 2238 OP_3DSTATE_BLEND_STATE_POINTERS, 2239 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2240 2241 {"3DSTATE_DEPTH_STENCIL_STATE_POINTERS", 2242 OP_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, 2243 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2244 2245 {"3DSTATE_BINDING_TABLE_POINTERS_VS", 2246 OP_3DSTATE_BINDING_TABLE_POINTERS_VS, 2247 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2248 2249 {"3DSTATE_BINDING_TABLE_POINTERS_HS", 2250 OP_3DSTATE_BINDING_TABLE_POINTERS_HS, 2251 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2252 2253 {"3DSTATE_BINDING_TABLE_POINTERS_DS", 2254 OP_3DSTATE_BINDING_TABLE_POINTERS_DS, 2255 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2256 2257 {"3DSTATE_BINDING_TABLE_POINTERS_GS", 2258 OP_3DSTATE_BINDING_TABLE_POINTERS_GS, 2259 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2260 2261 {"3DSTATE_BINDING_TABLE_POINTERS_PS", 2262 OP_3DSTATE_BINDING_TABLE_POINTERS_PS, 2263 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2264 2265 {"3DSTATE_SAMPLER_STATE_POINTERS_VS", 2266 OP_3DSTATE_SAMPLER_STATE_POINTERS_VS, 2267 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2268 2269 {"3DSTATE_SAMPLER_STATE_POINTERS_HS", 2270 OP_3DSTATE_SAMPLER_STATE_POINTERS_HS, 2271 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2272 2273 {"3DSTATE_SAMPLER_STATE_POINTERS_DS", 2274 OP_3DSTATE_SAMPLER_STATE_POINTERS_DS, 2275 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2276 2277 {"3DSTATE_SAMPLER_STATE_POINTERS_GS", 2278 OP_3DSTATE_SAMPLER_STATE_POINTERS_GS, 2279 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2280 2281 {"3DSTATE_SAMPLER_STATE_POINTERS_PS", 2282 OP_3DSTATE_SAMPLER_STATE_POINTERS_PS, 2283 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2284 2285 {"3DSTATE_URB_VS", OP_3DSTATE_URB_VS, F_LEN_VAR, R_RCS, D_ALL, 2286 0, 8, NULL}, 2287 2288 {"3DSTATE_URB_HS", OP_3DSTATE_URB_HS, F_LEN_VAR, R_RCS, D_ALL, 2289 0, 8, NULL}, 2290 2291 {"3DSTATE_URB_DS", OP_3DSTATE_URB_DS, F_LEN_VAR, R_RCS, D_ALL, 2292 0, 8, NULL}, 2293 2294 {"3DSTATE_URB_GS", OP_3DSTATE_URB_GS, F_LEN_VAR, R_RCS, D_ALL, 2295 0, 8, NULL}, 2296 2297 {"3DSTATE_GATHER_CONSTANT_VS", OP_3DSTATE_GATHER_CONSTANT_VS, 2298 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2299 2300 {"3DSTATE_GATHER_CONSTANT_GS", OP_3DSTATE_GATHER_CONSTANT_GS, 2301 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2302 2303 {"3DSTATE_GATHER_CONSTANT_HS", OP_3DSTATE_GATHER_CONSTANT_HS, 2304 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2305 2306 {"3DSTATE_GATHER_CONSTANT_DS", OP_3DSTATE_GATHER_CONSTANT_DS, 2307 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2308 2309 {"3DSTATE_GATHER_CONSTANT_PS", OP_3DSTATE_GATHER_CONSTANT_PS, 2310 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2311 2312 {"3DSTATE_DX9_CONSTANTF_VS", OP_3DSTATE_DX9_CONSTANTF_VS, 2313 F_LEN_VAR, R_RCS, D_ALL, 0, 11, NULL}, 2314 2315 {"3DSTATE_DX9_CONSTANTF_PS", OP_3DSTATE_DX9_CONSTANTF_PS, 2316 F_LEN_VAR, R_RCS, D_ALL, 0, 11, NULL}, 2317 2318 {"3DSTATE_DX9_CONSTANTI_VS", OP_3DSTATE_DX9_CONSTANTI_VS, 2319 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2320 2321 {"3DSTATE_DX9_CONSTANTI_PS", OP_3DSTATE_DX9_CONSTANTI_PS, 2322 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2323 2324 {"3DSTATE_DX9_CONSTANTB_VS", OP_3DSTATE_DX9_CONSTANTB_VS, 2325 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2326 2327 {"3DSTATE_DX9_CONSTANTB_PS", OP_3DSTATE_DX9_CONSTANTB_PS, 2328 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2329 2330 {"3DSTATE_DX9_LOCAL_VALID_VS", OP_3DSTATE_DX9_LOCAL_VALID_VS, 2331 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2332 2333 {"3DSTATE_DX9_LOCAL_VALID_PS", OP_3DSTATE_DX9_LOCAL_VALID_PS, 2334 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2335 2336 {"3DSTATE_DX9_GENERATE_ACTIVE_VS", OP_3DSTATE_DX9_GENERATE_ACTIVE_VS, 2337 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2338 2339 {"3DSTATE_DX9_GENERATE_ACTIVE_PS", OP_3DSTATE_DX9_GENERATE_ACTIVE_PS, 2340 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2341 2342 {"3DSTATE_BINDING_TABLE_EDIT_VS", OP_3DSTATE_BINDING_TABLE_EDIT_VS, 2343 F_LEN_VAR, R_RCS, D_ALL, 0, 9, NULL}, 2344 2345 {"3DSTATE_BINDING_TABLE_EDIT_GS", OP_3DSTATE_BINDING_TABLE_EDIT_GS, 2346 F_LEN_VAR, R_RCS, D_ALL, 0, 9, NULL}, 2347 2348 {"3DSTATE_BINDING_TABLE_EDIT_HS", OP_3DSTATE_BINDING_TABLE_EDIT_HS, 2349 F_LEN_VAR, R_RCS, D_ALL, 0, 9, NULL}, 2350 2351 {"3DSTATE_BINDING_TABLE_EDIT_DS", OP_3DSTATE_BINDING_TABLE_EDIT_DS, 2352 F_LEN_VAR, R_RCS, D_ALL, 0, 9, NULL}, 2353 2354 {"3DSTATE_BINDING_TABLE_EDIT_PS", OP_3DSTATE_BINDING_TABLE_EDIT_PS, 2355 F_LEN_VAR, R_RCS, D_ALL, 0, 9, NULL}, 2356 2357 {"3DSTATE_VF_INSTANCING", OP_3DSTATE_VF_INSTANCING, F_LEN_VAR, R_RCS, 2358 D_BDW_PLUS, 0, 8, NULL}, 2359 2360 {"3DSTATE_VF_SGVS", OP_3DSTATE_VF_SGVS, F_LEN_VAR, R_RCS, D_BDW_PLUS, 0, 8, 2361 NULL}, 2362 2363 {"3DSTATE_VF_TOPOLOGY", OP_3DSTATE_VF_TOPOLOGY, F_LEN_VAR, R_RCS, 2364 D_BDW_PLUS, 0, 8, NULL}, 2365 2366 {"3DSTATE_WM_CHROMAKEY", OP_3DSTATE_WM_CHROMAKEY, F_LEN_VAR, R_RCS, 2367 D_BDW_PLUS, 0, 8, NULL}, 2368 2369 {"3DSTATE_PS_BLEND", OP_3DSTATE_PS_BLEND, F_LEN_VAR, R_RCS, D_BDW_PLUS, 0, 2370 8, NULL}, 2371 2372 {"3DSTATE_WM_DEPTH_STENCIL", OP_3DSTATE_WM_DEPTH_STENCIL, F_LEN_VAR, 2373 R_RCS, D_BDW_PLUS, 0, 8, NULL}, 2374 2375 {"3DSTATE_PS_EXTRA", OP_3DSTATE_PS_EXTRA, F_LEN_VAR, R_RCS, D_BDW_PLUS, 0, 2376 8, NULL}, 2377 2378 {"3DSTATE_RASTER", OP_3DSTATE_RASTER, F_LEN_VAR, R_RCS, D_BDW_PLUS, 0, 8, 2379 NULL}, 2380 2381 {"3DSTATE_SBE_SWIZ", OP_3DSTATE_SBE_SWIZ, F_LEN_VAR, R_RCS, D_BDW_PLUS, 0, 8, 2382 NULL}, 2383 2384 {"3DSTATE_WM_HZ_OP", OP_3DSTATE_WM_HZ_OP, F_LEN_VAR, R_RCS, D_BDW_PLUS, 0, 8, 2385 NULL}, 2386 2387 {"3DSTATE_VERTEX_BUFFERS", OP_3DSTATE_VERTEX_BUFFERS, F_LEN_VAR, R_RCS, 2388 D_BDW_PLUS, 0, 8, NULL}, 2389 2390 {"3DSTATE_VERTEX_ELEMENTS", OP_3DSTATE_VERTEX_ELEMENTS, F_LEN_VAR, 2391 R_RCS, D_ALL, 0, 8, NULL}, 2392 2393 {"3DSTATE_INDEX_BUFFER", OP_3DSTATE_INDEX_BUFFER, F_LEN_VAR, R_RCS, 2394 D_BDW_PLUS, ADDR_FIX_1(2), 8, NULL}, 2395 2396 {"3DSTATE_VF_STATISTICS", OP_3DSTATE_VF_STATISTICS, F_LEN_CONST, 2397 R_RCS, D_ALL, 0, 1, NULL}, 2398 2399 {"3DSTATE_VF", OP_3DSTATE_VF, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2400 2401 {"3DSTATE_CC_STATE_POINTERS", OP_3DSTATE_CC_STATE_POINTERS, F_LEN_VAR, 2402 R_RCS, D_ALL, 0, 8, NULL}, 2403 2404 {"3DSTATE_SCISSOR_STATE_POINTERS", OP_3DSTATE_SCISSOR_STATE_POINTERS, 2405 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2406 2407 {"3DSTATE_GS", OP_3DSTATE_GS, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2408 2409 {"3DSTATE_CLIP", OP_3DSTATE_CLIP, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2410 2411 {"3DSTATE_WM", OP_3DSTATE_WM, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2412 2413 {"3DSTATE_CONSTANT_GS", OP_3DSTATE_CONSTANT_GS, F_LEN_VAR, R_RCS, 2414 D_BDW_PLUS, 0, 8, NULL}, 2415 2416 {"3DSTATE_CONSTANT_PS", OP_3DSTATE_CONSTANT_PS, F_LEN_VAR, R_RCS, 2417 D_BDW_PLUS, 0, 8, NULL}, 2418 2419 {"3DSTATE_SAMPLE_MASK", OP_3DSTATE_SAMPLE_MASK, F_LEN_VAR, R_RCS, 2420 D_ALL, 0, 8, NULL}, 2421 2422 {"3DSTATE_CONSTANT_HS", OP_3DSTATE_CONSTANT_HS, F_LEN_VAR, R_RCS, 2423 D_BDW_PLUS, 0, 8, NULL}, 2424 2425 {"3DSTATE_CONSTANT_DS", OP_3DSTATE_CONSTANT_DS, F_LEN_VAR, R_RCS, 2426 D_BDW_PLUS, 0, 8, NULL}, 2427 2428 {"3DSTATE_HS", OP_3DSTATE_HS, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2429 2430 {"3DSTATE_TE", OP_3DSTATE_TE, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2431 2432 {"3DSTATE_DS", OP_3DSTATE_DS, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2433 2434 {"3DSTATE_STREAMOUT", OP_3DSTATE_STREAMOUT, F_LEN_VAR, R_RCS, 2435 D_ALL, 0, 8, NULL}, 2436 2437 {"3DSTATE_SBE", OP_3DSTATE_SBE, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2438 2439 {"3DSTATE_PS", OP_3DSTATE_PS, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2440 2441 {"3DSTATE_DRAWING_RECTANGLE", OP_3DSTATE_DRAWING_RECTANGLE, F_LEN_VAR, 2442 R_RCS, D_ALL, 0, 8, NULL}, 2443 2444 {"3DSTATE_SAMPLER_PALETTE_LOAD0", OP_3DSTATE_SAMPLER_PALETTE_LOAD0, 2445 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2446 2447 {"3DSTATE_CHROMA_KEY", OP_3DSTATE_CHROMA_KEY, F_LEN_VAR, R_RCS, D_ALL, 2448 0, 8, NULL}, 2449 2450 {"3DSTATE_DEPTH_BUFFER", OP_3DSTATE_DEPTH_BUFFER, F_LEN_VAR, R_RCS, 2451 D_ALL, ADDR_FIX_1(2), 8, NULL}, 2452 2453 {"3DSTATE_POLY_STIPPLE_OFFSET", OP_3DSTATE_POLY_STIPPLE_OFFSET, 2454 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2455 2456 {"3DSTATE_POLY_STIPPLE_PATTERN", OP_3DSTATE_POLY_STIPPLE_PATTERN, 2457 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2458 2459 {"3DSTATE_LINE_STIPPLE", OP_3DSTATE_LINE_STIPPLE, F_LEN_VAR, R_RCS, 2460 D_ALL, 0, 8, NULL}, 2461 2462 {"3DSTATE_AA_LINE_PARAMS", OP_3DSTATE_AA_LINE_PARAMS, F_LEN_VAR, R_RCS, 2463 D_ALL, 0, 8, NULL}, 2464 2465 {"3DSTATE_GS_SVB_INDEX", OP_3DSTATE_GS_SVB_INDEX, F_LEN_VAR, R_RCS, 2466 D_ALL, 0, 8, NULL}, 2467 2468 {"3DSTATE_SAMPLER_PALETTE_LOAD1", OP_3DSTATE_SAMPLER_PALETTE_LOAD1, 2469 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2470 2471 {"3DSTATE_MULTISAMPLE", OP_3DSTATE_MULTISAMPLE_BDW, F_LEN_VAR, R_RCS, 2472 D_BDW_PLUS, 0, 8, NULL}, 2473 2474 {"3DSTATE_STENCIL_BUFFER", OP_3DSTATE_STENCIL_BUFFER, F_LEN_VAR, R_RCS, 2475 D_ALL, ADDR_FIX_1(2), 8, NULL}, 2476 2477 {"3DSTATE_HIER_DEPTH_BUFFER", OP_3DSTATE_HIER_DEPTH_BUFFER, F_LEN_VAR, 2478 R_RCS, D_ALL, ADDR_FIX_1(2), 8, NULL}, 2479 2480 {"3DSTATE_CLEAR_PARAMS", OP_3DSTATE_CLEAR_PARAMS, F_LEN_VAR, 2481 R_RCS, D_ALL, 0, 8, NULL}, 2482 2483 {"3DSTATE_PUSH_CONSTANT_ALLOC_VS", OP_3DSTATE_PUSH_CONSTANT_ALLOC_VS, 2484 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2485 2486 {"3DSTATE_PUSH_CONSTANT_ALLOC_HS", OP_3DSTATE_PUSH_CONSTANT_ALLOC_HS, 2487 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2488 2489 {"3DSTATE_PUSH_CONSTANT_ALLOC_DS", OP_3DSTATE_PUSH_CONSTANT_ALLOC_DS, 2490 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2491 2492 {"3DSTATE_PUSH_CONSTANT_ALLOC_GS", OP_3DSTATE_PUSH_CONSTANT_ALLOC_GS, 2493 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2494 2495 {"3DSTATE_PUSH_CONSTANT_ALLOC_PS", OP_3DSTATE_PUSH_CONSTANT_ALLOC_PS, 2496 F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2497 2498 {"3DSTATE_MONOFILTER_SIZE", OP_3DSTATE_MONOFILTER_SIZE, F_LEN_VAR, 2499 R_RCS, D_ALL, 0, 8, NULL}, 2500 2501 {"3DSTATE_SO_DECL_LIST", OP_3DSTATE_SO_DECL_LIST, F_LEN_VAR, R_RCS, 2502 D_ALL, 0, 9, NULL}, 2503 2504 {"3DSTATE_SO_BUFFER", OP_3DSTATE_SO_BUFFER, F_LEN_VAR, R_RCS, D_BDW_PLUS, 2505 ADDR_FIX_2(2, 4), 8, NULL}, 2506 2507 {"3DSTATE_BINDING_TABLE_POOL_ALLOC", 2508 OP_3DSTATE_BINDING_TABLE_POOL_ALLOC, 2509 F_LEN_VAR, R_RCS, D_BDW_PLUS, ADDR_FIX_1(1), 8, NULL}, 2510 2511 {"3DSTATE_GATHER_POOL_ALLOC", OP_3DSTATE_GATHER_POOL_ALLOC, 2512 F_LEN_VAR, R_RCS, D_BDW_PLUS, ADDR_FIX_1(1), 8, NULL}, 2513 2514 {"3DSTATE_DX9_CONSTANT_BUFFER_POOL_ALLOC", 2515 OP_3DSTATE_DX9_CONSTANT_BUFFER_POOL_ALLOC, 2516 F_LEN_VAR, R_RCS, D_BDW_PLUS, ADDR_FIX_1(1), 8, NULL}, 2517 2518 {"3DSTATE_SAMPLE_PATTERN", OP_3DSTATE_SAMPLE_PATTERN, F_LEN_VAR, R_RCS, 2519 D_BDW_PLUS, 0, 8, NULL}, 2520 2521 {"PIPE_CONTROL", OP_PIPE_CONTROL, F_LEN_VAR, R_RCS, D_ALL, 2522 ADDR_FIX_1(2), 8, cmd_handler_pipe_control}, 2523 2524 {"3DPRIMITIVE", OP_3DPRIMITIVE, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2525 2526 {"PIPELINE_SELECT", OP_PIPELINE_SELECT, F_LEN_CONST, R_RCS, D_ALL, 0, 2527 1, NULL}, 2528 2529 {"STATE_PREFETCH", OP_STATE_PREFETCH, F_LEN_VAR, R_RCS, D_ALL, 2530 ADDR_FIX_1(1), 8, NULL}, 2531 2532 {"STATE_SIP", OP_STATE_SIP, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2533 2534 {"STATE_BASE_ADDRESS", OP_STATE_BASE_ADDRESS, F_LEN_VAR, R_RCS, D_BDW_PLUS, 2535 ADDR_FIX_5(1, 3, 4, 5, 6), 8, NULL}, 2536 2537 {"OP_3D_MEDIA_0_1_4", OP_3D_MEDIA_0_1_4, F_LEN_VAR, R_RCS, D_ALL, 2538 ADDR_FIX_1(1), 8, NULL}, 2539 2540 {"OP_SWTESS_BASE_ADDRESS", OP_SWTESS_BASE_ADDRESS, 2541 F_LEN_VAR, R_RCS, D_ALL, ADDR_FIX_2(1, 2), 3, NULL}, 2542 2543 {"3DSTATE_VS", OP_3DSTATE_VS, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2544 2545 {"3DSTATE_SF", OP_3DSTATE_SF, F_LEN_VAR, R_RCS, D_ALL, 0, 8, NULL}, 2546 2547 {"3DSTATE_CONSTANT_VS", OP_3DSTATE_CONSTANT_VS, F_LEN_VAR, R_RCS, D_BDW_PLUS, 2548 0, 8, NULL}, 2549 2550 {"3DSTATE_COMPONENT_PACKING", OP_3DSTATE_COMPONENT_PACKING, F_LEN_VAR, R_RCS, 2551 D_SKL_PLUS, 0, 8, NULL}, 2552 2553 {"MEDIA_INTERFACE_DESCRIPTOR_LOAD", OP_MEDIA_INTERFACE_DESCRIPTOR_LOAD, 2554 F_LEN_VAR, R_RCS, D_ALL, 0, 16, NULL}, 2555 2556 {"MEDIA_GATEWAY_STATE", OP_MEDIA_GATEWAY_STATE, F_LEN_VAR, R_RCS, D_ALL, 2557 0, 16, NULL}, 2558 2559 {"MEDIA_STATE_FLUSH", OP_MEDIA_STATE_FLUSH, F_LEN_VAR, R_RCS, D_ALL, 2560 0, 16, NULL}, 2561 2562 {"MEDIA_POOL_STATE", OP_MEDIA_POOL_STATE, F_LEN_VAR, R_RCS, D_ALL, 2563 0, 16, NULL}, 2564 2565 {"MEDIA_OBJECT", OP_MEDIA_OBJECT, F_LEN_VAR, R_RCS, D_ALL, 0, 16, NULL}, 2566 2567 {"MEDIA_CURBE_LOAD", OP_MEDIA_CURBE_LOAD, F_LEN_VAR, R_RCS, D_ALL, 2568 0, 16, NULL}, 2569 2570 {"MEDIA_OBJECT_PRT", OP_MEDIA_OBJECT_PRT, F_LEN_VAR, R_RCS, D_ALL, 2571 0, 16, NULL}, 2572 2573 {"MEDIA_OBJECT_WALKER", OP_MEDIA_OBJECT_WALKER, F_LEN_VAR, R_RCS, D_ALL, 2574 0, 16, NULL}, 2575 2576 {"GPGPU_WALKER", OP_GPGPU_WALKER, F_LEN_VAR, R_RCS, D_ALL, 2577 0, 8, NULL}, 2578 2579 {"MEDIA_VFE_STATE", OP_MEDIA_VFE_STATE, F_LEN_VAR, R_RCS, D_ALL, 0, 16, 2580 NULL}, 2581 2582 {"3DSTATE_VF_STATISTICS_GM45", OP_3DSTATE_VF_STATISTICS_GM45, 2583 F_LEN_CONST, R_ALL, D_ALL, 0, 1, NULL}, 2584 2585 {"MFX_PIPE_MODE_SELECT", OP_MFX_PIPE_MODE_SELECT, F_LEN_VAR, 2586 R_VCS, D_ALL, 0, 12, NULL}, 2587 2588 {"MFX_SURFACE_STATE", OP_MFX_SURFACE_STATE, F_LEN_VAR, 2589 R_VCS, D_ALL, 0, 12, NULL}, 2590 2591 {"MFX_PIPE_BUF_ADDR_STATE", OP_MFX_PIPE_BUF_ADDR_STATE, F_LEN_VAR, 2592 R_VCS, D_BDW_PLUS, 0, 12, NULL}, 2593 2594 {"MFX_IND_OBJ_BASE_ADDR_STATE", OP_MFX_IND_OBJ_BASE_ADDR_STATE, 2595 F_LEN_VAR, R_VCS, D_BDW_PLUS, 0, 12, NULL}, 2596 2597 {"MFX_BSP_BUF_BASE_ADDR_STATE", OP_MFX_BSP_BUF_BASE_ADDR_STATE, 2598 F_LEN_VAR, R_VCS, D_BDW_PLUS, ADDR_FIX_3(1, 3, 5), 12, NULL}, 2599 2600 {"OP_2_0_0_5", OP_2_0_0_5, F_LEN_VAR, R_VCS, D_BDW_PLUS, 0, 12, NULL}, 2601 2602 {"MFX_STATE_POINTER", OP_MFX_STATE_POINTER, F_LEN_VAR, 2603 R_VCS, D_ALL, 0, 12, NULL}, 2604 2605 {"MFX_QM_STATE", OP_MFX_QM_STATE, F_LEN_VAR, 2606 R_VCS, D_ALL, 0, 12, NULL}, 2607 2608 {"MFX_FQM_STATE", OP_MFX_FQM_STATE, F_LEN_VAR, 2609 R_VCS, D_ALL, 0, 12, NULL}, 2610 2611 {"MFX_PAK_INSERT_OBJECT", OP_MFX_PAK_INSERT_OBJECT, F_LEN_VAR, 2612 R_VCS, D_ALL, 0, 12, NULL}, 2613 2614 {"MFX_STITCH_OBJECT", OP_MFX_STITCH_OBJECT, F_LEN_VAR, 2615 R_VCS, D_ALL, 0, 12, NULL}, 2616 2617 {"MFD_IT_OBJECT", OP_MFD_IT_OBJECT, F_LEN_VAR, 2618 R_VCS, D_ALL, 0, 12, NULL}, 2619 2620 {"MFX_WAIT", OP_MFX_WAIT, F_LEN_VAR, 2621 R_VCS, D_ALL, 0, 6, NULL}, 2622 2623 {"MFX_AVC_IMG_STATE", OP_MFX_AVC_IMG_STATE, F_LEN_VAR, 2624 R_VCS, D_ALL, 0, 12, NULL}, 2625 2626 {"MFX_AVC_QM_STATE", OP_MFX_AVC_QM_STATE, F_LEN_VAR, 2627 R_VCS, D_ALL, 0, 12, NULL}, 2628 2629 {"MFX_AVC_DIRECTMODE_STATE", OP_MFX_AVC_DIRECTMODE_STATE, F_LEN_VAR, 2630 R_VCS, D_ALL, 0, 12, NULL}, 2631 2632 {"MFX_AVC_SLICE_STATE", OP_MFX_AVC_SLICE_STATE, F_LEN_VAR, 2633 R_VCS, D_ALL, 0, 12, NULL}, 2634 2635 {"MFX_AVC_REF_IDX_STATE", OP_MFX_AVC_REF_IDX_STATE, F_LEN_VAR, 2636 R_VCS, D_ALL, 0, 12, NULL}, 2637 2638 {"MFX_AVC_WEIGHTOFFSET_STATE", OP_MFX_AVC_WEIGHTOFFSET_STATE, F_LEN_VAR, 2639 R_VCS, D_ALL, 0, 12, NULL}, 2640 2641 {"MFD_AVC_PICID_STATE", OP_MFD_AVC_PICID_STATE, F_LEN_VAR, 2642 R_VCS, D_ALL, 0, 12, NULL}, 2643 {"MFD_AVC_DPB_STATE", OP_MFD_AVC_DPB_STATE, F_LEN_VAR, 2644 R_VCS, D_ALL, 0, 12, NULL}, 2645 2646 {"MFD_AVC_BSD_OBJECT", OP_MFD_AVC_BSD_OBJECT, F_LEN_VAR, 2647 R_VCS, D_ALL, 0, 12, NULL}, 2648 2649 {"MFD_AVC_SLICEADDR", OP_MFD_AVC_SLICEADDR, F_LEN_VAR, 2650 R_VCS, D_ALL, ADDR_FIX_1(2), 12, NULL}, 2651 2652 {"MFC_AVC_PAK_OBJECT", OP_MFC_AVC_PAK_OBJECT, F_LEN_VAR, 2653 R_VCS, D_ALL, 0, 12, NULL}, 2654 2655 {"MFX_VC1_PRED_PIPE_STATE", OP_MFX_VC1_PRED_PIPE_STATE, F_LEN_VAR, 2656 R_VCS, D_ALL, 0, 12, NULL}, 2657 2658 {"MFX_VC1_DIRECTMODE_STATE", OP_MFX_VC1_DIRECTMODE_STATE, F_LEN_VAR, 2659 R_VCS, D_ALL, 0, 12, NULL}, 2660 2661 {"MFD_VC1_SHORT_PIC_STATE", OP_MFD_VC1_SHORT_PIC_STATE, F_LEN_VAR, 2662 R_VCS, D_ALL, 0, 12, NULL}, 2663 2664 {"MFD_VC1_LONG_PIC_STATE", OP_MFD_VC1_LONG_PIC_STATE, F_LEN_VAR, 2665 R_VCS, D_ALL, 0, 12, NULL}, 2666 2667 {"MFD_VC1_BSD_OBJECT", OP_MFD_VC1_BSD_OBJECT, F_LEN_VAR, 2668 R_VCS, D_ALL, 0, 12, NULL}, 2669 2670 {"MFC_MPEG2_SLICEGROUP_STATE", OP_MFC_MPEG2_SLICEGROUP_STATE, F_LEN_VAR, 2671 R_VCS, D_ALL, 0, 12, NULL}, 2672 2673 {"MFC_MPEG2_PAK_OBJECT", OP_MFC_MPEG2_PAK_OBJECT, F_LEN_VAR, 2674 R_VCS, D_ALL, 0, 12, NULL}, 2675 2676 {"MFX_MPEG2_PIC_STATE", OP_MFX_MPEG2_PIC_STATE, F_LEN_VAR, 2677 R_VCS, D_ALL, 0, 12, NULL}, 2678 2679 {"MFX_MPEG2_QM_STATE", OP_MFX_MPEG2_QM_STATE, F_LEN_VAR, 2680 R_VCS, D_ALL, 0, 12, NULL}, 2681 2682 {"MFD_MPEG2_BSD_OBJECT", OP_MFD_MPEG2_BSD_OBJECT, F_LEN_VAR, 2683 R_VCS, D_ALL, 0, 12, NULL}, 2684 2685 {"MFX_2_6_0_0", OP_MFX_2_6_0_0, F_LEN_VAR, R_VCS, D_ALL, 2686 0, 16, NULL}, 2687 2688 {"MFX_2_6_0_9", OP_MFX_2_6_0_9, F_LEN_VAR, R_VCS, D_ALL, 0, 16, NULL}, 2689 2690 {"MFX_2_6_0_8", OP_MFX_2_6_0_8, F_LEN_VAR, R_VCS, D_ALL, 0, 16, NULL}, 2691 2692 {"MFX_JPEG_PIC_STATE", OP_MFX_JPEG_PIC_STATE, F_LEN_VAR, 2693 R_VCS, D_ALL, 0, 12, NULL}, 2694 2695 {"MFX_JPEG_HUFF_TABLE_STATE", OP_MFX_JPEG_HUFF_TABLE_STATE, F_LEN_VAR, 2696 R_VCS, D_ALL, 0, 12, NULL}, 2697 2698 {"MFD_JPEG_BSD_OBJECT", OP_MFD_JPEG_BSD_OBJECT, F_LEN_VAR, 2699 R_VCS, D_ALL, 0, 12, NULL}, 2700 2701 {"VEBOX_STATE", OP_VEB_STATE, F_LEN_VAR, R_VECS, D_ALL, 0, 12, NULL}, 2702 2703 {"VEBOX_SURFACE_STATE", OP_VEB_SURFACE_STATE, F_LEN_VAR, R_VECS, D_ALL, 2704 0, 12, NULL}, 2705 2706 {"VEB_DI_IECP", OP_VEB_DNDI_IECP_STATE, F_LEN_VAR, R_VECS, D_BDW_PLUS, 2707 0, 12, NULL}, 2708 }; 2709 2710 static void add_cmd_entry(struct intel_gvt *gvt, struct cmd_entry *e) 2711 { 2712 hash_add(gvt->cmd_table, &e->hlist, e->info->opcode); 2713 } 2714 2715 /* call the cmd handler, and advance ip */ 2716 static int cmd_parser_exec(struct parser_exec_state *s) 2717 { 2718 struct intel_vgpu *vgpu = s->vgpu; 2719 const struct cmd_info *info; 2720 u32 cmd; 2721 int ret = 0; 2722 2723 cmd = cmd_val(s, 0); 2724 2725 /* fastpath for MI_NOOP */ 2726 if (cmd == MI_NOOP) 2727 info = &cmd_info[mi_noop_index]; 2728 else 2729 info = get_cmd_info(s->vgpu->gvt, cmd, s->engine); 2730 2731 if (info == NULL) { 2732 gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x, addr_type=%s, ring %s, workload=%p\n", 2733 cmd, get_opcode(cmd, s->engine), 2734 repr_addr_type(s->buf_addr_type), 2735 s->engine->name, s->workload); 2736 return -EBADRQC; 2737 } 2738 2739 s->info = info; 2740 2741 trace_gvt_command(vgpu->id, s->engine->id, s->ip_gma, s->ip_va, 2742 cmd_length(s), s->buf_type, s->buf_addr_type, 2743 s->workload, info->name); 2744 2745 if ((info->flag & F_LEN_MASK) == F_LEN_VAR_FIXED) { 2746 ret = gvt_check_valid_cmd_length(cmd_length(s), 2747 info->valid_len); 2748 if (ret) 2749 return ret; 2750 } 2751 2752 if (info->handler) { 2753 ret = info->handler(s); 2754 if (ret < 0) { 2755 gvt_vgpu_err("%s handler error\n", info->name); 2756 return ret; 2757 } 2758 } 2759 2760 if (!(info->flag & F_IP_ADVANCE_CUSTOM)) { 2761 ret = cmd_advance_default(s); 2762 if (ret) { 2763 gvt_vgpu_err("%s IP advance error\n", info->name); 2764 return ret; 2765 } 2766 } 2767 return 0; 2768 } 2769 2770 static inline bool gma_out_of_range(unsigned long gma, 2771 unsigned long gma_head, unsigned int gma_tail) 2772 { 2773 if (gma_tail >= gma_head) 2774 return (gma < gma_head) || (gma > gma_tail); 2775 else 2776 return (gma > gma_tail) && (gma < gma_head); 2777 } 2778 2779 /* Keep the consistent return type, e.g EBADRQC for unknown 2780 * cmd, EFAULT for invalid address, EPERM for nonpriv. later 2781 * works as the input of VM healthy status. 2782 */ 2783 static int command_scan(struct parser_exec_state *s, 2784 unsigned long rb_head, unsigned long rb_tail, 2785 unsigned long rb_start, unsigned long rb_len) 2786 { 2787 2788 unsigned long gma_head, gma_tail, gma_bottom; 2789 int ret = 0; 2790 struct intel_vgpu *vgpu = s->vgpu; 2791 2792 gma_head = rb_start + rb_head; 2793 gma_tail = rb_start + rb_tail; 2794 gma_bottom = rb_start + rb_len; 2795 2796 while (s->ip_gma != gma_tail) { 2797 if (s->buf_type == RING_BUFFER_INSTRUCTION || 2798 s->buf_type == RING_BUFFER_CTX) { 2799 if (!(s->ip_gma >= rb_start) || 2800 !(s->ip_gma < gma_bottom)) { 2801 gvt_vgpu_err("ip_gma %lx out of ring scope." 2802 "(base:0x%lx, bottom: 0x%lx)\n", 2803 s->ip_gma, rb_start, 2804 gma_bottom); 2805 parser_exec_state_dump(s); 2806 return -EFAULT; 2807 } 2808 if (gma_out_of_range(s->ip_gma, gma_head, gma_tail)) { 2809 gvt_vgpu_err("ip_gma %lx out of range." 2810 "base 0x%lx head 0x%lx tail 0x%lx\n", 2811 s->ip_gma, rb_start, 2812 rb_head, rb_tail); 2813 parser_exec_state_dump(s); 2814 break; 2815 } 2816 } 2817 ret = cmd_parser_exec(s); 2818 if (ret) { 2819 gvt_vgpu_err("cmd parser error\n"); 2820 parser_exec_state_dump(s); 2821 break; 2822 } 2823 } 2824 2825 return ret; 2826 } 2827 2828 static int scan_workload(struct intel_vgpu_workload *workload) 2829 { 2830 unsigned long gma_head, gma_tail, gma_bottom; 2831 struct parser_exec_state s; 2832 int ret = 0; 2833 2834 /* ring base is page aligned */ 2835 if (WARN_ON(!IS_ALIGNED(workload->rb_start, I915_GTT_PAGE_SIZE))) 2836 return -EINVAL; 2837 2838 gma_head = workload->rb_start + workload->rb_head; 2839 gma_tail = workload->rb_start + workload->rb_tail; 2840 gma_bottom = workload->rb_start + _RING_CTL_BUF_SIZE(workload->rb_ctl); 2841 2842 s.buf_type = RING_BUFFER_INSTRUCTION; 2843 s.buf_addr_type = GTT_BUFFER; 2844 s.vgpu = workload->vgpu; 2845 s.engine = workload->engine; 2846 s.ring_start = workload->rb_start; 2847 s.ring_size = _RING_CTL_BUF_SIZE(workload->rb_ctl); 2848 s.ring_head = gma_head; 2849 s.ring_tail = gma_tail; 2850 s.rb_va = workload->shadow_ring_buffer_va; 2851 s.workload = workload; 2852 s.is_ctx_wa = false; 2853 2854 if (bypass_scan_mask & workload->engine->mask || gma_head == gma_tail) 2855 return 0; 2856 2857 ret = ip_gma_set(&s, gma_head); 2858 if (ret) 2859 goto out; 2860 2861 ret = command_scan(&s, workload->rb_head, workload->rb_tail, 2862 workload->rb_start, _RING_CTL_BUF_SIZE(workload->rb_ctl)); 2863 2864 out: 2865 return ret; 2866 } 2867 2868 static int scan_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx) 2869 { 2870 2871 unsigned long gma_head, gma_tail, gma_bottom, ring_size, ring_tail; 2872 struct parser_exec_state s; 2873 int ret = 0; 2874 struct intel_vgpu_workload *workload = container_of(wa_ctx, 2875 struct intel_vgpu_workload, 2876 wa_ctx); 2877 2878 /* ring base is page aligned */ 2879 if (WARN_ON(!IS_ALIGNED(wa_ctx->indirect_ctx.guest_gma, 2880 I915_GTT_PAGE_SIZE))) 2881 return -EINVAL; 2882 2883 ring_tail = wa_ctx->indirect_ctx.size + 3 * sizeof(u32); 2884 ring_size = round_up(wa_ctx->indirect_ctx.size + CACHELINE_BYTES, 2885 PAGE_SIZE); 2886 gma_head = wa_ctx->indirect_ctx.guest_gma; 2887 gma_tail = wa_ctx->indirect_ctx.guest_gma + ring_tail; 2888 gma_bottom = wa_ctx->indirect_ctx.guest_gma + ring_size; 2889 2890 s.buf_type = RING_BUFFER_INSTRUCTION; 2891 s.buf_addr_type = GTT_BUFFER; 2892 s.vgpu = workload->vgpu; 2893 s.engine = workload->engine; 2894 s.ring_start = wa_ctx->indirect_ctx.guest_gma; 2895 s.ring_size = ring_size; 2896 s.ring_head = gma_head; 2897 s.ring_tail = gma_tail; 2898 s.rb_va = wa_ctx->indirect_ctx.shadow_va; 2899 s.workload = workload; 2900 s.is_ctx_wa = true; 2901 2902 ret = ip_gma_set(&s, gma_head); 2903 if (ret) 2904 goto out; 2905 2906 ret = command_scan(&s, 0, ring_tail, 2907 wa_ctx->indirect_ctx.guest_gma, ring_size); 2908 out: 2909 return ret; 2910 } 2911 2912 static int shadow_workload_ring_buffer(struct intel_vgpu_workload *workload) 2913 { 2914 struct intel_vgpu *vgpu = workload->vgpu; 2915 struct intel_vgpu_submission *s = &vgpu->submission; 2916 unsigned long gma_head, gma_tail, gma_top, guest_rb_size; 2917 void *shadow_ring_buffer_va; 2918 int ret; 2919 2920 guest_rb_size = _RING_CTL_BUF_SIZE(workload->rb_ctl); 2921 2922 /* calculate workload ring buffer size */ 2923 workload->rb_len = (workload->rb_tail + guest_rb_size - 2924 workload->rb_head) % guest_rb_size; 2925 2926 gma_head = workload->rb_start + workload->rb_head; 2927 gma_tail = workload->rb_start + workload->rb_tail; 2928 gma_top = workload->rb_start + guest_rb_size; 2929 2930 if (workload->rb_len > s->ring_scan_buffer_size[workload->engine->id]) { 2931 void *p; 2932 2933 /* realloc the new ring buffer if needed */ 2934 p = krealloc(s->ring_scan_buffer[workload->engine->id], 2935 workload->rb_len, GFP_KERNEL); 2936 if (!p) { 2937 gvt_vgpu_err("fail to re-alloc ring scan buffer\n"); 2938 return -ENOMEM; 2939 } 2940 s->ring_scan_buffer[workload->engine->id] = p; 2941 s->ring_scan_buffer_size[workload->engine->id] = workload->rb_len; 2942 } 2943 2944 shadow_ring_buffer_va = s->ring_scan_buffer[workload->engine->id]; 2945 2946 /* get shadow ring buffer va */ 2947 workload->shadow_ring_buffer_va = shadow_ring_buffer_va; 2948 2949 /* head > tail --> copy head <-> top */ 2950 if (gma_head > gma_tail) { 2951 ret = copy_gma_to_hva(vgpu, vgpu->gtt.ggtt_mm, 2952 gma_head, gma_top, shadow_ring_buffer_va); 2953 if (ret < 0) { 2954 gvt_vgpu_err("fail to copy guest ring buffer\n"); 2955 return ret; 2956 } 2957 shadow_ring_buffer_va += ret; 2958 gma_head = workload->rb_start; 2959 } 2960 2961 /* copy head or start <-> tail */ 2962 ret = copy_gma_to_hva(vgpu, vgpu->gtt.ggtt_mm, gma_head, gma_tail, 2963 shadow_ring_buffer_va); 2964 if (ret < 0) { 2965 gvt_vgpu_err("fail to copy guest ring buffer\n"); 2966 return ret; 2967 } 2968 return 0; 2969 } 2970 2971 int intel_gvt_scan_and_shadow_ringbuffer(struct intel_vgpu_workload *workload) 2972 { 2973 int ret; 2974 struct intel_vgpu *vgpu = workload->vgpu; 2975 2976 ret = shadow_workload_ring_buffer(workload); 2977 if (ret) { 2978 gvt_vgpu_err("fail to shadow workload ring_buffer\n"); 2979 return ret; 2980 } 2981 2982 ret = scan_workload(workload); 2983 if (ret) { 2984 gvt_vgpu_err("scan workload error\n"); 2985 return ret; 2986 } 2987 return 0; 2988 } 2989 2990 static int shadow_indirect_ctx(struct intel_shadow_wa_ctx *wa_ctx) 2991 { 2992 int ctx_size = wa_ctx->indirect_ctx.size; 2993 unsigned long guest_gma = wa_ctx->indirect_ctx.guest_gma; 2994 struct intel_vgpu_workload *workload = container_of(wa_ctx, 2995 struct intel_vgpu_workload, 2996 wa_ctx); 2997 struct intel_vgpu *vgpu = workload->vgpu; 2998 struct drm_i915_gem_object *obj; 2999 int ret = 0; 3000 void *map; 3001 3002 obj = i915_gem_object_create_shmem(workload->engine->i915, 3003 roundup(ctx_size + CACHELINE_BYTES, 3004 PAGE_SIZE)); 3005 if (IS_ERR(obj)) 3006 return PTR_ERR(obj); 3007 3008 /* get the va of the shadow batch buffer */ 3009 map = i915_gem_object_pin_map(obj, I915_MAP_WB); 3010 if (IS_ERR(map)) { 3011 gvt_vgpu_err("failed to vmap shadow indirect ctx\n"); 3012 ret = PTR_ERR(map); 3013 goto put_obj; 3014 } 3015 3016 i915_gem_object_lock(obj, NULL); 3017 ret = i915_gem_object_set_to_cpu_domain(obj, false); 3018 i915_gem_object_unlock(obj); 3019 if (ret) { 3020 gvt_vgpu_err("failed to set shadow indirect ctx to CPU\n"); 3021 goto unmap_src; 3022 } 3023 3024 ret = copy_gma_to_hva(workload->vgpu, 3025 workload->vgpu->gtt.ggtt_mm, 3026 guest_gma, guest_gma + ctx_size, 3027 map); 3028 if (ret < 0) { 3029 gvt_vgpu_err("fail to copy guest indirect ctx\n"); 3030 goto unmap_src; 3031 } 3032 3033 wa_ctx->indirect_ctx.obj = obj; 3034 wa_ctx->indirect_ctx.shadow_va = map; 3035 return 0; 3036 3037 unmap_src: 3038 i915_gem_object_unpin_map(obj); 3039 put_obj: 3040 i915_gem_object_put(obj); 3041 return ret; 3042 } 3043 3044 static int combine_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx) 3045 { 3046 u32 per_ctx_start[CACHELINE_DWORDS] = {0}; 3047 unsigned char *bb_start_sva; 3048 3049 if (!wa_ctx->per_ctx.valid) 3050 return 0; 3051 3052 per_ctx_start[0] = 0x18800001; 3053 per_ctx_start[1] = wa_ctx->per_ctx.guest_gma; 3054 3055 bb_start_sva = (unsigned char *)wa_ctx->indirect_ctx.shadow_va + 3056 wa_ctx->indirect_ctx.size; 3057 3058 memcpy(bb_start_sva, per_ctx_start, CACHELINE_BYTES); 3059 3060 return 0; 3061 } 3062 3063 int intel_gvt_scan_and_shadow_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx) 3064 { 3065 int ret; 3066 struct intel_vgpu_workload *workload = container_of(wa_ctx, 3067 struct intel_vgpu_workload, 3068 wa_ctx); 3069 struct intel_vgpu *vgpu = workload->vgpu; 3070 3071 if (wa_ctx->indirect_ctx.size == 0) 3072 return 0; 3073 3074 ret = shadow_indirect_ctx(wa_ctx); 3075 if (ret) { 3076 gvt_vgpu_err("fail to shadow indirect ctx\n"); 3077 return ret; 3078 } 3079 3080 combine_wa_ctx(wa_ctx); 3081 3082 ret = scan_wa_ctx(wa_ctx); 3083 if (ret) { 3084 gvt_vgpu_err("scan wa ctx error\n"); 3085 return ret; 3086 } 3087 3088 return 0; 3089 } 3090 3091 /* generate dummy contexts by sending empty requests to HW, and let 3092 * the HW to fill Engine Contexts. This dummy contexts are used for 3093 * initialization purpose (update reg whitelist), so referred to as 3094 * init context here 3095 */ 3096 void intel_gvt_update_reg_whitelist(struct intel_vgpu *vgpu) 3097 { 3098 const unsigned long start = LRC_STATE_PN * PAGE_SIZE; 3099 struct intel_gvt *gvt = vgpu->gvt; 3100 struct intel_engine_cs *engine; 3101 enum intel_engine_id id; 3102 3103 if (gvt->is_reg_whitelist_updated) 3104 return; 3105 3106 /* scan init ctx to update cmd accessible list */ 3107 for_each_engine(engine, gvt->gt, id) { 3108 struct parser_exec_state s; 3109 void *vaddr; 3110 int ret; 3111 3112 if (!engine->default_state) 3113 continue; 3114 3115 vaddr = shmem_pin_map(engine->default_state); 3116 if (IS_ERR(vaddr)) { 3117 gvt_err("failed to map %s->default state, err:%zd\n", 3118 engine->name, PTR_ERR(vaddr)); 3119 return; 3120 } 3121 3122 s.buf_type = RING_BUFFER_CTX; 3123 s.buf_addr_type = GTT_BUFFER; 3124 s.vgpu = vgpu; 3125 s.engine = engine; 3126 s.ring_start = 0; 3127 s.ring_size = engine->context_size - start; 3128 s.ring_head = 0; 3129 s.ring_tail = s.ring_size; 3130 s.rb_va = vaddr + start; 3131 s.workload = NULL; 3132 s.is_ctx_wa = false; 3133 s.is_init_ctx = true; 3134 3135 /* skipping the first RING_CTX_SIZE(0x50) dwords */ 3136 ret = ip_gma_set(&s, RING_CTX_SIZE); 3137 if (ret == 0) { 3138 ret = command_scan(&s, 0, s.ring_size, 0, s.ring_size); 3139 if (ret) 3140 gvt_err("Scan init ctx error\n"); 3141 } 3142 3143 shmem_unpin_map(engine->default_state, vaddr); 3144 if (ret) 3145 return; 3146 } 3147 3148 gvt->is_reg_whitelist_updated = true; 3149 } 3150 3151 int intel_gvt_scan_engine_context(struct intel_vgpu_workload *workload) 3152 { 3153 struct intel_vgpu *vgpu = workload->vgpu; 3154 unsigned long gma_head, gma_tail, gma_start, ctx_size; 3155 struct parser_exec_state s; 3156 int ring_id = workload->engine->id; 3157 struct intel_context *ce = vgpu->submission.shadow[ring_id]; 3158 int ret; 3159 3160 GEM_BUG_ON(atomic_read(&ce->pin_count) < 0); 3161 3162 ctx_size = workload->engine->context_size - PAGE_SIZE; 3163 3164 /* Only ring contxt is loaded to HW for inhibit context, no need to 3165 * scan engine context 3166 */ 3167 if (is_inhibit_context(ce)) 3168 return 0; 3169 3170 gma_start = i915_ggtt_offset(ce->state) + LRC_STATE_PN*PAGE_SIZE; 3171 gma_head = 0; 3172 gma_tail = ctx_size; 3173 3174 s.buf_type = RING_BUFFER_CTX; 3175 s.buf_addr_type = GTT_BUFFER; 3176 s.vgpu = workload->vgpu; 3177 s.engine = workload->engine; 3178 s.ring_start = gma_start; 3179 s.ring_size = ctx_size; 3180 s.ring_head = gma_start + gma_head; 3181 s.ring_tail = gma_start + gma_tail; 3182 s.rb_va = ce->lrc_reg_state; 3183 s.workload = workload; 3184 s.is_ctx_wa = false; 3185 s.is_init_ctx = false; 3186 3187 /* don't scan the first RING_CTX_SIZE(0x50) dwords, as it's ring 3188 * context 3189 */ 3190 ret = ip_gma_set(&s, gma_start + gma_head + RING_CTX_SIZE); 3191 if (ret) 3192 goto out; 3193 3194 ret = command_scan(&s, gma_head, gma_tail, 3195 gma_start, ctx_size); 3196 out: 3197 if (ret) 3198 gvt_vgpu_err("scan shadow ctx error\n"); 3199 3200 return ret; 3201 } 3202 3203 static int init_cmd_table(struct intel_gvt *gvt) 3204 { 3205 unsigned int gen_type = intel_gvt_get_device_type(gvt); 3206 int i; 3207 3208 for (i = 0; i < ARRAY_SIZE(cmd_info); i++) { 3209 struct cmd_entry *e; 3210 3211 if (!(cmd_info[i].devices & gen_type)) 3212 continue; 3213 3214 e = kzalloc(sizeof(*e), GFP_KERNEL); 3215 if (!e) 3216 return -ENOMEM; 3217 3218 e->info = &cmd_info[i]; 3219 if (cmd_info[i].opcode == OP_MI_NOOP) 3220 mi_noop_index = i; 3221 3222 INIT_HLIST_NODE(&e->hlist); 3223 add_cmd_entry(gvt, e); 3224 gvt_dbg_cmd("add %-30s op %04x flag %x devs %02x rings %02x\n", 3225 e->info->name, e->info->opcode, e->info->flag, 3226 e->info->devices, e->info->rings); 3227 } 3228 3229 return 0; 3230 } 3231 3232 static void clean_cmd_table(struct intel_gvt *gvt) 3233 { 3234 struct hlist_node *tmp; 3235 struct cmd_entry *e; 3236 int i; 3237 3238 hash_for_each_safe(gvt->cmd_table, i, tmp, e, hlist) 3239 kfree(e); 3240 3241 hash_init(gvt->cmd_table); 3242 } 3243 3244 void intel_gvt_clean_cmd_parser(struct intel_gvt *gvt) 3245 { 3246 clean_cmd_table(gvt); 3247 } 3248 3249 int intel_gvt_init_cmd_parser(struct intel_gvt *gvt) 3250 { 3251 int ret; 3252 3253 ret = init_cmd_table(gvt); 3254 if (ret) { 3255 intel_gvt_clean_cmd_parser(gvt); 3256 return ret; 3257 } 3258 return 0; 3259 } 3260