drivers/accel/amdxdna/amdxdna_gem.c
Source file repositories/reference/linux-study-clean/drivers/accel/amdxdna/amdxdna_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/amdxdna/amdxdna_gem.c- Extension
.c- Size
- 33271 bytes
- Lines
- 1349
- Domain
- Driver Families
- Bucket
- drivers/accel
- 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.
- 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
drm/amdxdna_accel.hdrm/drm_cache.hdrm/drm_device.hdrm/drm_gem.hdrm/drm_gem_shmem_helper.hdrm/drm_print.hdrm/gpu_scheduler.hlinux/dma-buf.hlinux/dma-direct.hlinux/iosys-map.hlinux/pagemap.hlinux/vmalloc.hamdxdna_cbuf.hamdxdna_ctx.hamdxdna_gem.hamdxdna_pci_drv.hamdxdna_ubuf.h
Detected Declarations
function amdxdna_init_dev_bofunction amdxdna_gem_heap_allocfunction amdxdna_gem_heap_freefunction amdxdna_gem_create_objfunction amdxdna_gem_destroy_objfunction BOfunction amdxdna_gem_vmapfunction amdxdna_gem_dev_addrfunction amdxdna_hmm_invalidatefunction amdxdna_hmm_unregisterfunction amdxdna_umap_releasefunction amdxdna_umap_putfunction amdxdna_hmm_unreg_workfunction amdxdna_hmm_registerfunction amdxdna_gem_dev_obj_freefunction amdxdna_insert_pagesfunction amdxdna_gem_obj_mmapfunction amdxdna_gem_dmabuf_mmapfunction amdxdna_imported_obj_freefunction amdxdna_gem_skip_bo_usagefunction amdxdna_gem_add_bo_usagefunction amdxdna_gem_del_bo_usagefunction amdxdna_gem_obj_freefunction amdxdna_gem_obj_openfunction amdxdna_gem_obj_closefunction amdxdna_gem_obj_vmapfunction amdxdna_gem_obj_vunmapfunction amdxdna_gem_dev_obj_vmapfunction amdxdna_gem_create_shmem_object_cbfunction amdxdna_gem_create_shmem_objectfunction amdxdna_gem_create_ubuf_objectfunction amdxdna_gem_create_cbuf_objectfunction amdxdna_gem_prime_importfunction amdxdna_drm_create_share_bofunction amdxdna_drm_create_dev_heap_bofunction amdxdna_drm_create_dev_bofunction amdxdna_drm_create_bo_ioctlfunction amdxdna_bo_pinfunction amdxdna_bo_unpinfunction amdxdna_gem_pin_nolockfunction xa_for_each_rangefunction amdxdna_gem_pinfunction amdxdna_gem_unpinfunction amdxdna_drm_get_bo_info_ioctlfunction amdxdna_flush_bofunction amdxdna_drm_sync_bo_ioctlfunction xa_for_each_rangefunction amdxdna_drm_get_bo_usage
Annotated Snippet
fault_ret = handle_mm_fault(vma, vma->vm_start + offset,
FAULT_FLAG_WRITE, NULL);
if (fault_ret & VM_FAULT_ERROR) {
vma->vm_ops->close(vma);
XDNA_ERR(xdna, "Fault in page failed");
return -EFAULT;
}
offset += PAGE_SIZE;
} while (--num_pages);
/* Drop the reference drm_gem_mmap_obj() acquired.*/
drm_gem_object_put(to_gobj(abo));
return 0;
}
static int amdxdna_gem_obj_mmap(struct drm_gem_object *gobj,
struct vm_area_struct *vma)
{
struct amdxdna_dev *xdna = to_xdna_dev(gobj->dev);
struct amdxdna_gem_obj *abo = to_xdna_obj(gobj);
int ret;
ret = amdxdna_hmm_register(abo, vma);
if (ret)
return ret;
ret = amdxdna_insert_pages(abo, vma);
if (ret) {
XDNA_ERR(xdna, "Failed insert pages, ret %d", ret);
goto hmm_unreg;
}
XDNA_DBG(xdna, "BO map_offset 0x%llx type %d userptr 0x%lx size 0x%lx",
drm_vma_node_offset_addr(&gobj->vma_node), abo->type,
vma->vm_start, gobj->size);
return 0;
hmm_unreg:
amdxdna_hmm_unregister(abo, vma);
return ret;
}
static int amdxdna_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
{
struct drm_gem_object *gobj = dma_buf->priv;
struct amdxdna_gem_obj *abo = to_xdna_obj(gobj);
unsigned long num_pages = vma_pages(vma);
int ret;
vma->vm_ops = &drm_gem_shmem_vm_ops;
vma->vm_private_data = gobj;
drm_gem_object_get(gobj);
ret = drm_gem_shmem_mmap(&abo->base, vma);
if (ret)
goto put_obj;
/* The buffer is based on memory pages. Fix the flag. */
vm_flags_mod(vma, VM_MIXEDMAP, VM_PFNMAP);
ret = vm_insert_pages(vma, vma->vm_start, abo->base.pages,
&num_pages);
if (ret)
goto close_vma;
return 0;
close_vma:
vma->vm_ops->close(vma);
put_obj:
drm_gem_object_put(gobj);
return ret;
}
static const struct dma_buf_ops amdxdna_dmabuf_ops = {
.attach = drm_gem_map_attach,
.detach = drm_gem_map_detach,
.map_dma_buf = drm_gem_map_dma_buf,
.unmap_dma_buf = drm_gem_unmap_dma_buf,
.release = drm_gem_dmabuf_release,
.mmap = amdxdna_gem_dmabuf_mmap,
.vmap = drm_gem_dmabuf_vmap,
.vunmap = drm_gem_dmabuf_vunmap,
};
static struct dma_buf *amdxdna_gem_prime_export(struct drm_gem_object *gobj, int flags)
{
struct amdxdna_gem_obj *abo = to_xdna_obj(gobj);
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
Annotation
- Immediate include surface: `drm/amdxdna_accel.h`, `drm/drm_cache.h`, `drm/drm_device.h`, `drm/drm_gem.h`, `drm/drm_gem_shmem_helper.h`, `drm/drm_print.h`, `drm/gpu_scheduler.h`, `linux/dma-buf.h`.
- Detected declarations: `function amdxdna_init_dev_bo`, `function amdxdna_gem_heap_alloc`, `function amdxdna_gem_heap_free`, `function amdxdna_gem_create_obj`, `function amdxdna_gem_destroy_obj`, `function BO`, `function amdxdna_gem_vmap`, `function amdxdna_gem_dev_addr`, `function amdxdna_hmm_invalidate`, `function amdxdna_hmm_unregister`.
- Atlas domain: Driver Families / drivers/accel.
- 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.
- 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.