/* * Copyright © 2008-2010 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * * Authors: * Eric Anholt <[email protected]> * Chris Wilson <[email protected]> * */ #include "gem/i915_gem_context.h" #include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" #include "i915_gem_evict.h" #include "i915_trace.h" I915_SELFTEST_DECLARE(…) static bool dying_vma(struct i915_vma *vma) { … } static int ggtt_flush(struct i915_address_space *vm) { … } static bool grab_vma(struct i915_vma *vma, struct i915_gem_ww_ctx *ww) { … } static void ungrab_vma(struct i915_vma *vma) { … } static bool mark_free(struct drm_mm_scan *scan, struct i915_gem_ww_ctx *ww, struct i915_vma *vma, unsigned int flags, struct list_head *unwind) { … } static bool defer_evict(struct i915_vma *vma) { … } /** * i915_gem_evict_something - Evict vmas to make room for binding a new one * @vm: address space to evict from * @ww: An optional struct i915_gem_ww_ctx. * @min_size: size of the desired free space * @alignment: alignment constraint of the desired free space * @color: color for the desired space * @start: start (inclusive) of the range from which to evict objects * @end: end (exclusive) of the range from which to evict objects * @flags: additional flags to control the eviction algorithm * * This function will try to evict vmas until a free space satisfying the * requirements is found. Callers must check first whether any such hole exists * already before calling this function. * * This function is used by the object/vma binding code. * * Since this function is only used to free up virtual address space it only * ignores pinned vmas, and not object where the backing storage itself is * pinned. Hence obj->pages_pin_count does not protect against eviction. * * To clarify: This is for freeing up virtual address space, not for freeing * memory in e.g. the shrinker. */ int i915_gem_evict_something(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww, u64 min_size, u64 alignment, unsigned long color, u64 start, u64 end, unsigned flags) { … } /** * i915_gem_evict_for_node - Evict vmas to make room for binding a new one * @vm: address space to evict from * @ww: An optional struct i915_gem_ww_ctx. * @target: range (and color) to evict for * @flags: additional flags to control the eviction algorithm * * This function will try to evict vmas that overlap the target node. * * To clarify: This is for freeing up virtual address space, not for freeing * memory in e.g. the shrinker. */ int i915_gem_evict_for_node(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww, struct drm_mm_node *target, unsigned int flags) { … } /** * i915_gem_evict_vm - Evict all idle vmas from a vm * @vm: Address space to cleanse * @ww: An optional struct i915_gem_ww_ctx. If not NULL, i915_gem_evict_vm * will be able to evict vma's locked by the ww as well. * @busy_bo: Optional pointer to struct drm_i915_gem_object. If not NULL, then * in the event i915_gem_evict_vm() is unable to trylock an object for eviction, * then @busy_bo will point to it. -EBUSY is also returned. The caller must drop * the vm->mutex, before trying again to acquire the contended lock. The caller * also owns a reference to the object. * * This function evicts all vmas from a vm. * * This is used by the execbuf code as a last-ditch effort to defragment the * address space. * * To clarify: This is for freeing up virtual address space, not for freeing * memory in e.g. the shrinker. */ int i915_gem_evict_vm(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww, struct drm_i915_gem_object **busy_bo) { … } #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) #include "selftests/i915_gem_evict.c" #endif