[PATCH 3/7] drm/amd/powerplay: simplify the code around retrieving power limit

Evan Quan evan.quan at amd.com
Mon Jun 8 10:52:30 UTC 2020


Use the cached max/current power limit for other cases except
.late_init.

Change-Id: Ia4c063207faf051db27be1956f40554913c31c3b
Signed-off-by: Evan Quan <evan.quan at amd.com>
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c         | 7 +++----
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c       | 6 +-----
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h     | 2 +-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c         | 6 +-----
 drivers/gpu/drm/amd/powerplay/sienna_cichlid_ppt.c | 6 +-----
 drivers/gpu/drm/amd/powerplay/smu_internal.h       | 3 +++
 6 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index a5fd1284ff1c..6757f65fd87e 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -831,9 +831,9 @@ static int smu_late_init(void *handle)
 		return ret;
 	}
 
-	ret = smu_get_power_limit(smu, &smu->default_power_limit, false, false);
+	ret = smu_get_asic_power_limits(smu);
 	if (ret) {
-		dev_err(adev->dev, "Failed to get default power limit!\n");
+		dev_err(adev->dev, "Failed to get asic power limits!\n");
 		return ret;
 	}
 
@@ -2222,8 +2222,7 @@ int smu_get_power_limit(struct smu_context *smu,
 		mutex_lock(&smu->mutex);
 	}
 
-	if (smu->ppt_funcs->get_power_limit)
-		ret = smu->ppt_funcs->get_power_limit(smu, limit, def);
+	*limit = (def ? smu->max_power_limit : smu->current_power_limit);
 
 	if (lock_needed)
 		mutex_unlock(&smu->mutex);
diff --git a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
index 2c78271123f7..66b8f143cc46 100644
--- a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
@@ -1409,9 +1409,7 @@ arcturus_get_profiling_clk_mask(struct smu_context *smu,
 	return 0;
 }
 
-static int arcturus_get_power_limit(struct smu_context *smu,
-				     uint32_t *limit,
-				     bool cap)
+static int arcturus_get_power_limit(struct smu_context *smu)
 {
 	struct smu_11_0_powerplay_table *powerplay_table =
 		(struct smu_11_0_powerplay_table *)smu->smu_table.power_play_table;
@@ -1439,8 +1437,6 @@ static int arcturus_get_power_limit(struct smu_context *smu,
 	}
 	smu->max_power_limit = power_limit;
 
-	*limit = (cap ? smu->max_power_limit : smu->current_power_limit);
-
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 574a793b5d26..db63ed057840 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -487,7 +487,7 @@ struct pptable_funcs {
 	int (*set_performance_level)(struct smu_context *smu, enum amd_dpm_forced_level level);
 	int (*display_disable_memory_clock_switch)(struct smu_context *smu, bool disable_memory_clock_switch);
 	void (*dump_pptable)(struct smu_context *smu);
-	int (*get_power_limit)(struct smu_context *smu, uint32_t *limit, bool asic_default);
+	int (*get_power_limit)(struct smu_context *smu);
 	int (*get_dpm_clk_limited)(struct smu_context *smu, enum smu_clk_type clk_type,
 				   uint32_t dpm_level, uint32_t *freq);
 	int (*set_df_cstate)(struct smu_context *smu, enum pp_df_cstate state);
diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
index b867f94ba559..2e0836976001 100644
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
@@ -1922,9 +1922,7 @@ static uint32_t navi10_get_pptable_power_limit(struct smu_context *smu)
 	return pptable->SocketPowerLimitAc[PPT_THROTTLER_PPT0];
 }
 
-static int navi10_get_power_limit(struct smu_context *smu,
-				  uint32_t *limit,
-				  bool cap)
+static int navi10_get_power_limit(struct smu_context *smu)
 {
 	struct smu_11_0_powerplay_table *powerplay_table =
 		(struct smu_11_0_powerplay_table *)smu->smu_table.power_play_table;
@@ -1952,8 +1950,6 @@ static int navi10_get_power_limit(struct smu_context *smu,
 	}
 	smu->max_power_limit = power_limit;
 
-	*limit = (cap ? smu->max_power_limit : smu->current_power_limit);
-
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/powerplay/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/powerplay/sienna_cichlid_ppt.c
index c427e233dfad..44719c110655 100644
--- a/drivers/gpu/drm/amd/powerplay/sienna_cichlid_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/sienna_cichlid_ppt.c
@@ -1743,9 +1743,7 @@ static uint32_t sienna_cichlid_get_pptable_power_limit(struct smu_context *smu)
 	return pptable->SocketPowerLimitAc[PPT_THROTTLER_PPT0];
 }
 
-static int sienna_cichlid_get_power_limit(struct smu_context *smu,
-				     uint32_t *limit,
-				     bool cap)
+static int sienna_cichlid_get_power_limit(struct smu_context *smu)
 {
 	struct smu_11_0_7_powerplay_table *powerplay_table =
 		(struct smu_11_0_7_powerplay_table *)smu->smu_table.power_play_table;
@@ -1773,8 +1771,6 @@ static int sienna_cichlid_get_power_limit(struct smu_context *smu,
 	}
 	smu->max_power_limit = power_limit;
 
-	*limit = (cap ? smu->max_power_limit : smu->current_power_limit);
-
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/powerplay/smu_internal.h b/drivers/gpu/drm/amd/powerplay/smu_internal.h
index 9c68c6c43f9d..346aea9198e9 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_internal.h
+++ b/drivers/gpu/drm/amd/powerplay/smu_internal.h
@@ -213,4 +213,7 @@ static inline int smu_send_smc_msg(struct smu_context *smu, enum smu_message_typ
 #define smu_log_thermal_throttling(smu) \
 		((smu)->ppt_funcs->log_thermal_throttling_event ? (smu)->ppt_funcs->log_thermal_throttling_event((smu)) : 0)
 
+#define smu_get_asic_power_limits(smu) \
+		((smu)->ppt_funcs->get_power_limit ? (smu)->ppt_funcs->get_power_limit((smu)) : 0)
+
 #endif
-- 
2.27.0



More information about the amd-gfx mailing list