diff mbox series

[08/21] drm/nouveau/nvkm: move vgaarb code from drm

Message ID 20240613170046.88687-9-bskeggs@nvidia.com (mailing list archive)
State New, archived
Headers show
Series drm/nouveau: insert auxiliary device between nvkm and drm | expand

Commit Message

Ben Skeggs June 13, 2024, 5 p.m. UTC
Signed-off-by: Ben Skeggs <bskeggs@nvidia.com>
---
 drivers/gpu/drm/nouveau/nouveau_vga.c         | 27 ----------------
 .../gpu/drm/nouveau/nvkm/subdev/pci/base.c    | 32 +++++++++++++++++++
 2 files changed, 32 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
index 83496af605a1..53b332708061 100644
--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
@@ -1,5 +1,4 @@ 
 // SPDX-License-Identifier: MIT
-#include <linux/vgaarb.h>
 #include <linux/vga_switcheroo.h>
 
 #include <drm/drm_fb_helper.h>
@@ -8,28 +7,6 @@ 
 #include "nouveau_acpi.h"
 #include "nouveau_vga.h"
 
-static unsigned int
-nouveau_vga_set_decode(struct pci_dev *pdev, bool state)
-{
-	struct nouveau_drm *drm = pci_get_drvdata(pdev);
-	struct nvif_device *device = &drm->device;
-
-	if (device->impl->family == NVIF_DEVICE_CURIE &&
-	    device->impl->chipset >= 0x4c)
-		nvif_wr32(device, 0x088060, state);
-	else
-	if (device->impl->chipset >= 0x40)
-		nvif_wr32(device, 0x088054, state);
-	else
-		nvif_wr32(device, 0x001854, state);
-
-	if (state)
-		return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
-		       VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
-	else
-		return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
-}
-
 static void
 nouveau_switcheroo_set_state(struct pci_dev *pdev,
 			     enum vga_switcheroo_state state)
@@ -94,8 +71,6 @@  nouveau_vga_init(struct nouveau_drm *drm)
 		return;
 	pdev = to_pci_dev(dev->dev);
 
-	vga_client_register(pdev, nouveau_vga_set_decode);
-
 	/* don't register Thunderbolt eGPU with vga_switcheroo */
 	if (pci_is_thunderbolt_attached(pdev))
 		return;
@@ -118,8 +93,6 @@  nouveau_vga_fini(struct nouveau_drm *drm)
 		return;
 	pdev = to_pci_dev(dev->dev);
 
-	vga_client_unregister(pdev);
-
 	if (pci_is_thunderbolt_attached(pdev))
 		return;
 
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/pci/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/pci/base.c
index 5a0de45d36ce..e4737b89cb63 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/pci/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/pci/base.c
@@ -27,6 +27,8 @@ 
 #include <core/option.h>
 #include <core/pci.h>
 
+#include <linux/vgaarb.h>
+
 void
 nvkm_pci_msi_rearm(struct nvkm_device *device)
 {
@@ -62,6 +64,29 @@  nvkm_pci_mask(struct nvkm_pci *pci, u16 addr, u32 mask, u32 value)
 	return data;
 }
 
+#include "nouveau_drv.h"
+
+static unsigned int
+nvkm_pci_vga_set_decode(struct pci_dev *pdev, bool state)
+{
+	struct nvkm_device *device = ((struct nouveau_drm *)pci_get_drvdata(pdev))->nvkm;
+
+	if (device->card_type == NV_40 &&
+	    device->chipset >= 0x4c)
+		nvkm_wr32(device, 0x088060, state);
+	else
+	if (device->chipset >= 0x40)
+		nvkm_wr32(device, 0x088054, state);
+	else
+		nvkm_wr32(device, 0x001854, state);
+
+	if (state)
+		return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
+		       VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
+	else
+		return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
+}
+
 void
 nvkm_pci_rom_shadow(struct nvkm_pci *pci, bool shadow)
 {
@@ -76,11 +101,16 @@  nvkm_pci_rom_shadow(struct nvkm_pci *pci, bool shadow)
 static int
 nvkm_pci_fini(struct nvkm_subdev *subdev, bool suspend)
 {
+	struct nvkm_device_pci *pdev = subdev->device->func->pci(subdev->device);
 	struct nvkm_pci *pci = nvkm_pci(subdev);
 
+	if (!subdev->use.enabled)
+		return 0;
+
 	if (pci->agp.bridge)
 		nvkm_agp_fini(pci);
 
+	vga_client_unregister(pdev->pdev);
 	return 0;
 }
 
@@ -111,6 +141,7 @@  nvkm_pci_oneinit(struct nvkm_subdev *subdev)
 static int
 nvkm_pci_init(struct nvkm_subdev *subdev)
 {
+	struct nvkm_device_pci *pdev = subdev->device->func->pci(subdev->device);
 	struct nvkm_pci *pci = nvkm_pci(subdev);
 	int ret;
 
@@ -131,6 +162,7 @@  nvkm_pci_init(struct nvkm_subdev *subdev)
 	if (pci->msi)
 		pci->func->msi_rearm(pci);
 
+	vga_client_register(pdev->pdev, nvkm_pci_vga_set_decode);
 	return 0;
 }