[CI 14/21] drm/exec: drm_exec_trylock()
Thomas Hellström
thomas.hellstrom at linux.intel.com
Wed May 15 08:14:42 UTC 2024
Signed-off-by: Thomas Hellström <thomas.hellstrom at linux.intel.com>
---
drivers/gpu/drm/drm_exec.c | 38 ++++++++++++++++++++++++++++++++++++++
include/drm/drm_exec.h | 1 +
2 files changed, 39 insertions(+)
diff --git a/drivers/gpu/drm/drm_exec.c b/drivers/gpu/drm/drm_exec.c
index 2a28cbccaec7..ec8c245e33d1 100644
--- a/drivers/gpu/drm/drm_exec.c
+++ b/drivers/gpu/drm/drm_exec.c
@@ -207,6 +207,44 @@ int drm_exec_handle_contended(struct drm_exec *exec)
}
EXPORT_SYMBOL(drm_exec_handle_contended);
+/**
+ * drm_exec_lock_obj - lock a GEM object for use
+ * @exec: the drm_exec object with the state
+ * @obj: the GEM object to lock
+ *
+ * Lock a GEM object for use and grab a reference to it.
+ *
+ * Returns: -EDEADLK if a contention is detected, -EALREADY when object is
+ * already locked (can be suppressed by setting the DRM_EXEC_IGNORE_DUPLICATES
+ * flag), -ENOMEM when memory allocation failed and zero for success.
+ */
+int drm_exec_trylock_obj(struct drm_exec *exec, struct drm_gem_object *obj)
+{
+ int ret;
+
+ might_alloc(GFP_KERNEL);
+
+ if (exec->prelocked == obj) {
+ drm_gem_object_put(exec->prelocked);
+ exec->prelocked = NULL;
+ return 0;
+ }
+
+ if (!dma_resv_trylock_ctx(obj->resv, &exec->ticket)) {
+ if (dma_resv_locking_ctx(obj->resv) == &exec->ticket)
+ return (exec->flags & DRM_EXEC_IGNORE_DUPLICATES) ? 0 : -EALREADY;
+ else
+ return -EBUSY;
+ }
+
+ ret = drm_exec_obj_locked(exec, obj);
+ if (ret)
+ dma_resv_unlock(obj->resv);
+
+ return ret;
+}
+EXPORT_SYMBOL(drm_exec_trylock_obj);
+
/**
* drm_exec_lock_obj - lock a GEM object for use
* @exec: the drm_exec object with the state
diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
index a3490794ef35..a37c851a178b 100644
--- a/include/drm/drm_exec.h
+++ b/include/drm/drm_exec.h
@@ -148,6 +148,7 @@ void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr);
void drm_exec_fini(struct drm_exec *exec);
bool drm_exec_cleanup(struct drm_exec *exec);
int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj);
+int drm_exec_trylock_obj(struct drm_exec *exec, struct drm_gem_object *obj);
void drm_exec_unlock_obj(struct drm_exec *exec, struct drm_gem_object *obj);
int drm_exec_prepare_obj(struct drm_exec *exec, struct drm_gem_object *obj,
unsigned int num_fences);
--
2.44.0
More information about the Intel-xe
mailing list