]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: check ASPM on the dGPU host link
authorYang Wang <kevinyang.wang@amd.com>
Wed, 5 Aug 2026 12:39:18 +0000 (20:39 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 12 Aug 2026 14:21:31 +0000 (10:21 -0400)
dGPUs with an internal PCIe switch expose graphics functions below the
switch downstream port. The automatic ASPM check uses the display
endpoint and evaluates the internal link instead of the host link.

Use the switch upstream port for the check and report the selected
link.

Fixes: 0ab5d711ec74 ("drm/amd: Refactor `amdgpu_aspm` to be evaluated per device")
Signed-off-by: Yang Wang <kevinyang.wang@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Reviewed-by: Kenneth Feng <kenneth.feng@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 4e0d6f2876e704fff707b18c40dbd383aea4a1c9)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

index bff3e06a756c5217d2a8e303f483bca2aaa4a634..16049bfb627b540c205435b5d9a8a69dd6a51c05 100644 (file)
@@ -1370,6 +1370,31 @@ static bool amdgpu_device_aspm_support_quirk(struct amdgpu_device *adev)
 #endif
 }
 
+/*
+ * Some dGPUs expose their display endpoint below an internal PCIe switch.
+ * Use the switch upstream port to query the host-facing link.
+ */
+static struct pci_dev *amdgpu_device_get_aspm_pdev(struct amdgpu_device *adev)
+{
+       struct pci_dev *swds, *swus;
+
+       swds = pci_upstream_bridge(adev->pdev);
+       if (!swds ||
+           (swds->vendor != PCI_VENDOR_ID_ATI &&
+            swds->vendor != PCI_VENDOR_ID_AMD) ||
+           pci_pcie_type(swds) != PCI_EXP_TYPE_DOWNSTREAM)
+               return adev->pdev;
+
+       swus = pci_upstream_bridge(swds);
+       if (!swus ||
+           (swus->vendor != PCI_VENDOR_ID_ATI &&
+            swus->vendor != PCI_VENDOR_ID_AMD) ||
+           pci_pcie_type(swus) != PCI_EXP_TYPE_UPSTREAM)
+               return adev->pdev;
+
+       return swus;
+}
+
 /**
  * amdgpu_device_should_use_aspm - check if the device should program ASPM
  *
@@ -1382,6 +1407,9 @@ static bool amdgpu_device_aspm_support_quirk(struct amdgpu_device *adev)
  */
 bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev)
 {
+       struct pci_dev *aspm_pdev, *parent;
+       bool enabled;
+
        switch (amdgpu_aspm) {
        case -1:
                break;
@@ -1396,7 +1424,27 @@ bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev)
                return false;
        if (amdgpu_device_aspm_support_quirk(adev))
                return false;
-       return pcie_aspm_enabled(adev->pdev);
+
+       /*
+        * pcie_aspm_enabled() checks the link between its argument and
+        * the immediate upstream bridge. Use SWUS for dGPUs with an
+        * internal switch so that this is the host-facing link.
+        */
+       aspm_pdev = amdgpu_device_get_aspm_pdev(adev);
+       parent = pci_upstream_bridge(aspm_pdev);
+       if (!parent) {
+               dev_dbg(adev->dev, "ASPM: no upstream PCIe link for %s\n",
+                       pci_name(aspm_pdev));
+               return false;
+       }
+
+       enabled = pcie_aspm_enabled(aspm_pdev);
+       /* Report the exact link used for the automatic ASPM decision. */
+       dev_dbg(adev->dev, "ASPM: link %s <-> %s is %s\n",
+               pci_name(parent), pci_name(aspm_pdev),
+               enabled ? "enabled" : "disabled");
+
+       return enabled;
 }
 
 /* if we get transitioned to only one device, take VGA back */