From 6777264dfabe2a7c75453031bee5bcc2e7882cf7 Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Fri, 26 Jul 2024 14:37:56 +1000 Subject: [PATCH] drm/nouveau: store nvkm_device pointer in nouveau_drm There's various different places in the drm code that get at the nvkm_device via various creative (and not very type-safe) means. One of those being via nvif_device.object.priv. Another patch series is going to entirely remove the ioctl-like interfaces beween the drm code and nvkm, and that field will no longer exist. This provides a safer replacement for accessing the nvkm_device, and will used more in upcoming patches to cleanup other cases. v2: - fixup printk macros to not oops if used before client ctor Signed-off-by: Ben Skeggs Signed-off-by: Danilo Krummrich Link: https://patchwork.freedesktop.org/patch/msgid/20240726043828.58966-6-bskeggs@nvidia.com --- drivers/gpu/drm/nouveau/nouveau_drm.c | 8 +++----- drivers/gpu/drm/nouveau/nouveau_drv.h | 16 ++++++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index f372bf2954aa..140e27af0d64 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -751,6 +751,8 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren if (!drm) return ERR_PTR(-ENOMEM); + drm->nvkm = device; + drm->dev = drm_dev_alloc(drm_driver, parent); if (IS_ERR(drm->dev)) { ret = PTR_ERR(drm->dev); @@ -888,14 +890,10 @@ fail_nvkm: void nouveau_drm_device_remove(struct nouveau_drm *drm) { - struct nvkm_client *client; - struct nvkm_device *device; + struct nvkm_device *device = drm->nvkm; drm_dev_unplug(drm->dev); - client = nvxx_client(&drm->client.base); - device = nvkm_device_find(client->device); - nouveau_drm_device_fini(drm); nouveau_drm_device_del(drm); nvkm_device_del(&device); diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index 7e624c587fc0..e7d072a9a477 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -201,6 +201,7 @@ u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size) #include struct nouveau_drm { + struct nvkm_device *nvkm; struct nvif_parent parent; struct nouveau_cli master; struct nouveau_cli client; @@ -332,18 +333,21 @@ void nouveau_drm_device_remove(struct nouveau_drm *); dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a); \ } while(0) -#define NV_FATAL(drm,f,a...) NV_PRINTK(crit, &(drm)->client, f, ##a) -#define NV_ERROR(drm,f,a...) NV_PRINTK(err, &(drm)->client, f, ##a) -#define NV_WARN(drm,f,a...) NV_PRINTK(warn, &(drm)->client, f, ##a) -#define NV_INFO(drm,f,a...) NV_PRINTK(info, &(drm)->client, f, ##a) +#define NV_PRINTK_(l,drm,f,a...) do { \ + dev_##l((drm)->nvkm->dev, "drm: "f, ##a); \ +} while(0) +#define NV_FATAL(drm,f,a...) NV_PRINTK_(crit, (drm), f, ##a) +#define NV_ERROR(drm,f,a...) NV_PRINTK_(err, (drm), f, ##a) +#define NV_WARN(drm,f,a...) NV_PRINTK_(warn, (drm), f, ##a) +#define NV_INFO(drm,f,a...) NV_PRINTK_(info, (drm), f, ##a) #define NV_DEBUG(drm,f,a...) do { \ if (drm_debug_enabled(DRM_UT_DRIVER)) \ - NV_PRINTK(info, &(drm)->client, f, ##a); \ + NV_PRINTK_(info, (drm), f, ##a); \ } while(0) #define NV_ATOMIC(drm,f,a...) do { \ if (drm_debug_enabled(DRM_UT_ATOMIC)) \ - NV_PRINTK(info, &(drm)->client, f, ##a); \ + NV_PRINTK_(info, (drm), f, ##a); \ } while(0) #define NV_PRINTK_ONCE(l,c,f,a...) NV_PRINTK(l##_once,c,f, ##a)