blob: 6ce4148a82b228170c8e078e62fabbe4a681f72a [file] [log] [blame]
Hadi Asyrafi616da772019-06-27 11:34:03 +08001/*
Jit Loon Lim86f6fb32023-05-17 12:26:11 +08002 * Copyright (c) 2019-2023, ARM Limited and Contributors. All rights reserved.
Sieu Mun Tang9dd2c182024-10-22 01:00:45 +08003 * Copyright (c) 2019-2023, Intel Corporation. All rights reserved.
4 * Copyright (c) 2024, Altera Corporation. All rights reserved.
Hadi Asyrafi616da772019-06-27 11:34:03 +08005 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#include <arch.h>
10#include <asm_macros.S>
11#include <cpu_macros.S>
12#include <platform_def.h>
Hadi Asyrafi0563a852019-10-22 12:59:32 +080013#include <el3_common_macros.S>
Hadi Asyrafi616da772019-06-27 11:34:03 +080014
15 .globl plat_secondary_cold_boot_setup
16 .globl platform_is_primary_cpu
17 .globl plat_is_my_cpu_primary
18 .globl plat_my_core_pos
19 .globl plat_crash_console_init
20 .globl plat_crash_console_putc
21 .globl plat_crash_console_flush
22 .globl platform_mem_init
Hadi Asyrafi0563a852019-10-22 12:59:32 +080023 .globl plat_secondary_cpus_bl31_entry
Sieu Mun Tang9dd2c182024-10-22 01:00:45 +080024 .globl invalidate_cache_low_el
Hadi Asyrafi616da772019-06-27 11:34:03 +080025
26 .globl plat_get_my_entrypoint
27
28 /* -----------------------------------------------------
29 * void plat_secondary_cold_boot_setup (void);
30 *
31 * This function performs any platform specific actions
32 * needed for a secondary cpu after a cold reset e.g
33 * mark the cpu's presence, mechanism to place it in a
34 * holding pen etc.
35 * -----------------------------------------------------
36 */
37func plat_secondary_cold_boot_setup
38 /* Wait until the it gets reset signal from rstmgr gets populated */
39poll_mailbox:
Jit Loon Lim4c249f12023-05-17 12:26:11 +080040#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
41 mov_imm x0, PLAT_SEC_ENTRY
42 cbz x0, poll_mailbox
43 br x0
44#else
Hadi Asyrafi616da772019-06-27 11:34:03 +080045 wfi
Hadi Asyrafi309ac012019-08-01 14:48:39 +080046 mov_imm x0, PLAT_SEC_ENTRY
Hadi Asyrafi616da772019-06-27 11:34:03 +080047 ldr x1, [x0]
48 mov_imm x2, PLAT_CPUID_RELEASE
49 ldr x3, [x2]
50 mrs x4, mpidr_el1
51 and x4, x4, #0xff
52 cmp x3, x4
53 b.ne poll_mailbox
54 br x1
Jit Loon Lim4c249f12023-05-17 12:26:11 +080055#endif
Hadi Asyrafi616da772019-06-27 11:34:03 +080056endfunc plat_secondary_cold_boot_setup
57
Jit Loon Lim4c249f12023-05-17 12:26:11 +080058#if ((PLATFORM_MODEL == PLAT_SOCFPGA_STRATIX10) || \
59 (PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX) || \
60 (PLATFORM_MODEL == PLAT_SOCFPGA_N5X))
61
Hadi Asyrafi616da772019-06-27 11:34:03 +080062func platform_is_primary_cpu
63 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
64 cmp x0, #PLAT_PRIMARY_CPU
65 cset x0, eq
66 ret
67endfunc platform_is_primary_cpu
68
Jit Loon Lim4c249f12023-05-17 12:26:11 +080069#else
70
71func platform_is_primary_cpu
72 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
73 cmp x0, #(PLAT_PRIMARY_CPU_A76)
74 b.eq primary_cpu
75 cmp x0, #(PLAT_PRIMARY_CPU_A55)
76 b.eq primary_cpu
77primary_cpu:
78 cset x0, eq
79 ret
80endfunc platform_is_primary_cpu
81
82#endif
83
Hadi Asyrafi616da772019-06-27 11:34:03 +080084func plat_is_my_cpu_primary
85 mrs x0, mpidr_el1
86 b platform_is_primary_cpu
87endfunc plat_is_my_cpu_primary
88
89func plat_my_core_pos
90 mrs x0, mpidr_el1
91 and x1, x0, #MPIDR_CPU_MASK
92 and x0, x0, #MPIDR_CLUSTER_MASK
Jit Loon Lim4c249f12023-05-17 12:26:11 +080093#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
94 add x0, x1, x0, LSR #8
95#else
Hadi Asyrafi616da772019-06-27 11:34:03 +080096 add x0, x1, x0, LSR #6
Jit Loon Lim4c249f12023-05-17 12:26:11 +080097#endif
Hadi Asyrafi616da772019-06-27 11:34:03 +080098 ret
99endfunc plat_my_core_pos
100
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800101func warm_reset_req
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800102#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
103 bl plat_is_my_cpu_primary
104 cbnz x0, warm_reset
105warm_reset:
106 mov_imm x1, PLAT_SEC_ENTRY
107 str xzr, [x1]
108 mrs x1, rmr_el3
109 orr x1, x1, #0x02
110 msr rmr_el3, x1
111 isb
112 dsb sy
113#else
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800114 str xzr, [x4]
115 bl plat_is_my_cpu_primary
116 cbz x0, cpu_in_wfi
117 mov_imm x1, PLAT_SEC_ENTRY
118 str xzr, [x1]
119 mrs x1, rmr_el3
120 orr x1, x1, #0x02
121 msr rmr_el3, x1
122 isb
123 dsb sy
124cpu_in_wfi:
125 wfi
126 b cpu_in_wfi
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800127#endif
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800128endfunc warm_reset_req
129
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800130/* TODO: Zephyr warm reset test */
131#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
Hadi Asyrafi616da772019-06-27 11:34:03 +0800132func plat_get_my_entrypoint
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800133 ldr x4, =L2_RESET_DONE_REG
134 ldr x5, [x4]
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800135 ldr x1, =PLAT_L2_RESET_REQ
136 cmp x1, x5
137 b.eq zephyr_reset_req
138 mov_imm x1, PLAT_SEC_ENTRY
139 ldr x0, [x1]
140 ret
141zephyr_reset_req:
142 ldr x0, =0x00
143 ret
144endfunc plat_get_my_entrypoint
145#else
146func plat_get_my_entrypoint
147 ldr x4, =L2_RESET_DONE_REG
148 ldr x5, [x4]
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800149 ldr x1, =L2_RESET_DONE_STATUS
150 cmp x1, x5
151 b.eq warm_reset_req
Hadi Asyrafi309ac012019-08-01 14:48:39 +0800152 mov_imm x1, PLAT_SEC_ENTRY
Hadi Asyrafi616da772019-06-27 11:34:03 +0800153 ldr x0, [x1]
154 ret
155endfunc plat_get_my_entrypoint
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800156#endif
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800157
Hadi Asyrafi616da772019-06-27 11:34:03 +0800158 /* ---------------------------------------------
159 * int plat_crash_console_init(void)
160 * Function to initialize the crash console
161 * without a C Runtime to print crash report.
162 * Clobber list : x0, x1, x2
163 * ---------------------------------------------
164 */
165func plat_crash_console_init
Boon Khai Ngb19ac612021-08-06 01:16:46 +0800166 mov_imm x0, CRASH_CONSOLE_BASE
Hadi Asyrafi616da772019-06-27 11:34:03 +0800167 mov_imm x1, PLAT_UART_CLOCK
168 mov_imm x2, PLAT_BAUDRATE
169 b console_16550_core_init
170endfunc plat_crash_console_init
171
172 /* ---------------------------------------------
173 * int plat_crash_console_putc(void)
174 * Function to print a character on the crash
175 * console without a C Runtime.
176 * Clobber list : x1, x2
177 * ---------------------------------------------
178 */
179func plat_crash_console_putc
Boon Khai Ngb19ac612021-08-06 01:16:46 +0800180 mov_imm x1, CRASH_CONSOLE_BASE
Hadi Asyrafi616da772019-06-27 11:34:03 +0800181 b console_16550_core_putc
182endfunc plat_crash_console_putc
183
184func plat_crash_console_flush
185 mov_imm x0, CRASH_CONSOLE_BASE
186 b console_16550_core_flush
187endfunc plat_crash_console_flush
188
189
190 /* --------------------------------------------------------
191 * void platform_mem_init (void);
192 *
193 * Any memory init, relocation to be done before the
194 * platform boots. Called very early in the boot process.
195 * --------------------------------------------------------
196 */
197func platform_mem_init
198 mov x0, #0
199 ret
200endfunc platform_mem_init
Hadi Asyrafi0563a852019-10-22 12:59:32 +0800201
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800202 /* --------------------------------------------------------
203 * macro plat_secondary_cpus_bl31_entry;
204 *
205 * el3_entrypoint_common init param configuration.
206 * Called very early in the secondary cores boot process.
207 * --------------------------------------------------------
208 */
Hadi Asyrafi0563a852019-10-22 12:59:32 +0800209func plat_secondary_cpus_bl31_entry
210 el3_entrypoint_common \
211 _init_sctlr=0 \
212 _warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS \
213 _secondary_cold_boot=!COLD_BOOT_SINGLE_CPU \
214 _init_memory=1 \
215 _init_c_runtime=1 \
216 _exception_vectors=runtime_exceptions \
217 _pie_fixup_size=BL31_LIMIT - BL31_BASE
218endfunc plat_secondary_cpus_bl31_entry
Sieu Mun Tang9dd2c182024-10-22 01:00:45 +0800219
220/* --------------------------------------------------------
221 * Invalidate for NS EL2 and EL1
222 * --------------------------------------------------------
223 */
224func invalidate_cache_low_el
225 mrs x0,SCR_EL3
226 orr x1,x0,#SCR_NS_BIT
227 msr SCR_EL3, x1
228 isb
229 tlbi ALLE2
230 dsb sy
231 tlbi ALLE1
232 dsb sy
233endfunc invalidate_cache_low_el