asahi_drm.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright (C) The Asahi Linux Contributors
  4. * Copyright (C) 2018-2023 Collabora Ltd.
  5. * Copyright (C) 2014-2018 Broadcom
  6. */
  7. #ifndef _ASAHI_DRM_H_
  8. #define _ASAHI_DRM_H_
  9. #include "drm.h"
  10. #if defined(__cplusplus)
  11. extern "C" {
  12. #endif
  13. /**
  14. * DOC: Introduction to the Asahi UAPI
  15. *
  16. * This documentation describes the Asahi IOCTLs.
  17. *
  18. * Just a few generic rules about the data passed to the Asahi IOCTLs (cribbed
  19. * from Panthor):
  20. *
  21. * - Structures must be aligned on 64-bit/8-byte. If the object is not
  22. * naturally aligned, a padding field must be added.
  23. * - Fields must be explicitly aligned to their natural type alignment with
  24. * pad[0..N] fields.
  25. * - All padding fields will be checked by the driver to make sure they are
  26. * zeroed.
  27. * - Flags can be added, but not removed/replaced.
  28. * - New fields can be added to the main structures (the structures
  29. * directly passed to the ioctl). Those fields can be added at the end of
  30. * the structure, or replace existing padding fields. Any new field being
  31. * added must preserve the behavior that existed before those fields were
  32. * added when a value of zero is passed.
  33. * - New fields can be added to indirect objects (objects pointed by the
  34. * main structure), iff those objects are passed a size to reflect the
  35. * size known by the userspace driver (see
  36. * drm_asahi_cmd_header::size).
  37. * - If the kernel driver is too old to know some fields, those will be
  38. * ignored if zero, and otherwise rejected (and so will be zero on output).
  39. * - If userspace is too old to know some fields, those will be zeroed
  40. * (input) before the structure is parsed by the kernel driver.
  41. * - Each new flag/field addition must come with a driver version update so
  42. * the userspace driver doesn't have to guess which flags are supported.
  43. * - Structures should not contain unions, as this would defeat the
  44. * extensibility of such structures.
  45. * - IOCTLs can't be removed or replaced. New IOCTL IDs should be placed
  46. * at the end of the drm_asahi_ioctl_id enum.
  47. */
  48. /**
  49. * enum drm_asahi_ioctl_id - IOCTL IDs
  50. *
  51. * Place new ioctls at the end, don't re-order, don't replace or remove entries.
  52. *
  53. * These IDs are not meant to be used directly. Use the DRM_IOCTL_ASAHI_xxx
  54. * definitions instead.
  55. */
  56. enum drm_asahi_ioctl_id {
  57. /** @DRM_ASAHI_GET_PARAMS: Query device properties. */
  58. DRM_ASAHI_GET_PARAMS = 0,
  59. /** @DRM_ASAHI_GET_TIME: Query device time. */
  60. DRM_ASAHI_GET_TIME,
  61. /** @DRM_ASAHI_VM_CREATE: Create a GPU VM address space. */
  62. DRM_ASAHI_VM_CREATE,
  63. /** @DRM_ASAHI_VM_DESTROY: Destroy a VM. */
  64. DRM_ASAHI_VM_DESTROY,
  65. /** @DRM_ASAHI_VM_BIND: Bind/unbind memory to a VM. */
  66. DRM_ASAHI_VM_BIND,
  67. /** @DRM_ASAHI_GEM_CREATE: Create a buffer object. */
  68. DRM_ASAHI_GEM_CREATE,
  69. /**
  70. * @DRM_ASAHI_GEM_MMAP_OFFSET: Get offset to pass to mmap() to map a
  71. * given GEM handle.
  72. */
  73. DRM_ASAHI_GEM_MMAP_OFFSET,
  74. /** @DRM_ASAHI_GEM_BIND_OBJECT: Bind memory as a special object */
  75. DRM_ASAHI_GEM_BIND_OBJECT,
  76. /** @DRM_ASAHI_QUEUE_CREATE: Create a scheduling queue. */
  77. DRM_ASAHI_QUEUE_CREATE,
  78. /** @DRM_ASAHI_QUEUE_DESTROY: Destroy a scheduling queue. */
  79. DRM_ASAHI_QUEUE_DESTROY,
  80. /** @DRM_ASAHI_SUBMIT: Submit commands to a queue. */
  81. DRM_ASAHI_SUBMIT,
  82. };
  83. #define DRM_ASAHI_MAX_CLUSTERS 64
  84. /**
  85. * struct drm_asahi_params_global - Global parameters.
  86. *
  87. * This struct may be queried by drm_asahi_get_params.
  88. */
  89. struct drm_asahi_params_global {
  90. /** @features: Feature bits from drm_asahi_feature */
  91. __u64 features;
  92. /** @gpu_generation: GPU generation, e.g. 13 for G13G */
  93. __u32 gpu_generation;
  94. /** @gpu_variant: GPU variant as a character, e.g. 'C' for G13C */
  95. __u32 gpu_variant;
  96. /**
  97. * @gpu_revision: GPU revision in BCD, e.g. 0x00 for 'A0' or
  98. * 0x21 for 'C1'
  99. */
  100. __u32 gpu_revision;
  101. /** @chip_id: Chip ID in BCD, e.g. 0x8103 for T8103 */
  102. __u32 chip_id;
  103. /** @num_dies: Number of dies in the SoC */
  104. __u32 num_dies;
  105. /** @num_clusters_total: Number of GPU clusters (across all dies) */
  106. __u32 num_clusters_total;
  107. /**
  108. * @num_cores_per_cluster: Number of logical cores per cluster
  109. * (including inactive/nonexistent)
  110. */
  111. __u32 num_cores_per_cluster;
  112. /** @max_frequency_khz: Maximum GPU core clock frequency */
  113. __u32 max_frequency_khz;
  114. /** @core_masks: Bitmask of present/enabled cores per cluster */
  115. __u64 core_masks[DRM_ASAHI_MAX_CLUSTERS];
  116. /**
  117. * @vm_start: VM range start VMA. Together with @vm_end, this defines
  118. * the window of valid GPU VAs. Userspace is expected to subdivide VAs
  119. * out of this window.
  120. *
  121. * This window contains all virtual addresses that userspace needs to
  122. * know about. There may be kernel-internal GPU VAs outside this range,
  123. * but that detail is not relevant here.
  124. */
  125. __u64 vm_start;
  126. /** @vm_end: VM range end VMA */
  127. __u64 vm_end;
  128. /**
  129. * @vm_kernel_min_size: Minimum kernel VMA window size.
  130. *
  131. * When creating a VM, userspace is required to carve out a section of
  132. * virtual addresses (within the range given by @vm_start and
  133. * @vm_end). The kernel will allocate various internal structures
  134. * within the specified VA range.
  135. *
  136. * Allowing userspace to choose the VA range for the kernel, rather than
  137. * the kernel reserving VAs and requiring userspace to cope, can assist
  138. * in implementing SVM.
  139. */
  140. __u64 vm_kernel_min_size;
  141. /**
  142. * @max_commands_per_submission: Maximum number of supported commands
  143. * per submission. This mirrors firmware limits. Userspace must split up
  144. * larger command buffers, which may require inserting additional
  145. * synchronization.
  146. */
  147. __u32 max_commands_per_submission;
  148. /**
  149. * @max_attachments: Maximum number of drm_asahi_attachment's per
  150. * command
  151. */
  152. __u32 max_attachments;
  153. /**
  154. * @command_timestamp_frequency_hz: Timebase frequency for timestamps
  155. * written during command execution, specified via drm_asahi_timestamp
  156. * structures. As this rate is controlled by the firmware, it is a
  157. * queryable parameter.
  158. *
  159. * Userspace must divide by this frequency to convert timestamps to
  160. * seconds, rather than hardcoding a particular firmware's rate.
  161. */
  162. __u64 command_timestamp_frequency_hz;
  163. };
  164. /**
  165. * enum drm_asahi_feature - Feature bits
  166. *
  167. * This covers only features that userspace cannot infer from the architecture
  168. * version. Most features don't need to be here.
  169. */
  170. enum drm_asahi_feature {
  171. /**
  172. * @DRM_ASAHI_FEATURE_SOFT_FAULTS: GPU has "soft fault" enabled. Shader
  173. * loads of unmapped memory will return zero. Shader stores to unmapped
  174. * memory will be silently discarded. Note that only shader load/store
  175. * is affected. Other hardware units are not affected, notably including
  176. * texture sampling.
  177. *
  178. * Soft fault is set when initializing the GPU and cannot be runtime
  179. * toggled. Therefore, it is exposed as a feature bit and not a
  180. * userspace-settable flag on the VM. When soft fault is enabled,
  181. * userspace can speculate memory accesses more aggressively.
  182. */
  183. DRM_ASAHI_FEATURE_SOFT_FAULTS = (1UL) << 0,
  184. };
  185. /**
  186. * struct drm_asahi_get_params - Arguments passed to DRM_IOCTL_ASAHI_GET_PARAMS
  187. */
  188. struct drm_asahi_get_params {
  189. /** @param_group: Parameter group to fetch (MBZ) */
  190. __u32 param_group;
  191. /** @pad: MBZ */
  192. __u32 pad;
  193. /** @pointer: User pointer to write parameter struct */
  194. __u64 pointer;
  195. /**
  196. * @size: Size of the user buffer. In case of older userspace, this may
  197. * be less than sizeof(struct drm_asahi_params_global). The kernel will
  198. * not write past the length specified here, allowing extensibility.
  199. */
  200. __u64 size;
  201. };
  202. /**
  203. * struct drm_asahi_vm_create - Arguments passed to DRM_IOCTL_ASAHI_VM_CREATE
  204. */
  205. struct drm_asahi_vm_create {
  206. /**
  207. * @kernel_start: Start of the kernel-reserved address range. See
  208. * drm_asahi_params_global::vm_kernel_min_size.
  209. *
  210. * Both @kernel_start and @kernel_end must be within the range of
  211. * valid VAs given by drm_asahi_params_global::vm_start and
  212. * drm_asahi_params_global::vm_end. The size of the kernel range
  213. * (@kernel_end - @kernel_start) must be at least
  214. * drm_asahi_params_global::vm_kernel_min_size.
  215. *
  216. * Userspace must not bind any memory on this VM into this reserved
  217. * range, it is for kernel use only.
  218. */
  219. __u64 kernel_start;
  220. /**
  221. * @kernel_end: End of the kernel-reserved address range. See
  222. * @kernel_start.
  223. */
  224. __u64 kernel_end;
  225. /** @vm_id: Returned VM ID */
  226. __u32 vm_id;
  227. /** @pad: MBZ */
  228. __u32 pad;
  229. };
  230. /**
  231. * struct drm_asahi_vm_destroy - Arguments passed to DRM_IOCTL_ASAHI_VM_DESTROY
  232. */
  233. struct drm_asahi_vm_destroy {
  234. /** @vm_id: VM ID to be destroyed */
  235. __u32 vm_id;
  236. /** @pad: MBZ */
  237. __u32 pad;
  238. };
  239. /**
  240. * enum drm_asahi_gem_flags - Flags for GEM creation
  241. */
  242. enum drm_asahi_gem_flags {
  243. /**
  244. * @DRM_ASAHI_GEM_WRITEBACK: BO should be CPU-mapped as writeback.
  245. *
  246. * Map as writeback instead of write-combine. This optimizes for CPU
  247. * reads.
  248. */
  249. DRM_ASAHI_GEM_WRITEBACK = (1L << 0),
  250. /**
  251. * @DRM_ASAHI_GEM_VM_PRIVATE: BO is private to this GPU VM (no exports).
  252. */
  253. DRM_ASAHI_GEM_VM_PRIVATE = (1L << 1),
  254. };
  255. /**
  256. * struct drm_asahi_gem_create - Arguments passed to DRM_IOCTL_ASAHI_GEM_CREATE
  257. */
  258. struct drm_asahi_gem_create {
  259. /** @size: Size of the BO */
  260. __u64 size;
  261. /** @flags: Combination of drm_asahi_gem_flags flags. */
  262. __u32 flags;
  263. /**
  264. * @vm_id: VM ID to assign to the BO, if DRM_ASAHI_GEM_VM_PRIVATE is set
  265. */
  266. __u32 vm_id;
  267. /** @handle: Returned GEM handle for the BO */
  268. __u32 handle;
  269. /** @pad: MBZ */
  270. __u32 pad;
  271. };
  272. /**
  273. * struct drm_asahi_gem_mmap_offset - Arguments passed to
  274. * DRM_IOCTL_ASAHI_GEM_MMAP_OFFSET
  275. */
  276. struct drm_asahi_gem_mmap_offset {
  277. /** @handle: Handle for the object being mapped. */
  278. __u32 handle;
  279. /** @flags: Must be zero */
  280. __u32 flags;
  281. /** @offset: The fake offset to use for subsequent mmap call */
  282. __u64 offset;
  283. };
  284. /**
  285. * enum drm_asahi_bind_flags - Flags for GEM binding
  286. */
  287. enum drm_asahi_bind_flags {
  288. /**
  289. * @DRM_ASAHI_BIND_UNBIND: Instead of binding a GEM object to the range,
  290. * simply unbind the GPU VMA range.
  291. */
  292. DRM_ASAHI_BIND_UNBIND = (1L << 0),
  293. /** @DRM_ASAHI_BIND_READ: Map BO with GPU read permission */
  294. DRM_ASAHI_BIND_READ = (1L << 1),
  295. /** @DRM_ASAHI_BIND_WRITE: Map BO with GPU write permission */
  296. DRM_ASAHI_BIND_WRITE = (1L << 2),
  297. /**
  298. * @DRM_ASAHI_BIND_SINGLE_PAGE: Map a single page of the BO repeatedly
  299. * across the VA range.
  300. *
  301. * This is useful to fill a VA range with scratch pages or zero pages.
  302. * It is intended as a mechanism to accelerate sparse.
  303. */
  304. DRM_ASAHI_BIND_SINGLE_PAGE = (1L << 3),
  305. };
  306. /**
  307. * struct drm_asahi_gem_bind_op - Description of a single GEM bind operation.
  308. */
  309. struct drm_asahi_gem_bind_op {
  310. /** @flags: Combination of drm_asahi_bind_flags flags. */
  311. __u32 flags;
  312. /** @handle: GEM object to bind (except for UNBIND) */
  313. __u32 handle;
  314. /**
  315. * @offset: Offset into the object (except for UNBIND).
  316. *
  317. * For a regular bind, this is the beginning of the region of the GEM
  318. * object to bind.
  319. *
  320. * For a single-page bind, this is the offset to the single page that
  321. * will be repeatedly bound.
  322. *
  323. * Must be page-size aligned.
  324. */
  325. __u64 offset;
  326. /**
  327. * @range: Number of bytes to bind/unbind to @addr.
  328. *
  329. * Must be page-size aligned.
  330. */
  331. __u64 range;
  332. /**
  333. * @addr: Address to bind to.
  334. *
  335. * Must be page-size aligned.
  336. */
  337. __u64 addr;
  338. };
  339. /**
  340. * struct drm_asahi_vm_bind - Arguments passed to
  341. * DRM_IOCTL_ASAHI_VM_BIND
  342. */
  343. struct drm_asahi_vm_bind {
  344. /** @vm_id: The ID of the VM to bind to */
  345. __u32 vm_id;
  346. /** @num_binds: number of binds in this IOCTL. */
  347. __u32 num_binds;
  348. /**
  349. * @stride: Stride in bytes between consecutive binds. This allows
  350. * extensibility of drm_asahi_gem_bind_op.
  351. */
  352. __u32 stride;
  353. /** @pad: MBZ */
  354. __u32 pad;
  355. /**
  356. * @userptr: User pointer to an array of @num_binds structures of type
  357. * @drm_asahi_gem_bind_op and size @stride bytes.
  358. */
  359. __u64 userptr;
  360. };
  361. /**
  362. * enum drm_asahi_bind_object_op - Special object bind operation
  363. */
  364. enum drm_asahi_bind_object_op {
  365. /** @DRM_ASAHI_BIND_OBJECT_OP_BIND: Bind a BO as a special GPU object */
  366. DRM_ASAHI_BIND_OBJECT_OP_BIND = 0,
  367. /** @DRM_ASAHI_BIND_OBJECT_OP_UNBIND: Unbind a special GPU object */
  368. DRM_ASAHI_BIND_OBJECT_OP_UNBIND = 1,
  369. };
  370. /**
  371. * enum drm_asahi_bind_object_flags - Special object bind flags
  372. */
  373. enum drm_asahi_bind_object_flags {
  374. /**
  375. * @DRM_ASAHI_BIND_OBJECT_USAGE_TIMESTAMPS: Map a BO as a timestamp
  376. * buffer.
  377. */
  378. DRM_ASAHI_BIND_OBJECT_USAGE_TIMESTAMPS = (1L << 0),
  379. };
  380. /**
  381. * struct drm_asahi_gem_bind_object - Arguments passed to
  382. * DRM_IOCTL_ASAHI_GEM_BIND_OBJECT
  383. */
  384. struct drm_asahi_gem_bind_object {
  385. /** @op: Bind operation (enum drm_asahi_bind_object_op) */
  386. __u32 op;
  387. /** @flags: Combination of drm_asahi_bind_object_flags flags. */
  388. __u32 flags;
  389. /** @handle: GEM object to bind/unbind (BIND) */
  390. __u32 handle;
  391. /** @vm_id: The ID of the VM to operate on (MBZ currently) */
  392. __u32 vm_id;
  393. /** @offset: Offset into the object (BIND only) */
  394. __u64 offset;
  395. /** @range: Number of bytes to bind/unbind (BIND only) */
  396. __u64 range;
  397. /** @object_handle: Object handle (out for BIND, in for UNBIND) */
  398. __u32 object_handle;
  399. /** @pad: MBZ */
  400. __u32 pad;
  401. };
  402. /**
  403. * enum drm_asahi_cmd_type - Command type
  404. */
  405. enum drm_asahi_cmd_type {
  406. /**
  407. * @DRM_ASAHI_CMD_RENDER: Render command, executing on the render
  408. * subqueue. Combined vertex and fragment operation.
  409. *
  410. * Followed by a @drm_asahi_cmd_render payload.
  411. */
  412. DRM_ASAHI_CMD_RENDER = 0,
  413. /**
  414. * @DRM_ASAHI_CMD_COMPUTE: Compute command on the compute subqueue.
  415. *
  416. * Followed by a @drm_asahi_cmd_compute payload.
  417. */
  418. DRM_ASAHI_CMD_COMPUTE = 1,
  419. /**
  420. * @DRM_ASAHI_SET_VERTEX_ATTACHMENTS: Software command to set
  421. * attachments for subsequent vertex shaders in the same submit.
  422. *
  423. * Followed by (possibly multiple) @drm_asahi_attachment payloads.
  424. */
  425. DRM_ASAHI_SET_VERTEX_ATTACHMENTS = 2,
  426. /**
  427. * @DRM_ASAHI_SET_FRAGMENT_ATTACHMENTS: Software command to set
  428. * attachments for subsequent fragment shaders in the same submit.
  429. *
  430. * Followed by (possibly multiple) @drm_asahi_attachment payloads.
  431. */
  432. DRM_ASAHI_SET_FRAGMENT_ATTACHMENTS = 3,
  433. /**
  434. * @DRM_ASAHI_SET_COMPUTE_ATTACHMENTS: Software command to set
  435. * attachments for subsequent compute shaders in the same submit.
  436. *
  437. * Followed by (possibly multiple) @drm_asahi_attachment payloads.
  438. */
  439. DRM_ASAHI_SET_COMPUTE_ATTACHMENTS = 4,
  440. };
  441. /**
  442. * enum drm_asahi_priority - Scheduling queue priority.
  443. *
  444. * These priorities are forwarded to the firmware to influence firmware
  445. * scheduling. The exact policy is ultimately decided by firmware, but
  446. * these enums allow userspace to communicate the intentions.
  447. */
  448. enum drm_asahi_priority {
  449. /** @DRM_ASAHI_PRIORITY_LOW: Low priority queue. */
  450. DRM_ASAHI_PRIORITY_LOW = 0,
  451. /** @DRM_ASAHI_PRIORITY_MEDIUM: Medium priority queue. */
  452. DRM_ASAHI_PRIORITY_MEDIUM = 1,
  453. /**
  454. * @DRM_ASAHI_PRIORITY_HIGH: High priority queue.
  455. *
  456. * Reserved for future extension.
  457. */
  458. DRM_ASAHI_PRIORITY_HIGH = 2,
  459. /**
  460. * @DRM_ASAHI_PRIORITY_REALTIME: Real-time priority queue.
  461. *
  462. * Reserved for future extension.
  463. */
  464. DRM_ASAHI_PRIORITY_REALTIME = 3,
  465. };
  466. /**
  467. * struct drm_asahi_queue_create - Arguments passed to
  468. * DRM_IOCTL_ASAHI_QUEUE_CREATE
  469. */
  470. struct drm_asahi_queue_create {
  471. /** @flags: MBZ */
  472. __u32 flags;
  473. /** @vm_id: The ID of the VM this queue is bound to */
  474. __u32 vm_id;
  475. /** @priority: One of drm_asahi_priority */
  476. __u32 priority;
  477. /** @queue_id: The returned queue ID */
  478. __u32 queue_id;
  479. /**
  480. * @usc_exec_base: GPU base address for all USC binaries (shaders) on
  481. * this queue. USC addresses are 32-bit relative to this 64-bit base.
  482. *
  483. * This sets the following registers on all queue commands:
  484. *
  485. * USC_EXEC_BASE_TA (vertex)
  486. * USC_EXEC_BASE_ISP (fragment)
  487. * USC_EXEC_BASE_CP (compute)
  488. *
  489. * While the hardware lets us configure these independently per command,
  490. * we do not have a use case for this. Instead, we expect userspace to
  491. * fix a 4GiB VA carveout for USC memory and pass its base address here.
  492. */
  493. __u64 usc_exec_base;
  494. };
  495. /**
  496. * struct drm_asahi_queue_destroy - Arguments passed to
  497. * DRM_IOCTL_ASAHI_QUEUE_DESTROY
  498. */
  499. struct drm_asahi_queue_destroy {
  500. /** @queue_id: The queue ID to be destroyed */
  501. __u32 queue_id;
  502. /** @pad: MBZ */
  503. __u32 pad;
  504. };
  505. /**
  506. * enum drm_asahi_sync_type - Sync item type
  507. */
  508. enum drm_asahi_sync_type {
  509. /** @DRM_ASAHI_SYNC_SYNCOBJ: Binary sync object */
  510. DRM_ASAHI_SYNC_SYNCOBJ = 0,
  511. /** @DRM_ASAHI_SYNC_TIMELINE_SYNCOBJ: Timeline sync object */
  512. DRM_ASAHI_SYNC_TIMELINE_SYNCOBJ = 1,
  513. };
  514. /**
  515. * struct drm_asahi_sync - Sync item
  516. */
  517. struct drm_asahi_sync {
  518. /** @sync_type: One of drm_asahi_sync_type */
  519. __u32 sync_type;
  520. /** @handle: The sync object handle */
  521. __u32 handle;
  522. /** @timeline_value: Timeline value for timeline sync objects */
  523. __u64 timeline_value;
  524. };
  525. /**
  526. * define DRM_ASAHI_BARRIER_NONE - Command index for no barrier
  527. *
  528. * This special value may be passed in to drm_asahi_command::vdm_barrier or
  529. * drm_asahi_command::cdm_barrier to indicate that the respective subqueue
  530. * should not wait on any previous work.
  531. */
  532. #define DRM_ASAHI_BARRIER_NONE (0xFFFFu)
  533. /**
  534. * struct drm_asahi_cmd_header - Top level command structure
  535. *
  536. * This struct is core to the command buffer definition and therefore is not
  537. * extensible.
  538. */
  539. struct drm_asahi_cmd_header {
  540. /** @cmd_type: One of drm_asahi_cmd_type */
  541. __u16 cmd_type;
  542. /**
  543. * @size: Size of this command, not including this header.
  544. *
  545. * For hardware commands, this enables extensibility of commands without
  546. * requiring extra command types. Passing a command that is shorter
  547. * than expected is explicitly allowed for backwards-compatibility.
  548. * Truncated fields will be zeroed.
  549. *
  550. * For the synthetic attachment setting commands, this implicitly
  551. * encodes the number of attachments. These commands take multiple
  552. * fixed-size @drm_asahi_attachment structures as their payload, so size
  553. * equals number of attachments * sizeof(struct drm_asahi_attachment).
  554. */
  555. __u16 size;
  556. /**
  557. * @vdm_barrier: VDM (render) command index to wait on.
  558. *
  559. * Barriers are indices relative to the beginning of a given submit. A
  560. * barrier of 0 waits on commands submitted to the respective subqueue
  561. * in previous submit ioctls. A barrier of N waits on N previous
  562. * commands on the subqueue within the current submit ioctl. As a
  563. * special case, passing @DRM_ASAHI_BARRIER_NONE avoids waiting on any
  564. * commands in the subqueue.
  565. *
  566. * Examples:
  567. *
  568. * 0: This waits on all previous work.
  569. *
  570. * NONE: This does not wait for anything on this subqueue.
  571. *
  572. * 1: This waits on the first render command in the submit.
  573. * This is valid only if there are multiple render commands in the
  574. * same submit.
  575. *
  576. * Barriers are valid only for hardware commands. Synthetic software
  577. * commands to set attachments must pass NONE here.
  578. */
  579. __u16 vdm_barrier;
  580. /**
  581. * @cdm_barrier: CDM (compute) command index to wait on.
  582. *
  583. * See @vdm_barrier, and replace VDM/render with CDM/compute.
  584. */
  585. __u16 cdm_barrier;
  586. };
  587. /**
  588. * struct drm_asahi_submit - Arguments passed to DRM_IOCTL_ASAHI_SUBMIT
  589. */
  590. struct drm_asahi_submit {
  591. /**
  592. * @syncs: An optional pointer to an array of drm_asahi_sync. The first
  593. * @in_sync_count elements are in-syncs, then the remaining
  594. * @out_sync_count elements are out-syncs. Using a single array with
  595. * explicit partitioning simplifies handling.
  596. */
  597. __u64 syncs;
  598. /**
  599. * @cmdbuf: Pointer to the command buffer to submit.
  600. *
  601. * This is a flat command buffer. By design, it contains no CPU
  602. * pointers, which makes it suitable for a virtgpu wire protocol without
  603. * requiring any serializing/deserializing step.
  604. *
  605. * It consists of a series of commands. Each command begins with a
  606. * fixed-size @drm_asahi_cmd_header header and is followed by a
  607. * variable-length payload according to the type and size in the header.
  608. *
  609. * The combined count of "real" hardware commands must be nonzero and at
  610. * most drm_asahi_params_global::max_commands_per_submission.
  611. */
  612. __u64 cmdbuf;
  613. /** @flags: Flags for command submission (MBZ) */
  614. __u32 flags;
  615. /** @queue_id: The queue ID to be submitted to */
  616. __u32 queue_id;
  617. /**
  618. * @in_sync_count: Number of sync objects to wait on before starting
  619. * this job.
  620. */
  621. __u32 in_sync_count;
  622. /**
  623. * @out_sync_count: Number of sync objects to signal upon completion of
  624. * this job.
  625. */
  626. __u32 out_sync_count;
  627. /** @cmdbuf_size: Command buffer size in bytes */
  628. __u32 cmdbuf_size;
  629. /** @pad: MBZ */
  630. __u32 pad;
  631. };
  632. /**
  633. * struct drm_asahi_attachment - Describe an "attachment".
  634. *
  635. * Attachments are any memory written by shaders, notably including render
  636. * target attachments written by the end-of-tile program. This is purely a hint
  637. * about the accessed memory regions. It is optional to specify, which is
  638. * fortunate as it cannot be specified precisely with bindless access anyway.
  639. * But where possible, it's probably a good idea for userspace to include these
  640. * hints, forwarded to the firmware.
  641. *
  642. * This struct is implicitly sized and therefore is not extensible.
  643. */
  644. struct drm_asahi_attachment {
  645. /** @pointer: Base address of the attachment */
  646. __u64 pointer;
  647. /** @size: Size of the attachment in bytes */
  648. __u64 size;
  649. /** @pad: MBZ */
  650. __u32 pad;
  651. /** @flags: MBZ */
  652. __u32 flags;
  653. };
  654. enum drm_asahi_render_flags {
  655. /**
  656. * @DRM_ASAHI_RENDER_VERTEX_SCRATCH: A vertex stage shader uses scratch
  657. * memory.
  658. */
  659. DRM_ASAHI_RENDER_VERTEX_SCRATCH = (1U << 0),
  660. /**
  661. * @DRM_ASAHI_RENDER_PROCESS_EMPTY_TILES: Process even empty tiles.
  662. * This must be set when clearing render targets.
  663. */
  664. DRM_ASAHI_RENDER_PROCESS_EMPTY_TILES = (1U << 1),
  665. /**
  666. * @DRM_ASAHI_RENDER_NO_VERTEX_CLUSTERING: Run vertex stage on a single
  667. * cluster (on multi-cluster GPUs)
  668. *
  669. * This harms performance but can workaround certain sync/coherency
  670. * bugs, and therefore is useful for debugging.
  671. */
  672. DRM_ASAHI_RENDER_NO_VERTEX_CLUSTERING = (1U << 2),
  673. /**
  674. * @DRM_ASAHI_RENDER_DBIAS_IS_INT: Use integer depth bias formula.
  675. *
  676. * Graphics specifications contain two alternate formulas for depth
  677. * bias, a float formula used with floating-point depth buffers and an
  678. * integer formula using with unorm depth buffers. This flag specifies
  679. * that the integer formula should be used. If omitted, the float
  680. * formula is used instead.
  681. *
  682. * This corresponds to bit 18 of the relevant hardware control register,
  683. * so we match that here for efficiency.
  684. */
  685. DRM_ASAHI_RENDER_DBIAS_IS_INT = (1U << 18),
  686. };
  687. /**
  688. * struct drm_asahi_zls_buffer - Describe a depth or stencil buffer.
  689. *
  690. * These fields correspond to hardware registers in the ZLS (Z Load/Store) unit.
  691. * There are three hardware registers for each field respectively for loads,
  692. * stores, and partial renders. In practice, it makes sense to set all to the
  693. * same values, except in exceptional cases not yet implemented in userspace, so
  694. * we do not duplicate here for simplicity/efficiency.
  695. *
  696. * This struct is embedded in other structs and therefore is not extensible.
  697. */
  698. struct drm_asahi_zls_buffer {
  699. /** @base: Base address of the buffer */
  700. __u64 base;
  701. /**
  702. * @comp_base: If the load buffer is compressed, address of the
  703. * compression metadata section.
  704. */
  705. __u64 comp_base;
  706. /**
  707. * @stride: If layered rendering is enabled, the number of bytes
  708. * between each layer of the buffer.
  709. */
  710. __u32 stride;
  711. /**
  712. * @comp_stride: If layered rendering is enabled, the number of bytes
  713. * between each layer of the compression metadata.
  714. */
  715. __u32 comp_stride;
  716. };
  717. /**
  718. * struct drm_asahi_timestamp - Describe a timestamp write.
  719. *
  720. * The firmware can optionally write the GPU timestamp at render pass
  721. * granularities, but it needs to be mapped specially via
  722. * DRM_IOCTL_ASAHI_GEM_BIND_OBJECT. This structure therefore describes where to
  723. * write as a handle-offset pair, rather than a GPU address like normal.
  724. *
  725. * This struct is embedded in other structs and therefore is not extensible.
  726. */
  727. struct drm_asahi_timestamp {
  728. /**
  729. * @handle: Handle of the timestamp buffer, or 0 to skip this
  730. * timestamp. If nonzero, this must equal the value returned in
  731. * drm_asahi_gem_bind_object::object_handle.
  732. */
  733. __u32 handle;
  734. /** @offset: Offset to write into the timestamp buffer */
  735. __u32 offset;
  736. };
  737. /**
  738. * struct drm_asahi_timestamps - Describe timestamp writes.
  739. *
  740. * Each operation that can be timestamped, can be timestamped at the start and
  741. * end. Therefore, drm_asahi_timestamp structs always come in pairs, bundled
  742. * together into drm_asahi_timestamps.
  743. *
  744. * This struct is embedded in other structs and therefore is not extensible.
  745. */
  746. struct drm_asahi_timestamps {
  747. /** @start: Timestamp recorded at the start of the operation */
  748. struct drm_asahi_timestamp start;
  749. /** @end: Timestamp recorded at the end of the operation */
  750. struct drm_asahi_timestamp end;
  751. };
  752. /**
  753. * struct drm_asahi_helper_program - Describe helper program configuration.
  754. *
  755. * The helper program is a compute-like kernel required for various hardware
  756. * functionality. Its most important role is dynamically allocating
  757. * scratch/stack memory for individual subgroups, by partitioning a static
  758. * allocation shared for the whole device. It is supplied by userspace via
  759. * drm_asahi_helper_program and internally dispatched by the hardware as needed.
  760. *
  761. * This struct is embedded in other structs and therefore is not extensible.
  762. */
  763. struct drm_asahi_helper_program {
  764. /**
  765. * @binary: USC address to the helper program binary. This is a tagged
  766. * pointer with configuration in the bottom bits.
  767. */
  768. __u32 binary;
  769. /** @cfg: Additional configuration bits for the helper program. */
  770. __u32 cfg;
  771. /**
  772. * @data: Data passed to the helper program. This value is not
  773. * interpreted by the kernel, firmware, or hardware in any way. It is
  774. * simply a sideband for userspace, set with the submit ioctl and read
  775. * via special registers inside the helper program.
  776. *
  777. * In practice, userspace will pass a 64-bit GPU VA here pointing to the
  778. * actual arguments, which presumably don't fit in 64-bits.
  779. */
  780. __u64 data;
  781. };
  782. /**
  783. * struct drm_asahi_bg_eot - Describe a background or end-of-tile program.
  784. *
  785. * The background and end-of-tile programs are dispatched by the hardware at the
  786. * beginning and end of rendering. As the hardware "tilebuffer" is simply local
  787. * memory, these programs are necessary to implement API-level render targets.
  788. * The fragment-like background program is responsible for loading either the
  789. * clear colour or the existing render target contents, while the compute-like
  790. * end-of-tile program stores the tilebuffer contents to memory.
  791. *
  792. * This struct is embedded in other structs and therefore is not extensible.
  793. */
  794. struct drm_asahi_bg_eot {
  795. /**
  796. * @usc: USC address of the hardware USC words binding resources
  797. * (including images and uniforms) and the program itself. Note this is
  798. * an additional layer of indirection compared to the helper program,
  799. * avoiding the need for a sideband for data. This is a tagged pointer
  800. * with additional configuration in the bottom bits.
  801. */
  802. __u32 usc;
  803. /**
  804. * @rsrc_spec: Resource specifier for the program. This is a packed
  805. * hardware data structure describing the required number of registers,
  806. * uniforms, bound textures, and bound samplers.
  807. */
  808. __u32 rsrc_spec;
  809. };
  810. /**
  811. * struct drm_asahi_cmd_render - Command to submit 3D
  812. *
  813. * This command submits a single render pass. The hardware control stream may
  814. * include many draws and subpasses, but within the command, the framebuffer
  815. * dimensions and attachments are fixed.
  816. *
  817. * The hardware requires the firmware to set a large number of Control Registers
  818. * setting up state at render pass granularity before each command rendering 3D.
  819. * The firmware bundles this state into data structures. Unfortunately, we
  820. * cannot expose either any of that directly to userspace, because the
  821. * kernel-firmware ABI is not stable. Although we can guarantee the firmware
  822. * updates in tandem with the kernel, we cannot break old userspace when
  823. * upgrading the firmware and kernel. Therefore, we need to abstract well the
  824. * data structures to avoid tying our hands with future firmwares.
  825. *
  826. * The bulk of drm_asahi_cmd_render therefore consists of values of hardware
  827. * control registers, marshalled via the firmware interface.
  828. *
  829. * The framebuffer/tilebuffer dimensions are also specified here. In addition to
  830. * being passed to the firmware/hardware, the kernel requires these dimensions
  831. * to calculate various essential tiling-related data structures. It is
  832. * unfortunate that our submits are heavier than on vendors with saner
  833. * hardware-software interfaces. The upshot is all of this information is
  834. * readily available to userspace with all current APIs.
  835. *
  836. * It looks odd - but it's not overly burdensome and it ensures we can remain
  837. * compatible with old userspace.
  838. */
  839. struct drm_asahi_cmd_render {
  840. /** @flags: Combination of drm_asahi_render_flags flags. */
  841. __u32 flags;
  842. /**
  843. * @isp_zls_pixels: ISP_ZLS_PIXELS register value. This contains the
  844. * depth/stencil width/height, which may differ from the framebuffer
  845. * width/height.
  846. */
  847. __u32 isp_zls_pixels;
  848. /**
  849. * @vdm_ctrl_stream_base: VDM_CTRL_STREAM_BASE register value. GPU
  850. * address to the beginning of the VDM control stream.
  851. */
  852. __u64 vdm_ctrl_stream_base;
  853. /** @vertex_helper: Helper program used for the vertex shader */
  854. struct drm_asahi_helper_program vertex_helper;
  855. /** @fragment_helper: Helper program used for the fragment shader */
  856. struct drm_asahi_helper_program fragment_helper;
  857. /**
  858. * @isp_scissor_base: ISP_SCISSOR_BASE register value. GPU address of an
  859. * array of scissor descriptors indexed in the render pass.
  860. */
  861. __u64 isp_scissor_base;
  862. /**
  863. * @isp_dbias_base: ISP_DBIAS_BASE register value. GPU address of an
  864. * array of depth bias values indexed in the render pass.
  865. */
  866. __u64 isp_dbias_base;
  867. /**
  868. * @isp_oclqry_base: ISP_OCLQRY_BASE register value. GPU address of an
  869. * array of occlusion query results written by the render pass.
  870. */
  871. __u64 isp_oclqry_base;
  872. /** @depth: Depth buffer */
  873. struct drm_asahi_zls_buffer depth;
  874. /** @stencil: Stencil buffer */
  875. struct drm_asahi_zls_buffer stencil;
  876. /** @zls_ctrl: ZLS_CTRL register value */
  877. __u64 zls_ctrl;
  878. /** @ppp_multisamplectl: PPP_MULTISAMPLECTL register value */
  879. __u64 ppp_multisamplectl;
  880. /**
  881. * @sampler_heap: Base address of the sampler heap. This heap is used
  882. * for both vertex shaders and fragment shaders. The registers are
  883. * per-stage, but there is no known use case for separate heaps.
  884. */
  885. __u64 sampler_heap;
  886. /** @ppp_ctrl: PPP_CTRL register value */
  887. __u32 ppp_ctrl;
  888. /** @width_px: Framebuffer width in pixels */
  889. __u16 width_px;
  890. /** @height_px: Framebuffer height in pixels */
  891. __u16 height_px;
  892. /** @layers: Number of layers in the framebuffer */
  893. __u16 layers;
  894. /** @sampler_count: Number of samplers in the sampler heap. */
  895. __u16 sampler_count;
  896. /** @utile_width_px: Width of a logical tilebuffer tile in pixels */
  897. __u8 utile_width_px;
  898. /** @utile_height_px: Height of a logical tilebuffer tile in pixels */
  899. __u8 utile_height_px;
  900. /** @samples: # of samples in the framebuffer. Must be 1, 2, or 4. */
  901. __u8 samples;
  902. /** @sample_size_B: # of bytes in the tilebuffer required per sample. */
  903. __u8 sample_size_B;
  904. /**
  905. * @isp_merge_upper_x: 32-bit float used in the hardware triangle
  906. * merging. Calculate as: tan(60 deg) * width.
  907. *
  908. * Making these values UAPI avoids requiring floating-point calculations
  909. * in the kernel in the hot path.
  910. */
  911. __u32 isp_merge_upper_x;
  912. /**
  913. * @isp_merge_upper_y: 32-bit float. Calculate as: tan(60 deg) * height.
  914. * See @isp_merge_upper_x.
  915. */
  916. __u32 isp_merge_upper_y;
  917. /** @bg: Background program run for each tile at the start */
  918. struct drm_asahi_bg_eot bg;
  919. /** @eot: End-of-tile program ran for each tile at the end */
  920. struct drm_asahi_bg_eot eot;
  921. /**
  922. * @partial_bg: Background program ran at the start of each tile when
  923. * resuming the render pass during a partial render.
  924. */
  925. struct drm_asahi_bg_eot partial_bg;
  926. /**
  927. * @partial_eot: End-of-tile program ran at the end of each tile when
  928. * pausing the render pass during a partial render.
  929. */
  930. struct drm_asahi_bg_eot partial_eot;
  931. /**
  932. * @isp_bgobjdepth: ISP_BGOBJDEPTH register value. This is the depth
  933. * buffer clear value, encoded in the depth buffer's format: either a
  934. * 32-bit float or a 16-bit unorm (with upper bits zeroed).
  935. */
  936. __u32 isp_bgobjdepth;
  937. /**
  938. * @isp_bgobjvals: ISP_BGOBJVALS register value. The bottom 8-bits
  939. * contain the stencil buffer clear value.
  940. */
  941. __u32 isp_bgobjvals;
  942. /** @ts_vtx: Timestamps for the vertex portion of the render */
  943. struct drm_asahi_timestamps ts_vtx;
  944. /** @ts_frag: Timestamps for the fragment portion of the render */
  945. struct drm_asahi_timestamps ts_frag;
  946. };
  947. /**
  948. * struct drm_asahi_cmd_compute - Command to submit compute
  949. *
  950. * This command submits a control stream consisting of compute dispatches. There
  951. * is essentially no limit on how many compute dispatches may be included in a
  952. * single compute command, although timestamps are at command granularity.
  953. */
  954. struct drm_asahi_cmd_compute {
  955. /** @flags: MBZ */
  956. __u32 flags;
  957. /** @sampler_count: Number of samplers in the sampler heap. */
  958. __u32 sampler_count;
  959. /**
  960. * @cdm_ctrl_stream_base: CDM_CTRL_STREAM_BASE register value. GPU
  961. * address to the beginning of the CDM control stream.
  962. */
  963. __u64 cdm_ctrl_stream_base;
  964. /**
  965. * @cdm_ctrl_stream_end: GPU base address to the end of the hardware
  966. * control stream. Note this only considers the first contiguous segment
  967. * of the control stream, as the stream might jump elsewhere.
  968. */
  969. __u64 cdm_ctrl_stream_end;
  970. /** @sampler_heap: Base address of the sampler heap. */
  971. __u64 sampler_heap;
  972. /** @helper: Helper program used for this compute command */
  973. struct drm_asahi_helper_program helper;
  974. /** @ts: Timestamps for the compute command */
  975. struct drm_asahi_timestamps ts;
  976. };
  977. /**
  978. * struct drm_asahi_get_time - Arguments passed to DRM_IOCTL_ASAHI_GET_TIME
  979. */
  980. struct drm_asahi_get_time {
  981. /** @flags: MBZ. */
  982. __u64 flags;
  983. /** @gpu_timestamp: On return, the GPU timestamp in nanoseconds. */
  984. __u64 gpu_timestamp;
  985. };
  986. /**
  987. * DRM_IOCTL_ASAHI() - Build an Asahi IOCTL number
  988. * @__access: Access type. Must be R, W or RW.
  989. * @__id: One of the DRM_ASAHI_xxx id.
  990. * @__type: Suffix of the type being passed to the IOCTL.
  991. *
  992. * Don't use this macro directly, use the DRM_IOCTL_ASAHI_xxx
  993. * values instead.
  994. *
  995. * Return: An IOCTL number to be passed to ioctl() from userspace.
  996. */
  997. #define DRM_IOCTL_ASAHI(__access, __id, __type) \
  998. DRM_IO ## __access(DRM_COMMAND_BASE + DRM_ASAHI_ ## __id, \
  999. struct drm_asahi_ ## __type)
  1000. /* Note: this is an enum so that it can be resolved by Rust bindgen. */
  1001. enum {
  1002. DRM_IOCTL_ASAHI_GET_PARAMS = DRM_IOCTL_ASAHI(W, GET_PARAMS, get_params),
  1003. DRM_IOCTL_ASAHI_GET_TIME = DRM_IOCTL_ASAHI(WR, GET_TIME, get_time),
  1004. DRM_IOCTL_ASAHI_VM_CREATE = DRM_IOCTL_ASAHI(WR, VM_CREATE, vm_create),
  1005. DRM_IOCTL_ASAHI_VM_DESTROY = DRM_IOCTL_ASAHI(W, VM_DESTROY, vm_destroy),
  1006. DRM_IOCTL_ASAHI_VM_BIND = DRM_IOCTL_ASAHI(W, VM_BIND, vm_bind),
  1007. DRM_IOCTL_ASAHI_GEM_CREATE = DRM_IOCTL_ASAHI(WR, GEM_CREATE, gem_create),
  1008. DRM_IOCTL_ASAHI_GEM_MMAP_OFFSET = DRM_IOCTL_ASAHI(WR, GEM_MMAP_OFFSET, gem_mmap_offset),
  1009. DRM_IOCTL_ASAHI_GEM_BIND_OBJECT = DRM_IOCTL_ASAHI(WR, GEM_BIND_OBJECT, gem_bind_object),
  1010. DRM_IOCTL_ASAHI_QUEUE_CREATE = DRM_IOCTL_ASAHI(WR, QUEUE_CREATE, queue_create),
  1011. DRM_IOCTL_ASAHI_QUEUE_DESTROY = DRM_IOCTL_ASAHI(W, QUEUE_DESTROY, queue_destroy),
  1012. DRM_IOCTL_ASAHI_SUBMIT = DRM_IOCTL_ASAHI(W, SUBMIT, submit),
  1013. };
  1014. #if defined(__cplusplus)
  1015. }
  1016. #endif
  1017. #endif /* _ASAHI_DRM_H_ */