[PATCH v2 i-g-t 1/3] lib/igt_sysfs: Add xe_sysfs_gt_has_node to check node existence

Marcin Bernatowicz marcin.bernatowicz at linux.intel.com
Thu Aug 1 10:27:46 UTC 2024


Introduce xe_sysfs_gt_has_node to verify if a specified node
exists within the sysfs gt directory of a device.

v2: Add newline before return statement (Kamil)
    Use "node" instead of "attribute" for more accuracy

Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
---
 lib/igt_sysfs.c | 26 ++++++++++++++++++++++++++
 lib/igt_sysfs.h |  1 +
 2 files changed, 27 insertions(+)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 550472d81..12abc4f7e 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -265,6 +265,32 @@ int xe_sysfs_gt_open(int xe_device, int gt)
 	return open(path, O_RDONLY);
 }
 
+/**
+ * xe_sysfs_gt_has_attr:
+ * @xe_device: fd of the device
+ * @gt: gt number
+ * @node: node inside sysfs gt dir that needs to be checked for existence
+ *
+ * This checks if specified node exists in device sysfs gt directory.
+ *
+ * Returns:
+ * true if node exists in sysfs, false otherwise.
+ */
+bool xe_sysfs_gt_has_node(int xe_device, int gt, const char *node)
+{
+	bool has_node;
+	int gt_fd;
+
+	gt_fd = xe_sysfs_gt_open(xe_device, gt);
+	if (gt_fd < 0)
+		return false;
+
+	has_node = igt_sysfs_has_attr(gt_fd, node);
+	close(gt_fd);
+
+	return has_node;
+}
+
 static const char *xe_engine_class_to_str(__u16 class)
 {
 	static const char * const str[] = {
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 5d050c786..27031a015 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -168,6 +168,7 @@ void igt_sysfs_engines(int xe, int engines, const char **property,
 
 char *xe_sysfs_gt_path(int xe_device, int gt, char *path, int pathlen);
 int xe_sysfs_gt_open(int xe_device, int gt);
+bool xe_sysfs_gt_has_node(int xe_device, int gt, const char *node);
 char *xe_sysfs_tile_path(int xe_device, int tile, char *path, int pathlen);
 int xe_sysfs_tile_open(int xe_device, int tile);
 int xe_sysfs_get_num_tiles(int xe_device);
-- 
2.31.1



More information about the igt-dev mailing list