Skip to contentSkip to conversation

drm/amd: Refactor `amdgpu_aspm` to be evaluated per device

PATCH In review Mario Limonciello 3 participants 4 messages Feb 17, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amd: Refactor `amdgpu_aspm` to be evaluated per device

Evaluating pcie_aspm_enabled as part of driver probe has the implication that if one PCIe bridge with an AMD GPU connected doesn't support ASPM then none of them do. This is an invalid assumption as the PCIe core will configure ASPM for individual PCIe bridges.

Create a new helper function that can be called by individual dGPUs to react to the amdgpu_aspm module parameter without having negative results for other dGPUs on the PCIe bus.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    | 25 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 ---
 drivers/gpu/drm/amd/amdgpu/cik.c              |  2 +-
 drivers/gpu/drm/amd/amdgpu/nv.c               |  2 +-
 drivers/gpu/drm/amd/amdgpu/si.c               |  2 +-
 drivers/gpu/drm/amd/amdgpu/soc15.c            |  2 +-
 drivers/gpu/drm/amd/amdgpu/vi.c               |  2 +-
 .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c   |  2 +-
 9 files changed, 32 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 3a126dce8a2f..f0a34aa4af78 100644
@@ -1297,6 +1297,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
 int amdgpu_device_pci_reset(struct amdgpu_device *adev);
 bool amdgpu_device_need_post(struct amdgpu_device *adev);
+bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev);
 
 void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
 				  u64 num_vis_bytes);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +25 -0
index 4667c992a4cc..283d7a7a5249 100644
@@ -1318,6 +1318,31 @@ bool amdgpu_device_need_post(struct amdgpu_device *adev)
 	return true;
 }
 
+/**
+ * amdgpu_device_should_use_aspm - check if the device should program ASPM
+ *
+ * @adev: amdgpu_device pointer
+ *
+ * Confirm whether the module parameter and pcie bridge agree that ASPM should
+ * be set for this device.
+ *
+ * Returns true if it should be used or false if not.
+ */
+bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev)
+{
+	switch (amdgpu_aspm) {
+	case -1:
+		break;
+	case 0:
+		return false;
+	case 1:
+		return true;
+	default:
+		return false;
+	}
+	return pcie_aspm_enabled(adev->pdev);
+}
+
 /* if we get transitioned to only one device, take VGA back */
 /**
  * amdgpu_device_vga_set_decode - enable/disable vga decode
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -3
index d2548fab51c5..5acd0473ed01 100644
@@ -2008,9 +2008,6 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 			return -ENODEV;
 	}
 
-	if (amdgpu_aspm == -1 && !pcie_aspm_enabled(pdev))
-		amdgpu_aspm = 0;
-
 	if (amdgpu_virtual_display ||
 	    amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
 		supports_atomic = true;
drivers/gpu/drm/amd/amdgpu/cik.c +1 -1
index f10ce740a29c..de6d10390ab2 100644
@@ -1719,7 +1719,7 @@ static void cik_program_aspm(struct amdgpu_device *adev)
 	bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
 	bool disable_clkreq = false;
 
-	if (amdgpu_aspm == 0)
+	if (!amdgpu_device_should_use_aspm(adev))
 		return;
 
 	if (pci_is_root_bus(adev->pdev->bus))
drivers/gpu/drm/amd/amdgpu/nv.c +1 -1
index 8a5642f2daa6..ebed9c84db04 100644
@@ -520,7 +520,7 @@ static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
 
 static void nv_program_aspm(struct amdgpu_device *adev)
 {
-	if (!amdgpu_aspm)
+	if (!amdgpu_device_should_use_aspm(adev))
 		return;
 
 	if (!(adev->flags & AMD_IS_APU) &&
drivers/gpu/drm/amd/amdgpu/si.c +1 -1
index e6d2f74a7976..7f99e130acd0 100644
@@ -2453,7 +2453,7 @@ static void si_program_aspm(struct amdgpu_device *adev)
 	bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
 	bool disable_clkreq = false;
 
-	if (amdgpu_aspm == 0)
+	if (!amdgpu_device_should_use_aspm(adev))
 		return;
 
 	if (adev->flags & AMD_IS_APU)
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -1
index 99a88f4d8050..fe21397323b0 100644
@@ -670,7 +670,7 @@ static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
 
 static void soc15_program_aspm(struct amdgpu_device *adev)
 {
-	if (!amdgpu_aspm)
+	if (!amdgpu_device_should_use_aspm(adev))
 		return;
 
 	if (!(adev->flags & AMD_IS_APU) &&
drivers/gpu/drm/amd/amdgpu/vi.c +1 -1
index 6645ebbd2696..039b90cdc3bc 100644
@@ -1140,7 +1140,7 @@ static void vi_program_aspm(struct amdgpu_device *adev)
 	bool bL1SS = false;
 	bool bClkReqSupport = true;
 
-	if (!amdgpu_aspm)
+	if (!amdgpu_device_should_use_aspm(adev))
 		return;
 
 	if (adev->flags & AMD_IS_APU ||
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +1 -1
index 4f0bc1841283..d9d634ce9575 100644
@@ -348,7 +348,7 @@ sienna_cichlid_get_allowed_feature_mask(struct smu_context *smu,
 	if (smu->dc_controlled_by_gpio)
        *(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_ACDC_BIT);
 
-	if (amdgpu_aspm)
+	if (amdgpu_device_should_use_aspm(adev))
 		*(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DS_LCLK_BIT);
 
 	return 0;
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 drm/amd: Use amdgpu_device_should_use_aspm on navi umd pstate switching

The program_aspm callback is already guarded for aspm, but the enable_aspm callback doesn't follow the module parameter.

Update it to use the helper amdgpu_device_should_use_aspm.

---
 drivers/gpu/drm/amd/amdgpu/nv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nv.c +2 -1
index ebed9c84db04..b246a37f4f39 100644
@@ -635,7 +635,8 @@ static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,
 		adev->gfx.funcs->update_perfmon_mgcg(adev, !enter);
 
 	if (!(adev->flags & AMD_IS_APU) &&
-	    (adev->nbio.funcs->enable_aspm))
+	    (adev->nbio.funcs->enable_aspm) &&
+	     amdgpu_device_should_use_aspm(adev))
 		adev->nbio.funcs->enable_aspm(adev, !enter);
 
 	return 0;
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/amd: Use amdgpu_device_should_use_aspm on navi umd pstate switching

Quoted 6 lines · Mario Limonciello

The program_aspm callback is already guarded for aspm, but the enable_aspm callback doesn't follow the module parameter.

Update it to use the helper amdgpu_device_should_use_aspm.

Series is

Thanks,
Lijo

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/nv.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/nv.c +2 -1
index ebed9c84db04..b246a37f4f39 100644
@@ -635,7 +635,8 @@ static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,
  		adev->gfx.funcs->update_perfmon_mgcg(adev, !enter);
 
  	if (!(adev->flags & AMD_IS_APU) &&
-	    (adev->nbio.funcs->enable_aspm))
+	    (adev->nbio.funcs->enable_aspm) &&
+	     amdgpu_device_should_use_aspm(adev))
  		adev->nbio.funcs->enable_aspm(adev, !enter);
 
  	return 0;
Reviewed-by on v1 1/2
#3 lore raw
In reply to Mario Limonciello

Series is:

Quoted 167 lines · Mario Limonciello

Evaluating pcie_aspm_enabled as part of driver probe has the implication that if one PCIe bridge with an AMD GPU connected doesn't support ASPM then none of them do. This is an invalid assumption as the PCIe core will configure ASPM for individual PCIe bridges.

Create a new helper function that can be called by individual dGPUs to react to the amdgpu_aspm module parameter without having negative results for other dGPUs on the PCIe bus.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    | 25 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 ---
 drivers/gpu/drm/amd/amdgpu/cik.c              |  2 +-
 drivers/gpu/drm/amd/amdgpu/nv.c               |  2 +-
 drivers/gpu/drm/amd/amdgpu/si.c               |  2 +-
 drivers/gpu/drm/amd/amdgpu/soc15.c            |  2 +-
 drivers/gpu/drm/amd/amdgpu/vi.c               |  2 +-
 .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c   |  2 +-
 9 files changed, 32 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 3a126dce8a2f..f0a34aa4af78 100644
@@ -1297,6 +1297,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
 int amdgpu_device_pci_reset(struct amdgpu_device *adev);
 bool amdgpu_device_need_post(struct amdgpu_device *adev);
+bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev);
 
 void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
                                  u64 num_vis_bytes);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +25 -0
index 4667c992a4cc..283d7a7a5249 100644
@@ -1318,6 +1318,31 @@ bool amdgpu_device_need_post(struct amdgpu_device *adev)
        return true;
 }
 
+/**
+ * amdgpu_device_should_use_aspm - check if the device should program ASPM
+ *
+ * @adev: amdgpu_device pointer
+ *
+ * Confirm whether the module parameter and pcie bridge agree that ASPM should
+ * be set for this device.
+ *
+ * Returns true if it should be used or false if not.
+ */
+bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev)
+{
+       switch (amdgpu_aspm) {
+       case -1:
+               break;
+       case 0:
+               return false;
+       case 1:
+               return true;
+       default:
+               return false;
+       }
+       return pcie_aspm_enabled(adev->pdev);
+}
+
 /* if we get transitioned to only one device, take VGA back */
 /**
  * amdgpu_device_vga_set_decode - enable/disable vga decode
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -3
index d2548fab51c5..5acd0473ed01 100644
@@ -2008,9 +2008,6 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
                        return -ENODEV;
        }
 
-       if (amdgpu_aspm == -1 && !pcie_aspm_enabled(pdev))
-               amdgpu_aspm = 0;
-
        if (amdgpu_virtual_display ||
            amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
                supports_atomic = true;
drivers/gpu/drm/amd/amdgpu/cik.c +1 -1
index f10ce740a29c..de6d10390ab2 100644
@@ -1719,7 +1719,7 @@ static void cik_program_aspm(struct amdgpu_device *adev)
        bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
        bool disable_clkreq = false;
 
-       if (amdgpu_aspm == 0)
+       if (!amdgpu_device_should_use_aspm(adev))
                return;
 
        if (pci_is_root_bus(adev->pdev->bus))
drivers/gpu/drm/amd/amdgpu/nv.c +1 -1
index 8a5642f2daa6..ebed9c84db04 100644
@@ -520,7 +520,7 @@ static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
 
 static void nv_program_aspm(struct amdgpu_device *adev)
 {
-       if (!amdgpu_aspm)
+       if (!amdgpu_device_should_use_aspm(adev))
                return;
 
        if (!(adev->flags & AMD_IS_APU) &&
drivers/gpu/drm/amd/amdgpu/si.c +1 -1
index e6d2f74a7976..7f99e130acd0 100644
@@ -2453,7 +2453,7 @@ static void si_program_aspm(struct amdgpu_device *adev)
        bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
        bool disable_clkreq = false;
 
-       if (amdgpu_aspm == 0)
+       if (!amdgpu_device_should_use_aspm(adev))
                return;
 
        if (adev->flags & AMD_IS_APU)
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -1
index 99a88f4d8050..fe21397323b0 100644
@@ -670,7 +670,7 @@ static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
 
 static void soc15_program_aspm(struct amdgpu_device *adev)
 {
-       if (!amdgpu_aspm)
+       if (!amdgpu_device_should_use_aspm(adev))
                return;
 
        if (!(adev->flags & AMD_IS_APU) &&
drivers/gpu/drm/amd/amdgpu/vi.c +1 -1
index 6645ebbd2696..039b90cdc3bc 100644
@@ -1140,7 +1140,7 @@ static void vi_program_aspm(struct amdgpu_device *adev)
        bool bL1SS = false;
        bool bClkReqSupport = true;
 
-       if (!amdgpu_aspm)
+       if (!amdgpu_device_should_use_aspm(adev))
                return;
 
        if (adev->flags & AMD_IS_APU ||
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +1 -2
index 4f0bc1841283..d9d634ce9575 100644
@@ -348,7 +348,7 @@ sienna_cichlid_get_allowed_feature_mask(struct smu_context *smu,
        if (smu->dc_controlled_by_gpio)
        *(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_ACDC_BIT);
 
-       if (amdgpu_aspm)
+       if (amdgpu_device_should_use_aspm(adev))
                *(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DS_LCLK_BIT);
 
        return 0;
--

2.25.1