i915_cmd_parser.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. /*
  2. * Copyright © 2013 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Brad Volkin <bradley.d.volkin@intel.com>
  25. *
  26. */
  27. #include "i915_drv.h"
  28. /**
  29. * DOC: batch buffer command parser
  30. *
  31. * Motivation:
  32. * Certain OpenGL features (e.g. transform feedback, performance monitoring)
  33. * require userspace code to submit batches containing commands such as
  34. * MI_LOAD_REGISTER_IMM to access various registers. Unfortunately, some
  35. * generations of the hardware will noop these commands in "unsecure" batches
  36. * (which includes all userspace batches submitted via i915) even though the
  37. * commands may be safe and represent the intended programming model of the
  38. * device.
  39. *
  40. * The software command parser is similar in operation to the command parsing
  41. * done in hardware for unsecure batches. However, the software parser allows
  42. * some operations that would be noop'd by hardware, if the parser determines
  43. * the operation is safe, and submits the batch as "secure" to prevent hardware
  44. * parsing.
  45. *
  46. * Threats:
  47. * At a high level, the hardware (and software) checks attempt to prevent
  48. * granting userspace undue privileges. There are three categories of privilege.
  49. *
  50. * First, commands which are explicitly defined as privileged or which should
  51. * only be used by the kernel driver. The parser generally rejects such
  52. * commands, though it may allow some from the drm master process.
  53. *
  54. * Second, commands which access registers. To support correct/enhanced
  55. * userspace functionality, particularly certain OpenGL extensions, the parser
  56. * provides a whitelist of registers which userspace may safely access (for both
  57. * normal and drm master processes).
  58. *
  59. * Third, commands which access privileged memory (i.e. GGTT, HWS page, etc).
  60. * The parser always rejects such commands.
  61. *
  62. * The majority of the problematic commands fall in the MI_* range, with only a
  63. * few specific commands on each ring (e.g. PIPE_CONTROL and MI_FLUSH_DW).
  64. *
  65. * Implementation:
  66. * Each ring maintains tables of commands and registers which the parser uses in
  67. * scanning batch buffers submitted to that ring.
  68. *
  69. * Since the set of commands that the parser must check for is significantly
  70. * smaller than the number of commands supported, the parser tables contain only
  71. * those commands required by the parser. This generally works because command
  72. * opcode ranges have standard command length encodings. So for commands that
  73. * the parser does not need to check, it can easily skip them. This is
  74. * implemented via a per-ring length decoding vfunc.
  75. *
  76. * Unfortunately, there are a number of commands that do not follow the standard
  77. * length encoding for their opcode range, primarily amongst the MI_* commands.
  78. * To handle this, the parser provides a way to define explicit "skip" entries
  79. * in the per-ring command tables.
  80. *
  81. * Other command table entries map fairly directly to high level categories
  82. * mentioned above: rejected, master-only, register whitelist. The parser
  83. * implements a number of checks, including the privileged memory checks, via a
  84. * general bitmasking mechanism.
  85. */
  86. #define STD_MI_OPCODE_MASK 0xFF800000
  87. #define STD_3D_OPCODE_MASK 0xFFFF0000
  88. #define STD_2D_OPCODE_MASK 0xFFC00000
  89. #define STD_MFX_OPCODE_MASK 0xFFFF0000
  90. #define CMD(op, opm, f, lm, fl, ...) \
  91. { \
  92. .flags = (fl) | ((f) ? CMD_DESC_FIXED : 0), \
  93. .cmd = { (op), (opm) }, \
  94. .length = { (lm) }, \
  95. __VA_ARGS__ \
  96. }
  97. /* Convenience macros to compress the tables */
  98. #define SMI STD_MI_OPCODE_MASK
  99. #define S3D STD_3D_OPCODE_MASK
  100. #define S2D STD_2D_OPCODE_MASK
  101. #define SMFX STD_MFX_OPCODE_MASK
  102. #define F true
  103. #define S CMD_DESC_SKIP
  104. #define R CMD_DESC_REJECT
  105. #define W CMD_DESC_REGISTER
  106. #define B CMD_DESC_BITMASK
  107. #define M CMD_DESC_MASTER
  108. /* Command Mask Fixed Len Action
  109. ---------------------------------------------------------- */
  110. static const struct drm_i915_cmd_descriptor common_cmds[] = {
  111. CMD( MI_NOOP, SMI, F, 1, S ),
  112. CMD( MI_USER_INTERRUPT, SMI, F, 1, R ),
  113. CMD( MI_WAIT_FOR_EVENT, SMI, F, 1, M ),
  114. CMD( MI_ARB_CHECK, SMI, F, 1, S ),
  115. CMD( MI_REPORT_HEAD, SMI, F, 1, S ),
  116. CMD( MI_SUSPEND_FLUSH, SMI, F, 1, S ),
  117. CMD( MI_SEMAPHORE_MBOX, SMI, !F, 0xFF, R ),
  118. CMD( MI_STORE_DWORD_INDEX, SMI, !F, 0xFF, R ),
  119. CMD( MI_LOAD_REGISTER_IMM(1), SMI, !F, 0xFF, W,
  120. .reg = { .offset = 1, .mask = 0x007FFFFC } ),
  121. CMD( MI_STORE_REGISTER_MEM(1), SMI, !F, 0xFF, W | B,
  122. .reg = { .offset = 1, .mask = 0x007FFFFC },
  123. .bits = {{
  124. .offset = 0,
  125. .mask = MI_GLOBAL_GTT,
  126. .expected = 0,
  127. }}, ),
  128. CMD( MI_LOAD_REGISTER_MEM, SMI, !F, 0xFF, W | B,
  129. .reg = { .offset = 1, .mask = 0x007FFFFC },
  130. .bits = {{
  131. .offset = 0,
  132. .mask = MI_GLOBAL_GTT,
  133. .expected = 0,
  134. }}, ),
  135. /*
  136. * MI_BATCH_BUFFER_START requires some special handling. It's not
  137. * really a 'skip' action but it doesn't seem like it's worth adding
  138. * a new action. See i915_parse_cmds().
  139. */
  140. CMD( MI_BATCH_BUFFER_START, SMI, !F, 0xFF, S ),
  141. };
  142. static const struct drm_i915_cmd_descriptor render_cmds[] = {
  143. CMD( MI_FLUSH, SMI, F, 1, S ),
  144. CMD( MI_ARB_ON_OFF, SMI, F, 1, R ),
  145. CMD( MI_PREDICATE, SMI, F, 1, S ),
  146. CMD( MI_TOPOLOGY_FILTER, SMI, F, 1, S ),
  147. CMD( MI_DISPLAY_FLIP, SMI, !F, 0xFF, R ),
  148. CMD( MI_SET_APPID, SMI, F, 1, S ),
  149. CMD( MI_SET_CONTEXT, SMI, !F, 0xFF, R ),
  150. CMD( MI_URB_CLEAR, SMI, !F, 0xFF, S ),
  151. CMD( MI_STORE_DWORD_IMM, SMI, !F, 0x3F, B,
  152. .bits = {{
  153. .offset = 0,
  154. .mask = MI_GLOBAL_GTT,
  155. .expected = 0,
  156. }}, ),
  157. CMD( MI_UPDATE_GTT, SMI, !F, 0xFF, R ),
  158. CMD( MI_CLFLUSH, SMI, !F, 0x3FF, B,
  159. .bits = {{
  160. .offset = 0,
  161. .mask = MI_GLOBAL_GTT,
  162. .expected = 0,
  163. }}, ),
  164. CMD( MI_REPORT_PERF_COUNT, SMI, !F, 0x3F, B,
  165. .bits = {{
  166. .offset = 1,
  167. .mask = MI_REPORT_PERF_COUNT_GGTT,
  168. .expected = 0,
  169. }}, ),
  170. CMD( MI_CONDITIONAL_BATCH_BUFFER_END, SMI, !F, 0xFF, B,
  171. .bits = {{
  172. .offset = 0,
  173. .mask = MI_GLOBAL_GTT,
  174. .expected = 0,
  175. }}, ),
  176. CMD( GFX_OP_3DSTATE_VF_STATISTICS, S3D, F, 1, S ),
  177. CMD( PIPELINE_SELECT, S3D, F, 1, S ),
  178. CMD( MEDIA_VFE_STATE, S3D, !F, 0xFFFF, B,
  179. .bits = {{
  180. .offset = 2,
  181. .mask = MEDIA_VFE_STATE_MMIO_ACCESS_MASK,
  182. .expected = 0,
  183. }}, ),
  184. CMD( GPGPU_OBJECT, S3D, !F, 0xFF, S ),
  185. CMD( GPGPU_WALKER, S3D, !F, 0xFF, S ),
  186. CMD( GFX_OP_3DSTATE_SO_DECL_LIST, S3D, !F, 0x1FF, S ),
  187. CMD( GFX_OP_PIPE_CONTROL(5), S3D, !F, 0xFF, B,
  188. .bits = {{
  189. .offset = 1,
  190. .mask = (PIPE_CONTROL_MMIO_WRITE | PIPE_CONTROL_NOTIFY),
  191. .expected = 0,
  192. },
  193. {
  194. .offset = 1,
  195. .mask = (PIPE_CONTROL_GLOBAL_GTT_IVB |
  196. PIPE_CONTROL_STORE_DATA_INDEX),
  197. .expected = 0,
  198. .condition_offset = 1,
  199. .condition_mask = PIPE_CONTROL_POST_SYNC_OP_MASK,
  200. }}, ),
  201. };
  202. static const struct drm_i915_cmd_descriptor hsw_render_cmds[] = {
  203. CMD( MI_SET_PREDICATE, SMI, F, 1, S ),
  204. CMD( MI_RS_CONTROL, SMI, F, 1, S ),
  205. CMD( MI_URB_ATOMIC_ALLOC, SMI, F, 1, S ),
  206. CMD( MI_SET_APPID, SMI, F, 1, S ),
  207. CMD( MI_RS_CONTEXT, SMI, F, 1, S ),
  208. CMD( MI_LOAD_SCAN_LINES_INCL, SMI, !F, 0x3F, M ),
  209. CMD( MI_LOAD_SCAN_LINES_EXCL, SMI, !F, 0x3F, R ),
  210. CMD( MI_LOAD_REGISTER_REG, SMI, !F, 0xFF, R ),
  211. CMD( MI_RS_STORE_DATA_IMM, SMI, !F, 0xFF, S ),
  212. CMD( MI_LOAD_URB_MEM, SMI, !F, 0xFF, S ),
  213. CMD( MI_STORE_URB_MEM, SMI, !F, 0xFF, S ),
  214. CMD( GFX_OP_3DSTATE_DX9_CONSTANTF_VS, S3D, !F, 0x7FF, S ),
  215. CMD( GFX_OP_3DSTATE_DX9_CONSTANTF_PS, S3D, !F, 0x7FF, S ),
  216. CMD( GFX_OP_3DSTATE_BINDING_TABLE_EDIT_VS, S3D, !F, 0x1FF, S ),
  217. CMD( GFX_OP_3DSTATE_BINDING_TABLE_EDIT_GS, S3D, !F, 0x1FF, S ),
  218. CMD( GFX_OP_3DSTATE_BINDING_TABLE_EDIT_HS, S3D, !F, 0x1FF, S ),
  219. CMD( GFX_OP_3DSTATE_BINDING_TABLE_EDIT_DS, S3D, !F, 0x1FF, S ),
  220. CMD( GFX_OP_3DSTATE_BINDING_TABLE_EDIT_PS, S3D, !F, 0x1FF, S ),
  221. };
  222. static const struct drm_i915_cmd_descriptor video_cmds[] = {
  223. CMD( MI_ARB_ON_OFF, SMI, F, 1, R ),
  224. CMD( MI_SET_APPID, SMI, F, 1, S ),
  225. CMD( MI_STORE_DWORD_IMM, SMI, !F, 0xFF, B,
  226. .bits = {{
  227. .offset = 0,
  228. .mask = MI_GLOBAL_GTT,
  229. .expected = 0,
  230. }}, ),
  231. CMD( MI_UPDATE_GTT, SMI, !F, 0x3F, R ),
  232. CMD( MI_FLUSH_DW, SMI, !F, 0x3F, B,
  233. .bits = {{
  234. .offset = 0,
  235. .mask = MI_FLUSH_DW_NOTIFY,
  236. .expected = 0,
  237. },
  238. {
  239. .offset = 1,
  240. .mask = MI_FLUSH_DW_USE_GTT,
  241. .expected = 0,
  242. .condition_offset = 0,
  243. .condition_mask = MI_FLUSH_DW_OP_MASK,
  244. },
  245. {
  246. .offset = 0,
  247. .mask = MI_FLUSH_DW_STORE_INDEX,
  248. .expected = 0,
  249. .condition_offset = 0,
  250. .condition_mask = MI_FLUSH_DW_OP_MASK,
  251. }}, ),
  252. CMD( MI_CONDITIONAL_BATCH_BUFFER_END, SMI, !F, 0xFF, B,
  253. .bits = {{
  254. .offset = 0,
  255. .mask = MI_GLOBAL_GTT,
  256. .expected = 0,
  257. }}, ),
  258. /*
  259. * MFX_WAIT doesn't fit the way we handle length for most commands.
  260. * It has a length field but it uses a non-standard length bias.
  261. * It is always 1 dword though, so just treat it as fixed length.
  262. */
  263. CMD( MFX_WAIT, SMFX, F, 1, S ),
  264. };
  265. static const struct drm_i915_cmd_descriptor vecs_cmds[] = {
  266. CMD( MI_ARB_ON_OFF, SMI, F, 1, R ),
  267. CMD( MI_SET_APPID, SMI, F, 1, S ),
  268. CMD( MI_STORE_DWORD_IMM, SMI, !F, 0xFF, B,
  269. .bits = {{
  270. .offset = 0,
  271. .mask = MI_GLOBAL_GTT,
  272. .expected = 0,
  273. }}, ),
  274. CMD( MI_UPDATE_GTT, SMI, !F, 0x3F, R ),
  275. CMD( MI_FLUSH_DW, SMI, !F, 0x3F, B,
  276. .bits = {{
  277. .offset = 0,
  278. .mask = MI_FLUSH_DW_NOTIFY,
  279. .expected = 0,
  280. },
  281. {
  282. .offset = 1,
  283. .mask = MI_FLUSH_DW_USE_GTT,
  284. .expected = 0,
  285. .condition_offset = 0,
  286. .condition_mask = MI_FLUSH_DW_OP_MASK,
  287. },
  288. {
  289. .offset = 0,
  290. .mask = MI_FLUSH_DW_STORE_INDEX,
  291. .expected = 0,
  292. .condition_offset = 0,
  293. .condition_mask = MI_FLUSH_DW_OP_MASK,
  294. }}, ),
  295. CMD( MI_CONDITIONAL_BATCH_BUFFER_END, SMI, !F, 0xFF, B,
  296. .bits = {{
  297. .offset = 0,
  298. .mask = MI_GLOBAL_GTT,
  299. .expected = 0,
  300. }}, ),
  301. };
  302. static const struct drm_i915_cmd_descriptor blt_cmds[] = {
  303. CMD( MI_DISPLAY_FLIP, SMI, !F, 0xFF, R ),
  304. CMD( MI_STORE_DWORD_IMM, SMI, !F, 0x3FF, B,
  305. .bits = {{
  306. .offset = 0,
  307. .mask = MI_GLOBAL_GTT,
  308. .expected = 0,
  309. }}, ),
  310. CMD( MI_UPDATE_GTT, SMI, !F, 0x3F, R ),
  311. CMD( MI_FLUSH_DW, SMI, !F, 0x3F, B,
  312. .bits = {{
  313. .offset = 0,
  314. .mask = MI_FLUSH_DW_NOTIFY,
  315. .expected = 0,
  316. },
  317. {
  318. .offset = 1,
  319. .mask = MI_FLUSH_DW_USE_GTT,
  320. .expected = 0,
  321. .condition_offset = 0,
  322. .condition_mask = MI_FLUSH_DW_OP_MASK,
  323. },
  324. {
  325. .offset = 0,
  326. .mask = MI_FLUSH_DW_STORE_INDEX,
  327. .expected = 0,
  328. .condition_offset = 0,
  329. .condition_mask = MI_FLUSH_DW_OP_MASK,
  330. }}, ),
  331. CMD( COLOR_BLT, S2D, !F, 0x3F, S ),
  332. CMD( SRC_COPY_BLT, S2D, !F, 0x3F, S ),
  333. };
  334. static const struct drm_i915_cmd_descriptor hsw_blt_cmds[] = {
  335. CMD( MI_LOAD_SCAN_LINES_INCL, SMI, !F, 0x3F, M ),
  336. CMD( MI_LOAD_SCAN_LINES_EXCL, SMI, !F, 0x3F, R ),
  337. };
  338. #undef CMD
  339. #undef SMI
  340. #undef S3D
  341. #undef S2D
  342. #undef SMFX
  343. #undef F
  344. #undef S
  345. #undef R
  346. #undef W
  347. #undef B
  348. #undef M
  349. static const struct drm_i915_cmd_table gen7_render_cmds[] = {
  350. { common_cmds, ARRAY_SIZE(common_cmds) },
  351. { render_cmds, ARRAY_SIZE(render_cmds) },
  352. };
  353. static const struct drm_i915_cmd_table hsw_render_ring_cmds[] = {
  354. { common_cmds, ARRAY_SIZE(common_cmds) },
  355. { render_cmds, ARRAY_SIZE(render_cmds) },
  356. { hsw_render_cmds, ARRAY_SIZE(hsw_render_cmds) },
  357. };
  358. static const struct drm_i915_cmd_table gen7_video_cmds[] = {
  359. { common_cmds, ARRAY_SIZE(common_cmds) },
  360. { video_cmds, ARRAY_SIZE(video_cmds) },
  361. };
  362. static const struct drm_i915_cmd_table hsw_vebox_cmds[] = {
  363. { common_cmds, ARRAY_SIZE(common_cmds) },
  364. { vecs_cmds, ARRAY_SIZE(vecs_cmds) },
  365. };
  366. static const struct drm_i915_cmd_table gen7_blt_cmds[] = {
  367. { common_cmds, ARRAY_SIZE(common_cmds) },
  368. { blt_cmds, ARRAY_SIZE(blt_cmds) },
  369. };
  370. static const struct drm_i915_cmd_table hsw_blt_ring_cmds[] = {
  371. { common_cmds, ARRAY_SIZE(common_cmds) },
  372. { blt_cmds, ARRAY_SIZE(blt_cmds) },
  373. { hsw_blt_cmds, ARRAY_SIZE(hsw_blt_cmds) },
  374. };
  375. /*
  376. * Register whitelists, sorted by increasing register offset.
  377. *
  378. * Some registers that userspace accesses are 64 bits. The register
  379. * access commands only allow 32-bit accesses. Hence, we have to include
  380. * entries for both halves of the 64-bit registers.
  381. */
  382. /* Convenience macro for adding 64-bit registers */
  383. #define REG64(addr) (addr), (addr + sizeof(u32))
  384. static const u32 gen7_render_regs[] = {
  385. REG64(HS_INVOCATION_COUNT),
  386. REG64(DS_INVOCATION_COUNT),
  387. REG64(IA_VERTICES_COUNT),
  388. REG64(IA_PRIMITIVES_COUNT),
  389. REG64(VS_INVOCATION_COUNT),
  390. REG64(GS_INVOCATION_COUNT),
  391. REG64(GS_PRIMITIVES_COUNT),
  392. REG64(CL_INVOCATION_COUNT),
  393. REG64(CL_PRIMITIVES_COUNT),
  394. REG64(PS_INVOCATION_COUNT),
  395. REG64(PS_DEPTH_COUNT),
  396. OACONTROL, /* Only allowed for LRI and SRM. See below. */
  397. REG64(MI_PREDICATE_SRC0),
  398. REG64(MI_PREDICATE_SRC1),
  399. GEN7_3DPRIM_END_OFFSET,
  400. GEN7_3DPRIM_START_VERTEX,
  401. GEN7_3DPRIM_VERTEX_COUNT,
  402. GEN7_3DPRIM_INSTANCE_COUNT,
  403. GEN7_3DPRIM_START_INSTANCE,
  404. GEN7_3DPRIM_BASE_VERTEX,
  405. REG64(GEN7_SO_NUM_PRIMS_WRITTEN(0)),
  406. REG64(GEN7_SO_NUM_PRIMS_WRITTEN(1)),
  407. REG64(GEN7_SO_NUM_PRIMS_WRITTEN(2)),
  408. REG64(GEN7_SO_NUM_PRIMS_WRITTEN(3)),
  409. REG64(GEN7_SO_PRIM_STORAGE_NEEDED(0)),
  410. REG64(GEN7_SO_PRIM_STORAGE_NEEDED(1)),
  411. REG64(GEN7_SO_PRIM_STORAGE_NEEDED(2)),
  412. REG64(GEN7_SO_PRIM_STORAGE_NEEDED(3)),
  413. GEN7_SO_WRITE_OFFSET(0),
  414. GEN7_SO_WRITE_OFFSET(1),
  415. GEN7_SO_WRITE_OFFSET(2),
  416. GEN7_SO_WRITE_OFFSET(3),
  417. GEN7_L3SQCREG1,
  418. GEN7_L3CNTLREG2,
  419. GEN7_L3CNTLREG3,
  420. };
  421. static const u32 gen7_blt_regs[] = {
  422. BCS_SWCTRL,
  423. };
  424. static const u32 ivb_master_regs[] = {
  425. FORCEWAKE_MT,
  426. DERRMR,
  427. GEN7_PIPE_DE_LOAD_SL(PIPE_A),
  428. GEN7_PIPE_DE_LOAD_SL(PIPE_B),
  429. GEN7_PIPE_DE_LOAD_SL(PIPE_C),
  430. };
  431. static const u32 hsw_master_regs[] = {
  432. FORCEWAKE_MT,
  433. DERRMR,
  434. };
  435. #undef REG64
  436. static u32 gen7_render_get_cmd_length_mask(u32 cmd_header)
  437. {
  438. u32 client = (cmd_header & INSTR_CLIENT_MASK) >> INSTR_CLIENT_SHIFT;
  439. u32 subclient =
  440. (cmd_header & INSTR_SUBCLIENT_MASK) >> INSTR_SUBCLIENT_SHIFT;
  441. if (client == INSTR_MI_CLIENT)
  442. return 0x3F;
  443. else if (client == INSTR_RC_CLIENT) {
  444. if (subclient == INSTR_MEDIA_SUBCLIENT)
  445. return 0xFFFF;
  446. else
  447. return 0xFF;
  448. }
  449. DRM_DEBUG_DRIVER("CMD: Abnormal rcs cmd length! 0x%08X\n", cmd_header);
  450. return 0;
  451. }
  452. static u32 gen7_bsd_get_cmd_length_mask(u32 cmd_header)
  453. {
  454. u32 client = (cmd_header & INSTR_CLIENT_MASK) >> INSTR_CLIENT_SHIFT;
  455. u32 subclient =
  456. (cmd_header & INSTR_SUBCLIENT_MASK) >> INSTR_SUBCLIENT_SHIFT;
  457. u32 op = (cmd_header & INSTR_26_TO_24_MASK) >> INSTR_26_TO_24_SHIFT;
  458. if (client == INSTR_MI_CLIENT)
  459. return 0x3F;
  460. else if (client == INSTR_RC_CLIENT) {
  461. if (subclient == INSTR_MEDIA_SUBCLIENT) {
  462. if (op == 6)
  463. return 0xFFFF;
  464. else
  465. return 0xFFF;
  466. } else
  467. return 0xFF;
  468. }
  469. DRM_DEBUG_DRIVER("CMD: Abnormal bsd cmd length! 0x%08X\n", cmd_header);
  470. return 0;
  471. }
  472. static u32 gen7_blt_get_cmd_length_mask(u32 cmd_header)
  473. {
  474. u32 client = (cmd_header & INSTR_CLIENT_MASK) >> INSTR_CLIENT_SHIFT;
  475. if (client == INSTR_MI_CLIENT)
  476. return 0x3F;
  477. else if (client == INSTR_BC_CLIENT)
  478. return 0xFF;
  479. DRM_DEBUG_DRIVER("CMD: Abnormal blt cmd length! 0x%08X\n", cmd_header);
  480. return 0;
  481. }
  482. static bool validate_cmds_sorted(struct intel_engine_cs *ring,
  483. const struct drm_i915_cmd_table *cmd_tables,
  484. int cmd_table_count)
  485. {
  486. int i;
  487. bool ret = true;
  488. if (!cmd_tables || cmd_table_count == 0)
  489. return true;
  490. for (i = 0; i < cmd_table_count; i++) {
  491. const struct drm_i915_cmd_table *table = &cmd_tables[i];
  492. u32 previous = 0;
  493. int j;
  494. for (j = 0; j < table->count; j++) {
  495. const struct drm_i915_cmd_descriptor *desc =
  496. &table->table[i];
  497. u32 curr = desc->cmd.value & desc->cmd.mask;
  498. if (curr < previous) {
  499. DRM_ERROR("CMD: table not sorted ring=%d table=%d entry=%d cmd=0x%08X prev=0x%08X\n",
  500. ring->id, i, j, curr, previous);
  501. ret = false;
  502. }
  503. previous = curr;
  504. }
  505. }
  506. return ret;
  507. }
  508. static bool check_sorted(int ring_id, const u32 *reg_table, int reg_count)
  509. {
  510. int i;
  511. u32 previous = 0;
  512. bool ret = true;
  513. for (i = 0; i < reg_count; i++) {
  514. u32 curr = reg_table[i];
  515. if (curr < previous) {
  516. DRM_ERROR("CMD: table not sorted ring=%d entry=%d reg=0x%08X prev=0x%08X\n",
  517. ring_id, i, curr, previous);
  518. ret = false;
  519. }
  520. previous = curr;
  521. }
  522. return ret;
  523. }
  524. static bool validate_regs_sorted(struct intel_engine_cs *ring)
  525. {
  526. return check_sorted(ring->id, ring->reg_table, ring->reg_count) &&
  527. check_sorted(ring->id, ring->master_reg_table,
  528. ring->master_reg_count);
  529. }
  530. struct cmd_node {
  531. const struct drm_i915_cmd_descriptor *desc;
  532. struct hlist_node node;
  533. };
  534. /*
  535. * Different command ranges have different numbers of bits for the opcode. For
  536. * example, MI commands use bits 31:23 while 3D commands use bits 31:16. The
  537. * problem is that, for example, MI commands use bits 22:16 for other fields
  538. * such as GGTT vs PPGTT bits. If we include those bits in the mask then when
  539. * we mask a command from a batch it could hash to the wrong bucket due to
  540. * non-opcode bits being set. But if we don't include those bits, some 3D
  541. * commands may hash to the same bucket due to not including opcode bits that
  542. * make the command unique. For now, we will risk hashing to the same bucket.
  543. *
  544. * If we attempt to generate a perfect hash, we should be able to look at bits
  545. * 31:29 of a command from a batch buffer and use the full mask for that
  546. * client. The existing INSTR_CLIENT_MASK/SHIFT defines can be used for this.
  547. */
  548. #define CMD_HASH_MASK STD_MI_OPCODE_MASK
  549. static int init_hash_table(struct intel_engine_cs *ring,
  550. const struct drm_i915_cmd_table *cmd_tables,
  551. int cmd_table_count)
  552. {
  553. int i, j;
  554. hash_init(ring->cmd_hash);
  555. for (i = 0; i < cmd_table_count; i++) {
  556. const struct drm_i915_cmd_table *table = &cmd_tables[i];
  557. for (j = 0; j < table->count; j++) {
  558. const struct drm_i915_cmd_descriptor *desc =
  559. &table->table[j];
  560. struct cmd_node *desc_node =
  561. kmalloc(sizeof(*desc_node), GFP_KERNEL);
  562. if (!desc_node)
  563. return -ENOMEM;
  564. desc_node->desc = desc;
  565. hash_add(ring->cmd_hash, &desc_node->node,
  566. desc->cmd.value & CMD_HASH_MASK);
  567. }
  568. }
  569. return 0;
  570. }
  571. static void fini_hash_table(struct intel_engine_cs *ring)
  572. {
  573. struct hlist_node *tmp;
  574. struct cmd_node *desc_node;
  575. int i;
  576. hash_for_each_safe(ring->cmd_hash, i, tmp, desc_node, node) {
  577. hash_del(&desc_node->node);
  578. kfree(desc_node);
  579. }
  580. }
  581. /**
  582. * i915_cmd_parser_init_ring() - set cmd parser related fields for a ringbuffer
  583. * @ring: the ringbuffer to initialize
  584. *
  585. * Optionally initializes fields related to batch buffer command parsing in the
  586. * struct intel_engine_cs based on whether the platform requires software
  587. * command parsing.
  588. *
  589. * Return: non-zero if initialization fails
  590. */
  591. int i915_cmd_parser_init_ring(struct intel_engine_cs *ring)
  592. {
  593. const struct drm_i915_cmd_table *cmd_tables;
  594. int cmd_table_count;
  595. int ret;
  596. if (!IS_GEN7(ring->dev))
  597. return 0;
  598. switch (ring->id) {
  599. case RCS:
  600. if (IS_HASWELL(ring->dev)) {
  601. cmd_tables = hsw_render_ring_cmds;
  602. cmd_table_count =
  603. ARRAY_SIZE(hsw_render_ring_cmds);
  604. } else {
  605. cmd_tables = gen7_render_cmds;
  606. cmd_table_count = ARRAY_SIZE(gen7_render_cmds);
  607. }
  608. ring->reg_table = gen7_render_regs;
  609. ring->reg_count = ARRAY_SIZE(gen7_render_regs);
  610. if (IS_HASWELL(ring->dev)) {
  611. ring->master_reg_table = hsw_master_regs;
  612. ring->master_reg_count = ARRAY_SIZE(hsw_master_regs);
  613. } else {
  614. ring->master_reg_table = ivb_master_regs;
  615. ring->master_reg_count = ARRAY_SIZE(ivb_master_regs);
  616. }
  617. ring->get_cmd_length_mask = gen7_render_get_cmd_length_mask;
  618. break;
  619. case VCS:
  620. cmd_tables = gen7_video_cmds;
  621. cmd_table_count = ARRAY_SIZE(gen7_video_cmds);
  622. ring->get_cmd_length_mask = gen7_bsd_get_cmd_length_mask;
  623. break;
  624. case BCS:
  625. if (IS_HASWELL(ring->dev)) {
  626. cmd_tables = hsw_blt_ring_cmds;
  627. cmd_table_count = ARRAY_SIZE(hsw_blt_ring_cmds);
  628. } else {
  629. cmd_tables = gen7_blt_cmds;
  630. cmd_table_count = ARRAY_SIZE(gen7_blt_cmds);
  631. }
  632. ring->reg_table = gen7_blt_regs;
  633. ring->reg_count = ARRAY_SIZE(gen7_blt_regs);
  634. if (IS_HASWELL(ring->dev)) {
  635. ring->master_reg_table = hsw_master_regs;
  636. ring->master_reg_count = ARRAY_SIZE(hsw_master_regs);
  637. } else {
  638. ring->master_reg_table = ivb_master_regs;
  639. ring->master_reg_count = ARRAY_SIZE(ivb_master_regs);
  640. }
  641. ring->get_cmd_length_mask = gen7_blt_get_cmd_length_mask;
  642. break;
  643. case VECS:
  644. cmd_tables = hsw_vebox_cmds;
  645. cmd_table_count = ARRAY_SIZE(hsw_vebox_cmds);
  646. /* VECS can use the same length_mask function as VCS */
  647. ring->get_cmd_length_mask = gen7_bsd_get_cmd_length_mask;
  648. break;
  649. default:
  650. DRM_ERROR("CMD: cmd_parser_init with unknown ring: %d\n",
  651. ring->id);
  652. BUG();
  653. }
  654. BUG_ON(!validate_cmds_sorted(ring, cmd_tables, cmd_table_count));
  655. BUG_ON(!validate_regs_sorted(ring));
  656. WARN_ON(!hash_empty(ring->cmd_hash));
  657. ret = init_hash_table(ring, cmd_tables, cmd_table_count);
  658. if (ret) {
  659. DRM_ERROR("CMD: cmd_parser_init failed!\n");
  660. fini_hash_table(ring);
  661. return ret;
  662. }
  663. ring->needs_cmd_parser = true;
  664. return 0;
  665. }
  666. /**
  667. * i915_cmd_parser_fini_ring() - clean up cmd parser related fields
  668. * @ring: the ringbuffer to clean up
  669. *
  670. * Releases any resources related to command parsing that may have been
  671. * initialized for the specified ring.
  672. */
  673. void i915_cmd_parser_fini_ring(struct intel_engine_cs *ring)
  674. {
  675. if (!ring->needs_cmd_parser)
  676. return;
  677. fini_hash_table(ring);
  678. }
  679. static const struct drm_i915_cmd_descriptor*
  680. find_cmd_in_table(struct intel_engine_cs *ring,
  681. u32 cmd_header)
  682. {
  683. struct cmd_node *desc_node;
  684. hash_for_each_possible(ring->cmd_hash, desc_node, node,
  685. cmd_header & CMD_HASH_MASK) {
  686. const struct drm_i915_cmd_descriptor *desc = desc_node->desc;
  687. u32 masked_cmd = desc->cmd.mask & cmd_header;
  688. u32 masked_value = desc->cmd.value & desc->cmd.mask;
  689. if (masked_cmd == masked_value)
  690. return desc;
  691. }
  692. return NULL;
  693. }
  694. /*
  695. * Returns a pointer to a descriptor for the command specified by cmd_header.
  696. *
  697. * The caller must supply space for a default descriptor via the default_desc
  698. * parameter. If no descriptor for the specified command exists in the ring's
  699. * command parser tables, this function fills in default_desc based on the
  700. * ring's default length encoding and returns default_desc.
  701. */
  702. static const struct drm_i915_cmd_descriptor*
  703. find_cmd(struct intel_engine_cs *ring,
  704. u32 cmd_header,
  705. struct drm_i915_cmd_descriptor *default_desc)
  706. {
  707. const struct drm_i915_cmd_descriptor *desc;
  708. u32 mask;
  709. desc = find_cmd_in_table(ring, cmd_header);
  710. if (desc)
  711. return desc;
  712. mask = ring->get_cmd_length_mask(cmd_header);
  713. if (!mask)
  714. return NULL;
  715. BUG_ON(!default_desc);
  716. default_desc->flags = CMD_DESC_SKIP;
  717. default_desc->length.mask = mask;
  718. return default_desc;
  719. }
  720. static bool valid_reg(const u32 *table, int count, u32 addr)
  721. {
  722. if (table && count != 0) {
  723. int i;
  724. for (i = 0; i < count; i++) {
  725. if (table[i] == addr)
  726. return true;
  727. }
  728. }
  729. return false;
  730. }
  731. static u32 *vmap_batch(struct drm_i915_gem_object *obj)
  732. {
  733. int i;
  734. void *addr = NULL;
  735. struct sg_page_iter sg_iter;
  736. struct page **pages;
  737. pages = drm_malloc_ab(obj->base.size >> PAGE_SHIFT, sizeof(*pages));
  738. if (pages == NULL) {
  739. DRM_DEBUG_DRIVER("Failed to get space for pages\n");
  740. goto finish;
  741. }
  742. i = 0;
  743. for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, 0) {
  744. pages[i] = sg_page_iter_page(&sg_iter);
  745. i++;
  746. }
  747. addr = vmap(pages, i, 0, PAGE_KERNEL);
  748. if (addr == NULL) {
  749. DRM_DEBUG_DRIVER("Failed to vmap pages\n");
  750. goto finish;
  751. }
  752. finish:
  753. if (pages)
  754. drm_free_large(pages);
  755. return (u32*)addr;
  756. }
  757. /* Returns a vmap'd pointer to dest_obj, which the caller must unmap */
  758. static u32 *copy_batch(struct drm_i915_gem_object *dest_obj,
  759. struct drm_i915_gem_object *src_obj,
  760. u32 batch_start_offset,
  761. u32 batch_len)
  762. {
  763. int ret = 0;
  764. int needs_clflush = 0;
  765. u32 *src_base, *dest_base = NULL;
  766. u32 *src_addr, *dest_addr;
  767. u32 offset = batch_start_offset / sizeof(*dest_addr);
  768. u32 end = batch_start_offset + batch_len;
  769. if (end > dest_obj->base.size || end > src_obj->base.size)
  770. return ERR_PTR(-E2BIG);
  771. ret = i915_gem_obj_prepare_shmem_read(src_obj, &needs_clflush);
  772. if (ret) {
  773. DRM_DEBUG_DRIVER("CMD: failed to prep read\n");
  774. return ERR_PTR(ret);
  775. }
  776. src_base = vmap_batch(src_obj);
  777. if (!src_base) {
  778. DRM_DEBUG_DRIVER("CMD: Failed to vmap batch\n");
  779. ret = -ENOMEM;
  780. goto unpin_src;
  781. }
  782. src_addr = src_base + offset;
  783. if (needs_clflush)
  784. drm_clflush_virt_range((char *)src_addr, batch_len);
  785. ret = i915_gem_object_set_to_cpu_domain(dest_obj, true);
  786. if (ret) {
  787. DRM_DEBUG_DRIVER("CMD: Failed to set batch CPU domain\n");
  788. goto unmap_src;
  789. }
  790. dest_base = vmap_batch(dest_obj);
  791. if (!dest_base) {
  792. DRM_DEBUG_DRIVER("CMD: Failed to vmap shadow batch\n");
  793. ret = -ENOMEM;
  794. goto unmap_src;
  795. }
  796. dest_addr = dest_base + offset;
  797. if (batch_start_offset != 0)
  798. memset((u8 *)dest_base, 0, batch_start_offset);
  799. memcpy(dest_addr, src_addr, batch_len);
  800. memset((u8 *)dest_addr + batch_len, 0, dest_obj->base.size - end);
  801. unmap_src:
  802. vunmap(src_base);
  803. unpin_src:
  804. i915_gem_object_unpin_pages(src_obj);
  805. return ret ? ERR_PTR(ret) : dest_base;
  806. }
  807. /**
  808. * i915_needs_cmd_parser() - should a given ring use software command parsing?
  809. * @ring: the ring in question
  810. *
  811. * Only certain platforms require software batch buffer command parsing, and
  812. * only when enabled via module parameter.
  813. *
  814. * Return: true if the ring requires software command parsing
  815. */
  816. bool i915_needs_cmd_parser(struct intel_engine_cs *ring)
  817. {
  818. if (!ring->needs_cmd_parser)
  819. return false;
  820. if (!USES_PPGTT(ring->dev))
  821. return false;
  822. return (i915.enable_cmd_parser == 1);
  823. }
  824. static bool check_cmd(const struct intel_engine_cs *ring,
  825. const struct drm_i915_cmd_descriptor *desc,
  826. const u32 *cmd,
  827. const bool is_master,
  828. bool *oacontrol_set)
  829. {
  830. if (desc->flags & CMD_DESC_REJECT) {
  831. DRM_DEBUG_DRIVER("CMD: Rejected command: 0x%08X\n", *cmd);
  832. return false;
  833. }
  834. if ((desc->flags & CMD_DESC_MASTER) && !is_master) {
  835. DRM_DEBUG_DRIVER("CMD: Rejected master-only command: 0x%08X\n",
  836. *cmd);
  837. return false;
  838. }
  839. if (desc->flags & CMD_DESC_REGISTER) {
  840. u32 reg_addr = cmd[desc->reg.offset] & desc->reg.mask;
  841. /*
  842. * OACONTROL requires some special handling for writes. We
  843. * want to make sure that any batch which enables OA also
  844. * disables it before the end of the batch. The goal is to
  845. * prevent one process from snooping on the perf data from
  846. * another process. To do that, we need to check the value
  847. * that will be written to the register. Hence, limit
  848. * OACONTROL writes to only MI_LOAD_REGISTER_IMM commands.
  849. */
  850. if (reg_addr == OACONTROL) {
  851. if (desc->cmd.value == MI_LOAD_REGISTER_MEM) {
  852. DRM_DEBUG_DRIVER("CMD: Rejected LRM to OACONTROL\n");
  853. return false;
  854. }
  855. if (desc->cmd.value == MI_LOAD_REGISTER_IMM(1))
  856. *oacontrol_set = (cmd[2] != 0);
  857. }
  858. if (!valid_reg(ring->reg_table,
  859. ring->reg_count, reg_addr)) {
  860. if (!is_master ||
  861. !valid_reg(ring->master_reg_table,
  862. ring->master_reg_count,
  863. reg_addr)) {
  864. DRM_DEBUG_DRIVER("CMD: Rejected register 0x%08X in command: 0x%08X (ring=%d)\n",
  865. reg_addr,
  866. *cmd,
  867. ring->id);
  868. return false;
  869. }
  870. }
  871. }
  872. if (desc->flags & CMD_DESC_BITMASK) {
  873. int i;
  874. for (i = 0; i < MAX_CMD_DESC_BITMASKS; i++) {
  875. u32 dword;
  876. if (desc->bits[i].mask == 0)
  877. break;
  878. if (desc->bits[i].condition_mask != 0) {
  879. u32 offset =
  880. desc->bits[i].condition_offset;
  881. u32 condition = cmd[offset] &
  882. desc->bits[i].condition_mask;
  883. if (condition == 0)
  884. continue;
  885. }
  886. dword = cmd[desc->bits[i].offset] &
  887. desc->bits[i].mask;
  888. if (dword != desc->bits[i].expected) {
  889. DRM_DEBUG_DRIVER("CMD: Rejected command 0x%08X for bitmask 0x%08X (exp=0x%08X act=0x%08X) (ring=%d)\n",
  890. *cmd,
  891. desc->bits[i].mask,
  892. desc->bits[i].expected,
  893. dword, ring->id);
  894. return false;
  895. }
  896. }
  897. }
  898. return true;
  899. }
  900. #define LENGTH_BIAS 2
  901. /**
  902. * i915_parse_cmds() - parse a submitted batch buffer for privilege violations
  903. * @ring: the ring on which the batch is to execute
  904. * @batch_obj: the batch buffer in question
  905. * @shadow_batch_obj: copy of the batch buffer in question
  906. * @batch_start_offset: byte offset in the batch at which execution starts
  907. * @batch_len: length of the commands in batch_obj
  908. * @is_master: is the submitting process the drm master?
  909. *
  910. * Parses the specified batch buffer looking for privilege violations as
  911. * described in the overview.
  912. *
  913. * Return: non-zero if the parser finds violations or otherwise fails; -EACCES
  914. * if the batch appears legal but should use hardware parsing
  915. */
  916. int i915_parse_cmds(struct intel_engine_cs *ring,
  917. struct drm_i915_gem_object *batch_obj,
  918. struct drm_i915_gem_object *shadow_batch_obj,
  919. u32 batch_start_offset,
  920. u32 batch_len,
  921. bool is_master)
  922. {
  923. int ret = 0;
  924. u32 *cmd, *batch_base, *batch_end;
  925. struct drm_i915_cmd_descriptor default_desc = { 0 };
  926. bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
  927. batch_base = copy_batch(shadow_batch_obj, batch_obj,
  928. batch_start_offset, batch_len);
  929. if (IS_ERR(batch_base)) {
  930. DRM_DEBUG_DRIVER("CMD: Failed to copy batch\n");
  931. return PTR_ERR(batch_base);
  932. }
  933. cmd = batch_base + (batch_start_offset / sizeof(*cmd));
  934. /*
  935. * We use the batch length as size because the shadow object is as
  936. * large or larger and copy_batch() will write MI_NOPs to the extra
  937. * space. Parsing should be faster in some cases this way.
  938. */
  939. batch_end = cmd + (batch_len / sizeof(*batch_end));
  940. while (cmd < batch_end) {
  941. const struct drm_i915_cmd_descriptor *desc;
  942. u32 length;
  943. if (*cmd == MI_BATCH_BUFFER_END)
  944. break;
  945. desc = find_cmd(ring, *cmd, &default_desc);
  946. if (!desc) {
  947. DRM_DEBUG_DRIVER("CMD: Unrecognized command: 0x%08X\n",
  948. *cmd);
  949. ret = -EINVAL;
  950. break;
  951. }
  952. /*
  953. * If the batch buffer contains a chained batch, return an
  954. * error that tells the caller to abort and dispatch the
  955. * workload as a non-secure batch.
  956. */
  957. if (desc->cmd.value == MI_BATCH_BUFFER_START) {
  958. ret = -EACCES;
  959. break;
  960. }
  961. if (desc->flags & CMD_DESC_FIXED)
  962. length = desc->length.fixed;
  963. else
  964. length = ((*cmd & desc->length.mask) + LENGTH_BIAS);
  965. if ((batch_end - cmd) < length) {
  966. DRM_DEBUG_DRIVER("CMD: Command length exceeds batch length: 0x%08X length=%u batchlen=%td\n",
  967. *cmd,
  968. length,
  969. batch_end - cmd);
  970. ret = -EINVAL;
  971. break;
  972. }
  973. if (!check_cmd(ring, desc, cmd, is_master, &oacontrol_set)) {
  974. ret = -EINVAL;
  975. break;
  976. }
  977. cmd += length;
  978. }
  979. if (oacontrol_set) {
  980. DRM_DEBUG_DRIVER("CMD: batch set OACONTROL but did not clear it\n");
  981. ret = -EINVAL;
  982. }
  983. if (cmd >= batch_end) {
  984. DRM_DEBUG_DRIVER("CMD: Got to the end of the buffer w/o a BBE cmd!\n");
  985. ret = -EINVAL;
  986. }
  987. vunmap(batch_base);
  988. return ret;
  989. }
  990. /**
  991. * i915_cmd_parser_get_version() - get the cmd parser version number
  992. *
  993. * The cmd parser maintains a simple increasing integer version number suitable
  994. * for passing to userspace clients to determine what operations are permitted.
  995. *
  996. * Return: the current version number of the cmd parser
  997. */
  998. int i915_cmd_parser_get_version(void)
  999. {
  1000. /*
  1001. * Command parser version history
  1002. *
  1003. * 1. Initial version. Checks batches and reports violations, but leaves
  1004. * hardware parsing enabled (so does not allow new use cases).
  1005. * 2. Allow access to the MI_PREDICATE_SRC0 and
  1006. * MI_PREDICATE_SRC1 registers.
  1007. */
  1008. return 2;
  1009. }