From 45d65ffcfea660dded788d6819399833e017fd9f Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Wed, 22 Jun 2022 10:26:31 +0800
Subject: [PATCH 141/183] uadk: add device isolation interface

Users need to check whether the device is isolated before using
the device. So add an isolation interface.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 include/wd.h |  8 ++++++++
 wd.c         | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/wd.h b/include/wd.h
index 8c45522..b8044a4 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -293,6 +293,14 @@ int wd_ctx_wait(handle_t h_ctx, __u16 ms);
  */
 int wd_is_sva(handle_t h_ctx);
 
+/**
+ * wd_is_isolate() - Check if the device has been isolated.
+ * @dev: Indicate one device.
+ *
+ * Return 1 if isolated, 0 for not isolated, less than 0 otherwise.
+ */
+int wd_is_isolate(struct uacce_dev *dev);
+
 /**
  * wd_get_accel_name() - Get device name or driver name.
  * @dev_path: The path of device. e.g. /dev/hisi_zip-0.
diff --git a/wd.c b/wd.c
index 2dbb2ab..9715e10 100644
--- a/wd.c
+++ b/wd.c
@@ -186,6 +186,24 @@ static int access_attr(const char *dev_root, const char *attr, int mode)
 	return access(attr_file, mode);
 }
 
+int wd_is_isolate(struct uacce_dev *dev)
+{
+	int value = 0;
+	int ret;
+
+	if (!dev || !dev->dev_root)
+		return -WD_EINVAL;
+
+	ret = access_attr(dev->dev_root, "isolate", F_OK);
+	if (!ret) {
+		ret = get_int_attr(dev, "isolate", &value);
+		if (ret < 0)
+			return ret;
+	}
+
+	return value == 1 ? 1 : 0;
+}
+
 static int get_dev_info(struct uacce_dev *dev)
 {
 	int value = 0;
-- 
2.27.0

