summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarcin Bernatowicz <marcin.bernatowicz@linux.intel.com>2022-04-27 20:29:23 +0530
committerPriyanka Dandamudi <priyanka.dandamudi@intel.com>2022-04-28 19:02:26 +0530
commitf928721f78e15f698400941d94454bb4122bb31f (patch)
tree1fdda8e91efb28adc33fcbaaeba51af174bd9106 /lib
parent3f5b7b81db7aa2dd767aeaaf3945ffe92fc90f8c (diff)
lib/sysfs: helper for number of GTs
Added convenience function returning number of GTs. Reads number of GT sysfs entries and returns number of GTs, if atleast one GT entry is found. v2: Add an assert condition to check for atleast one GT entry. (Priyanka) Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com> Signed-off-by: Priyanka Dandamudi <priyanka.dandamudi@intel.com> Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_sysfs.c23
-rw-r--r--lib/igt_sysfs.h1
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index e42251e6..40c9a2e3 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -265,6 +265,29 @@ int igt_sysfs_gt_open(int device, int gt)
}
/**
+ * igt_sysfs_get_num_gt:
+ * @device: fd of the device
+ *
+ * Reads number of GT sysfs entries.
+ * Asserts for atleast one GT entry.
+ * (see igt_sysfs_gt_path).
+ *
+ * Returns: Number of GTs.
+ */
+int igt_sysfs_get_num_gt(int device)
+{
+ int num_gts = 0;
+ char path[96];
+
+ while (igt_sysfs_gt_path(device, num_gts, path, sizeof(path)))
+ ++num_gts;
+
+ igt_assert_f(num_gts > 0, "No GT sysfs entry is found.");
+
+ return num_gts;
+}
+
+/**
* igt_sysfs_write:
* @dir: directory for the device from igt_sysfs_open()
* @attr: name of the sysfs node to open
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 8e39b8fa..1c9791a1 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -94,6 +94,7 @@ char *igt_sysfs_path(int device, char *path, int pathlen);
int igt_sysfs_open(int device);
char *igt_sysfs_gt_path(int device, int gt, char *path, int pathlen);
int igt_sysfs_gt_open(int device, int gt);
+int igt_sysfs_get_num_gt(int device);
bool igt_sysfs_has_attr(int dir, const char *attr);
const char *igt_sysfs_dir_id_to_name(int dir, enum i915_attr_id id);
const char *igt_sysfs_path_id_to_name(const char *path, enum i915_attr_id id);