xref: /rk3399_ARM-atf/include/lib/el3_runtime/context_mgmt.h (revision f132b4a05b23916c1101add4bd6d973a99983719)
1 /*
2  * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef __CM_H__
8 #define __CM_H__
9 
10 #ifndef AARCH32
11 #include <arch.h>
12 #endif
13 
14 /*******************************************************************************
15  * Forward declarations
16  ******************************************************************************/
17 struct entry_point_info;
18 
19 /*******************************************************************************
20  * Function & variable prototypes
21  ******************************************************************************/
22 void cm_init(void);
23 void *cm_get_context_by_index(unsigned int cpu_idx,
24 			      unsigned int security_state);
25 void cm_set_context_by_index(unsigned int cpu_idx,
26 			     void *context,
27 			     unsigned int security_state);
28 void *cm_get_context(uint32_t security_state);
29 void cm_set_context(void *context, uint32_t security_state);
30 void cm_init_my_context(const struct entry_point_info *ep);
31 void cm_init_context_by_index(unsigned int cpu_idx,
32 			      const struct entry_point_info *ep);
33 void cm_prepare_el3_exit(uint32_t security_state);
34 
35 #ifndef AARCH32
36 void cm_el1_sysregs_context_save(uint32_t security_state);
37 void cm_el1_sysregs_context_restore(uint32_t security_state);
38 void cm_set_elr_el3(uint32_t security_state, uintptr_t entrypoint);
39 void cm_set_elr_spsr_el3(uint32_t security_state,
40 			uintptr_t entrypoint, uint32_t spsr);
41 void cm_write_scr_el3_bit(uint32_t security_state,
42 			  uint32_t bit_pos,
43 			  uint32_t value);
44 void cm_set_next_eret_context(uint32_t security_state);
45 uint32_t cm_get_scr_el3(uint32_t security_state);
46 
47 
48 void cm_init_context(uint64_t mpidr,
49 		     const struct entry_point_info *ep) __deprecated;
50 
51 void *cm_get_context_by_mpidr(uint64_t mpidr,
52 			      uint32_t security_state) __deprecated;
53 void cm_set_context_by_mpidr(uint64_t mpidr,
54 			     void *context,
55 			     uint32_t security_state) __deprecated;
56 
57 /* Inline definitions */
58 
59 /*******************************************************************************
60  * This function is used to program the context that's used for exception
61  * return. This initializes the SP_EL3 to a pointer to a 'cpu_context' set for
62  * the required security state
63  ******************************************************************************/
64 static inline void cm_set_next_context(void *context)
65 {
66 #if ENABLE_ASSERTIONS
67 	uint64_t sp_mode;
68 
69 	/*
70 	 * Check that this function is called with SP_EL0 as the stack
71 	 * pointer
72 	 */
73 	__asm__ volatile("mrs	%0, SPSel\n"
74 			 : "=r" (sp_mode));
75 
76 	assert(sp_mode == MODE_SP_EL0);
77 #endif /* ENABLE_ASSERTIONS */
78 
79 	__asm__ volatile("msr	spsel, #1\n"
80 			 "mov	sp, %0\n"
81 			 "msr	spsel, #0\n"
82 			 : : "r" (context));
83 }
84 
85 #else
86 void *cm_get_next_context(void);
87 #endif /* AARCH32 */
88 
89 #endif /* __CM_H__ */
90