Skip to contentSkip to conversation

drm/amd/pm: parse pp_handle under appropriate conditions

PATCH In review Guchun Chen 2 participants 2 messages May 6, 2023 – May 7, 2023

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

PATCH v3 1/1 drm/amd/pm: parse pp_handle under appropriate conditions

amdgpu_dpm_is_overdrive_supported is a common API across all asics, so we should cast pp_handle into correct structure under different power frameworks.

v2: using return directly to simplify code
v3: SI asic does not carry od_enabled member in pp_handle, and update Fixes tag

Fixes eb4900aa4c49("drm/amdgpu: Fix kernel NULL pointer dereference in dpm functions")
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +13 -7
index 300e156b924f..86246f69dbe1 100644
@@ -1460,15 +1460,21 @@ int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
 
 int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
 {
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	struct smu_context *smu = adev->powerplay.pp_handle;
+	if (is_support_sw_smu(adev)) {
+		struct smu_context *smu = adev->powerplay.pp_handle;
+
+		return (smu->od_enabled || smu->is_apu);
+	} else {
+		struct pp_hwmgr *hwmgr;
 
-	if ((is_support_sw_smu(adev) && smu->od_enabled) ||
-	    (is_support_sw_smu(adev) && smu->is_apu) ||
-		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
-		return true;
+		/* SI asic does not carry od_enabled */
+		if (adev->family == AMDGPU_FAMILY_SI)
+			return false;
 
-	return false;
+		hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
+
+		return hwmgr->od_enabled;
+	}
 }
 
 int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines · Guchun Chen

amdgpu_dpm_is_overdrive_supported is a common API across all asics, so we should cast pp_handle into correct structure under different power frameworks.

v2: using return directly to simplify code
v3: SI asic does not carry od_enabled member in pp_handle, and update Fixes tag

Fixes eb4900aa4c49("drm/amdgpu: Fix kernel NULL pointer dereference in dpm functions")
Quoted 37 lines
---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 20 +++++++++++++-------
  1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +13 -7
index 300e156b924f..86246f69dbe1 100644
@@ -1460,15 +1460,21 @@ int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
 
  int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
  {
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	struct smu_context *smu = adev->powerplay.pp_handle;
+	if (is_support_sw_smu(adev)) {
+		struct smu_context *smu = adev->powerplay.pp_handle;
+
+		return (smu->od_enabled || smu->is_apu);
+	} else {
+		struct pp_hwmgr *hwmgr;
 
-	if ((is_support_sw_smu(adev) && smu->od_enabled) ||
-	    (is_support_sw_smu(adev) && smu->is_apu) ||
-		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
-		return true;
+		/* SI asic does not carry od_enabled */
+		if (adev->family == AMDGPU_FAMILY_SI)
+			return false;
 
-	return false;
+		hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle;
+
+		return hwmgr->od_enabled;
+	}
  }
 
  int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,