]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amd: Check that VPE has reached DPM0 in idle handler
authorMario Limonciello <mario.limonciello@amd.com>
Thu, 16 Oct 2025 18:55:27 +0000 (13:55 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:34:00 +0000 (15:34 -0500)
commit ba10f8d92a2c026b1052b4c0fa2cd7538838c965 upstream.

[Why]
Newer VPE microcode has functionality that will decrease DPM level
only when a workload has run for 2 or more seconds.  If VPE is turned
off before this DPM decrease and the PMFW doesn't reset it when
power gating VPE, the SOC can get stuck with a higher DPM level.

This can happen from amdgpu's ring buffer test because it's a short
quick workload for VPE and VPE is turned off after 1s.

[How]
In idle handler besides checking fences are drained check PMFW version
to determine if it will reset DPM when power gating VPE.  If PMFW will
not do this, then check VPE DPM level. If it is not DPM0 reschedule
delayed work again until it is.

v2: squash in return fix (Alex)

Cc: Peyton.Lee@amd.com
Reported-by: Sultan Alsawaf <sultan@kerneltoast.com>
Reviewed-by: Sultan Alsawaf <sultan@kerneltoast.com>
Tested-by: Sultan Alsawaf <sultan@kerneltoast.com>
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/4615
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 3ac635367eb589bee8edcc722f812a89970e14b7)
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c

index 5acd20ff59797bb687b1d4cf903d4da4bd7ecb6c..bf4d2e3f23956c2f99c613d99a530eaf0d352dc0 100644 (file)
@@ -321,6 +321,26 @@ static int vpe_early_init(void *handle)
        return 0;
 }
 
+static bool vpe_need_dpm0_at_power_down(struct amdgpu_device *adev)
+{
+       switch (amdgpu_ip_version(adev, VPE_HWIP, 0)) {
+       case IP_VERSION(6, 1, 1):
+               return adev->pm.fw_version < 0x0a640500;
+       default:
+               return false;
+       }
+}
+
+static int vpe_get_dpm_level(struct amdgpu_device *adev)
+{
+       struct amdgpu_vpe *vpe = &adev->vpe;
+
+       if (!adev->pm.dpm_enabled)
+               return 0;
+
+       return RREG32(vpe_get_reg_offset(vpe, 0, vpe->regs.dpm_request_lv));
+}
+
 static void vpe_idle_work_handler(struct work_struct *work)
 {
        struct amdgpu_device *adev =
@@ -328,11 +348,17 @@ static void vpe_idle_work_handler(struct work_struct *work)
        unsigned int fences = 0;
 
        fences += amdgpu_fence_count_emitted(&adev->vpe.ring);
+       if (fences)
+               goto reschedule;
 
-       if (fences == 0)
-               amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VPE, AMD_PG_STATE_GATE);
-       else
-               schedule_delayed_work(&adev->vpe.idle_work, VPE_IDLE_TIMEOUT);
+       if (vpe_need_dpm0_at_power_down(adev) && vpe_get_dpm_level(adev) != 0)
+               goto reschedule;
+
+       amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VPE, AMD_PG_STATE_GATE);
+       return;
+
+reschedule:
+       schedule_delayed_work(&adev->vpe.idle_work, VPE_IDLE_TIMEOUT);
 }
 
 static int vpe_common_init(struct amdgpu_vpe *vpe)