drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c- Extension
.c- Size
- 36578 bytes
- Lines
- 1367
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ktime.hlinux/module.hlinux/overflow.hlinux/pagemap.hlinux/pci.hlinux/dma-buf.hlinux/dma-fence-unwrap.hlinux/uaccess.hdrm/amdgpu_drm.hdrm/drm_drv.hdrm/drm_exec.hdrm/drm_gem_ttm_helper.hdrm/ttm/ttm_tt.hdrm/drm_syncobj.hamdgpu.hamdgpu_display.hamdgpu_dma_buf.hamdgpu_hmm.hamdgpu_xgmi.hamdgpu_vm.h
Detected Declarations
function filesfunction amdgpu_gem_update_timeline_nodefunction amdgpu_gem_faultfunction amdgpu_gem_object_freefunction amdgpu_gem_object_createfunction amdgpu_gem_force_releasefunction list_for_each_entryfunction idr_for_each_entryfunction amdgpu_gem_object_openfunction amdgpu_gem_object_closefunction amdgpu_gem_object_mmapfunction amdgpu_gem_create_ioctlfunction amdgpu_gem_userptr_ioctlfunction amdgpu_mode_dumb_mmapfunction amdgpu_gem_mmap_ioctlfunction amdgpu_gem_timeoutfunction amdgpu_gem_wait_idle_ioctlfunction amdgpu_gem_metadata_ioctlfunction BOfunction amdgpu_gem_va_ioctlfunction amdgpu_gem_op_ioctlfunction amdgpu_vm_bo_va_for_each_valid_mappingfunction amdgpu_vm_bo_va_for_each_invalid_mappingfunction amdgpu_gem_list_handles_ioctlfunction amdgpu_gem_align_pitchfunction amdgpu_mode_dumb_createfunction amdgpu_debugfs_gem_info_showfunction list_for_each_entryfunction idr_for_each_entryfunction amdgpu_debugfs_gem_init
Annotated Snippet
if (!syncobj_handles[i]) {
ret = -EINVAL;
goto free_memdup;
}
ret = drm_syncobj_find_fence(filp, syncobj_handles[i], 0, 0, &fence);
if (ret)
goto free_memdup;
dma_fence_wait(fence, false);
/* TODO: optimize async handling */
dma_fence_put(fence);
}
free_memdup:
kfree(syncobj_handles);
return ret;
}
static int
amdgpu_gem_update_timeline_node(struct drm_file *filp,
uint32_t syncobj_handle,
uint64_t point,
struct drm_syncobj **syncobj,
struct dma_fence_chain **chain)
{
if (!syncobj_handle)
return 0;
/* Find the sync object */
*syncobj = drm_syncobj_find(filp, syncobj_handle);
if (!*syncobj)
return -ENOENT;
if (!point)
return 0;
/* Allocate the chain node */
*chain = dma_fence_chain_alloc();
if (!*chain) {
drm_syncobj_put(*syncobj);
*syncobj = NULL;
return -ENOMEM;
}
return 0;
}
static vm_fault_t amdgpu_gem_fault(struct vm_fault *vmf)
{
struct ttm_buffer_object *bo = vmf->vma->vm_private_data;
struct drm_device *ddev = bo->base.dev;
vm_fault_t ret;
int idx;
ret = ttm_bo_vm_reserve(bo, vmf);
if (ret)
return ret;
if (drm_dev_enter(ddev, &idx)) {
ret = amdgpu_bo_fault_reserve_notify(bo);
if (ret) {
drm_dev_exit(idx);
goto unlock;
}
ret = ttm_bo_vm_fault_reserved(vmf, vmf->vma->vm_page_prot,
TTM_BO_VM_NUM_PREFAULT);
drm_dev_exit(idx);
} else {
ret = ttm_bo_vm_dummy_page(vmf, vmf->vma->vm_page_prot);
}
if (ret == VM_FAULT_RETRY && !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT))
return ret;
unlock:
dma_resv_unlock(bo->base.resv);
return ret;
}
static const struct vm_operations_struct amdgpu_gem_vm_ops = {
.fault = amdgpu_gem_fault,
.open = ttm_bo_vm_open,
.close = ttm_bo_vm_close,
.access = ttm_bo_vm_access
};
static void amdgpu_gem_object_free(struct drm_gem_object *gobj)
Annotation
- Immediate include surface: `linux/ktime.h`, `linux/module.h`, `linux/overflow.h`, `linux/pagemap.h`, `linux/pci.h`, `linux/dma-buf.h`, `linux/dma-fence-unwrap.h`, `linux/uaccess.h`.
- Detected declarations: `function files`, `function amdgpu_gem_update_timeline_node`, `function amdgpu_gem_fault`, `function amdgpu_gem_object_free`, `function amdgpu_gem_object_create`, `function amdgpu_gem_force_release`, `function list_for_each_entry`, `function idr_for_each_entry`, `function amdgpu_gem_object_open`, `function amdgpu_gem_object_close`.
- 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.