panfrost_drm.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. /* Valid flags to pass to drm_panfrost_create_bo */
  73. #define PANFROST_BO_NOEXEC 1
  74. #define PANFROST_BO_HEAP 2
  75. /**
  76. * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
  77. *
  78. * The flags argument is a bit mask of PANFROST_BO_* flags.
  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. DRM_PANFROST_PARAM_AFBC_FEATURES,
  157. };
  158. struct drm_panfrost_get_param {
  159. __u32 param;
  160. __u32 pad;
  161. __u64 value;
  162. };
  163. /**
  164. * Returns the offset for the BO in the GPU address space for this DRM fd.
  165. * This is the same value returned by drm_panfrost_create_bo, if that was called
  166. * from this DRM fd.
  167. */
  168. struct drm_panfrost_get_bo_offset {
  169. __u32 handle;
  170. __u32 pad;
  171. __u64 offset;
  172. };
  173. struct drm_panfrost_perfcnt_enable {
  174. __u32 enable;
  175. /*
  176. * On bifrost we have 2 sets of counters, this parameter defines the
  177. * one to track.
  178. */
  179. __u32 counterset;
  180. };
  181. struct drm_panfrost_perfcnt_dump {
  182. __u64 buf_ptr;
  183. };
  184. /* madvise provides a way to tell the kernel in case a buffers contents
  185. * can be discarded under memory pressure, which is useful for userspace
  186. * bo cache where we want to optimistically hold on to buffer allocate
  187. * and potential mmap, but allow the pages to be discarded under memory
  188. * pressure.
  189. *
  190. * Typical usage would involve madvise(DONTNEED) when buffer enters BO
  191. * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
  192. * In the WILLNEED case, 'retained' indicates to userspace whether the
  193. * backing pages still exist.
  194. */
  195. #define PANFROST_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */
  196. #define PANFROST_MADV_DONTNEED 1 /* backing pages not needed */
  197. struct drm_panfrost_madvise {
  198. __u32 handle; /* in, GEM handle */
  199. __u32 madv; /* in, PANFROST_MADV_x */
  200. __u32 retained; /* out, whether backing store still exists */
  201. };
  202. /* Definitions for coredump decoding in user space */
  203. #define PANFROSTDUMP_MAJOR 1
  204. #define PANFROSTDUMP_MINOR 0
  205. #define PANFROSTDUMP_MAGIC 0x464E4150 /* PANF */
  206. #define PANFROSTDUMP_BUF_REG 0
  207. #define PANFROSTDUMP_BUF_BOMAP (PANFROSTDUMP_BUF_REG + 1)
  208. #define PANFROSTDUMP_BUF_BO (PANFROSTDUMP_BUF_BOMAP + 1)
  209. #define PANFROSTDUMP_BUF_TRAILER (PANFROSTDUMP_BUF_BO + 1)
  210. /*
  211. * This structure is the native endianness of the dumping machine, tools can
  212. * detect the endianness by looking at the value in 'magic'.
  213. */
  214. struct panfrost_dump_object_header {
  215. __u32 magic;
  216. __u32 type;
  217. __u32 file_size;
  218. __u32 file_offset;
  219. union {
  220. struct {
  221. __u64 jc;
  222. __u32 gpu_id;
  223. __u32 major;
  224. __u32 minor;
  225. __u64 nbos;
  226. } reghdr;
  227. struct {
  228. __u32 valid;
  229. __u64 iova;
  230. __u32 data[2];
  231. } bomap;
  232. /*
  233. * Force same size in case we want to expand the header
  234. * with new fields and also keep it 512-byte aligned
  235. */
  236. __u32 sizer[496];
  237. };
  238. };
  239. /* Registers object, an array of these */
  240. struct panfrost_dump_registers {
  241. __u32 reg;
  242. __u32 value;
  243. };
  244. #if defined(__cplusplus)
  245. }
  246. #endif
  247. #endif /* _PANFROST_DRM_H_ */