msm_drm.h 7.8 KB

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