<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255)">
<span style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255);display:inline !important">>< > The limits are not
limited to sample window. There are limits like APU only limit, platform limit and totally obscure ones like PPT0/PPT1 etc.</span><br style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255)">
<span style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255);display:inline !important">>It's better that the
new enum takes care of those as well in case there is a need to make them available through sysfs.</span><br>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I think you mean something more like this?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="margin:0px;font-size:14.6667px;font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;background-color:rgb(255, 255, 255);display:inline !important">+ enum pp_power_constraints</span><br>
<span style="margin:0px;font-size:14.6667px;font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;background-color:rgb(255, 255, 255);display:inline !important">+{</span><br style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255)">
<span style="margin:0px;font-size:14.6667px;font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;background-color:rgb(255, 255, 255);display:inline !important">+ PP_PWR_CONSTRAINT_DEFAULT,</span><br style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255)">
<span style="margin:0px;font-size:14.6667px;font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;background-color:rgb(255, 255, 255);display:inline !important">+ PP_PWR_<span style="background-color:rgb(255, 255, 255);display:inline !important">CONSTRAINT_</span>FASTWINDOW,</span><br style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255)">
<span style="margin:0px;font-size:14.6667px;font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;background-color:rgb(255, 255, 255);display:inline !important">+};</span><br style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255)">
<span style="margin:0px;font-size:14.6667px;font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;background-color:rgb(255, 255, 255);display:inline !important">+</span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Lazar, Lijo <Lijo.Lazar@amd.com><br>
<b>Sent:</b> Monday, May 31, 2021 2:04 AM<br>
<b>To:</b> Powell, Darren <Darren.Powell@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> RE: [PATCH 2/6] amdgpu/pm: clean up smu_get_power_limit function signature</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">[Public]<br>
<br>
<br>
<br>
-----Original Message-----<br>
From: Powell, Darren <Darren.Powell@amd.com> <br>
Sent: Saturday, May 29, 2021 4:36 AM<br>
To: amd-gfx@lists.freedesktop.org<br>
Cc: Powell, Darren <Darren.Powell@amd.com><br>
Subject: [PATCH 2/6] amdgpu/pm: clean up smu_get_power_limit function signature<br>
<br>
add two new powerplay enums (limit_level, sample_window) add enums to smu_get_power_limit signature remove input bitfield stuffing of output variable limit update calls to smu_get_power_limit<br>
<br>
* Test<br>
AMDGPU_PCI_ADDR=`lspci -nn | grep "VGA\|Display" | cut -d " " -f 1` AMDGPU_HWMON=`ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | cut -d " " -f 10` HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON}<br>
<br>
lspci -nn | grep "VGA\|Display" ; \<br>
echo "=== power1 cap ===" ; cat $HWMON_DIR/power1_cap ; \<br>
echo "=== power1 cap max ===" ; cat $HWMON_DIR/power1_cap_max ; \<br>
echo "=== power1 cap def ===" ; cat $HWMON_DIR/power1_cap_default<br>
<br>
Signed-off-by: Darren Powell <darren.powell@amd.com><br>
---<br>
.../gpu/drm/amd/include/kgd_pp_interface.h | 14 ++++++++<br>
drivers/gpu/drm/amd/pm/amdgpu_pm.c | 18 +++++-----<br>
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h | 3 +-<br>
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 34 +++++++++++++++++--<br>
4 files changed, 57 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
index b1cd52a9d684..ddbf802ea8ad 100644<br>
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
@@ -192,6 +192,20 @@ enum pp_df_cstate {<br>
DF_CSTATE_ALLOW,<br>
};<br>
<br>
+enum pp_power_limit_level<br>
+{<br>
+ PP_PWR_LIMIT_MIN = -1,<br>
+ PP_PWR_LIMIT_CURRENT,<br>
+ PP_PWR_LIMIT_DEFAULT,<br>
+ PP_PWR_LIMIT_MAX,<br>
+};<br>
+<br>
+ enum pp_power_sample_window<br>
+{<br>
+ PP_PWR_WINDOW_DEFAULT,<br>
+ PP_PWR_WINDOW_FAST,<br>
+};<br>
+<br>
<br>
< > The limits are not limited to sample window. There are limits like APU only limit, platform limit and totally obscure ones like PPT0/PPT1 etc.
<br>
It's better that the new enum takes care of those as well in case there is a need to make them available through sysfs.<br>
<br>
Thanks,<br>
Lijo<br>
<br>
#define PP_GROUP_MASK 0xF0000000<br>
#define PP_GROUP_SHIFT 28<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
index 13da377888d2..f7b45803431d 100644<br>
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
@@ -2717,8 +2717,8 @@ static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev, {<br>
struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;<br>
- int limit_type = to_sensor_dev_attr(attr)->index;<br>
- uint32_t limit = limit_type << 24;<br>
+ enum pp_power_sample_window sample_window = to_sensor_dev_attr(attr)->index;<br>
+ uint32_t limit;<br>
uint32_t max_limit = 0;<br>
ssize_t size;<br>
int r;<br>
@@ -2735,7 +2735,7 @@ static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,<br>
}<br>
<br>
if (is_support_sw_smu(adev)) {<br>
- smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_MAX);<br>
+ smu_get_power_limit(&adev->smu, &limit, PP_PWR_LIMIT_MAX, <br>
+sample_window);<br>
size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
} else if (pp_funcs && pp_funcs->get_power_limit) {<br>
pp_funcs->get_power_limit(adev->powerplay.pp_handle,<br>
@@ -2757,8 +2757,8 @@ static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev, {<br>
struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;<br>
- int limit_type = to_sensor_dev_attr(attr)->index;<br>
- uint32_t limit = limit_type << 24;<br>
+ enum pp_power_sample_window sample_window = to_sensor_dev_attr(attr)->index;<br>
+ uint32_t limit;<br>
ssize_t size;<br>
int r;<br>
<br>
@@ -2774,7 +2774,7 @@ static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,<br>
}<br>
<br>
if (is_support_sw_smu(adev)) {<br>
- smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_CURRENT);<br>
+ smu_get_power_limit(&adev->smu, &limit, PP_PWR_LIMIT_CURRENT, <br>
+sample_window);<br>
size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
} else if (pp_funcs && pp_funcs->get_power_limit) {<br>
pp_funcs->get_power_limit(adev->powerplay.pp_handle,<br>
@@ -2796,8 +2796,8 @@ static ssize_t amdgpu_hwmon_show_power_cap_default(struct device *dev, {<br>
struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;<br>
- int limit_type = to_sensor_dev_attr(attr)->index;<br>
- uint32_t limit = limit_type << 24;<br>
+ enum pp_power_sample_window sample_window = to_sensor_dev_attr(attr)->index;<br>
+ uint32_t limit;<br>
ssize_t size;<br>
int r;<br>
<br>
@@ -2813,7 +2813,7 @@ static ssize_t amdgpu_hwmon_show_power_cap_default(struct device *dev,<br>
}<br>
<br>
if (is_support_sw_smu(adev)) {<br>
- smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_DEFAULT);<br>
+ smu_get_power_limit(&adev->smu, &limit, PP_PWR_LIMIT_DEFAULT, <br>
+sample_window);<br>
size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
} else if (pp_funcs && pp_funcs->get_power_limit) {<br>
pp_funcs->get_power_limit(adev->powerplay.pp_handle,<br>
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
index 523f9d2982e9..b97b960c2eac 100644<br>
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
@@ -1262,7 +1262,8 @@ enum smu_cmn2asic_mapping_type { #if !defined(SWSMU_CODE_LAYER_L2) && !defined(SWSMU_CODE_LAYER_L3) && !defined(SWSMU_CODE_LAYER_L4) int smu_get_power_limit(struct smu_context *smu,<br>
uint32_t *limit,<br>
- enum smu_ppt_limit_level limit_level);<br>
+ enum pp_power_limit_level pp_limit_level,<br>
+ enum pp_power_sample_window sample_window);<br>
<br>
bool smu_mode1_reset_is_support(struct smu_context *smu); bool smu_mode2_reset_is_support(struct smu_context *smu); diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
index 8aff67a667fa..44c1baa2748d 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
@@ -2168,14 +2168,44 @@ static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)<br>
<br>
int smu_get_power_limit(struct smu_context *smu,<br>
uint32_t *limit,<br>
- enum smu_ppt_limit_level limit_level)<br>
+ enum pp_power_limit_level pp_limit_level,<br>
+ enum pp_power_sample_window sample_window)<br>
{<br>
- uint32_t limit_type = *limit >> 24;<br>
+ enum smu_ppt_limit_level limit_level;<br>
+ uint32_t limit_type;<br>
int ret = 0;<br>
<br>
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)<br>
return -EOPNOTSUPP;<br>
<br>
+ switch(sample_window) {<br>
+ case PP_PWR_WINDOW_DEFAULT:<br>
+ limit_type = SMU_DEFAULT_PPT_LIMIT;<br>
+ break;<br>
+ case PP_PWR_WINDOW_FAST:<br>
+ limit_type = SMU_FAST_PPT_LIMIT;<br>
+ break;<br>
+ default:<br>
+ return -EOPNOTSUPP;<br>
+ break;<br>
+ }<br>
+<br>
+ switch(pp_limit_level){<br>
+ case PP_PWR_LIMIT_CURRENT:<br>
+ limit_level = SMU_PPT_LIMIT_CURRENT;<br>
+ break;<br>
+ case PP_PWR_LIMIT_DEFAULT:<br>
+ limit_level = SMU_PPT_LIMIT_DEFAULT;<br>
+ break;<br>
+ case PP_PWR_LIMIT_MAX:<br>
+ limit_level = SMU_PPT_LIMIT_MAX;<br>
+ break;<br>
+ case PP_PWR_LIMIT_MIN:<br>
+ default:<br>
+ return -EOPNOTSUPP;<br>
+ break;<br>
+ }<br>
+<br>
mutex_lock(&smu->mutex);<br>
<br>
if (limit_type != SMU_DEFAULT_PPT_LIMIT) {<br>
--<br>
2.25.1<br>
</div>
</span></font></div>
</div>
</body>
</html>