drm/nv50-/sw: share engine/channel constructor between implementations
authorBen Skeggs <bskeggs@redhat.com>
Wed, 2 Oct 2013 21:42:41 +0000 (07:42 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 8 Nov 2013 05:36:05 +0000 (15:36 +1000)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/core/engine/software/nv50.c
drivers/gpu/drm/nouveau/core/engine/software/nv50.h
drivers/gpu/drm/nouveau/core/engine/software/nvc0.c

index 591784078823bdcbccc491ad0ae05e3a16a223f4..5236a1430ef67dca80f71a681efdc1e4dfb04e77 100644 (file)
@@ -147,12 +147,13 @@ nv50_software_vblsem_release(struct nouveau_eventh *event, int head)
        return NVKM_EVENT_DROP;
 }
 
-static int
+int
 nv50_software_context_ctor(struct nouveau_object *parent,
                           struct nouveau_object *engine,
                           struct nouveau_oclass *oclass, void *data, u32 size,
                           struct nouveau_object **pobject)
 {
+       struct nv50_software_cclass *pclass = (void *)oclass;
        struct nv50_software_chan *chan;
        int ret;
 
@@ -162,30 +163,32 @@ nv50_software_context_ctor(struct nouveau_object *parent,
                return ret;
 
        chan->vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
-       chan->vblank.event.func = nv50_software_vblsem_release;
+       chan->vblank.event.func = pclass->vblank;
        return 0;
 }
 
-static struct nouveau_oclass
+static struct nv50_software_cclass
 nv50_software_cclass = {
-       .handle = NV_ENGCTX(SW, 0x50),
-       .ofuncs = &(struct nouveau_ofuncs) {
+       .base.handle = NV_ENGCTX(SW, 0x50),
+       .base.ofuncs = &(struct nouveau_ofuncs) {
                .ctor = nv50_software_context_ctor,
                .dtor = _nouveau_software_context_dtor,
                .init = _nouveau_software_context_init,
                .fini = _nouveau_software_context_fini,
        },
+       .vblank = nv50_software_vblsem_release,
 };
 
 /*******************************************************************************
  * software engine/subdev functions
  ******************************************************************************/
 
-static int
+int
 nv50_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
                   struct nouveau_oclass *oclass, void *data, u32 size,
                   struct nouveau_object **pobject)
 {
+       struct nv50_software_oclass *pclass = (void *)oclass;
        struct nv50_software_priv *priv;
        int ret;
 
@@ -194,8 +197,8 @@ nv50_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
        if (ret)
                return ret;
 
-       nv_engine(priv)->cclass = &nv50_software_cclass;
-       nv_engine(priv)->sclass = nv50_software_sclass;
+       nv_engine(priv)->cclass = pclass->cclass;
+       nv_engine(priv)->sclass = pclass->sclass;
        nv_subdev(priv)->intr = nv04_software_intr;
        return 0;
 }
@@ -209,4 +212,6 @@ nv50_software_oclass = &(struct nv50_software_oclass) {
                .init = _nouveau_software_init,
                .fini = _nouveau_software_fini,
        },
+       .cclass = &nv50_software_cclass.base,
+       .sclass =  nv50_software_sclass,
 }.base;
index 628b97ba2ed1763e6c801a4d15b8df14b01ecc4d..2c0b1b42b861d67d86d3b9b208f5729602616635 100644 (file)
@@ -5,12 +5,23 @@
 
 struct nv50_software_oclass {
        struct nouveau_oclass base;
+       struct nouveau_oclass *cclass;
+       struct nouveau_oclass *sclass;
 };
 
 struct nv50_software_priv {
        struct nouveau_software base;
 };
 
+int  nv50_software_ctor(struct nouveau_object *, struct nouveau_object *,
+                       struct nouveau_oclass *, void *, u32,
+                       struct nouveau_object **);
+
+struct nv50_software_cclass {
+       struct nouveau_oclass base;
+       int (*vblank)(struct nouveau_eventh *, int);
+};
+
 struct nv50_software_chan {
        struct nouveau_software_chan base;
        struct {
@@ -22,4 +33,9 @@ struct nv50_software_chan {
        } vblank;
 };
 
+int  nv50_software_context_ctor(struct nouveau_object *,
+                               struct nouveau_object *,
+                               struct nouveau_oclass *, void *, u32,
+                               struct nouveau_object **);
+
 #endif
index 69d871d7f76ee9ee653bcb9f17c8c3825659ce0b..27e47230e3e3d21d073b6bca26d48aac388831ca 100644 (file)
@@ -154,66 +154,31 @@ nvc0_software_vblsem_release(struct nouveau_eventh *event, int head)
        return NVKM_EVENT_DROP;
 }
 
-static int
-nvc0_software_context_ctor(struct nouveau_object *parent,
-                          struct nouveau_object *engine,
-                          struct nouveau_oclass *oclass, void *data, u32 size,
-                          struct nouveau_object **pobject)
-{
-       struct nv50_software_chan *chan;
-       int ret;
-
-       ret = nouveau_software_context_create(parent, engine, oclass, &chan);
-       *pobject = nv_object(chan);
-       if (ret)
-               return ret;
-
-       chan->vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
-       chan->vblank.event.func = nvc0_software_vblsem_release;
-       return 0;
-}
-
-static struct nouveau_oclass
+static struct nv50_software_cclass
 nvc0_software_cclass = {
-       .handle = NV_ENGCTX(SW, 0xc0),
-       .ofuncs = &(struct nouveau_ofuncs) {
-               .ctor = nvc0_software_context_ctor,
+       .base.handle = NV_ENGCTX(SW, 0xc0),
+       .base.ofuncs = &(struct nouveau_ofuncs) {
+               .ctor = nv50_software_context_ctor,
                .dtor = _nouveau_software_context_dtor,
                .init = _nouveau_software_context_init,
                .fini = _nouveau_software_context_fini,
        },
+       .vblank = nvc0_software_vblsem_release,
 };
 
 /*******************************************************************************
  * software engine/subdev functions
  ******************************************************************************/
 
-static int
-nvc0_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
-                  struct nouveau_oclass *oclass, void *data, u32 size,
-                  struct nouveau_object **pobject)
-{
-       struct nv50_software_priv *priv;
-       int ret;
-
-       ret = nouveau_software_create(parent, engine, oclass, &priv);
-       *pobject = nv_object(priv);
-       if (ret)
-               return ret;
-
-       nv_engine(priv)->cclass = &nvc0_software_cclass;
-       nv_engine(priv)->sclass = nvc0_software_sclass;
-       nv_subdev(priv)->intr = nv04_software_intr;
-       return 0;
-}
-
 struct nouveau_oclass *
 nvc0_software_oclass = &(struct nv50_software_oclass) {
        .base.handle = NV_ENGINE(SW, 0xc0),
        .base.ofuncs = &(struct nouveau_ofuncs) {
-               .ctor = nvc0_software_ctor,
+               .ctor = nv50_software_ctor,
                .dtor = _nouveau_software_dtor,
                .init = _nouveau_software_init,
                .fini = _nouveau_software_fini,
        },
+       .cclass = &nvc0_software_cclass.base,
+       .sclass =  nvc0_software_sclass,
 }.base;