drivers/gpu/drm/ttm/ttm_resource.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/ttm_resource.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/ttm/ttm_resource.c- Extension
.c- Size
- 26788 bytes
- Lines
- 956
- 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
linux/debugfs.hlinux/export.hlinux/io-mapping.hlinux/iosys-map.hlinux/scatterlist.hlinux/cgroup_dmem.hdrm/ttm/ttm_bo.hdrm/ttm/ttm_placement.hdrm/ttm/ttm_resource.hdrm/ttm/ttm_tt.hdrm/drm_print.hdrm/drm_util.h
Detected Declarations
function filesfunction ttm_resource_cursor_move_bulk_tailfunction ttm_bulk_move_adjust_cursorsfunction ttm_bulk_move_drop_cursorsfunction ttm_resource_cursor_initfunction ttm_resource_cursor_finifunction ttm_lru_bulk_move_initfunction ttm_lru_bulk_move_finifunction ttm_lru_bulk_move_tailfunction ttm_lru_bulk_move_posfunction ttm_lru_bulk_move_pos_tailfunction ttm_lru_bulk_move_addfunction ttm_lru_bulk_move_delfunction ttm_resource_is_swappedfunction ttm_resource_unevictablefunction ttm_resource_add_bulk_movefunction ttm_resource_del_bulk_movefunction ttm_resource_del_bulk_move_unevictablefunction ttm_resource_move_to_lru_tailfunction ttm_resource_initfunction ttm_resource_initfunction ttm_resource_allocfunction ttm_resource_freefunction ttm_resource_intersectsfunction ttm_resource_compatiblefunction ttm_resource_set_bofunction ttm_resource_manager_initfunction ttm_resource_manager_evict_allfunction ttm_resource_manager_usagefunction ttm_resource_manager_debugfunction ttm_resource_cursor_check_bulkfunction ttm_resource_manager_firstfunction ttm_resource_manager_nextfunction list_for_each_entry_continuefunction ttm_lru_first_res_or_nullfunction list_for_each_entryfunction ttm_kmap_iter_iomap_map_localfunction ttm_kmap_iter_iomap_unmap_localfunction sg_dma_addressfunction ttm_kmap_iter_linear_io_map_localfunction ttm_kmap_iter_linear_io_initfunction ttm_kmap_iter_linear_io_finifunction ttm_resource_manager_showfunction ttm_resource_manager_create_debugfsexport ttm_lru_bulk_move_initexport ttm_lru_bulk_move_finiexport ttm_lru_bulk_move_tailexport ttm_resource_init
Annotated Snippet
if (ret) {
if (ret == -EAGAIN)
ret = -ENOSPC;
return ret;
}
}
ret = man->func->alloc(man, bo, place, res_ptr);
if (ret) {
if (pool)
dmem_cgroup_uncharge(pool, bo->base.size);
return ret;
}
(*res_ptr)->css = pool;
spin_lock(&bo->bdev->lru_lock);
ttm_resource_add_bulk_move(*res_ptr, bo);
spin_unlock(&bo->bdev->lru_lock);
return 0;
}
EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_resource_alloc);
void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
{
struct ttm_resource_manager *man;
struct dmem_cgroup_pool_state *pool;
if (!*res)
return;
spin_lock(&bo->bdev->lru_lock);
ttm_resource_del_bulk_move(*res, bo);
spin_unlock(&bo->bdev->lru_lock);
pool = (*res)->css;
man = ttm_manager_type(bo->bdev, (*res)->mem_type);
man->func->free(man, *res);
*res = NULL;
if (man->cg)
dmem_cgroup_uncharge(pool, bo->base.size);
}
EXPORT_SYMBOL(ttm_resource_free);
/**
* ttm_resource_intersects - test for intersection
*
* @bdev: TTM device structure
* @res: The resource to test
* @place: The placement to test
* @size: How many bytes the new allocation needs.
*
* Test if @res intersects with @place and @size. Used for testing if evictions
* are valuable or not.
*
* Returns true if the res placement intersects with @place and @size.
*/
bool ttm_resource_intersects(struct ttm_device *bdev,
struct ttm_resource *res,
const struct ttm_place *place,
size_t size)
{
struct ttm_resource_manager *man;
man = ttm_manager_type(bdev, res->mem_type);
if (!place || !man->func->intersects)
return true;
return man->func->intersects(man, res, place, size);
}
/**
* ttm_resource_compatible - check if resource is compatible with placement
*
* @res: the resource to check
* @placement: the placement to check against
* @evicting: true if the caller is doing evictions
*
* Returns true if the placement is compatible.
*/
bool ttm_resource_compatible(struct ttm_resource *res,
struct ttm_placement *placement,
bool evicting)
{
struct ttm_buffer_object *bo = res->bo;
struct ttm_device *bdev = bo->bdev;
unsigned i;
if (res->placement & TTM_PL_FLAG_TEMPORARY)
return false;
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/export.h`, `linux/io-mapping.h`, `linux/iosys-map.h`, `linux/scatterlist.h`, `linux/cgroup_dmem.h`, `drm/ttm/ttm_bo.h`, `drm/ttm/ttm_placement.h`.
- Detected declarations: `function files`, `function ttm_resource_cursor_move_bulk_tail`, `function ttm_bulk_move_adjust_cursors`, `function ttm_bulk_move_drop_cursors`, `function ttm_resource_cursor_init`, `function ttm_resource_cursor_fini`, `function ttm_lru_bulk_move_init`, `function ttm_lru_bulk_move_fini`, `function ttm_lru_bulk_move_tail`, `function ttm_lru_bulk_move_pos`.
- 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.