Home | History | Annotate | Line # | Download | only in amdgpu
      1  1.1  riastrad /*	$NetBSD: amdgpu_vcn.h,v 1.2 2021/12/18 23:44:58 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2016 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  */
     25  1.1  riastrad 
     26  1.1  riastrad #ifndef __AMDGPU_VCN_H__
     27  1.1  riastrad #define __AMDGPU_VCN_H__
     28  1.1  riastrad 
     29  1.1  riastrad #define AMDGPU_VCN_STACK_SIZE		(128*1024)
     30  1.1  riastrad #define AMDGPU_VCN_CONTEXT_SIZE 	(512*1024)
     31  1.1  riastrad 
     32  1.1  riastrad #define AMDGPU_VCN_FIRMWARE_OFFSET	256
     33  1.1  riastrad #define AMDGPU_VCN_MAX_ENC_RINGS	3
     34  1.1  riastrad 
     35  1.1  riastrad #define AMDGPU_MAX_VCN_INSTANCES	2
     36  1.1  riastrad #define AMDGPU_MAX_VCN_ENC_RINGS  AMDGPU_VCN_MAX_ENC_RINGS * AMDGPU_MAX_VCN_INSTANCES
     37  1.1  riastrad 
     38  1.1  riastrad #define AMDGPU_VCN_HARVEST_VCN0 (1 << 0)
     39  1.1  riastrad #define AMDGPU_VCN_HARVEST_VCN1 (1 << 1)
     40  1.1  riastrad 
     41  1.1  riastrad #define VCN_DEC_KMD_CMD 		0x80000000
     42  1.1  riastrad #define VCN_DEC_CMD_FENCE		0x00000000
     43  1.1  riastrad #define VCN_DEC_CMD_TRAP		0x00000001
     44  1.1  riastrad #define VCN_DEC_CMD_WRITE_REG		0x00000004
     45  1.1  riastrad #define VCN_DEC_CMD_REG_READ_COND_WAIT	0x00000006
     46  1.1  riastrad #define VCN_DEC_CMD_PACKET_START	0x0000000a
     47  1.1  riastrad #define VCN_DEC_CMD_PACKET_END		0x0000000b
     48  1.1  riastrad 
     49  1.1  riastrad #define VCN_ENC_CMD_NO_OP		0x00000000
     50  1.1  riastrad #define VCN_ENC_CMD_END 		0x00000001
     51  1.1  riastrad #define VCN_ENC_CMD_IB			0x00000002
     52  1.1  riastrad #define VCN_ENC_CMD_FENCE		0x00000003
     53  1.1  riastrad #define VCN_ENC_CMD_TRAP		0x00000004
     54  1.1  riastrad #define VCN_ENC_CMD_REG_WRITE		0x0000000b
     55  1.1  riastrad #define VCN_ENC_CMD_REG_WAIT		0x0000000c
     56  1.1  riastrad 
     57  1.1  riastrad #define VCN_VID_SOC_ADDRESS_2_0 	0x1fa00
     58  1.1  riastrad #define VCN_AON_SOC_ADDRESS_2_0 	0x1f800
     59  1.1  riastrad #define VCN_VID_IP_ADDRESS_2_0		0x0
     60  1.1  riastrad #define VCN_AON_IP_ADDRESS_2_0		0x30000
     61  1.1  riastrad 
     62  1.1  riastrad #define mmUVD_RBC_XX_IB_REG_CHECK 					0x026b
     63  1.1  riastrad #define mmUVD_RBC_XX_IB_REG_CHECK_BASE_IDX 				1
     64  1.1  riastrad #define mmUVD_REG_XX_MASK 						0x026c
     65  1.1  riastrad #define mmUVD_REG_XX_MASK_BASE_IDX 					1
     66  1.1  riastrad 
     67  1.1  riastrad /* 1 second timeout */
     68  1.1  riastrad #define VCN_IDLE_TIMEOUT	msecs_to_jiffies(1000)
     69  1.1  riastrad 
     70  1.1  riastrad #define RREG32_SOC15_DPG_MODE(ip, inst_idx, reg, mask, sram_sel) 			\
     71  1.1  riastrad 	({	WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_MASK, mask); 			\
     72  1.1  riastrad 		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_CTL, 				\
     73  1.1  riastrad 			UVD_DPG_LMA_CTL__MASK_EN_MASK | 				\
     74  1.1  riastrad 			((adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg) 	\
     75  1.1  riastrad 			<< UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT) | 			\
     76  1.1  riastrad 			(sram_sel << UVD_DPG_LMA_CTL__SRAM_SEL__SHIFT)); 		\
     77  1.1  riastrad 		RREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_DATA); 			\
     78  1.1  riastrad 	})
     79  1.1  riastrad 
     80  1.1  riastrad #define WREG32_SOC15_DPG_MODE(ip, inst_idx, reg, value, mask, sram_sel) 		\
     81  1.1  riastrad 	do { 										\
     82  1.1  riastrad 		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_DATA, value); 			\
     83  1.1  riastrad 		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_MASK, mask); 			\
     84  1.1  riastrad 		WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_CTL, 				\
     85  1.1  riastrad 			UVD_DPG_LMA_CTL__READ_WRITE_MASK | 				\
     86  1.1  riastrad 			((adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg) 	\
     87  1.1  riastrad 			<< UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT) | 			\
     88  1.1  riastrad 			(sram_sel << UVD_DPG_LMA_CTL__SRAM_SEL__SHIFT)); 		\
     89  1.1  riastrad 	} while (0)
     90  1.1  riastrad 
     91  1.1  riastrad #define SOC15_DPG_MODE_OFFSET_2_0(ip, inst_idx, reg) 						\
     92  1.1  riastrad 	({											\
     93  1.1  riastrad 		uint32_t internal_reg_offset, addr;						\
     94  1.1  riastrad 		bool video_range, aon_range;							\
     95  1.1  riastrad 												\
     96  1.1  riastrad 		addr = (adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg);		\
     97  1.1  riastrad 		addr <<= 2; 									\
     98  1.1  riastrad 		video_range = ((((0xFFFFF & addr) >= (VCN_VID_SOC_ADDRESS_2_0)) && 		\
     99  1.1  riastrad 				((0xFFFFF & addr) < ((VCN_VID_SOC_ADDRESS_2_0 + 0x2600)))));	\
    100  1.1  riastrad 		aon_range   = ((((0xFFFFF & addr) >= (VCN_AON_SOC_ADDRESS_2_0)) && 		\
    101  1.1  riastrad 				((0xFFFFF & addr) < ((VCN_AON_SOC_ADDRESS_2_0 + 0x600)))));	\
    102  1.1  riastrad 		if (video_range) 								\
    103  1.1  riastrad 			internal_reg_offset = ((0xFFFFF & addr) - (VCN_VID_SOC_ADDRESS_2_0) + 	\
    104  1.1  riastrad 				(VCN_VID_IP_ADDRESS_2_0));					\
    105  1.1  riastrad 		else if (aon_range)								\
    106  1.1  riastrad 			internal_reg_offset = ((0xFFFFF & addr) - (VCN_AON_SOC_ADDRESS_2_0) + 	\
    107  1.1  riastrad 				(VCN_AON_IP_ADDRESS_2_0));					\
    108  1.1  riastrad 		else										\
    109  1.1  riastrad 			internal_reg_offset = (0xFFFFF & addr);					\
    110  1.1  riastrad 												\
    111  1.1  riastrad 		internal_reg_offset >>= 2;							\
    112  1.1  riastrad 	})
    113  1.1  riastrad 
    114  1.1  riastrad #define RREG32_SOC15_DPG_MODE_2_0(inst_idx, offset, mask_en) 					\
    115  1.1  riastrad 	({											\
    116  1.1  riastrad 		WREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_CTL, 					\
    117  1.1  riastrad 			(0x0 << UVD_DPG_LMA_CTL__READ_WRITE__SHIFT |				\
    118  1.1  riastrad 			mask_en << UVD_DPG_LMA_CTL__MASK_EN__SHIFT |				\
    119  1.1  riastrad 			offset << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT));			\
    120  1.1  riastrad 		RREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_DATA);				\
    121  1.1  riastrad 	})
    122  1.1  riastrad 
    123  1.1  riastrad #define WREG32_SOC15_DPG_MODE_2_0(inst_idx, offset, value, mask_en, indirect)			\
    124  1.1  riastrad 	do {											\
    125  1.1  riastrad 		if (!indirect) {								\
    126  1.1  riastrad 			WREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_DATA, value);			\
    127  1.1  riastrad 			WREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_CTL, 				\
    128  1.1  riastrad 				(0x1 << UVD_DPG_LMA_CTL__READ_WRITE__SHIFT |			\
    129  1.1  riastrad 				 mask_en << UVD_DPG_LMA_CTL__MASK_EN__SHIFT |			\
    130  1.1  riastrad 				 offset << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT));		\
    131  1.1  riastrad 		} else {									\
    132  1.1  riastrad 			*adev->vcn.inst[inst_idx].dpg_sram_curr_addr++ = offset;		\
    133  1.1  riastrad 			*adev->vcn.inst[inst_idx].dpg_sram_curr_addr++ = value;			\
    134  1.1  riastrad 		}										\
    135  1.1  riastrad 	} while (0)
    136  1.1  riastrad 
    137  1.1  riastrad enum engine_status_constants {
    138  1.1  riastrad 	UVD_PGFSM_STATUS__UVDM_UVDU_PWR_ON = 0x2AAAA0,
    139  1.1  riastrad 	UVD_PGFSM_STATUS__UVDM_UVDU_PWR_ON_2_0 = 0xAAAA0,
    140  1.1  riastrad 	UVD_PGFSM_CONFIG__UVDM_UVDU_PWR_ON = 0x00000002,
    141  1.1  riastrad 	UVD_STATUS__UVD_BUSY = 0x00000004,
    142  1.1  riastrad 	GB_ADDR_CONFIG_DEFAULT = 0x26010011,
    143  1.1  riastrad 	UVD_STATUS__IDLE = 0x2,
    144  1.1  riastrad 	UVD_STATUS__BUSY = 0x5,
    145  1.1  riastrad 	UVD_POWER_STATUS__UVD_POWER_STATUS_TILES_OFF = 0x1,
    146  1.1  riastrad 	UVD_STATUS__RBC_BUSY = 0x1,
    147  1.1  riastrad 	UVD_PGFSM_STATUS_UVDJ_PWR_ON = 0,
    148  1.1  riastrad };
    149  1.1  riastrad 
    150  1.1  riastrad enum internal_dpg_state {
    151  1.1  riastrad 	VCN_DPG_STATE__UNPAUSE = 0,
    152  1.1  riastrad 	VCN_DPG_STATE__PAUSE,
    153  1.1  riastrad };
    154  1.1  riastrad 
    155  1.1  riastrad struct dpg_pause_state {
    156  1.1  riastrad 	enum internal_dpg_state fw_based;
    157  1.1  riastrad 	enum internal_dpg_state jpeg;
    158  1.1  riastrad };
    159  1.1  riastrad 
    160  1.1  riastrad struct amdgpu_vcn_reg{
    161  1.1  riastrad 	unsigned	data0;
    162  1.1  riastrad 	unsigned	data1;
    163  1.1  riastrad 	unsigned	cmd;
    164  1.1  riastrad 	unsigned	nop;
    165  1.1  riastrad 	unsigned	context_id;
    166  1.1  riastrad 	unsigned	ib_vmid;
    167  1.1  riastrad 	unsigned	ib_bar_low;
    168  1.1  riastrad 	unsigned	ib_bar_high;
    169  1.1  riastrad 	unsigned	ib_size;
    170  1.1  riastrad 	unsigned	gp_scratch8;
    171  1.1  riastrad 	unsigned	scratch9;
    172  1.1  riastrad };
    173  1.1  riastrad 
    174  1.1  riastrad struct amdgpu_vcn_inst {
    175  1.1  riastrad 	struct amdgpu_bo	*vcpu_bo;
    176  1.1  riastrad 	void			*cpu_addr;
    177  1.1  riastrad 	uint64_t		gpu_addr;
    178  1.1  riastrad 	void			*saved_bo;
    179  1.1  riastrad 	struct amdgpu_ring	ring_dec;
    180  1.1  riastrad 	struct amdgpu_ring	ring_enc[AMDGPU_VCN_MAX_ENC_RINGS];
    181  1.1  riastrad 	struct amdgpu_irq_src	irq;
    182  1.1  riastrad 	struct amdgpu_vcn_reg	external;
    183  1.1  riastrad 	struct amdgpu_bo	*dpg_sram_bo;
    184  1.1  riastrad 	struct dpg_pause_state	pause_state;
    185  1.1  riastrad 	void			*dpg_sram_cpu_addr;
    186  1.1  riastrad 	uint64_t		dpg_sram_gpu_addr;
    187  1.1  riastrad 	uint32_t		*dpg_sram_curr_addr;
    188  1.1  riastrad };
    189  1.1  riastrad 
    190  1.1  riastrad struct amdgpu_vcn {
    191  1.1  riastrad 	unsigned		fw_version;
    192  1.1  riastrad 	struct delayed_work	idle_work;
    193  1.1  riastrad 	const struct firmware	*fw;	/* VCN firmware */
    194  1.1  riastrad 	unsigned		num_enc_rings;
    195  1.1  riastrad 	enum amd_powergating_state cur_state;
    196  1.1  riastrad 	bool			indirect_sram;
    197  1.1  riastrad 
    198  1.1  riastrad 	uint8_t	num_vcn_inst;
    199  1.1  riastrad 	struct amdgpu_vcn_inst	 inst[AMDGPU_MAX_VCN_INSTANCES];
    200  1.1  riastrad 	struct amdgpu_vcn_reg	 internal;
    201  1.1  riastrad 	struct drm_gpu_scheduler *vcn_enc_sched[AMDGPU_MAX_VCN_ENC_RINGS];
    202  1.1  riastrad 	struct drm_gpu_scheduler *vcn_dec_sched[AMDGPU_MAX_VCN_INSTANCES];
    203  1.1  riastrad 	uint32_t		 num_vcn_enc_sched;
    204  1.1  riastrad 	uint32_t		 num_vcn_dec_sched;
    205  1.1  riastrad 
    206  1.1  riastrad 	unsigned	harvest_config;
    207  1.1  riastrad 	int (*pause_dpg_mode)(struct amdgpu_device *adev,
    208  1.1  riastrad 		int inst_idx, struct dpg_pause_state *new_state);
    209  1.1  riastrad };
    210  1.1  riastrad 
    211  1.1  riastrad int amdgpu_vcn_sw_init(struct amdgpu_device *adev);
    212  1.1  riastrad int amdgpu_vcn_sw_fini(struct amdgpu_device *adev);
    213  1.1  riastrad int amdgpu_vcn_suspend(struct amdgpu_device *adev);
    214  1.1  riastrad int amdgpu_vcn_resume(struct amdgpu_device *adev);
    215  1.1  riastrad void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring);
    216  1.1  riastrad void amdgpu_vcn_ring_end_use(struct amdgpu_ring *ring);
    217  1.1  riastrad 
    218  1.1  riastrad int amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring *ring);
    219  1.1  riastrad int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout);
    220  1.1  riastrad 
    221  1.1  riastrad int amdgpu_vcn_enc_ring_test_ring(struct amdgpu_ring *ring);
    222  1.1  riastrad int amdgpu_vcn_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout);
    223  1.1  riastrad 
    224  1.1  riastrad #endif
    225