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) \ 74a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, 0, ip##_HWIP) 75496828e7STom St Denis 76b1bb8c01STom St Denis #define WREG32_SOC15(ip, inst, reg, value) \ 77a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), \ 78a5504e9aSPeng Ju Zhou value, 0, ip##_HWIP) 79a5504e9aSPeng Ju Zhou 80a5504e9aSPeng Ju Zhou #define WREG32_SOC15_IP(ip, reg, value) \ 81a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(reg, value, 0, ip##_HWIP) 82b1bb8c01STom St Denis 830da6f6e5SVictor Skvortsov #define WREG32_SOC15_IP_NO_KIQ(ip, reg, value) \ 840da6f6e5SVictor Skvortsov __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_NO_KIQ, ip##_HWIP) 850da6f6e5SVictor Skvortsov 86c708535eSShaoyun Liu #define WREG32_SOC15_NO_KIQ(ip, inst, reg, value) \ 87a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \ 88a5504e9aSPeng Ju Zhou value, AMDGPU_REGS_NO_KIQ, ip##_HWIP) 89c708535eSShaoyun Liu 90496828e7STom St Denis #define WREG32_SOC15_OFFSET(ip, inst, reg, offset, value) \ 91a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, \ 92a5504e9aSPeng Ju Zhou value, 0, ip##_HWIP) 93496828e7STom St Denis 94450da2efSJames Zhu #define SOC15_WAIT_ON_RREG(ip, inst, reg, expected_value, mask) \ 9581283feeSJames Zhu amdgpu_device_wait_on_rreg(adev, inst, \ 9681283feeSJames Zhu (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + (reg)), \ 9781283feeSJames Zhu #reg, expected_value, mask) 9881283feeSJames Zhu 9981283feeSJames Zhu #define SOC15_WAIT_ON_RREG_OFFSET(ip, inst, reg, offset, expected_value, mask) \ 10081283feeSJames Zhu amdgpu_device_wait_on_rreg(adev, inst, \ 10181283feeSJames Zhu (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + (reg) + (offset)), \ 10281283feeSJames Zhu #reg, expected_value, mask) 103ac06b4cfSRex Zhu 1046b1ff3ddSTrigger Huang #define WREG32_RLC(reg, value) \ 105a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_RLC, GC_HWIP) 1066b1ff3ddSTrigger Huang 10788f8575bSDennis Li #define WREG32_RLC_EX(prefix, reg, value) \ 10888f8575bSDennis Li do { \ 10988f8575bSDennis Li if (amdgpu_sriov_fullaccess(adev)) { \ 11088f8575bSDennis Li uint32_t i = 0; \ 11188f8575bSDennis Li uint32_t retries = 50000; \ 11288f8575bSDennis Li uint32_t r0 = adev->reg_offset[GC_HWIP][0][prefix##SCRATCH_REG0_BASE_IDX] + prefix##SCRATCH_REG0; \ 11388f8575bSDennis Li uint32_t r1 = adev->reg_offset[GC_HWIP][0][prefix##SCRATCH_REG1_BASE_IDX] + prefix##SCRATCH_REG1; \ 11488f8575bSDennis Li uint32_t spare_int = adev->reg_offset[GC_HWIP][0][prefix##RLC_SPARE_INT_BASE_IDX] + prefix##RLC_SPARE_INT; \ 11588f8575bSDennis Li WREG32(r0, value); \ 11688f8575bSDennis Li WREG32(r1, (reg | 0x80000000)); \ 11788f8575bSDennis Li WREG32(spare_int, 0x1); \ 11888f8575bSDennis Li for (i = 0; i < retries; i++) { \ 11988f8575bSDennis Li u32 tmp = RREG32(r1); \ 12088f8575bSDennis Li if (!(tmp & 0x80000000)) \ 12188f8575bSDennis Li break; \ 12288f8575bSDennis Li udelay(10); \ 12388f8575bSDennis Li } \ 12488f8575bSDennis Li if (i >= retries) \ 12588f8575bSDennis Li pr_err("timeout: rlcg program reg:0x%05x failed !\n", reg); \ 12688f8575bSDennis Li } else { \ 12788f8575bSDennis Li WREG32(reg, value); \ 12888f8575bSDennis Li } \ 12988f8575bSDennis Li } while (0) 13088f8575bSDennis Li 131a5504e9aSPeng Ju Zhou /* shadow the registers in the callback function */ 1326b1ff3ddSTrigger Huang #define WREG32_SOC15_RLC_SHADOW(ip, inst, reg, value) \ 133a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value, AMDGPU_REGS_RLC, GC_HWIP) 1345e025531SPeng Ju Zhou 135a5504e9aSPeng Ju Zhou /* for GC only */ 1365e025531SPeng Ju Zhou #define RREG32_RLC(reg) \ 137a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(reg, AMDGPU_REGS_RLC, GC_HWIP) 1385e025531SPeng Ju Zhou 139a5504e9aSPeng Ju Zhou #define WREG32_RLC_NO_KIQ(reg, value, hwip) \ 140a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_NO_KIQ | AMDGPU_REGS_RLC, hwip) 1416b1ff3ddSTrigger Huang 142a5504e9aSPeng Ju Zhou #define RREG32_RLC_NO_KIQ(reg, hwip) \ 143a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(reg, AMDGPU_REGS_NO_KIQ | AMDGPU_REGS_RLC, hwip) 1445e025531SPeng Ju Zhou 14522616eb5SDennis Li #define WREG32_SOC15_RLC_SHADOW_EX(prefix, ip, inst, reg, value) \ 14622616eb5SDennis Li do { \ 14722616eb5SDennis Li uint32_t target_reg = adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg;\ 14822616eb5SDennis Li if (amdgpu_sriov_fullaccess(adev)) { \ 14999951878SShiwu Zhang uint32_t r2 = adev->reg_offset[GC_HWIP][inst][prefix##SCRATCH_REG1_BASE_IDX] + prefix##SCRATCH_REG2; \ 15099951878SShiwu Zhang uint32_t r3 = adev->reg_offset[GC_HWIP][inst][prefix##SCRATCH_REG1_BASE_IDX] + prefix##SCRATCH_REG3; \ 15199951878SShiwu Zhang uint32_t grbm_cntl = adev->reg_offset[GC_HWIP][inst][prefix##GRBM_GFX_CNTL_BASE_IDX] + prefix##GRBM_GFX_CNTL; \ 15299951878SShiwu Zhang uint32_t grbm_idx = adev->reg_offset[GC_HWIP][inst][prefix##GRBM_GFX_INDEX_BASE_IDX] + prefix##GRBM_GFX_INDEX; \ 15322616eb5SDennis Li if (target_reg == grbm_cntl) \ 15422616eb5SDennis Li WREG32(r2, value); \ 15522616eb5SDennis Li else if (target_reg == grbm_idx) \ 15622616eb5SDennis Li WREG32(r3, value); \ 15722616eb5SDennis Li WREG32(target_reg, value); \ 15822616eb5SDennis Li } else { \ 15922616eb5SDennis Li WREG32(target_reg, value); \ 16022616eb5SDennis Li } \ 16122616eb5SDennis Li } while (0) 16222616eb5SDennis Li 1635e025531SPeng Ju Zhou #define RREG32_SOC15_RLC(ip, inst, reg) \ 164a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, AMDGPU_REGS_RLC, ip##_HWIP) 1655e025531SPeng Ju Zhou 1666b1ff3ddSTrigger Huang #define WREG32_SOC15_RLC(ip, inst, reg, value) \ 1676b1ff3ddSTrigger Huang do { \ 16899951878SShiwu Zhang uint32_t target_reg = adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg;\ 169a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__(target_reg, value, AMDGPU_REGS_RLC, ip##_HWIP); \ 1706b1ff3ddSTrigger Huang } while (0) 1716b1ff3ddSTrigger Huang 17288f8575bSDennis Li #define WREG32_SOC15_RLC_EX(prefix, ip, inst, reg, value) \ 17388f8575bSDennis Li do { \ 17499951878SShiwu Zhang uint32_t target_reg = adev->reg_offset[GC_HWIP][inst][reg##_BASE_IDX] + reg;\ 17588f8575bSDennis Li WREG32_RLC_EX(prefix, target_reg, value); \ 17688f8575bSDennis Li } while (0) 17788f8575bSDennis Li 1786b1ff3ddSTrigger Huang #define WREG32_FIELD15_RLC(ip, idx, reg, field, val) \ 179a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg), \ 180a5504e9aSPeng Ju Zhou (__RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ 181a5504e9aSPeng Ju Zhou AMDGPU_REGS_RLC, ip##_HWIP) & \ 182a5504e9aSPeng Ju Zhou ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field), \ 183a5504e9aSPeng Ju Zhou AMDGPU_REGS_RLC, ip##_HWIP) 1846b1ff3ddSTrigger Huang 1856b1ff3ddSTrigger Huang #define WREG32_SOC15_OFFSET_RLC(ip, inst, reg, offset, value) \ 186a5504e9aSPeng Ju Zhou __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, value, AMDGPU_REGS_RLC, ip##_HWIP) 1876b1ff3ddSTrigger Huang 1885e025531SPeng Ju Zhou #define RREG32_SOC15_OFFSET_RLC(ip, inst, reg, offset) \ 189a5504e9aSPeng Ju Zhou __RREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, AMDGPU_REGS_RLC, ip##_HWIP) 1905e025531SPeng Ju Zhou 191*2fa480d3SLe Ma /* inst equals to ext for some IPs */ 192*2fa480d3SLe Ma #define RREG32_SOC15_EXT(ip, inst, reg, ext) \ 193*2fa480d3SLe Ma RREG32_PCIE_EXT((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) * 4 \ 194*2fa480d3SLe Ma + adev->asic_funcs->encode_ext_smn_addressing(ext)) \ 195*2fa480d3SLe Ma 196*2fa480d3SLe Ma #define WREG32_SOC15_EXT(ip, inst, reg, ext, value) \ 197*2fa480d3SLe Ma WREG32_PCIE_EXT((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) * 4 \ 198*2fa480d3SLe Ma + adev->asic_funcs->encode_ext_smn_addressing(ext), \ 199*2fa480d3SLe Ma value) \ 200*2fa480d3SLe Ma 2018e3153baSKen Wang #endif 202