]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd: Reduce code duplication in runtime PM
authorMario Limonciello <mario.limonciello@amd.com>
Fri, 15 May 2026 20:30:57 +0000 (15:30 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 18 May 2026 22:19:39 +0000 (18:19 -0400)
[Why]
amdgpu_pmops_runtime_suspend() runs almost the same code  that
amdgpu_pmops_runtime_idle() runs. That is there is pointless code
duplication.

[How]
Move amdgpu_pmops_runtime_idle() up, extract common code and then
call from both functions.  No intended functional changes.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 99688391e70b011dada8663d313b66af0ed087b2..1781c0c3d010f8cd60ddde9025860ba26d8f05d3 100644 (file)
@@ -2810,12 +2810,11 @@ static int amdgpu_runtime_idle_check_userq(struct device *dev)
        return xa_empty(&adev->userq_doorbell_xa) ? 0 : -EBUSY;
 }
 
-static int amdgpu_pmops_runtime_suspend(struct device *dev)
+static int amdgpu_pmops_runtime_checks(struct device *dev)
 {
-       struct pci_dev *pdev = to_pci_dev(dev);
-       struct drm_device *drm_dev = pci_get_drvdata(pdev);
+       struct drm_device *drm_dev = dev_get_drvdata(dev);
        struct amdgpu_device *adev = drm_to_adev(drm_dev);
-       int ret, i;
+       int ret;
 
        if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
                pm_runtime_forbid(dev);
@@ -2825,7 +2824,27 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
        ret = amdgpu_runtime_idle_check_display(dev);
        if (ret)
                return ret;
-       ret = amdgpu_runtime_idle_check_userq(dev);
+
+       return amdgpu_runtime_idle_check_userq(dev);
+}
+
+static int amdgpu_pmops_runtime_idle(struct device *dev)
+{
+       int ret;
+
+       ret = amdgpu_pmops_runtime_checks(dev);
+       pm_runtime_autosuspend(dev);
+       return ret;
+}
+
+static int amdgpu_pmops_runtime_suspend(struct device *dev)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct drm_device *drm_dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
+       int ret, i;
+
+       ret = amdgpu_pmops_runtime_checks(dev);
        if (ret)
                return ret;
 
@@ -2937,27 +2956,6 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
        return 0;
 }
 
-static int amdgpu_pmops_runtime_idle(struct device *dev)
-{
-       struct drm_device *drm_dev = dev_get_drvdata(dev);
-       struct amdgpu_device *adev = drm_to_adev(drm_dev);
-       int ret;
-
-       if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
-               pm_runtime_forbid(dev);
-               return -EBUSY;
-       }
-
-       ret = amdgpu_runtime_idle_check_display(dev);
-       if (ret)
-               goto done;
-
-       ret = amdgpu_runtime_idle_check_userq(dev);
-done:
-       pm_runtime_autosuspend(dev);
-       return ret;
-}
-
 static int amdgpu_drm_release(struct inode *inode, struct file *filp)
 {
        struct drm_file *file_priv = filp->private_data;