drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c- Extension
.c- Size
- 48130 bytes
- Lines
- 1984
- 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/list_sort.hlinux/prime_numbers.hgem/i915_gem_context.hgem/i915_gem_internal.hgem/i915_gem_lmem.hgem/i915_gem_region.hgem/selftests/mock_context.hgt/intel_context.hgt/intel_gpu_commands.hgt/intel_gtt.hi915_random.hi915_selftest.hi915_vma_resource.hmock_drm.hmock_gem_device.hmock_gtt.higt_flush_test.h
Detected Declarations
function filesfunction fake_free_pagesfunction fake_get_pagesfunction fake_put_pagesfunction fake_dma_objectfunction igt_ppgtt_allocfunction lowlevel_holefunction close_object_listfunction list_for_each_entry_safefunction fill_holefunction for_each_prime_number_fromfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entry_reversefunction list_for_each_entry_reversefunction walk_holefunction for_each_prime_number_fromfunction pot_holefunction drunk_holefunction __shrink_holefunction shrink_holefunction for_each_prime_number_fromfunction shrink_boomfunction misaligned_casefunction misaligned_pinfunction for_each_memory_regionfunction exercise_ppgttfunction igt_ppgtt_fillfunction igt_ppgtt_walkfunction igt_ppgtt_potfunction igt_ppgtt_drunkfunction igt_ppgtt_lowlevelfunction igt_ppgtt_shrinkfunction igt_ppgtt_shrink_boomfunction igt_ppgtt_misaligned_pinfunction sort_holesfunction exercise_ggttfunction igt_ggtt_fillfunction igt_ggtt_walkfunction igt_ggtt_potfunction igt_ggtt_drunkfunction igt_ggtt_lowlevelfunction igt_ggtt_misaligned_pinfunction igt_ggtt_pagefunction track_vma_bindfunction exercise_mockfunction igt_mock_fillfunction igt_mock_walk
Annotated Snippet
if (err) {
i915_vm_free_pt_stash(&ppgtt->vm, &stash);
goto err_ppgtt_cleanup;
}
ppgtt->vm.allocate_va_range(&ppgtt->vm, &stash, 0, size);
cond_resched();
ppgtt->vm.clear_range(&ppgtt->vm, 0, size);
i915_vm_free_pt_stash(&ppgtt->vm, &stash);
}
/* Check we can incrementally allocate the entire range */
for (last = 0, size = 4096; size <= limit; last = size, size <<= 2) {
struct i915_vm_pt_stash stash = {};
err = i915_vm_alloc_pt_stash(&ppgtt->vm, &stash, size - last);
if (err)
goto err_ppgtt_cleanup;
err = i915_vm_map_pt_stash(&ppgtt->vm, &stash);
if (err) {
i915_vm_free_pt_stash(&ppgtt->vm, &stash);
goto err_ppgtt_cleanup;
}
ppgtt->vm.allocate_va_range(&ppgtt->vm, &stash,
last, size - last);
cond_resched();
i915_vm_free_pt_stash(&ppgtt->vm, &stash);
}
err_ppgtt_cleanup:
if (err == -EDEADLK) {
err = i915_gem_ww_ctx_backoff(&ww);
if (!err)
goto retry;
}
i915_gem_ww_ctx_fini(&ww);
ppgtt_vm_put:
i915_vm_put(&ppgtt->vm);
return err;
}
static int lowlevel_hole(struct i915_address_space *vm,
u64 hole_start, u64 hole_end,
unsigned long end_time)
{
const unsigned int min_alignment =
i915_vm_min_alignment(vm, INTEL_MEMORY_SYSTEM);
I915_RND_STATE(seed_prng);
struct i915_vma_resource *mock_vma_res;
unsigned int size;
mock_vma_res = kzalloc(sizeof(*mock_vma_res), GFP_KERNEL);
if (!mock_vma_res)
return -ENOMEM;
/* Keep creating larger objects until one cannot fit into the hole */
for (size = 12; (hole_end - hole_start) >> size; size++) {
I915_RND_SUBSTATE(prng, seed_prng);
struct drm_i915_gem_object *obj;
unsigned int *order, count, n;
u64 hole_size, aligned_size;
aligned_size = max_t(u32, ilog2(min_alignment), size);
hole_size = (hole_end - hole_start) >> aligned_size;
if (hole_size > KMALLOC_MAX_SIZE / sizeof(u32))
hole_size = KMALLOC_MAX_SIZE / sizeof(u32);
count = hole_size >> 1;
if (!count) {
pr_debug("%s: hole is too small [%llx - %llx] >> %d: %lld\n",
__func__, hole_start, hole_end, size, hole_size);
break;
}
do {
order = i915_random_order(count, &prng);
if (order)
break;
} while (count >>= 1);
if (!count) {
kfree(mock_vma_res);
return -ENOMEM;
}
GEM_BUG_ON(!order);
GEM_BUG_ON(count * BIT_ULL(aligned_size) > vm->total);
Annotation
- Immediate include surface: `linux/list_sort.h`, `linux/prime_numbers.h`, `gem/i915_gem_context.h`, `gem/i915_gem_internal.h`, `gem/i915_gem_lmem.h`, `gem/i915_gem_region.h`, `gem/selftests/mock_context.h`, `gt/intel_context.h`.
- Detected declarations: `function files`, `function fake_free_pages`, `function fake_get_pages`, `function fake_put_pages`, `function fake_dma_object`, `function igt_ppgtt_alloc`, `function lowlevel_hole`, `function close_object_list`, `function list_for_each_entry_safe`, `function fill_hole`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.