mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-27 03:49:57 -04:00
drm/gpuvm: add common dma-resv per struct drm_gpuvm
Provide a common dma-resv for GEM objects not being used outside of this GPU-VM. This is used in a subsequent patch to generalize dma-resv, external and evicted object handling and GEM validation. Acked-by: Christian König <christian.koenig@amd.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Signed-off-by: Danilo Krummrich <dakr@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20231108001259.15123-6-dakr@redhat.com
This commit is contained in:
@@ -61,6 +61,15 @@
|
||||
* contained within struct drm_gpuva already. Hence, for inserting &drm_gpuva
|
||||
* entries from within dma-fence signalling critical sections it is enough to
|
||||
* pre-allocate the &drm_gpuva structures.
|
||||
*
|
||||
* &drm_gem_objects which are private to a single VM can share a common
|
||||
* &dma_resv in order to improve locking efficiency (e.g. with &drm_exec).
|
||||
* For this purpose drivers must pass a &drm_gem_object to drm_gpuvm_init(), in
|
||||
* the following called 'resv object', which serves as the container of the
|
||||
* GPUVM's shared &dma_resv. This resv object can be a driver specific
|
||||
* &drm_gem_object, such as the &drm_gem_object containing the root page table,
|
||||
* but it can also be a 'dummy' object, which can be allocated with
|
||||
* drm_gpuvm_resv_object_alloc().
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -670,11 +679,49 @@ drm_gpuvm_range_valid(struct drm_gpuvm *gpuvm,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(drm_gpuvm_range_valid);
|
||||
|
||||
static void
|
||||
drm_gpuvm_gem_object_free(struct drm_gem_object *obj)
|
||||
{
|
||||
drm_gem_object_release(obj);
|
||||
kfree(obj);
|
||||
}
|
||||
|
||||
static const struct drm_gem_object_funcs drm_gpuvm_object_funcs = {
|
||||
.free = drm_gpuvm_gem_object_free,
|
||||
};
|
||||
|
||||
/**
|
||||
* drm_gpuvm_resv_object_alloc() - allocate a dummy &drm_gem_object
|
||||
* @drm: the drivers &drm_device
|
||||
*
|
||||
* Allocates a dummy &drm_gem_object which can be passed to drm_gpuvm_init() in
|
||||
* order to serve as root GEM object providing the &drm_resv shared across
|
||||
* &drm_gem_objects local to a single GPUVM.
|
||||
*
|
||||
* Returns: the &drm_gem_object on success, NULL on failure
|
||||
*/
|
||||
struct drm_gem_object *
|
||||
drm_gpuvm_resv_object_alloc(struct drm_device *drm)
|
||||
{
|
||||
struct drm_gem_object *obj;
|
||||
|
||||
obj = kzalloc(sizeof(*obj), GFP_KERNEL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->funcs = &drm_gpuvm_object_funcs;
|
||||
drm_gem_private_object_init(drm, obj, 0);
|
||||
|
||||
return obj;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(drm_gpuvm_resv_object_alloc);
|
||||
|
||||
/**
|
||||
* drm_gpuvm_init() - initialize a &drm_gpuvm
|
||||
* @gpuvm: pointer to the &drm_gpuvm to initialize
|
||||
* @name: the name of the GPU VA space
|
||||
* @drm: the &drm_device this VM resides in
|
||||
* @r_obj: the resv &drm_gem_object providing the GPUVM's common &dma_resv
|
||||
* @start_offset: the start offset of the GPU VA space
|
||||
* @range: the size of the GPU VA space
|
||||
* @reserve_offset: the start of the kernel reserved GPU VA area
|
||||
@@ -689,6 +736,7 @@ EXPORT_SYMBOL_GPL(drm_gpuvm_range_valid);
|
||||
void
|
||||
drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name,
|
||||
struct drm_device *drm,
|
||||
struct drm_gem_object *r_obj,
|
||||
u64 start_offset, u64 range,
|
||||
u64 reserve_offset, u64 reserve_range,
|
||||
const struct drm_gpuvm_ops *ops)
|
||||
@@ -699,6 +747,9 @@ drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name,
|
||||
gpuvm->name = name ? name : "unknown";
|
||||
gpuvm->ops = ops;
|
||||
gpuvm->drm = drm;
|
||||
gpuvm->r_obj = r_obj;
|
||||
|
||||
drm_gem_object_get(r_obj);
|
||||
|
||||
drm_gpuvm_warn_check_overflow(gpuvm, start_offset, range);
|
||||
gpuvm->mm_start = start_offset;
|
||||
@@ -733,6 +784,8 @@ drm_gpuvm_destroy(struct drm_gpuvm *gpuvm)
|
||||
|
||||
drm_WARN(gpuvm->drm, !RB_EMPTY_ROOT(&gpuvm->rb.tree.rb_root),
|
||||
"GPUVA tree is not empty, potentially leaking memory.\n");
|
||||
|
||||
drm_gem_object_put(gpuvm->r_obj);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(drm_gpuvm_destroy);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user