2 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 #include <asm_macros.S>
11 #include <el3_common_macros.S>
12 #include <runtime_svc.h>
13 #include <smcc_helpers.h>
14 #include <smcc_macros.S>
15 #include <xlat_tables_defs.h>
17 .globl sp_min_vector_table
18 .globl sp_min_entrypoint
19 .globl sp_min_warm_entrypoint
22 vector_base sp_min_vector_table
24 b plat_panic_handler /* Undef */
25 b handle_smc /* Syscall */
26 b plat_panic_handler /* Prefetch abort */
27 b plat_panic_handler /* Data abort */
28 b plat_panic_handler /* Reserved */
29 b plat_panic_handler /* IRQ */
30 b plat_panic_handler /* FIQ */
34 * The Cold boot/Reset entrypoint for SP_MIN
36 func sp_min_entrypoint
38 /* ---------------------------------------------------------------
39 * Preceding bootloader has populated r0 with a pointer to a
40 * 'bl_params_t' structure & r1 with a pointer to platform
42 * ---------------------------------------------------------------
47 /* ---------------------------------------------------------------------
48 * For !RESET_TO_SP_MIN systems, only the primary CPU ever reaches
49 * sp_min_entrypoint() during the cold boot flow, so the cold/warm boot
50 * and primary/secondary CPU logic should not be executed in this case.
52 * Also, assume that the previous bootloader has already set up the CPU
53 * endianness and has initialised the memory.
54 * ---------------------------------------------------------------------
56 el3_entrypoint_common \
58 _warm_boot_mailbox=0 \
59 _secondary_cold_boot=0 \
62 _exception_vectors=sp_min_vector_table
64 /* ---------------------------------------------------------------------
65 * Relay the previous bootloader's arguments to the platform layer
66 * ---------------------------------------------------------------------
71 /* ---------------------------------------------------------------------
72 * For RESET_TO_SP_MIN systems which have a programmable reset address,
73 * sp_min_entrypoint() is executed only on the cold boot path so we can
74 * skip the warm boot mailbox mechanism.
75 * ---------------------------------------------------------------------
77 el3_entrypoint_common \
79 _warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS \
80 _secondary_cold_boot=!COLD_BOOT_SINGLE_CPU \
83 _exception_vectors=sp_min_vector_table
85 /* ---------------------------------------------------------------------
86 * For RESET_TO_SP_MIN systems, BL32 (SP_MIN) is the first bootloader
87 * to run so there's no argument to relay from a previous bootloader.
88 * Zero the arguments passed to the platform layer to reflect that.
89 * ---------------------------------------------------------------------
93 #endif /* RESET_TO_SP_MIN */
95 bl sp_min_early_platform_setup
96 bl sp_min_plat_arch_setup
98 /* Jump to the main function */
101 /* -------------------------------------------------------------
102 * Clean the .data & .bss sections to main memory. This ensures
103 * that any global data which was initialised by the primary CPU
104 * is visible to secondary CPUs before they enable their data
105 * caches and participate in coherency.
106 * -------------------------------------------------------------
108 ldr r0, =__DATA_START__
109 ldr r1, =__DATA_END__
111 bl clean_dcache_range
113 ldr r0, =__BSS_START__
116 bl clean_dcache_range
118 /* Program the registers in cpu_context and exit monitor mode */
122 /* Restore the SCR */
123 ldr r2, [r0, #CTX_REGS_OFFSET + CTX_SCR]
127 /* Restore the SCTLR */
128 ldr r2, [r0, #CTX_REGS_OFFSET + CTX_NS_SCTLR]
132 /* The other cpu_context registers have been copied to smc context */
134 endfunc sp_min_entrypoint
138 * SMC handling function for SP_MIN.
141 smcc_save_gp_mode_regs
143 /* r0 points to smc_context */
144 mov r2, r0 /* handle */
148 * Save SCR in stack. r1 is pushed to meet the 8 byte
149 * stack alignment requirement.
152 and r3, r0, #SCR_NS_BIT /* flags */
154 /* Switch to Secure Mode*/
158 ldr r0, [r2, #SMC_CTX_GPREG_R0] /* smc_fid */
159 /* Check whether an SMC64 is issued */
160 tst r0, #(FUNCID_CC_MASK << FUNCID_CC_SHIFT)
161 beq 1f /* SMC32 is detected */
163 str r0, [r2, #SMC_CTX_GPREG_R0]
165 b 2f /* Skip handling the SMC */
167 mov r1, #0 /* cookie */
168 bl handle_runtime_svc
170 /* r0 points to smc context */
172 /* Restore SCR from stack */
182 * The Warm boot entrypoint for SP_MIN.
184 func sp_min_warm_entrypoint
186 * On the warm boot path, most of the EL3 initialisations performed by
187 * 'el3_entrypoint_common' must be skipped:
189 * - Only when the platform bypasses the BL1/BL32 (SP_MIN) entrypoint by
190 * programming the reset address do we need to set the CPU endianness.
191 * In other cases, we assume this has been taken care by the
194 * - No need to determine the type of boot, we know it is a warm boot.
196 * - Do not try to distinguish between primary and secondary CPUs, this
197 * notion only exists for a cold boot.
199 * - No need to initialise the memory or the C runtime environment,
200 * it has been done once and for all on the cold boot path.
202 el3_entrypoint_common \
203 _set_endian=PROGRAMMABLE_RESET_ADDRESS \
204 _warm_boot_mailbox=0 \
205 _secondary_cold_boot=0 \
208 _exception_vectors=sp_min_vector_table
211 * We're about to enable MMU and participate in PSCI state coordination.
213 * The PSCI implementation invokes platform routines that enable CPUs to
214 * participate in coherency. On a system where CPUs are not
215 * cache-coherent without appropriate platform specific programming,
216 * having caches enabled until such time might lead to coherency issues
217 * (resulting from stale data getting speculatively fetched, among
218 * others). Therefore we keep data caches disabled even after enabling
219 * the MMU for such platforms.
221 * On systems with hardware-assisted coherency, or on single cluster
222 * platforms, such platform specific programming is not required to
223 * enter coherency (as CPUs already are); and there's no reason to have
224 * caches disabled either.
226 mov r0, #DISABLE_DCACHE
227 bl bl32_plat_enable_mmu
229 #if HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY
231 orr r0, r0, #SCTLR_C_BIT
238 /* Program the registers in cpu_context and exit monitor mode */
242 /* Restore the SCR */
243 ldr r2, [r0, #CTX_REGS_OFFSET + CTX_SCR]
247 /* Restore the SCTLR */
248 ldr r2, [r0, #CTX_REGS_OFFSET + CTX_NS_SCTLR]
253 /* The other cpu_context registers have been copied to smc context */
255 endfunc sp_min_warm_entrypoint
258 * The function to restore the registers from SMC context and return
259 * to the mode restored to SPSR.
261 * Arguments : r0 must point to the SMC context to restore from.
264 smcc_restore_gp_mode_regs