Skip to content

Commit 4364162

Browse files
committed
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 7c9ee22 commit 4364162

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

drivers/gpu/drm/drm_gpuvm.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,49 @@ drm_gpuvm_prefetch_ops_create(struct drm_gpuvm *gpuvm,
26642664
}
26652665
EXPORT_SYMBOL_GPL(drm_gpuvm_prefetch_ops_create);
26662666

2667+
/**
2668+
* drm_gpuvm_bo_unmap() - unmaps a GEM
2669+
* @vm_bo: the &drm_gpuvm_bo abstraction
2670+
*
2671+
* This function calls the unmap callback for every GPUVA attached to a GEM.
2672+
*
2673+
* It is the callers responsibility to protect the GEMs GPUVA list against
2674+
* concurrent access using the GEMs dma_resv lock.
2675+
*
2676+
* Returns: a pointer to the &drm_gpuva_ops on success, an ERR_PTR on failure
2677+
*/
2678+
int
2679+
drm_gpuvm_bo_unmap(struct drm_gpuvm_bo *vm_bo, void *priv)
2680+
{
2681+
struct drm_gpuva_op *op;
2682+
int ret;
2683+
2684+
if (unlikely(!vm_bo->vm))
2685+
return -EINVAL;
2686+
2687+
const struct drm_gpuvm_ops *vm_ops = vm_bo->vm->ops;
2688+
2689+
if (unlikely(!(vm_ops && vm_ops->sm_step_unmap)))
2690+
return -EINVAL;
2691+
2692+
struct drm_gpuva_ops *ops = drm_gpuvm_bo_unmap_ops_create(vm_bo);
2693+
if (IS_ERR(ops))
2694+
return PTR_ERR(ops);
2695+
2696+
drm_gpuva_for_each_op(op, ops) {
2697+
drm_WARN_ON(vm_bo->vm->drm, op->op != DRM_GPUVA_OP_UNMAP);
2698+
2699+
ret = op_unmap_cb(vm_ops, priv, op->unmap.va, false);
2700+
if (ret)
2701+
goto cleanup;
2702+
}
2703+
2704+
cleanup:
2705+
drm_gpuva_ops_free(vm_bo->vm, ops);
2706+
return ret;
2707+
}
2708+
EXPORT_SYMBOL_GPL(drm_gpuvm_bo_unmap);
2709+
26672710
/**
26682711
* drm_gpuvm_bo_unmap_ops_create() - creates the &drm_gpuva_ops to unmap a GEM
26692712
* @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
@@ -1205,6 +1205,7 @@ int drm_gpuvm_sm_map(struct drm_gpuvm *gpuvm, void *priv,
12051205

12061206
int drm_gpuvm_sm_unmap(struct drm_gpuvm *gpuvm, void *priv,
12071207
u64 addr, u64 range);
1208+
int drm_gpuvm_bo_unmap(struct drm_gpuvm_bo *bo, void *priv);
12081209

12091210
void drm_gpuva_map(struct drm_gpuvm *gpuvm,
12101211
struct drm_gpuva *va,

0 commit comments

Comments
 (0)