[PATCH 6/9] drm/xe: Add xe_force_wake_tryget to simplify forcewake handling
Nirmoy Das
nirmoy.das at intel.com
Tue Jun 4 11:02:22 UTC 2024
Add xe_force_wake_tryget() a caller of xe_force_wake_get() would like
to skip early and not have to worry about undoing changes made by
xe_force_wake_get() on error.
Signed-off-by: Nirmoy Das <nirmoy.das at intel.com>
---
drivers/gpu/drm/xe/xe_force_wake.c | 22 ++++++++++++++++++++++
drivers/gpu/drm/xe/xe_force_wake.h | 2 ++
2 files changed, 24 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_force_wake.c b/drivers/gpu/drm/xe/xe_force_wake.c
index 9bbe8a5040da..9eef4ebaeccc 100644
--- a/drivers/gpu/drm/xe/xe_force_wake.c
+++ b/drivers/gpu/drm/xe/xe_force_wake.c
@@ -197,3 +197,25 @@ int xe_force_wake_put(struct xe_force_wake *fw,
return ret2;
}
+
+/**
+ * xe_force_wake_tryget - Attempt to wake up the specified force wake domains
+ * @fw: Pointer to the force wake structure
+ * @domains: Bitmask representing the domains to be woken up
+ *
+ * This function attempts to wake up the specified domains by calling
+ * xe_force_wake_get(). If xe_force_wake_get() fails, it calls xe_force_wake_put()
+ * to revert any partial changes and ensure system stability.
+ *
+ * Return: 0 on success, non-zero on failure, indicating one or more domains failed to wake up.
+ */
+int __must_check xe_force_wake_tryget(struct xe_force_wake *fw,
+ enum xe_force_wake_domains domains)
+{
+ int ret = xe_force_wake_get(fw, domains);
+
+ if (ret)
+ xe_force_wake_put(fw, domains);
+
+ return ret;
+}
diff --git a/drivers/gpu/drm/xe/xe_force_wake.h b/drivers/gpu/drm/xe/xe_force_wake.h
index 83cb157da7cc..3f918a09f029 100644
--- a/drivers/gpu/drm/xe/xe_force_wake.h
+++ b/drivers/gpu/drm/xe/xe_force_wake.h
@@ -17,6 +17,8 @@ void xe_force_wake_init_engines(struct xe_gt *gt,
struct xe_force_wake *fw);
int xe_force_wake_get(struct xe_force_wake *fw,
enum xe_force_wake_domains domains);
+int __must_check xe_force_wake_tryget(struct xe_force_wake *fw,
+ enum xe_force_wake_domains domains);
int xe_force_wake_put(struct xe_force_wake *fw,
enum xe_force_wake_domains domains);
--
2.42.0
More information about the Intel-xe
mailing list