drm/nouveau/device: convert user class to new-style nvkm_object
authorBen Skeggs <bskeggs@redhat.com>
Thu, 20 Aug 2015 04:54:18 +0000 (14:54 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 28 Aug 2015 02:40:39 +0000 (12:40 +1000)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvkm/core/device.h
drivers/gpu/drm/nouveau/nvkm/core/client.c
drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
drivers/gpu/drm/nouveau/nvkm/engine/dmaobj/base.c
drivers/gpu/drm/nouveau/nvkm/engine/pm/base.c

index 3786982c1360b420a4eb0f952e171a87e42e2dae..2467d4e0acf679f012679ca1e3235599374ae4e6 100644 (file)
@@ -272,10 +272,10 @@ enum nv_bus_type {
        NVKM_BUS_PLATFORM,
 };
 
-extern struct nvkm_ofuncs nvkm_udevice_ofuncs;
-
 void nvkm_device_del(struct nvkm_device **);
 
+extern const struct nvkm_sclass nvkm_udevice_sclass;
+
 /* device logging */
 #define nvdev_printk_(d,l,p,f,a...) do {                                       \
        struct nvkm_device *_device = (d);                                     \
index 1affa2299a8ce6435d141c3f3c3593a10ac67f9a..dce1d45cac5efe33d4b7e3e33a78131607f24af1 100644 (file)
@@ -180,25 +180,24 @@ static int
 nvkm_client_child_new(const struct nvkm_oclass *oclass,
                      void *data, u32 size, struct nvkm_object **pobject)
 {
-       static struct nvkm_oclass devobj = {
-               .handle = NV_DEVICE,
-               .ofuncs = &nvkm_udevice_ofuncs,
-       };
-       return nvkm_object_old(oclass->parent, NULL, &devobj, data, size, pobject);
+       return oclass->base.ctor(oclass, data, size, pobject);
 }
 
 static int
 nvkm_client_child_get(struct nvkm_object *object, int index,
                      struct nvkm_oclass *oclass)
 {
-       if (index == 0) {
-               oclass->base.oclass = NV_DEVICE;
-               oclass->base.minver = 0;
-               oclass->base.maxver = 0;
-               oclass->ctor = nvkm_client_child_new;
-               return 0;
+       const struct nvkm_sclass *sclass;
+
+       switch (index) {
+       case 0: sclass = &nvkm_udevice_sclass; break;
+       default:
+               return -EINVAL;
        }
-       return -EINVAL;
+
+       oclass->ctor = nvkm_client_child_new;
+       oclass->base = *sclass;
+       return 0;
 }
 
 static const struct nvkm_object_func
index a59a8e50706bac815fd5bfb30f7ecf5bcaf56e9c..73770fb4da975ee5e2f2f6663ff298364c6614ad 100644 (file)
@@ -1990,7 +1990,7 @@ nv_device(void *obj)
                        if (!nv_iclass(device, NV_SUBDEV_CLASS) &&
                            device->parent == &nvkm_client(device)->object) {
                                struct {
-                                       struct nvkm_parent base;
+                                       struct nvkm_object base;
                                        struct nvkm_device *device;
                                } *udevice = (void *)device;
                                return udevice->device;
index 59b28cbe66344995eaf2f9dc953de86558132420..fb4d04dc9340fc2ae5c142bc0b45cc32c1b19d1a 100644 (file)
@@ -21,6 +21,7 @@
  *
  * Authors: Ben Skeggs
  */
+#define nvkm_udevice(p) container_of((p), struct nvkm_udevice, object)
 #include "priv.h"
 
 #include <core/client.h>
 #include <subdev/fb.h>
 #include <subdev/instmem.h>
 #include <subdev/timer.h>
+#include <engine/disp.h>
+#include <engine/dmaobj.h>
+#include <engine/fifo.h>
+#include <engine/pm.h>
 
 #include <nvif/class.h>
 #include <nvif/unpack.h>
 
 struct nvkm_udevice {
-       struct nvkm_parent base;
+       struct nvkm_object object;
        struct nvkm_device *device;
 };
 
 static int
-nvkm_udevice_info(struct nvkm_object *object, void *data, u32 size)
+nvkm_udevice_info(struct nvkm_udevice *udev, void *data, u32 size)
 {
-       struct nvkm_udevice *udev = (void *)object;
+       struct nvkm_object *object = &udev->object;
        struct nvkm_device *device = udev->device;
        struct nvkm_fb *fb = device->fb;
        struct nvkm_instmem *imem = device->imem;
@@ -114,9 +119,8 @@ nvkm_udevice_info(struct nvkm_object *object, void *data, u32 size)
 }
 
 static int
-nvkm_udevice_time(struct nvkm_object *object, void *data, u32 size)
+nvkm_udevice_time(struct nvkm_udevice *udev, void *data, u32 size)
 {
-       struct nvkm_udevice *udev = (void *)object;
        struct nvkm_device *device = udev->device;
        struct nvkm_timer *tmr = device->timer;
        union {
@@ -134,63 +138,70 @@ nvkm_udevice_time(struct nvkm_object *object, void *data, u32 size)
 static int
 nvkm_udevice_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
 {
+       struct nvkm_udevice *udev = nvkm_udevice(object);
        switch (mthd) {
        case NV_DEVICE_V0_INFO:
-               return nvkm_udevice_info(object, data, size);
+               return nvkm_udevice_info(udev, data, size);
        case NV_DEVICE_V0_TIME:
-               return nvkm_udevice_time(object, data, size);
+               return nvkm_udevice_time(udev, data, size);
        default:
                break;
        }
        return -EINVAL;
 }
 
-static u8
-nvkm_udevice_rd08(struct nvkm_object *object, u64 addr)
+static int
+nvkm_udevice_rd08(struct nvkm_object *object, u64 addr, u8 *data)
 {
-       struct nvkm_udevice *udev = (void *)object;
-       return nvkm_rd08(udev->device, addr);
+       struct nvkm_udevice *udev = nvkm_udevice(object);
+       *data = nvkm_rd08(udev->device, addr);
+       return 0;
 }
 
-static u16
-nvkm_udevice_rd16(struct nvkm_object *object, u64 addr)
+static int
+nvkm_udevice_rd16(struct nvkm_object *object, u64 addr, u16 *data)
 {
-       struct nvkm_udevice *udev = (void *)object;
-       return nvkm_rd16(udev->device, addr);
+       struct nvkm_udevice *udev = nvkm_udevice(object);
+       *data = nvkm_rd16(udev->device, addr);
+       return 0;
 }
 
-static u32
-nvkm_udevice_rd32(struct nvkm_object *object, u64 addr)
+static int
+nvkm_udevice_rd32(struct nvkm_object *object, u64 addr, u32 *data)
 {
-       struct nvkm_udevice *udev = (void *)object;
-       return nvkm_rd32(udev->device, addr);
+       struct nvkm_udevice *udev = nvkm_udevice(object);
+       *data = nvkm_rd32(udev->device, addr);
+       return 0;
 }
 
-static void
+static int
 nvkm_udevice_wr08(struct nvkm_object *object, u64 addr, u8 data)
 {
-       struct nvkm_udevice *udev = (void *)object;
+       struct nvkm_udevice *udev = nvkm_udevice(object);
        nvkm_wr08(udev->device, addr, data);
+       return 0;
 }
 
-static void
+static int
 nvkm_udevice_wr16(struct nvkm_object *object, u64 addr, u16 data)
 {
-       struct nvkm_udevice *udev = (void *)object;
+       struct nvkm_udevice *udev = nvkm_udevice(object);
        nvkm_wr16(udev->device, addr, data);
+       return 0;
 }
 
-static void
+static int
 nvkm_udevice_wr32(struct nvkm_object *object, u64 addr, u32 data)
 {
-       struct nvkm_udevice *udev = (void *)object;
+       struct nvkm_udevice *udev = nvkm_udevice(object);
        nvkm_wr32(udev->device, addr, data);
+       return 0;
 }
 
 static int
 nvkm_udevice_map(struct nvkm_object *object, u64 *addr, u32 *size)
 {
-       struct nvkm_udevice *udev = (void *)object;
+       struct nvkm_udevice *udev = nvkm_udevice(object);
        struct nvkm_device *device = udev->device;
        *addr = nv_device_resource_start(device, 0);
        *size = nv_device_resource_len(device, 0);
@@ -200,7 +211,7 @@ nvkm_udevice_map(struct nvkm_object *object, u64 *addr, u32 *size)
 static int
 nvkm_udevice_fini(struct nvkm_object *object, bool suspend)
 {
-       struct nvkm_udevice *udev = (void *)object;
+       struct nvkm_udevice *udev = nvkm_udevice(object);
        struct nvkm_device *device = udev->device;
        int ret = 0;
 
@@ -221,7 +232,7 @@ done:
 static int
 nvkm_udevice_init(struct nvkm_object *object)
 {
-       struct nvkm_udevice *udev = (void *)object;
+       struct nvkm_udevice *udev = nvkm_udevice(object);
        struct nvkm_device *device = udev->device;
        int ret = 0;
 
@@ -239,34 +250,120 @@ done:
        return ret;
 }
 
-static struct nvkm_oclass
-nvkm_udevice_oclass_super = {
-       .handle = NV_DEVICE,
-       .ofuncs = &(struct nvkm_ofuncs) {
-               .dtor = _nvkm_parent_dtor,
-               .init = nvkm_udevice_init,
-               .fini = nvkm_udevice_fini,
-               .mthd = nvkm_udevice_mthd,
-               .map  = nvkm_udevice_map,
-               .rd08 = nvkm_udevice_rd08,
-               .rd16 = nvkm_udevice_rd16,
-               .rd32 = nvkm_udevice_rd32,
-               .wr08 = nvkm_udevice_wr08,
-               .wr16 = nvkm_udevice_wr16,
-               .wr32 = nvkm_udevice_wr32,
+static int
+nvkm_udevice_child_old(const struct nvkm_oclass *oclass,
+                      void *data, u32 size, struct nvkm_object **pobject)
+{
+       struct nvkm_object *parent = oclass->parent;
+       struct nvkm_engine *engine = oclass->engine;
+       struct nvkm_oclass *eclass = (void *)oclass->priv;
+       struct nvkm_object *engctx = NULL;
+       int ret;
+
+       if (engine->cclass) {
+               ret = nvkm_object_old(parent, &engine->subdev.object,
+                                     engine->cclass, NULL, 0, &engctx);
+               if (ret)
+                       return ret;
+       } else {
+               nvkm_object_ref(parent, &engctx);
        }
-};
+
+       ret = nvkm_object_old(engctx, &engine->subdev.object, eclass,
+                             data, size, pobject);
+       nvkm_object_ref(NULL, &engctx);
+       return ret;
+}
 
 static int
-nvkm_udevice_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
-                struct nvkm_oclass *oclass, void *data, u32 size,
+nvkm_udevice_child_new(const struct nvkm_oclass *oclass,
+                      void *data, u32 size, struct nvkm_object **pobject)
+{
+       struct nvkm_udevice *udev = nvkm_udevice(oclass->parent);
+       const struct nvkm_oclass *sclass = oclass->priv;
+       return nvkm_object_old(&udev->object, NULL,
+                              (struct nvkm_oclass *)sclass,
+                              data, size, pobject);
+}
+
+static int
+nvkm_udevice_child_get(struct nvkm_object *object, int index,
+                      struct nvkm_oclass *oclass)
+{
+       struct nvkm_udevice *udev = nvkm_udevice(object);
+       struct nvkm_device *device = udev->device;
+       struct nvkm_engine *engine;
+       u64 mask = (1ULL << NVDEV_ENGINE_DMAOBJ) |
+                  (1ULL << NVDEV_ENGINE_FIFO) |
+                  (1ULL << NVDEV_ENGINE_DISP) |
+                  (1ULL << NVDEV_ENGINE_PM);
+       int i;
+
+       for (; i = __ffs64(mask), mask; mask &= ~(1ULL << i)) {
+               if ((engine = nvkm_device_engine(device, i))) {
+                       struct nvkm_oclass *sclass = engine->sclass;
+                       int c = 0;
+                       while (sclass && sclass->ofuncs) {
+                               if (c++ == index) {
+                                       oclass->base.oclass = sclass->handle;
+                                       oclass->base.minver = -2;
+                                       oclass->base.maxver = -2;
+                                       oclass->ctor = nvkm_udevice_child_old;
+                                       oclass->priv = sclass;
+                                       oclass->engine = engine;
+                                       return 0;
+                               }
+                               sclass++;
+                       }
+                       index -= c;
+               }
+       }
+
+       if (index == 0) {
+               oclass->ctor = nvkm_udevice_child_new;
+               oclass->base.oclass = nvkm_control_oclass[0].handle;
+               oclass->base.minver = -2;
+               oclass->base.maxver = -2;
+               oclass->priv = &nvkm_control_oclass[0];
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+static const struct nvkm_object_func
+nvkm_udevice_super = {
+       .init = nvkm_udevice_init,
+       .fini = nvkm_udevice_fini,
+       .mthd = nvkm_udevice_mthd,
+       .map = nvkm_udevice_map,
+       .rd08 = nvkm_udevice_rd08,
+       .rd16 = nvkm_udevice_rd16,
+       .rd32 = nvkm_udevice_rd32,
+       .wr08 = nvkm_udevice_wr08,
+       .wr16 = nvkm_udevice_wr16,
+       .wr32 = nvkm_udevice_wr32,
+       .sclass = nvkm_udevice_child_get,
+};
+
+static const struct nvkm_object_func
+nvkm_udevice = {
+       .init = nvkm_udevice_init,
+       .fini = nvkm_udevice_fini,
+       .mthd = nvkm_udevice_mthd,
+       .sclass = nvkm_udevice_child_get,
+};
+
+int
+nvkm_udevice_new(const struct nvkm_oclass *oclass, void *data, u32 size,
                 struct nvkm_object **pobject)
 {
        union {
                struct nv_device_v0 v0;
        } *args = data;
-       struct nvkm_client *client = nvkm_client(parent);
-       struct nvkm_device *device;
+       struct nvkm_client *client = oclass->client;
+       struct nvkm_object *parent = &client->object;
+       const struct nvkm_object_func *func;
        struct nvkm_udevice *udev;
        int ret;
 
@@ -279,34 +376,30 @@ nvkm_udevice_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
 
        /* give priviledged clients register access */
        if (client->super)
-               oclass = &nvkm_udevice_oclass_super;
+               func = &nvkm_udevice_super;
+       else
+               func = &nvkm_udevice;
 
-       /* find the device subdev that matches what the client requested */
+       if (!(udev = kzalloc(sizeof(*udev), GFP_KERNEL)))
+               return -ENOMEM;
+       nvkm_object_ctor(func, oclass, &udev->object);
+       *pobject = &udev->object;
+
+       /* find the device that matches what the client requested */
        if (args->v0.device != ~0)
-               device = nvkm_device_find(args->v0.device);
+               udev->device = nvkm_device_find(args->v0.device);
        else
-               device = nvkm_device_find(client->device);
-       if (!device)
+               udev->device = nvkm_device_find(client->device);
+       if (!udev->device)
                return -ENODEV;
 
-       ret = nvkm_parent_create(parent, NULL, oclass, 0, nvkm_control_oclass,
-                                (1ULL << NVDEV_ENGINE_DMAOBJ) |
-                                (1ULL << NVDEV_ENGINE_FIFO) |
-                                (1ULL << NVDEV_ENGINE_DISP) |
-                                (1ULL << NVDEV_ENGINE_PM), &udev);
-       *pobject = nv_object(udev);
-       if (ret)
-               return ret;
-
-       udev->device = device;
        return 0;
 }
 
-struct nvkm_ofuncs
-nvkm_udevice_ofuncs = {
-       .ctor = nvkm_udevice_ctor,
-       .dtor = _nvkm_parent_dtor,
-       .init = nvkm_udevice_init,
-       .fini = nvkm_udevice_fini,
-       .mthd = nvkm_udevice_mthd,
+const struct nvkm_sclass
+nvkm_udevice_sclass = {
+       .oclass = NV_DEVICE,
+       .minver = 0,
+       .maxver = 0,
+       .ctor = nvkm_udevice_new,
 };
index a3632d4b05d4c61e4de0ddeaef0a4083add6d458..8743972009dc2243d557c9cfae15598f97dd082d 100644 (file)
@@ -1300,7 +1300,7 @@ nv50_disp_data_ctor(struct nvkm_object *parent,
        int ret;
 
        /* no context needed for channel objects... */
-       if (nv_mclass(parent) != NV_DEVICE) {
+       if (parent->parent != &nvkm_client(parent)->object) {
                atomic_inc(&parent->refcount);
                *pobject = parent;
                return 1;
index 7f9870789a0f3816bfbfeaf78ea62fbf2d064ab1..62f627360c875c3eac2aec630738799ce03b4119 100644 (file)
@@ -66,7 +66,7 @@ nvkm_dmaobj_bind(struct nvkm_dmaobj *dmaobj, struct nvkm_gpuobj *pargpu,
                struct nvkm_object *parent = (void *)pargpu;
                struct hack *object;
 
-               if (nv_mclass(parent->parent) == NV_DEVICE) {
+               if (parent->parent->parent == &nvkm_client(parent)->object) {
                        /* delayed, or no, binding */
                        return 0;
                }
index ae84db1f296bc63b83e853b70b80648f4928a3c8..90a7d89cc019b81ab93f6a3f38d663864e173297 100644 (file)
@@ -656,7 +656,7 @@ nvkm_perfctx_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
        int ret;
 
        /* no context needed for perfdom objects... */
-       if (nv_mclass(parent) != NV_DEVICE) {
+       if (parent->parent != &nvkm_client(parent)->object) {
                atomic_inc(&parent->refcount);
                *pobject = parent;
                return 1;