Skip to contentSkip to conversation

drm/amdgpu: check thunderbolt before switcheroo registration

PATCH In review Yang Wang 2 participants 2 messages Aug 12

Subsystems (2)
lore
Share & tools
lore

Yang Wang

author
#0 lore raw

PATCH 1/1 drm/amdgpu: check thunderbolt before switcheroo registration

introduce a helper to consolidate the vga_switcheroo registration condition used by the init and fini paths.

keep the explicit pci_is_thunderbolt_attached() check, as dev_is_removable() does not provide equivalent coverage for thunderbolt-attached gpus.

this ensures such devices remain excluded from switcheroo registration while preserving the existing px and apple gmux handling.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -6
index dd48ad6e9c52..5fd9116d3581 100644
@@ -3807,6 +3807,14 @@ static void amdgpu_device_sys_interface_fini(struct amdgpu_device *adev)
 	amdgpu_ptl_sysfs_fini(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)));
+}
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -4257,9 +4265,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 
 	px = amdgpu_device_supports_px(adev);
 
-	if (!pci_is_thunderbolt_attached(adev->pdev) &&
-	    (px || (!dev_is_removable(&adev->pdev->dev) &&
-		    apple_gmux_detect(NULL, NULL))))
+	if (amdgpu_device_should_register_switcheroo(adev, px))
 		vga_switcheroo_register_client(adev->pdev,
 					       &amdgpu_switcheroo_ops, px);
 
@@ -4424,9 +4430,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
 
 	px = amdgpu_device_supports_px(adev);
 
-	if (!pci_is_thunderbolt_attached(adev->pdev) &&
-	    (px || (!dev_is_removable(&adev->pdev->dev) &&
-		    apple_gmux_detect(NULL, NULL))))
+	if (amdgpu_device_should_register_switcheroo(adev, px))
 		vga_switcheroo_unregister_client(adev->pdev);
 
 	if (px)
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw

AMD General

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Wednesday, August 12, 2026 11:48 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Feng, Kenneth <[email protected]>
Subject: [PATCH] drm/amdgpu: check thunderbolt before switcheroo registration

introduce a helper to consolidate the vga_switcheroo registration condition used by the init and fini paths.

keep the explicit pci_is_thunderbolt_attached() check, as dev_is_removable() does not provide equivalent coverage for thunderbolt-attached gpus.

this ensures such devices remain excluded from switcheroo registration while preserving the existing px and apple gmux handling.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -6
index dd48ad6e9c52..5fd9116d3581 100644
@@ -3807,6 +3807,14 @@ static void amdgpu_device_sys_interface_fini(struct amdgpu_device *adev)
        amdgpu_ptl_sysfs_fini(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))); }
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -4257,9 +4265,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 
        px = amdgpu_device_supports_px(adev);
 
-       if (!pci_is_thunderbolt_attached(adev->pdev) &&
-           (px || (!dev_is_removable(&adev->pdev->dev) &&
-                   apple_gmux_detect(NULL, NULL))))
+       if (amdgpu_device_should_register_switcheroo(adev, px))
                vga_switcheroo_register_client(adev->pdev,
                                               &amdgpu_switcheroo_ops, px);
 
@@ -4424,9 +4430,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
 
        px = amdgpu_device_supports_px(adev);
 
-       if (!pci_is_thunderbolt_attached(adev->pdev) &&
-           (px || (!dev_is_removable(&adev->pdev->dev) &&
-                   apple_gmux_detect(NULL, NULL))))
+       if (amdgpu_device_should_register_switcheroo(adev, px))
                vga_switcheroo_unregister_client(adev->pdev);
 
        if (px)

--
2.54.0