Skip to content

Commit 10566e9

Browse files
hoshinolinaherrnst
authored andcommitted
drm/gpuvm: Add drm_gpuvm_bo_unmap()
Analogous to drm_gpuvm_bo_unmap_ops_create, this is a callback-driven unmap function for a given BO. Signed-off-by: Asahi Lina <[email protected]>
1 parent c611dfa commit 10566e9

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

drivers/gpu/drm/drm_gpuvm.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,55 @@ drm_gpuvm_prefetch_ops_create(struct drm_gpuvm *gpuvm,
29282928
}
29292929
EXPORT_SYMBOL_GPL(drm_gpuvm_prefetch_ops_create);
29302930

2931+
/**
2932+
* drm_gpuvm_bo_unmap() - unmaps a GEM
2933+
* @vm_bo: the &drm_gpuvm_bo abstraction
2934+
*
2935+
* This function calls the unmap callback for every GPUVA attached to a GEM.
2936+
*
2937+
* It is the callers responsibility to protect the GEMs GPUVA list against
2938+
* concurrent access using the GEMs dma_resv lock.
2939+
*
2940+
* Returns: a pointer to the &drm_gpuva_ops on success, an ERR_PTR on failure
2941+
*/
2942+
int
2943+
drm_gpuvm_bo_unmap(struct drm_gpuvm_bo *vm_bo, void *priv)
2944+
{
2945+
struct drm_gpuva_ops *ops;
2946+
struct drm_gpuva_op *op;
2947+
int ret;
2948+
2949+
if (unlikely(!vm_bo->vm))
2950+
return -EINVAL;
2951+
2952+
const struct drm_gpuvm_ops *vm_ops = vm_bo->vm->ops;
2953+
2954+
if (unlikely(!(vm_ops && vm_ops->sm_step_unmap)))
2955+
return -EINVAL;
2956+
2957+
if (drm_gpuvm_immediate_mode(vm_bo->vm)) {
2958+
guard(mutex)(&vm_bo->obj->gpuva.lock);
2959+
ops = drm_gpuvm_bo_unmap_ops_create(vm_bo);
2960+
} else {
2961+
ops = drm_gpuvm_bo_unmap_ops_create(vm_bo);
2962+
}
2963+
if (IS_ERR(ops))
2964+
return PTR_ERR(ops);
2965+
2966+
drm_gpuva_for_each_op(op, ops) {
2967+
drm_WARN_ON(vm_bo->vm->drm, op->op != DRM_GPUVA_OP_UNMAP);
2968+
2969+
ret = op_unmap_cb(vm_ops, priv, op->unmap.va, false, false);
2970+
if (ret)
2971+
goto cleanup;
2972+
}
2973+
2974+
cleanup:
2975+
drm_gpuva_ops_free(vm_bo->vm, ops);
2976+
return ret;
2977+
}
2978+
EXPORT_SYMBOL_GPL(drm_gpuvm_bo_unmap);
2979+
29312980
/**
29322981
* drm_gpuvm_bo_unmap_ops_create() - creates the &drm_gpuva_ops to unmap a GEM
29332982
* @vm_bo: the &drm_gpuvm_bo abstraction

include/drm/drm_gpuvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ int drm_gpuvm_sm_map(struct drm_gpuvm *gpuvm, void *priv,
12391239

12401240
int drm_gpuvm_sm_unmap(struct drm_gpuvm *gpuvm, void *priv,
12411241
u64 addr, u64 range);
1242+
int drm_gpuvm_bo_unmap(struct drm_gpuvm_bo *bo, void *priv);
12421243

12431244
int drm_gpuvm_sm_map_exec_lock(struct drm_gpuvm *gpuvm,
12441245
struct drm_exec *exec, unsigned int num_fences,

0 commit comments

Comments
 (0)