Commit b077656b authored by Likun Gao's avatar Likun Gao Committed by Alex Deucher
Browse files

drm/amdgpu/sdma6: use common function to init sdma fw



Use common function to init sdma v6 firmware ucode.

Signed-off-by: default avatarLikun Gao <Likun.Gao@amd.com>
Reviewed-by: default avatarHawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 52642d13
Loading
Loading
Loading
Loading
+2 −71
Original line number Diff line number Diff line
@@ -78,33 +78,6 @@ static u32 sdma_v6_0_get_reg_offset(struct amdgpu_device *adev, u32 instance, u3
	return base + internal_offset;
}

static int sdma_v6_0_init_inst_ctx(struct amdgpu_sdma_instance *sdma_inst)
{
	int err = 0;
	const struct sdma_firmware_header_v2_0 *hdr;

	err = amdgpu_ucode_validate(sdma_inst->fw);
	if (err)
		return err;

	hdr = (const struct sdma_firmware_header_v2_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_v6_0_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_v6_0_init_microcode - load ucode images from disk
 *
@@ -114,16 +87,10 @@ static void sdma_v6_0_destroy_inst_ctx(struct amdgpu_device *adev)
 * the driver (not loaded into hw).
 * Returns 0 on success, error on failure.
 */

// emulation only, won't work on real chip
// sdma 6.0.0 real chip need to use PSP to load firmware
static int sdma_v6_0_init_microcode(struct amdgpu_device *adev)
{
	char fw_name[30];
	char ucode_prefix[30];
	int err = 0, i;
	struct amdgpu_firmware_info *info = NULL;
	const struct sdma_firmware_header_v2_0 *sdma_hdr;

	DRM_DEBUG("\n");

@@ -131,43 +98,7 @@ static int sdma_v6_0_init_microcode(struct amdgpu_device *adev)

	snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);

	err = request_firmware(&adev->sdma.instance[0].fw, fw_name, adev->dev);
	if (err)
		goto out;

	err = sdma_v6_0_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));
	}

	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) {
		sdma_hdr = (const struct sdma_firmware_header_v2_0 *)adev->sdma.instance[0].fw->data;
		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA_UCODE_TH0];
		info->ucode_id = AMDGPU_UCODE_ID_SDMA_UCODE_TH0;
		info->fw = adev->sdma.instance[0].fw;
		adev->firmware.fw_size +=
			ALIGN(le32_to_cpu(sdma_hdr->ctx_ucode_size_bytes), PAGE_SIZE);
		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA_UCODE_TH1];
		info->ucode_id = AMDGPU_UCODE_ID_SDMA_UCODE_TH1;
		info->fw = adev->sdma.instance[0].fw;
		adev->firmware.fw_size +=
			ALIGN(le32_to_cpu(sdma_hdr->ctl_ucode_size_bytes), PAGE_SIZE);
	}

out:
	if (err) {
		DRM_ERROR("sdma_v6_0: Failed to load firmware \"%s\"\n", fw_name);
		sdma_v6_0_destroy_inst_ctx(adev);
	}
	return err;
	return amdgpu_sdma_init_microcode(adev, fw_name, 0, true);
}

static unsigned sdma_v6_0_ring_init_cond_exec(struct amdgpu_ring *ring)
@@ -1370,7 +1301,7 @@ static int sdma_v6_0_sw_fini(void *handle)
	for (i = 0; i < adev->sdma.num_instances; i++)
		amdgpu_ring_fini(&adev->sdma.instance[i].ring);

	sdma_v6_0_destroy_inst_ctx(adev);
	amdgpu_sdma_destroy_inst_ctx(adev, true);

	return 0;
}