<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:11pt;color:#0078D7;margin:5pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<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>
<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> Du, Xiaojian <Xiaojian.Du@amd.com><br>
<b>Sent:</b> Wednesday, January 13, 2021 7:22 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Huang, Ray <Ray.Huang@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Lazar, Lijo <Lijo.Lazar@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com>; Du, Xiaojian <Xiaojian.Du@amd.com><br>
<b>Subject:</b> [PATCH 2/2] drm/amd/pm: modify the fine grain tuning function for vangogh</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">This patch is to modify the fine grain tuning function for vangogh.<br>
It is risky to add two new flags to common smu struct.<br>
So this patch uses the existing old flag to make the two sysfs files<br>
work separately -- "power_dpm_force_performance_level" and<br>
"pp_od_clk_voltage".<br>
Only the power_dpm_force_performance_level is switched to "manual"<br>
mode, the fine grain tuning function will be started.<br>
In other mode, including "high","low","min_sclk","min_mclk",<br>
"standard" and "peak", the fine grain tuning function will be shut down,<br>
and the frequency range of gfx and cpu clock will be restored the<br>
default values.<br>
<br>
Signed-off-by: Xiaojian Du <Xiaojian.Du@amd.com><br>
---<br>
 drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h       |  3 --<br>
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  2 -<br>
 .../gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c  | 52 +++++++++++++++++--<br>
 3 files changed, 48 insertions(+), 9 deletions(-)<br>
<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 277559e80961..25ee9f51813b 100644<br>
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
@@ -466,9 +466,6 @@ struct smu_context<br>
         uint32_t gfx_actual_hard_min_freq;<br>
         uint32_t gfx_actual_soft_max_freq;<br>
 <br>
-       bool fine_grain_enabled;<br>
-       bool fine_grain_started;<br>
-</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[Kevin]:</div>
<div class="PlainText">the above codes should be merge into previous patch.</div>
<div class="PlainText">with the fixed, the patch is</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">Reviewed-by: Kevin Wang <kevin1.wang@amd.com></div>
<div class="PlainText"><br>
</div>
<div class="PlainText">Best Regards,<br>
Kevin</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">         uint32_t cpu_default_soft_min_freq;<br>
         uint32_t cpu_default_soft_max_freq;<br>
         uint32_t cpu_actual_soft_min_freq;<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
index 976a9105aecc..7fe61ad3ed10 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
@@ -419,8 +419,6 @@ static int smu_set_funcs(struct amdgpu_device *adev)<br>
                 break;<br>
         case CHIP_VANGOGH:<br>
                 vangogh_set_ppt_funcs(smu);<br>
-               /* enable the OD by default to allow the fine grain tuning function */<br>
-               smu->od_enabled = true;<br>
                 break;<br>
         default:<br>
                 return -EINVAL;<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c<br>
index b49044825680..3e32b223d47b 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c<br>
@@ -438,6 +438,7 @@ static int vangogh_print_fine_grain_clk(struct smu_context *smu,<br>
 {<br>
         DpmClocks_t *clk_table = smu->smu_table.clocks_table;<br>
         SmuMetrics_t metrics;<br>
+       struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);<br>
         int i, size = 0, ret = 0;<br>
         uint32_t cur_value = 0, value = 0, count = 0;<br>
         bool cur_value_match_level = false;<br>
@@ -450,7 +451,7 @@ static int vangogh_print_fine_grain_clk(struct smu_context *smu,<br>
 <br>
         switch (clk_type) {<br>
         case SMU_OD_SCLK:<br>
-               if (smu->od_enabled) {<br>
+               if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) {<br>
                         size = sprintf(buf, "%s:\n", "OD_SCLK");<br>
                         size += sprintf(buf + size, "0: %10uMhz\n",<br>
                         (smu->gfx_actual_hard_min_freq > 0) ? smu->gfx_actual_hard_min_freq : smu->gfx_default_hard_min_freq);<br>
@@ -459,7 +460,7 @@ static int vangogh_print_fine_grain_clk(struct smu_context *smu,<br>
                 }<br>
                 break;<br>
         case SMU_OD_CCLK:<br>
-               if (smu->od_enabled) {<br>
+               if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) {<br>
                         size = sprintf(buf, "CCLK_RANGE in Core%d:\n",  smu->cpu_core_id_select);<br>
                         size += sprintf(buf + size, "0: %10uMhz\n",<br>
                         (smu->cpu_actual_soft_min_freq > 0) ? smu->cpu_actual_soft_min_freq : smu->cpu_default_soft_min_freq);<br>
@@ -468,7 +469,7 @@ static int vangogh_print_fine_grain_clk(struct smu_context *smu,<br>
                 }<br>
                 break;<br>
         case SMU_OD_RANGE:<br>
-               if (smu->od_enabled) {<br>
+               if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) {<br>
                         size = sprintf(buf, "%s:\n", "OD_RANGE");<br>
                         size += sprintf(buf + size, "SCLK: %7uMhz %10uMhz\n",<br>
                                 smu->gfx_default_hard_min_freq, smu->gfx_default_soft_max_freq);<br>
@@ -1127,15 +1128,39 @@ static int vangogh_set_performance_level(struct smu_context *smu,<br>
 <br>
         switch (level) {<br>
         case AMD_DPM_FORCED_LEVEL_HIGH:<br>
+               smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;<br>
+               smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;<br>
+<br>
+               smu->cpu_actual_soft_min_freq = smu->cpu_default_soft_min_freq;<br>
+               smu->cpu_actual_soft_max_freq = smu->cpu_default_soft_max_freq;<br>
+<br>
                 ret = vangogh_force_dpm_limit_value(smu, true);<br>
                 break;<br>
         case AMD_DPM_FORCED_LEVEL_LOW:<br>
+               smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;<br>
+               smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;<br>
+<br>
+               smu->cpu_actual_soft_min_freq = smu->cpu_default_soft_min_freq;<br>
+               smu->cpu_actual_soft_max_freq = smu->cpu_default_soft_max_freq;<br>
+<br>
                 ret = vangogh_force_dpm_limit_value(smu, false);<br>
                 break;<br>
         case AMD_DPM_FORCED_LEVEL_AUTO:<br>
+               smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;<br>
+               smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;<br>
+<br>
+               smu->cpu_actual_soft_min_freq = smu->cpu_default_soft_min_freq;<br>
+               smu->cpu_actual_soft_max_freq = smu->cpu_default_soft_max_freq;<br>
+<br>
                 ret = vangogh_unforce_dpm_levels(smu);<br>
                 break;<br>
         case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:<br>
+               smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;<br>
+               smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;<br>
+<br>
+               smu->cpu_actual_soft_min_freq = smu->cpu_default_soft_min_freq;<br>
+               smu->cpu_actual_soft_max_freq = smu->cpu_default_soft_max_freq;<br>
+<br>
                 ret = smu_cmn_send_smc_msg_with_param(smu,<br>
                                         SMU_MSG_SetHardMinGfxClk,<br>
                                         VANGOGH_UMD_PSTATE_STANDARD_GFXCLK, NULL);<br>
@@ -1165,6 +1190,12 @@ static int vangogh_set_performance_level(struct smu_context *smu,<br>
 <br>
                 break;<br>
         case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:<br>
+               smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;<br>
+               smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;<br>
+<br>
+               smu->cpu_actual_soft_min_freq = smu->cpu_default_soft_min_freq;<br>
+               smu->cpu_actual_soft_max_freq = smu->cpu_default_soft_max_freq;<br>
+<br>
                 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinVcn,<br>
                                                                 VANGOGH_UMD_PSTATE_PEAK_DCLK, NULL);<br>
                 if (ret)<br>
@@ -1176,6 +1207,12 @@ static int vangogh_set_performance_level(struct smu_context *smu,<br>
                         return ret;<br>
                 break;<br>
         case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:<br>
+               smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;<br>
+               smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;<br>
+<br>
+               smu->cpu_actual_soft_min_freq = smu->cpu_default_soft_min_freq;<br>
+               smu->cpu_actual_soft_max_freq = smu->cpu_default_soft_max_freq;<br>
+<br>
                 ret = vangogh_get_profiling_clk_mask(smu, level,<br>
                                                         NULL,<br>
                                                         NULL,<br>
@@ -1189,6 +1226,12 @@ static int vangogh_set_performance_level(struct smu_context *smu,<br>
                 vangogh_force_clk_levels(smu, SMU_FCLK, 1 << fclk_mask);<br>
                 break;<br>
         case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:<br>
+               smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;<br>
+               smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;<br>
+<br>
+               smu->cpu_actual_soft_min_freq = smu->cpu_default_soft_min_freq;<br>
+               smu->cpu_actual_soft_max_freq = smu->cpu_default_soft_max_freq;<br>
+<br>
                 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinGfxClk,<br>
                                 VANGOGH_UMD_PSTATE_PEAK_GFXCLK, NULL);<br>
                 if (ret)<br>
@@ -1401,8 +1444,9 @@ static int vangogh_od_edit_dpm_table(struct smu_context *smu, enum PP_OD_DPM_TAB<br>
 {<br>
         int ret = 0;<br>
         int i;<br>
+       struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);<br>
 <br>
-       if (!smu->od_enabled) {<br>
+       if (!(smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)) {<br>
                 dev_warn(smu->adev->dev, "Fine grain is not enabled!\n");<br>
                 return -EINVAL;<br>
         }<br>
-- <br>
2.17.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>