[Intel-gfx] [PATCH 05/18] drm/i915: Add firmware version check

yu.dai at intel.com yu.dai at intel.com
Thu Mar 26 12:41:12 PDT 2015


From: Alex Dai <yu.dai at intel.com>

Set the firmware version that required by HW. Driver sets required
version according to platform. After firmware is loaded but before
send to HW, the major.minor version is read from CSS header field,
which is 17th DWORD currently. The major version must be same; the
minor version must be newer than required.

Currently the GuC fw version is 1.0.

Issue: VIZ-4884
Signed-off-by: Alex Dai <yu.dai at intel.com>
---
 drivers/gpu/drm/i915/intel_guc.h        |  1 +
 drivers/gpu/drm/i915/intel_guc_loader.c | 41 +++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/intel_uc_loader.c  |  6 ++++-
 drivers/gpu/drm/i915/intel_uc_loader.h  |  4 ++++
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_guc.h b/drivers/gpu/drm/i915/intel_guc.h
index d8e7c00..a06a7b3 100644
--- a/drivers/gpu/drm/i915/intel_guc.h
+++ b/drivers/gpu/drm/i915/intel_guc.h
@@ -50,6 +50,7 @@ struct intel_guc {
 
 #define UOS_RSA_SCRATCH_0	0xc200
 #define   UOS_RSA_SIG_SIZE	0x100
+#define   UOS_VERSION_OFFSET	0x11
 #define DMA_ADDR_0_LOW		0xc300
 #define DMA_ADDR_0_HIGH		0xc304
 #define DMA_ADDR_1_LOW		0xc308
diff --git a/drivers/gpu/drm/i915/intel_guc_loader.c b/drivers/gpu/drm/i915/intel_guc_loader.c
index 91af710..b9923b7 100644
--- a/drivers/gpu/drm/i915/intel_guc_loader.c
+++ b/drivers/gpu/drm/i915/intel_guc_loader.c
@@ -248,16 +248,53 @@ fail:
 	return err;
 }
 
+/*
+ * Check the firmware that was found; return TRUE if acceptable.
+ *
+ * For the GuC, we just check the version number embedded at a well-known
+ * offset within the firmware blob; note that UOS_RSA_SIG_SIZE is given
+ * in *bytes*, whereas UOS_VERSION_OFFSET is in DWords!
+ */
+static bool intel_guc_ucode_check(struct intel_uc_fw *guc_fw)
+{
+	uint32_t *data = (void *)(guc_fw->uc_fw_blob->data + UOS_RSA_SIG_SIZE);
+	uint32_t version, major, minor;
+
+	version = data[UOS_VERSION_OFFSET];
+	major = version >> 16;
+	minor = version & 0xFFFF;
+
+	if (major == guc_fw->uc_fw_ver_major &&
+	    minor >= guc_fw->uc_fw_ver_minor) {
+		DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n",
+			 major, minor,
+			 guc_fw->uc_fw_ver_major, guc_fw->uc_fw_ver_minor);
+		return true;
+	}
+
+	DRM_ERROR("GuC firmware version %d.%d, required %d.%d\n",
+		 major, minor,
+		 guc_fw->uc_fw_ver_major, guc_fw->uc_fw_ver_minor);
+	return false;
+}
+
 void intel_guc_ucode_init(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_uc_fw *guc_fw = &dev_priv->guc.guc_fw;
 	const char *path = NULL;
 
-	if (IS_GEN8(dev))
+	if (IS_GEN8(dev)) {
 		path = I915_GUC_UCODE_GEN8;
-	else if (IS_GEN9(dev))
+		guc_fw->uc_fw_ver_major = 1;
+		guc_fw->uc_fw_ver_minor = 0;
+		guc_fw->uc_fw_check = intel_guc_ucode_check;
+	} else if (IS_GEN9(dev)) {
 		path = I915_GUC_UCODE_GEN9;
+		guc_fw->uc_fw_ver_major = 1;
+		guc_fw->uc_fw_ver_minor = 0;
+		guc_fw->uc_fw_check = intel_guc_ucode_check;
+	}
 
 	intel_uc_fw_init(dev, guc_fw, "GuC", path, HAS_GUC_UCODE(dev));
 }
diff --git a/drivers/gpu/drm/i915/intel_uc_loader.c b/drivers/gpu/drm/i915/intel_uc_loader.c
index 249e56e..986dcf3 100644
--- a/drivers/gpu/drm/i915/intel_uc_loader.c
+++ b/drivers/gpu/drm/i915/intel_uc_loader.c
@@ -49,10 +49,12 @@ static void uc_fw_finish(struct drm_device *dev, struct intel_uc_fw *uc_fw)
 		uc_fw->uc_name, uc_fw->uc_fw_fetch_status, uc_fw->uc_fw_blob);
 
 	fw = uc_fw->uc_fw_blob;
-	uc_fw->uc_fw_blob = NULL;
 	if (!fw)
 		goto fail;
 
+	if (uc_fw->uc_fw_check && !uc_fw->uc_fw_check(uc_fw))
+		goto fail;
+
 	obj = i915_gem_alloc_object(dev, round_up(fw->size, PAGE_SIZE));
 	if (!obj)
 		goto fail;
@@ -64,6 +66,7 @@ static void uc_fw_finish(struct drm_device *dev, struct intel_uc_fw *uc_fw)
 	uc_fw->uc_fw_obj = obj;
 	uc_fw->uc_fw_size = fw->size;
 	uc_fw->uc_fw_fetch_status = INTEL_UC_FIRMWARE_SUCCESS;
+	uc_fw->uc_fw_blob = NULL;
 	release_firmware(fw);
 	return;
 
@@ -77,6 +80,7 @@ fail:
 		drm_gem_object_unreference(&obj->base);
 
 	uc_fw->uc_fw_fetch_status = INTEL_UC_FIRMWARE_FAIL;
+	uc_fw->uc_fw_blob = NULL;
 	release_firmware(fw);		/* OK even if fw is NULL */
 }
 
diff --git a/drivers/gpu/drm/i915/intel_uc_loader.h b/drivers/gpu/drm/i915/intel_uc_loader.h
index 661d46a..31bf65c 100644
--- a/drivers/gpu/drm/i915/intel_uc_loader.h
+++ b/drivers/gpu/drm/i915/intel_uc_loader.h
@@ -68,11 +68,15 @@ struct intel_uc_fw {
 	struct drm_i915_gem_object *	uc_fw_obj;
 	enum intel_uc_fw_status		uc_fw_fetch_status;
 	enum intel_uc_fw_status		uc_fw_load_status;
+	uint32_t			uc_fw_ver_major;
+	uint32_t			uc_fw_ver_minor;
+	bool				(*uc_fw_check)(struct intel_uc_fw *);
 };
 
 void intel_uc_fw_init(struct drm_device *dev, struct intel_uc_fw *uc_fw,
 	const char *uc_name, const char *fw_path, bool has_ucode);
 int intel_uc_fw_check(struct drm_device *dev, struct intel_uc_fw *uc_fw);
 void intel_uc_fw_fini(struct drm_device *dev, struct intel_uc_fw *uc_fw);
+bool intel_uc_fw_version_check(struct intel_uc_fw *fw, const char *data);
 
 #endif
-- 
1.9.1



More information about the Intel-gfx mailing list