v3d_drm.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /*
  2. * Copyright © 2014-2018 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 _V3D_DRM_H_
  24. #define _V3D_DRM_H_
  25. #include "drm.h"
  26. #if defined(__cplusplus)
  27. extern "C" {
  28. #endif
  29. #define DRM_V3D_SUBMIT_CL 0x00
  30. #define DRM_V3D_WAIT_BO 0x01
  31. #define DRM_V3D_CREATE_BO 0x02
  32. #define DRM_V3D_MMAP_BO 0x03
  33. #define DRM_V3D_GET_PARAM 0x04
  34. #define DRM_V3D_GET_BO_OFFSET 0x05
  35. #define DRM_V3D_SUBMIT_TFU 0x06
  36. #define DRM_V3D_SUBMIT_CSD 0x07
  37. #define DRM_V3D_PERFMON_CREATE 0x08
  38. #define DRM_V3D_PERFMON_DESTROY 0x09
  39. #define DRM_V3D_PERFMON_GET_VALUES 0x0a
  40. #define DRM_IOCTL_V3D_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CL, struct drm_v3d_submit_cl)
  41. #define DRM_IOCTL_V3D_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_WAIT_BO, struct drm_v3d_wait_bo)
  42. #define DRM_IOCTL_V3D_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_CREATE_BO, struct drm_v3d_create_bo)
  43. #define DRM_IOCTL_V3D_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_MMAP_BO, struct drm_v3d_mmap_bo)
  44. #define DRM_IOCTL_V3D_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_GET_PARAM, struct drm_v3d_get_param)
  45. #define DRM_IOCTL_V3D_GET_BO_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_GET_BO_OFFSET, struct drm_v3d_get_bo_offset)
  46. #define DRM_IOCTL_V3D_SUBMIT_TFU DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_TFU, struct drm_v3d_submit_tfu)
  47. #define DRM_IOCTL_V3D_SUBMIT_CSD DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CSD, struct drm_v3d_submit_csd)
  48. #define DRM_IOCTL_V3D_PERFMON_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_CREATE, \
  49. struct drm_v3d_perfmon_create)
  50. #define DRM_IOCTL_V3D_PERFMON_DESTROY DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_DESTROY, \
  51. struct drm_v3d_perfmon_destroy)
  52. #define DRM_IOCTL_V3D_PERFMON_GET_VALUES DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_GET_VALUES, \
  53. struct drm_v3d_perfmon_get_values)
  54. #define DRM_V3D_SUBMIT_CL_FLUSH_CACHE 0x01
  55. #define DRM_V3D_SUBMIT_EXTENSION 0x02
  56. /* struct drm_v3d_extension - ioctl extensions
  57. *
  58. * Linked-list of generic extensions where the id identify which struct is
  59. * pointed by ext_data. Therefore, DRM_V3D_EXT_ID_* is used on id to identify
  60. * the extension type.
  61. */
  62. struct drm_v3d_extension {
  63. __u64 next;
  64. __u32 id;
  65. #define DRM_V3D_EXT_ID_MULTI_SYNC 0x01
  66. __u32 flags; /* mbz */
  67. };
  68. /* struct drm_v3d_sem - wait/signal semaphore
  69. *
  70. * If binary semaphore, it only takes syncobj handle and ignores flags and
  71. * point fields. Point is defined for timeline syncobj feature.
  72. */
  73. struct drm_v3d_sem {
  74. __u32 handle; /* syncobj */
  75. /* rsv below, for future uses */
  76. __u32 flags;
  77. __u64 point; /* for timeline sem support */
  78. __u64 mbz[2]; /* must be zero, rsv */
  79. };
  80. /* Enum for each of the V3D queues. */
  81. enum v3d_queue {
  82. V3D_BIN,
  83. V3D_RENDER,
  84. V3D_TFU,
  85. V3D_CSD,
  86. V3D_CACHE_CLEAN,
  87. };
  88. /**
  89. * struct drm_v3d_multi_sync - ioctl extension to add support multiples
  90. * syncobjs for commands submission.
  91. *
  92. * When an extension of DRM_V3D_EXT_ID_MULTI_SYNC id is defined, it points to
  93. * this extension to define wait and signal dependencies, instead of single
  94. * in/out sync entries on submitting commands. The field flags is used to
  95. * determine the stage to set wait dependencies.
  96. */
  97. struct drm_v3d_multi_sync {
  98. struct drm_v3d_extension base;
  99. /* Array of wait and signal semaphores */
  100. __u64 in_syncs;
  101. __u64 out_syncs;
  102. /* Number of entries */
  103. __u32 in_sync_count;
  104. __u32 out_sync_count;
  105. /* set the stage (v3d_queue) to sync */
  106. __u32 wait_stage;
  107. __u32 pad; /* mbz */
  108. };
  109. /**
  110. * struct drm_v3d_submit_cl - ioctl argument for submitting commands to the 3D
  111. * engine.
  112. *
  113. * This asks the kernel to have the GPU execute an optional binner
  114. * command list, and a render command list.
  115. *
  116. * The L1T, slice, L2C, L2T, and GCA caches will be flushed before
  117. * each CL executes. The VCD cache should be flushed (if necessary)
  118. * by the submitted CLs. The TLB writes are guaranteed to have been
  119. * flushed by the time the render done IRQ happens, which is the
  120. * trigger for out_sync. Any dirtying of cachelines by the job (only
  121. * possible using TMU writes) must be flushed by the caller using the
  122. * DRM_V3D_SUBMIT_CL_FLUSH_CACHE_FLAG flag.
  123. */
  124. struct drm_v3d_submit_cl {
  125. /* Pointer to the binner command list.
  126. *
  127. * This is the first set of commands executed, which runs the
  128. * coordinate shader to determine where primitives land on the screen,
  129. * then writes out the state updates and draw calls necessary per tile
  130. * to the tile allocation BO.
  131. *
  132. * This BCL will block on any previous BCL submitted on the
  133. * same FD, but not on any RCL or BCLs submitted by other
  134. * clients -- that is left up to the submitter to control
  135. * using in_sync_bcl if necessary.
  136. */
  137. __u32 bcl_start;
  138. /** End address of the BCL (first byte after the BCL) */
  139. __u32 bcl_end;
  140. /* Offset of the render command list.
  141. *
  142. * This is the second set of commands executed, which will either
  143. * execute the tiles that have been set up by the BCL, or a fixed set
  144. * of tiles (in the case of RCL-only blits).
  145. *
  146. * This RCL will block on this submit's BCL, and any previous
  147. * RCL submitted on the same FD, but not on any RCL or BCLs
  148. * submitted by other clients -- that is left up to the
  149. * submitter to control using in_sync_rcl if necessary.
  150. */
  151. __u32 rcl_start;
  152. /** End address of the RCL (first byte after the RCL) */
  153. __u32 rcl_end;
  154. /** An optional sync object to wait on before starting the BCL. */
  155. __u32 in_sync_bcl;
  156. /** An optional sync object to wait on before starting the RCL. */
  157. __u32 in_sync_rcl;
  158. /** An optional sync object to place the completion fence in. */
  159. __u32 out_sync;
  160. /* Offset of the tile alloc memory
  161. *
  162. * This is optional on V3D 3.3 (where the CL can set the value) but
  163. * required on V3D 4.1.
  164. */
  165. __u32 qma;
  166. /** Size of the tile alloc memory. */
  167. __u32 qms;
  168. /** Offset of the tile state data array. */
  169. __u32 qts;
  170. /* Pointer to a u32 array of the BOs that are referenced by the job.
  171. */
  172. __u64 bo_handles;
  173. /* Number of BO handles passed in (size is that times 4). */
  174. __u32 bo_handle_count;
  175. /* DRM_V3D_SUBMIT_* properties */
  176. __u32 flags;
  177. /* ID of the perfmon to attach to this job. 0 means no perfmon. */
  178. __u32 perfmon_id;
  179. __u32 pad;
  180. /* Pointer to an array of ioctl extensions*/
  181. __u64 extensions;
  182. };
  183. /**
  184. * struct drm_v3d_wait_bo - ioctl argument for waiting for
  185. * completion of the last DRM_V3D_SUBMIT_CL on a BO.
  186. *
  187. * This is useful for cases where multiple processes might be
  188. * rendering to a BO and you want to wait for all rendering to be
  189. * completed.
  190. */
  191. struct drm_v3d_wait_bo {
  192. __u32 handle;
  193. __u32 pad;
  194. __u64 timeout_ns;
  195. };
  196. /**
  197. * struct drm_v3d_create_bo - ioctl argument for creating V3D BOs.
  198. *
  199. * There are currently no values for the flags argument, but it may be
  200. * used in a future extension.
  201. */
  202. struct drm_v3d_create_bo {
  203. __u32 size;
  204. __u32 flags;
  205. /** Returned GEM handle for the BO. */
  206. __u32 handle;
  207. /**
  208. * Returned offset for the BO in the V3D address space. This offset
  209. * is private to the DRM fd and is valid for the lifetime of the GEM
  210. * handle.
  211. *
  212. * This offset value will always be nonzero, since various HW
  213. * units treat 0 specially.
  214. */
  215. __u32 offset;
  216. };
  217. /**
  218. * struct drm_v3d_mmap_bo - ioctl argument for mapping V3D BOs.
  219. *
  220. * This doesn't actually perform an mmap. Instead, it returns the
  221. * offset you need to use in an mmap on the DRM device node. This
  222. * means that tools like valgrind end up knowing about the mapped
  223. * memory.
  224. *
  225. * There are currently no values for the flags argument, but it may be
  226. * used in a future extension.
  227. */
  228. struct drm_v3d_mmap_bo {
  229. /** Handle for the object being mapped. */
  230. __u32 handle;
  231. __u32 flags;
  232. /** offset into the drm node to use for subsequent mmap call. */
  233. __u64 offset;
  234. };
  235. enum drm_v3d_param {
  236. DRM_V3D_PARAM_V3D_UIFCFG,
  237. DRM_V3D_PARAM_V3D_HUB_IDENT1,
  238. DRM_V3D_PARAM_V3D_HUB_IDENT2,
  239. DRM_V3D_PARAM_V3D_HUB_IDENT3,
  240. DRM_V3D_PARAM_V3D_CORE0_IDENT0,
  241. DRM_V3D_PARAM_V3D_CORE0_IDENT1,
  242. DRM_V3D_PARAM_V3D_CORE0_IDENT2,
  243. DRM_V3D_PARAM_SUPPORTS_TFU,
  244. DRM_V3D_PARAM_SUPPORTS_CSD,
  245. DRM_V3D_PARAM_SUPPORTS_CACHE_FLUSH,
  246. DRM_V3D_PARAM_SUPPORTS_PERFMON,
  247. DRM_V3D_PARAM_SUPPORTS_MULTISYNC_EXT,
  248. };
  249. struct drm_v3d_get_param {
  250. __u32 param;
  251. __u32 pad;
  252. __u64 value;
  253. };
  254. /**
  255. * Returns the offset for the BO in the V3D address space for this DRM fd.
  256. * This is the same value returned by drm_v3d_create_bo, if that was called
  257. * from this DRM fd.
  258. */
  259. struct drm_v3d_get_bo_offset {
  260. __u32 handle;
  261. __u32 offset;
  262. };
  263. struct drm_v3d_submit_tfu {
  264. __u32 icfg;
  265. __u32 iia;
  266. __u32 iis;
  267. __u32 ica;
  268. __u32 iua;
  269. __u32 ioa;
  270. __u32 ios;
  271. __u32 coef[4];
  272. /* First handle is the output BO, following are other inputs.
  273. * 0 for unused.
  274. */
  275. __u32 bo_handles[4];
  276. /* sync object to block on before running the TFU job. Each TFU
  277. * job will execute in the order submitted to its FD. Synchronization
  278. * against rendering jobs requires using sync objects.
  279. */
  280. __u32 in_sync;
  281. /* Sync object to signal when the TFU job is done. */
  282. __u32 out_sync;
  283. __u32 flags;
  284. /* Pointer to an array of ioctl extensions*/
  285. __u64 extensions;
  286. };
  287. /* Submits a compute shader for dispatch. This job will block on any
  288. * previous compute shaders submitted on this fd, and any other
  289. * synchronization must be performed with in_sync/out_sync.
  290. */
  291. struct drm_v3d_submit_csd {
  292. __u32 cfg[7];
  293. __u32 coef[4];
  294. /* Pointer to a u32 array of the BOs that are referenced by the job.
  295. */
  296. __u64 bo_handles;
  297. /* Number of BO handles passed in (size is that times 4). */
  298. __u32 bo_handle_count;
  299. /* sync object to block on before running the CSD job. Each
  300. * CSD job will execute in the order submitted to its FD.
  301. * Synchronization against rendering/TFU jobs or CSD from
  302. * other fds requires using sync objects.
  303. */
  304. __u32 in_sync;
  305. /* Sync object to signal when the CSD job is done. */
  306. __u32 out_sync;
  307. /* ID of the perfmon to attach to this job. 0 means no perfmon. */
  308. __u32 perfmon_id;
  309. /* Pointer to an array of ioctl extensions*/
  310. __u64 extensions;
  311. __u32 flags;
  312. __u32 pad;
  313. };
  314. enum {
  315. V3D_PERFCNT_FEP_VALID_PRIMTS_NO_PIXELS,
  316. V3D_PERFCNT_FEP_VALID_PRIMS,
  317. V3D_PERFCNT_FEP_EZ_NFCLIP_QUADS,
  318. V3D_PERFCNT_FEP_VALID_QUADS,
  319. V3D_PERFCNT_TLB_QUADS_STENCIL_FAIL,
  320. V3D_PERFCNT_TLB_QUADS_STENCILZ_FAIL,
  321. V3D_PERFCNT_TLB_QUADS_STENCILZ_PASS,
  322. V3D_PERFCNT_TLB_QUADS_ZERO_COV,
  323. V3D_PERFCNT_TLB_QUADS_NONZERO_COV,
  324. V3D_PERFCNT_TLB_QUADS_WRITTEN,
  325. V3D_PERFCNT_PTB_PRIM_VIEWPOINT_DISCARD,
  326. V3D_PERFCNT_PTB_PRIM_CLIP,
  327. V3D_PERFCNT_PTB_PRIM_REV,
  328. V3D_PERFCNT_QPU_IDLE_CYCLES,
  329. V3D_PERFCNT_QPU_ACTIVE_CYCLES_VERTEX_COORD_USER,
  330. V3D_PERFCNT_QPU_ACTIVE_CYCLES_FRAG,
  331. V3D_PERFCNT_QPU_CYCLES_VALID_INSTR,
  332. V3D_PERFCNT_QPU_CYCLES_TMU_STALL,
  333. V3D_PERFCNT_QPU_CYCLES_SCOREBOARD_STALL,
  334. V3D_PERFCNT_QPU_CYCLES_VARYINGS_STALL,
  335. V3D_PERFCNT_QPU_IC_HIT,
  336. V3D_PERFCNT_QPU_IC_MISS,
  337. V3D_PERFCNT_QPU_UC_HIT,
  338. V3D_PERFCNT_QPU_UC_MISS,
  339. V3D_PERFCNT_TMU_TCACHE_ACCESS,
  340. V3D_PERFCNT_TMU_TCACHE_MISS,
  341. V3D_PERFCNT_VPM_VDW_STALL,
  342. V3D_PERFCNT_VPM_VCD_STALL,
  343. V3D_PERFCNT_BIN_ACTIVE,
  344. V3D_PERFCNT_RDR_ACTIVE,
  345. V3D_PERFCNT_L2T_HITS,
  346. V3D_PERFCNT_L2T_MISSES,
  347. V3D_PERFCNT_CYCLE_COUNT,
  348. V3D_PERFCNT_QPU_CYCLES_STALLED_VERTEX_COORD_USER,
  349. V3D_PERFCNT_QPU_CYCLES_STALLED_FRAGMENT,
  350. V3D_PERFCNT_PTB_PRIMS_BINNED,
  351. V3D_PERFCNT_AXI_WRITES_WATCH_0,
  352. V3D_PERFCNT_AXI_READS_WATCH_0,
  353. V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_0,
  354. V3D_PERFCNT_AXI_READ_STALLS_WATCH_0,
  355. V3D_PERFCNT_AXI_WRITE_BYTES_WATCH_0,
  356. V3D_PERFCNT_AXI_READ_BYTES_WATCH_0,
  357. V3D_PERFCNT_AXI_WRITES_WATCH_1,
  358. V3D_PERFCNT_AXI_READS_WATCH_1,
  359. V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_1,
  360. V3D_PERFCNT_AXI_READ_STALLS_WATCH_1,
  361. V3D_PERFCNT_AXI_WRITE_BYTES_WATCH_1,
  362. V3D_PERFCNT_AXI_READ_BYTES_WATCH_1,
  363. V3D_PERFCNT_TLB_PARTIAL_QUADS,
  364. V3D_PERFCNT_TMU_CONFIG_ACCESSES,
  365. V3D_PERFCNT_L2T_NO_ID_STALL,
  366. V3D_PERFCNT_L2T_COM_QUE_STALL,
  367. V3D_PERFCNT_L2T_TMU_WRITES,
  368. V3D_PERFCNT_TMU_ACTIVE_CYCLES,
  369. V3D_PERFCNT_TMU_STALLED_CYCLES,
  370. V3D_PERFCNT_CLE_ACTIVE,
  371. V3D_PERFCNT_L2T_TMU_READS,
  372. V3D_PERFCNT_L2T_CLE_READS,
  373. V3D_PERFCNT_L2T_VCD_READS,
  374. V3D_PERFCNT_L2T_TMUCFG_READS,
  375. V3D_PERFCNT_L2T_SLC0_READS,
  376. V3D_PERFCNT_L2T_SLC1_READS,
  377. V3D_PERFCNT_L2T_SLC2_READS,
  378. V3D_PERFCNT_L2T_TMU_W_MISSES,
  379. V3D_PERFCNT_L2T_TMU_R_MISSES,
  380. V3D_PERFCNT_L2T_CLE_MISSES,
  381. V3D_PERFCNT_L2T_VCD_MISSES,
  382. V3D_PERFCNT_L2T_TMUCFG_MISSES,
  383. V3D_PERFCNT_L2T_SLC0_MISSES,
  384. V3D_PERFCNT_L2T_SLC1_MISSES,
  385. V3D_PERFCNT_L2T_SLC2_MISSES,
  386. V3D_PERFCNT_CORE_MEM_WRITES,
  387. V3D_PERFCNT_L2T_MEM_WRITES,
  388. V3D_PERFCNT_PTB_MEM_WRITES,
  389. V3D_PERFCNT_TLB_MEM_WRITES,
  390. V3D_PERFCNT_CORE_MEM_READS,
  391. V3D_PERFCNT_L2T_MEM_READS,
  392. V3D_PERFCNT_PTB_MEM_READS,
  393. V3D_PERFCNT_PSE_MEM_READS,
  394. V3D_PERFCNT_TLB_MEM_READS,
  395. V3D_PERFCNT_GMP_MEM_READS,
  396. V3D_PERFCNT_PTB_W_MEM_WORDS,
  397. V3D_PERFCNT_TLB_W_MEM_WORDS,
  398. V3D_PERFCNT_PSE_R_MEM_WORDS,
  399. V3D_PERFCNT_TLB_R_MEM_WORDS,
  400. V3D_PERFCNT_TMU_MRU_HITS,
  401. V3D_PERFCNT_COMPUTE_ACTIVE,
  402. V3D_PERFCNT_NUM,
  403. };
  404. #define DRM_V3D_MAX_PERF_COUNTERS 32
  405. struct drm_v3d_perfmon_create {
  406. __u32 id;
  407. __u32 ncounters;
  408. __u8 counters[DRM_V3D_MAX_PERF_COUNTERS];
  409. };
  410. struct drm_v3d_perfmon_destroy {
  411. __u32 id;
  412. };
  413. /*
  414. * Returns the values of the performance counters tracked by this
  415. * perfmon (as an array of ncounters u64 values).
  416. *
  417. * No implicit synchronization is performed, so the user has to
  418. * guarantee that any jobs using this perfmon have already been
  419. * completed (probably by blocking on the seqno returned by the
  420. * last exec that used the perfmon).
  421. */
  422. struct drm_v3d_perfmon_get_values {
  423. __u32 id;
  424. __u32 pad;
  425. __u64 values_ptr;
  426. };
  427. #if defined(__cplusplus)
  428. }
  429. #endif
  430. #endif /* _V3D_DRM_H_ */