summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hellstrom <thomas-at-tungstengraphics-dot-com>2006-09-01 18:11:05 +0200
committerThomas Hellstrom <thomas-at-tungstengraphics-dot-com>2006-09-01 18:11:05 +0200
commit405b5d9ca8cc9f6c5c7bb764c684bf74ba7660c6 (patch)
treeb638e0fe1f0fb90d45bfb6434141e91688f4f726
parentef8e618cf30ab7dcbe8c7211e0c2508c5520a669 (diff)
Flag bit pattern bugfixes. Remove some error messages.
-rw-r--r--libdrm/xf86drm.c74
-rw-r--r--linux-core/drm_bo.c27
-rw-r--r--linux-core/drm_ttm.c2
-rw-r--r--shared-core/drm.h14
4 files changed, 64 insertions, 53 deletions
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index aa1a5998..073fd0c4 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -2598,6 +2598,7 @@ int drmBOCreate(int fd, drmTTM *ttm, unsigned long start, unsigned long size,
req->type = type;
buf->ttm = NULL;
+ buf->virtual = NULL;
switch(type) {
case drm_bo_type_ttm:
@@ -2631,7 +2632,6 @@ int drmBOCreate(int fd, drmTTM *ttm, unsigned long start, unsigned long size,
drmBOCopyReply(rep, buf);
buf->mapVirtual = NULL;
buf->mapCount = 0;
- buf->virtual = NULL;
return 0;
}
@@ -2642,6 +2642,12 @@ int drmBODestroy(int fd, drmBO *buf)
drm_bo_arg_request_t *req = &arg.req;
drm_bo_arg_reply_t *rep = &arg.rep;
+ if (buf->mapVirtual) {
+ (void) drmUnmap(buf->mapVirtual, buf->start + buf->size);
+ buf->mapVirtual = NULL;
+ buf->virtual = NULL;
+ }
+
arg.handled = 0;
req->handle = buf->handle;
req->op = drm_bo_destroy;
@@ -2730,25 +2736,31 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
int ret = 0;
/*
+ * At the moment, we don't allow recursive mapping of a buffer, since
+ * the first mapping may have to be unmapped before this one to succeed.
+ * This might result in a deadlock. We need a DRM mutex mechanism!!
+ */
+
+ if (buf->mapCount) {
+ drmMsg("Recursive mapping is currently not allowed.\n");
+ return -EAGAIN;
+ }
+
+ /*
* Make sure we have a virtual address of the buffer.
*/
- fprintf(stderr, "Address is 0x%08x\n", address);
- if (!buf->mapVirtual) {
- if (buf->mapCount == 0) {
- drmAddress virtual;
- ret = drmMap(fd, buf->mapHandle, buf->size + buf->start, &virtual);
- if (ret)
- return ret;
- ++buf->mapCount;
- buf->mapVirtual = virtual;
- buf->virtual = ((char *) virtual) + buf->start;
- fprintf(stderr,"Mapvirtual, virtual: 0x%08x 0x%08x\n",
- buf->mapVirtual, buf->virtual);
- }
+ if (!buf->virtual) {
+ drmAddress virtual;
+ ret = drmMap(fd, buf->mapHandle, buf->size + buf->start, &virtual);
+ if (ret)
+ return ret;
+ buf->mapVirtual = virtual;
+ buf->virtual = ((char *) virtual) + buf->start;
+ fprintf(stderr,"Mapvirtual, virtual: 0x%08x 0x%08x\n",
+ buf->mapVirtual, buf->virtual);
}
- fprintf(stderr, "Address is 0x%08x\n", address);
arg.handled = 0;
req->handle = buf->handle;
req->mask = mapFlags;
@@ -2761,28 +2773,21 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
* This IOCTL synchronizes the buffer.
*/
- fprintf(stderr, "Address is 0x%08x\n", address);
do {
ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg);
} while (ret != 0 && errno == EAGAIN);
- fprintf(stderr, "Address is 0x%08x\n", address);
- if (ret || !arg.handled || rep->ret) {
- if (--buf->mapCount == 0) {
- (void )drmUnmap(buf->mapVirtual, buf->start + buf->size);
- }
- }
if (ret)
return ret;
if (!arg.handled)
return -EFAULT;
if (rep->ret)
return rep->ret;
-
+
+ drmBOCopyReply(rep, buf);
buf->mapFlags = mapFlags;
- fprintf(stderr, "Address is 0x%08x\n", address);
+ ++buf->mapCount;
*address = buf->virtual;
- drmBOCopyReply(rep, buf);
return 0;
}
@@ -2793,13 +2798,6 @@ int drmBOUnmap(int fd, drmBO *buf)
drm_bo_arg_request_t *req = &arg.req;
drm_bo_arg_reply_t *rep = &arg.rep;
- if (buf->mapCount == 0) {
- return -EINVAL;
- }
-
- if (--buf->mapCount == 0) {
- (void) drmUnmap(buf->mapVirtual, buf->start + buf->size);
- }
arg.handled = 0;
req->handle = buf->handle;
@@ -2814,6 +2812,8 @@ int drmBOUnmap(int fd, drmBO *buf)
if (rep->ret)
return rep->ret;
+ --buf->mapCount;
+
return 0;
}
@@ -2825,6 +2825,11 @@ int drmBOValidate(int fd, drmBO *buf, unsigned flags, unsigned mask,
drm_bo_arg_reply_t *rep = &arg.rep;
int ret = 0;
+ if (buf->mapCount) {
+ drmMsg("Cannot validate while buffer is mapped.\n");
+ return -EAGAIN;
+ }
+
arg.handled = 0;
req->handle = buf->handle;
req->mask = flags;
@@ -2988,6 +2993,11 @@ int drmBOValidateList(int fd, drmBOList *list)
if (prevNext)
*prevNext = (unsigned long) arg;
+ if (node->buf->mapCount) {
+ drmMsg("Cannot validate while buffer is mapped.\n");
+ return -EAGAIN;
+ }
+
req->next = 0;
prevNext = &req->next;
arg->handled = 0;
diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c
index 317b5f7a..70342ac9 100644
--- a/linux-core/drm_bo.c
+++ b/linux-core/drm_bo.c
@@ -70,7 +70,6 @@ static int drm_move_tt_to_local(drm_buffer_object_t * buf)
BUG_ON(!buf->tt);
- DRM_ERROR("Flipping out of AGP\n");
mutex_lock(&dev->struct_mutex);
drm_unbind_ttm_region(buf->ttm_region);
drm_mm_put_block(&bm->tt_manager, buf->tt);
@@ -442,8 +441,9 @@ static int drm_move_local_to_tt(drm_buffer_object_t * bo, int no_wait)
if (ret)
return ret;
-
+#ifdef BODEBUG
DRM_ERROR("Flipping in to AGP 0x%08lx\n", bo->tt->start);
+#endif
mutex_lock(&dev->struct_mutex);
ret = drm_bind_ttm_region(bo->ttm_region, bo->tt->start);
if (ret) {
@@ -459,9 +459,9 @@ static int drm_move_local_to_tt(drm_buffer_object_t * bo, int no_wait)
bo->flags |= DRM_BO_FLAG_MEM_TT;
if (bo->priv_flags & _DRM_BO_FLAG_EVICTED) {
- DRM_ERROR("Flush read caches\n");
ret = dev->driver->bo_driver->invalidate_caches(dev, bo->flags);
- DRM_ERROR("Warning: Could not flush read caches\n");
+ if (ret)
+ DRM_ERROR("Warning: Could not flush read caches\n");
}
DRM_FLAG_MASKED(bo->priv_flags, 0, _DRM_BO_FLAG_EVICTED);
@@ -919,14 +919,12 @@ static int drm_bo_move_buffer(drm_buffer_object_t * bo, uint32_t new_flags,
/*
* Flush outstanding fences.
*/
- DRM_ERROR("Flushing fences\n");
drm_bo_busy(bo);
/*
* Make sure we're not mapped.
*/
- DRM_ERROR("Wait unmapped\n");
ret = drm_bo_wait_unmapped(bo, no_wait);
if (ret)
return ret;
@@ -935,7 +933,6 @@ static int drm_bo_move_buffer(drm_buffer_object_t * bo, uint32_t new_flags,
* Wait for outstanding fences.
*/
- DRM_ERROR("Wait fences\n");
ret = drm_bo_wait(bo, 0, no_wait);
if (ret == -EINTR)
@@ -979,19 +976,21 @@ static int drm_buffer_object_validate(drm_buffer_object_t * bo,
return -EINVAL;
}
- /*
- * Check whether we need to move buffer.
- */
-
+#ifdef BODEBUG
+ DRM_ERROR("New flags 0x%08x, Old flags 0x%08x\n",
+ new_flags, bo->flags);
+#endif
ret = driver->fence_type(new_flags, &bo->fence_class, &bo->fence_flags);
- DRM_ERROR("Fence type = 0x%08x\n", bo->fence_flags);
if (ret) {
DRM_ERROR("Driver did not support given buffer permissions\n");
return ret;
}
+ /*
+ * Check whether we need to move buffer.
+ */
+
if (flag_diff & DRM_BO_MASK_MEM) {
- DRM_ERROR("Calling move buffer\n");
ret = drm_bo_move_buffer(bo, new_flags, no_wait);
if (ret)
return ret;
@@ -1050,7 +1049,7 @@ static int drm_bo_handle_validate(drm_file_t * priv, uint32_t handle,
goto out;
ret = drm_bo_new_flags(dev, bo->flags,
- (flags & mask) | (bo->flags & ~mask), hint,
+ (flags & mask) | (bo->mask & ~mask), hint,
0, &new_flags, &bo->mask);
if (ret)
diff --git a/linux-core/drm_ttm.c b/linux-core/drm_ttm.c
index 97e3e96d..26133f9c 100644
--- a/linux-core/drm_ttm.c
+++ b/linux-core/drm_ttm.c
@@ -447,7 +447,9 @@ int drm_evict_ttm_region(drm_ttm_backend_list_t * entry)
entry->num_pages);
drm_ttm_unlock_mm(ttm, 0, 1);
}
+#ifdef BODEBUG
DRM_ERROR("Unbinding\n");
+#endif
be->unbind(entry->be);
if (ttm && be->needs_cache_adjust(be)) {
drm_set_caching(ttm, entry->page_offset,
diff --git a/shared-core/drm.h b/shared-core/drm.h
index f781abc6..a7d778ce 100644
--- a/shared-core/drm.h
+++ b/shared-core/drm.h
@@ -693,23 +693,23 @@ typedef struct drm_ttm_arg {
*/
/* Pinned buffer. */
-#define DRM_BO_FLAG_NO_EVICT 0x00000001
+#define DRM_BO_FLAG_NO_EVICT 0x00000010
/* Always keep a system memory shadow to a vram buffer */
-#define DRM_BO_FLAG_SHADOW_VRAM 0x00000002
+#define DRM_BO_FLAG_SHADOW_VRAM 0x00000020
/* When mapped for reading, make sure the buffer is cached even
if it means moving the buffer to system memory */
-#define DRM_BO_FLAG_SHAREABLE 0x00000004
+#define DRM_BO_FLAG_SHAREABLE 0x00000040
/* When there is a choice between VRAM and TT, prefer VRAM.
The default behaviour is to prefer TT. */
-#define DRM_BO_FLAG_CACHED 0x00000008
+#define DRM_BO_FLAG_CACHED 0x00000080
/* The buffer is shareable with other processes */
-#define DRM_BO_FLAG_READ_CACHED 0x00001000
+#define DRM_BO_FLAG_READ_CACHED 0x00080000
/* The buffer is currently cached */
-#define DRM_BO_FLAG_PREFER_VRAM 0x00002000
+#define DRM_BO_FLAG_PREFER_VRAM 0x00040000
/* Bind this buffer cached if the hardware supports it. */
-#define DRM_BO_FLAG_BIND_CACHED 0x00004000
+#define DRM_BO_FLAG_BIND_CACHED 0x0002000
/* Translation table aperture */
#define DRM_BO_FLAG_MEM_TT 0x01000000