Lines Matching +full:software +full:- +full:locked
1 // SPDX-License-Identifier: MIT
3 * Copyright (C) 2012-2014 Canonical Ltd (Maarten Lankhorst)
8 * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
12 * copy of this software and associated documentation files (the
13 * "Software"), to deal in the Software without restriction, including
15 * distribute, sub license, and/or sell copies of the Software, and to
16 * permit persons to whom the Software is furnished to do so, subject to
21 * of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
28 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
29 * USE OR OTHER DEALINGS IN THE SOFTWARE.
33 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
36 #include <linux/dma-resv.h>
37 #include <linux/dma-fence-array.h>
52 * locked write-side updates.
76 tmp = (long)rcu_dereference_check(list->table[index], in dma_resv_list_entry()
91 RCU_INIT_POINTER(list->table[index], (struct dma_fence *)tmp); in dma_resv_list_set()
111 list->max_fences = (size - offsetof(typeof(*list), table)) / in dma_resv_list_alloc()
112 sizeof(*list->table); in dma_resv_list_alloc()
125 for (i = 0; i < list->num_fences; ++i) { in dma_resv_list_free()
135 * dma_resv_init - initialize a reservation object
140 ww_mutex_init(&obj->lock, &reservation_ww_class); in dma_resv_init()
142 RCU_INIT_POINTER(obj->fences, NULL); in dma_resv_init()
147 * dma_resv_fini - destroys a reservation object
156 dma_resv_list_free(rcu_dereference_protected(obj->fences, true)); in dma_resv_fini()
157 ww_mutex_destroy(&obj->lock); in dma_resv_fini()
164 return rcu_dereference_check(obj->fences, dma_resv_held(obj)); in dma_resv_fences_list()
168 * dma_resv_reserve_fences - Reserve space to add fences to a dma_resv object.
173 * locked through dma_resv_lock().
175 * Note that the preallocated slots need to be re-reserved if @obj is unlocked
180 * Zero for success, or -errno
194 return -EINVAL; in dma_resv_reserve_fences()
197 if (old && old->max_fences) { in dma_resv_reserve_fences()
198 if ((old->num_fences + num_fences) <= old->max_fences) in dma_resv_reserve_fences()
200 max = max(old->num_fences + num_fences, old->max_fences * 2); in dma_resv_reserve_fences()
207 return -ENOMEM; in dma_resv_reserve_fences()
215 for (i = 0, j = 0, k = max; i < (old ? old->num_fences : 0); ++i) { in dma_resv_reserve_fences()
221 RCU_INIT_POINTER(new->table[--k], fence); in dma_resv_reserve_fences()
225 new->num_fences = j; in dma_resv_reserve_fences()
235 rcu_assign_pointer(obj->fences, new); in dma_resv_reserve_fences()
244 fence = rcu_dereference_protected(new->table[i], in dma_resv_reserve_fences()
256 * dma_resv_reset_max_fences - reset fences for debugging
259 * Reset the number of pre-reserved fence slots to test that drivers do
271 fences->max_fences = fences->num_fences; in dma_resv_reset_max_fences()
277 * dma_resv_add_fence - Add a fence to the dma_resv obj
282 * Add a fence to a slot, @obj must be locked with dma_resv_lock(), and
304 count = fobj->num_fences; in dma_resv_add_fence()
310 if ((old->context == fence->context && old_usage >= usage && in dma_resv_add_fence()
319 BUG_ON(fobj->num_fences >= fobj->max_fences); in dma_resv_add_fence()
324 smp_store_mb(fobj->num_fences, count); in dma_resv_add_fence()
329 * dma_resv_replace_fences - replace fences in the dma_resv obj
352 for (i = 0; list && i < list->num_fences; ++i) { in dma_resv_replace_fences()
356 if (old->context != context) in dma_resv_replace_fences()
368 cursor->index = 0; in dma_resv_iter_restart_unlocked()
369 cursor->num_fences = 0; in dma_resv_iter_restart_unlocked()
370 cursor->fences = dma_resv_fences_list(cursor->obj); in dma_resv_iter_restart_unlocked()
371 if (cursor->fences) in dma_resv_iter_restart_unlocked()
372 cursor->num_fences = cursor->fences->num_fences; in dma_resv_iter_restart_unlocked()
373 cursor->is_restarted = true; in dma_resv_iter_restart_unlocked()
379 if (!cursor->fences) in dma_resv_iter_walk_unlocked()
384 dma_fence_put(cursor->fence); in dma_resv_iter_walk_unlocked()
386 if (cursor->index >= cursor->num_fences) { in dma_resv_iter_walk_unlocked()
387 cursor->fence = NULL; in dma_resv_iter_walk_unlocked()
392 dma_resv_list_entry(cursor->fences, cursor->index++, in dma_resv_iter_walk_unlocked()
393 cursor->obj, &cursor->fence, in dma_resv_iter_walk_unlocked()
394 &cursor->fence_usage); in dma_resv_iter_walk_unlocked()
395 cursor->fence = dma_fence_get_rcu(cursor->fence); in dma_resv_iter_walk_unlocked()
396 if (!cursor->fence) { in dma_resv_iter_walk_unlocked()
401 if (!dma_fence_is_signaled(cursor->fence) && in dma_resv_iter_walk_unlocked()
402 cursor->usage >= cursor->fence_usage) in dma_resv_iter_walk_unlocked()
408 * dma_resv_iter_first_unlocked - first fence in an unlocked dma_resv obj.
415 * this reason prefer the locked dma_resv_iter_first() whenever possible.
425 } while (dma_resv_fences_list(cursor->obj) != cursor->fences); in dma_resv_iter_first_unlocked()
428 return cursor->fence; in dma_resv_iter_first_unlocked()
433 * dma_resv_iter_next_unlocked - next fence in an unlocked dma_resv obj.
438 * this reason prefer the locked dma_resv_iter_next() whenever possible.
447 cursor->is_restarted = false; in dma_resv_iter_next_unlocked()
448 restart = dma_resv_fences_list(cursor->obj) != cursor->fences; in dma_resv_iter_next_unlocked()
454 } while (dma_resv_fences_list(cursor->obj) != cursor->fences); in dma_resv_iter_next_unlocked()
457 return cursor->fence; in dma_resv_iter_next_unlocked()
462 * dma_resv_iter_first - first fence from a locked dma_resv object
474 dma_resv_assert_held(cursor->obj); in dma_resv_iter_first()
476 cursor->index = 0; in dma_resv_iter_first()
477 cursor->fences = dma_resv_fences_list(cursor->obj); in dma_resv_iter_first()
480 cursor->is_restarted = true; in dma_resv_iter_first()
486 * dma_resv_iter_next - next fence from a locked dma_resv object
496 dma_resv_assert_held(cursor->obj); in dma_resv_iter_next()
498 cursor->is_restarted = false; in dma_resv_iter_next()
501 if (!cursor->fences || in dma_resv_iter_next()
502 cursor->index >= cursor->fences->num_fences) in dma_resv_iter_next()
505 dma_resv_list_entry(cursor->fences, cursor->index++, in dma_resv_iter_next()
506 cursor->obj, &fence, &cursor->fence_usage); in dma_resv_iter_next()
507 } while (cursor->fence_usage > cursor->usage); in dma_resv_iter_next()
514 * dma_resv_copy_fences - Copy all fences from src to dst.
518 * Copy all fences from src to dst. dst-lock must be held.
539 return -ENOMEM; in dma_resv_copy_fences()
541 list->num_fences = 0; in dma_resv_copy_fences()
545 dma_resv_list_set(list, list->num_fences++, f, in dma_resv_copy_fences()
550 list = rcu_replace_pointer(dst->fences, list, dma_resv_held(dst)); in dma_resv_copy_fences()
557 * dma_resv_get_fences - Get an object's fences
566 * Returns either zero or -ENOMEM.
585 dma_fence_put((*fences)[--(*num_fences)]); in dma_resv_get_fences()
589 /* Eventually re-allocate the array */ in dma_resv_get_fences()
598 return -ENOMEM; in dma_resv_get_fences()
612 * dma_resv_get_singleton - Get a single fence for all the fences
618 * Returns either 0 for success or -ENOMEM.
653 while (count--) in dma_resv_get_singleton()
656 return -ENOMEM; in dma_resv_get_singleton()
659 *fence = &array->base; in dma_resv_get_singleton()
665 * dma_resv_wait_timeout - Wait on reservation's objects fences
674 * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
700 * dma_resv_set_deadline - Set a deadline on reservation's objects fences
723 * dma_resv_test_signaled - Test if a reservation object's fences have been
751 * dma_resv_describe - Dump description of the resv object into seq_file
782 return -ENOMEM; in dma_resv_lockdep()
790 if (ret == -EDEADLK) in dma_resv_lockdep()