drivers/gpu/drm/ttm/ttm_tt.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/ttm_tt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/ttm/ttm_tt.c- Extension
.c- Size
- 14374 bytes
- Lines
- 566
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cc_platform.hlinux/debugfs.hlinux/export.hlinux/file.hlinux/module.hlinux/sched.hlinux/shmem_fs.hdrm/drm_cache.hdrm/drm_device.hdrm/drm_print.hdrm/drm_util.hdrm/ttm/ttm_backup.hdrm/ttm/ttm_bo.hdrm/ttm/ttm_tt.httm_module.httm_pool_internal.h
Detected Declarations
function ttm_tt_createfunction cc_platform_hasfunction ttm_tt_alloc_page_directoryfunction ttm_dma_tt_alloc_page_directoryfunction ttm_sg_tt_alloc_page_directoryfunction ttm_tt_destroyfunction ttm_tt_init_fieldsfunction ttm_tt_initfunction ttm_tt_finifunction ttm_sg_tt_initfunction ttm_tt_swapinfunction ttm_tt_backupfunction ttm_tt_restorefunction ttm_tt_swapoutfunction ttm_tt_populatefunction ttm_tt_unpopulatefunction ttm_tt_debugfs_shrink_showfunction ttm_tt_mgr_initfunction ttm_kmap_iter_tt_map_localfunction ttm_kmap_iter_tt_unmap_localfunction ttm_kmap_iter_tt_initfunction ttm_tt_pages_limitfunction ttm_tt_setup_backupexport ttm_tt_initexport ttm_tt_finiexport ttm_sg_tt_initexport ttm_tt_restoreexport ttm_tt_populateexport ttm_kmap_iter_tt_initexport ttm_tt_pages_limitexport ttm_tt_setup_backup
Annotated Snippet
cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
page_flags |= TTM_TT_FLAG_DECRYPTED;
drm_info_once(ddev, "TT memory decryption enabled.");
}
bo->ttm = bdev->funcs->ttm_tt_create(bo, page_flags);
if (unlikely(bo->ttm == NULL))
return -ENOMEM;
WARN_ON(bo->ttm->page_flags & TTM_TT_FLAG_EXTERNAL_MAPPABLE &&
!(bo->ttm->page_flags & TTM_TT_FLAG_EXTERNAL));
return 0;
}
EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_tt_create);
/*
* Allocates storage for pointers to the pages that back the ttm.
*/
static int ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
{
ttm->pages = kvcalloc(ttm->num_pages, sizeof(void*), GFP_KERNEL);
if (!ttm->pages)
return -ENOMEM;
return 0;
}
static int ttm_dma_tt_alloc_page_directory(struct ttm_tt *ttm)
{
ttm->pages = kvcalloc(ttm->num_pages, sizeof(*ttm->pages) +
sizeof(*ttm->dma_address), GFP_KERNEL);
if (!ttm->pages)
return -ENOMEM;
ttm->dma_address = (void *)(ttm->pages + ttm->num_pages);
return 0;
}
static int ttm_sg_tt_alloc_page_directory(struct ttm_tt *ttm)
{
ttm->dma_address = kvzalloc_objs(*ttm->dma_address, ttm->num_pages);
if (!ttm->dma_address)
return -ENOMEM;
return 0;
}
void ttm_tt_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
{
bdev->funcs->ttm_tt_destroy(bdev, ttm);
}
EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_tt_destroy);
static void ttm_tt_init_fields(struct ttm_tt *ttm,
struct ttm_buffer_object *bo,
uint32_t page_flags,
enum ttm_caching caching,
unsigned long extra_pages)
{
ttm->num_pages = (PAGE_ALIGN(bo->base.size) >> PAGE_SHIFT) + extra_pages;
ttm->page_flags = page_flags;
ttm->dma_address = NULL;
ttm->swap_storage = NULL;
ttm->sg = bo->sg;
ttm->caching = caching;
ttm->restore = NULL;
ttm->backup = NULL;
}
int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
uint32_t page_flags, enum ttm_caching caching,
unsigned long extra_pages)
{
ttm_tt_init_fields(ttm, bo, page_flags, caching, extra_pages);
if (ttm_tt_alloc_page_directory(ttm)) {
pr_err("Failed allocating page table\n");
return -ENOMEM;
}
return 0;
}
EXPORT_SYMBOL(ttm_tt_init);
void ttm_tt_fini(struct ttm_tt *ttm)
{
WARN_ON(ttm->page_flags & TTM_TT_FLAG_PRIV_POPULATED);
if (ttm->swap_storage)
fput(ttm->swap_storage);
Annotation
- Immediate include surface: `linux/cc_platform.h`, `linux/debugfs.h`, `linux/export.h`, `linux/file.h`, `linux/module.h`, `linux/sched.h`, `linux/shmem_fs.h`, `drm/drm_cache.h`.
- Detected declarations: `function ttm_tt_create`, `function cc_platform_has`, `function ttm_tt_alloc_page_directory`, `function ttm_dma_tt_alloc_page_directory`, `function ttm_sg_tt_alloc_page_directory`, `function ttm_tt_destroy`, `function ttm_tt_init_fields`, `function ttm_tt_init`, `function ttm_tt_fini`, `function ttm_sg_tt_init`.
- 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.
- 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.