xe_drm.h 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2023 Intel Corporation
  4. */
  5. #ifndef _XE_DRM_H_
  6. #define _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. * - &DRM_IOCTL_XE_MADVISE
  79. * - &DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS
  80. */
  81. /*
  82. * xe specific ioctls.
  83. *
  84. * The device specific ioctl range is [DRM_COMMAND_BASE, DRM_COMMAND_END) ie
  85. * [0x40, 0xa0) (a0 is excluded). The numbers below are defined as offset
  86. * against DRM_COMMAND_BASE and should be between [0x0, 0x60).
  87. */
  88. #define DRM_XE_DEVICE_QUERY 0x00
  89. #define DRM_XE_GEM_CREATE 0x01
  90. #define DRM_XE_GEM_MMAP_OFFSET 0x02
  91. #define DRM_XE_VM_CREATE 0x03
  92. #define DRM_XE_VM_DESTROY 0x04
  93. #define DRM_XE_VM_BIND 0x05
  94. #define DRM_XE_EXEC_QUEUE_CREATE 0x06
  95. #define DRM_XE_EXEC_QUEUE_DESTROY 0x07
  96. #define DRM_XE_EXEC_QUEUE_GET_PROPERTY 0x08
  97. #define DRM_XE_EXEC 0x09
  98. #define DRM_XE_WAIT_USER_FENCE 0x0a
  99. #define DRM_XE_OBSERVATION 0x0b
  100. #define DRM_XE_MADVISE 0x0c
  101. #define DRM_XE_VM_QUERY_MEM_RANGE_ATTRS 0x0d
  102. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY 0x0e
  103. /* Must be kept compact -- no holes */
  104. #define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query)
  105. #define DRM_IOCTL_XE_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_CREATE, struct drm_xe_gem_create)
  106. #define DRM_IOCTL_XE_GEM_MMAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_MMAP_OFFSET, struct drm_xe_gem_mmap_offset)
  107. #define DRM_IOCTL_XE_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_CREATE, struct drm_xe_vm_create)
  108. #define DRM_IOCTL_XE_VM_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_DESTROY, struct drm_xe_vm_destroy)
  109. #define DRM_IOCTL_XE_VM_BIND DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_BIND, struct drm_xe_vm_bind)
  110. #define DRM_IOCTL_XE_EXEC_QUEUE_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_CREATE, struct drm_xe_exec_queue_create)
  111. #define DRM_IOCTL_XE_EXEC_QUEUE_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_DESTROY, struct drm_xe_exec_queue_destroy)
  112. #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)
  113. #define DRM_IOCTL_XE_EXEC DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec)
  114. #define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)
  115. #define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param)
  116. #define DRM_IOCTL_XE_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_MADVISE, struct drm_xe_madvise)
  117. #define DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_QUERY_MEM_RANGE_ATTRS, struct drm_xe_vm_query_mem_range_attr)
  118. #define DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property)
  119. /**
  120. * DOC: Xe IOCTL Extensions
  121. *
  122. * Before detailing the IOCTLs and its structs, it is important to highlight
  123. * that every IOCTL in Xe is extensible.
  124. *
  125. * Many interfaces need to grow over time. In most cases we can simply
  126. * extend the struct and have userspace pass in more data. Another option,
  127. * as demonstrated by Vulkan's approach to providing extensions for forward
  128. * and backward compatibility, is to use a list of optional structs to
  129. * provide those extra details.
  130. *
  131. * The key advantage to using an extension chain is that it allows us to
  132. * redefine the interface more easily than an ever growing struct of
  133. * increasing complexity, and for large parts of that interface to be
  134. * entirely optional. The downside is more pointer chasing; chasing across
  135. * the boundary with pointers encapsulated inside u64.
  136. *
  137. * Example chaining:
  138. *
  139. * .. code-block:: C
  140. *
  141. * struct drm_xe_user_extension ext3 {
  142. * .next_extension = 0, // end
  143. * .name = ...,
  144. * };
  145. * struct drm_xe_user_extension ext2 {
  146. * .next_extension = (uintptr_t)&ext3,
  147. * .name = ...,
  148. * };
  149. * struct drm_xe_user_extension ext1 {
  150. * .next_extension = (uintptr_t)&ext2,
  151. * .name = ...,
  152. * };
  153. *
  154. * Typically the struct drm_xe_user_extension would be embedded in some uAPI
  155. * struct, and in this case we would feed it the head of the chain(i.e ext1),
  156. * which would then apply all of the above extensions.
  157. */
  158. /**
  159. * struct drm_xe_user_extension - Base class for defining a chain of extensions
  160. */
  161. struct drm_xe_user_extension {
  162. /**
  163. * @next_extension:
  164. *
  165. * Pointer to the next struct drm_xe_user_extension, or zero if the end.
  166. */
  167. __u64 next_extension;
  168. /**
  169. * @name: Name of the extension.
  170. *
  171. * Note that the name here is just some integer.
  172. *
  173. * Also note that the name space for this is not global for the whole
  174. * driver, but rather its scope/meaning is limited to the specific piece
  175. * of uAPI which has embedded the struct drm_xe_user_extension.
  176. */
  177. __u32 name;
  178. /**
  179. * @pad: MBZ
  180. *
  181. * All undefined bits must be zero.
  182. */
  183. __u32 pad;
  184. };
  185. /**
  186. * struct drm_xe_ext_set_property - Generic set property extension
  187. *
  188. * A generic struct that allows any of the Xe's IOCTL to be extended
  189. * with a set_property operation.
  190. */
  191. struct drm_xe_ext_set_property {
  192. /** @base: base user extension */
  193. struct drm_xe_user_extension base;
  194. /** @property: property to set */
  195. __u32 property;
  196. /** @pad: MBZ */
  197. __u32 pad;
  198. union {
  199. /** @value: property value */
  200. __u64 value;
  201. /** @ptr: pointer to user value */
  202. __u64 ptr;
  203. };
  204. /** @reserved: Reserved */
  205. __u64 reserved[2];
  206. };
  207. /**
  208. * struct drm_xe_engine_class_instance - instance of an engine class
  209. *
  210. * It is returned as part of the @drm_xe_engine, but it also is used as
  211. * the input of engine selection for both @drm_xe_exec_queue_create and
  212. * @drm_xe_query_engine_cycles
  213. *
  214. * The @engine_class can be:
  215. * - %DRM_XE_ENGINE_CLASS_RENDER
  216. * - %DRM_XE_ENGINE_CLASS_COPY
  217. * - %DRM_XE_ENGINE_CLASS_VIDEO_DECODE
  218. * - %DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE
  219. * - %DRM_XE_ENGINE_CLASS_COMPUTE
  220. * - %DRM_XE_ENGINE_CLASS_VM_BIND - Kernel only classes (not actual
  221. * hardware engine class). Used for creating ordered queues of VM
  222. * bind operations.
  223. */
  224. struct drm_xe_engine_class_instance {
  225. #define DRM_XE_ENGINE_CLASS_RENDER 0
  226. #define DRM_XE_ENGINE_CLASS_COPY 1
  227. #define DRM_XE_ENGINE_CLASS_VIDEO_DECODE 2
  228. #define DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE 3
  229. #define DRM_XE_ENGINE_CLASS_COMPUTE 4
  230. #define DRM_XE_ENGINE_CLASS_VM_BIND 5
  231. /** @engine_class: engine class id */
  232. __u16 engine_class;
  233. /** @engine_instance: engine instance id */
  234. __u16 engine_instance;
  235. /** @gt_id: Unique ID of this GT within the PCI Device */
  236. __u16 gt_id;
  237. /** @pad: MBZ */
  238. __u16 pad;
  239. };
  240. /**
  241. * struct drm_xe_engine - describe hardware engine
  242. */
  243. struct drm_xe_engine {
  244. /** @instance: The @drm_xe_engine_class_instance */
  245. struct drm_xe_engine_class_instance instance;
  246. /** @reserved: Reserved */
  247. __u64 reserved[3];
  248. };
  249. /**
  250. * struct drm_xe_query_engines - describe engines
  251. *
  252. * If a query is made with a struct @drm_xe_device_query where .query
  253. * is equal to %DRM_XE_DEVICE_QUERY_ENGINES, then the reply uses an array of
  254. * struct @drm_xe_query_engines in .data.
  255. */
  256. struct drm_xe_query_engines {
  257. /** @num_engines: number of engines returned in @engines */
  258. __u32 num_engines;
  259. /** @pad: MBZ */
  260. __u32 pad;
  261. /** @engines: The returned engines for this device */
  262. struct drm_xe_engine engines[];
  263. };
  264. /**
  265. * enum drm_xe_memory_class - Supported memory classes.
  266. */
  267. enum drm_xe_memory_class {
  268. /** @DRM_XE_MEM_REGION_CLASS_SYSMEM: Represents system memory. */
  269. DRM_XE_MEM_REGION_CLASS_SYSMEM = 0,
  270. /**
  271. * @DRM_XE_MEM_REGION_CLASS_VRAM: On discrete platforms, this
  272. * represents the memory that is local to the device, which we
  273. * call VRAM. Not valid on integrated platforms.
  274. */
  275. DRM_XE_MEM_REGION_CLASS_VRAM
  276. };
  277. /**
  278. * struct drm_xe_mem_region - Describes some region as known to
  279. * the driver.
  280. */
  281. struct drm_xe_mem_region {
  282. /**
  283. * @mem_class: The memory class describing this region.
  284. *
  285. * See enum drm_xe_memory_class for supported values.
  286. */
  287. __u16 mem_class;
  288. /**
  289. * @instance: The unique ID for this region, which serves as the
  290. * index in the placement bitmask used as argument for
  291. * &DRM_IOCTL_XE_GEM_CREATE
  292. */
  293. __u16 instance;
  294. /**
  295. * @min_page_size: Min page-size in bytes for this region.
  296. *
  297. * When the kernel allocates memory for this region, the
  298. * underlying pages will be at least @min_page_size in size.
  299. * Buffer objects with an allowable placement in this region must be
  300. * created with a size aligned to this value.
  301. * GPU virtual address mappings of (parts of) buffer objects that
  302. * may be placed in this region must also have their GPU virtual
  303. * address and range aligned to this value.
  304. * Affected IOCTLS will return %-EINVAL if alignment restrictions are
  305. * not met.
  306. */
  307. __u32 min_page_size;
  308. /**
  309. * @total_size: The usable size in bytes for this region.
  310. */
  311. __u64 total_size;
  312. /**
  313. * @used: Estimate of the memory used in bytes for this region.
  314. *
  315. * Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable
  316. * accounting. Without this the value here will always equal
  317. * zero.
  318. */
  319. __u64 used;
  320. /**
  321. * @cpu_visible_size: How much of this region can be CPU
  322. * accessed, in bytes.
  323. *
  324. * This will always be <= @total_size, and the remainder (if
  325. * any) will not be CPU accessible. If the CPU accessible part
  326. * is smaller than @total_size then this is referred to as a
  327. * small BAR system.
  328. *
  329. * On systems without small BAR (full BAR), the probed_size will
  330. * always equal the @total_size, since all of it will be CPU
  331. * accessible.
  332. *
  333. * Note this is only tracked for DRM_XE_MEM_REGION_CLASS_VRAM
  334. * regions (for other types the value here will always equal
  335. * zero).
  336. */
  337. __u64 cpu_visible_size;
  338. /**
  339. * @cpu_visible_used: Estimate of CPU visible memory used, in
  340. * bytes.
  341. *
  342. * Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable
  343. * accounting. Without this the value here will always equal
  344. * zero. Note this is only currently tracked for
  345. * DRM_XE_MEM_REGION_CLASS_VRAM regions (for other types the value
  346. * here will always be zero).
  347. */
  348. __u64 cpu_visible_used;
  349. /** @reserved: Reserved */
  350. __u64 reserved[6];
  351. };
  352. /**
  353. * struct drm_xe_query_mem_regions - describe memory regions
  354. *
  355. * If a query is made with a struct drm_xe_device_query where .query
  356. * is equal to DRM_XE_DEVICE_QUERY_MEM_REGIONS, then the reply uses
  357. * struct drm_xe_query_mem_regions in .data.
  358. */
  359. struct drm_xe_query_mem_regions {
  360. /** @num_mem_regions: number of memory regions returned in @mem_regions */
  361. __u32 num_mem_regions;
  362. /** @pad: MBZ */
  363. __u32 pad;
  364. /** @mem_regions: The returned memory regions for this device */
  365. struct drm_xe_mem_region mem_regions[];
  366. };
  367. /**
  368. * struct drm_xe_query_config - describe the device configuration
  369. *
  370. * If a query is made with a struct drm_xe_device_query where .query
  371. * is equal to DRM_XE_DEVICE_QUERY_CONFIG, then the reply uses
  372. * struct drm_xe_query_config in .data.
  373. *
  374. * The index in @info can be:
  375. * - %DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID - Device ID (lower 16 bits)
  376. * and the device revision (next 8 bits)
  377. * - %DRM_XE_QUERY_CONFIG_FLAGS - Flags describing the device
  378. * configuration, see list below
  379. *
  380. * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM - Flag is set if the device
  381. * has usable VRAM
  382. * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY - Flag is set if the device
  383. * has low latency hint support
  384. * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR - Flag is set if the
  385. * device has CPU address mirroring support
  386. * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_NO_COMPRESSION_HINT - Flag is set if the
  387. * device supports the userspace hint %DRM_XE_GEM_CREATE_FLAG_NO_COMPRESSION.
  388. * This is exposed only on Xe2+.
  389. * - %DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT - Minimal memory alignment
  390. * required by this device, typically SZ_4K or SZ_64K
  391. * - %DRM_XE_QUERY_CONFIG_VA_BITS - Maximum bits of a virtual address
  392. * - %DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY - Value of the highest
  393. * available exec queue priority
  394. */
  395. struct drm_xe_query_config {
  396. /** @num_params: number of parameters returned in info */
  397. __u32 num_params;
  398. /** @pad: MBZ */
  399. __u32 pad;
  400. #define DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID 0
  401. #define DRM_XE_QUERY_CONFIG_FLAGS 1
  402. #define DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM (1 << 0)
  403. #define DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY (1 << 1)
  404. #define DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR (1 << 2)
  405. #define DRM_XE_QUERY_CONFIG_FLAG_HAS_NO_COMPRESSION_HINT (1 << 3)
  406. #define DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT 2
  407. #define DRM_XE_QUERY_CONFIG_VA_BITS 3
  408. #define DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY 4
  409. /** @info: array of elements containing the config info */
  410. __u64 info[];
  411. };
  412. /**
  413. * struct drm_xe_gt - describe an individual GT.
  414. *
  415. * To be used with drm_xe_query_gt_list, which will return a list with all the
  416. * existing GT individual descriptions.
  417. * Graphics Technology (GT) is a subset of a GPU/tile that is responsible for
  418. * implementing graphics and/or media operations.
  419. *
  420. * The index in @type can be:
  421. * - %DRM_XE_QUERY_GT_TYPE_MAIN
  422. * - %DRM_XE_QUERY_GT_TYPE_MEDIA
  423. */
  424. struct drm_xe_gt {
  425. #define DRM_XE_QUERY_GT_TYPE_MAIN 0
  426. #define DRM_XE_QUERY_GT_TYPE_MEDIA 1
  427. /** @type: GT type: Main or Media */
  428. __u16 type;
  429. /** @tile_id: Tile ID where this GT lives (Information only) */
  430. __u16 tile_id;
  431. /** @gt_id: Unique ID of this GT within the PCI Device */
  432. __u16 gt_id;
  433. /** @pad: MBZ */
  434. __u16 pad[3];
  435. /** @reference_clock: A clock frequency for timestamp */
  436. __u32 reference_clock;
  437. /**
  438. * @near_mem_regions: Bit mask of instances from
  439. * drm_xe_query_mem_regions that are nearest to the current engines
  440. * of this GT.
  441. * Each index in this mask refers directly to the struct
  442. * drm_xe_query_mem_regions' instance, no assumptions should
  443. * be made about order. The type of each region is described
  444. * by struct drm_xe_query_mem_regions' mem_class.
  445. */
  446. __u64 near_mem_regions;
  447. /**
  448. * @far_mem_regions: Bit mask of instances from
  449. * drm_xe_query_mem_regions that are far from the engines of this GT.
  450. * In general, they have extra indirections when compared to the
  451. * @near_mem_regions. For a discrete device this could mean system
  452. * memory and memory living in a different tile.
  453. * Each index in this mask refers directly to the struct
  454. * drm_xe_query_mem_regions' instance, no assumptions should
  455. * be made about order. The type of each region is described
  456. * by struct drm_xe_query_mem_regions' mem_class.
  457. */
  458. __u64 far_mem_regions;
  459. /** @ip_ver_major: Graphics/media IP major version on GMD_ID platforms */
  460. __u16 ip_ver_major;
  461. /** @ip_ver_minor: Graphics/media IP minor version on GMD_ID platforms */
  462. __u16 ip_ver_minor;
  463. /** @ip_ver_rev: Graphics/media IP revision version on GMD_ID platforms */
  464. __u16 ip_ver_rev;
  465. /** @pad2: MBZ */
  466. __u16 pad2;
  467. /** @reserved: Reserved */
  468. __u64 reserved[7];
  469. };
  470. /**
  471. * struct drm_xe_query_gt_list - A list with GT description items.
  472. *
  473. * If a query is made with a struct drm_xe_device_query where .query
  474. * is equal to DRM_XE_DEVICE_QUERY_GT_LIST, then the reply uses struct
  475. * drm_xe_query_gt_list in .data.
  476. */
  477. struct drm_xe_query_gt_list {
  478. /** @num_gt: number of GT items returned in gt_list */
  479. __u32 num_gt;
  480. /** @pad: MBZ */
  481. __u32 pad;
  482. /** @gt_list: The GT list returned for this device */
  483. struct drm_xe_gt gt_list[];
  484. };
  485. /**
  486. * struct drm_xe_query_topology_mask - describe the topology mask of a GT
  487. *
  488. * This is the hardware topology which reflects the internal physical
  489. * structure of the GPU.
  490. *
  491. * If a query is made with a struct drm_xe_device_query where .query
  492. * is equal to DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, then the reply uses
  493. * struct drm_xe_query_topology_mask in .data.
  494. *
  495. * The @type can be:
  496. * - %DRM_XE_TOPO_DSS_GEOMETRY - To query the mask of Dual Sub Slices
  497. * (DSS) available for geometry operations. For example a query response
  498. * containing the following in mask:
  499. * ``DSS_GEOMETRY ff ff ff ff 00 00 00 00``
  500. * means 32 DSS are available for geometry.
  501. * - %DRM_XE_TOPO_DSS_COMPUTE - To query the mask of Dual Sub Slices
  502. * (DSS) available for compute operations. For example a query response
  503. * containing the following in mask:
  504. * ``DSS_COMPUTE ff ff ff ff 00 00 00 00``
  505. * means 32 DSS are available for compute.
  506. * - %DRM_XE_TOPO_L3_BANK - To query the mask of enabled L3 banks. This type
  507. * may be omitted if the driver is unable to query the mask from the
  508. * hardware.
  509. * - %DRM_XE_TOPO_EU_PER_DSS - To query the mask of Execution Units (EU)
  510. * available per Dual Sub Slices (DSS). For example a query response
  511. * containing the following in mask:
  512. * ``EU_PER_DSS ff ff 00 00 00 00 00 00``
  513. * means each DSS has 16 SIMD8 EUs. This type may be omitted if device
  514. * doesn't have SIMD8 EUs.
  515. * - %DRM_XE_TOPO_SIMD16_EU_PER_DSS - To query the mask of SIMD16 Execution
  516. * Units (EU) available per Dual Sub Slices (DSS). For example a query
  517. * response containing the following in mask:
  518. * ``SIMD16_EU_PER_DSS ff ff 00 00 00 00 00 00``
  519. * means each DSS has 16 SIMD16 EUs. This type may be omitted if device
  520. * doesn't have SIMD16 EUs.
  521. */
  522. struct drm_xe_query_topology_mask {
  523. /** @gt_id: GT ID the mask is associated with */
  524. __u16 gt_id;
  525. #define DRM_XE_TOPO_DSS_GEOMETRY 1
  526. #define DRM_XE_TOPO_DSS_COMPUTE 2
  527. #define DRM_XE_TOPO_L3_BANK 3
  528. #define DRM_XE_TOPO_EU_PER_DSS 4
  529. #define DRM_XE_TOPO_SIMD16_EU_PER_DSS 5
  530. /** @type: type of mask */
  531. __u16 type;
  532. /** @num_bytes: number of bytes in requested mask */
  533. __u32 num_bytes;
  534. /** @mask: little-endian mask of @num_bytes */
  535. __u8 mask[];
  536. };
  537. /**
  538. * struct drm_xe_query_engine_cycles - correlate CPU and GPU timestamps
  539. *
  540. * If a query is made with a struct drm_xe_device_query where .query is equal to
  541. * DRM_XE_DEVICE_QUERY_ENGINE_CYCLES, then the reply uses struct drm_xe_query_engine_cycles
  542. * in .data. struct drm_xe_query_engine_cycles is allocated by the user and
  543. * .data points to this allocated structure.
  544. *
  545. * The query returns the engine cycles, which along with GT's @reference_clock,
  546. * can be used to calculate the engine timestamp. In addition the
  547. * query returns a set of cpu timestamps that indicate when the command
  548. * streamer cycle count was captured.
  549. */
  550. struct drm_xe_query_engine_cycles {
  551. /**
  552. * @eci: This is input by the user and is the engine for which command
  553. * streamer cycles is queried.
  554. */
  555. struct drm_xe_engine_class_instance eci;
  556. /**
  557. * @clockid: This is input by the user and is the reference clock id for
  558. * CPU timestamp. For definition, see clock_gettime(2) and
  559. * perf_event_open(2). Supported clock ids are CLOCK_MONOTONIC,
  560. * CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_BOOTTIME, CLOCK_TAI.
  561. */
  562. __s32 clockid;
  563. /** @width: Width of the engine cycle counter in bits. */
  564. __u32 width;
  565. /**
  566. * @engine_cycles: Engine cycles as read from its register
  567. * at 0x358 offset.
  568. */
  569. __u64 engine_cycles;
  570. /**
  571. * @cpu_timestamp: CPU timestamp in ns. The timestamp is captured before
  572. * reading the engine_cycles register using the reference clockid set by the
  573. * user.
  574. */
  575. __u64 cpu_timestamp;
  576. /**
  577. * @cpu_delta: Time delta in ns captured around reading the lower dword
  578. * of the engine_cycles register.
  579. */
  580. __u64 cpu_delta;
  581. };
  582. /**
  583. * struct drm_xe_query_uc_fw_version - query a micro-controller firmware version
  584. *
  585. * Given a uc_type this will return the branch, major, minor and patch version
  586. * of the micro-controller firmware.
  587. */
  588. struct drm_xe_query_uc_fw_version {
  589. /** @uc_type: The micro-controller type to query firmware version */
  590. #define XE_QUERY_UC_TYPE_GUC_SUBMISSION 0
  591. #define XE_QUERY_UC_TYPE_HUC 1
  592. __u16 uc_type;
  593. /** @pad: MBZ */
  594. __u16 pad;
  595. /** @branch_ver: branch uc fw version */
  596. __u32 branch_ver;
  597. /** @major_ver: major uc fw version */
  598. __u32 major_ver;
  599. /** @minor_ver: minor uc fw version */
  600. __u32 minor_ver;
  601. /** @patch_ver: patch uc fw version */
  602. __u32 patch_ver;
  603. /** @pad2: MBZ */
  604. __u32 pad2;
  605. /** @reserved: Reserved */
  606. __u64 reserved;
  607. };
  608. /**
  609. * struct drm_xe_query_pxp_status - query if PXP is ready
  610. *
  611. * If PXP is enabled and no fatal error has occurred, the status will be set to
  612. * one of the following values:
  613. * 0: PXP init still in progress
  614. * 1: PXP init complete
  615. *
  616. * If PXP is not enabled or something has gone wrong, the query will be failed
  617. * with one of the following error codes:
  618. * -ENODEV: PXP not supported or disabled;
  619. * -EIO: fatal error occurred during init, so PXP will never be enabled;
  620. * -EINVAL: incorrect value provided as part of the query;
  621. * -EFAULT: error copying the memory between kernel and userspace.
  622. *
  623. * The status can only be 0 in the first few seconds after driver load. If
  624. * everything works as expected, the status will transition to init complete in
  625. * less than 1 second, while in case of errors the driver might take longer to
  626. * start returning an error code, but it should still take less than 10 seconds.
  627. *
  628. * The supported session type bitmask is based on the values in
  629. * enum drm_xe_pxp_session_type. TYPE_NONE is always supported and therefore
  630. * is not reported in the bitmask.
  631. *
  632. */
  633. struct drm_xe_query_pxp_status {
  634. /** @status: current PXP status */
  635. __u32 status;
  636. /** @supported_session_types: bitmask of supported PXP session types */
  637. __u32 supported_session_types;
  638. };
  639. /**
  640. * struct drm_xe_device_query - Input of &DRM_IOCTL_XE_DEVICE_QUERY - main
  641. * structure to query device information
  642. *
  643. * The user selects the type of data to query among DRM_XE_DEVICE_QUERY_*
  644. * and sets the value in the query member. This determines the type of
  645. * the structure provided by the driver in data, among struct drm_xe_query_*.
  646. *
  647. * The @query can be:
  648. * - %DRM_XE_DEVICE_QUERY_ENGINES
  649. * - %DRM_XE_DEVICE_QUERY_MEM_REGIONS
  650. * - %DRM_XE_DEVICE_QUERY_CONFIG
  651. * - %DRM_XE_DEVICE_QUERY_GT_LIST
  652. * - %DRM_XE_DEVICE_QUERY_HWCONFIG - Query type to retrieve the hardware
  653. * configuration of the device such as information on slices, memory,
  654. * caches, and so on. It is provided as a table of key / value
  655. * attributes.
  656. * - %DRM_XE_DEVICE_QUERY_GT_TOPOLOGY
  657. * - %DRM_XE_DEVICE_QUERY_ENGINE_CYCLES
  658. * - %DRM_XE_DEVICE_QUERY_PXP_STATUS
  659. *
  660. * If size is set to 0, the driver fills it with the required size for
  661. * the requested type of data to query. If size is equal to the required
  662. * size, the queried information is copied into data. If size is set to
  663. * a value different from 0 and different from the required size, the
  664. * IOCTL call returns -EINVAL.
  665. *
  666. * For example the following code snippet allows retrieving and printing
  667. * information about the device engines with DRM_XE_DEVICE_QUERY_ENGINES:
  668. *
  669. * .. code-block:: C
  670. *
  671. * struct drm_xe_query_engines *engines;
  672. * struct drm_xe_device_query query = {
  673. * .extensions = 0,
  674. * .query = DRM_XE_DEVICE_QUERY_ENGINES,
  675. * .size = 0,
  676. * .data = 0,
  677. * };
  678. * ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query);
  679. * engines = malloc(query.size);
  680. * query.data = (uintptr_t)engines;
  681. * ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query);
  682. * for (int i = 0; i < engines->num_engines; i++) {
  683. * printf("Engine %d: %s\n", i,
  684. * engines->engines[i].instance.engine_class ==
  685. * DRM_XE_ENGINE_CLASS_RENDER ? "RENDER":
  686. * engines->engines[i].instance.engine_class ==
  687. * DRM_XE_ENGINE_CLASS_COPY ? "COPY":
  688. * engines->engines[i].instance.engine_class ==
  689. * DRM_XE_ENGINE_CLASS_VIDEO_DECODE ? "VIDEO_DECODE":
  690. * engines->engines[i].instance.engine_class ==
  691. * DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE ? "VIDEO_ENHANCE":
  692. * engines->engines[i].instance.engine_class ==
  693. * DRM_XE_ENGINE_CLASS_COMPUTE ? "COMPUTE":
  694. * "UNKNOWN");
  695. * }
  696. * free(engines);
  697. */
  698. struct drm_xe_device_query {
  699. /** @extensions: Pointer to the first extension struct, if any */
  700. __u64 extensions;
  701. #define DRM_XE_DEVICE_QUERY_ENGINES 0
  702. #define DRM_XE_DEVICE_QUERY_MEM_REGIONS 1
  703. #define DRM_XE_DEVICE_QUERY_CONFIG 2
  704. #define DRM_XE_DEVICE_QUERY_GT_LIST 3
  705. #define DRM_XE_DEVICE_QUERY_HWCONFIG 4
  706. #define DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 5
  707. #define DRM_XE_DEVICE_QUERY_ENGINE_CYCLES 6
  708. #define DRM_XE_DEVICE_QUERY_UC_FW_VERSION 7
  709. #define DRM_XE_DEVICE_QUERY_OA_UNITS 8
  710. #define DRM_XE_DEVICE_QUERY_PXP_STATUS 9
  711. #define DRM_XE_DEVICE_QUERY_EU_STALL 10
  712. /** @query: The type of data to query */
  713. __u32 query;
  714. /** @size: Size of the queried data */
  715. __u32 size;
  716. /** @data: Queried data is placed here */
  717. __u64 data;
  718. /** @reserved: Reserved */
  719. __u64 reserved[2];
  720. };
  721. /**
  722. * struct drm_xe_gem_create - Input of &DRM_IOCTL_XE_GEM_CREATE - A structure for
  723. * gem creation
  724. *
  725. * The @flags can be:
  726. * - %DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING - Modify the GEM object
  727. * allocation strategy by deferring physical memory allocation
  728. * until the object is either bound to a virtual memory region via
  729. * VM_BIND or accessed by the CPU. As a result, no backing memory is
  730. * reserved at the time of GEM object creation.
  731. * - %DRM_XE_GEM_CREATE_FLAG_SCANOUT - Indicates that the GEM object is
  732. * intended for scanout via the display engine. When set, kernel ensures
  733. * that the allocation is placed in a memory region compatible with the
  734. * display engine requirements. This may impose restrictions on tiling,
  735. * alignment, and memory placement to guarantee proper display functionality.
  736. * - %DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM - When using VRAM as a
  737. * possible placement, ensure that the corresponding VRAM allocation
  738. * will always use the CPU accessible part of VRAM. This is important
  739. * for small-bar systems (on full-bar systems this gets turned into a
  740. * noop).
  741. * Note1: System memory can be used as an extra placement if the kernel
  742. * should spill the allocation to system memory, if space can't be made
  743. * available in the CPU accessible part of VRAM (giving the same
  744. * behaviour as the i915 interface, see
  745. * I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS).
  746. * Note2: For clear-color CCS surfaces the kernel needs to read the
  747. * clear-color value stored in the buffer, and on discrete platforms we
  748. * need to use VRAM for display surfaces, therefore the kernel requires
  749. * setting this flag for such objects, otherwise an error is thrown on
  750. * small-bar systems.
  751. * - %DRM_XE_GEM_CREATE_FLAG_NO_COMPRESSION - Allows userspace to
  752. * hint that compression (CCS) should be disabled for the buffer being
  753. * created. This can avoid unnecessary memory operations and CCS state
  754. * management.
  755. * On pre-Xe2 platforms, this flag is currently rejected as compression
  756. * control is not supported via PAT index. On Xe2+ platforms, compression
  757. * is controlled via PAT entries. If this flag is set, the driver will reject
  758. * any VM bind that requests a PAT index enabling compression for this BO.
  759. * Note: On dGPU platforms, there is currently no change in behavior with
  760. * this flag, but future improvements may leverage it. The current benefit is
  761. * primarily applicable to iGPU platforms.
  762. *
  763. * @cpu_caching supports the following values:
  764. * - %DRM_XE_GEM_CPU_CACHING_WB - Allocate the pages with write-back
  765. * caching. On iGPU this can't be used for scanout surfaces. Currently
  766. * not allowed for objects placed in VRAM.
  767. * - %DRM_XE_GEM_CPU_CACHING_WC - Allocate the pages as write-combined. This
  768. * is uncached. Scanout surfaces should likely use this. All objects
  769. * that can be placed in VRAM must use this.
  770. *
  771. * This ioctl supports setting the following properties via the
  772. * %DRM_XE_GEM_CREATE_EXTENSION_SET_PROPERTY extension, which uses the
  773. * generic @drm_xe_ext_set_property struct:
  774. *
  775. * - %DRM_XE_GEM_CREATE_SET_PROPERTY_PXP_TYPE - set the type of PXP session
  776. * this object will be used with. Valid values are listed in enum
  777. * drm_xe_pxp_session_type. %DRM_XE_PXP_TYPE_NONE is the default behavior, so
  778. * there is no need to explicitly set that. Objects used with session of type
  779. * %DRM_XE_PXP_TYPE_HWDRM will be marked as invalid if a PXP invalidation
  780. * event occurs after their creation. Attempting to flip an invalid object
  781. * will cause a black frame to be displayed instead. Submissions with invalid
  782. * objects mapped in the VM will be rejected.
  783. */
  784. struct drm_xe_gem_create {
  785. #define DRM_XE_GEM_CREATE_EXTENSION_SET_PROPERTY 0
  786. #define DRM_XE_GEM_CREATE_SET_PROPERTY_PXP_TYPE 0
  787. /** @extensions: Pointer to the first extension struct, if any */
  788. __u64 extensions;
  789. /**
  790. * @size: Size of the object to be created, must match region
  791. * (system or vram) minimum alignment (&min_page_size).
  792. */
  793. __u64 size;
  794. /**
  795. * @placement: A mask of memory instances of where BO can be placed.
  796. * Each index in this mask refers directly to the struct
  797. * drm_xe_query_mem_regions' instance, no assumptions should
  798. * be made about order. The type of each region is described
  799. * by struct drm_xe_query_mem_regions' mem_class.
  800. */
  801. __u32 placement;
  802. #define DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING (1 << 0)
  803. #define DRM_XE_GEM_CREATE_FLAG_SCANOUT (1 << 1)
  804. #define DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM (1 << 2)
  805. #define DRM_XE_GEM_CREATE_FLAG_NO_COMPRESSION (1 << 3)
  806. /**
  807. * @flags: Flags, currently a mask of memory instances of where BO can
  808. * be placed
  809. */
  810. __u32 flags;
  811. /**
  812. * @vm_id: Attached VM, if any
  813. *
  814. * If a VM is specified, this BO must:
  815. *
  816. * 1. Only ever be bound to that VM.
  817. * 2. Cannot be exported as a PRIME fd.
  818. */
  819. __u32 vm_id;
  820. /**
  821. * @handle: Returned handle for the object.
  822. *
  823. * Object handles are nonzero.
  824. */
  825. __u32 handle;
  826. #define DRM_XE_GEM_CPU_CACHING_WB 1
  827. #define DRM_XE_GEM_CPU_CACHING_WC 2
  828. /**
  829. * @cpu_caching: The CPU caching mode to select for this object. If
  830. * mmaping the object the mode selected here will also be used. The
  831. * exception is when mapping system memory (including data evicted
  832. * to system) on discrete GPUs. The caching mode selected will
  833. * then be overridden to DRM_XE_GEM_CPU_CACHING_WB, and coherency
  834. * between GPU- and CPU is guaranteed. The caching mode of
  835. * existing CPU-mappings will be updated transparently to
  836. * user-space clients.
  837. */
  838. __u16 cpu_caching;
  839. /** @pad: MBZ */
  840. __u16 pad[3];
  841. /** @reserved: Reserved */
  842. __u64 reserved[2];
  843. };
  844. /**
  845. * struct drm_xe_gem_mmap_offset - Input of &DRM_IOCTL_XE_GEM_MMAP_OFFSET
  846. *
  847. * The @flags can be:
  848. * - %DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER - For user to query special offset
  849. * for use in mmap ioctl. Writing to the returned mmap address will generate a
  850. * PCI memory barrier with low overhead (avoiding IOCTL call as well as writing
  851. * to VRAM which would also add overhead), acting like an MI_MEM_FENCE
  852. * instruction.
  853. *
  854. * Note: The mmap size can be at most 4K, due to HW limitations. As a result
  855. * this interface is only supported on CPU architectures that support 4K page
  856. * size. The mmap_offset ioctl will detect this and gracefully return an
  857. * error, where userspace is expected to have a different fallback method for
  858. * triggering a barrier.
  859. *
  860. * Roughly the usage would be as follows:
  861. *
  862. * .. code-block:: C
  863. *
  864. * struct drm_xe_gem_mmap_offset mmo = {
  865. * .handle = 0, // must be set to 0
  866. * .flags = DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER,
  867. * };
  868. *
  869. * err = ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &mmo);
  870. * map = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, mmo.offset);
  871. * map[i] = 0xdeadbeaf; // issue barrier
  872. */
  873. struct drm_xe_gem_mmap_offset {
  874. /** @extensions: Pointer to the first extension struct, if any */
  875. __u64 extensions;
  876. /** @handle: Handle for the object being mapped. */
  877. __u32 handle;
  878. #define DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER (1 << 0)
  879. /** @flags: Flags */
  880. __u32 flags;
  881. /** @offset: The fake offset to use for subsequent mmap call */
  882. __u64 offset;
  883. /** @reserved: Reserved */
  884. __u64 reserved[2];
  885. };
  886. /**
  887. * struct drm_xe_vm_create - Input of &DRM_IOCTL_XE_VM_CREATE
  888. *
  889. * The @flags can be:
  890. * - %DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE - Map the whole virtual address
  891. * space of the VM to scratch page. A vm_bind would overwrite the scratch
  892. * page mapping. This flag is mutually exclusive with the
  893. * %DRM_XE_VM_CREATE_FLAG_FAULT_MODE flag, with an exception of on x2 and
  894. * xe3 platform.
  895. * - %DRM_XE_VM_CREATE_FLAG_LR_MODE - An LR, or Long Running VM accepts
  896. * exec submissions to its exec_queues that don't have an upper time
  897. * limit on the job execution time. But exec submissions to these
  898. * don't allow any of the sync types DRM_XE_SYNC_TYPE_SYNCOBJ,
  899. * DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ, used as out-syncobjs, that is,
  900. * together with sync flag DRM_XE_SYNC_FLAG_SIGNAL.
  901. * LR VMs can be created in recoverable page-fault mode using
  902. * DRM_XE_VM_CREATE_FLAG_FAULT_MODE, if the device supports it.
  903. * If that flag is omitted, the UMD can not rely on the slightly
  904. * different per-VM overcommit semantics that are enabled by
  905. * DRM_XE_VM_CREATE_FLAG_FAULT_MODE (see below), but KMD may
  906. * still enable recoverable pagefaults if supported by the device.
  907. * - %DRM_XE_VM_CREATE_FLAG_FAULT_MODE - Requires also
  908. * DRM_XE_VM_CREATE_FLAG_LR_MODE. It allows memory to be allocated on
  909. * demand when accessed, and also allows per-VM overcommit of memory.
  910. * The xe driver internally uses recoverable pagefaults to implement
  911. * this.
  912. */
  913. struct drm_xe_vm_create {
  914. /** @extensions: Pointer to the first extension struct, if any */
  915. __u64 extensions;
  916. #define DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE (1 << 0)
  917. #define DRM_XE_VM_CREATE_FLAG_LR_MODE (1 << 1)
  918. #define DRM_XE_VM_CREATE_FLAG_FAULT_MODE (1 << 2)
  919. /** @flags: Flags */
  920. __u32 flags;
  921. /** @vm_id: Returned VM ID */
  922. __u32 vm_id;
  923. /** @reserved: Reserved */
  924. __u64 reserved[2];
  925. };
  926. /**
  927. * struct drm_xe_vm_destroy - Input of &DRM_IOCTL_XE_VM_DESTROY
  928. */
  929. struct drm_xe_vm_destroy {
  930. /** @vm_id: VM ID */
  931. __u32 vm_id;
  932. /** @pad: MBZ */
  933. __u32 pad;
  934. /** @reserved: Reserved */
  935. __u64 reserved[2];
  936. };
  937. /**
  938. * struct drm_xe_vm_bind_op - run bind operations
  939. *
  940. * The @op can be:
  941. * - %DRM_XE_VM_BIND_OP_MAP
  942. * - %DRM_XE_VM_BIND_OP_UNMAP
  943. * - %DRM_XE_VM_BIND_OP_MAP_USERPTR
  944. * - %DRM_XE_VM_BIND_OP_UNMAP_ALL
  945. * - %DRM_XE_VM_BIND_OP_PREFETCH
  946. *
  947. * and the @flags can be:
  948. * - %DRM_XE_VM_BIND_FLAG_READONLY - Setup the page tables as read-only
  949. * to ensure write protection
  950. * - %DRM_XE_VM_BIND_FLAG_IMMEDIATE - On a faulting VM, do the
  951. * MAP operation immediately rather than deferring the MAP to the page
  952. * fault handler. This is implied on a non-faulting VM as there is no
  953. * fault handler to defer to.
  954. * - %DRM_XE_VM_BIND_FLAG_NULL - When the NULL flag is set, the page
  955. * tables are setup with a special bit which indicates writes are
  956. * dropped and all reads return zero. In the future, the NULL flags
  957. * will only be valid for DRM_XE_VM_BIND_OP_MAP operations, the BO
  958. * handle MBZ, and the BO offset MBZ. This flag is intended to
  959. * implement VK sparse bindings.
  960. * - %DRM_XE_VM_BIND_FLAG_CHECK_PXP - If the object is encrypted via PXP,
  961. * reject the binding if the encryption key is no longer valid. This
  962. * flag has no effect on BOs that are not marked as using PXP.
  963. * - %DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR - When the CPU address mirror flag is
  964. * set, no mappings are created rather the range is reserved for CPU address
  965. * mirroring which will be populated on GPU page faults or prefetches. Only
  966. * valid on VMs with DRM_XE_VM_CREATE_FLAG_FAULT_MODE set. The CPU address
  967. * mirror flag are only valid for DRM_XE_VM_BIND_OP_MAP operations, the BO
  968. * handle MBZ, and the BO offset MBZ.
  969. * - %DRM_XE_VM_BIND_FLAG_MADVISE_AUTORESET - Can be used in combination with
  970. * %DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR to reset madvises when the underlying
  971. * CPU address space range is unmapped (typically with munmap(2) or brk(2)).
  972. * The madvise values set with &DRM_IOCTL_XE_MADVISE are reset to the values
  973. * that were present immediately after the &DRM_IOCTL_XE_VM_BIND.
  974. * The reset GPU virtual address range is the intersection of the range bound
  975. * using &DRM_IOCTL_XE_VM_BIND and the virtual CPU address space range
  976. * unmapped.
  977. * This functionality is present to mimic the behaviour of CPU address space
  978. * madvises set using madvise(2), which are typically reset on unmap.
  979. * Note: free(3) may or may not call munmap(2) and/or brk(2), and may thus
  980. * not invoke autoreset. Neither will stack variables going out of scope.
  981. * Therefore it's recommended to always explicitly reset the madvises when
  982. * freeing the memory backing a region used in a &DRM_IOCTL_XE_MADVISE call.
  983. *
  984. * The @prefetch_mem_region_instance for %DRM_XE_VM_BIND_OP_PREFETCH can also be:
  985. * - %DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC, which ensures prefetching occurs in
  986. * the memory region advised by madvise.
  987. */
  988. struct drm_xe_vm_bind_op {
  989. /** @extensions: Pointer to the first extension struct, if any */
  990. __u64 extensions;
  991. /**
  992. * @obj: GEM object to operate on, MBZ for MAP_USERPTR, MBZ for UNMAP
  993. */
  994. __u32 obj;
  995. /**
  996. * @pat_index: The platform defined @pat_index to use for this mapping.
  997. * The index basically maps to some predefined memory attributes,
  998. * including things like caching, coherency, compression etc. The exact
  999. * meaning of the pat_index is platform specific and defined in the
  1000. * Bspec and PRMs. When the KMD sets up the binding the index here is
  1001. * encoded into the ppGTT PTE.
  1002. *
  1003. * For coherency the @pat_index needs to be at least 1way coherent when
  1004. * drm_xe_gem_create.cpu_caching is DRM_XE_GEM_CPU_CACHING_WB. The KMD
  1005. * will extract the coherency mode from the @pat_index and reject if
  1006. * there is a mismatch (see note below for pre-MTL platforms).
  1007. *
  1008. * Note: On pre-MTL platforms there is only a caching mode and no
  1009. * explicit coherency mode, but on such hardware there is always a
  1010. * shared-LLC (or is dgpu) so all GT memory accesses are coherent with
  1011. * CPU caches even with the caching mode set as uncached. It's only the
  1012. * display engine that is incoherent (on dgpu it must be in VRAM which
  1013. * is always mapped as WC on the CPU). However to keep the uapi somewhat
  1014. * consistent with newer platforms the KMD groups the different cache
  1015. * levels into the following coherency buckets on all pre-MTL platforms:
  1016. *
  1017. * ppGTT UC -> COH_NONE
  1018. * ppGTT WC -> COH_NONE
  1019. * ppGTT WT -> COH_NONE
  1020. * ppGTT WB -> COH_AT_LEAST_1WAY
  1021. *
  1022. * In practice UC/WC/WT should only ever used for scanout surfaces on
  1023. * such platforms (or perhaps in general for dma-buf if shared with
  1024. * another device) since it is only the display engine that is actually
  1025. * incoherent. Everything else should typically use WB given that we
  1026. * have a shared-LLC. On MTL+ this completely changes and the HW
  1027. * defines the coherency mode as part of the @pat_index, where
  1028. * incoherent GT access is possible.
  1029. *
  1030. * Note: For userptr and externally imported dma-buf the kernel expects
  1031. * either 1WAY or 2WAY for the @pat_index.
  1032. *
  1033. * For DRM_XE_VM_BIND_FLAG_NULL bindings there are no KMD restrictions
  1034. * on the @pat_index. For such mappings there is no actual memory being
  1035. * mapped (the address in the PTE is invalid), so the various PAT memory
  1036. * attributes likely do not apply. Simply leaving as zero is one
  1037. * option (still a valid pat_index). Same applies to
  1038. * DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR bindings as for such mapping
  1039. * there is no actual memory being mapped.
  1040. */
  1041. __u16 pat_index;
  1042. /** @pad: MBZ */
  1043. __u16 pad;
  1044. union {
  1045. /**
  1046. * @obj_offset: Offset into the object, MBZ for CLEAR_RANGE,
  1047. * ignored for unbind
  1048. */
  1049. __u64 obj_offset;
  1050. /** @userptr: user pointer to bind on */
  1051. __u64 userptr;
  1052. /**
  1053. * @cpu_addr_mirror_offset: Offset from GPU @addr to create
  1054. * CPU address mirror mappings. MBZ with current level of
  1055. * support (e.g. 1 to 1 mapping between GPU and CPU mappings
  1056. * only supported).
  1057. */
  1058. __s64 cpu_addr_mirror_offset;
  1059. };
  1060. /**
  1061. * @range: Number of bytes from the object to bind to addr, MBZ for UNMAP_ALL
  1062. */
  1063. __u64 range;
  1064. /** @addr: Address to operate on, MBZ for UNMAP_ALL */
  1065. __u64 addr;
  1066. #define DRM_XE_VM_BIND_OP_MAP 0x0
  1067. #define DRM_XE_VM_BIND_OP_UNMAP 0x1
  1068. #define DRM_XE_VM_BIND_OP_MAP_USERPTR 0x2
  1069. #define DRM_XE_VM_BIND_OP_UNMAP_ALL 0x3
  1070. #define DRM_XE_VM_BIND_OP_PREFETCH 0x4
  1071. /** @op: Bind operation to perform */
  1072. __u32 op;
  1073. #define DRM_XE_VM_BIND_FLAG_READONLY (1 << 0)
  1074. #define DRM_XE_VM_BIND_FLAG_IMMEDIATE (1 << 1)
  1075. #define DRM_XE_VM_BIND_FLAG_NULL (1 << 2)
  1076. #define DRM_XE_VM_BIND_FLAG_DUMPABLE (1 << 3)
  1077. #define DRM_XE_VM_BIND_FLAG_CHECK_PXP (1 << 4)
  1078. #define DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR (1 << 5)
  1079. #define DRM_XE_VM_BIND_FLAG_MADVISE_AUTORESET (1 << 6)
  1080. /** @flags: Bind flags */
  1081. __u32 flags;
  1082. #define DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC -1
  1083. /**
  1084. * @prefetch_mem_region_instance: Memory region to prefetch VMA to.
  1085. * It is a region instance, not a mask.
  1086. * To be used only with %DRM_XE_VM_BIND_OP_PREFETCH operation.
  1087. */
  1088. __u32 prefetch_mem_region_instance;
  1089. /** @pad2: MBZ */
  1090. __u32 pad2;
  1091. /** @reserved: Reserved */
  1092. __u64 reserved[3];
  1093. };
  1094. /**
  1095. * struct drm_xe_vm_bind - Input of &DRM_IOCTL_XE_VM_BIND
  1096. *
  1097. * Below is an example of a minimal use of @drm_xe_vm_bind to
  1098. * asynchronously bind the buffer `data` at address `BIND_ADDRESS` to
  1099. * illustrate `userptr`. It can be synchronized by using the example
  1100. * provided for @drm_xe_sync.
  1101. *
  1102. * .. code-block:: C
  1103. *
  1104. * data = aligned_alloc(ALIGNMENT, BO_SIZE);
  1105. * struct drm_xe_vm_bind bind = {
  1106. * .vm_id = vm,
  1107. * .num_binds = 1,
  1108. * .bind.obj = 0,
  1109. * .bind.obj_offset = to_user_pointer(data),
  1110. * .bind.range = BO_SIZE,
  1111. * .bind.addr = BIND_ADDRESS,
  1112. * .bind.op = DRM_XE_VM_BIND_OP_MAP_USERPTR,
  1113. * .bind.flags = 0,
  1114. * .num_syncs = 1,
  1115. * .syncs = &sync,
  1116. * .exec_queue_id = 0,
  1117. * };
  1118. * ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind);
  1119. *
  1120. */
  1121. struct drm_xe_vm_bind {
  1122. /** @extensions: Pointer to the first extension struct, if any */
  1123. __u64 extensions;
  1124. /** @vm_id: The ID of the VM to bind to */
  1125. __u32 vm_id;
  1126. /**
  1127. * @exec_queue_id: exec_queue_id, must be of class DRM_XE_ENGINE_CLASS_VM_BIND
  1128. * and exec queue must have same vm_id. If zero, the default VM bind engine
  1129. * is used.
  1130. */
  1131. __u32 exec_queue_id;
  1132. /** @pad: MBZ */
  1133. __u32 pad;
  1134. /** @num_binds: number of binds in this IOCTL */
  1135. __u32 num_binds;
  1136. union {
  1137. /** @bind: used if num_binds == 1 */
  1138. struct drm_xe_vm_bind_op bind;
  1139. /**
  1140. * @vector_of_binds: userptr to array of struct
  1141. * drm_xe_vm_bind_op if num_binds > 1
  1142. */
  1143. __u64 vector_of_binds;
  1144. };
  1145. /** @pad2: MBZ */
  1146. __u32 pad2;
  1147. /** @num_syncs: amount of syncs to wait on */
  1148. __u32 num_syncs;
  1149. /** @syncs: pointer to struct drm_xe_sync array */
  1150. __u64 syncs;
  1151. /** @reserved: Reserved */
  1152. __u64 reserved[2];
  1153. };
  1154. /**
  1155. * struct drm_xe_exec_queue_create - Input of &DRM_IOCTL_XE_EXEC_QUEUE_CREATE
  1156. *
  1157. * This ioctl supports setting the following properties via the
  1158. * %DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY extension, which uses the
  1159. * generic @drm_xe_ext_set_property struct:
  1160. *
  1161. * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY - set the queue priority.
  1162. * CAP_SYS_NICE is required to set a value above normal.
  1163. * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE - set the queue timeslice
  1164. * duration in microseconds.
  1165. * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE - set the type of PXP session
  1166. * this queue will be used with. Valid values are listed in enum
  1167. * drm_xe_pxp_session_type. %DRM_XE_PXP_TYPE_NONE is the default behavior, so
  1168. * there is no need to explicitly set that. When a queue of type
  1169. * %DRM_XE_PXP_TYPE_HWDRM is created, the PXP default HWDRM session
  1170. * (%XE_PXP_HWDRM_DEFAULT_SESSION) will be started, if isn't already running.
  1171. * The user is expected to query the PXP status via the query ioctl (see
  1172. * %DRM_XE_DEVICE_QUERY_PXP_STATUS) and to wait for PXP to be ready before
  1173. * attempting to create a queue with this property. When a queue is created
  1174. * before PXP is ready, the ioctl will return -EBUSY if init is still in
  1175. * progress or -EIO if init failed.
  1176. * Given that going into a power-saving state kills PXP HWDRM sessions,
  1177. * runtime PM will be blocked while queues of this type are alive.
  1178. * All PXP queues will be killed if a PXP invalidation event occurs.
  1179. * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP - Create a multi-queue group
  1180. * or add secondary queues to a multi-queue group.
  1181. * If the extension's 'value' field has %DRM_XE_MULTI_GROUP_CREATE flag set,
  1182. * then a new multi-queue group is created with this queue as the primary queue
  1183. * (Q0). Otherwise, the queue gets added to the multi-queue group whose primary
  1184. * queue's exec_queue_id is specified in the lower 32 bits of the 'value' field.
  1185. * All the other non-relevant bits of extension's 'value' field while adding the
  1186. * primary or the secondary queues of the group must be set to 0.
  1187. * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY - Set the queue
  1188. * priority within the multi-queue group. Current valid priority values are 0–2
  1189. * (default is 1), with higher values indicating higher priority.
  1190. *
  1191. * The example below shows how to use @drm_xe_exec_queue_create to create
  1192. * a simple exec_queue (no parallel submission) of class
  1193. * &DRM_XE_ENGINE_CLASS_RENDER.
  1194. *
  1195. * .. code-block:: C
  1196. *
  1197. * struct drm_xe_engine_class_instance instance = {
  1198. * .engine_class = DRM_XE_ENGINE_CLASS_RENDER,
  1199. * };
  1200. * struct drm_xe_exec_queue_create exec_queue_create = {
  1201. * .extensions = 0,
  1202. * .vm_id = vm,
  1203. * .num_bb_per_exec = 1,
  1204. * .num_eng_per_bb = 1,
  1205. * .instances = to_user_pointer(&instance),
  1206. * };
  1207. * ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create);
  1208. *
  1209. * Allow users to provide a hint to kernel for cases demanding low latency
  1210. * profile. Please note it will have impact on power consumption. User can
  1211. * indicate low latency hint with flag while creating exec queue as
  1212. * mentioned below,
  1213. *
  1214. * struct drm_xe_exec_queue_create exec_queue_create = {
  1215. * .flags = DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT,
  1216. * .extensions = 0,
  1217. * .vm_id = vm,
  1218. * .num_bb_per_exec = 1,
  1219. * .num_eng_per_bb = 1,
  1220. * .instances = to_user_pointer(&instance),
  1221. * };
  1222. * ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create);
  1223. *
  1224. */
  1225. struct drm_xe_exec_queue_create {
  1226. #define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY 0
  1227. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 0
  1228. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 1
  1229. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE 2
  1230. #define DRM_XE_EXEC_QUEUE_SET_HANG_REPLAY_STATE 3
  1231. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP 4
  1232. #define DRM_XE_MULTI_GROUP_CREATE (1ull << 63)
  1233. #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY 5
  1234. /** @extensions: Pointer to the first extension struct, if any */
  1235. __u64 extensions;
  1236. /** @width: submission width (number BB per exec) for this exec queue */
  1237. __u16 width;
  1238. /** @num_placements: number of valid placements for this exec queue */
  1239. __u16 num_placements;
  1240. /** @vm_id: VM to use for this exec queue */
  1241. __u32 vm_id;
  1242. #define DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT (1 << 0)
  1243. /** @flags: flags to use for this exec queue */
  1244. __u32 flags;
  1245. /** @exec_queue_id: Returned exec queue ID */
  1246. __u32 exec_queue_id;
  1247. /**
  1248. * @instances: user pointer to a 2-d array of struct
  1249. * drm_xe_engine_class_instance
  1250. *
  1251. * length = width (i) * num_placements (j)
  1252. * index = j + i * width
  1253. */
  1254. __u64 instances;
  1255. /** @reserved: Reserved */
  1256. __u64 reserved[2];
  1257. };
  1258. /**
  1259. * struct drm_xe_exec_queue_destroy - Input of &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY
  1260. */
  1261. struct drm_xe_exec_queue_destroy {
  1262. /** @exec_queue_id: Exec queue ID */
  1263. __u32 exec_queue_id;
  1264. /** @pad: MBZ */
  1265. __u32 pad;
  1266. /** @reserved: Reserved */
  1267. __u64 reserved[2];
  1268. };
  1269. /**
  1270. * struct drm_xe_exec_queue_get_property - Input of &DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY
  1271. *
  1272. * The @property can be:
  1273. * - %DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN
  1274. */
  1275. struct drm_xe_exec_queue_get_property {
  1276. /** @extensions: Pointer to the first extension struct, if any */
  1277. __u64 extensions;
  1278. /** @exec_queue_id: Exec queue ID */
  1279. __u32 exec_queue_id;
  1280. #define DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN 0
  1281. /** @property: property to get */
  1282. __u32 property;
  1283. /** @value: property value */
  1284. __u64 value;
  1285. /** @reserved: Reserved */
  1286. __u64 reserved[2];
  1287. };
  1288. /**
  1289. * struct drm_xe_sync - sync object
  1290. *
  1291. * The @type can be:
  1292. * - %DRM_XE_SYNC_TYPE_SYNCOBJ
  1293. * - %DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ
  1294. * - %DRM_XE_SYNC_TYPE_USER_FENCE
  1295. *
  1296. * and the @flags can be:
  1297. * - %DRM_XE_SYNC_FLAG_SIGNAL
  1298. *
  1299. * A minimal use of @drm_xe_sync looks like this:
  1300. *
  1301. * .. code-block:: C
  1302. *
  1303. * struct drm_xe_sync sync = {
  1304. * .flags = DRM_XE_SYNC_FLAG_SIGNAL,
  1305. * .type = DRM_XE_SYNC_TYPE_SYNCOBJ,
  1306. * };
  1307. * struct drm_syncobj_create syncobj_create = { 0 };
  1308. * ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &syncobj_create);
  1309. * sync.handle = syncobj_create.handle;
  1310. * ...
  1311. * use of &sync in drm_xe_exec or drm_xe_vm_bind
  1312. * ...
  1313. * struct drm_syncobj_wait wait = {
  1314. * .handles = &sync.handle,
  1315. * .timeout_nsec = INT64_MAX,
  1316. * .count_handles = 1,
  1317. * .flags = 0,
  1318. * .first_signaled = 0,
  1319. * .pad = 0,
  1320. * };
  1321. * ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &wait);
  1322. */
  1323. struct drm_xe_sync {
  1324. /** @extensions: Pointer to the first extension struct, if any */
  1325. __u64 extensions;
  1326. #define DRM_XE_SYNC_TYPE_SYNCOBJ 0x0
  1327. #define DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ 0x1
  1328. #define DRM_XE_SYNC_TYPE_USER_FENCE 0x2
  1329. /** @type: Type of the this sync object */
  1330. __u32 type;
  1331. #define DRM_XE_SYNC_FLAG_SIGNAL (1 << 0)
  1332. /** @flags: Sync Flags */
  1333. __u32 flags;
  1334. union {
  1335. /** @handle: Handle for the object */
  1336. __u32 handle;
  1337. /**
  1338. * @addr: Address of user fence. When sync is passed in via exec
  1339. * IOCTL this is a GPU address in the VM. When sync passed in via
  1340. * VM bind IOCTL this is a user pointer. In either case, it is
  1341. * the users responsibility that this address is present and
  1342. * mapped when the user fence is signalled. Must be qword
  1343. * aligned.
  1344. */
  1345. __u64 addr;
  1346. };
  1347. /**
  1348. * @timeline_value: Input for the timeline sync object. Needs to be
  1349. * different than 0 when used with %DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ.
  1350. */
  1351. __u64 timeline_value;
  1352. /** @reserved: Reserved */
  1353. __u64 reserved[2];
  1354. };
  1355. /**
  1356. * struct drm_xe_exec - Input of &DRM_IOCTL_XE_EXEC
  1357. *
  1358. * This is an example to use @drm_xe_exec for execution of the object
  1359. * at BIND_ADDRESS (see example in @drm_xe_vm_bind) by an exec_queue
  1360. * (see example in @drm_xe_exec_queue_create). It can be synchronized
  1361. * by using the example provided for @drm_xe_sync.
  1362. *
  1363. * .. code-block:: C
  1364. *
  1365. * struct drm_xe_exec exec = {
  1366. * .exec_queue_id = exec_queue,
  1367. * .syncs = &sync,
  1368. * .num_syncs = 1,
  1369. * .address = BIND_ADDRESS,
  1370. * .num_batch_buffer = 1,
  1371. * };
  1372. * ioctl(fd, DRM_IOCTL_XE_EXEC, &exec);
  1373. *
  1374. */
  1375. struct drm_xe_exec {
  1376. /** @extensions: Pointer to the first extension struct, if any */
  1377. __u64 extensions;
  1378. /** @exec_queue_id: Exec queue ID for the batch buffer */
  1379. __u32 exec_queue_id;
  1380. #define DRM_XE_MAX_SYNCS 1024
  1381. /** @num_syncs: Amount of struct drm_xe_sync in array. */
  1382. __u32 num_syncs;
  1383. /** @syncs: Pointer to struct drm_xe_sync array. */
  1384. __u64 syncs;
  1385. /**
  1386. * @address: address of batch buffer if num_batch_buffer == 1 or an
  1387. * array of batch buffer addresses
  1388. */
  1389. __u64 address;
  1390. /**
  1391. * @num_batch_buffer: number of batch buffer in this exec, must match
  1392. * the width of the engine
  1393. */
  1394. __u16 num_batch_buffer;
  1395. /** @pad: MBZ */
  1396. __u16 pad[3];
  1397. /** @reserved: Reserved */
  1398. __u64 reserved[2];
  1399. };
  1400. /**
  1401. * struct drm_xe_wait_user_fence - Input of &DRM_IOCTL_XE_WAIT_USER_FENCE
  1402. *
  1403. * Wait on user fence, XE will wake-up on every HW engine interrupt in the
  1404. * instances list and check if user fence is complete::
  1405. *
  1406. * (*addr & MASK) OP (VALUE & MASK)
  1407. *
  1408. * Returns to user on user fence completion or timeout.
  1409. *
  1410. * The @op can be:
  1411. * - %DRM_XE_UFENCE_WAIT_OP_EQ
  1412. * - %DRM_XE_UFENCE_WAIT_OP_NEQ
  1413. * - %DRM_XE_UFENCE_WAIT_OP_GT
  1414. * - %DRM_XE_UFENCE_WAIT_OP_GTE
  1415. * - %DRM_XE_UFENCE_WAIT_OP_LT
  1416. * - %DRM_XE_UFENCE_WAIT_OP_LTE
  1417. *
  1418. * and the @flags can be:
  1419. * - %DRM_XE_UFENCE_WAIT_FLAG_ABSTIME
  1420. * - %DRM_XE_UFENCE_WAIT_FLAG_SOFT_OP
  1421. *
  1422. * The @mask values can be for example:
  1423. * - 0xffu for u8
  1424. * - 0xffffu for u16
  1425. * - 0xffffffffu for u32
  1426. * - 0xffffffffffffffffu for u64
  1427. */
  1428. struct drm_xe_wait_user_fence {
  1429. /** @extensions: Pointer to the first extension struct, if any */
  1430. __u64 extensions;
  1431. /**
  1432. * @addr: user pointer address to wait on, must qword aligned
  1433. */
  1434. __u64 addr;
  1435. #define DRM_XE_UFENCE_WAIT_OP_EQ 0x0
  1436. #define DRM_XE_UFENCE_WAIT_OP_NEQ 0x1
  1437. #define DRM_XE_UFENCE_WAIT_OP_GT 0x2
  1438. #define DRM_XE_UFENCE_WAIT_OP_GTE 0x3
  1439. #define DRM_XE_UFENCE_WAIT_OP_LT 0x4
  1440. #define DRM_XE_UFENCE_WAIT_OP_LTE 0x5
  1441. /** @op: wait operation (type of comparison) */
  1442. __u16 op;
  1443. #define DRM_XE_UFENCE_WAIT_FLAG_ABSTIME (1 << 0)
  1444. /** @flags: wait flags */
  1445. __u16 flags;
  1446. /** @pad: MBZ */
  1447. __u32 pad;
  1448. /** @value: compare value */
  1449. __u64 value;
  1450. /** @mask: comparison mask */
  1451. __u64 mask;
  1452. /**
  1453. * @timeout: how long to wait before bailing, value in nanoseconds.
  1454. * Without DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flag set (relative timeout)
  1455. * it contains timeout expressed in nanoseconds to wait (fence will
  1456. * expire at now() + timeout).
  1457. * When DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flat is set (absolute timeout) wait
  1458. * will end at timeout (uses system MONOTONIC_CLOCK).
  1459. * Passing negative timeout leads to neverending wait.
  1460. *
  1461. * On relative timeout this value is updated with timeout left
  1462. * (for restarting the call in case of signal delivery).
  1463. * On absolute timeout this value stays intact (restarted call still
  1464. * expire at the same point of time).
  1465. */
  1466. __s64 timeout;
  1467. /** @exec_queue_id: exec_queue_id returned from xe_exec_queue_create_ioctl */
  1468. __u32 exec_queue_id;
  1469. /** @pad2: MBZ */
  1470. __u32 pad2;
  1471. /** @reserved: Reserved */
  1472. __u64 reserved[2];
  1473. };
  1474. /**
  1475. * enum drm_xe_observation_type - Observation stream types
  1476. */
  1477. enum drm_xe_observation_type {
  1478. /** @DRM_XE_OBSERVATION_TYPE_OA: OA observation stream type */
  1479. DRM_XE_OBSERVATION_TYPE_OA,
  1480. /** @DRM_XE_OBSERVATION_TYPE_EU_STALL: EU stall sampling observation stream type */
  1481. DRM_XE_OBSERVATION_TYPE_EU_STALL,
  1482. };
  1483. /**
  1484. * enum drm_xe_observation_op - Observation stream ops
  1485. */
  1486. enum drm_xe_observation_op {
  1487. /** @DRM_XE_OBSERVATION_OP_STREAM_OPEN: Open an observation stream */
  1488. DRM_XE_OBSERVATION_OP_STREAM_OPEN,
  1489. /** @DRM_XE_OBSERVATION_OP_ADD_CONFIG: Add observation stream config */
  1490. DRM_XE_OBSERVATION_OP_ADD_CONFIG,
  1491. /** @DRM_XE_OBSERVATION_OP_REMOVE_CONFIG: Remove observation stream config */
  1492. DRM_XE_OBSERVATION_OP_REMOVE_CONFIG,
  1493. };
  1494. /**
  1495. * struct drm_xe_observation_param - Input of &DRM_XE_OBSERVATION
  1496. *
  1497. * The observation layer enables multiplexing observation streams of
  1498. * multiple types. The actual params for a particular stream operation are
  1499. * supplied via the @param pointer (use __copy_from_user to get these
  1500. * params).
  1501. */
  1502. struct drm_xe_observation_param {
  1503. /** @extensions: Pointer to the first extension struct, if any */
  1504. __u64 extensions;
  1505. /** @observation_type: observation stream type, of enum @drm_xe_observation_type */
  1506. __u64 observation_type;
  1507. /** @observation_op: observation stream op, of enum @drm_xe_observation_op */
  1508. __u64 observation_op;
  1509. /** @param: Pointer to actual stream params */
  1510. __u64 param;
  1511. };
  1512. /**
  1513. * enum drm_xe_observation_ioctls - Observation stream fd ioctl's
  1514. *
  1515. * Information exchanged between userspace and kernel for observation fd
  1516. * ioctl's is stream type specific
  1517. */
  1518. enum drm_xe_observation_ioctls {
  1519. /** @DRM_XE_OBSERVATION_IOCTL_ENABLE: Enable data capture for an observation stream */
  1520. DRM_XE_OBSERVATION_IOCTL_ENABLE = _IO('i', 0x0),
  1521. /** @DRM_XE_OBSERVATION_IOCTL_DISABLE: Disable data capture for a observation stream */
  1522. DRM_XE_OBSERVATION_IOCTL_DISABLE = _IO('i', 0x1),
  1523. /** @DRM_XE_OBSERVATION_IOCTL_CONFIG: Change observation stream configuration */
  1524. DRM_XE_OBSERVATION_IOCTL_CONFIG = _IO('i', 0x2),
  1525. /** @DRM_XE_OBSERVATION_IOCTL_STATUS: Return observation stream status */
  1526. DRM_XE_OBSERVATION_IOCTL_STATUS = _IO('i', 0x3),
  1527. /** @DRM_XE_OBSERVATION_IOCTL_INFO: Return observation stream info */
  1528. DRM_XE_OBSERVATION_IOCTL_INFO = _IO('i', 0x4),
  1529. };
  1530. /**
  1531. * enum drm_xe_oa_unit_type - OA unit types
  1532. */
  1533. enum drm_xe_oa_unit_type {
  1534. /**
  1535. * @DRM_XE_OA_UNIT_TYPE_OAG: OAG OA unit. OAR/OAC are considered
  1536. * sub-types of OAG. For OAR/OAC, use OAG.
  1537. */
  1538. DRM_XE_OA_UNIT_TYPE_OAG,
  1539. /** @DRM_XE_OA_UNIT_TYPE_OAM: OAM OA unit */
  1540. DRM_XE_OA_UNIT_TYPE_OAM,
  1541. /** @DRM_XE_OA_UNIT_TYPE_OAM_SAG: OAM_SAG OA unit */
  1542. DRM_XE_OA_UNIT_TYPE_OAM_SAG,
  1543. /** @DRM_XE_OA_UNIT_TYPE_MERT: MERT OA unit */
  1544. DRM_XE_OA_UNIT_TYPE_MERT,
  1545. };
  1546. /**
  1547. * struct drm_xe_oa_unit - describe OA unit
  1548. */
  1549. struct drm_xe_oa_unit {
  1550. /** @extensions: Pointer to the first extension struct, if any */
  1551. __u64 extensions;
  1552. /** @oa_unit_id: OA unit ID */
  1553. __u32 oa_unit_id;
  1554. /** @oa_unit_type: OA unit type of @drm_xe_oa_unit_type */
  1555. __u32 oa_unit_type;
  1556. /** @capabilities: OA capabilities bit-mask */
  1557. __u64 capabilities;
  1558. #define DRM_XE_OA_CAPS_BASE (1 << 0)
  1559. #define DRM_XE_OA_CAPS_SYNCS (1 << 1)
  1560. #define DRM_XE_OA_CAPS_OA_BUFFER_SIZE (1 << 2)
  1561. #define DRM_XE_OA_CAPS_WAIT_NUM_REPORTS (1 << 3)
  1562. #define DRM_XE_OA_CAPS_OAM (1 << 4)
  1563. #define DRM_XE_OA_CAPS_OA_UNIT_GT_ID (1 << 5)
  1564. /** @oa_timestamp_freq: OA timestamp freq */
  1565. __u64 oa_timestamp_freq;
  1566. /** @gt_id: gt id for this OA unit */
  1567. __u16 gt_id;
  1568. /** @reserved1: MBZ */
  1569. __u16 reserved1[3];
  1570. /** @reserved: MBZ */
  1571. __u64 reserved[3];
  1572. /** @num_engines: number of engines in @eci array */
  1573. __u64 num_engines;
  1574. /** @eci: engines attached to this OA unit */
  1575. struct drm_xe_engine_class_instance eci[];
  1576. };
  1577. /**
  1578. * struct drm_xe_query_oa_units - describe OA units
  1579. *
  1580. * If a query is made with a struct drm_xe_device_query where .query
  1581. * is equal to DRM_XE_DEVICE_QUERY_OA_UNITS, then the reply uses struct
  1582. * drm_xe_query_oa_units in .data.
  1583. *
  1584. * OA unit properties for all OA units can be accessed using a code block
  1585. * such as the one below:
  1586. *
  1587. * .. code-block:: C
  1588. *
  1589. * struct drm_xe_query_oa_units *qoa;
  1590. * struct drm_xe_oa_unit *oau;
  1591. * u8 *poau;
  1592. *
  1593. * // malloc qoa and issue DRM_XE_DEVICE_QUERY_OA_UNITS. Then:
  1594. * poau = (u8 *)&qoa->oa_units[0];
  1595. * for (int i = 0; i < qoa->num_oa_units; i++) {
  1596. * oau = (struct drm_xe_oa_unit *)poau;
  1597. * // Access 'struct drm_xe_oa_unit' fields here
  1598. * poau += sizeof(*oau) + oau->num_engines * sizeof(oau->eci[0]);
  1599. * }
  1600. */
  1601. struct drm_xe_query_oa_units {
  1602. /** @extensions: Pointer to the first extension struct, if any */
  1603. __u64 extensions;
  1604. /** @num_oa_units: number of OA units returned in oau[] */
  1605. __u32 num_oa_units;
  1606. /** @pad: MBZ */
  1607. __u32 pad;
  1608. /**
  1609. * @oa_units: struct @drm_xe_oa_unit array returned for this device.
  1610. * Written below as a u64 array to avoid problems with nested flexible
  1611. * arrays with some compilers
  1612. */
  1613. __u64 oa_units[];
  1614. };
  1615. /**
  1616. * enum drm_xe_oa_format_type - OA format types as specified in PRM/Bspec
  1617. * 52198/60942
  1618. */
  1619. enum drm_xe_oa_format_type {
  1620. /** @DRM_XE_OA_FMT_TYPE_OAG: OAG report format */
  1621. DRM_XE_OA_FMT_TYPE_OAG,
  1622. /** @DRM_XE_OA_FMT_TYPE_OAR: OAR report format */
  1623. DRM_XE_OA_FMT_TYPE_OAR,
  1624. /** @DRM_XE_OA_FMT_TYPE_OAM: OAM report format */
  1625. DRM_XE_OA_FMT_TYPE_OAM,
  1626. /** @DRM_XE_OA_FMT_TYPE_OAC: OAC report format */
  1627. DRM_XE_OA_FMT_TYPE_OAC,
  1628. /** @DRM_XE_OA_FMT_TYPE_OAM_MPEC: OAM SAMEDIA or OAM MPEC report format */
  1629. DRM_XE_OA_FMT_TYPE_OAM_MPEC,
  1630. /** @DRM_XE_OA_FMT_TYPE_PEC: PEC report format */
  1631. DRM_XE_OA_FMT_TYPE_PEC,
  1632. };
  1633. /**
  1634. * enum drm_xe_oa_property_id - OA stream property id's
  1635. *
  1636. * Stream params are specified as a chain of @drm_xe_ext_set_property
  1637. * struct's, with @property values from enum @drm_xe_oa_property_id and
  1638. * @drm_xe_user_extension base.name set to @DRM_XE_OA_EXTENSION_SET_PROPERTY.
  1639. * @param field in struct @drm_xe_observation_param points to the first
  1640. * @drm_xe_ext_set_property struct.
  1641. *
  1642. * Exactly the same mechanism is also used for stream reconfiguration using the
  1643. * @DRM_XE_OBSERVATION_IOCTL_CONFIG observation stream fd ioctl, though only a
  1644. * subset of properties below can be specified for stream reconfiguration.
  1645. */
  1646. enum drm_xe_oa_property_id {
  1647. #define DRM_XE_OA_EXTENSION_SET_PROPERTY 0
  1648. /**
  1649. * @DRM_XE_OA_PROPERTY_OA_UNIT_ID: ID of the OA unit on which to open
  1650. * the OA stream, see @oa_unit_id in 'struct
  1651. * drm_xe_query_oa_units'. Defaults to 0 if not provided.
  1652. */
  1653. DRM_XE_OA_PROPERTY_OA_UNIT_ID = 1,
  1654. /**
  1655. * @DRM_XE_OA_PROPERTY_SAMPLE_OA: A value of 1 requests inclusion of raw
  1656. * OA unit reports or stream samples in a global buffer attached to an
  1657. * OA unit.
  1658. */
  1659. DRM_XE_OA_PROPERTY_SAMPLE_OA,
  1660. /**
  1661. * @DRM_XE_OA_PROPERTY_OA_METRIC_SET: OA metrics defining contents of OA
  1662. * reports, previously added via @DRM_XE_OBSERVATION_OP_ADD_CONFIG.
  1663. */
  1664. DRM_XE_OA_PROPERTY_OA_METRIC_SET,
  1665. /** @DRM_XE_OA_PROPERTY_OA_FORMAT: OA counter report format */
  1666. DRM_XE_OA_PROPERTY_OA_FORMAT,
  1667. /*
  1668. * OA_FORMAT's are specified the same way as in PRM/Bspec 52198/60942,
  1669. * in terms of the following quantities: a. enum @drm_xe_oa_format_type
  1670. * b. Counter select c. Counter size and d. BC report. Also refer to the
  1671. * oa_formats array in drivers/gpu/drm/xe/xe_oa.c.
  1672. */
  1673. #define DRM_XE_OA_FORMAT_MASK_FMT_TYPE (0xffu << 0)
  1674. #define DRM_XE_OA_FORMAT_MASK_COUNTER_SEL (0xffu << 8)
  1675. #define DRM_XE_OA_FORMAT_MASK_COUNTER_SIZE (0xffu << 16)
  1676. #define DRM_XE_OA_FORMAT_MASK_BC_REPORT (0xffu << 24)
  1677. /**
  1678. * @DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT: Requests periodic OA unit
  1679. * sampling with sampling frequency proportional to 2^(period_exponent + 1)
  1680. */
  1681. DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT,
  1682. /**
  1683. * @DRM_XE_OA_PROPERTY_OA_DISABLED: A value of 1 will open the OA
  1684. * stream in a DISABLED state (see @DRM_XE_OBSERVATION_IOCTL_ENABLE).
  1685. */
  1686. DRM_XE_OA_PROPERTY_OA_DISABLED,
  1687. /**
  1688. * @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID: Open the stream for a specific
  1689. * @exec_queue_id. OA queries can be executed on this exec queue.
  1690. */
  1691. DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID,
  1692. /**
  1693. * @DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE: Optional engine instance to
  1694. * pass along with @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID or will default to 0.
  1695. */
  1696. DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE,
  1697. /**
  1698. * @DRM_XE_OA_PROPERTY_NO_PREEMPT: Allow preemption and timeslicing
  1699. * to be disabled for the stream exec queue.
  1700. */
  1701. DRM_XE_OA_PROPERTY_NO_PREEMPT,
  1702. /**
  1703. * @DRM_XE_OA_PROPERTY_NUM_SYNCS: Number of syncs in the sync array
  1704. * specified in @DRM_XE_OA_PROPERTY_SYNCS
  1705. */
  1706. DRM_XE_OA_PROPERTY_NUM_SYNCS,
  1707. /**
  1708. * @DRM_XE_OA_PROPERTY_SYNCS: Pointer to struct @drm_xe_sync array
  1709. * with array size specified via @DRM_XE_OA_PROPERTY_NUM_SYNCS. OA
  1710. * configuration will wait till input fences signal. Output fences
  1711. * will signal after the new OA configuration takes effect. For
  1712. * @DRM_XE_SYNC_TYPE_USER_FENCE, @addr is a user pointer, similar
  1713. * to the VM bind case.
  1714. */
  1715. DRM_XE_OA_PROPERTY_SYNCS,
  1716. /**
  1717. * @DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE: Size of OA buffer to be
  1718. * allocated by the driver in bytes. Supported sizes are powers of
  1719. * 2 from 128 KiB to 128 MiB. When not specified, a 16 MiB OA
  1720. * buffer is allocated by default.
  1721. */
  1722. DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE,
  1723. /**
  1724. * @DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS: Number of reports to wait
  1725. * for before unblocking poll or read
  1726. */
  1727. DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS,
  1728. };
  1729. /**
  1730. * struct drm_xe_oa_config - OA metric configuration
  1731. *
  1732. * Multiple OA configs can be added using @DRM_XE_OBSERVATION_OP_ADD_CONFIG. A
  1733. * particular config can be specified when opening an OA stream using
  1734. * @DRM_XE_OA_PROPERTY_OA_METRIC_SET property.
  1735. */
  1736. struct drm_xe_oa_config {
  1737. /** @extensions: Pointer to the first extension struct, if any */
  1738. __u64 extensions;
  1739. /** @uuid: String formatted like "%\08x-%\04x-%\04x-%\04x-%\012x" */
  1740. char uuid[36];
  1741. /** @n_regs: Number of regs in @regs_ptr */
  1742. __u32 n_regs;
  1743. /**
  1744. * @regs_ptr: Pointer to (register address, value) pairs for OA config
  1745. * registers. Expected length of buffer is: (2 * sizeof(u32) * @n_regs).
  1746. */
  1747. __u64 regs_ptr;
  1748. };
  1749. /**
  1750. * struct drm_xe_oa_stream_status - OA stream status returned from
  1751. * @DRM_XE_OBSERVATION_IOCTL_STATUS observation stream fd ioctl. Userspace can
  1752. * call the ioctl to query stream status in response to EIO errno from
  1753. * observation fd read().
  1754. */
  1755. struct drm_xe_oa_stream_status {
  1756. /** @extensions: Pointer to the first extension struct, if any */
  1757. __u64 extensions;
  1758. /** @oa_status: OA stream status (see Bspec 46717/61226) */
  1759. __u64 oa_status;
  1760. #define DRM_XE_OASTATUS_MMIO_TRG_Q_FULL (1 << 3)
  1761. #define DRM_XE_OASTATUS_COUNTER_OVERFLOW (1 << 2)
  1762. #define DRM_XE_OASTATUS_BUFFER_OVERFLOW (1 << 1)
  1763. #define DRM_XE_OASTATUS_REPORT_LOST (1 << 0)
  1764. /** @reserved: reserved for future use */
  1765. __u64 reserved[3];
  1766. };
  1767. /**
  1768. * struct drm_xe_oa_stream_info - OA stream info returned from
  1769. * @DRM_XE_OBSERVATION_IOCTL_INFO observation stream fd ioctl
  1770. */
  1771. struct drm_xe_oa_stream_info {
  1772. /** @extensions: Pointer to the first extension struct, if any */
  1773. __u64 extensions;
  1774. /** @oa_buf_size: OA buffer size */
  1775. __u64 oa_buf_size;
  1776. /** @reserved: reserved for future use */
  1777. __u64 reserved[3];
  1778. };
  1779. /**
  1780. * enum drm_xe_pxp_session_type - Supported PXP session types.
  1781. *
  1782. * We currently only support HWDRM sessions, which are used for protected
  1783. * content that ends up being displayed, but the HW supports multiple types, so
  1784. * we might extend support in the future.
  1785. */
  1786. enum drm_xe_pxp_session_type {
  1787. /** @DRM_XE_PXP_TYPE_NONE: PXP not used */
  1788. DRM_XE_PXP_TYPE_NONE = 0,
  1789. /**
  1790. * @DRM_XE_PXP_TYPE_HWDRM: HWDRM sessions are used for content that ends
  1791. * up on the display.
  1792. */
  1793. DRM_XE_PXP_TYPE_HWDRM = 1,
  1794. };
  1795. /* ID of the protected content session managed by Xe when PXP is active */
  1796. #define DRM_XE_PXP_HWDRM_DEFAULT_SESSION 0xf
  1797. /**
  1798. * enum drm_xe_eu_stall_property_id - EU stall sampling input property ids.
  1799. *
  1800. * These properties are passed to the driver at open as a chain of
  1801. * @drm_xe_ext_set_property structures with @property set to these
  1802. * properties' enums and @value set to the corresponding values of these
  1803. * properties. @drm_xe_user_extension base.name should be set to
  1804. * @DRM_XE_EU_STALL_EXTENSION_SET_PROPERTY.
  1805. *
  1806. * With the file descriptor obtained from open, user space must enable
  1807. * the EU stall stream fd with @DRM_XE_OBSERVATION_IOCTL_ENABLE before
  1808. * calling read(). EIO errno from read() indicates HW dropped data
  1809. * due to full buffer.
  1810. */
  1811. enum drm_xe_eu_stall_property_id {
  1812. #define DRM_XE_EU_STALL_EXTENSION_SET_PROPERTY 0
  1813. /**
  1814. * @DRM_XE_EU_STALL_PROP_GT_ID: @gt_id of the GT on which
  1815. * EU stall data will be captured.
  1816. */
  1817. DRM_XE_EU_STALL_PROP_GT_ID = 1,
  1818. /**
  1819. * @DRM_XE_EU_STALL_PROP_SAMPLE_RATE: Sampling rate in
  1820. * GPU cycles from @sampling_rates in struct @drm_xe_query_eu_stall
  1821. */
  1822. DRM_XE_EU_STALL_PROP_SAMPLE_RATE,
  1823. /**
  1824. * @DRM_XE_EU_STALL_PROP_WAIT_NUM_REPORTS: Minimum number of
  1825. * EU stall data reports to be present in the kernel buffer
  1826. * before unblocking a blocked poll or read.
  1827. */
  1828. DRM_XE_EU_STALL_PROP_WAIT_NUM_REPORTS,
  1829. };
  1830. /**
  1831. * struct drm_xe_query_eu_stall - Information about EU stall sampling.
  1832. *
  1833. * If a query is made with a struct @drm_xe_device_query where .query
  1834. * is equal to @DRM_XE_DEVICE_QUERY_EU_STALL, then the reply uses
  1835. * struct @drm_xe_query_eu_stall in .data.
  1836. */
  1837. struct drm_xe_query_eu_stall {
  1838. /** @extensions: Pointer to the first extension struct, if any */
  1839. __u64 extensions;
  1840. /** @capabilities: EU stall capabilities bit-mask */
  1841. __u64 capabilities;
  1842. #define DRM_XE_EU_STALL_CAPS_BASE (1 << 0)
  1843. /** @record_size: size of each EU stall data record */
  1844. __u64 record_size;
  1845. /** @per_xecore_buf_size: internal per XeCore buffer size */
  1846. __u64 per_xecore_buf_size;
  1847. /** @reserved: Reserved */
  1848. __u64 reserved[5];
  1849. /** @num_sampling_rates: Number of sampling rates in @sampling_rates array */
  1850. __u64 num_sampling_rates;
  1851. /**
  1852. * @sampling_rates: Flexible array of sampling rates
  1853. * sorted in the fastest to slowest order.
  1854. * Sampling rates are specified in GPU clock cycles.
  1855. */
  1856. __u64 sampling_rates[];
  1857. };
  1858. /**
  1859. * struct drm_xe_madvise - Input of &DRM_IOCTL_XE_MADVISE
  1860. *
  1861. * This structure is used to set memory attributes for a virtual address range
  1862. * in a VM. The type of attribute is specified by @type, and the corresponding
  1863. * union member is used to provide additional parameters for @type.
  1864. *
  1865. * Supported attribute types:
  1866. * - DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC: Set preferred memory location.
  1867. * - DRM_XE_MEM_RANGE_ATTR_ATOMIC: Set atomic access policy.
  1868. * - DRM_XE_MEM_RANGE_ATTR_PAT: Set page attribute table index.
  1869. *
  1870. * Example:
  1871. *
  1872. * .. code-block:: C
  1873. *
  1874. * struct drm_xe_madvise madvise = {
  1875. * .vm_id = vm_id,
  1876. * .start = 0x100000,
  1877. * .range = 0x2000,
  1878. * .type = DRM_XE_MEM_RANGE_ATTR_ATOMIC,
  1879. * .atomic_val = DRM_XE_ATOMIC_DEVICE,
  1880. * };
  1881. *
  1882. * ioctl(fd, DRM_IOCTL_XE_MADVISE, &madvise);
  1883. *
  1884. */
  1885. struct drm_xe_madvise {
  1886. /** @extensions: Pointer to the first extension struct, if any */
  1887. __u64 extensions;
  1888. /** @start: start of the virtual address range */
  1889. __u64 start;
  1890. /** @range: size of the virtual address range */
  1891. __u64 range;
  1892. /** @vm_id: vm_id of the virtual range */
  1893. __u32 vm_id;
  1894. #define DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC 0
  1895. #define DRM_XE_MEM_RANGE_ATTR_ATOMIC 1
  1896. #define DRM_XE_MEM_RANGE_ATTR_PAT 2
  1897. /** @type: type of attribute */
  1898. __u32 type;
  1899. union {
  1900. /**
  1901. * @preferred_mem_loc: preferred memory location
  1902. *
  1903. * Used when @type == DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC
  1904. *
  1905. * Supported values for @preferred_mem_loc.devmem_fd:
  1906. * - DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE: set vram of fault tile as preferred loc
  1907. * - DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM: set smem as preferred loc
  1908. *
  1909. * Supported values for @preferred_mem_loc.migration_policy:
  1910. * - DRM_XE_MIGRATE_ALL_PAGES
  1911. * - DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES
  1912. */
  1913. struct {
  1914. #define DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE 0
  1915. #define DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM -1
  1916. /**
  1917. * @preferred_mem_loc.devmem_fd:
  1918. * Device file-descriptor of the device where the
  1919. * preferred memory is located, or one of the
  1920. * above special values. Please also see
  1921. * @preferred_mem_loc.region_instance below.
  1922. */
  1923. __u32 devmem_fd;
  1924. #define DRM_XE_MIGRATE_ALL_PAGES 0
  1925. #define DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES 1
  1926. /** @preferred_mem_loc.migration_policy: Page migration policy */
  1927. __u16 migration_policy;
  1928. /**
  1929. * @preferred_mem_loc.region_instance : Region instance.
  1930. * MBZ if @devmem_fd <= &DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE.
  1931. * Otherwise should point to the desired device
  1932. * VRAM instance of the device indicated by
  1933. * @preferred_mem_loc.devmem_fd.
  1934. */
  1935. __u16 region_instance;
  1936. /** @preferred_mem_loc.reserved : Reserved */
  1937. __u64 reserved;
  1938. } preferred_mem_loc;
  1939. /**
  1940. * @atomic: Atomic access policy
  1941. *
  1942. * Used when @type == DRM_XE_MEM_RANGE_ATTR_ATOMIC.
  1943. *
  1944. * Supported values for @atomic.val:
  1945. * - DRM_XE_ATOMIC_UNDEFINED: Undefined or default behaviour.
  1946. * Support both GPU and CPU atomic operations for system allocator.
  1947. * Support GPU atomic operations for normal(bo) allocator.
  1948. * - DRM_XE_ATOMIC_DEVICE: Support GPU atomic operations.
  1949. * - DRM_XE_ATOMIC_GLOBAL: Support both GPU and CPU atomic operations.
  1950. * - DRM_XE_ATOMIC_CPU: Support CPU atomic only, no GPU atomics supported.
  1951. */
  1952. struct {
  1953. #define DRM_XE_ATOMIC_UNDEFINED 0
  1954. #define DRM_XE_ATOMIC_DEVICE 1
  1955. #define DRM_XE_ATOMIC_GLOBAL 2
  1956. #define DRM_XE_ATOMIC_CPU 3
  1957. /** @atomic.val: value of atomic operation */
  1958. __u32 val;
  1959. /** @atomic.pad: MBZ */
  1960. __u32 pad;
  1961. /** @atomic.reserved: Reserved */
  1962. __u64 reserved;
  1963. } atomic;
  1964. /**
  1965. * @pat_index: Page attribute table index
  1966. *
  1967. * Used when @type == DRM_XE_MEM_RANGE_ATTR_PAT.
  1968. */
  1969. struct {
  1970. /** @pat_index.val: PAT index value */
  1971. __u32 val;
  1972. /** @pat_index.pad: MBZ */
  1973. __u32 pad;
  1974. /** @pat_index.reserved: Reserved */
  1975. __u64 reserved;
  1976. } pat_index;
  1977. };
  1978. /** @reserved: Reserved */
  1979. __u64 reserved[2];
  1980. };
  1981. /**
  1982. * struct drm_xe_mem_range_attr - Output of &DRM_IOCTL_XE_VM_QUERY_MEM_RANGES_ATTRS
  1983. *
  1984. * This structure is provided by userspace and filled by KMD in response to the
  1985. * DRM_IOCTL_XE_VM_QUERY_MEM_RANGES_ATTRS ioctl. It describes memory attributes of
  1986. * a memory ranges within a user specified address range in a VM.
  1987. *
  1988. * The structure includes information such as atomic access policy,
  1989. * page attribute table (PAT) index, and preferred memory location.
  1990. * Userspace allocates an array of these structures and passes a pointer to the
  1991. * ioctl to retrieve attributes for each memory ranges
  1992. *
  1993. * @extensions: Pointer to the first extension struct, if any
  1994. * @start: Start address of the memory range
  1995. * @end: End address of the virtual memory range
  1996. *
  1997. */
  1998. struct drm_xe_mem_range_attr {
  1999. /** @extensions: Pointer to the first extension struct, if any */
  2000. __u64 extensions;
  2001. /** @start: start of the memory range */
  2002. __u64 start;
  2003. /** @end: end of the memory range */
  2004. __u64 end;
  2005. /** @preferred_mem_loc: preferred memory location */
  2006. struct {
  2007. /** @preferred_mem_loc.devmem_fd: fd for preferred loc */
  2008. __u32 devmem_fd;
  2009. /** @preferred_mem_loc.migration_policy: Page migration policy */
  2010. __u32 migration_policy;
  2011. } preferred_mem_loc;
  2012. /** @atomic: Atomic access policy */
  2013. struct {
  2014. /** @atomic.val: atomic attribute */
  2015. __u32 val;
  2016. /** @atomic.reserved: Reserved */
  2017. __u32 reserved;
  2018. } atomic;
  2019. /** @pat_index: Page attribute table index */
  2020. struct {
  2021. /** @pat_index.val: PAT index */
  2022. __u32 val;
  2023. /** @pat_index.reserved: Reserved */
  2024. __u32 reserved;
  2025. } pat_index;
  2026. /** @reserved: Reserved */
  2027. __u64 reserved[2];
  2028. };
  2029. /**
  2030. * struct drm_xe_vm_query_mem_range_attr - Input of &DRM_IOCTL_XE_VM_QUERY_MEM_ATTRIBUTES
  2031. *
  2032. * This structure is used to query memory attributes of memory regions
  2033. * within a user specified address range in a VM. It provides detailed
  2034. * information about each memory range, including atomic access policy,
  2035. * page attribute table (PAT) index, and preferred memory location.
  2036. *
  2037. * Userspace first calls the ioctl with @num_mem_ranges = 0,
  2038. * @sizeof_mem_ranges_attr = 0 and @vector_of_vma_mem_attr = NULL to retrieve
  2039. * the number of memory regions and size of each memory range attribute.
  2040. * Then, it allocates a buffer of that size and calls the ioctl again to fill
  2041. * the buffer with memory range attributes.
  2042. *
  2043. * If second call fails with -ENOSPC, it means memory ranges changed between
  2044. * first call and now, retry IOCTL again with @num_mem_ranges = 0,
  2045. * @sizeof_mem_ranges_attr = 0 and @vector_of_vma_mem_attr = NULL followed by
  2046. * Second ioctl call.
  2047. *
  2048. * Example:
  2049. *
  2050. * .. code-block:: C
  2051. *
  2052. * struct drm_xe_vm_query_mem_range_attr query = {
  2053. * .vm_id = vm_id,
  2054. * .start = 0x100000,
  2055. * .range = 0x2000,
  2056. * };
  2057. *
  2058. * // First ioctl call to get num of mem regions and sizeof each attribute
  2059. * ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS, &query);
  2060. *
  2061. * // Allocate buffer for the memory region attributes
  2062. * void *ptr = malloc(query.num_mem_ranges * query.sizeof_mem_range_attr);
  2063. * void *ptr_start = ptr;
  2064. *
  2065. * query.vector_of_mem_attr = (uintptr_t)ptr;
  2066. *
  2067. * // Second ioctl call to actually fill the memory attributes
  2068. * ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS, &query);
  2069. *
  2070. * // Iterate over the returned memory region attributes
  2071. * for (unsigned int i = 0; i < query.num_mem_ranges; ++i) {
  2072. * struct drm_xe_mem_range_attr *attr = (struct drm_xe_mem_range_attr *)ptr;
  2073. *
  2074. * // Do something with attr
  2075. *
  2076. * // Move pointer by one entry
  2077. * ptr += query.sizeof_mem_range_attr;
  2078. * }
  2079. *
  2080. * free(ptr_start);
  2081. */
  2082. struct drm_xe_vm_query_mem_range_attr {
  2083. /** @extensions: Pointer to the first extension struct, if any */
  2084. __u64 extensions;
  2085. /** @vm_id: vm_id of the virtual range */
  2086. __u32 vm_id;
  2087. /** @num_mem_ranges: number of mem_ranges in range */
  2088. __u32 num_mem_ranges;
  2089. /** @start: start of the virtual address range */
  2090. __u64 start;
  2091. /** @range: size of the virtual address range */
  2092. __u64 range;
  2093. /** @sizeof_mem_range_attr: size of struct drm_xe_mem_range_attr */
  2094. __u64 sizeof_mem_range_attr;
  2095. /** @vector_of_mem_attr: userptr to array of struct drm_xe_mem_range_attr */
  2096. __u64 vector_of_mem_attr;
  2097. /** @reserved: Reserved */
  2098. __u64 reserved[2];
  2099. };
  2100. /**
  2101. * struct drm_xe_exec_queue_set_property - exec queue set property
  2102. *
  2103. * Sets execution queue properties dynamically.
  2104. * Currently only %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY
  2105. * property can be dynamically set.
  2106. */
  2107. struct drm_xe_exec_queue_set_property {
  2108. /** @extensions: Pointer to the first extension struct, if any */
  2109. __u64 extensions;
  2110. /** @exec_queue_id: Exec queue ID */
  2111. __u32 exec_queue_id;
  2112. /** @property: property to set */
  2113. __u32 property;
  2114. /** @value: property value */
  2115. __u64 value;
  2116. /** @reserved: Reserved */
  2117. __u64 reserved[2];
  2118. };
  2119. #if defined(__cplusplus)
  2120. }
  2121. #endif
  2122. #endif /* _XE_DRM_H_ */