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 27b1bb8c01STom St Denis /* Register Access Macros */ 28cd29253fSShaoyun Liu #define SOC15_REG_OFFSET(ip, inst, reg) (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) 298e3153baSKen Wang 30b1bb8c01STom St Denis #define WREG32_FIELD15(ip, idx, reg, field, val) \ 31b466107eSShaoyun Liu WREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ 32b466107eSShaoyun Liu (RREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg) \ 33b466107eSShaoyun Liu & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 34b1bb8c01STom St Denis 35b1bb8c01STom St Denis #define RREG32_SOC15(ip, inst, reg) \ 36b466107eSShaoyun Liu RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) 37b1bb8c01STom St Denis 38496828e7STom St Denis #define RREG32_SOC15_OFFSET(ip, inst, reg, offset) \ 39b466107eSShaoyun Liu RREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset) 40496828e7STom St Denis 41b1bb8c01STom St Denis #define WREG32_SOC15(ip, inst, reg, value) \ 42b466107eSShaoyun Liu WREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value) 43b1bb8c01STom St Denis 44c708535eSShaoyun Liu #define WREG32_SOC15_NO_KIQ(ip, inst, reg, value) \ 45b466107eSShaoyun Liu WREG32_NO_KIQ((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value) 46c708535eSShaoyun Liu 47496828e7STom St Denis #define WREG32_SOC15_OFFSET(ip, inst, reg, offset, value) \ 48b466107eSShaoyun Liu WREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, value) 49496828e7STom St Denis 50*ac06b4cfSRex Zhu #define SOC15_WAIT_ON_RREG(ip, inst, reg, expected_value, mask, ret) \ 51*ac06b4cfSRex Zhu do { \ 52*ac06b4cfSRex Zhu uint32_t tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \ 53*ac06b4cfSRex Zhu uint32_t loop = adev->usec_timeout; \ 54*ac06b4cfSRex Zhu while ((tmp_ & (mask)) != (expected_value)) { \ 55*ac06b4cfSRex Zhu udelay(2); \ 56*ac06b4cfSRex Zhu tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \ 57*ac06b4cfSRex Zhu loop--; \ 58*ac06b4cfSRex Zhu if (!loop) { \ 59*ac06b4cfSRex Zhu ret = -ETIMEDOUT; \ 60*ac06b4cfSRex Zhu break; \ 61*ac06b4cfSRex Zhu } \ 62*ac06b4cfSRex Zhu } \ 63*ac06b4cfSRex Zhu } while (0) 64*ac06b4cfSRex Zhu 658e3153baSKen Wang #endif 668e3153baSKen Wang 678e3153baSKen Wang 68