drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c- Extension
.c- Size
- 17149 bytes
- Lines
- 615
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
amdgpu.hamdgpu_display.hamdgpu_gem.hamdgpu_dma_buf.hamdgpu_xgmi.hamdgpu_vm.hamdgpu_ttm.hdrm/amdgpu_drm.hdrm/ttm/ttm_tt.hlinux/dma-buf.hlinux/dma-fence-array.hlinux/pci-p2pdma.h
Detected Declarations
function amdgpu_dma_buf_attachfunction amdgpu_dma_buf_pinfunction amdgpu_dma_buf_unpinfunction amdgpu_dma_buf_unmapfunction amdgpu_dma_buf_begin_cpu_accessfunction amdgpu_dma_buf_vmapfunction amdgpu_dma_buf_vunmapfunction amdgpu_dma_buf_create_objfunction amdgpu_dma_buf_move_notifyfunction amdgpu_dmabuf_is_xgmi_accessible
Annotated Snippet
if (ticket) {
/* When we get an error here it means that somebody
* else is holding the VM lock and updating page tables
* So we can just continue here.
*/
r = dma_resv_lock(resv, ticket);
if (r)
continue;
} else {
/* TODO: This is more problematic and we actually need
* to allow page tables updates without holding the
* lock.
*/
if (!dma_resv_trylock(resv))
continue;
}
/* Reserve fences for two SDMA page table updates */
r = dma_resv_reserve_fences(resv, 2);
if (!r)
r = amdgpu_vm_clear_freed(adev, vm, NULL);
/* Don't pass 'ticket' to amdgpu_vm_handle_moved: we want the clear=true
* path to be used otherwise we might update the PT of another process
* while it's using the BO.
* With clear=true, amdgpu_vm_bo_update will sync to command submission
* from the same VM.
*/
if (!r)
r = amdgpu_vm_handle_moved(adev, vm, NULL);
if (r && r != -EBUSY)
DRM_ERROR("Failed to invalidate VM page tables (%d))\n",
r);
dma_resv_unlock(resv);
}
}
static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops = {
.allow_peer2peer = true,
.invalidate_mappings = amdgpu_dma_buf_move_notify
};
/**
* amdgpu_gem_prime_import - &drm_driver.gem_prime_import implementation
* @dev: DRM device
* @dma_buf: Shared DMA buffer
*
* Import a dma_buf into a the driver and potentially create a new GEM object.
*
* Returns:
* GEM BO representing the shared DMA buffer for the given device.
*/
struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
struct dma_buf *dma_buf)
{
struct dma_buf_attachment *attach;
struct drm_gem_object *obj;
if (dma_buf->ops == &amdgpu_dmabuf_ops) {
obj = dma_buf->priv;
if (obj->dev == dev) {
/*
* Importing dmabuf exported from out own gem increases
* refcount on gem itself instead of f_count of dmabuf.
*/
drm_gem_object_get(obj);
return obj;
}
}
obj = amdgpu_dma_buf_create_obj(dev, dma_buf);
if (IS_ERR(obj))
return obj;
attach = dma_buf_dynamic_attach(dma_buf, dev->dev,
&amdgpu_dma_buf_attach_ops, obj);
if (IS_ERR(attach)) {
drm_gem_object_put(obj);
return ERR_CAST(attach);
}
get_dma_buf(dma_buf);
obj->import_attach = attach;
return obj;
}
/**
Annotation
- Immediate include surface: `amdgpu.h`, `amdgpu_display.h`, `amdgpu_gem.h`, `amdgpu_dma_buf.h`, `amdgpu_xgmi.h`, `amdgpu_vm.h`, `amdgpu_ttm.h`, `drm/amdgpu_drm.h`.
- Detected declarations: `function amdgpu_dma_buf_attach`, `function amdgpu_dma_buf_pin`, `function amdgpu_dma_buf_unpin`, `function amdgpu_dma_buf_unmap`, `function amdgpu_dma_buf_begin_cpu_access`, `function amdgpu_dma_buf_vmap`, `function amdgpu_dma_buf_vunmap`, `function amdgpu_dma_buf_create_obj`, `function amdgpu_dma_buf_move_notify`, `function amdgpu_dmabuf_is_xgmi_accessible`.
- 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.
- 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.