Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [RFC 1/3] drm/xe: Introduce force-wake guard class
Date: Mon, 17 Jun 2024 16:34:28 +0200	[thread overview]
Message-ID: <20240617143430.641-2-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20240617143430.641-1-michal.wajdeczko@intel.com>

There is support for 'classes' with constructor and destructor
semantics that can be used for any scope-based resource management,
like device force-wake management.

Add necessary definitions explicitly, since existing macros from
linux/cleanup.h can't deal with our specific requirements yet.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
---
 drivers/gpu/drm/xe/xe_force_wake.h       | 48 ++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_force_wake_types.h | 12 ++++++
 2 files changed, 60 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_force_wake.h b/drivers/gpu/drm/xe/xe_force_wake.h
index a2577672f4e3..0a09018b2a89 100644
--- a/drivers/gpu/drm/xe/xe_force_wake.h
+++ b/drivers/gpu/drm/xe/xe_force_wake.h
@@ -6,6 +6,8 @@
 #ifndef _XE_FORCE_WAKE_H_
 #define _XE_FORCE_WAKE_H_
 
+#include <linux/cleanup.h>
+
 #include "xe_assert.h"
 #include "xe_force_wake_types.h"
 
@@ -46,4 +48,50 @@ xe_force_wake_assert_held(struct xe_force_wake *fw,
 	xe_gt_assert(fw->gt, fw->awake_domains & domain);
 }
 
+/**
+ * class_xe_fw_constructor - The FW guard constructor
+ * @fw : the &xe_force_wake which manages domains
+ * @domain: force wake domain to wake
+ *
+ * Implements constructor semantics for the FW guard.
+ * See scoped_guard() for more details.
+ */
+static inline class_xe_fw_t class_xe_fw_constructor(struct xe_force_wake *fw,
+						    enum xe_force_wake_domains domain)
+{
+	class_xe_fw_t guard = {
+		.fw = fw,
+		.domain = domain,
+	};
+
+	if (fw && xe_force_wake_get(fw, domain))
+		guard.fw = NULL;
+
+	return guard;
+}
+
+/**
+ * class_xe_fw_destructor - The FW guard destructor
+ * @guard : the &class_xe_fw_t to cleanup
+ *
+ * Implements destructor semantics for the FW guard.
+ * See scoped_guard() for more details.
+ */
+static inline void class_xe_fw_destructor(class_xe_fw_t *guard)
+{
+	if (guard->fw)
+		xe_force_wake_put(guard->fw, guard->domain);
+}
+
+/**
+ * class_xe_fw_lock_ptr - The FW guard helper
+ * @guard : the &class_xe_fw_t
+ *
+ * See scoped_guard() for more details.
+ */
+static inline void *class_xe_fw_lock_ptr(class_xe_fw_t *guard)
+{
+	return guard->fw;
+}
+
 #endif
diff --git a/drivers/gpu/drm/xe/xe_force_wake_types.h b/drivers/gpu/drm/xe/xe_force_wake_types.h
index ed0edc2cdf9f..39220d5fe0f7 100644
--- a/drivers/gpu/drm/xe/xe_force_wake_types.h
+++ b/drivers/gpu/drm/xe/xe_force_wake_types.h
@@ -83,4 +83,16 @@ struct xe_force_wake {
 	struct xe_force_wake_domain domains[XE_FW_DOMAIN_ID_COUNT];
 };
 
+/**
+ * struct xe_force_wake_guard - Xe force wake guard class
+ */
+struct xe_force_wake_guard {
+	/** @fw: force wake manager */
+	struct xe_force_wake *fw;
+	/** @domain: awake domain under guard */
+	enum xe_force_wake_domains domain;
+};
+
+typedef struct xe_force_wake_guard class_xe_fw_t;
+
 #endif
-- 
2.43.0


  reply	other threads:[~2024-06-17 14:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17 14:34 [RFC 0/3] FW guard class Michal Wajdeczko
2024-06-17 14:34 ` Michal Wajdeczko [this message]
2024-06-17 14:34 ` [RFC 2/3] drm/xe: Use new FW guard in xe_mocs.c Michal Wajdeczko
2024-06-17 14:34 ` [RFC 3/3] drm/xe: Use new FW guard in xe_pat.c Michal Wajdeczko
2024-06-17 14:59 ` ✓ CI.Patch_applied: success for FW guard class Patchwork
2024-06-17 15:00 ` ✗ CI.checkpatch: warning " Patchwork
2024-06-17 15:01 ` ✓ CI.KUnit: success " Patchwork
2024-06-17 15:13 ` ✓ CI.Build: " Patchwork
2024-06-17 15:15 ` ✗ CI.Hooks: failure " Patchwork
2024-06-17 15:16 ` ✓ CI.checksparse: success " Patchwork
2024-06-17 15:38 ` ✓ CI.BAT: " Patchwork
2024-06-17 17:24 ` [RFC 0/3] " Matthew Brost
2024-06-17 18:00   ` Rodrigo Vivi
2024-06-17 18:06     ` Matthew Brost
2024-06-17 19:24     ` Michal Wajdeczko
2024-06-17 23:30       ` Matthew Brost
2024-06-18  0:54         ` Lucas De Marchi
2024-06-18  1:16           ` Matthew Brost
2024-06-18 18:08             ` Michal Wajdeczko
2024-06-18 18:44               ` Matthew Brost
2024-06-18 20:26           ` Rodrigo Vivi
2024-06-19  6:40             ` Thomas Hellström
2024-06-19 18:46               ` Rodrigo Vivi
2024-06-24 16:32             ` Nirmoy Das
2024-06-18  6:39 ` ✗ CI.FULL: failure for " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240617143430.641-2-michal.wajdeczko@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=rodrigo.vivi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox