summaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorTomer Tayar <ttayar@habana.ai>2020-09-02 13:43:32 +0300
committerOded Gabbay <ogabbay@kernel.org>2020-11-30 10:47:38 +0200
commitf44afb5b5a5d04448da843b2fe872e01669bc317 (patch)
tree58e09eb0ae0899232ecde2c7b90c3febc15c1e07 /drivers/misc
parentf07486745442f6118ede18e2b52ee7be69cde5a4 (diff)
downloadlinux-f44afb5b5a5d04448da843b2fe872e01669bc317.tar.gz
linux-f44afb5b5a5d04448da843b2fe872e01669bc317.tar.bz2
linux-f44afb5b5a5d04448da843b2fe872e01669bc317.zip
habanalabs: Add CB IOCTL opcode to retrieve CB information
Add a new CB IOCTL opcode that enables a user to query about a CB and get its usage count. Signed-off-by: Tomer Tayar <ttayar@habana.ai> Reviewed-by: Oded Gabbay <ogabbay@kernel.org> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/habanalabs/common/command_buffer.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/drivers/misc/habanalabs/common/command_buffer.c b/drivers/misc/habanalabs/common/command_buffer.c
index 2856bb3423ee..6f6a904ab6ca 100644
--- a/drivers/misc/habanalabs/common/command_buffer.c
+++ b/drivers/misc/habanalabs/common/command_buffer.c
@@ -375,12 +375,43 @@ int hl_cb_destroy(struct hl_device *hdev, struct hl_cb_mgr *mgr, u64 cb_handle)
return rc;
}
+static int hl_cb_info(struct hl_device *hdev, struct hl_cb_mgr *mgr,
+ u64 cb_handle, u32 *usage_cnt)
+{
+ struct hl_cb *cb;
+ u32 handle;
+ int rc = 0;
+
+ /* The CB handle was given to user to do mmap, so need to shift it back
+ * to the value which was allocated by the IDR module.
+ */
+ cb_handle >>= PAGE_SHIFT;
+ handle = (u32) cb_handle;
+
+ spin_lock(&mgr->cb_lock);
+
+ cb = idr_find(&mgr->cb_handles, handle);
+ if (!cb) {
+ dev_err(hdev->dev,
+ "CB info failed, no match to handle 0x%x\n", handle);
+ rc = -EINVAL;
+ goto out;
+ }
+
+ *usage_cnt = atomic_read(&cb->cs_cnt);
+
+out:
+ spin_unlock(&mgr->cb_lock);
+ return rc;
+}
+
int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data)
{
union hl_cb_args *args = data;
struct hl_device *hdev = hpriv->hdev;
enum hl_device_status status;
u64 handle = 0;
+ u32 usage_cnt = 0;
int rc;
if (!hl_device_operational(hdev, &status)) {
@@ -413,6 +444,13 @@ int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data)
args->in.cb_handle);
break;
+ case HL_CB_OP_INFO:
+ rc = hl_cb_info(hdev, &hpriv->cb_mgr, args->in.cb_handle,
+ &usage_cnt);
+ memset(args, 0, sizeof(*args));
+ args->out.usage_cnt = usage_cnt;
+ break;
+
default:
rc = -ENOTTY;
break;