Skip to contentSkip to conversation

drm/amd/pm/powerplay/smumgr/fiji_smumgr: Fix wrong return value of fiji_populate_smc_boot_level()

PATCH RESEND In review Wentao Liang 2 participants 2 messages Apr 14, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 drm/amd/pm/powerplay/smumgr/fiji_smumgr: Fix wrong return value of fiji_populate_smc_boot_level()

The return value of fiji_populate_smc_boot_level() is always 0, which represent the failure of the function. The result of phm_find_boot_level() should be recored and return. An error handling is also needed to phm_find_boot_level() to reset the boot level when the function fails. A proper implementation can be found in tonga_populate_smc_boot_level().

Fixes dcaf3483ae46 ("drm/amd/pm/powerplay/smumgr/fiji_smumgr: Remove unused variable 'result'")
---
 .../drm/amd/pm/powerplay/smumgr/fiji_smumgr.c | 23 +++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/smumgr/fiji_smumgr.c +16 -7
index 5e43ad2b2956..7d0cb3741b94 100644
@@ -1600,19 +1600,28 @@ static int fiji_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
 static int fiji_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
 		struct SMU73_Discrete_DpmTable *table)
 {
+	int result = 0;
 	struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
 
 	table->GraphicsBootLevel = 0;
 	table->MemoryBootLevel = 0;
 
 	/* find boot level from dpm table */
-	phm_find_boot_level(&(data->dpm_table.sclk_table),
-			    data->vbios_boot_state.sclk_bootup_value,
-			    (uint32_t *)&(table->GraphicsBootLevel));
+	result = phm_find_boot_level(&(data->dpm_table.sclk_table),
+				     data->vbios_boot_state.sclk_bootup_value,
+				     (uint32_t *)&(table->GraphicsBootLevel));
+	if (result) {
+		table->GraphicsBootLevel = 0;
+		return 0;
+	}
 
-	phm_find_boot_level(&(data->dpm_table.mclk_table),
-			    data->vbios_boot_state.mclk_bootup_value,
-			    (uint32_t *)&(table->MemoryBootLevel));
+	result = phm_find_boot_level(&(data->dpm_table.mclk_table),
+				     data->vbios_boot_state.mclk_bootup_value,
+				     (uint32_t *)&(table->MemoryBootLevel));
+	if (result) {
+		table->MemoryBootLevel = 0;
+		return 0;
+	}
 
 	table->BootVddc  = data->vbios_boot_state.vddc_bootup_value *
 			VOLTAGE_SCALE;
@@ -1625,7 +1634,7 @@ static int fiji_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
 	CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
 	CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
 
-	return 0;
+	return result;
 }
 
 static int fiji_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
Signature · 1 line
2.42.0.windows.2
#1 lore raw
Quoted 27 lines · Wentao Liang

The return value of fiji_populate_smc_boot_level() is always 0, which represent the failure of the function. The result of phm_find_boot_level() should be recored and return. An error handling is also needed to phm_find_boot_level() to reset the boot level when the function fails. A proper implementation can be found in tonga_populate_smc_boot_level().

Fixes dcaf3483ae46 ("drm/amd/pm/powerplay/smumgr/fiji_smumgr: Remove unused variable 'result'")
---
 .../drm/amd/pm/powerplay/smumgr/fiji_smumgr.c | 23 +++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/smumgr/fiji_smumgr.c +1 -0
index 5e43ad2b2956..7d0cb3741b94 100644
@@ -1600,19 +1600,28 @@ static int fiji_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
 static int fiji_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
                struct SMU73_Discrete_DpmTable *table)
 {
+       int result = 0;
        struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
 
        table->GraphicsBootLevel = 0;
        table->MemoryBootLevel = 0;
 

drivers/gpu/drm/amd/pm/powerplay/smumgr/fiji_smumgr.c static int fiji_populate_smc_uvd_level(struct pp_hwmgr *hwmgr, · line 1615

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/smumgr/fiji_smumgr.c +6 -3
        /* find boot level from dpm table */
-       phm_find_boot_level(&(data->dpm_table.sclk_table),
-                           data->vbios_boot_state.sclk_bootup_value,
-                           (uint32_t *)&(table->GraphicsBootLevel));
+       result = phm_find_boot_level(&(data->dpm_table.sclk_table),
+                                    data->vbios_boot_state.sclk_bootup_value,
+                                    (uint32_t *)&(table->GraphicsBootLevel));
+       if (result) {
+               table->GraphicsBootLevel = 0;
+               return 0;

This will skip setting the voltages later below.

drivers/gpu/drm/amd/pm/powerplay/smumgr/fiji_smumgr.c static int fiji_populate_smc_uvd_level(struct pp_hwmgr *hwmgr, · line 1623

Quoted 11 lines
drivers/gpu/drm/amd/pm/powerplay/smumgr/fiji_smumgr.c +7 -3
+       }
 
-       phm_find_boot_level(&(data->dpm_table.mclk_table),
-                           data->vbios_boot_state.mclk_bootup_value,
-                           (uint32_t *)&(table->MemoryBootLevel));
+       result = phm_find_boot_level(&(data->dpm_table.mclk_table),
+                                    data->vbios_boot_state.mclk_bootup_value,
+                                    (uint32_t *)&(table->MemoryBootLevel));
+       if (result) {
+               table->MemoryBootLevel = 0;
+               return 0;

Same here.

If you are intending to match the logic in tonga_populate_smc_boot_level(), the existing code already does that (minus the error message). This change would break that. Returning early may break working devices.

Alex

Quoted 16 lines
drivers/gpu/drm/amd/pm/powerplay/smumgr/fiji_smumgr.c +2 -2
+       }
 
        table->BootVddc  = data->vbios_boot_state.vddc_bootup_value *
                        VOLTAGE_SCALE;
@@ -1625,7 +1634,7 @@ static int fiji_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
        CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
        CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
 
-       return 0;
+       return result;
 }
 
 static int fiji_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
--

2.42.0.windows.2