blob: 6aa5645620df9c504d539ef97523fe51a595c043 [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 /* --------------------------------------------------------------------
21 * Save arguments x0, x1 from the previous Boot loader
22 * --------------------------------------------------------------------
23 */
24 mov x20, x0
25 mov x21, x1
26
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +010027 bl arch_init
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020028
29 /* --------------------------------------------------------------------
Alexei Fedorov2198e9a2019-12-12 14:14:55 +000030 * Invalidate the RW memory used by TFTF image.
31 * This is done to safeguard against possible corruption of this
32 * memory by dirty cache lines in a system cache as a result of use
33 * by an earlier boot loader stage.
34 * --------------------------------------------------------------------
35 */
36 adr x0, __DATA_START__
37 adr x1, __DATA_END__
38 sub x1, x1, x0
39 bl inv_dcache_range
40
41 /* --------------------------------------------------------------------
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020042 * This code is expected to be executed only by the primary CPU.
43 * Save the mpid for the first core that executes and if a secondary
44 * CPU has lost its way make it spin forever.
45 * --------------------------------------------------------------------
46 */
47 bl save_primary_mpid
48
49 /* --------------------------------------------------------------------
50 * Zero out NOBITS sections. There are 2 of them:
51 * - the .bss section;
52 * - the coherent memory section.
53 * --------------------------------------------------------------------
54 */
55 ldr x0, =__BSS_START__
56 ldr x1, =__BSS_SIZE__
57 bl zeromem16
58
59 ldr x0, =__COHERENT_RAM_START__
60 ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__
61 bl zeromem16
62
63 /* --------------------------------------------------------------------
64 * Give ourselves a small coherent stack to ease the pain of
65 * initializing the MMU
66 * --------------------------------------------------------------------
67 */
68 mrs x0, mpidr_el1
69 bl platform_set_coherent_stack
70
71 bl tftf_early_platform_setup
72 bl tftf_plat_arch_setup
73
74 /* --------------------------------------------------------------------
75 * Give ourselves a stack allocated in Normal -IS-WBWA memory
76 * --------------------------------------------------------------------
77 */
78 mrs x0, mpidr_el1
79 bl platform_set_stack
80
81 /* --------------------------------------------------------------------
Alexei Fedorov09ed7102020-01-30 14:06:28 +000082 * Save fw_config and hw_config addresses passed in x0, x1 from the
83 * previous boot loader
84 * --------------------------------------------------------------------
85 */
86 mov x0, x20
87 mov x1, x21
88 bl save_fw_hw_configs
89
90 /* --------------------------------------------------------------------
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020091 * tftf_cold_boot_main() will perform the remaining architectural and
92 * platform setup, initialise the test framework's state, then run the
93 * tests.
94 * --------------------------------------------------------------------
95 */
96 b tftf_cold_boot_main
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020097endfunc tftf_entrypoint
98
99/* ----------------------------------------------------------------------------
100 * Entry point for a CPU that has just been powered up.
101 * In : x0 - context_id
102 * ----------------------------------------------------------------------------
103 */
104func tftf_hotplug_entry
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200105 /* --------------------------------------------------------------------
106 * Preserve the context_id in a callee-saved register
107 * --------------------------------------------------------------------
108 */
109 mov x19, x0
110
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100111 bl arch_init
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200112
113 /* --------------------------------------------------------------------
114 * Give ourselves a small coherent stack to ease the pain of
115 * initializing the MMU
116 * --------------------------------------------------------------------
117 */
118 mrs x0, mpidr_el1
119 bl platform_set_coherent_stack
120
121 /* --------------------------------------------------------------------
122 * Enable the MMU
123 * --------------------------------------------------------------------
124 */
125 bl tftf_plat_enable_mmu
126
127 /* --------------------------------------------------------------------
128 * Give ourselves a stack in normal memory.
129 * --------------------------------------------------------------------
130 */
131 mrs x0, mpidr_el1
132 bl platform_set_stack
133
134 /* --------------------------------------------------------------------
135 * Save the context_id for later retrieval by tests
136 * --------------------------------------------------------------------
137 */
138 mrs x0, mpidr_el1
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000139 mov_imm x1, MPID_MASK
140 and x0, x0, x1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200141 bl platform_get_core_pos
142
143 mov x1, x19
144
145 bl tftf_set_cpu_on_ctx_id
146
147 /* --------------------------------------------------------------------
148 * Jump to warm boot main function
149 * --------------------------------------------------------------------
150 */
151 b tftf_warm_boot_main
152endfunc tftf_hotplug_entry
153
154/* ----------------------------------------------------------------------------
155 * Saves the mpid of the primary core and if the primary core
156 * is already saved then it loops infinitely.
157 * ----------------------------------------------------------------------------
158 */
159func save_primary_mpid
160 adrp x1, tftf_primary_core
161 ldr w0, [x1, :lo12:tftf_primary_core]
162 mov w2, #INVALID_MPID
163 cmp w0, w2
164 b.ne panic
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000165 mov_imm x2, MPID_MASK
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200166 mrs x0, mpidr_el1
167 and x0, x0, x2
168 str w0, [x1, :lo12:tftf_primary_core]
169 ret
170panic:
171 /* Primary core MPID already saved */
172 b .
173 ret
174endfunc save_primary_mpid
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100175
176/* Initialize architectural state. */
177func arch_init
178 mrs x0, CurrentEL
179 cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
180 b.eq el1_setup
181
182el2_setup:
183 /* Set the exception vectors. */
184 adr x0, tftf_vector
185 msr vbar_el2, x0
186
Joel Hutton6a6f4832019-04-08 15:46:36 +0100187 /* Enable the instruction cache and alignment checks. */
188 mov_imm x0, (SCTLR_EL2_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100189 msr sctlr_el2, x0
190
191 isb
192 ret
193
194el1_setup:
195 /* Set the exception vectors. */
196 adr x0, tftf_vector
197 msr vbar_el1, x0
198
199 /* Enable the instruction cache and stack pointer alignment checks. */
Joel Hutton6a6f4832019-04-08 15:46:36 +0100200 mov_imm x0, (SCTLR_EL1_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100201 msr sctlr_el1, x0
202
203 isb
204 ret
205endfunc arch_init
Alexei Fedorov09ed7102020-01-30 14:06:28 +0000206
207/* Set fw_config and hw_config addresses passed in x0, x1 */
208func save_fw_hw_configs
209 adrp x2, fw_config_base
210 str x0, [x2, :lo12:fw_config_base]
211 str x1, [x2, :lo12:hw_config_base]
212 ret
213endfunc save_fw_hw_configs