[14/26] drm/amd/powerplay: add od condition for power limit

Submitted by Huang, Ray on Feb. 25, 2019, 12:12 p.m.

Details

Message ID 1551096752-18205-15-git-send-email-ray.huang@amd.com
State New
Headers show
Series "Updates for SW SMU driver" ( rev: 1 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Huang, Ray Feb. 25, 2019, 12:12 p.m.
From: Likun Gao <Likun.Gao@amd.com>

Add condition to judge whether overdrive is enabled and correct power
limit value for overdrive used by power limit interface.

Signed-off-by: Likun Gao <Likun.Gao@amd.com>
Reviewed-by: Kevin Wang <kevin1.wang@amd.com>
---
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  1 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 20 ++++++++++++++++++--
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c     |  1 +
 3 files changed, 20 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 8c7eac9..594965c 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -307,6 +307,7 @@  struct smu_table_context
 	struct smu_table		memory_pool;
 	uint16_t                        software_shutdown_temp;
 	uint8_t                         thermal_controller_type;
+	uint16_t			TDPODLimit;
 
 	uint8_t				*od_feature_capabilities;
 	uint32_t			*od_settings_max;
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index 2932734..5531cd1 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -924,6 +924,10 @@  static int smu_v11_0_get_power_limit(struct smu_context *smu,
 	if (get_default) {
 		mutex_lock(&smu->mutex);
 		*limit = smu->default_power_limit;
+		if (smu->od_enabled) {
+			*limit *= (100 + smu->smu_table.TDPODLimit);
+			*limit /= 100;
+		}
 		mutex_unlock(&smu->mutex);
 	} else {
 			ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetPptLimit,
@@ -941,9 +945,21 @@  static int smu_v11_0_get_power_limit(struct smu_context *smu,
 
 static int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n)
 {
+	uint32_t max_power_limit;
 	int ret = 0;
-		if (smu_feature_is_enabled(smu, FEATURE_PPT_BIT))
-			ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n);
+
+	if (n == 0)
+		n = smu->default_power_limit;
+
+	max_power_limit = smu->default_power_limit;
+
+	if (smu->od_enabled) {
+		max_power_limit *= (100 + smu->smu_table.TDPODLimit);
+		max_power_limit /= 100;
+	}
+
+	if (smu_feature_is_enabled(smu, FEATURE_PPT_BIT))
+		ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n);
 	if (ret) {
 		pr_err("[%s] Set power limit Failed!", __func__);
 		return ret;
diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
index 6aa94ee..f97b60a 100644
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
@@ -265,6 +265,7 @@  static int vega20_store_powerplay_table(struct smu_context *smu)
 
 	table_context->software_shutdown_temp = powerplay_table->usSoftwareShutdownTemp;
 	table_context->thermal_controller_type = powerplay_table->ucThermalControllerType;
+	table_context->TDPODLimit = le32_to_cpu(powerplay_table->OverDrive8Table.ODSettingsMax[ATOM_VEGA20_ODSETTING_POWERPERCENTAGE]);
 
 	ret = vega20_setup_od8_information(smu);