From: Lucas De Marchi <lucas.demarchi@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH 6/9] drm/i915/dmc: extract function to parse dmc_header
Date: Fri, 7 Jun 2019 02:12:27 -0700 [thread overview]
Message-ID: <20190607091230.1489-7-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20190607091230.1489-1-lucas.demarchi@intel.com>
Complete the extraction of functions to parse specific parts of the
firmware. The return of the function parse_csr_fw() is now redundant
since it already sets the dmc_payload field. Changing it is left for
later to avoid noise in the commit.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
drivers/gpu/drm/i915/intel_csr.c | 130 ++++++++++++++++++-------------
1 file changed, 74 insertions(+), 56 deletions(-)
diff --git a/drivers/gpu/drm/i915/intel_csr.c b/drivers/gpu/drm/i915/intel_csr.c
index db5772616a4f..1fb42fd44519 100644
--- a/drivers/gpu/drm/i915/intel_csr.c
+++ b/drivers/gpu/drm/i915/intel_csr.c
@@ -332,6 +332,74 @@ static u32 find_dmc_fw_offset(const struct intel_fw_info *fw_info,
return dmc_offset;
}
+static u32 parse_csr_fw_dmc(struct intel_csr *csr,
+ const struct intel_dmc_header *dmc_header,
+ size_t rem_size)
+{
+ unsigned int i, payload_size;
+ u32 r;
+ u8 *payload;
+
+ if (rem_size < sizeof(struct intel_dmc_header))
+ goto error_truncated;
+
+ if (sizeof(struct intel_dmc_header) != dmc_header->header_len) {
+ DRM_ERROR("DMC firmware has wrong dmc header length "
+ "(%u bytes)\n",
+ (dmc_header->header_len));
+ return 0;
+ }
+
+ /* Cache the dmc header info. */
+ if (dmc_header->mmio_count > ARRAY_SIZE(csr->mmioaddr)) {
+ DRM_ERROR("DMC firmware has wrong mmio count %u\n",
+ dmc_header->mmio_count);
+ return 0;
+ }
+
+ csr->mmio_count = dmc_header->mmio_count;
+ for (i = 0; i < dmc_header->mmio_count; i++) {
+ if (dmc_header->mmioaddr[i] < CSR_MMIO_START_RANGE ||
+ dmc_header->mmioaddr[i] > CSR_MMIO_END_RANGE) {
+ DRM_ERROR("DMC firmware has wrong mmio address 0x%x\n",
+ dmc_header->mmioaddr[i]);
+ return 0;
+ }
+ csr->mmioaddr[i] = _MMIO(dmc_header->mmioaddr[i]);
+ csr->mmiodata[i] = dmc_header->mmiodata[i];
+ }
+
+ rem_size -= dmc_header->header_len;
+
+ /* fw_size is in dwords, so multiplied by 4 to convert into bytes. */
+ payload_size = dmc_header->fw_size * 4;
+ if (rem_size < payload_size)
+ goto error_truncated;
+
+ if (payload_size > csr->max_fw_size) {
+ DRM_ERROR("DMC FW too big (%u bytes)\n", payload_size);
+ return 0;
+ }
+ csr->dmc_fw_size = dmc_header->fw_size;
+
+ csr->dmc_payload = kmalloc(payload_size, GFP_KERNEL);
+ if (!csr->dmc_payload) {
+ DRM_ERROR("Memory allocation failed for dmc payload\n");
+ return 0;
+ }
+
+ r = sizeof(struct intel_dmc_header);
+ payload = (u8 *)(dmc_header) + r;
+ memcpy(csr->dmc_payload, payload, payload_size);
+ r += payload_size;
+
+ return r;
+
+error_truncated:
+ DRM_ERROR("Truncated DMC firmware, refusing.\n");
+ return 0;
+}
+
static u32
parse_csr_fw_package(struct intel_csr *csr,
const struct intel_package_header *package_header,
@@ -432,10 +500,8 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,
struct intel_dmc_header *dmc_header;
struct intel_csr *csr = &dev_priv->csr;
const struct stepping_info *si = intel_get_stepping_info(dev_priv);
- u32 readcount = 0, nbytes;
- u32 i, r;
- u32 *dmc_payload;
- size_t fsize;
+ u32 readcount = 0;
+ u32 r;
if (!fw)
return NULL;
@@ -455,62 +521,14 @@ static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,
return NULL;
readcount += r;
- fsize = readcount +
- sizeof(struct intel_dmc_header);
- if (fsize > fw->size)
- goto error_truncated;
- /* Extract dmc_header information. */
+ /* Extract dmc_header information */
dmc_header = (struct intel_dmc_header *)&fw->data[readcount];
- if (sizeof(struct intel_dmc_header) != (dmc_header->header_len)) {
- DRM_ERROR("DMC firmware has wrong dmc header length "
- "(%u bytes)\n",
- (dmc_header->header_len));
- return NULL;
- }
- readcount += sizeof(struct intel_dmc_header);
-
- /* Cache the dmc header info. */
- if (dmc_header->mmio_count > ARRAY_SIZE(csr->mmioaddr)) {
- DRM_ERROR("DMC firmware has wrong mmio count %u\n",
- dmc_header->mmio_count);
- return NULL;
- }
- csr->mmio_count = dmc_header->mmio_count;
- for (i = 0; i < dmc_header->mmio_count; i++) {
- if (dmc_header->mmioaddr[i] < CSR_MMIO_START_RANGE ||
- dmc_header->mmioaddr[i] > CSR_MMIO_END_RANGE) {
- DRM_ERROR("DMC firmware has wrong mmio address 0x%x\n",
- dmc_header->mmioaddr[i]);
- return NULL;
- }
- csr->mmioaddr[i] = _MMIO(dmc_header->mmioaddr[i]);
- csr->mmiodata[i] = dmc_header->mmiodata[i];
- }
-
- /* fw_size is in dwords, so multiplied by 4 to convert into bytes. */
- nbytes = dmc_header->fw_size * 4;
- fsize += nbytes;
- if (fsize > fw->size)
- goto error_truncated;
-
- if (nbytes > csr->max_fw_size) {
- DRM_ERROR("DMC FW too big (%u bytes)\n", nbytes);
- return NULL;
- }
- csr->dmc_fw_size = dmc_header->fw_size;
-
- dmc_payload = kmalloc(nbytes, GFP_KERNEL);
- if (!dmc_payload) {
- DRM_ERROR("Memory allocation failed for dmc payload\n");
+ r = parse_csr_fw_dmc(csr, dmc_header, fw->size - readcount);
+ if (!r)
return NULL;
- }
- return memcpy(dmc_payload, &fw->data[readcount], nbytes);
-
-error_truncated:
- DRM_ERROR("Truncated DMC firmware, rejecting.\n");
- return NULL;
+ return csr->dmc_payload;
}
static void intel_csr_runtime_pm_get(struct drm_i915_private *dev_priv)
--
2.21.0
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-06-07 9:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-07 9:12 [PATCH 0/9] Add support for new DMC headers Lucas De Marchi
2019-06-07 9:12 ` [PATCH 1/9] drm/i915/dmc: use kernel types Lucas De Marchi
2019-06-07 9:12 ` [PATCH 2/9] drm/i915/dmc: extract fw_info and table walk from intel_package_header Lucas De Marchi
2019-06-10 18:16 ` Srivatsa, Anusha
2019-06-07 9:12 ` [PATCH 3/9] drm/i915/dmc: add support for package_header with version 2 Lucas De Marchi
2019-06-10 18:22 ` Srivatsa, Anusha
2019-06-07 9:12 ` [PATCH 4/9] drm/i915/dmc: extract function to parse css header Lucas De Marchi
2019-06-14 19:30 ` Srivatsa, Anusha
2019-06-07 9:12 ` [PATCH 5/9] drm/i915/dmc: extract function to parse package_header Lucas De Marchi
2019-06-14 20:09 ` Srivatsa, Anusha
2019-06-07 9:12 ` Lucas De Marchi [this message]
2019-06-14 20:24 ` [PATCH 6/9] drm/i915/dmc: extract function to parse dmc_header Srivatsa, Anusha
2019-06-07 9:12 ` [PATCH 7/9] drm/i915/dmc: add support to load dmc_header version 3 Lucas De Marchi
2019-06-14 20:03 ` Srivatsa, Anusha
2019-06-07 9:12 ` [PATCH 8/9] drm/i915/dmc: remove redundant return in parse_csr_fw() Lucas De Marchi
2019-06-14 19:51 ` Srivatsa, Anusha
2019-06-07 9:12 ` [PATCH 9/9] drm/i915/dmc: protect against loading wrong firmware Lucas De Marchi
2019-06-14 19:44 ` Srivatsa, Anusha
2019-06-14 21:37 ` Lucas De Marchi
2019-06-17 17:46 ` Srivatsa, Anusha
2019-06-07 10:40 ` ✓ Fi.CI.BAT: success for Add support for new DMC headers Patchwork
2019-06-09 17:17 ` ✓ Fi.CI.IGT: " 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=20190607091230.1489-7-lucas.demarchi@intel.com \
--to=lucas.demarchi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox