msm_drm.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __MSM_DRM_H__
  18. #define __MSM_DRM_H__
  19. #include "drm.h"
  20. #if defined(__cplusplus)
  21. extern "C" {
  22. #endif
  23. /* Please note that modifications to all structs defined here are
  24. * subject to backwards-compatibility constraints:
  25. * 1) Do not use pointers, use __u64 instead for 32 bit / 64 bit
  26. * user/kernel compatibility
  27. * 2) Keep fields aligned to their size
  28. * 3) Because of how drm_ioctl() works, we can add new fields at
  29. * the end of an ioctl if some care is taken: drm_ioctl() will
  30. * zero out the new fields at the tail of the ioctl, so a zero
  31. * value should have a backwards compatible meaning. And for
  32. * output params, userspace won't see the newly added output
  33. * fields.. so that has to be somehow ok.
  34. */
  35. #define MSM_PIPE_NONE 0x00
  36. #define MSM_PIPE_2D0 0x01
  37. #define MSM_PIPE_2D1 0x02
  38. #define MSM_PIPE_3D0 0x10
  39. /* The pipe-id just uses the lower bits, so can be OR'd with flags in
  40. * the upper 16 bits (which could be extended further, if needed, maybe
  41. * we extend/overload the pipe-id some day to deal with multiple rings,
  42. * but even then I don't think we need the full lower 16 bits).
  43. */
  44. #define MSM_PIPE_ID_MASK 0xffff
  45. #define MSM_PIPE_ID(x) ((x) & MSM_PIPE_ID_MASK)
  46. #define MSM_PIPE_FLAGS(x) ((x) & ~MSM_PIPE_ID_MASK)
  47. /* timeouts are specified in clock-monotonic absolute times (to simplify
  48. * restarting interrupted ioctls). The following struct is logically the
  49. * same as 'struct timespec' but 32/64b ABI safe.
  50. */
  51. struct drm_msm_timespec {
  52. __s64 tv_sec; /* seconds */
  53. __s64 tv_nsec; /* nanoseconds */
  54. };
  55. #define MSM_PARAM_GPU_ID 0x01
  56. #define MSM_PARAM_GMEM_SIZE 0x02
  57. #define MSM_PARAM_CHIP_ID 0x03
  58. #define MSM_PARAM_MAX_FREQ 0x04
  59. #define MSM_PARAM_TIMESTAMP 0x05
  60. struct drm_msm_param {
  61. __u32 pipe; /* in, MSM_PIPE_x */
  62. __u32 param; /* in, MSM_PARAM_x */
  63. __u64 value; /* out (get_param) or in (set_param) */
  64. };
  65. /*
  66. * GEM buffers:
  67. */
  68. #define MSM_BO_SCANOUT 0x00000001 /* scanout capable */
  69. #define MSM_BO_GPU_READONLY 0x00000002
  70. #define MSM_BO_CACHE_MASK 0x000f0000
  71. /* cache modes */
  72. #define MSM_BO_CACHED 0x00010000
  73. #define MSM_BO_WC 0x00020000
  74. #define MSM_BO_UNCACHED 0x00040000
  75. #define MSM_BO_FLAGS (MSM_BO_SCANOUT | \
  76. MSM_BO_GPU_READONLY | \
  77. MSM_BO_CACHED | \
  78. MSM_BO_WC | \
  79. MSM_BO_UNCACHED)
  80. struct drm_msm_gem_new {
  81. __u64 size; /* in */
  82. __u32 flags; /* in, mask of MSM_BO_x */
  83. __u32 handle; /* out */
  84. };
  85. struct drm_msm_gem_info {
  86. __u32 handle; /* in */
  87. __u32 pad;
  88. __u64 offset; /* out, offset to pass to mmap() */
  89. };
  90. #define MSM_PREP_READ 0x01
  91. #define MSM_PREP_WRITE 0x02
  92. #define MSM_PREP_NOSYNC 0x04
  93. #define MSM_PREP_FLAGS (MSM_PREP_READ | MSM_PREP_WRITE | MSM_PREP_NOSYNC)
  94. struct drm_msm_gem_cpu_prep {
  95. __u32 handle; /* in */
  96. __u32 op; /* in, mask of MSM_PREP_x */
  97. struct drm_msm_timespec timeout; /* in */
  98. };
  99. struct drm_msm_gem_cpu_fini {
  100. __u32 handle; /* in */
  101. };
  102. /*
  103. * Cmdstream Submission:
  104. */
  105. /* The value written into the cmdstream is logically:
  106. *
  107. * ((relocbuf->gpuaddr + reloc_offset) << shift) | or
  108. *
  109. * When we have GPU's w/ >32bit ptrs, it should be possible to deal
  110. * with this by emit'ing two reloc entries with appropriate shift
  111. * values. Or a new MSM_SUBMIT_CMD_x type would also be an option.
  112. *
  113. * NOTE that reloc's must be sorted by order of increasing submit_offset,
  114. * otherwise EINVAL.
  115. */
  116. struct drm_msm_gem_submit_reloc {
  117. __u32 submit_offset; /* in, offset from submit_bo */
  118. __u32 or; /* in, value OR'd with result */
  119. __s32 shift; /* in, amount of left shift (can be negative) */
  120. __u32 reloc_idx; /* in, index of reloc_bo buffer */
  121. __u64 reloc_offset; /* in, offset from start of reloc_bo */
  122. };
  123. /* submit-types:
  124. * BUF - this cmd buffer is executed normally.
  125. * IB_TARGET_BUF - this cmd buffer is an IB target. Reloc's are
  126. * processed normally, but the kernel does not setup an IB to
  127. * this buffer in the first-level ringbuffer
  128. * CTX_RESTORE_BUF - only executed if there has been a GPU context
  129. * switch since the last SUBMIT ioctl
  130. */
  131. #define MSM_SUBMIT_CMD_BUF 0x0001
  132. #define MSM_SUBMIT_CMD_IB_TARGET_BUF 0x0002
  133. #define MSM_SUBMIT_CMD_CTX_RESTORE_BUF 0x0003
  134. struct drm_msm_gem_submit_cmd {
  135. __u32 type; /* in, one of MSM_SUBMIT_CMD_x */
  136. __u32 submit_idx; /* in, index of submit_bo cmdstream buffer */
  137. __u32 submit_offset; /* in, offset into submit_bo */
  138. __u32 size; /* in, cmdstream size */
  139. __u32 pad;
  140. __u32 nr_relocs; /* in, number of submit_reloc's */
  141. __u64 __user relocs; /* in, ptr to array of submit_reloc's */
  142. };
  143. /* Each buffer referenced elsewhere in the cmdstream submit (ie. the
  144. * cmdstream buffer(s) themselves or reloc entries) has one (and only
  145. * one) entry in the submit->bos[] table.
  146. *
  147. * As a optimization, the current buffer (gpu virtual address) can be
  148. * passed back through the 'presumed' field. If on a subsequent reloc,
  149. * userspace passes back a 'presumed' address that is still valid,
  150. * then patching the cmdstream for this entry is skipped. This can
  151. * avoid kernel needing to map/access the cmdstream bo in the common
  152. * case.
  153. */
  154. #define MSM_SUBMIT_BO_READ 0x0001
  155. #define MSM_SUBMIT_BO_WRITE 0x0002
  156. #define MSM_SUBMIT_BO_FLAGS (MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE)
  157. struct drm_msm_gem_submit_bo {
  158. __u32 flags; /* in, mask of MSM_SUBMIT_BO_x */
  159. __u32 handle; /* in, GEM handle */
  160. __u64 presumed; /* in/out, presumed buffer address */
  161. };
  162. /* Valid submit ioctl flags: */
  163. #define MSM_SUBMIT_NO_IMPLICIT 0x80000000 /* disable implicit sync */
  164. #define MSM_SUBMIT_FENCE_FD_IN 0x40000000 /* enable input fence_fd */
  165. #define MSM_SUBMIT_FENCE_FD_OUT 0x20000000 /* enable output fence_fd */
  166. #define MSM_SUBMIT_FLAGS ( \
  167. MSM_SUBMIT_NO_IMPLICIT | \
  168. MSM_SUBMIT_FENCE_FD_IN | \
  169. MSM_SUBMIT_FENCE_FD_OUT | \
  170. 0)
  171. /* Each cmdstream submit consists of a table of buffers involved, and
  172. * one or more cmdstream buffers. This allows for conditional execution
  173. * (context-restore), and IB buffers needed for per tile/bin draw cmds.
  174. */
  175. struct drm_msm_gem_submit {
  176. __u32 flags; /* MSM_PIPE_x | MSM_SUBMIT_x */
  177. __u32 fence; /* out */
  178. __u32 nr_bos; /* in, number of submit_bo's */
  179. __u32 nr_cmds; /* in, number of submit_cmd's */
  180. __u64 __user bos; /* in, ptr to array of submit_bo's */
  181. __u64 __user cmds; /* in, ptr to array of submit_cmd's */
  182. __s32 fence_fd; /* in/out fence fd (see MSM_SUBMIT_FENCE_FD_IN/OUT) */
  183. };
  184. /* The normal way to synchronize with the GPU is just to CPU_PREP on
  185. * a buffer if you need to access it from the CPU (other cmdstream
  186. * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
  187. * handle the required synchronization under the hood). This ioctl
  188. * mainly just exists as a way to implement the gallium pipe_fence
  189. * APIs without requiring a dummy bo to synchronize on.
  190. */
  191. struct drm_msm_wait_fence {
  192. __u32 fence; /* in */
  193. __u32 pad;
  194. struct drm_msm_timespec timeout; /* in */
  195. };
  196. /* madvise provides a way to tell the kernel in case a buffers contents
  197. * can be discarded under memory pressure, which is useful for userspace
  198. * bo cache where we want to optimistically hold on to buffer allocate
  199. * and potential mmap, but allow the pages to be discarded under memory
  200. * pressure.
  201. *
  202. * Typical usage would involve madvise(DONTNEED) when buffer enters BO
  203. * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
  204. * In the WILLNEED case, 'retained' indicates to userspace whether the
  205. * backing pages still exist.
  206. */
  207. #define MSM_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */
  208. #define MSM_MADV_DONTNEED 1 /* backing pages not needed */
  209. #define __MSM_MADV_PURGED 2 /* internal state */
  210. struct drm_msm_gem_madvise {
  211. __u32 handle; /* in, GEM handle */
  212. __u32 madv; /* in, MSM_MADV_x */
  213. __u32 retained; /* out, whether backing store still exists */
  214. };
  215. #define DRM_MSM_GET_PARAM 0x00
  216. /* placeholder:
  217. #define DRM_MSM_SET_PARAM 0x01
  218. */
  219. #define DRM_MSM_GEM_NEW 0x02
  220. #define DRM_MSM_GEM_INFO 0x03
  221. #define DRM_MSM_GEM_CPU_PREP 0x04
  222. #define DRM_MSM_GEM_CPU_FINI 0x05
  223. #define DRM_MSM_GEM_SUBMIT 0x06
  224. #define DRM_MSM_WAIT_FENCE 0x07
  225. #define DRM_MSM_GEM_MADVISE 0x08
  226. #define DRM_MSM_NUM_IOCTLS 0x09
  227. #define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param)
  228. #define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
  229. #define DRM_IOCTL_MSM_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct drm_msm_gem_info)
  230. #define DRM_IOCTL_MSM_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_PREP, struct drm_msm_gem_cpu_prep)
  231. #define DRM_IOCTL_MSM_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_FINI, struct drm_msm_gem_cpu_fini)
  232. #define DRM_IOCTL_MSM_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_SUBMIT, struct drm_msm_gem_submit)
  233. #define DRM_IOCTL_MSM_WAIT_FENCE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_FENCE, struct drm_msm_wait_fence)
  234. #define DRM_IOCTL_MSM_GEM_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_MADVISE, struct drm_msm_gem_madvise)
  235. #if defined(__cplusplus)
  236. }
  237. #endif
  238. #endif /* __MSM_DRM_H__ */