kfd_ioctl.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef KFD_IOCTL_H_INCLUDED
  23. #define KFD_IOCTL_H_INCLUDED
  24. #include <drm/drm.h>
  25. #include <linux/ioctl.h>
  26. /*
  27. * - 1.1 - initial version
  28. * - 1.3 - Add SMI events support
  29. * - 1.4 - Indicate new SRAM EDC bit in device properties
  30. * - 1.5 - Add SVM API
  31. * - 1.6 - Query clear flags in SVM get_attr API
  32. * - 1.7 - Checkpoint Restore (CRIU) API
  33. * - 1.8 - CRIU - Support for SDMA transfers with GTT BOs
  34. * - 1.9 - Add available memory ioctl
  35. * - 1.10 - Add SMI profiler event log
  36. * - 1.11 - Add unified memory for ctx save/restore area
  37. * - 1.12 - Add DMA buf export ioctl
  38. * - 1.13 - Add debugger API
  39. * - 1.14 - Update kfd_event_data
  40. */
  41. #define KFD_IOCTL_MAJOR_VERSION 1
  42. #define KFD_IOCTL_MINOR_VERSION 14
  43. struct kfd_ioctl_get_version_args {
  44. __u32 major_version; /* from KFD */
  45. __u32 minor_version; /* from KFD */
  46. };
  47. /* For kfd_ioctl_create_queue_args.queue_type. */
  48. #define KFD_IOC_QUEUE_TYPE_COMPUTE 0x0
  49. #define KFD_IOC_QUEUE_TYPE_SDMA 0x1
  50. #define KFD_IOC_QUEUE_TYPE_COMPUTE_AQL 0x2
  51. #define KFD_IOC_QUEUE_TYPE_SDMA_XGMI 0x3
  52. #define KFD_MAX_QUEUE_PERCENTAGE 100
  53. #define KFD_MAX_QUEUE_PRIORITY 15
  54. struct kfd_ioctl_create_queue_args {
  55. __u64 ring_base_address; /* to KFD */
  56. __u64 write_pointer_address; /* from KFD */
  57. __u64 read_pointer_address; /* from KFD */
  58. __u64 doorbell_offset; /* from KFD */
  59. __u32 ring_size; /* to KFD */
  60. __u32 gpu_id; /* to KFD */
  61. __u32 queue_type; /* to KFD */
  62. __u32 queue_percentage; /* to KFD */
  63. __u32 queue_priority; /* to KFD */
  64. __u32 queue_id; /* from KFD */
  65. __u64 eop_buffer_address; /* to KFD */
  66. __u64 eop_buffer_size; /* to KFD */
  67. __u64 ctx_save_restore_address; /* to KFD */
  68. __u32 ctx_save_restore_size; /* to KFD */
  69. __u32 ctl_stack_size; /* to KFD */
  70. };
  71. struct kfd_ioctl_destroy_queue_args {
  72. __u32 queue_id; /* to KFD */
  73. __u32 pad;
  74. };
  75. struct kfd_ioctl_update_queue_args {
  76. __u64 ring_base_address; /* to KFD */
  77. __u32 queue_id; /* to KFD */
  78. __u32 ring_size; /* to KFD */
  79. __u32 queue_percentage; /* to KFD */
  80. __u32 queue_priority; /* to KFD */
  81. };
  82. struct kfd_ioctl_set_cu_mask_args {
  83. __u32 queue_id; /* to KFD */
  84. __u32 num_cu_mask; /* to KFD */
  85. __u64 cu_mask_ptr; /* to KFD */
  86. };
  87. struct kfd_ioctl_get_queue_wave_state_args {
  88. __u64 ctl_stack_address; /* to KFD */
  89. __u32 ctl_stack_used_size; /* from KFD */
  90. __u32 save_area_used_size; /* from KFD */
  91. __u32 queue_id; /* to KFD */
  92. __u32 pad;
  93. };
  94. struct kfd_ioctl_get_available_memory_args {
  95. __u64 available; /* from KFD */
  96. __u32 gpu_id; /* to KFD */
  97. __u32 pad;
  98. };
  99. struct kfd_dbg_device_info_entry {
  100. __u64 exception_status;
  101. __u64 lds_base;
  102. __u64 lds_limit;
  103. __u64 scratch_base;
  104. __u64 scratch_limit;
  105. __u64 gpuvm_base;
  106. __u64 gpuvm_limit;
  107. __u32 gpu_id;
  108. __u32 location_id;
  109. __u32 vendor_id;
  110. __u32 device_id;
  111. __u32 revision_id;
  112. __u32 subsystem_vendor_id;
  113. __u32 subsystem_device_id;
  114. __u32 fw_version;
  115. __u32 gfx_target_version;
  116. __u32 simd_count;
  117. __u32 max_waves_per_simd;
  118. __u32 array_count;
  119. __u32 simd_arrays_per_engine;
  120. __u32 num_xcc;
  121. __u32 capability;
  122. __u32 debug_prop;
  123. };
  124. /* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */
  125. #define KFD_IOC_CACHE_POLICY_COHERENT 0
  126. #define KFD_IOC_CACHE_POLICY_NONCOHERENT 1
  127. struct kfd_ioctl_set_memory_policy_args {
  128. __u64 alternate_aperture_base; /* to KFD */
  129. __u64 alternate_aperture_size; /* to KFD */
  130. __u32 gpu_id; /* to KFD */
  131. __u32 default_policy; /* to KFD */
  132. __u32 alternate_policy; /* to KFD */
  133. __u32 pad;
  134. };
  135. /*
  136. * All counters are monotonic. They are used for profiling of compute jobs.
  137. * The profiling is done by userspace.
  138. *
  139. * In case of GPU reset, the counter should not be affected.
  140. */
  141. struct kfd_ioctl_get_clock_counters_args {
  142. __u64 gpu_clock_counter; /* from KFD */
  143. __u64 cpu_clock_counter; /* from KFD */
  144. __u64 system_clock_counter; /* from KFD */
  145. __u64 system_clock_freq; /* from KFD */
  146. __u32 gpu_id; /* to KFD */
  147. __u32 pad;
  148. };
  149. struct kfd_process_device_apertures {
  150. __u64 lds_base; /* from KFD */
  151. __u64 lds_limit; /* from KFD */
  152. __u64 scratch_base; /* from KFD */
  153. __u64 scratch_limit; /* from KFD */
  154. __u64 gpuvm_base; /* from KFD */
  155. __u64 gpuvm_limit; /* from KFD */
  156. __u32 gpu_id; /* from KFD */
  157. __u32 pad;
  158. };
  159. /*
  160. * AMDKFD_IOC_GET_PROCESS_APERTURES is deprecated. Use
  161. * AMDKFD_IOC_GET_PROCESS_APERTURES_NEW instead, which supports an
  162. * unlimited number of GPUs.
  163. */
  164. #define NUM_OF_SUPPORTED_GPUS 7
  165. struct kfd_ioctl_get_process_apertures_args {
  166. struct kfd_process_device_apertures
  167. process_apertures[NUM_OF_SUPPORTED_GPUS];/* from KFD */
  168. /* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS] */
  169. __u32 num_of_nodes;
  170. __u32 pad;
  171. };
  172. struct kfd_ioctl_get_process_apertures_new_args {
  173. /* User allocated. Pointer to struct kfd_process_device_apertures
  174. * filled in by Kernel
  175. */
  176. __u64 kfd_process_device_apertures_ptr;
  177. /* to KFD - indicates amount of memory present in
  178. * kfd_process_device_apertures_ptr
  179. * from KFD - Number of entries filled by KFD.
  180. */
  181. __u32 num_of_nodes;
  182. __u32 pad;
  183. };
  184. #define MAX_ALLOWED_NUM_POINTS 100
  185. #define MAX_ALLOWED_AW_BUFF_SIZE 4096
  186. #define MAX_ALLOWED_WAC_BUFF_SIZE 128
  187. struct kfd_ioctl_dbg_register_args {
  188. __u32 gpu_id; /* to KFD */
  189. __u32 pad;
  190. };
  191. struct kfd_ioctl_dbg_unregister_args {
  192. __u32 gpu_id; /* to KFD */
  193. __u32 pad;
  194. };
  195. struct kfd_ioctl_dbg_address_watch_args {
  196. __u64 content_ptr; /* a pointer to the actual content */
  197. __u32 gpu_id; /* to KFD */
  198. __u32 buf_size_in_bytes; /*including gpu_id and buf_size */
  199. };
  200. struct kfd_ioctl_dbg_wave_control_args {
  201. __u64 content_ptr; /* a pointer to the actual content */
  202. __u32 gpu_id; /* to KFD */
  203. __u32 buf_size_in_bytes; /*including gpu_id and buf_size */
  204. };
  205. #define KFD_INVALID_FD 0xffffffff
  206. /* Matching HSA_EVENTTYPE */
  207. #define KFD_IOC_EVENT_SIGNAL 0
  208. #define KFD_IOC_EVENT_NODECHANGE 1
  209. #define KFD_IOC_EVENT_DEVICESTATECHANGE 2
  210. #define KFD_IOC_EVENT_HW_EXCEPTION 3
  211. #define KFD_IOC_EVENT_SYSTEM_EVENT 4
  212. #define KFD_IOC_EVENT_DEBUG_EVENT 5
  213. #define KFD_IOC_EVENT_PROFILE_EVENT 6
  214. #define KFD_IOC_EVENT_QUEUE_EVENT 7
  215. #define KFD_IOC_EVENT_MEMORY 8
  216. #define KFD_IOC_WAIT_RESULT_COMPLETE 0
  217. #define KFD_IOC_WAIT_RESULT_TIMEOUT 1
  218. #define KFD_IOC_WAIT_RESULT_FAIL 2
  219. #define KFD_SIGNAL_EVENT_LIMIT 4096
  220. /* For kfd_event_data.hw_exception_data.reset_type. */
  221. #define KFD_HW_EXCEPTION_WHOLE_GPU_RESET 0
  222. #define KFD_HW_EXCEPTION_PER_ENGINE_RESET 1
  223. /* For kfd_event_data.hw_exception_data.reset_cause. */
  224. #define KFD_HW_EXCEPTION_GPU_HANG 0
  225. #define KFD_HW_EXCEPTION_ECC 1
  226. /* For kfd_hsa_memory_exception_data.ErrorType */
  227. #define KFD_MEM_ERR_NO_RAS 0
  228. #define KFD_MEM_ERR_SRAM_ECC 1
  229. #define KFD_MEM_ERR_POISON_CONSUMED 2
  230. #define KFD_MEM_ERR_GPU_HANG 3
  231. struct kfd_ioctl_create_event_args {
  232. __u64 event_page_offset; /* from KFD */
  233. __u32 event_trigger_data; /* from KFD - signal events only */
  234. __u32 event_type; /* to KFD */
  235. __u32 auto_reset; /* to KFD */
  236. __u32 node_id; /* to KFD - only valid for certain
  237. event types */
  238. __u32 event_id; /* from KFD */
  239. __u32 event_slot_index; /* from KFD */
  240. };
  241. struct kfd_ioctl_destroy_event_args {
  242. __u32 event_id; /* to KFD */
  243. __u32 pad;
  244. };
  245. struct kfd_ioctl_set_event_args {
  246. __u32 event_id; /* to KFD */
  247. __u32 pad;
  248. };
  249. struct kfd_ioctl_reset_event_args {
  250. __u32 event_id; /* to KFD */
  251. __u32 pad;
  252. };
  253. struct kfd_memory_exception_failure {
  254. __u32 NotPresent; /* Page not present or supervisor privilege */
  255. __u32 ReadOnly; /* Write access to a read-only page */
  256. __u32 NoExecute; /* Execute access to a page marked NX */
  257. __u32 imprecise; /* Can't determine the exact fault address */
  258. };
  259. /* memory exception data */
  260. struct kfd_hsa_memory_exception_data {
  261. struct kfd_memory_exception_failure failure;
  262. __u64 va;
  263. __u32 gpu_id;
  264. __u32 ErrorType; /* 0 = no RAS error,
  265. * 1 = ECC_SRAM,
  266. * 2 = Link_SYNFLOOD (poison),
  267. * 3 = GPU hang (not attributable to a specific cause),
  268. * other values reserved
  269. */
  270. };
  271. /* hw exception data */
  272. struct kfd_hsa_hw_exception_data {
  273. __u32 reset_type;
  274. __u32 reset_cause;
  275. __u32 memory_lost;
  276. __u32 gpu_id;
  277. };
  278. /* hsa signal event data */
  279. struct kfd_hsa_signal_event_data {
  280. __u64 last_event_age; /* to and from KFD */
  281. };
  282. /* Event data */
  283. struct kfd_event_data {
  284. union {
  285. /* From KFD */
  286. struct kfd_hsa_memory_exception_data memory_exception_data;
  287. struct kfd_hsa_hw_exception_data hw_exception_data;
  288. /* To and From KFD */
  289. struct kfd_hsa_signal_event_data signal_event_data;
  290. };
  291. __u64 kfd_event_data_ext; /* pointer to an extension structure
  292. for future exception types */
  293. __u32 event_id; /* to KFD */
  294. __u32 pad;
  295. };
  296. struct kfd_ioctl_wait_events_args {
  297. __u64 events_ptr; /* pointed to struct
  298. kfd_event_data array, to KFD */
  299. __u32 num_events; /* to KFD */
  300. __u32 wait_for_all; /* to KFD */
  301. __u32 timeout; /* to KFD */
  302. __u32 wait_result; /* from KFD */
  303. };
  304. struct kfd_ioctl_set_scratch_backing_va_args {
  305. __u64 va_addr; /* to KFD */
  306. __u32 gpu_id; /* to KFD */
  307. __u32 pad;
  308. };
  309. struct kfd_ioctl_get_tile_config_args {
  310. /* to KFD: pointer to tile array */
  311. __u64 tile_config_ptr;
  312. /* to KFD: pointer to macro tile array */
  313. __u64 macro_tile_config_ptr;
  314. /* to KFD: array size allocated by user mode
  315. * from KFD: array size filled by kernel
  316. */
  317. __u32 num_tile_configs;
  318. /* to KFD: array size allocated by user mode
  319. * from KFD: array size filled by kernel
  320. */
  321. __u32 num_macro_tile_configs;
  322. __u32 gpu_id; /* to KFD */
  323. __u32 gb_addr_config; /* from KFD */
  324. __u32 num_banks; /* from KFD */
  325. __u32 num_ranks; /* from KFD */
  326. /* struct size can be extended later if needed
  327. * without breaking ABI compatibility
  328. */
  329. };
  330. struct kfd_ioctl_set_trap_handler_args {
  331. __u64 tba_addr; /* to KFD */
  332. __u64 tma_addr; /* to KFD */
  333. __u32 gpu_id; /* to KFD */
  334. __u32 pad;
  335. };
  336. struct kfd_ioctl_acquire_vm_args {
  337. __u32 drm_fd; /* to KFD */
  338. __u32 gpu_id; /* to KFD */
  339. };
  340. /* Allocation flags: memory types */
  341. #define KFD_IOC_ALLOC_MEM_FLAGS_VRAM (1 << 0)
  342. #define KFD_IOC_ALLOC_MEM_FLAGS_GTT (1 << 1)
  343. #define KFD_IOC_ALLOC_MEM_FLAGS_USERPTR (1 << 2)
  344. #define KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL (1 << 3)
  345. #define KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP (1 << 4)
  346. /* Allocation flags: attributes/access options */
  347. #define KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE (1 << 31)
  348. #define KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE (1 << 30)
  349. #define KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC (1 << 29)
  350. #define KFD_IOC_ALLOC_MEM_FLAGS_NO_SUBSTITUTE (1 << 28)
  351. #define KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM (1 << 27)
  352. #define KFD_IOC_ALLOC_MEM_FLAGS_COHERENT (1 << 26)
  353. #define KFD_IOC_ALLOC_MEM_FLAGS_UNCACHED (1 << 25)
  354. /* Allocate memory for later SVM (shared virtual memory) mapping.
  355. *
  356. * @va_addr: virtual address of the memory to be allocated
  357. * all later mappings on all GPUs will use this address
  358. * @size: size in bytes
  359. * @handle: buffer handle returned to user mode, used to refer to
  360. * this allocation for mapping, unmapping and freeing
  361. * @mmap_offset: for CPU-mapping the allocation by mmapping a render node
  362. * for userptrs this is overloaded to specify the CPU address
  363. * @gpu_id: device identifier
  364. * @flags: memory type and attributes. See KFD_IOC_ALLOC_MEM_FLAGS above
  365. */
  366. struct kfd_ioctl_alloc_memory_of_gpu_args {
  367. __u64 va_addr; /* to KFD */
  368. __u64 size; /* to KFD */
  369. __u64 handle; /* from KFD */
  370. __u64 mmap_offset; /* to KFD (userptr), from KFD (mmap offset) */
  371. __u32 gpu_id; /* to KFD */
  372. __u32 flags;
  373. };
  374. /* Free memory allocated with kfd_ioctl_alloc_memory_of_gpu
  375. *
  376. * @handle: memory handle returned by alloc
  377. */
  378. struct kfd_ioctl_free_memory_of_gpu_args {
  379. __u64 handle; /* to KFD */
  380. };
  381. /* Map memory to one or more GPUs
  382. *
  383. * @handle: memory handle returned by alloc
  384. * @device_ids_array_ptr: array of gpu_ids (__u32 per device)
  385. * @n_devices: number of devices in the array
  386. * @n_success: number of devices mapped successfully
  387. *
  388. * @n_success returns information to the caller how many devices from
  389. * the start of the array have mapped the buffer successfully. It can
  390. * be passed into a subsequent retry call to skip those devices. For
  391. * the first call the caller should initialize it to 0.
  392. *
  393. * If the ioctl completes with return code 0 (success), n_success ==
  394. * n_devices.
  395. */
  396. struct kfd_ioctl_map_memory_to_gpu_args {
  397. __u64 handle; /* to KFD */
  398. __u64 device_ids_array_ptr; /* to KFD */
  399. __u32 n_devices; /* to KFD */
  400. __u32 n_success; /* to/from KFD */
  401. };
  402. /* Unmap memory from one or more GPUs
  403. *
  404. * same arguments as for mapping
  405. */
  406. struct kfd_ioctl_unmap_memory_from_gpu_args {
  407. __u64 handle; /* to KFD */
  408. __u64 device_ids_array_ptr; /* to KFD */
  409. __u32 n_devices; /* to KFD */
  410. __u32 n_success; /* to/from KFD */
  411. };
  412. /* Allocate GWS for specific queue
  413. *
  414. * @queue_id: queue's id that GWS is allocated for
  415. * @num_gws: how many GWS to allocate
  416. * @first_gws: index of the first GWS allocated.
  417. * only support contiguous GWS allocation
  418. */
  419. struct kfd_ioctl_alloc_queue_gws_args {
  420. __u32 queue_id; /* to KFD */
  421. __u32 num_gws; /* to KFD */
  422. __u32 first_gws; /* from KFD */
  423. __u32 pad;
  424. };
  425. struct kfd_ioctl_get_dmabuf_info_args {
  426. __u64 size; /* from KFD */
  427. __u64 metadata_ptr; /* to KFD */
  428. __u32 metadata_size; /* to KFD (space allocated by user)
  429. * from KFD (actual metadata size)
  430. */
  431. __u32 gpu_id; /* from KFD */
  432. __u32 flags; /* from KFD (KFD_IOC_ALLOC_MEM_FLAGS) */
  433. __u32 dmabuf_fd; /* to KFD */
  434. };
  435. struct kfd_ioctl_import_dmabuf_args {
  436. __u64 va_addr; /* to KFD */
  437. __u64 handle; /* from KFD */
  438. __u32 gpu_id; /* to KFD */
  439. __u32 dmabuf_fd; /* to KFD */
  440. };
  441. struct kfd_ioctl_export_dmabuf_args {
  442. __u64 handle; /* to KFD */
  443. __u32 flags; /* to KFD */
  444. __u32 dmabuf_fd; /* from KFD */
  445. };
  446. /*
  447. * KFD SMI(System Management Interface) events
  448. */
  449. enum kfd_smi_event {
  450. KFD_SMI_EVENT_NONE = 0, /* not used */
  451. KFD_SMI_EVENT_VMFAULT = 1, /* event start counting at 1 */
  452. KFD_SMI_EVENT_THERMAL_THROTTLE = 2,
  453. KFD_SMI_EVENT_GPU_PRE_RESET = 3,
  454. KFD_SMI_EVENT_GPU_POST_RESET = 4,
  455. KFD_SMI_EVENT_MIGRATE_START = 5,
  456. KFD_SMI_EVENT_MIGRATE_END = 6,
  457. KFD_SMI_EVENT_PAGE_FAULT_START = 7,
  458. KFD_SMI_EVENT_PAGE_FAULT_END = 8,
  459. KFD_SMI_EVENT_QUEUE_EVICTION = 9,
  460. KFD_SMI_EVENT_QUEUE_RESTORE = 10,
  461. KFD_SMI_EVENT_UNMAP_FROM_GPU = 11,
  462. /*
  463. * max event number, as a flag bit to get events from all processes,
  464. * this requires super user permission, otherwise will not be able to
  465. * receive event from any process. Without this flag to receive events
  466. * from same process.
  467. */
  468. KFD_SMI_EVENT_ALL_PROCESS = 64
  469. };
  470. enum KFD_MIGRATE_TRIGGERS {
  471. KFD_MIGRATE_TRIGGER_PREFETCH,
  472. KFD_MIGRATE_TRIGGER_PAGEFAULT_GPU,
  473. KFD_MIGRATE_TRIGGER_PAGEFAULT_CPU,
  474. KFD_MIGRATE_TRIGGER_TTM_EVICTION
  475. };
  476. enum KFD_QUEUE_EVICTION_TRIGGERS {
  477. KFD_QUEUE_EVICTION_TRIGGER_SVM,
  478. KFD_QUEUE_EVICTION_TRIGGER_USERPTR,
  479. KFD_QUEUE_EVICTION_TRIGGER_TTM,
  480. KFD_QUEUE_EVICTION_TRIGGER_SUSPEND,
  481. KFD_QUEUE_EVICTION_CRIU_CHECKPOINT,
  482. KFD_QUEUE_EVICTION_CRIU_RESTORE
  483. };
  484. enum KFD_SVM_UNMAP_TRIGGERS {
  485. KFD_SVM_UNMAP_TRIGGER_MMU_NOTIFY,
  486. KFD_SVM_UNMAP_TRIGGER_MMU_NOTIFY_MIGRATE,
  487. KFD_SVM_UNMAP_TRIGGER_UNMAP_FROM_CPU
  488. };
  489. #define KFD_SMI_EVENT_MASK_FROM_INDEX(i) (1ULL << ((i) - 1))
  490. #define KFD_SMI_EVENT_MSG_SIZE 96
  491. struct kfd_ioctl_smi_events_args {
  492. __u32 gpuid; /* to KFD */
  493. __u32 anon_fd; /* from KFD */
  494. };
  495. /**************************************************************************************************
  496. * CRIU IOCTLs (Checkpoint Restore In Userspace)
  497. *
  498. * When checkpointing a process, the userspace application will perform:
  499. * 1. PROCESS_INFO op to determine current process information. This pauses execution and evicts
  500. * all the queues.
  501. * 2. CHECKPOINT op to checkpoint process contents (BOs, queues, events, svm-ranges)
  502. * 3. UNPAUSE op to un-evict all the queues
  503. *
  504. * When restoring a process, the CRIU userspace application will perform:
  505. *
  506. * 1. RESTORE op to restore process contents
  507. * 2. RESUME op to start the process
  508. *
  509. * Note: Queues are forced into an evicted state after a successful PROCESS_INFO. User
  510. * application needs to perform an UNPAUSE operation after calling PROCESS_INFO.
  511. */
  512. enum kfd_criu_op {
  513. KFD_CRIU_OP_PROCESS_INFO,
  514. KFD_CRIU_OP_CHECKPOINT,
  515. KFD_CRIU_OP_UNPAUSE,
  516. KFD_CRIU_OP_RESTORE,
  517. KFD_CRIU_OP_RESUME,
  518. };
  519. /**
  520. * kfd_ioctl_criu_args - Arguments perform CRIU operation
  521. * @devices: [in/out] User pointer to memory location for devices information.
  522. * This is an array of type kfd_criu_device_bucket.
  523. * @bos: [in/out] User pointer to memory location for BOs information
  524. * This is an array of type kfd_criu_bo_bucket.
  525. * @priv_data: [in/out] User pointer to memory location for private data
  526. * @priv_data_size: [in/out] Size of priv_data in bytes
  527. * @num_devices: [in/out] Number of GPUs used by process. Size of @devices array.
  528. * @num_bos [in/out] Number of BOs used by process. Size of @bos array.
  529. * @num_objects: [in/out] Number of objects used by process. Objects are opaque to
  530. * user application.
  531. * @pid: [in/out] PID of the process being checkpointed
  532. * @op [in] Type of operation (kfd_criu_op)
  533. *
  534. * Return: 0 on success, -errno on failure
  535. */
  536. struct kfd_ioctl_criu_args {
  537. __u64 devices; /* Used during ops: CHECKPOINT, RESTORE */
  538. __u64 bos; /* Used during ops: CHECKPOINT, RESTORE */
  539. __u64 priv_data; /* Used during ops: CHECKPOINT, RESTORE */
  540. __u64 priv_data_size; /* Used during ops: PROCESS_INFO, RESTORE */
  541. __u32 num_devices; /* Used during ops: PROCESS_INFO, RESTORE */
  542. __u32 num_bos; /* Used during ops: PROCESS_INFO, RESTORE */
  543. __u32 num_objects; /* Used during ops: PROCESS_INFO, RESTORE */
  544. __u32 pid; /* Used during ops: PROCESS_INFO, RESUME */
  545. __u32 op;
  546. };
  547. struct kfd_criu_device_bucket {
  548. __u32 user_gpu_id;
  549. __u32 actual_gpu_id;
  550. __u32 drm_fd;
  551. __u32 pad;
  552. };
  553. struct kfd_criu_bo_bucket {
  554. __u64 addr;
  555. __u64 size;
  556. __u64 offset;
  557. __u64 restored_offset; /* During restore, updated offset for BO */
  558. __u32 gpu_id; /* This is the user_gpu_id */
  559. __u32 alloc_flags;
  560. __u32 dmabuf_fd;
  561. __u32 pad;
  562. };
  563. /* CRIU IOCTLs - END */
  564. /**************************************************************************************************/
  565. /* Register offset inside the remapped mmio page
  566. */
  567. enum kfd_mmio_remap {
  568. KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL = 0,
  569. KFD_MMIO_REMAP_HDP_REG_FLUSH_CNTL = 4,
  570. };
  571. /* Guarantee host access to memory */
  572. #define KFD_IOCTL_SVM_FLAG_HOST_ACCESS 0x00000001
  573. /* Fine grained coherency between all devices with access */
  574. #define KFD_IOCTL_SVM_FLAG_COHERENT 0x00000002
  575. /* Use any GPU in same hive as preferred device */
  576. #define KFD_IOCTL_SVM_FLAG_HIVE_LOCAL 0x00000004
  577. /* GPUs only read, allows replication */
  578. #define KFD_IOCTL_SVM_FLAG_GPU_RO 0x00000008
  579. /* Allow execution on GPU */
  580. #define KFD_IOCTL_SVM_FLAG_GPU_EXEC 0x00000010
  581. /* GPUs mostly read, may allow similar optimizations as RO, but writes fault */
  582. #define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY 0x00000020
  583. /* Keep GPU memory mapping always valid as if XNACK is disable */
  584. #define KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED 0x00000040
  585. /**
  586. * kfd_ioctl_svm_op - SVM ioctl operations
  587. *
  588. * @KFD_IOCTL_SVM_OP_SET_ATTR: Modify one or more attributes
  589. * @KFD_IOCTL_SVM_OP_GET_ATTR: Query one or more attributes
  590. */
  591. enum kfd_ioctl_svm_op {
  592. KFD_IOCTL_SVM_OP_SET_ATTR,
  593. KFD_IOCTL_SVM_OP_GET_ATTR
  594. };
  595. /** kfd_ioctl_svm_location - Enum for preferred and prefetch locations
  596. *
  597. * GPU IDs are used to specify GPUs as preferred and prefetch locations.
  598. * Below definitions are used for system memory or for leaving the preferred
  599. * location unspecified.
  600. */
  601. enum kfd_ioctl_svm_location {
  602. KFD_IOCTL_SVM_LOCATION_SYSMEM = 0,
  603. KFD_IOCTL_SVM_LOCATION_UNDEFINED = 0xffffffff
  604. };
  605. /**
  606. * kfd_ioctl_svm_attr_type - SVM attribute types
  607. *
  608. * @KFD_IOCTL_SVM_ATTR_PREFERRED_LOC: gpuid of the preferred location, 0 for
  609. * system memory
  610. * @KFD_IOCTL_SVM_ATTR_PREFETCH_LOC: gpuid of the prefetch location, 0 for
  611. * system memory. Setting this triggers an
  612. * immediate prefetch (migration).
  613. * @KFD_IOCTL_SVM_ATTR_ACCESS:
  614. * @KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE:
  615. * @KFD_IOCTL_SVM_ATTR_NO_ACCESS: specify memory access for the gpuid given
  616. * by the attribute value
  617. * @KFD_IOCTL_SVM_ATTR_SET_FLAGS: bitmask of flags to set (see
  618. * KFD_IOCTL_SVM_FLAG_...)
  619. * @KFD_IOCTL_SVM_ATTR_CLR_FLAGS: bitmask of flags to clear
  620. * @KFD_IOCTL_SVM_ATTR_GRANULARITY: migration granularity
  621. * (log2 num pages)
  622. */
  623. enum kfd_ioctl_svm_attr_type {
  624. KFD_IOCTL_SVM_ATTR_PREFERRED_LOC,
  625. KFD_IOCTL_SVM_ATTR_PREFETCH_LOC,
  626. KFD_IOCTL_SVM_ATTR_ACCESS,
  627. KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE,
  628. KFD_IOCTL_SVM_ATTR_NO_ACCESS,
  629. KFD_IOCTL_SVM_ATTR_SET_FLAGS,
  630. KFD_IOCTL_SVM_ATTR_CLR_FLAGS,
  631. KFD_IOCTL_SVM_ATTR_GRANULARITY
  632. };
  633. /**
  634. * kfd_ioctl_svm_attribute - Attributes as pairs of type and value
  635. *
  636. * The meaning of the @value depends on the attribute type.
  637. *
  638. * @type: attribute type (see enum @kfd_ioctl_svm_attr_type)
  639. * @value: attribute value
  640. */
  641. struct kfd_ioctl_svm_attribute {
  642. __u32 type;
  643. __u32 value;
  644. };
  645. /**
  646. * kfd_ioctl_svm_args - Arguments for SVM ioctl
  647. *
  648. * @op specifies the operation to perform (see enum
  649. * @kfd_ioctl_svm_op). @start_addr and @size are common for all
  650. * operations.
  651. *
  652. * A variable number of attributes can be given in @attrs.
  653. * @nattr specifies the number of attributes. New attributes can be
  654. * added in the future without breaking the ABI. If unknown attributes
  655. * are given, the function returns -EINVAL.
  656. *
  657. * @KFD_IOCTL_SVM_OP_SET_ATTR sets attributes for a virtual address
  658. * range. It may overlap existing virtual address ranges. If it does,
  659. * the existing ranges will be split such that the attribute changes
  660. * only apply to the specified address range.
  661. *
  662. * @KFD_IOCTL_SVM_OP_GET_ATTR returns the intersection of attributes
  663. * over all memory in the given range and returns the result as the
  664. * attribute value. If different pages have different preferred or
  665. * prefetch locations, 0xffffffff will be returned for
  666. * @KFD_IOCTL_SVM_ATTR_PREFERRED_LOC or
  667. * @KFD_IOCTL_SVM_ATTR_PREFETCH_LOC resepctively. For
  668. * @KFD_IOCTL_SVM_ATTR_SET_FLAGS, flags of all pages will be
  669. * aggregated by bitwise AND. That means, a flag will be set in the
  670. * output, if that flag is set for all pages in the range. For
  671. * @KFD_IOCTL_SVM_ATTR_CLR_FLAGS, flags of all pages will be
  672. * aggregated by bitwise NOR. That means, a flag will be set in the
  673. * output, if that flag is clear for all pages in the range.
  674. * The minimum migration granularity throughout the range will be
  675. * returned for @KFD_IOCTL_SVM_ATTR_GRANULARITY.
  676. *
  677. * Querying of accessibility attributes works by initializing the
  678. * attribute type to @KFD_IOCTL_SVM_ATTR_ACCESS and the value to the
  679. * GPUID being queried. Multiple attributes can be given to allow
  680. * querying multiple GPUIDs. The ioctl function overwrites the
  681. * attribute type to indicate the access for the specified GPU.
  682. */
  683. struct kfd_ioctl_svm_args {
  684. __u64 start_addr;
  685. __u64 size;
  686. __u32 op;
  687. __u32 nattr;
  688. /* Variable length array of attributes */
  689. struct kfd_ioctl_svm_attribute attrs[];
  690. };
  691. /**
  692. * kfd_ioctl_set_xnack_mode_args - Arguments for set_xnack_mode
  693. *
  694. * @xnack_enabled: [in/out] Whether to enable XNACK mode for this process
  695. *
  696. * @xnack_enabled indicates whether recoverable page faults should be
  697. * enabled for the current process. 0 means disabled, positive means
  698. * enabled, negative means leave unchanged. If enabled, virtual address
  699. * translations on GFXv9 and later AMD GPUs can return XNACK and retry
  700. * the access until a valid PTE is available. This is used to implement
  701. * device page faults.
  702. *
  703. * On output, @xnack_enabled returns the (new) current mode (0 or
  704. * positive). Therefore, a negative input value can be used to query
  705. * the current mode without changing it.
  706. *
  707. * The XNACK mode fundamentally changes the way SVM managed memory works
  708. * in the driver, with subtle effects on application performance and
  709. * functionality.
  710. *
  711. * Enabling XNACK mode requires shader programs to be compiled
  712. * differently. Furthermore, not all GPUs support changing the mode
  713. * per-process. Therefore changing the mode is only allowed while no
  714. * user mode queues exist in the process. This ensure that no shader
  715. * code is running that may be compiled for the wrong mode. And GPUs
  716. * that cannot change to the requested mode will prevent the XNACK
  717. * mode from occurring. All GPUs used by the process must be in the
  718. * same XNACK mode.
  719. *
  720. * GFXv8 or older GPUs do not support 48 bit virtual addresses or SVM.
  721. * Therefore those GPUs are not considered for the XNACK mode switch.
  722. *
  723. * Return: 0 on success, -errno on failure
  724. */
  725. struct kfd_ioctl_set_xnack_mode_args {
  726. __s32 xnack_enabled;
  727. };
  728. /* Wave launch override modes */
  729. enum kfd_dbg_trap_override_mode {
  730. KFD_DBG_TRAP_OVERRIDE_OR = 0,
  731. KFD_DBG_TRAP_OVERRIDE_REPLACE = 1
  732. };
  733. /* Wave launch overrides */
  734. enum kfd_dbg_trap_mask {
  735. KFD_DBG_TRAP_MASK_FP_INVALID = 1,
  736. KFD_DBG_TRAP_MASK_FP_INPUT_DENORMAL = 2,
  737. KFD_DBG_TRAP_MASK_FP_DIVIDE_BY_ZERO = 4,
  738. KFD_DBG_TRAP_MASK_FP_OVERFLOW = 8,
  739. KFD_DBG_TRAP_MASK_FP_UNDERFLOW = 16,
  740. KFD_DBG_TRAP_MASK_FP_INEXACT = 32,
  741. KFD_DBG_TRAP_MASK_INT_DIVIDE_BY_ZERO = 64,
  742. KFD_DBG_TRAP_MASK_DBG_ADDRESS_WATCH = 128,
  743. KFD_DBG_TRAP_MASK_DBG_MEMORY_VIOLATION = 256,
  744. KFD_DBG_TRAP_MASK_TRAP_ON_WAVE_START = (1 << 30),
  745. KFD_DBG_TRAP_MASK_TRAP_ON_WAVE_END = (1 << 31)
  746. };
  747. /* Wave launch modes */
  748. enum kfd_dbg_trap_wave_launch_mode {
  749. KFD_DBG_TRAP_WAVE_LAUNCH_MODE_NORMAL = 0,
  750. KFD_DBG_TRAP_WAVE_LAUNCH_MODE_HALT = 1,
  751. KFD_DBG_TRAP_WAVE_LAUNCH_MODE_DEBUG = 3
  752. };
  753. /* Address watch modes */
  754. enum kfd_dbg_trap_address_watch_mode {
  755. KFD_DBG_TRAP_ADDRESS_WATCH_MODE_READ = 0,
  756. KFD_DBG_TRAP_ADDRESS_WATCH_MODE_NONREAD = 1,
  757. KFD_DBG_TRAP_ADDRESS_WATCH_MODE_ATOMIC = 2,
  758. KFD_DBG_TRAP_ADDRESS_WATCH_MODE_ALL = 3
  759. };
  760. /* Additional wave settings */
  761. enum kfd_dbg_trap_flags {
  762. KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP = 1,
  763. };
  764. /* Trap exceptions */
  765. enum kfd_dbg_trap_exception_code {
  766. EC_NONE = 0,
  767. /* per queue */
  768. EC_QUEUE_WAVE_ABORT = 1,
  769. EC_QUEUE_WAVE_TRAP = 2,
  770. EC_QUEUE_WAVE_MATH_ERROR = 3,
  771. EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION = 4,
  772. EC_QUEUE_WAVE_MEMORY_VIOLATION = 5,
  773. EC_QUEUE_WAVE_APERTURE_VIOLATION = 6,
  774. EC_QUEUE_PACKET_DISPATCH_DIM_INVALID = 16,
  775. EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID = 17,
  776. EC_QUEUE_PACKET_DISPATCH_CODE_INVALID = 18,
  777. EC_QUEUE_PACKET_RESERVED = 19,
  778. EC_QUEUE_PACKET_UNSUPPORTED = 20,
  779. EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID = 21,
  780. EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID = 22,
  781. EC_QUEUE_PACKET_VENDOR_UNSUPPORTED = 23,
  782. EC_QUEUE_PREEMPTION_ERROR = 30,
  783. EC_QUEUE_NEW = 31,
  784. /* per device */
  785. EC_DEVICE_QUEUE_DELETE = 32,
  786. EC_DEVICE_MEMORY_VIOLATION = 33,
  787. EC_DEVICE_RAS_ERROR = 34,
  788. EC_DEVICE_FATAL_HALT = 35,
  789. EC_DEVICE_NEW = 36,
  790. /* per process */
  791. EC_PROCESS_RUNTIME = 48,
  792. EC_PROCESS_DEVICE_REMOVE = 49,
  793. EC_MAX
  794. };
  795. /* Mask generated by ecode in kfd_dbg_trap_exception_code */
  796. #define KFD_EC_MASK(ecode) (1ULL << (ecode - 1))
  797. /* Masks for exception code type checks below */
  798. #define KFD_EC_MASK_QUEUE (KFD_EC_MASK(EC_QUEUE_WAVE_ABORT) | \
  799. KFD_EC_MASK(EC_QUEUE_WAVE_TRAP) | \
  800. KFD_EC_MASK(EC_QUEUE_WAVE_MATH_ERROR) | \
  801. KFD_EC_MASK(EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION) | \
  802. KFD_EC_MASK(EC_QUEUE_WAVE_MEMORY_VIOLATION) | \
  803. KFD_EC_MASK(EC_QUEUE_WAVE_APERTURE_VIOLATION) | \
  804. KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_DIM_INVALID) | \
  805. KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID) | \
  806. KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_CODE_INVALID) | \
  807. KFD_EC_MASK(EC_QUEUE_PACKET_RESERVED) | \
  808. KFD_EC_MASK(EC_QUEUE_PACKET_UNSUPPORTED) | \
  809. KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID) | \
  810. KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID) | \
  811. KFD_EC_MASK(EC_QUEUE_PACKET_VENDOR_UNSUPPORTED) | \
  812. KFD_EC_MASK(EC_QUEUE_PREEMPTION_ERROR) | \
  813. KFD_EC_MASK(EC_QUEUE_NEW))
  814. #define KFD_EC_MASK_DEVICE (KFD_EC_MASK(EC_DEVICE_QUEUE_DELETE) | \
  815. KFD_EC_MASK(EC_DEVICE_RAS_ERROR) | \
  816. KFD_EC_MASK(EC_DEVICE_FATAL_HALT) | \
  817. KFD_EC_MASK(EC_DEVICE_MEMORY_VIOLATION) | \
  818. KFD_EC_MASK(EC_DEVICE_NEW))
  819. #define KFD_EC_MASK_PROCESS (KFD_EC_MASK(EC_PROCESS_RUNTIME) | \
  820. KFD_EC_MASK(EC_PROCESS_DEVICE_REMOVE))
  821. /* Checks for exception code types for KFD search */
  822. #define KFD_DBG_EC_TYPE_IS_QUEUE(ecode) \
  823. (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_QUEUE))
  824. #define KFD_DBG_EC_TYPE_IS_DEVICE(ecode) \
  825. (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_DEVICE))
  826. #define KFD_DBG_EC_TYPE_IS_PROCESS(ecode) \
  827. (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_PROCESS))
  828. /* Runtime enable states */
  829. enum kfd_dbg_runtime_state {
  830. DEBUG_RUNTIME_STATE_DISABLED = 0,
  831. DEBUG_RUNTIME_STATE_ENABLED = 1,
  832. DEBUG_RUNTIME_STATE_ENABLED_BUSY = 2,
  833. DEBUG_RUNTIME_STATE_ENABLED_ERROR = 3
  834. };
  835. /* Runtime enable status */
  836. struct kfd_runtime_info {
  837. __u64 r_debug;
  838. __u32 runtime_state;
  839. __u32 ttmp_setup;
  840. };
  841. /* Enable modes for runtime enable */
  842. #define KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK 1
  843. #define KFD_RUNTIME_ENABLE_MODE_TTMP_SAVE_MASK 2
  844. /**
  845. * kfd_ioctl_runtime_enable_args - Arguments for runtime enable
  846. *
  847. * Coordinates debug exception signalling and debug device enablement with runtime.
  848. *
  849. * @r_debug - pointer to user struct for sharing information between ROCr and the debuggger
  850. * @mode_mask - mask to set mode
  851. * KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK - enable runtime for debugging, otherwise disable
  852. * KFD_RUNTIME_ENABLE_MODE_TTMP_SAVE_MASK - enable trap temporary setup (ignore on disable)
  853. * @capabilities_mask - mask to notify runtime on what KFD supports
  854. *
  855. * Return - 0 on SUCCESS.
  856. * - EBUSY if runtime enable call already pending.
  857. * - EEXIST if user queues already active prior to call.
  858. * If process is debug enabled, runtime enable will enable debug devices and
  859. * wait for debugger process to send runtime exception EC_PROCESS_RUNTIME
  860. * to unblock - see kfd_ioctl_dbg_trap_args.
  861. *
  862. */
  863. struct kfd_ioctl_runtime_enable_args {
  864. __u64 r_debug;
  865. __u32 mode_mask;
  866. __u32 capabilities_mask;
  867. };
  868. /* Queue information */
  869. struct kfd_queue_snapshot_entry {
  870. __u64 exception_status;
  871. __u64 ring_base_address;
  872. __u64 write_pointer_address;
  873. __u64 read_pointer_address;
  874. __u64 ctx_save_restore_address;
  875. __u32 queue_id;
  876. __u32 gpu_id;
  877. __u32 ring_size;
  878. __u32 queue_type;
  879. __u32 ctx_save_restore_area_size;
  880. __u32 reserved;
  881. };
  882. /* Queue status return for suspend/resume */
  883. #define KFD_DBG_QUEUE_ERROR_BIT 30
  884. #define KFD_DBG_QUEUE_INVALID_BIT 31
  885. #define KFD_DBG_QUEUE_ERROR_MASK (1 << KFD_DBG_QUEUE_ERROR_BIT)
  886. #define KFD_DBG_QUEUE_INVALID_MASK (1 << KFD_DBG_QUEUE_INVALID_BIT)
  887. /* Context save area header information */
  888. struct kfd_context_save_area_header {
  889. struct {
  890. __u32 control_stack_offset;
  891. __u32 control_stack_size;
  892. __u32 wave_state_offset;
  893. __u32 wave_state_size;
  894. } wave_state;
  895. __u32 debug_offset;
  896. __u32 debug_size;
  897. __u64 err_payload_addr;
  898. __u32 err_event_id;
  899. __u32 reserved1;
  900. };
  901. /*
  902. * Debug operations
  903. *
  904. * For specifics on usage and return values, see documentation per operation
  905. * below. Otherwise, generic error returns apply:
  906. * - ESRCH if the process to debug does not exist.
  907. *
  908. * - EINVAL (with KFD_IOC_DBG_TRAP_ENABLE exempt) if operation
  909. * KFD_IOC_DBG_TRAP_ENABLE has not succeeded prior.
  910. * Also returns this error if GPU hardware scheduling is not supported.
  911. *
  912. * - EPERM (with KFD_IOC_DBG_TRAP_DISABLE exempt) if target process is not
  913. * PTRACE_ATTACHED. KFD_IOC_DBG_TRAP_DISABLE is exempt to allow
  914. * clean up of debug mode as long as process is debug enabled.
  915. *
  916. * - EACCES if any DBG_HW_OP (debug hardware operation) is requested when
  917. * AMDKFD_IOC_RUNTIME_ENABLE has not succeeded prior.
  918. *
  919. * - ENODEV if any GPU does not support debugging on a DBG_HW_OP call.
  920. *
  921. * - Other errors may be returned when a DBG_HW_OP occurs while the GPU
  922. * is in a fatal state.
  923. *
  924. */
  925. enum kfd_dbg_trap_operations {
  926. KFD_IOC_DBG_TRAP_ENABLE = 0,
  927. KFD_IOC_DBG_TRAP_DISABLE = 1,
  928. KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT = 2,
  929. KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED = 3,
  930. KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE = 4, /* DBG_HW_OP */
  931. KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE = 5, /* DBG_HW_OP */
  932. KFD_IOC_DBG_TRAP_SUSPEND_QUEUES = 6, /* DBG_HW_OP */
  933. KFD_IOC_DBG_TRAP_RESUME_QUEUES = 7, /* DBG_HW_OP */
  934. KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH = 8, /* DBG_HW_OP */
  935. KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH = 9, /* DBG_HW_OP */
  936. KFD_IOC_DBG_TRAP_SET_FLAGS = 10,
  937. KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT = 11,
  938. KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO = 12,
  939. KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT = 13,
  940. KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT = 14
  941. };
  942. /**
  943. * kfd_ioctl_dbg_trap_enable_args
  944. *
  945. * Arguments for KFD_IOC_DBG_TRAP_ENABLE.
  946. *
  947. * Enables debug session for target process. Call @op KFD_IOC_DBG_TRAP_DISABLE in
  948. * kfd_ioctl_dbg_trap_args to disable debug session.
  949. *
  950. * @exception_mask (IN) - exceptions to raise to the debugger
  951. * @rinfo_ptr (IN) - pointer to runtime info buffer (see kfd_runtime_info)
  952. * @rinfo_size (IN/OUT) - size of runtime info buffer in bytes
  953. * @dbg_fd (IN) - fd the KFD will nofify the debugger with of raised
  954. * exceptions set in exception_mask.
  955. *
  956. * Generic errors apply (see kfd_dbg_trap_operations).
  957. * Return - 0 on SUCCESS.
  958. * Copies KFD saved kfd_runtime_info to @rinfo_ptr on enable.
  959. * Size of kfd_runtime saved by the KFD returned to @rinfo_size.
  960. * - EBADF if KFD cannot get a reference to dbg_fd.
  961. * - EFAULT if KFD cannot copy runtime info to rinfo_ptr.
  962. * - EINVAL if target process is already debug enabled.
  963. *
  964. */
  965. struct kfd_ioctl_dbg_trap_enable_args {
  966. __u64 exception_mask;
  967. __u64 rinfo_ptr;
  968. __u32 rinfo_size;
  969. __u32 dbg_fd;
  970. };
  971. /**
  972. * kfd_ioctl_dbg_trap_send_runtime_event_args
  973. *
  974. *
  975. * Arguments for KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT.
  976. * Raises exceptions to runtime.
  977. *
  978. * @exception_mask (IN) - exceptions to raise to runtime
  979. * @gpu_id (IN) - target device id
  980. * @queue_id (IN) - target queue id
  981. *
  982. * Generic errors apply (see kfd_dbg_trap_operations).
  983. * Return - 0 on SUCCESS.
  984. * - ENODEV if gpu_id not found.
  985. * If exception_mask contains EC_PROCESS_RUNTIME, unblocks pending
  986. * AMDKFD_IOC_RUNTIME_ENABLE call - see kfd_ioctl_runtime_enable_args.
  987. * All other exceptions are raised to runtime through err_payload_addr.
  988. * See kfd_context_save_area_header.
  989. */
  990. struct kfd_ioctl_dbg_trap_send_runtime_event_args {
  991. __u64 exception_mask;
  992. __u32 gpu_id;
  993. __u32 queue_id;
  994. };
  995. /**
  996. * kfd_ioctl_dbg_trap_set_exceptions_enabled_args
  997. *
  998. * Arguments for KFD_IOC_SET_EXCEPTIONS_ENABLED
  999. * Set new exceptions to be raised to the debugger.
  1000. *
  1001. * @exception_mask (IN) - new exceptions to raise the debugger
  1002. *
  1003. * Generic errors apply (see kfd_dbg_trap_operations).
  1004. * Return - 0 on SUCCESS.
  1005. */
  1006. struct kfd_ioctl_dbg_trap_set_exceptions_enabled_args {
  1007. __u64 exception_mask;
  1008. };
  1009. /**
  1010. * kfd_ioctl_dbg_trap_set_wave_launch_override_args
  1011. *
  1012. * Arguments for KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE
  1013. * Enable HW exceptions to raise trap.
  1014. *
  1015. * @override_mode (IN) - see kfd_dbg_trap_override_mode
  1016. * @enable_mask (IN/OUT) - reference kfd_dbg_trap_mask.
  1017. * IN is the override modes requested to be enabled.
  1018. * OUT is referenced in Return below.
  1019. * @support_request_mask (IN/OUT) - reference kfd_dbg_trap_mask.
  1020. * IN is the override modes requested for support check.
  1021. * OUT is referenced in Return below.
  1022. *
  1023. * Generic errors apply (see kfd_dbg_trap_operations).
  1024. * Return - 0 on SUCCESS.
  1025. * Previous enablement is returned in @enable_mask.
  1026. * Actual override support is returned in @support_request_mask.
  1027. * - EINVAL if override mode is not supported.
  1028. * - EACCES if trap support requested is not actually supported.
  1029. * i.e. enable_mask (IN) is not a subset of support_request_mask (OUT).
  1030. * Otherwise it is considered a generic error (see kfd_dbg_trap_operations).
  1031. */
  1032. struct kfd_ioctl_dbg_trap_set_wave_launch_override_args {
  1033. __u32 override_mode;
  1034. __u32 enable_mask;
  1035. __u32 support_request_mask;
  1036. __u32 pad;
  1037. };
  1038. /**
  1039. * kfd_ioctl_dbg_trap_set_wave_launch_mode_args
  1040. *
  1041. * Arguments for KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE
  1042. * Set wave launch mode.
  1043. *
  1044. * @mode (IN) - see kfd_dbg_trap_wave_launch_mode
  1045. *
  1046. * Generic errors apply (see kfd_dbg_trap_operations).
  1047. * Return - 0 on SUCCESS.
  1048. */
  1049. struct kfd_ioctl_dbg_trap_set_wave_launch_mode_args {
  1050. __u32 launch_mode;
  1051. __u32 pad;
  1052. };
  1053. /**
  1054. * kfd_ioctl_dbg_trap_suspend_queues_ags
  1055. *
  1056. * Arguments for KFD_IOC_DBG_TRAP_SUSPEND_QUEUES
  1057. * Suspend queues.
  1058. *
  1059. * @exception_mask (IN) - raised exceptions to clear
  1060. * @queue_array_ptr (IN) - pointer to array of queue ids (u32 per queue id)
  1061. * to suspend
  1062. * @num_queues (IN) - number of queues to suspend in @queue_array_ptr
  1063. * @grace_period (IN) - wave time allowance before preemption
  1064. * per 1K GPU clock cycle unit
  1065. *
  1066. * Generic errors apply (see kfd_dbg_trap_operations).
  1067. * Destruction of a suspended queue is blocked until the queue is
  1068. * resumed. This allows the debugger to access queue information and
  1069. * the its context save area without running into a race condition on
  1070. * queue destruction.
  1071. * Automatically copies per queue context save area header information
  1072. * into the save area base
  1073. * (see kfd_queue_snapshot_entry and kfd_context_save_area_header).
  1074. *
  1075. * Return - Number of queues suspended on SUCCESS.
  1076. * . KFD_DBG_QUEUE_ERROR_MASK and KFD_DBG_QUEUE_INVALID_MASK masked
  1077. * for each queue id in @queue_array_ptr array reports unsuccessful
  1078. * suspend reason.
  1079. * KFD_DBG_QUEUE_ERROR_MASK = HW failure.
  1080. * KFD_DBG_QUEUE_INVALID_MASK = queue does not exist, is new or
  1081. * is being destroyed.
  1082. */
  1083. struct kfd_ioctl_dbg_trap_suspend_queues_args {
  1084. __u64 exception_mask;
  1085. __u64 queue_array_ptr;
  1086. __u32 num_queues;
  1087. __u32 grace_period;
  1088. };
  1089. /**
  1090. * kfd_ioctl_dbg_trap_resume_queues_args
  1091. *
  1092. * Arguments for KFD_IOC_DBG_TRAP_RESUME_QUEUES
  1093. * Resume queues.
  1094. *
  1095. * @queue_array_ptr (IN) - pointer to array of queue ids (u32 per queue id)
  1096. * to resume
  1097. * @num_queues (IN) - number of queues to resume in @queue_array_ptr
  1098. *
  1099. * Generic errors apply (see kfd_dbg_trap_operations).
  1100. * Return - Number of queues resumed on SUCCESS.
  1101. * KFD_DBG_QUEUE_ERROR_MASK and KFD_DBG_QUEUE_INVALID_MASK mask
  1102. * for each queue id in @queue_array_ptr array reports unsuccessful
  1103. * resume reason.
  1104. * KFD_DBG_QUEUE_ERROR_MASK = HW failure.
  1105. * KFD_DBG_QUEUE_INVALID_MASK = queue does not exist.
  1106. */
  1107. struct kfd_ioctl_dbg_trap_resume_queues_args {
  1108. __u64 queue_array_ptr;
  1109. __u32 num_queues;
  1110. __u32 pad;
  1111. };
  1112. /**
  1113. * kfd_ioctl_dbg_trap_set_node_address_watch_args
  1114. *
  1115. * Arguments for KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH
  1116. * Sets address watch for device.
  1117. *
  1118. * @address (IN) - watch address to set
  1119. * @mode (IN) - see kfd_dbg_trap_address_watch_mode
  1120. * @mask (IN) - watch address mask
  1121. * @gpu_id (IN) - target gpu to set watch point
  1122. * @id (OUT) - watch id allocated
  1123. *
  1124. * Generic errors apply (see kfd_dbg_trap_operations).
  1125. * Return - 0 on SUCCESS.
  1126. * Allocated watch ID returned to @id.
  1127. * - ENODEV if gpu_id not found.
  1128. * - ENOMEM if watch IDs can be allocated
  1129. */
  1130. struct kfd_ioctl_dbg_trap_set_node_address_watch_args {
  1131. __u64 address;
  1132. __u32 mode;
  1133. __u32 mask;
  1134. __u32 gpu_id;
  1135. __u32 id;
  1136. };
  1137. /**
  1138. * kfd_ioctl_dbg_trap_clear_node_address_watch_args
  1139. *
  1140. * Arguments for KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH
  1141. * Clear address watch for device.
  1142. *
  1143. * @gpu_id (IN) - target device to clear watch point
  1144. * @id (IN) - allocated watch id to clear
  1145. *
  1146. * Generic errors apply (see kfd_dbg_trap_operations).
  1147. * Return - 0 on SUCCESS.
  1148. * - ENODEV if gpu_id not found.
  1149. * - EINVAL if watch ID has not been allocated.
  1150. */
  1151. struct kfd_ioctl_dbg_trap_clear_node_address_watch_args {
  1152. __u32 gpu_id;
  1153. __u32 id;
  1154. };
  1155. /**
  1156. * kfd_ioctl_dbg_trap_set_flags_args
  1157. *
  1158. * Arguments for KFD_IOC_DBG_TRAP_SET_FLAGS
  1159. * Sets flags for wave behaviour.
  1160. *
  1161. * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled
  1162. *
  1163. * Generic errors apply (see kfd_dbg_trap_operations).
  1164. * Return - 0 on SUCCESS.
  1165. * - EACCESS if any debug device does not allow flag options.
  1166. */
  1167. struct kfd_ioctl_dbg_trap_set_flags_args {
  1168. __u32 flags;
  1169. __u32 pad;
  1170. };
  1171. /**
  1172. * kfd_ioctl_dbg_trap_query_debug_event_args
  1173. *
  1174. * Arguments for KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT
  1175. *
  1176. * Find one or more raised exceptions. This function can return multiple
  1177. * exceptions from a single queue or a single device with one call. To find
  1178. * all raised exceptions, this function must be called repeatedly until it
  1179. * returns -EAGAIN. Returned exceptions can optionally be cleared by
  1180. * setting the corresponding bit in the @exception_mask input parameter.
  1181. * However, clearing an exception prevents retrieving further information
  1182. * about it with KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO.
  1183. *
  1184. * @exception_mask (IN/OUT) - exception to clear (IN) and raised (OUT)
  1185. * @gpu_id (OUT) - gpu id of exceptions raised
  1186. * @queue_id (OUT) - queue id of exceptions raised
  1187. *
  1188. * Generic errors apply (see kfd_dbg_trap_operations).
  1189. * Return - 0 on raised exception found
  1190. * Raised exceptions found are returned in @exception mask
  1191. * with reported source id returned in @gpu_id or @queue_id.
  1192. * - EAGAIN if no raised exception has been found
  1193. */
  1194. struct kfd_ioctl_dbg_trap_query_debug_event_args {
  1195. __u64 exception_mask;
  1196. __u32 gpu_id;
  1197. __u32 queue_id;
  1198. };
  1199. /**
  1200. * kfd_ioctl_dbg_trap_query_exception_info_args
  1201. *
  1202. * Arguments KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO
  1203. * Get additional info on raised exception.
  1204. *
  1205. * @info_ptr (IN) - pointer to exception info buffer to copy to
  1206. * @info_size (IN/OUT) - exception info buffer size (bytes)
  1207. * @source_id (IN) - target gpu or queue id
  1208. * @exception_code (IN) - target exception
  1209. * @clear_exception (IN) - clear raised @exception_code exception
  1210. * (0 = false, 1 = true)
  1211. *
  1212. * Generic errors apply (see kfd_dbg_trap_operations).
  1213. * Return - 0 on SUCCESS.
  1214. * If @exception_code is EC_DEVICE_MEMORY_VIOLATION, copy @info_size(OUT)
  1215. * bytes of memory exception data to @info_ptr.
  1216. * If @exception_code is EC_PROCESS_RUNTIME, copy saved
  1217. * kfd_runtime_info to @info_ptr.
  1218. * Actual required @info_ptr size (bytes) is returned in @info_size.
  1219. */
  1220. struct kfd_ioctl_dbg_trap_query_exception_info_args {
  1221. __u64 info_ptr;
  1222. __u32 info_size;
  1223. __u32 source_id;
  1224. __u32 exception_code;
  1225. __u32 clear_exception;
  1226. };
  1227. /**
  1228. * kfd_ioctl_dbg_trap_get_queue_snapshot_args
  1229. *
  1230. * Arguments KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT
  1231. * Get queue information.
  1232. *
  1233. * @exception_mask (IN) - exceptions raised to clear
  1234. * @snapshot_buf_ptr (IN) - queue snapshot entry buffer (see kfd_queue_snapshot_entry)
  1235. * @num_queues (IN/OUT) - number of queue snapshot entries
  1236. * The debugger specifies the size of the array allocated in @num_queues.
  1237. * KFD returns the number of queues that actually existed. If this is
  1238. * larger than the size specified by the debugger, KFD will not overflow
  1239. * the array allocated by the debugger.
  1240. *
  1241. * @entry_size (IN/OUT) - size per entry in bytes
  1242. * The debugger specifies sizeof(struct kfd_queue_snapshot_entry) in
  1243. * @entry_size. KFD returns the number of bytes actually populated per
  1244. * entry. The debugger should use the KFD_IOCTL_MINOR_VERSION to determine,
  1245. * which fields in struct kfd_queue_snapshot_entry are valid. This allows
  1246. * growing the ABI in a backwards compatible manner.
  1247. * Note that entry_size(IN) should still be used to stride the snapshot buffer in the
  1248. * event that it's larger than actual kfd_queue_snapshot_entry.
  1249. *
  1250. * Generic errors apply (see kfd_dbg_trap_operations).
  1251. * Return - 0 on SUCCESS.
  1252. * Copies @num_queues(IN) queue snapshot entries of size @entry_size(IN)
  1253. * into @snapshot_buf_ptr if @num_queues(IN) > 0.
  1254. * Otherwise return @num_queues(OUT) queue snapshot entries that exist.
  1255. */
  1256. struct kfd_ioctl_dbg_trap_queue_snapshot_args {
  1257. __u64 exception_mask;
  1258. __u64 snapshot_buf_ptr;
  1259. __u32 num_queues;
  1260. __u32 entry_size;
  1261. };
  1262. /**
  1263. * kfd_ioctl_dbg_trap_get_device_snapshot_args
  1264. *
  1265. * Arguments for KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT
  1266. * Get device information.
  1267. *
  1268. * @exception_mask (IN) - exceptions raised to clear
  1269. * @snapshot_buf_ptr (IN) - pointer to snapshot buffer (see kfd_dbg_device_info_entry)
  1270. * @num_devices (IN/OUT) - number of debug devices to snapshot
  1271. * The debugger specifies the size of the array allocated in @num_devices.
  1272. * KFD returns the number of devices that actually existed. If this is
  1273. * larger than the size specified by the debugger, KFD will not overflow
  1274. * the array allocated by the debugger.
  1275. *
  1276. * @entry_size (IN/OUT) - size per entry in bytes
  1277. * The debugger specifies sizeof(struct kfd_dbg_device_info_entry) in
  1278. * @entry_size. KFD returns the number of bytes actually populated. The
  1279. * debugger should use KFD_IOCTL_MINOR_VERSION to determine, which fields
  1280. * in struct kfd_dbg_device_info_entry are valid. This allows growing the
  1281. * ABI in a backwards compatible manner.
  1282. * Note that entry_size(IN) should still be used to stride the snapshot buffer in the
  1283. * event that it's larger than actual kfd_dbg_device_info_entry.
  1284. *
  1285. * Generic errors apply (see kfd_dbg_trap_operations).
  1286. * Return - 0 on SUCCESS.
  1287. * Copies @num_devices(IN) device snapshot entries of size @entry_size(IN)
  1288. * into @snapshot_buf_ptr if @num_devices(IN) > 0.
  1289. * Otherwise return @num_devices(OUT) queue snapshot entries that exist.
  1290. */
  1291. struct kfd_ioctl_dbg_trap_device_snapshot_args {
  1292. __u64 exception_mask;
  1293. __u64 snapshot_buf_ptr;
  1294. __u32 num_devices;
  1295. __u32 entry_size;
  1296. };
  1297. /**
  1298. * kfd_ioctl_dbg_trap_args
  1299. *
  1300. * Arguments to debug target process.
  1301. *
  1302. * @pid - target process to debug
  1303. * @op - debug operation (see kfd_dbg_trap_operations)
  1304. *
  1305. * @op determines which union struct args to use.
  1306. * Refer to kern docs for each kfd_ioctl_dbg_trap_*_args struct.
  1307. */
  1308. struct kfd_ioctl_dbg_trap_args {
  1309. __u32 pid;
  1310. __u32 op;
  1311. union {
  1312. struct kfd_ioctl_dbg_trap_enable_args enable;
  1313. struct kfd_ioctl_dbg_trap_send_runtime_event_args send_runtime_event;
  1314. struct kfd_ioctl_dbg_trap_set_exceptions_enabled_args set_exceptions_enabled;
  1315. struct kfd_ioctl_dbg_trap_set_wave_launch_override_args launch_override;
  1316. struct kfd_ioctl_dbg_trap_set_wave_launch_mode_args launch_mode;
  1317. struct kfd_ioctl_dbg_trap_suspend_queues_args suspend_queues;
  1318. struct kfd_ioctl_dbg_trap_resume_queues_args resume_queues;
  1319. struct kfd_ioctl_dbg_trap_set_node_address_watch_args set_node_address_watch;
  1320. struct kfd_ioctl_dbg_trap_clear_node_address_watch_args clear_node_address_watch;
  1321. struct kfd_ioctl_dbg_trap_set_flags_args set_flags;
  1322. struct kfd_ioctl_dbg_trap_query_debug_event_args query_debug_event;
  1323. struct kfd_ioctl_dbg_trap_query_exception_info_args query_exception_info;
  1324. struct kfd_ioctl_dbg_trap_queue_snapshot_args queue_snapshot;
  1325. struct kfd_ioctl_dbg_trap_device_snapshot_args device_snapshot;
  1326. };
  1327. };
  1328. #define AMDKFD_IOCTL_BASE 'K'
  1329. #define AMDKFD_IO(nr) _IO(AMDKFD_IOCTL_BASE, nr)
  1330. #define AMDKFD_IOR(nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type)
  1331. #define AMDKFD_IOW(nr, type) _IOW(AMDKFD_IOCTL_BASE, nr, type)
  1332. #define AMDKFD_IOWR(nr, type) _IOWR(AMDKFD_IOCTL_BASE, nr, type)
  1333. #define AMDKFD_IOC_GET_VERSION \
  1334. AMDKFD_IOR(0x01, struct kfd_ioctl_get_version_args)
  1335. #define AMDKFD_IOC_CREATE_QUEUE \
  1336. AMDKFD_IOWR(0x02, struct kfd_ioctl_create_queue_args)
  1337. #define AMDKFD_IOC_DESTROY_QUEUE \
  1338. AMDKFD_IOWR(0x03, struct kfd_ioctl_destroy_queue_args)
  1339. #define AMDKFD_IOC_SET_MEMORY_POLICY \
  1340. AMDKFD_IOW(0x04, struct kfd_ioctl_set_memory_policy_args)
  1341. #define AMDKFD_IOC_GET_CLOCK_COUNTERS \
  1342. AMDKFD_IOWR(0x05, struct kfd_ioctl_get_clock_counters_args)
  1343. #define AMDKFD_IOC_GET_PROCESS_APERTURES \
  1344. AMDKFD_IOR(0x06, struct kfd_ioctl_get_process_apertures_args)
  1345. #define AMDKFD_IOC_UPDATE_QUEUE \
  1346. AMDKFD_IOW(0x07, struct kfd_ioctl_update_queue_args)
  1347. #define AMDKFD_IOC_CREATE_EVENT \
  1348. AMDKFD_IOWR(0x08, struct kfd_ioctl_create_event_args)
  1349. #define AMDKFD_IOC_DESTROY_EVENT \
  1350. AMDKFD_IOW(0x09, struct kfd_ioctl_destroy_event_args)
  1351. #define AMDKFD_IOC_SET_EVENT \
  1352. AMDKFD_IOW(0x0A, struct kfd_ioctl_set_event_args)
  1353. #define AMDKFD_IOC_RESET_EVENT \
  1354. AMDKFD_IOW(0x0B, struct kfd_ioctl_reset_event_args)
  1355. #define AMDKFD_IOC_WAIT_EVENTS \
  1356. AMDKFD_IOWR(0x0C, struct kfd_ioctl_wait_events_args)
  1357. #define AMDKFD_IOC_DBG_REGISTER_DEPRECATED \
  1358. AMDKFD_IOW(0x0D, struct kfd_ioctl_dbg_register_args)
  1359. #define AMDKFD_IOC_DBG_UNREGISTER_DEPRECATED \
  1360. AMDKFD_IOW(0x0E, struct kfd_ioctl_dbg_unregister_args)
  1361. #define AMDKFD_IOC_DBG_ADDRESS_WATCH_DEPRECATED \
  1362. AMDKFD_IOW(0x0F, struct kfd_ioctl_dbg_address_watch_args)
  1363. #define AMDKFD_IOC_DBG_WAVE_CONTROL_DEPRECATED \
  1364. AMDKFD_IOW(0x10, struct kfd_ioctl_dbg_wave_control_args)
  1365. #define AMDKFD_IOC_SET_SCRATCH_BACKING_VA \
  1366. AMDKFD_IOWR(0x11, struct kfd_ioctl_set_scratch_backing_va_args)
  1367. #define AMDKFD_IOC_GET_TILE_CONFIG \
  1368. AMDKFD_IOWR(0x12, struct kfd_ioctl_get_tile_config_args)
  1369. #define AMDKFD_IOC_SET_TRAP_HANDLER \
  1370. AMDKFD_IOW(0x13, struct kfd_ioctl_set_trap_handler_args)
  1371. #define AMDKFD_IOC_GET_PROCESS_APERTURES_NEW \
  1372. AMDKFD_IOWR(0x14, \
  1373. struct kfd_ioctl_get_process_apertures_new_args)
  1374. #define AMDKFD_IOC_ACQUIRE_VM \
  1375. AMDKFD_IOW(0x15, struct kfd_ioctl_acquire_vm_args)
  1376. #define AMDKFD_IOC_ALLOC_MEMORY_OF_GPU \
  1377. AMDKFD_IOWR(0x16, struct kfd_ioctl_alloc_memory_of_gpu_args)
  1378. #define AMDKFD_IOC_FREE_MEMORY_OF_GPU \
  1379. AMDKFD_IOW(0x17, struct kfd_ioctl_free_memory_of_gpu_args)
  1380. #define AMDKFD_IOC_MAP_MEMORY_TO_GPU \
  1381. AMDKFD_IOWR(0x18, struct kfd_ioctl_map_memory_to_gpu_args)
  1382. #define AMDKFD_IOC_UNMAP_MEMORY_FROM_GPU \
  1383. AMDKFD_IOWR(0x19, struct kfd_ioctl_unmap_memory_from_gpu_args)
  1384. #define AMDKFD_IOC_SET_CU_MASK \
  1385. AMDKFD_IOW(0x1A, struct kfd_ioctl_set_cu_mask_args)
  1386. #define AMDKFD_IOC_GET_QUEUE_WAVE_STATE \
  1387. AMDKFD_IOWR(0x1B, struct kfd_ioctl_get_queue_wave_state_args)
  1388. #define AMDKFD_IOC_GET_DMABUF_INFO \
  1389. AMDKFD_IOWR(0x1C, struct kfd_ioctl_get_dmabuf_info_args)
  1390. #define AMDKFD_IOC_IMPORT_DMABUF \
  1391. AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
  1392. #define AMDKFD_IOC_ALLOC_QUEUE_GWS \
  1393. AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
  1394. #define AMDKFD_IOC_SMI_EVENTS \
  1395. AMDKFD_IOWR(0x1F, struct kfd_ioctl_smi_events_args)
  1396. #define AMDKFD_IOC_SVM AMDKFD_IOWR(0x20, struct kfd_ioctl_svm_args)
  1397. #define AMDKFD_IOC_SET_XNACK_MODE \
  1398. AMDKFD_IOWR(0x21, struct kfd_ioctl_set_xnack_mode_args)
  1399. #define AMDKFD_IOC_CRIU_OP \
  1400. AMDKFD_IOWR(0x22, struct kfd_ioctl_criu_args)
  1401. #define AMDKFD_IOC_AVAILABLE_MEMORY \
  1402. AMDKFD_IOWR(0x23, struct kfd_ioctl_get_available_memory_args)
  1403. #define AMDKFD_IOC_EXPORT_DMABUF \
  1404. AMDKFD_IOWR(0x24, struct kfd_ioctl_export_dmabuf_args)
  1405. #define AMDKFD_IOC_RUNTIME_ENABLE \
  1406. AMDKFD_IOWR(0x25, struct kfd_ioctl_runtime_enable_args)
  1407. #define AMDKFD_IOC_DBG_TRAP \
  1408. AMDKFD_IOWR(0x26, struct kfd_ioctl_dbg_trap_args)
  1409. #define AMDKFD_COMMAND_START 0x01
  1410. #define AMDKFD_COMMAND_END 0x27
  1411. #endif