blob: 04a7d4c85698ebed97c920030a5935fdbe8a7ceb [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
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 * Cold boot entry point for the primary CPU.
16 * ----------------------------------------------------------------------------
17 */
18func tftf_entrypoint
19 /* --------------------------------------------------------------------
20 * Set the exception vectors
21 * --------------------------------------------------------------------
22 */
23 ldr r0, =tftf_vector
24 stcopr r0, HVBAR
25
26 /* --------------------------------------------------------------------
27 * Enable the instruction cache and asynchronous interrupts.
28 * --------------------------------------------------------------------
29 */
30 ldcopr r0, HSCTLR
31 ldr r1, =(HSCTLR_I_BIT | HSCTLR_A_BIT)
32 orr r0, r0, r1
33 stcopr r0, HSCTLR
34 isb
35
36 /* --------------------------------------------------------------------
37 * This code is expected to be executed only by the primary CPU.
38 * Save the mpid for the first core that executes and if a secondary
39 * CPU has lost its way make it spin forever.
40 * --------------------------------------------------------------------
41 */
42 bl save_primary_mpid
43
44 /* --------------------------------------------------------------------
45 * Zero out NOBITS sections. There are 2 of them:
46 * - the .bss section;
47 * - the coherent memory section.
48 * --------------------------------------------------------------------
49 */
50 ldr r0, =__BSS_START__
51 ldr r1, =__BSS_SIZE__
52 bl zeromem
53
54 ldr r0, =__COHERENT_RAM_START__
55 ldr r1, =__COHERENT_RAM_UNALIGNED_SIZE__
56 bl zeromem
57
58 /* --------------------------------------------------------------------
59 * Give ourselves a small coherent stack to ease the pain of
60 * initializing the MMU
61 * --------------------------------------------------------------------
62 */
63 ldcopr r0, MPIDR
64 bl platform_set_coherent_stack
65
66 bl tftf_early_platform_setup
67 bl tftf_plat_arch_setup
68
69 /* --------------------------------------------------------------------
70 * Give ourselves a stack allocated in Normal -IS-WBWA memory
71 * --------------------------------------------------------------------
72 */
73 ldcopr r0, MPIDR
74 bl platform_set_stack
75
76 /* --------------------------------------------------------------------
77 * tftf_cold_boot_main() will perform the remaining architectural and
78 * platform setup, initialise the test framework's state, then run the
79 * tests.
80 * --------------------------------------------------------------------
81 */
82 b tftf_cold_boot_main
83endfunc tftf_entrypoint
84
85/* ----------------------------------------------------------------------------
86 * Entry point for a CPU that has just been powered up.
87 * In : r0 - context_id
88 * ----------------------------------------------------------------------------
89 */
90func tftf_hotplug_entry
91
92 /* --------------------------------------------------------------------
93 * Preserve the context_id in a callee-saved register
94 * --------------------------------------------------------------------
95 */
96 mov r4, r0
97
98 /* --------------------------------------------------------------------
99 * Set the exception vectors
100 * --------------------------------------------------------------------
101 */
102 ldr r0, =tftf_vector
103 stcopr r0, HVBAR
104
105 /* --------------------------------------------------------------------
106 * Enable the instruction cache and asynchronous interrupts.
107 * --------------------------------------------------------------------
108 */
109 ldcopr r0, HSCTLR
110 ldr r1, =(HSCTLR_I_BIT | HSCTLR_A_BIT)
111 orr r0, r0, r1
112 stcopr r0, HSCTLR
113 isb
114
115 /* --------------------------------------------------------------------
116 * Give ourselves a small coherent stack to ease the pain of
117 * initializing the MMU
118 * --------------------------------------------------------------------
119 */
120 ldcopr r0, MPIDR
121 bl platform_set_coherent_stack
122
123 /* --------------------------------------------------------------------
124 * Enable the MMU
125 * --------------------------------------------------------------------
126 */
127 bl tftf_plat_enable_mmu
128
129 /* --------------------------------------------------------------------
130 * Give ourselves a stack in normal memory.
131 * --------------------------------------------------------------------
132 */
133 ldcopr r0, MPIDR
134 bl platform_set_stack
135
136 /* --------------------------------------------------------------------
137 * Save the context_id for later retrieval by tests
138 * --------------------------------------------------------------------
139 */
140 ldcopr r0, MPIDR
141 ldr r1, =MPID_MASK
142 and r0, r0, r1
143 bl platform_get_core_pos
144
145 mov r1, r4
146
147 bl tftf_set_cpu_on_ctx_id
148
149 /* --------------------------------------------------------------------
150 * Jump to warm boot main function
151 * --------------------------------------------------------------------
152 */
153 b tftf_warm_boot_main
154endfunc tftf_hotplug_entry
155
156/* ----------------------------------------------------------------------------
157 * Saves the mpid of the primary core and if the primary core
158 * is already saved then it loops infinitely.
159 * ----------------------------------------------------------------------------
160 */
161func save_primary_mpid
162 ldr r1, =tftf_primary_core
163 ldr r0, [r1]
164 mov r2, #INVALID_MPID
165 cmp r0, r2
166 bne panic
167 ldr r2, =MPID_MASK
168 ldcopr r0, MPIDR
169 and r0, r0, r2
170 str r0, [r1]
171 bx lr
172panic:
173 /* Primary core MPID already saved */
174 b panic
175endfunc save_primary_mpid