diff mbox series

[1/3,SRU,J/OEM-5.17] drm/amd: Refactor `amdgpu_aspm` to be evaluated per device

Message ID 20220705140820.42291-1-koba.ko@canonical.com
State New
Headers show
Series [1/3,SRU,J/OEM-5.17] drm/amd: Refactor `amdgpu_aspm` to be evaluated per device | expand

Commit Message

Koba Ko July 5, 2022, 2:08 p.m. UTC
From: Mario Limonciello <mario.limonciello@amd.com>

BugLink: https://bugs.launchpad.net/bugs/1966680

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>
(cherry picked from commit 0ab5d711ec74d9e60673900974806b7688857947)
Signed-off-by: Koba Ko <koba.ko@canonical.com>
---
 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(-)

Comments

Stefan Bader July 13, 2022, 8:25 a.m. UTC | #1
On 05.07.22 16:08, Koba Ko wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1966680
> 
> 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>
> (cherry picked from commit 0ab5d711ec74d9e60673900974806b7688857947)
> Signed-off-by: Koba Ko <koba.ko@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
> ---

All 3 changes appear to be proper cherry picks from upstream and #3 refers to 
fix the problem of enabling ASPM by default. ACKing all 3 patches (you should 
have used a cover email here).

-Stefan

>   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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index e8e8a74026159..2f48a6f7b439d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1296,6 +1296,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);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 052816f0efed4..7956089ed95a3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -1313,6 +1313,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
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 06adb66fd99ab..f0eb4a1a8312d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2012,9 +2012,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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
> index f10ce740a29cc..de6d10390ab2f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/cik.c
> +++ b/drivers/gpu/drm/amd/amdgpu/cik.c
> @@ -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))
> diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
> index 07fc591a65656..0acef9d1dc1fb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nv.c
> @@ -585,7 +585,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) &&
> diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c
> index e6d2f74a79765..7f99e130acd06 100644
> --- a/drivers/gpu/drm/amd/amdgpu/si.c
> +++ b/drivers/gpu/drm/amd/amdgpu/si.c
> @@ -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)
> diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
> index 12f80fdc1fbc9..4683095154db8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/soc15.c
> +++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
> @@ -703,7 +703,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) &&
> diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
> index 6645ebbd2696c..039b90cdc3bca 100644
> --- a/drivers/gpu/drm/amd/amdgpu/vi.c
> +++ b/drivers/gpu/drm/amd/amdgpu/vi.c
> @@ -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 ||
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> index 5488a0edb942d..c96d57ad47ea9 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> @@ -341,7 +341,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;
Tim Gardner July 13, 2022, 12:23 p.m. UTC | #2
On 7/5/22 08:08, Koba Ko wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1966680
> 
> 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>
> (cherry picked from commit 0ab5d711ec74d9e60673900974806b7688857947)
> Signed-off-by: Koba Ko <koba.ko@canonical.com>
> ---
>   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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index e8e8a74026159..2f48a6f7b439d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1296,6 +1296,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);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 052816f0efed4..7956089ed95a3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -1313,6 +1313,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
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 06adb66fd99ab..f0eb4a1a8312d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2012,9 +2012,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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
> index f10ce740a29cc..de6d10390ab2f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/cik.c
> +++ b/drivers/gpu/drm/amd/amdgpu/cik.c
> @@ -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))
> diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
> index 07fc591a65656..0acef9d1dc1fb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nv.c
> @@ -585,7 +585,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) &&
> diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c
> index e6d2f74a79765..7f99e130acd06 100644
> --- a/drivers/gpu/drm/amd/amdgpu/si.c
> +++ b/drivers/gpu/drm/amd/amdgpu/si.c
> @@ -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)
> diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
> index 12f80fdc1fbc9..4683095154db8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/soc15.c
> +++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
> @@ -703,7 +703,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) &&
> diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
> index 6645ebbd2696c..039b90cdc3bca 100644
> --- a/drivers/gpu/drm/amd/amdgpu/vi.c
> +++ b/drivers/gpu/drm/amd/amdgpu/vi.c
> @@ -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 ||
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> index 5488a0edb942d..c96d57ad47ea9 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> @@ -341,7 +341,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;
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Stefan Bader Aug. 2, 2022, 9:56 a.m. UTC | #3
On 05.07.22 16:08, Koba Ko wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1966680
> 
> 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>
> (cherry picked from commit 0ab5d711ec74d9e60673900974806b7688857947)
> Signed-off-by: Koba Ko <koba.ko@canonical.com>
> ---

Applied to jammy:linux/master-next now with a context adjustment to patch #1. I 
am not sure how this can be sanely done to oem-5.17 since the bug report for 
reverting to enable by default was used to fix this properly. With OEM kernels 
potentially having picked up the revert, this is now a rather messy state.  Thanks.

-Stefan

>   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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index e8e8a74026159..2f48a6f7b439d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1296,6 +1296,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);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 052816f0efed4..7956089ed95a3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -1313,6 +1313,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
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 06adb66fd99ab..f0eb4a1a8312d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2012,9 +2012,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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
> index f10ce740a29cc..de6d10390ab2f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/cik.c
> +++ b/drivers/gpu/drm/amd/amdgpu/cik.c
> @@ -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))
> diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
> index 07fc591a65656..0acef9d1dc1fb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nv.c
> @@ -585,7 +585,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) &&
> diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c
> index e6d2f74a79765..7f99e130acd06 100644
> --- a/drivers/gpu/drm/amd/amdgpu/si.c
> +++ b/drivers/gpu/drm/amd/amdgpu/si.c
> @@ -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)
> diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
> index 12f80fdc1fbc9..4683095154db8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/soc15.c
> +++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
> @@ -703,7 +703,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) &&
> diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
> index 6645ebbd2696c..039b90cdc3bca 100644
> --- a/drivers/gpu/drm/amd/amdgpu/vi.c
> +++ b/drivers/gpu/drm/amd/amdgpu/vi.c
> @@ -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 ||
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> index 5488a0edb942d..c96d57ad47ea9 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> @@ -341,7 +341,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;
Timo Aaltonen Aug. 4, 2022, 8:04 a.m. UTC | #4
Koba Ko kirjoitti 5.7.2022 klo 17.08:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1966680
applied to oem-5.17, thanks
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index e8e8a74026159..2f48a6f7b439d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1296,6 +1296,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);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 052816f0efed4..7956089ed95a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1313,6 +1313,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
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 06adb66fd99ab..f0eb4a1a8312d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2012,9 +2012,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;
diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
index f10ce740a29cc..de6d10390ab2f 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik.c
@@ -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))
diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
index 07fc591a65656..0acef9d1dc1fb 100644
--- a/drivers/gpu/drm/amd/amdgpu/nv.c
+++ b/drivers/gpu/drm/amd/amdgpu/nv.c
@@ -585,7 +585,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) &&
diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c
index e6d2f74a79765..7f99e130acd06 100644
--- a/drivers/gpu/drm/amd/amdgpu/si.c
+++ b/drivers/gpu/drm/amd/amdgpu/si.c
@@ -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)
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 12f80fdc1fbc9..4683095154db8 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -703,7 +703,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) &&
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index 6645ebbd2696c..039b90cdc3bca 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -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 ||
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
index 5488a0edb942d..c96d57ad47ea9 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
@@ -341,7 +341,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;