drm/amdgpu/sdma5: use common function to init sdma fw
authorLikun Gao <Likun.Gao@amd.com>
Thu, 22 Sep 2022 06:38:51 +0000 (14:38 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 29 Sep 2022 13:41:43 +0000 (09:41 -0400)
Use common function to init sdma v5 firmware ucode.

Signed-off-by: Likun Gao <Likun.Gao@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c

index a019ac92edb73140310bc544a09e2509774ca06d..c05c3eebde4c7da0c77dcd2cb6a8c4c982686cb2 100644 (file)
@@ -240,10 +240,7 @@ static int sdma_v5_0_init_microcode(struct amdgpu_device *adev)
 {
        const char *chip_name;
        char fw_name[40];
-       int err = 0, i;
-       struct amdgpu_firmware_info *info = NULL;
-       const struct common_firmware_header *header = NULL;
-       const struct sdma_firmware_header_v1_0 *hdr;
+       int ret, i;
 
        if (amdgpu_sriov_vf(adev) && (adev->ip_versions[SDMA0_HWIP][0] == IP_VERSION(5, 0, 5)))
                return 0;
@@ -272,38 +269,12 @@ static int sdma_v5_0_init_microcode(struct amdgpu_device *adev)
                        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma.bin", chip_name);
                else
                        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma1.bin", chip_name);
-               err = request_firmware(&adev->sdma.instance[i].fw, fw_name, adev->dev);
-               if (err)
-                       goto out;
-               err = amdgpu_ucode_validate(adev->sdma.instance[i].fw);
-               if (err)
-                       goto out;
-               hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
-               adev->sdma.instance[i].fw_version = le32_to_cpu(hdr->header.ucode_version);
-               adev->sdma.instance[i].feature_version = le32_to_cpu(hdr->ucode_feature_version);
-               if (adev->sdma.instance[i].feature_version >= 20)
-                       adev->sdma.instance[i].burst_nop = true;
-               DRM_DEBUG("psp_load == '%s'\n",
-                               adev->firmware.load_type == AMDGPU_FW_LOAD_PSP ? "true" : "false");
-
-               if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
-                       info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i];
-                       info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i;
-                       info->fw = adev->sdma.instance[i].fw;
-                       header = (const struct common_firmware_header *)info->fw->data;
-                       adev->firmware.fw_size +=
-                               ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
-               }
-       }
-out:
-       if (err) {
-               DRM_ERROR("sdma_v5_0: Failed to load firmware \"%s\"\n", fw_name);
-               for (i = 0; i < adev->sdma.num_instances; i++) {
-                       release_firmware(adev->sdma.instance[i].fw);
-                       adev->sdma.instance[i].fw = NULL;
-               }
+               ret = amdgpu_sdma_init_microcode(adev, fw_name, i, false);
+               if (ret)
+                       return ret;
        }
-       return err;
+       
+       return ret;
 }
 
 static unsigned sdma_v5_0_ring_init_cond_exec(struct amdgpu_ring *ring)
@@ -1465,12 +1436,10 @@ static int sdma_v5_0_sw_fini(void *handle)
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        int i;
 
-       for (i = 0; i < adev->sdma.num_instances; i++) {
-               release_firmware(adev->sdma.instance[i].fw);
-               adev->sdma.instance[i].fw = NULL;
-
+       for (i = 0; i < adev->sdma.num_instances; i++)
                amdgpu_ring_fini(&adev->sdma.instance[i].ring);
-       }
+
+       amdgpu_sdma_destroy_inst_ctx(adev, false);
 
        return 0;
 }
index 95689ef4be102115c19166f168a680e7a42c4a1c..f136fec7b4f4adc43a19a8dff8e5cb08214b4d3a 100644 (file)
@@ -89,33 +89,6 @@ static u32 sdma_v5_2_get_reg_offset(struct amdgpu_device *adev, u32 instance, u3
        return base + internal_offset;
 }
 
-static int sdma_v5_2_init_inst_ctx(struct amdgpu_sdma_instance *sdma_inst)
-{
-       int err = 0;
-       const struct sdma_firmware_header_v1_0 *hdr;
-
-       err = amdgpu_ucode_validate(sdma_inst->fw);
-       if (err)
-               return err;
-
-       hdr = (const struct sdma_firmware_header_v1_0 *)sdma_inst->fw->data;
-       sdma_inst->fw_version = le32_to_cpu(hdr->header.ucode_version);
-       sdma_inst->feature_version = le32_to_cpu(hdr->ucode_feature_version);
-
-       if (sdma_inst->feature_version >= 20)
-               sdma_inst->burst_nop = true;
-
-       return 0;
-}
-
-static void sdma_v5_2_destroy_inst_ctx(struct amdgpu_device *adev)
-{
-       release_firmware(adev->sdma.instance[0].fw);
-
-       memset((void *)adev->sdma.instance, 0,
-              sizeof(struct amdgpu_sdma_instance) * AMDGPU_MAX_SDMA_INSTANCES);
-}
-
 /**
  * sdma_v5_2_init_microcode - load ucode images from disk
  *
@@ -132,9 +105,6 @@ static int sdma_v5_2_init_microcode(struct amdgpu_device *adev)
 {
        const char *chip_name;
        char fw_name[40];
-       int err = 0, i;
-       struct amdgpu_firmware_info *info = NULL;
-       const struct common_firmware_header *header = NULL;
 
        DRM_DEBUG("\n");
 
@@ -169,42 +139,7 @@ static int sdma_v5_2_init_microcode(struct amdgpu_device *adev)
 
        snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", chip_name);
 
-       err = request_firmware(&adev->sdma.instance[0].fw, fw_name, adev->dev);
-       if (err)
-               goto out;
-
-       err = sdma_v5_2_init_inst_ctx(&adev->sdma.instance[0]);
-       if (err)
-               goto out;
-
-       for (i = 1; i < adev->sdma.num_instances; i++)
-               memcpy((void *)&adev->sdma.instance[i],
-                      (void *)&adev->sdma.instance[0],
-                      sizeof(struct amdgpu_sdma_instance));
-
-       if (amdgpu_sriov_vf(adev) && (adev->ip_versions[SDMA0_HWIP][0] == IP_VERSION(5, 2, 0)))
-               return 0;
-
-       DRM_DEBUG("psp_load == '%s'\n",
-                 adev->firmware.load_type == AMDGPU_FW_LOAD_PSP ? "true" : "false");
-
-       if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
-               for (i = 0; i < adev->sdma.num_instances; i++) {
-                       info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i];
-                       info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i;
-                       info->fw = adev->sdma.instance[i].fw;
-                       header = (const struct common_firmware_header *)info->fw->data;
-                       adev->firmware.fw_size +=
-                               ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
-               }
-       }
-
-out:
-       if (err) {
-               DRM_ERROR("sdma_v5_2: Failed to load firmware \"%s\"\n", fw_name);
-               sdma_v5_2_destroy_inst_ctx(adev);
-       }
-       return err;
+       return amdgpu_sdma_init_microcode(adev, fw_name, 0, true);
 }
 
 static unsigned sdma_v5_2_ring_init_cond_exec(struct amdgpu_ring *ring)
@@ -1406,7 +1341,7 @@ static int sdma_v5_2_sw_fini(void *handle)
        for (i = 0; i < adev->sdma.num_instances; i++)
                amdgpu_ring_fini(&adev->sdma.instance[i].ring);
 
-       sdma_v5_2_destroy_inst_ctx(adev);
+       amdgpu_sdma_destroy_inst_ctx(adev, true);
 
        return 0;
 }