Skip to contentSkip to conversation

drm/amd/pm: only poweron/off vcn/jpeg when they are valid.

PATCH Superseded Yifan Zhang 2 participants 2 messages Aug 31, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/pm: only poweron/off vcn/jpeg when they are valid.

If vcn is disabled in kernel parameters, don't touch vcn, otherwise it may cause vcn hang.

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 31 ++++++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +27 -4
index f005a90c35af..f5e7ce011cab 100644
@@ -1454,6 +1454,21 @@ static int smu_start_smc_engine(struct smu_context *smu)
 	return ret;
 }
 
+static bool is_vcn_enabled(struct amdgpu_device *adev)
+{
+	int i;
+
+	for (i = 0; i < adev->num_ip_blocks; i++) {
+		if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_VCN ||
+			adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_JPEG) &&
+			!adev->ip_blocks[i].status.valid)
+
+			return false;
+	}
+
+	return true;
+}
+
 static int smu_hw_init(void *handle)
 {
 	int ret;
@@ -1475,8 +1490,14 @@ static int smu_hw_init(void *handle)
 		ret = smu_set_gfx_imu_enable(smu);
 		if (ret)
 			return ret;
-		smu_dpm_set_vcn_enable(smu, true);
-		smu_dpm_set_jpeg_enable(smu, true);
+		/*
+		 * don't poweron vcn/jpeg when they are skipped.
+		 */
+		if (is_vcn_enabled(adev)) {
+			dev_info(adev->dev, "yep, vcn are valid\n");
+			smu_dpm_set_vcn_enable(smu, true);
+			smu_dpm_set_jpeg_enable(smu, true);
+		}
 		smu_set_gfx_cgpg(smu, true);
 	}
 
@@ -1651,8 +1672,10 @@ static int smu_hw_fini(void *handle)
 	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
 		return 0;
 
-	smu_dpm_set_vcn_enable(smu, false);
-	smu_dpm_set_jpeg_enable(smu, false);
+	if (is_vcn_enabled(adev)) {
+		smu_dpm_set_vcn_enable(smu, false);
+		smu_dpm_set_jpeg_enable(smu, false);
+	}
 
 	adev->vcn.cur_state = AMD_PG_STATE_GATE;
 	adev->jpeg.cur_state = AMD_PG_STATE_GATE;
Signature · 1 line
2.37.3
#1 lore raw

[AMD Official Use Only - General]

Quoted 52 lines

-----Original Message-----
From: Zhang, Yifan <[email protected]>
Sent: Thursday, August 31, 2023 2:10 PM
To: [email protected]
Cc: Quan, Evan <[email protected]>; Ma, Li <[email protected]>; Zhang, Yifan <[email protected]>
Subject: [PATCH] drm/amd/pm: only poweron/off vcn/jpeg when they are valid.

If vcn is disabled in kernel parameters, don't touch vcn, otherwise it may cause vcn hang.

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 31
++++++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +6 -0
index f005a90c35af..f5e7ce011cab 100644
@@ -1454,6 +1454,21 @@ static int smu_start_smc_engine(struct
 smu_context *smu)
      return ret;
 }
 
+static bool is_vcn_enabled(struct amdgpu_device *adev)
+{
+     int i;
+
+     for (i = 0; i < adev->num_ip_blocks; i++) {
+             if ((adev->ip_blocks[i].version->type ==

AMD_IP_BLOCK_TYPE_VCN ||
+ adev->ip_blocks[i].version->type ==
AMD_IP_BLOCK_TYPE_JPEG) &&

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +8 -0
+                     !adev->ip_blocks[i].status.valid)
+
+                     return false;
+     }
+
+     return true;
+}
+
 static int smu_hw_init(void *handle)
 {
      int ret;
@@ -1475,8 +1490,14 @@ static int smu_hw_init(void *handle)
              ret = smu_set_gfx_imu_enable(smu);
              if (ret)
                      return ret;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_hw_init(void *handle) · line 1500

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +8 -2
-             smu_dpm_set_vcn_enable(smu, true);
-             smu_dpm_set_jpeg_enable(smu, true);
+             /*
+              * don't poweron vcn/jpeg when they are skipped.
+              */
+             if (is_vcn_enabled(adev)) {
+                     dev_info(adev->dev, "yep, vcn are valid\n");
+                     smu_dpm_set_vcn_enable(smu, true);
+                     smu_dpm_set_jpeg_enable(smu, true);
+             }

Better to move the "is_vcn_enabled" check into smu_dpm_set_vcn/jpeg_enable. That will make code more tidy. Also, the "dev_info" here is obviously not needed.

Evan

Quoted 18 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
              smu_set_gfx_cgpg(smu, true);
      }
 
@@ -1651,8 +1672,10 @@ static int smu_hw_fini(void *handle)
      if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
              return 0;
 
-     smu_dpm_set_vcn_enable(smu, false);
-     smu_dpm_set_jpeg_enable(smu, false);
+     if (is_vcn_enabled(adev)) {
+             smu_dpm_set_vcn_enable(smu, false);
+             smu_dpm_set_jpeg_enable(smu, false);
+     }
 
      adev->vcn.cur_state = AMD_PG_STATE_GATE;
      adev->jpeg.cur_state = AMD_PG_STATE_GATE;
--

2.37.3