diff options
author | Danilo Krummrich <dakr@redhat.com> | 2023-11-08 01:12:39 +0100 |
---|---|---|
committer | Danilo Krummrich <dakr@redhat.com> | 2023-11-13 18:19:06 +0100 |
commit | 8af72338dd81d1f8667e0240bd28f5fc98b3f20d (patch) | |
tree | d673166ea0d3ed4d2ed6720e43bef0a4e520f563 /include/drm/drm_gpuvm.h | |
parent | drm/nouveau: separately allocate struct nouveau_uvmm (diff) | |
download | linux-8af72338dd81d1f8667e0240bd28f5fc98b3f20d.tar.xz linux-8af72338dd81d1f8667e0240bd28f5fc98b3f20d.zip |
drm/gpuvm: reference count drm_gpuvm structures
Implement reference counting for struct drm_gpuvm.
Acked-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Danilo Krummrich <dakr@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231108001259.15123-10-dakr@redhat.com
Diffstat (limited to '')
-rw-r--r-- | include/drm/drm_gpuvm.h | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/include/drm/drm_gpuvm.h b/include/drm/drm_gpuvm.h index 0c2e24155a93..4e6e1fd3485a 100644 --- a/include/drm/drm_gpuvm.h +++ b/include/drm/drm_gpuvm.h @@ -248,6 +248,11 @@ struct drm_gpuvm { } rb; /** + * @kref: reference count of this object + */ + struct kref kref; + + /** * @kernel_alloc_node: * * &drm_gpuva representing the address space cutout reserved for @@ -273,7 +278,23 @@ void drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name, u64 start_offset, u64 range, u64 reserve_offset, u64 reserve_range, const struct drm_gpuvm_ops *ops); -void drm_gpuvm_destroy(struct drm_gpuvm *gpuvm); + +/** + * drm_gpuvm_get() - acquire a struct drm_gpuvm reference + * @gpuvm: the &drm_gpuvm to acquire the reference of + * + * This function acquires an additional reference to @gpuvm. It is illegal to + * call this without already holding a reference. No locks required. + */ +static inline struct drm_gpuvm * +drm_gpuvm_get(struct drm_gpuvm *gpuvm) +{ + kref_get(&gpuvm->kref); + + return gpuvm; +} + +void drm_gpuvm_put(struct drm_gpuvm *gpuvm); bool drm_gpuvm_range_valid(struct drm_gpuvm *gpuvm, u64 addr, u64 range); bool drm_gpuvm_interval_empty(struct drm_gpuvm *gpuvm, u64 addr, u64 range); @@ -674,6 +695,14 @@ static inline void drm_gpuva_init_from_op(struct drm_gpuva *va, */ struct drm_gpuvm_ops { /** + * @vm_free: called when the last reference of a struct drm_gpuvm is + * dropped + * + * This callback is mandatory. + */ + void (*vm_free)(struct drm_gpuvm *gpuvm); + + /** * @op_alloc: called when the &drm_gpuvm allocates * a struct drm_gpuva_op * |