Commit 2d1ac1cb authored by Darren Powell's avatar Darren Powell Committed by Alex Deucher

amdgpu/pm: (v2) add limit_type to (pptable_funcs)->set_power_limit signature

 v2
 add check for SMU_DEFAULT_PPT_LIMIT

 v1
 modify (pptable_funcs)->set_power_limit signature
 modify smu11 set_power_limit signature (arcturus, navi10, sienna_cichlid)
 modify smu13 set_power_limit signature (aldabaran)
 modify vangogh_set_power_limit signature (vangogh)

=== Test ===
sudo bash

AMDGPU_PCI_ADDR=`lspci -nn | grep "VGA\|Display" | cut -d " " -f 1`
AMDGPU_HWMON=`ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}'`
HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON}
LOGFILE=pp_show_power_cap.log

cp $LOGFILE{,.old}
lspci -nn | grep "VGA\|Display" > $LOGFILE
FILES="
power1_cap
power2_cap"

for f in $FILES
do
  if test -f "$HWMON_DIR/$f"; then
    echo === $f === >> $LOGFILE
    cat $HWMON_DIR/$f >> $LOGFILE
    RESTORE_VALUE=`cat $HWMON_DIR/$f` 2>&1  >> $LOGFILE
    echo RESTORE_VALUE $RESTORE_VALUE >> $LOGFILE
    echo 120000000 > $HWMON_DIR/$f
    sleep 3
    cat $HWMON_DIR/$f >> $LOGFILE
    echo $RESTORE_VALUE > $HWMON_DIR/$f
    sleep 3
    cat $HWMON_DIR/$f >> $LOGFILE
  else
    echo === $f === >> $LOGFILE
    echo File Not Found >> $LOGFILE
  fi
done
cat $LOGFILE
Signed-off-by: default avatarDarren Powell <darren.powell@amd.com>
Reviewed-by: default avatarLijo Lazar <lijo.lazar@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 91a1a52d
...@@ -1008,7 +1008,9 @@ struct pptable_funcs { ...@@ -1008,7 +1008,9 @@ struct pptable_funcs {
/** /**
* @set_power_limit: Set power limit in watts. * @set_power_limit: Set power limit in watts.
*/ */
int (*set_power_limit)(struct smu_context *smu, uint32_t n); int (*set_power_limit)(struct smu_context *smu,
enum smu_ppt_limit_type limit_type,
uint32_t limit);
/** /**
* @init_max_sustainable_clocks: Populate max sustainable clock speed * @init_max_sustainable_clocks: Populate max sustainable clock speed
......
...@@ -197,7 +197,9 @@ int smu_v11_0_notify_display_change(struct smu_context *smu); ...@@ -197,7 +197,9 @@ int smu_v11_0_notify_display_change(struct smu_context *smu);
int smu_v11_0_get_current_power_limit(struct smu_context *smu, int smu_v11_0_get_current_power_limit(struct smu_context *smu,
uint32_t *power_limit); uint32_t *power_limit);
int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n); int smu_v11_0_set_power_limit(struct smu_context *smu,
enum smu_ppt_limit_type limit_type,
uint32_t limit);
int smu_v11_0_init_max_sustainable_clocks(struct smu_context *smu); int smu_v11_0_init_max_sustainable_clocks(struct smu_context *smu);
......
...@@ -163,7 +163,9 @@ int smu_v13_0_notify_display_change(struct smu_context *smu); ...@@ -163,7 +163,9 @@ int smu_v13_0_notify_display_change(struct smu_context *smu);
int smu_v13_0_get_current_power_limit(struct smu_context *smu, int smu_v13_0_get_current_power_limit(struct smu_context *smu,
uint32_t *power_limit); uint32_t *power_limit);
int smu_v13_0_set_power_limit(struct smu_context *smu, uint32_t n); int smu_v13_0_set_power_limit(struct smu_context *smu,
enum smu_ppt_limit_type limit_type,
uint32_t limit);
int smu_v13_0_init_max_sustainable_clocks(struct smu_context *smu); int smu_v13_0_init_max_sustainable_clocks(struct smu_context *smu);
......
...@@ -2344,9 +2344,10 @@ static int smu_set_power_limit(void *handle, uint32_t limit) ...@@ -2344,9 +2344,10 @@ static int smu_set_power_limit(void *handle, uint32_t limit)
mutex_lock(&smu->mutex); mutex_lock(&smu->mutex);
limit &= (1<<24)-1;
if (limit_type != SMU_DEFAULT_PPT_LIMIT) if (limit_type != SMU_DEFAULT_PPT_LIMIT)
if (smu->ppt_funcs->set_power_limit) { if (smu->ppt_funcs->set_power_limit) {
ret = smu->ppt_funcs->set_power_limit(smu, limit); ret = smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
goto out; goto out;
} }
...@@ -2362,7 +2363,7 @@ static int smu_set_power_limit(void *handle, uint32_t limit) ...@@ -2362,7 +2363,7 @@ static int smu_set_power_limit(void *handle, uint32_t limit)
limit = smu->current_power_limit; limit = smu->current_power_limit;
if (smu->ppt_funcs->set_power_limit) { if (smu->ppt_funcs->set_power_limit) {
ret = smu->ppt_funcs->set_power_limit(smu, limit); ret = smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE))
smu->user_dpm_profile.power_limit = limit; smu->user_dpm_profile.power_limit = limit;
} }
......
...@@ -978,11 +978,16 @@ int smu_v11_0_get_current_power_limit(struct smu_context *smu, ...@@ -978,11 +978,16 @@ int smu_v11_0_get_current_power_limit(struct smu_context *smu,
return ret; return ret;
} }
int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n) int smu_v11_0_set_power_limit(struct smu_context *smu,
enum smu_ppt_limit_type limit_type,
uint32_t limit)
{ {
int power_src; int power_src;
int ret = 0; int ret = 0;
if (limit_type != SMU_DEFAULT_PPT_LIMIT)
return -EINVAL;
if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) { if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) {
dev_err(smu->adev->dev, "Setting new power limit is not supported!\n"); dev_err(smu->adev->dev, "Setting new power limit is not supported!\n");
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -1001,16 +1006,16 @@ int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n) ...@@ -1001,16 +1006,16 @@ int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n)
* BIT 16-23: PowerSource * BIT 16-23: PowerSource
* BIT 0-15: PowerLimit * BIT 0-15: PowerLimit
*/ */
n &= 0xFFFF; limit &= 0xFFFF;
n |= 0 << 24; limit |= 0 << 24;
n |= (power_src) << 16; limit |= (power_src) << 16;
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n, NULL); ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, limit, NULL);
if (ret) { if (ret) {
dev_err(smu->adev->dev, "[%s] Set power limit Failed!\n", __func__); dev_err(smu->adev->dev, "[%s] Set power limit Failed!\n", __func__);
return ret; return ret;
} }
smu->current_power_limit = n; smu->current_power_limit = limit;
return 0; return 0;
} }
......
...@@ -2144,11 +2144,12 @@ static int vangogh_get_ppt_limit(struct smu_context *smu, ...@@ -2144,11 +2144,12 @@ static int vangogh_get_ppt_limit(struct smu_context *smu,
return 0; return 0;
} }
static int vangogh_set_power_limit(struct smu_context *smu, uint32_t ppt_limit) static int vangogh_set_power_limit(struct smu_context *smu,
enum smu_ppt_limit_type limit_type,
uint32_t ppt_limit)
{ {
struct smu_11_5_power_context *power_context = struct smu_11_5_power_context *power_context =
smu->smu_power.power_context; smu->smu_power.power_context;
uint32_t limit_type = ppt_limit >> 24;
int ret = 0; int ret = 0;
if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) { if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) {
......
...@@ -1241,11 +1241,13 @@ static int aldebaran_get_power_limit(struct smu_context *smu, ...@@ -1241,11 +1241,13 @@ static int aldebaran_get_power_limit(struct smu_context *smu,
return 0; return 0;
} }
static int aldebaran_set_power_limit(struct smu_context *smu, uint32_t n) static int aldebaran_set_power_limit(struct smu_context *smu,
enum smu_ppt_limit_type limit_type,
uint32_t limit)
{ {
/* Power limit can be set only through primary die */ /* Power limit can be set only through primary die */
if (aldebaran_is_primary(smu)) if (aldebaran_is_primary(smu))
return smu_v13_0_set_power_limit(smu, n); return smu_v13_0_set_power_limit(smu, limit_type, limit);
return -EINVAL; return -EINVAL;
} }
......
...@@ -945,22 +945,27 @@ int smu_v13_0_get_current_power_limit(struct smu_context *smu, ...@@ -945,22 +945,27 @@ int smu_v13_0_get_current_power_limit(struct smu_context *smu,
return ret; return ret;
} }
int smu_v13_0_set_power_limit(struct smu_context *smu, uint32_t n) int smu_v13_0_set_power_limit(struct smu_context *smu,
enum smu_ppt_limit_type limit_type,
uint32_t limit)
{ {
int ret = 0; int ret = 0;
if (limit_type != SMU_DEFAULT_PPT_LIMIT)
return -EINVAL;
if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) { if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) {
dev_err(smu->adev->dev, "Setting new power limit is not supported!\n"); dev_err(smu->adev->dev, "Setting new power limit is not supported!\n");
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n, NULL); ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, limit, NULL);
if (ret) { if (ret) {
dev_err(smu->adev->dev, "[%s] Set power limit Failed!\n", __func__); dev_err(smu->adev->dev, "[%s] Set power limit Failed!\n", __func__);
return ret; return ret;
} }
smu->current_power_limit = n; smu->current_power_limit = limit;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment