aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/vmwgfx/vmwgfx_resource.c')
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index c1912f852b42..e57667ca7557 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -354,7 +354,7 @@ int vmw_user_lookup_handle(struct vmw_private *dev_priv,
354 } 354 }
355 355
356 *out_surf = NULL; 356 *out_surf = NULL;
357 ret = vmw_user_dmabuf_lookup(tfile, handle, out_buf); 357 ret = vmw_user_dmabuf_lookup(tfile, handle, out_buf, NULL);
358 return ret; 358 return ret;
359} 359}
360 360
@@ -481,7 +481,8 @@ int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
481 uint32_t size, 481 uint32_t size,
482 bool shareable, 482 bool shareable,
483 uint32_t *handle, 483 uint32_t *handle,
484 struct vmw_dma_buffer **p_dma_buf) 484 struct vmw_dma_buffer **p_dma_buf,
485 struct ttm_base_object **p_base)
485{ 486{
486 struct vmw_user_dma_buffer *user_bo; 487 struct vmw_user_dma_buffer *user_bo;
487 struct ttm_buffer_object *tmp; 488 struct ttm_buffer_object *tmp;
@@ -515,6 +516,10 @@ int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
515 } 516 }
516 517
517 *p_dma_buf = &user_bo->dma; 518 *p_dma_buf = &user_bo->dma;
519 if (p_base) {
520 *p_base = &user_bo->prime.base;
521 kref_get(&(*p_base)->refcount);
522 }
518 *handle = user_bo->prime.base.hash.key; 523 *handle = user_bo->prime.base.hash.key;
519 524
520out_no_base_object: 525out_no_base_object:
@@ -631,6 +636,7 @@ int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
631 struct vmw_dma_buffer *dma_buf; 636 struct vmw_dma_buffer *dma_buf;
632 struct vmw_user_dma_buffer *user_bo; 637 struct vmw_user_dma_buffer *user_bo;
633 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 638 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
639 struct ttm_base_object *buffer_base;
634 int ret; 640 int ret;
635 641
636 if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) == 0 642 if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) == 0
@@ -643,7 +649,8 @@ int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
643 649
644 switch (arg->op) { 650 switch (arg->op) {
645 case drm_vmw_synccpu_grab: 651 case drm_vmw_synccpu_grab:
646 ret = vmw_user_dmabuf_lookup(tfile, arg->handle, &dma_buf); 652 ret = vmw_user_dmabuf_lookup(tfile, arg->handle, &dma_buf,
653 &buffer_base);
647 if (unlikely(ret != 0)) 654 if (unlikely(ret != 0))
648 return ret; 655 return ret;
649 656
@@ -651,6 +658,7 @@ int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
651 dma); 658 dma);
652 ret = vmw_user_dmabuf_synccpu_grab(user_bo, tfile, arg->flags); 659 ret = vmw_user_dmabuf_synccpu_grab(user_bo, tfile, arg->flags);
653 vmw_dmabuf_unreference(&dma_buf); 660 vmw_dmabuf_unreference(&dma_buf);
661 ttm_base_object_unref(&buffer_base);
654 if (unlikely(ret != 0 && ret != -ERESTARTSYS && 662 if (unlikely(ret != 0 && ret != -ERESTARTSYS &&
655 ret != -EBUSY)) { 663 ret != -EBUSY)) {
656 DRM_ERROR("Failed synccpu grab on handle 0x%08x.\n", 664 DRM_ERROR("Failed synccpu grab on handle 0x%08x.\n",
@@ -692,7 +700,8 @@ int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
692 return ret; 700 return ret;
693 701
694 ret = vmw_user_dmabuf_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 702 ret = vmw_user_dmabuf_alloc(dev_priv, vmw_fpriv(file_priv)->tfile,
695 req->size, false, &handle, &dma_buf); 703 req->size, false, &handle, &dma_buf,
704 NULL);
696 if (unlikely(ret != 0)) 705 if (unlikely(ret != 0))
697 goto out_no_dmabuf; 706 goto out_no_dmabuf;
698 707
@@ -721,7 +730,8 @@ int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
721} 730}
722 731
723int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile, 732int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
724 uint32_t handle, struct vmw_dma_buffer **out) 733 uint32_t handle, struct vmw_dma_buffer **out,
734 struct ttm_base_object **p_base)
725{ 735{
726 struct vmw_user_dma_buffer *vmw_user_bo; 736 struct vmw_user_dma_buffer *vmw_user_bo;
727 struct ttm_base_object *base; 737 struct ttm_base_object *base;
@@ -743,7 +753,10 @@ int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
743 vmw_user_bo = container_of(base, struct vmw_user_dma_buffer, 753 vmw_user_bo = container_of(base, struct vmw_user_dma_buffer,
744 prime.base); 754 prime.base);
745 (void)ttm_bo_reference(&vmw_user_bo->dma.base); 755 (void)ttm_bo_reference(&vmw_user_bo->dma.base);
746 ttm_base_object_unref(&base); 756 if (p_base)
757 *p_base = base;
758 else
759 ttm_base_object_unref(&base);
747 *out = &vmw_user_bo->dma; 760 *out = &vmw_user_bo->dma;
748 761
749 return 0; 762 return 0;
@@ -1004,7 +1017,7 @@ int vmw_dumb_create(struct drm_file *file_priv,
1004 1017
1005 ret = vmw_user_dmabuf_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 1018 ret = vmw_user_dmabuf_alloc(dev_priv, vmw_fpriv(file_priv)->tfile,
1006 args->size, false, &args->handle, 1019 args->size, false, &args->handle,
1007 &dma_buf); 1020 &dma_buf, NULL);
1008 if (unlikely(ret != 0)) 1021 if (unlikely(ret != 0))
1009 goto out_no_dmabuf; 1022 goto out_no_dmabuf;
1010 1023
@@ -1032,7 +1045,7 @@ int vmw_dumb_map_offset(struct drm_file *file_priv,
1032 struct vmw_dma_buffer *out_buf; 1045 struct vmw_dma_buffer *out_buf;
1033 int ret; 1046 int ret;
1034 1047
1035 ret = vmw_user_dmabuf_lookup(tfile, handle, &out_buf); 1048 ret = vmw_user_dmabuf_lookup(tfile, handle, &out_buf, NULL);
1036 if (ret != 0) 1049 if (ret != 0)
1037 return -EINVAL; 1050 return -EINVAL;
1038 1051