drivers/gpu/drm/ttm/ttm_device.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/ttm_device.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/ttm/ttm_device.c- Extension
.c- Size
- 8353 bytes
- Lines
- 320
- 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/mm.hdrm/ttm/ttm_allocation.hdrm/ttm/ttm_bo.hdrm/ttm/ttm_device.hdrm/ttm/ttm_tt.hdrm/ttm/ttm_placement.httm_module.httm_bo_internal.h
Detected Declarations
function ttm_global_releasefunction ttm_global_initfunction ttm_device_prepare_hibernationfunction ttm_global_swapoutfunction ttm_device_swapoutfunction ttm_device_initfunction ttm_device_finifunction ttm_device_clear_lru_dma_mappingsfunction ttm_device_clear_dma_mappingsexport ttm_globexport ttm_device_prepare_hibernationexport ttm_device_swapoutexport ttm_device_initexport ttm_device_finiexport ttm_device_clear_dma_mappings
Annotated Snippet
if (unlikely(glob->dummy_read_page == NULL)) {
ret = -ENOMEM;
goto out;
}
pr_warn("Using GFP_DMA32 fallback for dummy_read_page\n");
}
INIT_LIST_HEAD(&glob->device_list);
atomic_set(&glob->bo_count, 0);
debugfs_create_atomic_t("buffer_objects", 0444, ttm_debugfs_root,
&glob->bo_count);
out:
if (ret && ttm_debugfs_root)
debugfs_remove(ttm_debugfs_root);
if (ret)
--ttm_glob_use_count;
mutex_unlock(&ttm_global_mutex);
return ret;
}
/**
* ttm_device_prepare_hibernation - move GTT BOs to shmem for hibernation.
*
* @bdev: A pointer to a struct ttm_device to prepare hibernation for.
*
* Return: 0 on success, negative number on failure.
*/
int ttm_device_prepare_hibernation(struct ttm_device *bdev)
{
struct ttm_operation_ctx ctx = { };
int ret;
do {
ret = ttm_device_swapout(bdev, &ctx, GFP_KERNEL);
} while (ret > 0);
return ret;
}
EXPORT_SYMBOL(ttm_device_prepare_hibernation);
/*
* A buffer object shrink method that tries to swap out the first
* buffer object on the global::swap_lru list.
*/
int ttm_global_swapout(struct ttm_operation_ctx *ctx, gfp_t gfp_flags)
{
struct ttm_global *glob = &ttm_glob;
struct ttm_device *bdev;
int ret = 0;
mutex_lock(&ttm_global_mutex);
list_for_each_entry(bdev, &glob->device_list, device_list) {
ret = ttm_device_swapout(bdev, ctx, gfp_flags);
if (ret > 0) {
list_move_tail(&bdev->device_list, &glob->device_list);
break;
}
}
mutex_unlock(&ttm_global_mutex);
return ret;
}
int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
gfp_t gfp_flags)
{
struct ttm_resource_manager *man;
unsigned i;
s64 lret;
for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) {
man = ttm_manager_type(bdev, i);
if (!man || !man->use_tt)
continue;
lret = ttm_bo_swapout(bdev, ctx, man, gfp_flags, 1);
/* Can be both positive (num_pages) and negative (error) */
if (lret)
return lret;
}
return 0;
}
EXPORT_SYMBOL(ttm_device_swapout);
/**
* ttm_device_init
*
* @bdev: A pointer to a struct ttm_device to initialize.
* @funcs: Function table for the device.
* @dev: The core kernel device pointer for DMA mappings and allocations.
* @mapping: The address space to use for this bo.
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/export.h`, `linux/mm.h`, `drm/ttm/ttm_allocation.h`, `drm/ttm/ttm_bo.h`, `drm/ttm/ttm_device.h`, `drm/ttm/ttm_tt.h`, `drm/ttm/ttm_placement.h`.
- Detected declarations: `function ttm_global_release`, `function ttm_global_init`, `function ttm_device_prepare_hibernation`, `function ttm_global_swapout`, `function ttm_device_swapout`, `function ttm_device_init`, `function ttm_device_fini`, `function ttm_device_clear_lru_dma_mappings`, `function ttm_device_clear_dma_mappings`, `export ttm_glob`.
- 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.