]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe: Return forcewake reference type from force_wake_get_any_engine()
authorMatt Roper <matthew.d.roper@intel.com>
Tue, 18 Nov 2025 16:43:53 +0000 (08:43 -0800)
committerMatt Roper <matthew.d.roper@intel.com>
Wed, 19 Nov 2025 19:58:57 +0000 (11:58 -0800)
Adjust the signature of force_wake_get_any_engine() such that it returns
a 'struct xe_force_wake_ref' rather than a boolean success/failure.
Failure cases are now recognized by inspecting the hardware engine
returned by reference; a NULL hwe indicates that no engine's forcewake
could be obtained.

These changes will make it cleaner and easier to incorporate scope-based
cleanup in force_wake_get_any_engine()'s caller in a future patch.

Reviewed-by: Gustavo Sousa <gustavo.sousa@intel.com>
Link: https://patch.msgid.link/20251118164338.3572146-43-matthew.d.roper@intel.com
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
drivers/gpu/drm/xe/xe_drm_client.c

index f931ff9b1ec03d939b50d4cb40aeb1eca19d0bf0..78551832723bf4498e2102c6d983958ea3589926 100644 (file)
@@ -285,32 +285,31 @@ static struct xe_hw_engine *any_engine(struct xe_device *xe)
        return NULL;
 }
 
-static bool force_wake_get_any_engine(struct xe_device *xe,
-                                     struct xe_hw_engine **phwe,
-                                     unsigned int *pfw_ref)
+/*
+ * Pick any engine and grab its forcewake.  On error phwe will be NULL and
+ * the returned forcewake reference will be invalid.  Callers should check
+ * phwe against NULL.
+ */
+static struct xe_force_wake_ref force_wake_get_any_engine(struct xe_device *xe,
+                                                         struct xe_hw_engine **phwe)
 {
        enum xe_force_wake_domains domain;
-       unsigned int fw_ref;
+       struct xe_force_wake_ref fw_ref = {};
        struct xe_hw_engine *hwe;
-       struct xe_force_wake *fw;
+
+       *phwe = NULL;
 
        hwe = any_engine(xe);
        if (!hwe)
-               return false;
+               return fw_ref;  /* will be invalid */
 
        domain = xe_hw_engine_to_fw_domain(hwe);
-       fw = gt_to_fw(hwe->gt);
-
-       fw_ref = xe_force_wake_get(fw, domain);
-       if (!xe_force_wake_ref_has_domain(fw_ref, domain)) {
-               xe_force_wake_put(fw, fw_ref);
-               return false;
-       }
 
-       *phwe = hwe;
-       *pfw_ref = fw_ref;
+       fw_ref = xe_force_wake_constructor(gt_to_fw(hwe->gt), domain);
+       if (xe_force_wake_ref_has_domain(fw_ref.domains, domain))
+               *phwe = hwe;    /* valid forcewake */
 
-       return true;
+       return fw_ref;
 }
 
 static void show_run_ticks(struct drm_printer *p, struct drm_file *file)
@@ -322,7 +321,7 @@ static void show_run_ticks(struct drm_printer *p, struct drm_file *file)
        struct xe_hw_engine *hwe;
        struct xe_exec_queue *q;
        u64 gpu_timestamp;
-       unsigned int fw_ref;
+       struct xe_force_wake_ref fw_ref;
 
        /*
         * RING_TIMESTAMP registers are inaccessible in VF mode.
@@ -340,7 +339,8 @@ static void show_run_ticks(struct drm_printer *p, struct drm_file *file)
                       !atomic_read(&xef->exec_queue.pending_removal));
 
        xe_pm_runtime_get(xe);
-       if (!force_wake_get_any_engine(xe, &hwe, &fw_ref)) {
+       fw_ref = force_wake_get_any_engine(xe, &hwe);
+       if (!hwe) {
                xe_pm_runtime_put(xe);
                return;
        }
@@ -360,7 +360,7 @@ static void show_run_ticks(struct drm_printer *p, struct drm_file *file)
 
        gpu_timestamp = xe_hw_engine_read_timestamp(hwe);
 
-       xe_force_wake_put(gt_to_fw(hwe->gt), fw_ref);
+       xe_force_wake_put(gt_to_fw(hwe->gt), fw_ref.domains);
        xe_pm_runtime_put(xe);
 
        for (class = 0; class < XE_ENGINE_CLASS_MAX; class++) {