vc4_drm.h 8.9 KB

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