Commit fcd90fee authored by Evan Quan's avatar Evan Quan Committed by Alex Deucher

drm/amd/powerplay: minor fixes around SW SMU power and fan setting

Add checking for possible invalid input and null pointer. And
drop redundant code.
Signed-off-by: default avatarEvan Quan <evan.quan@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 1c425915
...@@ -1616,20 +1616,16 @@ static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev, ...@@ -1616,20 +1616,16 @@ static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
(adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
return -EINVAL; return -EINVAL;
if (is_support_sw_smu(adev)) { err = kstrtoint(buf, 10, &value);
err = kstrtoint(buf, 10, &value); if (err)
if (err) return err;
return err;
if (is_support_sw_smu(adev)) {
smu_set_fan_control_mode(&adev->smu, value); smu_set_fan_control_mode(&adev->smu, value);
} else { } else {
if (!adev->powerplay.pp_funcs->set_fan_control_mode) if (!adev->powerplay.pp_funcs->set_fan_control_mode)
return -EINVAL; return -EINVAL;
err = kstrtoint(buf, 10, &value);
if (err)
return err;
amdgpu_dpm_set_fan_control_mode(adev, value); amdgpu_dpm_set_fan_control_mode(adev, value);
} }
...@@ -2049,16 +2045,18 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev, ...@@ -2049,16 +2045,18 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
return err; return err;
value = value / 1000000; /* convert to Watt */ value = value / 1000000; /* convert to Watt */
if (is_support_sw_smu(adev)) { if (is_support_sw_smu(adev)) {
adev->smu.funcs->set_power_limit(&adev->smu, value); err = smu_set_power_limit(&adev->smu, value);
} else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit) { } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit) {
err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value); err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
if (err)
return err;
} else { } else {
return -EINVAL; err = -EINVAL;
} }
if (err)
return err;
return count; return count;
} }
......
...@@ -1100,6 +1100,8 @@ static int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n) ...@@ -1100,6 +1100,8 @@ static int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n)
max_power_limit *= (100 + smu->smu_table.TDPODLimit); max_power_limit *= (100 + smu->smu_table.TDPODLimit);
max_power_limit /= 100; max_power_limit /= 100;
} }
if (n > max_power_limit)
return -EINVAL;
if (smu_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) if (smu_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT))
ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n); ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n);
...@@ -1421,17 +1423,17 @@ smu_v11_0_get_fan_control_mode(struct smu_context *smu) ...@@ -1421,17 +1423,17 @@ smu_v11_0_get_fan_control_mode(struct smu_context *smu)
} }
static int static int
smu_v11_0_smc_fan_control(struct smu_context *smu, bool start) smu_v11_0_auto_fan_control(struct smu_context *smu, bool auto_fan_control)
{ {
int ret = 0; int ret = 0;
if (smu_feature_is_supported(smu, SMU_FEATURE_FAN_CONTROL_BIT)) if (smu_feature_is_supported(smu, SMU_FEATURE_FAN_CONTROL_BIT))
return 0; return 0;
ret = smu_feature_set_enabled(smu, SMU_FEATURE_FAN_CONTROL_BIT, start); ret = smu_feature_set_enabled(smu, SMU_FEATURE_FAN_CONTROL_BIT, auto_fan_control);
if (ret) if (ret)
pr_err("[%s]%s smc FAN CONTROL feature failed!", pr_err("[%s]%s smc FAN CONTROL feature failed!",
__func__, (start ? "Start" : "Stop")); __func__, (auto_fan_control ? "Start" : "Stop"));
return ret; return ret;
} }
...@@ -1455,16 +1457,15 @@ static int ...@@ -1455,16 +1457,15 @@ static int
smu_v11_0_set_fan_speed_percent(struct smu_context *smu, uint32_t speed) smu_v11_0_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)
{ {
struct amdgpu_device *adev = smu->adev; struct amdgpu_device *adev = smu->adev;
uint32_t duty100; uint32_t duty100, duty;
uint32_t duty;
uint64_t tmp64; uint64_t tmp64;
bool stop = 0;
if (speed > 100) if (speed > 100)
speed = 100; speed = 100;
if (smu_v11_0_smc_fan_control(smu, stop)) if (smu_v11_0_auto_fan_control(smu, 0))
return -EINVAL; return -EINVAL;
duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1), duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
CG_FDO_CTRL1, FMAX_DUTY100); CG_FDO_CTRL1, FMAX_DUTY100);
if (!duty100) if (!duty100)
...@@ -1486,18 +1487,16 @@ smu_v11_0_set_fan_control_mode(struct smu_context *smu, ...@@ -1486,18 +1487,16 @@ smu_v11_0_set_fan_control_mode(struct smu_context *smu,
uint32_t mode) uint32_t mode)
{ {
int ret = 0; int ret = 0;
bool start = 1;
bool stop = 0;
switch (mode) { switch (mode) {
case AMD_FAN_CTRL_NONE: case AMD_FAN_CTRL_NONE:
ret = smu_v11_0_set_fan_speed_percent(smu, 100); ret = smu_v11_0_set_fan_speed_percent(smu, 100);
break; break;
case AMD_FAN_CTRL_MANUAL: case AMD_FAN_CTRL_MANUAL:
ret = smu_v11_0_smc_fan_control(smu, stop); ret = smu_v11_0_auto_fan_control(smu, 0);
break; break;
case AMD_FAN_CTRL_AUTO: case AMD_FAN_CTRL_AUTO:
ret = smu_v11_0_smc_fan_control(smu, start); ret = smu_v11_0_auto_fan_control(smu, 1);
break; break;
default: default:
break; break;
...@@ -1517,13 +1516,12 @@ static int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu, ...@@ -1517,13 +1516,12 @@ static int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
struct amdgpu_device *adev = smu->adev; struct amdgpu_device *adev = smu->adev;
int ret; int ret;
uint32_t tach_period, crystal_clock_freq; uint32_t tach_period, crystal_clock_freq;
bool stop = 0;
if (!speed) if (!speed)
return -EINVAL; return -EINVAL;
mutex_lock(&(smu->mutex)); mutex_lock(&(smu->mutex));
ret = smu_v11_0_smc_fan_control(smu, stop); ret = smu_v11_0_auto_fan_control(smu, 0);
if (ret) if (ret)
goto set_fan_speed_rpm_failed; goto set_fan_speed_rpm_failed;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment