blob: cbd0121284455b707ed63e6226abf97fb6c00b39 [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.
Hadi Asyrafi616da772019-06-27 11:34:03 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <cpu_macros.S>
10#include <platform_def.h>
Hadi Asyrafi0563a852019-10-22 12:59:32 +080011#include <el3_common_macros.S>
Hadi Asyrafi616da772019-06-27 11:34:03 +080012
13 .globl plat_secondary_cold_boot_setup
14 .globl platform_is_primary_cpu
15 .globl plat_is_my_cpu_primary
16 .globl plat_my_core_pos
17 .globl plat_crash_console_init
18 .globl plat_crash_console_putc
19 .globl plat_crash_console_flush
20 .globl platform_mem_init
Hadi Asyrafi0563a852019-10-22 12:59:32 +080021 .globl plat_secondary_cpus_bl31_entry
Hadi Asyrafi616da772019-06-27 11:34:03 +080022
23 .globl plat_get_my_entrypoint
24
25 /* -----------------------------------------------------
26 * void plat_secondary_cold_boot_setup (void);
27 *
28 * This function performs any platform specific actions
29 * needed for a secondary cpu after a cold reset e.g
30 * mark the cpu's presence, mechanism to place it in a
31 * holding pen etc.
32 * -----------------------------------------------------
33 */
34func plat_secondary_cold_boot_setup
35 /* Wait until the it gets reset signal from rstmgr gets populated */
36poll_mailbox:
Jit Loon Lim4c249f12023-05-17 12:26:11 +080037#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
38 mov_imm x0, PLAT_SEC_ENTRY
39 cbz x0, poll_mailbox
40 br x0
41#else
Hadi Asyrafi616da772019-06-27 11:34:03 +080042 wfi
Hadi Asyrafi309ac012019-08-01 14:48:39 +080043 mov_imm x0, PLAT_SEC_ENTRY
Hadi Asyrafi616da772019-06-27 11:34:03 +080044 ldr x1, [x0]
45 mov_imm x2, PLAT_CPUID_RELEASE
46 ldr x3, [x2]
47 mrs x4, mpidr_el1
48 and x4, x4, #0xff
49 cmp x3, x4
50 b.ne poll_mailbox
51 br x1
Jit Loon Lim4c249f12023-05-17 12:26:11 +080052#endif
Hadi Asyrafi616da772019-06-27 11:34:03 +080053endfunc plat_secondary_cold_boot_setup
54
Jit Loon Lim4c249f12023-05-17 12:26:11 +080055#if ((PLATFORM_MODEL == PLAT_SOCFPGA_STRATIX10) || \
56 (PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX) || \
57 (PLATFORM_MODEL == PLAT_SOCFPGA_N5X))
58
Hadi Asyrafi616da772019-06-27 11:34:03 +080059func platform_is_primary_cpu
60 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
61 cmp x0, #PLAT_PRIMARY_CPU
62 cset x0, eq
63 ret
64endfunc platform_is_primary_cpu
65
Jit Loon Lim4c249f12023-05-17 12:26:11 +080066#else
67
68func platform_is_primary_cpu
69 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
70 cmp x0, #(PLAT_PRIMARY_CPU_A76)
71 b.eq primary_cpu
72 cmp x0, #(PLAT_PRIMARY_CPU_A55)
73 b.eq primary_cpu
74primary_cpu:
75 cset x0, eq
76 ret
77endfunc platform_is_primary_cpu
78
79#endif
80
Hadi Asyrafi616da772019-06-27 11:34:03 +080081func plat_is_my_cpu_primary
82 mrs x0, mpidr_el1
83 b platform_is_primary_cpu
84endfunc plat_is_my_cpu_primary
85
86func plat_my_core_pos
87 mrs x0, mpidr_el1
88 and x1, x0, #MPIDR_CPU_MASK
89 and x0, x0, #MPIDR_CLUSTER_MASK
Jit Loon Lim4c249f12023-05-17 12:26:11 +080090#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
91 add x0, x1, x0, LSR #8
92#else
Hadi Asyrafi616da772019-06-27 11:34:03 +080093 add x0, x1, x0, LSR #6
Jit Loon Lim4c249f12023-05-17 12:26:11 +080094#endif
Hadi Asyrafi616da772019-06-27 11:34:03 +080095 ret
96endfunc plat_my_core_pos
97
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +080098func warm_reset_req
Jit Loon Lim4c249f12023-05-17 12:26:11 +080099#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
100 bl plat_is_my_cpu_primary
101 cbnz x0, warm_reset
102warm_reset:
103 mov_imm x1, PLAT_SEC_ENTRY
104 str xzr, [x1]
105 mrs x1, rmr_el3
106 orr x1, x1, #0x02
107 msr rmr_el3, x1
108 isb
109 dsb sy
110#else
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800111 str xzr, [x4]
112 bl plat_is_my_cpu_primary
113 cbz x0, cpu_in_wfi
114 mov_imm x1, PLAT_SEC_ENTRY
115 str xzr, [x1]
116 mrs x1, rmr_el3
117 orr x1, x1, #0x02
118 msr rmr_el3, x1
119 isb
120 dsb sy
121cpu_in_wfi:
122 wfi
123 b cpu_in_wfi
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800124#endif
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800125endfunc warm_reset_req
126
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800127/* TODO: Zephyr warm reset test */
128#if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5
Hadi Asyrafi616da772019-06-27 11:34:03 +0800129func plat_get_my_entrypoint
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800130 ldr x4, =L2_RESET_DONE_REG
131 ldr x5, [x4]
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800132 ldr x1, =PLAT_L2_RESET_REQ
133 cmp x1, x5
134 b.eq zephyr_reset_req
135 mov_imm x1, PLAT_SEC_ENTRY
136 ldr x0, [x1]
137 ret
138zephyr_reset_req:
139 ldr x0, =0x00
140 ret
141endfunc plat_get_my_entrypoint
142#else
143func plat_get_my_entrypoint
144 ldr x4, =L2_RESET_DONE_REG
145 ldr x5, [x4]
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800146 ldr x1, =L2_RESET_DONE_STATUS
147 cmp x1, x5
148 b.eq warm_reset_req
Hadi Asyrafi309ac012019-08-01 14:48:39 +0800149 mov_imm x1, PLAT_SEC_ENTRY
Hadi Asyrafi616da772019-06-27 11:34:03 +0800150 ldr x0, [x1]
151 ret
152endfunc plat_get_my_entrypoint
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800153#endif
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800154
Hadi Asyrafi616da772019-06-27 11:34:03 +0800155 /* ---------------------------------------------
156 * int plat_crash_console_init(void)
157 * Function to initialize the crash console
158 * without a C Runtime to print crash report.
159 * Clobber list : x0, x1, x2
160 * ---------------------------------------------
161 */
162func plat_crash_console_init
Boon Khai Ngb19ac612021-08-06 01:16:46 +0800163 mov_imm x0, CRASH_CONSOLE_BASE
Hadi Asyrafi616da772019-06-27 11:34:03 +0800164 mov_imm x1, PLAT_UART_CLOCK
165 mov_imm x2, PLAT_BAUDRATE
166 b console_16550_core_init
167endfunc plat_crash_console_init
168
169 /* ---------------------------------------------
170 * int plat_crash_console_putc(void)
171 * Function to print a character on the crash
172 * console without a C Runtime.
173 * Clobber list : x1, x2
174 * ---------------------------------------------
175 */
176func plat_crash_console_putc
Boon Khai Ngb19ac612021-08-06 01:16:46 +0800177 mov_imm x1, CRASH_CONSOLE_BASE
Hadi Asyrafi616da772019-06-27 11:34:03 +0800178 b console_16550_core_putc
179endfunc plat_crash_console_putc
180
181func plat_crash_console_flush
182 mov_imm x0, CRASH_CONSOLE_BASE
183 b console_16550_core_flush
184endfunc plat_crash_console_flush
185
186
187 /* --------------------------------------------------------
188 * void platform_mem_init (void);
189 *
190 * Any memory init, relocation to be done before the
191 * platform boots. Called very early in the boot process.
192 * --------------------------------------------------------
193 */
194func platform_mem_init
195 mov x0, #0
196 ret
197endfunc platform_mem_init
Hadi Asyrafi0563a852019-10-22 12:59:32 +0800198
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800199 /* --------------------------------------------------------
200 * macro plat_secondary_cpus_bl31_entry;
201 *
202 * el3_entrypoint_common init param configuration.
203 * Called very early in the secondary cores boot process.
204 * --------------------------------------------------------
205 */
Hadi Asyrafi0563a852019-10-22 12:59:32 +0800206func plat_secondary_cpus_bl31_entry
207 el3_entrypoint_common \
208 _init_sctlr=0 \
209 _warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS \
210 _secondary_cold_boot=!COLD_BOOT_SINGLE_CPU \
211 _init_memory=1 \
212 _init_c_runtime=1 \
213 _exception_vectors=runtime_exceptions \
214 _pie_fixup_size=BL31_LIMIT - BL31_BASE
215endfunc plat_secondary_cpus_bl31_entry