msm_drm.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #ifndef __MSM_DRM_H__
  25. #define __MSM_DRM_H__
  26. #include "drm.h"
  27. #if defined(__cplusplus)
  28. extern "C" {
  29. #endif
  30. /* Please note that modifications to all structs defined here are
  31. * subject to backwards-compatibility constraints:
  32. * 1) Do not use pointers, use __u64 instead for 32 bit / 64 bit
  33. * user/kernel compatibility
  34. * 2) Keep fields aligned to their size
  35. * 3) Because of how drm_ioctl() works, we can add new fields at
  36. * the end of an ioctl if some care is taken: drm_ioctl() will
  37. * zero out the new fields at the tail of the ioctl, so a zero
  38. * value should have a backwards compatible meaning. And for
  39. * output params, userspace won't see the newly added output
  40. * fields.. so that has to be somehow ok.
  41. */
  42. #define MSM_PIPE_NONE 0x00
  43. #define MSM_PIPE_2D0 0x01
  44. #define MSM_PIPE_2D1 0x02
  45. #define MSM_PIPE_3D0 0x10
  46. /* The pipe-id just uses the lower bits, so can be OR'd with flags in
  47. * the upper 16 bits (which could be extended further, if needed, maybe
  48. * we extend/overload the pipe-id some day to deal with multiple rings,
  49. * but even then I don't think we need the full lower 16 bits).
  50. */
  51. #define MSM_PIPE_ID_MASK 0xffff
  52. #define MSM_PIPE_ID(x) ((x) & MSM_PIPE_ID_MASK)
  53. #define MSM_PIPE_FLAGS(x) ((x) & ~MSM_PIPE_ID_MASK)
  54. /* timeouts are specified in clock-monotonic absolute times (to simplify
  55. * restarting interrupted ioctls). The following struct is logically the
  56. * same as 'struct timespec' but 32/64b ABI safe.
  57. */
  58. struct drm_msm_timespec {
  59. __s64 tv_sec; /* seconds */
  60. __s64 tv_nsec; /* nanoseconds */
  61. };
  62. /* Below "RO" indicates a read-only param, "WO" indicates write-only, and
  63. * "RW" indicates a param that can be both read (GET_PARAM) and written
  64. * (SET_PARAM)
  65. */
  66. #define MSM_PARAM_GPU_ID 0x01 /* RO */
  67. #define MSM_PARAM_GMEM_SIZE 0x02 /* RO */
  68. #define MSM_PARAM_CHIP_ID 0x03 /* RO */
  69. #define MSM_PARAM_MAX_FREQ 0x04 /* RO */
  70. #define MSM_PARAM_TIMESTAMP 0x05 /* RO */
  71. #define MSM_PARAM_GMEM_BASE 0x06 /* RO */
  72. #define MSM_PARAM_PRIORITIES 0x07 /* RO: The # of priority levels */
  73. #define MSM_PARAM_PP_PGTABLE 0x08 /* RO: Deprecated, always returns zero */
  74. #define MSM_PARAM_FAULTS 0x09 /* RO */
  75. #define MSM_PARAM_SUSPENDS 0x0a /* RO */
  76. #define MSM_PARAM_SYSPROF 0x0b /* WO: 1 preserves perfcntrs, 2 also disables suspend */
  77. #define MSM_PARAM_COMM 0x0c /* WO: override for task->comm */
  78. #define MSM_PARAM_CMDLINE 0x0d /* WO: override for task cmdline */
  79. #define MSM_PARAM_VA_START 0x0e /* RO: start of valid GPU iova range */
  80. #define MSM_PARAM_VA_SIZE 0x0f /* RO: size of valid GPU iova range (bytes) */
  81. /* For backwards compat. The original support for preemption was based on
  82. * a single ring per priority level so # of priority levels equals the #
  83. * of rings. With drm/scheduler providing additional levels of priority,
  84. * the number of priorities is greater than the # of rings. The param is
  85. * renamed to better reflect this.
  86. */
  87. #define MSM_PARAM_NR_RINGS MSM_PARAM_PRIORITIES
  88. struct drm_msm_param {
  89. __u32 pipe; /* in, MSM_PIPE_x */
  90. __u32 param; /* in, MSM_PARAM_x */
  91. __u64 value; /* out (get_param) or in (set_param) */
  92. __u32 len; /* zero for non-pointer params */
  93. __u32 pad; /* must be zero */
  94. };
  95. /*
  96. * GEM buffers:
  97. */
  98. #define MSM_BO_SCANOUT 0x00000001 /* scanout capable */
  99. #define MSM_BO_GPU_READONLY 0x00000002
  100. #define MSM_BO_CACHE_MASK 0x000f0000
  101. /* cache modes */
  102. #define MSM_BO_CACHED 0x00010000
  103. #define MSM_BO_WC 0x00020000
  104. #define MSM_BO_UNCACHED 0x00040000 /* deprecated, use MSM_BO_WC */
  105. #define MSM_BO_CACHED_COHERENT 0x080000
  106. #define MSM_BO_FLAGS (MSM_BO_SCANOUT | \
  107. MSM_BO_GPU_READONLY | \
  108. MSM_BO_CACHE_MASK)
  109. struct drm_msm_gem_new {
  110. __u64 size; /* in */
  111. __u32 flags; /* in, mask of MSM_BO_x */
  112. __u32 handle; /* out */
  113. };
  114. /* Get or set GEM buffer info. The requested value can be passed
  115. * directly in 'value', or for data larger than 64b 'value' is a
  116. * pointer to userspace buffer, with 'len' specifying the number of
  117. * bytes copied into that buffer. For info returned by pointer,
  118. * calling the GEM_INFO ioctl with null 'value' will return the
  119. * required buffer size in 'len'
  120. */
  121. #define MSM_INFO_GET_OFFSET 0x00 /* get mmap() offset, returned by value */
  122. #define MSM_INFO_GET_IOVA 0x01 /* get iova, returned by value */
  123. #define MSM_INFO_SET_NAME 0x02 /* set the debug name (by pointer) */
  124. #define MSM_INFO_GET_NAME 0x03 /* get debug name, returned by pointer */
  125. #define MSM_INFO_SET_IOVA 0x04 /* set the iova, passed by value */
  126. #define MSM_INFO_GET_FLAGS 0x05 /* get the MSM_BO_x flags */
  127. struct drm_msm_gem_info {
  128. __u32 handle; /* in */
  129. __u32 info; /* in - one of MSM_INFO_* */
  130. __u64 value; /* in or out */
  131. __u32 len; /* in or out */
  132. __u32 pad;
  133. };
  134. #define MSM_PREP_READ 0x01
  135. #define MSM_PREP_WRITE 0x02
  136. #define MSM_PREP_NOSYNC 0x04
  137. #define MSM_PREP_BOOST 0x08
  138. #define MSM_PREP_FLAGS (MSM_PREP_READ | \
  139. MSM_PREP_WRITE | \
  140. MSM_PREP_NOSYNC | \
  141. MSM_PREP_BOOST | \
  142. 0)
  143. struct drm_msm_gem_cpu_prep {
  144. __u32 handle; /* in */
  145. __u32 op; /* in, mask of MSM_PREP_x */
  146. struct drm_msm_timespec timeout; /* in */
  147. };
  148. struct drm_msm_gem_cpu_fini {
  149. __u32 handle; /* in */
  150. };
  151. /*
  152. * Cmdstream Submission:
  153. */
  154. /* The value written into the cmdstream is logically:
  155. *
  156. * ((relocbuf->gpuaddr + reloc_offset) << shift) | or
  157. *
  158. * When we have GPU's w/ >32bit ptrs, it should be possible to deal
  159. * with this by emit'ing two reloc entries with appropriate shift
  160. * values. Or a new MSM_SUBMIT_CMD_x type would also be an option.
  161. *
  162. * NOTE that reloc's must be sorted by order of increasing submit_offset,
  163. * otherwise EINVAL.
  164. */
  165. struct drm_msm_gem_submit_reloc {
  166. __u32 submit_offset; /* in, offset from submit_bo */
  167. #ifdef __cplusplus
  168. __u32 _or; /* in, value OR'd with result */
  169. #else
  170. __u32 or; /* in, value OR'd with result */
  171. #endif
  172. __s32 shift; /* in, amount of left shift (can be negative) */
  173. __u32 reloc_idx; /* in, index of reloc_bo buffer */
  174. __u64 reloc_offset; /* in, offset from start of reloc_bo */
  175. };
  176. /* submit-types:
  177. * BUF - this cmd buffer is executed normally.
  178. * IB_TARGET_BUF - this cmd buffer is an IB target. Reloc's are
  179. * processed normally, but the kernel does not setup an IB to
  180. * this buffer in the first-level ringbuffer
  181. * CTX_RESTORE_BUF - only executed if there has been a GPU context
  182. * switch since the last SUBMIT ioctl
  183. */
  184. #define MSM_SUBMIT_CMD_BUF 0x0001
  185. #define MSM_SUBMIT_CMD_IB_TARGET_BUF 0x0002
  186. #define MSM_SUBMIT_CMD_CTX_RESTORE_BUF 0x0003
  187. struct drm_msm_gem_submit_cmd {
  188. __u32 type; /* in, one of MSM_SUBMIT_CMD_x */
  189. __u32 submit_idx; /* in, index of submit_bo cmdstream buffer */
  190. __u32 submit_offset; /* in, offset into submit_bo */
  191. __u32 size; /* in, cmdstream size */
  192. __u32 pad;
  193. __u32 nr_relocs; /* in, number of submit_reloc's */
  194. __u64 relocs; /* in, ptr to array of submit_reloc's */
  195. };
  196. /* Each buffer referenced elsewhere in the cmdstream submit (ie. the
  197. * cmdstream buffer(s) themselves or reloc entries) has one (and only
  198. * one) entry in the submit->bos[] table.
  199. *
  200. * As a optimization, the current buffer (gpu virtual address) can be
  201. * passed back through the 'presumed' field. If on a subsequent reloc,
  202. * userspace passes back a 'presumed' address that is still valid,
  203. * then patching the cmdstream for this entry is skipped. This can
  204. * avoid kernel needing to map/access the cmdstream bo in the common
  205. * case.
  206. */
  207. #define MSM_SUBMIT_BO_READ 0x0001
  208. #define MSM_SUBMIT_BO_WRITE 0x0002
  209. #define MSM_SUBMIT_BO_DUMP 0x0004
  210. #define MSM_SUBMIT_BO_NO_IMPLICIT 0x0008
  211. #define MSM_SUBMIT_BO_FLAGS (MSM_SUBMIT_BO_READ | \
  212. MSM_SUBMIT_BO_WRITE | \
  213. MSM_SUBMIT_BO_DUMP | \
  214. MSM_SUBMIT_BO_NO_IMPLICIT)
  215. struct drm_msm_gem_submit_bo {
  216. __u32 flags; /* in, mask of MSM_SUBMIT_BO_x */
  217. __u32 handle; /* in, GEM handle */
  218. __u64 presumed; /* in/out, presumed buffer address */
  219. };
  220. /* Valid submit ioctl flags: */
  221. #define MSM_SUBMIT_NO_IMPLICIT 0x80000000 /* disable implicit sync */
  222. #define MSM_SUBMIT_FENCE_FD_IN 0x40000000 /* enable input fence_fd */
  223. #define MSM_SUBMIT_FENCE_FD_OUT 0x20000000 /* enable output fence_fd */
  224. #define MSM_SUBMIT_SUDO 0x10000000 /* run submitted cmds from RB */
  225. #define MSM_SUBMIT_SYNCOBJ_IN 0x08000000 /* enable input syncobj */
  226. #define MSM_SUBMIT_SYNCOBJ_OUT 0x04000000 /* enable output syncobj */
  227. #define MSM_SUBMIT_FENCE_SN_IN 0x02000000 /* userspace passes in seqno fence */
  228. #define MSM_SUBMIT_FLAGS ( \
  229. MSM_SUBMIT_NO_IMPLICIT | \
  230. MSM_SUBMIT_FENCE_FD_IN | \
  231. MSM_SUBMIT_FENCE_FD_OUT | \
  232. MSM_SUBMIT_SUDO | \
  233. MSM_SUBMIT_SYNCOBJ_IN | \
  234. MSM_SUBMIT_SYNCOBJ_OUT | \
  235. MSM_SUBMIT_FENCE_SN_IN | \
  236. 0)
  237. #define MSM_SUBMIT_SYNCOBJ_RESET 0x00000001 /* Reset syncobj after wait. */
  238. #define MSM_SUBMIT_SYNCOBJ_FLAGS ( \
  239. MSM_SUBMIT_SYNCOBJ_RESET | \
  240. 0)
  241. struct drm_msm_gem_submit_syncobj {
  242. __u32 handle; /* in, syncobj handle. */
  243. __u32 flags; /* in, from MSM_SUBMIT_SYNCOBJ_FLAGS */
  244. __u64 point; /* in, timepoint for timeline syncobjs. */
  245. };
  246. /* Each cmdstream submit consists of a table of buffers involved, and
  247. * one or more cmdstream buffers. This allows for conditional execution
  248. * (context-restore), and IB buffers needed for per tile/bin draw cmds.
  249. */
  250. struct drm_msm_gem_submit {
  251. __u32 flags; /* MSM_PIPE_x | MSM_SUBMIT_x */
  252. __u32 fence; /* out (or in with MSM_SUBMIT_FENCE_SN_IN flag) */
  253. __u32 nr_bos; /* in, number of submit_bo's */
  254. __u32 nr_cmds; /* in, number of submit_cmd's */
  255. __u64 bos; /* in, ptr to array of submit_bo's */
  256. __u64 cmds; /* in, ptr to array of submit_cmd's */
  257. __s32 fence_fd; /* in/out fence fd (see MSM_SUBMIT_FENCE_FD_IN/OUT) */
  258. __u32 queueid; /* in, submitqueue id */
  259. __u64 in_syncobjs; /* in, ptr to array of drm_msm_gem_submit_syncobj */
  260. __u64 out_syncobjs; /* in, ptr to array of drm_msm_gem_submit_syncobj */
  261. __u32 nr_in_syncobjs; /* in, number of entries in in_syncobj */
  262. __u32 nr_out_syncobjs; /* in, number of entries in out_syncobj. */
  263. __u32 syncobj_stride; /* in, stride of syncobj arrays. */
  264. __u32 pad; /*in, reserved for future use, always 0. */
  265. };
  266. #define MSM_WAIT_FENCE_BOOST 0x00000001
  267. #define MSM_WAIT_FENCE_FLAGS ( \
  268. MSM_WAIT_FENCE_BOOST | \
  269. 0)
  270. /* The normal way to synchronize with the GPU is just to CPU_PREP on
  271. * a buffer if you need to access it from the CPU (other cmdstream
  272. * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
  273. * handle the required synchronization under the hood). This ioctl
  274. * mainly just exists as a way to implement the gallium pipe_fence
  275. * APIs without requiring a dummy bo to synchronize on.
  276. */
  277. struct drm_msm_wait_fence {
  278. __u32 fence; /* in */
  279. __u32 flags; /* in, bitmask of MSM_WAIT_FENCE_x */
  280. struct drm_msm_timespec timeout; /* in */
  281. __u32 queueid; /* in, submitqueue id */
  282. };
  283. /* madvise provides a way to tell the kernel in case a buffers contents
  284. * can be discarded under memory pressure, which is useful for userspace
  285. * bo cache where we want to optimistically hold on to buffer allocate
  286. * and potential mmap, but allow the pages to be discarded under memory
  287. * pressure.
  288. *
  289. * Typical usage would involve madvise(DONTNEED) when buffer enters BO
  290. * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
  291. * In the WILLNEED case, 'retained' indicates to userspace whether the
  292. * backing pages still exist.
  293. */
  294. #define MSM_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */
  295. #define MSM_MADV_DONTNEED 1 /* backing pages not needed */
  296. #define __MSM_MADV_PURGED 2 /* internal state */
  297. struct drm_msm_gem_madvise {
  298. __u32 handle; /* in, GEM handle */
  299. __u32 madv; /* in, MSM_MADV_x */
  300. __u32 retained; /* out, whether backing store still exists */
  301. };
  302. /*
  303. * Draw queues allow the user to set specific submission parameter. Command
  304. * submissions specify a specific submitqueue to use. ID 0 is reserved for
  305. * backwards compatibility as a "default" submitqueue
  306. */
  307. #define MSM_SUBMITQUEUE_FLAGS (0)
  308. /*
  309. * The submitqueue priority should be between 0 and MSM_PARAM_PRIORITIES-1,
  310. * a lower numeric value is higher priority.
  311. */
  312. struct drm_msm_submitqueue {
  313. __u32 flags; /* in, MSM_SUBMITQUEUE_x */
  314. __u32 prio; /* in, Priority level */
  315. __u32 id; /* out, identifier */
  316. };
  317. #define MSM_SUBMITQUEUE_PARAM_FAULTS 0
  318. struct drm_msm_submitqueue_query {
  319. __u64 data;
  320. __u32 id;
  321. __u32 param;
  322. __u32 len;
  323. __u32 pad;
  324. };
  325. #define DRM_MSM_GET_PARAM 0x00
  326. #define DRM_MSM_SET_PARAM 0x01
  327. #define DRM_MSM_GEM_NEW 0x02
  328. #define DRM_MSM_GEM_INFO 0x03
  329. #define DRM_MSM_GEM_CPU_PREP 0x04
  330. #define DRM_MSM_GEM_CPU_FINI 0x05
  331. #define DRM_MSM_GEM_SUBMIT 0x06
  332. #define DRM_MSM_WAIT_FENCE 0x07
  333. #define DRM_MSM_GEM_MADVISE 0x08
  334. /* placeholder:
  335. #define DRM_MSM_GEM_SVM_NEW 0x09
  336. */
  337. #define DRM_MSM_SUBMITQUEUE_NEW 0x0A
  338. #define DRM_MSM_SUBMITQUEUE_CLOSE 0x0B
  339. #define DRM_MSM_SUBMITQUEUE_QUERY 0x0C
  340. #define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param)
  341. #define DRM_IOCTL_MSM_SET_PARAM DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_SET_PARAM, struct drm_msm_param)
  342. #define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
  343. #define DRM_IOCTL_MSM_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct drm_msm_gem_info)
  344. #define DRM_IOCTL_MSM_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_PREP, struct drm_msm_gem_cpu_prep)
  345. #define DRM_IOCTL_MSM_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_FINI, struct drm_msm_gem_cpu_fini)
  346. #define DRM_IOCTL_MSM_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_SUBMIT, struct drm_msm_gem_submit)
  347. #define DRM_IOCTL_MSM_WAIT_FENCE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_FENCE, struct drm_msm_wait_fence)
  348. #define DRM_IOCTL_MSM_GEM_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_MADVISE, struct drm_msm_gem_madvise)
  349. #define DRM_IOCTL_MSM_SUBMITQUEUE_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_SUBMITQUEUE_NEW, struct drm_msm_submitqueue)
  350. #define DRM_IOCTL_MSM_SUBMITQUEUE_CLOSE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_SUBMITQUEUE_CLOSE, __u32)
  351. #define DRM_IOCTL_MSM_SUBMITQUEUE_QUERY DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_SUBMITQUEUE_QUERY, struct drm_msm_submitqueue_query)
  352. #if defined(__cplusplus)
  353. }
  354. #endif
  355. #endif /* __MSM_DRM_H__ */