intel_gpu_commands.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /* SPDX-License-Identifier: MIT*/
  2. /*
  3. * Copyright © 2003-2018 Intel Corporation
  4. */
  5. #ifndef _INTEL_GPU_COMMANDS_H_
  6. #define _INTEL_GPU_COMMANDS_H_
  7. #include <linux/bitops.h>
  8. /*
  9. * Target address alignments required for GPU access e.g.
  10. * MI_STORE_DWORD_IMM.
  11. */
  12. #define alignof_dword 4
  13. #define alignof_qword 8
  14. /*
  15. * Instruction field definitions used by the command parser
  16. */
  17. #define INSTR_CLIENT_SHIFT 29
  18. #define INSTR_MI_CLIENT 0x0
  19. #define INSTR_BC_CLIENT 0x2
  20. #define INSTR_GSC_CLIENT 0x2 /* MTL+ */
  21. #define INSTR_RC_CLIENT 0x3
  22. #define INSTR_SUBCLIENT_SHIFT 27
  23. #define INSTR_SUBCLIENT_MASK 0x18000000
  24. #define INSTR_MEDIA_SUBCLIENT 0x2
  25. #define INSTR_26_TO_24_MASK 0x7000000
  26. #define INSTR_26_TO_24_SHIFT 24
  27. #define __INSTR(client) ((client) << INSTR_CLIENT_SHIFT)
  28. /*
  29. * Memory interface instructions used by the kernel
  30. */
  31. #define MI_INSTR(opcode, flags) \
  32. (__INSTR(INSTR_MI_CLIENT) | (opcode) << 23 | (flags))
  33. /* Many MI commands use bit 22 of the header dword for GGTT vs PPGTT */
  34. #define MI_GLOBAL_GTT (1<<22)
  35. #define MI_NOOP MI_INSTR(0, 0)
  36. #define MI_SET_PREDICATE MI_INSTR(0x01, 0)
  37. #define MI_SET_PREDICATE_DISABLE (0 << 0)
  38. #define MI_USER_INTERRUPT MI_INSTR(0x02, 0)
  39. #define MI_WAIT_FOR_EVENT MI_INSTR(0x03, 0)
  40. #define MI_WAIT_FOR_OVERLAY_FLIP (1<<16)
  41. #define MI_WAIT_FOR_PLANE_B_FLIP (1<<6)
  42. #define MI_WAIT_FOR_PLANE_A_FLIP (1<<2)
  43. #define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
  44. #define MI_FLUSH MI_INSTR(0x04, 0)
  45. #define MI_READ_FLUSH (1 << 0)
  46. #define MI_EXE_FLUSH (1 << 1)
  47. #define MI_NO_WRITE_FLUSH (1 << 2)
  48. #define MI_SCENE_COUNT (1 << 3) /* just increment scene count */
  49. #define MI_END_SCENE (1 << 4) /* flush binner and incr scene count */
  50. #define MI_INVALIDATE_ISP (1 << 5) /* invalidate indirect state pointers */
  51. #define MI_REPORT_HEAD MI_INSTR(0x07, 0)
  52. #define MI_ARB_ON_OFF MI_INSTR(0x08, 0)
  53. #define MI_ARB_ENABLE (1<<0)
  54. #define MI_ARB_DISABLE (0<<0)
  55. #define MI_BATCH_BUFFER_END MI_INSTR(0x0a, 0)
  56. #define MI_SUSPEND_FLUSH MI_INSTR(0x0b, 0)
  57. #define MI_SUSPEND_FLUSH_EN (1<<0)
  58. #define MI_SET_APPID MI_INSTR(0x0e, 0)
  59. #define MI_SET_APPID_SESSION_ID(x) ((x) << 0)
  60. #define MI_OVERLAY_FLIP MI_INSTR(0x11, 0)
  61. #define MI_OVERLAY_CONTINUE (0x0<<21)
  62. #define MI_OVERLAY_ON (0x1<<21)
  63. #define MI_OVERLAY_OFF (0x2<<21)
  64. #define MI_LOAD_SCAN_LINES_INCL MI_INSTR(0x12, 0)
  65. #define MI_DISPLAY_FLIP MI_INSTR(0x14, 2)
  66. #define MI_DISPLAY_FLIP_I915 MI_INSTR(0x14, 1)
  67. #define MI_DISPLAY_FLIP_PLANE(n) ((n) << 20)
  68. /* IVB has funny definitions for which plane to flip. */
  69. #define MI_DISPLAY_FLIP_IVB_PLANE_A (0 << 19)
  70. #define MI_DISPLAY_FLIP_IVB_PLANE_B (1 << 19)
  71. #define MI_DISPLAY_FLIP_IVB_SPRITE_A (2 << 19)
  72. #define MI_DISPLAY_FLIP_IVB_SPRITE_B (3 << 19)
  73. #define MI_DISPLAY_FLIP_IVB_PLANE_C (4 << 19)
  74. #define MI_DISPLAY_FLIP_IVB_SPRITE_C (5 << 19)
  75. /* SKL ones */
  76. #define MI_DISPLAY_FLIP_SKL_PLANE_1_A (0 << 8)
  77. #define MI_DISPLAY_FLIP_SKL_PLANE_1_B (1 << 8)
  78. #define MI_DISPLAY_FLIP_SKL_PLANE_1_C (2 << 8)
  79. #define MI_DISPLAY_FLIP_SKL_PLANE_2_A (4 << 8)
  80. #define MI_DISPLAY_FLIP_SKL_PLANE_2_B (5 << 8)
  81. #define MI_DISPLAY_FLIP_SKL_PLANE_2_C (6 << 8)
  82. #define MI_DISPLAY_FLIP_SKL_PLANE_3_A (7 << 8)
  83. #define MI_DISPLAY_FLIP_SKL_PLANE_3_B (8 << 8)
  84. #define MI_DISPLAY_FLIP_SKL_PLANE_3_C (9 << 8)
  85. #define MI_SEMAPHORE_MBOX MI_INSTR(0x16, 1) /* gen6, gen7 */
  86. #define MI_SEMAPHORE_GLOBAL_GTT (1<<22)
  87. #define MI_SEMAPHORE_UPDATE (1<<21)
  88. #define MI_SEMAPHORE_COMPARE (1<<20)
  89. #define MI_SEMAPHORE_REGISTER (1<<18)
  90. #define MI_SEMAPHORE_SYNC_VR (0<<16) /* RCS wait for VCS (RVSYNC) */
  91. #define MI_SEMAPHORE_SYNC_VER (1<<16) /* RCS wait for VECS (RVESYNC) */
  92. #define MI_SEMAPHORE_SYNC_BR (2<<16) /* RCS wait for BCS (RBSYNC) */
  93. #define MI_SEMAPHORE_SYNC_BV (0<<16) /* VCS wait for BCS (VBSYNC) */
  94. #define MI_SEMAPHORE_SYNC_VEV (1<<16) /* VCS wait for VECS (VVESYNC) */
  95. #define MI_SEMAPHORE_SYNC_RV (2<<16) /* VCS wait for RCS (VRSYNC) */
  96. #define MI_SEMAPHORE_SYNC_RB (0<<16) /* BCS wait for RCS (BRSYNC) */
  97. #define MI_SEMAPHORE_SYNC_VEB (1<<16) /* BCS wait for VECS (BVESYNC) */
  98. #define MI_SEMAPHORE_SYNC_VB (2<<16) /* BCS wait for VCS (BVSYNC) */
  99. #define MI_SEMAPHORE_SYNC_BVE (0<<16) /* VECS wait for BCS (VEBSYNC) */
  100. #define MI_SEMAPHORE_SYNC_VVE (1<<16) /* VECS wait for VCS (VEVSYNC) */
  101. #define MI_SEMAPHORE_SYNC_RVE (2<<16) /* VECS wait for RCS (VERSYNC) */
  102. #define MI_SEMAPHORE_SYNC_INVALID (3<<16)
  103. #define MI_SEMAPHORE_SYNC_MASK (3<<16)
  104. #define MI_SET_CONTEXT MI_INSTR(0x18, 0)
  105. #define MI_MM_SPACE_GTT (1<<8)
  106. #define MI_MM_SPACE_PHYSICAL (0<<8)
  107. #define MI_SAVE_EXT_STATE_EN (1<<3)
  108. #define MI_RESTORE_EXT_STATE_EN (1<<2)
  109. #define MI_FORCE_RESTORE (1<<1)
  110. #define MI_RESTORE_INHIBIT (1<<0)
  111. #define HSW_MI_RS_SAVE_STATE_EN (1<<3)
  112. #define HSW_MI_RS_RESTORE_STATE_EN (1<<2)
  113. #define MI_SEMAPHORE_SIGNAL MI_INSTR(0x1b, 0) /* GEN8+ */
  114. #define MI_SEMAPHORE_TARGET(engine) ((engine)<<15)
  115. #define MI_SEMAPHORE_WAIT MI_INSTR(0x1c, 2) /* GEN8+ */
  116. #define MI_SEMAPHORE_WAIT_TOKEN MI_INSTR(0x1c, 3) /* GEN12+ */
  117. #define MI_SEMAPHORE_REGISTER_POLL (1 << 16)
  118. #define MI_SEMAPHORE_POLL (1 << 15)
  119. #define MI_SEMAPHORE_SAD_GT_SDD (0 << 12)
  120. #define MI_SEMAPHORE_SAD_GTE_SDD (1 << 12)
  121. #define MI_SEMAPHORE_SAD_LT_SDD (2 << 12)
  122. #define MI_SEMAPHORE_SAD_LTE_SDD (3 << 12)
  123. #define MI_SEMAPHORE_SAD_EQ_SDD (4 << 12)
  124. #define MI_SEMAPHORE_SAD_NEQ_SDD (5 << 12)
  125. #define MI_SEMAPHORE_TOKEN_MASK REG_GENMASK(9, 5)
  126. #define MI_SEMAPHORE_TOKEN_SHIFT 5
  127. #define MI_STORE_DATA_IMM MI_INSTR(0x20, 0)
  128. #define MI_STORE_DWORD_IMM MI_INSTR(0x20, 1)
  129. #define MI_STORE_DWORD_IMM_GEN4 MI_INSTR(0x20, 2)
  130. #define MI_STORE_QWORD_IMM_GEN8 (MI_INSTR(0x20, 3) | REG_BIT(21))
  131. #define MI_MEM_VIRTUAL (1 << 22) /* 945,g33,965 */
  132. #define MI_USE_GGTT (1 << 22) /* g4x+ */
  133. #define MI_STORE_DWORD_INDEX MI_INSTR(0x21, 1)
  134. #define MI_ATOMIC MI_INSTR(0x2f, 1)
  135. #define MI_ATOMIC_INLINE (MI_INSTR(0x2f, 9) | MI_ATOMIC_INLINE_DATA)
  136. #define MI_ATOMIC_GLOBAL_GTT (1 << 22)
  137. #define MI_ATOMIC_INLINE_DATA (1 << 18)
  138. #define MI_ATOMIC_CS_STALL (1 << 17)
  139. #define MI_ATOMIC_MOVE (0x4 << 8)
  140. /*
  141. * Official intel docs are somewhat sloppy concerning MI_LOAD_REGISTER_IMM:
  142. * - Always issue a MI_NOOP _before_ the MI_LOAD_REGISTER_IMM - otherwise hw
  143. * simply ignores the register load under certain conditions.
  144. * - One can actually load arbitrary many arbitrary registers: Simply issue x
  145. * address/value pairs. Don't overdue it, though, x <= 2^4 must hold!
  146. */
  147. #define MI_LOAD_REGISTER_IMM(x) MI_INSTR(0x22, 2*(x)-1)
  148. /* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
  149. #define MI_LRI_LRM_CS_MMIO REG_BIT(19)
  150. #define MI_LRI_MMIO_REMAP_EN REG_BIT(17)
  151. #define MI_LRI_FORCE_POSTED (1<<12)
  152. #define MI_LOAD_REGISTER_IMM_MAX_REGS (126)
  153. #define MI_STORE_REGISTER_MEM MI_INSTR(0x24, 1)
  154. #define MI_STORE_REGISTER_MEM_GEN8 MI_INSTR(0x24, 2)
  155. #define MI_SRM_LRM_GLOBAL_GTT (1<<22)
  156. #define MI_FLUSH_DW MI_INSTR(0x26, 1) /* for GEN6 */
  157. #define MI_FLUSH_DW_PROTECTED_MEM_EN (1 << 22)
  158. #define MI_FLUSH_DW_STORE_INDEX (1<<21)
  159. #define MI_INVALIDATE_TLB (1<<18)
  160. #define MI_FLUSH_DW_CCS (1<<16)
  161. #define MI_FLUSH_DW_OP_STOREDW (1<<14)
  162. #define MI_FLUSH_DW_OP_MASK (3<<14)
  163. #define MI_FLUSH_DW_LLC (1<<9)
  164. #define MI_FLUSH_DW_NOTIFY (1<<8)
  165. #define MI_INVALIDATE_BSD (1<<7)
  166. #define MI_FLUSH_DW_USE_GTT (1<<2)
  167. #define MI_FLUSH_DW_USE_PPGTT (0<<2)
  168. #define MI_LOAD_REGISTER_MEM MI_INSTR(0x29, 1)
  169. #define MI_LOAD_REGISTER_MEM_GEN8 MI_INSTR(0x29, 2)
  170. #define MI_LOAD_REGISTER_REG MI_INSTR(0x2A, 1)
  171. #define MI_LRR_SOURCE_CS_MMIO REG_BIT(18)
  172. #define MI_BATCH_BUFFER MI_INSTR(0x30, 1)
  173. #define MI_BATCH_NON_SECURE (1)
  174. /* for snb/ivb/vlv this also means "batch in ppgtt" when ppgtt is enabled. */
  175. #define MI_BATCH_NON_SECURE_I965 (1<<8)
  176. #define MI_BATCH_PPGTT_HSW (1<<8)
  177. #define MI_BATCH_NON_SECURE_HSW (1<<13)
  178. #define MI_BATCH_BUFFER_START MI_INSTR(0x31, 0)
  179. #define MI_BATCH_GTT (2<<6) /* aliased with (1<<7) on gen4 */
  180. #define MI_BATCH_BUFFER_START_GEN8 MI_INSTR(0x31, 1)
  181. #define MI_BATCH_RESOURCE_STREAMER REG_BIT(10)
  182. #define MI_BATCH_PREDICATE REG_BIT(15) /* HSW+ on RCS only*/
  183. #define MI_OPCODE(x) (((x) >> 23) & 0x3f)
  184. #define IS_MI_LRI_CMD(x) (MI_OPCODE(x) == MI_OPCODE(MI_INSTR(0x22, 0)))
  185. #define MI_LRI_LEN(x) (((x) & 0xff) + 1)
  186. /*
  187. * 3D instructions used by the kernel
  188. */
  189. #define GFX_INSTR(opcode, flags) ((0x3 << 29) | ((opcode) << 24) | (flags))
  190. #define GEN9_MEDIA_POOL_STATE ((0x3 << 29) | (0x2 << 27) | (0x5 << 16) | 4)
  191. #define GEN9_MEDIA_POOL_ENABLE (1 << 31)
  192. #define GFX_OP_RASTER_RULES ((0x3<<29)|(0x7<<24))
  193. #define GFX_OP_SCISSOR ((0x3<<29)|(0x1c<<24)|(0x10<<19))
  194. #define SC_UPDATE_SCISSOR (0x1<<1)
  195. #define SC_ENABLE_MASK (0x1<<0)
  196. #define SC_ENABLE (0x1<<0)
  197. #define GFX_OP_LOAD_INDIRECT ((0x3<<29)|(0x1d<<24)|(0x7<<16))
  198. #define GFX_OP_SCISSOR_INFO ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
  199. #define SCI_YMIN_MASK (0xffff<<16)
  200. #define SCI_XMIN_MASK (0xffff<<0)
  201. #define SCI_YMAX_MASK (0xffff<<16)
  202. #define SCI_XMAX_MASK (0xffff<<0)
  203. #define GFX_OP_SCISSOR_ENABLE ((0x3<<29)|(0x1c<<24)|(0x10<<19))
  204. #define GFX_OP_SCISSOR_RECT ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
  205. #define GFX_OP_COLOR_FACTOR ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
  206. #define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16))
  207. #define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x4)
  208. #define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
  209. #define GFX_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
  210. #define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
  211. #define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
  212. #define CMD_3DSTATE_MESH_CONTROL ((0x3 << 29) | (0x3 << 27) | (0x0 << 24) | (0x77 << 16) | (0x3))
  213. #define XY_CTRL_SURF_INSTR_SIZE 5
  214. #define MI_FLUSH_DW_SIZE 3
  215. #define XY_CTRL_SURF_COPY_BLT ((2 << 29) | (0x48 << 22) | 3)
  216. #define SRC_ACCESS_TYPE_SHIFT 21
  217. #define DST_ACCESS_TYPE_SHIFT 20
  218. #define CCS_SIZE_MASK 0x3FF
  219. #define CCS_SIZE_SHIFT 8
  220. #define XY_CTRL_SURF_MOCS_MASK GENMASK(31, 25)
  221. #define NUM_CCS_BYTES_PER_BLOCK 256
  222. #define NUM_BYTES_PER_CCS_BYTE 256
  223. #define NUM_CCS_BLKS_PER_XFER 1024
  224. #define INDIRECT_ACCESS 0
  225. #define DIRECT_ACCESS 1
  226. #define COLOR_BLT_CMD (2 << 29 | 0x40 << 22 | (5 - 2))
  227. #define XY_COLOR_BLT_CMD (2 << 29 | 0x50 << 22)
  228. #define XY_FAST_COLOR_BLT_CMD (2 << 29 | 0x44 << 22)
  229. #define XY_FAST_COLOR_BLT_DEPTH_32 (2 << 19)
  230. #define XY_FAST_COLOR_BLT_DW 16
  231. #define XY_FAST_COLOR_BLT_MOCS_MASK GENMASK(27, 21)
  232. #define XY_FAST_COLOR_BLT_MEM_TYPE_SHIFT 31
  233. #define XY_FAST_COPY_BLT_D0_SRC_TILING_MASK REG_GENMASK(21, 20)
  234. #define XY_FAST_COPY_BLT_D0_DST_TILING_MASK REG_GENMASK(14, 13)
  235. #define XY_FAST_COPY_BLT_D0_SRC_TILE_MODE(mode) \
  236. REG_FIELD_PREP(XY_FAST_COPY_BLT_D0_SRC_TILING_MASK, mode)
  237. #define XY_FAST_COPY_BLT_D0_DST_TILE_MODE(mode) \
  238. REG_FIELD_PREP(XY_FAST_COPY_BLT_D0_DST_TILING_MASK, mode)
  239. #define LINEAR 0
  240. #define TILE_X 0x1
  241. #define XMAJOR 0x1
  242. #define YMAJOR 0x2
  243. #define TILE_64 0x3
  244. #define XY_FAST_COPY_BLT_D1_SRC_TILE4 REG_BIT(31)
  245. #define XY_FAST_COPY_BLT_D1_DST_TILE4 REG_BIT(30)
  246. #define BLIT_CCTL_SRC_MOCS_MASK REG_GENMASK(6, 0)
  247. #define BLIT_CCTL_DST_MOCS_MASK REG_GENMASK(14, 8)
  248. /* Note: MOCS value = (index << 1) */
  249. #define BLIT_CCTL_SRC_MOCS(idx) \
  250. REG_FIELD_PREP(BLIT_CCTL_SRC_MOCS_MASK, (idx) << 1)
  251. #define BLIT_CCTL_DST_MOCS(idx) \
  252. REG_FIELD_PREP(BLIT_CCTL_DST_MOCS_MASK, (idx) << 1)
  253. #define SRC_COPY_BLT_CMD (2 << 29 | 0x43 << 22)
  254. #define GEN9_XY_FAST_COPY_BLT_CMD (2 << 29 | 0x42 << 22)
  255. #define XY_SRC_COPY_BLT_CMD (2 << 29 | 0x53 << 22)
  256. #define XY_MONO_SRC_COPY_IMM_BLT (2 << 29 | 0x71 << 22 | 5)
  257. #define BLT_WRITE_A (2<<20)
  258. #define BLT_WRITE_RGB (1<<20)
  259. #define BLT_WRITE_RGBA (BLT_WRITE_RGB | BLT_WRITE_A)
  260. #define BLT_DEPTH_8 (0<<24)
  261. #define BLT_DEPTH_16_565 (1<<24)
  262. #define BLT_DEPTH_16_1555 (2<<24)
  263. #define BLT_DEPTH_32 (3<<24)
  264. #define BLT_ROP_SRC_COPY (0xcc<<16)
  265. #define BLT_ROP_COLOR_COPY (0xf0<<16)
  266. #define XY_SRC_COPY_BLT_SRC_TILED (1<<15) /* 965+ only */
  267. #define XY_SRC_COPY_BLT_DST_TILED (1<<11) /* 965+ only */
  268. #define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
  269. #define ASYNC_FLIP (1<<22)
  270. #define DISPLAY_PLANE_A (0<<20)
  271. #define DISPLAY_PLANE_B (1<<20)
  272. #define GFX_OP_PIPE_CONTROL(len) ((0x3<<29)|(0x3<<27)|(0x2<<24)|((len)-2))
  273. #define PIPE_CONTROL_COMMAND_CACHE_INVALIDATE (1<<29) /* gen11+ */
  274. #define PIPE_CONTROL_TILE_CACHE_FLUSH (1<<28) /* gen11+ */
  275. #define PIPE_CONTROL_FLUSH_L3 (1<<27)
  276. #define PIPE_CONTROL_AMFS_FLUSH (1<<25) /* gen12+ */
  277. #define PIPE_CONTROL_GLOBAL_GTT_IVB (1<<24) /* gen7+ */
  278. #define PIPE_CONTROL_MMIO_WRITE (1<<23)
  279. #define PIPE_CONTROL_STORE_DATA_INDEX (1<<21)
  280. #define PIPE_CONTROL_CS_STALL (1<<20)
  281. #define PIPE_CONTROL_GLOBAL_SNAPSHOT_RESET (1<<19)
  282. #define PIPE_CONTROL_TLB_INVALIDATE (1<<18)
  283. #define PIPE_CONTROL_PSD_SYNC (1<<17) /* gen11+ */
  284. #define PIPE_CONTROL_MEDIA_STATE_CLEAR (1<<16)
  285. #define PIPE_CONTROL_WRITE_TIMESTAMP (3<<14)
  286. #define PIPE_CONTROL_QW_WRITE (1<<14)
  287. #define PIPE_CONTROL_POST_SYNC_OP_MASK (3<<14)
  288. #define PIPE_CONTROL_DEPTH_STALL (1<<13)
  289. #define PIPE_CONTROL_CCS_FLUSH (1<<13) /* MTL+ */
  290. #define PIPE_CONTROL_WRITE_FLUSH (1<<12)
  291. #define PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH (1<<12) /* gen6+ */
  292. #define PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE (1<<11) /* MBZ on ILK */
  293. #define PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE (1<<10) /* GM45+ only */
  294. #define PIPE_CONTROL_INDIRECT_STATE_DISABLE (1<<9)
  295. #define PIPE_CONTROL0_HDC_PIPELINE_FLUSH REG_BIT(9) /* gen12 */
  296. #define PIPE_CONTROL_NOTIFY (1<<8)
  297. #define PIPE_CONTROL_FLUSH_ENABLE (1<<7) /* gen7+ */
  298. #define PIPE_CONTROL_DC_FLUSH_ENABLE (1<<5)
  299. #define PIPE_CONTROL_VF_CACHE_INVALIDATE (1<<4)
  300. #define PIPE_CONTROL_CONST_CACHE_INVALIDATE (1<<3)
  301. #define PIPE_CONTROL_STATE_CACHE_INVALIDATE (1<<2)
  302. #define PIPE_CONTROL_STALL_AT_SCOREBOARD (1<<1)
  303. #define PIPE_CONTROL_DEPTH_CACHE_FLUSH (1<<0)
  304. #define PIPE_CONTROL_GLOBAL_GTT (1<<2) /* in addr dword */
  305. /*
  306. * 3D-related flags that can't be set on _engines_ that lack access to the 3D
  307. * pipeline (i.e., CCS engines).
  308. */
  309. #define PIPE_CONTROL_3D_ENGINE_FLAGS (\
  310. PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH | \
  311. PIPE_CONTROL_DEPTH_CACHE_FLUSH | \
  312. PIPE_CONTROL_TILE_CACHE_FLUSH | \
  313. PIPE_CONTROL_DEPTH_STALL | \
  314. PIPE_CONTROL_STALL_AT_SCOREBOARD | \
  315. PIPE_CONTROL_PSD_SYNC | \
  316. PIPE_CONTROL_AMFS_FLUSH | \
  317. PIPE_CONTROL_VF_CACHE_INVALIDATE | \
  318. PIPE_CONTROL_GLOBAL_SNAPSHOT_RESET)
  319. /* 3D-related flags that can't be set on _platforms_ that lack a 3D pipeline */
  320. #define PIPE_CONTROL_3D_ARCH_FLAGS ( \
  321. PIPE_CONTROL_3D_ENGINE_FLAGS | \
  322. PIPE_CONTROL_INDIRECT_STATE_DISABLE | \
  323. PIPE_CONTROL_FLUSH_ENABLE | \
  324. PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | \
  325. PIPE_CONTROL_DC_FLUSH_ENABLE)
  326. #define MI_MATH(x) MI_INSTR(0x1a, (x) - 1)
  327. #define MI_MATH_INSTR(opcode, op1, op2) ((opcode) << 20 | (op1) << 10 | (op2))
  328. /* Opcodes for MI_MATH_INSTR */
  329. #define MI_MATH_NOOP MI_MATH_INSTR(0x000, 0x0, 0x0)
  330. #define MI_MATH_LOAD(op1, op2) MI_MATH_INSTR(0x080, op1, op2)
  331. #define MI_MATH_LOADINV(op1, op2) MI_MATH_INSTR(0x480, op1, op2)
  332. #define MI_MATH_LOAD0(op1) MI_MATH_INSTR(0x081, op1)
  333. #define MI_MATH_LOAD1(op1) MI_MATH_INSTR(0x481, op1)
  334. #define MI_MATH_ADD MI_MATH_INSTR(0x100, 0x0, 0x0)
  335. #define MI_MATH_SUB MI_MATH_INSTR(0x101, 0x0, 0x0)
  336. #define MI_MATH_AND MI_MATH_INSTR(0x102, 0x0, 0x0)
  337. #define MI_MATH_OR MI_MATH_INSTR(0x103, 0x0, 0x0)
  338. #define MI_MATH_XOR MI_MATH_INSTR(0x104, 0x0, 0x0)
  339. #define MI_MATH_STORE(op1, op2) MI_MATH_INSTR(0x180, op1, op2)
  340. #define MI_MATH_STOREINV(op1, op2) MI_MATH_INSTR(0x580, op1, op2)
  341. /* Registers used as operands in MI_MATH_INSTR */
  342. #define MI_MATH_REG(x) (x)
  343. #define MI_MATH_REG_SRCA 0x20
  344. #define MI_MATH_REG_SRCB 0x21
  345. #define MI_MATH_REG_ACCU 0x31
  346. #define MI_MATH_REG_ZF 0x32
  347. #define MI_MATH_REG_CF 0x33
  348. /*
  349. * Media instructions used by the kernel
  350. */
  351. #define MEDIA_INSTR(pipe, op, sub_op, flags) \
  352. (__INSTR(INSTR_RC_CLIENT) | (pipe) << INSTR_SUBCLIENT_SHIFT | \
  353. (op) << INSTR_26_TO_24_SHIFT | (sub_op) << 16 | (flags))
  354. #define MFX_WAIT MEDIA_INSTR(1, 0, 0, 0)
  355. #define MFX_WAIT_DW0_MFX_SYNC_CONTROL_FLAG REG_BIT(8)
  356. #define MFX_WAIT_DW0_PXP_SYNC_CONTROL_FLAG REG_BIT(9)
  357. #define CRYPTO_KEY_EXCHANGE MEDIA_INSTR(2, 6, 9, 0)
  358. /*
  359. * Commands used only by the command parser
  360. */
  361. #define MI_SET_PREDICATE MI_INSTR(0x01, 0)
  362. #define MI_ARB_CHECK MI_INSTR(0x05, 0)
  363. #define MI_RS_CONTROL MI_INSTR(0x06, 0)
  364. #define MI_URB_ATOMIC_ALLOC MI_INSTR(0x09, 0)
  365. #define MI_PREDICATE MI_INSTR(0x0C, 0)
  366. #define MI_RS_CONTEXT MI_INSTR(0x0F, 0)
  367. #define MI_TOPOLOGY_FILTER MI_INSTR(0x0D, 0)
  368. #define MI_LOAD_SCAN_LINES_EXCL MI_INSTR(0x13, 0)
  369. #define MI_URB_CLEAR MI_INSTR(0x19, 0)
  370. #define MI_UPDATE_GTT MI_INSTR(0x23, 0)
  371. #define MI_CLFLUSH MI_INSTR(0x27, 0)
  372. #define MI_REPORT_PERF_COUNT MI_INSTR(0x28, 0)
  373. #define MI_REPORT_PERF_COUNT_GGTT (1<<0)
  374. #define MI_RS_STORE_DATA_IMM MI_INSTR(0x2B, 0)
  375. #define MI_LOAD_URB_MEM MI_INSTR(0x2C, 0)
  376. #define MI_STORE_URB_MEM MI_INSTR(0x2D, 0)
  377. #define MI_CONDITIONAL_BATCH_BUFFER_END MI_INSTR(0x36, 0)
  378. #define MI_DO_COMPARE REG_BIT(21)
  379. #define STATE_BASE_ADDRESS \
  380. ((0x3 << 29) | (0x0 << 27) | (0x1 << 24) | (0x1 << 16))
  381. #define BASE_ADDRESS_MODIFY REG_BIT(0)
  382. #define PIPELINE_SELECT \
  383. ((0x3 << 29) | (0x1 << 27) | (0x1 << 24) | (0x4 << 16))
  384. #define PIPELINE_SELECT_MEDIA REG_BIT(0)
  385. #define GFX_OP_3DSTATE_VF_STATISTICS \
  386. ((0x3 << 29) | (0x1 << 27) | (0x0 << 24) | (0xB << 16))
  387. #define MEDIA_VFE_STATE \
  388. ((0x3 << 29) | (0x2 << 27) | (0x0 << 24) | (0x0 << 16))
  389. #define MEDIA_VFE_STATE_MMIO_ACCESS_MASK (0x18)
  390. #define MEDIA_INTERFACE_DESCRIPTOR_LOAD \
  391. ((0x3 << 29) | (0x2 << 27) | (0x0 << 24) | (0x2 << 16))
  392. #define MEDIA_OBJECT \
  393. ((0x3 << 29) | (0x2 << 27) | (0x1 << 24) | (0x0 << 16))
  394. #define GPGPU_OBJECT ((0x3<<29)|(0x2<<27)|(0x1<<24)|(0x4<<16))
  395. #define GPGPU_WALKER ((0x3<<29)|(0x2<<27)|(0x1<<24)|(0x5<<16))
  396. #define GFX_OP_3DSTATE_DX9_CONSTANTF_VS \
  397. ((0x3<<29)|(0x3<<27)|(0x0<<24)|(0x39<<16))
  398. #define GFX_OP_3DSTATE_DX9_CONSTANTF_PS \
  399. ((0x3<<29)|(0x3<<27)|(0x0<<24)|(0x3A<<16))
  400. #define GFX_OP_3DSTATE_SO_DECL_LIST \
  401. ((0x3<<29)|(0x3<<27)|(0x1<<24)|(0x17<<16))
  402. #define GFX_OP_3DSTATE_BINDING_TABLE_EDIT_VS \
  403. ((0x3<<29)|(0x3<<27)|(0x0<<24)|(0x43<<16))
  404. #define GFX_OP_3DSTATE_BINDING_TABLE_EDIT_GS \
  405. ((0x3<<29)|(0x3<<27)|(0x0<<24)|(0x44<<16))
  406. #define GFX_OP_3DSTATE_BINDING_TABLE_EDIT_HS \
  407. ((0x3<<29)|(0x3<<27)|(0x0<<24)|(0x45<<16))
  408. #define GFX_OP_3DSTATE_BINDING_TABLE_EDIT_DS \
  409. ((0x3<<29)|(0x3<<27)|(0x0<<24)|(0x46<<16))
  410. #define GFX_OP_3DSTATE_BINDING_TABLE_EDIT_PS \
  411. ((0x3<<29)|(0x3<<27)|(0x0<<24)|(0x47<<16))
  412. #define COLOR_BLT ((0x2<<29)|(0x40<<22))
  413. #define SRC_COPY_BLT ((0x2<<29)|(0x43<<22))
  414. #define GSC_INSTR(opcode, data, flags) \
  415. (__INSTR(INSTR_GSC_CLIENT) | (opcode) << 22 | (data) << 9 | (flags))
  416. #define GSC_FW_LOAD GSC_INSTR(1, 0, 2)
  417. #define HECI1_FW_LIMIT_VALID (1 << 31)
  418. #define GSC_HECI_CMD_PKT GSC_INSTR(0, 0, 6)
  419. /*
  420. * Used to convert any address to canonical form.
  421. * Starting from gen8, some commands (e.g. STATE_BASE_ADDRESS,
  422. * MI_LOAD_REGISTER_MEM and others, see Broadwell PRM Vol2a) require the
  423. * addresses to be in a canonical form:
  424. * "GraphicsAddress[63:48] are ignored by the HW and assumed to be in correct
  425. * canonical form [63:48] == [47]."
  426. */
  427. #define GEN8_HIGH_ADDRESS_BIT 47
  428. static inline u64 gen8_canonical_addr(u64 address)
  429. {
  430. return sign_extend64(address, GEN8_HIGH_ADDRESS_BIT);
  431. }
  432. static inline u64 gen8_noncanonical_addr(u64 address)
  433. {
  434. return address & GENMASK_ULL(GEN8_HIGH_ADDRESS_BIT, 0);
  435. }
  436. static inline u32 *__gen6_emit_bb_start(u32 *cs, u32 addr, unsigned int flags)
  437. {
  438. *cs++ = MI_BATCH_BUFFER_START | flags;
  439. *cs++ = addr;
  440. return cs;
  441. }
  442. #endif /* _INTEL_GPU_COMMANDS_H_ */