Skip to contentSkip to conversation

Adjustment to power limit setting

PATCH In review Mario Limonciello 2 participants 6 messages Oct 9, 2025 – Oct 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover Adjustment to power limit setting

Lijo pointed out to me that
commit ed4efe426a49 ("drm/amd: Restore cached power limit during resume") commit 796ff8a7e01b ("drm/amd: Restore cached manual clock settings during resume")

both should be unnecessary because smu_restore_dpm_user_profile() already restores them. However in looking at the code there is a case that isn't properly restored - the FAST PPT limits supported by Van Gogh. The nuance isn't immediately obvious because the limit variable is overloaded with limit type.

v5:
* Re-order limit of zero handling.
* Drop first and last patch, which were already merged.

Mario Limonciello (4):
drm/amd: Stop overloading power limit with limit type drm/amd: Remove second call to set_power_limit()
drm/amd: Save and restore all limit types
drm/amd: Drop calls to restore power limit and clock from smu_resume()

 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  3 +-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  3 +-
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 +-
 .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  2 +-
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 59 ++++++++-----------
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  3 +-
 .../gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c  |  1 -
 8 files changed, 31 insertions(+), 44 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v5 1/4 drm/amd: Stop overloading power limit with limit type

When passed around internally the upper 8 bits of power limit include the limit type. This is non-obvious without digging into the nuances of each function. Instead pass the limit type as an argument to all applicable layers.

---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h   |  2 +-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c              |  3 ++-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c               |  3 +--
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h          |  2 +-
 drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  2 +-
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        | 10 ++++------
 drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c |  1 -
 7 files changed, 10 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -1
index 2b0cdb2a2775..87814c2b526e 100644
@@ -454,7 +454,7 @@ struct amd_pm_funcs {
 				bool gate,
 				int inst);
 	int (*set_clockgating_by_smu)(void *handle, uint32_t msg_id);
-	int (*set_power_limit)(void *handle, uint32_t n);
+	int (*set_power_limit)(void *handle, uint32_t limit_type, uint32_t n);
 	int (*get_power_limit)(void *handle, uint32_t *limit,
 			enum pp_power_limit_level pp_limit_level,
 			enum pp_power_type power_type);
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -1
index 518d07afc7df..5d08dc3b7110 100644
@@ -1616,6 +1616,7 @@ int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
 }
 
 int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit_type,
 			       uint32_t limit)
 {
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
@@ -1626,7 +1627,7 @@ int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
 
 	mutex_lock(&adev->pm.mutex);
 	ret = pp_funcs->set_power_limit(adev->powerplay.pp_handle,
-					limit);
+					limit_type, limit);
 	mutex_unlock(&adev->pm.mutex);
 
 	return ret;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2
index b5fbb0fd1dc0..6bdf185c6b60 100644
@@ -3390,13 +3390,12 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
 		return err;
 
 	value = value / 1000000; /* convert to Watt */
-	value |= limit_type << 24;
 
 	err = amdgpu_pm_get_access(adev);
 	if (err < 0)
 		return err;
 
-	err = amdgpu_dpm_set_power_limit(adev, value);
+	err = amdgpu_dpm_set_power_limit(adev, limit_type, value);
 
 	amdgpu_pm_put_access(adev);
 
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -1
index 65c1d98af26c..3bce74f8bb0a 100644
@@ -553,7 +553,7 @@ int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
 			       enum pp_power_limit_level pp_limit_level,
 			       enum pp_power_type power_type);
 int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
-			       uint32_t limit);
+			       uint32_t limit_type, uint32_t limit);
 int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device *adev);
 int amdgpu_dpm_debugfs_print_current_performance_level(struct amdgpu_device *adev,
 						       struct seq_file *m);
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
index fb595a70bbd1..76a5353d7f4a 100644
@@ -952,7 +952,7 @@ static int pp_dpm_switch_power_profile(void *handle,
 	return 0;
 }
 
-static int pp_set_power_limit(void *handle, uint32_t limit)
+static int pp_set_power_limit(void *handle, uint32_t limit_type, uint32_t limit)
 {
 	struct pp_hwmgr *hwmgr = handle;
 	uint32_t max_power_limit;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -6
index fb8086859857..1c5f37cd5b75 100644
@@ -68,7 +68,7 @@ static int smu_handle_task(struct smu_context *smu,
 static int smu_reset(struct smu_context *smu);
 static int smu_set_fan_speed_pwm(void *handle, u32 speed);
 static int smu_set_fan_control_mode(void *handle, u32 value);
-static int smu_set_power_limit(void *handle, uint32_t limit);
+static int smu_set_power_limit(void *handle, uint32_t limit_type, uint32_t limit);
 static int smu_set_fan_speed_rpm(void *handle, uint32_t speed);
 static int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled);
 static int smu_set_mp1_state(void *handle, enum pp_mp1_state mp1_state);
@@ -510,7 +510,7 @@ static void smu_restore_dpm_user_profile(struct smu_context *smu)
 
 	/* set the user dpm power limit */
 	if (smu->user_dpm_profile.power_limit) {
-		ret = smu_set_power_limit(smu, smu->user_dpm_profile.power_limit);
+		ret = smu_set_power_limit(smu, SMU_DEFAULT_PPT_LIMIT, smu->current_power_limit);
 		if (ret)
 			dev_err(smu->adev->dev, "Failed to set power limit value\n");
 	}
@@ -2258,7 +2258,7 @@ static int smu_resume(struct amdgpu_ip_block *ip_block)
 	adev->pm.dpm_enabled = true;
 
 	if (smu->current_power_limit) {
-		ret = smu_set_power_limit(smu, smu->current_power_limit);
+		ret = smu_set_power_limit(smu, SMU_DEFAULT_PPT_LIMIT, smu->current_power_limit);
 		if (ret && ret != -EOPNOTSUPP)
 			return ret;
 	}
@@ -2958,16 +2958,14 @@ int smu_get_power_limit(void *handle,
 	return ret;
 }
 
-static int smu_set_power_limit(void *handle, uint32_t limit)
+static int smu_set_power_limit(void *handle, uint32_t limit_type, uint32_t limit)
 {
 	struct smu_context *smu = handle;
-	uint32_t limit_type = limit >> 24;
 	int ret = 0;
 
 	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
 		return -EOPNOTSUPP;
 
-	limit &= (1<<24)-1;
 	if (limit_type != SMU_DEFAULT_PPT_LIMIT)
 		if (smu->ppt_funcs->set_power_limit)
 			return smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +0 -1
index 9fadfa820f5d..1dcbf250f486 100644
@@ -2397,7 +2397,6 @@ static int vangogh_set_power_limit(struct smu_context *smu,
 		smu->current_power_limit = ppt_limit;
 		break;
 	case SMU_FAST_PPT_LIMIT:
-		ppt_limit &= ~(SMU_FAST_PPT_LIMIT << 24);
 		if (ppt_limit > power_context->max_fast_ppt_limit) {
 			dev_err(smu->adev->dev,
 				"New power limit (%d) is over the max allowed %d\n",
Signature · 1 line
2.51.0
#2 lore raw

PATCH v5 2/4 drm/amd: Remove second call to set_power_limit()

In reply to Mario Limonciello

The min/max limits only make sense for default PPT. Restructure smu_set_power_limit() to only use them in that case.

---
v5:
* Re-order calls so that limit of "0" always resets to default limit for all parts

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +9 -12
index 1c5f37cd5b75..a55f94b91bc9 100644
@@ -2966,20 +2966,17 @@ static int smu_set_power_limit(void *handle, uint32_t limit_type, uint32_t limit
 	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
 		return -EOPNOTSUPP;
 
-	if (limit_type != SMU_DEFAULT_PPT_LIMIT)
-		if (smu->ppt_funcs->set_power_limit)
-			return smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
-
-	if ((limit > smu->max_power_limit) || (limit < smu->min_power_limit)) {
-		dev_err(smu->adev->dev,
-			"New power limit (%d) is out of range [%d,%d]\n",
-			limit, smu->min_power_limit, smu->max_power_limit);
-		return -EINVAL;
+	if (limit_type == SMU_DEFAULT_PPT_LIMIT) {
+		if (!limit)
+			limit = smu->current_power_limit;
+		if ((limit > smu->max_power_limit) || (limit < smu->min_power_limit)) {
+			dev_err(smu->adev->dev,
+				"New power limit (%d) is out of range [%d,%d]\n",
+				limit, smu->min_power_limit, smu->max_power_limit);
+			return -EINVAL;
+		}
 	}
 
-	if (!limit)
-		limit = smu->current_power_limit;
-
 	if (smu->ppt_funcs->set_power_limit) {
 		ret = smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
 		if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE))
Signature · 1 line
2.51.0
Reviewed-by on v5 2/4
#3 lore raw

RE: [PATCH v5 2/4] drm/amd: Remove second call to set_power_limit()

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 9 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Friday, October 10, 2025 2:29 AM
To: Limonciello, Mario <[email protected]>; amd- [email protected]
Cc: Robert Beckett <[email protected]>
Subject: [PATCH v5 2/4] drm/amd: Remove second call to set_power_limit()

Quoted 4 lines

The min/max limits only make sense for default PPT. Restructure smu_set_power_limit() to only use them in that case.

Thanks,
Lijo

Quoted 51 lines

---
v5:
* Re-order calls so that limit of "0" always resets to default limit for all parts
---
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 21 +++++++++------------

1 file changed, 9 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
index 1c5f37cd5b75..a55f94b91bc9 100644
@@ -2966,20 +2966,17 @@ static int smu_set_power_limit(void *handle,

uint32_t limit_type, uint32_t limit

      if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
              return -EOPNOTSUPP;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-      if (limit_type != SMU_DEFAULT_PPT_LIMIT)
-              if (smu->ppt_funcs->set_power_limit)
-                      return smu->ppt_funcs->set_power_limit(smu,

limit_type, limit);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -6
-
-      if ((limit > smu->max_power_limit) || (limit < smu->min_power_limit)) {
-              dev_err(smu->adev->dev,
-                      "New power limit (%d) is out of range [%d,%d]\n",
-                      limit, smu->min_power_limit, smu->max_power_limit);
-              return -EINVAL;
+      if (limit_type == SMU_DEFAULT_PPT_LIMIT) {
+              if (!limit)
+                      limit = smu->current_power_limit;
+              if ((limit > smu->max_power_limit) || (limit < smu-
Quoted 1 line

min_power_limit)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
+                      dev_err(smu->adev->dev,
+                              "New power limit (%d) is out of range

[%d,%d]\n",
+ limit, smu->min_power_limit, smu-

Quoted 1 line

max_power_limit);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -3
+                      return -EINVAL;
+              }
      }
 
-      if (!limit)
-              limit = smu->current_power_limit;
-
      if (smu->ppt_funcs->set_power_limit) {
              ret = smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
              if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE))
--
2.51.0

#4 lore raw

PATCH v5 3/4 drm/amd: Save and restore all limit types

In reply to Mario Limonciello

Vangogh has separate limits for default PPT and fast PPT. Add infrastructure to save both of these limits and restore both of them.

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 19 ++++++++++++-------
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  3 ++-
 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +12 -7
index a55f94b91bc9..ea27c087ecf1 100644
@@ -508,11 +508,14 @@ static void smu_restore_dpm_user_profile(struct smu_context *smu)
 	/* Enable restore flag */
 	smu->user_dpm_profile.flags |= SMU_DPM_USER_PROFILE_RESTORE;
 
-	/* set the user dpm power limit */
-	if (smu->user_dpm_profile.power_limit) {
-		ret = smu_set_power_limit(smu, SMU_DEFAULT_PPT_LIMIT, smu->current_power_limit);
+	/* set the user dpm power limits */
+	for (int i = SMU_DEFAULT_PPT_LIMIT; i < SMU_LIMIT_TYPE_COUNT; i++) {
+		if (!smu->user_dpm_profile.power_limits[i])
+			continue;
+		ret = smu_set_power_limit(smu, i,
+					  smu->user_dpm_profile.power_limits[i]);
 		if (ret)
-			dev_err(smu->adev->dev, "Failed to set power limit value\n");
+			dev_err(smu->adev->dev, "Failed to set %d power limit value\n", i);
 	}
 
 	/* set the user dpm clock configurations */
@@ -2979,11 +2982,13 @@ static int smu_set_power_limit(void *handle, uint32_t limit_type, uint32_t limit
 
 	if (smu->ppt_funcs->set_power_limit) {
 		ret = smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
-		if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE))
-			smu->user_dpm_profile.power_limit = limit;
+		if (ret)
+			return ret;
+		if (!(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE))
+			smu->user_dpm_profile.power_limits[limit_type] = limit;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int smu_print_smuclk_levels(struct smu_context *smu, enum smu_clk_type clk_type, char *buf)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +2 -1
index 582c186d8b62..32387e8c138b 100644
@@ -212,6 +212,7 @@ enum smu_power_src_type {
 enum smu_ppt_limit_type {
 	SMU_DEFAULT_PPT_LIMIT = 0,
 	SMU_FAST_PPT_LIMIT,
+	SMU_LIMIT_TYPE_COUNT,
 };
 
 enum smu_ppt_limit_level {
@@ -231,7 +232,7 @@ enum smu_memory_pool_size {
 
 struct smu_user_dpm_profile {
 	uint32_t fan_mode;
-	uint32_t power_limit;
+	uint32_t power_limits[SMU_LIMIT_TYPE_COUNT];
 	uint32_t fan_speed_pwm;
 	uint32_t fan_speed_rpm;
 	uint32_t flags;
Signature · 1 line
2.51.0
#5 lore raw

PATCH v5 4/4 drm/amd: Drop calls to restore power limit and clock from smu_resume()

In reply to Mario Limonciello

User requested power limits and clock settings are already restored as part of smu_restore_dpm_user_profile(). It's unnecessary to call the same restore as part of smu_resume().

Revert the following commits to drop that extra restore:
commit ed4efe426a49 ("drm/amd: Restore cached power limit during resume")
commit 796ff8a7e01b ("drm/amd: Restore cached manual clock settings during resume") commit f9b80514a722 ("drm/amd: Only restore cached manual clock settings in restore if OD enabled")

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 13 -------------
 1 file changed, 13 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -13
index ea27c087ecf1..183dd4138a85 100644
@@ -2228,7 +2228,6 @@ static int smu_resume(struct amdgpu_ip_block *ip_block)
 	int ret;
 	struct amdgpu_device *adev = ip_block->adev;
 	struct smu_context *smu = adev->powerplay.pp_handle;
-	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
 
 	if (amdgpu_sriov_multi_vf_mode(adev))
 		return 0;
@@ -2260,18 +2259,6 @@ static int smu_resume(struct amdgpu_ip_block *ip_block)
 
 	adev->pm.dpm_enabled = true;
 
-	if (smu->current_power_limit) {
-		ret = smu_set_power_limit(smu, SMU_DEFAULT_PPT_LIMIT, smu->current_power_limit);
-		if (ret && ret != -EOPNOTSUPP)
-			return ret;
-	}
-
-	if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL && smu->od_enabled) {
-		ret = smu_od_edit_dpm_table(smu, PP_OD_COMMIT_DPM_TABLE, NULL, 0);
-		if (ret)
-			return ret;
-	}
-
 	dev_info(adev->dev, "SMU is resumed successfully!\n");
 
 	return 0;
Signature · 1 line
2.51.0