[PATCH i-g-t 07/10] lib/xe: Add xe_wa_from_cache()

Gustavo Sousa <[email protected]>
Newsgroups org.freedesktop.lists.igt-dev
Message-ID <[email protected]>
An upcoming change will need to check if a workaround is enabled
during the creation of the xe_device struct, i.e., during the
execution of xe_device_get().  It is not possible to call xe_wa() in
that context because the struct is not yet cached and xe_wa() calling
xe_device_get() will cause an infinite recursion.

Add the function xe_wa_from_cache() to allow checking for workarounds
in that specific scenario and make a note in the function's
documentation about its purpose.

Signed-off-by: Gustavo Sousa <[email protected]>
---
 lib/xe/xe_wa.c | 34 ++++++++++++++++++++++++++++------
 lib/xe/xe_wa.h |  1 +
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/lib/xe/xe_wa.c b/lib/xe/xe_wa.c
index 8c8f7156c21f..ac3dcf6ef1c1 100644
--- a/lib/xe/xe_wa.c
+++ b/lib/xe/xe_wa.c
@@ -105,19 +105,28 @@ static bool debugfs_dump_has_wa(char *dump, const char *wa)
 
 /**
  * xe_wa: Check if a workaround is enabled for the device.
- * @fd: A drm file descriptor.
+ * @xe_dev: Xe device where the cached data is stashed.
  * @wa: Name of the workaround to be checked.
  *
- * Return a boolean indicating whether the workaround is enabled.
- * On error, returns false and a warning is printed.
+ * This function is like xe_wa(), but it receives the "incomplete"
+ * (see next paragraph) xe_device struct directly instead of a drm
+ * file descriptor.
+ *
+ * This function is only expected to be used in specific paths during
+ * the initialization of a xe_device struct (i.e. during execution of
+ * xe_device_get()), where the workaround cache is ready
+ * (i.e. xe_wa_build_cache()), but the xe_device struct is not yet
+ * fully built and cached (which is a requirement for xe_wa()).
  */
-bool xe_wa(int fd, const char *wa)
+bool xe_wa_from_cache(struct xe_device *xe_dev, const char *wa)
 {
-	char **dumps = xe_device_get(fd)->wa_cache;
+	char **dumps;
 
-	if (igt_warn_on(!dumps))
+	if (igt_warn_on(!xe_dev->wa_cache))
 		return false;
 
+	dumps = xe_dev->wa_cache;
+
 	for (char **dump = dumps; *dump; dump++)
 		if (debugfs_dump_has_wa(*dump, wa))
 			return true;
@@ -125,6 +134,19 @@ bool xe_wa(int fd, const char *wa)
 	return false;
 }
 
+/**
+ * xe_wa: Check if a workaround is enabled for the device.
+ * @fd: A drm file descriptor.
+ * @wa: Name of the workaround to be checked.
+ *
+ * Return a boolean indicating whether the workaround is enabled.
+ * On error, returns false and a warning is printed.
+ */
+bool xe_wa(int fd, const char *wa)
+{
+	return xe_wa_from_cache(xe_device_get(fd), wa);
+}
+
 /**
  * xe_wa_build_cache: Build cached data for xe_wa().
  * @xe_dev: Xe device where the cache will be stashed.
diff --git a/lib/xe/xe_wa.h b/lib/xe/xe_wa.h
index aa1c50c0f9c9..2f141ae15016 100644
--- a/lib/xe/xe_wa.h
+++ b/lib/xe/xe_wa.h
@@ -14,5 +14,6 @@ bool xe_wa(int fd, const char *wa);
 
 void xe_wa_build_cache(struct xe_device *xe_dev);
 void xe_wa_free_cache(struct xe_device *xe_dev);
+bool xe_wa_from_cache(struct xe_device *xe_dev, const char *wa);
 
 #endif /* XE_WA_H */

-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.