nouveau: give resources a start property
authorBen Skeggs <skeggsb@gmail.com>
Sun, 9 Dec 2007 15:07:47 +0000 (02:07 +1100)
committerBen Skeggs <skeggsb@gmail.com>
Sun, 9 Dec 2007 15:10:42 +0000 (02:10 +1100)
src/mesa/drivers/dri/nouveau_winsys/Makefile
src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h
src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c
src/mesa/drivers/dri/nouveau_winsys/nouveau_resource.c [new file with mode: 0644]
src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c
src/mesa/pipe/nouveau/nouveau_winsys.h
src/mesa/pipe/nv40/nv40_context.c

index fe9a9668b11f77919224e4db052f50d505b6f7aa..f2490c823d4c1a2dde89959385ad614f93d7fd56 100644 (file)
@@ -22,6 +22,7 @@ DRIVER_SOURCES = \
        nouveau_lock.c \
        nouveau_notifier.c \
        nouveau_pushbuf.c \
+       nouveau_resource.c \
        nouveau_screen.c \
        nouveau_swapbuffers.c \
        nouveau_winsys.c \
index f176767f13651f0d9139d853fadfa9c3b695c5b3..1c2a2c12cff239917fb810919d75e8285aee7990 100644 (file)
@@ -281,7 +281,8 @@ nouveau_bo_validate(struct nouveau_channel *, struct nouveau_bo *,
                    struct nouveau_fence *fence, uint32_t flags);
 
 extern int
-nouveau_resource_init(struct nouveau_resource **heap, int size);
+nouveau_resource_init(struct nouveau_resource **heap, unsigned start,
+                     unsigned size);
 
 extern int
 nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv,
index 6cb06f8c37bc9d46d66308e89bd5cfda0ac6f31d..551889f94c7f11babc879261916b7d55fce5ac8d 100644 (file)
@@ -36,7 +36,7 @@ nouveau_pushbuf_init(struct nouveau_channel *chan)
                return -EINVAL;
 
        /* Everything except first 4KiB of the push buffer is managed by us */
-       if (nouveau_resource_init(&nvchan->pb_heap,
+       if (nouveau_resource_init(&nvchan->pb_heap, 4096,
                                  nvchan->drm.cmdbuf_size - 4096))
                return -EINVAL;
 
@@ -116,7 +116,7 @@ nouveau_pushbuf_flush(struct nouveau_channel *chan)
 #ifdef NOUVEAU_DMA_DEBUG
        nvchan->dma.push_free = 1;
 #endif
-       OUT_RING_CH(chan, 0x20000000 | (nvpb->res->start + 4096));
+       OUT_RING_CH(chan, 0x20000000 | nvpb->res->start);
 
        /* Add JMP back to master pushbuf from indirect pushbuf */
        (*nvpb->base.cur++) =
@@ -179,7 +179,7 @@ out_realloc:
 
        nvpb->base.channel = chan;
        nvpb->base.remaining = nvpb->res->size / 4;
-       nvpb->base.cur = &nvchan->pushbuf[(nvpb->res->start + 4096)/4];
+       nvpb->base.cur = &nvchan->pushbuf[nvpb->res->start/4];
 
        if (nvchan->pb_tail) {
                nouveau_pushbuf(nvchan->pb_tail)->next = &nvpb->base;
diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_resource.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_resource.c
new file mode 100644 (file)
index 0000000..5d9d578
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2007 Nouveau Project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include "nouveau_drmif.h"
+#include "nouveau_local.h"
+
+int
+nouveau_resource_init(struct nouveau_resource **heap,
+                     unsigned start, unsigned size)
+{
+       struct nouveau_resource *r;
+
+       r = calloc(1, sizeof(struct nouveau_resource));
+       if (!r)
+               return 1;
+
+       r->start = start;
+       r->size  = size;
+       *heap = r;
+       return 0;
+}
+
+int
+nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv,
+                      struct nouveau_resource **res)
+{
+       struct nouveau_resource *r;
+
+       if (!heap || !size || !res || *res)
+               return 1;
+
+       while (heap) {
+               if (!heap->in_use && heap->size >= size) {
+                       r = calloc(1, sizeof(struct nouveau_resource));
+                       if (!r)
+                               return 1;
+
+                       r->start  = (heap->start + heap->size) - size;
+                       r->size   = size;
+                       r->in_use = 1;
+                       r->priv   = priv;
+
+                       heap->size -= size;
+
+                       r->next = heap->next;
+                       if (heap->next)
+                               heap->next->prev = r;
+                       r->prev = heap;
+                       heap->next = r;
+
+                       *res = r;
+                       return 0;
+               }
+                       
+               heap = heap->next;
+       }
+
+       return 1;
+}
+
+void
+nouveau_resource_free(struct nouveau_resource **res)
+{
+       struct nouveau_resource *r;
+
+       if (!res || !*res)
+               return;
+       r = *res;
+
+       if (r->prev && !r->prev->in_use) {
+               r->prev->next = r->next;
+               if (r->next)
+                       r->next->prev = r->prev;
+               r->prev->size += r->size;
+               free(r);
+       } else
+       if (r->next && !r->next->in_use) {
+               r->next->prev = r->prev;
+               if (r->prev)
+                       r->prev->next = r->next;
+               r->next->size += r->size;
+               r->next->start = r->start;
+               free(r);
+       } else {
+               r->in_use = 0;
+       }
+
+       *res = NULL;
+}
index 9919272ebe160d5bbb7720d2a725533aa38967af..e6481a20f2cea8c8d73b7bf4d48e03ca7f3f3a18 100644 (file)
@@ -5,89 +5,6 @@
 
 #include "pipe/nouveau/nouveau_winsys.h"
 
-int
-nouveau_resource_init(struct nouveau_resource **heap, int size)
-{
-       struct nouveau_resource *r;
-
-       r = calloc(1, sizeof(struct nouveau_resource));
-       if (!r)
-               return 1;
-
-       r->start = 0;
-       r->size  = size;
-       *heap = r;
-       return 0;
-}
-
-int
-nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv,
-                      struct nouveau_resource **res)
-{
-       struct nouveau_resource *r;
-
-       if (!heap || !size || !res || *res)
-               return 1;
-
-       while (heap) {
-               if (!heap->in_use && heap->size >= size) {
-                       r = calloc(1, sizeof(struct nouveau_resource));
-                       if (!r)
-                               return 1;
-
-                       r->start  = (heap->start + heap->size) - size;
-                       r->size   = size;
-                       r->in_use = TRUE;
-                       r->priv   = priv;
-
-                       heap->size -= size;
-
-                       r->next = heap->next;
-                       if (heap->next)
-                               heap->next->prev = r;
-                       r->prev = heap;
-                       heap->next = r;
-
-                       *res = r;
-                       return 0;
-               }
-                       
-               heap = heap->next;
-       }
-
-       return 1;
-}
-
-void
-nouveau_resource_free(struct nouveau_resource **res)
-{
-       struct nouveau_resource *r;
-
-       if (!res || !*res)
-               return;
-       r = *res;
-
-       if (r->prev && !r->prev->in_use) {
-               r->prev->next = r->next;
-               if (r->next)
-                       r->next->prev = r->prev;
-               r->prev->size += r->size;
-               free(r);
-       } else
-       if (r->next && !r->next->in_use) {
-               r->next->prev = r->prev;
-               if (r->prev)
-                       r->prev->next = r->next;
-               r->next->size += r->size;
-               r->next->start = r->start;
-               free(r);
-       } else {
-               r->in_use = FALSE;
-       }
-
-       *res = NULL;
-}
-
 static int
 nouveau_pipe_notifier_alloc(struct nouveau_winsys *nvws, int count,
                            struct nouveau_notifier **notify)
index 4525f7113c26afd2a309a36ff4e8fbf4b3ba1b9b..7b80027c3a6165f5b62ee1b9e05904f54f9fa757 100644 (file)
@@ -17,7 +17,8 @@ struct nouveau_winsys {
 
        struct nouveau_channel *channel;
 
-       int  (*res_init)(struct nouveau_resource **heap, int size);
+       int  (*res_init)(struct nouveau_resource **heap, unsigned start,
+                        unsigned size);
        int  (*res_alloc)(struct nouveau_resource *heap, int size, void *priv,
                          struct nouveau_resource **);
        void (*res_free)(struct nouveau_resource **);
index 7b77c70e81d215453e82637178dc8b1ab1b3b5d6..518ba3574f7a446413476845a0447709e1259390 100644 (file)
@@ -241,8 +241,8 @@ nv40_create(struct pipe_winsys *pipe_winsys, struct nouveau_winsys *nvws,
                return NULL;
        }
 
-       if (nvws->res_init(&nv40->vertprog.exec_heap, 512) ||
-           nvws->res_init(&nv40->vertprog.data_heap, 256)) {
+       if (nvws->res_init(&nv40->vertprog.exec_heap, 0, 512) ||
+           nvws->res_init(&nv40->vertprog.data_heap, 0, 256)) {
                nvws->res_free(&nv40->vertprog.exec_heap);
                nvws->res_free(&nv40->vertprog.data_heap);
                free(nv40);