Commit 9bb86b63 authored by Ofir Bitton's avatar Ofir Bitton Committed by Oded Gabbay
Browse files

habanalabs: advanced FW loading



Today driver is able to load a whole FW binary into a specific
location on ASIC. We add support for loading sections from the
same FW binary into different loactions.

Signed-off-by: default avatarOfir Bitton <obitton@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent 977d53a6
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -20,16 +20,18 @@
 * @hdev: pointer to hl_device structure.
 * @fw_name: the firmware image name
 * @dst: IO memory mapped address space to copy firmware to
 * @src_offset: offset in src FW to copy from
 * @size: amount of bytes to copy (0 to copy the whole binary)
 *
 * Copy fw code from firmware file to device memory.
 *
 * Return: 0 on success, non-zero for failure.
 */
int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
				void __iomem *dst)
				void __iomem *dst, u32 src_offset, u32 size)
{
	const struct firmware *fw;
	const u64 *fw_data;
	const void *fw_data;
	size_t fw_size;
	int rc;

@@ -57,9 +59,20 @@ int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
		goto out;
	}

	fw_data = (const u64 *) fw->data;
	if (size - src_offset > fw_size) {
		dev_err(hdev->dev,
			"size to copy(%u) and offset(%u) are invalid\n",
			size, src_offset);
		rc = -EINVAL;
		goto out;
	}

	if (size)
		fw_size = size;

	fw_data = (const void *) fw->data;

	memcpy_toio(dst, fw_data, fw_size);
	memcpy_toio(dst, fw_data + src_offset, fw_size);

out:
	release_firmware(fw);
+1 −1
Original line number Diff line number Diff line
@@ -2028,7 +2028,7 @@ int hl_mmu_if_set_funcs(struct hl_device *hdev);
void hl_mmu_v1_set_funcs(struct hl_device *hdev);

int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
				void __iomem *dst);
				void __iomem *dst, u32 src_offset, u32 size);
int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode);
int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
				u16 len, u32 timeout, long *result);
+2 −2
Original line number Diff line number Diff line
@@ -3529,7 +3529,7 @@ static int gaudi_load_firmware_to_device(struct hl_device *hdev)

	dst = hdev->pcie_bar[HBM_BAR_ID] + LINUX_FW_OFFSET;

	return hl_fw_load_fw_to_device(hdev, GAUDI_LINUX_FW_FILE, dst);
	return hl_fw_load_fw_to_device(hdev, GAUDI_LINUX_FW_FILE, dst, 0, 0);
}

static int gaudi_load_boot_fit_to_device(struct hl_device *hdev)
@@ -3538,7 +3538,7 @@ static int gaudi_load_boot_fit_to_device(struct hl_device *hdev)

	dst = hdev->pcie_bar[SRAM_BAR_ID] + BOOT_FIT_SRAM_OFFSET;

	return hl_fw_load_fw_to_device(hdev, GAUDI_BOOT_FIT_FILE, dst);
	return hl_fw_load_fw_to_device(hdev, GAUDI_BOOT_FIT_FILE, dst, 0, 0);
}

static void gaudi_read_device_fw_version(struct hl_device *hdev,
+2 −2
Original line number Diff line number Diff line
@@ -2315,7 +2315,7 @@ static int goya_load_firmware_to_device(struct hl_device *hdev)

	dst = hdev->pcie_bar[DDR_BAR_ID] + LINUX_FW_OFFSET;

	return hl_fw_load_fw_to_device(hdev, GOYA_LINUX_FW_FILE, dst);
	return hl_fw_load_fw_to_device(hdev, GOYA_LINUX_FW_FILE, dst, 0, 0);
}

/*
@@ -2332,7 +2332,7 @@ static int goya_load_boot_fit_to_device(struct hl_device *hdev)

	dst = hdev->pcie_bar[SRAM_CFG_BAR_ID] + BOOT_FIT_SRAM_OFFSET;

	return hl_fw_load_fw_to_device(hdev, GOYA_BOOT_FIT_FILE, dst);
	return hl_fw_load_fw_to_device(hdev, GOYA_BOOT_FIT_FILE, dst, 0, 0);
}

/*