[PATCH] drm/amdgpu/smu: move fan rpm query into the asic specific code

Quan, Evan Evan.Quan at amd.com
Fri Jul 19 01:20:19 UTC 2019


Reviewed-by: Evan Quan <evan.quan at amd.com>

> -----Original Message-----
> From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> On Behalf Of Alex
> Deucher
> Sent: Friday, July 19, 2019 4:28 AM
> To: amd-gfx at lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher at amd.com>
> Subject: [PATCH] drm/amdgpu/smu: move fan rpm query into the asic
> specific code
> 
> On vega20, there is an SMU message to query it.  On navi, it's fetched from
> the metrics table.
> 
> Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        |  4 ++--
>  .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |  6 +++---
>  drivers/gpu/drm/amd/powerplay/navi10_ppt.c    | 12 ++++++-----
>  drivers/gpu/drm/amd/powerplay/smu_v11_0.c     | 18 -----------------
>  drivers/gpu/drm/amd/powerplay/vega20_ppt.c    | 20
> ++++++++++++++++++-
>  5 files changed, 31 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 8b7efd0a7028..03ca8c69114f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -1734,7 +1734,7 @@ static ssize_t
> amdgpu_hwmon_get_fan1_input(struct device *dev,
>  		return -EINVAL;
> 
>  	if (is_support_sw_smu(adev)) {
> -		err = smu_get_current_rpm(&adev->smu, &speed);
> +		err = smu_get_fan_speed_rpm(&adev->smu, &speed);
>  		if (err)
>  			return err;
>  	} else if (adev->powerplay.pp_funcs->get_fan_speed_rpm) { @@ -
> 1794,7 +1794,7 @@ static ssize_t amdgpu_hwmon_get_fan1_target(struct
> device *dev,
>  		return -EINVAL;
> 
>  	if (is_support_sw_smu(adev)) {
> -		err = smu_get_current_rpm(&adev->smu, &rpm);
> +		err = smu_get_fan_speed_rpm(&adev->smu, &rpm);
>  		if (err)
>  			return err;
>  	} else if (adev->powerplay.pp_funcs->get_fan_speed_rpm) { diff --
> git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
> b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
> index 514d31518853..87e44c3a2d73 100644
> --- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
> +++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
> @@ -623,6 +623,7 @@ struct pptable_funcs {
>  	int (*tables_init)(struct smu_context *smu, struct smu_table
> *tables);
>  	int (*set_thermal_fan_table)(struct smu_context *smu);
>  	int (*get_fan_speed_percent)(struct smu_context *smu, uint32_t
> *speed);
> +	int (*get_fan_speed_rpm)(struct smu_context *smu, uint32_t
> *speed);
>  	int (*set_watermarks_table)(struct smu_context *smu, void
> *watermarks,
>  				    struct
> dm_pp_wm_sets_with_clock_ranges_soc15 *clock_ranges);
>  	int (*get_current_clk_freq_by_table)(struct smu_context *smu,
> @@ -695,7 +696,6 @@ struct smu_funcs
>  	int (*set_watermarks_for_clock_ranges)(struct smu_context *smu,
>  					       struct
> dm_pp_wm_sets_with_clock_ranges_soc15 *clock_ranges);
>  	int (*conv_power_profile_to_pplib_workload)(int power_profile);
> -	int (*get_current_rpm)(struct smu_context *smu, uint32_t *speed);
>  	uint32_t (*get_fan_control_mode)(struct smu_context *smu);
>  	int (*set_fan_control_mode)(struct smu_context *smu, uint32_t
> mode);
>  	int (*set_fan_speed_percent)(struct smu_context *smu, uint32_t
> speed); @@ -761,8 +761,6 @@ struct smu_funcs
>  	((smu)->funcs->init_max_sustainable_clocks ? (smu)->funcs-
> >init_max_sustainable_clocks((smu)) : 0)  #define
> smu_set_default_od_settings(smu, initialize) \
>  	((smu)->ppt_funcs->set_default_od_settings ? (smu)->ppt_funcs-
> >set_default_od_settings((smu), (initialize)) : 0) -#define
> smu_get_current_rpm(smu, speed) \
> -	((smu)->funcs->get_current_rpm ? (smu)->funcs-
> >get_current_rpm((smu), (speed)) : 0)
>  #define smu_set_fan_speed_rpm(smu, speed) \
>  	((smu)->funcs->set_fan_speed_rpm ? (smu)->funcs-
> >set_fan_speed_rpm((smu), (speed)) : 0)  #define
> smu_send_smc_msg(smu, msg) \ @@ -851,6 +849,8 @@ struct smu_funcs
>  	((smu)->ppt_funcs->get_fan_speed_percent ? (smu)->ppt_funcs-
> >get_fan_speed_percent((smu), (speed)) : 0)  #define
> smu_set_fan_speed_percent(smu, speed) \
>  	((smu)->funcs->set_fan_speed_percent ? (smu)->funcs-
> >set_fan_speed_percent((smu), (speed)) : 0)
> +#define smu_get_fan_speed_rpm(smu, speed) \
> +	((smu)->ppt_funcs->get_fan_speed_rpm ?
> +(smu)->ppt_funcs->get_fan_speed_rpm((smu), (speed)) : 0)
> 
>  #define smu_msg_get_index(smu, msg) \
>  	((smu)->ppt_funcs? ((smu)->ppt_funcs->get_smu_msg_index?
> (smu)->ppt_funcs->get_smu_msg_index((smu), (msg)) : -EINVAL) : -EINVAL)
> diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
> b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
> index 80daded31970..352fab1b3444 100644
> --- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
> +++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
> @@ -974,12 +974,13 @@ static bool navi10_is_dpm_running(struct
> smu_context *smu)
>  	return !!(feature_enabled & SMC_DPM_FEATURE);  }
> 
> -static int navi10_get_fan_speed(struct smu_context *smu, uint16_t *value)
> +static int navi10_get_fan_speed_rpm(struct smu_context *smu,
> +				    uint32_t *speed)
>  {
>  	SmuMetrics_t metrics;
>  	int ret = 0;
> 
> -	if (!value)
> +	if (!speed)
>  		return -EINVAL;
> 
>  	memset(&metrics, 0, sizeof(metrics));
> @@ -989,7 +990,7 @@ static int navi10_get_fan_speed(struct smu_context
> *smu, uint16_t *value)
>  	if (ret)
>  		return ret;
> 
> -	*value = metrics.CurrFanSpeed;
> +	*speed = metrics.CurrFanSpeed;
> 
>  	return ret;
>  }
> @@ -999,10 +1000,10 @@ static int navi10_get_fan_speed_percent(struct
> smu_context *smu,  {
>  	int ret = 0;
>  	uint32_t percent = 0;
> -	uint16_t current_rpm;
> +	uint32_t current_rpm;
>  	PPTable_t *pptable = smu->smu_table.driver_pptable;
> 
> -	ret = navi10_get_fan_speed(smu, &current_rpm);
> +	ret = navi10_get_fan_speed_rpm(smu, &current_rpm);
>  	if (ret)
>  		return ret;
> 
> @@ -1617,6 +1618,7 @@ static const struct pptable_funcs navi10_ppt_funcs
> = {
>  	.unforce_dpm_levels = navi10_unforce_dpm_levels,
>  	.is_dpm_running = navi10_is_dpm_running,
>  	.get_fan_speed_percent = navi10_get_fan_speed_percent,
> +	.get_fan_speed_rpm = navi10_get_fan_speed_rpm,
>  	.get_power_profile_mode = navi10_get_power_profile_mode,
>  	.set_power_profile_mode = navi10_set_power_profile_mode,
>  	.get_profiling_clk_mask = navi10_get_profiling_clk_mask, diff --git
> a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
> b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
> index 9f3a84fbb9cf..a41ce29b23dc 100644
> --- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
> +++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
> @@ -1405,23 +1405,6 @@ static int smu_v11_0_gfx_off_control(struct
> smu_context *smu, bool enable)
>  	return ret;
>  }
> 
> -static int smu_v11_0_get_current_rpm(struct smu_context *smu,
> -				     uint32_t *current_rpm)
> -{
> -	int ret;
> -
> -	ret = smu_send_smc_msg(smu, SMU_MSG_GetCurrentRpm);
> -
> -	if (ret) {
> -		pr_err("Attempt to get current RPM from SMC Failed!\n");
> -		return ret;
> -	}
> -
> -	smu_read_smc_arg(smu, current_rpm);
> -
> -	return 0;
> -}
> -
>  static uint32_t
>  smu_v11_0_get_fan_control_mode(struct smu_context *smu)  { @@ -
> 1807,7 +1790,6 @@ static const struct smu_funcs smu_v11_0_funcs = {
>  	.set_deep_sleep_dcefclk = smu_v11_0_set_deep_sleep_dcefclk,
>  	.display_clock_voltage_request =
> smu_v11_0_display_clock_voltage_request,
>  	.set_watermarks_for_clock_ranges =
> smu_v11_0_set_watermarks_for_clock_ranges,
> -	.get_current_rpm = smu_v11_0_get_current_rpm,
>  	.get_fan_control_mode = smu_v11_0_get_fan_control_mode,
>  	.set_fan_control_mode = smu_v11_0_set_fan_control_mode,
>  	.set_fan_speed_percent = smu_v11_0_set_fan_speed_percent, diff
> --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
> b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
> index 080956ea0570..43cd74795417 100644
> --- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
> +++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
> @@ -3039,6 +3039,23 @@ static int vega20_set_thermal_fan_table(struct
> smu_context *smu)
>  	return ret;
>  }
> 
> +static int vega20_get_fan_speed_rpm(struct smu_context *smu,
> +				    uint32_t *speed)
> +{
> +	int ret;
> +
> +	ret = smu_send_smc_msg(smu, SMU_MSG_GetCurrentRpm);
> +
> +	if (ret) {
> +		pr_err("Attempt to get current RPM from SMC Failed!\n");
> +		return ret;
> +	}
> +
> +	smu_read_smc_arg(smu, speed);
> +
> +	return 0;
> +}
> +
>  static int vega20_get_fan_speed_percent(struct smu_context *smu,
>  					uint32_t *speed)
>  {
> @@ -3046,7 +3063,7 @@ static int vega20_get_fan_speed_percent(struct
> smu_context *smu,
>  	uint32_t current_rpm = 0, percent = 0;
>  	PPTable_t *pptable = smu->smu_table.driver_pptable;
> 
> -	ret = smu_get_current_rpm(smu, &current_rpm);
> +	ret = vega20_get_fan_speed_rpm(smu, &current_rpm);
>  	if (ret)
>  		return ret;
> 
> @@ -3317,6 +3334,7 @@ static const struct pptable_funcs vega20_ppt_funcs
> = {
>  	.is_dpm_running = vega20_is_dpm_running,
>  	.set_thermal_fan_table = vega20_set_thermal_fan_table,
>  	.get_fan_speed_percent = vega20_get_fan_speed_percent,
> +	.get_fan_speed_rpm = vega20_get_fan_speed_rpm,
>  	.set_watermarks_table = vega20_set_watermarks_table,
>  	.get_thermal_temperature_range =
> vega20_get_thermal_temperature_range
>  };
> --
> 2.20.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx


More information about the amd-gfx mailing list