summaryrefslogtreecommitdiff
path: root/lib/igt_sysfs.c
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/igt_sysfs.c
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/igt_sysfs.c')
-rw-r--r--lib/igt_sysfs.c23
1 files changed, 23 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