2 * Copyright 2022 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
24 #ifndef __MES_API_DEF_H__
25 #define __MES_API_DEF_H__
29 #define MES_API_VERSION 1
31 /* Driver submits one API(cmd) as a single Frame and this command size is same
32 * for all API to ease the debugging and parsing of ring buffer.
34 enum { API_FRAME_SIZE_IN_DWORDS = 64 };
36 /* To avoid command in scheduler context to be overwritten whenenver mutilple
37 * interrupts come in, this creates another queue.
39 enum { API_NUMBER_OF_COMMAND_MAX = 32 };
42 MES_API_TYPE_SCHEDULER = 1,
46 enum MES_SCH_API_OPCODE {
47 MES_SCH_API_SET_HW_RSRC = 0,
48 MES_SCH_API_SET_SCHEDULING_CONFIG = 1, /* agreegated db, quantums, etc */
49 MES_SCH_API_ADD_QUEUE = 2,
50 MES_SCH_API_REMOVE_QUEUE = 3,
51 MES_SCH_API_PERFORM_YIELD = 4,
52 MES_SCH_API_SET_GANG_PRIORITY_LEVEL = 5,
53 MES_SCH_API_SUSPEND = 6,
54 MES_SCH_API_RESUME = 7,
55 MES_SCH_API_RESET = 8,
56 MES_SCH_API_SET_LOG_BUFFER = 9,
57 MES_SCH_API_CHANGE_GANG_PRORITY = 10,
58 MES_SCH_API_QUERY_SCHEDULER_STATUS = 11,
59 MES_SCH_API_PROGRAM_GDS = 12,
60 MES_SCH_API_SET_DEBUG_VMID = 13,
61 MES_SCH_API_MISC = 14,
62 MES_SCH_API_UPDATE_ROOT_PAGE_TABLE = 15,
63 MES_SCH_API_AMD_LOG = 16,
64 MES_SCH_API_SET_HW_RSRC_1 = 19,
65 MES_SCH_API_MAX = 0xFF
68 union MES_API_HEADER {
70 uint32_t type : 4; /* 0 - Invalid; 1 - Scheduling; 2 - TBD */
72 uint32_t dwsize : 8; /* including header */
73 uint32_t reserved : 12;
79 enum MES_AMD_PRIORITY_LEVEL {
80 AMD_PRIORITY_LEVEL_LOW = 0,
81 AMD_PRIORITY_LEVEL_NORMAL = 1,
82 AMD_PRIORITY_LEVEL_MEDIUM = 2,
83 AMD_PRIORITY_LEVEL_HIGH = 3,
84 AMD_PRIORITY_LEVEL_REALTIME = 4,
85 AMD_PRIORITY_NUM_LEVELS
90 MES_QUEUE_TYPE_COMPUTE,
95 struct MES_API_STATUS {
96 uint64_t api_completion_fence_addr;
97 uint64_t api_completion_fence_value;
100 enum { MAX_COMPUTE_PIPES = 8 };
101 enum { MAX_GFX_PIPES = 2 };
102 enum { MAX_SDMA_PIPES = 2 };
104 enum { MAX_COMPUTE_HQD_PER_PIPE = 8 };
105 enum { MAX_GFX_HQD_PER_PIPE = 8 };
106 enum { MAX_SDMA_HQD_PER_PIPE = 10 };
107 enum { MAX_SDMA_HQD_PER_PIPE_11_0 = 8 };
109 enum { MAX_QUEUES_IN_A_GANG = 8 };
117 enum { VMID_INVALID = 0xffff };
119 enum { MAX_VMID_GCHUB = 16 };
120 enum { MAX_VMID_MMHUB = 16 };
122 enum SET_DEBUG_VMID_OPERATIONS {
123 DEBUG_VMID_OP_PROGRAM = 0,
124 DEBUG_VMID_OP_ALLOCATE = 1,
125 DEBUG_VMID_OP_RELEASE = 2
128 enum MES_LOG_OPERATION {
129 MES_LOG_OPERATION_CONTEXT_STATE_CHANGE = 0,
130 MES_LOG_OPERATION_QUEUE_NEW_WORK = 1,
131 MES_LOG_OPERATION_QUEUE_UNWAIT_SYNC_OBJECT = 2,
132 MES_LOG_OPERATION_QUEUE_NO_MORE_WORK = 3,
133 MES_LOG_OPERATION_QUEUE_WAIT_SYNC_OBJECT = 4,
134 MES_LOG_OPERATION_QUEUE_INVALID = 0xF,
137 enum MES_LOG_CONTEXT_STATE {
138 MES_LOG_CONTEXT_STATE_IDLE = 0,
139 MES_LOG_CONTEXT_STATE_RUNNING = 1,
140 MES_LOG_CONTEXT_STATE_READY = 2,
141 MES_LOG_CONTEXT_STATE_READY_STANDBY = 3,
142 MES_LOG_CONTEXT_STATE_INVALID = 0xF,
145 struct MES_LOG_CONTEXT_STATE_CHANGE {
147 enum MES_LOG_CONTEXT_STATE new_context_state;
150 struct MES_LOG_QUEUE_NEW_WORK {
155 struct MES_LOG_QUEUE_UNWAIT_SYNC_OBJECT {
157 uint64_t h_sync_object;
160 struct MES_LOG_QUEUE_NO_MORE_WORK {
165 struct MES_LOG_QUEUE_WAIT_SYNC_OBJECT {
167 uint64_t h_sync_object;
170 struct MES_LOG_ENTRY_HEADER {
171 uint32_t first_free_entry_index;
172 uint32_t wraparound_count;
173 uint64_t number_of_entries;
174 uint64_t reserved[2];
177 struct MES_LOG_ENTRY_DATA {
178 uint64_t gpu_time_stamp;
179 uint32_t operation_type; /* operation_type is of MES_LOG_OPERATION type */
180 uint32_t reserved_operation_type_bits;
182 struct MES_LOG_CONTEXT_STATE_CHANGE context_state_change;
183 struct MES_LOG_QUEUE_NEW_WORK queue_new_work;
184 struct MES_LOG_QUEUE_UNWAIT_SYNC_OBJECT queue_unwait_sync_object;
185 struct MES_LOG_QUEUE_NO_MORE_WORK queue_no_more_work;
186 struct MES_LOG_QUEUE_WAIT_SYNC_OBJECT queue_wait_sync_object;
191 struct MES_LOG_BUFFER {
192 struct MES_LOG_ENTRY_HEADER header;
193 struct MES_LOG_ENTRY_DATA entries[1];
196 enum MES_SWIP_TO_HWIP_DEF {
197 MES_MAX_HWIP_SEGMENT = 8,
200 union MESAPI_SET_HW_RESOURCES {
202 union MES_API_HEADER header;
203 uint32_t vmid_mask_mmhub;
204 uint32_t vmid_mask_gfxhub;
206 uint32_t paging_vmid;
207 uint32_t compute_hqd_mask[MAX_COMPUTE_PIPES];
208 uint32_t gfx_hqd_mask[MAX_GFX_PIPES];
209 uint32_t sdma_hqd_mask[MAX_SDMA_PIPES];
210 uint32_t aggregated_doorbells[AMD_PRIORITY_NUM_LEVELS];
211 uint64_t g_sch_ctx_gpu_mc_ptr;
212 uint64_t query_status_fence_gpu_mc_ptr;
213 uint32_t gc_base[MES_MAX_HWIP_SEGMENT];
214 uint32_t mmhub_base[MES_MAX_HWIP_SEGMENT];
215 uint32_t osssys_base[MES_MAX_HWIP_SEGMENT];
216 struct MES_API_STATUS api_status;
219 uint32_t disable_reset : 1;
220 uint32_t use_different_vmid_compute : 1;
221 uint32_t disable_mes_log : 1;
222 uint32_t apply_mmhub_pgvm_invalidate_ack_loss_wa : 1;
223 uint32_t apply_grbm_remote_register_dummy_read_wa : 1;
224 uint32_t second_gfx_pipe_enabled : 1;
225 uint32_t enable_level_process_quantum_check : 1;
226 uint32_t legacy_sch_mode : 1;
227 uint32_t disable_add_queue_wptr_mc_addr : 1;
228 uint32_t enable_mes_event_int_logging : 1;
229 uint32_t enable_reg_active_poll : 1;
230 uint32_t reserved : 21;
232 uint32_t uint32_t_all;
234 uint32_t oversubscription_timer;
235 uint64_t doorbell_info;
236 uint64_t event_intr_history_gpu_mc_ptr;
239 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
242 union MESAPI_SET_HW_RESOURCES_1 {
244 union MES_API_HEADER header;
245 struct MES_API_STATUS api_status;
249 uint32_t enable_mes_info_ctx : 1;
250 uint32_t reserved : 31;
254 uint64_t mes_info_ctx_mc_addr;
255 uint32_t mes_info_ctx_size;
256 uint32_t mes_kiq_unmap_timeout; // unit is 100ms
259 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
262 union MESAPI__ADD_QUEUE {
264 union MES_API_HEADER header;
266 uint64_t page_table_base_addr;
267 uint64_t process_va_start;
268 uint64_t process_va_end;
269 uint64_t process_quantum;
270 uint64_t process_context_addr;
271 uint64_t gang_quantum;
272 uint64_t gang_context_addr;
273 uint32_t inprocess_gang_priority;
274 enum MES_AMD_PRIORITY_LEVEL gang_global_priority_level;
275 uint32_t doorbell_offset;
280 enum MES_QUEUE_TYPE queue_type;
286 uint64_t trap_handler_addr;
287 uint32_t vm_context_cntl;
291 uint32_t debug_vmid : 4;
292 uint32_t program_gds : 1;
293 uint32_t is_gang_suspended : 1;
294 uint32_t is_tmz_queue : 1;
295 uint32_t map_kiq_utility_queue : 1;
296 uint32_t is_kfd_process : 1;
297 uint32_t trap_en : 1;
298 uint32_t is_aql_queue : 1;
299 uint32_t skip_process_ctx_clear : 1;
300 uint32_t map_legacy_kq : 1;
301 uint32_t exclusively_scheduled : 1;
302 uint32_t is_long_running : 1;
303 uint32_t is_dwm_queue : 1;
304 uint32_t is_video_blit_queue : 1;
305 uint32_t reserved : 14;
307 struct MES_API_STATUS api_status;
311 uint32_t process_context_array_index;
312 uint32_t gang_context_array_index;
315 uint32_t alignment_mode_setting;
316 uint64_t unmap_flag_addr;
319 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
322 union MESAPI__REMOVE_QUEUE {
324 union MES_API_HEADER header;
325 uint32_t doorbell_offset;
326 uint64_t gang_context_addr;
329 uint32_t unmap_legacy_gfx_queue : 1;
330 uint32_t unmap_kiq_utility_queue : 1;
331 uint32_t preempt_legacy_gfx_queue : 1;
332 uint32_t unmap_legacy_queue : 1;
333 uint32_t reserved : 28;
335 struct MES_API_STATUS api_status;
343 enum MES_QUEUE_TYPE queue_type;
346 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
349 union MESAPI__SET_SCHEDULING_CONFIG {
351 union MES_API_HEADER header;
352 /* Grace period when preempting another priority band for this
353 * priority band. The value for idle priority band is ignored,
354 * as it never preempts other bands.
356 uint64_t grace_period_other_levels[AMD_PRIORITY_NUM_LEVELS];
357 /* Default quantum for scheduling across processes within
360 uint64_t process_quantum_for_level[AMD_PRIORITY_NUM_LEVELS];
361 /* Default grace period for processes that preempt each other
362 * within a priority band.
364 uint64_t process_grace_period_same_level[AMD_PRIORITY_NUM_LEVELS];
365 /* For normal level this field specifies the target GPU
366 * percentage in situations when it's starved by the high level.
367 * Valid values are between 0 and 50, with the default being 10.
369 uint32_t normal_yield_percent;
370 struct MES_API_STATUS api_status;
373 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
376 union MESAPI__PERFORM_YIELD {
378 union MES_API_HEADER header;
380 struct MES_API_STATUS api_status;
383 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
386 union MESAPI__CHANGE_GANG_PRIORITY_LEVEL {
388 union MES_API_HEADER header;
389 uint32_t inprocess_gang_priority;
390 enum MES_AMD_PRIORITY_LEVEL gang_global_priority_level;
391 uint64_t gang_quantum;
392 uint64_t gang_context_addr;
393 struct MES_API_STATUS api_status;
396 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
399 union MESAPI__SUSPEND {
401 union MES_API_HEADER header;
402 /* false - suspend all gangs; true - specific gang */
404 uint32_t suspend_all_gangs : 1;
405 uint32_t reserved : 31;
407 /* gang_context_addr is valid only if suspend_all = false */
408 uint64_t gang_context_addr;
410 uint64_t suspend_fence_addr;
411 uint32_t suspend_fence_value;
413 struct MES_API_STATUS api_status;
416 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
419 union MESAPI__RESUME {
421 union MES_API_HEADER header;
422 /* false - resume all gangs; true - specified gang */
424 uint32_t resume_all_gangs : 1;
425 uint32_t reserved : 31;
427 /* valid only if resume_all_gangs = false */
428 uint64_t gang_context_addr;
430 struct MES_API_STATUS api_status;
433 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
436 union MESAPI__RESET {
438 union MES_API_HEADER header;
441 /* Only reset the queue given by doorbell_offset (not entire gang) */
442 uint32_t reset_queue_only : 1;
443 /* Hang detection first then reset any queues that are hung */
444 uint32_t hang_detect_then_reset : 1;
445 /* Only do hang detection (no reset) */
446 uint32_t hang_detect_only : 1;
447 /* Rest HP and LP kernel queues not managed by MES */
448 uint32_t reset_legacy_gfx : 1;
449 uint32_t reserved : 28;
452 uint64_t gang_context_addr;
454 /* valid only if reset_queue_only = true */
455 uint32_t doorbell_offset;
457 /* valid only if hang_detect_then_reset = true */
458 uint64_t doorbell_offset_addr;
459 enum MES_QUEUE_TYPE queue_type;
461 /* valid only if reset_legacy_gfx = true */
463 uint32_t queue_id_lp;
465 uint64_t mqd_mc_addr_lp;
466 uint32_t doorbell_offset_lp;
467 uint64_t wptr_addr_lp;
470 uint32_t queue_id_hp;
472 uint64_t mqd_mc_addr_hp;
473 uint32_t doorbell_offset_hp;
474 uint64_t wptr_addr_hp;
476 struct MES_API_STATUS api_status;
479 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
482 union MESAPI__SET_LOGGING_BUFFER {
484 union MES_API_HEADER header;
485 /* There are separate log buffers for each queue type */
486 enum MES_QUEUE_TYPE log_type;
487 /* Log buffer GPU Address */
488 uint64_t logging_buffer_addr;
489 /* number of entries in the log buffer */
490 uint32_t number_of_entries;
491 /* Entry index at which CPU interrupt needs to be signalled */
492 uint32_t interrupt_entry;
494 struct MES_API_STATUS api_status;
497 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
500 union MESAPI__QUERY_MES_STATUS {
502 union MES_API_HEADER header;
503 bool mes_healthy; /* 0 - not healthy, 1 - healthy */
504 struct MES_API_STATUS api_status;
507 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
510 union MESAPI__PROGRAM_GDS {
512 union MES_API_HEADER header;
513 uint64_t process_context_addr;
519 struct MES_API_STATUS api_status;
522 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
525 union MESAPI__SET_DEBUG_VMID {
527 union MES_API_HEADER header;
528 struct MES_API_STATUS api_status;
531 uint32_t use_gds : 1;
532 uint32_t operation : 2;
533 uint32_t reserved : 29;
539 uint64_t process_context_addr;
540 uint64_t page_table_base_addr;
541 uint64_t process_va_start;
542 uint64_t process_va_end;
549 /* output addr of the acquired vmid value */
550 uint64_t output_addr;
553 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
556 enum MESAPI_MISC_OPCODE {
557 MESAPI_MISC__WRITE_REG,
558 MESAPI_MISC__INV_GART,
559 MESAPI_MISC__QUERY_STATUS,
560 MESAPI_MISC__READ_REG,
561 MESAPI_MISC__WAIT_REG_MEM,
562 MESAPI_MISC__SET_SHADER_DEBUGGER,
566 enum { MISC_DATA_MAX_SIZE_IN_DWORDS = 20 };
575 uint64_t buffer_addr;
579 WRM_OPERATION__WAIT_REG_MEM,
580 WRM_OPERATION__WR_WAIT_WR_REG,
584 struct WAIT_REG_MEM {
585 enum WRM_OPERATION op;
588 uint32_t reg_offset1;
589 uint32_t reg_offset2;
593 uint64_t inv_range_va_start;
594 uint64_t inv_range_size;
597 struct QUERY_STATUS {
601 struct SET_SHADER_DEBUGGER {
602 uint64_t process_context_addr;
605 uint32_t single_memop : 1; /* SQ_DEBUG.single_memop */
606 uint32_t single_alu_op : 1; /* SQ_DEBUG.single_alu_op */
607 uint32_t reserved : 29;
608 uint32_t process_ctx_flush : 1;
612 uint32_t spi_gdbg_per_vmid_cntl;
613 uint32_t tcp_watch_cntl[4]; /* TCP_WATCHx_CNTL */
619 union MES_API_HEADER header;
620 enum MESAPI_MISC_OPCODE opcode;
621 struct MES_API_STATUS api_status;
624 struct WRITE_REG write_reg;
625 struct INV_GART inv_gart;
626 struct QUERY_STATUS query_status;
627 struct READ_REG read_reg;
628 struct WAIT_REG_MEM wait_reg_mem;
629 struct SET_SHADER_DEBUGGER set_shader_debugger;
630 enum MES_AMD_PRIORITY_LEVEL queue_sch_level;
632 uint32_t data[MISC_DATA_MAX_SIZE_IN_DWORDS];
636 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
639 union MESAPI__UPDATE_ROOT_PAGE_TABLE {
641 union MES_API_HEADER header;
642 uint64_t page_table_base_addr;
643 uint64_t process_context_addr;
644 struct MES_API_STATUS api_status;
647 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
650 union MESAPI_AMD_LOG {
652 union MES_API_HEADER header;
653 uint64_t p_buffer_memory;
654 uint64_t p_buffer_size_used;
655 struct MES_API_STATUS api_status;
658 uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];