Lines Matching +full:ref +full:-
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
32 * Base- and reference object implementation for the various
50 * @ref_hash: Hash tables of ref objects, one per ttm_ref_type,
51 * for fast lookup of ref objects given a base object.
79 * This is the per-device data structure needed for ttm object management.
92 * @hash: Hash entry for the per-file object reference hash.
94 * @head: List entry for the per-file list of ref-objects.
96 * @kref: Ref count.
98 * @obj: Base object this ref object is referencing.
100 * @ref_type: Type of ref object.
105 * a particular ttm_object_file. It also carries a ref count to avoid creating
106 * multiple ref objects if a ttm_object_file references the same base
124 refcount_acquire(&tfile->refcount); in ttm_object_file_ref()
140 if (refcount_release(&tfile->refcount)) in ttm_object_file_unref()
153 struct ttm_object_device *tdev = tfile->tdev; in ttm_base_object_init()
156 base->shareable = shareable; in ttm_base_object_init()
157 base->tfile = ttm_object_file_ref(tfile); in ttm_base_object_init()
158 base->refcount_release = rcount_release; in ttm_base_object_init()
159 base->ref_obj_release = ref_obj_release; in ttm_base_object_init()
160 base->object_type = object_type; in ttm_base_object_init()
161 refcount_init(&base->refcount, 1); in ttm_base_object_init()
162 rw_init(&tdev->object_lock, "ttmbao"); in ttm_base_object_init()
163 rw_wlock(&tdev->object_lock); in ttm_base_object_init()
164 ret = drm_ht_just_insert_please(&tdev->object_hash, in ttm_base_object_init()
165 &base->hash, in ttm_base_object_init()
167 rw_wunlock(&tdev->object_lock); in ttm_base_object_init()
179 rw_wlock(&tdev->object_lock); in ttm_base_object_init()
180 (void)drm_ht_remove_item(&tdev->object_hash, &base->hash); in ttm_base_object_init()
181 rw_wunlock(&tdev->object_lock); in ttm_base_object_init()
188 struct ttm_object_device *tdev = base->tfile->tdev; in ttm_release_base()
190 (void)drm_ht_remove_item(&tdev->object_hash, &base->hash); in ttm_release_base()
191 rw_wunlock(&tdev->object_lock); in ttm_release_base()
198 if (base->refcount_release) { in ttm_release_base()
199 ttm_object_file_unref(&base->tfile); in ttm_release_base()
200 base->refcount_release(&base); in ttm_release_base()
202 rw_wlock(&tdev->object_lock); in ttm_release_base()
208 struct ttm_object_device *tdev = base->tfile->tdev; in ttm_base_object_unref()
217 rw_wlock(&tdev->object_lock); in ttm_base_object_unref()
218 if (refcount_release(&base->refcount)) in ttm_base_object_unref()
220 rw_wunlock(&tdev->object_lock); in ttm_base_object_unref()
226 struct ttm_object_device *tdev = tfile->tdev; in ttm_base_object_lookup()
231 rw_rlock(&tdev->object_lock); in ttm_base_object_lookup()
232 ret = drm_ht_find_item(&tdev->object_hash, key, &hash); in ttm_base_object_lookup()
236 refcount_acquire(&base->refcount); in ttm_base_object_lookup()
238 rw_runlock(&tdev->object_lock); in ttm_base_object_lookup()
243 if (tfile != base->tfile && !base->shareable) { in ttm_base_object_lookup()
244 printf("[TTM] Attempted access of non-shareable object %p\n", in ttm_base_object_lookup()
253 MALLOC_DEFINE(M_TTM_OBJ_REF, "ttm_obj_ref", "TTM Ref Objects");
259 struct drm_open_hash *ht = &tfile->ref_hash[ref_type]; in ttm_ref_object_add()
260 struct ttm_ref_object *ref; in ttm_ref_object_add() local
262 struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob; in ttm_ref_object_add()
263 int ret = -EINVAL; in ttm_ref_object_add()
268 while (ret == -EINVAL) { in ttm_ref_object_add()
269 rw_rlock(&tfile->lock); in ttm_ref_object_add()
270 ret = drm_ht_find_item(ht, base->hash.key, &hash); in ttm_ref_object_add()
273 ref = drm_hash_entry(hash, struct ttm_ref_object, hash); in ttm_ref_object_add()
274 refcount_acquire(&ref->kref); in ttm_ref_object_add()
275 rw_runlock(&tfile->lock); in ttm_ref_object_add()
279 rw_runlock(&tfile->lock); in ttm_ref_object_add()
280 ret = ttm_mem_global_alloc(mem_glob, sizeof(*ref), in ttm_ref_object_add()
284 ref = malloc(sizeof(*ref), M_TTM_OBJ_REF, M_WAITOK); in ttm_ref_object_add()
285 ref->hash.key = base->hash.key; in ttm_ref_object_add()
286 ref->obj = base; in ttm_ref_object_add()
287 ref->tfile = tfile; in ttm_ref_object_add()
288 ref->ref_type = ref_type; in ttm_ref_object_add()
289 refcount_init(&ref->kref, 1); in ttm_ref_object_add()
291 rw_wlock(&tfile->lock); in ttm_ref_object_add()
292 ret = drm_ht_insert_item(ht, &ref->hash); in ttm_ref_object_add()
295 list_add_tail(&ref->head, &tfile->ref_list); in ttm_ref_object_add()
296 refcount_acquire(&base->refcount); in ttm_ref_object_add()
297 rw_wunlock(&tfile->lock); in ttm_ref_object_add()
303 rw_wunlock(&tfile->lock); in ttm_ref_object_add()
304 MPASS(ret == -EINVAL); in ttm_ref_object_add()
306 ttm_mem_global_free(mem_glob, sizeof(*ref)); in ttm_ref_object_add()
307 free(ref, M_TTM_OBJ_REF); in ttm_ref_object_add()
313 static void ttm_ref_object_release(struct ttm_ref_object *ref) in ttm_ref_object_release() argument
315 struct ttm_base_object *base = ref->obj; in ttm_ref_object_release()
316 struct ttm_object_file *tfile = ref->tfile; in ttm_ref_object_release()
318 struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob; in ttm_ref_object_release()
320 ht = &tfile->ref_hash[ref->ref_type]; in ttm_ref_object_release()
321 (void)drm_ht_remove_item(ht, &ref->hash); in ttm_ref_object_release()
322 list_del(&ref->head); in ttm_ref_object_release()
323 rw_wunlock(&tfile->lock); in ttm_ref_object_release()
325 if (ref->ref_type != TTM_REF_USAGE && base->ref_obj_release) in ttm_ref_object_release()
326 base->ref_obj_release(base, ref->ref_type); in ttm_ref_object_release()
328 ttm_base_object_unref(&ref->obj); in ttm_ref_object_release()
329 ttm_mem_global_free(mem_glob, sizeof(*ref)); in ttm_ref_object_release()
330 free(ref, M_TTM_OBJ_REF); in ttm_ref_object_release()
331 rw_wlock(&tfile->lock); in ttm_ref_object_release()
337 struct drm_open_hash *ht = &tfile->ref_hash[ref_type]; in ttm_ref_object_base_unref()
338 struct ttm_ref_object *ref; in ttm_ref_object_base_unref() local
342 rw_wlock(&tfile->lock); in ttm_ref_object_base_unref()
345 rw_wunlock(&tfile->lock); in ttm_ref_object_base_unref()
346 return -EINVAL; in ttm_ref_object_base_unref()
348 ref = drm_hash_entry(hash, struct ttm_ref_object, hash); in ttm_ref_object_base_unref()
349 if (refcount_release(&ref->kref)) in ttm_ref_object_base_unref()
350 ttm_ref_object_release(ref); in ttm_ref_object_base_unref()
351 rw_wunlock(&tfile->lock); in ttm_ref_object_base_unref()
357 struct ttm_ref_object *ref; in ttm_object_file_release() local
363 rw_wlock(&tfile->lock); in ttm_object_file_release()
370 while (!list_empty(&tfile->ref_list)) { in ttm_object_file_release()
371 list = tfile->ref_list.next; in ttm_object_file_release()
372 ref = list_entry(list, struct ttm_ref_object, head); in ttm_object_file_release()
373 ttm_ref_object_release(ref); in ttm_object_file_release()
377 drm_ht_remove(&tfile->ref_hash[i]); in ttm_object_file_release()
379 rw_wunlock(&tfile->lock); in ttm_object_file_release()
392 rw_init(&tfile->lock, "ttmfo"); in ttm_object_file_init()
393 tfile->tdev = tdev; in ttm_object_file_init()
394 refcount_init(&tfile->refcount, 1); in ttm_object_file_init()
395 INIT_LIST_HEAD(&tfile->ref_list); in ttm_object_file_init()
398 ret = drm_ht_create(&tfile->ref_hash[i], hash_order); in ttm_object_file_init()
408 drm_ht_remove(&tfile->ref_hash[i]); in ttm_object_file_init()
425 tdev->mem_glob = mem_glob; in ttm_object_device_init()
426 rw_init(&tdev->object_lock, "ttmdo"); in ttm_object_device_init()
427 atomic_set(&tdev->object_count, 0); in ttm_object_device_init()
428 ret = drm_ht_create(&tdev->object_hash, hash_order); in ttm_object_device_init()
443 rw_wlock(&tdev->object_lock); in ttm_object_device_release()
444 drm_ht_remove(&tdev->object_hash); in ttm_object_device_release()
445 rw_wunlock(&tdev->object_lock); in ttm_object_device_release()