drivers/gpu/drm/i915/i915_gem_evict.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/i915_gem_evict.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/i915/i915_gem_evict.c
Extension
.c
Size
15981 bytes
Lines
546
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!i915_gem_object_trylock(vma->obj, ww)) {
			i915_gem_object_put(vma->obj);
			return false;
		}
	} else {
		/* Dead objects don't need pins */
		atomic_and(~I915_VMA_PIN_MASK, &vma->flags);
	}

	return true;
}

static void ungrab_vma(struct i915_vma *vma)
{
	if (dying_vma(vma))
		return;

	i915_gem_object_unlock(vma->obj);
	i915_gem_object_put(vma->obj);
}

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)
{
	if (i915_vma_is_pinned(vma))
		return false;

	if (!grab_vma(vma, ww))
		return false;

	list_add(&vma->evict_link, unwind);
	return drm_mm_scan_add_block(scan, &vma->node);
}

static bool defer_evict(struct i915_vma *vma)
{
	if (i915_vma_is_active(vma))
		return true;

	if (i915_vma_is_scanout(vma))
		return true;

	return false;
}

/**
 * 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)
{
	struct drm_mm_scan scan;
	struct list_head eviction_list;
	struct i915_vma *vma, *next;
	struct drm_mm_node *node;
	enum drm_mm_insert_mode mode;
	struct i915_vma *active;
	struct intel_gt *gt;
	int ret;

Annotation

Implementation Notes