drm/amd: Refactor `amdgpu_aspm` to be evaluated per device
authorMario Limonciello <mario.limonciello@amd.com>
Thu, 17 Feb 2022 05:19:58 +0000 (23:19 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Jul 2022 14:35:06 +0000 (16:35 +0200)
[ Upstream commit 0ab5d711ec74d9e60673900974806b7688857947 ]

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.

Suggested-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/cik.c
drivers/gpu/drm/amd/amdgpu/nv.c
drivers/gpu/drm/amd/amdgpu/si.c
drivers/gpu/drm/amd/amdgpu/soc15.c
drivers/gpu/drm/amd/amdgpu/vi.c
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c

index 2eebefd26fa82cf51430107fbab2e76b8896aef2..5f95d03fd46a03a01892ec589a0cf0d94df00216 100644 (file)
@@ -1285,6 +1285,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);
index a926b5ebbfdf5ecf98dd9fc95c0621097f548f33..d1af709cc7dca63b7cb9c6d6080bd8ff2c9f9d80 100644 (file)
@@ -1309,6 +1309,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
index f10ce740a29ccefdb841c4f232769f79398ecdff..de6d10390ab2f195fcb3a03091f904ce1edf2c0c 100644 (file)
@@ -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))
index 9cbed9a8f1c04b649da643ffd610edc583cd9862..6e277236b44fbad20abec005a11e666a79be7fe8 100644 (file)
@@ -584,7 +584,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) &&
index e6d2f74a79765d1e954fe9b73b8ef009bc3d8b30..7f99e130acd0663eec48e3e6149468fd2b833c45 100644 (file)
@@ -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)
index 6439d5c3d8d8b32ba830561d30de5f6cecc3a289..bdb47ae96ce6ac982b6172d78f046bf8f09d553d 100644 (file)
@@ -689,7 +689,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) &&
index 6645ebbd2696c6b653165b18c74770d2bc42bbe8..039b90cdc3bcac9f22167d7d25489a3ffa113535 100644 (file)
@@ -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 ||
index 574a9d7f7a5e7491791ac69ca5dc5d38e2befdd7..918d5c7c2328b65f650a490ae978d7c4ac82c759 100644 (file)
@@ -338,7 +338,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;