panfrost_drm.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2014-2018 Broadcom
  4. * Copyright © 2019 Collabora ltd.
  5. */
  6. #ifndef _PANFROST_DRM_H_
  7. #define _PANFROST_DRM_H_
  8. #include "drm.h"
  9. #if defined(__cplusplus)
  10. extern "C" {
  11. #endif
  12. #define DRM_PANFROST_SUBMIT 0x00
  13. #define DRM_PANFROST_WAIT_BO 0x01
  14. #define DRM_PANFROST_CREATE_BO 0x02
  15. #define DRM_PANFROST_MMAP_BO 0x03
  16. #define DRM_PANFROST_GET_PARAM 0x04
  17. #define DRM_PANFROST_GET_BO_OFFSET 0x05
  18. #define DRM_PANFROST_PERFCNT_ENABLE 0x06
  19. #define DRM_PANFROST_PERFCNT_DUMP 0x07
  20. #define DRM_PANFROST_MADVISE 0x08
  21. #define DRM_IOCTL_PANFROST_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)
  22. #define DRM_IOCTL_PANFROST_WAIT_BO DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)
  23. #define DRM_IOCTL_PANFROST_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_CREATE_BO, struct drm_panfrost_create_bo)
  24. #define DRM_IOCTL_PANFROST_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MMAP_BO, struct drm_panfrost_mmap_bo)
  25. #define DRM_IOCTL_PANFROST_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param)
  26. #define DRM_IOCTL_PANFROST_GET_BO_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset)
  27. #define DRM_IOCTL_PANFROST_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise)
  28. /*
  29. * Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module
  30. * param is set to true.
  31. * All these ioctl(s) are subject to deprecation, so please don't rely on
  32. * them for anything but debugging purpose.
  33. */
  34. #define DRM_IOCTL_PANFROST_PERFCNT_ENABLE DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)
  35. #define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)
  36. #define PANFROST_JD_REQ_FS (1 << 0)
  37. /**
  38. * struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D
  39. * engine.
  40. *
  41. * This asks the kernel to have the GPU execute a render command list.
  42. */
  43. struct drm_panfrost_submit {
  44. /** Address to GPU mapping of job descriptor */
  45. __u64 jc;
  46. /** An optional array of sync objects to wait on before starting this job. */
  47. __u64 in_syncs;
  48. /** Number of sync objects to wait on before starting this job. */
  49. __u32 in_sync_count;
  50. /** An optional sync object to place the completion fence in. */
  51. __u32 out_sync;
  52. /** Pointer to a u32 array of the BOs that are referenced by the job. */
  53. __u64 bo_handles;
  54. /** Number of BO handles passed in (size is that times 4). */
  55. __u32 bo_handle_count;
  56. /** A combination of PANFROST_JD_REQ_* */
  57. __u32 requirements;
  58. };
  59. /**
  60. * struct drm_panfrost_wait_bo - ioctl argument for waiting for
  61. * completion of the last DRM_PANFROST_SUBMIT on a BO.
  62. *
  63. * This is useful for cases where multiple processes might be
  64. * rendering to a BO and you want to wait for all rendering to be
  65. * completed.
  66. */
  67. struct drm_panfrost_wait_bo {
  68. __u32 handle;
  69. __u32 pad;
  70. __s64 timeout_ns; /* absolute */
  71. };
  72. #define PANFROST_BO_NOEXEC 1
  73. #define PANFROST_BO_HEAP 2
  74. /**
  75. * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
  76. *
  77. * There are currently no values for the flags argument, but it may be
  78. * used in a future extension.
  79. */
  80. struct drm_panfrost_create_bo {
  81. __u32 size;
  82. __u32 flags;
  83. /** Returned GEM handle for the BO. */
  84. __u32 handle;
  85. /* Pad, must be zero-filled. */
  86. __u32 pad;
  87. /**
  88. * Returned offset for the BO in the GPU address space. This offset
  89. * is private to the DRM fd and is valid for the lifetime of the GEM
  90. * handle.
  91. *
  92. * This offset value will always be nonzero, since various HW
  93. * units treat 0 specially.
  94. */
  95. __u64 offset;
  96. };
  97. /**
  98. * struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.
  99. *
  100. * This doesn't actually perform an mmap. Instead, it returns the
  101. * offset you need to use in an mmap on the DRM device node. This
  102. * means that tools like valgrind end up knowing about the mapped
  103. * memory.
  104. *
  105. * There are currently no values for the flags argument, but it may be
  106. * used in a future extension.
  107. */
  108. struct drm_panfrost_mmap_bo {
  109. /** Handle for the object being mapped. */
  110. __u32 handle;
  111. __u32 flags;
  112. /** offset into the drm node to use for subsequent mmap call. */
  113. __u64 offset;
  114. };
  115. enum drm_panfrost_param {
  116. DRM_PANFROST_PARAM_GPU_PROD_ID,
  117. DRM_PANFROST_PARAM_GPU_REVISION,
  118. DRM_PANFROST_PARAM_SHADER_PRESENT,
  119. DRM_PANFROST_PARAM_TILER_PRESENT,
  120. DRM_PANFROST_PARAM_L2_PRESENT,
  121. DRM_PANFROST_PARAM_STACK_PRESENT,
  122. DRM_PANFROST_PARAM_AS_PRESENT,
  123. DRM_PANFROST_PARAM_JS_PRESENT,
  124. DRM_PANFROST_PARAM_L2_FEATURES,
  125. DRM_PANFROST_PARAM_CORE_FEATURES,
  126. DRM_PANFROST_PARAM_TILER_FEATURES,
  127. DRM_PANFROST_PARAM_MEM_FEATURES,
  128. DRM_PANFROST_PARAM_MMU_FEATURES,
  129. DRM_PANFROST_PARAM_THREAD_FEATURES,
  130. DRM_PANFROST_PARAM_MAX_THREADS,
  131. DRM_PANFROST_PARAM_THREAD_MAX_WORKGROUP_SZ,
  132. DRM_PANFROST_PARAM_THREAD_MAX_BARRIER_SZ,
  133. DRM_PANFROST_PARAM_COHERENCY_FEATURES,
  134. DRM_PANFROST_PARAM_TEXTURE_FEATURES0,
  135. DRM_PANFROST_PARAM_TEXTURE_FEATURES1,
  136. DRM_PANFROST_PARAM_TEXTURE_FEATURES2,
  137. DRM_PANFROST_PARAM_TEXTURE_FEATURES3,
  138. DRM_PANFROST_PARAM_JS_FEATURES0,
  139. DRM_PANFROST_PARAM_JS_FEATURES1,
  140. DRM_PANFROST_PARAM_JS_FEATURES2,
  141. DRM_PANFROST_PARAM_JS_FEATURES3,
  142. DRM_PANFROST_PARAM_JS_FEATURES4,
  143. DRM_PANFROST_PARAM_JS_FEATURES5,
  144. DRM_PANFROST_PARAM_JS_FEATURES6,
  145. DRM_PANFROST_PARAM_JS_FEATURES7,
  146. DRM_PANFROST_PARAM_JS_FEATURES8,
  147. DRM_PANFROST_PARAM_JS_FEATURES9,
  148. DRM_PANFROST_PARAM_JS_FEATURES10,
  149. DRM_PANFROST_PARAM_JS_FEATURES11,
  150. DRM_PANFROST_PARAM_JS_FEATURES12,
  151. DRM_PANFROST_PARAM_JS_FEATURES13,
  152. DRM_PANFROST_PARAM_JS_FEATURES14,
  153. DRM_PANFROST_PARAM_JS_FEATURES15,
  154. DRM_PANFROST_PARAM_NR_CORE_GROUPS,
  155. DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,
  156. };
  157. struct drm_panfrost_get_param {
  158. __u32 param;
  159. __u32 pad;
  160. __u64 value;
  161. };
  162. /**
  163. * Returns the offset for the BO in the GPU address space for this DRM fd.
  164. * This is the same value returned by drm_panfrost_create_bo, if that was called
  165. * from this DRM fd.
  166. */
  167. struct drm_panfrost_get_bo_offset {
  168. __u32 handle;
  169. __u32 pad;
  170. __u64 offset;
  171. };
  172. struct drm_panfrost_perfcnt_enable {
  173. __u32 enable;
  174. /*
  175. * On bifrost we have 2 sets of counters, this parameter defines the
  176. * one to track.
  177. */
  178. __u32 counterset;
  179. };
  180. struct drm_panfrost_perfcnt_dump {
  181. __u64 buf_ptr;
  182. };
  183. /* madvise provides a way to tell the kernel in case a buffers contents
  184. * can be discarded under memory pressure, which is useful for userspace
  185. * bo cache where we want to optimistically hold on to buffer allocate
  186. * and potential mmap, but allow the pages to be discarded under memory
  187. * pressure.
  188. *
  189. * Typical usage would involve madvise(DONTNEED) when buffer enters BO
  190. * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
  191. * In the WILLNEED case, 'retained' indicates to userspace whether the
  192. * backing pages still exist.
  193. */
  194. #define PANFROST_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */
  195. #define PANFROST_MADV_DONTNEED 1 /* backing pages not needed */
  196. struct drm_panfrost_madvise {
  197. __u32 handle; /* in, GEM handle */
  198. __u32 madv; /* in, PANFROST_MADV_x */
  199. __u32 retained; /* out, whether backing store still exists */
  200. };
  201. #if defined(__cplusplus)
  202. }
  203. #endif
  204. #endif /* _PANFROST_DRM_H_ */