blob: 81fd207b406e72406a8319d682e19dbc4cb08cdf [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Joel Hutton6a6f4832019-04-08 15:46:36 +01002 * Copyright (c) 2018-2019, 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
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +010020 bl arch_init
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020021
22 /* --------------------------------------------------------------------
Alexei Fedorov2198e9a2019-12-12 14:14:55 +000023 * Invalidate the RW memory used by TFTF image.
24 * This is done to safeguard against possible corruption of this
25 * memory by dirty cache lines in a system cache as a result of use
26 * by an earlier boot loader stage.
27 * --------------------------------------------------------------------
28 */
29 adr x0, __DATA_START__
30 adr x1, __DATA_END__
31 sub x1, x1, x0
32 bl inv_dcache_range
33
34 /* --------------------------------------------------------------------
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035 * This code is expected to be executed only by the primary CPU.
36 * Save the mpid for the first core that executes and if a secondary
37 * CPU has lost its way make it spin forever.
38 * --------------------------------------------------------------------
39 */
40 bl save_primary_mpid
41
42 /* --------------------------------------------------------------------
43 * Zero out NOBITS sections. There are 2 of them:
44 * - the .bss section;
45 * - the coherent memory section.
46 * --------------------------------------------------------------------
47 */
48 ldr x0, =__BSS_START__
49 ldr x1, =__BSS_SIZE__
50 bl zeromem16
51
52 ldr x0, =__COHERENT_RAM_START__
53 ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__
54 bl zeromem16
55
56 /* --------------------------------------------------------------------
57 * Give ourselves a small coherent stack to ease the pain of
58 * initializing the MMU
59 * --------------------------------------------------------------------
60 */
61 mrs x0, mpidr_el1
62 bl platform_set_coherent_stack
63
64 bl tftf_early_platform_setup
65 bl tftf_plat_arch_setup
66
67 /* --------------------------------------------------------------------
68 * Give ourselves a stack allocated in Normal -IS-WBWA memory
69 * --------------------------------------------------------------------
70 */
71 mrs x0, mpidr_el1
72 bl platform_set_stack
73
74 /* --------------------------------------------------------------------
75 * tftf_cold_boot_main() will perform the remaining architectural and
76 * platform setup, initialise the test framework's state, then run the
77 * tests.
78 * --------------------------------------------------------------------
79 */
80 b tftf_cold_boot_main
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020081endfunc tftf_entrypoint
82
83/* ----------------------------------------------------------------------------
84 * Entry point for a CPU that has just been powered up.
85 * In : x0 - context_id
86 * ----------------------------------------------------------------------------
87 */
88func tftf_hotplug_entry
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020089 /* --------------------------------------------------------------------
90 * Preserve the context_id in a callee-saved register
91 * --------------------------------------------------------------------
92 */
93 mov x19, x0
94
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +010095 bl arch_init
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020096
97 /* --------------------------------------------------------------------
98 * Give ourselves a small coherent stack to ease the pain of
99 * initializing the MMU
100 * --------------------------------------------------------------------
101 */
102 mrs x0, mpidr_el1
103 bl platform_set_coherent_stack
104
105 /* --------------------------------------------------------------------
106 * Enable the MMU
107 * --------------------------------------------------------------------
108 */
109 bl tftf_plat_enable_mmu
110
111 /* --------------------------------------------------------------------
112 * Give ourselves a stack in normal memory.
113 * --------------------------------------------------------------------
114 */
115 mrs x0, mpidr_el1
116 bl platform_set_stack
117
118 /* --------------------------------------------------------------------
119 * Save the context_id for later retrieval by tests
120 * --------------------------------------------------------------------
121 */
122 mrs x0, mpidr_el1
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000123 mov_imm x1, MPID_MASK
124 and x0, x0, x1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200125 bl platform_get_core_pos
126
127 mov x1, x19
128
129 bl tftf_set_cpu_on_ctx_id
130
131 /* --------------------------------------------------------------------
132 * Jump to warm boot main function
133 * --------------------------------------------------------------------
134 */
135 b tftf_warm_boot_main
136endfunc tftf_hotplug_entry
137
138/* ----------------------------------------------------------------------------
139 * Saves the mpid of the primary core and if the primary core
140 * is already saved then it loops infinitely.
141 * ----------------------------------------------------------------------------
142 */
143func save_primary_mpid
144 adrp x1, tftf_primary_core
145 ldr w0, [x1, :lo12:tftf_primary_core]
146 mov w2, #INVALID_MPID
147 cmp w0, w2
148 b.ne panic
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000149 mov_imm x2, MPID_MASK
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200150 mrs x0, mpidr_el1
151 and x0, x0, x2
152 str w0, [x1, :lo12:tftf_primary_core]
153 ret
154panic:
155 /* Primary core MPID already saved */
156 b .
157 ret
158endfunc save_primary_mpid
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100159
160/* Initialize architectural state. */
161func arch_init
162 mrs x0, CurrentEL
163 cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
164 b.eq el1_setup
165
166el2_setup:
167 /* Set the exception vectors. */
168 adr x0, tftf_vector
169 msr vbar_el2, x0
170
Joel Hutton6a6f4832019-04-08 15:46:36 +0100171 /* Enable the instruction cache and alignment checks. */
172 mov_imm x0, (SCTLR_EL2_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100173 msr sctlr_el2, x0
174
175 isb
176 ret
177
178el1_setup:
179 /* Set the exception vectors. */
180 adr x0, tftf_vector
181 msr vbar_el1, x0
182
183 /* Enable the instruction cache and stack pointer alignment checks. */
Joel Hutton6a6f4832019-04-08 15:46:36 +0100184 mov_imm x0, (SCTLR_EL1_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100185 msr sctlr_el1, x0
186
187 isb
188 ret
189endfunc arch_init