xe_drm.h 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2023 Intel Corporation
  4. */
  5. #ifndef _UAPI_XE_DRM_H_
  6. #define _UAPI_XE_DRM_H_
  7. #include "drm.h"
  8. #if defined(__cplusplus)
  9. extern "C" {
  10. #endif
  11. /*
  12. * Please note that modifications to all structs defined here are
  13. * subject to backwards-compatibility constraints.
  14. * Sections in this file are organized as follows:
  15. * 1. IOCTL definition
  16. * 2. Extension definition and helper structs
  17. * 3. IOCTL's Query structs in the order of the Query's entries.
  18. * 4. The rest of IOCTL structs in the order of IOCTL declaration.
  19. */
  20. /**
  21. * DOC: Xe Device Block Diagram
  22. *
  23. * The diagram below represents a high-level simplification of a discrete
  24. * GPU supported by the Xe driver. It shows some device components which
  25. * are necessary to understand this API, as well as how their relations
  26. * to each other. This diagram does not represent real hardware::
  27. *
  28. * ┌──────────────────────────────────────────────────────────────────┐
  29. * │ ┌──────────────────────────────────────────────────┐ ┌─────────┐ │
  30. * │ │ ┌───────────────────────┐ ┌─────┐ │ │ ┌─────┐ │ │
  31. * │ │ │ VRAM0 ├───┤ ... │ │ │ │VRAM1│ │ │
  32. * │ │ └───────────┬───────────┘ └─GT1─┘ │ │ └──┬──┘ │ │
  33. * │ │ ┌──────────────────┴───────────────────────────┐ │ │ ┌──┴──┐ │ │
  34. * │ │ │ ┌─────────────────────┐ ┌─────────────────┐ │ │ │ │ │ │ │
  35. * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │
  36. * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │RCS0 │ │BCS0 │ │ │ │ │ │ │ │ │
  37. * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │
  38. * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │
  39. * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │VCS0 │ │VCS1 │ │ │ │ │ │ │ │ │
  40. * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │
  41. * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │
  42. * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │VECS0│ │VECS1│ │ │ │ │ │ ... │ │ │
  43. * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │
  44. * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │
  45. * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │CCS0 │ │CCS1 │ │ │ │ │ │ │ │ │
  46. * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │
  47. * │ │ │ └─────────DSS─────────┘ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │
  48. * │ │ │ │ │CCS2 │ │CCS3 │ │ │ │ │ │ │ │ │
  49. * │ │ │ ┌─────┐ ┌─────┐ ┌─────┐ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │
  50. * │ │ │ │ ... │ │ ... │ │ ... │ │ │ │ │ │ │ │ │ │
  51. * │ │ │ └─DSS─┘ └─DSS─┘ └─DSS─┘ └─────Engines─────┘ │ │ │ │ │ │ │
  52. * │ │ └───────────────────────────GT0────────────────┘ │ │ └─GT2─┘ │ │
  53. * │ └────────────────────────────Tile0─────────────────┘ └─ Tile1──┘ │
  54. * └─────────────────────────────Device0───────┬──────────────────────┘
  55. * │
  56. * ───────────────────────┴────────── PCI bus
  57. */
  58. /**
  59. * DOC: Xe uAPI Overview
  60. *
  61. * This section aims to describe the Xe's IOCTL entries, its structs, and other
  62. * Xe related uAPI such as uevents and PMU (Platform Monitoring Unit) related
  63. * entries and usage.
  64. *
  65. * List of supported IOCTLs:
  66. * - &DRM_IOCTL_XE_DEVICE_QUERY
  67. * - &DRM_IOCTL_XE_GEM_CREATE
  68. * - &DRM_IOCTL_XE_GEM_MMAP_OFFSET
  69. * - &DRM_IOCTL_XE_VM_CREATE
  70. * - &DRM_IOCTL_XE_VM_DESTROY
  71. * - &DRM_IOCTL_XE_VM_BIND
  72. * - &DRM_IOCTL_XE_EXEC_QUEUE_CREATE
  73. * - &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY
  74. * - &DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY
  75. * - &DRM_IOCTL_XE_EXEC
  76. * - &DRM_IOCTL_XE_WAIT_USER_FENCE
  77. * - &DRM_IOCTL_XE_OBSERVATION
  78. */
  79. /*
  80. * xe specific ioctls.
  81. *
  82. * The device specific ioctl range is [DRM_COMMAND_BASE, DRM_COMMAND_END) ie
  83. * [0x40, 0xa0) (a0 is excluded). The numbers below are defined as offset
  84. * against DRM_COMMAND_BASE and should be between [0x0, 0x60).
  85. */
  86. #define DRM_XE_DEVICE_QUERY 0x00
  87. #define DRM_XE_GEM_CREATE 0x01
  88. #define DRM_XE_GEM_MMAP_OFFSET 0x02
  89. #define DRM_XE_VM_CREATE 0x03
  90. #define DRM_XE_VM_DESTROY 0x04
  91. #define DRM_XE_VM_BIND 0x05
  92. #define DRM_XE_EXEC_QUEUE_CREATE 0x06
  93. #define DRM_XE_EXEC_QUEUE_DESTROY 0x07
  94. #define DRM_XE_EXEC_QUEUE_GET_PROPERTY 0x08
  95. #define DRM_XE_EXEC 0x09
  96. #define DRM_XE_WAIT_USER_FENCE 0x0a
  97. #define DRM_XE_OBSERVATION 0x0b
  98. /* Must be kept compact -- no holes */
  99. #define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query)
  100. #define DRM_IOCTL_XE_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_CREATE, struct drm_xe_gem_create)
  101. #define DRM_IOCTL_XE_GEM_MMAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_MMAP_OFFSET, struct drm_xe_gem_mmap_offset)
  102. #define DRM_IOCTL_XE_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_CREATE, struct drm_xe_vm_create)
  103. #define DRM_IOCTL_XE_VM_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_DESTROY, struct drm_xe_vm_destroy)
  104. #define DRM_IOCTL_XE_VM_BIND DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_BIND, struct drm_xe_vm_bind)
  105. #define DRM_IOCTL_XE_EXEC_QUEUE_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_CREATE, struct drm_xe_exec_queue_create)
  106. #define DRM_IOCTL_XE_EXEC_QUEUE_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_DESTROY, struct drm_xe_exec_queue_destroy)
  107. #define DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_GET_PROPERTY, struct drm_xe_exec_queue_get_property)
  108. #define DRM_IOCTL_XE_EXEC DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec)
  109. #define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)
  110. #define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param)
  111. /**
  112. * DOC: Xe IOCTL Extensions
  113. *
  114. * Before detailing the IOCTLs and its structs, it is important to highlight
  115. * that every IOCTL in Xe is extensible.
  116. *
  117. * Many interfaces need to grow over time. In most cases we can simply
  118. * extend the struct and have userspace pass in more data. Another option,
  119. * as demonstrated by Vulkan's approach to providing extensions for forward
  120. * and backward compatibility, is to use a list of optional structs to
  121. * provide those extra details.
  122. *
  123. * The key advantage to using an extension chain is that it allows us to
  124. * redefine the interface more easily than an ever growing struct of
  125. * increasing complexity, and for large parts of that interface to be
  126. * entirely optional. The downside is more pointer chasing; chasing across
  127. * the __user boundary with pointers encapsulated inside u64.
  128. *
  129. * Example chaining:
  130. *
  131. * .. code-block:: C
  132. *
  133. * struct drm_xe_user_extension ext3 {
  134. * .next_extension = 0, // end
  135. * .name = ...,
  136. * };
  137. * struct drm_xe_user_extension ext2 {
  138. * .next_extension = (uintptr_t)&ext3,
  139. * .name = ...,
  140. * };
  141. * struct drm_xe_user_extension ext1 {
  142. * .next_extension = (uintptr_t)&ext2,
  143. * .name = ...,
  144. * };
  145. *
  146. * Typically the struct drm_xe_user_extension would be embedded in some uAPI
  147. * struct, and in this case we would feed it the head of the chain(i.e ext1),
  148. * which would then apply all of the above extensions.
  149. */
  150. /**
  151. * struct drm_xe_user_extension - Base class for defining a chain of extensions
  152. */
  153. struct drm_xe_user_extension {
  154. /**
  155. * @next_extension:
  156. *
  157. * Pointer to the next struct drm_xe_user_extension, or zero if the end.
  158. */
  159. __u64 next_extension;
  160. /**
  161. * @name: Name of the extension.
  162. *
  163. * Note that the name here is just some integer.
  164. *
  165. * Also note that the name space for this is not global for the whole
  166. * driver, but rather its scope/meaning is limited to the specific piece
  167. * of uAPI which has embedded the struct drm_xe_user_extension.
  168. */
  169. __u32 name;
  170. /**
  171. * @pad: MBZ
  172. *
  173. * All undefined bits must be zero.
  174. */
  175. __u32 pad;
  176. };
  177. /**
  178. * struct drm_xe_ext_set_property - Generic set property extension
  179. *
  180. * A generic struct that allows any of the Xe's IOCTL to be extended
  181. * with a set_property operation.
  182. */
  183. struct drm_xe_ext_set_property {
  184. /** @base: base user extension */
  185. struct drm_xe_user_extension base;
  186. /** @property: property to set */
  187. __u32 property;
  188. /** @pad: MBZ */
  189. __u32 pad;
  190. /** @value: property value */
  191. __u64 value;
  192. /** @reserved: Reserved */
  193. __u64 reserved[2];
  194. };
  195. /**
  196. * struct drm_xe_engine_class_instance - instance of an engine class
  197. *
  198. * It is returned as part of the @drm_xe_engine, but it also is used as
  199. * the input of engine selection for both @drm_xe_exec_queue_create and
  200. * @drm_xe_query_engine_cycles
  201. *
  202. * The @engine_class can be:
  203. * - %DRM_XE_ENGINE_CLASS_RENDER
  204. * - %DRM_XE_ENGINE_CLASS_COPY
  205. * - %DRM_XE_ENGINE_CLASS_VIDEO_DECODE
  206. * - %DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE
  207. * - %DRM_XE_ENGINE_CLASS_COMPUTE
  208. * - %DRM_XE_ENGINE_CLASS_VM_BIND - Kernel only classes (not actual
  209. * hardware engine class). Used for creating ordered queues of VM
  210. * bind operations.
  211. */
  212. struct drm_xe_engine_class_instance {
  213. #define DRM_XE_ENGINE_CLASS_RENDER 0
  214. #define DRM_XE_ENGINE_CLASS_COPY 1
  215. #define DRM_XE_ENGINE_CLASS_VIDEO_DECODE 2
  216. #define DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE 3
  217. #define DRM_XE_ENGINE_CLASS_COMPUTE 4
  218. #define DRM_XE_ENGINE_CLASS_VM_BIND 5
  219. /** @engine_class: engine class id */
  220. __u16 engine_class;
  221. /** @engine_instance: engine instance id */
  222. __u16 engine_instance;
  223. /** @gt_id: Unique ID of this GT within the PCI Device */
  224. __u16 gt_id;
  225. /** @pad: MBZ */
  226. __u16 pad;
  227. };
  228. /**
  229. * struct drm_xe_engine - describe hardware engine
  230. */
  231. struct drm_xe_engine {
  232. /** @instance: The @drm_xe_engine_class_instance */
  233. struct drm_xe_engine_class_instance instance;
  234. /** @reserved: Reserved */
  235. __u64 reserved[3];
  236. };
  237. /**
  238. * struct drm_xe_query_engines - describe engines
  239. *
  240. * If a query is made with a struct @drm_xe_device_query where .query
  241. * is equal to %DRM_XE_DEVICE_QUERY_ENGINES, then the reply uses an array of
  242. * struct @drm_xe_query_engines in .data.
  243. */
  244. struct drm_xe_query_engines {
  245. /** @num_engines: number of engines returned in @engines */
  246. __u32 num_engines;
  247. /** @pad: MBZ */
  248. __u32 pad;
  249. /** @engines: The returned engines for this device */
  250. struct drm_xe_engine engines[];
  251. };
  252. /**
  253. * enum drm_xe_memory_class - Supported memory classes.
  254. */
  255. enum drm_xe_memory_class {
  256. /** @DRM_XE_MEM_REGION_CLASS_SYSMEM: Represents system memory. */
  257. DRM_XE_MEM_REGION_CLASS_SYSMEM = 0,
  258. /**
  259. * @DRM_XE_MEM_REGION_CLASS_VRAM: On discrete platforms, this
  260. * represents the memory that is local to the device, which we
  261. * call VRAM. Not valid on integrated platforms.
  262. */
  263. DRM_XE_MEM_REGION_CLASS_VRAM
  264. };
  265. /**
  266. * struct drm_xe_mem_region - Describes some region as known to
  267. * the driver.
  268. */
  269. struct drm_xe_mem_region {
  270. /**
  271. * @mem_class: The memory class describing this region.
  272. *
  273. * See enum drm_xe_memory_class for supported values.
  274. */
  275. __u16 mem_class;
  276. /**
  277. * @instance: The unique ID for this region, which serves as the
  278. * index in the placement bitmask used as argument for
  279. * &DRM_IOCTL_XE_GEM_CREATE
  280. */
  281. __u16 instance;
  282. /**
  283. * @min_page_size: Min page-size in bytes for this region.
  284. *
  285. * When the kernel allocates memory for this region, the
  286. * underlying pages will be at least @min_page_size in size.
  287. * Buffer objects with an allowable placement in this region must be
  288. * created with a size aligned to this value.
  289. * GPU virtual address mappings of (parts of) buffer objects that
  290. * may be placed in this region must also have their GPU virtual
  291. * address and range aligned to this value.
  292. * Affected IOCTLS will return %-EINVAL if alignment restrictions are
  293. * not met.
  294. */
  295. __u32 min_page_size;
  296. /**
  297. * @total_size: The usable size in bytes for this region.
  298. */
  299. __u64 total_size;
  300. /**
  301. * @used: Estimate of the memory used in bytes for this region.
  302. *
  303. * Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable
  304. * accounting. Without this the value here will always equal
  305. * zero.
  306. */
  307. __u64 used;
  308. /**
  309. * @cpu_visible_size: How much of this region can be CPU
  310. * accessed, in bytes.
  311. *
  312. * This will always be <= @total_size, and the remainder (if
  313. * any) will not be CPU accessible. If the CPU accessible part
  314. * is smaller than @total_size then this is referred to as a
  315. * small BAR system.
  316. *
  317. * On systems without small BAR (full BAR), the probed_size will
  318. * always equal the @total_size, since all of it will be CPU
  319. * accessible.
  320. *
  321. * Note this is only tracked for DRM_XE_MEM_REGION_CLASS_VRAM
  322. * regions (for other types the value here will always equal
  323. * zero).
  324. */
  325. __u64 cpu_visible_size;
  326. /**
  327. * @cpu_visible_used: Estimate of CPU visible memory used, in
  328. * bytes.
  329. *
  330. * Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable
  331. * accounting. Without this the value here will always equal
  332. * zero. Note this is only currently tracked for
  333. * DRM_XE_MEM_REGION_CLASS_VRAM regions (for other types the value
  334. * here will always be zero).
  335. */
  336. __u64 cpu_visible_used;
  337. /** @reserved: Reserved */
  338. __u64 reserved[6];
  339. };
  340. /**
  341. * struct drm_xe_query_mem_regions - describe memory regions
  342. *
  343. * If a query is made with a struct drm_xe_device_query where .query
  344. * is equal to DRM_XE_DEVICE_QUERY_MEM_REGIONS, then the reply uses
  345. * struct drm_xe_query_mem_regions in .data.
  346. */
  347. struct drm_xe_query_mem_regions {
  348. /** @num_mem_regions: number of memory regions returned in @mem_regions */
  349. __u32 num_mem_regions;
  350. /** @pad: MBZ */
  351. __u32 pad;
  352. /** @mem_regions: The returned memory regions for this device */
  353. struct drm_xe_mem_region mem_regions[];
  354. };
  355. /**
  356. * struct drm_xe_query_config - describe the device configuration
  357. *
  358. * If a query is made with a struct drm_xe_device_query where .query
  359. * is equal to DRM_XE_DEVICE_QUERY_CONFIG, then the reply uses
  360. * struct drm_xe_query_config in .data.
  361. *
  362. * The index in @info can be:
  363. * - %DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID - Device ID (lower 16 bits)
  364. * and the device revision (next 8 bits)
  365. * - %DRM_XE_QUERY_CONFIG_FLAGS - Flags describing the device
  366. * configuration, see list below
  367. *
  368. * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM - Flag is set if the device
  369. * has usable VRAM
  370. * - %DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT - Minimal memory alignment
  371. * required by this device, typically SZ_4K or SZ_64K
  372. * - %DRM_XE_QUERY_CONFIG_VA_BITS - Maximum bits of a virtual address
  373. * - %DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY - Value of the highest
  374. * available exec queue priority
  375. */
  376. struct drm_xe_query_config {
  377. /** @num_params: number of parameters returned in info */
  378. __u32 num_params;
  379. /** @pad: MBZ */
  380. __u32 pad;
  381. #define DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID 0
  382. #define DRM_XE_QUERY_CONFIG_FLAGS 1
  383. #define DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM (1 << 0)
  384. #define DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT 2
  385. #define DRM_XE_QUERY_CONFIG_VA_BITS 3
  386. #define DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY 4
  387. /** @info: array of elements containing the config info */
  388. __u64 info[];
  389. };
  390. /**
  391. * struct drm_xe_gt - describe an individual GT.
  392. *
  393. * To be used with drm_xe_query_gt_list, which will return a list with all the
  394. * existing GT individual descriptions.
  395. * Graphics Technology (GT) is a subset of a GPU/tile that is responsible for
  396. * implementing graphics and/or media operations.
  397. *
  398. * The index in @type can be:
  399. * - %DRM_XE_QUERY_GT_TYPE_MAIN
  400. * - %DRM_XE_QUERY_GT_TYPE_MEDIA
  401. */
  402. struct drm_xe_gt {
  403. #define DRM_XE_QUERY_GT_TYPE_MAIN 0
  404. #define DRM_XE_QUERY_GT_TYPE_MEDIA 1
  405. /** @type: GT type: Main or Media */
  406. __u16 type;
  407. /** @tile_id: Tile ID where this GT lives (Information only) */
  408. __u16 tile_id;
  409. /** @gt_id: Unique ID of this GT within the PCI Device */
  410. __u16 gt_id;
  411. /** @pad: MBZ */
  412. __u16 pad[3];
  413. /** @reference_clock: A clock frequency for timestamp */
  414. __u32 reference_clock;
  415. /**
  416. * @near_mem_regions: Bit mask of instances from
  417. * drm_xe_query_mem_regions that are nearest to the current engines
  418. * of this GT.
  419. * Each index in this mask refers directly to the struct
  420. * drm_xe_query_mem_regions' instance, no assumptions should
  421. * be made about order. The type of each region is described
  422. * by struct drm_xe_query_mem_regions' mem_class.
  423. */
  424. __u64 near_mem_regions;
  425. /**
  426. * @far_mem_regions: Bit mask of instances from
  427. * drm_xe_query_mem_regions that are far from the engines of this GT.
  428. * In general, they have extra indirections when compared to the
  429. * @near_mem_regions. For a discrete device this could mean system
  430. * memory and memory living in a different tile.
  431. * Each index in this mask refers directly to the struct
  432. * drm_xe_query_mem_regions' instance, no assumptions should
  433. * be made about order. The type of each region is described
  434. * by struct drm_xe_query_mem_regions' mem_class.
  435. */
  436. __u64 far_mem_regions;
  437. /** @ip_ver_major: Graphics/media IP major version on GMD_ID platforms */
  438. __u16 ip_ver_major;
  439. /** @ip_ver_minor: Graphics/media IP minor version on GMD_ID platforms */
  440. __u16 ip_ver_minor;
  441. /** @ip_ver_rev: Graphics/media IP revision version on GMD_ID platforms */
  442. __u16 ip_ver_rev;
  443. /** @pad2: MBZ */
  444. __u16 pad2;
  445. /** @reserved: Reserved */
  446. __u64 reserved[7];
  447. };
  448. /**
  449. * struct drm_xe_query_gt_list - A list with GT description items.
  450. *
  451. * If a query is made with a struct drm_xe_device_query where .query
  452. * is equal to DRM_XE_DEVICE_QUERY_GT_LIST, then the reply uses struct
  453. * drm_xe_query_gt_list in .data.
  454. */
  455. struct drm_xe_query_gt_list {
  456. /** @num_gt: number of GT items returned in gt_list */
  457. __u32 num_gt;
  458. /** @pad: MBZ */
  459. __u32 pad;
  460. /** @gt_list: The GT list returned for this device */
  461. struct drm_xe_gt gt_list[];
  462. };
  463. /**
  464. * struct drm_xe_query_topology_mask - describe the topology mask of a GT
  465. *
  466. * This is the hardware topology which reflects the internal physical
  467. * structure of the GPU.
  468. *
  469. * If a query is made with a struct drm_xe_device_query where .query
  470. * is equal to DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, then the reply uses
  471. * struct drm_xe_query_topology_mask in .data.
  472. *
  473. * The @type can be:
  474. * - %DRM_XE_TOPO_DSS_GEOMETRY - To query the mask of Dual Sub Slices
  475. * (DSS) available for geometry operations. For example a query response
  476. * containing the following in mask:
  477. * ``DSS_GEOMETRY ff ff ff ff 00 00 00 00``
  478. * means 32 DSS are available for geometry.
  479. * - %DRM_XE_TOPO_DSS_COMPUTE - To query the mask of Dual Sub Slices
  480. * (DSS) available for compute operations. For example a query response
  481. * containing the following in mask:
  482. * ``DSS_COMPUTE ff ff ff ff 00 00 00 00``
  483. * means 32 DSS are available for compute.
  484. * - %DRM_XE_TOPO_L3_BANK - To query the mask of enabled L3 banks. This type
  485. * may be omitted if the driver is unable to query the mask from the
  486. * hardware.
  487. * - %DRM_XE_TOPO_EU_PER_DSS - To query the mask of Execution Units (EU)
  488. * available per Dual Sub Slices (DSS). For example a query response
  489. * containing the following in mask:
  490. * ``EU_PER_DSS ff ff 00 00 00 00 00 00``
  491. * means each DSS has 16 SIMD8 EUs. This type may be omitted if device
  492. * doesn't have SIMD8 EUs.
  493. * - %DRM_XE_TOPO_SIMD16_EU_PER_DSS - To query the mask of SIMD16 Execution
  494. * Units (EU) available per Dual Sub Slices (DSS). For example a query
  495. * response containing the following in mask:
  496. * ``SIMD16_EU_PER_DSS ff ff 00 00 00 00 00 00``
  497. * means each DSS has 16 SIMD16 EUs. This type may be omitted if device
  498. * doesn't have SIMD16 EUs.
  499. */
  500. struct drm_xe_query_topology_mask {
  501. /** @gt_id: GT ID the mask is associated with */
  502. __u16 gt_id;
  503. #define DRM_XE_TOPO_DSS_GEOMETRY 1
  504. #define DRM_XE_TOPO_DSS_COMPUTE 2
  505. #define DRM_XE_TOPO_L3_BANK 3
  506. #define DRM_XE_TOPO_EU_PER_DSS 4
  507. #define DRM_XE_TOPO_SIMD16_EU_PER_DSS 5
  508. /** @type: type of mask */
  509. __u16 type;
  510. /** @num_bytes: number of bytes in requested mask */
  511. __u32 num_bytes;
  512. /** @mask: little-endian mask of @num_bytes */
  513. __u8 mask[];
  514. };
  515. /**
  516. * struct drm_xe_query_engine_cycles - correlate CPU and GPU timestamps
  517. *
  518. * If a query is made with a struct drm_xe_device_query where .query is equal to
  519. * DRM_XE_DEVICE_QUERY_ENGINE_CYCLES, then the reply uses struct drm_xe_query_engine_cycles
  520. * in .data. struct drm_xe_query_engine_cycles is allocated by the user and
  521. * .data points to this allocated structure.
  522. *
  523. * The query returns the engine cycles, which along with GT's @reference_clock,
  524. * can be used to calculate the engine timestamp. In addition the
  525. * query returns a set of cpu timestamps that indicate when the command
  526. * streamer cycle count was captured.
  527. */
  528. struct drm_xe_query_engine_cycles {
  529. /**
  530. * @eci: This is input by the user and is the engine for which command
  531. * streamer cycles is queried.
  532. */
  533. struct drm_xe_engine_class_instance eci;
  534. /**
  535. * @clockid: This is input by the user and is the reference clock id for
  536. * CPU timestamp. For definition, see clock_gettime(2) and
  537. * perf_event_open(2). Supported clock ids are CLOCK_MONOTONIC,
  538. * CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_BOOTTIME, CLOCK_TAI.
  539. */
  540. __s32 clockid;
  541. /** @width: Width of the engine cycle counter in bits. */
  542. __u32 width;
  543. /**
  544. * @engine_cycles: Engine cycles as read from its register
  545. * at 0x358 offset.
  546. */
  547. __u64 engine_cycles;
  548. /**
  549. * @cpu_timestamp: CPU timestamp in ns. The timestamp is captured before
  550. * reading the engine_cycles register using the reference clockid set by the
  551. * user.
  552. */
  553. __u64 cpu_timestamp;
  554. /**
  555. * @cpu_delta: Time delta in ns captured around reading the lower dword
  556. * of the engine_cycles register.
  557. */
  558. __u64 cpu_delta;
  559. };
  560. /**
  561. * struct drm_xe_query_uc_fw_version - query a micro-controller firmware version
  562. *
  563. * Given a uc_type this will return the branch, major, minor and patch version
  564. * of the micro-controller firmware.
  565. */
  566. struct drm_xe_query_uc_fw_version {
  567. /** @uc_type: The micro-controller type to query firmware version */
  568. #define XE_QUERY_UC_TYPE_GUC_SUBMISSION 0
  569. #define XE_QUERY_UC_TYPE_HUC 1
  570. __u16 uc_type;
  571. /** @pad: MBZ */
  572. __u16 pad;
  573. /** @branch_ver: branch uc fw version */
  574. __u32 branch_ver;
  575. /** @major_ver: major uc fw version */
  576. __u32 major_ver;
  577. /** @minor_ver: minor uc fw version */
  578. __u32 minor_ver;
  579. /** @patch_ver: patch uc fw version */
  580. __u32 patch_ver;
  581. /** @pad2: MBZ */
  582. __u32 pad2;
  583. /** @reserved: Reserved */
  584. __u64 reserved;
  585. };
  586. /**
  587. * struct drm_xe_device_query - Input of &DRM_IOCTL_XE_DEVICE_QUERY - main
  588. * structure to query device information
  589. *
  590. * The user selects the type of data to query among DRM_XE_DEVICE_QUERY_*
  591. * and sets the value in the query member. This determines the type of
  592. * the structure provided by the driver in data, among struct drm_xe_query_*.
  593. *
  594. * The @query can be:
  595. * - %DRM_XE_DEVICE_QUERY_ENGINES
  596. * - %DRM_XE_DEVICE_QUERY_MEM_REGIONS
  597. * - %DRM_XE_DEVICE_QUERY_CONFIG
  598. * - %DRM_XE_DEVICE_QUERY_GT_LIST
  599. * - %DRM_XE_DEVICE_QUERY_HWCONFIG - Query type to retrieve the hardware
  600. * configuration of the device such as information on slices, memory,
  601. * caches, and so on. It is provided as a table of key / value
  602. * attributes.
  603. * - %DRM_XE_DEVICE_QUERY_GT_TOPOLOGY
  604. * - %DRM_XE_DEVICE_QUERY_ENGINE_CYCLES
  605. *
  606. * If size is set to 0, the driver fills it with the required size for
  607. * the requested type of data to query. If size is equal to the required
  608. * size, the queried information is copied into data. If size is set to
  609. * a value different from 0 and different from the required size, the
  610. * IOCTL call returns -EINVAL.
  611. *
  612. * For example the following code snippet allows retrieving and printing
  613. * information about the device engines with DRM_XE_DEVICE_QUERY_ENGINES:
  614. *
  615. * .. code-block:: C
  616. *
  617. * struct drm_xe_query_engines *engines;
  618. * struct drm_xe_device_query query = {
  619. * .extensions = 0,
  620. * .query = DRM_XE_DEVICE_QUERY_ENGINES,
  621. * .size = 0,
  622. * .data = 0,
  623. * };
  624. * ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query);
  625. * engines = malloc(query.size);
  626. * query.data = (uintptr_t)engines;
  627. * ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query);
  628. * for (int i = 0; i < engines->num_engines; i++) {
  629. * printf("Engine %d: %s\n", i,
  630. * engines->engines[i].instance.engine_class ==
  631. * DRM_XE_ENGINE_CLASS_RENDER ? "RENDER":
  632. * engines->engines[i].instance.engine_class ==
  633. * DRM_XE_ENGINE_CLASS_COPY ? "COPY":
  634. * engines->engines[i].instance.engine_class ==
  635. * DRM_XE_ENGINE_CLASS_VIDEO_DECODE ? "VIDEO_DECODE":
  636. * engines->engines[i].instance.engine_class ==
  637. * DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE ? "VIDEO_ENHANCE":
  638. * engines->engines[i].instance.engine_class ==
  639. * DRM_XE_ENGINE_CLASS_COMPUTE ? "COMPUTE":
  640. * "UNKNOWN");
  641. * }
  642. * free(engines);
  643. */
  644. struct drm_xe_device_query {
  645. /** @extensions: Pointer to the first extension struct, if any */
  646. __u64 extensions;
  647. #define DRM_XE_DEVICE_QUERY_ENGINES 0
  648. #define DRM_XE_DEVICE_QUERY_MEM_REGIONS 1
  649. #define DRM_XE_DEVICE_QUERY_CONFIG 2
  650. #define DRM_XE_DEVICE_QUERY_GT_LIST 3
  651. #define DRM_XE_DEVICE_QUERY_HWCONFIG 4
  652. #define DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 5
  653. #define DRM_XE_DEVICE_QUERY_ENGINE_CYCLES 6
  654. #define DRM_XE_DEVICE_QUERY_UC_FW_VERSION 7
  655. #define DRM_XE_DEVICE_QUERY_OA_UNITS 8
  656. /** @query: The type of data to query */
  657. __u32 query;
  658. /** @size: Size of the queried data */
  659. __u32 size;
  660. /** @data: Queried data is placed here */
  661. __u64 data;
  662. /** @reserved: Reserved */
  663. __u64 reserved[2];
  664. };
  665. /**
  666. * struct drm_xe_gem_create - Input of &DRM_IOCTL_XE_GEM_CREATE - A structure for
  667. * gem creation
  668. *
  669. * The @flags can be:
  670. * - %DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING
  671. * - %DRM_XE_GEM_CREATE_FLAG_SCANOUT
  672. * - %DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM - When using VRAM as a
  673. * possible placement, ensure that the corresponding VRAM allocation
  674. * will always use the CPU accessible part of VRAM. This is important
  675. * for small-bar systems (on full-bar systems this gets turned into a
  676. * noop).
  677. * Note1: System memory can be used as an extra placement if the kernel
  678. * should spill the allocation to system memory, if space can't be made
  679. * available in the CPU accessible part of VRAM (giving the same
  680. * behaviour as the i915 interface, see
  681. * I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS).
  682. * Note2: For clear-color CCS surfaces the kernel needs to read the
  683. * clear-color value stored in the buffer, and on discrete platforms we
  684. * need to use VRAM for display surfaces, therefore the kernel requires
  685. * setting this flag for such objects, otherwise an error is thrown on
  686. * small-bar systems.
  687. *
  688. * @cpu_caching supports the following values:
  689. * - %DRM_XE_GEM_CPU_CACHING_WB - Allocate the pages with write-back
  690. * caching. On iGPU this can't be used for scanout surfaces. Currently
  691. * not allowed for objects placed in VRAM.
  692. * - %DRM_XE_GEM_CPU_CACHING_WC - Allocate the pages as write-combined. This
  693. * is uncached. Scanout surfaces should likely use this. All objects
  694. * that can be placed in VRAM must use this.
  695. */
  696. struct drm_xe_gem_create {
  697. /** @extensions: Pointer to the first extension struct, if any */
  698. __u64 extensions;
  699. /**
  700. * @size: Size of the object to be created, must match region
  701. * (system or vram) minimum alignment (&min_page_size).
  702. */
  703. __u64 size;
  704. /**
  705. * @placement: A mask of memory instances of where BO can be placed.
  706. * Each index in this mask refers directly to the struct
  707. * drm_xe_query_mem_regions' instance, no assumptions should
  708. * be made about order. The type of each region is described
  709. * by struct drm_xe_query_mem_regions' mem_class.
  710. */
  711. __u32 placement;
  712. #define DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING (1 << 0)
  713. #define DRM_XE_GEM_CREATE_FLAG_SCANOUT (1 << 1)
  714. #define DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM (1 << 2)
  715. /**
  716. * @flags: Flags, currently a mask of memory instances of where BO can
  717. * be placed
  718. */
  719. __u32 flags;
  720. /**
  721. * @vm_id: Attached VM, if any
  722. *
  723. * If a VM is specified, this BO must:
  724. *
  725. * 1. Only ever be bound to that VM.
  726. * 2. Cannot be exported as a PRIME fd.
  727. */
  728. __u32 vm_id;
  729. /**
  730. * @handle: Returned handle for the object.
  731. *
  732. * Object handles are nonzero.
  733. */
  734. __u32 handle;
  735. #define DRM_XE_GEM_CPU_CACHING_WB 1
  736. #define DRM_XE_GEM_CPU_CACHING_WC 2
  737. /**
  738. * @cpu_caching: The CPU caching mode to select for this object. If
  739. * mmaping the object the mode selected here will also be used. The
  740. * exception is when mapping system memory (including data evicted
  741. * to system) on discrete GPUs. The caching mode selected will
  742. * then be overridden to DRM_XE_GEM_CPU_CACHING_WB, and coherency
  743. * between GPU- and CPU is guaranteed. The caching mode of
  744. * existing CPU-mappings will be updated transparently to
  745. * user-space clients.
  746. */
  747. __u16 cpu_caching;
  748. /** @pad: MBZ */
  749. __u16 pad[3];
  750. /** @reserved: Reserved */
  751. __u64 reserved[2];
  752. };
  753. /**
  754. * struct drm_xe_gem_mmap_offset - Input of &DRM_IOCTL_XE_GEM_MMAP_OFFSET
  755. */
  756. struct drm_xe_gem_mmap_offset {
  757. /** @extensions: Pointer to the first extension struct, if any */
  758. __u64 extensions;
  759. /** @handle: Handle for the object being mapped. */
  760. __u32 handle;
  761. /** @flags: Must be zero */
  762. __u32 flags;
  763. /** @offset: The fake offset to use for subsequent mmap call */
  764. __u64 offset;
  765. /** @reserved: Reserved */
  766. __u64 reserved[2];
  767. };
  768. /**
  769. * struct drm_xe_vm_create - Input of &DRM_IOCTL_XE_VM_CREATE
  770. *
  771. * The @flags can be:
  772. * - %DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE
  773. * - %DRM_XE_VM_CREATE_FLAG_LR_MODE - An LR, or Long Running VM accepts
  774. * exec submissions to its exec_queues that don't have an upper time
  775. * limit on the job execution time. But exec submissions to these
  776. * don't allow any of the flags DRM_XE_SYNC_FLAG_SYNCOBJ,
  777. * DRM_XE_SYNC_FLAG_TIMELINE_SYNCOBJ, DRM_XE_SYNC_FLAG_DMA_BUF,
  778. * used as out-syncobjs, that is, together with DRM_XE_SYNC_FLAG_SIGNAL.
  779. * LR VMs can be created in recoverable page-fault mode using
  780. * DRM_XE_VM_CREATE_FLAG_FAULT_MODE, if the device supports it.
  781. * If that flag is omitted, the UMD can not rely on the slightly
  782. * different per-VM overcommit semantics that are enabled by
  783. * DRM_XE_VM_CREATE_FLAG_FAULT_MODE (see below), but KMD may
  784. * still enable recoverable pagefaults if supported by the device.
  785. * - %DRM_XE_VM_CREATE_FLAG_FAULT_MODE - Requires also
  786. * DRM_XE_VM_CREATE_FLAG_LR_MODE. It allows memory to be allocated on
  787. * demand when accessed, and also allows per-VM overcommit of memory.
  788. * The xe driver internally uses recoverable pagefaults to implement
  789. * this.
  790. */
  791. struct drm_xe_vm_create {
  792. /** @extensions: Pointer to the first extension struct, if any */
  793. __u64 extensions;
  794. #define DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE (1 << 0)
  795. #define DRM_XE_VM_CREATE_FLAG_LR_MODE (1 << 1)
  796. #define DRM_XE_VM_CREATE_FLAG_FAULT_MODE (1 << 2)
  797. /** @flags: Flags */
  798. __u32 flags;
  799. /** @vm_id: Returned VM ID */
  800. __u32 vm_id;
  801. /** @reserved: Reserved */
  802. __u64 reserved[2];
  803. };
  804. /**
  805. * struct drm_xe_vm_destroy - Input of &DRM_IOCTL_XE_VM_DESTROY
  806. */
  807. struct drm_xe_vm_destroy {
  808. /** @vm_id: VM ID */
  809. __u32 vm_id;
  810. /** @pad: MBZ */
  811. __u32 pad;
  812. /** @reserved: Reserved */
  813. __u64 reserved[2];
  814. };
  815. /**
  816. * struct drm_xe_vm_bind_op - run bind operations
  817. *
  818. * The @op can be:
  819. * - %DRM_XE_VM_BIND_OP_MAP
  820. * - %DRM_XE_VM_BIND_OP_UNMAP
  821. * - %DRM_XE_VM_BIND_OP_MAP_USERPTR
  822. * - %DRM_XE_VM_BIND_OP_UNMAP_ALL
  823. * - %DRM_XE_VM_BIND_OP_PREFETCH
  824. *
  825. * and the @flags can be:
  826. * - %DRM_XE_VM_BIND_FLAG_READONLY - Setup the page tables as read-only
  827. * to ensure write protection
  828. * - %DRM_XE_VM_BIND_FLAG_IMMEDIATE - On a faulting VM, do the
  829. * MAP operation immediately rather than deferring the MAP to the page
  830. * fault handler. This is implied on a non-faulting VM as there is no
  831. * fault handler to defer to.
  832. * - %DRM_XE_VM_BIND_FLAG_NULL - When the NULL flag is set, the page
  833. * tables are setup with a special bit which indicates writes are
  834. * dropped and all reads return zero. In the future, the NULL flags
  835. * will only be valid for DRM_XE_VM_BIND_OP_MAP operations, the BO
  836. * handle MBZ, and the BO offset MBZ. This flag is intended to
  837. * implement VK sparse bindings.
  838. */
  839. struct drm_xe_vm_bind_op {
  840. /** @extensions: Pointer to the first extension struct, if any */
  841. __u64 extensions;
  842. /**
  843. * @obj: GEM object to operate on, MBZ for MAP_USERPTR, MBZ for UNMAP
  844. */
  845. __u32 obj;
  846. /**
  847. * @pat_index: The platform defined @pat_index to use for this mapping.
  848. * The index basically maps to some predefined memory attributes,
  849. * including things like caching, coherency, compression etc. The exact
  850. * meaning of the pat_index is platform specific and defined in the
  851. * Bspec and PRMs. When the KMD sets up the binding the index here is
  852. * encoded into the ppGTT PTE.
  853. *
  854. * For coherency the @pat_index needs to be at least 1way coherent when
  855. * drm_xe_gem_create.cpu_caching is DRM_XE_GEM_CPU_CACHING_WB. The KMD
  856. * will extract the coherency mode from the @pat_index and reject if
  857. * there is a mismatch (see note below for pre-MTL platforms).
  858. *
  859. * Note: On pre-MTL platforms there is only a caching mode and no
  860. * explicit coherency mode, but on such hardware there is always a
  861. * shared-LLC (or is dgpu) so all GT memory accesses are coherent with
  862. * CPU caches even with the caching mode set as uncached. It's only the
  863. * display engine that is incoherent (on dgpu it must be in VRAM which
  864. * is always mapped as WC on the CPU). However to keep the uapi somewhat
  865. * consistent with newer platforms the KMD groups the different cache
  866. * levels into the following coherency buckets on all pre-MTL platforms:
  867. *
  868. * ppGTT UC -> COH_NONE
  869. * ppGTT WC -> COH_NONE
  870. * ppGTT WT -> COH_NONE
  871. * ppGTT WB -> COH_AT_LEAST_1WAY
  872. *
  873. * In practice UC/WC/WT should only ever used for scanout surfaces on
  874. * such platforms (or perhaps in general for dma-buf if shared with
  875. * another device) since it is only the display engine that is actually
  876. * incoherent. Everything else should typically use WB given that we
  877. * have a shared-LLC. On MTL+ this completely changes and the HW
  878. * defines the coherency mode as part of the @pat_index, where
  879. * incoherent GT access is possible.
  880. *
  881. * Note: For userptr and externally imported dma-buf the kernel expects
  882. * either 1WAY or 2WAY for the @pat_index.
  883. *
  884. * For DRM_XE_VM_BIND_FLAG_NULL bindings there are no KMD restrictions
  885. * on the @pat_index. For such mappings there is no actual memory being
  886. * mapped (the address in the PTE is invalid), so the various PAT memory
  887. * attributes likely do not apply. Simply leaving as zero is one
  888. * option (still a valid pat_index).
  889. */
  890. __u16 pat_index;
  891. /** @pad: MBZ */
  892. __u16 pad;
  893. union {
  894. /**
  895. * @obj_offset: Offset into the object, MBZ for CLEAR_RANGE,
  896. * ignored for unbind
  897. */
  898. __u64 obj_offset;
  899. /** @userptr: user pointer to bind on */
  900. __u64 userptr;
  901. };
  902. /**
  903. * @range: Number of bytes from the object to bind to addr, MBZ for UNMAP_ALL
  904. */
  905. __u64 range;
  906. /** @addr: Address to operate on, MBZ for UNMAP_ALL */
  907. __u64 addr;
  908. #define DRM_XE_VM_BIND_OP_MAP 0x0
  909. #define DRM_XE_VM_BIND_OP_UNMAP 0x1
  910. #define DRM_XE_VM_BIND_OP_MAP_USERPTR 0x2
  911. #define DRM_XE_VM_BIND_OP_UNMAP_ALL 0x3
  912. #define DRM_XE_VM_BIND_OP_PREFETCH 0x4
  913. /** @op: Bind operation to perform */
  914. __u32 op;
  915. #define DRM_XE_VM_BIND_FLAG_READONLY (1 << 0)
  916. #define DRM_XE_VM_BIND_FLAG_IMMEDIATE (1 << 1)
  917. #define DRM_XE_VM_BIND_FLAG_NULL (1 << 2)
  918. #define DRM_XE_VM_BIND_FLAG_DUMPABLE (1 << 3)
  919. /** @flags: Bind flags */
  920. __u32 flags;
  921. /**
  922. * @prefetch_mem_region_instance: Memory region to prefetch VMA to.
  923. * It is a region instance, not a mask.
  924. * To be used only with %DRM_XE_VM_BIND_OP_PREFETCH operation.
  925. */
  926. __u32 prefetch_mem_region_instance;
  927. /** @pad2: MBZ */
  928. __u32 pad2;
  929. /** @reserved: Reserved */
  930. __u64 reserved[3];
  931. };
  932. /**
  933. * struct drm_xe_vm_bind - Input of &DRM_IOCTL_XE_VM_BIND
  934. *
  935. * Below is an example of a minimal use of @drm_xe_vm_bind to
  936. * asynchronously bind the buffer `data` at address `BIND_ADDRESS` to
  937. * illustrate `userptr`. It can be synchronized by using the example
  938. * provided for @drm_xe_sync.
  939. *
  940. * .. code-block:: C
  941. *
  942. * data = aligned_alloc(ALIGNMENT, BO_SIZE);
  943. * struct drm_xe_vm_bind bind = {
  944. * .vm_id = vm,
  945. * .num_binds = 1,
  946. * .bind.obj = 0,
  947. * .bind.obj_offset = to_user_pointer(data),
  948. * .bind.range = BO_SIZE,
  949. * .bind.addr = BIND_ADDRESS,
  950. * .bind.op = DRM_XE_VM_BIND_OP_MAP_USERPTR,
  951. * .bind.flags = 0,
  952. * .num_syncs = 1,
  953. * .syncs = &sync,
  954. * .exec_queue_id = 0,
  955. * };
  956. * ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind);
  957. *
  958. */
  959. struct drm_xe_vm_bind {
  960. /** @extensions: Pointer to the first extension struct, if any */
  961. __u64 extensions;
  962. /** @vm_id: The ID of the VM to bind to */
  963. __u32 vm_id;
  964. /**
  965. * @exec_queue_id: exec_queue_id, must be of class DRM_XE_ENGINE_CLASS_VM_BIND
  966. * and exec queue must have same vm_id. If zero, the default VM bind engine
  967. * is used.
  968. */
  969. __u32 exec_queue_id;
  970. /** @pad: MBZ */
  971. __u32 pad;
  972. /** @num_binds: number of binds in this IOCTL */
  973. __u32 num_binds;
  974. union {
  975. /** @bind: used if num_binds == 1 */
  976. struct drm_xe_vm_bind_op bind;
  977. /**
  978. * @vector_of_binds: userptr to array of struct
  979. * drm_xe_vm_bind_op if num_binds > 1
  980. */
  981. __u64 vector_of_binds;
  982. };
  983. /** @pad2: MBZ */
  984. __u32 pad2;
  985. /** @num_syncs: amount of syncs to wait on */
  986. __u32 num_syncs;
  987. /** @syncs: pointer to struct drm_xe_sync array */
  988. __u64 syncs;
  989. /** @reserved: Reserved */
  990. __u64 reserved[2];
  991. };
  992. /**
  993. * struct drm_xe_exec_queue_create - Input of &DRM_IOCTL_XE_EXEC_QUEUE_CREATE
  994. *
  995. * The example below shows how to use @drm_xe_exec_queue_create to create
  996. * a simple exec_queue (no parallel submission) of class
  997. * &DRM_XE_ENGINE_CLASS_RENDER.
  998. *
  999. * .. code-block:: C
  1000. *
  1001. * struct drm_xe_engine_class_instance instance = {
  1002. * .engine_class = DRM_XE_ENGINE_CLASS_RENDER,
  1003. * };
  1004. * struct drm_xe_exec_queue_create exec_queue_create = {
  1005. * .extensions = 0,
  1006. * .vm_id = vm,
  1007. * .num_bb_per_exec = 1,
  1008. * .num_eng_per_bb = 1,
  1009. * .instances = to_user_pointer(&instance),
  1010. * };
  1011. * ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create);
  1012. *
  1013. */
  1014. struct drm_xe_exec_queue_create {
  1015. #define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY 0
  1016. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 0
  1017. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 1
  1018. /** @extensions: Pointer to the first extension struct, if any */
  1019. __u64 extensions;
  1020. /** @width: submission width (number BB per exec) for this exec queue */
  1021. __u16 width;
  1022. /** @num_placements: number of valid placements for this exec queue */
  1023. __u16 num_placements;
  1024. /** @vm_id: VM to use for this exec queue */
  1025. __u32 vm_id;
  1026. /** @flags: MBZ */
  1027. __u32 flags;
  1028. /** @exec_queue_id: Returned exec queue ID */
  1029. __u32 exec_queue_id;
  1030. /**
  1031. * @instances: user pointer to a 2-d array of struct
  1032. * drm_xe_engine_class_instance
  1033. *
  1034. * length = width (i) * num_placements (j)
  1035. * index = j + i * width
  1036. */
  1037. __u64 instances;
  1038. /** @reserved: Reserved */
  1039. __u64 reserved[2];
  1040. };
  1041. /**
  1042. * struct drm_xe_exec_queue_destroy - Input of &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY
  1043. */
  1044. struct drm_xe_exec_queue_destroy {
  1045. /** @exec_queue_id: Exec queue ID */
  1046. __u32 exec_queue_id;
  1047. /** @pad: MBZ */
  1048. __u32 pad;
  1049. /** @reserved: Reserved */
  1050. __u64 reserved[2];
  1051. };
  1052. /**
  1053. * struct drm_xe_exec_queue_get_property - Input of &DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY
  1054. *
  1055. * The @property can be:
  1056. * - %DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN
  1057. */
  1058. struct drm_xe_exec_queue_get_property {
  1059. /** @extensions: Pointer to the first extension struct, if any */
  1060. __u64 extensions;
  1061. /** @exec_queue_id: Exec queue ID */
  1062. __u32 exec_queue_id;
  1063. #define DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN 0
  1064. /** @property: property to get */
  1065. __u32 property;
  1066. /** @value: property value */
  1067. __u64 value;
  1068. /** @reserved: Reserved */
  1069. __u64 reserved[2];
  1070. };
  1071. /**
  1072. * struct drm_xe_sync - sync object
  1073. *
  1074. * The @type can be:
  1075. * - %DRM_XE_SYNC_TYPE_SYNCOBJ
  1076. * - %DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ
  1077. * - %DRM_XE_SYNC_TYPE_USER_FENCE
  1078. *
  1079. * and the @flags can be:
  1080. * - %DRM_XE_SYNC_FLAG_SIGNAL
  1081. *
  1082. * A minimal use of @drm_xe_sync looks like this:
  1083. *
  1084. * .. code-block:: C
  1085. *
  1086. * struct drm_xe_sync sync = {
  1087. * .flags = DRM_XE_SYNC_FLAG_SIGNAL,
  1088. * .type = DRM_XE_SYNC_TYPE_SYNCOBJ,
  1089. * };
  1090. * struct drm_syncobj_create syncobj_create = { 0 };
  1091. * ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &syncobj_create);
  1092. * sync.handle = syncobj_create.handle;
  1093. * ...
  1094. * use of &sync in drm_xe_exec or drm_xe_vm_bind
  1095. * ...
  1096. * struct drm_syncobj_wait wait = {
  1097. * .handles = &sync.handle,
  1098. * .timeout_nsec = INT64_MAX,
  1099. * .count_handles = 1,
  1100. * .flags = 0,
  1101. * .first_signaled = 0,
  1102. * .pad = 0,
  1103. * };
  1104. * ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &wait);
  1105. */
  1106. struct drm_xe_sync {
  1107. /** @extensions: Pointer to the first extension struct, if any */
  1108. __u64 extensions;
  1109. #define DRM_XE_SYNC_TYPE_SYNCOBJ 0x0
  1110. #define DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ 0x1
  1111. #define DRM_XE_SYNC_TYPE_USER_FENCE 0x2
  1112. /** @type: Type of the this sync object */
  1113. __u32 type;
  1114. #define DRM_XE_SYNC_FLAG_SIGNAL (1 << 0)
  1115. /** @flags: Sync Flags */
  1116. __u32 flags;
  1117. union {
  1118. /** @handle: Handle for the object */
  1119. __u32 handle;
  1120. /**
  1121. * @addr: Address of user fence. When sync is passed in via exec
  1122. * IOCTL this is a GPU address in the VM. When sync passed in via
  1123. * VM bind IOCTL this is a user pointer. In either case, it is
  1124. * the users responsibility that this address is present and
  1125. * mapped when the user fence is signalled. Must be qword
  1126. * aligned.
  1127. */
  1128. __u64 addr;
  1129. };
  1130. /**
  1131. * @timeline_value: Input for the timeline sync object. Needs to be
  1132. * different than 0 when used with %DRM_XE_SYNC_FLAG_TIMELINE_SYNCOBJ.
  1133. */
  1134. __u64 timeline_value;
  1135. /** @reserved: Reserved */
  1136. __u64 reserved[2];
  1137. };
  1138. /**
  1139. * struct drm_xe_exec - Input of &DRM_IOCTL_XE_EXEC
  1140. *
  1141. * This is an example to use @drm_xe_exec for execution of the object
  1142. * at BIND_ADDRESS (see example in @drm_xe_vm_bind) by an exec_queue
  1143. * (see example in @drm_xe_exec_queue_create). It can be synchronized
  1144. * by using the example provided for @drm_xe_sync.
  1145. *
  1146. * .. code-block:: C
  1147. *
  1148. * struct drm_xe_exec exec = {
  1149. * .exec_queue_id = exec_queue,
  1150. * .syncs = &sync,
  1151. * .num_syncs = 1,
  1152. * .address = BIND_ADDRESS,
  1153. * .num_batch_buffer = 1,
  1154. * };
  1155. * ioctl(fd, DRM_IOCTL_XE_EXEC, &exec);
  1156. *
  1157. */
  1158. struct drm_xe_exec {
  1159. /** @extensions: Pointer to the first extension struct, if any */
  1160. __u64 extensions;
  1161. /** @exec_queue_id: Exec queue ID for the batch buffer */
  1162. __u32 exec_queue_id;
  1163. /** @num_syncs: Amount of struct drm_xe_sync in array. */
  1164. __u32 num_syncs;
  1165. /** @syncs: Pointer to struct drm_xe_sync array. */
  1166. __u64 syncs;
  1167. /**
  1168. * @address: address of batch buffer if num_batch_buffer == 1 or an
  1169. * array of batch buffer addresses
  1170. */
  1171. __u64 address;
  1172. /**
  1173. * @num_batch_buffer: number of batch buffer in this exec, must match
  1174. * the width of the engine
  1175. */
  1176. __u16 num_batch_buffer;
  1177. /** @pad: MBZ */
  1178. __u16 pad[3];
  1179. /** @reserved: Reserved */
  1180. __u64 reserved[2];
  1181. };
  1182. /**
  1183. * struct drm_xe_wait_user_fence - Input of &DRM_IOCTL_XE_WAIT_USER_FENCE
  1184. *
  1185. * Wait on user fence, XE will wake-up on every HW engine interrupt in the
  1186. * instances list and check if user fence is complete::
  1187. *
  1188. * (*addr & MASK) OP (VALUE & MASK)
  1189. *
  1190. * Returns to user on user fence completion or timeout.
  1191. *
  1192. * The @op can be:
  1193. * - %DRM_XE_UFENCE_WAIT_OP_EQ
  1194. * - %DRM_XE_UFENCE_WAIT_OP_NEQ
  1195. * - %DRM_XE_UFENCE_WAIT_OP_GT
  1196. * - %DRM_XE_UFENCE_WAIT_OP_GTE
  1197. * - %DRM_XE_UFENCE_WAIT_OP_LT
  1198. * - %DRM_XE_UFENCE_WAIT_OP_LTE
  1199. *
  1200. * and the @flags can be:
  1201. * - %DRM_XE_UFENCE_WAIT_FLAG_ABSTIME
  1202. * - %DRM_XE_UFENCE_WAIT_FLAG_SOFT_OP
  1203. *
  1204. * The @mask values can be for example:
  1205. * - 0xffu for u8
  1206. * - 0xffffu for u16
  1207. * - 0xffffffffu for u32
  1208. * - 0xffffffffffffffffu for u64
  1209. */
  1210. struct drm_xe_wait_user_fence {
  1211. /** @extensions: Pointer to the first extension struct, if any */
  1212. __u64 extensions;
  1213. /**
  1214. * @addr: user pointer address to wait on, must qword aligned
  1215. */
  1216. __u64 addr;
  1217. #define DRM_XE_UFENCE_WAIT_OP_EQ 0x0
  1218. #define DRM_XE_UFENCE_WAIT_OP_NEQ 0x1
  1219. #define DRM_XE_UFENCE_WAIT_OP_GT 0x2
  1220. #define DRM_XE_UFENCE_WAIT_OP_GTE 0x3
  1221. #define DRM_XE_UFENCE_WAIT_OP_LT 0x4
  1222. #define DRM_XE_UFENCE_WAIT_OP_LTE 0x5
  1223. /** @op: wait operation (type of comparison) */
  1224. __u16 op;
  1225. #define DRM_XE_UFENCE_WAIT_FLAG_ABSTIME (1 << 0)
  1226. /** @flags: wait flags */
  1227. __u16 flags;
  1228. /** @pad: MBZ */
  1229. __u32 pad;
  1230. /** @value: compare value */
  1231. __u64 value;
  1232. /** @mask: comparison mask */
  1233. __u64 mask;
  1234. /**
  1235. * @timeout: how long to wait before bailing, value in nanoseconds.
  1236. * Without DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flag set (relative timeout)
  1237. * it contains timeout expressed in nanoseconds to wait (fence will
  1238. * expire at now() + timeout).
  1239. * When DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flat is set (absolute timeout) wait
  1240. * will end at timeout (uses system MONOTONIC_CLOCK).
  1241. * Passing negative timeout leads to neverending wait.
  1242. *
  1243. * On relative timeout this value is updated with timeout left
  1244. * (for restarting the call in case of signal delivery).
  1245. * On absolute timeout this value stays intact (restarted call still
  1246. * expire at the same point of time).
  1247. */
  1248. __s64 timeout;
  1249. /** @exec_queue_id: exec_queue_id returned from xe_exec_queue_create_ioctl */
  1250. __u32 exec_queue_id;
  1251. /** @pad2: MBZ */
  1252. __u32 pad2;
  1253. /** @reserved: Reserved */
  1254. __u64 reserved[2];
  1255. };
  1256. /**
  1257. * enum drm_xe_observation_type - Observation stream types
  1258. */
  1259. enum drm_xe_observation_type {
  1260. /** @DRM_XE_OBSERVATION_TYPE_OA: OA observation stream type */
  1261. DRM_XE_OBSERVATION_TYPE_OA,
  1262. };
  1263. /**
  1264. * enum drm_xe_observation_op - Observation stream ops
  1265. */
  1266. enum drm_xe_observation_op {
  1267. /** @DRM_XE_OBSERVATION_OP_STREAM_OPEN: Open an observation stream */
  1268. DRM_XE_OBSERVATION_OP_STREAM_OPEN,
  1269. /** @DRM_XE_OBSERVATION_OP_ADD_CONFIG: Add observation stream config */
  1270. DRM_XE_OBSERVATION_OP_ADD_CONFIG,
  1271. /** @DRM_XE_OBSERVATION_OP_REMOVE_CONFIG: Remove observation stream config */
  1272. DRM_XE_OBSERVATION_OP_REMOVE_CONFIG,
  1273. };
  1274. /**
  1275. * struct drm_xe_observation_param - Input of &DRM_XE_OBSERVATION
  1276. *
  1277. * The observation layer enables multiplexing observation streams of
  1278. * multiple types. The actual params for a particular stream operation are
  1279. * supplied via the @param pointer (use __copy_from_user to get these
  1280. * params).
  1281. */
  1282. struct drm_xe_observation_param {
  1283. /** @extensions: Pointer to the first extension struct, if any */
  1284. __u64 extensions;
  1285. /** @observation_type: observation stream type, of enum @drm_xe_observation_type */
  1286. __u64 observation_type;
  1287. /** @observation_op: observation stream op, of enum @drm_xe_observation_op */
  1288. __u64 observation_op;
  1289. /** @param: Pointer to actual stream params */
  1290. __u64 param;
  1291. };
  1292. /**
  1293. * enum drm_xe_observation_ioctls - Observation stream fd ioctl's
  1294. *
  1295. * Information exchanged between userspace and kernel for observation fd
  1296. * ioctl's is stream type specific
  1297. */
  1298. enum drm_xe_observation_ioctls {
  1299. /** @DRM_XE_OBSERVATION_IOCTL_ENABLE: Enable data capture for an observation stream */
  1300. DRM_XE_OBSERVATION_IOCTL_ENABLE = _IO('i', 0x0),
  1301. /** @DRM_XE_OBSERVATION_IOCTL_DISABLE: Disable data capture for a observation stream */
  1302. DRM_XE_OBSERVATION_IOCTL_DISABLE = _IO('i', 0x1),
  1303. /** @DRM_XE_OBSERVATION_IOCTL_CONFIG: Change observation stream configuration */
  1304. DRM_XE_OBSERVATION_IOCTL_CONFIG = _IO('i', 0x2),
  1305. /** @DRM_XE_OBSERVATION_IOCTL_STATUS: Return observation stream status */
  1306. DRM_XE_OBSERVATION_IOCTL_STATUS = _IO('i', 0x3),
  1307. /** @DRM_XE_OBSERVATION_IOCTL_INFO: Return observation stream info */
  1308. DRM_XE_OBSERVATION_IOCTL_INFO = _IO('i', 0x4),
  1309. };
  1310. /**
  1311. * enum drm_xe_oa_unit_type - OA unit types
  1312. */
  1313. enum drm_xe_oa_unit_type {
  1314. /**
  1315. * @DRM_XE_OA_UNIT_TYPE_OAG: OAG OA unit. OAR/OAC are considered
  1316. * sub-types of OAG. For OAR/OAC, use OAG.
  1317. */
  1318. DRM_XE_OA_UNIT_TYPE_OAG,
  1319. /** @DRM_XE_OA_UNIT_TYPE_OAM: OAM OA unit */
  1320. DRM_XE_OA_UNIT_TYPE_OAM,
  1321. };
  1322. /**
  1323. * struct drm_xe_oa_unit - describe OA unit
  1324. */
  1325. struct drm_xe_oa_unit {
  1326. /** @extensions: Pointer to the first extension struct, if any */
  1327. __u64 extensions;
  1328. /** @oa_unit_id: OA unit ID */
  1329. __u32 oa_unit_id;
  1330. /** @oa_unit_type: OA unit type of @drm_xe_oa_unit_type */
  1331. __u32 oa_unit_type;
  1332. /** @capabilities: OA capabilities bit-mask */
  1333. __u64 capabilities;
  1334. #define DRM_XE_OA_CAPS_BASE (1 << 0)
  1335. #define DRM_XE_OA_CAPS_SYNCS (1 << 1)
  1336. /** @oa_timestamp_freq: OA timestamp freq */
  1337. __u64 oa_timestamp_freq;
  1338. /** @reserved: MBZ */
  1339. __u64 reserved[4];
  1340. /** @num_engines: number of engines in @eci array */
  1341. __u64 num_engines;
  1342. /** @eci: engines attached to this OA unit */
  1343. struct drm_xe_engine_class_instance eci[];
  1344. };
  1345. /**
  1346. * struct drm_xe_query_oa_units - describe OA units
  1347. *
  1348. * If a query is made with a struct drm_xe_device_query where .query
  1349. * is equal to DRM_XE_DEVICE_QUERY_OA_UNITS, then the reply uses struct
  1350. * drm_xe_query_oa_units in .data.
  1351. *
  1352. * OA unit properties for all OA units can be accessed using a code block
  1353. * such as the one below:
  1354. *
  1355. * .. code-block:: C
  1356. *
  1357. * struct drm_xe_query_oa_units *qoa;
  1358. * struct drm_xe_oa_unit *oau;
  1359. * u8 *poau;
  1360. *
  1361. * // malloc qoa and issue DRM_XE_DEVICE_QUERY_OA_UNITS. Then:
  1362. * poau = (u8 *)&qoa->oa_units[0];
  1363. * for (int i = 0; i < qoa->num_oa_units; i++) {
  1364. * oau = (struct drm_xe_oa_unit *)poau;
  1365. * // Access 'struct drm_xe_oa_unit' fields here
  1366. * poau += sizeof(*oau) + oau->num_engines * sizeof(oau->eci[0]);
  1367. * }
  1368. */
  1369. struct drm_xe_query_oa_units {
  1370. /** @extensions: Pointer to the first extension struct, if any */
  1371. __u64 extensions;
  1372. /** @num_oa_units: number of OA units returned in oau[] */
  1373. __u32 num_oa_units;
  1374. /** @pad: MBZ */
  1375. __u32 pad;
  1376. /**
  1377. * @oa_units: struct @drm_xe_oa_unit array returned for this device.
  1378. * Written below as a u64 array to avoid problems with nested flexible
  1379. * arrays with some compilers
  1380. */
  1381. __u64 oa_units[];
  1382. };
  1383. /**
  1384. * enum drm_xe_oa_format_type - OA format types as specified in PRM/Bspec
  1385. * 52198/60942
  1386. */
  1387. enum drm_xe_oa_format_type {
  1388. /** @DRM_XE_OA_FMT_TYPE_OAG: OAG report format */
  1389. DRM_XE_OA_FMT_TYPE_OAG,
  1390. /** @DRM_XE_OA_FMT_TYPE_OAR: OAR report format */
  1391. DRM_XE_OA_FMT_TYPE_OAR,
  1392. /** @DRM_XE_OA_FMT_TYPE_OAM: OAM report format */
  1393. DRM_XE_OA_FMT_TYPE_OAM,
  1394. /** @DRM_XE_OA_FMT_TYPE_OAC: OAC report format */
  1395. DRM_XE_OA_FMT_TYPE_OAC,
  1396. /** @DRM_XE_OA_FMT_TYPE_OAM_MPEC: OAM SAMEDIA or OAM MPEC report format */
  1397. DRM_XE_OA_FMT_TYPE_OAM_MPEC,
  1398. /** @DRM_XE_OA_FMT_TYPE_PEC: PEC report format */
  1399. DRM_XE_OA_FMT_TYPE_PEC,
  1400. };
  1401. /**
  1402. * enum drm_xe_oa_property_id - OA stream property id's
  1403. *
  1404. * Stream params are specified as a chain of @drm_xe_ext_set_property
  1405. * struct's, with @property values from enum @drm_xe_oa_property_id and
  1406. * @drm_xe_user_extension base.name set to @DRM_XE_OA_EXTENSION_SET_PROPERTY.
  1407. * @param field in struct @drm_xe_observation_param points to the first
  1408. * @drm_xe_ext_set_property struct.
  1409. *
  1410. * Exactly the same mechanism is also used for stream reconfiguration using the
  1411. * @DRM_XE_OBSERVATION_IOCTL_CONFIG observation stream fd ioctl, though only a
  1412. * subset of properties below can be specified for stream reconfiguration.
  1413. */
  1414. enum drm_xe_oa_property_id {
  1415. #define DRM_XE_OA_EXTENSION_SET_PROPERTY 0
  1416. /**
  1417. * @DRM_XE_OA_PROPERTY_OA_UNIT_ID: ID of the OA unit on which to open
  1418. * the OA stream, see @oa_unit_id in 'struct
  1419. * drm_xe_query_oa_units'. Defaults to 0 if not provided.
  1420. */
  1421. DRM_XE_OA_PROPERTY_OA_UNIT_ID = 1,
  1422. /**
  1423. * @DRM_XE_OA_PROPERTY_SAMPLE_OA: A value of 1 requests inclusion of raw
  1424. * OA unit reports or stream samples in a global buffer attached to an
  1425. * OA unit.
  1426. */
  1427. DRM_XE_OA_PROPERTY_SAMPLE_OA,
  1428. /**
  1429. * @DRM_XE_OA_PROPERTY_OA_METRIC_SET: OA metrics defining contents of OA
  1430. * reports, previously added via @DRM_XE_OBSERVATION_OP_ADD_CONFIG.
  1431. */
  1432. DRM_XE_OA_PROPERTY_OA_METRIC_SET,
  1433. /** @DRM_XE_OA_PROPERTY_OA_FORMAT: OA counter report format */
  1434. DRM_XE_OA_PROPERTY_OA_FORMAT,
  1435. /*
  1436. * OA_FORMAT's are specified the same way as in PRM/Bspec 52198/60942,
  1437. * in terms of the following quantities: a. enum @drm_xe_oa_format_type
  1438. * b. Counter select c. Counter size and d. BC report. Also refer to the
  1439. * oa_formats array in drivers/gpu/drm/xe/xe_oa.c.
  1440. */
  1441. #define DRM_XE_OA_FORMAT_MASK_FMT_TYPE (0xffu << 0)
  1442. #define DRM_XE_OA_FORMAT_MASK_COUNTER_SEL (0xffu << 8)
  1443. #define DRM_XE_OA_FORMAT_MASK_COUNTER_SIZE (0xffu << 16)
  1444. #define DRM_XE_OA_FORMAT_MASK_BC_REPORT (0xffu << 24)
  1445. /**
  1446. * @DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT: Requests periodic OA unit
  1447. * sampling with sampling frequency proportional to 2^(period_exponent + 1)
  1448. */
  1449. DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT,
  1450. /**
  1451. * @DRM_XE_OA_PROPERTY_OA_DISABLED: A value of 1 will open the OA
  1452. * stream in a DISABLED state (see @DRM_XE_OBSERVATION_IOCTL_ENABLE).
  1453. */
  1454. DRM_XE_OA_PROPERTY_OA_DISABLED,
  1455. /**
  1456. * @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID: Open the stream for a specific
  1457. * @exec_queue_id. OA queries can be executed on this exec queue.
  1458. */
  1459. DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID,
  1460. /**
  1461. * @DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE: Optional engine instance to
  1462. * pass along with @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID or will default to 0.
  1463. */
  1464. DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE,
  1465. /**
  1466. * @DRM_XE_OA_PROPERTY_NO_PREEMPT: Allow preemption and timeslicing
  1467. * to be disabled for the stream exec queue.
  1468. */
  1469. DRM_XE_OA_PROPERTY_NO_PREEMPT,
  1470. /**
  1471. * @DRM_XE_OA_PROPERTY_NUM_SYNCS: Number of syncs in the sync array
  1472. * specified in @DRM_XE_OA_PROPERTY_SYNCS
  1473. */
  1474. DRM_XE_OA_PROPERTY_NUM_SYNCS,
  1475. /**
  1476. * @DRM_XE_OA_PROPERTY_SYNCS: Pointer to struct @drm_xe_sync array
  1477. * with array size specified via @DRM_XE_OA_PROPERTY_NUM_SYNCS. OA
  1478. * configuration will wait till input fences signal. Output fences
  1479. * will signal after the new OA configuration takes effect. For
  1480. * @DRM_XE_SYNC_TYPE_USER_FENCE, @addr is a user pointer, similar
  1481. * to the VM bind case.
  1482. */
  1483. DRM_XE_OA_PROPERTY_SYNCS,
  1484. };
  1485. /**
  1486. * struct drm_xe_oa_config - OA metric configuration
  1487. *
  1488. * Multiple OA configs can be added using @DRM_XE_OBSERVATION_OP_ADD_CONFIG. A
  1489. * particular config can be specified when opening an OA stream using
  1490. * @DRM_XE_OA_PROPERTY_OA_METRIC_SET property.
  1491. */
  1492. struct drm_xe_oa_config {
  1493. /** @extensions: Pointer to the first extension struct, if any */
  1494. __u64 extensions;
  1495. /** @uuid: String formatted like "%\08x-%\04x-%\04x-%\04x-%\012x" */
  1496. char uuid[36];
  1497. /** @n_regs: Number of regs in @regs_ptr */
  1498. __u32 n_regs;
  1499. /**
  1500. * @regs_ptr: Pointer to (register address, value) pairs for OA config
  1501. * registers. Expected length of buffer is: (2 * sizeof(u32) * @n_regs).
  1502. */
  1503. __u64 regs_ptr;
  1504. };
  1505. /**
  1506. * struct drm_xe_oa_stream_status - OA stream status returned from
  1507. * @DRM_XE_OBSERVATION_IOCTL_STATUS observation stream fd ioctl. Userspace can
  1508. * call the ioctl to query stream status in response to EIO errno from
  1509. * observation fd read().
  1510. */
  1511. struct drm_xe_oa_stream_status {
  1512. /** @extensions: Pointer to the first extension struct, if any */
  1513. __u64 extensions;
  1514. /** @oa_status: OA stream status (see Bspec 46717/61226) */
  1515. __u64 oa_status;
  1516. #define DRM_XE_OASTATUS_MMIO_TRG_Q_FULL (1 << 3)
  1517. #define DRM_XE_OASTATUS_COUNTER_OVERFLOW (1 << 2)
  1518. #define DRM_XE_OASTATUS_BUFFER_OVERFLOW (1 << 1)
  1519. #define DRM_XE_OASTATUS_REPORT_LOST (1 << 0)
  1520. /** @reserved: reserved for future use */
  1521. __u64 reserved[3];
  1522. };
  1523. /**
  1524. * struct drm_xe_oa_stream_info - OA stream info returned from
  1525. * @DRM_XE_OBSERVATION_IOCTL_INFO observation stream fd ioctl
  1526. */
  1527. struct drm_xe_oa_stream_info {
  1528. /** @extensions: Pointer to the first extension struct, if any */
  1529. __u64 extensions;
  1530. /** @oa_buf_size: OA buffer size */
  1531. __u64 oa_buf_size;
  1532. /** @reserved: reserved for future use */
  1533. __u64 reserved[3];
  1534. };
  1535. #if defined(__cplusplus)
  1536. }
  1537. #endif
  1538. #endif /* _UAPI_XE_DRM_H_ */