1 1.1 riastrad /* $NetBSD: soc15_common.h,v 1.2 2021/12/18 23:44:59 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 __SOC15_COMMON_H__ 27 1.1 riastrad #define __SOC15_COMMON_H__ 28 1.1 riastrad 29 1.1 riastrad /* Register Access Macros */ 30 1.1 riastrad #define SOC15_REG_OFFSET(ip, inst, reg) (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) 31 1.1 riastrad 32 1.1 riastrad #define WREG32_FIELD15(ip, idx, reg, field, val) \ 33 1.1 riastrad WREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ 34 1.1 riastrad (RREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg) \ 35 1.1 riastrad & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 36 1.1 riastrad 37 1.1 riastrad #define RREG32_SOC15(ip, inst, reg) \ 38 1.1 riastrad RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) 39 1.1 riastrad 40 1.1 riastrad #define RREG32_SOC15_OFFSET(ip, inst, reg, offset) \ 41 1.1 riastrad RREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset) 42 1.1 riastrad 43 1.1 riastrad #define WREG32_SOC15(ip, inst, reg, value) \ 44 1.1 riastrad WREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value) 45 1.1 riastrad 46 1.1 riastrad #define WREG32_SOC15_NO_KIQ(ip, inst, reg, value) \ 47 1.1 riastrad WREG32_NO_KIQ((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value) 48 1.1 riastrad 49 1.1 riastrad #define WREG32_SOC15_OFFSET(ip, inst, reg, offset, value) \ 50 1.1 riastrad WREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, value) 51 1.1 riastrad 52 1.1 riastrad #define SOC15_WAIT_ON_RREG(ip, inst, reg, expected_value, mask, ret) \ 53 1.1 riastrad do { \ 54 1.1 riastrad uint32_t old_ = 0; \ 55 1.1 riastrad uint32_t tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \ 56 1.1 riastrad uint32_t loop = adev->usec_timeout; \ 57 1.1 riastrad ret = 0; \ 58 1.1 riastrad while ((tmp_ & (mask)) != (expected_value)) { \ 59 1.1 riastrad if (old_ != tmp_) { \ 60 1.1 riastrad loop = adev->usec_timeout; \ 61 1.1 riastrad old_ = tmp_; \ 62 1.1 riastrad } else \ 63 1.1 riastrad udelay(1); \ 64 1.1 riastrad tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \ 65 1.1 riastrad loop--; \ 66 1.1 riastrad if (!loop) { \ 67 1.1 riastrad DRM_WARN("Register(%d) [%s] failed to reach value 0x%08x != 0x%08x\n", \ 68 1.1 riastrad inst, #reg, (unsigned)expected_value, (unsigned)(tmp_ & (mask))); \ 69 1.1 riastrad ret = -ETIMEDOUT; \ 70 1.1 riastrad break; \ 71 1.1 riastrad } \ 72 1.1 riastrad } \ 73 1.1 riastrad } while (0) 74 1.1 riastrad 75 1.1 riastrad #define AMDGPU_VIRT_SUPPORT_RLC_PRG_REG(a) (amdgpu_sriov_vf((a)) && !amdgpu_sriov_runtime((a))) 76 1.1 riastrad #define WREG32_RLC(reg, value) \ 77 1.1 riastrad do { \ 78 1.1 riastrad if (AMDGPU_VIRT_SUPPORT_RLC_PRG_REG(adev)) { \ 79 1.1 riastrad uint32_t i = 0; \ 80 1.1 riastrad uint32_t retries = 50000; \ 81 1.1 riastrad uint32_t r0 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0; \ 82 1.1 riastrad uint32_t r1 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1; \ 83 1.1 riastrad uint32_t spare_int = adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT; \ 84 1.1 riastrad WREG32(r0, value); \ 85 1.1 riastrad WREG32(r1, (reg | 0x80000000)); \ 86 1.1 riastrad WREG32(spare_int, 0x1); \ 87 1.1 riastrad for (i = 0; i < retries; i++) { \ 88 1.1 riastrad u32 tmp = RREG32(r1); \ 89 1.1 riastrad if (!(tmp & 0x80000000)) \ 90 1.1 riastrad break; \ 91 1.1 riastrad udelay(10); \ 92 1.1 riastrad } \ 93 1.1 riastrad if (i >= retries) \ 94 1.1 riastrad pr_err("timeout: rlcg program reg:0x%05x failed !\n", reg); \ 95 1.1 riastrad } else { \ 96 1.1 riastrad WREG32(reg, value); \ 97 1.1 riastrad } \ 98 1.1 riastrad } while (0) 99 1.1 riastrad 100 1.1 riastrad #define WREG32_SOC15_RLC_SHADOW(ip, inst, reg, value) \ 101 1.1 riastrad do { \ 102 1.1 riastrad uint32_t target_reg = adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg;\ 103 1.1 riastrad if (AMDGPU_VIRT_SUPPORT_RLC_PRG_REG(adev)) { \ 104 1.1 riastrad uint32_t r2 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2; \ 105 1.1 riastrad uint32_t r3 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3; \ 106 1.1 riastrad uint32_t grbm_cntl = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_CNTL_BASE_IDX] + mmGRBM_GFX_CNTL; \ 107 1.1 riastrad uint32_t grbm_idx = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_INDEX_BASE_IDX] + mmGRBM_GFX_INDEX; \ 108 1.1 riastrad if (target_reg == grbm_cntl) \ 109 1.1 riastrad WREG32(r2, value); \ 110 1.1 riastrad else if (target_reg == grbm_idx) \ 111 1.1 riastrad WREG32(r3, value); \ 112 1.1 riastrad WREG32(target_reg, value); \ 113 1.1 riastrad } else { \ 114 1.1 riastrad WREG32(target_reg, value); \ 115 1.1 riastrad } \ 116 1.1 riastrad } while (0) 117 1.1 riastrad 118 1.1 riastrad #define WREG32_SOC15_RLC(ip, inst, reg, value) \ 119 1.1 riastrad do { \ 120 1.1 riastrad uint32_t target_reg = adev->reg_offset[GC_HWIP][0][reg##_BASE_IDX] + reg;\ 121 1.1 riastrad WREG32_RLC(target_reg, value); \ 122 1.1 riastrad } while (0) 123 1.1 riastrad 124 1.1 riastrad #define WREG32_FIELD15_RLC(ip, idx, reg, field, val) \ 125 1.1 riastrad WREG32_RLC((adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg), \ 126 1.1 riastrad (RREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg) \ 127 1.1 riastrad & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 128 1.1 riastrad 129 1.1 riastrad #define WREG32_SOC15_OFFSET_RLC(ip, inst, reg, offset, value) \ 130 1.1 riastrad WREG32_RLC(((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset), value) 131 1.1 riastrad 132 1.1 riastrad #endif 133