xref: /optee_os/core/pta/qcom/pas/dsp.c (revision fedadb6460b1ea7db709c6f5a0572f5a8cb8e5c9)
1*fedadb64SJorge Ramirez-Ortiz // SPDX-License-Identifier: BSD-2-Clause
2*fedadb64SJorge Ramirez-Ortiz /*
3*fedadb64SJorge Ramirez-Ortiz  * Copyright (c) 2026, Qualcomm Technologies, Inc. and/or its subsidiaries.
4*fedadb64SJorge Ramirez-Ortiz  */
5*fedadb64SJorge Ramirez-Ortiz 
6*fedadb64SJorge Ramirez-Ortiz #include <io.h>
7*fedadb64SJorge Ramirez-Ortiz #include <mm/core_mmu.h>
8*fedadb64SJorge Ramirez-Ortiz #include <stdint.h>
9*fedadb64SJorge Ramirez-Ortiz #include <string.h>
10*fedadb64SJorge Ramirez-Ortiz 
11*fedadb64SJorge Ramirez-Ortiz #include "dsp.h"
12*fedadb64SJorge Ramirez-Ortiz #include "pas.h"
13*fedadb64SJorge Ramirez-Ortiz 
14*fedadb64SJorge Ramirez-Ortiz #define CBCR_BRANCH_ENABLE_BIT	BIT(0)
15*fedadb64SJorge Ramirez-Ortiz #define CBCR_HW_CTL_ENABLE_BIT	BIT(1)
16*fedadb64SJorge Ramirez-Ortiz 
17*fedadb64SJorge Ramirez-Ortiz #define BOOT_CORE_START		BIT(0)
18*fedadb64SJorge Ramirez-Ortiz #define BOOT_CMD_START		BIT(0)
19*fedadb64SJorge Ramirez-Ortiz #define BOOT_FSM_TIMEOUT	10000
20*fedadb64SJorge Ramirez-Ortiz 
dsp_fw_start(struct qcom_pas_data * data,const struct dsp_fw_boot_regs * regs)21*fedadb64SJorge Ramirez-Ortiz TEE_Result dsp_fw_start(struct qcom_pas_data *data,
22*fedadb64SJorge Ramirez-Ortiz 			const struct dsp_fw_boot_regs *regs)
23*fedadb64SJorge Ramirez-Ortiz {
24*fedadb64SJorge Ramirez-Ortiz 	vaddr_t base = io_pa_or_va(&data->base, data->size);
25*fedadb64SJorge Ramirez-Ortiz 	uint64_t timeout;
26*fedadb64SJorge Ramirez-Ortiz 
27*fedadb64SJorge Ramirez-Ortiz 	if (!regs)
28*fedadb64SJorge Ramirez-Ortiz 		return TEE_ERROR_BAD_PARAMETERS;
29*fedadb64SJorge Ramirez-Ortiz 
30*fedadb64SJorge Ramirez-Ortiz 	io_write32(base + regs->xo_cbcr, CBCR_BRANCH_ENABLE_BIT);
31*fedadb64SJorge Ramirez-Ortiz 	io_write32(base + regs->sleep_cbcr, CBCR_BRANCH_ENABLE_BIT);
32*fedadb64SJorge Ramirez-Ortiz 
33*fedadb64SJorge Ramirez-Ortiz 	if (data->pas_id == PAS_ID_TURING)
34*fedadb64SJorge Ramirez-Ortiz 		io_write32(base + regs->core_cbcr,
35*fedadb64SJorge Ramirez-Ortiz 			   CBCR_BRANCH_ENABLE_BIT | CBCR_HW_CTL_ENABLE_BIT);
36*fedadb64SJorge Ramirez-Ortiz 	else
37*fedadb64SJorge Ramirez-Ortiz 		io_write32(base + regs->core_cbcr, CBCR_BRANCH_ENABLE_BIT);
38*fedadb64SJorge Ramirez-Ortiz 
39*fedadb64SJorge Ramirez-Ortiz 	io_write32(base + regs->rst_evb, data->fw_base >> 4);
40*fedadb64SJorge Ramirez-Ortiz 	dsb();
41*fedadb64SJorge Ramirez-Ortiz 
42*fedadb64SJorge Ramirez-Ortiz 	io_write32(base + regs->core_start, BOOT_CORE_START);
43*fedadb64SJorge Ramirez-Ortiz 	io_write32(base + regs->boot_cmd, BOOT_CMD_START);
44*fedadb64SJorge Ramirez-Ortiz 
45*fedadb64SJorge Ramirez-Ortiz 	timeout = timeout_init_us(BOOT_FSM_TIMEOUT);
46*fedadb64SJorge Ramirez-Ortiz 
47*fedadb64SJorge Ramirez-Ortiz 	while (!timeout_elapsed(timeout)) {
48*fedadb64SJorge Ramirez-Ortiz 		if (io_read32(base + regs->boot_status) & BIT(0))
49*fedadb64SJorge Ramirez-Ortiz 			return TEE_SUCCESS;
50*fedadb64SJorge Ramirez-Ortiz 
51*fedadb64SJorge Ramirez-Ortiz 		udelay(10);
52*fedadb64SJorge Ramirez-Ortiz 	}
53*fedadb64SJorge Ramirez-Ortiz 
54*fedadb64SJorge Ramirez-Ortiz 	EMSG("Timed out waiting for DSP to boot");
55*fedadb64SJorge Ramirez-Ortiz 
56*fedadb64SJorge Ramirez-Ortiz 	return TEE_ERROR_TIMEOUT;
57*fedadb64SJorge Ramirez-Ortiz }
58*fedadb64SJorge Ramirez-Ortiz 
59