aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2018-09-26 10:03:57 -0400
committerThomas Hellstrom <thellstrom@vmware.com>2018-09-28 02:57:07 -0400
commitb733bc2e0accd60af23719fd1fc77941c11059f4 (patch)
tree51ad685edbba9b9ad16b2489f3d186c7f5378976
parent64ad2abfe9a628ce79859d072704bd1ef7682044 (diff)
drm/vmwgfx: Look up user buffer objects without taking a reference
Identically to how we look up ttm base objects witout reference, provide the same functionality to vmw user buffer objects which derive from them. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Sinclair Yeh <syeh@vmware.com>
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_bo.c41
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h12
2 files changed, 53 insertions, 0 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index 3df4e5266cac..7ce1c2f87d9a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -921,6 +921,47 @@ int vmw_user_bo_lookup(struct ttm_object_file *tfile,
921 return 0; 921 return 0;
922} 922}
923 923
924/**
925 * vmw_user_bo_noref_lookup - Look up a vmw user buffer object without reference
926 * @tfile: The TTM object file the handle is registered with.
927 * @handle: The user buffer object handle.
928 *
929 * This function looks up a struct vmw_user_bo and returns a pointer to the
930 * struct vmw_buffer_object it derives from without refcounting the pointer.
931 * The returned pointer is only valid until vmw_user_bo_noref_release() is
932 * called, and the object pointed to by the returned pointer may be doomed.
933 * Any persistent usage of the object requires a refcount to be taken using
934 * ttm_bo_reference_unless_doomed(). Iff this function returns successfully it
935 * needs to be paired with vmw_user_bo_noref_release() and no sleeping-
936 * or scheduling functions may be called inbetween these function calls.
937 *
938 * Return: A struct vmw_buffer_object pointer if successful or negative
939 * error pointer on failure.
940 */
941struct vmw_buffer_object *
942vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle)
943{
944 struct vmw_user_buffer_object *vmw_user_bo;
945 struct ttm_base_object *base;
946
947 base = ttm_base_object_noref_lookup(tfile, handle);
948 if (!base) {
949 DRM_ERROR("Invalid buffer object handle 0x%08lx.\n",
950 (unsigned long)handle);
951 return ERR_PTR(-ESRCH);
952 }
953
954 if (unlikely(ttm_base_object_type(base) != ttm_buffer_type)) {
955 ttm_base_object_noref_release();
956 DRM_ERROR("Invalid buffer object handle 0x%08lx.\n",
957 (unsigned long)handle);
958 return ERR_PTR(-EINVAL);
959 }
960
961 vmw_user_bo = container_of(base, struct vmw_user_buffer_object,
962 prime.base);
963 return &vmw_user_bo->vbo;
964}
924 965
925/** 966/**
926 * vmw_user_bo_reference - Open a handle to a vmw user buffer object. 967 * vmw_user_bo_reference - Open a handle to a vmw user buffer object.
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index d83bb70627ec..061fa937f369 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -772,6 +772,18 @@ extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
772extern void vmw_bo_move_notify(struct ttm_buffer_object *bo, 772extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
773 struct ttm_mem_reg *mem); 773 struct ttm_mem_reg *mem);
774extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo); 774extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
775extern struct vmw_buffer_object *
776vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle);
777
778/**
779 * vmw_user_bo_noref_release - release a buffer object pointer looked up
780 * without reference
781 */
782static inline void vmw_user_bo_noref_release(void)
783{
784 ttm_base_object_noref_release();
785}
786
775 787
776/** 788/**
777 * Misc Ioctl functionality - vmwgfx_ioctl.c 789 * Misc Ioctl functionality - vmwgfx_ioctl.c