Commit 1bfe5e77 authored by Yang Wang's avatar Yang Wang Committed by Alex Deucher

drm/amdgpu: enhance amdgpu_ucode_request() function flexibility

v1:
Adding formatting string feature to improve function flexibility.

v2:
modify macro name to ADMGPU_UCODE_MAX_NAME.
Signed-off-by: default avatarYang Wang <kevinyang.wang@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 37f43248
......@@ -28,6 +28,8 @@
#include "amdgpu.h"
#include "amdgpu_ucode.h"
#define AMDGPU_UCODE_NAME_MAX (128)
static void amdgpu_ucode_print_common_hdr(const struct common_firmware_header *hdr)
{
DRM_DEBUG("size_bytes: %u\n", le32_to_cpu(hdr->size_bytes));
......@@ -1427,28 +1429,40 @@ void amdgpu_ucode_ip_version_decode(struct amdgpu_device *adev, int block_type,
*
* @adev: amdgpu device
* @fw: pointer to load firmware to
* @fw_name: firmware to load
* @fmt: firmware name format string
* @...: variable arguments
*
* 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)
const char *fmt, ...)
{
int err = request_firmware(fw, fw_name, adev->dev);
char fname[AMDGPU_UCODE_NAME_MAX];
va_list ap;
int r;
va_start(ap, fmt);
r = vsnprintf(fname, sizeof(fname), fmt, ap);
va_end(ap);
if (r == sizeof(fname)) {
dev_warn(adev->dev, "amdgpu firmware name buffer overflow\n");
return -EOVERFLOW;
}
if (err)
r = request_firmware(fw, fname, adev->dev);
if (r)
return -ENODEV;
err = amdgpu_ucode_validate(*fw);
if (err) {
dev_dbg(adev->dev, "\"%s\" failed to validate\n", fw_name);
r = amdgpu_ucode_validate(*fw);
if (r) {
dev_dbg(adev->dev, "\"%s\" failed to validate\n", fname);
release_firmware(*fw);
*fw = NULL;
}
return err;
return r;
}
/*
......
......@@ -593,8 +593,9 @@ void amdgpu_ucode_print_rlc_hdr(const struct common_firmware_header *hdr);
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);
__printf(3, 4)
int amdgpu_ucode_request(struct amdgpu_device *adev, const struct firmware **fw,
const char *fw_name);
const char *fmt, ...);
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);
......
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