Commit 1249dc17 authored by Michał Winiarski's avatar Michał Winiarski Committed by Chris Wilson

drm/i915/uc: Move FW size sanity check back to fetch

While we need to know WOPCM size to do this sanity check, it has more to
do with FW than with WOPCM. Let's move the check to fetch phase, it's
not like WOPCM is going to grow in the meantime.

v2: rebased
v3: use __intel_uc_fw_get_upload_size (Daniele)
Signed-off-by: default avatarMichał Winiarski <michal.winiarski@intel.com>
Signed-off-by: default avatarMichal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Jackie Li <yaodong.li@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: default avatarDaniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20190816105501.31020-2-michal.wajdeczko@intel.com
parent 3ba09632
...@@ -265,6 +265,7 @@ int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw, struct drm_i915_private *i915) ...@@ -265,6 +265,7 @@ int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw, struct drm_i915_private *i915)
size_t size; size_t size;
int err; int err;
GEM_BUG_ON(!i915->wopcm.size);
GEM_BUG_ON(!intel_uc_fw_supported(uc_fw)); GEM_BUG_ON(!intel_uc_fw_supported(uc_fw));
err = i915_inject_load_error(i915, -ENXIO); err = i915_inject_load_error(i915, -ENXIO);
...@@ -324,6 +325,16 @@ int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw, struct drm_i915_private *i915) ...@@ -324,6 +325,16 @@ int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw, struct drm_i915_private *i915)
goto fail; goto fail;
} }
/* Sanity check whether this fw is not larger than whole WOPCM memory */
size = __intel_uc_fw_get_upload_size(uc_fw);
if (unlikely(size >= i915->wopcm.size)) {
dev_warn(dev, "%s firmware %s: invalid size: %zu > %zu\n",
intel_uc_fw_type_repr(uc_fw->type), uc_fw->path,
size, (size_t)i915->wopcm.size);
err = -E2BIG;
goto fail;
}
/* Get version numbers from the CSS header */ /* Get version numbers from the CSS header */
switch (uc_fw->type) { switch (uc_fw->type) {
case INTEL_UC_FW_TYPE_GUC: case INTEL_UC_FW_TYPE_GUC:
......
...@@ -173,6 +173,11 @@ static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw) ...@@ -173,6 +173,11 @@ static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw)
intel_uc_fw_change_status(uc_fw, INTEL_UC_FIRMWARE_AVAILABLE); intel_uc_fw_change_status(uc_fw, INTEL_UC_FIRMWARE_AVAILABLE);
} }
static inline u32 __intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
{
return sizeof(struct uc_css_header) + uc_fw->ucode_size;
}
/** /**
* intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded. * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
* @uc_fw: uC firmware. * @uc_fw: uC firmware.
...@@ -186,7 +191,7 @@ static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw) ...@@ -186,7 +191,7 @@ static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
if (!intel_uc_fw_is_available(uc_fw)) if (!intel_uc_fw_is_available(uc_fw))
return 0; return 0;
return sizeof(struct uc_css_header) + uc_fw->ucode_size; return __intel_uc_fw_get_upload_size(uc_fw);
} }
void intel_uc_fw_init_early(struct intel_uc_fw *uc_fw, void intel_uc_fw_init_early(struct intel_uc_fw *uc_fw,
......
...@@ -181,22 +181,12 @@ void intel_wopcm_init(struct intel_wopcm *wopcm) ...@@ -181,22 +181,12 @@ void intel_wopcm_init(struct intel_wopcm *wopcm)
GEM_BUG_ON(!wopcm->size); GEM_BUG_ON(!wopcm->size);
GEM_BUG_ON(wopcm->guc.base); GEM_BUG_ON(wopcm->guc.base);
GEM_BUG_ON(wopcm->guc.size); GEM_BUG_ON(wopcm->guc.size);
GEM_BUG_ON(guc_fw_size >= wopcm->size);
GEM_BUG_ON(huc_fw_size >= wopcm->size);
if (i915_inject_probe_failure(i915)) if (i915_inject_probe_failure(i915))
return; return;
if (guc_fw_size >= wopcm->size) {
DRM_ERROR("GuC FW (%uKiB) is too big to fit in WOPCM.",
guc_fw_size / 1024);
return;
}
if (huc_fw_size >= wopcm->size) {
DRM_ERROR("HuC FW (%uKiB) is too big to fit in WOPCM.",
huc_fw_size / 1024);
return;
}
guc_wopcm_base = ALIGN(huc_fw_size + WOPCM_RESERVED_SIZE, guc_wopcm_base = ALIGN(huc_fw_size + WOPCM_RESERVED_SIZE,
GUC_WOPCM_OFFSET_ALIGNMENT); GUC_WOPCM_OFFSET_ALIGNMENT);
if ((guc_wopcm_base + ctx_rsvd) >= wopcm->size) { if ((guc_wopcm_base + ctx_rsvd) >= wopcm->size) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment