vc4_drm.h 8.8 KB

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