blob: c1f04b972772d7e9d0e11e8a32bfd0d2d0e84739 [file] [log] [blame]
Achin Gupta7aea9082014-02-01 07:51:28 +00001/*
Soby Mathewb911cc72017-02-13 12:46:28 +00002 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
Achin Gupta7aea9082014-02-01 07:51:28 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta7aea9082014-02-01 07:51:28 +00005 */
6
7#ifndef __CM_H__
8#define __CM_H__
9
Soby Mathewb911cc72017-02-13 12:46:28 +000010#ifndef AARCH32
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010011#include <arch.h>
Soby Mathewb911cc72017-02-13 12:46:28 +000012#endif
Achin Gupta7aea9082014-02-01 07:51:28 +000013
Achin Gupta7aea9082014-02-01 07:51:28 +000014/*******************************************************************************
Andrew Thoelke4e126072014-06-04 21:10:52 +010015 * Forward declarations
16 ******************************************************************************/
17struct entry_point_info;
18
19/*******************************************************************************
Achin Gupta7aea9082014-02-01 07:51:28 +000020 * Function & variable prototypes
21 ******************************************************************************/
Dan Handleya17fefa2014-05-14 12:38:32 +010022void cm_init(void);
Soby Mathewb0082d22015-04-09 13:40:55 +010023void *cm_get_context_by_index(unsigned int cpu_idx,
24 unsigned int security_state);
25void cm_set_context_by_index(unsigned int cpu_idx,
26 void *context,
27 unsigned int security_state);
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010028void *cm_get_context(uint32_t security_state);
29void cm_set_context(void *context, uint32_t security_state);
Soby Mathewb0082d22015-04-09 13:40:55 +010030void cm_init_my_context(const struct entry_point_info *ep);
31void cm_init_context_by_index(unsigned int cpu_idx,
32 const struct entry_point_info *ep);
Andrew Thoelke4e126072014-06-04 21:10:52 +010033void cm_prepare_el3_exit(uint32_t security_state);
Soby Mathew748be1d2016-05-05 14:10:46 +010034
35#ifndef AARCH32
Dan Handleya17fefa2014-05-14 12:38:32 +010036void cm_el1_sysregs_context_save(uint32_t security_state);
37void cm_el1_sysregs_context_restore(uint32_t security_state);
Soby Mathewa0fedc42016-06-16 14:52:04 +010038void cm_set_elr_el3(uint32_t security_state, uintptr_t entrypoint);
Andrew Thoelke4e126072014-06-04 21:10:52 +010039void cm_set_elr_spsr_el3(uint32_t security_state,
Soby Mathewa0fedc42016-06-16 14:52:04 +010040 uintptr_t entrypoint, uint32_t spsr);
Dan Handleya17fefa2014-05-14 12:38:32 +010041void cm_write_scr_el3_bit(uint32_t security_state,
42 uint32_t bit_pos,
43 uint32_t value);
44void cm_set_next_eret_context(uint32_t security_state);
Dan Handleya17fefa2014-05-14 12:38:32 +010045uint32_t cm_get_scr_el3(uint32_t security_state);
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010046
Soby Mathew748be1d2016-05-05 14:10:46 +010047
48void cm_init_context(uint64_t mpidr,
49 const struct entry_point_info *ep) __deprecated;
50
51void *cm_get_context_by_mpidr(uint64_t mpidr,
52 uint32_t security_state) __deprecated;
53void cm_set_context_by_mpidr(uint64_t mpidr,
54 void *context,
55 uint32_t security_state) __deprecated;
56
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010057/* Inline definitions */
58
59/*******************************************************************************
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010060 * 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
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010063 ******************************************************************************/
Sandrine Bailleux37a12df2016-04-11 13:17:50 +010064static inline void cm_set_next_context(void *context)
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010065{
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000066#if ENABLE_ASSERTIONS
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010067 uint64_t sp_mode;
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010068
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010069 /*
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));
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010075
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010076 assert(sp_mode == MODE_SP_EL0);
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000077#endif /* ENABLE_ASSERTIONS */
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010078
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010079 __asm__ volatile("msr spsel, #1\n"
80 "mov sp, %0\n"
81 "msr spsel, #0\n"
82 : : "r" (context));
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010083}
Yatharth Kochar5d361212016-06-28 17:07:09 +010084
85#else
86void *cm_get_next_context(void);
Soby Mathew748be1d2016-05-05 14:10:46 +010087#endif /* AARCH32 */
Yatharth Kochar5d361212016-06-28 17:07:09 +010088
Achin Gupta7aea9082014-02-01 07:51:28 +000089#endif /* __CM_H__ */