drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c- Extension
.c- Size
- 29771 bytes
- Lines
- 1087
- 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.
- 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/types.hlinux/dma-direction.hlinux/dma-mapping.hlinux/migrate.hamdgpu_sync.hamdgpu_object.hamdgpu_vm.hamdgpu_res_cursor.hkfd_priv.hkfd_svm.hkfd_migrate.hkfd_smi_events.h
Detected Declarations
function filesfunction svm_migrate_gart_mapfunction svm_migrate_copy_memory_gartfunction svm_migrate_copy_donefunction svm_migrate_addr_to_pfnfunction svm_migrate_get_vram_pagefunction svm_migrate_put_vram_pagefunction svm_migrate_addrfunction svm_migrate_get_sys_pagefunction svm_migrate_put_sys_pagefunction svm_migrate_successful_pagesfunction svm_migrate_copy_to_vramfunction svm_migrate_vma_to_vramfunction svm_migrate_ram_to_vramfunction svm_migrate_folio_freefunction svm_migrate_copy_to_ramfunction svm_migrate_vma_to_ramfunction svm_migrate_vram_to_ramfunction svm_migrate_vram_to_vramfunction svm_migrate_to_vramfunction svm_migrate_to_ramfunction kgd2kfd_init_zone_device
Annotated Snippet
if (direction == FROM_VRAM_TO_RAM) {
gart_s = svm_migrate_direct_mapping_addr(adev, *vram);
r = svm_migrate_gart_map(ring, entity, size, sys, &gart_d, 0);
} else if (direction == FROM_RAM_TO_VRAM) {
r = svm_migrate_gart_map(ring, entity, size, sys, &gart_s,
KFD_IOCTL_SVM_FLAG_GPU_RO);
gart_d = svm_migrate_direct_mapping_addr(adev, *vram);
}
if (r) {
dev_err(adev->dev, "fail %d create gart mapping\n", r);
goto out_unlock;
}
r = amdgpu_copy_buffer(adev, entity,
gart_s, gart_d, size * PAGE_SIZE,
NULL, &next, true, 0);
if (r) {
dev_err(adev->dev, "fail %d to copy memory\n", r);
goto out_unlock;
}
dma_fence_put(*mfence);
*mfence = next;
npages -= size;
if (npages) {
sys += size;
vram += size;
}
}
out_unlock:
mutex_unlock(&entity->lock);
return r;
}
/**
* svm_migrate_copy_done - wait for memory copy sdma is done
*
* @adev: amdgpu device the sdma memory copy is executing on
* @mfence: migrate fence
*
* Wait for dma fence is signaled, if the copy ssplit into multiple sdma
* operations, this is the last sdma operation fence.
*
* Context: called after svm_migrate_copy_memory
*
* Return:
* 0 - success
* otherwise - error code from dma fence signal
*/
static int
svm_migrate_copy_done(struct amdgpu_device *adev, struct dma_fence *mfence)
{
int r = 0;
if (mfence) {
r = dma_fence_wait(mfence, false);
dma_fence_put(mfence);
pr_debug("sdma copy memory fence done\n");
}
return r;
}
unsigned long
svm_migrate_addr_to_pfn(struct amdgpu_device *adev, unsigned long addr)
{
return (addr + adev->kfd.pgmap.range.start) >> PAGE_SHIFT;
}
static void
svm_migrate_get_vram_page(struct svm_range *prange, unsigned long pfn)
{
struct page *page;
page = pfn_to_page(pfn);
svm_range_bo_ref(prange->svm_bo);
page->zone_device_data = prange->svm_bo;
zone_device_page_init(page, page_pgmap(page), 0);
}
static void
svm_migrate_put_vram_page(struct amdgpu_device *adev, unsigned long addr)
{
struct page *page;
page = pfn_to_page(svm_migrate_addr_to_pfn(adev, addr));
unlock_page(page);
Annotation
- Immediate include surface: `linux/types.h`, `linux/dma-direction.h`, `linux/dma-mapping.h`, `linux/migrate.h`, `amdgpu_sync.h`, `amdgpu_object.h`, `amdgpu_vm.h`, `amdgpu_res_cursor.h`.
- Detected declarations: `function files`, `function svm_migrate_gart_map`, `function svm_migrate_copy_memory_gart`, `function svm_migrate_copy_done`, `function svm_migrate_addr_to_pfn`, `function svm_migrate_get_vram_page`, `function svm_migrate_put_vram_page`, `function svm_migrate_addr`, `function svm_migrate_get_sys_page`, `function svm_migrate_put_sys_page`.
- 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.
- 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.