blob: 0a4afe0e01008667c08646552ed7661de2baecdf [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 /* --------------------------------------------------------------------
23 * This code is expected to be executed only by the primary CPU.
24 * Save the mpid for the first core that executes and if a secondary
25 * CPU has lost its way make it spin forever.
26 * --------------------------------------------------------------------
27 */
28 bl save_primary_mpid
29
30 /* --------------------------------------------------------------------
31 * Zero out NOBITS sections. There are 2 of them:
32 * - the .bss section;
33 * - the coherent memory section.
34 * --------------------------------------------------------------------
35 */
36 ldr x0, =__BSS_START__
37 ldr x1, =__BSS_SIZE__
38 bl zeromem16
39
40 ldr x0, =__COHERENT_RAM_START__
41 ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__
42 bl zeromem16
43
44 /* --------------------------------------------------------------------
45 * Give ourselves a small coherent stack to ease the pain of
46 * initializing the MMU
47 * --------------------------------------------------------------------
48 */
49 mrs x0, mpidr_el1
50 bl platform_set_coherent_stack
51
52 bl tftf_early_platform_setup
53 bl tftf_plat_arch_setup
54
55 /* --------------------------------------------------------------------
56 * Give ourselves a stack allocated in Normal -IS-WBWA memory
57 * --------------------------------------------------------------------
58 */
59 mrs x0, mpidr_el1
60 bl platform_set_stack
61
62 /* --------------------------------------------------------------------
63 * tftf_cold_boot_main() will perform the remaining architectural and
64 * platform setup, initialise the test framework's state, then run the
65 * tests.
66 * --------------------------------------------------------------------
67 */
68 b tftf_cold_boot_main
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020069endfunc tftf_entrypoint
70
71/* ----------------------------------------------------------------------------
72 * Entry point for a CPU that has just been powered up.
73 * In : x0 - context_id
74 * ----------------------------------------------------------------------------
75 */
76func tftf_hotplug_entry
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020077 /* --------------------------------------------------------------------
78 * Preserve the context_id in a callee-saved register
79 * --------------------------------------------------------------------
80 */
81 mov x19, x0
82
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +010083 bl arch_init
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020084
85 /* --------------------------------------------------------------------
86 * Give ourselves a small coherent stack to ease the pain of
87 * initializing the MMU
88 * --------------------------------------------------------------------
89 */
90 mrs x0, mpidr_el1
91 bl platform_set_coherent_stack
92
93 /* --------------------------------------------------------------------
94 * Enable the MMU
95 * --------------------------------------------------------------------
96 */
97 bl tftf_plat_enable_mmu
98
99 /* --------------------------------------------------------------------
100 * Give ourselves a stack in normal memory.
101 * --------------------------------------------------------------------
102 */
103 mrs x0, mpidr_el1
104 bl platform_set_stack
105
106 /* --------------------------------------------------------------------
107 * Save the context_id for later retrieval by tests
108 * --------------------------------------------------------------------
109 */
110 mrs x0, mpidr_el1
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000111 mov_imm x1, MPID_MASK
112 and x0, x0, x1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200113 bl platform_get_core_pos
114
115 mov x1, x19
116
117 bl tftf_set_cpu_on_ctx_id
118
119 /* --------------------------------------------------------------------
120 * Jump to warm boot main function
121 * --------------------------------------------------------------------
122 */
123 b tftf_warm_boot_main
124endfunc tftf_hotplug_entry
125
126/* ----------------------------------------------------------------------------
127 * Saves the mpid of the primary core and if the primary core
128 * is already saved then it loops infinitely.
129 * ----------------------------------------------------------------------------
130 */
131func save_primary_mpid
132 adrp x1, tftf_primary_core
133 ldr w0, [x1, :lo12:tftf_primary_core]
134 mov w2, #INVALID_MPID
135 cmp w0, w2
136 b.ne panic
Antonio Nino Diaz8c0f86b2018-11-23 13:50:59 +0000137 mov_imm x2, MPID_MASK
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200138 mrs x0, mpidr_el1
139 and x0, x0, x2
140 str w0, [x1, :lo12:tftf_primary_core]
141 ret
142panic:
143 /* Primary core MPID already saved */
144 b .
145 ret
146endfunc save_primary_mpid
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100147
148/* Initialize architectural state. */
149func arch_init
150 mrs x0, CurrentEL
151 cmp x0, #(MODE_EL1 << MODE_EL_SHIFT)
152 b.eq el1_setup
153
154el2_setup:
155 /* Set the exception vectors. */
156 adr x0, tftf_vector
157 msr vbar_el2, x0
158
Joel Hutton6a6f4832019-04-08 15:46:36 +0100159 /* Enable the instruction cache and alignment checks. */
160 mov_imm x0, (SCTLR_EL2_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100161 msr sctlr_el2, x0
162
163 isb
164 ret
165
166el1_setup:
167 /* Set the exception vectors. */
168 adr x0, tftf_vector
169 msr vbar_el1, x0
170
171 /* Enable the instruction cache and stack pointer alignment checks. */
Joel Hutton6a6f4832019-04-08 15:46:36 +0100172 mov_imm x0, (SCTLR_EL1_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxa1948da2018-12-18 10:16:25 +0100173 msr sctlr_el1, x0
174
175 isb
176 ret
177endfunc arch_init