[PATCH 12/21] drm/nouveau/nvkm: prepare pci/tegra probe()/remove() functions

Ben Skeggs bskeggs at nvidia.com
Thu Jun 13 17:00:04 UTC 2024


Rename, and modify the signatures of nvkm_device_{pci,tegra}_new() to be
consistent with pci/platform driver probe() functions.

The DRM driver is still calling the functions as it did before, just via
the new pci/platform driver structs in NVKM that will eventually be used
for driver registration.

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 .../gpu/drm/nouveau/include/nvkm/core/pci.h   |  3 +-
 .../gpu/drm/nouveau/include/nvkm/core/tegra.h |  5 +--
 drivers/gpu/drm/nouveau/nouveau_drm.c         | 13 ++++---
 drivers/gpu/drm/nouveau/nouveau_platform.c    |  2 +
 drivers/gpu/drm/nouveau/nvkm/device/pci.c     | 24 ++++++++++--
 drivers/gpu/drm/nouveau/nvkm/device/tegra.c   | 37 ++++++++++++-------
 6 files changed, 55 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvkm/core/pci.h b/drivers/gpu/drm/nouveau/include/nvkm/core/pci.h
index a1e9ee6da44e..b9e10dad6ee9 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/core/pci.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/core/pci.h
@@ -11,6 +11,5 @@ struct nvkm_device_pci {
 	struct dev_pm_domain vga_pm_domain;
 };
 
-int nvkm_device_pci_new(struct pci_dev *, const char *cfg, const char *dbg,
-			struct nvkm_device **);
+extern struct pci_driver nvkm_device_pci_driver;
 #endif
diff --git a/drivers/gpu/drm/nouveau/include/nvkm/core/tegra.h b/drivers/gpu/drm/nouveau/include/nvkm/core/tegra.h
index 22f74fc88cd7..e641f387fa3e 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/core/tegra.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/core/tegra.h
@@ -48,8 +48,5 @@ struct nvkm_device_tegra_func {
 	bool require_vdd;
 };
 
-int nvkm_device_tegra_new(const struct nvkm_device_tegra_func *,
-			  struct platform_device *,
-			  const char *cfg, const char *dbg,
-			  struct nvkm_device **);
+extern struct platform_driver nvkm_device_tegra;
 #endif
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 580849b78231..632635c16b88 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -801,10 +801,12 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 	/* We need to check that the chipset is supported before booting
 	 * fbdev off the hardware, as there's no way to put it back.
 	 */
-	ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug, &device);
+	ret = nvkm_device_pci_driver.probe(pdev, NULL);
 	if (ret)
 		return ret;
 
+	device = pci_get_drvdata(pdev);
+
 	/* Remove conflicting drivers (vesafb, efifb etc). */
 	ret = drm_aperture_remove_conflicting_pci_framebuffers(pdev, &driver_pci);
 	if (ret)
@@ -849,13 +851,10 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 void
 nouveau_drm_device_remove(struct nouveau_drm *drm)
 {
-	struct nvkm_device *device = drm->nvkm;
-
 	drm_dev_unplug(drm->dev);
 
 	nouveau_drm_device_fini(drm);
 	nouveau_drm_device_del(drm);
-	nvkm_device_del(&device);
 }
 
 static void
@@ -868,6 +867,8 @@ nouveau_drm_remove(struct pci_dev *pdev)
 		pdev->pm_cap = drm->old_pm_cap;
 	nouveau_drm_device_remove(drm);
 	pci_disable_device(pdev);
+
+	nvkm_device_pci_driver.remove(pdev);
 }
 
 static int
@@ -1349,10 +1350,12 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 	struct nouveau_drm *drm;
 	int err;
 
-	err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug, pdevice);
+	err = nvkm_device_tegra.probe(pdev);
 	if (err)
 		return ERR_PTR(err);
 
+	*pdevice = platform_get_drvdata(pdev);
+
 	drm = nouveau_drm_device_new(&driver_platform, &pdev->dev, *pdevice);
 	if (IS_ERR(drm)) {
 		err = PTR_ERR(drm);
diff --git a/drivers/gpu/drm/nouveau/nouveau_platform.c b/drivers/gpu/drm/nouveau/nouveau_platform.c
index 3194b110eff8..23beac1f96f1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_platform.c
+++ b/drivers/gpu/drm/nouveau/nouveau_platform.c
@@ -42,6 +42,8 @@ static void nouveau_platform_remove(struct platform_device *pdev)
 	struct nouveau_drm *drm = platform_get_drvdata(pdev);
 
 	nouveau_drm_device_remove(drm);
+
+	nvkm_device_tegra.remove_new(pdev);
 }
 
 #if IS_ENABLED(CONFIG_OF)
diff --git a/drivers/gpu/drm/nouveau/nvkm/device/pci.c b/drivers/gpu/drm/nouveau/nvkm/device/pci.c
index 16e059866168..be6433eab814 100644
--- a/drivers/gpu/drm/nouveau/nvkm/device/pci.c
+++ b/drivers/gpu/drm/nouveau/nvkm/device/pci.c
@@ -1626,9 +1626,19 @@ nvkm_device_pci_func = {
 	.cpu_coherent = !IS_ENABLED(CONFIG_ARM),
 };
 
-int
-nvkm_device_pci_new(struct pci_dev *pci_dev, const char *cfg, const char *dbg,
-		    struct nvkm_device **pdevice)
+#include "nouveau_drv.h"
+
+static void
+nvkm_device_pci_remove(struct pci_dev *dev)
+{
+	struct drm_device *drm_dev = pci_get_drvdata(dev);
+	struct nvkm_device *device = nouveau_drm(drm_dev)->nvkm;
+
+	nvkm_device_del(&device);
+}
+
+static int
+nvkm_device_pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
 {
 	const struct nvkm_device_quirk *quirk = NULL;
 	const struct nvkm_device_pci_device *pcid;
@@ -1705,7 +1715,7 @@ nvkm_device_pci_new(struct pci_dev *pci_dev, const char *cfg, const char *dbg,
 		return ret;
 	}
 
-	*pdevice = &pdev->device;
+	pci_set_drvdata(pci_dev, &pdev->device);
 
 	if (nvkm_runpm) {
 		if (!nouveau_dsm_priv.optimus_detected) {
@@ -1718,3 +1728,9 @@ nvkm_device_pci_new(struct pci_dev *pci_dev, const char *cfg, const char *dbg,
 
 	return 0;
 }
+
+struct pci_driver
+nvkm_device_pci_driver = {
+	.probe = nvkm_device_pci_probe,
+	.remove = nvkm_device_pci_remove,
+};
diff --git a/drivers/gpu/drm/nouveau/nvkm/device/tegra.c b/drivers/gpu/drm/nouveau/nvkm/device/tegra.c
index 9c3673c74b19..f0c1258170f4 100644
--- a/drivers/gpu/drm/nouveau/nvkm/device/tegra.c
+++ b/drivers/gpu/drm/nouveau/nvkm/device/tegra.c
@@ -233,12 +233,20 @@ nvkm_device_tegra_func = {
 	.cpu_coherent = false,
 };
 
-int
-nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
-		      struct platform_device *pdev,
-		      const char *cfg, const char *dbg,
-		      struct nvkm_device **pdevice)
+#include "nouveau_drv.h"
+
+static void
+nvkm_device_tegra_remove(struct platform_device *pdev)
+{
+	struct nvkm_device *device = ((struct nouveau_drm *)platform_get_drvdata(pdev))->nvkm;
+
+	nvkm_device_del(&device);
+}
+
+static int
+nvkm_device_tegra_probe(struct platform_device *pdev)
 {
+	const struct nvkm_device_tegra_func *func = of_device_get_match_data(&pdev->dev);
 	struct nvkm_device_tegra *tdev;
 	struct nvkm_device *device;
 	unsigned long rate;
@@ -318,7 +326,7 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
 		return ret;
 	}
 
-	*pdevice = &tdev->device;
+	platform_set_drvdata(pdev, &tdev->device);
 	return 0;
 
 remove:
@@ -327,13 +335,14 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
 	kfree(tdev);
 	return ret;
 }
+
+struct platform_driver
+nvkm_device_tegra = {
+	.probe = nvkm_device_tegra_probe,
+	.remove_new = nvkm_device_tegra_remove,
+};
 #else
-int
-nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
-		      struct platform_device *pdev,
-		      const char *cfg, const char *dbg,
-		      struct nvkm_device **pdevice)
-{
-	return -ENOSYS;
-}
+struct platform_driver
+nvkm_device_tegra = {
+};
 #endif
-- 
2.44.0



More information about the Nouveau mailing list