diff options
| author | Evan Quan <evan.quan@amd.com> | 2020-06-08 16:47:59 +0800 |
|---|---|---|
| committer | Alex Deucher <alexander.deucher@amd.com> | 2020-07-01 01:59:18 -0400 |
| commit | 5213e49df397e6056c30b368e2f986950f0b4bbb (patch) | |
| tree | 6b78bd328af3d0fdc571553b29af00d23e61d661 /drivers/gpu | |
| parent | drm/amd/powerplay: simplify the code around retrieving power limit (diff) | |
| download | linux-5213e49df397e6056c30b368e2f986950f0b4bbb.tar.gz linux-5213e49df397e6056c30b368e2f986950f0b4bbb.zip | |
drm/amd/powerplay: simplify the code around setting power limit
Use the cached max/current power limit and move the input check
to the top layer.
Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu')
| -rw-r--r-- | drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 11 | ||||
| -rw-r--r-- | drivers/gpu/drm/amd/powerplay/smu_v11_0.c | 16 |
2 files changed, 13 insertions, 14 deletions
diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c index 6757f65fd87e..7cde80c9614f 100644 --- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c @@ -2239,9 +2239,20 @@ int smu_set_power_limit(struct smu_context *smu, uint32_t limit) mutex_lock(&smu->mutex); + if (limit > smu->max_power_limit) { + dev_err(smu->adev->dev, + "New power limit (%d) is over the max allowed %d\n", + limit, smu->max_power_limit); + goto out; + } + + if (!limit) + limit = smu->current_power_limit; + if (smu->ppt_funcs->set_power_limit) ret = smu->ppt_funcs->set_power_limit(smu, limit); +out: mutex_unlock(&smu->mutex); return ret; diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c index 53491c55abd8..a15460bdea39 100644 --- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c +++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c @@ -1082,19 +1082,6 @@ int smu_v11_0_get_current_power_limit(struct smu_context *smu, int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n) { int ret = 0; - uint32_t max_power_limit; - - max_power_limit = smu_get_max_power_limit(smu); - - if (n > max_power_limit) { - dev_err(smu->adev->dev, "New power limit (%d) is over the max allowed %d\n", - n, - max_power_limit); - return -EINVAL; - } - - if (n == 0) - n = smu->default_power_limit; if (!smu_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) { dev_err(smu->adev->dev, "Setting new power limit is not supported!\n"); @@ -1106,7 +1093,8 @@ int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n) dev_err(smu->adev->dev, "[%s] Set power limit Failed!\n", __func__); return ret; } - smu->power_limit = n; + + smu->current_power_limit = n; return 0; } |
