<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:#0078D7;margin:15pt;" 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);">
Acked-by: Kevin Wang <kevin1.wang@amd.com></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);">
Best Regards,<br>
Kevin</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> Gao, Likun <Likun.Gao@amd.com><br>
<b>Sent:</b> Tuesday, June 2, 2020 5:08 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Feng, Kenneth <Kenneth.Feng@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com>; Gao, Likun <Likun.Gao@amd.com><br>
<b>Subject:</b> [PATCH] drm/amd/powerplay: move powerplay table operation out of smu_v11_0.c</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">From: Likun Gao <Likun.Gao@amd.com><br>
<br>
move smu_v11_0_get_max_power_limit and smu_v11_0_set_thermal_range<br>
function from smu_v11_0.c to asic specific _ppt.c to avoid powerplay<br>
table conflict with different ASIC with smu11.<br>
<br>
Signed-off-by: Likun Gao <Likun.Gao@amd.com><br>
Change-Id: I194f44e9f59daf19fa4758ed746fa13ccece4308<br>
---<br>
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c  | 64 ++++++++++++++++++-<br>
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |  2 +<br>
 drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h |  2 -<br>
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c    | 64 ++++++++++++++++++-<br>
 drivers/gpu/drm/amd/powerplay/smu_internal.h  |  5 ++<br>
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c     | 63 +-----------------<br>
 6 files changed, 135 insertions(+), 65 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c<br>
index 1c66b7d7139c..d5527e834a8e 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c<br>
@@ -37,6 +37,8 @@<br>
 #include "arcturus_ppsmc.h"<br>
 #include "nbio/nbio_7_4_offset.h"<br>
 #include "nbio/nbio_7_4_sh_mask.h"<br>
+#include "thm/thm_11_0_2_offset.h"<br>
+#include "thm/thm_11_0_2_sh_mask.h"<br>
 #include "amdgpu_xgmi.h"<br>
 #include <linux/i2c.h><br>
 #include <linux/pci.h><br>
@@ -1324,7 +1326,7 @@ static int arcturus_get_power_limit(struct smu_context *smu,<br>
         }<br>
 <br>
         if (cap)<br>
-               *limit = smu_v11_0_get_max_power_limit(smu);<br>
+               *limit = smu_get_max_power_limit(smu);<br>
         else<br>
                 *limit = smu->power_limit;<br>
 <br>
@@ -2286,6 +2288,64 @@ static int arcturus_set_df_cstate(struct smu_context *smu,<br>
         return smu_send_smc_msg_with_param(smu, SMU_MSG_DFCstateControl, state, NULL);<br>
 }<br>
 <br>
+static int arcturus_set_thermal_range(struct smu_context *smu,<br>
+                                      struct smu_temperature_range range)<br>
+{<br>
+       struct amdgpu_device *adev = smu->adev;<br>
+       int low = SMU_THERMAL_MINIMUM_ALERT_TEMP;<br>
+       int high = SMU_THERMAL_MAXIMUM_ALERT_TEMP;<br>
+       uint32_t val;<br>
+       struct smu_table_context *table_context = &smu->smu_table;<br>
+       struct smu_11_0_powerplay_table *powerplay_table = table_context->power_play_table;<br>
+<br>
+       low = max(SMU_THERMAL_MINIMUM_ALERT_TEMP,<br>
+                       range.min / SMU_TEMPERATURE_UNITS_PER_CENTIGRADES);<br>
+       high = min((uint16_t)SMU_THERMAL_MAXIMUM_ALERT_TEMP, powerplay_table->software_shutdown_temp);<br>
+<br>
+       if (low > high)<br>
+               return -EINVAL;<br>
+<br>
+       val = RREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, MAX_IH_CREDIT, 5);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_IH_HW_ENA, 1);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTH_MASK, 0);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTL_MASK, 0);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTH, (high & 0xff));<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, (low & 0xff));<br>
+       val = val & (~THM_THERMAL_INT_CTRL__THERM_TRIGGER_MASK_MASK);<br>
+<br>
+       WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL, val);<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static uint32_t atcturus_get_max_power_limit(struct smu_context *smu) {<br>
+       uint32_t od_limit, max_power_limit;<br>
+       struct smu_11_0_powerplay_table *powerplay_table = NULL;<br>
+       struct smu_table_context *table_context = &smu->smu_table;<br>
+       powerplay_table = table_context->power_play_table;<br>
+<br>
+       max_power_limit = smu_get_pptable_power_limit(smu);<br>
+<br>
+       if (!max_power_limit) {<br>
+               // If we couldn't get the table limit, fall back on first-read value<br>
+               if (!smu->default_power_limit)<br>
+                       smu->default_power_limit = smu->power_limit;<br>
+               max_power_limit = smu->default_power_limit;<br>
+       }<br>
+<br>
+       if (smu->od_enabled) {<br>
+               od_limit = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);<br>
+<br>
+               pr_debug("ODSETTING_POWERPERCENTAGE: %d (default: %d)\n", od_limit, smu->default_power_limit);<br>
+<br>
+               max_power_limit *= (100 + od_limit);<br>
+               max_power_limit /= 100;<br>
+       }<br>
+<br>
+       return max_power_limit;<br>
+}<br>
+<br>
 static const struct pptable_funcs arcturus_ppt_funcs = {<br>
         /* translate smu index into arcturus specific index */<br>
         .get_smu_msg_index = arcturus_get_smu_msg_index,<br>
@@ -2379,6 +2439,8 @@ static const struct pptable_funcs arcturus_ppt_funcs = {<br>
         .override_pcie_parameters = smu_v11_0_override_pcie_parameters,<br>
         .get_pptable_power_limit = arcturus_get_pptable_power_limit,<br>
         .set_df_cstate = arcturus_set_df_cstate,<br>
+       .set_thermal_range = arcturus_set_thermal_range,<br>
+       .get_max_power_limit = atcturus_get_max_power_limit,<br>
 };<br>
 <br>
 void arcturus_set_ppt_funcs(struct smu_context *smu)<br>
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
index 928eed220f93..0453482fb748 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
@@ -574,6 +574,8 @@ struct pptable_funcs {<br>
         uint32_t (*get_pptable_power_limit)(struct smu_context *smu);<br>
         int (*disable_umc_cdr_12gbps_workaround)(struct smu_context *smu);<br>
         int (*set_power_source)(struct smu_context *smu, enum smu_power_src_type power_src);<br>
+       int (*set_thermal_range)(struct smu_context *smu, struct smu_temperature_range range);<br>
+       uint32_t (*get_max_power_limit)(struct smu_context *smu);<br>
 };<br>
 <br>
 int smu_load_microcode(struct smu_context *smu);<br>
diff --git a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h<br>
index 1f5830bbcc3e..4ad3f07891fe 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h<br>
+++ b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h<br>
@@ -262,8 +262,6 @@ int smu_v11_0_override_pcie_parameters(struct smu_context *smu);<br>
 <br>
 int smu_v11_0_set_default_od_settings(struct smu_context *smu, bool initialize, size_t overdrive_table_size);<br>
 <br>
-uint32_t smu_v11_0_get_max_power_limit(struct smu_context *smu);<br>
-<br>
 int smu_v11_0_set_performance_level(struct smu_context *smu,<br>
                                     enum amd_dpm_forced_level level);<br>
 <br>
diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
index 0c9be864d072..3641f059186e 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
@@ -37,6 +37,8 @@<br>
 #include "smu_v11_0_ppsmc.h"<br>
 #include "nbio/nbio_2_3_offset.h"<br>
 #include "nbio/nbio_2_3_sh_mask.h"<br>
+#include "thm/thm_11_0_2_offset.h"<br>
+#include "thm/thm_11_0_2_sh_mask.h"<br>
 <br>
 #include "asic_reg/mp/mp_11_0_sh_mask.h"<br>
 <br>
@@ -1841,7 +1843,7 @@ static int navi10_get_power_limit(struct smu_context *smu,<br>
         }<br>
 <br>
         if (cap)<br>
-               *limit = smu_v11_0_get_max_power_limit(smu);<br>
+               *limit = smu_get_max_power_limit(smu);<br>
         else<br>
                 *limit = smu->power_limit;<br>
 <br>
@@ -2253,6 +2255,64 @@ static int navi10_disable_umc_cdr_12gbps_workaround(struct smu_context *smu)<br>
         return navi10_dummy_pstate_control(smu, true);<br>
 }<br>
 <br>
+static int navi10_set_thermal_range(struct smu_context *smu,<br>
+                                      struct smu_temperature_range range)<br>
+{<br>
+       struct amdgpu_device *adev = smu->adev;<br>
+       int low = SMU_THERMAL_MINIMUM_ALERT_TEMP;<br>
+       int high = SMU_THERMAL_MAXIMUM_ALERT_TEMP;<br>
+       uint32_t val;<br>
+       struct smu_table_context *table_context = &smu->smu_table;<br>
+       struct smu_11_0_powerplay_table *powerplay_table = table_context->power_play_table;<br>
+<br>
+       low = max(SMU_THERMAL_MINIMUM_ALERT_TEMP,<br>
+                       range.min / SMU_TEMPERATURE_UNITS_PER_CENTIGRADES);<br>
+       high = min((uint16_t)SMU_THERMAL_MAXIMUM_ALERT_TEMP, powerplay_table->software_shutdown_temp);<br>
+<br>
+       if (low > high)<br>
+               return -EINVAL;<br>
+<br>
+       val = RREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, MAX_IH_CREDIT, 5);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_IH_HW_ENA, 1);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTH_MASK, 0);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTL_MASK, 0);<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTH, (high & 0xff));<br>
+       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, (low & 0xff));<br>
+       val = val & (~THM_THERMAL_INT_CTRL__THERM_TRIGGER_MASK_MASK);<br>
+<br>
+       WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL, val);<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+static uint32_t navi10_get_max_power_limit(struct smu_context *smu) {<br>
+       uint32_t od_limit, max_power_limit;<br>
+       struct smu_11_0_powerplay_table *powerplay_table = NULL;<br>
+       struct smu_table_context *table_context = &smu->smu_table;<br>
+       powerplay_table = table_context->power_play_table;<br>
+<br>
+       max_power_limit = smu_get_pptable_power_limit(smu);<br>
+<br>
+       if (!max_power_limit) {<br>
+               // If we couldn't get the table limit, fall back on first-read value<br>
+               if (!smu->default_power_limit)<br>
+                       smu->default_power_limit = smu->power_limit;<br>
+               max_power_limit = smu->default_power_limit;<br>
+       }<br>
+<br>
+       if (smu->od_enabled) {<br>
+               od_limit = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);<br>
+<br>
+               pr_debug("ODSETTING_POWERPERCENTAGE: %d (default: %d)\n", od_limit, smu->default_power_limit);<br>
+<br>
+               max_power_limit *= (100 + od_limit);<br>
+               max_power_limit /= 100;<br>
+       }<br>
+<br>
+       return max_power_limit;<br>
+}<br>
+<br>
 static const struct pptable_funcs navi10_ppt_funcs = {<br>
         .tables_init = navi10_tables_init,<br>
         .alloc_dpm_context = navi10_allocate_dpm_context,<br>
@@ -2348,6 +2408,8 @@ static const struct pptable_funcs navi10_ppt_funcs = {<br>
         .run_btc = navi10_run_btc,<br>
         .disable_umc_cdr_12gbps_workaround = navi10_disable_umc_cdr_12gbps_workaround,<br>
         .set_power_source = smu_v11_0_set_power_source,<br>
+       .set_thermal_range = navi10_set_thermal_range,<br>
+       .get_max_power_limit = navi10_get_max_power_limit,<br>
 };<br>
 <br>
 void navi10_set_ppt_funcs(struct smu_context *smu)<br>
diff --git a/drivers/gpu/drm/amd/powerplay/smu_internal.h b/drivers/gpu/drm/amd/powerplay/smu_internal.h<br>
index c97444841abc..093b63d405e5 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/smu_internal.h<br>
+++ b/drivers/gpu/drm/amd/powerplay/smu_internal.h<br>
@@ -208,6 +208,11 @@ static inline int smu_send_smc_msg(struct smu_context *smu, enum smu_message_typ<br>
 #define smu_update_pcie_parameters(smu, pcie_gen_cap, pcie_width_cap) \<br>
                 ((smu)->ppt_funcs->update_pcie_parameters ? (smu)->ppt_funcs->update_pcie_parameters((smu), (pcie_gen_cap), (pcie_width_cap)) : 0)<br>
 <br>
+#define smu_set_thermal_range(smu, range) \<br>
+               ((smu)->ppt_funcs->set_thermal_range ? (smu)->ppt_funcs->set_thermal_range((smu), (range)) : 0)<br>
+#define smu_get_max_power_limit(smu) \<br>
+               ((smu)->ppt_funcs->get_max_power_limit ? (smu)->ppt_funcs->get_max_power_limit((smu)) : 0)<br>
+<br>
 #define smu_disable_umc_cdr_12gbps_workaround(smu) \<br>
         ((smu)->ppt_funcs->disable_umc_cdr_12gbps_workaround ? (smu)->ppt_funcs->disable_umc_cdr_12gbps_workaround((smu)) : 0)<br>
 <br>
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c<br>
index 4c2d98becc16..5133110dc5c8 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c<br>
@@ -32,7 +32,6 @@<br>
 #include "atomfirmware.h"<br>
 #include "amdgpu_atomfirmware.h"<br>
 #include "smu_v11_0.h"<br>
-#include "smu_v11_0_pptable.h"<br>
 #include "soc15_common.h"<br>
 #include "atom.h"<br>
 #include "amd_pcie.h"<br>
@@ -1093,33 +1092,6 @@ int smu_v11_0_init_max_sustainable_clocks(struct smu_context *smu)<br>
         return 0;<br>
 }<br>
 <br>
-uint32_t smu_v11_0_get_max_power_limit(struct smu_context *smu) {<br>
-       uint32_t od_limit, max_power_limit;<br>
-       struct smu_11_0_powerplay_table *powerplay_table = NULL;<br>
-       struct smu_table_context *table_context = &smu->smu_table;<br>
-       powerplay_table = table_context->power_play_table;<br>
-<br>
-       max_power_limit = smu_get_pptable_power_limit(smu);<br>
-<br>
-       if (!max_power_limit) {<br>
-               // If we couldn't get the table limit, fall back on first-read value<br>
-               if (!smu->default_power_limit)<br>
-                       smu->default_power_limit = smu->power_limit;<br>
-               max_power_limit = smu->default_power_limit;<br>
-       }<br>
-<br>
-       if (smu->od_enabled) {<br>
-               od_limit = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);<br>
-<br>
-               pr_debug("ODSETTING_POWERPERCENTAGE: %d (default: %d)\n", od_limit, smu->default_power_limit);<br>
-<br>
-               max_power_limit *= (100 + od_limit);<br>
-               max_power_limit /= 100;<br>
-       }<br>
-<br>
-       return max_power_limit;<br>
-}<br>
-<br>
 int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n)<br>
 {<br>
         int ret = 0;<br>
@@ -1128,7 +1100,7 @@ int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n)<br>
         if (amdgpu_sriov_vf(smu->adev))<br>
                 return 0;<br>
 <br>
-       max_power_limit = smu_v11_0_get_max_power_limit(smu);<br>
+       max_power_limit = smu_get_max_power_limit(smu);<br>
 <br>
         if (n > max_power_limit) {<br>
                 pr_err("New power limit (%d) is over the max allowed %d\n",<br>
@@ -1186,37 +1158,6 @@ int smu_v11_0_get_current_clk_freq(struct smu_context *smu,<br>
         return ret;<br>
 }<br>
 <br>
-static int smu_v11_0_set_thermal_range(struct smu_context *smu,<br>
-                                      struct smu_temperature_range range)<br>
-{<br>
-       struct amdgpu_device *adev = smu->adev;<br>
-       int low = SMU_THERMAL_MINIMUM_ALERT_TEMP;<br>
-       int high = SMU_THERMAL_MAXIMUM_ALERT_TEMP;<br>
-       uint32_t val;<br>
-       struct smu_table_context *table_context = &smu->smu_table;<br>
-       struct smu_11_0_powerplay_table *powerplay_table = table_context->power_play_table;<br>
-<br>
-       low = max(SMU_THERMAL_MINIMUM_ALERT_TEMP,<br>
-                       range.min / SMU_TEMPERATURE_UNITS_PER_CENTIGRADES);<br>
-       high = min((uint16_t)SMU_THERMAL_MAXIMUM_ALERT_TEMP, powerplay_table->software_shutdown_temp);<br>
-<br>
-       if (low > high)<br>
-               return -EINVAL;<br>
-<br>
-       val = RREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL);<br>
-       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, MAX_IH_CREDIT, 5);<br>
-       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_IH_HW_ENA, 1);<br>
-       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTH_MASK, 0);<br>
-       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTL_MASK, 0);<br>
-       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTH, (high & 0xff));<br>
-       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, (low & 0xff));<br>
-       val = val & (~THM_THERMAL_INT_CTRL__THERM_TRIGGER_MASK_MASK);<br>
-<br>
-       WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL, val);<br>
-<br>
-       return 0;<br>
-}<br>
-<br>
 static int smu_v11_0_enable_thermal_alert(struct smu_context *smu)<br>
 {<br>
         struct amdgpu_device *adev = smu->adev;<br>
@@ -1244,7 +1185,7 @@ int smu_v11_0_start_thermal_control(struct smu_context *smu)<br>
                 return ret;<br>
 <br>
         if (smu->smu_table.thermal_controller_type) {<br>
-               ret = smu_v11_0_set_thermal_range(smu, range);<br>
+               ret = smu_set_thermal_range(smu, range);<br>
                 if (ret)<br>
                         return ret;<br>
 <br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>