drivers/gpu/drm/ttm/ttm_bo.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/ttm_bo.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/ttm/ttm_bo.c- Extension
.c- Size
- 35021 bytes
- Lines
- 1301
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
drm/drm_print.hdrm/drm_util.hdrm/ttm/ttm_allocation.hdrm/ttm/ttm_bo.hdrm/ttm/ttm_placement.hdrm/ttm/ttm_tt.hlinux/export.hlinux/jiffies.hlinux/slab.hlinux/sched.hlinux/mm.hlinux/file.hlinux/module.hlinux/atomic.hlinux/cgroup_dmem.hlinux/dma-resv.httm_module.httm_bo_internal.h
Detected Declarations
struct ttm_bo_evict_walkstruct ttm_bo_swapout_walkfunction Copyrightfunction ttm_bo_move_to_lru_tailfunction ttm_lru_bulk_move_tailfunction ttm_bo_handle_move_memfunction ttm_bo_cleanup_memtype_usefunction ttm_bo_individualize_resvfunction ttm_bo_flush_all_fencesfunction ttm_bo_delayed_deletefunction ttm_bo_releasefunction ttm_bo_putfunction ttm_bo_finifunction ttm_bo_bounce_temp_bufferfunction ttm_bo_evictfunction ttm_bo_eviction_valuablefunction ttm_bo_evict_firstfunction ttm_bo_evict_cbfunction ttm_bo_evict_allocfunction ttm_bo_pinfunction ttm_bo_unpinfunction ttm_bo_add_pipelined_eviction_fencesfunction ttm_bo_alloc_resourcefunction ttm_bo_mem_spacefunction ttm_bo_validatefunction ttm_bo_init_reservedfunction ttm_bo_init_validatefunction ttm_bo_unmap_virtualfunction ttm_bo_wait_ctxfunction ttm_bo_swapout_cbfunction ttm_bo_swapoutfunction ttm_bo_tt_destroyfunction ttm_bo_populatefunction ttm_bo_setup_exportexport ttm_bo_move_to_lru_tailexport ttm_bo_set_bulk_moveexport ttm_bo_finiexport ttm_bo_eviction_valuableexport ttm_bo_pinexport ttm_bo_unpinexport ttm_bo_mem_spaceexport ttm_bo_validateexport ttm_bo_init_reservedexport ttm_bo_init_validateexport ttm_bo_unmap_virtualexport ttm_bo_wait_ctxexport ttm_bo_populateexport ttm_bo_setup_export
Annotated Snippet
struct ttm_bo_evict_walk {
/** @walk: The walk base parameters. */
struct ttm_lru_walk walk;
/** @place: The place passed to the resource allocation. */
const struct ttm_place *place;
/** @evictor: The buffer object we're trying to make room for. */
struct ttm_buffer_object *evictor;
/** @res: The allocated resource if any. */
struct ttm_resource **res;
/** @evicted: Number of successful evictions. */
unsigned long evicted;
/** @limit_pool: Which pool limit we should test against */
struct dmem_cgroup_pool_state *limit_pool;
/** @try_low: Whether we should attempt to evict BO's with low watermark threshold */
bool try_low;
/** @hit_low: If we cannot evict a bo when @try_low is false (first pass) */
bool hit_low;
};
static s64 ttm_bo_evict_cb(struct ttm_lru_walk *walk, struct ttm_buffer_object *bo)
{
struct ttm_bo_evict_walk *evict_walk =
container_of(walk, typeof(*evict_walk), walk);
s64 lret;
if (!dmem_cgroup_state_evict_valuable(evict_walk->limit_pool, bo->resource->css,
evict_walk->try_low, &evict_walk->hit_low))
return 0;
if (bo->pin_count || !bo->bdev->funcs->eviction_valuable(bo, evict_walk->place))
return 0;
if (bo->deleted) {
lret = ttm_bo_wait_ctx(bo, walk->arg.ctx);
if (!lret)
ttm_bo_cleanup_memtype_use(bo);
} else {
lret = ttm_bo_evict(bo, walk->arg.ctx);
}
if (lret)
goto out;
evict_walk->evicted++;
if (evict_walk->res)
lret = ttm_resource_alloc(evict_walk->evictor, evict_walk->place,
evict_walk->res, NULL);
if (lret == 0)
return 1;
out:
/* Errors that should terminate the walk. */
if (lret == -ENOSPC)
return -EBUSY;
return lret;
}
static const struct ttm_lru_walk_ops ttm_evict_walk_ops = {
.process_bo = ttm_bo_evict_cb,
};
static int ttm_bo_evict_alloc(struct ttm_device *bdev,
struct ttm_resource_manager *man,
const struct ttm_place *place,
struct ttm_buffer_object *evictor,
struct ttm_operation_ctx *ctx,
struct ww_acquire_ctx *ticket,
struct ttm_resource **res,
struct dmem_cgroup_pool_state *limit_pool)
{
struct ttm_bo_evict_walk evict_walk = {
.walk = {
.ops = &ttm_evict_walk_ops,
.arg = {
.ctx = ctx,
.ticket = ticket,
}
},
.place = place,
.evictor = evictor,
.res = res,
.limit_pool = limit_pool,
};
s64 lret;
evict_walk.walk.arg.trylock_only = true;
lret = ttm_lru_walk_for_evict(&evict_walk.walk, bdev, man, 1);
/* One more attempt if we hit low limit? */
Annotation
- Immediate include surface: `drm/drm_print.h`, `drm/drm_util.h`, `drm/ttm/ttm_allocation.h`, `drm/ttm/ttm_bo.h`, `drm/ttm/ttm_placement.h`, `drm/ttm/ttm_tt.h`, `linux/export.h`, `linux/jiffies.h`.
- Detected declarations: `struct ttm_bo_evict_walk`, `struct ttm_bo_swapout_walk`, `function Copyright`, `function ttm_bo_move_to_lru_tail`, `function ttm_lru_bulk_move_tail`, `function ttm_bo_handle_move_mem`, `function ttm_bo_cleanup_memtype_use`, `function ttm_bo_individualize_resv`, `function ttm_bo_flush_all_fences`, `function ttm_bo_delayed_delete`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration 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.