summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Hajda <andrzej.hajda@intel.com>2024-06-27 09:25:03 +0200
committerKamil Konieczny <kamil.konieczny@linux.intel.com>2024-07-02 17:35:05 +0200
commit04e05e2aeff3a958572795ca0b2dec53074cf6ca (patch)
tree38cd7c8f697fc54192ae49d2c85128e41220d543
parent04e219dbe77bb759afe43681bad810f9aabf84c1 (diff)
lib/igt_sysfs: add helpers to access engine sysfs directory
Helpers follow convention of xe_sysfs_gt_(path|open). v7: - staticize local const array v8: - added xe_ prefix to local helper Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com> Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
-rw-r--r--lib/igt_sysfs.c71
-rw-r--r--lib/igt_sysfs.h3
2 files changed, 74 insertions, 0 deletions
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 0c5817eb1..ffeec1ca2 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -40,7 +40,9 @@
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
+#include <xe_drm.h>
+#include "drmtest.h"
#include "igt_core.h"
#include "igt_sysfs.h"
#include "igt_device.h"
@@ -263,6 +265,75 @@ int xe_sysfs_gt_open(int xe_device, int gt)
return open(path, O_RDONLY);
}
+static const char *xe_engine_class_to_str(__u16 class)
+{
+ static const char * const str[] = {
+ [DRM_XE_ENGINE_CLASS_RENDER] = "rcs",
+ [DRM_XE_ENGINE_CLASS_COPY] = "bcs",
+ [DRM_XE_ENGINE_CLASS_VIDEO_DECODE] = "vcs",
+ [DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs",
+ [DRM_XE_ENGINE_CLASS_COMPUTE] = "ccs",
+ };
+
+ if (class < ARRAY_SIZE(str))
+ return str[class];
+
+ return "unk";
+}
+
+/**
+ * xe_sysfs_engine_path:
+ * @xe_device: fd of the device
+ * @gt: gt number
+ * @class: engine class
+ * @path: buffer to fill with the sysfs gt path to the device
+ * @pathlen: length of @path buffer
+ *
+ * Returns:
+ * The directory path, or NULL on failure.
+ */
+char *
+xe_sysfs_engine_path(int xe_device, int gt, int class, char *path, int pathlen)
+{
+ struct stat st;
+ int tile = IS_PONTEVECCHIO(intel_get_drm_devid(xe_device)) ? gt : 0;
+
+ if (xe_device < 0)
+ return NULL;
+
+ if (igt_debug_on(fstat(xe_device, &st)) || igt_debug_on(!S_ISCHR(st.st_mode)))
+ return NULL;
+
+ snprintf(path, pathlen, "/sys/dev/char/%d:%d/device/tile%d/gt%d/engines/%s",
+ major(st.st_rdev), minor(st.st_rdev), tile, gt, xe_engine_class_to_str(class));
+
+ if (!access(path, F_OK))
+ return path;
+
+ return NULL;
+}
+
+/**
+ * xe_sysfs_engine_open:
+ * @xe_device: fd of the device
+ * @gt: gt number
+ * @class: engine class
+ *
+ * This opens the sysfs gt directory corresponding to device and tile for use
+ *
+ * Returns:
+ * The directory fd, or -1 on failure.
+ */
+int xe_sysfs_engine_open(int xe_device, int gt, int class)
+{
+ char path[96];
+
+ if (!xe_sysfs_engine_path(xe_device, gt, class, path, sizeof(path)))
+ return -1;
+
+ return open(path, O_RDONLY);
+}
+
/**
* igt_sysfs_gt_path:
* @device: fd of the device
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index f37d80ec1..6c604d939 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -166,4 +166,7 @@ int xe_sysfs_gt_open(int xe_device, int gt);
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);
+char *xe_sysfs_engine_path(int xe_device, int gt, int class, char *path, int pathlen);
+int xe_sysfs_engine_open(int xe_device, int gt, int class);
+
#endif /* __IGT_SYSFS_H__ */