drm/pci: add support for getting the supported link bw.
authorDave Airlie <airlied@redhat.com>
Wed, 27 Jun 2012 07:35:53 +0000 (08:35 +0100)
committerDave Airlie <airlied@redhat.com>
Fri, 20 Jul 2012 02:29:25 +0000 (22:29 -0400)
This should work for PCIE3.0 as well.

Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_pci.c
include/drm/drmP.h

index 13f3d936472f3aadeed78ca465b2cf4feef617ff..5320364582ce144912354bfb62587a6c2233fcfb 100644 (file)
@@ -465,3 +465,52 @@ void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver)
        DRM_INFO("Module unloaded\n");
 }
 EXPORT_SYMBOL(drm_pci_exit);
+
+int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *mask)
+{
+       struct pci_dev *root;
+       int pos;
+       u32 lnkcap, lnkcap2;
+
+       *mask = 0;
+       if (!dev->pdev)
+               return -EINVAL;
+
+       if (!pci_is_pcie(dev->pdev))
+               return -EINVAL;
+
+       root = dev->pdev->bus->self;
+
+       pos = pci_pcie_cap(root);
+       if (!pos)
+               return -EINVAL;
+
+       /* we've been informed via and serverworks don't make the cut */
+       if (root->vendor == PCI_VENDOR_ID_VIA ||
+           root->vendor == PCI_VENDOR_ID_SERVERWORKS)
+               return -EINVAL;
+
+       pci_read_config_dword(root, pos + PCI_EXP_LNKCAP, &lnkcap);
+       pci_read_config_dword(root, pos + PCI_EXP_LNKCAP2, &lnkcap2);
+
+       lnkcap &= PCI_EXP_LNKCAP_SLS;
+       lnkcap2 &= 0xfe;
+
+       if (lnkcap2) { /* PCIE GEN 3.0 */
+               if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
+                       *mask |= DRM_PCIE_SPEED_25;
+               if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
+                       *mask |= DRM_PCIE_SPEED_50;
+               if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
+                       *mask |= DRM_PCIE_SPEED_80;
+       } else {
+               if (lnkcap & 1)
+                       *mask |= DRM_PCIE_SPEED_25;
+               if (lnkcap & 2)
+                       *mask |= DRM_PCIE_SPEED_50;
+       }
+
+       DRM_INFO("probing gen 2 caps for device %x:%x = %x/%x\n", root->vendor, root->device, lnkcap, lnkcap2);
+       return 0;
+}
+EXPORT_SYMBOL(drm_pcie_get_speed_cap_mask);
index 31ad880ca2efa56e380173b463ef6bc939ba837e..e4e3be3b94647e42ae342c3bf85795b657358126 100644 (file)
@@ -1761,6 +1761,11 @@ extern int drm_get_pci_dev(struct pci_dev *pdev,
                           const struct pci_device_id *ent,
                           struct drm_driver *driver);
 
+#define DRM_PCIE_SPEED_25 1
+#define DRM_PCIE_SPEED_50 2
+#define DRM_PCIE_SPEED_80 4
+
+extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
 
 /* platform section */
 extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);