18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2019 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef __AMDGPU_MES_H__
258c2ecf20Sopenharmony_ci#define __AMDGPU_MES_H__
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define AMDGPU_MES_MAX_COMPUTE_PIPES        8
288c2ecf20Sopenharmony_ci#define AMDGPU_MES_MAX_GFX_PIPES            2
298c2ecf20Sopenharmony_ci#define AMDGPU_MES_MAX_SDMA_PIPES           2
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cienum amdgpu_mes_priority_level {
328c2ecf20Sopenharmony_ci	AMDGPU_MES_PRIORITY_LEVEL_LOW       = 0,
338c2ecf20Sopenharmony_ci	AMDGPU_MES_PRIORITY_LEVEL_NORMAL    = 1,
348c2ecf20Sopenharmony_ci	AMDGPU_MES_PRIORITY_LEVEL_MEDIUM    = 2,
358c2ecf20Sopenharmony_ci	AMDGPU_MES_PRIORITY_LEVEL_HIGH      = 3,
368c2ecf20Sopenharmony_ci	AMDGPU_MES_PRIORITY_LEVEL_REALTIME  = 4,
378c2ecf20Sopenharmony_ci	AMDGPU_MES_PRIORITY_NUM_LEVELS
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct amdgpu_mes_funcs;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct amdgpu_mes {
438c2ecf20Sopenharmony_ci	struct amdgpu_device            *adev;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	uint32_t                        total_max_queue;
468c2ecf20Sopenharmony_ci	uint32_t                        doorbell_id_offset;
478c2ecf20Sopenharmony_ci	uint32_t                        max_doorbell_slices;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	uint64_t                        default_process_quantum;
508c2ecf20Sopenharmony_ci	uint64_t                        default_gang_quantum;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	struct amdgpu_ring              ring;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	const struct firmware           *fw;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/* mes ucode */
578c2ecf20Sopenharmony_ci	struct amdgpu_bo		*ucode_fw_obj;
588c2ecf20Sopenharmony_ci	uint64_t			ucode_fw_gpu_addr;
598c2ecf20Sopenharmony_ci	uint32_t			*ucode_fw_ptr;
608c2ecf20Sopenharmony_ci	uint32_t                        ucode_fw_version;
618c2ecf20Sopenharmony_ci	uint64_t                        uc_start_addr;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	/* mes ucode data */
648c2ecf20Sopenharmony_ci	struct amdgpu_bo		*data_fw_obj;
658c2ecf20Sopenharmony_ci	uint64_t			data_fw_gpu_addr;
668c2ecf20Sopenharmony_ci	uint32_t			*data_fw_ptr;
678c2ecf20Sopenharmony_ci	uint32_t                        data_fw_version;
688c2ecf20Sopenharmony_ci	uint64_t                        data_start_addr;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* eop gpu obj */
718c2ecf20Sopenharmony_ci	struct amdgpu_bo		*eop_gpu_obj;
728c2ecf20Sopenharmony_ci	uint64_t                        eop_gpu_addr;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	void                            *mqd_backup;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	uint32_t                        vmid_mask_gfxhub;
778c2ecf20Sopenharmony_ci	uint32_t                        vmid_mask_mmhub;
788c2ecf20Sopenharmony_ci	uint32_t                        compute_hqd_mask[AMDGPU_MES_MAX_COMPUTE_PIPES];
798c2ecf20Sopenharmony_ci	uint32_t                        gfx_hqd_mask[AMDGPU_MES_MAX_GFX_PIPES];
808c2ecf20Sopenharmony_ci	uint32_t                        sdma_hqd_mask[AMDGPU_MES_MAX_SDMA_PIPES];
818c2ecf20Sopenharmony_ci	uint32_t                        agreegated_doorbells[AMDGPU_MES_PRIORITY_NUM_LEVELS];
828c2ecf20Sopenharmony_ci	uint32_t                        sch_ctx_offs;
838c2ecf20Sopenharmony_ci	uint64_t			sch_ctx_gpu_addr;
848c2ecf20Sopenharmony_ci	uint64_t			*sch_ctx_ptr;
858c2ecf20Sopenharmony_ci	uint32_t			query_status_fence_offs;
868c2ecf20Sopenharmony_ci	uint64_t			query_status_fence_gpu_addr;
878c2ecf20Sopenharmony_ci	uint64_t			*query_status_fence_ptr;
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	/* ip specific functions */
908c2ecf20Sopenharmony_ci	const struct amdgpu_mes_funcs   *funcs;
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct mes_add_queue_input {
948c2ecf20Sopenharmony_ci	uint32_t	process_id;
958c2ecf20Sopenharmony_ci	uint64_t	page_table_base_addr;
968c2ecf20Sopenharmony_ci	uint64_t	process_va_start;
978c2ecf20Sopenharmony_ci	uint64_t	process_va_end;
988c2ecf20Sopenharmony_ci	uint64_t	process_quantum;
998c2ecf20Sopenharmony_ci	uint64_t	process_context_addr;
1008c2ecf20Sopenharmony_ci	uint64_t	gang_quantum;
1018c2ecf20Sopenharmony_ci	uint64_t	gang_context_addr;
1028c2ecf20Sopenharmony_ci	uint32_t	inprocess_gang_priority;
1038c2ecf20Sopenharmony_ci	uint32_t	gang_global_priority_level;
1048c2ecf20Sopenharmony_ci	uint32_t	doorbell_offset;
1058c2ecf20Sopenharmony_ci	uint64_t	mqd_addr;
1068c2ecf20Sopenharmony_ci	uint64_t	wptr_addr;
1078c2ecf20Sopenharmony_ci	uint32_t	queue_type;
1088c2ecf20Sopenharmony_ci	uint32_t	paging;
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct mes_remove_queue_input {
1128c2ecf20Sopenharmony_ci	uint32_t	doorbell_offset;
1138c2ecf20Sopenharmony_ci	uint64_t	gang_context_addr;
1148c2ecf20Sopenharmony_ci};
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistruct mes_suspend_gang_input {
1178c2ecf20Sopenharmony_ci	bool		suspend_all_gangs;
1188c2ecf20Sopenharmony_ci	uint64_t	gang_context_addr;
1198c2ecf20Sopenharmony_ci	uint64_t	suspend_fence_addr;
1208c2ecf20Sopenharmony_ci	uint32_t	suspend_fence_value;
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistruct mes_resume_gang_input {
1248c2ecf20Sopenharmony_ci	bool		resume_all_gangs;
1258c2ecf20Sopenharmony_ci	uint64_t	gang_context_addr;
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistruct amdgpu_mes_funcs {
1298c2ecf20Sopenharmony_ci	int (*add_hw_queue)(struct amdgpu_mes *mes,
1308c2ecf20Sopenharmony_ci			    struct mes_add_queue_input *input);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	int (*remove_hw_queue)(struct amdgpu_mes *mes,
1338c2ecf20Sopenharmony_ci			       struct mes_remove_queue_input *input);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	int (*suspend_gang)(struct amdgpu_mes *mes,
1368c2ecf20Sopenharmony_ci			    struct mes_suspend_gang_input *input);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	int (*resume_gang)(struct amdgpu_mes *mes,
1398c2ecf20Sopenharmony_ci			   struct mes_resume_gang_input *input);
1408c2ecf20Sopenharmony_ci};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#endif /* __AMDGPU_MES_H__ */
143