1 1.1 riastrad /* $NetBSD: radeon_sumo_smc.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2012 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 #include <sys/cdefs.h> 27 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_sumo_smc.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $"); 28 1.1 riastrad 29 1.1 riastrad #include "radeon.h" 30 1.1 riastrad #include "sumod.h" 31 1.1 riastrad #include "sumo_dpm.h" 32 1.1 riastrad #include "ppsmc.h" 33 1.1 riastrad 34 1.1 riastrad #define SUMO_SMU_SERVICE_ROUTINE_PG_INIT 1 35 1.1 riastrad #define SUMO_SMU_SERVICE_ROUTINE_ALTVDDNB_NOTIFY 27 36 1.1 riastrad #define SUMO_SMU_SERVICE_ROUTINE_GFX_SRV_ID_20 20 37 1.1 riastrad 38 1.1 riastrad struct sumo_power_info *sumo_get_pi(struct radeon_device *rdev); 39 1.1 riastrad 40 1.1 riastrad static void sumo_send_msg_to_smu(struct radeon_device *rdev, u32 id) 41 1.1 riastrad { 42 1.1 riastrad u32 gfx_int_req; 43 1.1 riastrad int i; 44 1.1 riastrad 45 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 46 1.1 riastrad if (RREG32(GFX_INT_STATUS) & INT_DONE) 47 1.1 riastrad break; 48 1.1 riastrad udelay(1); 49 1.1 riastrad } 50 1.1 riastrad 51 1.1 riastrad gfx_int_req = SERV_INDEX(id) | INT_REQ; 52 1.1 riastrad WREG32(GFX_INT_REQ, gfx_int_req); 53 1.1 riastrad 54 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 55 1.1 riastrad if (RREG32(GFX_INT_REQ) & INT_REQ) 56 1.1 riastrad break; 57 1.1 riastrad udelay(1); 58 1.1 riastrad } 59 1.1 riastrad 60 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 61 1.1 riastrad if (RREG32(GFX_INT_STATUS) & INT_ACK) 62 1.1 riastrad break; 63 1.1 riastrad udelay(1); 64 1.1 riastrad } 65 1.1 riastrad 66 1.1 riastrad for (i = 0; i < rdev->usec_timeout; i++) { 67 1.1 riastrad if (RREG32(GFX_INT_STATUS) & INT_DONE) 68 1.1 riastrad break; 69 1.1 riastrad udelay(1); 70 1.1 riastrad } 71 1.1 riastrad 72 1.1 riastrad gfx_int_req &= ~INT_REQ; 73 1.1 riastrad WREG32(GFX_INT_REQ, gfx_int_req); 74 1.1 riastrad } 75 1.1 riastrad 76 1.1 riastrad void sumo_initialize_m3_arb(struct radeon_device *rdev) 77 1.1 riastrad { 78 1.1 riastrad struct sumo_power_info *pi = sumo_get_pi(rdev); 79 1.1 riastrad u32 i; 80 1.1 riastrad 81 1.1 riastrad if (!pi->enable_dynamic_m3_arbiter) 82 1.1 riastrad return; 83 1.1 riastrad 84 1.1 riastrad for (i = 0; i < NUMBER_OF_M3ARB_PARAM_SETS; i++) 85 1.1 riastrad WREG32_RCU(MCU_M3ARB_PARAMS + (i * 4), 86 1.1 riastrad pi->sys_info.csr_m3_arb_cntl_default[i]); 87 1.1 riastrad 88 1.1 riastrad for (; i < NUMBER_OF_M3ARB_PARAM_SETS * 2; i++) 89 1.1 riastrad WREG32_RCU(MCU_M3ARB_PARAMS + (i * 4), 90 1.1 riastrad pi->sys_info.csr_m3_arb_cntl_uvd[i % NUMBER_OF_M3ARB_PARAM_SETS]); 91 1.1 riastrad 92 1.1 riastrad for (; i < NUMBER_OF_M3ARB_PARAM_SETS * 3; i++) 93 1.1 riastrad WREG32_RCU(MCU_M3ARB_PARAMS + (i * 4), 94 1.1 riastrad pi->sys_info.csr_m3_arb_cntl_fs3d[i % NUMBER_OF_M3ARB_PARAM_SETS]); 95 1.1 riastrad } 96 1.1 riastrad 97 1.1 riastrad static bool sumo_is_alt_vddnb_supported(struct radeon_device *rdev) 98 1.1 riastrad { 99 1.1 riastrad struct sumo_power_info *pi = sumo_get_pi(rdev); 100 1.1 riastrad bool return_code = false; 101 1.1 riastrad 102 1.1 riastrad if (!pi->enable_alt_vddnb) 103 1.1 riastrad return return_code; 104 1.1 riastrad 105 1.1 riastrad if ((rdev->family == CHIP_SUMO) || (rdev->family == CHIP_SUMO2)) { 106 1.1 riastrad if (pi->fw_version >= 0x00010C00) 107 1.1 riastrad return_code = true; 108 1.1 riastrad } 109 1.1 riastrad 110 1.1 riastrad return return_code; 111 1.1 riastrad } 112 1.1 riastrad 113 1.1 riastrad void sumo_smu_notify_alt_vddnb_change(struct radeon_device *rdev, 114 1.1 riastrad bool powersaving, bool force_nbps1) 115 1.1 riastrad { 116 1.1 riastrad u32 param = 0; 117 1.1 riastrad 118 1.1 riastrad if (!sumo_is_alt_vddnb_supported(rdev)) 119 1.1 riastrad return; 120 1.1 riastrad 121 1.1 riastrad if (powersaving) 122 1.1 riastrad param |= 1; 123 1.1 riastrad 124 1.1 riastrad if (force_nbps1) 125 1.1 riastrad param |= 2; 126 1.1 riastrad 127 1.1 riastrad WREG32_RCU(RCU_ALTVDDNB_NOTIFY, param); 128 1.1 riastrad 129 1.1 riastrad sumo_send_msg_to_smu(rdev, SUMO_SMU_SERVICE_ROUTINE_ALTVDDNB_NOTIFY); 130 1.1 riastrad } 131 1.1 riastrad 132 1.1 riastrad void sumo_smu_pg_init(struct radeon_device *rdev) 133 1.1 riastrad { 134 1.1 riastrad sumo_send_msg_to_smu(rdev, SUMO_SMU_SERVICE_ROUTINE_PG_INIT); 135 1.1 riastrad } 136 1.1 riastrad 137 1.1 riastrad static u32 sumo_power_of_4(u32 unit) 138 1.1 riastrad { 139 1.1 riastrad u32 ret = 1; 140 1.1 riastrad u32 i; 141 1.1 riastrad 142 1.1 riastrad for (i = 0; i < unit; i++) 143 1.1 riastrad ret *= 4; 144 1.1 riastrad 145 1.1 riastrad return ret; 146 1.1 riastrad } 147 1.1 riastrad 148 1.1 riastrad void sumo_enable_boost_timer(struct radeon_device *rdev) 149 1.1 riastrad { 150 1.1 riastrad struct sumo_power_info *pi = sumo_get_pi(rdev); 151 1.1 riastrad u32 period, unit, timer_value; 152 1.1 riastrad u32 xclk = radeon_get_xclk(rdev); 153 1.1 riastrad 154 1.1 riastrad unit = (RREG32_RCU(RCU_LCLK_SCALING_CNTL) & LCLK_SCALING_TIMER_PRESCALER_MASK) 155 1.1 riastrad >> LCLK_SCALING_TIMER_PRESCALER_SHIFT; 156 1.1 riastrad 157 1.1 riastrad period = 100 * (xclk / 100 / sumo_power_of_4(unit)); 158 1.1 riastrad 159 1.1 riastrad timer_value = (period << 16) | (unit << 4); 160 1.1 riastrad 161 1.1 riastrad WREG32_RCU(RCU_GNB_PWR_REP_TIMER_CNTL, timer_value); 162 1.1 riastrad WREG32_RCU(RCU_BOOST_MARGIN, pi->sys_info.sclk_dpm_boost_margin); 163 1.1 riastrad WREG32_RCU(RCU_THROTTLE_MARGIN, pi->sys_info.sclk_dpm_throttle_margin); 164 1.1 riastrad WREG32_RCU(GNB_TDP_LIMIT, pi->sys_info.gnb_tdp_limit); 165 1.1 riastrad WREG32_RCU(RCU_SclkDpmTdpLimitPG, pi->sys_info.sclk_dpm_tdp_limit_pg); 166 1.1 riastrad 167 1.1 riastrad sumo_send_msg_to_smu(rdev, SUMO_SMU_SERVICE_ROUTINE_GFX_SRV_ID_20); 168 1.1 riastrad } 169 1.1 riastrad 170 1.1 riastrad void sumo_set_tdp_limit(struct radeon_device *rdev, u32 index, u32 tdp_limit) 171 1.1 riastrad { 172 1.1 riastrad u32 regoffset = 0; 173 1.1 riastrad u32 shift = 0; 174 1.1 riastrad u32 mask = 0xFFF; 175 1.1 riastrad u32 sclk_dpm_tdp_limit; 176 1.1 riastrad 177 1.1 riastrad switch (index) { 178 1.1 riastrad case 0: 179 1.1 riastrad regoffset = RCU_SclkDpmTdpLimit01; 180 1.1 riastrad shift = 16; 181 1.1 riastrad break; 182 1.1 riastrad case 1: 183 1.1 riastrad regoffset = RCU_SclkDpmTdpLimit01; 184 1.1 riastrad shift = 0; 185 1.1 riastrad break; 186 1.1 riastrad case 2: 187 1.1 riastrad regoffset = RCU_SclkDpmTdpLimit23; 188 1.1 riastrad shift = 16; 189 1.1 riastrad break; 190 1.1 riastrad case 3: 191 1.1 riastrad regoffset = RCU_SclkDpmTdpLimit23; 192 1.1 riastrad shift = 0; 193 1.1 riastrad break; 194 1.1 riastrad case 4: 195 1.1 riastrad regoffset = RCU_SclkDpmTdpLimit47; 196 1.1 riastrad shift = 16; 197 1.1 riastrad break; 198 1.1 riastrad case 7: 199 1.1 riastrad regoffset = RCU_SclkDpmTdpLimit47; 200 1.1 riastrad shift = 0; 201 1.1 riastrad break; 202 1.1 riastrad default: 203 1.1 riastrad break; 204 1.1 riastrad } 205 1.1 riastrad 206 1.1 riastrad sclk_dpm_tdp_limit = RREG32_RCU(regoffset); 207 1.1 riastrad sclk_dpm_tdp_limit &= ~(mask << shift); 208 1.1 riastrad sclk_dpm_tdp_limit |= (tdp_limit << shift); 209 1.1 riastrad WREG32_RCU(regoffset, sclk_dpm_tdp_limit); 210 1.1 riastrad } 211 1.1 riastrad 212 1.1 riastrad void sumo_boost_state_enable(struct radeon_device *rdev, bool enable) 213 1.1 riastrad { 214 1.1 riastrad u32 boost_disable = RREG32_RCU(RCU_GPU_BOOST_DISABLE); 215 1.1 riastrad 216 1.1 riastrad boost_disable &= 0xFFFFFFFE; 217 1.1 riastrad boost_disable |= (enable ? 0 : 1); 218 1.1 riastrad WREG32_RCU(RCU_GPU_BOOST_DISABLE, boost_disable); 219 1.1 riastrad } 220 1.1 riastrad 221 1.1 riastrad u32 sumo_get_running_fw_version(struct radeon_device *rdev) 222 1.1 riastrad { 223 1.1 riastrad return RREG32_RCU(RCU_FW_VERSION); 224 1.1 riastrad } 225 1.1 riastrad 226