panfrost_drm.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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_PANFROST_SET_LABEL_BO 0x09
  22. #define DRM_PANFROST_JM_CTX_CREATE 0x0a
  23. #define DRM_PANFROST_JM_CTX_DESTROY 0x0b
  24. #define DRM_PANFROST_SYNC_BO 0x0c
  25. #define DRM_PANFROST_QUERY_BO_INFO 0x0d
  26. #define DRM_IOCTL_PANFROST_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)
  27. #define DRM_IOCTL_PANFROST_WAIT_BO DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)
  28. #define DRM_IOCTL_PANFROST_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_CREATE_BO, struct drm_panfrost_create_bo)
  29. #define DRM_IOCTL_PANFROST_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MMAP_BO, struct drm_panfrost_mmap_bo)
  30. #define DRM_IOCTL_PANFROST_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param)
  31. #define DRM_IOCTL_PANFROST_GET_BO_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset)
  32. #define DRM_IOCTL_PANFROST_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise)
  33. #define DRM_IOCTL_PANFROST_SET_LABEL_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_SET_LABEL_BO, struct drm_panfrost_set_label_bo)
  34. #define DRM_IOCTL_PANFROST_JM_CTX_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_CREATE, struct drm_panfrost_jm_ctx_create)
  35. #define DRM_IOCTL_PANFROST_JM_CTX_DESTROY DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_DESTROY, struct drm_panfrost_jm_ctx_destroy)
  36. #define DRM_IOCTL_PANFROST_SYNC_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_SYNC_BO, struct drm_panfrost_sync_bo)
  37. #define DRM_IOCTL_PANFROST_QUERY_BO_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_QUERY_BO_INFO, struct drm_panfrost_query_bo_info)
  38. /*
  39. * Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module
  40. * param is set to true.
  41. * All these ioctl(s) are subject to deprecation, so please don't rely on
  42. * them for anything but debugging purpose.
  43. */
  44. #define DRM_IOCTL_PANFROST_PERFCNT_ENABLE DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)
  45. #define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)
  46. #define PANFROST_JD_REQ_FS (1 << 0)
  47. #define PANFROST_JD_REQ_CYCLE_COUNT (1 << 1)
  48. /**
  49. * struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D
  50. * engine.
  51. *
  52. * This asks the kernel to have the GPU execute a render command list.
  53. */
  54. struct drm_panfrost_submit {
  55. /**
  56. * @jc: Address to GPU mapping of job descriptor
  57. */
  58. __u64 jc;
  59. /**
  60. * @in_syncs: An optional array of sync objects to wait on
  61. * before starting this job.
  62. */
  63. __u64 in_syncs;
  64. /**
  65. * @in_sync_count: Number of sync objects to wait on before
  66. * starting this job.
  67. */
  68. __u32 in_sync_count;
  69. /**
  70. * @out_sync: An optional sync object to place the completion fence in.
  71. */
  72. __u32 out_sync;
  73. /**
  74. * @bo_handles: Pointer to a u32 array of the BOs that are
  75. * referenced by the job.
  76. */
  77. __u64 bo_handles;
  78. /**
  79. * @bo_handle_count: Number of BO handles passed in (size is
  80. * that times 4).
  81. */
  82. __u32 bo_handle_count;
  83. /**
  84. * @requirements: A combination of PANFROST_JD_REQ_*
  85. */
  86. __u32 requirements;
  87. /**
  88. * @jm_ctx_handle: JM context handle. Zero if you want to use the
  89. * default context.
  90. */
  91. __u32 jm_ctx_handle;
  92. /**
  93. * @pad: Padding field. Must be zero.
  94. */
  95. __u32 pad;
  96. };
  97. /**
  98. * struct drm_panfrost_wait_bo - ioctl argument for waiting for
  99. * completion of the last DRM_PANFROST_SUBMIT on a BO.
  100. *
  101. * This is useful for cases where multiple processes might be
  102. * rendering to a BO and you want to wait for all rendering to be
  103. * completed.
  104. */
  105. struct drm_panfrost_wait_bo {
  106. /**
  107. * @handle: Handle for the object to wait for.
  108. */
  109. __u32 handle;
  110. /**
  111. * @pad: Padding, must be zero-filled.
  112. */
  113. __u32 pad;
  114. /**
  115. * @timeout_ns: absolute number of nanoseconds to wait.
  116. */
  117. __s64 timeout_ns;
  118. };
  119. /* Valid flags to pass to drm_panfrost_create_bo.
  120. * PANFROST_BO_WB_MMAP can't be set if PANFROST_BO_HEAP is.
  121. */
  122. #define PANFROST_BO_NOEXEC 1
  123. #define PANFROST_BO_HEAP 2
  124. #define PANFROST_BO_WB_MMAP 4
  125. /**
  126. * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
  127. *
  128. * The flags argument is a bit mask of PANFROST_BO_* flags.
  129. */
  130. struct drm_panfrost_create_bo {
  131. /**
  132. * @size: size of shmem/BO area to create (bytes)
  133. */
  134. __u32 size;
  135. /**
  136. * @flags: see PANFROST_BO_* flags
  137. */
  138. __u32 flags;
  139. /**
  140. * @handle: Returned GEM handle for the BO.
  141. */
  142. __u32 handle;
  143. /**
  144. * @pad: Padding, must be zero-filled.
  145. */
  146. __u32 pad;
  147. /**
  148. * @offset: Returned offset for the BO in the GPU address space.
  149. * This offset is private to the DRM fd and is valid for the
  150. * lifetime of the GEM handle.
  151. *
  152. * This offset value will always be nonzero, since various HW
  153. * units treat 0 specially.
  154. */
  155. __u64 offset;
  156. };
  157. /**
  158. * struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.
  159. *
  160. * This doesn't actually perform an mmap. Instead, it returns the
  161. * offset you need to use in an mmap on the DRM device node. This
  162. * means that tools like valgrind end up knowing about the mapped
  163. * memory.
  164. *
  165. * There are currently no values for the flags argument, but it may be
  166. * used in a future extension.
  167. */
  168. struct drm_panfrost_mmap_bo {
  169. /**
  170. * @handle: Handle for the object being mapped.
  171. */
  172. __u32 handle;
  173. /**
  174. * @flags: currently not used (should be zero)
  175. */
  176. __u32 flags;
  177. /**
  178. * @offset: offset into the drm node to use for subsequent mmap call.
  179. */
  180. __u64 offset;
  181. };
  182. enum drm_panfrost_param {
  183. DRM_PANFROST_PARAM_GPU_PROD_ID,
  184. DRM_PANFROST_PARAM_GPU_REVISION,
  185. DRM_PANFROST_PARAM_SHADER_PRESENT,
  186. DRM_PANFROST_PARAM_TILER_PRESENT,
  187. DRM_PANFROST_PARAM_L2_PRESENT,
  188. DRM_PANFROST_PARAM_STACK_PRESENT,
  189. DRM_PANFROST_PARAM_AS_PRESENT,
  190. DRM_PANFROST_PARAM_JS_PRESENT,
  191. DRM_PANFROST_PARAM_L2_FEATURES,
  192. DRM_PANFROST_PARAM_CORE_FEATURES,
  193. DRM_PANFROST_PARAM_TILER_FEATURES,
  194. DRM_PANFROST_PARAM_MEM_FEATURES,
  195. DRM_PANFROST_PARAM_MMU_FEATURES,
  196. DRM_PANFROST_PARAM_THREAD_FEATURES,
  197. DRM_PANFROST_PARAM_MAX_THREADS,
  198. DRM_PANFROST_PARAM_THREAD_MAX_WORKGROUP_SZ,
  199. DRM_PANFROST_PARAM_THREAD_MAX_BARRIER_SZ,
  200. DRM_PANFROST_PARAM_COHERENCY_FEATURES,
  201. DRM_PANFROST_PARAM_TEXTURE_FEATURES0,
  202. DRM_PANFROST_PARAM_TEXTURE_FEATURES1,
  203. DRM_PANFROST_PARAM_TEXTURE_FEATURES2,
  204. DRM_PANFROST_PARAM_TEXTURE_FEATURES3,
  205. DRM_PANFROST_PARAM_JS_FEATURES0,
  206. DRM_PANFROST_PARAM_JS_FEATURES1,
  207. DRM_PANFROST_PARAM_JS_FEATURES2,
  208. DRM_PANFROST_PARAM_JS_FEATURES3,
  209. DRM_PANFROST_PARAM_JS_FEATURES4,
  210. DRM_PANFROST_PARAM_JS_FEATURES5,
  211. DRM_PANFROST_PARAM_JS_FEATURES6,
  212. DRM_PANFROST_PARAM_JS_FEATURES7,
  213. DRM_PANFROST_PARAM_JS_FEATURES8,
  214. DRM_PANFROST_PARAM_JS_FEATURES9,
  215. DRM_PANFROST_PARAM_JS_FEATURES10,
  216. DRM_PANFROST_PARAM_JS_FEATURES11,
  217. DRM_PANFROST_PARAM_JS_FEATURES12,
  218. DRM_PANFROST_PARAM_JS_FEATURES13,
  219. DRM_PANFROST_PARAM_JS_FEATURES14,
  220. DRM_PANFROST_PARAM_JS_FEATURES15,
  221. DRM_PANFROST_PARAM_NR_CORE_GROUPS,
  222. DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,
  223. DRM_PANFROST_PARAM_AFBC_FEATURES,
  224. DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP,
  225. DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP_FREQUENCY,
  226. DRM_PANFROST_PARAM_ALLOWED_JM_CTX_PRIORITIES,
  227. DRM_PANFROST_PARAM_SELECTED_COHERENCY,
  228. };
  229. enum drm_panfrost_gpu_coherency {
  230. DRM_PANFROST_GPU_COHERENCY_ACE_LITE = 0,
  231. DRM_PANFROST_GPU_COHERENCY_ACE = 1,
  232. DRM_PANFROST_GPU_COHERENCY_NONE = 31,
  233. };
  234. struct drm_panfrost_get_param {
  235. __u32 param;
  236. __u32 pad;
  237. __u64 value;
  238. };
  239. /*
  240. * Returns the offset for the BO in the GPU address space for this DRM fd.
  241. * This is the same value returned by drm_panfrost_create_bo, if that was called
  242. * from this DRM fd.
  243. */
  244. struct drm_panfrost_get_bo_offset {
  245. __u32 handle;
  246. __u32 pad;
  247. __u64 offset;
  248. };
  249. struct drm_panfrost_perfcnt_enable {
  250. __u32 enable;
  251. /*
  252. * On bifrost we have 2 sets of counters, this parameter defines the
  253. * one to track.
  254. */
  255. __u32 counterset;
  256. };
  257. struct drm_panfrost_perfcnt_dump {
  258. __u64 buf_ptr;
  259. };
  260. /* madvise provides a way to tell the kernel in case a buffers contents
  261. * can be discarded under memory pressure, which is useful for userspace
  262. * bo cache where we want to optimistically hold on to buffer allocate
  263. * and potential mmap, but allow the pages to be discarded under memory
  264. * pressure.
  265. *
  266. * Typical usage would involve madvise(DONTNEED) when buffer enters BO
  267. * cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.
  268. * In the WILLNEED case, 'retained' indicates to userspace whether the
  269. * backing pages still exist.
  270. */
  271. #define PANFROST_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */
  272. #define PANFROST_MADV_DONTNEED 1 /* backing pages not needed */
  273. struct drm_panfrost_madvise {
  274. __u32 handle; /* in, GEM handle */
  275. __u32 madv; /* in, PANFROST_MADV_x */
  276. __u32 retained; /* out, whether backing store still exists */
  277. };
  278. /**
  279. * struct drm_panfrost_set_label_bo - ioctl argument for labelling Panfrost BOs.
  280. */
  281. struct drm_panfrost_set_label_bo {
  282. /**
  283. * @handle: Handle of the buffer object to label.
  284. */
  285. __u32 handle;
  286. /**
  287. * @pad: Must be zero.
  288. */
  289. __u32 pad;
  290. /**
  291. * @label: User pointer to a NUL-terminated string
  292. *
  293. * Length cannot be greater than 4096.
  294. * NULL is permitted and means clear the label.
  295. */
  296. __u64 label;
  297. };
  298. /* Valid flags to pass to drm_panfrost_bo_sync_op */
  299. #define PANFROST_BO_SYNC_CPU_CACHE_FLUSH 0
  300. #define PANFROST_BO_SYNC_CPU_CACHE_FLUSH_AND_INVALIDATE 1
  301. /**
  302. * struct drm_panthor_bo_flush_map_op - BO map sync op
  303. */
  304. struct drm_panfrost_bo_sync_op {
  305. /** @handle: Handle of the buffer object to sync. */
  306. __u32 handle;
  307. /** @type: Type of sync operation. */
  308. __u32 type;
  309. /**
  310. * @offset: Offset into the BO at which the sync range starts.
  311. *
  312. * This will be rounded down to the nearest cache line as needed.
  313. */
  314. __u32 offset;
  315. /**
  316. * @size: Size of the range to sync
  317. *
  318. * @size + @offset will be rounded up to the nearest cache line as
  319. * needed.
  320. */
  321. __u32 size;
  322. };
  323. /**
  324. * struct drm_panfrost_sync_bo - ioctl argument for syncing BO maps
  325. */
  326. struct drm_panfrost_sync_bo {
  327. /** Array of struct drm_panfrost_bo_sync_op */
  328. __u64 ops;
  329. /** Number of BO sync ops */
  330. __u32 op_count;
  331. __u32 pad;
  332. };
  333. /** BO comes from a different subsystem. */
  334. #define DRM_PANFROST_BO_IS_IMPORTED (1 << 0)
  335. struct drm_panfrost_query_bo_info {
  336. /** Handle of the object being queried. */
  337. __u32 handle;
  338. /** Extra flags that are not coming from the BO_CREATE ioctl(). */
  339. __u32 extra_flags;
  340. /** Flags passed at creation time. */
  341. __u32 create_flags;
  342. /** Will be zero on return. */
  343. __u32 pad;
  344. };
  345. /* Definitions for coredump decoding in user space */
  346. #define PANFROSTDUMP_MAJOR 1
  347. #define PANFROSTDUMP_MINOR 0
  348. #define PANFROSTDUMP_MAGIC 0x464E4150 /* PANF */
  349. #define PANFROSTDUMP_BUF_REG 0
  350. #define PANFROSTDUMP_BUF_BOMAP (PANFROSTDUMP_BUF_REG + 1)
  351. #define PANFROSTDUMP_BUF_BO (PANFROSTDUMP_BUF_BOMAP + 1)
  352. #define PANFROSTDUMP_BUF_TRAILER (PANFROSTDUMP_BUF_BO + 1)
  353. /*
  354. * This structure is the native endianness of the dumping machine, tools can
  355. * detect the endianness by looking at the value in 'magic'.
  356. */
  357. struct panfrost_dump_object_header {
  358. __u32 magic;
  359. __u32 type;
  360. __u32 file_size;
  361. __u32 file_offset;
  362. union {
  363. struct {
  364. __u64 jc;
  365. __u32 gpu_id;
  366. __u32 major;
  367. __u32 minor;
  368. __u64 nbos;
  369. } reghdr;
  370. struct {
  371. __u32 valid;
  372. __u64 iova;
  373. __u32 data[2];
  374. } bomap;
  375. /*
  376. * Force same size in case we want to expand the header
  377. * with new fields and also keep it 512-byte aligned
  378. */
  379. __u32 sizer[496];
  380. };
  381. };
  382. /* Registers object, an array of these */
  383. struct panfrost_dump_registers {
  384. __u32 reg;
  385. __u32 value;
  386. };
  387. enum drm_panfrost_jm_ctx_priority {
  388. /**
  389. * @PANFROST_JM_CTX_PRIORITY_LOW: Low priority context.
  390. */
  391. PANFROST_JM_CTX_PRIORITY_LOW = 0,
  392. /**
  393. * @PANFROST_JM_CTX_PRIORITY_MEDIUM: Medium priority context.
  394. */
  395. PANFROST_JM_CTX_PRIORITY_MEDIUM,
  396. /**
  397. * @PANFROST_JM_CTX_PRIORITY_HIGH: High priority context.
  398. *
  399. * Requires CAP_SYS_NICE or DRM_MASTER.
  400. */
  401. PANFROST_JM_CTX_PRIORITY_HIGH,
  402. };
  403. struct drm_panfrost_jm_ctx_create {
  404. /**
  405. * @handle: Handle of the created JM context
  406. */
  407. __u32 handle;
  408. /**
  409. * @priority: Context priority (see enum drm_panfrost_jm_ctx_priority).
  410. */
  411. __u32 priority;
  412. };
  413. struct drm_panfrost_jm_ctx_destroy {
  414. /**
  415. * @handle: Handle of the JM context to destroy.
  416. *
  417. * Must be a valid context handle returned by DRM_IOCTL_PANTHOR_JM_CTX_CREATE.
  418. */
  419. __u32 handle;
  420. /**
  421. * @pad: Padding field, must be zero.
  422. */
  423. __u32 pad;
  424. };
  425. #if defined(__cplusplus)
  426. }
  427. #endif
  428. #endif /* _PANFROST_DRM_H_ */