vc4_drm.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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 _VC4_DRM_H_
  24. #define _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_VC4_LABEL_BO 0x0a
  40. #define DRM_VC4_GEM_MADVISE 0x0b
  41. #define DRM_VC4_PERFMON_CREATE 0x0c
  42. #define DRM_VC4_PERFMON_DESTROY 0x0d
  43. #define DRM_VC4_PERFMON_GET_VALUES 0x0e
  44. #define DRM_IOCTL_VC4_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl)
  45. #define DRM_IOCTL_VC4_WAIT_SEQNO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno)
  46. #define DRM_IOCTL_VC4_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_BO, struct drm_vc4_wait_bo)
  47. #define DRM_IOCTL_VC4_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo)
  48. #define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo)
  49. #define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo)
  50. #define DRM_IOCTL_VC4_GET_HANG_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state)
  51. #define DRM_IOCTL_VC4_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param)
  52. #define DRM_IOCTL_VC4_SET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SET_TILING, struct drm_vc4_set_tiling)
  53. #define DRM_IOCTL_VC4_GET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_TILING, struct drm_vc4_get_tiling)
  54. #define DRM_IOCTL_VC4_LABEL_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_LABEL_BO, struct drm_vc4_label_bo)
  55. #define DRM_IOCTL_VC4_GEM_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GEM_MADVISE, struct drm_vc4_gem_madvise)
  56. #define DRM_IOCTL_VC4_PERFMON_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_PERFMON_CREATE, struct drm_vc4_perfmon_create)
  57. #define DRM_IOCTL_VC4_PERFMON_DESTROY DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_PERFMON_DESTROY, struct drm_vc4_perfmon_destroy)
  58. #define DRM_IOCTL_VC4_PERFMON_GET_VALUES DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_PERFMON_GET_VALUES, struct drm_vc4_perfmon_get_values)
  59. struct drm_vc4_submit_rcl_surface {
  60. __u32 hindex; /* Handle index, or ~0 if not present. */
  61. __u32 offset; /* Offset to start of buffer. */
  62. /*
  63. * Bits for either render config (color_write) or load/store packet.
  64. * Bits should all be 0 for MSAA load/stores.
  65. */
  66. __u16 bits;
  67. #define VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES (1 << 0)
  68. __u16 flags;
  69. };
  70. /**
  71. * struct drm_vc4_submit_cl - ioctl argument for submitting commands to the 3D
  72. * engine.
  73. *
  74. * Drivers typically use GPU BOs to store batchbuffers / command lists and
  75. * their associated state. However, because the VC4 lacks an MMU, we have to
  76. * do validation of memory accesses by the GPU commands. If we were to store
  77. * our commands in BOs, we'd need to do uncached readback from them to do the
  78. * validation process, which is too expensive. Instead, userspace accumulates
  79. * commands and associated state in plain memory, then the kernel copies the
  80. * data to its own address space, and then validates and stores it in a GPU
  81. * BO.
  82. */
  83. struct drm_vc4_submit_cl {
  84. /* Pointer to the binner command list.
  85. *
  86. * This is the first set of commands executed, which runs the
  87. * coordinate shader to determine where primitives land on the screen,
  88. * then writes out the state updates and draw calls necessary per tile
  89. * to the tile allocation BO.
  90. */
  91. __u64 bin_cl;
  92. /* Pointer to the shader records.
  93. *
  94. * Shader records are the structures read by the hardware that contain
  95. * pointers to uniforms, shaders, and vertex attributes. The
  96. * reference to the shader record has enough information to determine
  97. * how many pointers are necessary (fixed number for shaders/uniforms,
  98. * and an attribute count), so those BO indices into bo_handles are
  99. * just stored as __u32s before each shader record passed in.
  100. */
  101. __u64 shader_rec;
  102. /* Pointer to uniform data and texture handles for the textures
  103. * referenced by the shader.
  104. *
  105. * For each shader state record, there is a set of uniform data in the
  106. * order referenced by the record (FS, VS, then CS). Each set of
  107. * uniform data has a __u32 index into bo_handles per texture
  108. * sample operation, in the order the QPU_W_TMUn_S writes appear in
  109. * the program. Following the texture BO handle indices is the actual
  110. * uniform data.
  111. *
  112. * The individual uniform state blocks don't have sizes passed in,
  113. * because the kernel has to determine the sizes anyway during shader
  114. * code validation.
  115. */
  116. __u64 uniforms;
  117. __u64 bo_handles;
  118. /* Size in bytes of the binner command list. */
  119. __u32 bin_cl_size;
  120. /* Size in bytes of the set of shader records. */
  121. __u32 shader_rec_size;
  122. /* Number of shader records.
  123. *
  124. * This could just be computed from the contents of shader_records and
  125. * the address bits of references to them from the bin CL, but it
  126. * keeps the kernel from having to resize some allocations it makes.
  127. */
  128. __u32 shader_rec_count;
  129. /* Size in bytes of the uniform state. */
  130. __u32 uniforms_size;
  131. /* Number of BO handles passed in (size is that times 4). */
  132. __u32 bo_handle_count;
  133. /* RCL setup: */
  134. __u16 width;
  135. __u16 height;
  136. __u8 min_x_tile;
  137. __u8 min_y_tile;
  138. __u8 max_x_tile;
  139. __u8 max_y_tile;
  140. struct drm_vc4_submit_rcl_surface color_read;
  141. struct drm_vc4_submit_rcl_surface color_write;
  142. struct drm_vc4_submit_rcl_surface zs_read;
  143. struct drm_vc4_submit_rcl_surface zs_write;
  144. struct drm_vc4_submit_rcl_surface msaa_color_write;
  145. struct drm_vc4_submit_rcl_surface msaa_zs_write;
  146. __u32 clear_color[2];
  147. __u32 clear_z;
  148. __u8 clear_s;
  149. __u32 pad:24;
  150. #define VC4_SUBMIT_CL_USE_CLEAR_COLOR (1 << 0)
  151. /* By default, the kernel gets to choose the order that the tiles are
  152. * rendered in. If this is set, then the tiles will be rendered in a
  153. * raster order, with the right-to-left vs left-to-right and
  154. * top-to-bottom vs bottom-to-top dictated by
  155. * VC4_SUBMIT_CL_RCL_ORDER_INCREASING_*. This allows overlapping
  156. * blits to be implemented using the 3D engine.
  157. */
  158. #define VC4_SUBMIT_CL_FIXED_RCL_ORDER (1 << 1)
  159. #define VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X (1 << 2)
  160. #define VC4_SUBMIT_CL_RCL_ORDER_INCREASING_Y (1 << 3)
  161. __u32 flags;
  162. /* Returned value of the seqno of this render job (for the
  163. * wait ioctl).
  164. */
  165. __u64 seqno;
  166. /* ID of the perfmon to attach to this job. 0 means no perfmon. */
  167. __u32 perfmonid;
  168. /* Syncobj handle to wait on. If set, processing of this render job
  169. * will not start until the syncobj is signaled. 0 means ignore.
  170. */
  171. __u32 in_sync;
  172. /* Syncobj handle to export fence to. If set, the fence in the syncobj
  173. * will be replaced with a fence that signals upon completion of this
  174. * render job. 0 means ignore.
  175. */
  176. __u32 out_sync;
  177. __u32 pad2;
  178. };
  179. /**
  180. * struct drm_vc4_wait_seqno - ioctl argument for waiting for
  181. * DRM_VC4_SUBMIT_CL completion using its returned seqno.
  182. *
  183. * timeout_ns is the timeout in nanoseconds, where "0" means "don't
  184. * block, just return the status."
  185. */
  186. struct drm_vc4_wait_seqno {
  187. __u64 seqno;
  188. __u64 timeout_ns;
  189. };
  190. /**
  191. * struct drm_vc4_wait_bo - ioctl argument for waiting for
  192. * completion of the last DRM_VC4_SUBMIT_CL on a BO.
  193. *
  194. * This is useful for cases where multiple processes might be
  195. * rendering to a BO and you want to wait for all rendering to be
  196. * completed.
  197. */
  198. struct drm_vc4_wait_bo {
  199. __u32 handle;
  200. __u32 pad;
  201. __u64 timeout_ns;
  202. };
  203. /**
  204. * struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs.
  205. *
  206. * There are currently no values for the flags argument, but it may be
  207. * used in a future extension.
  208. */
  209. struct drm_vc4_create_bo {
  210. __u32 size;
  211. __u32 flags;
  212. /** Returned GEM handle for the BO. */
  213. __u32 handle;
  214. __u32 pad;
  215. };
  216. /**
  217. * struct drm_vc4_mmap_bo - ioctl argument for mapping VC4 BOs.
  218. *
  219. * This doesn't actually perform an mmap. Instead, it returns the
  220. * offset you need to use in an mmap on the DRM device node. This
  221. * means that tools like valgrind end up knowing about the mapped
  222. * memory.
  223. *
  224. * There are currently no values for the flags argument, but it may be
  225. * used in a future extension.
  226. */
  227. struct drm_vc4_mmap_bo {
  228. /** Handle for the object being mapped. */
  229. __u32 handle;
  230. __u32 flags;
  231. /** offset into the drm node to use for subsequent mmap call. */
  232. __u64 offset;
  233. };
  234. /**
  235. * struct drm_vc4_create_shader_bo - ioctl argument for creating VC4
  236. * shader BOs.
  237. *
  238. * Since allowing a shader to be overwritten while it's also being
  239. * executed from would allow privlege escalation, shaders must be
  240. * created using this ioctl, and they can't be mmapped later.
  241. */
  242. struct drm_vc4_create_shader_bo {
  243. /* Size of the data argument. */
  244. __u32 size;
  245. /* Flags, currently must be 0. */
  246. __u32 flags;
  247. /* Pointer to the data. */
  248. __u64 data;
  249. /** Returned GEM handle for the BO. */
  250. __u32 handle;
  251. /* Pad, must be 0. */
  252. __u32 pad;
  253. };
  254. struct drm_vc4_get_hang_state_bo {
  255. __u32 handle;
  256. __u32 paddr;
  257. __u32 size;
  258. __u32 pad;
  259. };
  260. /**
  261. * struct drm_vc4_hang_state - ioctl argument for collecting state
  262. * from a GPU hang for analysis.
  263. */
  264. struct drm_vc4_get_hang_state {
  265. /** Pointer to array of struct drm_vc4_get_hang_state_bo. */
  266. __u64 bo;
  267. /**
  268. * On input, the size of the bo array. Output is the number
  269. * of bos to be returned.
  270. */
  271. __u32 bo_count;
  272. __u32 start_bin, start_render;
  273. __u32 ct0ca, ct0ea;
  274. __u32 ct1ca, ct1ea;
  275. __u32 ct0cs, ct1cs;
  276. __u32 ct0ra0, ct1ra0;
  277. __u32 bpca, bpcs;
  278. __u32 bpoa, bpos;
  279. __u32 vpmbase;
  280. __u32 dbge;
  281. __u32 fdbgo;
  282. __u32 fdbgb;
  283. __u32 fdbgr;
  284. __u32 fdbgs;
  285. __u32 errstat;
  286. /* Pad that we may save more registers into in the future. */
  287. __u32 pad[16];
  288. };
  289. #define DRM_VC4_PARAM_V3D_IDENT0 0
  290. #define DRM_VC4_PARAM_V3D_IDENT1 1
  291. #define DRM_VC4_PARAM_V3D_IDENT2 2
  292. #define DRM_VC4_PARAM_SUPPORTS_BRANCHES 3
  293. #define DRM_VC4_PARAM_SUPPORTS_ETC1 4
  294. #define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 5
  295. #define DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER 6
  296. #define DRM_VC4_PARAM_SUPPORTS_MADVISE 7
  297. #define DRM_VC4_PARAM_SUPPORTS_PERFMON 8
  298. struct drm_vc4_get_param {
  299. __u32 param;
  300. __u32 pad;
  301. __u64 value;
  302. };
  303. struct drm_vc4_get_tiling {
  304. __u32 handle;
  305. __u32 flags;
  306. __u64 modifier;
  307. };
  308. struct drm_vc4_set_tiling {
  309. __u32 handle;
  310. __u32 flags;
  311. __u64 modifier;
  312. };
  313. /**
  314. * struct drm_vc4_label_bo - Attach a name to a BO for debug purposes.
  315. */
  316. struct drm_vc4_label_bo {
  317. __u32 handle;
  318. __u32 len;
  319. __u64 name;
  320. };
  321. /*
  322. * States prefixed with '__' are internal states and cannot be passed to the
  323. * DRM_IOCTL_VC4_GEM_MADVISE ioctl.
  324. */
  325. #define VC4_MADV_WILLNEED 0
  326. #define VC4_MADV_DONTNEED 1
  327. #define __VC4_MADV_PURGED 2
  328. #define __VC4_MADV_NOTSUPP 3
  329. struct drm_vc4_gem_madvise {
  330. __u32 handle;
  331. __u32 madv;
  332. __u32 retained;
  333. __u32 pad;
  334. };
  335. enum {
  336. VC4_PERFCNT_FEP_VALID_PRIMS_NO_RENDER,
  337. VC4_PERFCNT_FEP_VALID_PRIMS_RENDER,
  338. VC4_PERFCNT_FEP_CLIPPED_QUADS,
  339. VC4_PERFCNT_FEP_VALID_QUADS,
  340. VC4_PERFCNT_TLB_QUADS_NOT_PASSING_STENCIL,
  341. VC4_PERFCNT_TLB_QUADS_NOT_PASSING_Z_AND_STENCIL,
  342. VC4_PERFCNT_TLB_QUADS_PASSING_Z_AND_STENCIL,
  343. VC4_PERFCNT_TLB_QUADS_ZERO_COVERAGE,
  344. VC4_PERFCNT_TLB_QUADS_NON_ZERO_COVERAGE,
  345. VC4_PERFCNT_TLB_QUADS_WRITTEN_TO_COLOR_BUF,
  346. VC4_PERFCNT_PLB_PRIMS_OUTSIDE_VIEWPORT,
  347. VC4_PERFCNT_PLB_PRIMS_NEED_CLIPPING,
  348. VC4_PERFCNT_PSE_PRIMS_REVERSED,
  349. VC4_PERFCNT_QPU_TOTAL_IDLE_CYCLES,
  350. VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_VERTEX_COORD_SHADING,
  351. VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_FRAGMENT_SHADING,
  352. VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_EXEC_VALID_INST,
  353. VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_WAITING_TMUS,
  354. VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_WAITING_SCOREBOARD,
  355. VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_WAITING_VARYINGS,
  356. VC4_PERFCNT_QPU_TOTAL_INST_CACHE_HIT,
  357. VC4_PERFCNT_QPU_TOTAL_INST_CACHE_MISS,
  358. VC4_PERFCNT_QPU_TOTAL_UNIFORM_CACHE_HIT,
  359. VC4_PERFCNT_QPU_TOTAL_UNIFORM_CACHE_MISS,
  360. VC4_PERFCNT_TMU_TOTAL_TEXT_QUADS_PROCESSED,
  361. VC4_PERFCNT_TMU_TOTAL_TEXT_CACHE_MISS,
  362. VC4_PERFCNT_VPM_TOTAL_CLK_CYCLES_VDW_STALLED,
  363. VC4_PERFCNT_VPM_TOTAL_CLK_CYCLES_VCD_STALLED,
  364. VC4_PERFCNT_L2C_TOTAL_L2_CACHE_HIT,
  365. VC4_PERFCNT_L2C_TOTAL_L2_CACHE_MISS,
  366. VC4_PERFCNT_NUM_EVENTS,
  367. };
  368. #define DRM_VC4_MAX_PERF_COUNTERS 16
  369. struct drm_vc4_perfmon_create {
  370. __u32 id;
  371. __u32 ncounters;
  372. __u8 events[DRM_VC4_MAX_PERF_COUNTERS];
  373. };
  374. struct drm_vc4_perfmon_destroy {
  375. __u32 id;
  376. };
  377. /*
  378. * Returns the values of the performance counters tracked by this
  379. * perfmon (as an array of ncounters u64 values).
  380. *
  381. * No implicit synchronization is performed, so the user has to
  382. * guarantee that any jobs using this perfmon have already been
  383. * completed (probably by blocking on the seqno returned by the
  384. * last exec that used the perfmon).
  385. */
  386. struct drm_vc4_perfmon_get_values {
  387. __u32 id;
  388. __u64 values_ptr;
  389. };
  390. #if defined(__cplusplus)
  391. }
  392. #endif
  393. #endif /* _VC4_DRM_H_ */