panthor_drm.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. /* SPDX-License-Identifier: MIT */
  2. /* Copyright (C) 2023 Collabora ltd. */
  3. #ifndef _PANTHOR_DRM_H_
  4. #define _PANTHOR_DRM_H_
  5. #include "drm.h"
  6. #if defined(__cplusplus)
  7. extern "C" {
  8. #endif
  9. /**
  10. * DOC: Introduction
  11. *
  12. * This documentation describes the Panthor IOCTLs.
  13. *
  14. * Just a few generic rules about the data passed to the Panthor IOCTLs:
  15. *
  16. * - Structures must be aligned on 64-bit/8-byte. If the object is not
  17. * naturally aligned, a padding field must be added.
  18. * - Fields must be explicitly aligned to their natural type alignment with
  19. * pad[0..N] fields.
  20. * - All padding fields will be checked by the driver to make sure they are
  21. * zeroed.
  22. * - Flags can be added, but not removed/replaced.
  23. * - New fields can be added to the main structures (the structures
  24. * directly passed to the ioctl). Those fields can be added at the end of
  25. * the structure, or replace existing padding fields. Any new field being
  26. * added must preserve the behavior that existed before those fields were
  27. * added when a value of zero is passed.
  28. * - New fields can be added to indirect objects (objects pointed by the
  29. * main structure), iff those objects are passed a size to reflect the
  30. * size known by the userspace driver (see drm_panthor_obj_array::stride
  31. * or drm_panthor_dev_query::size).
  32. * - If the kernel driver is too old to know some fields, those will be
  33. * ignored if zero, and otherwise rejected (and so will be zero on output).
  34. * - If userspace is too old to know some fields, those will be zeroed
  35. * (input) before the structure is parsed by the kernel driver.
  36. * - Each new flag/field addition must come with a driver version update so
  37. * the userspace driver doesn't have to trial and error to know which
  38. * flags are supported.
  39. * - Structures should not contain unions, as this would defeat the
  40. * extensibility of such structures.
  41. * - IOCTLs can't be removed or replaced. New IOCTL IDs should be placed
  42. * at the end of the drm_panthor_ioctl_id enum.
  43. */
  44. /**
  45. * DOC: MMIO regions exposed to userspace.
  46. *
  47. * .. c:macro:: DRM_PANTHOR_USER_MMIO_OFFSET
  48. *
  49. * File offset for all MMIO regions being exposed to userspace. Don't use
  50. * this value directly, use DRM_PANTHOR_USER_<name>_OFFSET values instead.
  51. * pgoffset passed to mmap2() is an unsigned long, which forces us to use a
  52. * different offset on 32-bit and 64-bit systems.
  53. *
  54. * .. c:macro:: DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET
  55. *
  56. * File offset for the LATEST_FLUSH_ID register. The Userspace driver controls
  57. * GPU cache flushing through CS instructions, but the flush reduction
  58. * mechanism requires a flush_id. This flush_id could be queried with an
  59. * ioctl, but Arm provides a well-isolated register page containing only this
  60. * read-only register, so let's expose this page through a static mmap offset
  61. * and allow direct mapping of this MMIO region so we can avoid the
  62. * user <-> kernel round-trip.
  63. */
  64. #define DRM_PANTHOR_USER_MMIO_OFFSET_32BIT (1ull << 43)
  65. #define DRM_PANTHOR_USER_MMIO_OFFSET_64BIT (1ull << 56)
  66. #define DRM_PANTHOR_USER_MMIO_OFFSET (sizeof(unsigned long) < 8 ? \
  67. DRM_PANTHOR_USER_MMIO_OFFSET_32BIT : \
  68. DRM_PANTHOR_USER_MMIO_OFFSET_64BIT)
  69. #define DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET (DRM_PANTHOR_USER_MMIO_OFFSET | 0)
  70. /**
  71. * DOC: IOCTL IDs
  72. *
  73. * enum drm_panthor_ioctl_id - IOCTL IDs
  74. *
  75. * Place new ioctls at the end, don't re-order, don't replace or remove entries.
  76. *
  77. * These IDs are not meant to be used directly. Use the DRM_IOCTL_PANTHOR_xxx
  78. * definitions instead.
  79. */
  80. enum drm_panthor_ioctl_id {
  81. /** @DRM_PANTHOR_DEV_QUERY: Query device information. */
  82. DRM_PANTHOR_DEV_QUERY = 0,
  83. /** @DRM_PANTHOR_VM_CREATE: Create a VM. */
  84. DRM_PANTHOR_VM_CREATE,
  85. /** @DRM_PANTHOR_VM_DESTROY: Destroy a VM. */
  86. DRM_PANTHOR_VM_DESTROY,
  87. /** @DRM_PANTHOR_VM_BIND: Bind/unbind memory to a VM. */
  88. DRM_PANTHOR_VM_BIND,
  89. /** @DRM_PANTHOR_VM_GET_STATE: Get VM state. */
  90. DRM_PANTHOR_VM_GET_STATE,
  91. /** @DRM_PANTHOR_BO_CREATE: Create a buffer object. */
  92. DRM_PANTHOR_BO_CREATE,
  93. /**
  94. * @DRM_PANTHOR_BO_MMAP_OFFSET: Get the file offset to pass to
  95. * mmap to map a GEM object.
  96. */
  97. DRM_PANTHOR_BO_MMAP_OFFSET,
  98. /** @DRM_PANTHOR_GROUP_CREATE: Create a scheduling group. */
  99. DRM_PANTHOR_GROUP_CREATE,
  100. /** @DRM_PANTHOR_GROUP_DESTROY: Destroy a scheduling group. */
  101. DRM_PANTHOR_GROUP_DESTROY,
  102. /**
  103. * @DRM_PANTHOR_GROUP_SUBMIT: Submit jobs to queues belonging
  104. * to a specific scheduling group.
  105. */
  106. DRM_PANTHOR_GROUP_SUBMIT,
  107. /** @DRM_PANTHOR_GROUP_GET_STATE: Get the state of a scheduling group. */
  108. DRM_PANTHOR_GROUP_GET_STATE,
  109. /** @DRM_PANTHOR_TILER_HEAP_CREATE: Create a tiler heap. */
  110. DRM_PANTHOR_TILER_HEAP_CREATE,
  111. /** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */
  112. DRM_PANTHOR_TILER_HEAP_DESTROY,
  113. };
  114. /**
  115. * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number
  116. * @__access: Access type. Must be R, W or RW.
  117. * @__id: One of the DRM_PANTHOR_xxx id.
  118. * @__type: Suffix of the type being passed to the IOCTL.
  119. *
  120. * Don't use this macro directly, use the DRM_IOCTL_PANTHOR_xxx
  121. * values instead.
  122. *
  123. * Return: An IOCTL number to be passed to ioctl() from userspace.
  124. */
  125. #define DRM_IOCTL_PANTHOR(__access, __id, __type) \
  126. DRM_IO ## __access(DRM_COMMAND_BASE + DRM_PANTHOR_ ## __id, \
  127. struct drm_panthor_ ## __type)
  128. #define DRM_IOCTL_PANTHOR_DEV_QUERY \
  129. DRM_IOCTL_PANTHOR(WR, DEV_QUERY, dev_query)
  130. #define DRM_IOCTL_PANTHOR_VM_CREATE \
  131. DRM_IOCTL_PANTHOR(WR, VM_CREATE, vm_create)
  132. #define DRM_IOCTL_PANTHOR_VM_DESTROY \
  133. DRM_IOCTL_PANTHOR(WR, VM_DESTROY, vm_destroy)
  134. #define DRM_IOCTL_PANTHOR_VM_BIND \
  135. DRM_IOCTL_PANTHOR(WR, VM_BIND, vm_bind)
  136. #define DRM_IOCTL_PANTHOR_VM_GET_STATE \
  137. DRM_IOCTL_PANTHOR(WR, VM_GET_STATE, vm_get_state)
  138. #define DRM_IOCTL_PANTHOR_BO_CREATE \
  139. DRM_IOCTL_PANTHOR(WR, BO_CREATE, bo_create)
  140. #define DRM_IOCTL_PANTHOR_BO_MMAP_OFFSET \
  141. DRM_IOCTL_PANTHOR(WR, BO_MMAP_OFFSET, bo_mmap_offset)
  142. #define DRM_IOCTL_PANTHOR_GROUP_CREATE \
  143. DRM_IOCTL_PANTHOR(WR, GROUP_CREATE, group_create)
  144. #define DRM_IOCTL_PANTHOR_GROUP_DESTROY \
  145. DRM_IOCTL_PANTHOR(WR, GROUP_DESTROY, group_destroy)
  146. #define DRM_IOCTL_PANTHOR_GROUP_SUBMIT \
  147. DRM_IOCTL_PANTHOR(WR, GROUP_SUBMIT, group_submit)
  148. #define DRM_IOCTL_PANTHOR_GROUP_GET_STATE \
  149. DRM_IOCTL_PANTHOR(WR, GROUP_GET_STATE, group_get_state)
  150. #define DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE \
  151. DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create)
  152. #define DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY \
  153. DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy)
  154. /**
  155. * DOC: IOCTL arguments
  156. */
  157. /**
  158. * struct drm_panthor_obj_array - Object array.
  159. *
  160. * This object is used to pass an array of objects whose size is subject to changes in
  161. * future versions of the driver. In order to support this mutability, we pass a stride
  162. * describing the size of the object as known by userspace.
  163. *
  164. * You shouldn't fill drm_panthor_obj_array fields directly. You should instead use
  165. * the DRM_PANTHOR_OBJ_ARRAY() macro that takes care of initializing the stride to
  166. * the object size.
  167. */
  168. struct drm_panthor_obj_array {
  169. /** @stride: Stride of object struct. Used for versioning. */
  170. __u32 stride;
  171. /** @count: Number of objects in the array. */
  172. __u32 count;
  173. /** @array: User pointer to an array of objects. */
  174. __u64 array;
  175. };
  176. /**
  177. * DRM_PANTHOR_OBJ_ARRAY() - Initialize a drm_panthor_obj_array field.
  178. * @cnt: Number of elements in the array.
  179. * @ptr: Pointer to the array to pass to the kernel.
  180. *
  181. * Macro initializing a drm_panthor_obj_array based on the object size as known
  182. * by userspace.
  183. */
  184. #define DRM_PANTHOR_OBJ_ARRAY(cnt, ptr) \
  185. { .stride = sizeof((ptr)[0]), .count = (cnt), .array = (__u64)(uintptr_t)(ptr) }
  186. /**
  187. * enum drm_panthor_sync_op_flags - Synchronization operation flags.
  188. */
  189. enum drm_panthor_sync_op_flags {
  190. /** @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK: Synchronization handle type mask. */
  191. DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK = 0xff,
  192. /** @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ: Synchronization object type. */
  193. DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ = 0,
  194. /**
  195. * @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ: Timeline synchronization
  196. * object type.
  197. */
  198. DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ = 1,
  199. /** @DRM_PANTHOR_SYNC_OP_WAIT: Wait operation. */
  200. DRM_PANTHOR_SYNC_OP_WAIT = 0 << 31,
  201. /** @DRM_PANTHOR_SYNC_OP_SIGNAL: Signal operation. */
  202. DRM_PANTHOR_SYNC_OP_SIGNAL = (int)(1u << 31),
  203. };
  204. /**
  205. * struct drm_panthor_sync_op - Synchronization operation.
  206. */
  207. struct drm_panthor_sync_op {
  208. /** @flags: Synchronization operation flags. Combination of DRM_PANTHOR_SYNC_OP values. */
  209. __u32 flags;
  210. /** @handle: Sync handle. */
  211. __u32 handle;
  212. /**
  213. * @timeline_value: MBZ if
  214. * (flags & DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK) !=
  215. * DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ.
  216. */
  217. __u64 timeline_value;
  218. };
  219. /**
  220. * enum drm_panthor_dev_query_type - Query type
  221. *
  222. * Place new types at the end, don't re-order, don't remove or replace.
  223. */
  224. enum drm_panthor_dev_query_type {
  225. /** @DRM_PANTHOR_DEV_QUERY_GPU_INFO: Query GPU information. */
  226. DRM_PANTHOR_DEV_QUERY_GPU_INFO = 0,
  227. /** @DRM_PANTHOR_DEV_QUERY_CSIF_INFO: Query command-stream interface information. */
  228. DRM_PANTHOR_DEV_QUERY_CSIF_INFO,
  229. };
  230. /**
  231. * struct drm_panthor_gpu_info - GPU information
  232. *
  233. * Structure grouping all queryable information relating to the GPU.
  234. */
  235. struct drm_panthor_gpu_info {
  236. /** @gpu_id : GPU ID. */
  237. __u32 gpu_id;
  238. #define DRM_PANTHOR_ARCH_MAJOR(x) ((x) >> 28)
  239. #define DRM_PANTHOR_ARCH_MINOR(x) (((x) >> 24) & 0xf)
  240. #define DRM_PANTHOR_ARCH_REV(x) (((x) >> 20) & 0xf)
  241. #define DRM_PANTHOR_PRODUCT_MAJOR(x) (((x) >> 16) & 0xf)
  242. #define DRM_PANTHOR_VERSION_MAJOR(x) (((x) >> 12) & 0xf)
  243. #define DRM_PANTHOR_VERSION_MINOR(x) (((x) >> 4) & 0xff)
  244. #define DRM_PANTHOR_VERSION_STATUS(x) ((x) & 0xf)
  245. /** @gpu_rev: GPU revision. */
  246. __u32 gpu_rev;
  247. /** @csf_id: Command stream frontend ID. */
  248. __u32 csf_id;
  249. #define DRM_PANTHOR_CSHW_MAJOR(x) (((x) >> 26) & 0x3f)
  250. #define DRM_PANTHOR_CSHW_MINOR(x) (((x) >> 20) & 0x3f)
  251. #define DRM_PANTHOR_CSHW_REV(x) (((x) >> 16) & 0xf)
  252. #define DRM_PANTHOR_MCU_MAJOR(x) (((x) >> 10) & 0x3f)
  253. #define DRM_PANTHOR_MCU_MINOR(x) (((x) >> 4) & 0x3f)
  254. #define DRM_PANTHOR_MCU_REV(x) ((x) & 0xf)
  255. /** @l2_features: L2-cache features. */
  256. __u32 l2_features;
  257. /** @tiler_features: Tiler features. */
  258. __u32 tiler_features;
  259. /** @mem_features: Memory features. */
  260. __u32 mem_features;
  261. /** @mmu_features: MMU features. */
  262. __u32 mmu_features;
  263. #define DRM_PANTHOR_MMU_VA_BITS(x) ((x) & 0xff)
  264. /** @thread_features: Thread features. */
  265. __u32 thread_features;
  266. /** @max_threads: Maximum number of threads. */
  267. __u32 max_threads;
  268. /** @thread_max_workgroup_size: Maximum workgroup size. */
  269. __u32 thread_max_workgroup_size;
  270. /**
  271. * @thread_max_barrier_size: Maximum number of threads that can wait
  272. * simultaneously on a barrier.
  273. */
  274. __u32 thread_max_barrier_size;
  275. /** @coherency_features: Coherency features. */
  276. __u32 coherency_features;
  277. /** @texture_features: Texture features. */
  278. __u32 texture_features[4];
  279. /** @as_present: Bitmask encoding the number of address-space exposed by the MMU. */
  280. __u32 as_present;
  281. /** @pad0: MBZ. */
  282. __u32 pad0;
  283. /** @shader_present: Bitmask encoding the shader cores exposed by the GPU. */
  284. __u64 shader_present;
  285. /** @l2_present: Bitmask encoding the L2 caches exposed by the GPU. */
  286. __u64 l2_present;
  287. /** @tiler_present: Bitmask encoding the tiler units exposed by the GPU. */
  288. __u64 tiler_present;
  289. /** @core_features: Used to discriminate core variants when they exist. */
  290. __u32 core_features;
  291. /** @pad: MBZ. */
  292. __u32 pad;
  293. };
  294. /**
  295. * struct drm_panthor_csif_info - Command stream interface information
  296. *
  297. * Structure grouping all queryable information relating to the command stream interface.
  298. */
  299. struct drm_panthor_csif_info {
  300. /** @csg_slot_count: Number of command stream group slots exposed by the firmware. */
  301. __u32 csg_slot_count;
  302. /** @cs_slot_count: Number of command stream slots per group. */
  303. __u32 cs_slot_count;
  304. /** @cs_reg_count: Number of command stream registers. */
  305. __u32 cs_reg_count;
  306. /** @scoreboard_slot_count: Number of scoreboard slots. */
  307. __u32 scoreboard_slot_count;
  308. /**
  309. * @unpreserved_cs_reg_count: Number of command stream registers reserved by
  310. * the kernel driver to call a userspace command stream.
  311. *
  312. * All registers can be used by a userspace command stream, but the
  313. * [cs_slot_count - unpreserved_cs_reg_count .. cs_slot_count] registers are
  314. * used by the kernel when DRM_PANTHOR_IOCTL_GROUP_SUBMIT is called.
  315. */
  316. __u32 unpreserved_cs_reg_count;
  317. /**
  318. * @pad: Padding field, set to zero.
  319. */
  320. __u32 pad;
  321. };
  322. /**
  323. * struct drm_panthor_dev_query - Arguments passed to DRM_PANTHOR_IOCTL_DEV_QUERY
  324. */
  325. struct drm_panthor_dev_query {
  326. /** @type: the query type (see drm_panthor_dev_query_type). */
  327. __u32 type;
  328. /**
  329. * @size: size of the type being queried.
  330. *
  331. * If pointer is NULL, size is updated by the driver to provide the
  332. * output structure size. If pointer is not NULL, the driver will
  333. * only copy min(size, actual_structure_size) bytes to the pointer,
  334. * and update the size accordingly. This allows us to extend query
  335. * types without breaking userspace.
  336. */
  337. __u32 size;
  338. /**
  339. * @pointer: user pointer to a query type struct.
  340. *
  341. * Pointer can be NULL, in which case, nothing is copied, but the
  342. * actual structure size is returned. If not NULL, it must point to
  343. * a location that's large enough to hold size bytes.
  344. */
  345. __u64 pointer;
  346. };
  347. /**
  348. * struct drm_panthor_vm_create - Arguments passed to DRM_PANTHOR_IOCTL_VM_CREATE
  349. */
  350. struct drm_panthor_vm_create {
  351. /** @flags: VM flags, MBZ. */
  352. __u32 flags;
  353. /** @id: Returned VM ID. */
  354. __u32 id;
  355. /**
  356. * @user_va_range: Size of the VA space reserved for user objects.
  357. *
  358. * The kernel will pick the remaining space to map kernel-only objects to the
  359. * VM (heap chunks, heap context, ring buffers, kernel synchronization objects,
  360. * ...). If the space left for kernel objects is too small, kernel object
  361. * allocation will fail further down the road. One can use
  362. * drm_panthor_gpu_info::mmu_features to extract the total virtual address
  363. * range, and chose a user_va_range that leaves some space to the kernel.
  364. *
  365. * If user_va_range is zero, the kernel will pick a sensible value based on
  366. * TASK_SIZE and the virtual range supported by the GPU MMU (the kernel/user
  367. * split should leave enough VA space for userspace processes to support SVM,
  368. * while still allowing the kernel to map some amount of kernel objects in
  369. * the kernel VA range). The value chosen by the driver will be returned in
  370. * @user_va_range.
  371. *
  372. * User VA space always starts at 0x0, kernel VA space is always placed after
  373. * the user VA range.
  374. */
  375. __u64 user_va_range;
  376. };
  377. /**
  378. * struct drm_panthor_vm_destroy - Arguments passed to DRM_PANTHOR_IOCTL_VM_DESTROY
  379. */
  380. struct drm_panthor_vm_destroy {
  381. /** @id: ID of the VM to destroy. */
  382. __u32 id;
  383. /** @pad: MBZ. */
  384. __u32 pad;
  385. };
  386. /**
  387. * enum drm_panthor_vm_bind_op_flags - VM bind operation flags
  388. */
  389. enum drm_panthor_vm_bind_op_flags {
  390. /**
  391. * @DRM_PANTHOR_VM_BIND_OP_MAP_READONLY: Map the memory read-only.
  392. *
  393. * Only valid with DRM_PANTHOR_VM_BIND_OP_TYPE_MAP.
  394. */
  395. DRM_PANTHOR_VM_BIND_OP_MAP_READONLY = 1 << 0,
  396. /**
  397. * @DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC: Map the memory not-executable.
  398. *
  399. * Only valid with DRM_PANTHOR_VM_BIND_OP_TYPE_MAP.
  400. */
  401. DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC = 1 << 1,
  402. /**
  403. * @DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED: Map the memory uncached.
  404. *
  405. * Only valid with DRM_PANTHOR_VM_BIND_OP_TYPE_MAP.
  406. */
  407. DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED = 1 << 2,
  408. /**
  409. * @DRM_PANTHOR_VM_BIND_OP_TYPE_MASK: Mask used to determine the type of operation.
  410. */
  411. DRM_PANTHOR_VM_BIND_OP_TYPE_MASK = (int)(0xfu << 28),
  412. /** @DRM_PANTHOR_VM_BIND_OP_TYPE_MAP: Map operation. */
  413. DRM_PANTHOR_VM_BIND_OP_TYPE_MAP = 0 << 28,
  414. /** @DRM_PANTHOR_VM_BIND_OP_TYPE_UNMAP: Unmap operation. */
  415. DRM_PANTHOR_VM_BIND_OP_TYPE_UNMAP = 1 << 28,
  416. /**
  417. * @DRM_PANTHOR_VM_BIND_OP_TYPE_SYNC_ONLY: No VM operation.
  418. *
  419. * Just serves as a synchronization point on a VM queue.
  420. *
  421. * Only valid if %DRM_PANTHOR_VM_BIND_ASYNC is set in drm_panthor_vm_bind::flags,
  422. * and drm_panthor_vm_bind_op::syncs contains at least one element.
  423. */
  424. DRM_PANTHOR_VM_BIND_OP_TYPE_SYNC_ONLY = 2 << 28,
  425. };
  426. /**
  427. * struct drm_panthor_vm_bind_op - VM bind operation
  428. */
  429. struct drm_panthor_vm_bind_op {
  430. /** @flags: Combination of drm_panthor_vm_bind_op_flags flags. */
  431. __u32 flags;
  432. /**
  433. * @bo_handle: Handle of the buffer object to map.
  434. * MBZ for unmap or sync-only operations.
  435. */
  436. __u32 bo_handle;
  437. /**
  438. * @bo_offset: Buffer object offset.
  439. * MBZ for unmap or sync-only operations.
  440. */
  441. __u64 bo_offset;
  442. /**
  443. * @va: Virtual address to map/unmap.
  444. * MBZ for sync-only operations.
  445. */
  446. __u64 va;
  447. /**
  448. * @size: Size to map/unmap.
  449. * MBZ for sync-only operations.
  450. */
  451. __u64 size;
  452. /**
  453. * @syncs: Array of struct drm_panthor_sync_op synchronization
  454. * operations.
  455. *
  456. * This array must be empty if %DRM_PANTHOR_VM_BIND_ASYNC is not set on
  457. * the drm_panthor_vm_bind object containing this VM bind operation.
  458. *
  459. * This array shall not be empty for sync-only operations.
  460. */
  461. struct drm_panthor_obj_array syncs;
  462. };
  463. /**
  464. * enum drm_panthor_vm_bind_flags - VM bind flags
  465. */
  466. enum drm_panthor_vm_bind_flags {
  467. /**
  468. * @DRM_PANTHOR_VM_BIND_ASYNC: VM bind operations are queued to the VM
  469. * queue instead of being executed synchronously.
  470. */
  471. DRM_PANTHOR_VM_BIND_ASYNC = 1 << 0,
  472. };
  473. /**
  474. * struct drm_panthor_vm_bind - Arguments passed to DRM_IOCTL_PANTHOR_VM_BIND
  475. */
  476. struct drm_panthor_vm_bind {
  477. /** @vm_id: VM targeted by the bind request. */
  478. __u32 vm_id;
  479. /** @flags: Combination of drm_panthor_vm_bind_flags flags. */
  480. __u32 flags;
  481. /** @ops: Array of struct drm_panthor_vm_bind_op bind operations. */
  482. struct drm_panthor_obj_array ops;
  483. };
  484. /**
  485. * enum drm_panthor_vm_state - VM states.
  486. */
  487. enum drm_panthor_vm_state {
  488. /**
  489. * @DRM_PANTHOR_VM_STATE_USABLE: VM is usable.
  490. *
  491. * New VM operations will be accepted on this VM.
  492. */
  493. DRM_PANTHOR_VM_STATE_USABLE,
  494. /**
  495. * @DRM_PANTHOR_VM_STATE_UNUSABLE: VM is unusable.
  496. *
  497. * Something put the VM in an unusable state (like an asynchronous
  498. * VM_BIND request failing for any reason).
  499. *
  500. * Once the VM is in this state, all new MAP operations will be
  501. * rejected, and any GPU job targeting this VM will fail.
  502. * UNMAP operations are still accepted.
  503. *
  504. * The only way to recover from an unusable VM is to create a new
  505. * VM, and destroy the old one.
  506. */
  507. DRM_PANTHOR_VM_STATE_UNUSABLE,
  508. };
  509. /**
  510. * struct drm_panthor_vm_get_state - Get VM state.
  511. */
  512. struct drm_panthor_vm_get_state {
  513. /** @vm_id: VM targeted by the get_state request. */
  514. __u32 vm_id;
  515. /**
  516. * @state: state returned by the driver.
  517. *
  518. * Must be one of the enum drm_panthor_vm_state values.
  519. */
  520. __u32 state;
  521. };
  522. /**
  523. * enum drm_panthor_bo_flags - Buffer object flags, passed at creation time.
  524. */
  525. enum drm_panthor_bo_flags {
  526. /** @DRM_PANTHOR_BO_NO_MMAP: The buffer object will never be CPU-mapped in userspace. */
  527. DRM_PANTHOR_BO_NO_MMAP = (1 << 0),
  528. };
  529. /**
  530. * struct drm_panthor_bo_create - Arguments passed to DRM_IOCTL_PANTHOR_BO_CREATE.
  531. */
  532. struct drm_panthor_bo_create {
  533. /**
  534. * @size: Requested size for the object
  535. *
  536. * The (page-aligned) allocated size for the object will be returned.
  537. */
  538. __u64 size;
  539. /**
  540. * @flags: Flags. Must be a combination of drm_panthor_bo_flags flags.
  541. */
  542. __u32 flags;
  543. /**
  544. * @exclusive_vm_id: Exclusive VM this buffer object will be mapped to.
  545. *
  546. * If not zero, the field must refer to a valid VM ID, and implies that:
  547. * - the buffer object will only ever be bound to that VM
  548. * - cannot be exported as a PRIME fd
  549. */
  550. __u32 exclusive_vm_id;
  551. /**
  552. * @handle: Returned handle for the object.
  553. *
  554. * Object handles are nonzero.
  555. */
  556. __u32 handle;
  557. /** @pad: MBZ. */
  558. __u32 pad;
  559. };
  560. /**
  561. * struct drm_panthor_bo_mmap_offset - Arguments passed to DRM_IOCTL_PANTHOR_BO_MMAP_OFFSET.
  562. */
  563. struct drm_panthor_bo_mmap_offset {
  564. /** @handle: Handle of the object we want an mmap offset for. */
  565. __u32 handle;
  566. /** @pad: MBZ. */
  567. __u32 pad;
  568. /** @offset: The fake offset to use for subsequent mmap calls. */
  569. __u64 offset;
  570. };
  571. /**
  572. * struct drm_panthor_queue_create - Queue creation arguments.
  573. */
  574. struct drm_panthor_queue_create {
  575. /**
  576. * @priority: Defines the priority of queues inside a group. Goes from 0 to 15,
  577. * 15 being the highest priority.
  578. */
  579. __u8 priority;
  580. /** @pad: Padding fields, MBZ. */
  581. __u8 pad[3];
  582. /** @ringbuf_size: Size of the ring buffer to allocate to this queue. */
  583. __u32 ringbuf_size;
  584. };
  585. /**
  586. * enum drm_panthor_group_priority - Scheduling group priority
  587. */
  588. enum drm_panthor_group_priority {
  589. /** @PANTHOR_GROUP_PRIORITY_LOW: Low priority group. */
  590. PANTHOR_GROUP_PRIORITY_LOW = 0,
  591. /** @PANTHOR_GROUP_PRIORITY_MEDIUM: Medium priority group. */
  592. PANTHOR_GROUP_PRIORITY_MEDIUM,
  593. /**
  594. * @PANTHOR_GROUP_PRIORITY_HIGH: High priority group.
  595. *
  596. * Requires CAP_SYS_NICE or DRM_MASTER.
  597. */
  598. PANTHOR_GROUP_PRIORITY_HIGH,
  599. };
  600. /**
  601. * struct drm_panthor_group_create - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_CREATE
  602. */
  603. struct drm_panthor_group_create {
  604. /** @queues: Array of drm_panthor_queue_create elements. */
  605. struct drm_panthor_obj_array queues;
  606. /**
  607. * @max_compute_cores: Maximum number of cores that can be used by compute
  608. * jobs across CS queues bound to this group.
  609. *
  610. * Must be less or equal to the number of bits set in @compute_core_mask.
  611. */
  612. __u8 max_compute_cores;
  613. /**
  614. * @max_fragment_cores: Maximum number of cores that can be used by fragment
  615. * jobs across CS queues bound to this group.
  616. *
  617. * Must be less or equal to the number of bits set in @fragment_core_mask.
  618. */
  619. __u8 max_fragment_cores;
  620. /**
  621. * @max_tiler_cores: Maximum number of tilers that can be used by tiler jobs
  622. * across CS queues bound to this group.
  623. *
  624. * Must be less or equal to the number of bits set in @tiler_core_mask.
  625. */
  626. __u8 max_tiler_cores;
  627. /** @priority: Group priority (see enum drm_panthor_group_priority). */
  628. __u8 priority;
  629. /** @pad: Padding field, MBZ. */
  630. __u32 pad;
  631. /**
  632. * @compute_core_mask: Mask encoding cores that can be used for compute jobs.
  633. *
  634. * This field must have at least @max_compute_cores bits set.
  635. *
  636. * The bits set here should also be set in drm_panthor_gpu_info::shader_present.
  637. */
  638. __u64 compute_core_mask;
  639. /**
  640. * @fragment_core_mask: Mask encoding cores that can be used for fragment jobs.
  641. *
  642. * This field must have at least @max_fragment_cores bits set.
  643. *
  644. * The bits set here should also be set in drm_panthor_gpu_info::shader_present.
  645. */
  646. __u64 fragment_core_mask;
  647. /**
  648. * @tiler_core_mask: Mask encoding cores that can be used for tiler jobs.
  649. *
  650. * This field must have at least @max_tiler_cores bits set.
  651. *
  652. * The bits set here should also be set in drm_panthor_gpu_info::tiler_present.
  653. */
  654. __u64 tiler_core_mask;
  655. /**
  656. * @vm_id: VM ID to bind this group to.
  657. *
  658. * All submission to queues bound to this group will use this VM.
  659. */
  660. __u32 vm_id;
  661. /**
  662. * @group_handle: Returned group handle. Passed back when submitting jobs or
  663. * destroying a group.
  664. */
  665. __u32 group_handle;
  666. };
  667. /**
  668. * struct drm_panthor_group_destroy - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_DESTROY
  669. */
  670. struct drm_panthor_group_destroy {
  671. /** @group_handle: Group to destroy */
  672. __u32 group_handle;
  673. /** @pad: Padding field, MBZ. */
  674. __u32 pad;
  675. };
  676. /**
  677. * struct drm_panthor_queue_submit - Job submission arguments.
  678. *
  679. * This is describing the userspace command stream to call from the kernel
  680. * command stream ring-buffer. Queue submission is always part of a group
  681. * submission, taking one or more jobs to submit to the underlying queues.
  682. */
  683. struct drm_panthor_queue_submit {
  684. /** @queue_index: Index of the queue inside a group. */
  685. __u32 queue_index;
  686. /**
  687. * @stream_size: Size of the command stream to execute.
  688. *
  689. * Must be 64-bit/8-byte aligned (the size of a CS instruction)
  690. *
  691. * Can be zero if stream_addr is zero too.
  692. *
  693. * When the stream size is zero, the queue submit serves as a
  694. * synchronization point.
  695. */
  696. __u32 stream_size;
  697. /**
  698. * @stream_addr: GPU address of the command stream to execute.
  699. *
  700. * Must be aligned on 64-byte.
  701. *
  702. * Can be zero is stream_size is zero too.
  703. */
  704. __u64 stream_addr;
  705. /**
  706. * @latest_flush: FLUSH_ID read at the time the stream was built.
  707. *
  708. * This allows cache flush elimination for the automatic
  709. * flush+invalidate(all) done at submission time, which is needed to
  710. * ensure the GPU doesn't get garbage when reading the indirect command
  711. * stream buffers. If you want the cache flush to happen
  712. * unconditionally, pass a zero here.
  713. *
  714. * Ignored when stream_size is zero.
  715. */
  716. __u32 latest_flush;
  717. /** @pad: MBZ. */
  718. __u32 pad;
  719. /** @syncs: Array of struct drm_panthor_sync_op sync operations. */
  720. struct drm_panthor_obj_array syncs;
  721. };
  722. /**
  723. * struct drm_panthor_group_submit - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_SUBMIT
  724. */
  725. struct drm_panthor_group_submit {
  726. /** @group_handle: Handle of the group to queue jobs to. */
  727. __u32 group_handle;
  728. /** @pad: MBZ. */
  729. __u32 pad;
  730. /** @queue_submits: Array of drm_panthor_queue_submit objects. */
  731. struct drm_panthor_obj_array queue_submits;
  732. };
  733. /**
  734. * enum drm_panthor_group_state_flags - Group state flags
  735. */
  736. enum drm_panthor_group_state_flags {
  737. /**
  738. * @DRM_PANTHOR_GROUP_STATE_TIMEDOUT: Group had unfinished jobs.
  739. *
  740. * When a group ends up with this flag set, no jobs can be submitted to its queues.
  741. */
  742. DRM_PANTHOR_GROUP_STATE_TIMEDOUT = 1 << 0,
  743. /**
  744. * @DRM_PANTHOR_GROUP_STATE_FATAL_FAULT: Group had fatal faults.
  745. *
  746. * When a group ends up with this flag set, no jobs can be submitted to its queues.
  747. */
  748. DRM_PANTHOR_GROUP_STATE_FATAL_FAULT = 1 << 1,
  749. };
  750. /**
  751. * struct drm_panthor_group_get_state - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_GET_STATE
  752. *
  753. * Used to query the state of a group and decide whether a new group should be created to
  754. * replace it.
  755. */
  756. struct drm_panthor_group_get_state {
  757. /** @group_handle: Handle of the group to query state on */
  758. __u32 group_handle;
  759. /**
  760. * @state: Combination of DRM_PANTHOR_GROUP_STATE_* flags encoding the
  761. * group state.
  762. */
  763. __u32 state;
  764. /** @fatal_queues: Bitmask of queues that faced fatal faults. */
  765. __u32 fatal_queues;
  766. /** @pad: MBZ */
  767. __u32 pad;
  768. };
  769. /**
  770. * struct drm_panthor_tiler_heap_create - Arguments passed to DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE
  771. */
  772. struct drm_panthor_tiler_heap_create {
  773. /** @vm_id: VM ID the tiler heap should be mapped to */
  774. __u32 vm_id;
  775. /** @initial_chunk_count: Initial number of chunks to allocate. Must be at least one. */
  776. __u32 initial_chunk_count;
  777. /**
  778. * @chunk_size: Chunk size.
  779. *
  780. * Must be page-aligned and lie in the [128k:8M] range.
  781. */
  782. __u32 chunk_size;
  783. /**
  784. * @max_chunks: Maximum number of chunks that can be allocated.
  785. *
  786. * Must be at least @initial_chunk_count.
  787. */
  788. __u32 max_chunks;
  789. /**
  790. * @target_in_flight: Maximum number of in-flight render passes.
  791. *
  792. * If the heap has more than tiler jobs in-flight, the FW will wait for render
  793. * passes to finish before queuing new tiler jobs.
  794. */
  795. __u32 target_in_flight;
  796. /** @handle: Returned heap handle. Passed back to DESTROY_TILER_HEAP. */
  797. __u32 handle;
  798. /** @tiler_heap_ctx_gpu_va: Returned heap GPU virtual address returned */
  799. __u64 tiler_heap_ctx_gpu_va;
  800. /**
  801. * @first_heap_chunk_gpu_va: First heap chunk.
  802. *
  803. * The tiler heap is formed of heap chunks forming a single-link list. This
  804. * is the first element in the list.
  805. */
  806. __u64 first_heap_chunk_gpu_va;
  807. };
  808. /**
  809. * struct drm_panthor_tiler_heap_destroy - Arguments passed to DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY
  810. */
  811. struct drm_panthor_tiler_heap_destroy {
  812. /**
  813. * @handle: Handle of the tiler heap to destroy.
  814. *
  815. * Must be a valid heap handle returned by DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE.
  816. */
  817. __u32 handle;
  818. /** @pad: Padding field, MBZ. */
  819. __u32 pad;
  820. };
  821. #if defined(__cplusplus)
  822. }
  823. #endif
  824. #endif /* _PANTHOR_DRM_H_ */