From 36022db40912b86843acdc3f3a81c5cb07eb550c Mon Sep 17 00:00:00 2001 From: jsg Date: Tue, 13 Jun 2023 03:37:20 +0000 Subject: [PATCH] drm/amd: Add a new helper for loading/validating microcode From Mario Limonciello a3e3a640d4fd9d7d40c1737e2b4373b7f4470eab in linux-6.1.y/6.1.29 2210af50ae7f4104269dfde7bafbbfbacdbe1a2b in mainline linux --- sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.c | 36 +++++++++++++++++++++++ sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.h | 3 ++ 2 files changed, 39 insertions(+) diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.c index 4fb96366326..6fbc7f1a855 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.c @@ -1095,3 +1095,39 @@ void amdgpu_ucode_ip_version_decode(struct amdgpu_device *adev, int block_type, snprintf(ucode_prefix, len, "%s_%d_%d_%d", ip_name, maj, min, rev); } + +/* + * amdgpu_ucode_request - Fetch and validate amdgpu microcode + * + * @adev: amdgpu device + * @fw: pointer to load firmware to + * @fw_name: firmware to load + * + * This is a helper that will use request_firmware and amdgpu_ucode_validate + * to load and run basic validation on firmware. If the load fails, remap + * the error code to -ENODEV, so that early_init functions will fail to load. + */ +int amdgpu_ucode_request(struct amdgpu_device *adev, const struct firmware **fw, + const char *fw_name) +{ + int err = request_firmware(fw, fw_name, adev->dev); + + if (err) + return -ENODEV; + err = amdgpu_ucode_validate(*fw); + if (err) + dev_dbg(adev->dev, "\"%s\" failed to validate\n", fw_name); + + return err; +} + +/* + * amdgpu_ucode_release - Release firmware microcode + * + * @fw: pointer to firmware to release + */ +void amdgpu_ucode_release(const struct firmware **fw) +{ + release_firmware(*fw); + *fw = NULL; +} diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.h b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.h index cdbdc6071a8..fd53c10d42a 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.h +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ucode.h @@ -543,6 +543,9 @@ void amdgpu_ucode_print_sdma_hdr(const struct common_firmware_header *hdr); void amdgpu_ucode_print_psp_hdr(const struct common_firmware_header *hdr); void amdgpu_ucode_print_gpu_info_hdr(const struct common_firmware_header *hdr); int amdgpu_ucode_validate(const struct firmware *fw); +int amdgpu_ucode_request(struct amdgpu_device *adev, const struct firmware **fw, + const char *fw_name); +void amdgpu_ucode_release(const struct firmware **fw); bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr, uint16_t hdr_major, uint16_t hdr_minor); -- 2.20.1