<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">
<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);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Prike Liang <Prike.Liang@amd.com><br>
<b>Sent:</b> Friday, February 18, 2022 2:04 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Liang, Prike <Prike.Liang@amd.com>; Lazar, Lijo <Lijo.Lazar@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Quan, Evan <Evan.Quan@amd.com><br>
<b>Subject:</b> [PATCH v2] drm/amd/pm: validate SMU feature enable message for getting feature enabled mask</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">There's always miss the SMU feature enabled checked in the NPI phase,<br>
so let validate the SMU feature enable message directly rather than<br>
add more and more MP1 version check.<br>
<br>
Signed-off-by: Prike Liang <Prike.Liang@amd.com><br>
Signed-off-by: Lijo Lazar <Lijo.Lazar@amd.com><br>
---<br>
 .../amd/pm/swsmu/smu11/cyan_skillfish_ppt.c   | 12 ++++-<br>
 .../gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c   | 12 ++++-<br>
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c        | 48 ++++++++-----------<br>
 3 files changed, 43 insertions(+), 29 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/cyan_skillfish_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/cyan_skillfish_ppt.c<br>
index b3a0f3fb3e65..f1a4a720d426 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/cyan_skillfish_ppt.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/cyan_skillfish_ppt.c<br>
@@ -552,6 +552,16 @@ static int cyan_skillfish_get_dpm_ultimate_freq(struct smu_context *smu,<br>
         return 0;<br>
 }<br>
 <br>
+static int cyan_skillfish_get_enabled_mask(struct smu_context *smu,<br>
+                                          uint64_t *feature_mask)<br>
+{<br>
+       if (!feature_mask)<br>
+               return -EINVAL;<br>
+       memset(feature_mask, 0xff, sizeof(*feature_mask));<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
 static const struct pptable_funcs cyan_skillfish_ppt_funcs = {<br>
 <br>
         .check_fw_status = smu_v11_0_check_fw_status,<br>
@@ -562,7 +572,7 @@ static const struct pptable_funcs cyan_skillfish_ppt_funcs = {<br>
         .fini_smc_tables = smu_v11_0_fini_smc_tables,<br>
         .read_sensor = cyan_skillfish_read_sensor,<br>
         .print_clk_levels = cyan_skillfish_print_clk_levels,<br>
-       .get_enabled_mask = smu_cmn_get_enabled_mask,<br>
+       .get_enabled_mask = cyan_skillfish_get_enabled_mask,<br>
         .is_dpm_running = cyan_skillfish_is_dpm_running,<br>
         .get_gpu_metrics = cyan_skillfish_get_gpu_metrics,<br>
         .od_edit_dpm_table = cyan_skillfish_od_edit_dpm_table,<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c<br>
index e99e7b2bf25b..fd6c44ece168 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c<br>
@@ -1366,6 +1366,16 @@ static int renoir_gfx_state_change_set(struct smu_context *smu, uint32_t state)<br>
         return 0;<br>
 }<br>
 <br>
+static int renoir_get_enabled_mask(struct smu_context *smu,<br>
+                                  uint64_t *feature_mask)<br>
+{<br>
+       if (!feature_mask)<br>
+               return -EINVAL;<br>
+       memset(feature_mask, 0xff, sizeof(*feature_mask));<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
 static const struct pptable_funcs renoir_ppt_funcs = {<br>
         .set_power_state = NULL,<br>
         .print_clk_levels = renoir_print_clk_levels,<br>
@@ -1390,7 +1400,7 @@ static const struct pptable_funcs renoir_ppt_funcs = {<br>
         .init_smc_tables = renoir_init_smc_tables,<br>
         .fini_smc_tables = smu_v12_0_fini_smc_tables,<br>
         .set_default_dpm_table = smu_v12_0_set_default_dpm_tables,<br>
-       .get_enabled_mask = smu_cmn_get_enabled_mask,<br>
+       .get_enabled_mask = renoir_get_enabled_mask,<br>
         .feature_is_enabled = smu_cmn_feature_is_enabled,<br>
         .disable_all_features_with_exception = smu_cmn_disable_all_features_with_exception,<br>
         .get_dpm_ultimate_freq = renoir_get_dpm_ultimate_freq,<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c<br>
index f24111d28290..33151983d9ea 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c<br>
@@ -59,6 +59,12 @@ static const char * const __smu_message_names[] = {<br>
         SMU_MESSAGE_TYPES<br>
 };<br>
 <br>
+#define smu_cmn_call_asic_func(intf, smu, args...)                             \<br>
+       ((smu)->ppt_funcs ? ((smu)->ppt_funcs->intf ?                          \<br>
+                                    (smu)->ppt_funcs->intf(smu, ##args) :     \<br>
+                                    -ENOTSUPP) :                              \<br>
+                           -EINVAL)<br>
+<br>
 static const char *smu_get_message_name(struct smu_context *smu,<br>
                                         enum smu_message_type type)<br>
 {<br>
@@ -493,6 +499,12 @@ int smu_cmn_feature_is_supported(struct smu_context *smu,<br>
         return test_bit(feature_id, feature->supported);<br>
 }<br>
 <br>
+int __smu_get_enabled_features(struct smu_context *smu,<br>
+                              uint64_t *enabled_features)<br>
+{<br>
+       return smu_cmn_call_asic_func(get_enabled_mask, smu, enabled_features);<br>
+}<br>
+<br>
 int smu_cmn_feature_is_enabled(struct smu_context *smu,<br>
                                enum smu_feature_mask mask)<br>
 {<br>
@@ -500,7 +512,7 @@ int smu_cmn_feature_is_enabled(struct smu_context *smu,<br>
         uint64_t enabled_features;<br>
         int feature_id;<br>
 <br>
-       if (smu_cmn_get_enabled_mask(smu, &enabled_features)) {<br>
+       if (__smu_get_enabled_features(smu, &enabled_features)) {<br>
                 dev_err(adev->dev, "Failed to retrieve enabled ppfeatures!\n");<br>
                 return 0;<br>
         }<br>
@@ -552,10 +564,9 @@ bool smu_cmn_clk_dpm_is_enabled(struct smu_context *smu,<br>
 int smu_cmn_get_enabled_mask(struct smu_context *smu,<br>
                              uint64_t *feature_mask)<br>
 {<br>
-       struct amdgpu_device *adev = smu->adev;<br>
         uint32_t *feature_mask_high;<br>
         uint32_t *feature_mask_low;<br>
-       int ret = 0;<br>
+       int ret = 0, index = 0;<br>
 <br>
         if (!feature_mask)<br>
                 return -EINVAL;<br>
@@ -563,12 +574,10 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,<br>
         feature_mask_low = &((uint32_t *)feature_mask)[0];<br>
         feature_mask_high = &((uint32_t *)feature_mask)[1];<br>
 <br>
-       switch (adev->ip_versions[MP1_HWIP][0]) {<br>
-       /* For Vangogh and Yellow Carp */<br>
-       case IP_VERSION(11, 5, 0):<br>
-       case IP_VERSION(13, 0, 1):<br>
-       case IP_VERSION(13, 0, 3):<br>
-       case IP_VERSION(13, 0, 8):<br>
+       index = smu_cmn_to_asic_specific_index(smu,<br>
+                                               CMN2ASIC_MAPPING_MSG,<br>
+                                               SMU_MSG_GetEnabledSmuFeatures);<br>
+       if (index > 0) {<br>
                 ret = smu_cmn_send_smc_msg_with_param(smu,<br>
                                                       SMU_MSG_GetEnabledSmuFeatures,<br>
                                                       0,<br>
@@ -580,19 +589,7 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,<br>
                                                       SMU_MSG_GetEnabledSmuFeatures,<br>
                                                       1,<br>
                                                       feature_mask_high);<br>
-               break;<br>
-       /*<br>
-        * For Cyan Skillfish and Renoir, there is no interface provided by PMFW<br>
-        * to retrieve the enabled features. So, we assume all features are enabled.<br>
-        * TODO: add other APU ASICs which suffer from the same issue here<br>
-        */<br>
-       case IP_VERSION(11, 0, 8):<br>
-       case IP_VERSION(12, 0, 0):<br>
-       case IP_VERSION(12, 0, 1):<br>
-               memset(feature_mask, 0xff, sizeof(*feature_mask));<br>
-               break;<br>
-       /* other dGPU ASICs */<br>
-       default:<br>
+       } else {<br>
                 ret = smu_cmn_send_smc_msg(smu,<br>
                                            SMU_MSG_GetEnabledSmuFeaturesHigh,<br>
                                            feature_mask_high);<br>
@@ -602,7 +599,6 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,<br>
                 ret = smu_cmn_send_smc_msg(smu,<br>
                                            SMU_MSG_GetEnabledSmuFeaturesLow,<br>
                                            feature_mask_low);<br>
-               break;<br>
         }<br>
 <br>
         return ret;<br>
@@ -696,8 +692,7 @@ size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,<br>
         int ret = 0, i;<br>
         int feature_id;<br>
 <br>
-       ret = smu_cmn_get_enabled_mask(smu,<br>
-                                      &feature_mask);<br>
+       ret = __smu_get_enabled_features(smu, &feature_mask);<br>
         if (ret)<br>
                 return 0;<br>
 <br>
@@ -749,8 +744,7 @@ int smu_cmn_set_pp_feature_mask(struct smu_context *smu,<br>
         uint64_t feature_2_enabled = 0;<br>
         uint64_t feature_2_disabled = 0;<br>
 <br>
-       ret = smu_cmn_get_enabled_mask(smu,<br>
-                                      &feature_mask);<br>
+       ret = __smu_get_enabled_features(smu, &feature_mask);<br>
         if (ret)<br>
                 return ret;<br>
 <br>
-- <br>
2.17.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>