summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Skeggs <skeggsb@gmail.com>2007-12-10 02:07:47 +1100
committerBen Skeggs <skeggsb@gmail.com>2007-12-10 02:10:42 +1100
commit1a3987240a547ba6e625c864f10a033858de4c65 (patch)
treee33806bca6827580d8d604eaa904d91ce54cca3a /src
parent88b56c454513f5097b7806ffaa5c313881861504 (diff)
nouveau: give resources a start property
Diffstat (limited to 'src')
-rw-r--r--src/mesa/drivers/dri/nouveau_winsys/Makefile1
-rw-r--r--src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h3
-rw-r--r--src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c6
-rw-r--r--src/mesa/drivers/dri/nouveau_winsys/nouveau_resource.c111
-rw-r--r--src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c83
-rw-r--r--src/mesa/pipe/nouveau/nouveau_winsys.h3
-rw-r--r--src/mesa/pipe/nv40/nv40_context.c4
7 files changed, 121 insertions, 90 deletions
diff --git a/src/mesa/drivers/dri/nouveau_winsys/Makefile b/src/mesa/drivers/dri/nouveau_winsys/Makefile
index fe9a9668b1..f2490c823d 100644
--- a/src/mesa/drivers/dri/nouveau_winsys/Makefile
+++ b/src/mesa/drivers/dri/nouveau_winsys/Makefile
@@ -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 \
diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h b/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h
index f176767f13..1c2a2c12cf 100644
--- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h
+++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h
@@ -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,
diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c
index 6cb06f8c37..551889f94c 100644
--- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c
+++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c
@@ -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
index 0000000000..5d9d578b4f
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_resource.c
@@ -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;
+}
diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c
index 9919272ebe..e6481a20f2 100644
--- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c
+++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c
@@ -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)
diff --git a/src/mesa/pipe/nouveau/nouveau_winsys.h b/src/mesa/pipe/nouveau/nouveau_winsys.h
index 4525f7113c..7b80027c3a 100644
--- a/src/mesa/pipe/nouveau/nouveau_winsys.h
+++ b/src/mesa/pipe/nouveau/nouveau_winsys.h
@@ -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 **);
diff --git a/src/mesa/pipe/nv40/nv40_context.c b/src/mesa/pipe/nv40/nv40_context.c
index 7b77c70e81..518ba3574f 100644
--- a/src/mesa/pipe/nv40/nv40_context.c
+++ b/src/mesa/pipe/nv40/nv40_context.c
@@ -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);