aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/habanalabs/common/context.c
diff options
context:
space:
mode:
authorOded Gabbay <ogabbay@kernel.org>2021-11-30 23:02:21 +0200
committerOded Gabbay <ogabbay@kernel.org>2021-12-26 08:59:08 +0200
commit4337b50b5fe5ee64c821790f601ee6153bb9f027 (patch)
tree8a528f4e86286c1b4129134d21cbb65909cac438 /drivers/misc/habanalabs/common/context.c
parenthabanalabs: fix etr asid configuration (diff)
downloadlinux-dev-4337b50b5fe5ee64c821790f601ee6153bb9f027.tar.xz
linux-dev-4337b50b5fe5ee64c821790f601ee6153bb9f027.zip
habanalabs: add helper to get compute context
There are multiple places where the code needs to get the context's pointer and increment its ref cnt. This is the proper way instead of using the compute context pointer in the device structure. Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Diffstat (limited to 'drivers/misc/habanalabs/common/context.c')
-rw-r--r--drivers/misc/habanalabs/common/context.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/misc/habanalabs/common/context.c b/drivers/misc/habanalabs/common/context.c
index 8de1217b2ed2..b2884107fa15 100644
--- a/drivers/misc/habanalabs/common/context.c
+++ b/drivers/misc/habanalabs/common/context.c
@@ -272,6 +272,29 @@ int hl_ctx_put(struct hl_ctx *ctx)
return kref_put(&ctx->refcount, hl_ctx_do_release);
}
+struct hl_ctx *hl_get_compute_ctx(struct hl_device *hdev)
+{
+ struct hl_ctx *ctx = NULL;
+ struct hl_fpriv *hpriv;
+
+ mutex_lock(&hdev->fpriv_list_lock);
+
+ list_for_each_entry(hpriv, &hdev->fpriv_list, dev_node) {
+ /* There can only be a single user which has opened the compute device, so exit
+ * immediately once we find him
+ */
+ if (!hpriv->is_control) {
+ ctx = hpriv->ctx;
+ hl_ctx_get(hdev, ctx);
+ break;
+ }
+ }
+
+ mutex_unlock(&hdev->fpriv_list_lock);
+
+ return ctx;
+}
+
/*
* hl_ctx_get_fence_locked - get CS fence under CS lock
*