drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c- Extension
.c- Size
- 10477 bytes
- Lines
- 375
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
drm/ttm/ttm_range_manager.hamdgpu.h
Detected Declarations
function filesfunction amdgpu_mem_info_gtt_total_showfunction amdgpu_mem_info_gtt_used_showfunction amdgpu_gtt_mgr_has_gart_addrfunction amdgpu_gtt_mgr_newfunction ttm_resource_manager_usagefunction amdgpu_gtt_mgr_delfunction amdgpu_gtt_mgr_alloc_entriesfunction amdgpu_gtt_mgr_free_entriesfunction amdgpu_gtt_mgr_recoverfunction amdgpu_gtt_mgr_intersectsfunction amdgpu_gtt_mgr_compatiblefunction amdgpu_gtt_mgr_debugfunction amdgpu_gtt_mgr_initfunction amdgpu_gtt_mgr_fini
Annotated Snippet
ttm_resource_manager_usage(man) > man->size) {
r = -ENOSPC;
goto err_free;
}
if (place->lpfn) {
spin_lock(&mgr->lock);
r = drm_mm_insert_node_in_range(&mgr->mm, &node->mm_nodes[0],
num_pages, tbo->page_alignment,
0, place->fpfn, place->lpfn,
DRM_MM_INSERT_BEST);
spin_unlock(&mgr->lock);
if (unlikely(r))
goto err_free;
node->base.start = node->mm_nodes[0].start;
} else {
node->mm_nodes[0].start = 0;
node->mm_nodes[0].size = PFN_UP(node->base.size);
node->base.start = AMDGPU_BO_INVALID_OFFSET;
}
*res = &node->base;
return 0;
err_free:
ttm_resource_fini(man, &node->base);
kfree(node);
return r;
}
/**
* amdgpu_gtt_mgr_del - free ranges
*
* @man: TTM memory type manager
* @res: TTM memory object
*
* Free the allocated GTT again.
*/
static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,
struct ttm_resource *res)
{
struct ttm_range_mgr_node *node = to_ttm_range_mgr_node(res);
struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
spin_lock(&mgr->lock);
if (drm_mm_node_allocated(&node->mm_nodes[0]))
drm_mm_remove_node(&node->mm_nodes[0]);
spin_unlock(&mgr->lock);
ttm_resource_fini(man, res);
kfree(node);
}
/**
* amdgpu_gtt_mgr_alloc_entries - alloc GART entries without GTT bo
*
* @mgr: The GTT manager object
* @mm_node: The drm mm node to return the new allocation node information
* @num_pages: The number of pages for the new allocation
* @mode: The new allocation mode
*
* Helper to dynamic alloc GART entries to map memory not accociated with
* GTT BO, for example VRAM BO physical memory, remote physical memory.
*/
int amdgpu_gtt_mgr_alloc_entries(struct amdgpu_gtt_mgr *mgr,
struct drm_mm_node *mm_node,
u64 num_pages,
enum drm_mm_insert_mode mode)
{
struct amdgpu_device *adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);
u32 alignment = 0;
int r;
/* Align to TLB L2 cache entry size to work around "V bit HW bug" */
if (adev->family == AMDGPU_FAMILY_SI) {
alignment = 32 * 1024 / AMDGPU_GPU_PAGE_SIZE;
num_pages = ALIGN(num_pages, alignment);
}
spin_lock(&mgr->lock);
r = drm_mm_insert_node_in_range(&mgr->mm, mm_node, num_pages,
alignment, GART_ENTRY_WITHOUT_BO_COLOR, 0,
adev->gmc.gart_size >> PAGE_SHIFT,
mode);
spin_unlock(&mgr->lock);
return r;
}
/**
Annotation
- Immediate include surface: `drm/ttm/ttm_range_manager.h`, `amdgpu.h`.
- Detected declarations: `function files`, `function amdgpu_mem_info_gtt_total_show`, `function amdgpu_mem_info_gtt_used_show`, `function amdgpu_gtt_mgr_has_gart_addr`, `function amdgpu_gtt_mgr_new`, `function ttm_resource_manager_usage`, `function amdgpu_gtt_mgr_del`, `function amdgpu_gtt_mgr_alloc_entries`, `function amdgpu_gtt_mgr_free_entries`, `function amdgpu_gtt_mgr_recover`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.