amdgpu_drm.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. /* amdgpu_drm.h -- Public header for the amdgpu driver -*- linux-c -*-
  2. *
  3. * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
  4. * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
  5. * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
  6. * Copyright 2014 Advanced Micro Devices, Inc.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Authors:
  27. * Kevin E. Martin <martin@valinux.com>
  28. * Gareth Hughes <gareth@valinux.com>
  29. * Keith Whitwell <keith@tungstengraphics.com>
  30. */
  31. #ifndef __AMDGPU_DRM_H__
  32. #define __AMDGPU_DRM_H__
  33. #include "drm.h"
  34. #if defined(__cplusplus)
  35. extern "C" {
  36. #endif
  37. #define DRM_AMDGPU_GEM_CREATE 0x00
  38. #define DRM_AMDGPU_GEM_MMAP 0x01
  39. #define DRM_AMDGPU_CTX 0x02
  40. #define DRM_AMDGPU_BO_LIST 0x03
  41. #define DRM_AMDGPU_CS 0x04
  42. #define DRM_AMDGPU_INFO 0x05
  43. #define DRM_AMDGPU_GEM_METADATA 0x06
  44. #define DRM_AMDGPU_GEM_WAIT_IDLE 0x07
  45. #define DRM_AMDGPU_GEM_VA 0x08
  46. #define DRM_AMDGPU_WAIT_CS 0x09
  47. #define DRM_AMDGPU_GEM_OP 0x10
  48. #define DRM_AMDGPU_GEM_USERPTR 0x11
  49. #define DRM_AMDGPU_WAIT_FENCES 0x12
  50. #define DRM_AMDGPU_VM 0x13
  51. #define DRM_AMDGPU_FENCE_TO_HANDLE 0x14
  52. #define DRM_AMDGPU_SCHED 0x15
  53. #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  54. #define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
  55. #define DRM_IOCTL_AMDGPU_CTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)
  56. #define DRM_IOCTL_AMDGPU_BO_LIST DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_BO_LIST, union drm_amdgpu_bo_list)
  57. #define DRM_IOCTL_AMDGPU_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CS, union drm_amdgpu_cs)
  58. #define DRM_IOCTL_AMDGPU_INFO DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_INFO, struct drm_amdgpu_info)
  59. #define DRM_IOCTL_AMDGPU_GEM_METADATA DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_METADATA, struct drm_amdgpu_gem_metadata)
  60. #define DRM_IOCTL_AMDGPU_GEM_WAIT_IDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_WAIT_IDLE, union drm_amdgpu_gem_wait_idle)
  61. #define DRM_IOCTL_AMDGPU_GEM_VA DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_VA, struct drm_amdgpu_gem_va)
  62. #define DRM_IOCTL_AMDGPU_WAIT_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_CS, union drm_amdgpu_wait_cs)
  63. #define DRM_IOCTL_AMDGPU_GEM_OP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_OP, struct drm_amdgpu_gem_op)
  64. #define DRM_IOCTL_AMDGPU_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr)
  65. #define DRM_IOCTL_AMDGPU_WAIT_FENCES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_FENCES, union drm_amdgpu_wait_fences)
  66. #define DRM_IOCTL_AMDGPU_VM DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)
  67. #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)
  68. #define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)
  69. /**
  70. * DOC: memory domains
  71. *
  72. * %AMDGPU_GEM_DOMAIN_CPU System memory that is not GPU accessible.
  73. * Memory in this pool could be swapped out to disk if there is pressure.
  74. *
  75. * %AMDGPU_GEM_DOMAIN_GTT GPU accessible system memory, mapped into the
  76. * GPU's virtual address space via gart. Gart memory linearizes non-contiguous
  77. * pages of system memory, allows GPU access system memory in a linezrized
  78. * fashion.
  79. *
  80. * %AMDGPU_GEM_DOMAIN_VRAM Local video memory. For APUs, it is memory
  81. * carved out by the BIOS.
  82. *
  83. * %AMDGPU_GEM_DOMAIN_GDS Global on-chip data storage used to share data
  84. * across shader threads.
  85. *
  86. * %AMDGPU_GEM_DOMAIN_GWS Global wave sync, used to synchronize the
  87. * execution of all the waves on a device.
  88. *
  89. * %AMDGPU_GEM_DOMAIN_OA Ordered append, used by 3D or Compute engines
  90. * for appending data.
  91. */
  92. #define AMDGPU_GEM_DOMAIN_CPU 0x1
  93. #define AMDGPU_GEM_DOMAIN_GTT 0x2
  94. #define AMDGPU_GEM_DOMAIN_VRAM 0x4
  95. #define AMDGPU_GEM_DOMAIN_GDS 0x8
  96. #define AMDGPU_GEM_DOMAIN_GWS 0x10
  97. #define AMDGPU_GEM_DOMAIN_OA 0x20
  98. #define AMDGPU_GEM_DOMAIN_MASK (AMDGPU_GEM_DOMAIN_CPU | \
  99. AMDGPU_GEM_DOMAIN_GTT | \
  100. AMDGPU_GEM_DOMAIN_VRAM | \
  101. AMDGPU_GEM_DOMAIN_GDS | \
  102. AMDGPU_GEM_DOMAIN_GWS | \
  103. AMDGPU_GEM_DOMAIN_OA)
  104. /* Flag that CPU access will be required for the case of VRAM domain */
  105. #define AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED (1 << 0)
  106. /* Flag that CPU access will not work, this VRAM domain is invisible */
  107. #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS (1 << 1)
  108. /* Flag that USWC attributes should be used for GTT */
  109. #define AMDGPU_GEM_CREATE_CPU_GTT_USWC (1 << 2)
  110. /* Flag that the memory should be in VRAM and cleared */
  111. #define AMDGPU_GEM_CREATE_VRAM_CLEARED (1 << 3)
  112. /* Flag that create shadow bo(GTT) while allocating vram bo */
  113. #define AMDGPU_GEM_CREATE_SHADOW (1 << 4)
  114. /* Flag that allocating the BO should use linear VRAM */
  115. #define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS (1 << 5)
  116. /* Flag that BO is always valid in this VM */
  117. #define AMDGPU_GEM_CREATE_VM_ALWAYS_VALID (1 << 6)
  118. /* Flag that BO sharing will be explicitly synchronized */
  119. #define AMDGPU_GEM_CREATE_EXPLICIT_SYNC (1 << 7)
  120. /* Flag that indicates allocating MQD gart on GFX9, where the mtype
  121. * for the second page onward should be set to NC.
  122. */
  123. #define AMDGPU_GEM_CREATE_MQD_GFX9 (1 << 8)
  124. struct drm_amdgpu_gem_create_in {
  125. /** the requested memory size */
  126. __u64 bo_size;
  127. /** physical start_addr alignment in bytes for some HW requirements */
  128. __u64 alignment;
  129. /** the requested memory domains */
  130. __u64 domains;
  131. /** allocation flags */
  132. __u64 domain_flags;
  133. };
  134. struct drm_amdgpu_gem_create_out {
  135. /** returned GEM object handle */
  136. __u32 handle;
  137. __u32 _pad;
  138. };
  139. union drm_amdgpu_gem_create {
  140. struct drm_amdgpu_gem_create_in in;
  141. struct drm_amdgpu_gem_create_out out;
  142. };
  143. /** Opcode to create new residency list. */
  144. #define AMDGPU_BO_LIST_OP_CREATE 0
  145. /** Opcode to destroy previously created residency list */
  146. #define AMDGPU_BO_LIST_OP_DESTROY 1
  147. /** Opcode to update resource information in the list */
  148. #define AMDGPU_BO_LIST_OP_UPDATE 2
  149. struct drm_amdgpu_bo_list_in {
  150. /** Type of operation */
  151. __u32 operation;
  152. /** Handle of list or 0 if we want to create one */
  153. __u32 list_handle;
  154. /** Number of BOs in list */
  155. __u32 bo_number;
  156. /** Size of each element describing BO */
  157. __u32 bo_info_size;
  158. /** Pointer to array describing BOs */
  159. __u64 bo_info_ptr;
  160. };
  161. struct drm_amdgpu_bo_list_entry {
  162. /** Handle of BO */
  163. __u32 bo_handle;
  164. /** New (if specified) BO priority to be used during migration */
  165. __u32 bo_priority;
  166. };
  167. struct drm_amdgpu_bo_list_out {
  168. /** Handle of resource list */
  169. __u32 list_handle;
  170. __u32 _pad;
  171. };
  172. union drm_amdgpu_bo_list {
  173. struct drm_amdgpu_bo_list_in in;
  174. struct drm_amdgpu_bo_list_out out;
  175. };
  176. /* context related */
  177. #define AMDGPU_CTX_OP_ALLOC_CTX 1
  178. #define AMDGPU_CTX_OP_FREE_CTX 2
  179. #define AMDGPU_CTX_OP_QUERY_STATE 3
  180. #define AMDGPU_CTX_OP_QUERY_STATE2 4
  181. /* GPU reset status */
  182. #define AMDGPU_CTX_NO_RESET 0
  183. /* this the context caused it */
  184. #define AMDGPU_CTX_GUILTY_RESET 1
  185. /* some other context caused it */
  186. #define AMDGPU_CTX_INNOCENT_RESET 2
  187. /* unknown cause */
  188. #define AMDGPU_CTX_UNKNOWN_RESET 3
  189. /* indicate gpu reset occured after ctx created */
  190. #define AMDGPU_CTX_QUERY2_FLAGS_RESET (1<<0)
  191. /* indicate vram lost occured after ctx created */
  192. #define AMDGPU_CTX_QUERY2_FLAGS_VRAMLOST (1<<1)
  193. /* indicate some job from this context once cause gpu hang */
  194. #define AMDGPU_CTX_QUERY2_FLAGS_GUILTY (1<<2)
  195. /* Context priority level */
  196. #define AMDGPU_CTX_PRIORITY_UNSET -2048
  197. #define AMDGPU_CTX_PRIORITY_VERY_LOW -1023
  198. #define AMDGPU_CTX_PRIORITY_LOW -512
  199. #define AMDGPU_CTX_PRIORITY_NORMAL 0
  200. /* Selecting a priority above NORMAL requires CAP_SYS_NICE or DRM_MASTER */
  201. #define AMDGPU_CTX_PRIORITY_HIGH 512
  202. #define AMDGPU_CTX_PRIORITY_VERY_HIGH 1023
  203. struct drm_amdgpu_ctx_in {
  204. /** AMDGPU_CTX_OP_* */
  205. __u32 op;
  206. /** For future use, no flags defined so far */
  207. __u32 flags;
  208. __u32 ctx_id;
  209. __s32 priority;
  210. };
  211. union drm_amdgpu_ctx_out {
  212. struct {
  213. __u32 ctx_id;
  214. __u32 _pad;
  215. } alloc;
  216. struct {
  217. /** For future use, no flags defined so far */
  218. __u64 flags;
  219. /** Number of resets caused by this context so far. */
  220. __u32 hangs;
  221. /** Reset status since the last call of the ioctl. */
  222. __u32 reset_status;
  223. } state;
  224. };
  225. union drm_amdgpu_ctx {
  226. struct drm_amdgpu_ctx_in in;
  227. union drm_amdgpu_ctx_out out;
  228. };
  229. /* vm ioctl */
  230. #define AMDGPU_VM_OP_RESERVE_VMID 1
  231. #define AMDGPU_VM_OP_UNRESERVE_VMID 2
  232. struct drm_amdgpu_vm_in {
  233. /** AMDGPU_VM_OP_* */
  234. __u32 op;
  235. __u32 flags;
  236. };
  237. struct drm_amdgpu_vm_out {
  238. /** For future use, no flags defined so far */
  239. __u64 flags;
  240. };
  241. union drm_amdgpu_vm {
  242. struct drm_amdgpu_vm_in in;
  243. struct drm_amdgpu_vm_out out;
  244. };
  245. /* sched ioctl */
  246. #define AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE 1
  247. struct drm_amdgpu_sched_in {
  248. /* AMDGPU_SCHED_OP_* */
  249. __u32 op;
  250. __u32 fd;
  251. __s32 priority;
  252. __u32 flags;
  253. };
  254. union drm_amdgpu_sched {
  255. struct drm_amdgpu_sched_in in;
  256. };
  257. /*
  258. * This is not a reliable API and you should expect it to fail for any
  259. * number of reasons and have fallback path that do not use userptr to
  260. * perform any operation.
  261. */
  262. #define AMDGPU_GEM_USERPTR_READONLY (1 << 0)
  263. #define AMDGPU_GEM_USERPTR_ANONONLY (1 << 1)
  264. #define AMDGPU_GEM_USERPTR_VALIDATE (1 << 2)
  265. #define AMDGPU_GEM_USERPTR_REGISTER (1 << 3)
  266. struct drm_amdgpu_gem_userptr {
  267. __u64 addr;
  268. __u64 size;
  269. /* AMDGPU_GEM_USERPTR_* */
  270. __u32 flags;
  271. /* Resulting GEM handle */
  272. __u32 handle;
  273. };
  274. /* SI-CI-VI: */
  275. /* same meaning as the GB_TILE_MODE and GL_MACRO_TILE_MODE fields */
  276. #define AMDGPU_TILING_ARRAY_MODE_SHIFT 0
  277. #define AMDGPU_TILING_ARRAY_MODE_MASK 0xf
  278. #define AMDGPU_TILING_PIPE_CONFIG_SHIFT 4
  279. #define AMDGPU_TILING_PIPE_CONFIG_MASK 0x1f
  280. #define AMDGPU_TILING_TILE_SPLIT_SHIFT 9
  281. #define AMDGPU_TILING_TILE_SPLIT_MASK 0x7
  282. #define AMDGPU_TILING_MICRO_TILE_MODE_SHIFT 12
  283. #define AMDGPU_TILING_MICRO_TILE_MODE_MASK 0x7
  284. #define AMDGPU_TILING_BANK_WIDTH_SHIFT 15
  285. #define AMDGPU_TILING_BANK_WIDTH_MASK 0x3
  286. #define AMDGPU_TILING_BANK_HEIGHT_SHIFT 17
  287. #define AMDGPU_TILING_BANK_HEIGHT_MASK 0x3
  288. #define AMDGPU_TILING_MACRO_TILE_ASPECT_SHIFT 19
  289. #define AMDGPU_TILING_MACRO_TILE_ASPECT_MASK 0x3
  290. #define AMDGPU_TILING_NUM_BANKS_SHIFT 21
  291. #define AMDGPU_TILING_NUM_BANKS_MASK 0x3
  292. /* GFX9 and later: */
  293. #define AMDGPU_TILING_SWIZZLE_MODE_SHIFT 0
  294. #define AMDGPU_TILING_SWIZZLE_MODE_MASK 0x1f
  295. /* Set/Get helpers for tiling flags. */
  296. #define AMDGPU_TILING_SET(field, value) \
  297. (((__u64)(value) & AMDGPU_TILING_##field##_MASK) << AMDGPU_TILING_##field##_SHIFT)
  298. #define AMDGPU_TILING_GET(value, field) \
  299. (((__u64)(value) >> AMDGPU_TILING_##field##_SHIFT) & AMDGPU_TILING_##field##_MASK)
  300. #define AMDGPU_GEM_METADATA_OP_SET_METADATA 1
  301. #define AMDGPU_GEM_METADATA_OP_GET_METADATA 2
  302. /** The same structure is shared for input/output */
  303. struct drm_amdgpu_gem_metadata {
  304. /** GEM Object handle */
  305. __u32 handle;
  306. /** Do we want get or set metadata */
  307. __u32 op;
  308. struct {
  309. /** For future use, no flags defined so far */
  310. __u64 flags;
  311. /** family specific tiling info */
  312. __u64 tiling_info;
  313. __u32 data_size_bytes;
  314. __u32 data[64];
  315. } data;
  316. };
  317. struct drm_amdgpu_gem_mmap_in {
  318. /** the GEM object handle */
  319. __u32 handle;
  320. __u32 _pad;
  321. };
  322. struct drm_amdgpu_gem_mmap_out {
  323. /** mmap offset from the vma offset manager */
  324. __u64 addr_ptr;
  325. };
  326. union drm_amdgpu_gem_mmap {
  327. struct drm_amdgpu_gem_mmap_in in;
  328. struct drm_amdgpu_gem_mmap_out out;
  329. };
  330. struct drm_amdgpu_gem_wait_idle_in {
  331. /** GEM object handle */
  332. __u32 handle;
  333. /** For future use, no flags defined so far */
  334. __u32 flags;
  335. /** Absolute timeout to wait */
  336. __u64 timeout;
  337. };
  338. struct drm_amdgpu_gem_wait_idle_out {
  339. /** BO status: 0 - BO is idle, 1 - BO is busy */
  340. __u32 status;
  341. /** Returned current memory domain */
  342. __u32 domain;
  343. };
  344. union drm_amdgpu_gem_wait_idle {
  345. struct drm_amdgpu_gem_wait_idle_in in;
  346. struct drm_amdgpu_gem_wait_idle_out out;
  347. };
  348. struct drm_amdgpu_wait_cs_in {
  349. /* Command submission handle
  350. * handle equals 0 means none to wait for
  351. * handle equals ~0ull means wait for the latest sequence number
  352. */
  353. __u64 handle;
  354. /** Absolute timeout to wait */
  355. __u64 timeout;
  356. __u32 ip_type;
  357. __u32 ip_instance;
  358. __u32 ring;
  359. __u32 ctx_id;
  360. };
  361. struct drm_amdgpu_wait_cs_out {
  362. /** CS status: 0 - CS completed, 1 - CS still busy */
  363. __u64 status;
  364. };
  365. union drm_amdgpu_wait_cs {
  366. struct drm_amdgpu_wait_cs_in in;
  367. struct drm_amdgpu_wait_cs_out out;
  368. };
  369. struct drm_amdgpu_fence {
  370. __u32 ctx_id;
  371. __u32 ip_type;
  372. __u32 ip_instance;
  373. __u32 ring;
  374. __u64 seq_no;
  375. };
  376. struct drm_amdgpu_wait_fences_in {
  377. /** This points to uint64_t * which points to fences */
  378. __u64 fences;
  379. __u32 fence_count;
  380. __u32 wait_all;
  381. __u64 timeout_ns;
  382. };
  383. struct drm_amdgpu_wait_fences_out {
  384. __u32 status;
  385. __u32 first_signaled;
  386. };
  387. union drm_amdgpu_wait_fences {
  388. struct drm_amdgpu_wait_fences_in in;
  389. struct drm_amdgpu_wait_fences_out out;
  390. };
  391. #define AMDGPU_GEM_OP_GET_GEM_CREATE_INFO 0
  392. #define AMDGPU_GEM_OP_SET_PLACEMENT 1
  393. /* Sets or returns a value associated with a buffer. */
  394. struct drm_amdgpu_gem_op {
  395. /** GEM object handle */
  396. __u32 handle;
  397. /** AMDGPU_GEM_OP_* */
  398. __u32 op;
  399. /** Input or return value */
  400. __u64 value;
  401. };
  402. #define AMDGPU_VA_OP_MAP 1
  403. #define AMDGPU_VA_OP_UNMAP 2
  404. #define AMDGPU_VA_OP_CLEAR 3
  405. #define AMDGPU_VA_OP_REPLACE 4
  406. /* Delay the page table update till the next CS */
  407. #define AMDGPU_VM_DELAY_UPDATE (1 << 0)
  408. /* Mapping flags */
  409. /* readable mapping */
  410. #define AMDGPU_VM_PAGE_READABLE (1 << 1)
  411. /* writable mapping */
  412. #define AMDGPU_VM_PAGE_WRITEABLE (1 << 2)
  413. /* executable mapping, new for VI */
  414. #define AMDGPU_VM_PAGE_EXECUTABLE (1 << 3)
  415. /* partially resident texture */
  416. #define AMDGPU_VM_PAGE_PRT (1 << 4)
  417. /* MTYPE flags use bit 5 to 8 */
  418. #define AMDGPU_VM_MTYPE_MASK (0xf << 5)
  419. /* Default MTYPE. Pre-AI must use this. Recommended for newer ASICs. */
  420. #define AMDGPU_VM_MTYPE_DEFAULT (0 << 5)
  421. /* Use NC MTYPE instead of default MTYPE */
  422. #define AMDGPU_VM_MTYPE_NC (1 << 5)
  423. /* Use WC MTYPE instead of default MTYPE */
  424. #define AMDGPU_VM_MTYPE_WC (2 << 5)
  425. /* Use CC MTYPE instead of default MTYPE */
  426. #define AMDGPU_VM_MTYPE_CC (3 << 5)
  427. /* Use UC MTYPE instead of default MTYPE */
  428. #define AMDGPU_VM_MTYPE_UC (4 << 5)
  429. struct drm_amdgpu_gem_va {
  430. /** GEM object handle */
  431. __u32 handle;
  432. __u32 _pad;
  433. /** AMDGPU_VA_OP_* */
  434. __u32 operation;
  435. /** AMDGPU_VM_PAGE_* */
  436. __u32 flags;
  437. /** va address to assign . Must be correctly aligned.*/
  438. __u64 va_address;
  439. /** Specify offset inside of BO to assign. Must be correctly aligned.*/
  440. __u64 offset_in_bo;
  441. /** Specify mapping size. Must be correctly aligned. */
  442. __u64 map_size;
  443. };
  444. #define AMDGPU_HW_IP_GFX 0
  445. #define AMDGPU_HW_IP_COMPUTE 1
  446. #define AMDGPU_HW_IP_DMA 2
  447. #define AMDGPU_HW_IP_UVD 3
  448. #define AMDGPU_HW_IP_VCE 4
  449. #define AMDGPU_HW_IP_UVD_ENC 5
  450. #define AMDGPU_HW_IP_VCN_DEC 6
  451. #define AMDGPU_HW_IP_VCN_ENC 7
  452. #define AMDGPU_HW_IP_VCN_JPEG 8
  453. #define AMDGPU_HW_IP_NUM 9
  454. #define AMDGPU_HW_IP_INSTANCE_MAX_COUNT 1
  455. #define AMDGPU_CHUNK_ID_IB 0x01
  456. #define AMDGPU_CHUNK_ID_FENCE 0x02
  457. #define AMDGPU_CHUNK_ID_DEPENDENCIES 0x03
  458. #define AMDGPU_CHUNK_ID_SYNCOBJ_IN 0x04
  459. #define AMDGPU_CHUNK_ID_SYNCOBJ_OUT 0x05
  460. #define AMDGPU_CHUNK_ID_BO_HANDLES 0x06
  461. struct drm_amdgpu_cs_chunk {
  462. __u32 chunk_id;
  463. __u32 length_dw;
  464. __u64 chunk_data;
  465. };
  466. struct drm_amdgpu_cs_in {
  467. /** Rendering context id */
  468. __u32 ctx_id;
  469. /** Handle of resource list associated with CS */
  470. __u32 bo_list_handle;
  471. __u32 num_chunks;
  472. __u32 _pad;
  473. /** this points to __u64 * which point to cs chunks */
  474. __u64 chunks;
  475. };
  476. struct drm_amdgpu_cs_out {
  477. __u64 handle;
  478. };
  479. union drm_amdgpu_cs {
  480. struct drm_amdgpu_cs_in in;
  481. struct drm_amdgpu_cs_out out;
  482. };
  483. /* Specify flags to be used for IB */
  484. /* This IB should be submitted to CE */
  485. #define AMDGPU_IB_FLAG_CE (1<<0)
  486. /* Preamble flag, which means the IB could be dropped if no context switch */
  487. #define AMDGPU_IB_FLAG_PREAMBLE (1<<1)
  488. /* Preempt flag, IB should set Pre_enb bit if PREEMPT flag detected */
  489. #define AMDGPU_IB_FLAG_PREEMPT (1<<2)
  490. /* The IB fence should do the L2 writeback but not invalidate any shader
  491. * caches (L2/vL1/sL1/I$). */
  492. #define AMDGPU_IB_FLAG_TC_WB_NOT_INVALIDATE (1 << 3)
  493. struct drm_amdgpu_cs_chunk_ib {
  494. __u32 _pad;
  495. /** AMDGPU_IB_FLAG_* */
  496. __u32 flags;
  497. /** Virtual address to begin IB execution */
  498. __u64 va_start;
  499. /** Size of submission */
  500. __u32 ib_bytes;
  501. /** HW IP to submit to */
  502. __u32 ip_type;
  503. /** HW IP index of the same type to submit to */
  504. __u32 ip_instance;
  505. /** Ring index to submit to */
  506. __u32 ring;
  507. };
  508. struct drm_amdgpu_cs_chunk_dep {
  509. __u32 ip_type;
  510. __u32 ip_instance;
  511. __u32 ring;
  512. __u32 ctx_id;
  513. __u64 handle;
  514. };
  515. struct drm_amdgpu_cs_chunk_fence {
  516. __u32 handle;
  517. __u32 offset;
  518. };
  519. struct drm_amdgpu_cs_chunk_sem {
  520. __u32 handle;
  521. };
  522. #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ 0
  523. #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD 1
  524. #define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD 2
  525. union drm_amdgpu_fence_to_handle {
  526. struct {
  527. struct drm_amdgpu_fence fence;
  528. __u32 what;
  529. __u32 pad;
  530. } in;
  531. struct {
  532. __u32 handle;
  533. } out;
  534. };
  535. struct drm_amdgpu_cs_chunk_data {
  536. union {
  537. struct drm_amdgpu_cs_chunk_ib ib_data;
  538. struct drm_amdgpu_cs_chunk_fence fence_data;
  539. };
  540. };
  541. /**
  542. * Query h/w info: Flag that this is integrated (a.h.a. fusion) GPU
  543. *
  544. */
  545. #define AMDGPU_IDS_FLAGS_FUSION 0x1
  546. #define AMDGPU_IDS_FLAGS_PREEMPTION 0x2
  547. /* indicate if acceleration can be working */
  548. #define AMDGPU_INFO_ACCEL_WORKING 0x00
  549. /* get the crtc_id from the mode object id? */
  550. #define AMDGPU_INFO_CRTC_FROM_ID 0x01
  551. /* query hw IP info */
  552. #define AMDGPU_INFO_HW_IP_INFO 0x02
  553. /* query hw IP instance count for the specified type */
  554. #define AMDGPU_INFO_HW_IP_COUNT 0x03
  555. /* timestamp for GL_ARB_timer_query */
  556. #define AMDGPU_INFO_TIMESTAMP 0x05
  557. /* Query the firmware version */
  558. #define AMDGPU_INFO_FW_VERSION 0x0e
  559. /* Subquery id: Query VCE firmware version */
  560. #define AMDGPU_INFO_FW_VCE 0x1
  561. /* Subquery id: Query UVD firmware version */
  562. #define AMDGPU_INFO_FW_UVD 0x2
  563. /* Subquery id: Query GMC firmware version */
  564. #define AMDGPU_INFO_FW_GMC 0x03
  565. /* Subquery id: Query GFX ME firmware version */
  566. #define AMDGPU_INFO_FW_GFX_ME 0x04
  567. /* Subquery id: Query GFX PFP firmware version */
  568. #define AMDGPU_INFO_FW_GFX_PFP 0x05
  569. /* Subquery id: Query GFX CE firmware version */
  570. #define AMDGPU_INFO_FW_GFX_CE 0x06
  571. /* Subquery id: Query GFX RLC firmware version */
  572. #define AMDGPU_INFO_FW_GFX_RLC 0x07
  573. /* Subquery id: Query GFX MEC firmware version */
  574. #define AMDGPU_INFO_FW_GFX_MEC 0x08
  575. /* Subquery id: Query SMC firmware version */
  576. #define AMDGPU_INFO_FW_SMC 0x0a
  577. /* Subquery id: Query SDMA firmware version */
  578. #define AMDGPU_INFO_FW_SDMA 0x0b
  579. /* Subquery id: Query PSP SOS firmware version */
  580. #define AMDGPU_INFO_FW_SOS 0x0c
  581. /* Subquery id: Query PSP ASD firmware version */
  582. #define AMDGPU_INFO_FW_ASD 0x0d
  583. /* Subquery id: Query VCN firmware version */
  584. #define AMDGPU_INFO_FW_VCN 0x0e
  585. /* Subquery id: Query GFX RLC SRLC firmware version */
  586. #define AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_CNTL 0x0f
  587. /* Subquery id: Query GFX RLC SRLG firmware version */
  588. #define AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_GPM_MEM 0x10
  589. /* Subquery id: Query GFX RLC SRLS firmware version */
  590. #define AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_SRM_MEM 0x11
  591. /* number of bytes moved for TTM migration */
  592. #define AMDGPU_INFO_NUM_BYTES_MOVED 0x0f
  593. /* the used VRAM size */
  594. #define AMDGPU_INFO_VRAM_USAGE 0x10
  595. /* the used GTT size */
  596. #define AMDGPU_INFO_GTT_USAGE 0x11
  597. /* Information about GDS, etc. resource configuration */
  598. #define AMDGPU_INFO_GDS_CONFIG 0x13
  599. /* Query information about VRAM and GTT domains */
  600. #define AMDGPU_INFO_VRAM_GTT 0x14
  601. /* Query information about register in MMR address space*/
  602. #define AMDGPU_INFO_READ_MMR_REG 0x15
  603. /* Query information about device: rev id, family, etc. */
  604. #define AMDGPU_INFO_DEV_INFO 0x16
  605. /* visible vram usage */
  606. #define AMDGPU_INFO_VIS_VRAM_USAGE 0x17
  607. /* number of TTM buffer evictions */
  608. #define AMDGPU_INFO_NUM_EVICTIONS 0x18
  609. /* Query memory about VRAM and GTT domains */
  610. #define AMDGPU_INFO_MEMORY 0x19
  611. /* Query vce clock table */
  612. #define AMDGPU_INFO_VCE_CLOCK_TABLE 0x1A
  613. /* Query vbios related information */
  614. #define AMDGPU_INFO_VBIOS 0x1B
  615. /* Subquery id: Query vbios size */
  616. #define AMDGPU_INFO_VBIOS_SIZE 0x1
  617. /* Subquery id: Query vbios image */
  618. #define AMDGPU_INFO_VBIOS_IMAGE 0x2
  619. /* Query UVD handles */
  620. #define AMDGPU_INFO_NUM_HANDLES 0x1C
  621. /* Query sensor related information */
  622. #define AMDGPU_INFO_SENSOR 0x1D
  623. /* Subquery id: Query GPU shader clock */
  624. #define AMDGPU_INFO_SENSOR_GFX_SCLK 0x1
  625. /* Subquery id: Query GPU memory clock */
  626. #define AMDGPU_INFO_SENSOR_GFX_MCLK 0x2
  627. /* Subquery id: Query GPU temperature */
  628. #define AMDGPU_INFO_SENSOR_GPU_TEMP 0x3
  629. /* Subquery id: Query GPU load */
  630. #define AMDGPU_INFO_SENSOR_GPU_LOAD 0x4
  631. /* Subquery id: Query average GPU power */
  632. #define AMDGPU_INFO_SENSOR_GPU_AVG_POWER 0x5
  633. /* Subquery id: Query northbridge voltage */
  634. #define AMDGPU_INFO_SENSOR_VDDNB 0x6
  635. /* Subquery id: Query graphics voltage */
  636. #define AMDGPU_INFO_SENSOR_VDDGFX 0x7
  637. /* Subquery id: Query GPU stable pstate shader clock */
  638. #define AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_SCLK 0x8
  639. /* Subquery id: Query GPU stable pstate memory clock */
  640. #define AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_MCLK 0x9
  641. /* Number of VRAM page faults on CPU access. */
  642. #define AMDGPU_INFO_NUM_VRAM_CPU_PAGE_FAULTS 0x1E
  643. #define AMDGPU_INFO_VRAM_LOST_COUNTER 0x1F
  644. #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
  645. #define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
  646. #define AMDGPU_INFO_MMR_SH_INDEX_SHIFT 8
  647. #define AMDGPU_INFO_MMR_SH_INDEX_MASK 0xff
  648. struct drm_amdgpu_query_fw {
  649. /** AMDGPU_INFO_FW_* */
  650. __u32 fw_type;
  651. /**
  652. * Index of the IP if there are more IPs of
  653. * the same type.
  654. */
  655. __u32 ip_instance;
  656. /**
  657. * Index of the engine. Whether this is used depends
  658. * on the firmware type. (e.g. MEC, SDMA)
  659. */
  660. __u32 index;
  661. __u32 _pad;
  662. };
  663. /* Input structure for the INFO ioctl */
  664. struct drm_amdgpu_info {
  665. /* Where the return value will be stored */
  666. __u64 return_pointer;
  667. /* The size of the return value. Just like "size" in "snprintf",
  668. * it limits how many bytes the kernel can write. */
  669. __u32 return_size;
  670. /* The query request id. */
  671. __u32 query;
  672. union {
  673. struct {
  674. __u32 id;
  675. __u32 _pad;
  676. } mode_crtc;
  677. struct {
  678. /** AMDGPU_HW_IP_* */
  679. __u32 type;
  680. /**
  681. * Index of the IP if there are more IPs of the same
  682. * type. Ignored by AMDGPU_INFO_HW_IP_COUNT.
  683. */
  684. __u32 ip_instance;
  685. } query_hw_ip;
  686. struct {
  687. __u32 dword_offset;
  688. /** number of registers to read */
  689. __u32 count;
  690. __u32 instance;
  691. /** For future use, no flags defined so far */
  692. __u32 flags;
  693. } read_mmr_reg;
  694. struct drm_amdgpu_query_fw query_fw;
  695. struct {
  696. __u32 type;
  697. __u32 offset;
  698. } vbios_info;
  699. struct {
  700. __u32 type;
  701. } sensor_info;
  702. };
  703. };
  704. struct drm_amdgpu_info_gds {
  705. /** GDS GFX partition size */
  706. __u32 gds_gfx_partition_size;
  707. /** GDS compute partition size */
  708. __u32 compute_partition_size;
  709. /** total GDS memory size */
  710. __u32 gds_total_size;
  711. /** GWS size per GFX partition */
  712. __u32 gws_per_gfx_partition;
  713. /** GSW size per compute partition */
  714. __u32 gws_per_compute_partition;
  715. /** OA size per GFX partition */
  716. __u32 oa_per_gfx_partition;
  717. /** OA size per compute partition */
  718. __u32 oa_per_compute_partition;
  719. __u32 _pad;
  720. };
  721. struct drm_amdgpu_info_vram_gtt {
  722. __u64 vram_size;
  723. __u64 vram_cpu_accessible_size;
  724. __u64 gtt_size;
  725. };
  726. struct drm_amdgpu_heap_info {
  727. /** max. physical memory */
  728. __u64 total_heap_size;
  729. /** Theoretical max. available memory in the given heap */
  730. __u64 usable_heap_size;
  731. /**
  732. * Number of bytes allocated in the heap. This includes all processes
  733. * and private allocations in the kernel. It changes when new buffers
  734. * are allocated, freed, and moved. It cannot be larger than
  735. * heap_size.
  736. */
  737. __u64 heap_usage;
  738. /**
  739. * Theoretical possible max. size of buffer which
  740. * could be allocated in the given heap
  741. */
  742. __u64 max_allocation;
  743. };
  744. struct drm_amdgpu_memory_info {
  745. struct drm_amdgpu_heap_info vram;
  746. struct drm_amdgpu_heap_info cpu_accessible_vram;
  747. struct drm_amdgpu_heap_info gtt;
  748. };
  749. struct drm_amdgpu_info_firmware {
  750. __u32 ver;
  751. __u32 feature;
  752. };
  753. #define AMDGPU_VRAM_TYPE_UNKNOWN 0
  754. #define AMDGPU_VRAM_TYPE_GDDR1 1
  755. #define AMDGPU_VRAM_TYPE_DDR2 2
  756. #define AMDGPU_VRAM_TYPE_GDDR3 3
  757. #define AMDGPU_VRAM_TYPE_GDDR4 4
  758. #define AMDGPU_VRAM_TYPE_GDDR5 5
  759. #define AMDGPU_VRAM_TYPE_HBM 6
  760. #define AMDGPU_VRAM_TYPE_DDR3 7
  761. #define AMDGPU_VRAM_TYPE_DDR4 8
  762. struct drm_amdgpu_info_device {
  763. /** PCI Device ID */
  764. __u32 device_id;
  765. /** Internal chip revision: A0, A1, etc.) */
  766. __u32 chip_rev;
  767. __u32 external_rev;
  768. /** Revision id in PCI Config space */
  769. __u32 pci_rev;
  770. __u32 family;
  771. __u32 num_shader_engines;
  772. __u32 num_shader_arrays_per_engine;
  773. /* in KHz */
  774. __u32 gpu_counter_freq;
  775. __u64 max_engine_clock;
  776. __u64 max_memory_clock;
  777. /* cu information */
  778. __u32 cu_active_number;
  779. /* NOTE: cu_ao_mask is INVALID, DON'T use it */
  780. __u32 cu_ao_mask;
  781. __u32 cu_bitmap[4][4];
  782. /** Render backend pipe mask. One render backend is CB+DB. */
  783. __u32 enabled_rb_pipes_mask;
  784. __u32 num_rb_pipes;
  785. __u32 num_hw_gfx_contexts;
  786. __u32 _pad;
  787. __u64 ids_flags;
  788. /** Starting virtual address for UMDs. */
  789. __u64 virtual_address_offset;
  790. /** The maximum virtual address */
  791. __u64 virtual_address_max;
  792. /** Required alignment of virtual addresses. */
  793. __u32 virtual_address_alignment;
  794. /** Page table entry - fragment size */
  795. __u32 pte_fragment_size;
  796. __u32 gart_page_size;
  797. /** constant engine ram size*/
  798. __u32 ce_ram_size;
  799. /** video memory type info*/
  800. __u32 vram_type;
  801. /** video memory bit width*/
  802. __u32 vram_bit_width;
  803. /* vce harvesting instance */
  804. __u32 vce_harvest_config;
  805. /* gfx double offchip LDS buffers */
  806. __u32 gc_double_offchip_lds_buf;
  807. /* NGG Primitive Buffer */
  808. __u64 prim_buf_gpu_addr;
  809. /* NGG Position Buffer */
  810. __u64 pos_buf_gpu_addr;
  811. /* NGG Control Sideband */
  812. __u64 cntl_sb_buf_gpu_addr;
  813. /* NGG Parameter Cache */
  814. __u64 param_buf_gpu_addr;
  815. __u32 prim_buf_size;
  816. __u32 pos_buf_size;
  817. __u32 cntl_sb_buf_size;
  818. __u32 param_buf_size;
  819. /* wavefront size*/
  820. __u32 wave_front_size;
  821. /* shader visible vgprs*/
  822. __u32 num_shader_visible_vgprs;
  823. /* CU per shader array*/
  824. __u32 num_cu_per_sh;
  825. /* number of tcc blocks*/
  826. __u32 num_tcc_blocks;
  827. /* gs vgt table depth*/
  828. __u32 gs_vgt_table_depth;
  829. /* gs primitive buffer depth*/
  830. __u32 gs_prim_buffer_depth;
  831. /* max gs wavefront per vgt*/
  832. __u32 max_gs_waves_per_vgt;
  833. __u32 _pad1;
  834. /* always on cu bitmap */
  835. __u32 cu_ao_bitmap[4][4];
  836. /** Starting high virtual address for UMDs. */
  837. __u64 high_va_offset;
  838. /** The maximum high virtual address */
  839. __u64 high_va_max;
  840. };
  841. struct drm_amdgpu_info_hw_ip {
  842. /** Version of h/w IP */
  843. __u32 hw_ip_version_major;
  844. __u32 hw_ip_version_minor;
  845. /** Capabilities */
  846. __u64 capabilities_flags;
  847. /** command buffer address start alignment*/
  848. __u32 ib_start_alignment;
  849. /** command buffer size alignment*/
  850. __u32 ib_size_alignment;
  851. /** Bitmask of available rings. Bit 0 means ring 0, etc. */
  852. __u32 available_rings;
  853. __u32 _pad;
  854. };
  855. struct drm_amdgpu_info_num_handles {
  856. /** Max handles as supported by firmware for UVD */
  857. __u32 uvd_max_handles;
  858. /** Handles currently in use for UVD */
  859. __u32 uvd_used_handles;
  860. };
  861. #define AMDGPU_VCE_CLOCK_TABLE_ENTRIES 6
  862. struct drm_amdgpu_info_vce_clock_table_entry {
  863. /** System clock */
  864. __u32 sclk;
  865. /** Memory clock */
  866. __u32 mclk;
  867. /** VCE clock */
  868. __u32 eclk;
  869. __u32 pad;
  870. };
  871. struct drm_amdgpu_info_vce_clock_table {
  872. struct drm_amdgpu_info_vce_clock_table_entry entries[AMDGPU_VCE_CLOCK_TABLE_ENTRIES];
  873. __u32 num_valid_entries;
  874. __u32 pad;
  875. };
  876. /*
  877. * Supported GPU families
  878. */
  879. #define AMDGPU_FAMILY_UNKNOWN 0
  880. #define AMDGPU_FAMILY_SI 110 /* Hainan, Oland, Verde, Pitcairn, Tahiti */
  881. #define AMDGPU_FAMILY_CI 120 /* Bonaire, Hawaii */
  882. #define AMDGPU_FAMILY_KV 125 /* Kaveri, Kabini, Mullins */
  883. #define AMDGPU_FAMILY_VI 130 /* Iceland, Tonga */
  884. #define AMDGPU_FAMILY_CZ 135 /* Carrizo, Stoney */
  885. #define AMDGPU_FAMILY_AI 141 /* Vega10 */
  886. #define AMDGPU_FAMILY_RV 142 /* Raven */
  887. #if defined(__cplusplus)
  888. }
  889. #endif
  890. #endif