All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH v2 4/8] drm/i915/uc: Move xfer rsa logic to common function
Date: Tue, 23 Jul 2019 19:21:49 -0700	[thread overview]
Message-ID: <20190724022153.8927-5-daniele.ceraolospurio@intel.com> (raw)
In-Reply-To: <20190724022153.8927-1-daniele.ceraolospurio@intel.com>

The way we copy the RSA is the same for GuC and HuC, so we can move the
logic in a common function. this will also make any update needed for
local memory easier.

v2: return the number of copied bytes and check it (Chris)

Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> #v1
---
 drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c |  7 +++----
 drivers/gpu/drm/i915/gt/uc/intel_huc_fw.c | 10 +++++-----
 drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c  | 18 ++++++++++++++++++
 drivers/gpu/drm/i915/gt/uc/intel_uc_fw.h  |  1 +
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
index 085e7842ef8a..09b0ff2bd256 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
@@ -77,13 +77,12 @@ static void guc_prepare_xfer(struct intel_guc *guc)
 static void guc_xfer_rsa(struct intel_guc *guc)
 {
 	struct intel_uncore *uncore = guc_to_gt(guc)->uncore;
-	struct intel_uc_fw *fw = &guc->fw;
-	struct sg_table *pages = fw->obj->mm.pages;
 	u32 rsa[UOS_RSA_SCRATCH_COUNT];
+	size_t copied;
 	int i;
 
-	sg_pcopy_to_buffer(pages->sgl, pages->nents,
-			   rsa, sizeof(rsa), fw->rsa_offset);
+	copied = intel_uc_fw_copy_rsa(&guc->fw, rsa, sizeof(rsa));
+	GEM_BUG_ON(copied < sizeof(rsa));
 
 	for (i = 0; i < UOS_RSA_SCRATCH_COUNT; i++)
 		intel_uncore_write(uncore, UOS_RSA_SCRATCH(i), rsa[i]);
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_huc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_huc_fw.c
index fa2151fa3a13..8f119ff291fa 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_huc_fw.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_huc_fw.c
@@ -38,17 +38,17 @@ void intel_huc_fw_init_early(struct intel_huc *huc)
 
 static void huc_xfer_rsa(struct intel_huc *huc)
 {
-	struct intel_uc_fw *fw = &huc->fw;
-	struct sg_table *pages = fw->obj->mm.pages;
+	size_t copied;
 
 	/*
 	 * HuC firmware image is outside GuC accessible range.
 	 * Copy the RSA signature out of the image into
 	 * the perma-pinned region set aside for it
 	 */
-	sg_pcopy_to_buffer(pages->sgl, pages->nents,
-			   huc->rsa_data_vaddr, fw->rsa_size,
-			   fw->rsa_offset);
+	GEM_BUG_ON(huc->fw.rsa_size > huc->rsa_data->size);
+	copied = intel_uc_fw_copy_rsa(&huc->fw, huc->rsa_data_vaddr,
+				      huc->rsa_data->size);
+	GEM_BUG_ON(copied < huc->fw.rsa_size);
 }
 
 static int huc_xfer_ucode(struct intel_huc *huc)
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c
index 9fc72c2e50d1..909a8196f9d4 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c
@@ -462,6 +462,24 @@ void intel_uc_fw_cleanup_fetch(struct intel_uc_fw *uc_fw)
 	uc_fw->status = INTEL_UC_FIRMWARE_SELECTION_DONE;
 }
 
+/**
+ * intel_uc_fw_copy_rsa - copy fw RSA to buffer
+ *
+ * @uc_fw: uC firmware
+ * @dst: dst buffer
+ * @max_len: max number of bytes to copy
+ *
+ * Return: number of copied bytes.
+ */
+size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len)
+{
+	struct sg_table *pages = uc_fw->obj->mm.pages;
+	u32 size = min_t(u32, uc_fw->rsa_size, max_len);
+
+	return sg_pcopy_to_buffer(pages->sgl, pages->nents,
+				  dst, size, uc_fw->rsa_offset);
+}
+
 /**
  * intel_uc_fw_dump - dump information about uC firmware
  * @uc_fw: uC firmware
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.h b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.h
index ecdec4320260..572b7873fe19 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.h
+++ b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.h
@@ -177,6 +177,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
 int intel_uc_fw_init(struct intel_uc_fw *uc_fw);
 void intel_uc_fw_fini(struct intel_uc_fw *uc_fw);
 u32 intel_uc_fw_ggtt_offset(struct intel_uc_fw *uc_fw);
+size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len);
 void intel_uc_fw_dump(const struct intel_uc_fw *uc_fw, struct drm_printer *p);
 
 #endif
-- 
2.22.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-07-24  2:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24  2:21 [PATCH v2 0/8] uC fw path unification + misc clean-up Daniele Ceraolo Spurio
2019-07-24  2:21 ` [PATCH v2 1/8] drm/i915/uc: Unify uC platform check Daniele Ceraolo Spurio
2019-07-24 10:30   ` Michal Wajdeczko
2019-07-24  2:21 ` [PATCH v2 2/8] drm/i915/uc: Unify uC FW selection Daniele Ceraolo Spurio
2019-07-24  8:46   ` Chris Wilson
2019-07-24 11:31   ` Michal Wajdeczko
2019-07-24 16:28     ` Daniele Ceraolo Spurio
2019-07-24  2:21 ` [PATCH v2 3/8] drm/i915/uc: Unify uc_fw status tracking Daniele Ceraolo Spurio
2019-07-24 12:35   ` Michal Wajdeczko
2019-07-24 16:37     ` Daniele Ceraolo Spurio
2019-07-24 17:24       ` Michal Wajdeczko
2019-07-24 17:31         ` Daniele Ceraolo Spurio
2019-07-24  2:21 ` Daniele Ceraolo Spurio [this message]
2019-07-24 12:46   ` [PATCH v2 4/8] drm/i915/uc: Move xfer rsa logic to common function Michal Wajdeczko
2019-07-24  2:21 ` [PATCH v2 5/8] drm/i915/huc: Copy huc rsa only once Daniele Ceraolo Spurio
2019-07-24 12:55   ` Michal Wajdeczko
2019-07-24 14:18     ` Chris Wilson
2019-07-24  2:21 ` [PATCH v2 6/8] drm/i915/guc: Set GuC init params " Daniele Ceraolo Spurio
2019-07-24  8:19   ` Chris Wilson
2019-07-24 10:29     ` Chris Wilson
2019-07-24  2:21 ` [PATCH v2 7/8] drm/i915/uc: Plumb the gt through fw_upload Daniele Ceraolo Spurio
2019-07-24  2:21 ` [PATCH v2 8/8] drm/i915/uc: Unify uC firmware upload Daniele Ceraolo Spurio
2019-07-24  8:26   ` Chris Wilson
2019-07-24  2:34 ` ✗ Fi.CI.CHECKPATCH: warning for uC fw path unification + misc clean-up (rev2) Patchwork
2019-07-24  2:39 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-07-24  2:54 ` ✓ Fi.CI.BAT: success " 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=20190724022153.8927-5-daniele.ceraolospurio@intel.com \
    --to=daniele.ceraolospurio@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.