2 * Copyright 2017 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "vega12_thermal.h"
25 #include "vega12_hwmgr.h"
26 #include "vega12_smumgr.h"
27 #include "vega12_ppsmc.h"
28 #include "vega12_inc.h"
29 #include "soc15_common.h"
32 static int vega12_get_current_rpm(struct pp_hwmgr *hwmgr, uint32_t *current_rpm)
34 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr,
35 PPSMC_MSG_GetCurrentRpm,
37 "Attempt to get current RPM from SMC Failed!",
43 int vega12_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
44 struct phm_fan_speed_info *fan_speed_info)
46 memset(fan_speed_info, 0, sizeof(*fan_speed_info));
47 fan_speed_info->supports_percent_read = false;
48 fan_speed_info->supports_percent_write = false;
49 fan_speed_info->supports_rpm_read = true;
50 fan_speed_info->supports_rpm_write = true;
55 int vega12_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *speed)
59 return vega12_get_current_rpm(hwmgr, speed);
63 * @fn vega12_enable_fan_control_feature
64 * @brief Enables the SMC Fan Control Feature.
66 * @param hwmgr - the address of the powerplay hardware manager.
67 * @return 0 on success. -1 otherwise.
69 static int vega12_enable_fan_control_feature(struct pp_hwmgr *hwmgr)
72 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
74 if (data->smu_features[GNLD_FAN_CONTROL].supported) {
75 PP_ASSERT_WITH_CODE(!vega12_enable_smc_features(
77 data->smu_features[GNLD_FAN_CONTROL].
79 "Attempt to Enable FAN CONTROL feature Failed!",
81 data->smu_features[GNLD_FAN_CONTROL].enabled = true;
87 static int vega12_disable_fan_control_feature(struct pp_hwmgr *hwmgr)
90 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
92 if (data->smu_features[GNLD_FAN_CONTROL].supported) {
93 PP_ASSERT_WITH_CODE(!vega12_enable_smc_features(
95 data->smu_features[GNLD_FAN_CONTROL].
97 "Attempt to Enable FAN CONTROL feature Failed!",
99 data->smu_features[GNLD_FAN_CONTROL].enabled = false;
105 int vega12_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr)
107 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
109 if (data->smu_features[GNLD_FAN_CONTROL].supported)
111 !vega12_enable_fan_control_feature(hwmgr),
112 "Attempt to Enable SMC FAN CONTROL Feature Failed!",
119 int vega12_fan_ctrl_stop_smc_fan_control(struct pp_hwmgr *hwmgr)
121 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
123 if (data->smu_features[GNLD_FAN_CONTROL].supported)
124 PP_ASSERT_WITH_CODE(!vega12_disable_fan_control_feature(hwmgr),
125 "Attempt to Disable SMC FAN CONTROL Feature Failed!",
132 * Reset Fan Speed to default.
133 * @param hwmgr the address of the powerplay hardware manager.
134 * @exception Always succeeds.
136 int vega12_fan_ctrl_reset_fan_speed_to_default(struct pp_hwmgr *hwmgr)
138 return vega12_fan_ctrl_start_smc_fan_control(hwmgr);
142 * Reads the remote temperature from the SIslands thermal controller.
144 * @param hwmgr The address of the hardware manager.
146 int vega12_thermal_get_temperature(struct pp_hwmgr *hwmgr)
148 struct amdgpu_device *adev = hwmgr->adev;
151 temp = RREG32_SOC15(THM, 0, mmCG_MULT_THERMAL_STATUS);
153 temp = (temp & CG_MULT_THERMAL_STATUS__CTF_TEMP_MASK) >>
154 CG_MULT_THERMAL_STATUS__CTF_TEMP__SHIFT;
158 temp *= PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
163 * Set the requested temperature range for high and low alert signals
165 * @param hwmgr The address of the hardware manager.
166 * @param range Temperature range to be programmed for
167 * high and low alert signals
168 * @exception PP_Result_BadInput if the input data is not valid.
170 static int vega12_thermal_set_temperature_range(struct pp_hwmgr *hwmgr,
171 struct PP_TemperatureRange *range)
173 struct phm_ppt_v3_information *pptable_information =
174 (struct phm_ppt_v3_information *)hwmgr->pptable;
175 struct amdgpu_device *adev = hwmgr->adev;
176 int low = VEGA12_THERMAL_MINIMUM_ALERT_TEMP;
177 int high = VEGA12_THERMAL_MAXIMUM_ALERT_TEMP;
180 /* compare them in unit celsius degree */
181 if (low < range->min / PP_TEMPERATURE_UNITS_PER_CENTIGRADES)
182 low = range->min / PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
183 if (high > pptable_information->us_software_shutdown_temp)
184 high = pptable_information->us_software_shutdown_temp;
189 val = RREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL);
191 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, MAX_IH_CREDIT, 5);
192 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_IH_HW_ENA, 1);
193 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTH, high);
194 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, low);
195 val = val & (~THM_THERMAL_INT_CTRL__THERM_TRIGGER_MASK_MASK);
197 WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL, val);
203 * Enable thermal alerts on the RV770 thermal controller.
205 * @param hwmgr The address of the hardware manager.
207 static int vega12_thermal_enable_alert(struct pp_hwmgr *hwmgr)
209 struct amdgpu_device *adev = hwmgr->adev;
212 val |= (1 << THM_THERMAL_INT_ENA__THERM_INTH_CLR__SHIFT);
213 val |= (1 << THM_THERMAL_INT_ENA__THERM_INTL_CLR__SHIFT);
214 val |= (1 << THM_THERMAL_INT_ENA__THERM_TRIGGER_CLR__SHIFT);
216 WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_ENA, val);
222 * Disable thermal alerts on the RV770 thermal controller.
223 * @param hwmgr The address of the hardware manager.
225 int vega12_thermal_disable_alert(struct pp_hwmgr *hwmgr)
227 struct amdgpu_device *adev = hwmgr->adev;
229 WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_ENA, 0);
235 * Uninitialize the thermal controller.
236 * Currently just disables alerts.
237 * @param hwmgr The address of the hardware manager.
239 int vega12_thermal_stop_thermal_controller(struct pp_hwmgr *hwmgr)
241 int result = vega12_thermal_disable_alert(hwmgr);
247 * Set up the fan table to control the fan using the SMC.
248 * @param hwmgr the address of the powerplay hardware manager.
249 * @param pInput the pointer to input data
250 * @param pOutput the pointer to output data
251 * @param pStorage the pointer to temporary storage
252 * @param Result the last failure code
253 * @return result from set temperature range routine
255 static int vega12_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
258 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
259 PPTable_t *table = &(data->smc_state_table.pp_table);
261 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
262 PPSMC_MSG_SetFanTemperatureTarget,
263 (uint32_t)table->FanTargetTemperature,
270 * Start the fan control on the SMC.
271 * @param hwmgr the address of the powerplay hardware manager.
272 * @param pInput the pointer to input data
273 * @param pOutput the pointer to output data
274 * @param pStorage the pointer to temporary storage
275 * @param Result the last failure code
276 * @return result from set temperature range routine
278 static int vega12_thermal_start_smc_fan_control(struct pp_hwmgr *hwmgr)
280 /* If the fantable setup has failed we could have disabled
281 * PHM_PlatformCaps_MicrocodeFanControl even after
282 * this function was included in the table.
283 * Make sure that we still think controlling the fan is OK.
285 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
286 vega12_fan_ctrl_start_smc_fan_control(hwmgr);
292 int vega12_start_thermal_controller(struct pp_hwmgr *hwmgr,
293 struct PP_TemperatureRange *range)
300 ret = vega12_thermal_set_temperature_range(hwmgr, range);
304 vega12_thermal_enable_alert(hwmgr);
305 /* We should restrict performance levels to low before we halt the SMC.
306 * On the other hand we are still in boot state when we do this
307 * so it would be pointless.
308 * If this assumption changes we have to revisit this table.
310 ret = vega12_thermal_setup_fan_table(hwmgr);
314 vega12_thermal_start_smc_fan_control(hwmgr);