vc4_drm.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Copyright © 2014-2015 Broadcom
  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. #ifndef _UAPI_VC4_DRM_H_
  24. #define _UAPI_VC4_DRM_H_
  25. #include "drm.h"
  26. #if defined(__cplusplus)
  27. extern "C" {
  28. #endif
  29. #define DRM_VC4_SUBMIT_CL 0x00
  30. #define DRM_VC4_WAIT_SEQNO 0x01
  31. #define DRM_VC4_WAIT_BO 0x02
  32. #define DRM_VC4_CREATE_BO 0x03
  33. #define DRM_VC4_MMAP_BO 0x04
  34. #define DRM_VC4_CREATE_SHADER_BO 0x05
  35. #define DRM_VC4_GET_HANG_STATE 0x06
  36. #define DRM_VC4_GET_PARAM 0x07
  37. #define DRM_VC4_SET_TILING 0x08
  38. #define DRM_VC4_GET_TILING 0x09
  39. #define DRM_IOCTL_VC4_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl)
  40. #define DRM_IOCTL_VC4_WAIT_SEQNO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno)
  41. #define DRM_IOCTL_VC4_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_BO, struct drm_vc4_wait_bo)
  42. #define DRM_IOCTL_VC4_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo)
  43. #define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo)
  44. #define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo)
  45. #define DRM_IOCTL_VC4_GET_HANG_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state)
  46. #define DRM_IOCTL_VC4_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param)
  47. #define DRM_IOCTL_VC4_SET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SET_TILING, struct drm_vc4_set_tiling)
  48. #define DRM_IOCTL_VC4_GET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_TILING, struct drm_vc4_get_tiling)
  49. struct drm_vc4_submit_rcl_surface {
  50. __u32 hindex; /* Handle index, or ~0 if not present. */
  51. __u32 offset; /* Offset to start of buffer. */
  52. /*
  53. * Bits for either render config (color_write) or load/store packet.
  54. * Bits should all be 0 for MSAA load/stores.
  55. */
  56. __u16 bits;
  57. #define VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES (1 << 0)
  58. __u16 flags;
  59. };
  60. /**
  61. * struct drm_vc4_submit_cl - ioctl argument for submitting commands to the 3D
  62. * engine.
  63. *
  64. * Drivers typically use GPU BOs to store batchbuffers / command lists and
  65. * their associated state. However, because the VC4 lacks an MMU, we have to
  66. * do validation of memory accesses by the GPU commands. If we were to store
  67. * our commands in BOs, we'd need to do uncached readback from them to do the
  68. * validation process, which is too expensive. Instead, userspace accumulates
  69. * commands and associated state in plain memory, then the kernel copies the
  70. * data to its own address space, and then validates and stores it in a GPU
  71. * BO.
  72. */
  73. struct drm_vc4_submit_cl {
  74. /* Pointer to the binner command list.
  75. *
  76. * This is the first set of commands executed, which runs the
  77. * coordinate shader to determine where primitives land on the screen,
  78. * then writes out the state updates and draw calls necessary per tile
  79. * to the tile allocation BO.
  80. */
  81. __u64 bin_cl;
  82. /* Pointer to the shader records.
  83. *
  84. * Shader records are the structures read by the hardware that contain
  85. * pointers to uniforms, shaders, and vertex attributes. The
  86. * reference to the shader record has enough information to determine
  87. * how many pointers are necessary (fixed number for shaders/uniforms,
  88. * and an attribute count), so those BO indices into bo_handles are
  89. * just stored as __u32s before each shader record passed in.
  90. */
  91. __u64 shader_rec;
  92. /* Pointer to uniform data and texture handles for the textures
  93. * referenced by the shader.
  94. *
  95. * For each shader state record, there is a set of uniform data in the
  96. * order referenced by the record (FS, VS, then CS). Each set of
  97. * uniform data has a __u32 index into bo_handles per texture
  98. * sample operation, in the order the QPU_W_TMUn_S writes appear in
  99. * the program. Following the texture BO handle indices is the actual
  100. * uniform data.
  101. *
  102. * The individual uniform state blocks don't have sizes passed in,
  103. * because the kernel has to determine the sizes anyway during shader
  104. * code validation.
  105. */
  106. __u64 uniforms;
  107. __u64 bo_handles;
  108. /* Size in bytes of the binner command list. */
  109. __u32 bin_cl_size;
  110. /* Size in bytes of the set of shader records. */
  111. __u32 shader_rec_size;
  112. /* Number of shader records.
  113. *
  114. * This could just be computed from the contents of shader_records and
  115. * the address bits of references to them from the bin CL, but it
  116. * keeps the kernel from having to resize some allocations it makes.
  117. */
  118. __u32 shader_rec_count;
  119. /* Size in bytes of the uniform state. */
  120. __u32 uniforms_size;
  121. /* Number of BO handles passed in (size is that times 4). */
  122. __u32 bo_handle_count;
  123. /* RCL setup: */
  124. __u16 width;
  125. __u16 height;
  126. __u8 min_x_tile;
  127. __u8 min_y_tile;
  128. __u8 max_x_tile;
  129. __u8 max_y_tile;
  130. struct drm_vc4_submit_rcl_surface color_read;
  131. struct drm_vc4_submit_rcl_surface color_write;
  132. struct drm_vc4_submit_rcl_surface zs_read;
  133. struct drm_vc4_submit_rcl_surface zs_write;
  134. struct drm_vc4_submit_rcl_surface msaa_color_write;
  135. struct drm_vc4_submit_rcl_surface msaa_zs_write;
  136. __u32 clear_color[2];
  137. __u32 clear_z;
  138. __u8 clear_s;
  139. __u32 pad:24;
  140. #define VC4_SUBMIT_CL_USE_CLEAR_COLOR (1 << 0)
  141. __u32 flags;
  142. /* Returned value of the seqno of this render job (for the
  143. * wait ioctl).
  144. */
  145. __u64 seqno;
  146. };
  147. /**
  148. * struct drm_vc4_wait_seqno - ioctl argument for waiting for
  149. * DRM_VC4_SUBMIT_CL completion using its returned seqno.
  150. *
  151. * timeout_ns is the timeout in nanoseconds, where "0" means "don't
  152. * block, just return the status."
  153. */
  154. struct drm_vc4_wait_seqno {
  155. __u64 seqno;
  156. __u64 timeout_ns;
  157. };
  158. /**
  159. * struct drm_vc4_wait_bo - ioctl argument for waiting for
  160. * completion of the last DRM_VC4_SUBMIT_CL on a BO.
  161. *
  162. * This is useful for cases where multiple processes might be
  163. * rendering to a BO and you want to wait for all rendering to be
  164. * completed.
  165. */
  166. struct drm_vc4_wait_bo {
  167. __u32 handle;
  168. __u32 pad;
  169. __u64 timeout_ns;
  170. };
  171. /**
  172. * struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs.
  173. *
  174. * There are currently no values for the flags argument, but it may be
  175. * used in a future extension.
  176. */
  177. struct drm_vc4_create_bo {
  178. __u32 size;
  179. __u32 flags;
  180. /** Returned GEM handle for the BO. */
  181. __u32 handle;
  182. __u32 pad;
  183. };
  184. /**
  185. * struct drm_vc4_mmap_bo - ioctl argument for mapping VC4 BOs.
  186. *
  187. * This doesn't actually perform an mmap. Instead, it returns the
  188. * offset you need to use in an mmap on the DRM device node. This
  189. * means that tools like valgrind end up knowing about the mapped
  190. * memory.
  191. *
  192. * There are currently no values for the flags argument, but it may be
  193. * used in a future extension.
  194. */
  195. struct drm_vc4_mmap_bo {
  196. /** Handle for the object being mapped. */
  197. __u32 handle;
  198. __u32 flags;
  199. /** offset into the drm node to use for subsequent mmap call. */
  200. __u64 offset;
  201. };
  202. /**
  203. * struct drm_vc4_create_shader_bo - ioctl argument for creating VC4
  204. * shader BOs.
  205. *
  206. * Since allowing a shader to be overwritten while it's also being
  207. * executed from would allow privlege escalation, shaders must be
  208. * created using this ioctl, and they can't be mmapped later.
  209. */
  210. struct drm_vc4_create_shader_bo {
  211. /* Size of the data argument. */
  212. __u32 size;
  213. /* Flags, currently must be 0. */
  214. __u32 flags;
  215. /* Pointer to the data. */
  216. __u64 data;
  217. /** Returned GEM handle for the BO. */
  218. __u32 handle;
  219. /* Pad, must be 0. */
  220. __u32 pad;
  221. };
  222. struct drm_vc4_get_hang_state_bo {
  223. __u32 handle;
  224. __u32 paddr;
  225. __u32 size;
  226. __u32 pad;
  227. };
  228. /**
  229. * struct drm_vc4_hang_state - ioctl argument for collecting state
  230. * from a GPU hang for analysis.
  231. */
  232. struct drm_vc4_get_hang_state {
  233. /** Pointer to array of struct drm_vc4_get_hang_state_bo. */
  234. __u64 bo;
  235. /**
  236. * On input, the size of the bo array. Output is the number
  237. * of bos to be returned.
  238. */
  239. __u32 bo_count;
  240. __u32 start_bin, start_render;
  241. __u32 ct0ca, ct0ea;
  242. __u32 ct1ca, ct1ea;
  243. __u32 ct0cs, ct1cs;
  244. __u32 ct0ra0, ct1ra0;
  245. __u32 bpca, bpcs;
  246. __u32 bpoa, bpos;
  247. __u32 vpmbase;
  248. __u32 dbge;
  249. __u32 fdbgo;
  250. __u32 fdbgb;
  251. __u32 fdbgr;
  252. __u32 fdbgs;
  253. __u32 errstat;
  254. /* Pad that we may save more registers into in the future. */
  255. __u32 pad[16];
  256. };
  257. #define DRM_VC4_PARAM_V3D_IDENT0 0
  258. #define DRM_VC4_PARAM_V3D_IDENT1 1
  259. #define DRM_VC4_PARAM_V3D_IDENT2 2
  260. #define DRM_VC4_PARAM_SUPPORTS_BRANCHES 3
  261. #define DRM_VC4_PARAM_SUPPORTS_ETC1 4
  262. #define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 5
  263. struct drm_vc4_get_param {
  264. __u32 param;
  265. __u32 pad;
  266. __u64 value;
  267. };
  268. struct drm_vc4_get_tiling {
  269. __u32 handle;
  270. __u32 flags;
  271. __u64 modifier;
  272. };
  273. struct drm_vc4_set_tiling {
  274. __u32 handle;
  275. __u32 flags;
  276. __u64 modifier;
  277. };
  278. #if defined(__cplusplus)
  279. }
  280. #endif
  281. #endif /* _UAPI_VC4_DRM_H_ */