From f928721f78e15f698400941d94454bb4122bb31f Mon Sep 17 00:00:00 2001 From: Marcin Bernatowicz Date: Wed, 27 Apr 2022 20:29:23 +0530 Subject: 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 Signed-off-by: Priyanka Dandamudi Reviewed-by: Kamil Konieczny --- lib/igt_sysfs.c | 23 +++++++++++++++++++++++ lib/igt_sysfs.h | 1 + 2 files changed, 24 insertions(+) (limited to 'lib') 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 @@ -264,6 +264,29 @@ int igt_sysfs_gt_open(int device, int gt) return open(path, O_RDONLY); } +/** + * 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() 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); -- cgit v1.2.3