All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: add helper for determining removable devices (USB4, TB)
@ 2026-11-19 14:43 Alex Deucher
  2026-11-19 14:46 ` Mario Limonciello
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Deucher @ 2026-11-19 14:43 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, superm1

Apparently some Intel TB ports don't set dev_is_removable() on attached
devices and thus the current check fails.  Add a helper to check both
dev_is_removable() and TB attached.

Cc: superm1@kernel.org
Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/6163
Fixes: d9b3a066dfcd ("drm/amd: Exclude dGPUs in eGPU enclosures from DPM quirks")
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 24 ++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c     |  4 ++--
 4 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 7e1b9a70fd150..5dfb57e7c0b32 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1053,6 +1053,8 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 
 int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context);
 
+bool amdgpu_device_is_removable(struct amdgpu_device *adev);
+
 int emu_soc_asic_init(struct amdgpu_device *adev);
 
 /*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
index 6bbca70a4e2eb..4918e891f9781 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
@@ -369,7 +369,7 @@ static bool amdgpu_atrm_get_bios(struct amdgpu_device *adev)
 	bool found = false;
 
 	/* ATRM is for on-platform devices only */
-	if (dev_is_removable(&adev->pdev->dev))
+	if (amdgpu_device_is_removable(adev))
 		return false;
 
 	while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index ea960085bfc8c..7179011d1b0a2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -617,8 +617,7 @@ void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
 	int bamaco_support;
 
 	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
-	if (pci_is_thunderbolt_attached(adev->pdev) ||
-	    dev_is_removable(&adev->pdev->dev)) {
+	if (amdgpu_device_is_removable(adev)) {
 		dev_info(adev->dev,
 			 "Runtime PM disabled for externally attached device\n");
 		return;
@@ -1286,6 +1285,16 @@ bool amdgpu_device_seamless_boot_supported(struct amdgpu_device *adev)
 	return amdgpu_ip_version(adev, DCE_HWIP, 0) >= IP_VERSION(3, 0, 0);
 }
 
+bool amdgpu_device_is_removable(struct amdgpu_device *adev)
+{
+	/* older TB systems don't set dev_is_removable so check both here */
+	if (dev_is_removable(adev->dev) ||
+	    pci_is_thunderbolt_attached(adev->pdev))
+		return true;
+
+	return false;
+}
+
 #if IS_ENABLED(CONFIG_X86)
 static const struct x86_cpu_id amdgpu_pcie_dynamic_switching_quirks[] = {
 	/*
@@ -1308,8 +1317,8 @@ static const struct x86_cpu_id amdgpu_pcie_dynamic_switching_quirks[] = {
 
 static bool amdgpu_device_pcie_dynamic_switching_supported(struct amdgpu_device *adev)
 {
-	/* eGPU change speeds based on USB4 fabric conditions */
-	if (dev_is_removable(adev->dev))
+	/* eGPU change speeds based on USB4/TB fabric conditions */
+	if (amdgpu_device_is_removable(adev))
 		return true;
 
 	/* Hosts have problems with dynamic speed switching */
@@ -2077,7 +2086,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	    (amdgpu_is_atpx_hybrid() ||
 	     amdgpu_has_atpx_dgpu_power_cntl()) &&
 	    ((adev->flags & AMD_IS_APU) == 0) &&
-	    !dev_is_removable(&adev->pdev->dev))
+	    !amdgpu_device_is_removable(adev))
 		adev->flags |= AMD_IS_PX;
 
 	if (!(adev->flags & AMD_IS_APU)) {
@@ -3820,9 +3829,8 @@ static void amdgpu_device_sys_interface_fini(struct amdgpu_device *adev)
 static bool
 amdgpu_device_should_register_switcheroo(struct amdgpu_device *adev, bool px)
 {
-	return !pci_is_thunderbolt_attached(adev->pdev) &&
-	       (px || (!dev_is_removable(&adev->pdev->dev) &&
-		       apple_gmux_detect(NULL, NULL)));
+	return !amdgpu_device_is_removable(adev) &&
+		(px || apple_gmux_detect(NULL, NULL));
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c b/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c
index 04041b398781b..3da92fb09495d 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c
@@ -357,7 +357,7 @@ static void nbio_v2_3_enable_aspm(struct amdgpu_device *adev,
 
 		data |= NAVI10_PCIE__LC_L0S_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT;
 
-		if (dev_is_removable(&adev->pdev->dev))
+		if (amdgpu_device_is_removable(adev))
 			data |= NAVI10_PCIE__LC_L1_INACTIVITY_TBT_DEFAULT  << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
 		else
 			data |= NAVI10_PCIE__LC_L1_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
@@ -476,7 +476,7 @@ static void nbio_v2_3_program_aspm(struct amdgpu_device *adev)
 
 	def = data = RREG32_PCIE(smnPCIE_LC_CNTL);
 	data |= NAVI10_PCIE__LC_L0S_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT;
-	if (dev_is_removable(&adev->pdev->dev))
+	if (amdgpu_device_is_removable(adev))
 		data |= NAVI10_PCIE__LC_L1_INACTIVITY_TBT_DEFAULT  << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
 	else
 		data |= NAVI10_PCIE__LC_L1_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdgpu: add helper for determining removable devices (USB4, TB)
  2026-11-19 14:43 [PATCH] drm/amdgpu: add helper for determining removable devices (USB4, TB) Alex Deucher
@ 2026-11-19 14:46 ` Mario Limonciello
  0 siblings, 0 replies; 2+ messages in thread
From: Mario Limonciello @ 2026-11-19 14:46 UTC (permalink / raw)
  To: Alex Deucher, amd-gfx

On 11/19/26 08:43, Alex Deucher wrote:
> Apparently some Intel TB ports don't set dev_is_removable() on attached
> devices and thus the current check fails.  Add a helper to check both
> dev_is_removable() and TB attached.
> 
> Cc: superm1@kernel.org
> Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/6163
> Fixes: d9b3a066dfcd ("drm/amd: Exclude dGPUs in eGPU enclosures from DPM quirks")
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c   |  2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 24 ++++++++++++++--------
>   drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c     |  4 ++--
>   4 files changed, 21 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 7e1b9a70fd150..5dfb57e7c0b32 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1053,6 +1053,8 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
>   
>   int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context);
>   
> +bool amdgpu_device_is_removable(struct amdgpu_device *adev);
> +
>   int emu_soc_asic_init(struct amdgpu_device *adev);
>   
>   /*
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
> index 6bbca70a4e2eb..4918e891f9781 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
> @@ -369,7 +369,7 @@ static bool amdgpu_atrm_get_bios(struct amdgpu_device *adev)
>   	bool found = false;
>   
>   	/* ATRM is for on-platform devices only */
> -	if (dev_is_removable(&adev->pdev->dev))
> +	if (amdgpu_device_is_removable(adev))
>   		return false;
>   
>   	while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index ea960085bfc8c..7179011d1b0a2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -617,8 +617,7 @@ void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
>   	int bamaco_support;
>   
>   	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> -	if (pci_is_thunderbolt_attached(adev->pdev) ||
> -	    dev_is_removable(&adev->pdev->dev)) {
> +	if (amdgpu_device_is_removable(adev)) {
>   		dev_info(adev->dev,
>   			 "Runtime PM disabled for externally attached device\n");
>   		return;
> @@ -1286,6 +1285,16 @@ bool amdgpu_device_seamless_boot_supported(struct amdgpu_device *adev)
>   	return amdgpu_ip_version(adev, DCE_HWIP, 0) >= IP_VERSION(3, 0, 0);
>   }
>   
> +bool amdgpu_device_is_removable(struct amdgpu_device *adev)
> +{
> +	/* older TB systems don't set dev_is_removable so check both here */
> +	if (dev_is_removable(adev->dev) ||
> +	    pci_is_thunderbolt_attached(adev->pdev))
> +		return true;
> +
> +	return false;
> +}
> +
>   #if IS_ENABLED(CONFIG_X86)
>   static const struct x86_cpu_id amdgpu_pcie_dynamic_switching_quirks[] = {
>   	/*
> @@ -1308,8 +1317,8 @@ static const struct x86_cpu_id amdgpu_pcie_dynamic_switching_quirks[] = {
>   
>   static bool amdgpu_device_pcie_dynamic_switching_supported(struct amdgpu_device *adev)
>   {
> -	/* eGPU change speeds based on USB4 fabric conditions */
> -	if (dev_is_removable(adev->dev))
> +	/* eGPU change speeds based on USB4/TB fabric conditions */
> +	if (amdgpu_device_is_removable(adev))
>   		return true;
>   
>   	/* Hosts have problems with dynamic speed switching */
> @@ -2077,7 +2086,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
>   	    (amdgpu_is_atpx_hybrid() ||
>   	     amdgpu_has_atpx_dgpu_power_cntl()) &&
>   	    ((adev->flags & AMD_IS_APU) == 0) &&
> -	    !dev_is_removable(&adev->pdev->dev))
> +	    !amdgpu_device_is_removable(adev))
>   		adev->flags |= AMD_IS_PX;
>   
>   	if (!(adev->flags & AMD_IS_APU)) {
> @@ -3820,9 +3829,8 @@ static void amdgpu_device_sys_interface_fini(struct amdgpu_device *adev)
>   static bool
>   amdgpu_device_should_register_switcheroo(struct amdgpu_device *adev, bool px)
>   {
> -	return !pci_is_thunderbolt_attached(adev->pdev) &&
> -	       (px || (!dev_is_removable(&adev->pdev->dev) &&
> -		       apple_gmux_detect(NULL, NULL)));
> +	return !amdgpu_device_is_removable(adev) &&
> +		(px || apple_gmux_detect(NULL, NULL));
>   }
>   
>   /**
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c b/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c
> index 04041b398781b..3da92fb09495d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c
> @@ -357,7 +357,7 @@ static void nbio_v2_3_enable_aspm(struct amdgpu_device *adev,
>   
>   		data |= NAVI10_PCIE__LC_L0S_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT;
>   
> -		if (dev_is_removable(&adev->pdev->dev))
> +		if (amdgpu_device_is_removable(adev))
>   			data |= NAVI10_PCIE__LC_L1_INACTIVITY_TBT_DEFAULT  << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
>   		else
>   			data |= NAVI10_PCIE__LC_L1_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
> @@ -476,7 +476,7 @@ static void nbio_v2_3_program_aspm(struct amdgpu_device *adev)
>   
>   	def = data = RREG32_PCIE(smnPCIE_LC_CNTL);
>   	data |= NAVI10_PCIE__LC_L0S_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT;
> -	if (dev_is_removable(&adev->pdev->dev))
> +	if (amdgpu_device_is_removable(adev))
>   		data |= NAVI10_PCIE__LC_L1_INACTIVITY_TBT_DEFAULT  << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
>   	else
>   		data |= NAVI10_PCIE__LC_L1_INACTIVITY_DEFAULT << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 14:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 14:43 [PATCH] drm/amdgpu: add helper for determining removable devices (USB4, TB) Alex Deucher
2026-11-19 14:46 ` Mario Limonciello

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.