public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Badal Nilawar <badal.nilawar@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, rodrigo.vivi@intel.com,
	alexander.usyskin@intel.com, michael.j.ruhl@intel.com,
	daniele.ceraolospurio@intel.com
Subject: [RFC PATCH 3/4] drm/xe/xe_late_bind_fw: Track firmware load status
Date: Thu,  5 Mar 2026 16:14:44 +0530	[thread overview]
Message-ID: <20260305104441.2857181-9-badal.nilawar@intel.com> (raw)
In-Reply-To: <20260305104441.2857181-6-badal.nilawar@intel.com>

In CRI, Intel PMT depends on the ocode runtime status. Track the
late-binding firmware load status and expose an API, for xe_vsec driver,
to query it.

Signed-off-by: Badal Nilawar <badal.nilawar@intel.com>
---
 drivers/gpu/drm/xe/xe_late_bind_fw.c       | 68 +++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_late_bind_fw.h       |  5 +-
 drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 23 ++++++++
 drivers/gpu/drm/xe/xe_pm.c                 |  5 +-
 4 files changed, 96 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c b/drivers/gpu/drm/xe/xe_late_bind_fw.c
index d3ef2926517bd..87137d6e4aaec 100644
--- a/drivers/gpu/drm/xe/xe_late_bind_fw.c
+++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c
@@ -53,6 +53,32 @@ late_bind_fw_to_xe(struct xe_late_bind_fw *lb_fw)
 	return container_of(lb_fw, struct xe_device, late_bind.late_bind_fw[lb_fw->id]);
 }
 
+static const char *xe_late_bind_fw_status_to_str(enum xe_late_bind_fw_status status)
+{
+	switch (status) {
+	case XE_LB_FW_NOT_SUPPORTED:
+		return "Not Supported";
+	case XE_LB_FW_AVAILABLE:
+		return "Available";
+	case XE_LB_FW_RUNNING:
+		return "Running";
+	case XE_LB_FW_FAILED:
+		return "Failed";
+	default:
+		return "Unknown";
+	}
+}
+
+static void xe_late_bind_change_fw_status(struct xe_late_bind_fw *lb_fw,
+					  enum xe_late_bind_fw_status status)
+{
+	struct xe_device *xe = late_bind_fw_to_xe(lb_fw);
+
+	lb_fw->__status = status;
+	drm_dbg(&xe->drm, "%s firmware status changed to %s\n",
+		fw_id_to_name[lb_fw->id], xe_late_bind_fw_status_to_str(status));
+}
+
 /* Refer to the "Late Bind based Firmware Layout" documentation entry for details */
 static int parse_cpd_header(struct xe_late_bind_fw *lb_fw,
 			    const void *data, size_t size, const char *manifest_entry)
@@ -235,6 +261,13 @@ static void xe_late_bind_wait_for_worker_completion(struct xe_late_bind *late_bi
 			drm_dbg(&xe->drm, "Flush work: load %s firmware\n",
 				fw_id_to_name[lbfw->id]);
 			flush_work(&lbfw->work);
+
+			/*
+			 * flush is being called during component unbind, suspend etc.
+			 * So mark status XE_LB_FW_RUNNING -> XE_LB_FW_AVAILABLE
+			 */
+			if (lbfw->__status == XE_LB_FW_RUNNING)
+				xe_late_bind_change_fw_status(lbfw, XE_LB_FW_AVAILABLE);
 		}
 	}
 }
@@ -282,6 +315,7 @@ static void xe_late_bind_work(struct work_struct *work)
 	if (!ret) {
 		drm_dbg(&xe->drm, "Load %s firmware successful\n",
 			fw_id_to_name[lbfw->id]);
+		xe_late_bind_change_fw_status(lbfw, XE_LB_FW_RUNNING);
 		goto out;
 	}
 
@@ -294,10 +328,23 @@ static void xe_late_bind_work(struct work_struct *work)
 	/* Do not re-attempt fw load */
 	drmm_kfree(&xe->drm, (void *)lbfw->payload);
 	lbfw->payload = NULL;
+	xe_late_bind_change_fw_status(lbfw, XE_LB_FW_FAILED);
 out:
 	xe_pm_runtime_put(xe);
 }
 
+static void  xe_late_bind_fw_stop(struct xe_late_bind *late_bind)
+{
+	struct xe_late_bind_fw *lbfw;
+	int fw_id;
+
+	for (fw_id = 0; fw_id < XE_LB_FW_MAX_ID; fw_id++) {
+		lbfw = &late_bind->late_bind_fw[fw_id];
+		if (lbfw->payload && lbfw->status == XE_LB_FW_RUNNING)
+			xe_late_bind_change_fw_status(lbfw, XE_LB_FW_AVAILABLE);
+	}
+}
+
 static int xe_late_bind_fw_load(struct xe_late_bind *late_bind)
 {
 	struct xe_device *xe = late_bind_to_xe(late_bind);
@@ -331,6 +378,7 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)
 	lb_fw->id = fw_id;
 	lb_fw->type = fw_id_to_type[lb_fw->id];
 	lb_fw->flags &= ~INTEL_LB_FLAG_IS_PERSISTENT;
+	xe_late_bind_change_fw_status(lb_fw, XE_LB_FW_NOT_SUPPORTED);
 
 	if (lb_fw->type == INTEL_LB_TYPE_FAN_CONTROL) {
 		ret = xe_late_bind_fw_num_fans(late_bind, &num_fans);
@@ -379,6 +427,7 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)
 	memcpy((void *)lb_fw->payload, fw->data, lb_fw->payload_size);
 	release_firmware(fw);
 	INIT_WORK(&lb_fw->work, xe_late_bind_work);
+	xe_late_bind_change_fw_status(lb_fw, XE_LB_FW_AVAILABLE);
 
 	return 0;
 }
@@ -445,15 +494,30 @@ static void xe_late_bind_remove(void *arg)
 	}
 }
 
-void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind)
+/**
+ * xe_late_bind_ocode_status() - get ocode late bind firmware status
+ * @xe: pointer to xe device.
+ *
+ * Return: 0 if unsupported, 1 if available, 2 if running, 3 if failed.
+ */
+int xe_late_bind_ocode_status(struct xe_device *xe)
+{
+	struct xe_late_bind_fw *lbfw = &xe->late_bind.late_bind_fw[XE_LB_FW_OCODE];
+
+	return lbfw->status;
+}
+
+void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind, bool is_runtime)
 {
 	if (!late_bind->component_added)
 		return;
 
 	if (late_bind->disable)
 		return;
+	if (!is_runtime)
+		xe_late_bind_wait_for_worker_completion(late_bind);
 
-	xe_late_bind_wait_for_worker_completion(late_bind);
+	xe_late_bind_fw_stop(late_bind);
 }
 
 void xe_late_bind_pm_resume(struct xe_late_bind *late_bind)
diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.h b/drivers/gpu/drm/xe/xe_late_bind_fw.h
index 8896fea3068e5..b441f5789f24b 100644
--- a/drivers/gpu/drm/xe/xe_late_bind_fw.h
+++ b/drivers/gpu/drm/xe/xe_late_bind_fw.h
@@ -9,9 +9,10 @@
 #include <linux/types.h>
 
 struct xe_late_bind;
+struct xe_device;
 
 int xe_late_bind_init(struct xe_late_bind *late_bind);
-void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind);
+void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind, bool is_runtime);
 void xe_late_bind_pm_resume(struct xe_late_bind *late_bind);
-
+int xe_late_bind_ocode_status(struct xe_device *xe);
 #endif
diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw_types.h b/drivers/gpu/drm/xe/xe_late_bind_fw_types.h
index a128e3f638a6c..4cdbd775b103e 100644
--- a/drivers/gpu/drm/xe/xe_late_bind_fw_types.h
+++ b/drivers/gpu/drm/xe/xe_late_bind_fw_types.h
@@ -26,6 +26,20 @@ enum xe_late_bind_fw_id {
 	XE_LB_FW_MAX_ID
 };
 
+/**
+ * enum xe_late_bind_fw_status - enum to determine late binding fw status
+ */
+enum xe_late_bind_fw_status {
+	/** @XE_LB_FW_NOT_SUPPORTED: firmware not available/supported */
+	XE_LB_FW_NOT_SUPPORTED,
+	/** @XE_LB_FW_AVAILABLE: firmware found and copied to memory */
+	XE_LB_FW_AVAILABLE,
+	/** @XE_LB_FW_RUNNING: firmware is running */
+	XE_LB_FW_RUNNING,
+	/** @XE_LB_FW_FAILED: firmware load is failed */
+	XE_LB_FW_FAILED,
+};
+
 /**
  * struct xe_late_bind_fw
  */
@@ -46,6 +60,15 @@ struct xe_late_bind_fw {
 	struct work_struct work;
 	/** @version: late binding blob manifest version */
 	struct gsc_version version;
+	union {
+		/** @status: firmware load status */
+		const enum xe_late_bind_fw_status status;
+		/**
+		 * @__status: private firmware load status - only to be used
+		 * by firmware loading code
+		 */
+		enum xe_late_bind_fw_status __status;
+	};
 };
 
 /**
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index f85b12c1a85d2..9aa873f57b5ad 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -182,7 +182,7 @@ int xe_pm_suspend(struct xe_device *xe)
 	if (err)
 		goto err;
 
-	xe_late_bind_pm_suspend(&xe->late_bind);
+	xe_late_bind_pm_suspend(&xe->late_bind, false);
 
 	for_each_gt(gt, xe, id)
 		xe_gt_suspend_prepare(gt);
@@ -612,6 +612,9 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
 			goto out_resume;
 	}
 
+	if (xe->d3cold.allowed)
+		xe_late_bind_pm_suspend(&xe->late_bind, true);
+
 	xe_irq_suspend(xe);
 
 	xe_display_pm_runtime_suspend_late(xe);
-- 
2.52.0


  parent reply	other threads:[~2026-03-05 10:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-05 10:44 [RFC PATCH 0/4] Add ocode late binding support for CRI Badal Nilawar
2026-03-05 10:44 ` [RFC PATCH 1/4] drm/xe/xe_late_bind_fw: Refactor pm flow Badal Nilawar
2026-03-05 14:20   ` Rodrigo Vivi
2026-03-05 10:44 ` [RFC PATCH 2/4] drm/xe/xe_late_bind_fw: Add support to load Ocode firmware on CRI Badal Nilawar
2026-03-05 23:38   ` Daniele Ceraolo Spurio
2026-03-05 10:44 ` Badal Nilawar [this message]
2026-03-05 23:52   ` [RFC PATCH 3/4] drm/xe/xe_late_bind_fw: Track firmware load status Daniele Ceraolo Spurio
2026-03-05 10:44 ` [RFC PATCH 4/4] drm/xe/xe_late_bind_fw: Enable late binding support for CRI Badal Nilawar
2026-03-06 11:26 ` ✗ CI.KUnit: failure for Add ocode " 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=20260305104441.2857181-9-badal.nilawar@intel.com \
    --to=badal.nilawar@intel.com \
    --cc=alexander.usyskin@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=daniele.ceraolospurio@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=michael.j.ruhl@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