Commit a9a95523 authored by Daniele Ceraolo Spurio's avatar Daniele Ceraolo Spurio Committed by Rodrigo Vivi

drm/xe/uc: Prepare for parsing of different header types

GSC binaries and newer HuC ones use GSC-style headers instead of the
CSS. In preparation for adding support for such parsing, split out the
current parsing code to its own function, to make it cleaner to add the
new paths. The existing doc section has also been renamed to narrow it
to CSS-based binaries.

v2: new patch in series, split out from next patch for easier reviewing
v3: drop unneeded include (Lucas)
Signed-off-by: default avatarDaniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Alan Previn <alan.previn.teres.alexis@intel.com>
Cc: John Harrison <John.C.Harrison@Intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
parent 8a93b0b4
...@@ -8,7 +8,7 @@ Firmware Layout ...@@ -8,7 +8,7 @@ Firmware Layout
=============== ===============
.. kernel-doc:: drivers/gpu/drm/xe/xe_uc_fw_abi.h .. kernel-doc:: drivers/gpu/drm/xe/xe_uc_fw_abi.h
:doc: Firmware Layout :doc: CSS-based Firmware Layout
Write Once Protected Content Memory (WOPCM) Layout Write Once Protected Content Memory (WOPCM) Layout
================================================== ==================================================
......
...@@ -344,57 +344,22 @@ static int uc_fw_check_version_requirements(struct xe_uc_fw *uc_fw) ...@@ -344,57 +344,22 @@ static int uc_fw_check_version_requirements(struct xe_uc_fw *uc_fw)
return -ENOEXEC; return -ENOEXEC;
} }
int xe_uc_fw_init(struct xe_uc_fw *uc_fw) /* Refer to the "CSS-based Firmware Layout" documentation entry for details */
static int parse_css_header(struct xe_uc_fw *uc_fw, const void *fw_data, size_t fw_size)
{ {
struct xe_device *xe = uc_fw_to_xe(uc_fw); struct xe_device *xe = uc_fw_to_xe(uc_fw);
struct xe_gt *gt = uc_fw_to_gt(uc_fw);
struct xe_tile *tile = gt_to_tile(gt);
struct device *dev = xe->drm.dev;
const struct firmware *fw = NULL;
struct uc_css_header *css; struct uc_css_header *css;
struct xe_bo *obj;
size_t size; size_t size;
int err;
/*
* we use FIRMWARE_UNINITIALIZED to detect checks against uc_fw->status
* before we're looked at the HW caps to see if we have uc support
*/
BUILD_BUG_ON(XE_UC_FIRMWARE_UNINITIALIZED);
xe_assert(xe, !uc_fw->status);
xe_assert(xe, !uc_fw->path);
uc_fw_auto_select(xe, uc_fw);
xe_uc_fw_change_status(uc_fw, uc_fw->path ?
XE_UC_FIRMWARE_SELECTED :
XE_UC_FIRMWARE_NOT_SUPPORTED);
if (!xe_uc_fw_is_supported(uc_fw))
return 0;
uc_fw_override(uc_fw);
/* an empty path means the firmware is disabled */
if (!xe_device_uc_enabled(xe) || !(*uc_fw->path)) {
xe_uc_fw_change_status(uc_fw, XE_UC_FIRMWARE_DISABLED);
drm_dbg(&xe->drm, "%s disabled", xe_uc_fw_type_repr(uc_fw->type));
return 0;
}
err = request_firmware(&fw, uc_fw->path, dev);
if (err)
goto fail;
/* Check the size of the blob before examining buffer contents */ /* Check the size of the blob before examining buffer contents */
if (unlikely(fw->size < sizeof(struct uc_css_header))) { if (unlikely(fw_size < sizeof(struct uc_css_header))) {
drm_warn(&xe->drm, "%s firmware %s: invalid size: %zu < %zu\n", drm_warn(&xe->drm, "%s firmware %s: invalid size: %zu < %zu\n",
xe_uc_fw_type_repr(uc_fw->type), uc_fw->path, xe_uc_fw_type_repr(uc_fw->type), uc_fw->path,
fw->size, sizeof(struct uc_css_header)); fw_size, sizeof(struct uc_css_header));
err = -ENODATA; return -ENODATA;
goto fail;
} }
css = (struct uc_css_header *)fw->data; css = (struct uc_css_header *)fw_data;
/* Check integrity of size values inside CSS header */ /* Check integrity of size values inside CSS header */
size = (css->header_size_dw - css->key_size_dw - css->modulus_size_dw - size = (css->header_size_dw - css->key_size_dw - css->modulus_size_dw -
...@@ -403,9 +368,8 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw) ...@@ -403,9 +368,8 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw)
drm_warn(&xe->drm, drm_warn(&xe->drm,
"%s firmware %s: unexpected header size: %zu != %zu\n", "%s firmware %s: unexpected header size: %zu != %zu\n",
xe_uc_fw_type_repr(uc_fw->type), uc_fw->path, xe_uc_fw_type_repr(uc_fw->type), uc_fw->path,
fw->size, sizeof(struct uc_css_header)); fw_size, sizeof(struct uc_css_header));
err = -EPROTO; return -EPROTO;
goto fail;
} }
/* uCode size must calculated from other sizes */ /* uCode size must calculated from other sizes */
...@@ -417,12 +381,11 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw) ...@@ -417,12 +381,11 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw)
/* At least, it should have header, uCode and RSA. Size of all three. */ /* At least, it should have header, uCode and RSA. Size of all three. */
size = sizeof(struct uc_css_header) + uc_fw->ucode_size + size = sizeof(struct uc_css_header) + uc_fw->ucode_size +
uc_fw->rsa_size; uc_fw->rsa_size;
if (unlikely(fw->size < size)) { if (unlikely(fw_size < size)) {
drm_warn(&xe->drm, "%s firmware %s: invalid size: %zu < %zu\n", drm_warn(&xe->drm, "%s firmware %s: invalid size: %zu < %zu\n",
xe_uc_fw_type_repr(uc_fw->type), uc_fw->path, xe_uc_fw_type_repr(uc_fw->type), uc_fw->path,
fw->size, size); fw_size, size);
err = -ENOEXEC; return -ENOEXEC;
goto fail;
} }
/* Get version numbers from the CSS header */ /* Get version numbers from the CSS header */
...@@ -433,6 +396,60 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw) ...@@ -433,6 +396,60 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw)
uc_fw->patch_ver_found = FIELD_GET(CSS_SW_VERSION_UC_PATCH, uc_fw->patch_ver_found = FIELD_GET(CSS_SW_VERSION_UC_PATCH,
css->sw_version); css->sw_version);
if (uc_fw->type == XE_UC_FW_TYPE_GUC)
guc_read_css_info(uc_fw, css);
return 0;
}
static int parse_headers(struct xe_uc_fw *uc_fw, const struct firmware *fw)
{
return parse_css_header(uc_fw, fw->data, fw->size);
}
int xe_uc_fw_init(struct xe_uc_fw *uc_fw)
{
struct xe_device *xe = uc_fw_to_xe(uc_fw);
struct xe_gt *gt = uc_fw_to_gt(uc_fw);
struct xe_tile *tile = gt_to_tile(gt);
struct device *dev = xe->drm.dev;
const struct firmware *fw = NULL;
struct xe_bo *obj;
int err;
/*
* we use FIRMWARE_UNINITIALIZED to detect checks against uc_fw->status
* before we're looked at the HW caps to see if we have uc support
*/
BUILD_BUG_ON(XE_UC_FIRMWARE_UNINITIALIZED);
xe_assert(xe, !uc_fw->status);
xe_assert(xe, !uc_fw->path);
uc_fw_auto_select(xe, uc_fw);
xe_uc_fw_change_status(uc_fw, uc_fw->path ?
XE_UC_FIRMWARE_SELECTED :
XE_UC_FIRMWARE_NOT_SUPPORTED);
if (!xe_uc_fw_is_supported(uc_fw))
return 0;
uc_fw_override(uc_fw);
/* an empty path means the firmware is disabled */
if (!xe_device_uc_enabled(xe) || !(*uc_fw->path)) {
xe_uc_fw_change_status(uc_fw, XE_UC_FIRMWARE_DISABLED);
drm_dbg(&xe->drm, "%s disabled", xe_uc_fw_type_repr(uc_fw->type));
return 0;
}
err = request_firmware(&fw, uc_fw->path, dev);
if (err)
goto fail;
err = parse_headers(uc_fw, fw);
if (err)
goto fail;
drm_info(&xe->drm, "Using %s firmware from %s version %u.%u.%u\n", drm_info(&xe->drm, "Using %s firmware from %s version %u.%u.%u\n",
xe_uc_fw_type_repr(uc_fw->type), uc_fw->path, xe_uc_fw_type_repr(uc_fw->type), uc_fw->path,
uc_fw->major_ver_found, uc_fw->minor_ver_found, uc_fw->patch_ver_found); uc_fw->major_ver_found, uc_fw->minor_ver_found, uc_fw->patch_ver_found);
...@@ -441,9 +458,6 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw) ...@@ -441,9 +458,6 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw)
if (err) if (err)
goto fail; goto fail;
if (uc_fw->type == XE_UC_FW_TYPE_GUC)
guc_read_css_info(uc_fw, css);
obj = xe_bo_create_from_data(xe, tile, fw->data, fw->size, obj = xe_bo_create_from_data(xe, tile, fw->data, fw->size,
ttm_bo_type_kernel, ttm_bo_type_kernel,
XE_BO_CREATE_VRAM_IF_DGFX(tile) | XE_BO_CREATE_VRAM_IF_DGFX(tile) |
......
...@@ -10,9 +10,12 @@ ...@@ -10,9 +10,12 @@
#include <linux/types.h> #include <linux/types.h>
/** /**
* DOC: Firmware Layout * DOC: CSS-based Firmware Layout
* *
* The GuC/HuC firmware layout looks like this:: * The CSS-based firmware structure is used for GuC releases on all platforms
* and for HuC releases up to DG1. Starting from DG2/MTL the HuC uses the GSC
* layout instead.
* The CSS firmware layout looks like this::
* *
* +======================================================================+ * +======================================================================+
* | Firmware blob | * | Firmware blob |
......
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