aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2018-09-26 09:57:46 -0400
committerThomas Hellstrom <thellstrom@vmware.com>2018-09-28 02:55:10 -0400
commit24dc64c1ba5c3ef0463d59fef6df09336754188d (patch)
tree90b59c211d1d1375d2cd98b657aa400dd964b599
parente14c02e6b6990e9f6ee18a214a22ac26bae1b25e (diff)
drm/ttm: Export ttm_bo_get_unless_zero()
Export ttm_bo_get_unless_zero() to be used when looking up buffer objects that are removed from the lookup structure in the destructor. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Sinclair Yeh <syeh@vmware.com> Reviewed-by: Christian König <christian.koenig@amd.com>
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c3
-rw-r--r--include/drm/ttm/ttm_bo_api.h18
2 files changed, 19 insertions, 2 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 6fe91c1b692d..a1d977fbade5 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -409,8 +409,7 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
409 node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages); 409 node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages);
410 if (likely(node)) { 410 if (likely(node)) {
411 bo = container_of(node, struct ttm_buffer_object, vma_node); 411 bo = container_of(node, struct ttm_buffer_object, vma_node);
412 if (!kref_get_unless_zero(&bo->kref)) 412 bo = ttm_bo_get_unless_zero(bo);
413 bo = NULL;
414 } 413 }
415 414
416 drm_vma_offset_unlock_lookup(&bdev->vma_manager); 415 drm_vma_offset_unlock_lookup(&bdev->vma_manager);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 8c19470785e2..3fc4854dce49 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -313,6 +313,24 @@ ttm_bo_reference(struct ttm_buffer_object *bo)
313} 313}
314 314
315/** 315/**
316 * ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless
317 * its refcount has already reached zero.
318 * @bo: The buffer object.
319 *
320 * Used to reference a TTM buffer object in lookups where the object is removed
321 * from the lookup structure during the destructor and for RCU lookups.
322 *
323 * Returns: @bo if the referencing was successful, NULL otherwise.
324 */
325static inline __must_check struct ttm_buffer_object *
326ttm_bo_get_unless_zero(struct ttm_buffer_object *bo)
327{
328 if (!kref_get_unless_zero(&bo->kref))
329 return NULL;
330 return bo;
331}
332
333/**
316 * ttm_bo_wait - wait for buffer idle. 334 * ttm_bo_wait - wait for buffer idle.
317 * 335 *
318 * @bo: The buffer object. 336 * @bo: The buffer object.