xref: /rk3399_ARM-atf/include/lib/el3_runtime/context_mgmt.h (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
1532ed618SSoby Mathew /*
25dffb46cSSoby Mathew  * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
3532ed618SSoby Mathew  *
4*82cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5532ed618SSoby Mathew  */
6532ed618SSoby Mathew 
7532ed618SSoby Mathew #ifndef __CM_H__
8532ed618SSoby Mathew #define __CM_H__
9532ed618SSoby Mathew 
105dffb46cSSoby Mathew #ifndef AARCH32
11532ed618SSoby Mathew #include <arch.h>
125dffb46cSSoby Mathew #endif
13532ed618SSoby Mathew 
14532ed618SSoby Mathew /*******************************************************************************
15532ed618SSoby Mathew  * Forward declarations
16532ed618SSoby Mathew  ******************************************************************************/
17532ed618SSoby Mathew struct entry_point_info;
18532ed618SSoby Mathew 
19532ed618SSoby Mathew /*******************************************************************************
20532ed618SSoby Mathew  * Function & variable prototypes
21532ed618SSoby Mathew  ******************************************************************************/
22532ed618SSoby Mathew void cm_init(void);
23532ed618SSoby Mathew void *cm_get_context_by_index(unsigned int cpu_idx,
24532ed618SSoby Mathew 			      unsigned int security_state);
25532ed618SSoby Mathew void cm_set_context_by_index(unsigned int cpu_idx,
26532ed618SSoby Mathew 			     void *context,
27532ed618SSoby Mathew 			     unsigned int security_state);
28532ed618SSoby Mathew void *cm_get_context(uint32_t security_state);
29532ed618SSoby Mathew void cm_set_context(void *context, uint32_t security_state);
30532ed618SSoby Mathew void cm_init_my_context(const struct entry_point_info *ep);
31532ed618SSoby Mathew void cm_init_context_by_index(unsigned int cpu_idx,
32532ed618SSoby Mathew 			      const struct entry_point_info *ep);
33532ed618SSoby Mathew void cm_prepare_el3_exit(uint32_t security_state);
34e33b78a6SSoby Mathew 
35e33b78a6SSoby Mathew #ifndef AARCH32
36532ed618SSoby Mathew void cm_el1_sysregs_context_save(uint32_t security_state);
37532ed618SSoby Mathew void cm_el1_sysregs_context_restore(uint32_t security_state);
38532ed618SSoby Mathew void cm_set_elr_el3(uint32_t security_state, uintptr_t entrypoint);
39532ed618SSoby Mathew void cm_set_elr_spsr_el3(uint32_t security_state,
40532ed618SSoby Mathew 			uintptr_t entrypoint, uint32_t spsr);
41532ed618SSoby Mathew void cm_write_scr_el3_bit(uint32_t security_state,
42532ed618SSoby Mathew 			  uint32_t bit_pos,
43532ed618SSoby Mathew 			  uint32_t value);
44532ed618SSoby Mathew void cm_set_next_eret_context(uint32_t security_state);
45532ed618SSoby Mathew uint32_t cm_get_scr_el3(uint32_t security_state);
46532ed618SSoby Mathew 
47e33b78a6SSoby Mathew 
48e33b78a6SSoby Mathew void cm_init_context(uint64_t mpidr,
49e33b78a6SSoby Mathew 		     const struct entry_point_info *ep) __deprecated;
50e33b78a6SSoby Mathew 
51e33b78a6SSoby Mathew void *cm_get_context_by_mpidr(uint64_t mpidr,
52e33b78a6SSoby Mathew 			      uint32_t security_state) __deprecated;
53e33b78a6SSoby Mathew void cm_set_context_by_mpidr(uint64_t mpidr,
54e33b78a6SSoby Mathew 			     void *context,
55e33b78a6SSoby Mathew 			     uint32_t security_state) __deprecated;
56e33b78a6SSoby Mathew 
57532ed618SSoby Mathew /* Inline definitions */
58532ed618SSoby Mathew 
59532ed618SSoby Mathew /*******************************************************************************
60532ed618SSoby Mathew  * This function is used to program the context that's used for exception
61532ed618SSoby Mathew  * return. This initializes the SP_EL3 to a pointer to a 'cpu_context' set for
62532ed618SSoby Mathew  * the required security state
63532ed618SSoby Mathew  ******************************************************************************/
64532ed618SSoby Mathew static inline void cm_set_next_context(void *context)
65532ed618SSoby Mathew {
66aa61368eSAntonio Nino Diaz #if ENABLE_ASSERTIONS
67532ed618SSoby Mathew 	uint64_t sp_mode;
68532ed618SSoby Mathew 
69532ed618SSoby Mathew 	/*
70532ed618SSoby Mathew 	 * Check that this function is called with SP_EL0 as the stack
71532ed618SSoby Mathew 	 * pointer
72532ed618SSoby Mathew 	 */
73532ed618SSoby Mathew 	__asm__ volatile("mrs	%0, SPSel\n"
74532ed618SSoby Mathew 			 : "=r" (sp_mode));
75532ed618SSoby Mathew 
76532ed618SSoby Mathew 	assert(sp_mode == MODE_SP_EL0);
77aa61368eSAntonio Nino Diaz #endif /* ENABLE_ASSERTIONS */
78532ed618SSoby Mathew 
79532ed618SSoby Mathew 	__asm__ volatile("msr	spsel, #1\n"
80532ed618SSoby Mathew 			 "mov	sp, %0\n"
81532ed618SSoby Mathew 			 "msr	spsel, #0\n"
82532ed618SSoby Mathew 			 : : "r" (context));
83532ed618SSoby Mathew }
84f3b4914bSYatharth Kochar 
85f3b4914bSYatharth Kochar #else
86f3b4914bSYatharth Kochar void *cm_get_next_context(void);
87e33b78a6SSoby Mathew #endif /* AARCH32 */
88f3b4914bSYatharth Kochar 
89532ed618SSoby Mathew #endif /* __CM_H__ */
90