blob: 2b619aaa568312b3bd3e15b44b0d82f6b9bd8d66 [file] [log] [blame]
Achin Gupta7aea9082014-02-01 07:51:28 +00001/*
Soby Mathewb0082d22015-04-09 13:40:55 +01002 * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
Achin Gupta7aea9082014-02-01 07:51:28 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
Achin Gupta27b895e2014-05-04 18:38:28 +010031#include <arch.h>
Achin Gupta7aea9082014-02-01 07:51:28 +000032#include <arch_helpers.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010033#include <assert.h>
Achin Gupta7aea9082014-02-01 07:51:28 +000034#include <bl_common.h>
Soby Mathew5e5c2072014-04-07 15:28:55 +010035#include <bl31.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010036#include <context.h>
Achin Gupta7aea9082014-02-01 07:51:28 +000037#include <context_mgmt.h>
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010038#include <cpu_data.h>
Achin Gupta191e86e2014-05-09 10:03:15 +010039#include <interrupt_mgmt.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010040#include <platform.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010041#include <platform_def.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010042#include <runtime_svc.h>
Andrew Thoelke4e126072014-06-04 21:10:52 +010043#include <string.h>
Achin Gupta7aea9082014-02-01 07:51:28 +000044
Achin Gupta7aea9082014-02-01 07:51:28 +000045
46/*******************************************************************************
47 * Context management library initialisation routine. This library is used by
48 * runtime services to share pointers to 'cpu_context' structures for the secure
49 * and non-secure states. Management of the structures and their associated
50 * memory is not done by the context management library e.g. the PSCI service
51 * manages the cpu context used for entry from and exit to the non-secure state.
52 * The Secure payload dispatcher service manages the context(s) corresponding to
53 * the secure state. It also uses this library to get access to the non-secure
54 * state cpu context pointers.
55 * Lastly, this library provides the api to make SP_EL3 point to the cpu context
56 * which will used for programming an entry into a lower EL. The same context
57 * will used to save state upon exception entry from that EL.
58 ******************************************************************************/
Juan Castillo2d552402014-06-13 17:05:10 +010059void cm_init(void)
Achin Gupta7aea9082014-02-01 07:51:28 +000060{
61 /*
62 * The context management library has only global data to intialize, but
63 * that will be done when the BSS is zeroed out
64 */
65}
66
67/*******************************************************************************
68 * This function returns a pointer to the most recent 'cpu_context' structure
Soby Mathewb0082d22015-04-09 13:40:55 +010069 * for the CPU identified by `cpu_idx` that was set as the context for the
70 * specified security state. NULL is returned if no such structure has been
71 * specified.
72 ******************************************************************************/
73void *cm_get_context_by_index(unsigned int cpu_idx,
74 unsigned int security_state)
75{
76 assert(sec_state_is_valid(security_state));
77
78 return get_cpu_data_by_index(cpu_idx, cpu_context[security_state]);
79}
80
81/*******************************************************************************
82 * This function sets the pointer to the current 'cpu_context' structure for the
83 * specified security state for the CPU identified by CPU index.
84 ******************************************************************************/
85void cm_set_context_by_index(unsigned int cpu_idx, void *context,
86 unsigned int security_state)
87{
88 assert(sec_state_is_valid(security_state));
89
90 set_cpu_data_by_index(cpu_idx, cpu_context[security_state], context);
91}
92
Soby Mathew18a62042015-10-26 14:29:21 +000093#if !ERROR_DEPRECATED
94/*
95 * These context management helpers are deprecated but are maintained for use
96 * by SPDs which have not migrated to the new API. If ERROR_DEPRECATED
97 * is enabled, these are excluded from the build so as to force users to
98 * migrate to the new API.
99 */
100
Soby Mathewb0082d22015-04-09 13:40:55 +0100101/*******************************************************************************
102 * This function returns a pointer to the most recent 'cpu_context' structure
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100103 * for the CPU identified by MPIDR that was set as the context for the specified
104 * security state. NULL is returned if no such structure has been specified.
Achin Gupta7aea9082014-02-01 07:51:28 +0000105 ******************************************************************************/
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100106void *cm_get_context_by_mpidr(uint64_t mpidr, uint32_t security_state)
Achin Gupta7aea9082014-02-01 07:51:28 +0000107{
Juan Castillof558cac2014-06-05 09:45:36 +0100108 assert(sec_state_is_valid(security_state));
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100109
Soby Mathewb0082d22015-04-09 13:40:55 +0100110 return cm_get_context_by_index(platform_get_core_pos(mpidr), security_state);
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100111}
112
113/*******************************************************************************
Achin Gupta7aea9082014-02-01 07:51:28 +0000114 * This function sets the pointer to the current 'cpu_context' structure for the
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100115 * specified security state for the CPU identified by MPIDR
Achin Gupta7aea9082014-02-01 07:51:28 +0000116 ******************************************************************************/
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100117void cm_set_context_by_mpidr(uint64_t mpidr, void *context, uint32_t security_state)
Achin Gupta7aea9082014-02-01 07:51:28 +0000118{
Juan Castillof558cac2014-06-05 09:45:36 +0100119 assert(sec_state_is_valid(security_state));
Achin Gupta7aea9082014-02-01 07:51:28 +0000120
Soby Mathewb0082d22015-04-09 13:40:55 +0100121 cm_set_context_by_index(platform_get_core_pos(mpidr),
122 context, security_state);
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100123}
Soby Mathew18a62042015-10-26 14:29:21 +0000124
125/*******************************************************************************
126 * The following function provides a compatibility function for SPDs using the
127 * existing cm library routines. This function is expected to be invoked for
128 * initializing the cpu_context for the CPU specified by MPIDR for first use.
129 ******************************************************************************/
130void cm_init_context(unsigned long mpidr, const entry_point_info_t *ep)
131{
132 if ((mpidr & MPIDR_AFFINITY_MASK) ==
133 (read_mpidr_el1() & MPIDR_AFFINITY_MASK))
134 cm_init_my_context(ep);
135 else
136 cm_init_context_by_index(platform_get_core_pos(mpidr), ep);
137}
138#endif
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100139
140/*******************************************************************************
Andrew Thoelke4e126072014-06-04 21:10:52 +0100141 * This function is used to program the context that's used for exception
142 * return. This initializes the SP_EL3 to a pointer to a 'cpu_context' set for
143 * the required security state
144 ******************************************************************************/
145static inline void cm_set_next_context(void *context)
146{
147#if DEBUG
148 uint64_t sp_mode;
149
150 /*
151 * Check that this function is called with SP_EL0 as the stack
152 * pointer
153 */
154 __asm__ volatile("mrs %0, SPSel\n"
155 : "=r" (sp_mode));
156
157 assert(sp_mode == MODE_SP_EL0);
158#endif
159
160 __asm__ volatile("msr spsel, #1\n"
161 "mov sp, %0\n"
162 "msr spsel, #0\n"
163 : : "r" (context));
164}
165
166/*******************************************************************************
Soby Mathewb0082d22015-04-09 13:40:55 +0100167 * The following function initializes the cpu_context 'ctx' for
Andrew Thoelke4e126072014-06-04 21:10:52 +0100168 * first use, and sets the initial entrypoint state as specified by the
169 * entry_point_info structure.
170 *
171 * The security state to initialize is determined by the SECURE attribute
172 * of the entry_point_info. The function returns a pointer to the initialized
173 * context and sets this as the next context to return to.
174 *
175 * The EE and ST attributes are used to configure the endianess and secure
Soby Mathewb0082d22015-04-09 13:40:55 +0100176 * timer availability for the new execution context.
Andrew Thoelke4e126072014-06-04 21:10:52 +0100177 *
178 * To prepare the register state for entry call cm_prepare_el3_exit() and
179 * el3_exit(). For Secure-EL1 cm_prepare_el3_exit() is equivalent to
180 * cm_e1_sysreg_context_restore().
181 ******************************************************************************/
Soby Mathewb0082d22015-04-09 13:40:55 +0100182static void cm_init_context_common(cpu_context_t *ctx, const entry_point_info_t *ep)
Andrew Thoelke4e126072014-06-04 21:10:52 +0100183{
Soby Mathewb0082d22015-04-09 13:40:55 +0100184 unsigned int security_state;
Andrew Thoelke4e126072014-06-04 21:10:52 +0100185 uint32_t scr_el3;
186 el3_state_t *state;
187 gp_regs_t *gp_regs;
188 unsigned long sctlr_elx;
189
Andrew Thoelke4e126072014-06-04 21:10:52 +0100190 assert(ctx);
191
Soby Mathewb0082d22015-04-09 13:40:55 +0100192 security_state = GET_SECURITY_STATE(ep->h.attr);
193
Andrew Thoelke4e126072014-06-04 21:10:52 +0100194 /* Clear any residual register values from the context */
195 memset(ctx, 0, sizeof(*ctx));
196
197 /*
198 * Base the context SCR on the current value, adjust for entry point
199 * specific requirements and set trap bits from the IMF
200 * TODO: provide the base/global SCR bits using another mechanism?
201 */
202 scr_el3 = read_scr();
203 scr_el3 &= ~(SCR_NS_BIT | SCR_RW_BIT | SCR_FIQ_BIT | SCR_IRQ_BIT |
204 SCR_ST_BIT | SCR_HCE_BIT);
205
206 if (security_state != SECURE)
207 scr_el3 |= SCR_NS_BIT;
208
209 if (GET_RW(ep->spsr) == MODE_RW_64)
210 scr_el3 |= SCR_RW_BIT;
211
212 if (EP_GET_ST(ep->h.attr))
213 scr_el3 |= SCR_ST_BIT;
214
215 scr_el3 |= get_scr_el3_from_routing_model(security_state);
216
217 /*
218 * Set up SCTLR_ELx for the target exception level:
219 * EE bit is taken from the entrpoint attributes
220 * M, C and I bits must be zero (as required by PSCI specification)
221 *
222 * The target exception level is based on the spsr mode requested.
223 * If execution is requested to EL2 or hyp mode, HVC is enabled
224 * via SCR_EL3.HCE.
225 *
226 * Always compute the SCTLR_EL1 value and save in the cpu_context
227 * - the EL2 registers are set up by cm_preapre_ns_entry() as they
228 * are not part of the stored cpu_context
229 *
230 * TODO: In debug builds the spsr should be validated and checked
231 * against the CPU support, security state, endianess and pc
232 */
233 sctlr_elx = EP_GET_EE(ep->h.attr) ? SCTLR_EE_BIT : 0;
Jens Wiklanderc93c9df2014-09-04 10:23:27 +0200234 if (GET_RW(ep->spsr) == MODE_RW_64)
235 sctlr_elx |= SCTLR_EL1_RES1;
236 else
237 sctlr_elx |= SCTLR_AARCH32_EL1_RES1;
Andrew Thoelke4e126072014-06-04 21:10:52 +0100238 write_ctx_reg(get_sysregs_ctx(ctx), CTX_SCTLR_EL1, sctlr_elx);
239
240 if ((GET_RW(ep->spsr) == MODE_RW_64
241 && GET_EL(ep->spsr) == MODE_EL2)
242 || (GET_RW(ep->spsr) != MODE_RW_64
243 && GET_M32(ep->spsr) == MODE32_hyp)) {
244 scr_el3 |= SCR_HCE_BIT;
245 }
246
247 /* Populate EL3 state so that we've the right context before doing ERET */
248 state = get_el3state_ctx(ctx);
249 write_ctx_reg(state, CTX_SCR_EL3, scr_el3);
250 write_ctx_reg(state, CTX_ELR_EL3, ep->pc);
251 write_ctx_reg(state, CTX_SPSR_EL3, ep->spsr);
252
253 /*
254 * Store the X0-X7 value from the entrypoint into the context
255 * Use memcpy as we are in control of the layout of the structures
256 */
257 gp_regs = get_gpregs_ctx(ctx);
258 memcpy(gp_regs, (void *)&ep->args, sizeof(aapcs64_params_t));
259}
260
261/*******************************************************************************
Soby Mathewb0082d22015-04-09 13:40:55 +0100262 * The following function initializes the cpu_context for a CPU specified by
263 * its `cpu_idx` for first use, and sets the initial entrypoint state as
264 * specified by the entry_point_info structure.
265 ******************************************************************************/
266void cm_init_context_by_index(unsigned int cpu_idx,
267 const entry_point_info_t *ep)
268{
269 cpu_context_t *ctx;
270 ctx = cm_get_context_by_index(cpu_idx, GET_SECURITY_STATE(ep->h.attr));
271 cm_init_context_common(ctx, ep);
272}
273
274/*******************************************************************************
275 * The following function initializes the cpu_context for the current CPU
276 * for first use, and sets the initial entrypoint state as specified by the
277 * entry_point_info structure.
278 ******************************************************************************/
279void cm_init_my_context(const entry_point_info_t *ep)
280{
281 cpu_context_t *ctx;
282 ctx = cm_get_context(GET_SECURITY_STATE(ep->h.attr));
283 cm_init_context_common(ctx, ep);
284}
285
286/*******************************************************************************
Andrew Thoelke4e126072014-06-04 21:10:52 +0100287 * Prepare the CPU system registers for first entry into secure or normal world
288 *
289 * If execution is requested to EL2 or hyp mode, SCTLR_EL2 is initialized
290 * If execution is requested to non-secure EL1 or svc mode, and the CPU supports
291 * EL2 then EL2 is disabled by configuring all necessary EL2 registers.
292 * For all entries, the EL1 registers are initialized from the cpu_context
293 ******************************************************************************/
294void cm_prepare_el3_exit(uint32_t security_state)
295{
296 uint32_t sctlr_elx, scr_el3, cptr_el2;
297 cpu_context_t *ctx = cm_get_context(security_state);
298
299 assert(ctx);
300
301 if (security_state == NON_SECURE) {
302 scr_el3 = read_ctx_reg(get_el3state_ctx(ctx), CTX_SCR_EL3);
303 if (scr_el3 & SCR_HCE_BIT) {
304 /* Use SCTLR_EL1.EE value to initialise sctlr_el2 */
305 sctlr_elx = read_ctx_reg(get_sysregs_ctx(ctx),
306 CTX_SCTLR_EL1);
307 sctlr_elx &= ~SCTLR_EE_BIT;
308 sctlr_elx |= SCTLR_EL2_RES1;
309 write_sctlr_el2(sctlr_elx);
310 } else if (read_id_aa64pfr0_el1() &
311 (ID_AA64PFR0_ELX_MASK << ID_AA64PFR0_EL2_SHIFT)) {
312 /* EL2 present but unused, need to disable safely */
313
314 /* HCR_EL2 = 0, except RW bit set to match SCR_EL3 */
315 write_hcr_el2((scr_el3 & SCR_RW_BIT) ? HCR_RW_BIT : 0);
316
317 /* SCTLR_EL2 : can be ignored when bypassing */
318
319 /* CPTR_EL2 : disable all traps TCPAC, TTA, TFP */
320 cptr_el2 = read_cptr_el2();
321 cptr_el2 &= ~(TCPAC_BIT | TTA_BIT | TFP_BIT);
322 write_cptr_el2(cptr_el2);
323
324 /* Enable EL1 access to timer */
325 write_cnthctl_el2(EL1PCEN_BIT | EL1PCTEN_BIT);
326
Soby Mathewfeddfcf2014-08-29 14:41:58 +0100327 /* Reset CNTVOFF_EL2 */
328 write_cntvoff_el2(0);
329
Andrew Thoelke4e126072014-06-04 21:10:52 +0100330 /* Set VPIDR, VMPIDR to match MIDR, MPIDR */
331 write_vpidr_el2(read_midr_el1());
332 write_vmpidr_el2(read_mpidr_el1());
Sandrine Bailleux8b0eafe2015-11-25 17:00:44 +0000333
334 /*
335 * Reset VTTBR_EL2.
336 * Needed because cache maintenance operations depend on
337 * the VMID even when non-secure EL1&0 stage 2 address
338 * translation are disabled.
339 */
340 write_vttbr_el2(0);
Andrew Thoelke4e126072014-06-04 21:10:52 +0100341 }
342 }
343
344 el1_sysregs_context_restore(get_sysregs_ctx(ctx));
345
346 cm_set_next_context(ctx);
347}
348
349/*******************************************************************************
Soby Mathew2ed46e92014-07-04 16:02:26 +0100350 * The next four functions are used by runtime services to save and restore
351 * EL1 context on the 'cpu_context' structure for the specified security
Achin Gupta7aea9082014-02-01 07:51:28 +0000352 * state.
353 ******************************************************************************/
Achin Gupta7aea9082014-02-01 07:51:28 +0000354void cm_el1_sysregs_context_save(uint32_t security_state)
355{
Dan Handleye2712bc2014-04-10 15:37:22 +0100356 cpu_context_t *ctx;
Achin Gupta7aea9082014-02-01 07:51:28 +0000357
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100358 ctx = cm_get_context(security_state);
Achin Gupta7aea9082014-02-01 07:51:28 +0000359 assert(ctx);
360
361 el1_sysregs_context_save(get_sysregs_ctx(ctx));
362}
363
364void cm_el1_sysregs_context_restore(uint32_t security_state)
365{
Dan Handleye2712bc2014-04-10 15:37:22 +0100366 cpu_context_t *ctx;
Achin Gupta7aea9082014-02-01 07:51:28 +0000367
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100368 ctx = cm_get_context(security_state);
Achin Gupta7aea9082014-02-01 07:51:28 +0000369 assert(ctx);
370
371 el1_sysregs_context_restore(get_sysregs_ctx(ctx));
372}
373
374/*******************************************************************************
Andrew Thoelke4e126072014-06-04 21:10:52 +0100375 * This function populates ELR_EL3 member of 'cpu_context' pertaining to the
376 * given security state with the given entrypoint
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000377 ******************************************************************************/
Andrew Thoelke4e126072014-06-04 21:10:52 +0100378void cm_set_elr_el3(uint32_t security_state, uint64_t entrypoint)
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000379{
Dan Handleye2712bc2014-04-10 15:37:22 +0100380 cpu_context_t *ctx;
381 el3_state_t *state;
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000382
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100383 ctx = cm_get_context(security_state);
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000384 assert(ctx);
385
Andrew Thoelke4e126072014-06-04 21:10:52 +0100386 /* Populate EL3 state so that ERET jumps to the correct entry */
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000387 state = get_el3state_ctx(ctx);
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000388 write_ctx_reg(state, CTX_ELR_EL3, entrypoint);
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000389}
390
391/*******************************************************************************
Andrew Thoelke4e126072014-06-04 21:10:52 +0100392 * This function populates ELR_EL3 and SPSR_EL3 members of 'cpu_context'
393 * pertaining to the given security state
Achin Gupta607084e2014-02-09 18:24:19 +0000394 ******************************************************************************/
Andrew Thoelke4e126072014-06-04 21:10:52 +0100395void cm_set_elr_spsr_el3(uint32_t security_state,
396 uint64_t entrypoint, uint32_t spsr)
Achin Gupta607084e2014-02-09 18:24:19 +0000397{
Dan Handleye2712bc2014-04-10 15:37:22 +0100398 cpu_context_t *ctx;
399 el3_state_t *state;
Achin Gupta607084e2014-02-09 18:24:19 +0000400
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100401 ctx = cm_get_context(security_state);
Achin Gupta607084e2014-02-09 18:24:19 +0000402 assert(ctx);
403
404 /* Populate EL3 state so that ERET jumps to the correct entry */
405 state = get_el3state_ctx(ctx);
406 write_ctx_reg(state, CTX_ELR_EL3, entrypoint);
Andrew Thoelke4e126072014-06-04 21:10:52 +0100407 write_ctx_reg(state, CTX_SPSR_EL3, spsr);
Achin Gupta607084e2014-02-09 18:24:19 +0000408}
409
410/*******************************************************************************
Achin Gupta27b895e2014-05-04 18:38:28 +0100411 * This function updates a single bit in the SCR_EL3 member of the 'cpu_context'
412 * pertaining to the given security state using the value and bit position
413 * specified in the parameters. It preserves all other bits.
414 ******************************************************************************/
415void cm_write_scr_el3_bit(uint32_t security_state,
416 uint32_t bit_pos,
417 uint32_t value)
418{
419 cpu_context_t *ctx;
420 el3_state_t *state;
421 uint32_t scr_el3;
422
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100423 ctx = cm_get_context(security_state);
Achin Gupta27b895e2014-05-04 18:38:28 +0100424 assert(ctx);
425
426 /* Ensure that the bit position is a valid one */
427 assert((1 << bit_pos) & SCR_VALID_BIT_MASK);
428
429 /* Ensure that the 'value' is only a bit wide */
430 assert(value <= 1);
431
432 /*
433 * Get the SCR_EL3 value from the cpu context, clear the desired bit
434 * and set it to its new value.
435 */
436 state = get_el3state_ctx(ctx);
437 scr_el3 = read_ctx_reg(state, CTX_SCR_EL3);
438 scr_el3 &= ~(1 << bit_pos);
439 scr_el3 |= value << bit_pos;
440 write_ctx_reg(state, CTX_SCR_EL3, scr_el3);
441}
442
443/*******************************************************************************
444 * This function retrieves SCR_EL3 member of 'cpu_context' pertaining to the
445 * given security state.
446 ******************************************************************************/
447uint32_t cm_get_scr_el3(uint32_t security_state)
448{
449 cpu_context_t *ctx;
450 el3_state_t *state;
451
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100452 ctx = cm_get_context(security_state);
Achin Gupta27b895e2014-05-04 18:38:28 +0100453 assert(ctx);
454
455 /* Populate EL3 state so that ERET jumps to the correct entry */
456 state = get_el3state_ctx(ctx);
457 return read_ctx_reg(state, CTX_SCR_EL3);
458}
459
460/*******************************************************************************
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000461 * This function is used to program the context that's used for exception
462 * return. This initializes the SP_EL3 to a pointer to a 'cpu_context' set for
463 * the required security state
Achin Gupta7aea9082014-02-01 07:51:28 +0000464 ******************************************************************************/
465void cm_set_next_eret_context(uint32_t security_state)
466{
Dan Handleye2712bc2014-04-10 15:37:22 +0100467 cpu_context_t *ctx;
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000468
Andrew Thoelkea2f65532014-05-14 17:09:32 +0100469 ctx = cm_get_context(security_state);
Achin Gupta7aea9082014-02-01 07:51:28 +0000470 assert(ctx);
471
Andrew Thoelke4e126072014-06-04 21:10:52 +0100472 cm_set_next_context(ctx);
Achin Gupta7aea9082014-02-01 07:51:28 +0000473}