drm/amdgpu: use pcie functions for link width and speed
authorAlex Deucher <alexander.deucher@amd.com>
Mon, 25 Jun 2018 18:07:50 +0000 (13:07 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 5 Jul 2018 21:39:59 +0000 (16:39 -0500)
Use the newly exported pci functions to get the link width
and speed rather than using the drm duplicated versions.

Also query the GPU link caps directly rather than hardcoding
them.

Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c
drivers/gpu/drm/amd/amdgpu/ci_dpm.c
drivers/gpu/drm/amd/amdgpu/si_dpm.c

index c35db859f050da46009c898dedf77eae2f30997d..d43abbd2a3cc2e3b67b9b050c5b2e7a0f3cbc7ad 100644 (file)
@@ -3311,8 +3311,9 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  */
 static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
 {
-       u32 mask;
-       int ret;
+       struct pci_dev *pdev;
+       enum pci_bus_speed speed_cap;
+       enum pcie_link_width link_width;
 
        if (amdgpu_pcie_gen_cap)
                adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap;
@@ -3330,27 +3331,61 @@ static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
        }
 
        if (adev->pm.pcie_gen_mask == 0) {
-               ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
-               if (!ret) {
-                       adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+               /* asic caps */
+               pdev = adev->pdev;
+               speed_cap = pcie_get_speed_cap(pdev);
+               if (speed_cap == PCI_SPEED_UNKNOWN) {
+                       adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
                                                  CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
                                                  CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
-
-                       if (mask & DRM_PCIE_SPEED_25)
-                               adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
-                       if (mask & DRM_PCIE_SPEED_50)
-                               adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2;
-                       if (mask & DRM_PCIE_SPEED_80)
-                               adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3;
                } else {
-                       adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
+                       if (speed_cap == PCIE_SPEED_16_0GT)
+                               adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+                                                         CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
+                                                         CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3 |
+                                                         CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN4);
+                       else if (speed_cap == PCIE_SPEED_8_0GT)
+                               adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+                                                         CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
+                                                         CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
+                       else if (speed_cap == PCIE_SPEED_5_0GT)
+                               adev->pm.pcie_gen_mask |= (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+                                                         CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2);
+                       else
+                               adev->pm.pcie_gen_mask |= CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1;
+               }
+               /* platform caps */
+               pdev = adev->ddev->pdev->bus->self;
+               speed_cap = pcie_get_speed_cap(pdev);
+               if (speed_cap == PCI_SPEED_UNKNOWN) {
+                       adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+                                                  CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2);
+               } else {
+                       if (speed_cap == PCIE_SPEED_16_0GT)
+                               adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+                                                          CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
+                                                          CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3 |
+                                                          CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4);
+                       else if (speed_cap == PCIE_SPEED_8_0GT)
+                               adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+                                                          CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
+                                                          CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3);
+                       else if (speed_cap == PCIE_SPEED_5_0GT)
+                               adev->pm.pcie_gen_mask |= (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1 |
+                                                          CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2);
+                       else
+                               adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
+
                }
        }
        if (adev->pm.pcie_mlw_mask == 0) {
-               ret = drm_pcie_get_max_link_width(adev->ddev, &mask);
-               if (!ret) {
-                       switch (mask) {
-                       case 32:
+               pdev = adev->ddev->pdev->bus->self;
+               link_width = pcie_get_width_cap(pdev);
+               if (link_width == PCIE_LNK_WIDTH_UNKNOWN) {
+                       adev->pm.pcie_mlw_mask |= AMDGPU_DEFAULT_PCIE_MLW_MASK;
+               } else {
+                       switch (link_width) {
+                       case PCIE_LNK_X32:
                                adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
@@ -3359,7 +3394,7 @@ static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
                                break;
-                       case 16:
+                       case PCIE_LNK_X16:
                                adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
@@ -3367,36 +3402,34 @@ static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
                                break;
-                       case 12:
+                       case PCIE_LNK_X12:
                                adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
                                break;
-                       case 8:
+                       case PCIE_LNK_X8:
                                adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
                                break;
-                       case 4:
+                       case PCIE_LNK_X4:
                                adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
                                break;
-                       case 2:
+                       case PCIE_LNK_X2:
                                adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
                                                          CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
                                break;
-                       case 1:
+                       case PCIE_LNK_X1:
                                adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1;
                                break;
                        default:
                                break;
                        }
-               } else {
-                       adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
                }
        }
 }
index 77ad59ade85ca79b56d352608e96fde4395ece99..1c4595562f8fd29bc682764265e5d2fd472b1f2c 100644 (file)
@@ -28,6 +28,7 @@
 #include "amdgpu_i2c.h"
 #include "amdgpu_dpm.h"
 #include "atom.h"
+#include "amd_pcie.h"
 
 void amdgpu_dpm_print_class_info(u32 class, u32 class2)
 {
@@ -936,9 +937,11 @@ enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
        case AMDGPU_PCIE_GEN3:
                return AMDGPU_PCIE_GEN3;
        default:
-               if ((sys_mask & DRM_PCIE_SPEED_80) && (default_gen == AMDGPU_PCIE_GEN3))
+               if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
+                   (default_gen == AMDGPU_PCIE_GEN3))
                        return AMDGPU_PCIE_GEN3;
-               else if ((sys_mask & DRM_PCIE_SPEED_50) && (default_gen == AMDGPU_PCIE_GEN2))
+               else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
+                        (default_gen == AMDGPU_PCIE_GEN2))
                        return AMDGPU_PCIE_GEN2;
                else
                        return AMDGPU_PCIE_GEN1;
index d79ad93b01c32e3b389c73c3c276194c26131105..d2469453dca26e8d4848fa98037d44bdea92cd8d 100644 (file)
@@ -5846,8 +5846,7 @@ static int ci_dpm_init(struct amdgpu_device *adev)
        adev->pm.dpm.priv = pi;
 
        pi->sys_pcie_mask =
-               (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_MASK) >>
-               CAIL_PCIE_LINK_SPEED_SUPPORT_SHIFT;
+               adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_MASK;
 
        pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
 
index 3560b7dc1798640d0f50163fe39a52c552bca608..db327b4125626d411e155de18bfeb28f4efb92b4 100644 (file)
@@ -7318,8 +7318,7 @@ static int si_dpm_init(struct amdgpu_device *adev)
        pi = &eg_pi->rv7xx;
 
        si_pi->sys_pcie_mask =
-               (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_MASK) >>
-               CAIL_PCIE_LINK_SPEED_SUPPORT_SHIFT;
+               adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_MASK;
        si_pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
        si_pi->boot_pcie_gen = si_get_current_pcie_speed(adev);