drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
Subsystems (2)
PATCH 1/3 drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
The minRPM speed maybe equal to zero. so need to check input RPM not equal to 0, otherwise cause divide-by-zero driver crash.
--- drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c +1 -0
@@ -260,6 +260,7 @@ int smu7_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)if (hwmgr->thermal_controller.fanInfo.bNoFan || (hwmgr->thermal_controller.fanInfo. ucTachometerPulsesPerRevolution ==0 ) || + speed ==0 || (speed < hwmgr->thermal_controller.fanInfo.ulMinRPM) || (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM))return 0 ;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1537427667-23717-1-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org
PATCH 2/3 drm/amdgpu: Add fan RPM setting via sysfs
User can set fan's revolution per minute viafan1_input.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 28 +++++++++++++++++++++++++- drivers/gpu/drm/amd/include/kgd_pp_interface.h | 1 + drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 19 +++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +3 -0
@@ -278,6 +278,9 @@ enum amdgpu_pcie_gen {#define amdgpu_dpm_get_fan_speed_rpm (adev, s) \ ((adev)->powerplay.pp_funcs->get_fan_speed_rpm)((adev)->powerplay.pp_handle, (s)) +#define amdgpu_dpm_set_fan_speed_rpm (adev, s) \ + ((adev)->powerplay.pp_funcs->set_fan_speed_rpm)((adev)->powerplay.pp_handle, (s)) +#define amdgpu_dpm_get_sclk (adev, l) \ ((adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)))
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +27 -1
@@ -1187,6 +1187,32 @@ static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,return sprintf (buf,"%i\n" , speed); } +static ssize_t amdgpu_hwmon_set_fan1_input (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct amdgpu_device *adev =dev_get_drvdata (dev); +int err; +u32 value; + +/* Can't adjust fan when the card is off */ +if ((adev->flags &AMD_IS_PX ) && + (adev->ddev->switch_power_state !=DRM_SWITCH_POWER_ON )) +return -EINVAL ; + + err =kstrtou32 (buf,10 , &value); +if (err) +return err; + +if (adev->powerplay.pp_funcs->set_fan_speed_rpm) { + err =amdgpu_dpm_set_fan_speed_rpm (adev, value); +if (err) +return err; + } + +return count; +} +static ssize_t amdgpu_hwmon_show_vddgfx (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1419,7 +1445,7 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev, static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0); static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0); static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0); -static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0); +static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_input, amdgpu_hwmon_set_fan1_input, 0); static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0); static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0); static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
@@ -227,6 +227,7 @@ struct amd_pm_funcs {enum amd_dpm_forced_level (*get_performance_level)(void *handle);enum amd_pm_state_type (*get_current_power_state)(void *handle);int (*get_fan_speed_rpm)(void *handle,uint32_t *rpm); +int (*set_fan_speed_rpm)(void *handle,uint32_t rpm);int (*get_pp_num_states)(void *handle,struct pp_states_info *data);int (*get_pp_table)(void *handle,char **table);int (*set_pp_table)(void *handle,const char *buf,size_t size);
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +19 -0
@@ -586,6 +586,24 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)return ret; } +static int pp_dpm_set_fan_speed_rpm (void *handle,uint32_t rpm) +{ +struct pp_hwmgr *hwmgr = handle; +int ret =0 ; + +if (!hwmgr || !hwmgr->pm_en) +return -EINVAL ; + +if (hwmgr->hwmgr_func->set_fan_speed_rpm ==NULL ) { +pr_info ("%s was not implemented.\n" , __func__); +return 0 ; + } +mutex_lock (&hwmgr->smu_lock); + ret = hwmgr->hwmgr_func->set_fan_speed_rpm (hwmgr, rpm); +mutex_unlock (&hwmgr->smu_lock); +return ret; +} +static int pp_dpm_get_pp_num_states (void *handle,struct pp_states_info *data) {
@@ -1265,6 +1283,7 @@ static int pp_notify_smu_enable_pwe(void *handle) .set_fan_speed_percent = pp_dpm_set_fan_speed_percent, .get_fan_speed_percent = pp_dpm_get_fan_speed_percent, .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm, + .set_fan_speed_rpm = pp_dpm_set_fan_speed_rpm, .get_pp_num_states = pp_dpm_get_pp_num_states, .get_pp_table = pp_dpm_get_pp_table, .set_pp_table = pp_dpm_set_pp_table,
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amd/pp: Fix fan's RPM setting not work on VI/Vega10
In reply to a message not in the archiveset the target rpm value to wrong register.
--- drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c | 2 +- drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c +1 -1
@@ -273,7 +273,7 @@ int smu7_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed) tach_period =60 * crystal_clock_freq *10000 / (8 * speed);PHM_WRITE_VFPF_INDIRECT_FIELD (hwmgr->device,CGS_IND_REG__SMC , -CG_TACH_STATUS ,TACH_PERIOD , tach_period); +CG_TACH_CTRL ,TARGET_PERIOD , tach_period);return smu7_fan_ctrl_set_static_mode (hwmgr,FDO_PWM_MODE_STATIC_RPM ); }
drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c +3 -3
@@ -321,9 +321,9 @@ int vega10_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)if (!result) { crystal_clock_freq =amdgpu_asic_get_xclk ((struct amdgpu_device *)hwmgr->adev); tach_period =60 * crystal_clock_freq *10000 / (8 * speed); -WREG32_SOC15 (THM ,0 , mmCG_TACH_STATUS, -REG_SET_FIELD (RREG32_SOC15 (THM ,0 , mmCG_TACH_STATUS), -CG_TACH_STATUS ,TACH_PERIOD , +WREG32_SOC15 (THM ,0 , mmCG_TACH_CTRL, +REG_SET_FIELD (RREG32_SOC15 (THM ,0 , mmCG_TACH_CTRL), +CG_TACH_CTRL ,TARGET_PERIOD , tach_period)); }return vega10_fan_ctrl_set_static_mode (hwmgr,FDO_PWM_MODE_STATIC_RPM );
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Deucher, Alexander
Reviewed-bySeries is:
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Rex Zhu <[email protected]>
Sent: Thursday, September 20, 2018 3:14:25 AM
To: [email protected]
Cc: Zhu, Rex
Subject: [PATCH 1/3] drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
The minRPM speed maybe equal to zero. so need to check input RPM not equal to 0, otherwise cause divide-by-zero driver crash.
--- drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c +1 -0
@@ -260,6 +260,7 @@ int smu7_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)if (hwmgr->thermal_controller.fanInfo.bNoFan || (hwmgr->thermal_controller.fanInfo. ucTachometerPulsesPerRevolution ==0 ) || + speed ==0 || (speed < hwmgr->thermal_controller.fanInfo.ulMinRPM) || (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM))return 0 ;
--
1.9.1
_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BN6PR12MB18097706023511533D3B4E6FF7130-/b2+HYfkarSEx6ez0IUAagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Zhu, Rex
Reviewed-by Alex DeucherHi Alex and Evan,
For the fan control via sysfs, I think we need to clarify the use case.
We support manual/auto fan control mode.
User can set the mode through pwm_enable. 1 mean manual. 2 mean auto User can set fan speed via pwm1 and fan1_input.
For pwm1, user set the percentage value (0% - 100%)
And can get the pwm1's range via sysfs: pwm1_min, pwm1_max. the range is [0, 255]. In driver, we transfer to [0% - 100%]
For fan1_input, user set the fan's resolution per minute
No way for user to get the range. On Tonga, the range is (0, 6000]. Not support zero-rpm on tonga.
Do we need to add new sysfs to expose the RPM range or just print the range in dmesg if user's setting is out of range?
Another question is:
Currently, the default fan control mode is auto.
When user change the fan speed via pwm1 or fan1_input, we switch to manual mode automatically.
So if user want to change back to auto fan control mode, they need to echo 2 to pwm_enable.
Best Regards
Rex
From: Deucher, Alexander
Sent: Thursday, September 20, 2018 9:52 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH 1/3] drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
Series is:
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org<mailto:[email protected]>> on behalf of Rex Zhu <[email protected]<mailto:[email protected]>>
Sent: Thursday, September 20, 2018 3:14:25 AM
To: [email protected]<mailto:[email protected]>
Cc: Zhu, Rex
Subject: [PATCH 1/3] drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
The minRPM speed maybe equal to zero. so need to check input RPM not equal to 0, otherwise cause divide-by-zero driver crash.
--- drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c +1 -0
@@ -260,6 +260,7 @@ int smu7_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)if (hwmgr->thermal_controller.fanInfo.bNoFan || (hwmgr->thermal_controller.fanInfo. ucTachometerPulsesPerRevolution ==0 ) || + speed ==0 || (speed < hwmgr->thermal_controller.fanInfo.ulMinRPM) || (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM))return 0 ;
--
1.9.1
_______________________________________________
amd-gfx mailing list [email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BYAPR12MB277505BCC3D7AB18104E3A4CFB130-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Deucher, Alexander
Reviewed-by Alex Deucher________________________________
From: Zhu, Rex
Sent: Thursday, September 20, 2018 10:43 AM
To: Deucher, Alexander; [email protected]; Quan, Evan
Subject: RE: [PATCH 1/3] drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
Hi Alex and Evan,
For the fan control via sysfs, I think we need to clarify the use case.
We support manual/auto fan control mode.
User can set the mode through pwm_enable. 1 mean manual. 2 mean auto
User can set fan speed via pwm1 and fan1_input.
For pwm1, user set the percentage value (0% - 100%)
And can get the pwm1’s range via sysfs: pwm1_min, pwm1_max. the range is [0, 255]. In driver, we transfer to [0% - 100%]
For fan1_input, user set the fan’s resolution per minute
No way for user to get the range. On Tonga, the range is (0, 6000]. Not support zero-rpm on tonga.
Do we need to add new sysfs to expose the RPM range or just print the range in dmesg if user’s setting is out of range?
Yes, expose the rpm limits via fan1_min and max. See:
https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
for more info on standard sysfs interfaces for hwmon.
Another question is:
Currently, the default fan control mode is auto.
When user change the fan speed via pwm1 or fan1_input, we switch to manual mode automatically.
So if user want to change back to auto fan control mode, they need to echo 2 to pwm_enable.
I think we should reject any changes unless the user selects manual (1) first.
Best Regards
Rex
From: Deucher, Alexander
Sent: Thursday, September 20, 2018 9:52 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH 1/3] drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
Series is:
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org<mailto:[email protected]>> on behalf of Rex Zhu <[email protected]<mailto:[email protected]>>
Sent: Thursday, September 20, 2018 3:14:25 AM
To: [email protected]<mailto:[email protected]>
Cc: Zhu, Rex
Subject: [PATCH 1/3] drm/amd/pp: Avoid divide-by-zero in smu7_fan_ctrl_set_fan_speed_rpm
The minRPM speed maybe equal to zero. so need to check input RPM not equal to 0, otherwise cause divide-by-zero driver crash.
--- drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c +1 -0
@@ -260,6 +260,7 @@ int smu7_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)if (hwmgr->thermal_controller.fanInfo.bNoFan || (hwmgr->thermal_controller.fanInfo. ucTachometerPulsesPerRevolution ==0 ) || + speed ==0 || (speed < hwmgr->thermal_controller.fanInfo.ulMinRPM) || (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM))return 0 ;
--
1.9.1
_______________________________________________
amd-gfx mailing list [email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx