drivers/gpu/drm/i915/gem/i915_gem_ttm.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/gem/i915_gem_ttm.c- Extension
.c- Size
- 39072 bytes
- Lines
- 1387
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/shmem_fs.hlinux/gpu_buddy.hdrm/drm_print.hdrm/ttm/ttm_placement.hdrm/ttm/ttm_tt.hi915_drv.hi915_jiffies.hi915_ttm_buddy_manager.hintel_memory_region.hintel_region_ttm.hgem/i915_gem_mman.hgem/i915_gem_object.hgem/i915_gem_region.hgem/i915_gem_ttm.hgem/i915_gem_ttm_move.hgem/i915_gem_ttm_pm.hgt/intel_gpu_commands.h
Detected Declarations
struct i915_ttm_ttfunction i915_ttm_err_to_gemfunction i915_ttm_select_tt_cachingfunction i915_ttm_place_from_regionfunction i915_ttm_placement_from_objfunction i915_ttm_tt_shmem_populatefunction i915_ttm_tt_shmem_unpopulatefunction i915_ttm_tt_releasefunction i915_ttm_tt_populatefunction i915_ttm_tt_unpopulatefunction i915_ttm_tt_destroyfunction i915_ttm_eviction_valuablefunction i915_ttm_evict_flagsfunction i915_ttm_free_cached_io_rsgtfunction i915_ttm_purgefunction i915_ttm_shrinkfunction i915_ttm_delete_mem_notifyfunction alivefunction i915_ttm_resource_get_stfunction i915_ttm_truncatefunction i915_ttm_swap_notifyfunction i915_ttm_resource_mappablefunction i915_ttm_io_mem_reservefunction i915_ttm_io_mem_pfnfunction i915_ttm_access_memoryfunction __i915_ttm_get_pagesfunction i915_ttm_get_pagesfunction i915_ttm_migratefunction i915_ttm_migratefunction i915_ttm_put_pagesfunction i915_ttm_adjust_lrufunction set_pagesfunction i915_ttm_delayed_freefunction vm_fault_ttmfunction ttm_ttfunction ttm_bo_vm_reservefunction vm_access_ttmfunction ttm_vm_openfunction ttm_vm_closefunction i915_ttm_mmap_offsetfunction i915_ttm_unmap_virtualfunction i915_ttm_bo_destroyfunction __i915_gem_ttm_object_initfunction i915_gem_ttm_system_setup
Annotated Snippet
struct i915_ttm_tt {
struct ttm_tt ttm;
struct device *dev;
struct i915_refct_sgt cached_rsgt;
bool is_shmem;
struct file *filp;
};
static const struct ttm_place sys_placement_flags = {
.fpfn = 0,
.lpfn = 0,
.mem_type = I915_PL_SYSTEM,
.flags = 0,
};
static struct ttm_placement i915_sys_placement = {
.num_placement = 1,
.placement = &sys_placement_flags,
};
/**
* i915_ttm_sys_placement - Return the struct ttm_placement to be
* used for an object in system memory.
*
* Rather than making the struct extern, use this
* function.
*
* Return: A pointer to a static variable for sys placement.
*/
struct ttm_placement *i915_ttm_sys_placement(void)
{
return &i915_sys_placement;
}
static int i915_ttm_err_to_gem(int err)
{
/* Fastpath */
if (likely(!err))
return 0;
switch (err) {
case -EBUSY:
/*
* TTM likes to convert -EDEADLK to -EBUSY, and wants us to
* restart the operation, since we don't record the contending
* lock. We use -EAGAIN to restart.
*/
return -EAGAIN;
case -ENOSPC:
/*
* Memory type / region is full, and we can't evict.
* Except possibly system, that returns -ENOMEM;
*/
return -ENXIO;
default:
break;
}
return err;
}
static enum ttm_caching
i915_ttm_select_tt_caching(const struct drm_i915_gem_object *obj)
{
/*
* Objects only allowed in system get cached cpu-mappings, or when
* evicting lmem-only buffers to system for swapping. Other objects get
* WC mapping for now. Even if in system.
*/
if (obj->mm.n_placements <= 1)
return ttm_cached;
return ttm_write_combined;
}
static void
i915_ttm_place_from_region(const struct intel_memory_region *mr,
struct ttm_place *place,
resource_size_t offset,
resource_size_t size,
unsigned int flags)
{
memset(place, 0, sizeof(*place));
place->mem_type = intel_region_to_ttm_type(mr);
if (mr->type == INTEL_MEMORY_SYSTEM)
return;
if (flags & I915_BO_ALLOC_CONTIGUOUS)
Annotation
- Immediate include surface: `linux/shmem_fs.h`, `linux/gpu_buddy.h`, `drm/drm_print.h`, `drm/ttm/ttm_placement.h`, `drm/ttm/ttm_tt.h`, `i915_drv.h`, `i915_jiffies.h`, `i915_ttm_buddy_manager.h`.
- Detected declarations: `struct i915_ttm_tt`, `function i915_ttm_err_to_gem`, `function i915_ttm_select_tt_caching`, `function i915_ttm_place_from_region`, `function i915_ttm_placement_from_obj`, `function i915_ttm_tt_shmem_populate`, `function i915_ttm_tt_shmem_unpopulate`, `function i915_ttm_tt_release`, `function i915_ttm_tt_populate`, `function i915_ttm_tt_unpopulate`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.