drm/amdgpu: refactoring the runtime pm mode detection code
authorMa Jun <Jun.Ma2@amd.com>
Wed, 27 Mar 2024 07:18:40 +0000 (15:18 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 17 Apr 2024 02:39:16 +0000 (22:39 -0400)
refactor the code of runtime pm mode detection to support
amdgpu_runtime_pm =2 and 1 two cases

Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
Reviewed-by: Yang Wang <kevinyang.wang@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@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_kms.c

index 65c17c59c152d077336d89ba5eb20fd7e3c3fe3e..e0d7f4ee7e162f982becd7dfbd1152fd4eb7d000 100644 (file)
@@ -1409,6 +1409,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev);
 bool amdgpu_device_supports_boco(struct drm_device *dev);
 bool amdgpu_device_supports_smart_shift(struct drm_device *dev);
 int amdgpu_device_supports_baco(struct drm_device *dev);
+void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev);
 bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
                                      struct amdgpu_device *peer_adev);
 int amdgpu_device_baco_enter(struct drm_device *dev);
index 48a2de92180a792d1ff8823f9be8394f7968eaf9..1b2e177bc2d6b3b3f3d6da4cc8caa038d3d33b63 100644 (file)
@@ -350,6 +350,81 @@ int amdgpu_device_supports_baco(struct drm_device *dev)
        return amdgpu_asic_supports_baco(adev);
 }
 
+void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
+{
+       struct drm_device *dev;
+       int bamaco_support;
+
+       dev = adev_to_drm(adev);
+
+       adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
+       bamaco_support = amdgpu_device_supports_baco(dev);
+
+       switch (amdgpu_runtime_pm) {
+       case 2:
+               if (bamaco_support & MACO_SUPPORT) {
+                       adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
+                       dev_info(adev->dev, "Forcing BAMACO for runtime pm\n");
+               } else if (bamaco_support == BACO_SUPPORT) {
+                       adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+                       dev_info(adev->dev, "Requested mode BAMACO not available,fallback to use BACO\n");
+               }
+               break;
+       case 1:
+               if (bamaco_support & BACO_SUPPORT) {
+                       adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+                       dev_info(adev->dev, "Forcing BACO for runtime pm\n");
+               }
+               break;
+       case -1:
+       case -2:
+               if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
+                       adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
+                       dev_info(adev->dev, "Using ATPX for runtime pm\n");
+               } else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
+                       adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
+                       dev_info(adev->dev, "Using BOCO for runtime pm\n");
+               } else {
+                       if (!bamaco_support)
+                               goto no_runtime_pm;
+
+                       switch (adev->asic_type) {
+                       case CHIP_VEGA20:
+                       case CHIP_ARCTURUS:
+                               /* BACO are not supported on vega20 and arctrus */
+                               break;
+                       case CHIP_VEGA10:
+                               /* enable BACO as runpm mode if noretry=0 */
+                               if (!adev->gmc.noretry)
+                                       adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+                               break;
+                       default:
+                               /* enable BACO as runpm mode on CI+ */
+                               adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+                               break;
+                       }
+
+                       if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
+                               if (bamaco_support & MACO_SUPPORT) {
+                                       adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
+                                       dev_info(adev->dev, "Using BAMACO for runtime pm\n");
+                               } else {
+                                       dev_info(adev->dev, "Using BACO for runtime pm\n");
+                               }
+                       }
+               }
+               break;
+       case 0:
+               dev_info(adev->dev, "runtime pm is manually disabled\n");
+               break;
+       default:
+               break;
+       }
+
+no_runtime_pm:
+       if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
+               dev_info(adev->dev, "Runtime PM not available\n");
+}
 /**
  * amdgpu_device_supports_smart_shift - Is the device dGPU with
  * smart shift support
index 55eb4e4eb8f2f175b3ccc7abe35b6616f4ce2052..a0ea6fe8d0606ba45dd6308393484366f6635e6b 100644 (file)
@@ -133,7 +133,6 @@ void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
 int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
 {
        struct drm_device *dev;
-       int bamaco_support = 0;
        int r, acpi_status;
 
        dev = adev_to_drm(adev);
@@ -150,52 +149,7 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
                goto out;
        }
 
-       adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
-       if (amdgpu_device_supports_px(dev) &&
-           (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
-               adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
-               dev_info(adev->dev, "Using ATPX for runtime pm\n");
-       } else if (amdgpu_device_supports_boco(dev) &&
-                  (amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
-               adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
-               dev_info(adev->dev, "Using BOCO for runtime pm\n");
-       } else if (amdgpu_runtime_pm != 0) {
-               bamaco_support = amdgpu_device_supports_baco(dev);
-
-               if (!bamaco_support)
-                       goto no_runtime_pm;
-
-               switch (adev->asic_type) {
-               case CHIP_VEGA20:
-               case CHIP_ARCTURUS:
-                       /* enable BACO as runpm mode if runpm=1 */
-                       if (amdgpu_runtime_pm > 0)
-                               adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
-                       break;
-               case CHIP_VEGA10:
-                       /* enable BACO as runpm mode if noretry=0 */
-                       if (!adev->gmc.noretry)
-                               adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
-                       break;
-               default:
-                       /* enable BACO as runpm mode on CI+ */
-                       adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
-                       break;
-               }
-
-               if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
-                       if (bamaco_support & MACO_SUPPORT) {
-                               adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
-                               dev_info(adev->dev, "Using BAMACO for runtime pm\n");
-                       } else {
-                               dev_info(adev->dev, "Using BACO for runtime pm\n");
-                       }
-               }
-       }
-
-no_runtime_pm:
-       if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
-               dev_info(adev->dev, "NO pm mode for runtime pm\n");
+       amdgpu_device_detect_runtime_pm_mode(adev);
 
        /* Call ACPI methods: require modeset init
         * but failure is not fatal