The `amdgpu_ucode_request` helper will ensure that the return code for
missing firmware is -ENODEV so that early_init can fail.

The `amdgpu_ucode_release` helper is for symmetry on unload.

Reviewed-by: Alex Deucher <alexander.deuc...@amd.com>
Signed-off-by: Mario Limonciello <mario.limoncie...@amd.com>
---
v5->v6:
 * Adjust for amdgpu_ucode_release argument change
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 71 ++++++++------------------
 1 file changed, 20 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
index 49d34c7bbf20..140bb18ff768 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
@@ -3891,18 +3891,12 @@ static int gfx_v10_0_ring_test_ib(struct amdgpu_ring 
*ring, long timeout)
 
 static void gfx_v10_0_free_microcode(struct amdgpu_device *adev)
 {
-       release_firmware(adev->gfx.pfp_fw);
-       adev->gfx.pfp_fw = NULL;
-       release_firmware(adev->gfx.me_fw);
-       adev->gfx.me_fw = NULL;
-       release_firmware(adev->gfx.ce_fw);
-       adev->gfx.ce_fw = NULL;
-       release_firmware(adev->gfx.rlc_fw);
-       adev->gfx.rlc_fw = NULL;
-       release_firmware(adev->gfx.mec_fw);
-       adev->gfx.mec_fw = NULL;
-       release_firmware(adev->gfx.mec2_fw);
-       adev->gfx.mec2_fw = NULL;
+       amdgpu_ucode_release(&adev->gfx.pfp_fw);
+       amdgpu_ucode_release(&adev->gfx.me_fw);
+       amdgpu_ucode_release(&adev->gfx.ce_fw);
+       amdgpu_ucode_release(&adev->gfx.rlc_fw);
+       amdgpu_ucode_release(&adev->gfx.mec_fw);
+       amdgpu_ucode_release(&adev->gfx.mec2_fw);
 
        kfree(adev->gfx.rlc.register_list_format);
 }
@@ -4030,41 +4024,31 @@ static int gfx_v10_0_init_microcode(struct 
amdgpu_device *adev)
        }
 
        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_pfp%s.bin", chip_name, 
wks);
-       err = request_firmware(&adev->gfx.pfp_fw, fw_name, adev->dev);
-       if (err)
-               goto out;
-       err = amdgpu_ucode_validate(adev->gfx.pfp_fw);
+       err = amdgpu_ucode_request(adev, &adev->gfx.pfp_fw, fw_name);
        if (err)
                goto out;
        amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_PFP);
 
        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_me%s.bin", chip_name, 
wks);
-       err = request_firmware(&adev->gfx.me_fw, fw_name, adev->dev);
-       if (err)
-               goto out;
-       err = amdgpu_ucode_validate(adev->gfx.me_fw);
+       err = amdgpu_ucode_request(adev, &adev->gfx.me_fw, fw_name);
        if (err)
                goto out;
        amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_ME);
 
        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ce%s.bin", chip_name, 
wks);
-       err = request_firmware(&adev->gfx.ce_fw, fw_name, adev->dev);
-       if (err)
-               goto out;
-       err = amdgpu_ucode_validate(adev->gfx.ce_fw);
+       err = amdgpu_ucode_request(adev, &adev->gfx.ce_fw, fw_name);
        if (err)
                goto out;
        amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_CE);
 
        if (!amdgpu_sriov_vf(adev)) {
                snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_rlc.bin", 
chip_name);
-               err = request_firmware(&adev->gfx.rlc_fw, fw_name, adev->dev);
-               if (err)
-                       goto out;
+               err = amdgpu_ucode_request(adev, &adev->gfx.rlc_fw, fw_name);
                /* don't check this.  There are apparently firmwares in the 
wild with
                 * incorrect size in the header
                 */
-               err = amdgpu_ucode_validate(adev->gfx.rlc_fw);
+               if (err == -ENODEV)
+                       goto out;
                if (err)
                        dev_dbg(adev->dev,
                                "gfx10: amdgpu_ucode_validate() failed 
\"%s\"\n",
@@ -4078,21 +4062,15 @@ static int gfx_v10_0_init_microcode(struct 
amdgpu_device *adev)
        }
 
        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec%s.bin", chip_name, 
wks);
-       err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev);
-       if (err)
-               goto out;
-       err = amdgpu_ucode_validate(adev->gfx.mec_fw);
+       err = amdgpu_ucode_request(adev, &adev->gfx.mec_fw, fw_name);
        if (err)
                goto out;
        amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC1);
        amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC1_JT);
 
        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec2%s.bin", chip_name, 
wks);
-       err = request_firmware(&adev->gfx.mec2_fw, fw_name, adev->dev);
+       err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw, fw_name);
        if (!err) {
-               err = amdgpu_ucode_validate(adev->gfx.mec2_fw);
-               if (err)
-                       goto out;
                amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
                amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
        } else {
@@ -4103,21 +4081,12 @@ static int gfx_v10_0_init_microcode(struct 
amdgpu_device *adev)
        gfx_v10_0_check_fw_write_wait(adev);
 out:
        if (err) {
-               dev_err(adev->dev,
-                       "gfx10: Failed to init firmware \"%s\"\n",
-                       fw_name);
-               release_firmware(adev->gfx.pfp_fw);
-               adev->gfx.pfp_fw = NULL;
-               release_firmware(adev->gfx.me_fw);
-               adev->gfx.me_fw = NULL;
-               release_firmware(adev->gfx.ce_fw);
-               adev->gfx.ce_fw = NULL;
-               release_firmware(adev->gfx.rlc_fw);
-               adev->gfx.rlc_fw = NULL;
-               release_firmware(adev->gfx.mec_fw);
-               adev->gfx.mec_fw = NULL;
-               release_firmware(adev->gfx.mec2_fw);
-               adev->gfx.mec2_fw = NULL;
+               amdgpu_ucode_release(&adev->gfx.pfp_fw);
+               amdgpu_ucode_release(&adev->gfx.me_fw);
+               amdgpu_ucode_release(&adev->gfx.ce_fw);
+               amdgpu_ucode_release(&adev->gfx.rlc_fw);
+               amdgpu_ucode_release(&adev->gfx.mec_fw);
+               amdgpu_ucode_release(&adev->gfx.mec2_fw);
        }
 
        gfx_v10_0_check_gfxoff_flag(adev);
-- 
2.34.1

Reply via email to