]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
drm/nouveau: store nvkm_device pointer in nouveau_drm
authorBen Skeggs <bskeggs@nvidia.com>
Fri, 26 Jul 2024 04:37:56 +0000 (14:37 +1000)
committerDanilo Krummrich <dakr@kernel.org>
Sat, 27 Jul 2024 01:05:21 +0000 (03:05 +0200)
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 <bskeggs@nvidia.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240726043828.58966-6-bskeggs@nvidia.com
drivers/gpu/drm/nouveau/nouveau_drm.c
drivers/gpu/drm/nouveau/nouveau_drv.h

index f372bf2954aa3fe26a47725321ae6e0e900af421..140e27af0d649b87d4e1dc0730feafd6d35070be 100644 (file)
@@ -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);
index 7e624c587fc03c679f2e82c8d3f80f4319984025..e7d072a9a47777ea84bd76d7eb75446b6fe2d72f 100644 (file)
@@ -201,6 +201,7 @@ u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size)
 #include <nvif/parent.h>
 
 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)