18e3153baSKen Wang /* 28e3153baSKen Wang * Copyright 2016 Advanced Micro Devices, Inc. 38e3153baSKen Wang * 48e3153baSKen Wang * Permission is hereby granted, free of charge, to any person obtaining a 58e3153baSKen Wang * copy of this software and associated documentation files (the "Software"), 68e3153baSKen Wang * to deal in the Software without restriction, including without limitation 78e3153baSKen Wang * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88e3153baSKen Wang * and/or sell copies of the Software, and to permit persons to whom the 98e3153baSKen Wang * Software is furnished to do so, subject to the following conditions: 108e3153baSKen Wang * 118e3153baSKen Wang * The above copyright notice and this permission notice shall be included in 128e3153baSKen Wang * all copies or substantial portions of the Software. 138e3153baSKen Wang * 148e3153baSKen Wang * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158e3153baSKen Wang * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168e3153baSKen Wang * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178e3153baSKen Wang * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188e3153baSKen Wang * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198e3153baSKen Wang * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208e3153baSKen Wang * OTHER DEALINGS IN THE SOFTWARE. 218e3153baSKen Wang * 228e3153baSKen Wang */ 238e3153baSKen Wang 248e3153baSKen Wang #ifndef __SOC15_COMMON_H__ 258e3153baSKen Wang #define __SOC15_COMMON_H__ 268e3153baSKen Wang 27659a4ab8SLijo Lazar /* GET_INST returns the physical instance corresponding to a logical instance */ 28659a4ab8SLijo Lazar #define GET_INST(ip, inst) (adev->ip_map.logical_to_dev_inst? adev->ip_map.logical_to_dev_inst(adev, ip##_HWIP, inst): inst) 29659a4ab8SLijo Lazar 30b1bb8c01STom St Denis /* Register Access Macros */ 31cd29253fSShaoyun Liu #define SOC15_REG_OFFSET(ip, inst, reg) (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) 3281283feeSJames Zhu #define SOC15_REG_OFFSET1(ip, inst, reg, offset) \ 3381283feeSJames Zhu (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + (reg)+(offset)) 348e3153baSKen Wang 35a5504e9aSPeng Ju Zhou #define __WREG32_SOC15_RLC__(reg, value, flag, hwip) \ 361b2dc99eSHawking Zhang ((amdgpu_sriov_vf(adev) && adev->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported) ? \ 371b2dc99eSHawking Zhang amdgpu_sriov_wreg(adev, reg, value, flag, hwip) : \ 38a5504e9aSPeng Ju Zhou WREG32(reg, value)) 39a5504e9aSPeng Ju Zhou 40a5504e9aSPeng Ju Zhou #define __RREG32_SOC15_RLC__(reg, flag, hwip) \ 411b2dc99eSHawking Zhang ((amdgpu_sriov_vf(adev) && adev->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported) ? \ 421b2dc99eSHawking Zhang amdgpu_sriov_rreg(adev, reg, flag, hwip) : \ 43a5504e9aSPeng Ju Zhou RREG32(reg)) 44a5504e9aSPeng Ju Zhou 45b1bb8c01STom St Denis #define WREG32_FIELD15(ip, idx, reg, field, val) \ 46a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ 47a5504e9aSPeng Ju Zhou (__RREG32_SOC15_RLC__( \ 48a5504e9aSPeng Ju Zhou adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ 49a5504e9aSPeng Ju Zhou 0, ip##_HWIP) & \ 50a5504e9aSPeng Ju Zhou ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field), \ 51a5504e9aSPeng Ju Zhou 0, ip##_HWIP) 52b1bb8c01STom St Denis 53ba9e7a4aSStanley.Yang #define WREG32_FIELD15_PREREG(ip, idx, reg_name, field, val) \ 54ba9e7a4aSStanley.Yang __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][reg##reg_name##_BASE_IDX] + reg##reg_name, \ 55ba9e7a4aSStanley.Yang (__RREG32_SOC15_RLC__( \ 56ba9e7a4aSStanley.Yang adev->reg_offset[ip##_HWIP][idx][reg##reg_name##_BASE_IDX] + reg##reg_name, \ 57ba9e7a4aSStanley.Yang 0, ip##_HWIP) & \ 58ba9e7a4aSStanley.Yang ~REG_FIELD_MASK(reg_name, field)) | (val) << REG_FIELD_SHIFT(reg_name, field), \ 59ba9e7a4aSStanley.Yang 0, ip##_HWIP) 60ba9e7a4aSStanley.Yang 61b1bb8c01STom St Denis #define RREG32_SOC15(ip, inst, reg) \ 62a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \ 63a5504e9aSPeng Ju Zhou 0, ip##_HWIP) 64a5504e9aSPeng Ju Zhou 65a5504e9aSPeng Ju Zhou #define RREG32_SOC15_IP(ip, reg) __RREG32_SOC15_RLC__(reg, 0, ip##_HWIP) 66b1bb8c01STom St Denis 670da6f6e5SVictor Skvortsov #define RREG32_SOC15_IP_NO_KIQ(ip, reg) __RREG32_SOC15_RLC__(reg, AMDGPU_REGS_NO_KIQ, ip##_HWIP) 680da6f6e5SVictor Skvortsov 69c2ce6aebSMonk Liu #define RREG32_SOC15_NO_KIQ(ip, inst, reg) \ 70a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \ 71a5504e9aSPeng Ju Zhou AMDGPU_REGS_NO_KIQ, ip##_HWIP) 72c2ce6aebSMonk Liu 73496828e7STom St Denis #define RREG32_SOC15_OFFSET(ip, inst, reg, offset) \ 74*55ff23d9SSonny Jiang __RREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + (reg)) + \ 75*55ff23d9SSonny Jiang (offset), 0, ip##_HWIP) 76496828e7STom St Denis 77b1bb8c01STom St Denis #define WREG32_SOC15(ip, inst, reg, value) \ 78a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), \ 79a5504e9aSPeng Ju Zhou value, 0, ip##_HWIP) 80a5504e9aSPeng Ju Zhou 81a5504e9aSPeng Ju Zhou #define WREG32_SOC15_IP(ip, reg, value) \ 82a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(reg, value, 0, ip##_HWIP) 83b1bb8c01STom St Denis 840da6f6e5SVictor Skvortsov #define WREG32_SOC15_IP_NO_KIQ(ip, reg, value) \ 850da6f6e5SVictor Skvortsov __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_NO_KIQ, ip##_HWIP) 860da6f6e5SVictor Skvortsov 87c708535eSShaoyun Liu #define WREG32_SOC15_NO_KIQ(ip, inst, reg, value) \ 88a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \ 89a5504e9aSPeng Ju Zhou value, AMDGPU_REGS_NO_KIQ, ip##_HWIP) 90c708535eSShaoyun Liu 91496828e7STom St Denis #define WREG32_SOC15_OFFSET(ip, inst, reg, offset, value) \ 92a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, \ 93a5504e9aSPeng Ju Zhou value, 0, ip##_HWIP) 94496828e7STom St Denis 95450da2efSJames Zhu #define SOC15_WAIT_ON_RREG(ip, inst, reg, expected_value, mask) \ 9681283feeSJames Zhu amdgpu_device_wait_on_rreg(adev, inst, \ 9781283feeSJames Zhu (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + (reg)), \ 9881283feeSJames Zhu #reg, expected_value, mask) 9981283feeSJames Zhu 10081283feeSJames Zhu #define SOC15_WAIT_ON_RREG_OFFSET(ip, inst, reg, offset, expected_value, mask) \ 10181283feeSJames Zhu amdgpu_device_wait_on_rreg(adev, inst, \ 10281283feeSJames Zhu (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + (reg) + (offset)), \ 10381283feeSJames Zhu #reg, expected_value, mask) 104ac06b4cfSRex Zhu 1056b1ff3ddSTrigger Huang #define WREG32_RLC(reg, value) \ 106a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_RLC, GC_HWIP) 1076b1ff3ddSTrigger Huang 10888f8575bSDennis Li #define WREG32_RLC_EX(prefix, reg, value) \ 10988f8575bSDennis Li do { \ 11088f8575bSDennis Li if (amdgpu_sriov_fullaccess(adev)) { \ 11188f8575bSDennis Li uint32_t i = 0; \ 11288f8575bSDennis Li uint32_t retries = 50000; \ 11388f8575bSDennis Li uint32_t r0 = adev->reg_offset[GC_HWIP][0][prefix##SCRATCH_REG0_BASE_IDX] + prefix##SCRATCH_REG0; \ 11488f8575bSDennis Li uint32_t r1 = adev->reg_offset[GC_HWIP][0][prefix##SCRATCH_REG1_BASE_IDX] + prefix##SCRATCH_REG1; \ 11588f8575bSDennis Li uint32_t spare_int = adev->reg_offset[GC_HWIP][0][prefix##RLC_SPARE_INT_BASE_IDX] + prefix##RLC_SPARE_INT; \ 11688f8575bSDennis Li WREG32(r0, value); \ 11788f8575bSDennis Li WREG32(r1, (reg | 0x80000000)); \ 11888f8575bSDennis Li WREG32(spare_int, 0x1); \ 11988f8575bSDennis Li for (i = 0; i < retries; i++) { \ 12088f8575bSDennis Li u32 tmp = RREG32(r1); \ 12188f8575bSDennis Li if (!(tmp & 0x80000000)) \ 12288f8575bSDennis Li break; \ 12388f8575bSDennis Li udelay(10); \ 12488f8575bSDennis Li } \ 12588f8575bSDennis Li if (i >= retries) \ 12688f8575bSDennis Li pr_err("timeout: rlcg program reg:0x%05x failed !\n", reg); \ 12788f8575bSDennis Li } else { \ 12888f8575bSDennis Li WREG32(reg, value); \ 12988f8575bSDennis Li } \ 13088f8575bSDennis Li } while (0) 13188f8575bSDennis Li 132a5504e9aSPeng Ju Zhou /* shadow the registers in the callback function */ 1336b1ff3ddSTrigger Huang #define WREG32_SOC15_RLC_SHADOW(ip, inst, reg, value) \ 134a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value, AMDGPU_REGS_RLC, GC_HWIP) 1355e025531SPeng Ju Zhou 136a5504e9aSPeng Ju Zhou /* for GC only */ 1375e025531SPeng Ju Zhou #define RREG32_RLC(reg) \ 138a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(reg, AMDGPU_REGS_RLC, GC_HWIP) 1395e025531SPeng Ju Zhou 140a5504e9aSPeng Ju Zhou #define WREG32_RLC_NO_KIQ(reg, value, hwip) \ 141a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_NO_KIQ | AMDGPU_REGS_RLC, hwip) 1426b1ff3ddSTrigger Huang 143a5504e9aSPeng Ju Zhou #define RREG32_RLC_NO_KIQ(reg, hwip) \ 144a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(reg, AMDGPU_REGS_NO_KIQ | AMDGPU_REGS_RLC, hwip) 1455e025531SPeng Ju Zhou 14622616eb5SDennis Li #define WREG32_SOC15_RLC_SHADOW_EX(prefix, ip, inst, reg, value) \ 14722616eb5SDennis Li do { \ 14822616eb5SDennis Li uint32_t target_reg = adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg;\ 14922616eb5SDennis Li if (amdgpu_sriov_fullaccess(adev)) { \ 15099951878SShiwu Zhang uint32_t r2 = adev->reg_offset[GC_HWIP][inst][prefix##SCRATCH_REG1_BASE_IDX] + prefix##SCRATCH_REG2; \ 15199951878SShiwu Zhang uint32_t r3 = adev->reg_offset[GC_HWIP][inst][prefix##SCRATCH_REG1_BASE_IDX] + prefix##SCRATCH_REG3; \ 15299951878SShiwu Zhang uint32_t grbm_cntl = adev->reg_offset[GC_HWIP][inst][prefix##GRBM_GFX_CNTL_BASE_IDX] + prefix##GRBM_GFX_CNTL; \ 15399951878SShiwu Zhang uint32_t grbm_idx = adev->reg_offset[GC_HWIP][inst][prefix##GRBM_GFX_INDEX_BASE_IDX] + prefix##GRBM_GFX_INDEX; \ 15422616eb5SDennis Li if (target_reg == grbm_cntl) \ 15522616eb5SDennis Li WREG32(r2, value); \ 15622616eb5SDennis Li else if (target_reg == grbm_idx) \ 15722616eb5SDennis Li WREG32(r3, value); \ 15822616eb5SDennis Li WREG32(target_reg, value); \ 15922616eb5SDennis Li } else { \ 16022616eb5SDennis Li WREG32(target_reg, value); \ 16122616eb5SDennis Li } \ 16222616eb5SDennis Li } while (0) 16322616eb5SDennis Li 1645e025531SPeng Ju Zhou #define RREG32_SOC15_RLC(ip, inst, reg) \ 165a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, AMDGPU_REGS_RLC, ip##_HWIP) 1665e025531SPeng Ju Zhou 1676b1ff3ddSTrigger Huang #define WREG32_SOC15_RLC(ip, inst, reg, value) \ 1686b1ff3ddSTrigger Huang do { \ 16999951878SShiwu Zhang uint32_t target_reg = adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg;\ 170a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(target_reg, value, AMDGPU_REGS_RLC, ip##_HWIP); \ 1716b1ff3ddSTrigger Huang } while (0) 1726b1ff3ddSTrigger Huang 17388f8575bSDennis Li #define WREG32_SOC15_RLC_EX(prefix, ip, inst, reg, value) \ 17488f8575bSDennis Li do { \ 17599951878SShiwu Zhang uint32_t target_reg = adev->reg_offset[GC_HWIP][inst][reg##_BASE_IDX] + reg;\ 17688f8575bSDennis Li WREG32_RLC_EX(prefix, target_reg, value); \ 17788f8575bSDennis Li } while (0) 17888f8575bSDennis Li 1796b1ff3ddSTrigger Huang #define WREG32_FIELD15_RLC(ip, idx, reg, field, val) \ 180a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg), \ 181a5504e9aSPeng Ju Zhou (__RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ 182a5504e9aSPeng Ju Zhou AMDGPU_REGS_RLC, ip##_HWIP) & \ 183a5504e9aSPeng Ju Zhou ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field), \ 184a5504e9aSPeng Ju Zhou AMDGPU_REGS_RLC, ip##_HWIP) 1856b1ff3ddSTrigger Huang 1866b1ff3ddSTrigger Huang #define WREG32_SOC15_OFFSET_RLC(ip, inst, reg, offset, value) \ 187a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, value, AMDGPU_REGS_RLC, ip##_HWIP) 1886b1ff3ddSTrigger Huang 1895e025531SPeng Ju Zhou #define RREG32_SOC15_OFFSET_RLC(ip, inst, reg, offset) \ 190a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, AMDGPU_REGS_RLC, ip##_HWIP) 1915e025531SPeng Ju Zhou 1922fa480d3SLe Ma /* inst equals to ext for some IPs */ 1932fa480d3SLe Ma #define RREG32_SOC15_EXT(ip, inst, reg, ext) \ 1942fa480d3SLe Ma RREG32_PCIE_EXT((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) * 4 \ 1952fa480d3SLe Ma + adev->asic_funcs->encode_ext_smn_addressing(ext)) \ 1962fa480d3SLe Ma 1972fa480d3SLe Ma #define WREG32_SOC15_EXT(ip, inst, reg, ext, value) \ 1982fa480d3SLe Ma WREG32_PCIE_EXT((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) * 4 \ 1992fa480d3SLe Ma + adev->asic_funcs->encode_ext_smn_addressing(ext), \ 2002fa480d3SLe Ma value) \ 2012fa480d3SLe Ma 2028e3153baSKen Wang #endif 203