From e6e4946c82ab6f63143df7f49f38fa56f7e8980a Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Mon, 16 Apr 2007 16:23:05 +0200 Subject: Require the hardware lock for buffer creation (since that implies a validate). Fix drm_bo_wait_unfenced error messages and codes. Fix some return codes from libdrm. --- libdrm/xf86drm.c | 14 +++++++------- linux-core/drm_bo.c | 28 ++++++++++++---------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index a815ed7a..2473162b 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2814,7 +2814,7 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, } while (ret != 0 && errno == EAGAIN); if (ret) - return ret; + return -errno; if (!arg.handled) return -EFAULT; if (rep->ret) @@ -2870,7 +2870,7 @@ int drmBOValidate(int fd, drmBO *buf, unsigned flags, unsigned mask, } while (ret && errno == EAGAIN); if (ret) - return ret; + return -errno; if (!arg.handled) return -EFAULT; if (rep->ret) @@ -2897,7 +2897,7 @@ int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle) ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); if (ret) - return ret; + return -errno; if (!arg.handled) return -EFAULT; if (rep->ret) @@ -2919,7 +2919,7 @@ int drmBOInfo(int fd, drmBO *buf) ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); if (ret) - return ret; + return -errno; if (!arg.handled) return -EFAULT; if (rep->ret) @@ -2947,7 +2947,7 @@ int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint) } while (ret && errno == EAGAIN); if (ret) - return ret; + return -errno; if (!arg.handled) return -EFAULT; if (rep->ret) @@ -3199,7 +3199,7 @@ int drmMMLock(int fd, unsigned memType) ret = ioctl(fd, DRM_IOCTL_MM_INIT, &arg); } while (ret && errno == EAGAIN); - return ret; + return -errno; } int drmMMUnlock(int fd, unsigned memType) @@ -3215,7 +3215,7 @@ int drmMMUnlock(int fd, unsigned memType) ret = ioctl(fd, DRM_IOCTL_MM_INIT, &arg); } while (ret && errno == EAGAIN); - return ret; + return -errno; } #define DRM_MAX_FDS 16 diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index 17d6fbc0..b08700a3 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1024,30 +1024,23 @@ static int drm_bo_wait_unfenced(drm_buffer_object_t * bo, int no_wait, int eagain_if_wait) { int ret = (bo->priv_flags & _DRM_BO_FLAG_UNFENCED); - unsigned long _end = jiffies + 3 * DRM_HZ; if (ret && no_wait) return -EBUSY; else if (!ret) return 0; - do { - mutex_unlock(&bo->mutex); - DRM_WAIT_ON(ret, bo->event_queue, 3 * DRM_HZ, - !drm_bo_check_unfenced(bo)); - mutex_lock(&bo->mutex); - if (ret == -EINTR) - return -EAGAIN; - if (ret) { - DRM_ERROR - ("Error waiting for buffer to become fenced\n"); - return ret; - } - ret = (bo->priv_flags & _DRM_BO_FLAG_UNFENCED); - } while (ret && !time_after_eq(jiffies, _end)); + ret = 0; + mutex_unlock(&bo->mutex); + DRM_WAIT_ON(ret, bo->event_queue, 3 * DRM_HZ, + !drm_bo_check_unfenced(bo)); + mutex_lock(&bo->mutex); + if (ret == -EINTR) + return -EAGAIN; + ret = (bo->priv_flags & _DRM_BO_FLAG_UNFENCED); if (ret) { DRM_ERROR("Timeout waiting for buffer to become fenced\n"); - return ret; + return -EBUSY; } if (eagain_if_wait) return -EAGAIN; @@ -1669,6 +1662,9 @@ int drm_bo_ioctl(DRM_IOCTL_ARGS) rep.ret = 0; switch (req->op) { case drm_bo_create: + rep.ret = drm_bo_lock_test(dev, filp); + if (rep.ret) + break; rep.ret = drm_buffer_object_create(priv, req->size, req->type, -- cgit v1.2.3 From e91ceff6c98661bfae5db008e024b71a8a0f5129 Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Tue, 17 Apr 2007 08:46:45 +0200 Subject: Add a code comment. --- linux-core/drm_bo.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index b08700a3..4ecfb79c 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1715,6 +1715,13 @@ int drm_bo_ioctl(DRM_IOCTL_ARGS) drm_buffer_type, &uo); if (rep.ret) break; + + /* + * Note: The following code is only to + * fill in the rep argument. drm_lookup_user_object ups the + * refcount which is decreased again when we're done with the bo. + */ + mutex_lock(&dev->struct_mutex); uo = drm_lookup_user_object(priv, req->handle); entry = -- cgit v1.2.3 From e805ca959dbef85ac7b508639a64832a7995703a Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Tue, 17 Apr 2007 08:58:23 +0200 Subject: via: Make sure we flush write-combining using a follow-up read. --- shared-core/via_dma.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shared-core/via_dma.c b/shared-core/via_dma.c index 8c5a5c64..c73634e4 100644 --- a/shared-core/via_dma.c +++ b/shared-core/via_dma.c @@ -430,8 +430,10 @@ static int via_hook_segment(drm_via_private_t *dev_priv, paused = 0; via_flush_write_combine(); - *dev_priv->last_pause_ptr = pause_addr_lo; + (void) *(volatile uint32_t *)(via_get_dma(dev_priv) -1); + *paused_at = pause_addr_lo; via_flush_write_combine(); + (void) *paused_at; reader = *(dev_priv->hw_addr_ptr); ptr = ((volatile char *)paused_at - dev_priv->dma_ptr) + dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4; @@ -536,7 +538,7 @@ static void via_cmdbuf_start(drm_via_private_t * dev_priv) &pause_addr_hi, & pause_addr_lo, 1) - 1; via_flush_write_combine(); - while(! *dev_priv->last_pause_ptr); + (void) *(volatile uint32_t *)dev_priv->last_pause_ptr; VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16)); VIA_WRITE(VIA_REG_TRANSPACE, command); -- cgit v1.2.3 From 5432cc4abf672ed3adb10fd5d61a6a5716089a98 Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Tue, 17 Apr 2007 10:53:19 +0200 Subject: Fix buffer object reference problems. (Reported by Dave Airlie). --- linux-core/drm_bo.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index 4ecfb79c..88adfc98 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1716,22 +1716,7 @@ int drm_bo_ioctl(DRM_IOCTL_ARGS) if (rep.ret) break; - /* - * Note: The following code is only to - * fill in the rep argument. drm_lookup_user_object ups the - * refcount which is decreased again when we're done with the bo. - */ - - mutex_lock(&dev->struct_mutex); - uo = drm_lookup_user_object(priv, req->handle); - entry = - drm_user_object_entry(uo, drm_buffer_object_t, - base); - atomic_dec(&entry->usage); - mutex_unlock(&dev->struct_mutex); - mutex_lock(&entry->mutex); - drm_bo_fill_rep_arg(entry, &rep); - mutex_unlock(&entry->mutex); + rep.ret = drm_bo_handle_info(priv, req->handle, &rep); break; case drm_bo_unreference: rep.ret = drm_user_object_unref(priv, req->handle, -- cgit v1.2.3 From 5a96d59ce9d9ad5816e2d0e195afa9902445f594 Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Tue, 17 Apr 2007 14:15:37 +0200 Subject: Don't always free up memory space when we unpin buffers. --- linux-core/drm_bo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index 88adfc98..450e448c 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1399,7 +1399,10 @@ static int drm_buffer_object_validate(drm_buffer_object_t * bo, } else if (bo->pinned_node != NULL) { mutex_lock(&dev->struct_mutex); - drm_mm_put_block(bo->pinned_node); + + if (bo->pinned_node != bo->mem.mm_node) + drm_mm_put_block(bo->pinned_node); + list_del_init(&bo->pinned_lru); bo->pinned_node = NULL; mutex_unlock(&dev->struct_mutex); -- cgit v1.2.3