drivers/gpu/drm/radeon/radeon_ttm.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/radeon/radeon_ttm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/radeon/radeon_ttm.c- Extension
.c- Size
- 23438 bytes
- Lines
- 911
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/debugfs.hlinux/dma-mapping.hlinux/pagemap.hlinux/pci.hlinux/seq_file.hlinux/slab.hlinux/swap.hdrm/drm_device.hdrm/drm_file.hdrm/drm_prime.hdrm/radeon_drm.hdrm/ttm/ttm_bo.hdrm/ttm/ttm_placement.hdrm/ttm/ttm_range_manager.hdrm/ttm/ttm_tt.hradeon_reg.hradeon.hradeon_ttm.h
Detected Declarations
struct radeon_ttm_ttfunction radeon_ttm_init_vramfunction radeon_ttm_init_gttfunction radeon_evict_flagsfunction radeon_move_blitfunction radeon_bo_movefunction radeon_ttm_io_mem_reservefunction radeon_ttm_tt_pin_userptrfunction radeon_ttm_tt_unpin_userptrfunction for_each_sgtable_pagefunction radeon_ttm_backend_is_boundfunction radeon_ttm_backend_bindfunction radeon_ttm_backend_unbindfunction radeon_ttm_backend_destroyfunction radeon_ttm_tt_populatefunction radeon_ttm_tt_unpopulatefunction radeon_ttm_tt_set_userptrfunction radeon_ttm_tt_is_boundfunction radeon_ttm_tt_bindfunction radeon_ttm_tt_unbindfunction radeon_ttm_tt_destroyfunction radeon_ttm_tt_has_userptrfunction radeon_ttm_tt_is_readonlyfunction radeon_ttm_initfunction radeon_ttm_finifunction radeon_ttm_set_active_vram_sizefunction radeon_ttm_page_pool_showfunction radeon_ttm_vram_openfunction radeon_ttm_vram_readfunction radeon_ttm_gtt_openfunction radeon_ttm_gtt_readfunction radeon_ttm_debugfs_init
Annotated Snippet
static const struct file_operations radeon_ttm_vram_fops = {
.owner = THIS_MODULE,
.open = radeon_ttm_vram_open,
.read = radeon_ttm_vram_read,
.llseek = default_llseek
};
static int radeon_ttm_gtt_open(struct inode *inode, struct file *filep)
{
struct radeon_device *rdev = inode->i_private;
i_size_write(inode, rdev->mc.gtt_size);
filep->private_data = inode->i_private;
return 0;
}
static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
size_t size, loff_t *pos)
{
struct radeon_device *rdev = f->private_data;
ssize_t result = 0;
int r;
while (size) {
loff_t p = *pos / PAGE_SIZE;
unsigned off = *pos & ~PAGE_MASK;
size_t cur_size = min_t(size_t, size, PAGE_SIZE - off);
struct page *page;
void *ptr;
if (p >= rdev->gart.num_cpu_pages)
return result;
page = rdev->gart.pages[p];
if (page) {
ptr = kmap_local_page(page);
ptr += off;
r = copy_to_user(buf, ptr, cur_size);
kunmap_local(ptr);
} else
r = clear_user(buf, cur_size);
if (r)
return -EFAULT;
result += cur_size;
buf += cur_size;
*pos += cur_size;
size -= cur_size;
}
return result;
}
static const struct file_operations radeon_ttm_gtt_fops = {
.owner = THIS_MODULE,
.open = radeon_ttm_gtt_open,
.read = radeon_ttm_gtt_read,
.llseek = default_llseek
};
#endif
static void radeon_ttm_debugfs_init(struct radeon_device *rdev)
{
#if defined(CONFIG_DEBUG_FS)
struct drm_minor *minor = rdev_to_drm(rdev)->primary;
struct dentry *root = minor->debugfs_root;
debugfs_create_file("radeon_vram", 0444, root, rdev,
&radeon_ttm_vram_fops);
debugfs_create_file("radeon_gtt", 0444, root, rdev,
&radeon_ttm_gtt_fops);
debugfs_create_file("ttm_page_pool", 0444, root, rdev,
&radeon_ttm_page_pool_fops);
ttm_resource_manager_create_debugfs(ttm_manager_type(&rdev->mman.bdev,
TTM_PL_VRAM),
root, "radeon_vram_mm");
ttm_resource_manager_create_debugfs(ttm_manager_type(&rdev->mman.bdev,
TTM_PL_TT),
root, "radeon_gtt_mm");
#endif
}
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/dma-mapping.h`, `linux/pagemap.h`, `linux/pci.h`, `linux/seq_file.h`, `linux/slab.h`, `linux/swap.h`, `drm/drm_device.h`.
- Detected declarations: `struct radeon_ttm_tt`, `function radeon_ttm_init_vram`, `function radeon_ttm_init_gtt`, `function radeon_evict_flags`, `function radeon_move_blit`, `function radeon_bo_move`, `function radeon_ttm_io_mem_reserve`, `function radeon_ttm_tt_pin_userptr`, `function radeon_ttm_tt_unpin_userptr`, `function for_each_sgtable_page`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.