[PATCH i-g-t v1.1] lib/igt_gt: Fallback on filenames in igt_open_forcewake_handle()

Lucas De Marchi lucas.demarchi at intel.com
Wed Sep 18 19:16:26 UTC 2024


If fd is -1, we don't know what file should be used for forcewake.
We could open the debugfs dir and figure out from there, but it's also
cheap to just handle a fallback approach. Ideally fd == -1 wouldn't be
passed and eventually this could be removed.

v2: Fix copy-and-paste error s/XE/I915/

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 lib/igt_gt.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index c84368fbd..4b096768f 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -502,17 +502,31 @@ void igt_stop_hang_helper(void)
  */
 int igt_open_forcewake_handle(int fd)
 {
-	const char *fn;
+	enum {
+		I915,
+		XE,
+	};
+	const char *fn[] = {
+		[I915] = "i915_forcewake_user",
+		[XE] = "forcewake_all",
+	};
 
 	if (getenv("IGT_NO_FORCEWAKE"))
 		return -1;
 
 	if (is_xe_device(fd))
-		fn = "forcewake_all";
-	else
-		fn = "i915_forcewake_user";
+		return igt_debugfs_open(fd, fn[XE], O_RDONLY);
+	if (is_i915_device(fd))
+		return igt_debugfs_open(fd, fn[I915], O_RDONLY);
+
+	for (unsigned int i = 0; i < ARRAY_SIZE(fn); i++) {
+		int ret = igt_debugfs_open(fd, fn[i], O_RDONLY);
+
+		if (ret >= 0)
+			return ret;
+	}
 
-	return igt_debugfs_open(fd, fn, O_RDONLY);
+	return -ENOENT;
 }
 
 #if defined(__x86_64__) || defined(__i386__)
-- 
2.46.1



More information about the igt-dev mailing list