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