drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c- Extension
.c- Size
- 84980 bytes
- Lines
- 3202
- 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.
- 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.
- 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/dma-fence-array.hlinux/interval_tree_generic.hlinux/idr.hlinux/dma-buf.hdrm/amdgpu_drm.hdrm/drm_drv.hdrm/ttm/ttm_tt.hdrm/drm_exec.hamdgpu.hamdgpu_vm.hamdgpu_trace.hamdgpu_amdkfd.hamdgpu_gmc.hamdgpu_xgmi.hamdgpu_dma_buf.hamdgpu_res_cursor.hkfd_svm.h
Detected Declarations
struct amdgpu_prt_cbstruct amdgpu_vm_tlb_seq_structfunction amdgpu_vm_assert_lockedfunction amdgpu_vm_bo_status_initfunction amdgpu_vm_bo_lock_listsfunction amdgpu_vm_bo_unlock_listsfunction amdgpu_vm_is_bo_always_validfunction amdgpu_vm_bo_evictedfunction amdgpu_vm_bo_movedfunction amdgpu_vm_bo_idlefunction amdgpu_vm_bo_reset_state_machinefunction changedfunction amdgpu_vm_bo_update_sharedfunction amdgpu_vm_update_stats_lockedfunction amdgpu_vm_update_statsfunction amdgpu_vm_bo_base_initfunction amdgpu_vm_lock_pdfunction amdgpu_vm_lock_individualfunction amdgpu_vm_move_to_lru_tailfunction amdgpu_vm_init_entitiesfunction amdgpu_vm_fini_entitiesfunction amdgpu_vm_generationfunction amdgpu_vm_validatefunction list_for_each_entry_safefunction list_for_each_entry_safefunction amdgpu_vm_readyfunction amdgpu_vm_check_compute_bugfunction amdgpu_vm_need_pipeline_syncfunction amdgpu_vm_flushfunction amdgpu_vm_map_gartfunction amdgpu_vm_update_pdesfunction list_for_each_entryfunction amdgpu_vm_tlb_seq_cbfunction amdgpu_vm_tlb_flushfunction amdgpu_vm_update_rangefunction amdgpu_vm_get_memoryfunction amdgpu_vm_bo_updatefunction list_for_each_entryfunction amdgpu_vm_update_prt_statefunction amdgpu_vm_prt_getfunction amdgpu_vm_prt_putfunction amdgpu_vm_prt_cbfunction amdgpu_vm_add_prt_cbfunction amdgpu_vm_free_mappingfunction amdgpu_vm_prt_finifunction dma_resv_for_each_fencefunction amdgpu_vm_clear_freedfunction amdgpu_vm_handle_moved
Annotated Snippet
struct amdgpu_prt_cb {
/**
* @adev: amdgpu device
*/
struct amdgpu_device *adev;
/**
* @cb: callback
*/
struct dma_fence_cb cb;
};
/**
* struct amdgpu_vm_tlb_seq_struct - Helper to increment the TLB flush sequence
*/
struct amdgpu_vm_tlb_seq_struct {
/**
* @vm: pointer to the amdgpu_vm structure to set the fence sequence on
*/
struct amdgpu_vm *vm;
/**
* @cb: callback
*/
struct dma_fence_cb cb;
};
/**
* amdgpu_vm_assert_locked - check if VM is correctly locked
* @vm: the VM which schould be tested
*
* Asserts that the VM root PD is locked.
*/
static void amdgpu_vm_assert_locked(struct amdgpu_vm *vm)
{
dma_resv_assert_held(vm->root.bo->tbo.base.resv);
}
/* Initialize the amdgpu_vm_bo_status object */
static void amdgpu_vm_bo_status_init(struct amdgpu_vm_bo_status *lists)
{
INIT_LIST_HEAD(&lists->evicted);
INIT_LIST_HEAD(&lists->moved);
INIT_LIST_HEAD(&lists->idle);
}
/*
* Make sure we have the lock to modify the vm_bo status and return the object
* with the status lists.
*/
static struct amdgpu_vm_bo_status *
amdgpu_vm_bo_lock_lists(struct amdgpu_vm_bo_base *vm_bo)
{
struct amdgpu_vm *vm = vm_bo->vm;
struct amdgpu_bo *bo = vm_bo->bo;
if (amdgpu_vm_is_bo_always_valid(vm, bo)) {
/* No extra locking needed, protected by the root PD resv lock */
amdgpu_vm_assert_locked(vm);
if (bo->tbo.type == ttm_bo_type_kernel)
return &vm->kernel;
return &vm->always_valid;
}
spin_lock(&vm_bo->vm->individual_lock);
return &vm->individual;
}
/* Eventually unlock the status list lock again */
static void amdgpu_vm_bo_unlock_lists(struct amdgpu_vm_bo_base *vm_bo)
{
if (amdgpu_vm_is_bo_always_valid(vm_bo->vm, vm_bo->bo))
amdgpu_vm_assert_locked(vm_bo->vm);
else
spin_unlock(&vm_bo->vm->individual_lock);
}
/**
* amdgpu_vm_is_bo_always_valid - check if the BO is VM always valid
*
* @vm: VM to test against.
* @bo: BO to be tested.
*
* Returns true if the BO shares the dma_resv object with the root PD and is
* always guaranteed to be valid inside the VM.
*/
bool amdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo)
Annotation
- Immediate include surface: `linux/dma-fence-array.h`, `linux/interval_tree_generic.h`, `linux/idr.h`, `linux/dma-buf.h`, `drm/amdgpu_drm.h`, `drm/drm_drv.h`, `drm/ttm/ttm_tt.h`, `drm/drm_exec.h`.
- Detected declarations: `struct amdgpu_prt_cb`, `struct amdgpu_vm_tlb_seq_struct`, `function amdgpu_vm_assert_locked`, `function amdgpu_vm_bo_status_init`, `function amdgpu_vm_bo_lock_lists`, `function amdgpu_vm_bo_unlock_lists`, `function amdgpu_vm_is_bo_always_valid`, `function amdgpu_vm_bo_evicted`, `function amdgpu_vm_bo_moved`, `function amdgpu_vm_bo_idle`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.
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.