Skip to content

Commit

Permalink
drm/gpuvm: Add drm_gpuvm_bo_unmap()
Browse files Browse the repository at this point in the history
Analogous to drm_gpuvm_bo_unmap_ops_create, this is a callback-driven
unmap function for a given BO.

Signed-off-by: Asahi Lina <lina@asahilina.net>
  • Loading branch information
asahilina authored and jannau committed Dec 21, 2024
1 parent 44de788 commit 5c59860
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions drivers/gpu/drm/drm_gpuvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,49 @@ drm_gpuvm_prefetch_ops_create(struct drm_gpuvm *gpuvm,
}
EXPORT_SYMBOL_GPL(drm_gpuvm_prefetch_ops_create);

/**
* drm_gpuvm_bo_unmap() - unmaps a GEM
* @vm_bo: the &drm_gpuvm_bo abstraction
*
* This function calls the unmap callback for every GPUVA attached to a GEM.
*
* It is the callers responsibility to protect the GEMs GPUVA list against
* concurrent access using the GEMs dma_resv lock.
*
* Returns: a pointer to the &drm_gpuva_ops on success, an ERR_PTR on failure
*/
int
drm_gpuvm_bo_unmap(struct drm_gpuvm_bo *vm_bo, void *priv)
{
struct drm_gpuva_op *op;
int ret;

if (unlikely(!vm_bo->vm))
return -EINVAL;

const struct drm_gpuvm_ops *vm_ops = vm_bo->vm->ops;

if (unlikely(!(vm_ops && vm_ops->sm_step_unmap)))
return -EINVAL;

struct drm_gpuva_ops *ops = drm_gpuvm_bo_unmap_ops_create(vm_bo);
if (IS_ERR(ops))
return PTR_ERR(ops);

drm_gpuva_for_each_op(op, ops) {
drm_WARN_ON(vm_bo->vm->drm, op->op != DRM_GPUVA_OP_UNMAP);

ret = op_unmap_cb(vm_ops, priv, op->unmap.va, false);
if (ret)
goto cleanup;
}

cleanup:
drm_gpuva_ops_free(vm_bo->vm, ops);
return ret;
}
EXPORT_SYMBOL_GPL(drm_gpuvm_bo_unmap);

/**
* drm_gpuvm_bo_unmap_ops_create() - creates the &drm_gpuva_ops to unmap a GEM
* @vm_bo: the &drm_gpuvm_bo abstraction
Expand Down
1 change: 1 addition & 0 deletions include/drm/drm_gpuvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ int drm_gpuvm_sm_map(struct drm_gpuvm *gpuvm, void *priv,

int drm_gpuvm_sm_unmap(struct drm_gpuvm *gpuvm, void *priv,
u64 addr, u64 range);
int drm_gpuvm_bo_unmap(struct drm_gpuvm_bo *bo, void *priv);

void drm_gpuva_map(struct drm_gpuvm *gpuvm,
struct drm_gpuva *va,
Expand Down

0 comments on commit 5c59860

Please sign in to comment.