drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c- Extension
.c- Size
- 45378 bytes
- Lines
- 1874
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/highmem.hlinux/prime_numbers.hdrm/drm_print.hgem/i915_gem_internal.hgem/i915_gem_lmem.hgem/i915_gem_region.hgem/i915_gem_ttm.hgem/i915_gem_ttm_move.hgt/intel_engine_pm.hgt/intel_gpu_commands.hgt/intel_gt.hgt/intel_gt_pm.hgt/intel_migrate.hi915_reg.hi915_ttm_buddy_manager.hhuge_gem_object.hi915_selftest.hselftests/i915_random.hselftests/igt_flush_test.hselftests/igt_reset.hselftests/igt_mmap.h
Detected Declarations
struct tilefunction swizzle_bitfunction tiled_offsetfunction check_partial_mappingfunction check_partial_mappingsfunction for_each_prime_number_fromfunction setup_tile_sizefunction HAS_128_BYTE_Y_TILINGfunction igt_partial_tilingfunction igt_smoke_tilingfunction make_obj_busyfunction for_each_uabi_enginefunction default_mappingfunction create_sys_or_internalfunction assert_mmap_offsetfunction disable_retire_workerfunction restore_retire_workerfunction mmap_offset_lockfunction mmap_offset_unlockfunction igt_mmap_offset_exhaustionfunction gtt_setfunction gtt_checkfunction wc_setfunction wc_checkfunction can_mmapfunction __igt_mmapfunction igt_mmapfunction for_each_memory_regionfunction igt_close_objectsfunction list_for_each_entry_safefunction igt_make_evictablefunction list_for_each_entryfunction igt_fill_mappablefunction ___igt_mmap_migratefunction __igt_mmap_migratefunction for_each_gtfunction igt_mmap_migratefunction for_each_memory_regionfunction can_accessfunction __igt_mmap_accessfunction igt_mmap_accessfunction for_each_memory_regionfunction __igt_mmap_gpufunction for_each_uabi_enginefunction igt_mmap_gpufunction for_each_memory_regionfunction check_present_ptefunction check_absent_pte
Annotated Snippet
struct tile {
unsigned int width;
unsigned int height;
unsigned int stride;
unsigned int size;
unsigned int tiling;
unsigned int swizzle;
};
static u64 swizzle_bit(unsigned int bit, u64 offset)
{
return (offset & BIT_ULL(bit)) >> (bit - 6);
}
static u64 tiled_offset(const struct tile *tile, u64 v)
{
u64 x, y;
if (tile->tiling == I915_TILING_NONE)
return v;
y = div64_u64_rem(v, tile->stride, &x);
v = div64_u64_rem(y, tile->height, &y) * tile->stride * tile->height;
if (tile->tiling == I915_TILING_X) {
v += y * tile->width;
v += div64_u64_rem(x, tile->width, &x) << tile->size;
v += x;
} else if (tile->width == 128) {
const unsigned int ytile_span = 16;
const unsigned int ytile_height = 512;
v += y * ytile_span;
v += div64_u64_rem(x, ytile_span, &x) * ytile_height;
v += x;
} else {
const unsigned int ytile_span = 32;
const unsigned int ytile_height = 256;
v += y * ytile_span;
v += div64_u64_rem(x, ytile_span, &x) * ytile_height;
v += x;
}
switch (tile->swizzle) {
case I915_BIT_6_SWIZZLE_9:
v ^= swizzle_bit(9, v);
break;
case I915_BIT_6_SWIZZLE_9_10:
v ^= swizzle_bit(9, v) ^ swizzle_bit(10, v);
break;
case I915_BIT_6_SWIZZLE_9_11:
v ^= swizzle_bit(9, v) ^ swizzle_bit(11, v);
break;
case I915_BIT_6_SWIZZLE_9_10_11:
v ^= swizzle_bit(9, v) ^ swizzle_bit(10, v) ^ swizzle_bit(11, v);
break;
}
return v;
}
static int check_partial_mapping(struct drm_i915_gem_object *obj,
const struct tile *tile,
struct rnd_state *prng)
{
const unsigned long npages = obj->base.size / PAGE_SIZE;
struct drm_i915_private *i915 = to_i915(obj->base.dev);
struct i915_gtt_view view;
struct i915_vma *vma;
unsigned long offset;
unsigned long page;
u32 __iomem *io;
struct page *p;
unsigned int n;
u32 *cpu;
int err;
err = i915_gem_object_set_tiling(obj, tile->tiling, tile->stride);
if (err) {
pr_err("Failed to set tiling mode=%u, stride=%u, err=%d\n",
tile->tiling, tile->stride, err);
return err;
}
GEM_BUG_ON(i915_gem_object_get_tiling(obj) != tile->tiling);
GEM_BUG_ON(i915_gem_object_get_stride(obj) != tile->stride);
i915_gem_object_lock(obj, NULL);
err = i915_gem_object_set_to_gtt_domain(obj, true);
Annotation
- Immediate include surface: `linux/highmem.h`, `linux/prime_numbers.h`, `drm/drm_print.h`, `gem/i915_gem_internal.h`, `gem/i915_gem_lmem.h`, `gem/i915_gem_region.h`, `gem/i915_gem_ttm.h`, `gem/i915_gem_ttm_move.h`.
- Detected declarations: `struct tile`, `function swizzle_bit`, `function tiled_offset`, `function check_partial_mapping`, `function check_partial_mappings`, `function for_each_prime_number_from`, `function setup_tile_size`, `function HAS_128_BYTE_Y_TILING`, `function igt_partial_tiling`, `function igt_smoke_tiling`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.