162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2016 Advanced Micro Devices, Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
1262306a36Sopenharmony_ci * all copies or substantial portions of the Software.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#ifndef __AMDGPU_VCN_H__
2562306a36Sopenharmony_ci#define __AMDGPU_VCN_H__
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#include "amdgpu_ras.h"
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define AMDGPU_VCN_STACK_SIZE		(128*1024)
3062306a36Sopenharmony_ci#define AMDGPU_VCN_CONTEXT_SIZE 	(512*1024)
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define AMDGPU_VCN_FIRMWARE_OFFSET	256
3362306a36Sopenharmony_ci#define AMDGPU_VCN_MAX_ENC_RINGS	3
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define AMDGPU_MAX_VCN_INSTANCES	4
3662306a36Sopenharmony_ci#define AMDGPU_MAX_VCN_ENC_RINGS  AMDGPU_VCN_MAX_ENC_RINGS * AMDGPU_MAX_VCN_INSTANCES
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define AMDGPU_VCN_HARVEST_VCN0 (1 << 0)
3962306a36Sopenharmony_ci#define AMDGPU_VCN_HARVEST_VCN1 (1 << 1)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define VCN_DEC_KMD_CMD 		0x80000000
4262306a36Sopenharmony_ci#define VCN_DEC_CMD_FENCE		0x00000000
4362306a36Sopenharmony_ci#define VCN_DEC_CMD_TRAP		0x00000001
4462306a36Sopenharmony_ci#define VCN_DEC_CMD_WRITE_REG		0x00000004
4562306a36Sopenharmony_ci#define VCN_DEC_CMD_REG_READ_COND_WAIT	0x00000006
4662306a36Sopenharmony_ci#define VCN_DEC_CMD_PACKET_START	0x0000000a
4762306a36Sopenharmony_ci#define VCN_DEC_CMD_PACKET_END		0x0000000b
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_NO_OP		0x00000000
5062306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_END		0x00000001
5162306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_IB		0x00000002
5262306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_FENCE		0x00000003
5362306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_TRAP		0x00000004
5462306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_IB_AUTO		0x00000005
5562306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_SEMAPHORE	0x00000006
5662306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_PREEMPT_FENCE	0x00000009
5762306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_REG_WRITE	0x0000000b
5862306a36Sopenharmony_ci#define VCN_DEC_SW_CMD_REG_WAIT		0x0000000c
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define VCN_ENC_CMD_NO_OP		0x00000000
6162306a36Sopenharmony_ci#define VCN_ENC_CMD_END 		0x00000001
6262306a36Sopenharmony_ci#define VCN_ENC_CMD_IB			0x00000002
6362306a36Sopenharmony_ci#define VCN_ENC_CMD_FENCE		0x00000003
6462306a36Sopenharmony_ci#define VCN_ENC_CMD_TRAP		0x00000004
6562306a36Sopenharmony_ci#define VCN_ENC_CMD_REG_WRITE		0x0000000b
6662306a36Sopenharmony_ci#define VCN_ENC_CMD_REG_WAIT		0x0000000c
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define VCN_AON_SOC_ADDRESS_2_0 	0x1f800
6962306a36Sopenharmony_ci#define VCN1_AON_SOC_ADDRESS_3_0 	0x48000
7062306a36Sopenharmony_ci#define VCN_VID_IP_ADDRESS_2_0		0x0
7162306a36Sopenharmony_ci#define VCN_AON_IP_ADDRESS_2_0		0x30000
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define mmUVD_RBC_XX_IB_REG_CHECK 					0x026b
7462306a36Sopenharmony_ci#define mmUVD_RBC_XX_IB_REG_CHECK_BASE_IDX 				1
7562306a36Sopenharmony_ci#define mmUVD_REG_XX_MASK 						0x026c
7662306a36Sopenharmony_ci#define mmUVD_REG_XX_MASK_BASE_IDX 					1
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/* 1 second timeout */
7962306a36Sopenharmony_ci#define VCN_IDLE_TIMEOUT	msecs_to_jiffies(1000)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define RREG32_SOC15_DPG_MODE_1_0(ip, inst_idx, reg, mask, sram_sel) 			\
8262306a36Sopenharmony_ci	({	WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_MASK, mask); 			\
8362306a36Sopenharmony_ci		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_CTL, 				\
8462306a36Sopenharmony_ci			UVD_DPG_LMA_CTL__MASK_EN_MASK | 				\
8562306a36Sopenharmony_ci			((adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg) 	\
8662306a36Sopenharmony_ci			<< UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT) | 			\
8762306a36Sopenharmony_ci			(sram_sel << UVD_DPG_LMA_CTL__SRAM_SEL__SHIFT)); 		\
8862306a36Sopenharmony_ci		RREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_DATA); 			\
8962306a36Sopenharmony_ci	})
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#define WREG32_SOC15_DPG_MODE_1_0(ip, inst_idx, reg, value, mask, sram_sel) 		\
9262306a36Sopenharmony_ci	do { 										\
9362306a36Sopenharmony_ci		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_DATA, value); 			\
9462306a36Sopenharmony_ci		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_MASK, mask); 			\
9562306a36Sopenharmony_ci		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_CTL, 				\
9662306a36Sopenharmony_ci			UVD_DPG_LMA_CTL__READ_WRITE_MASK | 				\
9762306a36Sopenharmony_ci			((adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg) 	\
9862306a36Sopenharmony_ci			<< UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT) | 			\
9962306a36Sopenharmony_ci			(sram_sel << UVD_DPG_LMA_CTL__SRAM_SEL__SHIFT)); 		\
10062306a36Sopenharmony_ci	} while (0)
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#define SOC15_DPG_MODE_OFFSET(ip, inst_idx, reg) 						\
10362306a36Sopenharmony_ci	({											\
10462306a36Sopenharmony_ci		uint32_t internal_reg_offset, addr;						\
10562306a36Sopenharmony_ci		bool video_range, video1_range, aon_range, aon1_range;				\
10662306a36Sopenharmony_ci												\
10762306a36Sopenharmony_ci		addr = (adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg);		\
10862306a36Sopenharmony_ci		addr <<= 2; 									\
10962306a36Sopenharmony_ci		video_range = ((((0xFFFFF & addr) >= (VCN_VID_SOC_ADDRESS_2_0)) && 		\
11062306a36Sopenharmony_ci				((0xFFFFF & addr) < ((VCN_VID_SOC_ADDRESS_2_0 + 0x2600)))));	\
11162306a36Sopenharmony_ci		video1_range = ((((0xFFFFF & addr) >= (VCN1_VID_SOC_ADDRESS_3_0)) && 		\
11262306a36Sopenharmony_ci				((0xFFFFF & addr) < ((VCN1_VID_SOC_ADDRESS_3_0 + 0x2600)))));	\
11362306a36Sopenharmony_ci		aon_range   = ((((0xFFFFF & addr) >= (VCN_AON_SOC_ADDRESS_2_0)) && 		\
11462306a36Sopenharmony_ci				((0xFFFFF & addr) < ((VCN_AON_SOC_ADDRESS_2_0 + 0x600)))));	\
11562306a36Sopenharmony_ci		aon1_range   = ((((0xFFFFF & addr) >= (VCN1_AON_SOC_ADDRESS_3_0)) && 		\
11662306a36Sopenharmony_ci				((0xFFFFF & addr) < ((VCN1_AON_SOC_ADDRESS_3_0 + 0x600)))));	\
11762306a36Sopenharmony_ci		if (video_range) 								\
11862306a36Sopenharmony_ci			internal_reg_offset = ((0xFFFFF & addr) - (VCN_VID_SOC_ADDRESS_2_0) + 	\
11962306a36Sopenharmony_ci				(VCN_VID_IP_ADDRESS_2_0));					\
12062306a36Sopenharmony_ci		else if (aon_range)								\
12162306a36Sopenharmony_ci			internal_reg_offset = ((0xFFFFF & addr) - (VCN_AON_SOC_ADDRESS_2_0) + 	\
12262306a36Sopenharmony_ci				(VCN_AON_IP_ADDRESS_2_0));					\
12362306a36Sopenharmony_ci		else if (video1_range) 								\
12462306a36Sopenharmony_ci			internal_reg_offset = ((0xFFFFF & addr) - (VCN1_VID_SOC_ADDRESS_3_0) + 	\
12562306a36Sopenharmony_ci				(VCN_VID_IP_ADDRESS_2_0));					\
12662306a36Sopenharmony_ci		else if (aon1_range)								\
12762306a36Sopenharmony_ci			internal_reg_offset = ((0xFFFFF & addr) - (VCN1_AON_SOC_ADDRESS_3_0) + 	\
12862306a36Sopenharmony_ci				(VCN_AON_IP_ADDRESS_2_0));					\
12962306a36Sopenharmony_ci		else										\
13062306a36Sopenharmony_ci			internal_reg_offset = (0xFFFFF & addr);					\
13162306a36Sopenharmony_ci												\
13262306a36Sopenharmony_ci		internal_reg_offset >>= 2;							\
13362306a36Sopenharmony_ci	})
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci#define RREG32_SOC15_DPG_MODE(inst_idx, offset, mask_en) 					\
13662306a36Sopenharmony_ci	({											\
13762306a36Sopenharmony_ci		WREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_CTL, 					\
13862306a36Sopenharmony_ci			(0x0 << UVD_DPG_LMA_CTL__READ_WRITE__SHIFT |				\
13962306a36Sopenharmony_ci			mask_en << UVD_DPG_LMA_CTL__MASK_EN__SHIFT |				\
14062306a36Sopenharmony_ci			offset << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT));			\
14162306a36Sopenharmony_ci		RREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_DATA);				\
14262306a36Sopenharmony_ci	})
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci#define WREG32_SOC15_DPG_MODE(inst_idx, offset, value, mask_en, indirect)             \
14562306a36Sopenharmony_ci	do {                                                                          \
14662306a36Sopenharmony_ci		if (!indirect) {                                                      \
14762306a36Sopenharmony_ci			WREG32_SOC15(VCN, GET_INST(VCN, inst_idx),                    \
14862306a36Sopenharmony_ci				     mmUVD_DPG_LMA_DATA, value);                      \
14962306a36Sopenharmony_ci			WREG32_SOC15(                                                 \
15062306a36Sopenharmony_ci				VCN, GET_INST(VCN, inst_idx),                         \
15162306a36Sopenharmony_ci				mmUVD_DPG_LMA_CTL,                                    \
15262306a36Sopenharmony_ci				(0x1 << UVD_DPG_LMA_CTL__READ_WRITE__SHIFT |          \
15362306a36Sopenharmony_ci				 mask_en << UVD_DPG_LMA_CTL__MASK_EN__SHIFT |         \
15462306a36Sopenharmony_ci				 offset << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT)); \
15562306a36Sopenharmony_ci		} else {                                                              \
15662306a36Sopenharmony_ci			*adev->vcn.inst[inst_idx].dpg_sram_curr_addr++ =              \
15762306a36Sopenharmony_ci				offset;                                               \
15862306a36Sopenharmony_ci			*adev->vcn.inst[inst_idx].dpg_sram_curr_addr++ =              \
15962306a36Sopenharmony_ci				value;                                                \
16062306a36Sopenharmony_ci		}                                                                     \
16162306a36Sopenharmony_ci	} while (0)
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci#define AMDGPU_FW_SHARED_FLAG_0_UNIFIED_QUEUE (1 << 2)
16462306a36Sopenharmony_ci#define AMDGPU_FW_SHARED_FLAG_0_DRM_KEY_INJECT (1 << 4)
16562306a36Sopenharmony_ci#define AMDGPU_VCN_FW_SHARED_FLAG_0_RB	(1 << 6)
16662306a36Sopenharmony_ci#define AMDGPU_VCN_MULTI_QUEUE_FLAG	(1 << 8)
16762306a36Sopenharmony_ci#define AMDGPU_VCN_SW_RING_FLAG		(1 << 9)
16862306a36Sopenharmony_ci#define AMDGPU_VCN_FW_LOGGING_FLAG	(1 << 10)
16962306a36Sopenharmony_ci#define AMDGPU_VCN_SMU_VERSION_INFO_FLAG (1 << 11)
17062306a36Sopenharmony_ci#define AMDGPU_VCN_SMU_DPM_INTERFACE_FLAG (1 << 11)
17162306a36Sopenharmony_ci#define AMDGPU_VCN_VF_RB_SETUP_FLAG (1 << 14)
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#define AMDGPU_VCN_IB_FLAG_DECODE_BUFFER	0x00000001
17462306a36Sopenharmony_ci#define AMDGPU_VCN_CMD_FLAG_MSG_BUFFER		0x00000001
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci#define VCN_CODEC_DISABLE_MASK_AV1  (1 << 0)
17762306a36Sopenharmony_ci#define VCN_CODEC_DISABLE_MASK_VP9  (1 << 1)
17862306a36Sopenharmony_ci#define VCN_CODEC_DISABLE_MASK_HEVC (1 << 2)
17962306a36Sopenharmony_ci#define VCN_CODEC_DISABLE_MASK_H264 (1 << 3)
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci#define AMDGPU_VCN_SMU_DPM_INTERFACE_DGPU (0)
18262306a36Sopenharmony_ci#define AMDGPU_VCN_SMU_DPM_INTERFACE_APU (1)
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci#define AMDGPU_DRM_KEY_INJECT_WORKAROUND_VCNFW_ASD_HANDSHAKING 2
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_cienum fw_queue_mode {
18762306a36Sopenharmony_ci	FW_QUEUE_RING_RESET = 1,
18862306a36Sopenharmony_ci	FW_QUEUE_DPG_HOLD_OFF = 2,
18962306a36Sopenharmony_ci};
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_cienum engine_status_constants {
19262306a36Sopenharmony_ci	UVD_PGFSM_STATUS__UVDM_UVDU_PWR_ON = 0x2AAAA0,
19362306a36Sopenharmony_ci	UVD_PGFSM_STATUS__UVDM_UVDU_PWR_ON_2_0 = 0xAAAA0,
19462306a36Sopenharmony_ci	UVD_PGFSM_STATUS__UVDM_UVDU_UVDLM_PWR_ON_3_0 = 0x2A2A8AA0,
19562306a36Sopenharmony_ci	UVD_PGFSM_CONFIG__UVDM_UVDU_PWR_ON = 0x00000002,
19662306a36Sopenharmony_ci	UVD_STATUS__UVD_BUSY = 0x00000004,
19762306a36Sopenharmony_ci	GB_ADDR_CONFIG_DEFAULT = 0x26010011,
19862306a36Sopenharmony_ci	UVD_STATUS__IDLE = 0x2,
19962306a36Sopenharmony_ci	UVD_STATUS__BUSY = 0x5,
20062306a36Sopenharmony_ci	UVD_POWER_STATUS__UVD_POWER_STATUS_TILES_OFF = 0x1,
20162306a36Sopenharmony_ci	UVD_STATUS__RBC_BUSY = 0x1,
20262306a36Sopenharmony_ci	UVD_PGFSM_STATUS_UVDJ_PWR_ON = 0,
20362306a36Sopenharmony_ci};
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cienum internal_dpg_state {
20662306a36Sopenharmony_ci	VCN_DPG_STATE__UNPAUSE = 0,
20762306a36Sopenharmony_ci	VCN_DPG_STATE__PAUSE,
20862306a36Sopenharmony_ci};
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_cistruct dpg_pause_state {
21162306a36Sopenharmony_ci	enum internal_dpg_state fw_based;
21262306a36Sopenharmony_ci	enum internal_dpg_state jpeg;
21362306a36Sopenharmony_ci};
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_cistruct amdgpu_vcn_reg{
21662306a36Sopenharmony_ci	unsigned	data0;
21762306a36Sopenharmony_ci	unsigned	data1;
21862306a36Sopenharmony_ci	unsigned	cmd;
21962306a36Sopenharmony_ci	unsigned	nop;
22062306a36Sopenharmony_ci	unsigned	context_id;
22162306a36Sopenharmony_ci	unsigned	ib_vmid;
22262306a36Sopenharmony_ci	unsigned	ib_bar_low;
22362306a36Sopenharmony_ci	unsigned	ib_bar_high;
22462306a36Sopenharmony_ci	unsigned	ib_size;
22562306a36Sopenharmony_ci	unsigned	gp_scratch8;
22662306a36Sopenharmony_ci	unsigned	scratch9;
22762306a36Sopenharmony_ci};
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_cistruct amdgpu_vcn_fw_shared {
23062306a36Sopenharmony_ci	void        *cpu_addr;
23162306a36Sopenharmony_ci	uint64_t    gpu_addr;
23262306a36Sopenharmony_ci	uint32_t    mem_size;
23362306a36Sopenharmony_ci	uint32_t    log_offset;
23462306a36Sopenharmony_ci};
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_cistruct amdgpu_vcn_inst {
23762306a36Sopenharmony_ci	struct amdgpu_bo	*vcpu_bo;
23862306a36Sopenharmony_ci	void			*cpu_addr;
23962306a36Sopenharmony_ci	uint64_t		gpu_addr;
24062306a36Sopenharmony_ci	void			*saved_bo;
24162306a36Sopenharmony_ci	struct amdgpu_ring	ring_dec;
24262306a36Sopenharmony_ci	struct amdgpu_ring	ring_enc[AMDGPU_VCN_MAX_ENC_RINGS];
24362306a36Sopenharmony_ci	atomic_t		sched_score;
24462306a36Sopenharmony_ci	struct amdgpu_irq_src	irq;
24562306a36Sopenharmony_ci	struct amdgpu_irq_src	ras_poison_irq;
24662306a36Sopenharmony_ci	struct amdgpu_vcn_reg	external;
24762306a36Sopenharmony_ci	struct amdgpu_bo	*dpg_sram_bo;
24862306a36Sopenharmony_ci	struct dpg_pause_state	pause_state;
24962306a36Sopenharmony_ci	void			*dpg_sram_cpu_addr;
25062306a36Sopenharmony_ci	uint64_t		dpg_sram_gpu_addr;
25162306a36Sopenharmony_ci	uint32_t		*dpg_sram_curr_addr;
25262306a36Sopenharmony_ci	atomic_t		dpg_enc_submission_cnt;
25362306a36Sopenharmony_ci	struct amdgpu_vcn_fw_shared fw_shared;
25462306a36Sopenharmony_ci	uint8_t			aid_id;
25562306a36Sopenharmony_ci};
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_cistruct amdgpu_vcn_ras {
25862306a36Sopenharmony_ci	struct amdgpu_ras_block_object ras_block;
25962306a36Sopenharmony_ci};
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_cistruct amdgpu_vcn {
26262306a36Sopenharmony_ci	unsigned		fw_version;
26362306a36Sopenharmony_ci	struct delayed_work	idle_work;
26462306a36Sopenharmony_ci	const struct firmware	*fw;	/* VCN firmware */
26562306a36Sopenharmony_ci	unsigned		num_enc_rings;
26662306a36Sopenharmony_ci	enum amd_powergating_state cur_state;
26762306a36Sopenharmony_ci	bool			indirect_sram;
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci	uint8_t	num_vcn_inst;
27062306a36Sopenharmony_ci	struct amdgpu_vcn_inst	 inst[AMDGPU_MAX_VCN_INSTANCES];
27162306a36Sopenharmony_ci	uint8_t			 vcn_config[AMDGPU_MAX_VCN_INSTANCES];
27262306a36Sopenharmony_ci	uint32_t		 vcn_codec_disable_mask[AMDGPU_MAX_VCN_INSTANCES];
27362306a36Sopenharmony_ci	struct amdgpu_vcn_reg	 internal;
27462306a36Sopenharmony_ci	struct mutex		 vcn_pg_lock;
27562306a36Sopenharmony_ci	struct mutex		vcn1_jpeg1_workaround;
27662306a36Sopenharmony_ci	atomic_t		 total_submission_cnt;
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci	unsigned	harvest_config;
27962306a36Sopenharmony_ci	int (*pause_dpg_mode)(struct amdgpu_device *adev,
28062306a36Sopenharmony_ci		int inst_idx, struct dpg_pause_state *new_state);
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci	struct ras_common_if    *ras_if;
28362306a36Sopenharmony_ci	struct amdgpu_vcn_ras   *ras;
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci	uint16_t inst_mask;
28662306a36Sopenharmony_ci	uint8_t	num_inst_per_aid;
28762306a36Sopenharmony_ci};
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_cistruct amdgpu_fw_shared_rb_ptrs_struct {
29062306a36Sopenharmony_ci	/* to WA DPG R/W ptr issues.*/
29162306a36Sopenharmony_ci	uint32_t  rptr;
29262306a36Sopenharmony_ci	uint32_t  wptr;
29362306a36Sopenharmony_ci};
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_cistruct amdgpu_fw_shared_multi_queue {
29662306a36Sopenharmony_ci	uint8_t decode_queue_mode;
29762306a36Sopenharmony_ci	uint8_t encode_generalpurpose_queue_mode;
29862306a36Sopenharmony_ci	uint8_t encode_lowlatency_queue_mode;
29962306a36Sopenharmony_ci	uint8_t encode_realtime_queue_mode;
30062306a36Sopenharmony_ci	uint8_t padding[4];
30162306a36Sopenharmony_ci};
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_cistruct amdgpu_fw_shared_sw_ring {
30462306a36Sopenharmony_ci	uint8_t is_enabled;
30562306a36Sopenharmony_ci	uint8_t padding[3];
30662306a36Sopenharmony_ci};
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_cistruct amdgpu_fw_shared_unified_queue_struct {
30962306a36Sopenharmony_ci	uint8_t is_enabled;
31062306a36Sopenharmony_ci	uint8_t queue_mode;
31162306a36Sopenharmony_ci	uint8_t queue_status;
31262306a36Sopenharmony_ci	uint8_t padding[5];
31362306a36Sopenharmony_ci};
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_cistruct amdgpu_fw_shared_fw_logging {
31662306a36Sopenharmony_ci	uint8_t is_enabled;
31762306a36Sopenharmony_ci	uint32_t addr_lo;
31862306a36Sopenharmony_ci	uint32_t addr_hi;
31962306a36Sopenharmony_ci	uint32_t size;
32062306a36Sopenharmony_ci};
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_cistruct amdgpu_fw_shared_smu_interface_info {
32362306a36Sopenharmony_ci	uint8_t smu_interface_type;
32462306a36Sopenharmony_ci	uint8_t padding[3];
32562306a36Sopenharmony_ci};
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_cistruct amdgpu_fw_shared {
32862306a36Sopenharmony_ci	uint32_t present_flag_0;
32962306a36Sopenharmony_ci	uint8_t pad[44];
33062306a36Sopenharmony_ci	struct amdgpu_fw_shared_rb_ptrs_struct rb;
33162306a36Sopenharmony_ci	uint8_t pad1[1];
33262306a36Sopenharmony_ci	struct amdgpu_fw_shared_multi_queue multi_queue;
33362306a36Sopenharmony_ci	struct amdgpu_fw_shared_sw_ring sw_ring;
33462306a36Sopenharmony_ci	struct amdgpu_fw_shared_fw_logging fw_log;
33562306a36Sopenharmony_ci	struct amdgpu_fw_shared_smu_interface_info smu_interface_info;
33662306a36Sopenharmony_ci};
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_cistruct amdgpu_fw_shared_rb_setup {
33962306a36Sopenharmony_ci	uint32_t is_rb_enabled_flags;
34062306a36Sopenharmony_ci	uint32_t rb_addr_lo;
34162306a36Sopenharmony_ci	uint32_t rb_addr_hi;
34262306a36Sopenharmony_ci	uint32_t  rb_size;
34362306a36Sopenharmony_ci	uint32_t  rb4_addr_lo;
34462306a36Sopenharmony_ci	uint32_t  rb4_addr_hi;
34562306a36Sopenharmony_ci	uint32_t  rb4_size;
34662306a36Sopenharmony_ci	uint32_t  reserved[6];
34762306a36Sopenharmony_ci};
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_cistruct amdgpu_fw_shared_drm_key_wa {
35062306a36Sopenharmony_ci	uint8_t  method;
35162306a36Sopenharmony_ci	uint8_t  reserved[3];
35262306a36Sopenharmony_ci};
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_cistruct amdgpu_vcn4_fw_shared {
35562306a36Sopenharmony_ci	uint32_t present_flag_0;
35662306a36Sopenharmony_ci	uint8_t pad[12];
35762306a36Sopenharmony_ci	struct amdgpu_fw_shared_unified_queue_struct sq;
35862306a36Sopenharmony_ci	uint8_t pad1[8];
35962306a36Sopenharmony_ci	struct amdgpu_fw_shared_fw_logging fw_log;
36062306a36Sopenharmony_ci	uint8_t pad2[20];
36162306a36Sopenharmony_ci	struct amdgpu_fw_shared_rb_setup rb_setup;
36262306a36Sopenharmony_ci	struct amdgpu_fw_shared_smu_interface_info smu_dpm_interface;
36362306a36Sopenharmony_ci	struct amdgpu_fw_shared_drm_key_wa drm_key_wa;
36462306a36Sopenharmony_ci};
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_cistruct amdgpu_vcn_fwlog {
36762306a36Sopenharmony_ci	uint32_t rptr;
36862306a36Sopenharmony_ci	uint32_t wptr;
36962306a36Sopenharmony_ci	uint32_t buffer_size;
37062306a36Sopenharmony_ci	uint32_t header_size;
37162306a36Sopenharmony_ci	uint8_t wrapped;
37262306a36Sopenharmony_ci};
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_cistruct amdgpu_vcn_decode_buffer {
37562306a36Sopenharmony_ci	uint32_t valid_buf_flag;
37662306a36Sopenharmony_ci	uint32_t msg_buffer_address_hi;
37762306a36Sopenharmony_ci	uint32_t msg_buffer_address_lo;
37862306a36Sopenharmony_ci	uint32_t pad[30];
37962306a36Sopenharmony_ci};
38062306a36Sopenharmony_ci
38162306a36Sopenharmony_ci#define VCN_BLOCK_ENCODE_DISABLE_MASK 0x80
38262306a36Sopenharmony_ci#define VCN_BLOCK_DECODE_DISABLE_MASK 0x40
38362306a36Sopenharmony_ci#define VCN_BLOCK_QUEUE_DISABLE_MASK 0xC0
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_cienum vcn_ring_type {
38662306a36Sopenharmony_ci	VCN_ENCODE_RING,
38762306a36Sopenharmony_ci	VCN_DECODE_RING,
38862306a36Sopenharmony_ci	VCN_UNIFIED_RING,
38962306a36Sopenharmony_ci};
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ciint amdgpu_vcn_early_init(struct amdgpu_device *adev);
39262306a36Sopenharmony_ciint amdgpu_vcn_sw_init(struct amdgpu_device *adev);
39362306a36Sopenharmony_ciint amdgpu_vcn_sw_fini(struct amdgpu_device *adev);
39462306a36Sopenharmony_ciint amdgpu_vcn_suspend(struct amdgpu_device *adev);
39562306a36Sopenharmony_ciint amdgpu_vcn_resume(struct amdgpu_device *adev);
39662306a36Sopenharmony_civoid amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring);
39762306a36Sopenharmony_civoid amdgpu_vcn_ring_end_use(struct amdgpu_ring *ring);
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_cibool amdgpu_vcn_is_disabled_vcn(struct amdgpu_device *adev,
40062306a36Sopenharmony_ci				enum vcn_ring_type type, uint32_t vcn_instance);
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_ciint amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring *ring);
40362306a36Sopenharmony_ciint amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout);
40462306a36Sopenharmony_ciint amdgpu_vcn_dec_sw_ring_test_ring(struct amdgpu_ring *ring);
40562306a36Sopenharmony_ciint amdgpu_vcn_dec_sw_ring_test_ib(struct amdgpu_ring *ring, long timeout);
40662306a36Sopenharmony_ciint amdgpu_vcn_unified_ring_test_ib(struct amdgpu_ring *ring, long timeout);
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_ciint amdgpu_vcn_enc_ring_test_ring(struct amdgpu_ring *ring);
40962306a36Sopenharmony_ciint amdgpu_vcn_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout);
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_cienum amdgpu_ring_priority_level amdgpu_vcn_get_enc_ring_prio(int ring);
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_civoid amdgpu_vcn_setup_ucode(struct amdgpu_device *adev);
41462306a36Sopenharmony_ci
41562306a36Sopenharmony_civoid amdgpu_vcn_fwlog_init(struct amdgpu_vcn_inst *vcn);
41662306a36Sopenharmony_civoid amdgpu_debugfs_vcn_fwlog_init(struct amdgpu_device *adev,
41762306a36Sopenharmony_ci                                   uint8_t i, struct amdgpu_vcn_inst *vcn);
41862306a36Sopenharmony_ci
41962306a36Sopenharmony_ciint amdgpu_vcn_process_poison_irq(struct amdgpu_device *adev,
42062306a36Sopenharmony_ci			struct amdgpu_irq_src *source,
42162306a36Sopenharmony_ci			struct amdgpu_iv_entry *entry);
42262306a36Sopenharmony_ciint amdgpu_vcn_ras_late_init(struct amdgpu_device *adev,
42362306a36Sopenharmony_ci			struct ras_common_if *ras_block);
42462306a36Sopenharmony_ciint amdgpu_vcn_ras_sw_init(struct amdgpu_device *adev);
42562306a36Sopenharmony_ci
42662306a36Sopenharmony_ciint amdgpu_vcn_psp_update_sram(struct amdgpu_device *adev, int inst_idx,
42762306a36Sopenharmony_ci			       enum AMDGPU_UCODE_ID ucode_id);
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_ci#endif
430