msm_drm.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. /* Please note that modifications to all structs defined here are
  21. * subject to backwards-compatibility constraints:
  22. * 1) Do not use pointers, use __u64 instead for 32 bit / 64 bit
  23. * user/kernel compatibility
  24. * 2) Keep fields aligned to their size
  25. * 3) Because of how drm_ioctl() works, we can add new fields at
  26. * the end of an ioctl if some care is taken: drm_ioctl() will
  27. * zero out the new fields at the tail of the ioctl, so a zero
  28. * value should have a backwards compatible meaning. And for
  29. * output params, userspace won't see the newly added output
  30. * fields.. so that has to be somehow ok.
  31. */
  32. #define MSM_PIPE_NONE 0x00
  33. #define MSM_PIPE_2D0 0x01
  34. #define MSM_PIPE_2D1 0x02
  35. #define MSM_PIPE_3D0 0x10
  36. /* timeouts are specified in clock-monotonic absolute times (to simplify
  37. * restarting interrupted ioctls). The following struct is logically the
  38. * same as 'struct timespec' but 32/64b ABI safe.
  39. */
  40. struct drm_msm_timespec {
  41. __s64 tv_sec; /* seconds */
  42. __s64 tv_nsec; /* nanoseconds */
  43. };
  44. #define MSM_PARAM_GPU_ID 0x01
  45. #define MSM_PARAM_GMEM_SIZE 0x02
  46. #define MSM_PARAM_CHIP_ID 0x03
  47. #define MSM_PARAM_MAX_FREQ 0x04
  48. #define MSM_PARAM_TIMESTAMP 0x05
  49. struct drm_msm_param {
  50. __u32 pipe; /* in, MSM_PIPE_x */
  51. __u32 param; /* in, MSM_PARAM_x */
  52. __u64 value; /* out (get_param) or in (set_param) */
  53. };
  54. /*
  55. * GEM buffers:
  56. */
  57. #define MSM_BO_SCANOUT 0x00000001 /* scanout capable */
  58. #define MSM_BO_GPU_READONLY 0x00000002
  59. #define MSM_BO_CACHE_MASK 0x000f0000
  60. /* cache modes */
  61. #define MSM_BO_CACHED 0x00010000
  62. #define MSM_BO_WC 0x00020000
  63. #define MSM_BO_UNCACHED 0x00040000
  64. #define MSM_BO_FLAGS (MSM_BO_SCANOUT | \
  65. MSM_BO_GPU_READONLY | \
  66. MSM_BO_CACHED | \
  67. MSM_BO_WC | \
  68. MSM_BO_UNCACHED)
  69. struct drm_msm_gem_new {
  70. __u64 size; /* in */
  71. __u32 flags; /* in, mask of MSM_BO_x */
  72. __u32 handle; /* out */
  73. };
  74. struct drm_msm_gem_info {
  75. __u32 handle; /* in */
  76. __u32 pad;
  77. __u64 offset; /* out, offset to pass to mmap() */
  78. };
  79. #define MSM_PREP_READ 0x01
  80. #define MSM_PREP_WRITE 0x02
  81. #define MSM_PREP_NOSYNC 0x04
  82. #define MSM_PREP_FLAGS (MSM_PREP_READ | MSM_PREP_WRITE | MSM_PREP_NOSYNC)
  83. struct drm_msm_gem_cpu_prep {
  84. __u32 handle; /* in */
  85. __u32 op; /* in, mask of MSM_PREP_x */
  86. struct drm_msm_timespec timeout; /* in */
  87. };
  88. struct drm_msm_gem_cpu_fini {
  89. __u32 handle; /* in */
  90. };
  91. /*
  92. * Cmdstream Submission:
  93. */
  94. /* The value written into the cmdstream is logically:
  95. *
  96. * ((relocbuf->gpuaddr + reloc_offset) << shift) | or
  97. *
  98. * When we have GPU's w/ >32bit ptrs, it should be possible to deal
  99. * with this by emit'ing two reloc entries with appropriate shift
  100. * values. Or a new MSM_SUBMIT_CMD_x type would also be an option.
  101. *
  102. * NOTE that reloc's must be sorted by order of increasing submit_offset,
  103. * otherwise EINVAL.
  104. */
  105. struct drm_msm_gem_submit_reloc {
  106. __u32 submit_offset; /* in, offset from submit_bo */
  107. __u32 or; /* in, value OR'd with result */
  108. __s32 shift; /* in, amount of left shift (can be negative) */
  109. __u32 reloc_idx; /* in, index of reloc_bo buffer */
  110. __u64 reloc_offset; /* in, offset from start of reloc_bo */
  111. };
  112. /* submit-types:
  113. * BUF - this cmd buffer is executed normally.
  114. * IB_TARGET_BUF - this cmd buffer is an IB target. Reloc's are
  115. * processed normally, but the kernel does not setup an IB to
  116. * this buffer in the first-level ringbuffer
  117. * CTX_RESTORE_BUF - only executed if there has been a GPU context
  118. * switch since the last SUBMIT ioctl
  119. */
  120. #define MSM_SUBMIT_CMD_BUF 0x0001
  121. #define MSM_SUBMIT_CMD_IB_TARGET_BUF 0x0002
  122. #define MSM_SUBMIT_CMD_CTX_RESTORE_BUF 0x0003
  123. struct drm_msm_gem_submit_cmd {
  124. __u32 type; /* in, one of MSM_SUBMIT_CMD_x */
  125. __u32 submit_idx; /* in, index of submit_bo cmdstream buffer */
  126. __u32 submit_offset; /* in, offset into submit_bo */
  127. __u32 size; /* in, cmdstream size */
  128. __u32 pad;
  129. __u32 nr_relocs; /* in, number of submit_reloc's */
  130. __u64 __user relocs; /* in, ptr to array of submit_reloc's */
  131. };
  132. /* Each buffer referenced elsewhere in the cmdstream submit (ie. the
  133. * cmdstream buffer(s) themselves or reloc entries) has one (and only
  134. * one) entry in the submit->bos[] table.
  135. *
  136. * As a optimization, the current buffer (gpu virtual address) can be
  137. * passed back through the 'presumed' field. If on a subsequent reloc,
  138. * userspace passes back a 'presumed' address that is still valid,
  139. * then patching the cmdstream for this entry is skipped. This can
  140. * avoid kernel needing to map/access the cmdstream bo in the common
  141. * case.
  142. */
  143. #define MSM_SUBMIT_BO_READ 0x0001
  144. #define MSM_SUBMIT_BO_WRITE 0x0002
  145. #define MSM_SUBMIT_BO_FLAGS (MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE)
  146. struct drm_msm_gem_submit_bo {
  147. __u32 flags; /* in, mask of MSM_SUBMIT_BO_x */
  148. __u32 handle; /* in, GEM handle */
  149. __u64 presumed; /* in/out, presumed buffer address */
  150. };
  151. /* Each cmdstream submit consists of a table of buffers involved, and
  152. * one or more cmdstream buffers. This allows for conditional execution
  153. * (context-restore), and IB buffers needed for per tile/bin draw cmds.
  154. */
  155. struct drm_msm_gem_submit {
  156. __u32 pipe; /* in, MSM_PIPE_x */
  157. __u32 fence; /* out */
  158. __u32 nr_bos; /* in, number of submit_bo's */
  159. __u32 nr_cmds; /* in, number of submit_cmd's */
  160. __u64 __user bos; /* in, ptr to array of submit_bo's */
  161. __u64 __user cmds; /* in, ptr to array of submit_cmd's */
  162. };
  163. /* The normal way to synchronize with the GPU is just to CPU_PREP on
  164. * a buffer if you need to access it from the CPU (other cmdstream
  165. * submission from same or other contexts, PAGE_FLIP ioctl, etc, all
  166. * handle the required synchronization under the hood). This ioctl
  167. * mainly just exists as a way to implement the gallium pipe_fence
  168. * APIs without requiring a dummy bo to synchronize on.
  169. */
  170. struct drm_msm_wait_fence {
  171. __u32 fence; /* in */
  172. __u32 pad;
  173. struct drm_msm_timespec timeout; /* in */
  174. };
  175. #define DRM_MSM_GET_PARAM 0x00
  176. /* placeholder:
  177. #define DRM_MSM_SET_PARAM 0x01
  178. */
  179. #define DRM_MSM_GEM_NEW 0x02
  180. #define DRM_MSM_GEM_INFO 0x03
  181. #define DRM_MSM_GEM_CPU_PREP 0x04
  182. #define DRM_MSM_GEM_CPU_FINI 0x05
  183. #define DRM_MSM_GEM_SUBMIT 0x06
  184. #define DRM_MSM_WAIT_FENCE 0x07
  185. #define DRM_MSM_NUM_IOCTLS 0x08
  186. #define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param)
  187. #define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
  188. #define DRM_IOCTL_MSM_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct drm_msm_gem_info)
  189. #define DRM_IOCTL_MSM_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_PREP, struct drm_msm_gem_cpu_prep)
  190. #define DRM_IOCTL_MSM_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_GEM_CPU_FINI, struct drm_msm_gem_cpu_fini)
  191. #define DRM_IOCTL_MSM_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_SUBMIT, struct drm_msm_gem_submit)
  192. #define DRM_IOCTL_MSM_WAIT_FENCE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_FENCE, struct drm_msm_wait_fence)
  193. #endif /* __MSM_DRM_H__ */