drm/nouveau: use object class structs more extensively
authorBen Skeggs <bskeggs@redhat.com>
Tue, 19 Oct 2010 09:57:34 +0000 (19:57 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 3 Dec 2010 05:06:54 +0000 (15:06 +1000)
The structs themselves, as well as the non-sw object creation function are
probably very misnamed now.  That's a problem for later :)

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nouveau_drv.h
drivers/gpu/drm/nouveau/nouveau_fence.c
drivers/gpu/drm/nouveau/nouveau_object.c
drivers/gpu/drm/nouveau/nv10_graph.c
drivers/gpu/drm/nouveau/nv20_graph.c
drivers/gpu/drm/nouveau/nv40_graph.c

index 2fdc26655ca190e156f9c27f9e7fb2f780ebde46..2099f04c0b0adc47917feefb05260786fa77d683 100644 (file)
@@ -842,8 +842,6 @@ extern int nouveau_gpuobj_gart_dma_new(struct nouveau_channel *,
                                       uint32_t *o_ret);
 extern int nouveau_gpuobj_gr_new(struct nouveau_channel *, int class,
                                 struct nouveau_gpuobj **);
-extern int nouveau_gpuobj_sw_new(struct nouveau_channel *, int class,
-                                struct nouveau_gpuobj **);
 extern int nouveau_ioctl_grobj_alloc(struct drm_device *, void *data,
                                     struct drm_file *);
 extern int nouveau_ioctl_gpuobj_free(struct drm_device *, void *data,
index f70bec835f5fb6b550e3c6d856832edb97cd0df7..75ce1b45d8a473b8f7a901d730a73c06475934db 100644 (file)
@@ -437,7 +437,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
        int ret;
 
        /* Create an NV_SW object for various sync purposes */
-       ret = nouveau_gpuobj_sw_new(chan, NV_SW, &obj);
+       ret = nouveau_gpuobj_gr_new(chan, NV_SW, &obj);
        if (ret)
                return ret;
 
index 70ffd753050333597b3439b87e5b558b63df5cf1..9c26da4cdc004665a904c405b509caa51a0781d2 100644 (file)
@@ -495,23 +495,67 @@ nouveau_gpuobj_gart_dma_new(struct nouveau_channel *chan,
    entry[5]:
    set to 0?
 */
+static int
+nouveau_gpuobj_sw_new(struct nouveau_channel *chan, int class,
+                     struct nouveau_gpuobj **gpuobj_ret)
+{
+       struct drm_nouveau_private *dev_priv;
+       struct nouveau_gpuobj *gpuobj;
+
+       if (!chan || !gpuobj_ret || *gpuobj_ret != NULL)
+               return -EINVAL;
+       dev_priv = chan->dev->dev_private;
+
+       gpuobj = kzalloc(sizeof(*gpuobj), GFP_KERNEL);
+       if (!gpuobj)
+               return -ENOMEM;
+       gpuobj->dev = chan->dev;
+       gpuobj->engine = NVOBJ_ENGINE_SW;
+       gpuobj->class = class;
+       kref_init(&gpuobj->refcount);
+       gpuobj->cinst = 0x40;
+
+       spin_lock(&dev_priv->ramin_lock);
+       list_add_tail(&gpuobj->list, &dev_priv->gpuobj_list);
+       spin_unlock(&dev_priv->ramin_lock);
+       *gpuobj_ret = gpuobj;
+       return 0;
+}
+
 int
 nouveau_gpuobj_gr_new(struct nouveau_channel *chan, int class,
                      struct nouveau_gpuobj **gpuobj)
 {
+       struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
+       struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
+       struct nouveau_pgraph_object_class *grc;
        struct drm_device *dev = chan->dev;
-       struct drm_nouveau_private *dev_priv = dev->dev_private;
        int ret;
 
        NV_DEBUG(dev, "ch%d class=0x%04x\n", chan->id, class);
 
+       grc = pgraph->grclass;
+       while (grc->id) {
+               if (grc->id == class)
+                       break;
+               grc++;
+       }
+
+       if (!grc->id) {
+               NV_ERROR(dev, "illegal object class: 0x%x\n", class);
+               return -EINVAL;
+       }
+
+       if (grc->engine == NVOBJ_ENGINE_SW)
+               return nouveau_gpuobj_sw_new(chan, class, gpuobj);
+
        ret = nouveau_gpuobj_new(dev, chan,
                                 nouveau_gpuobj_class_instmem_size(dev, class),
                                 16,
                                 NVOBJ_FLAG_ZERO_ALLOC | NVOBJ_FLAG_ZERO_FREE,
                                 gpuobj);
        if (ret) {
-               NV_ERROR(dev, "Error creating gpuobj: %d\n", ret);
+               NV_ERROR(dev, "error creating gpuobj: %d\n", ret);
                return ret;
        }
 
@@ -541,38 +585,11 @@ nouveau_gpuobj_gr_new(struct nouveau_channel *chan, int class,
        }
        dev_priv->engine.instmem.flush(dev);
 
-       (*gpuobj)->engine = NVOBJ_ENGINE_GR;
+       (*gpuobj)->engine = grc->engine;
        (*gpuobj)->class  = class;
        return 0;
 }
 
-int
-nouveau_gpuobj_sw_new(struct nouveau_channel *chan, int class,
-                     struct nouveau_gpuobj **gpuobj_ret)
-{
-       struct drm_nouveau_private *dev_priv;
-       struct nouveau_gpuobj *gpuobj;
-
-       if (!chan || !gpuobj_ret || *gpuobj_ret != NULL)
-               return -EINVAL;
-       dev_priv = chan->dev->dev_private;
-
-       gpuobj = kzalloc(sizeof(*gpuobj), GFP_KERNEL);
-       if (!gpuobj)
-               return -ENOMEM;
-       gpuobj->dev = chan->dev;
-       gpuobj->engine = NVOBJ_ENGINE_SW;
-       gpuobj->class = class;
-       kref_init(&gpuobj->refcount);
-       gpuobj->cinst = 0x40;
-
-       spin_lock(&dev_priv->ramin_lock);
-       list_add_tail(&gpuobj->list, &dev_priv->gpuobj_list);
-       spin_unlock(&dev_priv->ramin_lock);
-       *gpuobj_ret = gpuobj;
-       return 0;
-}
-
 static int
 nouveau_gpuobj_channel_init_pramin(struct nouveau_channel *chan)
 {
@@ -868,10 +885,7 @@ nouveau_gpuobj_resume(struct drm_device *dev)
 int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
                              struct drm_file *file_priv)
 {
-       struct drm_nouveau_private *dev_priv = dev->dev_private;
        struct drm_nouveau_grobj_alloc *init = data;
-       struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
-       struct nouveau_pgraph_object_class *grc;
        struct nouveau_gpuobj *gr = NULL;
        struct nouveau_channel *chan;
        int ret;
@@ -879,18 +893,6 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
        if (init->handle == ~0)
                return -EINVAL;
 
-       grc = pgraph->grclass;
-       while (grc->id) {
-               if (grc->id == init->class)
-                       break;
-               grc++;
-       }
-
-       if (!grc->id) {
-               NV_ERROR(dev, "Illegal object class: 0x%x\n", init->class);
-               return -EPERM;
-       }
-
        chan = nouveau_channel_get(dev, file_priv, init->channel);
        if (IS_ERR(chan))
                return PTR_ERR(chan);
@@ -900,10 +902,7 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
                goto out;
        }
 
-       if (grc->engine != NVOBJ_ENGINE_SW)
-               ret = nouveau_gpuobj_gr_new(chan, grc->id, &gr);
-       else
-               ret = nouveau_gpuobj_sw_new(chan, grc->id, &gr);
+       ret = nouveau_gpuobj_gr_new(chan, init->class, &gr);
        if (ret) {
                NV_ERROR(dev, "Error creating object: %d (%d/0x%08x)\n",
                         ret, init->channel, init->handle);
index 375d63161d120275839d66f986356902213369c6..ed31a622889e6292b42e062e3f1780f86110757c 100644 (file)
@@ -1075,6 +1075,7 @@ static struct nouveau_pgraph_object_method nv17_graph_celsius_mthds[] = {
 };
 
 struct nouveau_pgraph_object_class nv10_graph_grclass[] = {
+       { 0x506e, NVOBJ_ENGINE_SW, NULL }, /* nvsw */
        { 0x0030, NVOBJ_ENGINE_GR, NULL }, /* null */
        { 0x0039, NVOBJ_ENGINE_GR, NULL }, /* m2mf */
        { 0x004a, NVOBJ_ENGINE_GR, NULL }, /* gdirect */
index 109418d72f93b75f2dd736c49404f84a287d2ef2..872f8d059694116cae66c5af5f2ea8f5097f9c66 100644 (file)
@@ -757,6 +757,7 @@ nv30_graph_init(struct drm_device *dev)
 }
 
 struct nouveau_pgraph_object_class nv20_graph_grclass[] = {
+       { 0x506e, NVOBJ_ENGINE_SW, NULL }, /* nvsw */
        { 0x0030, NVOBJ_ENGINE_GR, NULL }, /* null */
        { 0x0039, NVOBJ_ENGINE_GR, NULL }, /* m2mf */
        { 0x004a, NVOBJ_ENGINE_GR, NULL }, /* gdirect */
@@ -777,6 +778,7 @@ struct nouveau_pgraph_object_class nv20_graph_grclass[] = {
 };
 
 struct nouveau_pgraph_object_class nv30_graph_grclass[] = {
+       { 0x506e, NVOBJ_ENGINE_SW, NULL }, /* nvsw */
        { 0x0030, NVOBJ_ENGINE_GR, NULL }, /* null */
        { 0x0039, NVOBJ_ENGINE_GR, NULL }, /* m2mf */
        { 0x004a, NVOBJ_ENGINE_GR, NULL }, /* gdirect */
index cd47760b2d0a8a013248d02017890b5341a8fd60..70d957895ceaa91832e6f6b003312ca6fd49864d 100644 (file)
@@ -409,6 +409,7 @@ void nv40_graph_takedown(struct drm_device *dev)
 }
 
 struct nouveau_pgraph_object_class nv40_graph_grclass[] = {
+       { 0x506e, NVOBJ_ENGINE_SW, NULL }, /* nvsw */
        { 0x0030, NVOBJ_ENGINE_GR, NULL }, /* null */
        { 0x0039, NVOBJ_ENGINE_GR, NULL }, /* m2mf */
        { 0x004a, NVOBJ_ENGINE_GR, NULL }, /* gdirect */