Set up APUs to follow similar policies as dGPUs in that they can
potentially runtime suspend.  If an APU is runtime suspended then
prepare it for the matching system state (s0ix or s3) so that steps
can be skipped when runtime suspended.

It's important to note that default runtime PM policy will prevent
entering runtime PM when displays are connected. This can be changed
by setting amdgpu.runpm=-2.

Cc: Antheas Kapenekakis <[email protected]>
Signed-off-by: Mario Limonciello (AMD) <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  6 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 17 +++++++++++++++--
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h    |  1 +
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 6fffb47cb9b42..749fb29026ef5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -497,6 +497,12 @@ void amdgpu_device_detect_runtime_pm_mode(struct 
amdgpu_device *adev)
                        adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
                        dev_info(adev->dev, "Using BOCO for runtime pm\n");
                } else {
+                       /* APU runtime pm */
+                       if (adev->flags & AMD_IS_APU) {
+                               adev->pm.rpm_mode = AMDGPU_RUNPM_APU;
+                               dev_info(adev->dev, "Using APU runtime pm\n");
+                               break;
+                       }
                        if (!bamaco_support)
                                goto no_runtime_pm;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 25b725bd38201..ebe544c544c10 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2471,7 +2471,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
                if (amdgpu_device_supports_px(adev))
                        dev_pm_set_driver_flags(ddev->dev, 
DPM_FLAG_NO_DIRECT_COMPLETE);
                /* we want direct complete for BOCO */
-               if (amdgpu_device_supports_boco(adev))
+               if (amdgpu_device_supports_boco(adev) || adev->flags & 
AMD_IS_APU)
                        dev_pm_set_driver_flags(ddev->dev, 
DPM_FLAG_SMART_PREPARE |
                                                DPM_FLAG_SMART_SUSPEND |
                                                DPM_FLAG_MAY_SKIP_RESUME);
@@ -2581,7 +2581,7 @@ static int amdgpu_pmops_prepare(struct device *dev)
        /* Return a positive number here so
         * DPM_FLAG_SMART_SUSPEND works properly
         */
-       if (amdgpu_device_supports_boco(adev) && pm_runtime_suspended(dev))
+       if (pm_runtime_suspended(dev))
                return 1;
 
        /* if we will not support s3 or s2i for the device
@@ -2848,6 +2848,15 @@ static int amdgpu_pmops_runtime_suspend(struct device 
*dev)
        ret = amdgpu_device_prepare(drm_dev);
        if (ret)
                return ret;
+
+       /* for APUs - match the sleep state of the system */
+       if (adev->pm.rpm_mode == AMDGPU_RUNPM_APU) {
+               if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)
+                       adev->in_s0ix = true;
+               else
+                       adev->in_s3 = true;
+       }
+
        ret = amdgpu_device_suspend(drm_dev, false);
        if (ret) {
                adev->in_runpm = false;
@@ -2925,6 +2934,10 @@ static int amdgpu_pmops_runtime_resume(struct device 
*dev)
        if (adev->pm.rpm_mode == AMDGPU_RUNPM_PX)
                drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
        adev->in_runpm = false;
+       if (adev->pm.rpm_mode == AMDGPU_RUNPM_APU) {
+               adev->in_s0ix = false;
+               adev->in_s3 = false;
+       }
        return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h 
b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index c7ea293856827..2972c874b5e6d 100644
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
@@ -51,6 +51,7 @@ enum amdgpu_runpm_mode {
        AMDGPU_RUNPM_BOCO,
        AMDGPU_RUNPM_BACO,
        AMDGPU_RUNPM_BAMACO,
+       AMDGPU_RUNPM_APU,
 };
 
 #define BACO_SUPPORT (1<<0)
-- 
2.43.0

Reply via email to