blob: 7937b88048e96613d27b0f9419fd6f67c4e59fa1 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Alexei Fedorov09ed7102020-01-30 14:06:28 +00002 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <tftf.h>
10
11 .globl tftf_entrypoint
12 .globl tftf_hotplug_entry
13
14
15/* ----------------------------------------------------------------------------
16 * Cold boot entry point for the primary CPU.
17 * ----------------------------------------------------------------------------
18 */
19func tftf_entrypoint
Alexei Fedorov09ed7102020-01-30 14:06:28 +000020 /* --------------------------------------------------------------------
Harrison Mutai6e011642023-09-22 17:17:35 +010021 * Save arguments x0-x3 from the previous bootloader.
Alexei Fedorov09ed7102020-01-30 14:06:28 +000022 * --------------------------------------------------------------------
23 */
24 mov x20, x0
25 mov x21, x1
Harrison Mutai6e011642023-09-22 17:17:35 +010026 mov x22, x2
27 mov x23, x3
Alexei Fedorov09ed7102020-01-30 14:06:28 +000028
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +010029 bl arch_init
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020030
31 /* --------------------------------------------------------------------
Alexei Fedorov2198e9a2019-12-12 14:14:55 +000032 * Invalidate the RW memory used by TFTF image.
33 * This is done to safeguard against possible corruption of this
34 * memory by dirty cache lines in a system cache as a result of use
35 * by an earlier boot loader stage.
36 * --------------------------------------------------------------------
37 */
38 adr x0, __DATA_START__
39 adr x1, __DATA_END__
40 sub x1, x1, x0
41 bl inv_dcache_range
42
43 /* --------------------------------------------------------------------
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020044 * This code is expected to be executed only by the primary CPU.
45 * Save the mpid for the first core that executes and if a secondary
46 * CPU has lost its way make it spin forever.
47 * --------------------------------------------------------------------
48 */
49 bl save_primary_mpid
50
51 /* --------------------------------------------------------------------
52 * Zero out NOBITS sections. There are 2 of them:
53 * - the .bss section;
54 * - the coherent memory section.
55 * --------------------------------------------------------------------
56 */
57 ldr x0, =__BSS_START__
58 ldr x1, =__BSS_SIZE__
59 bl zeromem16
60
61 ldr x0, =__COHERENT_RAM_START__
62 ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__
63 bl zeromem16
64
65 /* --------------------------------------------------------------------
66 * Give ourselves a small coherent stack to ease the pain of
67 * initializing the MMU
68 * --------------------------------------------------------------------
69 */
70 mrs x0, mpidr_el1
71 bl platform_set_coherent_stack
72
73 bl tftf_early_platform_setup
74 bl tftf_plat_arch_setup
75
76 /* --------------------------------------------------------------------
77 * Give ourselves a stack allocated in Normal -IS-WBWA memory
78 * --------------------------------------------------------------------
79 */
80 mrs x0, mpidr_el1
81 bl platform_set_stack
82
83 /* --------------------------------------------------------------------
Harrison Mutai6e011642023-09-22 17:17:35 +010084 * Save the fw_config or transfer list and hw_config addresses passed
85 * in registers x0 to x3 from the previous bootloader.
Alexei Fedorov09ed7102020-01-30 14:06:28 +000086 * --------------------------------------------------------------------
87 */
88 mov x0, x20
89 mov x1, x21
Harrison Mutai6e011642023-09-22 17:17:35 +010090 mov x2, x22
91 mov x3, x23
92 bl save_handoff_params
Alexei Fedorov09ed7102020-01-30 14:06:28 +000093
94 /* --------------------------------------------------------------------
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020095 * tftf_cold_boot_main() will perform the remaining architectural and
96 * platform setup, initialise the test framework's state, then run the
97 * tests.
98 * --------------------------------------------------------------------
99 */
100 b tftf_cold_boot_main
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200101endfunc tftf_entrypoint
102
103/* ----------------------------------------------------------------------------
104 * Entry point for a CPU that has just been powered up.
105 * In : x0 - context_id
106 * ----------------------------------------------------------------------------
107 */
108func tftf_hotplug_entry
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200109 /* --------------------------------------------------------------------
110 * Preserve the context_id in a callee-saved register
111 * --------------------------------------------------------------------
112 */
113 mov x19, x0
114
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100115 bl arch_init
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200116
117 /* --------------------------------------------------------------------
118 * Give ourselves a small coherent stack to ease the pain of
119 * initializing the MMU
120 * --------------------------------------------------------------------
121 */
122 mrs x0, mpidr_el1
123 bl platform_set_coherent_stack
124
125 /* --------------------------------------------------------------------
126 * Enable the MMU
127 * --------------------------------------------------------------------
128 */
129 bl tftf_plat_enable_mmu
130
131 /* --------------------------------------------------------------------
132 * Give ourselves a stack in normal memory.
133 * --------------------------------------------------------------------
134 */
135 mrs x0, mpidr_el1
136 bl platform_set_stack
137
138 /* --------------------------------------------------------------------
139 * Save the context_id for later retrieval by tests
140 * --------------------------------------------------------------------
141 */
142 mrs x0, mpidr_el1
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000143 mov_imm x1, MPID_MASK
144 and x0, x0, x1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200145 bl platform_get_core_pos
146
147 mov x1, x19
148
149 bl tftf_set_cpu_on_ctx_id
150
151 /* --------------------------------------------------------------------
152 * Jump to warm boot main function
153 * --------------------------------------------------------------------
154 */
155 b tftf_warm_boot_main
156endfunc tftf_hotplug_entry
157
158/* ----------------------------------------------------------------------------
159 * Saves the mpid of the primary core and if the primary core
160 * is already saved then it loops infinitely.
161 * ----------------------------------------------------------------------------
162 */
163func save_primary_mpid
164 adrp x1, tftf_primary_core
165 ldr w0, [x1, :lo12:tftf_primary_core]
166 mov w2, #INVALID_MPID
167 cmp w0, w2
168 b.ne panic
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000169 mov_imm x2, MPID_MASK
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200170 mrs x0, mpidr_el1
171 and x0, x0, x2
172 str w0, [x1, :lo12:tftf_primary_core]
173 ret
174panic:
175 /* Primary core MPID already saved */
176 b .
177 ret
178endfunc save_primary_mpid
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100179
180/* Initialize architectural state. */
181func arch_init
182 mrs x0, CurrentEL
183 cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
184 b.eq el1_setup
185
186el2_setup:
187 /* Set the exception vectors. */
188 adr x0, tftf_vector
189 msr vbar_el2, x0
190
Joel Hutton6a6f4832019-04-08 15:46:36 +0100191 /* Enable the instruction cache and alignment checks. */
192 mov_imm x0, (SCTLR_EL2_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100193 msr sctlr_el2, x0
194
195 isb
196 ret
197
198el1_setup:
199 /* Set the exception vectors. */
200 adr x0, tftf_vector
201 msr vbar_el1, x0
202
203 /* Enable the instruction cache and stack pointer alignment checks. */
Joel Hutton6a6f4832019-04-08 15:46:36 +0100204 mov_imm x0, (SCTLR_EL1_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100205 msr sctlr_el1, x0
206
207 isb
208 ret
209endfunc arch_init
Alexei Fedorov09ed7102020-01-30 14:06:28 +0000210
Harrison Mutai6e011642023-09-22 17:17:35 +0100211
212/* ----------------------------------------------------------------------------
213 * Save fw_config or transfer list and hw_config addresses passed in registers
214 * x0 to x3 from the previous bootloader.
215 * ----------------------------------------------------------------------------
216 */
217func save_handoff_params
218#if TRANSFER_LIST
219 adrp x4, ns_tl
220 str x3, [x4, :lo12:ns_tl]
221 str x1, [x4, :lo12:tl_signature]
222 str x0, [x4, :lo12:hw_config_base]
223#else
Alexei Fedorov09ed7102020-01-30 14:06:28 +0000224 adrp x2, fw_config_base
225 str x0, [x2, :lo12:fw_config_base]
226 str x1, [x2, :lo12:hw_config_base]
Harrison Mutai6e011642023-09-22 17:17:35 +0100227#endif
Alexei Fedorov09ed7102020-01-30 14:06:28 +0000228 ret
Harrison Mutai6e011642023-09-22 17:17:35 +0100229endfunc save_handoff_params