vc4_drm.h 9.2 KB

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