Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Badal Nilawar <badal.nilawar@intel.com>
To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, rodrigo.vivi@intel.com,
	alexander.usyskin@intel.com, gregkh@linuxfoundation.org,
	daniele.ceraolospurio@intel.com, jgg@nvidia.com
Subject: [PATCH v2 04/10] drm/xe/xe_late_bind_fw: Initialize late binding firmware
Date: Fri,  6 Jun 2025 23:27:01 +0530	[thread overview]
Message-ID: <20250606175707.1403384-5-badal.nilawar@intel.com> (raw)
In-Reply-To: <20250606175707.1403384-1-badal.nilawar@intel.com>

Search for late binding firmware binaries and populate the meta data of
firmware structures.

v2:
 - drm_err if firmware size is more than max pay load size (Daniele)
 - s/request_firmware/firmware_request_nowarn/ as firmware will
   not be available for all possible cards (Daniele)

Signed-off-by: Badal Nilawar <badal.nilawar@intel.com>
---
 drivers/gpu/drm/xe/xe_device.c             |  2 +
 drivers/gpu/drm/xe/xe_late_bind_fw.c       | 86 +++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_late_bind_fw.h       |  1 +
 drivers/gpu/drm/xe/xe_late_bind_fw_types.h | 37 ++++++++++
 4 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index e062ddaa83bb..df4b0e038a6d 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -891,6 +891,8 @@ int xe_device_probe(struct xe_device *xe)
 
 	xe_late_bind_init(&xe->late_bind);
 
+	xe_late_bind_fw_init(&xe->late_bind);
+
 	err = xe_oa_init(xe);
 	if (err)
 		return err;
diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c b/drivers/gpu/drm/xe/xe_late_bind_fw.c
index 22eb9b51b4ee..0231f3dcfc18 100644
--- a/drivers/gpu/drm/xe/xe_late_bind_fw.c
+++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c
@@ -5,6 +5,7 @@
 
 #include <linux/component.h>
 #include <linux/delay.h>
+#include <linux/firmware.h>
 
 #include <drm/drm_managed.h>
 #include <drm/intel/i915_component.h>
@@ -13,13 +14,94 @@
 
 #include "xe_device.h"
 #include "xe_late_bind_fw.h"
+#include "xe_pcode.h"
+#include "xe_pcode_api.h"
 
-static struct xe_device *
-late_bind_to_xe(struct xe_late_bind *late_bind)
+static const char * const fw_type_to_name[] = {
+		[CSC_LATE_BINDING_TYPE_FAN_CONTROL] = "fan_control",
+	};
+
+static struct xe_device *late_bind_to_xe(struct xe_late_bind *late_bind)
 {
 	return container_of(late_bind, struct xe_device, late_bind);
 }
 
+static int late_bind_fw_num_fans(struct xe_late_bind *late_bind)
+{
+	struct xe_device *xe = late_bind_to_xe(late_bind);
+	struct xe_tile *root_tile = xe_device_get_root_tile(xe);
+	u32 uval;
+
+	if (!xe_pcode_read(root_tile,
+			   PCODE_MBOX(FAN_SPEED_CONTROL, FSC_READ_NUM_FANS, 0), &uval, NULL))
+		return uval;
+	else
+		return 0;
+}
+
+static int late_bind_fw_init(struct xe_late_bind *late_bind, u32 type)
+{
+	struct xe_device *xe = late_bind_to_xe(late_bind);
+	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+	struct xe_late_bind_fw *lb_fw;
+	const struct firmware *fw;
+	u32 num_fans;
+	int ret;
+
+	if (!late_bind->component_added)
+		return 0;
+
+	lb_fw = &late_bind->late_bind_fw;
+
+	lb_fw->type = type;
+	lb_fw->valid = false;
+
+	if (lb_fw->type == CSC_LATE_BINDING_TYPE_FAN_CONTROL) {
+		num_fans = late_bind_fw_num_fans(late_bind);
+		drm_dbg(&xe->drm, "Number of Fans: %d\n", num_fans);
+		if (!num_fans)
+			return 0;
+	}
+
+	lb_fw->flags = CSC_LATE_BINDING_FLAGS_IS_PERSISTENT;
+
+	snprintf(lb_fw->blob_path, sizeof(lb_fw->blob_path), "xe/%s_8086_%04x_%04x_%04x.bin",
+		 fw_type_to_name[type], pdev->device,
+		 pdev->subsystem_vendor, pdev->subsystem_device);
+
+	drm_dbg(&xe->drm, "Request late binding firmware %s\n", lb_fw->blob_path);
+	ret = firmware_request_nowarn(&fw, lb_fw->blob_path, xe->drm.dev);
+	if (ret) {
+		drm_dbg(&xe->drm, "Failed to request %s\n", lb_fw->blob_path);
+		return 0;
+	}
+
+	if (fw->size > MAX_PAYLOAD_SIZE) {
+		lb_fw->payload_size = MAX_PAYLOAD_SIZE;
+		drm_err(&xe->drm, "Firmware %s size %zu is larger than max pay load size %u\n",
+			lb_fw->blob_path, fw->size, MAX_PAYLOAD_SIZE);
+		return 0;
+	}
+
+	lb_fw->payload_size = fw->size;
+
+	memcpy(lb_fw->payload, fw->data, lb_fw->payload_size);
+	release_firmware(fw);
+	lb_fw->valid = true;
+
+	return 0;
+}
+
+/**
+ * xe_mei_late_bind_fw_init() - Initialize late bind firmware
+ *
+ * Return: 0 if the initialization was successful, a negative errno otherwise.
+ */
+int xe_late_bind_fw_init(struct xe_late_bind *late_bind)
+{
+	return late_bind_fw_init(late_bind, CSC_LATE_BINDING_TYPE_FAN_CONTROL);
+}
+
 static int xe_late_bind_component_bind(struct device *xe_kdev,
 				       struct device *mei_kdev, void *data)
 {
diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.h b/drivers/gpu/drm/xe/xe_late_bind_fw.h
index 4c73571c3e62..a8b47523b203 100644
--- a/drivers/gpu/drm/xe/xe_late_bind_fw.h
+++ b/drivers/gpu/drm/xe/xe_late_bind_fw.h
@@ -11,5 +11,6 @@
 struct xe_late_bind;
 
 int xe_late_bind_init(struct xe_late_bind *late_bind);
+int xe_late_bind_fw_init(struct xe_late_bind *late_bind);
 
 #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 afa1917b5f51..c427e141c685 100644
--- a/drivers/gpu/drm/xe/xe_late_bind_fw_types.h
+++ b/drivers/gpu/drm/xe/xe_late_bind_fw_types.h
@@ -10,6 +10,41 @@
 #include <linux/mutex.h>
 #include <linux/types.h>
 
+#define MAX_PAYLOAD_SIZE (1024 * 4)
+
+/**
+ * xe_late_bind_fw_type - enum to determine late binding fw type
+ */
+enum xe_late_bind_type {
+	CSC_LATE_BINDING_TYPE_FAN_CONTROL = 1,
+};
+
+/**
+ * Late Binding flags
+ */
+enum csc_late_binding_flags {
+	/** Persistent across warm reset */
+	CSC_LATE_BINDING_FLAGS_IS_PERSISTENT = 0x1
+};
+
+/**
+ * struct xe_late_bind_fw
+ */
+struct xe_late_bind_fw {
+	/** @late_bind_fw.valid */
+	bool valid;
+	/** @late_bind_fw.blob_path: late binding fw blob path */
+	char blob_path[PATH_MAX];
+	/** @late_bind_fw.type */
+	u32  type;
+	/** @late_bind_fw.flags */
+	u32  flags;
+	/** @late_bind_fw.payload: to store the late binding blob */
+	u8  payload[MAX_PAYLOAD_SIZE];
+	/** @late_bind_fw.payload_size: late binding blob payload_size */
+	size_t payload_size;
+};
+
 /**
  * struct xe_late_bind_component - Late Binding services component
  * @mei_dev: device that provide Late Binding service.
@@ -34,6 +69,8 @@ struct xe_late_bind {
 	bool component_added;
 	/** @late_bind.mutex: protects the component binding and usage */
 	struct mutex mutex;
+	/** @late_bind.late_bind_fw: late binding firmware */
+	struct xe_late_bind_fw late_bind_fw;
 };
 
 #endif
-- 
2.34.1


  parent reply	other threads:[~2025-06-06 17:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06 17:56 [PATCH v2 00/10] Introducing firmware late binding Badal Nilawar
2025-06-06 17:56 ` [PATCH v2 01/10] mei: bus: add mei_cldev_mtu interface Badal Nilawar
2025-06-15 18:19   ` Umesh Nerlige Ramappa
2025-06-06 17:56 ` [PATCH v2 02/10] mei: late_bind: add late binding component driver Badal Nilawar
2025-06-14  8:02   ` Gupta, Anshuman
2025-06-16 15:13     ` Nilawar, Badal
2025-06-06 17:57 ` [PATCH v2 03/10] drm/xe/xe_late_bind_fw: Introducing xe_late_bind_fw Badal Nilawar
2025-06-10 21:47   ` Daniele Ceraolo Spurio
2025-06-14  9:57   ` Gupta, Anshuman
2025-06-06 17:57 ` Badal Nilawar [this message]
2025-06-11  0:06   ` [PATCH v2 04/10] drm/xe/xe_late_bind_fw: Initialize late binding firmware Daniele Ceraolo Spurio
2025-06-12 10:35     ` Nilawar, Badal
2025-06-12 15:11       ` Nilawar, Badal
2025-06-06 17:57 ` [PATCH v2 05/10] drm/xe/xe_late_bind_fw: Load " Badal Nilawar
2025-06-11  0:17   ` Daniele Ceraolo Spurio
2025-06-12 11:54     ` Usyskin, Alexander
2025-06-12 13:26       ` Nilawar, Badal
2025-06-12 13:31     ` Nilawar, Badal
2025-06-15 18:26   ` Umesh Nerlige Ramappa
2025-06-17  9:00     ` Nilawar, Badal
2025-06-06 17:57 ` [PATCH v2 06/10] drm/xe/xe_late_bind_fw: Reload late binding fw in rpm resume Badal Nilawar
2025-06-06 17:57 ` [PATCH v2 07/10] drm/xe/xe_late_bind_fw: Reload late binding fw in S2Idle/S3 resume Badal Nilawar
2025-06-06 17:57 ` [PATCH v2 08/10] drm/xe/xe_late_bind_fw: Introduce debug fs node to disable late binding Badal Nilawar
2025-06-12 21:28   ` Daniele Ceraolo Spurio
2025-06-06 17:57 ` [PATCH v2 09/10] {fwctl,drm}/xe/pcode: Introduce xe_pcode_fwctl Badal Nilawar
2025-06-16 14:42   ` Rodrigo Vivi
2025-06-06 17:57 ` [PATCH v2 10/10] [CI]drm/xe/xe_late_bind_fw: Select INTEL_MEI_LATE_BIND for CI Do not review Badal Nilawar
2025-06-07  8:02   ` kernel test robot

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=20250606175707.1403384-5-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=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jgg@nvidia.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