[PATCH v6 1/8] drm/xe/uc_fw: Allow re-initializing firmware

Raag Jadav
2026-04-23T10:03:22Z

In preparation of usecases which require re-initializing firmware without
reloading the driver, introduce xe_uc_fw_reinit(). The uC firmware bo
already exists but since it's contents are on VRAM, they are lost on PCIe
FLR. Copy the firmware back to it's bo and mark it as loadable as part of
re-initialization.

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
Tested-by: Lukasz Laguna <lukasz.laguna@intel.com>
---
v2: Add kernel doc (Matthew Brost)
v6: Skip uC firmware selection during re-initialization (Daniele)
---
drivers/gpu/drm/xe/xe_uc_fw.c | 49 +++++++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_uc_fw.h | 1 +
2 files changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_uc_fw.c b/drivers/gpu/drm/xe/xe_uc_fw.c
index df2aa196f6f9..9bb646ee998b 100644
--- a/drivers/gpu/drm/xe/xe_uc_fw.c
+++ b/drivers/gpu/drm/xe/xe_uc_fw.c
@@ -834,6 +834,14 @@ static int uc_fw_copy(struct xe_uc_fw *uc_fw, const void *data, size_t size, u32
return err;
}

+static void uc_fw_reinit(struct xe_uc_fw *uc_fw, const void *data)
+{
+ struct xe_device *xe = uc_fw_to_xe(uc_fw);
+
+ xe_map_memcpy_to(xe, &uc_fw->bo->vmap, 0, data, uc_fw->size);
+ xe_uc_fw_change_status(uc_fw, XE_UC_FIRMWARE_LOADABLE);
+}
+
int xe_uc_fw_init(struct xe_uc_fw *uc_fw)
{
const struct firmware *fw = NULL;
@@ -857,6 +865,47 @@ int xe_uc_fw_init(struct xe_uc_fw *uc_fw)
}
ALLOW_ERROR_INJECTION(xe_uc_fw_init, ERRNO); /* See xe_pci_probe() */

+/**
+ * xe_uc_fw_reinit() - Re-initialize uC firmware into its bo
+ * @uc_fw: uC firmware
+ *
+ * Returns: 0 on success, negative error code otherwise.
+ */
+int xe_uc_fw_reinit(struct xe_uc_fw *uc_fw)
+{
+ struct xe_device *xe = uc_fw_to_xe(uc_fw);
+ struct xe_uc_fw_version new_fw, old_fw;
+ const struct firmware *fw = NULL;
+ int err;
+
+ /* We shouldn't be here for the firmware which wasn't loaded */
+ xe_assert(xe, xe_uc_fw_is_available(uc_fw));
+
+ old_fw = uc_fw->versions.found[XE_UC_FW_VER_RELEASE];
+
+ err = firmware_request_nowarn(&fw, uc_fw->path, xe->drm.dev);
+ if (err)
+ goto fail;
+
+ err = parse_headers(uc_fw, fw);
+ if (err)
+ goto fail;
+
+ new_fw = uc_fw->versions.found[XE_UC_FW_VER_RELEASE];
+ if (new_fw.branch != old_fw.branch || new_fw.major != old_fw.major ||
+ new_fw.minor != old_fw.minor || new_fw.patch != old_fw.patch ||
+ new_fw.build != old_fw.build || uc_fw->size != fw->size) {
+ drm_err(&xe->drm, "%s firmware mismatch on %s",
+ xe_uc_fw_type_repr(uc_fw->type), uc_fw->path);
+ return -ENOEXEC;
+ }
+
+ uc_fw_reinit(uc_fw, fw->data);
+fail:
+ uc_fw_release(fw);
+ return err;
+}
+
static u32 uc_fw_ggtt_offset(struct xe_uc_fw *uc_fw)
{
return xe_bo_ggtt_addr(uc_fw->bo);
diff --git a/drivers/gpu/drm/xe/xe_uc_fw.h b/drivers/gpu/drm/xe/xe_uc_fw.h
index bb281b72a677..9f469bf07d66 100644
--- a/drivers/gpu/drm/xe/xe_uc_fw.h
+++ b/drivers/gpu/drm/xe/xe_uc_fw.h
@@ -15,6 +15,7 @@
struct drm_printer;

int xe_uc_fw_init(struct xe_uc_fw *uc_fw);
+int xe_uc_fw_reinit(struct xe_uc_fw *uc_fw);
size_t xe_uc_fw_copy_rsa(struct xe_uc_fw *uc_fw, void *dst, u32 max_len);
int xe_uc_fw_upload(struct xe_uc_fw *uc_fw, u32 offset, u32 dma_flags);
int xe_uc_fw_check_version_requirements(struct xe_uc_fw *uc_fw);
--
2.43.0