Skip to contentSkip to conversation

drm/amdgpu: add helper for determining removable devices (USB4, TB)

PATCH In review Alex Deucher 2 participants 2 messages Nov 19

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: add helper for determining removable devices (USB4, TB)

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.

Fixes d9b3a066dfcd ("drm/amd: Exclude dGPUs in eGPU enclosures from DPM quirks")
---
 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index 7e1b9a70fd150..5dfb57e7c0b32 100644
@@ -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);
 
 /*
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +1 -1
index 6bbca70a4e2eb..4918e891f9781 100644
@@ -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))) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +16 -8
index ea960085bfc8c..7179011d1b0a2 100644
@@ -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));
 }
 
 /**
drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c +2 -2
index 04041b398781b..3da92fb09495d 100644
@@ -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;
Signature · 1 line
2.56.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Alex Deucher

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.

Fixes d9b3a066dfcd ("drm/amd: Exclude dGPUs in eGPU enclosures from DPM quirks")
Quoted 118 lines
---
  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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index 7e1b9a70fd150..5dfb57e7c0b32 100644
@@ -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);
 
  /*
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +1 -1
index 6bbca70a4e2eb..4918e891f9781 100644
@@ -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))) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +16 -8
index ea960085bfc8c..7179011d1b0a2 100644
@@ -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));
  }
 
  /**
drivers/gpu/drm/amd/amdgpu/nbio_v2_3.c +2 -2
index 04041b398781b..3da92fb09495d 100644
@@ -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;