drm/amd: Refactor `amdgpu_aspm` to be evaluated per device
authorjsg <jsg@openbsd.org>
Wed, 13 Jul 2022 03:50:53 +0000 (03:50 +0000)
committerjsg <jsg@openbsd.org>
Wed, 13 Jul 2022 03:50:53 +0000 (03:50 +0000)
From Mario Limonciello
0a9a60dcedaacde4b903337b7445cb431b4dd119 in linux 5.15.y/5.15.54
0ab5d711ec74d9e60673900974806b7688857947 in mainline linux

sys/dev/pci/drm/amd/amdgpu/amdgpu.h
sys/dev/pci/drm/amd/amdgpu/amdgpu_cik.c
sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c
sys/dev/pci/drm/amd/amdgpu/amdgpu_si.c
sys/dev/pci/drm/amd/amdgpu/nv.c
sys/dev/pci/drm/amd/amdgpu/soc15.c
sys/dev/pci/drm/amd/amdgpu/vi.c
sys/dev/pci/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c

index 50d729a..4420167 100644 (file)
@@ -1314,6 +1314,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 eae678e..c51a5f4 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 735a632..f10abf2 100644 (file)
@@ -1327,6 +1327,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 47d1187..95e9c45 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 2406c60..3bdbd60 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 dcdbbdf..355e5b6 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 f901263..a9a9bae 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 3fa8b43..7ae2f30 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;