blob: 6c43c66cfdae4b7d7bac19a64be374a7b6a871f3 [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 *
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
31#ifndef __CM_H__
32#define __CM_H__
33
Soby Mathewb911cc72017-02-13 12:46:28 +000034#ifndef AARCH32
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010035#include <arch.h>
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000036#include <assert.h>
37#include <stdint.h>
Soby Mathewb911cc72017-02-13 12:46:28 +000038#endif
Achin Gupta7aea9082014-02-01 07:51:28 +000039
Achin Gupta7aea9082014-02-01 07:51:28 +000040/*******************************************************************************
Andrew Thoelke4e126072014-06-04 21:10:52 +010041 * Forward declarations
42 ******************************************************************************/
43struct entry_point_info;
44
45/*******************************************************************************
Achin Gupta7aea9082014-02-01 07:51:28 +000046 * Function & variable prototypes
47 ******************************************************************************/
Dan Handleya17fefa2014-05-14 12:38:32 +010048void cm_init(void);
Soby Mathewb0082d22015-04-09 13:40:55 +010049void *cm_get_context_by_index(unsigned int cpu_idx,
50 unsigned int security_state);
51void cm_set_context_by_index(unsigned int cpu_idx,
52 void *context,
53 unsigned int security_state);
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010054void *cm_get_context(uint32_t security_state);
55void cm_set_context(void *context, uint32_t security_state);
Soby Mathewb0082d22015-04-09 13:40:55 +010056void cm_init_my_context(const struct entry_point_info *ep);
57void cm_init_context_by_index(unsigned int cpu_idx,
58 const struct entry_point_info *ep);
Andrew Thoelke4e126072014-06-04 21:10:52 +010059void cm_prepare_el3_exit(uint32_t security_state);
Soby Mathew748be1d2016-05-05 14:10:46 +010060
61#ifndef AARCH32
Dan Handleya17fefa2014-05-14 12:38:32 +010062void cm_el1_sysregs_context_save(uint32_t security_state);
63void cm_el1_sysregs_context_restore(uint32_t security_state);
Soby Mathewa0fedc42016-06-16 14:52:04 +010064void cm_set_elr_el3(uint32_t security_state, uintptr_t entrypoint);
Andrew Thoelke4e126072014-06-04 21:10:52 +010065void cm_set_elr_spsr_el3(uint32_t security_state,
Soby Mathewa0fedc42016-06-16 14:52:04 +010066 uintptr_t entrypoint, uint32_t spsr);
Dan Handleya17fefa2014-05-14 12:38:32 +010067void cm_write_scr_el3_bit(uint32_t security_state,
68 uint32_t bit_pos,
69 uint32_t value);
70void cm_set_next_eret_context(uint32_t security_state);
Dan Handleya17fefa2014-05-14 12:38:32 +010071uint32_t cm_get_scr_el3(uint32_t security_state);
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010072
Soby Mathew748be1d2016-05-05 14:10:46 +010073
74void cm_init_context(uint64_t mpidr,
75 const struct entry_point_info *ep) __deprecated;
76
77void *cm_get_context_by_mpidr(uint64_t mpidr,
78 uint32_t security_state) __deprecated;
79void cm_set_context_by_mpidr(uint64_t mpidr,
80 void *context,
81 uint32_t security_state) __deprecated;
82
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010083/* Inline definitions */
84
85/*******************************************************************************
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010086 * This function is used to program the context that's used for exception
87 * return. This initializes the SP_EL3 to a pointer to a 'cpu_context' set for
88 * the required security state
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010089 ******************************************************************************/
Sandrine Bailleux37a12df2016-04-11 13:17:50 +010090static inline void cm_set_next_context(void *context)
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010091{
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000092#if ENABLE_ASSERTIONS
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010093 uint64_t sp_mode;
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010094
Yatharth Kochar6c0566c2015-10-02 17:56:48 +010095 /*
96 * Check that this function is called with SP_EL0 as the stack
97 * pointer
98 */
99 __asm__ volatile("mrs %0, SPSel\n"
100 : "=r" (sp_mode));
Andrew Thoelkec02dbd62014-06-02 10:00:25 +0100101
Yatharth Kochar6c0566c2015-10-02 17:56:48 +0100102 assert(sp_mode == MODE_SP_EL0);
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +0000103#endif /* ENABLE_ASSERTIONS */
Andrew Thoelkec02dbd62014-06-02 10:00:25 +0100104
Yatharth Kochar6c0566c2015-10-02 17:56:48 +0100105 __asm__ volatile("msr spsel, #1\n"
106 "mov sp, %0\n"
107 "msr spsel, #0\n"
108 : : "r" (context));
Andrew Thoelkec02dbd62014-06-02 10:00:25 +0100109}
Yatharth Kochar5d361212016-06-28 17:07:09 +0100110
111#else
112void *cm_get_next_context(void);
Soby Mathew748be1d2016-05-05 14:10:46 +0100113#endif /* AARCH32 */
Yatharth Kochar5d361212016-06-28 17:07:09 +0100114
Achin Gupta7aea9082014-02-01 07:51:28 +0000115#endif /* __CM_H__ */