public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] drm/amdgpu: register a vga_switcheroo client for MacBooks with apple-gmux
@ 2023-02-16 10:28 Orlando Chamberlain
  2023-02-16 14:52 ` Alex Deucher
  0 siblings, 1 reply; 3+ messages in thread
From: Orlando Chamberlain @ 2023-02-16 10:28 UTC (permalink / raw)
  To: amd-gfx
  Cc: Alex Deucher, Christian König, Pan Xinhui, David Airlie,
	Daniel Vetter, Evan Quan, dri-devel, linux-kernel, Aditya Garg,
	Aun-Ali Zaidi, Kerem Karabay, Orlando Chamberlain

Commit 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and
vga_switcheroo") made amdgpu only register a vga_switcheroo client for
GPU's with PX, however AMD GPUs in dual gpu Apple Macbooks do need to
register, but don't have PX. Instead of AMD's PX, they use apple-gmux.

Use apple_gmux_detect() to identify these gpus, and
pci_is_thunderbolt_attached() to ensure eGPUs connected to Dual GPU
Macbooks don't register with vga_switcheroo.

Fixes: 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and vga_switcheroo")
Link: https://lore.kernel.org/amd-gfx/20230210044826.9834-10-orlandoch.dev@gmail.com/
Signed-off-by: Orlando Chamberlain <orlandoch.dev@gmail.com>
---
v1->v2: Use apple_gmux_detect()
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 2f28a8c02f64..ef8b996f0622 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -35,6 +35,7 @@
 #include <linux/devcoredump.h>
 #include <generated/utsrelease.h>
 #include <linux/pci-p2pdma.h>
+#include <linux/apple-gmux.h>
 
 #include <drm/drm_aperture.h>
 #include <drm/drm_atomic_helper.h>
@@ -3919,12 +3920,15 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
 		vga_client_register(adev->pdev, amdgpu_device_vga_set_decode);
 
-	if (amdgpu_device_supports_px(ddev)) {
-		px = true;
+	px = amdgpu_device_supports_px(ddev);
+
+	if (px || (!pci_is_thunderbolt_attached(adev->pdev) &&
+				apple_gmux_detect(NULL, NULL)))
 		vga_switcheroo_register_client(adev->pdev,
 					       &amdgpu_switcheroo_ops, px);
+
+	if (px)
 		vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
-	}
 
 	if (adev->gmc.xgmi.pending_reset)
 		queue_delayed_work(system_wq, &mgpu_info.delayed_reset_work,
@@ -4029,6 +4033,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
 void amdgpu_device_fini_sw(struct amdgpu_device *adev)
 {
 	int idx;
+	bool px;
 
 	amdgpu_fence_driver_sw_fini(adev);
 	amdgpu_device_ip_fini(adev);
@@ -4048,10 +4053,16 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
 
 	kfree(adev->bios);
 	adev->bios = NULL;
-	if (amdgpu_device_supports_px(adev_to_drm(adev))) {
+
+	px = amdgpu_device_supports_px(adev_to_drm(adev));
+
+	if (px || (!pci_is_thunderbolt_attached(adev->pdev) &&
+				apple_gmux_detect(NULL, NULL)))
 		vga_switcheroo_unregister_client(adev->pdev);
+
+	if (px)
 		vga_switcheroo_fini_domain_pm_ops(adev->dev);
-	}
+
 	if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
 		vga_client_unregister(adev->pdev);
 
-- 
2.39.1


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

* Re: [PATCHv2] drm/amdgpu: register a vga_switcheroo client for MacBooks with apple-gmux
  2023-02-16 10:28 [PATCHv2] drm/amdgpu: register a vga_switcheroo client for MacBooks with apple-gmux Orlando Chamberlain
@ 2023-02-16 14:52 ` Alex Deucher
  2023-02-16 23:15   ` Orlando Chamberlain
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Deucher @ 2023-02-16 14:52 UTC (permalink / raw)
  To: Orlando Chamberlain
  Cc: amd-gfx, Aun-Ali Zaidi, Kerem Karabay, Pan Xinhui, linux-kernel,
	dri-devel, Aditya Garg, Daniel Vetter, Alex Deucher, Evan Quan,
	David Airlie, Christian König

On Thu, Feb 16, 2023 at 8:45 AM Orlando Chamberlain
<orlandoch.dev@gmail.com> wrote:
>
> Commit 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and
> vga_switcheroo") made amdgpu only register a vga_switcheroo client for
> GPU's with PX, however AMD GPUs in dual gpu Apple Macbooks do need to
> register, but don't have PX. Instead of AMD's PX, they use apple-gmux.
>
> Use apple_gmux_detect() to identify these gpus, and
> pci_is_thunderbolt_attached() to ensure eGPUs connected to Dual GPU
> Macbooks don't register with vga_switcheroo.
>
> Fixes: 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and vga_switcheroo")
> Link: https://lore.kernel.org/amd-gfx/20230210044826.9834-10-orlandoch.dev@gmail.com/
> Signed-off-by: Orlando Chamberlain <orlandoch.dev@gmail.com>

This needs ifdefs around the apple_gmux stuff so that it will build
without the gmux support.

Alex

> ---
> v1->v2: Use apple_gmux_detect()
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 2f28a8c02f64..ef8b996f0622 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -35,6 +35,7 @@
>  #include <linux/devcoredump.h>
>  #include <generated/utsrelease.h>
>  #include <linux/pci-p2pdma.h>
> +#include <linux/apple-gmux.h>
>
>  #include <drm/drm_aperture.h>
>  #include <drm/drm_atomic_helper.h>
> @@ -3919,12 +3920,15 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>         if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
>                 vga_client_register(adev->pdev, amdgpu_device_vga_set_decode);
>
> -       if (amdgpu_device_supports_px(ddev)) {
> -               px = true;
> +       px = amdgpu_device_supports_px(ddev);
> +
> +       if (px || (!pci_is_thunderbolt_attached(adev->pdev) &&
> +                               apple_gmux_detect(NULL, NULL)))
>                 vga_switcheroo_register_client(adev->pdev,
>                                                &amdgpu_switcheroo_ops, px);
> +
> +       if (px)
>                 vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
> -       }
>
>         if (adev->gmc.xgmi.pending_reset)
>                 queue_delayed_work(system_wq, &mgpu_info.delayed_reset_work,
> @@ -4029,6 +4033,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
>  void amdgpu_device_fini_sw(struct amdgpu_device *adev)
>  {
>         int idx;
> +       bool px;
>
>         amdgpu_fence_driver_sw_fini(adev);
>         amdgpu_device_ip_fini(adev);
> @@ -4048,10 +4053,16 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
>
>         kfree(adev->bios);
>         adev->bios = NULL;
> -       if (amdgpu_device_supports_px(adev_to_drm(adev))) {
> +
> +       px = amdgpu_device_supports_px(adev_to_drm(adev));
> +
> +       if (px || (!pci_is_thunderbolt_attached(adev->pdev) &&
> +                               apple_gmux_detect(NULL, NULL)))
>                 vga_switcheroo_unregister_client(adev->pdev);
> +
> +       if (px)
>                 vga_switcheroo_fini_domain_pm_ops(adev->dev);
> -       }
> +
>         if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
>                 vga_client_unregister(adev->pdev);
>
> --
> 2.39.1
>

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

* Re: [PATCHv2] drm/amdgpu: register a vga_switcheroo client for MacBooks with apple-gmux
  2023-02-16 14:52 ` Alex Deucher
@ 2023-02-16 23:15   ` Orlando Chamberlain
  0 siblings, 0 replies; 3+ messages in thread
From: Orlando Chamberlain @ 2023-02-16 23:15 UTC (permalink / raw)
  To: Alex Deucher
  Cc: amd-gfx, Aun-Ali Zaidi, Kerem Karabay, Pan Xinhui, linux-kernel,
	dri-devel, Aditya Garg, Daniel Vetter, Alex Deucher, Evan Quan,
	David Airlie, Christian König

On Thu, 16 Feb 2023 09:52:57 -0500
Alex Deucher <alexdeucher@gmail.com> wrote:

> On Thu, Feb 16, 2023 at 8:45 AM Orlando Chamberlain
> <orlandoch.dev@gmail.com> wrote:
> >
> > Commit 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and
> > vga_switcheroo") made amdgpu only register a vga_switcheroo client
> > for GPU's with PX, however AMD GPUs in dual gpu Apple Macbooks do
> > need to register, but don't have PX. Instead of AMD's PX, they use
> > apple-gmux.
> >
> > Use apple_gmux_detect() to identify these gpus, and
> > pci_is_thunderbolt_attached() to ensure eGPUs connected to Dual GPU
> > Macbooks don't register with vga_switcheroo.
> >
> > Fixes: 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and
> > vga_switcheroo") Link:
> > https://lore.kernel.org/amd-gfx/20230210044826.9834-10-orlandoch.dev@gmail.com/
> > Signed-off-by: Orlando Chamberlain <orlandoch.dev@gmail.com>  
> 
> This needs ifdefs around the apple_gmux stuff so that it will build
> without the gmux support.

There are ifdefs in include/linux/apple-gmux.h already, will
those be sufficient?

> 
> Alex
> 
> > ---
> > v1->v2: Use apple_gmux_detect()
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 21
> > ++++++++++++++++----- 1 file changed, 16 insertions(+), 5
> > deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index
> > 2f28a8c02f64..ef8b996f0622 100644 ---
> > a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -35,6 +35,7 @@
> >  #include <linux/devcoredump.h>
> >  #include <generated/utsrelease.h>
> >  #include <linux/pci-p2pdma.h>
> > +#include <linux/apple-gmux.h>
> >
> >  #include <drm/drm_aperture.h>
> >  #include <drm/drm_atomic_helper.h>
> > @@ -3919,12 +3920,15 @@ int amdgpu_device_init(struct amdgpu_device
> > *adev, if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
> >                 vga_client_register(adev->pdev,
> > amdgpu_device_vga_set_decode);
> >
> > -       if (amdgpu_device_supports_px(ddev)) {
> > -               px = true;
> > +       px = amdgpu_device_supports_px(ddev);
> > +
> > +       if (px || (!pci_is_thunderbolt_attached(adev->pdev) &&
> > +                               apple_gmux_detect(NULL, NULL)))
> >                 vga_switcheroo_register_client(adev->pdev,
> >                                                &amdgpu_switcheroo_ops,
> > px); +
> > +       if (px)
> >                 vga_switcheroo_init_domain_pm_ops(adev->dev,
> > &adev->vga_pm_domain);
> > -       }
> >
> >         if (adev->gmc.xgmi.pending_reset)
> >                 queue_delayed_work(system_wq,
> > &mgpu_info.delayed_reset_work, @@ -4029,6 +4033,7 @@ void
> > amdgpu_device_fini_hw(struct amdgpu_device *adev) void
> > amdgpu_device_fini_sw(struct amdgpu_device *adev) {
> >         int idx;
> > +       bool px;
> >
> >         amdgpu_fence_driver_sw_fini(adev);
> >         amdgpu_device_ip_fini(adev);
> > @@ -4048,10 +4053,16 @@ void amdgpu_device_fini_sw(struct
> > amdgpu_device *adev)
> >
> >         kfree(adev->bios);
> >         adev->bios = NULL;
> > -       if (amdgpu_device_supports_px(adev_to_drm(adev))) {
> > +
> > +       px = amdgpu_device_supports_px(adev_to_drm(adev));
> > +
> > +       if (px || (!pci_is_thunderbolt_attached(adev->pdev) &&
> > +                               apple_gmux_detect(NULL, NULL)))
> >                 vga_switcheroo_unregister_client(adev->pdev);
> > +
> > +       if (px)
> >                 vga_switcheroo_fini_domain_pm_ops(adev->dev);
> > -       }
> > +
> >         if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
> >                 vga_client_unregister(adev->pdev);
> >
> > --
> > 2.39.1
> >  


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

end of thread, other threads:[~2023-02-16 23:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-16 10:28 [PATCHv2] drm/amdgpu: register a vga_switcheroo client for MacBooks with apple-gmux Orlando Chamberlain
2023-02-16 14:52 ` Alex Deucher
2023-02-16 23:15   ` Orlando Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox