Skip to contentSkip to conversation

drm/amd/pm: validate SMU feature enable message for getting feature enabled mask

PATCH Superseded Prike Liang 2 participants 6 messages Feb 18, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/pm: validate SMU feature enable message for getting feature enabled mask

There's always miss the SMU feature enabled checked in the NPI phase, so let validate the SMU feature enable message directly rather than add more and more MP1 version check.

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 28 ++++++--------------------
 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +6 -22
index f24111d28290..da1ac70ed455 100644
@@ -552,10 +552,9 @@ bool smu_cmn_clk_dpm_is_enabled(struct smu_context *smu,
 int smu_cmn_get_enabled_mask(struct smu_context *smu,
 			     uint64_t *feature_mask)
 {
-	struct amdgpu_device *adev = smu->adev;
 	uint32_t *feature_mask_high;
 	uint32_t *feature_mask_low;
-	int ret = 0;
+	int ret = 0, index = 0;
 
 	if (!feature_mask)
 		return -EINVAL;
@@ -563,12 +562,10 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,
 	feature_mask_low = &((uint32_t *)feature_mask)[0];
 	feature_mask_high = &((uint32_t *)feature_mask)[1];
 
-	switch (adev->ip_versions[MP1_HWIP][0]) {
-	/* For Vangogh and Yellow Carp */
-	case IP_VERSION(11, 5, 0):
-	case IP_VERSION(13, 0, 1):
-	case IP_VERSION(13, 0, 3):
-	case IP_VERSION(13, 0, 8):
+	index = smu_cmn_to_asic_specific_index(smu,
+						CMN2ASIC_MAPPING_MSG,
+						SMU_MSG_GetEnabledSmuFeatures);
+	if (index > 0) {
 		ret = smu_cmn_send_smc_msg_with_param(smu,
 						      SMU_MSG_GetEnabledSmuFeatures,
 						      0,
@@ -580,19 +577,7 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,
 						      SMU_MSG_GetEnabledSmuFeatures,
 						      1,
 						      feature_mask_high);
-		break;
-	/*
-	 * For Cyan Skillfish and Renoir, there is no interface provided by PMFW
-	 * to retrieve the enabled features. So, we assume all features are enabled.
-	 * TODO: add other APU ASICs which suffer from the same issue here
-	 */
-	case IP_VERSION(11, 0, 8):
-	case IP_VERSION(12, 0, 0):
-	case IP_VERSION(12, 0, 1):
-		memset(feature_mask, 0xff, sizeof(*feature_mask));
-		break;
-	/* other dGPU ASICs */
-	default:
+	} else {
 		ret = smu_cmn_send_smc_msg(smu,
 					   SMU_MSG_GetEnabledSmuFeaturesHigh,
 					   feature_mask_high);
@@ -602,7 +587,6 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,
 		ret = smu_cmn_send_smc_msg(smu,
 					   SMU_MSG_GetEnabledSmuFeaturesLow,
 					   feature_mask_low);
-		break;
 	}
 
 	return ret;
Signature · 1 line
2.17.1
#1 lore raw

[Public]

Please ignore this patch for the moment and seems need take care the RN series for a special case.

Quoted 95 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Friday, February 18, 2022 11:55 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; Huang, Ray <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH] drm/amd/pm: validate SMU feature enable message for getting feature enabled mask

There's always miss the SMU feature enabled checked in the NPI phase, so let validate the SMU feature enable message directly rather than add more and more MP1 version check.

---
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 28 ++++++--------------------
 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
index f24111d28290..da1ac70ed455 100644
@@ -552,10 +552,9 @@ bool smu_cmn_clk_dpm_is_enabled(struct

smu_context *smu, int smu_cmn_get_enabled_mask(struct smu_context *smu,

                           uint64_t *feature_mask)

{

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +5 -8
-     struct amdgpu_device *adev = smu->adev;
      uint32_t *feature_mask_high;
      uint32_t *feature_mask_low;
-     int ret = 0;
+     int ret = 0, index = 0;
 
      if (!feature_mask)
              return -EINVAL;
@@ -563,12 +562,10 @@ int smu_cmn_get_enabled_mask(struct
 smu_context *smu,
      feature_mask_low = &((uint32_t *)feature_mask)[0];
      feature_mask_high = &((uint32_t *)feature_mask)[1];
 
-     switch (adev->ip_versions[MP1_HWIP][0]) {
-     /* For Vangogh and Yellow Carp */
-     case IP_VERSION(11, 5, 0):
-     case IP_VERSION(13, 0, 1):
-     case IP_VERSION(13, 0, 3):
-     case IP_VERSION(13, 0, 8):
+     index = smu_cmn_to_asic_specific_index(smu,
+                                             CMN2ASIC_MAPPING_MSG,
+
      SMU_MSG_GetEnabledSmuFeatures);
+     if (index > 0) {
              ret = smu_cmn_send_smc_msg_with_param(smu,

SMU_MSG_GetEnabledSmuFeatures,

                                                    0,
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -3
@@ -580,19 +577,7 @@ int smu_cmn_get_enabled_mask(struct
 smu_context *smu,
 
 SMU_MSG_GetEnabledSmuFeatures,
                                                    1,
                                                    feature_mask_high);
-             break;
-     /*
-      * For Cyan Skillfish and Renoir, there is no interface provided by

PMFW
- * to retrieve the enabled features. So, we assume all features are
enabled.

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -9
-      * TODO: add other APU ASICs which suffer from the same issue here
-      */
-     case IP_VERSION(11, 0, 8):
-     case IP_VERSION(12, 0, 0):
-     case IP_VERSION(12, 0, 1):
-             memset(feature_mask, 0xff, sizeof(*feature_mask));
-             break;
-     /* other dGPU ASICs */
-     default:
+     } else {
              ret = smu_cmn_send_smc_msg(smu,

SMU_MSG_GetEnabledSmuFeaturesHigh,

                                         feature_mask_high);
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -1
@@ -602,7 +587,6 @@ int smu_cmn_get_enabled_mask(struct smu_context
 *smu,
              ret = smu_cmn_send_smc_msg(smu,
 
 SMU_MSG_GetEnabledSmuFeaturesLow,
                                         feature_mask_low);
-             break;
      }
      return ret;

--
2.17.1

#2 lore raw
In reply to Prike Liang
Quoted 47 lines · Prike Liang

There's always miss the SMU feature enabled checked in the NPI phase, so let validate the SMU feature enable message directly rather than add more and more MP1 version check.

---
  drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 28 ++++++--------------------
  1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +5 -9
index f24111d28290..da1ac70ed455 100644
@@ -552,10 +552,9 @@ bool smu_cmn_clk_dpm_is_enabled(struct smu_context *smu,
  int smu_cmn_get_enabled_mask(struct smu_context *smu,
  			     uint64_t *feature_mask)
  {
-	struct amdgpu_device *adev = smu->adev;
  	uint32_t *feature_mask_high;
  	uint32_t *feature_mask_low;
-	int ret = 0;
+	int ret = 0, index = 0;
 
  	if (!feature_mask)
  		return -EINVAL;
@@ -563,12 +562,10 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,
  	feature_mask_low = &((uint32_t *)feature_mask)[0];
  	feature_mask_high = &((uint32_t *)feature_mask)[1];
 
-	switch (adev->ip_versions[MP1_HWIP][0]) {
-	/* For Vangogh and Yellow Carp */
-	case IP_VERSION(11, 5, 0):
-	case IP_VERSION(13, 0, 1):
-	case IP_VERSION(13, 0, 3):
-	case IP_VERSION(13, 0, 8):
+	index = smu_cmn_to_asic_specific_index(smu,
+						CMN2ASIC_MAPPING_MSG,
+						SMU_MSG_GetEnabledSmuFeatures);
+	if (index > 0) {
  		ret = smu_cmn_send_smc_msg_with_param(smu,
  						      SMU_MSG_GetEnabledSmuFeatures,
  						      0,
@@ -580,19 +577,7 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,
  						      SMU_MSG_GetEnabledSmuFeatures,
  						      1,
  						      feature_mask_high);
-		break;

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct smu_context *smu, · line 593

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -10
-	/*
-	 * For Cyan Skillfish and Renoir, there is no interface provided by PMFW
-	 * to retrieve the enabled features. So, we assume all features are enabled.
-	 * TODO: add other APU ASICs which suffer from the same issue here
-	 */
-	case IP_VERSION(11, 0, 8):
-	case IP_VERSION(12, 0, 0):
-	case IP_VERSION(12, 0, 1):
-		memset(feature_mask, 0xff, sizeof(*feature_mask));
-		break;

This is broken now as these ASICs don't support any message. It is best to take out smu_cmn_get_enabled_mask altogether and move to smu_v*.c or *_ppt.c as this is a callback function.

Thanks,
Lijo

Quoted 15 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -3
-	/* other dGPU ASICs */
-	default:
+	} else {
  		ret = smu_cmn_send_smc_msg(smu,
  					   SMU_MSG_GetEnabledSmuFeaturesHigh,
  					   feature_mask_high);
@@ -602,7 +587,6 @@ int smu_cmn_get_enabled_mask(struct smu_context *smu,
  		ret = smu_cmn_send_smc_msg(smu,
  					   SMU_MSG_GetEnabledSmuFeaturesLow,
  					   feature_mask_low);
-		break;
  	}
 
  	return ret;
#3 lore raw

[Public]

Quoted 80 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, February 18, 2022 12:05 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: validate SMU feature enable message for getting feature enabled mask

Quoted 7 lines · Prike Liang

There's always miss the SMU feature enabled checked in the NPI phase, so let validate the SMU feature enable message directly rather than add more and more MP1 version check.

---
  drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 28 ++++++-------------------

-

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c bool smu_cmn_clk_dpm_is_enabled(struct

Quoted 8 lines
  1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
index f24111d28290..da1ac70ed455 100644
@@ -552,10 +552,9 @@ bool smu_cmn_clk_dpm_is_enabled(struct

smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
  int smu_cmn_get_enabled_mask(struct smu_context *smu,
                         uint64_t *feature_mask)
  {
-   struct amdgpu_device *adev = smu->adev;
    uint32_t *feature_mask_high;
    uint32_t *feature_mask_low;
-   int ret = 0;
+   int ret = 0, index = 0;
 
    if (!feature_mask)
            return -EINVAL;
@@ -563,12 +562,10 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct smu_context *smu,

Quoted 12 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +3 -6
    feature_mask_low = &((uint32_t *)feature_mask)[0];
    feature_mask_high = &((uint32_t *)feature_mask)[1];
 
-   switch (adev->ip_versions[MP1_HWIP][0]) {
-   /* For Vangogh and Yellow Carp */
-   case IP_VERSION(11, 5, 0):
-   case IP_VERSION(13, 0, 1):
-   case IP_VERSION(13, 0, 3):
-   case IP_VERSION(13, 0, 8):
+   index = smu_cmn_to_asic_specific_index(smu,
+                                           CMN2ASIC_MAPPING_MSG,
+
      SMU_MSG_GetEnabledSmuFeatures);

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct smu_context *smu,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -0
+   if (index > 0) {
            ret = smu_cmn_send_smc_msg_with_param(smu,
 

SMU_MSG_GetEnabledSmuFeatures,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
                                                  0,
@@ -580,19 +577,7 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

Quoted 1 line

SMU_MSG_GetEnabledSmuFeatures,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct smu_context *smu,

Quoted 5 lines
                                                  1,
                                                  feature_mask_high);
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -3
-           break;
-   /*
-    * For Cyan Skillfish and Renoir, there is no interface provided by

PMFW

Quoted 1 line

- * to retrieve the enabled features. So, we assume all features are

enabled.

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct smu_context *smu, · line 593

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -7
-    * TODO: add other APU ASICs which suffer from the same issue here
-    */
-   case IP_VERSION(11, 0, 8):
-   case IP_VERSION(12, 0, 0):
-   case IP_VERSION(12, 0, 1):
-           memset(feature_mask, 0xff, sizeof(*feature_mask));
-           break;
Quoted 7 lines

This is broken now as these ASICs don't support any message. It is best to take out smu_cmn_get_enabled_mask altogether and move to smu_v*.c or *_ppt.c as this is a callback function.

Thanks,
Lijo

Before this solution I also consider put the smu_cmn_get_enabled_mask implementation in each *_ppt directly, but seems need some effort for implementing on each *_ppt. How about we also check the SMU_MSG_GetEnabledSmuFeaturesHigh mapping index? As to the ASCI not support neither SMU_MSG_GetEnabledSmuFeatures nor SMU_MSG_GetEnabledSmuFeaturesHigh will hard code the feature mask in this case.

Quoted 18 lines

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct smu_context *smu, · line 581

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
-   /* other dGPU ASICs */
-   default:
+   } else {
            ret = smu_cmn_send_smc_msg(smu,

SMU_MSG_GetEnabledSmuFeaturesHigh,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 2 lines
                                       feature_mask_high);
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
@@ -602,7 +587,6 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct smu_context *smu, · line 591

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
            ret = smu_cmn_send_smc_msg(smu,
 

SMU_MSG_GetEnabledSmuFeaturesLow,

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -1
                                       feature_mask_low);
-           break;
    }
 
    return ret;
#4 lore raw
Quoted 82 lines · Prike

[Public]

Quoted 80 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, February 18, 2022 12:05 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: validate SMU feature enable message for getting feature enabled mask

Quoted 7 lines · Prike Liang

There's always miss the SMU feature enabled checked in the NPI phase, so let validate the SMU feature enable message directly rather than add more and more MP1 version check.

---
   drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 28 ++++++-------------------

-

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c bool smu_cmn_clk_dpm_is_enabled(struct

Quoted 8 lines
   1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
index f24111d28290..da1ac70ed455 100644
@@ -552,10 +552,9 @@ bool smu_cmn_clk_dpm_is_enabled(struct

smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
   int smu_cmn_get_enabled_mask(struct smu_context *smu,
                          uint64_t *feature_mask)
   {
-   struct amdgpu_device *adev = smu->adev;
     uint32_t *feature_mask_high;
     uint32_t *feature_mask_low;
-   int ret = 0;
+   int ret = 0, index = 0;
 
     if (!feature_mask)
             return -EINVAL;
@@ -563,12 +562,10 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct · line 567

Quoted 12 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +3 -6
     feature_mask_low = &((uint32_t *)feature_mask)[0];
     feature_mask_high = &((uint32_t *)feature_mask)[1];
 
-   switch (adev->ip_versions[MP1_HWIP][0]) {
-   /* For Vangogh and Yellow Carp */
-   case IP_VERSION(11, 5, 0):
-   case IP_VERSION(13, 0, 1):
-   case IP_VERSION(13, 0, 3):
-   case IP_VERSION(13, 0, 8):
+   index = smu_cmn_to_asic_specific_index(smu,
+                                           CMN2ASIC_MAPPING_MSG,
+
       SMU_MSG_GetEnabledSmuFeatures);

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct · line 570

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -0
+   if (index > 0) {
             ret = smu_cmn_send_smc_msg_with_param(smu,
 

SMU_MSG_GetEnabledSmuFeatures,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
                                                   0,
@@ -580,19 +577,7 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

Quoted 1 line

SMU_MSG_GetEnabledSmuFeatures,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c

Quoted 5 lines
                                                   1,
                                                   feature_mask_high);
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -3
-           break;
-   /*
-    * For Cyan Skillfish and Renoir, there is no interface provided by

PMFW

Quoted 1 line

- * to retrieve the enabled features. So, we assume all features are

enabled.

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -7
-    * TODO: add other APU ASICs which suffer from the same issue here
-    */
-   case IP_VERSION(11, 0, 8):
-   case IP_VERSION(12, 0, 0):
-   case IP_VERSION(12, 0, 1):
-           memset(feature_mask, 0xff, sizeof(*feature_mask));
-           break;
Quoted 9 lines
Quoted 7 lines

This is broken now as these ASICs don't support any message. It is best to take out smu_cmn_get_enabled_mask altogether and move to smu_v*.c or *_ppt.c as this is a callback function.

Thanks,
Lijo

Before this solution I also consider put the smu_cmn_get_enabled_mask implementation in each *_ppt directly, but seems need some effort for implementing on each *_ppt. How about we also check the SMU_MSG_GetEnabledSmuFeaturesHigh mapping index? As to the ASCI not support neither SMU_MSG_GetEnabledSmuFeatures nor SMU_MSG_GetEnabledSmuFeaturesHigh will hard code the feature mask in this case.

Something like attached refactoring and then for the rest you could apply your patch.

Thanks,
Lijo

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
-   /* other dGPU ASICs */
-   default:
+   } else {
             ret = smu_cmn_send_smc_msg(smu,

SMU_MSG_GetEnabledSmuFeaturesHigh,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 2 lines
                                        feature_mask_high);
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
@@ -602,7 +587,6 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
             ret = smu_cmn_send_smc_msg(smu,
 
Quoted 7 lines
Quoted 7 lines

SMU_MSG_GetEnabledSmuFeaturesLow,

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -1
                                        feature_mask_low);
-           break;
     }
 
     return ret;
drivers/gpu/drm/amd/pm/swsmu/smu11/cyan_skillfish_ppt.c +11 -1
index b3a0f3fb3e65..f1a4a720d426 100644
@@ -552,6 +552,16 @@ static int cyan_skillfish_get_dpm_ultimate_freq(struct smu_context *smu,
 	return 0;
 }
 
+static int cyan_skillfish_get_enabled_mask(struct smu_context *smu,
+					   uint64_t *feature_mask)
+{
+	if (!feature_mask)
+		return -EINVAL;
+	memset(feature_mask, 0xff, sizeof(*feature_mask));
+
+	return 0;
+}
+
 static const struct pptable_funcs cyan_skillfish_ppt_funcs = {
 
 	.check_fw_status = smu_v11_0_check_fw_status,
@@ -562,7 +572,7 @@ static const struct pptable_funcs cyan_skillfish_ppt_funcs = {
 	.fini_smc_tables = smu_v11_0_fini_smc_tables,
 	.read_sensor = cyan_skillfish_read_sensor,
 	.print_clk_levels = cyan_skillfish_print_clk_levels,
-	.get_enabled_mask = smu_cmn_get_enabled_mask,
+	.get_enabled_mask = cyan_skillfish_get_enabled_mask,
 	.is_dpm_running = cyan_skillfish_is_dpm_running,
 	.get_gpu_metrics = cyan_skillfish_get_gpu_metrics,
 	.od_edit_dpm_table = cyan_skillfish_od_edit_dpm_table,
drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c +11 -1
index e99e7b2bf25b..fd6c44ece168 100644
@@ -1366,6 +1366,16 @@ static int renoir_gfx_state_change_set(struct smu_context *smu, uint32_t state)
 	return 0;
 }
 
+static int renoir_get_enabled_mask(struct smu_context *smu,
+				   uint64_t *feature_mask)
+{
+	if (!feature_mask)
+		return -EINVAL;
+	memset(feature_mask, 0xff, sizeof(*feature_mask));
+
+	return 0;
+}
+
 static const struct pptable_funcs renoir_ppt_funcs = {
 	.set_power_state = NULL,
 	.print_clk_levels = renoir_print_clk_levels,
@@ -1390,7 +1400,7 @@ static const struct pptable_funcs renoir_ppt_funcs = {
 	.init_smc_tables = renoir_init_smc_tables,
 	.fini_smc_tables = smu_v12_0_fini_smc_tables,
 	.set_default_dpm_table = smu_v12_0_set_default_dpm_tables,
-	.get_enabled_mask = smu_cmn_get_enabled_mask,
+	.get_enabled_mask = renoir_get_enabled_mask,
 	.feature_is_enabled = smu_cmn_feature_is_enabled,
 	.disable_all_features_with_exception = smu_cmn_disable_all_features_with_exception,
 	.get_dpm_ultimate_freq = renoir_get_dpm_ultimate_freq,
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +15 -5
index 4c12abcd995d..aa0ca579ad6d 100644
@@ -59,6 +59,12 @@ static const char * const __smu_message_names[] = {
 	SMU_MESSAGE_TYPES
 };
 
+#define smu_cmn_call_asic_func(intf, smu, args...)                             \
+	((smu)->ppt_funcs ? ((smu)->ppt_funcs->intf ?                          \
+				     (smu)->ppt_funcs->intf(smu, ##args) :     \
+				     -ENOTSUPP) :                              \
+			    -EINVAL)
+
 static const char *smu_get_message_name(struct smu_context *smu,
 					enum smu_message_type type)
 {
@@ -493,6 +499,12 @@ int smu_cmn_feature_is_supported(struct smu_context *smu,
 	return test_bit(feature_id, feature->supported);
 }
 
+int __smu_get_enabled_features(struct smu_context *smu,
+			       uint64_t *enabled_features)
+{
+	return smu_cmn_call_asic_func(get_enabled_mask, smu, enabled_features);
+}
+
 int smu_cmn_feature_is_enabled(struct smu_context *smu,
 			       enum smu_feature_mask mask)
 {
@@ -500,7 +512,7 @@ int smu_cmn_feature_is_enabled(struct smu_context *smu,
 	uint64_t enabled_features;
 	int feature_id;
 
-	if (smu_cmn_get_enabled_mask(smu, &enabled_features)) {
+	if (__smu_get_enabled_features(smu, &enabled_features)) {
 		dev_err(adev->dev, "Failed to retrieve enabled ppfeatures!\n");
 		return 0;
 	}
@@ -695,8 +707,7 @@ size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,
 	int ret = 0, i;
 	int feature_id;
 
-	ret = smu_cmn_get_enabled_mask(smu,
-				       &feature_mask);
+	ret = __smu_get_enabled_features(smu, &feature_mask);
 	if (ret)
 		return 0;
 
@@ -748,8 +759,7 @@ int smu_cmn_set_pp_feature_mask(struct smu_context *smu,
 	uint64_t feature_2_enabled = 0;
 	uint64_t feature_2_disabled = 0;
 
-	ret = smu_cmn_get_enabled_mask(smu,
-				       &feature_mask);
+	ret = __smu_get_enabled_features(smu, &feature_mask);
 	if (ret)
 		return ret;
 
#5 lore raw

[Public]

Quoted 111 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, February 18, 2022 1:29 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: validate SMU feature enable message for getting feature enabled mask

Quoted 83 lines · Prike

[Public]

Quoted 81 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, February 18, 2022 12:05 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: validate SMU feature enable message for getting feature enabled mask

Quoted 8 lines · Prike Liang

There's always miss the SMU feature enabled checked in the NPI phase, so let validate the SMU feature enable message directly rather than add more and more MP1 version check.

---
   drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 28

++++++-------------------

-

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c bool smu_cmn_clk_dpm_is_enabled(struct

Quoted 8 lines
   1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -0
index f24111d28290..da1ac70ed455 100644
@@ -552,10 +552,9 @@ bool smu_cmn_clk_dpm_is_enabled(struct

smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
   int smu_cmn_get_enabled_mask(struct smu_context *smu,
                          uint64_t *feature_mask)
   {
-   struct amdgpu_device *adev = smu->adev;
     uint32_t *feature_mask_high;
     uint32_t *feature_mask_low;
-   int ret = 0;
+   int ret = 0, index = 0;
 
     if (!feature_mask)
             return -EINVAL;
@@ -563,12 +562,10 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct · line 567

Quoted 12 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +3 -6
     feature_mask_low = &((uint32_t *)feature_mask)[0];
     feature_mask_high = &((uint32_t *)feature_mask)[1];
 
-   switch (adev->ip_versions[MP1_HWIP][0]) {
-   /* For Vangogh and Yellow Carp */
-   case IP_VERSION(11, 5, 0):
-   case IP_VERSION(13, 0, 1):
-   case IP_VERSION(13, 0, 3):
-   case IP_VERSION(13, 0, 8):
+   index = smu_cmn_to_asic_specific_index(smu,
+                                           CMN2ASIC_MAPPING_MSG,
+
       SMU_MSG_GetEnabledSmuFeatures);

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct · line 570

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -0
+   if (index > 0) {
             ret = smu_cmn_send_smc_msg_with_param(smu,
 

SMU_MSG_GetEnabledSmuFeatures,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c int smu_cmn_get_enabled_mask(struct

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -0
                                                   0, @@ -580,19
+577,7 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

Quoted 1 line

SMU_MSG_GetEnabledSmuFeatures,

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c

Quoted 5 lines
                                                   1,
                                                   feature_mask_high);
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -3
-           break;
-   /*
-    * For Cyan Skillfish and Renoir, there is no interface provided by

PMFW

Quoted 1 line

- * to retrieve the enabled features. So, we assume all features are

enabled.

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +0 -7
-    * TODO: add other APU ASICs which suffer from the same issue here
-    */
-   case IP_VERSION(11, 0, 8):
-   case IP_VERSION(12, 0, 0):
-   case IP_VERSION(12, 0, 1):
-           memset(feature_mask, 0xff, sizeof(*feature_mask));
-           break;
Quoted 8 lines
Quoted 7 lines

This is broken now as these ASICs don't support any message. It is best to take out smu_cmn_get_enabled_mask altogether and move to smu_v*.c or *_ppt.c as this is a callback function.

Thanks,
Lijo

Before this solution I also consider put the smu_cmn_get_enabled_mask

implementation in each *_ppt directly, but seems need some effort for implementing on each *_ppt. How about we also check the SMU_MSG_GetEnabledSmuFeaturesHigh mapping index? As to the ASCI not support neither SMU_MSG_GetEnabledSmuFeatures nor SMU_MSG_GetEnabledSmuFeaturesHigh will hard code the feature mask in this case.

Quoted 1 line
Quoted 6 lines

Something like attached refactoring and then for the rest you could apply your patch.

Thanks,
Lijo

Well, this also looks good for handling the feature mask not support scenario case by case, before this I want to handle everything on the smu_cmn_get_enabled_mask(). Will update the patch base on your proposal, thanks!

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +1 -2
-   /* other dGPU ASICs */
-   default:
+   } else {
             ret = smu_cmn_send_smc_msg(smu,

SMU_MSG_GetEnabledSmuFeaturesHigh,

Quoted 2 lines
                                        feature_mask_high); @@

-602,7 +587,6 @@ int smu_cmn_get_enabled_mask(struct

smu_context *smu,

Quoted 2 lines

ret = smu_cmn_send_smc_msg(smu,

SMU_MSG_GetEnabledSmuFeaturesLow,

Quoted 6 lines
                                        feature_mask_low);
-           break;
     }

     return ret;