drm/nouveau/mpeg: convert user classes to new-style nvkm_object
authorBen Skeggs <bskeggs@redhat.com>
Thu, 20 Aug 2015 04:54:19 +0000 (14:54 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 28 Aug 2015 02:40:41 +0000 (12:40 +1000)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvif/class.h
drivers/gpu/drm/nouveau/include/nvkm/engine/mpeg.h
drivers/gpu/drm/nouveau/nvkm/engine/mpeg/g84.c
drivers/gpu/drm/nouveau/nvkm/engine/mpeg/nv31.c
drivers/gpu/drm/nouveau/nvkm/engine/mpeg/nv31.h
drivers/gpu/drm/nouveau/nvkm/engine/mpeg/nv40.c
drivers/gpu/drm/nouveau/nvkm/engine/mpeg/nv44.c
drivers/gpu/drm/nouveau/nvkm/engine/mpeg/nv50.c
drivers/gpu/drm/nouveau/nvkm/engine/mpeg/priv.h [new file with mode: 0644]

index 3edd4c1d563116d3167d121d0a8f807fc9833694..1b85ffe629aa70dd3d70428af74c17dfbfd5e2f1 100644 (file)
@@ -45,6 +45,9 @@
 #define GM107_DISP                                                   0x00009470
 #define GM204_DISP                                                   0x00009570
 
+#define NV31_MPEG                                                    0x00003174
+#define G82_MPEG                                                     0x00008274
+
 #define NV74_VP2                                                     0x00007476
 
 #define NV50_DISP_CURSOR                                             0x0000507a
index db5c3d5a0752023f81fa5ef6fd4882d41ad4dddd..029fd0c28d22f0eaf0aa69ce9126d28f6f33d8b2 100644 (file)
@@ -1,26 +1,5 @@
 #ifndef __NVKM_MPEG_H__
 #define __NVKM_MPEG_H__
-#include <core/engctx.h>
-
-struct nvkm_mpeg_chan {
-       struct nvkm_engctx base;
-};
-
-#define nvkm_mpeg_context_create(p,e,c,g,s,a,f,d)                           \
-       nvkm_engctx_create((p), (e), (c), (g), (s), (a), (f), (d))
-#define nvkm_mpeg_context_destroy(d)                                        \
-       nvkm_engctx_destroy(&(d)->base)
-#define nvkm_mpeg_context_init(d)                                           \
-       nvkm_engctx_init(&(d)->base)
-#define nvkm_mpeg_context_fini(d,s)                                         \
-       nvkm_engctx_fini(&(d)->base, (s))
-
-#define _nvkm_mpeg_context_dtor _nvkm_engctx_dtor
-#define _nvkm_mpeg_context_init _nvkm_engctx_init
-#define _nvkm_mpeg_context_fini _nvkm_engctx_fini
-#define _nvkm_mpeg_context_rd32 _nvkm_engctx_rd32
-#define _nvkm_mpeg_context_wr32 _nvkm_engctx_wr32
-
 #include <core/engine.h>
 
 struct nvkm_mpeg {
@@ -45,9 +24,6 @@ extern struct nvkm_oclass nv40_mpeg_oclass;
 extern struct nvkm_oclass nv44_mpeg_oclass;
 extern struct nvkm_oclass nv50_mpeg_oclass;
 extern struct nvkm_oclass g84_mpeg_oclass;
-extern struct nvkm_ofuncs nv31_mpeg_ofuncs;
-extern struct nvkm_oclass nv31_mpeg_cclass;
-extern struct nvkm_oclass nv31_mpeg_sclass[];
 extern struct nvkm_oclass nv40_mpeg_sclass[];
 void nv31_mpeg_intr(struct nvkm_subdev *);
 void nv31_mpeg_tile_prog(struct nvkm_engine *, int);
index cdcca3ab4332b052f40c47fbd98ffeb71eb0cd40..c72fd75cd8cf65c60316f079d804f5a5746a1df8 100644 (file)
  *
  * Authors: Ben Skeggs
  */
-#include <engine/mpeg.h>
+#include "priv.h"
 
-struct g84_mpeg_chan {
-       struct nvkm_mpeg_chan base;
-};
-
-/*******************************************************************************
- * MPEG object classes
- ******************************************************************************/
+#include <nvif/class.h>
 
-static struct nvkm_oclass
-g84_mpeg_sclass[] = {
-       { 0x8274, &nv50_mpeg_ofuncs },
-       {}
+static const struct nvkm_engine_func
+g84_mpeg = {
+       .cclass = &nv50_mpeg_cclass,
+       .sclass = {
+               { -1, -1, G82_MPEG, &nv31_mpeg_object },
+               {}
+       }
 };
 
-/*******************************************************************************
- * PMPEG context
- ******************************************************************************/
-
-static struct nvkm_oclass
-g84_mpeg_cclass = {
-       .handle = NV_ENGCTX(MPEG, 0x84),
-       .ofuncs = &(struct nvkm_ofuncs) {
-               .ctor = nv50_mpeg_context_ctor,
-               .dtor = _nvkm_mpeg_context_dtor,
-               .init = _nvkm_mpeg_context_init,
-               .fini = _nvkm_mpeg_context_fini,
-               .rd32 = _nvkm_mpeg_context_rd32,
-               .wr32 = _nvkm_mpeg_context_wr32,
-       },
-};
-
-/*******************************************************************************
- * PMPEG engine/subdev functions
- ******************************************************************************/
-
 static int
 g84_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
              struct nvkm_oclass *oclass, void *data, u32 size,
@@ -71,10 +47,10 @@ g84_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
        if (ret)
                return ret;
 
+       mpeg->engine.func = &g84_mpeg;
+
        nv_subdev(mpeg)->unit = 0x00000002;
        nv_subdev(mpeg)->intr = nv50_mpeg_intr;
-       nv_engine(mpeg)->cclass = &g84_mpeg_cclass;
-       nv_engine(mpeg)->sclass = g84_mpeg_sclass;
        return 0;
 }
 
index 211b44c00c850a778dcf26b9720167ea8fe4fa75..417cc31a12ef78122a65361c1e79b8006399cfa6 100644 (file)
 #include <core/client.h>
 #include <subdev/fb.h>
 #include <subdev/timer.h>
+#include <engine/fifo.h>
+
+#include <nvif/class.h>
 
 /*******************************************************************************
  * MPEG object classes
  ******************************************************************************/
 
 static int
-nv31_mpeg_object_ctor(struct nvkm_object *parent,
-                     struct nvkm_object *engine,
-                     struct nvkm_oclass *oclass, void *data, u32 size,
-                     struct nvkm_object **pobject)
+nv31_mpeg_object_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
+                     int align, struct nvkm_gpuobj **pgpuobj)
 {
-       struct nvkm_gpuobj *obj;
-       int ret;
+       int ret = nvkm_gpuobj_new(object->engine->subdev.device, 16, align,
+                                 false, parent, pgpuobj);
+       if (ret == 0) {
+               nvkm_kmap(*pgpuobj);
+               nvkm_wo32(*pgpuobj, 0x00, object->oclass_name);
+               nvkm_wo32(*pgpuobj, 0x04, 0x00000000);
+               nvkm_wo32(*pgpuobj, 0x08, 0x00000000);
+               nvkm_wo32(*pgpuobj, 0x0c, 0x00000000);
+               nvkm_done(*pgpuobj);
+       }
+       return ret;
+}
 
-       ret = nvkm_gpuobj_create(parent, engine, oclass, 0, parent,
-                                20, 16, 0, &obj);
-       *pobject = nv_object(obj);
-       if (ret)
-               return ret;
+const struct nvkm_object_func
+nv31_mpeg_object = {
+       .bind = nv31_mpeg_object_bind,
+};
 
-       nvkm_kmap(obj);
-       nvkm_wo32(obj, 0x00, nv_mclass(obj));
-       nvkm_wo32(obj, 0x04, 0x00000000);
-       nvkm_wo32(obj, 0x08, 0x00000000);
-       nvkm_wo32(obj, 0x0c, 0x00000000);
-       nvkm_done(obj);
-       return 0;
+/*******************************************************************************
+ * PMPEG context
+ ******************************************************************************/
+
+static void *
+nv31_mpeg_chan_dtor(struct nvkm_object *object)
+{
+       struct nv31_mpeg_chan *chan = nv31_mpeg_chan(object);
+       struct nv31_mpeg *mpeg = chan->mpeg;
+       unsigned long flags;
+
+       spin_lock_irqsave(&mpeg->base.engine.lock, flags);
+       if (mpeg->chan == chan)
+               mpeg->chan = NULL;
+       spin_unlock_irqrestore(&mpeg->base.engine.lock, flags);
+       return chan;
+}
+
+static const struct nvkm_object_func
+nv31_mpeg_chan = {
+       .dtor = nv31_mpeg_chan_dtor,
+};
+
+int
+nv31_mpeg_chan_new(struct nvkm_fifo_chan *fifoch,
+                  const struct nvkm_oclass *oclass,
+                  struct nvkm_object **pobject)
+{
+       struct nv31_mpeg *mpeg = nv31_mpeg(oclass->engine);
+       struct nv31_mpeg_chan *chan;
+       unsigned long flags;
+       int ret = -EBUSY;
+
+       if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
+               return -ENOMEM;
+       nvkm_object_ctor(&nv31_mpeg_chan, oclass, &chan->object);
+       chan->mpeg = mpeg;
+       chan->fifo = fifoch;
+       *pobject = &chan->object;
+
+       spin_lock_irqsave(&mpeg->base.engine.lock, flags);
+       if (!mpeg->chan) {
+               mpeg->chan = chan;
+               ret = 0;
+       }
+       spin_unlock_irqrestore(&mpeg->base.engine.lock, flags);
+       return ret;
+}
+
+/*******************************************************************************
+ * PMPEG engine/subdev functions
+ ******************************************************************************/
+
+void
+nv31_mpeg_tile_prog(struct nvkm_engine *engine, int i)
+{
+       struct nv31_mpeg *mpeg = (void *)engine;
+       struct nvkm_device *device = mpeg->base.engine.subdev.device;
+       struct nvkm_fb_tile *tile = &device->fb->tile.region[i];
+
+       nvkm_wr32(device, 0x00b008 + (i * 0x10), tile->pitch);
+       nvkm_wr32(device, 0x00b004 + (i * 0x10), tile->limit);
+       nvkm_wr32(device, 0x00b000 + (i * 0x10), tile->addr);
 }
 
 static bool
@@ -109,95 +175,6 @@ nv31_mpeg_mthd(struct nv31_mpeg *mpeg, u32 mthd, u32 data)
        return false;
 }
 
-struct nvkm_ofuncs
-nv31_mpeg_ofuncs = {
-       .ctor = nv31_mpeg_object_ctor,
-       .dtor = _nvkm_gpuobj_dtor,
-       .init = _nvkm_gpuobj_init,
-       .fini = _nvkm_gpuobj_fini,
-       .rd32 = _nvkm_gpuobj_rd32,
-       .wr32 = _nvkm_gpuobj_wr32,
-};
-
-struct nvkm_oclass
-nv31_mpeg_sclass[] = {
-       { 0x3174, &nv31_mpeg_ofuncs },
-       {}
-};
-
-/*******************************************************************************
- * PMPEG context
- ******************************************************************************/
-
-static int
-nv31_mpeg_context_ctor(struct nvkm_object *parent,
-                      struct nvkm_object *engine,
-                      struct nvkm_oclass *oclass, void *data, u32 size,
-                      struct nvkm_object **pobject)
-{
-       struct nv31_mpeg *mpeg = (void *)engine;
-       struct nv31_mpeg_chan *chan;
-       unsigned long flags;
-       int ret;
-
-       ret = nvkm_object_create(parent, engine, oclass, 0, &chan);
-       *pobject = nv_object(chan);
-       if (ret)
-               return ret;
-
-       spin_lock_irqsave(&nv_engine(mpeg)->lock, flags);
-       if (mpeg->chan) {
-               spin_unlock_irqrestore(&nv_engine(mpeg)->lock, flags);
-               nvkm_object_destroy(&chan->base);
-               *pobject = NULL;
-               return -EBUSY;
-       }
-       chan->fifo = nvkm_fifo_chan(parent);
-       mpeg->chan = chan;
-       spin_unlock_irqrestore(&nv_engine(mpeg)->lock, flags);
-       return 0;
-}
-
-static void
-nv31_mpeg_context_dtor(struct nvkm_object *object)
-{
-       struct nv31_mpeg *mpeg = (void *)object->engine;
-       struct nv31_mpeg_chan *chan = (void *)object;
-       unsigned long flags;
-
-       spin_lock_irqsave(&nv_engine(mpeg)->lock, flags);
-       mpeg->chan = NULL;
-       spin_unlock_irqrestore(&nv_engine(mpeg)->lock, flags);
-       nvkm_object_destroy(&chan->base);
-}
-
-struct nvkm_oclass
-nv31_mpeg_cclass = {
-       .handle = NV_ENGCTX(MPEG, 0x31),
-       .ofuncs = &(struct nvkm_ofuncs) {
-               .ctor = nv31_mpeg_context_ctor,
-               .dtor = nv31_mpeg_context_dtor,
-               .init = _nvkm_object_init,
-               .fini = _nvkm_object_fini,
-       },
-};
-
-/*******************************************************************************
- * PMPEG engine/subdev functions
- ******************************************************************************/
-
-void
-nv31_mpeg_tile_prog(struct nvkm_engine *engine, int i)
-{
-       struct nv31_mpeg *mpeg = (void *)engine;
-       struct nvkm_device *device = mpeg->base.engine.subdev.device;
-       struct nvkm_fb_tile *tile = &device->fb->tile.region[i];
-
-       nvkm_wr32(device, 0x00b008 + (i * 0x10), tile->pitch);
-       nvkm_wr32(device, 0x00b004 + (i * 0x10), tile->limit);
-       nvkm_wr32(device, 0x00b000 + (i * 0x10), tile->addr);
-}
-
 void
 nv31_mpeg_intr(struct nvkm_subdev *subdev)
 {
@@ -231,13 +208,22 @@ nv31_mpeg_intr(struct nvkm_subdev *subdev)
        if (show) {
                nvkm_error(subdev, "ch %d [%s] %08x %08x %08x %08x\n",
                           mpeg->chan ? mpeg->chan->fifo->chid : -1,
-                          mpeg->chan ? mpeg->chan->fifo->object.client->name :
+                          mpeg->chan ? mpeg->chan->object.client->name :
                           "unknown", stat, type, mthd, data);
        }
 
        spin_unlock_irqrestore(&mpeg->base.engine.lock, flags);
 }
 
+static const struct nvkm_engine_func
+nv31_mpeg = {
+       .fifo.cclass = nv31_mpeg_chan_new,
+       .sclass = {
+               { -1, -1, NV31_MPEG, &nv31_mpeg_object },
+               {}
+       }
+};
+
 static int
 nv31_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
               struct nvkm_oclass *oclass, void *data, u32 size,
@@ -251,11 +237,11 @@ nv31_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
        if (ret)
                return ret;
 
+       mpeg->base.engine.func = &nv31_mpeg;
+
        mpeg->mthd_dma = nv31_mpeg_mthd_dma;
        nv_subdev(mpeg)->unit = 0x00000002;
        nv_subdev(mpeg)->intr = nv31_mpeg_intr;
-       nv_engine(mpeg)->cclass = &nv31_mpeg_cclass;
-       nv_engine(mpeg)->sclass = nv31_mpeg_sclass;
        nv_engine(mpeg)->tile_prog = nv31_mpeg_tile_prog;
        return 0;
 }
index 6bdd409d5769c3e8fc51769c99b7cb1b285631f5..a2dae83fbc71acd8bead9f234b3ca55f99fb031e 100644 (file)
@@ -1,16 +1,23 @@
 #ifndef __NV31_MPEG_H__
 #define __NV31_MPEG_H__
+#define nv31_mpeg(p) container_of((p), struct nv31_mpeg, base.engine)
+#include "priv.h"
 #include <engine/mpeg.h>
-#include <engine/fifo.h>
-
-struct nv31_mpeg_chan {
-       struct nvkm_object base;
-       struct nvkm_fifo_chan *fifo;
-};
 
 struct nv31_mpeg {
        struct nvkm_mpeg base;
        struct nv31_mpeg_chan *chan;
        bool (*mthd_dma)(struct nvkm_device *, u32 mthd, u32 data);
 };
+
+#define nv31_mpeg_chan(p) container_of((p), struct nv31_mpeg_chan, object)
+
+struct nv31_mpeg_chan {
+       struct nvkm_object object;
+       struct nv31_mpeg *mpeg;
+       struct nvkm_fifo_chan *fifo;
+};
+
+int nv31_mpeg_chan_new(struct nvkm_fifo_chan *, const struct nvkm_oclass *,
+                      struct nvkm_object **);
 #endif
index cc167dcc788f75bcc502c9b95e535af266bf88be..b4ef1ebd38ab24be8128e30c9fd014f02a2733d8 100644 (file)
@@ -25,9 +25,7 @@
 
 #include <subdev/instmem.h>
 
-/*******************************************************************************
- * MPEG object classes
- ******************************************************************************/
+#include <nvif/class.h>
 
 bool
 nv40_mpeg_mthd_dma(struct nvkm_device *device, u32 mthd, u32 data)
@@ -67,16 +65,6 @@ nv40_mpeg_mthd_dma(struct nvkm_device *device, u32 mthd, u32 data)
        return true;
 }
 
-struct nvkm_oclass
-nv40_mpeg_sclass[] = {
-       { 0x3174, &nv31_mpeg_ofuncs },
-       {}
-};
-
-/*******************************************************************************
- * PMPEG engine/subdev functions
- ******************************************************************************/
-
 static void
 nv40_mpeg_intr(struct nvkm_subdev *subdev)
 {
@@ -93,6 +81,15 @@ nv40_mpeg_intr(struct nvkm_subdev *subdev)
        }
 }
 
+static const struct nvkm_engine_func
+nv40_mpeg = {
+       .fifo.cclass = nv31_mpeg_chan_new,
+       .sclass = {
+               { -1, -1, NV31_MPEG, &nv31_mpeg_object },
+               {}
+       }
+};
+
 static int
 nv40_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
               struct nvkm_oclass *oclass, void *data, u32 size,
@@ -106,11 +103,11 @@ nv40_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
        if (ret)
                return ret;
 
+       mpeg->base.engine.func = &nv40_mpeg;
+
        mpeg->mthd_dma = nv40_mpeg_mthd_dma;
        nv_subdev(mpeg)->unit = 0x00000002;
        nv_subdev(mpeg)->intr = nv40_mpeg_intr;
-       nv_engine(mpeg)->cclass = &nv31_mpeg_cclass;
-       nv_engine(mpeg)->sclass = nv40_mpeg_sclass;
        nv_engine(mpeg)->tile_prog = nv31_mpeg_tile_prog;
        return 0;
 }
index ff9ddc67a292139151b7d5c4bf50e98a3820c9b7..0f9ef18bf18d0955ffc1d9aa165ea8b6579d85e8 100644 (file)
  *
  * Authors: Ben Skeggs
  */
-#include <engine/mpeg.h>
+#define nv44_mpeg(p) container_of((p), struct nv44_mpeg, base.engine)
+#include "priv.h"
 
 #include <core/client.h>
 #include <engine/fifo.h>
 
+#include <nvif/class.h>
+
 struct nv44_mpeg {
        struct nvkm_mpeg base;
        struct list_head chan;
 };
 
+bool nv40_mpeg_mthd_dma(struct nvkm_device *, u32, u32);
+
+/*******************************************************************************
+ * PMPEG context
+ ******************************************************************************/
+#define nv44_mpeg_chan(p) container_of((p), struct nv44_mpeg_chan, object)
+
 struct nv44_mpeg_chan {
-       struct nvkm_mpeg_chan base;
+       struct nvkm_object object;
+       struct nv44_mpeg *mpeg;
        struct nvkm_fifo_chan *fifo;
-       u32 inst;
        struct list_head head;
+       u32 inst;
 };
 
-bool nv40_mpeg_mthd_dma(struct nvkm_device *, u32, u32);
+static int
+nv44_mpeg_chan_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
+                   int align, struct nvkm_gpuobj **pgpuobj)
+{
+       struct nv44_mpeg_chan *chan = nv44_mpeg_chan(object);
+       int ret = nvkm_gpuobj_new(chan->object.engine->subdev.device, 264 * 4,
+                                 align, true, parent, pgpuobj);
+       if (ret == 0) {
+               chan->inst = (*pgpuobj)->addr;
+               nvkm_kmap(*pgpuobj);
+               nvkm_wo32(*pgpuobj, 0x78, 0x02001ec1);
+               nvkm_done(*pgpuobj);
+       }
+       return ret;
+}
 
-/*******************************************************************************
- * PMPEG context
- ******************************************************************************/
+static int
+nv44_mpeg_chan_fini(struct nvkm_object *object, bool suspend)
+{
 
-static void
-nv44_mpeg_context_dtor(struct nvkm_object *object)
+       struct nv44_mpeg_chan *chan = nv44_mpeg_chan(object);
+       struct nv44_mpeg *mpeg = chan->mpeg;
+       struct nvkm_device *device = mpeg->base.engine.subdev.device;
+       u32 inst = 0x80000000 | (chan->inst >> 4);
+
+       nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000000);
+       if (nvkm_rd32(device, 0x00b318) == inst)
+               nvkm_mask(device, 0x00b318, 0x80000000, 0x00000000);
+       nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000001);
+       return 0;
+}
+
+static void *
+nv44_mpeg_chan_dtor(struct nvkm_object *object)
 {
-       struct nv44_mpeg_chan *chan = (void *)object;
-       struct nv44_mpeg *mpeg = (void *)object->engine;
+       struct nv44_mpeg_chan *chan = nv44_mpeg_chan(object);
+       struct nv44_mpeg *mpeg = chan->mpeg;
        unsigned long flags;
        spin_lock_irqsave(&mpeg->base.engine.lock, flags);
        list_del(&chan->head);
        spin_unlock_irqrestore(&mpeg->base.engine.lock, flags);
-       nvkm_mpeg_context_destroy(&chan->base);
+       return chan;
 }
 
+static const struct nvkm_object_func
+nv44_mpeg_chan = {
+       .dtor = nv44_mpeg_chan_dtor,
+       .fini = nv44_mpeg_chan_fini,
+       .bind = nv44_mpeg_chan_bind,
+};
+
 static int
-nv44_mpeg_context_ctor(struct nvkm_object *parent,
-                      struct nvkm_object *engine,
-                      struct nvkm_oclass *oclass, void *data, u32 size,
-                      struct nvkm_object **pobject)
+nv44_mpeg_chan_new(struct nvkm_fifo_chan *fifoch,
+                  const struct nvkm_oclass *oclass,
+                  struct nvkm_object **pobject)
 {
-       struct nv44_mpeg *mpeg = (void *)engine;
+       struct nv44_mpeg *mpeg = nv44_mpeg(oclass->engine);
        struct nv44_mpeg_chan *chan;
        unsigned long flags;
-       int ret;
 
-       ret = nvkm_mpeg_context_create(parent, engine, oclass, NULL, 264 * 4,
-                                      16, NVOBJ_FLAG_ZERO_ALLOC, &chan);
-       *pobject = nv_object(chan);
-       if (ret)
-               return ret;
+       if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
+               return -ENOMEM;
+       nvkm_object_ctor(&nv44_mpeg_chan, oclass, &chan->object);
+       chan->mpeg = mpeg;
+       chan->fifo = fifoch;
+       *pobject = &chan->object;
 
        spin_lock_irqsave(&mpeg->base.engine.lock, flags);
-       chan->fifo = nvkm_fifo_chan(parent);
-       chan->inst = chan->base.base.gpuobj.addr;
        list_add(&chan->head, &mpeg->chan);
        spin_unlock_irqrestore(&mpeg->base.engine.lock, flags);
-
-       nvkm_kmap(&chan->base.base.gpuobj);
-       nvkm_wo32(&chan->base.base.gpuobj, 0x78, 0x02001ec1);
-       nvkm_done(&chan->base.base.gpuobj);
        return 0;
 }
 
-static int
-nv44_mpeg_context_fini(struct nvkm_object *object, bool suspend)
-{
-
-       struct nvkm_mpeg *mpeg = (void *)object->engine;
-       struct nv44_mpeg_chan *chan = (void *)object;
-       struct nvkm_device *device = mpeg->engine.subdev.device;
-       u32 inst = 0x80000000 | nv_gpuobj(chan)->addr >> 4;
-
-       nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000000);
-       if (nvkm_rd32(device, 0x00b318) == inst)
-               nvkm_mask(device, 0x00b318, 0x80000000, 0x00000000);
-       nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000001);
-       return 0;
-}
-
-static struct nvkm_oclass
-nv44_mpeg_cclass = {
-       .handle = NV_ENGCTX(MPEG, 0x44),
-       .ofuncs = &(struct nvkm_ofuncs) {
-               .ctor = nv44_mpeg_context_ctor,
-               .dtor = nv44_mpeg_context_dtor,
-               .init = _nvkm_mpeg_context_init,
-               .fini = nv44_mpeg_context_fini,
-               .rd32 = _nvkm_mpeg_context_rd32,
-               .wr32 = _nvkm_mpeg_context_wr32,
-       },
-};
-
 /*******************************************************************************
  * PMPEG engine/subdev functions
  ******************************************************************************/
@@ -175,7 +183,7 @@ nv44_mpeg_intr(struct nvkm_subdev *subdev)
        if (show) {
                nvkm_error(subdev, "ch %d [%08x %s] %08x %08x %08x %08x\n",
                           chan ? chan->fifo->chid : -1, inst << 4,
-                          chan ? chan->fifo->object.client->name : "unknown",
+                          chan ? chan->object.client->name : "unknown",
                           stat, type, mthd, data);
        }
 
@@ -198,6 +206,15 @@ nv44_mpeg_me_intr(struct nvkm_subdev *subdev)
        }
 }
 
+static const struct nvkm_engine_func
+nv44_mpeg = {
+       .fifo.cclass = nv44_mpeg_chan_new,
+       .sclass = {
+               { -1, -1, NV31_MPEG, &nv31_mpeg_object },
+               {}
+       }
+};
+
 static int
 nv44_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
               struct nvkm_oclass *oclass, void *data, u32 size,
@@ -212,11 +229,10 @@ nv44_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
                return ret;
 
        INIT_LIST_HEAD(&mpeg->chan);
+       mpeg->base.engine.func = &nv44_mpeg;
 
        nv_subdev(mpeg)->unit = 0x00000002;
        nv_subdev(mpeg)->intr = nv44_mpeg_me_intr;
-       nv_engine(mpeg)->cclass = &nv44_mpeg_cclass;
-       nv_engine(mpeg)->sclass = nv40_mpeg_sclass;
        nv_engine(mpeg)->tile_prog = nv31_mpeg_tile_prog;
        return 0;
 }
index c906c43e9065cd2088aead51d8f7cbcc28f1bb2f..a94c73e08ae36c7f0b55f95f2d6298fc245bf8a9 100644 (file)
  *
  * Authors: Ben Skeggs
  */
-#include <engine/mpeg.h>
+#include "priv.h"
 
+#include <core/gpuobj.h>
 #include <subdev/timer.h>
 
-struct nv50_mpeg_chan {
-       struct nvkm_mpeg_chan base;
-};
-
-/*******************************************************************************
- * MPEG object classes
- ******************************************************************************/
-
-static int
-nv50_mpeg_object_ctor(struct nvkm_object *parent,
-                     struct nvkm_object *engine,
-                     struct nvkm_oclass *oclass, void *data, u32 size,
-                     struct nvkm_object **pobject)
-{
-       struct nvkm_gpuobj *obj;
-       int ret;
-
-       ret = nvkm_gpuobj_create(parent, engine, oclass, 0, parent,
-                                16, 16, 0, &obj);
-       *pobject = nv_object(obj);
-       if (ret)
-               return ret;
-
-       nvkm_kmap(obj);
-       nvkm_wo32(obj, 0x00, nv_mclass(obj));
-       nvkm_wo32(obj, 0x04, 0x00000000);
-       nvkm_wo32(obj, 0x08, 0x00000000);
-       nvkm_wo32(obj, 0x0c, 0x00000000);
-       nvkm_done(obj);
-       return 0;
-}
-
-struct nvkm_ofuncs
-nv50_mpeg_ofuncs = {
-       .ctor = nv50_mpeg_object_ctor,
-       .dtor = _nvkm_gpuobj_dtor,
-       .init = _nvkm_gpuobj_init,
-       .fini = _nvkm_gpuobj_fini,
-       .rd32 = _nvkm_gpuobj_rd32,
-       .wr32 = _nvkm_gpuobj_wr32,
-};
-
-static struct nvkm_oclass
-nv50_mpeg_sclass[] = {
-       { 0x3174, &nv50_mpeg_ofuncs },
-       {}
-};
+#include <nvif/class.h>
 
 /*******************************************************************************
  * PMPEG context
  ******************************************************************************/
 
-int
-nv50_mpeg_context_ctor(struct nvkm_object *parent,
-                      struct nvkm_object *engine,
-                      struct nvkm_oclass *oclass, void *data, u32 size,
-                      struct nvkm_object **pobject)
+static int
+nv50_mpeg_cclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
+                     int align, struct nvkm_gpuobj **pgpuobj)
 {
-       struct nv50_mpeg_chan *chan;
-       struct nvkm_gpuobj *image;
-       int ret;
-
-       ret = nvkm_mpeg_context_create(parent, engine, oclass, NULL, 128 * 4,
-                                      0, NVOBJ_FLAG_ZERO_ALLOC, &chan);
-       *pobject = nv_object(chan);
-       if (ret)
-               return ret;
-
-       image = &chan->base.base.gpuobj;
-
-       nvkm_kmap(image);
-       nvkm_wo32(image, 0x0070, 0x00801ec1);
-       nvkm_wo32(image, 0x007c, 0x0000037c);
-       nvkm_done(image);
-       return 0;
+       int ret = nvkm_gpuobj_new(object->engine->subdev.device, 128 * 4,
+                                 align, true, parent, pgpuobj);
+       if (ret == 0) {
+               nvkm_kmap(*pgpuobj);
+               nvkm_wo32(*pgpuobj, 0x70, 0x00801ec1);
+               nvkm_wo32(*pgpuobj, 0x7c, 0x0000037c);
+               nvkm_done(*pgpuobj);
+       }
+       return ret;
 }
 
-static struct nvkm_oclass
+const struct nvkm_object_func
 nv50_mpeg_cclass = {
-       .handle = NV_ENGCTX(MPEG, 0x50),
-       .ofuncs = &(struct nvkm_ofuncs) {
-               .ctor = nv50_mpeg_context_ctor,
-               .dtor = _nvkm_mpeg_context_dtor,
-               .init = _nvkm_mpeg_context_init,
-               .fini = _nvkm_mpeg_context_fini,
-               .rd32 = _nvkm_mpeg_context_rd32,
-               .wr32 = _nvkm_mpeg_context_wr32,
-       },
+       .bind = nv50_mpeg_cclass_bind,
 };
 
 /*******************************************************************************
@@ -162,6 +99,15 @@ nv50_vpe_intr(struct nvkm_subdev *subdev)
        }
 }
 
+static const struct nvkm_engine_func
+nv50_mpeg = {
+       .cclass = &nv50_mpeg_cclass,
+       .sclass = {
+               { -1, -1, NV31_MPEG, &nv31_mpeg_object },
+               {}
+       }
+};
+
 static int
 nv50_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
               struct nvkm_oclass *oclass, void *data, u32 size,
@@ -175,10 +121,10 @@ nv50_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
        if (ret)
                return ret;
 
+       mpeg->engine.func = &nv50_mpeg;
+
        nv_subdev(mpeg)->unit = 0x00400002;
        nv_subdev(mpeg)->intr = nv50_vpe_intr;
-       nv_engine(mpeg)->cclass = &nv50_mpeg_cclass;
-       nv_engine(mpeg)->sclass = nv50_mpeg_sclass;
        return 0;
 }
 
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/mpeg/priv.h b/drivers/gpu/drm/nouveau/nvkm/engine/mpeg/priv.h
new file mode 100644 (file)
index 0000000..8b31eca
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __NVKM_MPEG_PRIV_H__
+#define __NVKM_MPEG_PRIV_H__
+#include <engine/mpeg.h>
+struct nvkm_fifo_chan;
+
+extern const struct nvkm_object_func nv31_mpeg_object;
+
+extern const struct nvkm_object_func nv50_mpeg_cclass;
+#endif