OSDN Git Service

nouveau: add asserts to make sure krefs are there
[android-x86/external-libdrm.git] / nouveau / pushbuf.c
index 7b9dbaa..8e7dcdf 100644 (file)
@@ -234,6 +234,8 @@ pushbuf_krel(struct nouveau_pushbuf *push, struct nouveau_bo *bo,
        bkref = cli_kref_get(push->client, bo);
        krel  = &krec->reloc[krec->nr_reloc++];
 
+       assert(pkref);
+       assert(bkref);
        krel->reloc_bo_index = pkref - krec->buffer;
        krel->reloc_bo_offset = (push->cur - nvpb->ptr) * 4;
        krel->bo_index = bkref - krec->buffer;
@@ -336,6 +338,8 @@ pushbuf_submit(struct nouveau_pushbuf *push, struct nouveau_object *chan)
                req.push = (uint64_t)(unsigned long)krec->push;
                req.suffix0 = nvpb->suffix0;
                req.suffix1 = nvpb->suffix1;
+               req.vram_available = 0; /* for valgrind */
+               req.gart_available = 0;
 
                if (dbg_on(0))
                        pushbuf_dump(krec, krec_id++, fifo->channel);
@@ -345,8 +349,10 @@ pushbuf_submit(struct nouveau_pushbuf *push, struct nouveau_object *chan)
                                          &req, sizeof(req));
                nvpb->suffix0 = req.suffix0;
                nvpb->suffix1 = req.suffix1;
-               dev->vram_limit = (req.vram_available * 80) / 100;
-               dev->gart_limit = (req.gart_available * 80) / 100;
+               dev->vram_limit = (req.vram_available *
+                               nouveau_device(dev)->vram_limit_percent) / 100;
+               dev->gart_limit = (req.gart_available *
+                               nouveau_device(dev)->gart_limit_percent) / 100;
 #else
                if (dbg_on(31))
                        ret = -EINVAL;
@@ -522,7 +528,7 @@ pushbuf_validate(struct nouveau_pushbuf *push, bool retry)
                }
        }
 
-       return 0;
+       return ret;
 }
 
 int
@@ -534,7 +540,7 @@ nouveau_pushbuf_new(struct nouveau_client *client, struct nouveau_object *chan,
        struct nouveau_fifo *fifo = chan->data;
        struct nouveau_pushbuf_priv *nvpb;
        struct nouveau_pushbuf *push;
-       struct drm_nouveau_gem_pushbuf req;
+       struct drm_nouveau_gem_pushbuf req = {};
        int ret;
 
        if (chan->oclass != NOUVEAU_FIFO_CHANNEL_CLASS)
@@ -572,13 +578,13 @@ nouveau_pushbuf_new(struct nouveau_client *client, struct nouveau_object *chan,
        push->client = client;
        push->channel = immediate ? chan : NULL;
        push->flags = NOUVEAU_BO_RD;
-       if (fifo->pushbuf & NOUVEAU_GEM_DOMAIN_VRAM) {
-               push->flags |= NOUVEAU_BO_VRAM;
-               nvpb->type   = NOUVEAU_BO_VRAM;
-       }
        if (fifo->pushbuf & NOUVEAU_GEM_DOMAIN_GART) {
                push->flags |= NOUVEAU_BO_GART;
                nvpb->type   = NOUVEAU_BO_GART;
+       } else
+       if (fifo->pushbuf & NOUVEAU_GEM_DOMAIN_VRAM) {
+               push->flags |= NOUVEAU_BO_VRAM;
+               nvpb->type   = NOUVEAU_BO_VRAM;
        }
        nvpb->type |= NOUVEAU_BO_MAP;
 
@@ -717,6 +723,7 @@ nouveau_pushbuf_data(struct nouveau_pushbuf *push, struct nouveau_bo *bo,
 
        if (bo) {
                kref = cli_kref_get(push->client, bo);
+               assert(kref);
                kpsh = &krec->push[krec->nr_push++];
                kpsh->bo_index = kref - krec->buffer;
                kpsh->offset   = offset;
@@ -735,7 +742,8 @@ void
 nouveau_pushbuf_reloc(struct nouveau_pushbuf *push, struct nouveau_bo *bo,
                      uint32_t data, uint32_t flags, uint32_t vor, uint32_t tor)
 {
-       *push->cur++ = pushbuf_krel(push, bo, data, flags, vor, tor);
+       *push->cur = pushbuf_krel(push, bo, data, flags, vor, tor);
+       push->cur++;
 }
 
 int
@@ -752,6 +760,7 @@ nouveau_pushbuf_refd(struct nouveau_pushbuf *push, struct nouveau_bo *bo)
 
        if (cli_push_get(push->client, bo) == push) {
                kref = cli_kref_get(push->client, bo);
+               assert(kref);
                if (kref->read_domains)
                        flags |= NOUVEAU_BO_RD;
                if (kref->write_domains)