logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

kfd_ioctl.h (58113B)


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