From: Peter Antoine Subject: Re: [PATCH v3 2/6] drm/i915/huc: Unified css_header struct for GuC and HuC Date: Thu, 7 Jul 2016 11:09:33 +0100 (BST) Message-ID: References: <1467815071-35665-1-git-send-email-peter.antoine@intel.com> <1467815071-35665-2-git-send-email-peter.antoine@intel.com> <1467837650.26811.210.camel@intel.com> Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1934284396-1467886175=:2912" Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DFDC6E1A3 for ; Thu, 7 Jul 2016 10:09:36 +0000 (UTC) In-Reply-To: <1467837650.26811.210.camel@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: "Vivi, Rodrigo" Cc: "intel-gfx@lists.freedesktop.org" , "yu.dai@intel.com" List-Id: intel-gfx@lists.freedesktop.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1934284396-1467886175=:2912 Content-Type: TEXT/PLAIN; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On Wed, 6 Jul 2016, Vivi, Rodrigo wrote: > On Wed, 2016-07-06 at 15:24 +0100, Peter Antoine wrote: >> HuC firmware css header has almost exactly same definition as GuC >> firmware except for the sw_version. Also, add a new member fw_type >> into intel_uc_fw to indicate what kind of fw it is. So, the loader >> will pull right sw_version from header. >> >> v2: rebased on-top of drm-intel-nightly >> v3: rebased on-top of drm-intel-nightly (again). >> >> Signed-off-by: Alex Dai >> Signed-off-by: Peter Antoine >> --- >> =C2=A0drivers/gpu/drm/i915/intel_guc.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0|=C2=A0=C2=A04 ++++ >> =C2=A0drivers/gpu/drm/i915/intel_guc_fwif.h=C2=A0=C2=A0=C2=A0| 16 ++++= ++++++--- >> =C2=A0drivers/gpu/drm/i915/intel_guc_loader.c | 40 +++++++++++++++++++= +++- >> ---------- >> =C2=A03 files changed, 44 insertions(+), 16 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/intel_guc.h >> b/drivers/gpu/drm/i915/intel_guc.h >> index 02adcfc..ebf9c8d 100644 >> --- a/drivers/gpu/drm/i915/intel_guc.h >> +++ b/drivers/gpu/drm/i915/intel_guc.h >> @@ -97,6 +97,9 @@ enum intel_uc_fw_status { >> =C2=A0 UC_FIRMWARE_SUCCESS >> =C2=A0}; >> =C2=A0 >> +#define UC_FW_TYPE_GUC 0 >> +#define UC_FW_TYPE_HUC 1 >> + Yes. I'll change it. Peter. > > couldn't this be an enum? > >> =C2=A0/* >> =C2=A0 * This structure encapsulates all the data needed during the >> process >> =C2=A0 * of fetching, caching, and loading the firmware image into the >> GuC. >> @@ -114,6 +117,7 @@ struct intel_uc_fw { >> =C2=A0 uint16_t major_ver_found; >> =C2=A0 uint16_t minor_ver_found; >> =C2=A0 >> + uint32_t fw_type; >> =C2=A0 uint32_t header_size; >> =C2=A0 uint32_t header_offset; >> =C2=A0 uint32_t rsa_size; >> diff --git a/drivers/gpu/drm/i915/intel_guc_fwif.h >> b/drivers/gpu/drm/i915/intel_guc_fwif.h >> index 944786d..a69ee36 100644 >> --- a/drivers/gpu/drm/i915/intel_guc_fwif.h >> +++ b/drivers/gpu/drm/i915/intel_guc_fwif.h >> @@ -154,7 +154,7 @@ >> =C2=A0 * The GuC firmware layout looks like this: >> =C2=A0 * >> =C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0+-------------------------------= + >> - *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0|=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0guc_css_header=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0| >> + *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0|=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0uc_css_header=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0| >> =C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0| contains major/minor version=C2= =A0=C2=A0| >> =C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0+-------------------------------= + >> =C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0|=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0uCode=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0| >> @@ -180,9 +180,16 @@ >> =C2=A0 * 3. Length info of each component can be found in header, in >> dwords. >> =C2=A0 * 4. Modulus and exponent key are not required by driver. They = may >> not appear >> =C2=A0 * in fw. So driver will load a truncated firmware in this case. >> + * >> + * HuC firmware layout is same as GuC firmware. >> + * >> + * HuC firmware css header is different. However, the only >> difference is where >> + * the version information is saved. The uc_css_header is unified to >> support >> + * both. Driver should get HuC version from >> uc_css_header.huc_sw_version, while >> + * uc_css_header.guc_sw_version for GuC. >> =C2=A0 */ >> =C2=A0 >> -struct guc_css_header { >> +struct uc_css_header { >> =C2=A0 uint32_t module_type; >> =C2=A0 /* header_size includes all non-uCode bits, including >> css_header, rsa >> =C2=A0 =C2=A0* key, modulus key and exponent data. */ >> @@ -213,7 +220,10 @@ struct guc_css_header { >> =C2=A0 >> =C2=A0 char username[8]; >> =C2=A0 char buildnumber[12]; >> - uint32_t device_id; >> + union { >> + uint32_t device_id; >> + uint32_t huc_sw_version; >> + }; >> =C2=A0 uint32_t guc_sw_version; >> =C2=A0 uint32_t prod_preprod_fw; >> =C2=A0 uint32_t reserved[12]; >> diff --git a/drivers/gpu/drm/i915/intel_guc_loader.c >> b/drivers/gpu/drm/i915/intel_guc_loader.c >> index 1afa49b..42b6509 100644 >> --- a/drivers/gpu/drm/i915/intel_guc_loader.c >> +++ b/drivers/gpu/drm/i915/intel_guc_loader.c >> @@ -553,7 +553,7 @@ void intel_uc_fw_fetch(struct drm_device *dev, >> struct intel_uc_fw *uc_fw) >> =C2=A0{ >> =C2=A0 struct drm_i915_gem_object *obj; >> =C2=A0 const struct firmware *fw; >> - struct guc_css_header *css; >> + struct uc_css_header *css; >> =C2=A0 size_t size; >> =C2=A0 int err; >> =C2=A0 >> @@ -570,19 +570,19 @@ void intel_uc_fw_fetch(struct drm_device *dev, >> struct intel_uc_fw *uc_fw) >> =C2=A0 uc_fw->uc_fw_path, fw); >> =C2=A0 >> =C2=A0 /* Check the size of the blob before examining buffer >> contents */ >> - if (fw->size < sizeof(struct guc_css_header)) { >> + if (fw->size < sizeof(struct uc_css_header)) { >> =C2=A0 DRM_ERROR("Firmware header is missing\n"); >> =C2=A0 goto fail; >> =C2=A0 } >> =C2=A0 >> - css =3D (struct guc_css_header *)fw->data; >> + css =3D (struct uc_css_header *)fw->data; >> =C2=A0 >> =C2=A0 /* Firmware bits always start from header */ >> =C2=A0 uc_fw->header_offset =3D 0; >> =C2=A0 uc_fw->header_size =3D (css->header_size_dw - css- >>> modulus_size_dw - >> =C2=A0 css->key_size_dw - css->exponent_size_dw) * >> sizeof(u32); >> =C2=A0 >> - if (uc_fw->header_size !=3D sizeof(struct guc_css_header)) { >> + if (uc_fw->header_size !=3D sizeof(struct uc_css_header)) { >> =C2=A0 DRM_ERROR("CSS header definition mismatch\n"); >> =C2=A0 goto fail; >> =C2=A0 } >> @@ -606,21 +606,35 @@ void intel_uc_fw_fetch(struct drm_device *dev, >> struct intel_uc_fw *uc_fw) >> =C2=A0 goto fail; >> =C2=A0 } >> =C2=A0 >> - /* Header and uCode will be loaded to WOPCM. Size of the >> two. */ >> - size =3D uc_fw->header_size + uc_fw->ucode_size; >> - if (size > guc_wopcm_size(to_i915(dev))) { >> - DRM_ERROR("Firmware is too large to fit in >> WOPCM\n"); >> - goto fail; >> - } >> - >> =C2=A0 /* >> =C2=A0 =C2=A0* The GuC firmware image has the version number embedded = at >> a well-known >> =C2=A0 =C2=A0* offset within the firmware blob; note that major / mino= r >> version are >> =C2=A0 =C2=A0* TWO bytes each (i.e. u16), although all pointers and >> offsets are defined >> =C2=A0 =C2=A0* in terms of bytes (u8). >> =C2=A0 =C2=A0*/ >> - uc_fw->major_ver_found =3D css->guc_sw_version >> 16; >> - uc_fw->minor_ver_found =3D css->guc_sw_version & 0xFFFF; >> + switch (uc_fw->fw_type) { >> + case UC_FW_TYPE_GUC: >> + /* Header and uCode will be loaded to WOPCM. Size of >> the two. */ >> + size =3D uc_fw->header_size + uc_fw->ucode_size; >> + >> + /* Top 32k of WOPCM is reserved (8K stack + 24k RC6 >> context). */ >> + if (size > guc_wopcm_size(to_i915(dev))) { >> + DRM_ERROR("Firmware is too large to fit in >> WOPCM\n"); >> + goto fail; >> + } >> + >> + uc_fw->major_ver_found =3D css->guc_sw_version >> 16; >> + uc_fw->minor_ver_found =3D css->guc_sw_version & >> 0xFFFF; >> + break; >> + case UC_FW_TYPE_HUC: >> + uc_fw->major_ver_found =3D css->huc_sw_version >> 16; >> + uc_fw->minor_ver_found =3D css->huc_sw_version & >> 0xFFFF; >> + break; >> + default: >> + DRM_ERROR("Unknown firmware type %d\n", uc_fw- >>> fw_type); >> + err =3D -ENOEXEC; >> + goto fail; >> + } >> =C2=A0 >> =C2=A0 if (uc_fw->major_ver_found !=3D uc_fw->major_ver_wanted || >> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0uc_fw->minor_ver_found < uc_fw->minor_v= er_wanted) { -- Peter Antoine (Android Graphics Driver Software Engineer) --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 --8323329-1934284396-1467886175=:2912 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSW50ZWwtZ2Z4 IG1haWxpbmcgbGlzdApJbnRlbC1nZnhAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vaW50ZWwtZ2Z4Cg== --8323329-1934284396-1467886175=:2912--