drivers/accel/ivpu/ivpu_gem.c
Source file repositories/reference/linux-study-clean/drivers/accel/ivpu/ivpu_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/ivpu/ivpu_gem.c- Extension
.c- Size
- 14265 bytes
- Lines
- 580
- 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.
- 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-buf.hlinux/highmem.hlinux/module.hlinux/set_memory.hlinux/xarray.hdrm/drm_cache.hdrm/drm_debugfs.hdrm/drm_file.hdrm/drm_utils.hivpu_drv.hivpu_fw.hivpu_gem.hivpu_hw.hivpu_mmu.hivpu_mmu_context.h
Detected Declarations
function ivpu_dbg_bofunction ivpu_bo_lockfunction ivpu_bo_unlockfunction ivpu_bo_bindfunction ivpu_bo_alloc_vpu_addrfunction ivpu_bo_unbind_lockedfunction ivpu_bo_unbind_all_bos_from_contextfunction ivpu_gem_bo_openfunction ivpu_gem_bo_freefunction ivpu_gem_statusfunction ivpu_bo_create_ioctlfunction ivpu_bo_createfunction ivpu_bo_freefunction ivpu_bo_info_ioctlfunction ivpu_bo_wait_ioctlfunction ivpu_bo_print_infofunction ivpu_bo_listfunction ivpu_bo_list_print
Annotated Snippet
if (ret) {
ivpu_err(vdev, "Failed to map BO in MMU: %d\n", ret);
goto unlock;
}
bo->mmu_mapped = true;
}
unlock:
ivpu_bo_unlock(bo);
return ret;
}
static int
ivpu_bo_alloc_vpu_addr(struct ivpu_bo *bo, struct ivpu_mmu_context *ctx,
const struct ivpu_addr_range *range)
{
struct ivpu_device *vdev = ivpu_bo_to_vdev(bo);
int idx, ret;
if (!drm_dev_enter(&vdev->drm, &idx))
return -ENODEV;
ivpu_bo_lock(bo);
ret = ivpu_mmu_context_insert_node(ctx, range, ivpu_bo_size(bo), &bo->mm_node);
if (!ret) {
bo->ctx = ctx;
bo->ctx_id = ctx->id;
bo->vpu_addr = bo->mm_node.start;
ivpu_dbg_bo(vdev, bo, "vaddr");
}
ivpu_bo_unlock(bo);
drm_dev_exit(idx);
return ret;
}
static void ivpu_bo_unbind_locked(struct ivpu_bo *bo)
{
struct ivpu_device *vdev = ivpu_bo_to_vdev(bo);
dma_resv_assert_held(bo->base.base.resv);
if (bo->mmu_mapped) {
drm_WARN_ON(&vdev->drm, !bo->ctx);
drm_WARN_ON(&vdev->drm, !bo->vpu_addr);
drm_WARN_ON(&vdev->drm, !bo->base.sgt);
ivpu_mmu_context_unmap_sgt(vdev, bo->ctx, bo->vpu_addr, bo->base.sgt);
bo->mmu_mapped = false;
}
if (bo->ctx) {
ivpu_mmu_context_remove_node(bo->ctx, &bo->mm_node);
bo->ctx = NULL;
}
if (bo->base.sgt) {
if (drm_gem_is_imported(&bo->base.base)) {
dma_buf_unmap_attachment(bo->base.base.import_attach,
bo->base.sgt, DMA_BIDIRECTIONAL);
} else {
dma_unmap_sgtable(vdev->drm.dev, bo->base.sgt, DMA_BIDIRECTIONAL, 0);
sg_free_table(bo->base.sgt);
kfree(bo->base.sgt);
}
bo->base.sgt = NULL;
}
}
void ivpu_bo_unbind_all_bos_from_context(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx)
{
struct ivpu_bo *bo;
if (drm_WARN_ON(&vdev->drm, !ctx))
return;
mutex_lock(&vdev->bo_list_lock);
list_for_each_entry(bo, &vdev->bo_list, bo_list_node) {
ivpu_bo_lock(bo);
if (bo->ctx == ctx) {
ivpu_dbg_bo(vdev, bo, "unbind");
ivpu_bo_unbind_locked(bo);
}
ivpu_bo_unlock(bo);
}
mutex_unlock(&vdev->bo_list_lock);
}
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/highmem.h`, `linux/module.h`, `linux/set_memory.h`, `linux/xarray.h`, `drm/drm_cache.h`, `drm/drm_debugfs.h`, `drm/drm_file.h`.
- Detected declarations: `function ivpu_dbg_bo`, `function ivpu_bo_lock`, `function ivpu_bo_unlock`, `function ivpu_bo_bind`, `function ivpu_bo_alloc_vpu_addr`, `function ivpu_bo_unbind_locked`, `function ivpu_bo_unbind_all_bos_from_context`, `function ivpu_gem_bo_open`, `function ivpu_gem_bo_free`, `function ivpu_gem_status`.
- Atlas domain: Driver Families / drivers/accel.
- Implementation status: source implementation candidate.
- 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.