drm/amdgpu: move pci handling out of pm ops
authorAlex Deucher <alexander.deucher@amd.com>
Wed, 20 Nov 2019 22:31:11 +0000 (17:31 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 26 Nov 2019 19:51:03 +0000 (14:51 -0500)
The documentation says the that PCI core handles this
for you unless you choose to implement it.  Just rely
on the PCI core to handle the pci specific bits.

Reviewed-by: Zhan Liu <zhan.liu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index dd961f0a5a750ee53d6da0c333a61daf0baa2ee2..145a2efd560a0cdcfd9e339d5afb7a1c10fabf7b 100644 (file)
@@ -1185,8 +1185,8 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
 void amdgpu_driver_postclose_kms(struct drm_device *dev,
                                 struct drm_file *file_priv);
 int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
-int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
-int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
+int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
+int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
 u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
 int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
 void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
index d472526d97b9f55ff6231e0ec4865d67dd0c9794..aae8a29f48ad4d8102ba3b2bf12db643ff488b58 100644 (file)
@@ -1087,6 +1087,7 @@ static int amdgpu_device_check_arguments(struct amdgpu_device *adev)
 static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
 {
        struct drm_device *dev = pci_get_drvdata(pdev);
+       int r;
 
        if (amdgpu_device_supports_boco(dev) && state == VGA_SWITCHEROO_OFF)
                return;
@@ -1096,7 +1097,12 @@ static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
                /* don't suspend or resume card normally */
                dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
 
-               amdgpu_device_resume(dev, true, true);
+               pci_set_power_state(dev->pdev, PCI_D0);
+               pci_restore_state(dev->pdev);
+               r = pci_enable_device(dev->pdev);
+               if (r)
+                       DRM_WARN("pci_enable_device failed (%d)\n", r);
+               amdgpu_device_resume(dev, true);
 
                dev->switch_power_state = DRM_SWITCH_POWER_ON;
                drm_kms_helper_poll_enable(dev);
@@ -1104,7 +1110,11 @@ static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
                pr_info("amdgpu: switched off\n");
                drm_kms_helper_poll_disable(dev);
                dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
-               amdgpu_device_suspend(dev, true, true);
+               amdgpu_device_suspend(dev, true);
+               pci_save_state(dev->pdev);
+               /* Shut down the device */
+               pci_disable_device(dev->pdev);
+               pci_set_power_state(dev->pdev, PCI_D3cold);
                dev->switch_power_state = DRM_SWITCH_POWER_OFF;
        }
 }
@@ -3195,7 +3205,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
  * Returns 0 for success or an error on failure.
  * Called at driver suspend.
  */
-int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
+int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)
 {
        struct amdgpu_device *adev;
        struct drm_crtc *crtc;
@@ -3278,13 +3288,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
         */
        amdgpu_bo_evict_vram(adev);
 
-       if (suspend) {
-               pci_save_state(dev->pdev);
-               /* Shut down the device */
-               pci_disable_device(dev->pdev);
-               pci_set_power_state(dev->pdev, PCI_D3hot);
-       }
-
        return 0;
 }
 
@@ -3299,7 +3302,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  * Returns 0 for success or an error on failure.
  * Called at driver resume.
  */
-int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon)
+int amdgpu_device_resume(struct drm_device *dev, bool fbcon)
 {
        struct drm_connector *connector;
        struct drm_connector_list_iter iter;
@@ -3310,14 +3313,6 @@ int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon)
        if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
                return 0;
 
-       if (resume) {
-               pci_set_power_state(dev->pdev, PCI_D0);
-               pci_restore_state(dev->pdev);
-               r = pci_enable_device(dev->pdev);
-               if (r)
-                       return r;
-       }
-
        /* post card */
        if (amdgpu_device_need_post(adev)) {
                r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
index 459bca6514e6e7fd086b10551874735cc39b3927..3f6f14ce1511a9bc1ff2741226690c64c1206d4b 100644 (file)
@@ -1147,7 +1147,7 @@ static int amdgpu_pmops_suspend(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
 
-       return amdgpu_device_suspend(drm_dev, true, true);
+       return amdgpu_device_suspend(drm_dev, true);
 }
 
 static int amdgpu_pmops_resume(struct device *dev)
@@ -1162,7 +1162,7 @@ static int amdgpu_pmops_resume(struct device *dev)
                pm_runtime_enable(dev);
        }
 
-       return amdgpu_device_resume(drm_dev, true, true);
+       return amdgpu_device_resume(drm_dev, true);
 }
 
 static int amdgpu_pmops_freeze(struct device *dev)
@@ -1171,7 +1171,7 @@ static int amdgpu_pmops_freeze(struct device *dev)
        struct amdgpu_device *adev = drm_dev->dev_private;
        int r;
 
-       r = amdgpu_device_suspend(drm_dev, false, true);
+       r = amdgpu_device_suspend(drm_dev, true);
        if (r)
                return r;
        return amdgpu_asic_reset(adev);
@@ -1181,21 +1181,21 @@ static int amdgpu_pmops_thaw(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
 
-       return amdgpu_device_resume(drm_dev, false, true);
+       return amdgpu_device_resume(drm_dev, true);
 }
 
 static int amdgpu_pmops_poweroff(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
 
-       return amdgpu_device_suspend(drm_dev, true, true);
+       return amdgpu_device_suspend(drm_dev, true);
 }
 
 static int amdgpu_pmops_restore(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
 
-       return amdgpu_device_resume(drm_dev, false, true);
+       return amdgpu_device_resume(drm_dev, true);
 }
 
 static int amdgpu_pmops_runtime_suspend(struct device *dev)
@@ -1214,7 +1214,7 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
                drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
        drm_kms_helper_poll_disable(drm_dev);
 
-       ret = amdgpu_device_suspend(drm_dev, false, false);
+       ret = amdgpu_device_suspend(drm_dev, false);
        if (amdgpu_device_supports_boco(drm_dev)) {
                /* Only need to handle PCI state in the driver for ATPX
                 * PCI core handles it for _PR3.
@@ -1264,7 +1264,7 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
        } else if (amdgpu_device_supports_baco(drm_dev)) {
                amdgpu_device_baco_exit(drm_dev);
        }
-       ret = amdgpu_device_resume(drm_dev, false, false);
+       ret = amdgpu_device_resume(drm_dev, false);
        drm_kms_helper_poll_enable(drm_dev);
        if (amdgpu_device_supports_boco(drm_dev))
                drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;