kfd_ioctl.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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. */
  38. #define KFD_IOCTL_MAJOR_VERSION 1
  39. #define KFD_IOCTL_MINOR_VERSION 11
  40. struct kfd_ioctl_get_version_args {
  41. __u32 major_version; /* from KFD */
  42. __u32 minor_version; /* from KFD */
  43. };
  44. /* For kfd_ioctl_create_queue_args.queue_type. */
  45. #define KFD_IOC_QUEUE_TYPE_COMPUTE 0x0
  46. #define KFD_IOC_QUEUE_TYPE_SDMA 0x1
  47. #define KFD_IOC_QUEUE_TYPE_COMPUTE_AQL 0x2
  48. #define KFD_IOC_QUEUE_TYPE_SDMA_XGMI 0x3
  49. #define KFD_MAX_QUEUE_PERCENTAGE 100
  50. #define KFD_MAX_QUEUE_PRIORITY 15
  51. struct kfd_ioctl_create_queue_args {
  52. __u64 ring_base_address; /* to KFD */
  53. __u64 write_pointer_address; /* from KFD */
  54. __u64 read_pointer_address; /* from KFD */
  55. __u64 doorbell_offset; /* from KFD */
  56. __u32 ring_size; /* to KFD */
  57. __u32 gpu_id; /* to KFD */
  58. __u32 queue_type; /* to KFD */
  59. __u32 queue_percentage; /* to KFD */
  60. __u32 queue_priority; /* to KFD */
  61. __u32 queue_id; /* from KFD */
  62. __u64 eop_buffer_address; /* to KFD */
  63. __u64 eop_buffer_size; /* to KFD */
  64. __u64 ctx_save_restore_address; /* to KFD */
  65. __u32 ctx_save_restore_size; /* to KFD */
  66. __u32 ctl_stack_size; /* to KFD */
  67. };
  68. struct kfd_ioctl_destroy_queue_args {
  69. __u32 queue_id; /* to KFD */
  70. __u32 pad;
  71. };
  72. struct kfd_ioctl_update_queue_args {
  73. __u64 ring_base_address; /* to KFD */
  74. __u32 queue_id; /* to KFD */
  75. __u32 ring_size; /* to KFD */
  76. __u32 queue_percentage; /* to KFD */
  77. __u32 queue_priority; /* to KFD */
  78. };
  79. struct kfd_ioctl_set_cu_mask_args {
  80. __u32 queue_id; /* to KFD */
  81. __u32 num_cu_mask; /* to KFD */
  82. __u64 cu_mask_ptr; /* to KFD */
  83. };
  84. struct kfd_ioctl_get_queue_wave_state_args {
  85. __u64 ctl_stack_address; /* to KFD */
  86. __u32 ctl_stack_used_size; /* from KFD */
  87. __u32 save_area_used_size; /* from KFD */
  88. __u32 queue_id; /* to KFD */
  89. __u32 pad;
  90. };
  91. struct kfd_ioctl_get_available_memory_args {
  92. __u64 available; /* from KFD */
  93. __u32 gpu_id; /* to KFD */
  94. __u32 pad;
  95. };
  96. /* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */
  97. #define KFD_IOC_CACHE_POLICY_COHERENT 0
  98. #define KFD_IOC_CACHE_POLICY_NONCOHERENT 1
  99. struct kfd_ioctl_set_memory_policy_args {
  100. __u64 alternate_aperture_base; /* to KFD */
  101. __u64 alternate_aperture_size; /* to KFD */
  102. __u32 gpu_id; /* to KFD */
  103. __u32 default_policy; /* to KFD */
  104. __u32 alternate_policy; /* to KFD */
  105. __u32 pad;
  106. };
  107. /*
  108. * All counters are monotonic. They are used for profiling of compute jobs.
  109. * The profiling is done by userspace.
  110. *
  111. * In case of GPU reset, the counter should not be affected.
  112. */
  113. struct kfd_ioctl_get_clock_counters_args {
  114. __u64 gpu_clock_counter; /* from KFD */
  115. __u64 cpu_clock_counter; /* from KFD */
  116. __u64 system_clock_counter; /* from KFD */
  117. __u64 system_clock_freq; /* from KFD */
  118. __u32 gpu_id; /* to KFD */
  119. __u32 pad;
  120. };
  121. struct kfd_process_device_apertures {
  122. __u64 lds_base; /* from KFD */
  123. __u64 lds_limit; /* from KFD */
  124. __u64 scratch_base; /* from KFD */
  125. __u64 scratch_limit; /* from KFD */
  126. __u64 gpuvm_base; /* from KFD */
  127. __u64 gpuvm_limit; /* from KFD */
  128. __u32 gpu_id; /* from KFD */
  129. __u32 pad;
  130. };
  131. /*
  132. * AMDKFD_IOC_GET_PROCESS_APERTURES is deprecated. Use
  133. * AMDKFD_IOC_GET_PROCESS_APERTURES_NEW instead, which supports an
  134. * unlimited number of GPUs.
  135. */
  136. #define NUM_OF_SUPPORTED_GPUS 7
  137. struct kfd_ioctl_get_process_apertures_args {
  138. struct kfd_process_device_apertures
  139. process_apertures[NUM_OF_SUPPORTED_GPUS];/* from KFD */
  140. /* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS] */
  141. __u32 num_of_nodes;
  142. __u32 pad;
  143. };
  144. struct kfd_ioctl_get_process_apertures_new_args {
  145. /* User allocated. Pointer to struct kfd_process_device_apertures
  146. * filled in by Kernel
  147. */
  148. __u64 kfd_process_device_apertures_ptr;
  149. /* to KFD - indicates amount of memory present in
  150. * kfd_process_device_apertures_ptr
  151. * from KFD - Number of entries filled by KFD.
  152. */
  153. __u32 num_of_nodes;
  154. __u32 pad;
  155. };
  156. #define MAX_ALLOWED_NUM_POINTS 100
  157. #define MAX_ALLOWED_AW_BUFF_SIZE 4096
  158. #define MAX_ALLOWED_WAC_BUFF_SIZE 128
  159. struct kfd_ioctl_dbg_register_args {
  160. __u32 gpu_id; /* to KFD */
  161. __u32 pad;
  162. };
  163. struct kfd_ioctl_dbg_unregister_args {
  164. __u32 gpu_id; /* to KFD */
  165. __u32 pad;
  166. };
  167. struct kfd_ioctl_dbg_address_watch_args {
  168. __u64 content_ptr; /* a pointer to the actual content */
  169. __u32 gpu_id; /* to KFD */
  170. __u32 buf_size_in_bytes; /*including gpu_id and buf_size */
  171. };
  172. struct kfd_ioctl_dbg_wave_control_args {
  173. __u64 content_ptr; /* a pointer to the actual content */
  174. __u32 gpu_id; /* to KFD */
  175. __u32 buf_size_in_bytes; /*including gpu_id and buf_size */
  176. };
  177. #define KFD_INVALID_FD 0xffffffff
  178. /* Matching HSA_EVENTTYPE */
  179. #define KFD_IOC_EVENT_SIGNAL 0
  180. #define KFD_IOC_EVENT_NODECHANGE 1
  181. #define KFD_IOC_EVENT_DEVICESTATECHANGE 2
  182. #define KFD_IOC_EVENT_HW_EXCEPTION 3
  183. #define KFD_IOC_EVENT_SYSTEM_EVENT 4
  184. #define KFD_IOC_EVENT_DEBUG_EVENT 5
  185. #define KFD_IOC_EVENT_PROFILE_EVENT 6
  186. #define KFD_IOC_EVENT_QUEUE_EVENT 7
  187. #define KFD_IOC_EVENT_MEMORY 8
  188. #define KFD_IOC_WAIT_RESULT_COMPLETE 0
  189. #define KFD_IOC_WAIT_RESULT_TIMEOUT 1
  190. #define KFD_IOC_WAIT_RESULT_FAIL 2
  191. #define KFD_SIGNAL_EVENT_LIMIT 4096
  192. /* For kfd_event_data.hw_exception_data.reset_type. */
  193. #define KFD_HW_EXCEPTION_WHOLE_GPU_RESET 0
  194. #define KFD_HW_EXCEPTION_PER_ENGINE_RESET 1
  195. /* For kfd_event_data.hw_exception_data.reset_cause. */
  196. #define KFD_HW_EXCEPTION_GPU_HANG 0
  197. #define KFD_HW_EXCEPTION_ECC 1
  198. /* For kfd_hsa_memory_exception_data.ErrorType */
  199. #define KFD_MEM_ERR_NO_RAS 0
  200. #define KFD_MEM_ERR_SRAM_ECC 1
  201. #define KFD_MEM_ERR_POISON_CONSUMED 2
  202. #define KFD_MEM_ERR_GPU_HANG 3
  203. struct kfd_ioctl_create_event_args {
  204. __u64 event_page_offset; /* from KFD */
  205. __u32 event_trigger_data; /* from KFD - signal events only */
  206. __u32 event_type; /* to KFD */
  207. __u32 auto_reset; /* to KFD */
  208. __u32 node_id; /* to KFD - only valid for certain
  209. event types */
  210. __u32 event_id; /* from KFD */
  211. __u32 event_slot_index; /* from KFD */
  212. };
  213. struct kfd_ioctl_destroy_event_args {
  214. __u32 event_id; /* to KFD */
  215. __u32 pad;
  216. };
  217. struct kfd_ioctl_set_event_args {
  218. __u32 event_id; /* to KFD */
  219. __u32 pad;
  220. };
  221. struct kfd_ioctl_reset_event_args {
  222. __u32 event_id; /* to KFD */
  223. __u32 pad;
  224. };
  225. struct kfd_memory_exception_failure {
  226. __u32 NotPresent; /* Page not present or supervisor privilege */
  227. __u32 ReadOnly; /* Write access to a read-only page */
  228. __u32 NoExecute; /* Execute access to a page marked NX */
  229. __u32 imprecise; /* Can't determine the exact fault address */
  230. };
  231. /* memory exception data */
  232. struct kfd_hsa_memory_exception_data {
  233. struct kfd_memory_exception_failure failure;
  234. __u64 va;
  235. __u32 gpu_id;
  236. __u32 ErrorType; /* 0 = no RAS error,
  237. * 1 = ECC_SRAM,
  238. * 2 = Link_SYNFLOOD (poison),
  239. * 3 = GPU hang (not attributable to a specific cause),
  240. * other values reserved
  241. */
  242. };
  243. /* hw exception data */
  244. struct kfd_hsa_hw_exception_data {
  245. __u32 reset_type;
  246. __u32 reset_cause;
  247. __u32 memory_lost;
  248. __u32 gpu_id;
  249. };
  250. /* Event data */
  251. struct kfd_event_data {
  252. union {
  253. struct kfd_hsa_memory_exception_data memory_exception_data;
  254. struct kfd_hsa_hw_exception_data hw_exception_data;
  255. }; /* From KFD */
  256. __u64 kfd_event_data_ext; /* pointer to an extension structure
  257. for future exception types */
  258. __u32 event_id; /* to KFD */
  259. __u32 pad;
  260. };
  261. struct kfd_ioctl_wait_events_args {
  262. __u64 events_ptr; /* pointed to struct
  263. kfd_event_data array, to KFD */
  264. __u32 num_events; /* to KFD */
  265. __u32 wait_for_all; /* to KFD */
  266. __u32 timeout; /* to KFD */
  267. __u32 wait_result; /* from KFD */
  268. };
  269. struct kfd_ioctl_set_scratch_backing_va_args {
  270. __u64 va_addr; /* to KFD */
  271. __u32 gpu_id; /* to KFD */
  272. __u32 pad;
  273. };
  274. struct kfd_ioctl_get_tile_config_args {
  275. /* to KFD: pointer to tile array */
  276. __u64 tile_config_ptr;
  277. /* to KFD: pointer to macro tile array */
  278. __u64 macro_tile_config_ptr;
  279. /* to KFD: array size allocated by user mode
  280. * from KFD: array size filled by kernel
  281. */
  282. __u32 num_tile_configs;
  283. /* to KFD: array size allocated by user mode
  284. * from KFD: array size filled by kernel
  285. */
  286. __u32 num_macro_tile_configs;
  287. __u32 gpu_id; /* to KFD */
  288. __u32 gb_addr_config; /* from KFD */
  289. __u32 num_banks; /* from KFD */
  290. __u32 num_ranks; /* from KFD */
  291. /* struct size can be extended later if needed
  292. * without breaking ABI compatibility
  293. */
  294. };
  295. struct kfd_ioctl_set_trap_handler_args {
  296. __u64 tba_addr; /* to KFD */
  297. __u64 tma_addr; /* to KFD */
  298. __u32 gpu_id; /* to KFD */
  299. __u32 pad;
  300. };
  301. struct kfd_ioctl_acquire_vm_args {
  302. __u32 drm_fd; /* to KFD */
  303. __u32 gpu_id; /* to KFD */
  304. };
  305. /* Allocation flags: memory types */
  306. #define KFD_IOC_ALLOC_MEM_FLAGS_VRAM (1 << 0)
  307. #define KFD_IOC_ALLOC_MEM_FLAGS_GTT (1 << 1)
  308. #define KFD_IOC_ALLOC_MEM_FLAGS_USERPTR (1 << 2)
  309. #define KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL (1 << 3)
  310. #define KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP (1 << 4)
  311. /* Allocation flags: attributes/access options */
  312. #define KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE (1 << 31)
  313. #define KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE (1 << 30)
  314. #define KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC (1 << 29)
  315. #define KFD_IOC_ALLOC_MEM_FLAGS_NO_SUBSTITUTE (1 << 28)
  316. #define KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM (1 << 27)
  317. #define KFD_IOC_ALLOC_MEM_FLAGS_COHERENT (1 << 26)
  318. #define KFD_IOC_ALLOC_MEM_FLAGS_UNCACHED (1 << 25)
  319. /* Allocate memory for later SVM (shared virtual memory) mapping.
  320. *
  321. * @va_addr: virtual address of the memory to be allocated
  322. * all later mappings on all GPUs will use this address
  323. * @size: size in bytes
  324. * @handle: buffer handle returned to user mode, used to refer to
  325. * this allocation for mapping, unmapping and freeing
  326. * @mmap_offset: for CPU-mapping the allocation by mmapping a render node
  327. * for userptrs this is overloaded to specify the CPU address
  328. * @gpu_id: device identifier
  329. * @flags: memory type and attributes. See KFD_IOC_ALLOC_MEM_FLAGS above
  330. */
  331. struct kfd_ioctl_alloc_memory_of_gpu_args {
  332. __u64 va_addr; /* to KFD */
  333. __u64 size; /* to KFD */
  334. __u64 handle; /* from KFD */
  335. __u64 mmap_offset; /* to KFD (userptr), from KFD (mmap offset) */
  336. __u32 gpu_id; /* to KFD */
  337. __u32 flags;
  338. };
  339. /* Free memory allocated with kfd_ioctl_alloc_memory_of_gpu
  340. *
  341. * @handle: memory handle returned by alloc
  342. */
  343. struct kfd_ioctl_free_memory_of_gpu_args {
  344. __u64 handle; /* to KFD */
  345. };
  346. /* Map memory to one or more GPUs
  347. *
  348. * @handle: memory handle returned by alloc
  349. * @device_ids_array_ptr: array of gpu_ids (__u32 per device)
  350. * @n_devices: number of devices in the array
  351. * @n_success: number of devices mapped successfully
  352. *
  353. * @n_success returns information to the caller how many devices from
  354. * the start of the array have mapped the buffer successfully. It can
  355. * be passed into a subsequent retry call to skip those devices. For
  356. * the first call the caller should initialize it to 0.
  357. *
  358. * If the ioctl completes with return code 0 (success), n_success ==
  359. * n_devices.
  360. */
  361. struct kfd_ioctl_map_memory_to_gpu_args {
  362. __u64 handle; /* to KFD */
  363. __u64 device_ids_array_ptr; /* to KFD */
  364. __u32 n_devices; /* to KFD */
  365. __u32 n_success; /* to/from KFD */
  366. };
  367. /* Unmap memory from one or more GPUs
  368. *
  369. * same arguments as for mapping
  370. */
  371. struct kfd_ioctl_unmap_memory_from_gpu_args {
  372. __u64 handle; /* to KFD */
  373. __u64 device_ids_array_ptr; /* to KFD */
  374. __u32 n_devices; /* to KFD */
  375. __u32 n_success; /* to/from KFD */
  376. };
  377. /* Allocate GWS for specific queue
  378. *
  379. * @queue_id: queue's id that GWS is allocated for
  380. * @num_gws: how many GWS to allocate
  381. * @first_gws: index of the first GWS allocated.
  382. * only support contiguous GWS allocation
  383. */
  384. struct kfd_ioctl_alloc_queue_gws_args {
  385. __u32 queue_id; /* to KFD */
  386. __u32 num_gws; /* to KFD */
  387. __u32 first_gws; /* from KFD */
  388. __u32 pad;
  389. };
  390. struct kfd_ioctl_get_dmabuf_info_args {
  391. __u64 size; /* from KFD */
  392. __u64 metadata_ptr; /* to KFD */
  393. __u32 metadata_size; /* to KFD (space allocated by user)
  394. * from KFD (actual metadata size)
  395. */
  396. __u32 gpu_id; /* from KFD */
  397. __u32 flags; /* from KFD (KFD_IOC_ALLOC_MEM_FLAGS) */
  398. __u32 dmabuf_fd; /* to KFD */
  399. };
  400. struct kfd_ioctl_import_dmabuf_args {
  401. __u64 va_addr; /* to KFD */
  402. __u64 handle; /* from KFD */
  403. __u32 gpu_id; /* to KFD */
  404. __u32 dmabuf_fd; /* to KFD */
  405. };
  406. /*
  407. * KFD SMI(System Management Interface) events
  408. */
  409. enum kfd_smi_event {
  410. KFD_SMI_EVENT_NONE = 0, /* not used */
  411. KFD_SMI_EVENT_VMFAULT = 1, /* event start counting at 1 */
  412. KFD_SMI_EVENT_THERMAL_THROTTLE = 2,
  413. KFD_SMI_EVENT_GPU_PRE_RESET = 3,
  414. KFD_SMI_EVENT_GPU_POST_RESET = 4,
  415. KFD_SMI_EVENT_MIGRATE_START = 5,
  416. KFD_SMI_EVENT_MIGRATE_END = 6,
  417. KFD_SMI_EVENT_PAGE_FAULT_START = 7,
  418. KFD_SMI_EVENT_PAGE_FAULT_END = 8,
  419. KFD_SMI_EVENT_QUEUE_EVICTION = 9,
  420. KFD_SMI_EVENT_QUEUE_RESTORE = 10,
  421. KFD_SMI_EVENT_UNMAP_FROM_GPU = 11,
  422. /*
  423. * max event number, as a flag bit to get events from all processes,
  424. * this requires super user permission, otherwise will not be able to
  425. * receive event from any process. Without this flag to receive events
  426. * from same process.
  427. */
  428. KFD_SMI_EVENT_ALL_PROCESS = 64
  429. };
  430. enum KFD_MIGRATE_TRIGGERS {
  431. KFD_MIGRATE_TRIGGER_PREFETCH,
  432. KFD_MIGRATE_TRIGGER_PAGEFAULT_GPU,
  433. KFD_MIGRATE_TRIGGER_PAGEFAULT_CPU,
  434. KFD_MIGRATE_TRIGGER_TTM_EVICTION
  435. };
  436. enum KFD_QUEUE_EVICTION_TRIGGERS {
  437. KFD_QUEUE_EVICTION_TRIGGER_SVM,
  438. KFD_QUEUE_EVICTION_TRIGGER_USERPTR,
  439. KFD_QUEUE_EVICTION_TRIGGER_TTM,
  440. KFD_QUEUE_EVICTION_TRIGGER_SUSPEND,
  441. KFD_QUEUE_EVICTION_CRIU_CHECKPOINT,
  442. KFD_QUEUE_EVICTION_CRIU_RESTORE
  443. };
  444. enum KFD_SVM_UNMAP_TRIGGERS {
  445. KFD_SVM_UNMAP_TRIGGER_MMU_NOTIFY,
  446. KFD_SVM_UNMAP_TRIGGER_MMU_NOTIFY_MIGRATE,
  447. KFD_SVM_UNMAP_TRIGGER_UNMAP_FROM_CPU
  448. };
  449. #define KFD_SMI_EVENT_MASK_FROM_INDEX(i) (1ULL << ((i) - 1))
  450. #define KFD_SMI_EVENT_MSG_SIZE 96
  451. struct kfd_ioctl_smi_events_args {
  452. __u32 gpuid; /* to KFD */
  453. __u32 anon_fd; /* from KFD */
  454. };
  455. /**************************************************************************************************
  456. * CRIU IOCTLs (Checkpoint Restore In Userspace)
  457. *
  458. * When checkpointing a process, the userspace application will perform:
  459. * 1. PROCESS_INFO op to determine current process information. This pauses execution and evicts
  460. * all the queues.
  461. * 2. CHECKPOINT op to checkpoint process contents (BOs, queues, events, svm-ranges)
  462. * 3. UNPAUSE op to un-evict all the queues
  463. *
  464. * When restoring a process, the CRIU userspace application will perform:
  465. *
  466. * 1. RESTORE op to restore process contents
  467. * 2. RESUME op to start the process
  468. *
  469. * Note: Queues are forced into an evicted state after a successful PROCESS_INFO. User
  470. * application needs to perform an UNPAUSE operation after calling PROCESS_INFO.
  471. */
  472. enum kfd_criu_op {
  473. KFD_CRIU_OP_PROCESS_INFO,
  474. KFD_CRIU_OP_CHECKPOINT,
  475. KFD_CRIU_OP_UNPAUSE,
  476. KFD_CRIU_OP_RESTORE,
  477. KFD_CRIU_OP_RESUME,
  478. };
  479. /**
  480. * kfd_ioctl_criu_args - Arguments perform CRIU operation
  481. * @devices: [in/out] User pointer to memory location for devices information.
  482. * This is an array of type kfd_criu_device_bucket.
  483. * @bos: [in/out] User pointer to memory location for BOs information
  484. * This is an array of type kfd_criu_bo_bucket.
  485. * @priv_data: [in/out] User pointer to memory location for private data
  486. * @priv_data_size: [in/out] Size of priv_data in bytes
  487. * @num_devices: [in/out] Number of GPUs used by process. Size of @devices array.
  488. * @num_bos [in/out] Number of BOs used by process. Size of @bos array.
  489. * @num_objects: [in/out] Number of objects used by process. Objects are opaque to
  490. * user application.
  491. * @pid: [in/out] PID of the process being checkpointed
  492. * @op [in] Type of operation (kfd_criu_op)
  493. *
  494. * Return: 0 on success, -errno on failure
  495. */
  496. struct kfd_ioctl_criu_args {
  497. __u64 devices; /* Used during ops: CHECKPOINT, RESTORE */
  498. __u64 bos; /* Used during ops: CHECKPOINT, RESTORE */
  499. __u64 priv_data; /* Used during ops: CHECKPOINT, RESTORE */
  500. __u64 priv_data_size; /* Used during ops: PROCESS_INFO, RESTORE */
  501. __u32 num_devices; /* Used during ops: PROCESS_INFO, RESTORE */
  502. __u32 num_bos; /* Used during ops: PROCESS_INFO, RESTORE */
  503. __u32 num_objects; /* Used during ops: PROCESS_INFO, RESTORE */
  504. __u32 pid; /* Used during ops: PROCESS_INFO, RESUME */
  505. __u32 op;
  506. };
  507. struct kfd_criu_device_bucket {
  508. __u32 user_gpu_id;
  509. __u32 actual_gpu_id;
  510. __u32 drm_fd;
  511. __u32 pad;
  512. };
  513. struct kfd_criu_bo_bucket {
  514. __u64 addr;
  515. __u64 size;
  516. __u64 offset;
  517. __u64 restored_offset; /* During restore, updated offset for BO */
  518. __u32 gpu_id; /* This is the user_gpu_id */
  519. __u32 alloc_flags;
  520. __u32 dmabuf_fd;
  521. __u32 pad;
  522. };
  523. /* CRIU IOCTLs - END */
  524. /**************************************************************************************************/
  525. /* Register offset inside the remapped mmio page
  526. */
  527. enum kfd_mmio_remap {
  528. KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL = 0,
  529. KFD_MMIO_REMAP_HDP_REG_FLUSH_CNTL = 4,
  530. };
  531. /* Guarantee host access to memory */
  532. #define KFD_IOCTL_SVM_FLAG_HOST_ACCESS 0x00000001
  533. /* Fine grained coherency between all devices with access */
  534. #define KFD_IOCTL_SVM_FLAG_COHERENT 0x00000002
  535. /* Use any GPU in same hive as preferred device */
  536. #define KFD_IOCTL_SVM_FLAG_HIVE_LOCAL 0x00000004
  537. /* GPUs only read, allows replication */
  538. #define KFD_IOCTL_SVM_FLAG_GPU_RO 0x00000008
  539. /* Allow execution on GPU */
  540. #define KFD_IOCTL_SVM_FLAG_GPU_EXEC 0x00000010
  541. /* GPUs mostly read, may allow similar optimizations as RO, but writes fault */
  542. #define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY 0x00000020
  543. /* Keep GPU memory mapping always valid as if XNACK is disable */
  544. #define KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED 0x00000040
  545. /**
  546. * kfd_ioctl_svm_op - SVM ioctl operations
  547. *
  548. * @KFD_IOCTL_SVM_OP_SET_ATTR: Modify one or more attributes
  549. * @KFD_IOCTL_SVM_OP_GET_ATTR: Query one or more attributes
  550. */
  551. enum kfd_ioctl_svm_op {
  552. KFD_IOCTL_SVM_OP_SET_ATTR,
  553. KFD_IOCTL_SVM_OP_GET_ATTR
  554. };
  555. /** kfd_ioctl_svm_location - Enum for preferred and prefetch locations
  556. *
  557. * GPU IDs are used to specify GPUs as preferred and prefetch locations.
  558. * Below definitions are used for system memory or for leaving the preferred
  559. * location unspecified.
  560. */
  561. enum kfd_ioctl_svm_location {
  562. KFD_IOCTL_SVM_LOCATION_SYSMEM = 0,
  563. KFD_IOCTL_SVM_LOCATION_UNDEFINED = 0xffffffff
  564. };
  565. /**
  566. * kfd_ioctl_svm_attr_type - SVM attribute types
  567. *
  568. * @KFD_IOCTL_SVM_ATTR_PREFERRED_LOC: gpuid of the preferred location, 0 for
  569. * system memory
  570. * @KFD_IOCTL_SVM_ATTR_PREFETCH_LOC: gpuid of the prefetch location, 0 for
  571. * system memory. Setting this triggers an
  572. * immediate prefetch (migration).
  573. * @KFD_IOCTL_SVM_ATTR_ACCESS:
  574. * @KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE:
  575. * @KFD_IOCTL_SVM_ATTR_NO_ACCESS: specify memory access for the gpuid given
  576. * by the attribute value
  577. * @KFD_IOCTL_SVM_ATTR_SET_FLAGS: bitmask of flags to set (see
  578. * KFD_IOCTL_SVM_FLAG_...)
  579. * @KFD_IOCTL_SVM_ATTR_CLR_FLAGS: bitmask of flags to clear
  580. * @KFD_IOCTL_SVM_ATTR_GRANULARITY: migration granularity
  581. * (log2 num pages)
  582. */
  583. enum kfd_ioctl_svm_attr_type {
  584. KFD_IOCTL_SVM_ATTR_PREFERRED_LOC,
  585. KFD_IOCTL_SVM_ATTR_PREFETCH_LOC,
  586. KFD_IOCTL_SVM_ATTR_ACCESS,
  587. KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE,
  588. KFD_IOCTL_SVM_ATTR_NO_ACCESS,
  589. KFD_IOCTL_SVM_ATTR_SET_FLAGS,
  590. KFD_IOCTL_SVM_ATTR_CLR_FLAGS,
  591. KFD_IOCTL_SVM_ATTR_GRANULARITY
  592. };
  593. /**
  594. * kfd_ioctl_svm_attribute - Attributes as pairs of type and value
  595. *
  596. * The meaning of the @value depends on the attribute type.
  597. *
  598. * @type: attribute type (see enum @kfd_ioctl_svm_attr_type)
  599. * @value: attribute value
  600. */
  601. struct kfd_ioctl_svm_attribute {
  602. __u32 type;
  603. __u32 value;
  604. };
  605. /**
  606. * kfd_ioctl_svm_args - Arguments for SVM ioctl
  607. *
  608. * @op specifies the operation to perform (see enum
  609. * @kfd_ioctl_svm_op). @start_addr and @size are common for all
  610. * operations.
  611. *
  612. * A variable number of attributes can be given in @attrs.
  613. * @nattr specifies the number of attributes. New attributes can be
  614. * added in the future without breaking the ABI. If unknown attributes
  615. * are given, the function returns -EINVAL.
  616. *
  617. * @KFD_IOCTL_SVM_OP_SET_ATTR sets attributes for a virtual address
  618. * range. It may overlap existing virtual address ranges. If it does,
  619. * the existing ranges will be split such that the attribute changes
  620. * only apply to the specified address range.
  621. *
  622. * @KFD_IOCTL_SVM_OP_GET_ATTR returns the intersection of attributes
  623. * over all memory in the given range and returns the result as the
  624. * attribute value. If different pages have different preferred or
  625. * prefetch locations, 0xffffffff will be returned for
  626. * @KFD_IOCTL_SVM_ATTR_PREFERRED_LOC or
  627. * @KFD_IOCTL_SVM_ATTR_PREFETCH_LOC resepctively. For
  628. * @KFD_IOCTL_SVM_ATTR_SET_FLAGS, flags of all pages will be
  629. * aggregated by bitwise AND. That means, a flag will be set in the
  630. * output, if that flag is set for all pages in the range. For
  631. * @KFD_IOCTL_SVM_ATTR_CLR_FLAGS, flags of all pages will be
  632. * aggregated by bitwise NOR. That means, a flag will be set in the
  633. * output, if that flag is clear for all pages in the range.
  634. * The minimum migration granularity throughout the range will be
  635. * returned for @KFD_IOCTL_SVM_ATTR_GRANULARITY.
  636. *
  637. * Querying of accessibility attributes works by initializing the
  638. * attribute type to @KFD_IOCTL_SVM_ATTR_ACCESS and the value to the
  639. * GPUID being queried. Multiple attributes can be given to allow
  640. * querying multiple GPUIDs. The ioctl function overwrites the
  641. * attribute type to indicate the access for the specified GPU.
  642. */
  643. struct kfd_ioctl_svm_args {
  644. __u64 start_addr;
  645. __u64 size;
  646. __u32 op;
  647. __u32 nattr;
  648. /* Variable length array of attributes */
  649. struct kfd_ioctl_svm_attribute attrs[];
  650. };
  651. /**
  652. * kfd_ioctl_set_xnack_mode_args - Arguments for set_xnack_mode
  653. *
  654. * @xnack_enabled: [in/out] Whether to enable XNACK mode for this process
  655. *
  656. * @xnack_enabled indicates whether recoverable page faults should be
  657. * enabled for the current process. 0 means disabled, positive means
  658. * enabled, negative means leave unchanged. If enabled, virtual address
  659. * translations on GFXv9 and later AMD GPUs can return XNACK and retry
  660. * the access until a valid PTE is available. This is used to implement
  661. * device page faults.
  662. *
  663. * On output, @xnack_enabled returns the (new) current mode (0 or
  664. * positive). Therefore, a negative input value can be used to query
  665. * the current mode without changing it.
  666. *
  667. * The XNACK mode fundamentally changes the way SVM managed memory works
  668. * in the driver, with subtle effects on application performance and
  669. * functionality.
  670. *
  671. * Enabling XNACK mode requires shader programs to be compiled
  672. * differently. Furthermore, not all GPUs support changing the mode
  673. * per-process. Therefore changing the mode is only allowed while no
  674. * user mode queues exist in the process. This ensure that no shader
  675. * code is running that may be compiled for the wrong mode. And GPUs
  676. * that cannot change to the requested mode will prevent the XNACK
  677. * mode from occurring. All GPUs used by the process must be in the
  678. * same XNACK mode.
  679. *
  680. * GFXv8 or older GPUs do not support 48 bit virtual addresses or SVM.
  681. * Therefore those GPUs are not considered for the XNACK mode switch.
  682. *
  683. * Return: 0 on success, -errno on failure
  684. */
  685. struct kfd_ioctl_set_xnack_mode_args {
  686. __s32 xnack_enabled;
  687. };
  688. #define AMDKFD_IOCTL_BASE 'K'
  689. #define AMDKFD_IO(nr) _IO(AMDKFD_IOCTL_BASE, nr)
  690. #define AMDKFD_IOR(nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type)
  691. #define AMDKFD_IOW(nr, type) _IOW(AMDKFD_IOCTL_BASE, nr, type)
  692. #define AMDKFD_IOWR(nr, type) _IOWR(AMDKFD_IOCTL_BASE, nr, type)
  693. #define AMDKFD_IOC_GET_VERSION \
  694. AMDKFD_IOR(0x01, struct kfd_ioctl_get_version_args)
  695. #define AMDKFD_IOC_CREATE_QUEUE \
  696. AMDKFD_IOWR(0x02, struct kfd_ioctl_create_queue_args)
  697. #define AMDKFD_IOC_DESTROY_QUEUE \
  698. AMDKFD_IOWR(0x03, struct kfd_ioctl_destroy_queue_args)
  699. #define AMDKFD_IOC_SET_MEMORY_POLICY \
  700. AMDKFD_IOW(0x04, struct kfd_ioctl_set_memory_policy_args)
  701. #define AMDKFD_IOC_GET_CLOCK_COUNTERS \
  702. AMDKFD_IOWR(0x05, struct kfd_ioctl_get_clock_counters_args)
  703. #define AMDKFD_IOC_GET_PROCESS_APERTURES \
  704. AMDKFD_IOR(0x06, struct kfd_ioctl_get_process_apertures_args)
  705. #define AMDKFD_IOC_UPDATE_QUEUE \
  706. AMDKFD_IOW(0x07, struct kfd_ioctl_update_queue_args)
  707. #define AMDKFD_IOC_CREATE_EVENT \
  708. AMDKFD_IOWR(0x08, struct kfd_ioctl_create_event_args)
  709. #define AMDKFD_IOC_DESTROY_EVENT \
  710. AMDKFD_IOW(0x09, struct kfd_ioctl_destroy_event_args)
  711. #define AMDKFD_IOC_SET_EVENT \
  712. AMDKFD_IOW(0x0A, struct kfd_ioctl_set_event_args)
  713. #define AMDKFD_IOC_RESET_EVENT \
  714. AMDKFD_IOW(0x0B, struct kfd_ioctl_reset_event_args)
  715. #define AMDKFD_IOC_WAIT_EVENTS \
  716. AMDKFD_IOWR(0x0C, struct kfd_ioctl_wait_events_args)
  717. #define AMDKFD_IOC_DBG_REGISTER_DEPRECATED \
  718. AMDKFD_IOW(0x0D, struct kfd_ioctl_dbg_register_args)
  719. #define AMDKFD_IOC_DBG_UNREGISTER_DEPRECATED \
  720. AMDKFD_IOW(0x0E, struct kfd_ioctl_dbg_unregister_args)
  721. #define AMDKFD_IOC_DBG_ADDRESS_WATCH_DEPRECATED \
  722. AMDKFD_IOW(0x0F, struct kfd_ioctl_dbg_address_watch_args)
  723. #define AMDKFD_IOC_DBG_WAVE_CONTROL_DEPRECATED \
  724. AMDKFD_IOW(0x10, struct kfd_ioctl_dbg_wave_control_args)
  725. #define AMDKFD_IOC_SET_SCRATCH_BACKING_VA \
  726. AMDKFD_IOWR(0x11, struct kfd_ioctl_set_scratch_backing_va_args)
  727. #define AMDKFD_IOC_GET_TILE_CONFIG \
  728. AMDKFD_IOWR(0x12, struct kfd_ioctl_get_tile_config_args)
  729. #define AMDKFD_IOC_SET_TRAP_HANDLER \
  730. AMDKFD_IOW(0x13, struct kfd_ioctl_set_trap_handler_args)
  731. #define AMDKFD_IOC_GET_PROCESS_APERTURES_NEW \
  732. AMDKFD_IOWR(0x14, \
  733. struct kfd_ioctl_get_process_apertures_new_args)
  734. #define AMDKFD_IOC_ACQUIRE_VM \
  735. AMDKFD_IOW(0x15, struct kfd_ioctl_acquire_vm_args)
  736. #define AMDKFD_IOC_ALLOC_MEMORY_OF_GPU \
  737. AMDKFD_IOWR(0x16, struct kfd_ioctl_alloc_memory_of_gpu_args)
  738. #define AMDKFD_IOC_FREE_MEMORY_OF_GPU \
  739. AMDKFD_IOW(0x17, struct kfd_ioctl_free_memory_of_gpu_args)
  740. #define AMDKFD_IOC_MAP_MEMORY_TO_GPU \
  741. AMDKFD_IOWR(0x18, struct kfd_ioctl_map_memory_to_gpu_args)
  742. #define AMDKFD_IOC_UNMAP_MEMORY_FROM_GPU \
  743. AMDKFD_IOWR(0x19, struct kfd_ioctl_unmap_memory_from_gpu_args)
  744. #define AMDKFD_IOC_SET_CU_MASK \
  745. AMDKFD_IOW(0x1A, struct kfd_ioctl_set_cu_mask_args)
  746. #define AMDKFD_IOC_GET_QUEUE_WAVE_STATE \
  747. AMDKFD_IOWR(0x1B, struct kfd_ioctl_get_queue_wave_state_args)
  748. #define AMDKFD_IOC_GET_DMABUF_INFO \
  749. AMDKFD_IOWR(0x1C, struct kfd_ioctl_get_dmabuf_info_args)
  750. #define AMDKFD_IOC_IMPORT_DMABUF \
  751. AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
  752. #define AMDKFD_IOC_ALLOC_QUEUE_GWS \
  753. AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
  754. #define AMDKFD_IOC_SMI_EVENTS \
  755. AMDKFD_IOWR(0x1F, struct kfd_ioctl_smi_events_args)
  756. #define AMDKFD_IOC_SVM AMDKFD_IOWR(0x20, struct kfd_ioctl_svm_args)
  757. #define AMDKFD_IOC_SET_XNACK_MODE \
  758. AMDKFD_IOWR(0x21, struct kfd_ioctl_set_xnack_mode_args)
  759. #define AMDKFD_IOC_CRIU_OP \
  760. AMDKFD_IOWR(0x22, struct kfd_ioctl_criu_args)
  761. #define AMDKFD_IOC_AVAILABLE_MEMORY \
  762. AMDKFD_IOWR(0x23, struct kfd_ioctl_get_available_memory_args)
  763. #define AMDKFD_COMMAND_START 0x01
  764. #define AMDKFD_COMMAND_END 0x24
  765. #endif