xref: /linux/drivers/gpu/drm/amd/include/mes_v12_api_def.h (revision 07fdad3a93756b872da7b53647715c48d0f4a2d0)
1 /*
2  * Copyright 2023 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 
24 #ifndef __MES_API_DEF_H__
25 #define __MES_API_DEF_H__
26 
27 #pragma pack(push, 8)
28 
29 #define MES_API_VERSION 0x14
30 
31 /* Maximum log buffer size for MES. Needs to be updated if MES expands MES_EVT_INTR_HIST_LOG_12 */
32 #define  AMDGPU_MES_LOG_BUFFER_SIZE  0xC000
33 
34 /* Driver submits one API(cmd) as a single Frame and this command size is same for all API
35  * to ease the debugging and parsing of ring buffer.
36  */
37 enum {API_FRAME_SIZE_IN_DWORDS = 64};
38 
39 /* To avoid command in scheduler context to be overwritten whenenver mutilple interrupts come in,
40  * this creates another queue
41  */
42 enum {API_NUMBER_OF_COMMAND_MAX   = 32};
43 
44 enum MES_API_TYPE {
45 	MES_API_TYPE_SCHEDULER = 1,
46 	MES_API_TYPE_MAX
47 };
48 
49 enum MES_SCH_API_OPCODE {
50 	MES_SCH_API_SET_HW_RSRC			= 0,
51 	MES_SCH_API_SET_SCHEDULING_CONFIG	= 1, /* agreegated db, quantums, etc */
52 	MES_SCH_API_ADD_QUEUE			= 2,
53 	MES_SCH_API_REMOVE_QUEUE		= 3,
54 	MES_SCH_API_PERFORM_YIELD		= 4,
55 	MES_SCH_API_SET_GANG_PRIORITY_LEVEL	= 5, /* For windows GANG = Context */
56 	MES_SCH_API_SUSPEND			= 6,
57 	MES_SCH_API_RESUME			= 7,
58 	MES_SCH_API_RESET			= 8,
59 	MES_SCH_API_SET_LOG_BUFFER		= 9,
60 	MES_SCH_API_CHANGE_GANG_PRORITY		= 10,
61 	MES_SCH_API_QUERY_SCHEDULER_STATUS	= 11,
62 	MES_SCH_API_SET_DEBUG_VMID		= 13,
63 	MES_SCH_API_MISC			= 14,
64 	MES_SCH_API_UPDATE_ROOT_PAGE_TABLE	= 15,
65 	MES_SCH_API_AMD_LOG			= 16,
66 	MES_SCH_API_SET_SE_MODE			= 17,
67 	MES_SCH_API_SET_GANG_SUBMIT		= 18,
68 	MES_SCH_API_SET_HW_RSRC_1               = 19,
69 	MES_SCH_API_INV_TLBS                    = 20,
70 
71 	MES_SCH_API_MAX = 0xFF
72 };
73 
74 union MES_API_HEADER {
75 	struct {
76 		uint32_t type	  : 4; /* 0 - Invalid; 1 - Scheduling; 2 - TBD */
77 		uint32_t opcode   : 8;
78 		uint32_t dwsize   : 8; /* including header */
79 		uint32_t reserved : 12;
80 	};
81 
82 	uint32_t u32All;
83 };
84 
85 enum MES_AMD_PRIORITY_LEVEL {
86 	AMD_PRIORITY_LEVEL_LOW		= 0,
87 	AMD_PRIORITY_LEVEL_NORMAL	= 1,
88 	AMD_PRIORITY_LEVEL_MEDIUM	= 2,
89 	AMD_PRIORITY_LEVEL_HIGH		= 3,
90 	AMD_PRIORITY_LEVEL_REALTIME	= 4,
91 
92 	AMD_PRIORITY_NUM_LEVELS
93 };
94 
95 enum MES_QUEUE_TYPE {
96 	MES_QUEUE_TYPE_GFX,
97 	MES_QUEUE_TYPE_COMPUTE,
98 	MES_QUEUE_TYPE_SDMA,
99 
100 	MES_QUEUE_TYPE_MAX,
101 	MES_QUEUE_TYPE_SCHQ = MES_QUEUE_TYPE_MAX,
102 };
103 
104 struct MES_API_STATUS {
105 	uint64_t api_completion_fence_addr;
106 	uint64_t api_completion_fence_value;
107 };
108 
109 /*
110  * MES will set api_completion_fence_value in api_completion_fence_addr
111  * when it can successflly process the API. MES will also trigger
112  * following interrupt when it finish process the API no matter success
113  * or failed.
114  *     Interrupt source id 181 (EOP) with context ID (DW 6 in the int
115  *     cookie) set to 0xb1 and context type set to 8. Driver side need
116  *     to enable TIME_STAMP_INT_ENABLE in CPC_INT_CNTL for MES pipe to
117  *     catch this interrupt.
118  *     Driver side also need to set enable_mes_fence_int = 1 in
119  *     set_HW_resource package to enable this fence interrupt.
120  * when the API process failed.
121  *     lowre 32 bits set to 0.
122  *     higher 32 bits set as follows (bit shift within high 32)
123  *         bit 0  -  7    API specific error code.
124  *         bit 8  - 15    API OPCODE.
125  *         bit 16 - 23    MISC OPCODE if any
126  *         bit 24 - 30    ERROR category (API_ERROR_XXX)
127  *         bit 31         Set to 1 to indicate error status
128  *
129  */
130 enum { MES_SCH_ERROR_CODE_HEADER_SHIFT_12 = 8 };
131 enum { MES_SCH_ERROR_CODE_MISC_OP_SHIFT_12 = 16 };
132 enum { MES_ERROR_CATEGORY_SHIFT_12 = 24 };
133 enum { MES_API_STATUS_ERROR_SHIFT_12 = 31 };
134 
135 enum MES_ERROR_CATEGORY_CODE_12 {
136 	MES_ERROR_API                = 1,
137 	MES_ERROR_SCHEDULING         = 2,
138 	MES_ERROR_UNKNOWN            = 3,
139 };
140 
141 #define MES_ERR_CODE(api_err, opcode, misc_op, category) \
142 			((uint64) (api_err | opcode << MES_SCH_ERROR_CODE_HEADER_SHIFT_12 | \
143 			misc_op << MES_SCH_ERROR_CODE_MISC_OP_SHIFT_12 | \
144 			category << MES_ERROR_CATEGORY_SHIFT_12 | \
145 			1 << MES_API_STATUS_ERROR_SHIFT_12) << 32)
146 
147 enum { MAX_COMPUTE_PIPES = 8 };
148 enum { MAX_GFX_PIPES	 = 2 };
149 enum { MAX_SDMA_PIPES	 = 2 };
150 
151 enum { MAX_COMPUTE_HQD_PER_PIPE		= 8 };
152 enum { MAX_GFX_HQD_PER_PIPE		= 8 };
153 enum { MAX_SDMA_HQD_PER_PIPE		= 10 };
154 enum { MAX_SDMA_HQD_PER_PIPE_11_0	= 8 };
155 
156 
157 enum { MAX_QUEUES_IN_A_GANG = 8 };
158 
159 enum VM_HUB_TYPE {
160 	VM_HUB_TYPE_GC = 0,
161 	VM_HUB_TYPE_MM = 1,
162 
163 	VM_HUB_TYPE_MAX,
164 };
165 
166 enum { VMID_INVALID = 0xffff };
167 
168 enum { MAX_VMID_GCHUB = 16 };
169 enum { MAX_VMID_MMHUB = 16 };
170 
171 enum SET_DEBUG_VMID_OPERATIONS {
172 	DEBUG_VMID_OP_PROGRAM	= 0,
173 	DEBUG_VMID_OP_ALLOCATE	= 1,
174 	DEBUG_VMID_OP_RELEASE	= 2,
175 	DEBUG_VMID_OP_VM_SETUP	= 3 // used to set up the debug vmid page table in the kernel queue case (mode 1)
176 };
177 
178 enum MES_MS_LOG_CONTEXT_STATE {
179 	MES_LOG_CONTEXT_STATE_IDLE		= 0,
180 	MES_LOG_CONTEXT_STATE_RUNNING		= 1,
181 	MES_LOG_CONTEXT_STATE_READY		= 2,
182 	MES_LOG_CONTEXT_STATE_READY_STANDBY	= 3,
183 	MES_LOG_CONTEXT_STATE_INVALID		= 0xF,
184 };
185 
186 enum MES_MS_LOG_OPERATION {
187 	MES_LOG_OPERATION_CONTEXT_STATE_CHANGE		= 0,
188 	MES_LOG_OPERATION_QUEUE_NEW_WORK		= 1,
189 	MES_LOG_OPERATION_QUEUE_UNWAIT_SYNC_OBJECT	= 2,
190 	MES_LOG_OPERATION_QUEUE_NO_MORE_WORK		= 3,
191 	MES_LOG_OPERATION_QUEUE_WAIT_SYNC_OBJECT	= 4,
192 	MES_LOG_OPERATION_QUEUE_INVALID			= 0xF,
193 };
194 
195 struct MES_LOG_CONTEXT_STATE_CHANGE {
196 	uint64_t			h_context;
197 	enum MES_MS_LOG_CONTEXT_STATE	new_context_state;
198 };
199 
200 struct MES_LOG_QUEUE_NEW_WORK {
201 	uint64_t	h_queue;
202 	uint64_t	reserved;
203 };
204 
205 struct MES_LOG_QUEUE_UNWAIT_SYNC_OBJECT {
206 	uint64_t	h_queue;
207 	uint64_t	h_sync_object;
208 };
209 
210 struct MES_LOG_QUEUE_NO_MORE_WORK {
211 	uint64_t	h_queue;
212 	uint64_t	reserved;
213 };
214 
215 struct MES_LOG_QUEUE_WAIT_SYNC_OBJECT {
216 	uint64_t	h_queue;
217 	uint64_t	h_sync_object;
218 };
219 
220 struct MES_LOG_ENTRY_HEADER {
221 	uint32_t first_free_entry_index;
222 	uint32_t wraparound_count;
223 	uint64_t number_of_entries;
224 	uint64_t reserved[2];
225 };
226 
227 struct MES_LOG_ENTRY_DATA {
228 	uint64_t gpu_time_stamp;
229 	uint32_t operation_type; /* operation_type is of MES_LOG_OPERATION type */
230 	uint32_t reserved_operation_type_bits;
231 	union {
232 		struct MES_LOG_CONTEXT_STATE_CHANGE context_state_change;
233 		struct MES_LOG_QUEUE_NEW_WORK queue_new_work;
234 		struct MES_LOG_QUEUE_UNWAIT_SYNC_OBJECT queue_unwait_sync_object;
235 		struct MES_LOG_QUEUE_NO_MORE_WORK queue_no_more_work;
236 		struct MES_LOG_QUEUE_WAIT_SYNC_OBJECT queue_wait_sync_object;
237 		uint64_t all[2];
238 	};
239 };
240 
241 struct MES_LOG_BUFFER {
242 	struct MES_LOG_ENTRY_HEADER header;
243 	struct MES_LOG_ENTRY_DATA	entries[];
244 };
245 
246 enum MES_SWIP_TO_HWIP_DEF {
247 	MES_MAX_HWIP_SEGMENT = 8,
248 };
249 
250 union MESAPI_SET_HW_RESOURCES {
251 	struct {
252 		union MES_API_HEADER	header;
253 		uint32_t		vmid_mask_mmhub;
254 		uint32_t		vmid_mask_gfxhub;
255 		uint32_t		gds_size;
256 		uint32_t		paging_vmid;
257 		uint32_t		compute_hqd_mask[MAX_COMPUTE_PIPES];
258 		uint32_t		gfx_hqd_mask[MAX_GFX_PIPES];
259 		uint32_t		sdma_hqd_mask[MAX_SDMA_PIPES];
260 		uint32_t		aggregated_doorbells[AMD_PRIORITY_NUM_LEVELS];
261 		uint64_t		g_sch_ctx_gpu_mc_ptr;
262 		uint64_t		query_status_fence_gpu_mc_ptr;
263 		uint32_t		gc_base[MES_MAX_HWIP_SEGMENT];
264 		uint32_t		mmhub_base[MES_MAX_HWIP_SEGMENT];
265 		uint32_t		osssys_base[MES_MAX_HWIP_SEGMENT];
266 		struct MES_API_STATUS	api_status;
267 		union {
268 			struct {
269 				uint32_t disable_reset : 1;
270 				uint32_t use_different_vmid_compute : 1;
271 				uint32_t disable_mes_log   : 1;
272 				uint32_t apply_mmhub_pgvm_invalidate_ack_loss_wa : 1;
273 				uint32_t apply_grbm_remote_register_dummy_read_wa : 1;
274 				uint32_t second_gfx_pipe_enabled : 1;
275 				uint32_t enable_level_process_quantum_check : 1;
276 				uint32_t legacy_sch_mode : 1;
277 				uint32_t disable_add_queue_wptr_mc_addr : 1;
278 				uint32_t enable_mes_event_int_logging : 1;
279 				uint32_t enable_reg_active_poll : 1;
280 				uint32_t use_disable_queue_in_legacy_uq_preemption : 1;
281 				uint32_t send_write_data : 1;
282 				uint32_t os_tdr_timeout_override : 1;
283 				uint32_t use_rs64mem_for_proc_gang_ctx : 1;
284 				uint32_t halt_on_misaligned_access : 1;
285 				uint32_t use_add_queue_unmap_flag_addr : 1;
286 				uint32_t enable_mes_sch_stb_log : 1;
287 				uint32_t limit_single_process : 1;
288 				uint32_t unmapped_doorbell_handling: 2;
289 				uint32_t enable_mes_fence_int: 1;
290 				uint32_t enable_lr_compute_wa : 1;
291 				uint32_t reserved : 9;
292 			};
293 			uint32_t uint32_all;
294 		};
295 	uint32_t	oversubscription_timer;
296 	uint64_t	doorbell_info;
297 	uint64_t	event_intr_history_gpu_mc_ptr;
298 	uint64_t	timestamp;
299 	uint32_t	os_tdr_timeout_in_sec;
300 	};
301 
302 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
303 };
304 
305 union MESAPI_SET_HW_RESOURCES_1 {
306 	struct {
307 		union MES_API_HEADER                header;
308 		struct MES_API_STATUS               api_status;
309 		uint64_t                            timestamp;
310 		union {
311 			struct {
312 				uint32_t enable_mes_debug_ctx : 1;
313 				uint32_t reserved : 31;
314 			};
315 			uint32_t uint32_all;
316 		};
317 		uint64_t                            mes_debug_ctx_mc_addr;
318 		uint32_t                            mes_debug_ctx_size;
319 		/* unit is 100ms */
320 		uint32_t                            mes_kiq_unmap_timeout;
321 		uint64_t                            reserved1;
322 		uint64_t                            cleaner_shader_fence_mc_addr;
323 	};
324 
325 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
326 };
327 
328 union MESAPI__ADD_QUEUE {
329 	struct {
330 		union MES_API_HEADER	header;
331 		uint32_t		process_id;
332 		uint64_t		page_table_base_addr;
333 		uint64_t		process_va_start;
334 		uint64_t		process_va_end;
335 		uint64_t		process_quantum;
336 		uint64_t		process_context_addr;
337 		uint64_t		gang_quantum;
338 		uint64_t		gang_context_addr;
339 		uint32_t		inprocess_gang_priority;
340 		enum MES_AMD_PRIORITY_LEVEL gang_global_priority_level;
341 		uint32_t		doorbell_offset;
342 		uint64_t		mqd_addr;
343 		/* From MES_API_VERSION 2, mc addr is expected for wptr_addr */
344 		uint64_t		wptr_addr;
345 		uint64_t		h_context;
346 		uint64_t		h_queue;
347 		enum MES_QUEUE_TYPE	queue_type;
348 		uint32_t		gds_base;
349 		union {
350 			/* backwards compatibility with Linux, remove union once they use kfd_queue_size */
351 			uint32_t	gds_size;
352 			uint32_t	kfd_queue_size;
353 		};
354 		uint32_t		gws_base;
355 		uint32_t		gws_size;
356 		uint32_t		oa_mask;
357 		uint64_t		trap_handler_addr;
358 		uint32_t		vm_context_cntl;
359 
360 		struct {
361 			uint32_t paging	 : 1;
362 			uint32_t debug_vmid  : 4;
363 			uint32_t program_gds : 1;
364 			uint32_t is_gang_suspended : 1;
365 			uint32_t is_tmz_queue : 1;
366 			uint32_t map_kiq_utility_queue : 1;
367 			uint32_t is_kfd_process : 1;
368 			uint32_t trap_en : 1;
369 			uint32_t is_aql_queue : 1;
370 			uint32_t skip_process_ctx_clear : 1;
371 			uint32_t map_legacy_kq : 1;
372 			uint32_t exclusively_scheduled : 1;
373 			uint32_t is_long_running : 1;
374 			uint32_t is_dwm_queue : 1;
375 			uint32_t reserved	 : 15;
376 		};
377 		struct MES_API_STATUS	api_status;
378 		uint64_t		tma_addr;
379 		uint32_t		sch_id;
380 		uint64_t		timestamp;
381 		uint32_t		process_context_array_index;
382 		uint32_t		gang_context_array_index;
383 		uint32_t		pipe_id;	//used for mapping legacy kernel queue
384 		uint32_t		queue_id;
385 		uint32_t		alignment_mode_setting;
386 	};
387 
388 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
389 };
390 
391 union MESAPI__REMOVE_QUEUE {
392 	struct {
393 		union MES_API_HEADER	header;
394 		uint32_t		doorbell_offset;
395 		uint64_t		gang_context_addr;
396 
397 		struct {
398 			uint32_t reserved01		  : 1;
399 			uint32_t unmap_kiq_utility_queue  : 1;
400 			uint32_t preempt_legacy_gfx_queue : 1;
401 			uint32_t unmap_legacy_queue	  : 1;
402 			uint32_t reserved		  : 28;
403 		};
404 		struct MES_API_STATUS		api_status;
405 
406 		uint32_t			pipe_id;
407 		uint32_t			queue_id;
408 
409 		uint64_t			tf_addr;
410 		uint32_t			tf_data;
411 
412 		enum MES_QUEUE_TYPE		queue_type;
413 		uint64_t			timestamp;
414 		uint32_t			gang_context_array_index;
415 	};
416 
417 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
418 };
419 
420 union MESAPI__SET_SCHEDULING_CONFIG {
421 	struct {
422 		union MES_API_HEADER	header;
423 		/* Grace period when preempting another priority band for this priority band.
424 		 * The value for idle priority band is ignored, as it never preempts other bands.
425 		 */
426 		uint64_t		grace_period_other_levels[AMD_PRIORITY_NUM_LEVELS];
427 
428 		/* Default quantum for scheduling across processes within a priority band. */
429 		uint64_t		process_quantum_for_level[AMD_PRIORITY_NUM_LEVELS];
430 
431 		/* Default grace period for processes that preempt each other within a priority band.*/
432 		uint64_t		process_grace_period_same_level[AMD_PRIORITY_NUM_LEVELS];
433 
434 		/* For normal level this field specifies the target GPU percentage in situations when it's starved by the high level.
435 		 * Valid values are between 0 and 50, with the default being 10.
436 		 */
437 		uint32_t		normal_yield_percent;
438 
439 		struct MES_API_STATUS	api_status;
440 		uint64_t		timestamp;
441 	};
442 
443 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
444 };
445 
446 union MESAPI__PERFORM_YIELD {
447 	struct {
448 		union MES_API_HEADER	header;
449 		uint32_t		dummy;
450 		struct MES_API_STATUS	api_status;
451 		uint64_t		timestamp;
452 	};
453 
454 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
455 };
456 
457 union MESAPI__CHANGE_GANG_PRIORITY_LEVEL {
458 	struct {
459 		union MES_API_HEADER		header;
460 		uint32_t			inprocess_gang_priority;
461 		enum MES_AMD_PRIORITY_LEVEL gang_global_priority_level;
462 		uint64_t			gang_quantum;
463 		uint64_t			gang_context_addr;
464 		struct MES_API_STATUS		api_status;
465 		uint32_t			doorbell_offset;
466 		uint64_t			timestamp;
467 		uint32_t			gang_context_array_index;
468 		struct {
469 			uint32_t		queue_quantum_scale	: 2;
470 			uint32_t		queue_quantum_duration	: 8;
471 			uint32_t		apply_quantum_all_processes : 1;
472 			uint32_t		reserved		: 21;
473 		};
474 	};
475 
476 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
477 };
478 
479 union MESAPI__SUSPEND {
480 	struct {
481 		union MES_API_HEADER	header;
482 		/* false - suspend all gangs; true - specific gang */
483 		struct {
484 			uint32_t	suspend_all_gangs : 1;
485 			uint32_t	reserved : 31;
486 		};
487 		/* gang_context_addr is valid only if suspend_all = false */
488 
489 		uint64_t		gang_context_addr;
490 
491 		uint64_t		suspend_fence_addr;
492 		uint32_t		suspend_fence_value;
493 
494 		struct MES_API_STATUS	api_status;
495 
496 		union {
497 			uint32_t return_value; // to be removed
498 			uint32_t sch_id;       //keep the old return_value temporarily for compatibility
499 		};
500 		uint32_t		doorbell_offset;
501 		uint64_t		timestamp;
502 		enum MES_QUEUE_TYPE	legacy_uq_type;
503 		enum MES_AMD_PRIORITY_LEVEL legacy_uq_priority_level;
504 		uint32_t		gang_context_array_index;
505 	};
506 
507 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
508 };
509 
510 union MESAPI__RESUME {
511 	struct {
512 		union MES_API_HEADER	header;
513 		/* false - resume all gangs; true - specified gang */
514 		struct {
515 			uint32_t	resume_all_gangs : 1;
516 			uint32_t	reserved : 31;
517 		};
518 		/* valid only if resume_all_gangs = false */
519 		uint64_t		gang_context_addr;
520 
521 		struct MES_API_STATUS	api_status;
522 		uint32_t		doorbell_offset;
523 		uint64_t		timestamp;
524 		uint32_t		gang_context_array_index;
525 	};
526 
527 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
528 };
529 
530 union MESAPI__RESET {
531 	struct {
532 		union MES_API_HEADER		header;
533 
534 		struct {
535 			/* Only reset the queue given by doorbell_offset (not entire gang) */
536 			uint32_t		reset_queue_only : 1;
537 			/* Hang detection first then reset any queues that are hung */
538 			uint32_t		hang_detect_then_reset : 1;
539 			/* Only do hang detection (no reset) */
540 			uint32_t		hang_detect_only : 1;
541 			/* Reset HP and LP kernel queues not managed by MES */
542 			uint32_t		reset_legacy_gfx : 1;
543 			/* Fallback to use conneceted queue index when CP_CNTX_STAT method fails (gfx pipe 0) */
544 			uint32_t		use_connected_queue_index : 1;
545 			/* For gfx pipe 1 */
546 			uint32_t		use_connected_queue_index_p1 : 1;
547 			uint32_t		reserved : 26;
548 		};
549 
550 		uint64_t			gang_context_addr;
551 
552 		/* valid only if reset_queue_only = true */
553 		uint32_t			doorbell_offset;
554 
555 		/* valid only if hang_detect_then_reset = true */
556 		uint64_t			doorbell_offset_addr;
557 		enum MES_QUEUE_TYPE		queue_type;
558 
559 		/* valid only if reset_legacy_gfx = true */
560 		uint32_t			pipe_id_lp;
561 		uint32_t			queue_id_lp;
562 		uint32_t			vmid_id_lp;
563 		uint64_t			mqd_mc_addr_lp;
564 		uint32_t			doorbell_offset_lp;
565 		uint64_t			wptr_addr_lp;
566 
567 		uint32_t			pipe_id_hp;
568 		uint32_t			queue_id_hp;
569 		uint32_t			vmid_id_hp;
570 		uint64_t			mqd_mc_addr_hp;
571 		uint32_t			doorbell_offset_hp;
572 		uint64_t			wptr_addr_hp;
573 
574 		struct MES_API_STATUS		api_status;
575 		uint32_t			active_vmids;
576 		uint64_t			timestamp;
577 
578 		uint32_t			gang_context_array_index;
579 
580 		uint32_t			connected_queue_index;
581 		uint32_t			connected_queue_index_p1;
582 	};
583 
584 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
585 };
586 
587 union MESAPI__SET_LOGGING_BUFFER {
588 	struct {
589 		union MES_API_HEADER		header;
590 		/* There are separate log buffers for each queue type */
591 		enum MES_QUEUE_TYPE		log_type;
592 		/* Log buffer GPU Address */
593 		uint64_t			logging_buffer_addr;
594 		/* number of entries in the log buffer */
595 		uint32_t			number_of_entries;
596 		/* Entry index at which CPU interrupt needs to be signalled */
597 		uint32_t			interrupt_entry;
598 
599 		struct MES_API_STATUS		api_status;
600 		uint64_t			timestamp;
601 		uint32_t			vmid;
602 	};
603 
604 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
605 };
606 
607 enum MES_API_QUERY_MES_OPCODE {
608 	MES_API_QUERY_MES__GET_CTX_ARRAY_SIZE,
609 	MES_API_QUERY_MES__CHECK_HEALTHY,
610 	MES_API_QUERY_MES__MAX,
611 };
612 
613 enum { QUERY_MES_MAX_SIZE_IN_DWORDS = 20 };
614 
615 struct MES_API_QUERY_MES__CTX_ARRAY_SIZE {
616 	uint64_t	proc_ctx_array_size_addr;
617 	uint64_t	gang_ctx_array_size_addr;
618 };
619 
620 struct MES_API_QUERY_MES__HEALTHY_CHECK {
621 	uint64_t	healthy_addr;
622 };
623 
624 union MESAPI__QUERY_MES_STATUS {
625 	struct {
626 		union MES_API_HEADER		header;
627 		enum MES_API_QUERY_MES_OPCODE	subopcode;
628 		struct MES_API_STATUS		api_status;
629 		uint64_t			timestamp;
630 		union {
631 			struct MES_API_QUERY_MES__CTX_ARRAY_SIZE	ctx_array_size;
632 			struct MES_API_QUERY_MES__HEALTHY_CHECK	healthy_check;
633 			uint32_t data[QUERY_MES_MAX_SIZE_IN_DWORDS];
634 		};
635 	};
636 
637 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
638 };
639 
640 union MESAPI__SET_DEBUG_VMID {
641 	struct {
642 		union MES_API_HEADER	header;
643 		struct MES_API_STATUS	api_status;
644 		union {
645 			struct {
646 			uint32_t use_gds   : 1;
647 			uint32_t operation : 2;
648 			uint32_t reserved  : 29;
649 			} flags;
650 			uint32_t u32All;
651 		};
652 		uint32_t		reserved;
653 		uint32_t		debug_vmid;
654 		uint64_t		process_context_addr;
655 		uint64_t		page_table_base_addr;
656 		uint64_t		process_va_start;
657 		uint64_t		process_va_end;
658 		uint32_t		gds_base;
659 		uint32_t		gds_size;
660 		uint32_t		gws_base;
661 		uint32_t		gws_size;
662 		uint32_t		oa_mask;
663 
664 		uint64_t		output_addr; // output addr of the acquired vmid value
665 
666 		uint64_t		timestamp;
667 
668 		uint32_t		process_vm_cntl;
669 		enum MES_QUEUE_TYPE	queue_type;
670 
671 		uint32_t		process_context_array_index;
672 
673 		uint32_t		alignment_mode_setting;
674 	};
675 
676 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
677 };
678 
679 enum MESAPI_MISC_OPCODE {
680 	MESAPI_MISC__WRITE_REG,
681 	MESAPI_MISC__INV_GART,
682 	MESAPI_MISC__QUERY_STATUS,
683 	MESAPI_MISC__READ_REG,
684 	MESAPI_MISC__WAIT_REG_MEM,
685 	MESAPI_MISC__SET_SHADER_DEBUGGER,
686 	MESAPI_MISC__NOTIFY_WORK_ON_UNMAPPED_QUEUE,
687 	MESAPI_MISC__NOTIFY_TO_UNMAP_PROCESSES,
688 	MESAPI_MISC__QUERY_HUNG_ENGINE_ID,
689 	MESAPI_MISC__CHANGE_CONFIG,
690 	MESAPI_MISC__LAUNCH_CLEANER_SHADER,
691 	MESAPI_MISC__SETUP_MES_DBGEXT,
692 
693 	MESAPI_MISC__MAX,
694 };
695 
696 enum {MISC_DATA_MAX_SIZE_IN_DWORDS = 20};
697 
698 struct WRITE_REG {
699 	uint32_t	reg_offset;
700 	uint32_t	reg_value;
701 };
702 
703 struct READ_REG {
704 	uint32_t reg_offset;
705 	uint64_t buffer_addr;
706 	union {
707 		struct {
708 			uint32_t read64Bits : 1;
709 			uint32_t reserved : 31;
710 		} bits;
711 		uint32_t all;
712 	} option;
713 };
714 
715 struct INV_GART {
716 	uint64_t	inv_range_va_start;
717 	uint64_t	inv_range_size;
718 };
719 
720 struct QUERY_STATUS {
721 	uint32_t context_id;
722 };
723 
724 enum WRM_OPERATION {
725 	WRM_OPERATION__WAIT_REG_MEM,
726 	WRM_OPERATION__WR_WAIT_WR_REG,
727 
728 	WRM_OPERATION__MAX,
729 };
730 
731 struct WAIT_REG_MEM {
732 	enum WRM_OPERATION op;
733 	/* only function = equal_to_the_reference_value and mem_space = register_space supported for now */
734 	uint32_t reference;
735 	uint32_t mask;
736 	uint32_t reg_offset1;
737 	uint32_t reg_offset2;
738 };
739 
740 struct SET_SHADER_DEBUGGER {
741 	uint64_t process_context_addr;
742 	union {
743 		struct {
744 			uint32_t single_memop : 1; // SQ_DEBUG.single_memop
745 			uint32_t single_alu_op : 1; // SQ_DEBUG.single_alu_op
746 			uint32_t reserved : 30;
747 		};
748 		uint32_t u32all;
749 	} flags;
750 	uint32_t spi_gdbg_per_vmid_cntl;
751 	uint32_t tcp_watch_cntl[4]; // TCP_WATCHx_CNTL
752 	uint32_t trap_en;
753 };
754 
755 struct SET_GANG_SUBMIT {
756 	uint64_t gang_context_addr;
757 	uint64_t slave_gang_context_addr;
758 	uint32_t gang_context_array_index;
759 	uint32_t slave_gang_context_array_index;
760 };
761 
762 enum MESAPI_MISC__CHANGE_CONFIG_OPTION {
763 	MESAPI_MISC__CHANGE_CONFIG_OPTION_LIMIT_SINGLE_PROCESS = 0,
764 	MESAPI_MISC__CHANGE_CONFIG_OPTION_ENABLE_HWS_LOGGING_BUFFER = 1,
765 	MESAPI_MISC__CHANGE_CONFIG_OPTION_CHANGE_TDR_CONFIG    = 2,
766 
767 	MESAPI_MISC__CHANGE_CONFIG_OPTION_MAX = 0x1F
768 };
769 
770 struct CHANGE_CONFIG {
771 	enum MESAPI_MISC__CHANGE_CONFIG_OPTION opcode;
772 	union {
773 		struct  {
774 			uint32_t limit_single_process : 1;
775 			uint32_t enable_hws_logging_buffer : 1;
776 			uint32_t reserved : 30;
777 		} bits;
778 		uint32_t all;
779 	} option;
780 
781 	struct {
782 		uint32_t tdr_level;
783 		uint32_t tdr_delay;
784 	} tdr_config;
785 };
786 
787 union MESAPI__MISC {
788 	struct {
789 		union MES_API_HEADER	header;
790 		enum MESAPI_MISC_OPCODE opcode;
791 		struct MES_API_STATUS	api_status;
792 		union {
793 			struct WRITE_REG write_reg;
794 			struct INV_GART inv_gart;
795 			struct QUERY_STATUS query_status;
796 			struct READ_REG read_reg;
797 			struct WAIT_REG_MEM wait_reg_mem;
798 			struct SET_SHADER_DEBUGGER set_shader_debugger;
799 			enum MES_AMD_PRIORITY_LEVEL queue_sch_level;
800 			struct CHANGE_CONFIG change_config;
801 			uint32_t data[MISC_DATA_MAX_SIZE_IN_DWORDS];
802 		};
803 		uint64_t		timestamp;
804 		uint32_t		doorbell_offset;
805 		uint32_t		os_fence;
806 	};
807 
808 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
809 };
810 
811 union MESAPI__UPDATE_ROOT_PAGE_TABLE {
812 	struct {
813 		union MES_API_HEADER		header;
814 		uint64_t			page_table_base_addr;
815 		uint64_t			process_context_addr;
816 		struct MES_API_STATUS		api_status;
817 		uint64_t			timestamp;
818 		uint32_t			process_context_array_index;
819 	};
820 
821 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
822 };
823 
824 union MESAPI_AMD_LOG {
825 	struct {
826 		union MES_API_HEADER		header;
827 		uint64_t			p_buffer_memory;
828 		uint64_t			p_buffer_size_used;
829 		struct MES_API_STATUS		api_status;
830 		uint64_t			timestamp;
831 	};
832 
833 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
834 };
835 
836 enum MES_SE_MODE {
837 	MES_SE_MODE_INVALID	= 0,
838 	MES_SE_MODE_SINGLE_SE	= 1,
839 	MES_SE_MODE_DUAL_SE	= 2,
840 	MES_SE_MODE_LOWER_POWER	= 3,
841 };
842 
843 union MESAPI__SET_SE_MODE {
844 	struct {
845 		union MES_API_HEADER header;
846 		/* the new SE mode to apply*/
847 		enum MES_SE_MODE new_se_mode;
848 		/* the fence to make sure the ItCpgCtxtSync packet is completed */
849 		uint64_t cpg_ctxt_sync_fence_addr;
850 		uint32_t cpg_ctxt_sync_fence_value;
851 		/* log_seq_time - Scheduler logs the switch seq start/end ts in the IH cookies */
852 		union {
853 			struct {
854 				uint32_t log_seq_time : 1;
855 				uint32_t reserved : 31;
856 			};
857 			uint32_t uint32_all;
858 		};
859 		struct MES_API_STATUS api_status;
860 	};
861 
862 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
863 };
864 
865 union MESAPI__SET_GANG_SUBMIT {
866 	struct {
867 		union MES_API_HEADER	header;
868 		struct MES_API_STATUS	api_status;
869 		struct SET_GANG_SUBMIT	set_gang_submit;
870 	};
871 
872 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
873 };
874 
875 /*
876  * @inv_sel        0-select pasid as input to do the invalidation , 1-select vmid
877  * @flush_type     0-old style, 1-light weight, 2-heavyweight, 3-heavyweight2
878  * @inv_sel_id     specific pasid when inv_sel is 0 and specific vmid if inv_sel is 1
879  * @hub_id         0-gc_hub, 1-mm_hub
880  */
881 struct INV_TLBS {
882 	uint8_t     inv_sel;
883 	uint8_t     flush_type;
884 	uint16_t    inv_sel_id;
885 	uint32_t    hub_id;
886 	/* If following two inv_range setting are all 0 , whole VM will be invalidated,
887 	 * otherwise only required range be invalidated
888 	 */
889 	uint64_t    inv_range_va_start;
890 	uint64_t    inv_range_size;
891 	uint64_t    reserved;
892 };
893 
894 union MESAPI__INV_TLBS {
895 	struct {
896 		union MES_API_HEADER    header;
897 		struct MES_API_STATUS   api_status;
898 		struct INV_TLBS         invalidate_tlbs;
899 	};
900 
901 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
902 };
903 
904 #pragma pack(pop)
905 
906 #endif
907