<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><a class="mention ms-bgc-nlr ms-fcl-b" id="OWAAM679094" href="mailto:Kenneth.Feng@amd.com">@Feng, Kenneth</a></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">please help me review this patch, this patch is reveiwed before.</p>
<p style="margin-top:0;margin-bottom:0">but this patch is missed from navi10 topic branch.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Best Regards,<br>
Kevin</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Wang, Kevin(Yang) <Kevin1.Wang@amd.com><br>
<b>Sent:</b> Tuesday, July 23, 2019 5:31:47 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>; Huang, Ray <Ray.Huang@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com>; Feng, Kenneth <Kenneth.Feng@amd.com><br>
<b>Subject:</b> [PATCH] drm/amd/powerplay: add callback function of get_thermal_temperature_range</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">1. the thermal temperature is asic related data, move the code logic to<br>
xxx_ppt.c.<br>
2. replace data structure PP_TemperatureRange with<br>
smu_temperature_range.<br>
3. change temperature uint from temp*1000 to temp (temperature uint).<br>
<br>
Signed-off-by: Kevin Wang <kevin1.wang@amd.com><br>
Signed-off-by: Kenneth Feng <kenneth.feng@amd.com><br>
Acked-by: Huang Rui <ray.huang@amd.com><br>
---<br>
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |  1 -<br>
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c    | 17 ++++++++++<br>
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c     | 18 ++++++----<br>
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c    | 34 ++++++-------------<br>
 4 files changed, 40 insertions(+), 30 deletions(-)<br>
<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 34093ddca105..7105f8041088 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
@@ -439,7 +439,6 @@ struct smu_table_context<br>
         struct smu_table                *tables;<br>
         uint32_t                        table_count;<br>
         struct smu_table                memory_pool;<br>
-       uint16_t                        software_shutdown_temp;<br>
         uint8_t                         thermal_controller_type;<br>
         uint16_t                        TDPODLimit;<br>
 <br>
diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
index 46e2913e4af4..a4c4d4997189 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
@@ -1638,6 +1638,22 @@ static int navi10_set_performance_level(struct smu_context *smu, enum amd_dpm_fo<br>
         return ret;<br>
 }<br>
 <br>
+static int navi10_get_thermal_temperature_range(struct smu_context *smu,<br>
+                                               struct smu_temperature_range *range)<br>
+{<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>
+       if (!range || !powerplay_table)<br>
+               return -EINVAL;<br>
+<br>
+       /* The unit is temperature */<br>
+       range->min = 0;<br>
+       range->max = powerplay_table->software_shutdown_temp;<br>
+<br>
+       return 0;<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>
@@ -1674,6 +1690,7 @@ static const struct pptable_funcs navi10_ppt_funcs = {<br>
         .get_ppfeature_status = navi10_get_ppfeature_status,<br>
         .set_ppfeature_status = navi10_set_ppfeature_status,<br>
         .set_performance_level = navi10_set_performance_level,<br>
+       .get_thermal_temperature_range = navi10_get_thermal_temperature_range,<br>
 };<br>
 <br>
 void navi10_set_ppt_funcs(struct smu_context *smu)<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 76bc157525d0..4ad9e0c5a637 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c<br>
@@ -1147,10 +1147,8 @@ 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>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
-       int high = SMU_THERMAL_MAXIMUM_ALERT_TEMP *<br>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
+       int low = SMU_THERMAL_MINIMUM_ALERT_TEMP;<br>
+       int high = SMU_THERMAL_MAXIMUM_ALERT_TEMP;<br>
         uint32_t val;<br>
 <br>
         if (!range)<br>
@@ -1161,6 +1159,9 @@ static int smu_v11_0_set_thermal_range(struct smu_context *smu,<br>
         if (high > range->max)<br>
                 high = range->max;<br>
 <br>
+       low = max(SMU_THERMAL_MINIMUM_ALERT_TEMP, range->min);<br>
+       high = min(SMU_THERMAL_MAXIMUM_ALERT_TEMP, range->max);<br>
+<br>
         if (low > high)<br>
                 return -EINVAL;<br>
 <br>
@@ -1169,8 +1170,8 @@ static int smu_v11_0_set_thermal_range(struct smu_context *smu,<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 / SMU_TEMPERATURE_UNITS_PER_CENTIGRADES));<br>
-       val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, (low / SMU_TEMPERATURE_UNITS_PER_CENTIGRADES));<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>
@@ -1209,7 +1210,10 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)<br>
 <br>
         if (!smu->pm_enabled)<br>
                 return ret;<br>
+<br>
         ret = smu_get_thermal_temperature_range(smu, &range);<br>
+       if (ret)<br>
+               return ret;<br>
 <br>
         if (smu->smu_table.thermal_controller_type) {<br>
                 ret = smu_v11_0_set_thermal_range(smu, &range);<br>
@@ -1234,6 +1238,8 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)<br>
         adev->pm.dpm.thermal.min_mem_temp = range.mem_min;<br>
         adev->pm.dpm.thermal.max_mem_crit_temp = range.mem_crit_max;<br>
         adev->pm.dpm.thermal.max_mem_emergency_temp = range.mem_emergency_max;<br>
+       adev->pm.dpm.thermal.min_temp = range.min * SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
+       adev->pm.dpm.thermal.max_temp = range.max * SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
 <br>
         return ret;<br>
 }<br>
diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c<br>
index bcd0efaf7bbd..deb102ffedc2 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c<br>
@@ -463,7 +463,6 @@ static int vega20_store_powerplay_table(struct smu_context *smu)<br>
         memcpy(table_context->driver_pptable, &powerplay_table->smcPPTable,<br>
                sizeof(PPTable_t));<br>
 <br>
-       table_context->software_shutdown_temp = powerplay_table->usSoftwareShutdownTemp;<br>
         table_context->thermal_controller_type = powerplay_table->ucThermalControllerType;<br>
         table_context->TDPODLimit = le32_to_cpu(powerplay_table->OverDrive8Table.ODSettingsMax[ATOM_VEGA20_ODSETTING_POWERPERCENTAGE]);<br>
 <br>
@@ -3235,35 +3234,24 @@ static int vega20_set_watermarks_table(struct smu_context *smu,<br>
         return 0;<br>
 }<br>
 <br>
-static const struct smu_temperature_range vega20_thermal_policy[] =<br>
-{<br>
-       {-273150,  99000, 99000, -273150, 99000, 99000, -273150, 99000, 99000},<br>
-       { 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000},<br>
-};<br>
-<br>
 static int vega20_get_thermal_temperature_range(struct smu_context *smu,<br>
                                                 struct smu_temperature_range*range)<br>
 {<br>
-<br>
+       struct smu_table_context *table_context = &smu->smu_table;<br>
+       ATOM_Vega20_POWERPLAYTABLE *powerplay_table = table_context->power_play_table;<br>
         PPTable_t *pptable = smu->smu_table.driver_pptable;<br>
 <br>
-       if (!range)<br>
+       if (!range || !powerplay_table)<br>
                 return -EINVAL;<br>
 <br>
-       memcpy(range, &vega20_thermal_policy[0], sizeof(struct smu_temperature_range));<br>
-<br>
-       range->max = pptable->TedgeLimit *<br>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
-       range->edge_emergency_max = (pptable->TedgeLimit + CTF_OFFSET_EDGE) *<br>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
-       range->hotspot_crit_max = pptable->ThotspotLimit *<br>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
-       range->hotspot_emergency_max = (pptable->ThotspotLimit + CTF_OFFSET_HOTSPOT) *<br>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
-       range->mem_crit_max = pptable->ThbmLimit *<br>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
-       range->mem_emergency_max = (pptable->ThbmLimit + CTF_OFFSET_HBM)*<br>
-               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
+       /* The unit is temperature */<br>
+       range->min = 0;<br>
+       range->max = powerplay_table->usSoftwareShutdownTemp;<br>
+       range->edge_emergency_max = (pptable->TedgeLimit + CTF_OFFSET_EDGE);<br>
+       range->hotspot_crit_max = pptable->ThotspotLimit;<br>
+       range->hotspot_emergency_max = (pptable->ThotspotLimit + CTF_OFFSET_HOTSPOT);<br>
+       range->mem_crit_max = pptable->ThbmLimit;<br>
+       range->mem_emergency_max = (pptable->ThbmLimit + CTF_OFFSET_HBM);<br>
 <br>
 <br>
         return 0;<br>
-- <br>
2.22.0<br>
<br>
</div>
</span></font></div>
</body>
</html>