Lines Matching refs:vma
41 static bool dying_vma(struct i915_vma *vma)
43 return !kref_read(&vma->obj->base.refcount);
58 static bool grab_vma(struct i915_vma *vma, struct i915_gem_ww_ctx *ww) in grab_vma() argument
64 if (i915_gem_object_get_rcu(vma->obj)) { in grab_vma()
65 if (!i915_gem_object_trylock(vma->obj, ww)) { in grab_vma()
66 i915_gem_object_put(vma->obj); in grab_vma()
71 atomic_and(~I915_VMA_PIN_MASK, &vma->flags); in grab_vma()
77 static void ungrab_vma(struct i915_vma *vma) in ungrab_vma() argument
79 if (dying_vma(vma)) in ungrab_vma()
82 i915_gem_object_unlock(vma->obj); in ungrab_vma()
83 i915_gem_object_put(vma->obj); in ungrab_vma()
89 struct i915_vma *vma, in mark_free() argument
93 if (i915_vma_is_pinned(vma)) in mark_free()
96 if (!grab_vma(vma, ww)) in mark_free()
99 list_add(&vma->evict_link, unwind); in mark_free()
100 return drm_mm_scan_add_block(scan, &vma->node); in mark_free()
103 static bool defer_evict(struct i915_vma *vma) in defer_evict() argument
105 if (i915_vma_is_active(vma)) in defer_evict()
108 if (i915_vma_is_scanout(vma)) in defer_evict()
148 struct i915_vma *vma, *next; in i915_gem_evict_something() local
182 list_for_each_entry_safe(vma, next, &vm->bound_list, vm_link) { in i915_gem_evict_something()
183 if (vma == active) { /* now seen this vma twice */ in i915_gem_evict_something()
205 if (active != ERR_PTR(-EAGAIN) && defer_evict(vma)) { in i915_gem_evict_something()
207 active = vma; in i915_gem_evict_something()
209 list_move_tail(&vma->vm_link, &vm->bound_list); in i915_gem_evict_something()
213 if (mark_free(&scan, ww, vma, flags, &eviction_list)) in i915_gem_evict_something()
218 list_for_each_entry_safe(vma, next, &eviction_list, evict_link) { in i915_gem_evict_something()
219 ret = drm_mm_scan_remove_block(&scan, &vma->node); in i915_gem_evict_something()
221 ungrab_vma(vma); in i915_gem_evict_something()
265 list_for_each_entry_safe(vma, next, &eviction_list, evict_link) { in i915_gem_evict_something()
266 if (drm_mm_scan_remove_block(&scan, &vma->node)) { in i915_gem_evict_something()
267 __i915_vma_pin(vma); in i915_gem_evict_something()
269 list_del(&vma->evict_link); in i915_gem_evict_something()
270 ungrab_vma(vma); in i915_gem_evict_something()
276 list_for_each_entry_safe(vma, next, &eviction_list, evict_link) { in i915_gem_evict_something()
277 __i915_vma_unpin(vma); in i915_gem_evict_something()
279 ret = __i915_vma_unbind(vma); in i915_gem_evict_something()
280 ungrab_vma(vma); in i915_gem_evict_something()
284 vma = container_of(node, struct i915_vma, node); in i915_gem_evict_something()
287 if (vma->node.color != I915_COLOR_UNEVICTABLE && in i915_gem_evict_something()
288 grab_vma(vma, ww)) { in i915_gem_evict_something()
289 ret = __i915_vma_unbind(vma); in i915_gem_evict_something()
290 ungrab_vma(vma); in i915_gem_evict_something()
320 struct i915_vma *vma, *next; in i915_gem_evict_for_node() local
355 vma = container_of(node, typeof(*vma), node); in i915_gem_evict_for_node()
375 if (i915_vma_is_pinned(vma)) { in i915_gem_evict_for_node()
380 if (flags & PIN_NONBLOCK && i915_vma_is_active(vma)) { in i915_gem_evict_for_node()
385 if (!grab_vma(vma, ww)) { in i915_gem_evict_for_node()
399 __i915_vma_pin(vma); in i915_gem_evict_for_node()
400 list_add(&vma->evict_link, &eviction_list); in i915_gem_evict_for_node()
403 list_for_each_entry_safe(vma, next, &eviction_list, evict_link) { in i915_gem_evict_for_node()
404 __i915_vma_unpin(vma); in i915_gem_evict_for_node()
406 ret = __i915_vma_unbind(vma); in i915_gem_evict_for_node()
408 ungrab_vma(vma); in i915_gem_evict_for_node()
453 struct i915_vma *vma, *vn; in i915_gem_evict_vm() local
457 list_for_each_entry(vma, &vm->bound_list, vm_link) { in i915_gem_evict_vm()
458 if (i915_vma_is_pinned(vma)) in i915_gem_evict_vm()
466 if (!i915_gem_object_get_rcu(vma->obj) || in i915_gem_evict_vm()
467 (ww && (dma_resv_locking_ctx(vma->obj->base.resv) == &ww->ctx))) { in i915_gem_evict_vm()
468 __i915_vma_pin(vma); in i915_gem_evict_vm()
469 list_add(&vma->evict_link, &locked_eviction_list); in i915_gem_evict_vm()
473 if (!i915_gem_object_trylock(vma->obj, ww)) { in i915_gem_evict_vm()
475 *busy_bo = vma->obj; /* holds ref */ in i915_gem_evict_vm()
479 i915_gem_object_put(vma->obj); in i915_gem_evict_vm()
483 __i915_vma_pin(vma); in i915_gem_evict_vm()
484 list_add(&vma->evict_link, &eviction_list); in i915_gem_evict_vm()
490 list_for_each_entry_safe(vma, vn, &locked_eviction_list, evict_link) { in i915_gem_evict_vm()
491 __i915_vma_unpin(vma); in i915_gem_evict_vm()
494 ret = __i915_vma_unbind(vma); in i915_gem_evict_vm()
498 if (!dying_vma(vma)) in i915_gem_evict_vm()
499 i915_gem_object_put(vma->obj); in i915_gem_evict_vm()
502 list_for_each_entry_safe(vma, vn, &eviction_list, evict_link) { in i915_gem_evict_vm()
503 __i915_vma_unpin(vma); in i915_gem_evict_vm()
505 ret = __i915_vma_unbind(vma); in i915_gem_evict_vm()
510 i915_gem_object_unlock(vma->obj); in i915_gem_evict_vm()
511 i915_gem_object_put(vma->obj); in i915_gem_evict_vm()