18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2016 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_VCN_H__ 258c2ecf20Sopenharmony_ci#define __AMDGPU_VCN_H__ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define AMDGPU_VCN_STACK_SIZE (128*1024) 288c2ecf20Sopenharmony_ci#define AMDGPU_VCN_CONTEXT_SIZE (512*1024) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define AMDGPU_VCN_FIRMWARE_OFFSET 256 318c2ecf20Sopenharmony_ci#define AMDGPU_VCN_MAX_ENC_RINGS 3 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define AMDGPU_MAX_VCN_INSTANCES 2 348c2ecf20Sopenharmony_ci#define AMDGPU_MAX_VCN_ENC_RINGS AMDGPU_VCN_MAX_ENC_RINGS * AMDGPU_MAX_VCN_INSTANCES 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define AMDGPU_VCN_HARVEST_VCN0 (1 << 0) 378c2ecf20Sopenharmony_ci#define AMDGPU_VCN_HARVEST_VCN1 (1 << 1) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define VCN_DEC_KMD_CMD 0x80000000 408c2ecf20Sopenharmony_ci#define VCN_DEC_CMD_FENCE 0x00000000 418c2ecf20Sopenharmony_ci#define VCN_DEC_CMD_TRAP 0x00000001 428c2ecf20Sopenharmony_ci#define VCN_DEC_CMD_WRITE_REG 0x00000004 438c2ecf20Sopenharmony_ci#define VCN_DEC_CMD_REG_READ_COND_WAIT 0x00000006 448c2ecf20Sopenharmony_ci#define VCN_DEC_CMD_PACKET_START 0x0000000a 458c2ecf20Sopenharmony_ci#define VCN_DEC_CMD_PACKET_END 0x0000000b 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define VCN_ENC_CMD_NO_OP 0x00000000 488c2ecf20Sopenharmony_ci#define VCN_ENC_CMD_END 0x00000001 498c2ecf20Sopenharmony_ci#define VCN_ENC_CMD_IB 0x00000002 508c2ecf20Sopenharmony_ci#define VCN_ENC_CMD_FENCE 0x00000003 518c2ecf20Sopenharmony_ci#define VCN_ENC_CMD_TRAP 0x00000004 528c2ecf20Sopenharmony_ci#define VCN_ENC_CMD_REG_WRITE 0x0000000b 538c2ecf20Sopenharmony_ci#define VCN_ENC_CMD_REG_WAIT 0x0000000c 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define VCN_VID_SOC_ADDRESS_2_0 0x1fa00 568c2ecf20Sopenharmony_ci#define VCN1_VID_SOC_ADDRESS_3_0 0x48200 578c2ecf20Sopenharmony_ci#define VCN_AON_SOC_ADDRESS_2_0 0x1f800 588c2ecf20Sopenharmony_ci#define VCN1_AON_SOC_ADDRESS_3_0 0x48000 598c2ecf20Sopenharmony_ci#define VCN_VID_IP_ADDRESS_2_0 0x0 608c2ecf20Sopenharmony_ci#define VCN_AON_IP_ADDRESS_2_0 0x30000 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#define mmUVD_RBC_XX_IB_REG_CHECK 0x026b 638c2ecf20Sopenharmony_ci#define mmUVD_RBC_XX_IB_REG_CHECK_BASE_IDX 1 648c2ecf20Sopenharmony_ci#define mmUVD_REG_XX_MASK 0x026c 658c2ecf20Sopenharmony_ci#define mmUVD_REG_XX_MASK_BASE_IDX 1 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* 1 second timeout */ 688c2ecf20Sopenharmony_ci#define VCN_IDLE_TIMEOUT msecs_to_jiffies(1000) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define RREG32_SOC15_DPG_MODE_1_0(ip, inst_idx, reg, mask, sram_sel) \ 718c2ecf20Sopenharmony_ci ({ WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_MASK, mask); \ 728c2ecf20Sopenharmony_ci WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_CTL, \ 738c2ecf20Sopenharmony_ci UVD_DPG_LMA_CTL__MASK_EN_MASK | \ 748c2ecf20Sopenharmony_ci ((adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg) \ 758c2ecf20Sopenharmony_ci << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT) | \ 768c2ecf20Sopenharmony_ci (sram_sel << UVD_DPG_LMA_CTL__SRAM_SEL__SHIFT)); \ 778c2ecf20Sopenharmony_ci RREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_DATA); \ 788c2ecf20Sopenharmony_ci }) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define WREG32_SOC15_DPG_MODE_1_0(ip, inst_idx, reg, value, mask, sram_sel) \ 818c2ecf20Sopenharmony_ci do { \ 828c2ecf20Sopenharmony_ci WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_DATA, value); \ 838c2ecf20Sopenharmony_ci WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_MASK, mask); \ 848c2ecf20Sopenharmony_ci WREG32_SOC15(ip, inst_idx, mmUVD_DPG_LMA_CTL, \ 858c2ecf20Sopenharmony_ci UVD_DPG_LMA_CTL__READ_WRITE_MASK | \ 868c2ecf20Sopenharmony_ci ((adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg) \ 878c2ecf20Sopenharmony_ci << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT) | \ 888c2ecf20Sopenharmony_ci (sram_sel << UVD_DPG_LMA_CTL__SRAM_SEL__SHIFT)); \ 898c2ecf20Sopenharmony_ci } while (0) 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define SOC15_DPG_MODE_OFFSET(ip, inst_idx, reg) \ 928c2ecf20Sopenharmony_ci ({ \ 938c2ecf20Sopenharmony_ci uint32_t internal_reg_offset, addr; \ 948c2ecf20Sopenharmony_ci bool video_range, video1_range, aon_range, aon1_range; \ 958c2ecf20Sopenharmony_ci \ 968c2ecf20Sopenharmony_ci addr = (adev->reg_offset[ip##_HWIP][inst_idx][reg##_BASE_IDX] + reg); \ 978c2ecf20Sopenharmony_ci addr <<= 2; \ 988c2ecf20Sopenharmony_ci video_range = ((((0xFFFFF & addr) >= (VCN_VID_SOC_ADDRESS_2_0)) && \ 998c2ecf20Sopenharmony_ci ((0xFFFFF & addr) < ((VCN_VID_SOC_ADDRESS_2_0 + 0x2600))))); \ 1008c2ecf20Sopenharmony_ci video1_range = ((((0xFFFFF & addr) >= (VCN1_VID_SOC_ADDRESS_3_0)) && \ 1018c2ecf20Sopenharmony_ci ((0xFFFFF & addr) < ((VCN1_VID_SOC_ADDRESS_3_0 + 0x2600))))); \ 1028c2ecf20Sopenharmony_ci aon_range = ((((0xFFFFF & addr) >= (VCN_AON_SOC_ADDRESS_2_0)) && \ 1038c2ecf20Sopenharmony_ci ((0xFFFFF & addr) < ((VCN_AON_SOC_ADDRESS_2_0 + 0x600))))); \ 1048c2ecf20Sopenharmony_ci aon1_range = ((((0xFFFFF & addr) >= (VCN1_AON_SOC_ADDRESS_3_0)) && \ 1058c2ecf20Sopenharmony_ci ((0xFFFFF & addr) < ((VCN1_AON_SOC_ADDRESS_3_0 + 0x600))))); \ 1068c2ecf20Sopenharmony_ci if (video_range) \ 1078c2ecf20Sopenharmony_ci internal_reg_offset = ((0xFFFFF & addr) - (VCN_VID_SOC_ADDRESS_2_0) + \ 1088c2ecf20Sopenharmony_ci (VCN_VID_IP_ADDRESS_2_0)); \ 1098c2ecf20Sopenharmony_ci else if (aon_range) \ 1108c2ecf20Sopenharmony_ci internal_reg_offset = ((0xFFFFF & addr) - (VCN_AON_SOC_ADDRESS_2_0) + \ 1118c2ecf20Sopenharmony_ci (VCN_AON_IP_ADDRESS_2_0)); \ 1128c2ecf20Sopenharmony_ci else if (video1_range) \ 1138c2ecf20Sopenharmony_ci internal_reg_offset = ((0xFFFFF & addr) - (VCN1_VID_SOC_ADDRESS_3_0) + \ 1148c2ecf20Sopenharmony_ci (VCN_VID_IP_ADDRESS_2_0)); \ 1158c2ecf20Sopenharmony_ci else if (aon1_range) \ 1168c2ecf20Sopenharmony_ci internal_reg_offset = ((0xFFFFF & addr) - (VCN1_AON_SOC_ADDRESS_3_0) + \ 1178c2ecf20Sopenharmony_ci (VCN_AON_IP_ADDRESS_2_0)); \ 1188c2ecf20Sopenharmony_ci else \ 1198c2ecf20Sopenharmony_ci internal_reg_offset = (0xFFFFF & addr); \ 1208c2ecf20Sopenharmony_ci \ 1218c2ecf20Sopenharmony_ci internal_reg_offset >>= 2; \ 1228c2ecf20Sopenharmony_ci }) 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#define RREG32_SOC15_DPG_MODE(inst_idx, offset, mask_en) \ 1258c2ecf20Sopenharmony_ci ({ \ 1268c2ecf20Sopenharmony_ci WREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_CTL, \ 1278c2ecf20Sopenharmony_ci (0x0 << UVD_DPG_LMA_CTL__READ_WRITE__SHIFT | \ 1288c2ecf20Sopenharmony_ci mask_en << UVD_DPG_LMA_CTL__MASK_EN__SHIFT | \ 1298c2ecf20Sopenharmony_ci offset << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT)); \ 1308c2ecf20Sopenharmony_ci RREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_DATA); \ 1318c2ecf20Sopenharmony_ci }) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define WREG32_SOC15_DPG_MODE(inst_idx, offset, value, mask_en, indirect) \ 1348c2ecf20Sopenharmony_ci do { \ 1358c2ecf20Sopenharmony_ci if (!indirect) { \ 1368c2ecf20Sopenharmony_ci WREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_DATA, value); \ 1378c2ecf20Sopenharmony_ci WREG32_SOC15(VCN, inst_idx, mmUVD_DPG_LMA_CTL, \ 1388c2ecf20Sopenharmony_ci (0x1 << UVD_DPG_LMA_CTL__READ_WRITE__SHIFT | \ 1398c2ecf20Sopenharmony_ci mask_en << UVD_DPG_LMA_CTL__MASK_EN__SHIFT | \ 1408c2ecf20Sopenharmony_ci offset << UVD_DPG_LMA_CTL__READ_WRITE_ADDR__SHIFT)); \ 1418c2ecf20Sopenharmony_ci } else { \ 1428c2ecf20Sopenharmony_ci *adev->vcn.inst[inst_idx].dpg_sram_curr_addr++ = offset; \ 1438c2ecf20Sopenharmony_ci *adev->vcn.inst[inst_idx].dpg_sram_curr_addr++ = value; \ 1448c2ecf20Sopenharmony_ci } \ 1458c2ecf20Sopenharmony_ci } while (0) 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#define AMDGPU_VCN_MULTI_QUEUE_FLAG (1 << 8) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cienum fw_queue_mode { 1508c2ecf20Sopenharmony_ci FW_QUEUE_RING_RESET = 1, 1518c2ecf20Sopenharmony_ci FW_QUEUE_DPG_HOLD_OFF = 2, 1528c2ecf20Sopenharmony_ci}; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cienum engine_status_constants { 1558c2ecf20Sopenharmony_ci UVD_PGFSM_STATUS__UVDM_UVDU_PWR_ON = 0x2AAAA0, 1568c2ecf20Sopenharmony_ci UVD_PGFSM_STATUS__UVDM_UVDU_PWR_ON_2_0 = 0xAAAA0, 1578c2ecf20Sopenharmony_ci UVD_PGFSM_STATUS__UVDM_UVDU_UVDLM_PWR_ON_3_0 = 0x2A2A8AA0, 1588c2ecf20Sopenharmony_ci UVD_PGFSM_CONFIG__UVDM_UVDU_PWR_ON = 0x00000002, 1598c2ecf20Sopenharmony_ci UVD_STATUS__UVD_BUSY = 0x00000004, 1608c2ecf20Sopenharmony_ci GB_ADDR_CONFIG_DEFAULT = 0x26010011, 1618c2ecf20Sopenharmony_ci UVD_STATUS__IDLE = 0x2, 1628c2ecf20Sopenharmony_ci UVD_STATUS__BUSY = 0x5, 1638c2ecf20Sopenharmony_ci UVD_POWER_STATUS__UVD_POWER_STATUS_TILES_OFF = 0x1, 1648c2ecf20Sopenharmony_ci UVD_STATUS__RBC_BUSY = 0x1, 1658c2ecf20Sopenharmony_ci UVD_PGFSM_STATUS_UVDJ_PWR_ON = 0, 1668c2ecf20Sopenharmony_ci}; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cienum internal_dpg_state { 1698c2ecf20Sopenharmony_ci VCN_DPG_STATE__UNPAUSE = 0, 1708c2ecf20Sopenharmony_ci VCN_DPG_STATE__PAUSE, 1718c2ecf20Sopenharmony_ci}; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistruct dpg_pause_state { 1748c2ecf20Sopenharmony_ci enum internal_dpg_state fw_based; 1758c2ecf20Sopenharmony_ci enum internal_dpg_state jpeg; 1768c2ecf20Sopenharmony_ci}; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistruct amdgpu_vcn_reg{ 1798c2ecf20Sopenharmony_ci unsigned data0; 1808c2ecf20Sopenharmony_ci unsigned data1; 1818c2ecf20Sopenharmony_ci unsigned cmd; 1828c2ecf20Sopenharmony_ci unsigned nop; 1838c2ecf20Sopenharmony_ci unsigned context_id; 1848c2ecf20Sopenharmony_ci unsigned ib_vmid; 1858c2ecf20Sopenharmony_ci unsigned ib_bar_low; 1868c2ecf20Sopenharmony_ci unsigned ib_bar_high; 1878c2ecf20Sopenharmony_ci unsigned ib_size; 1888c2ecf20Sopenharmony_ci unsigned gp_scratch8; 1898c2ecf20Sopenharmony_ci unsigned scratch9; 1908c2ecf20Sopenharmony_ci}; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_cistruct amdgpu_vcn_inst { 1938c2ecf20Sopenharmony_ci struct amdgpu_bo *vcpu_bo; 1948c2ecf20Sopenharmony_ci void *cpu_addr; 1958c2ecf20Sopenharmony_ci uint64_t gpu_addr; 1968c2ecf20Sopenharmony_ci void *saved_bo; 1978c2ecf20Sopenharmony_ci struct amdgpu_ring ring_dec; 1988c2ecf20Sopenharmony_ci struct amdgpu_ring ring_enc[AMDGPU_VCN_MAX_ENC_RINGS]; 1998c2ecf20Sopenharmony_ci struct amdgpu_irq_src irq; 2008c2ecf20Sopenharmony_ci struct amdgpu_vcn_reg external; 2018c2ecf20Sopenharmony_ci struct amdgpu_bo *dpg_sram_bo; 2028c2ecf20Sopenharmony_ci struct dpg_pause_state pause_state; 2038c2ecf20Sopenharmony_ci void *dpg_sram_cpu_addr; 2048c2ecf20Sopenharmony_ci uint64_t dpg_sram_gpu_addr; 2058c2ecf20Sopenharmony_ci uint32_t *dpg_sram_curr_addr; 2068c2ecf20Sopenharmony_ci atomic_t dpg_enc_submission_cnt; 2078c2ecf20Sopenharmony_ci void *fw_shared_cpu_addr; 2088c2ecf20Sopenharmony_ci uint64_t fw_shared_gpu_addr; 2098c2ecf20Sopenharmony_ci}; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistruct amdgpu_vcn { 2128c2ecf20Sopenharmony_ci unsigned fw_version; 2138c2ecf20Sopenharmony_ci struct delayed_work idle_work; 2148c2ecf20Sopenharmony_ci const struct firmware *fw; /* VCN firmware */ 2158c2ecf20Sopenharmony_ci unsigned num_enc_rings; 2168c2ecf20Sopenharmony_ci enum amd_powergating_state cur_state; 2178c2ecf20Sopenharmony_ci bool indirect_sram; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci uint8_t num_vcn_inst; 2208c2ecf20Sopenharmony_ci struct amdgpu_vcn_inst inst[AMDGPU_MAX_VCN_INSTANCES]; 2218c2ecf20Sopenharmony_ci struct amdgpu_vcn_reg internal; 2228c2ecf20Sopenharmony_ci struct mutex vcn_pg_lock; 2238c2ecf20Sopenharmony_ci struct mutex vcn1_jpeg1_workaround; 2248c2ecf20Sopenharmony_ci atomic_t total_submission_cnt; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci unsigned harvest_config; 2278c2ecf20Sopenharmony_ci int (*pause_dpg_mode)(struct amdgpu_device *adev, 2288c2ecf20Sopenharmony_ci int inst_idx, struct dpg_pause_state *new_state); 2298c2ecf20Sopenharmony_ci}; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_cistruct amdgpu_fw_shared_multi_queue { 2328c2ecf20Sopenharmony_ci uint8_t decode_queue_mode; 2338c2ecf20Sopenharmony_ci uint8_t encode_generalpurpose_queue_mode; 2348c2ecf20Sopenharmony_ci uint8_t encode_lowlatency_queue_mode; 2358c2ecf20Sopenharmony_ci uint8_t encode_realtime_queue_mode; 2368c2ecf20Sopenharmony_ci uint8_t padding[4]; 2378c2ecf20Sopenharmony_ci}; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistruct amdgpu_fw_shared { 2408c2ecf20Sopenharmony_ci uint32_t present_flag_0; 2418c2ecf20Sopenharmony_ci uint8_t pad[53]; 2428c2ecf20Sopenharmony_ci struct amdgpu_fw_shared_multi_queue multi_queue; 2438c2ecf20Sopenharmony_ci} __attribute__((__packed__)); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ciint amdgpu_vcn_sw_init(struct amdgpu_device *adev); 2468c2ecf20Sopenharmony_ciint amdgpu_vcn_sw_fini(struct amdgpu_device *adev); 2478c2ecf20Sopenharmony_ciint amdgpu_vcn_suspend(struct amdgpu_device *adev); 2488c2ecf20Sopenharmony_ciint amdgpu_vcn_resume(struct amdgpu_device *adev); 2498c2ecf20Sopenharmony_civoid amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring); 2508c2ecf20Sopenharmony_civoid amdgpu_vcn_ring_end_use(struct amdgpu_ring *ring); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ciint amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring *ring); 2538c2ecf20Sopenharmony_ciint amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ciint amdgpu_vcn_enc_ring_test_ring(struct amdgpu_ring *ring); 2568c2ecf20Sopenharmony_ciint amdgpu_vcn_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout); 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci#endif 259