xref: /rk3399_ARM-atf/services/spd/tspd/tspd_private.h (revision 97043ac98e13a726dbf8b3b41654dca759e3da2c)
1375f538aSAchin Gupta /*
2375f538aSAchin Gupta  * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3375f538aSAchin Gupta  *
4375f538aSAchin Gupta  * Redistribution and use in source and binary forms, with or without
5375f538aSAchin Gupta  * modification, are permitted provided that the following conditions are met:
6375f538aSAchin Gupta  *
7375f538aSAchin Gupta  * Redistributions of source code must retain the above copyright notice, this
8375f538aSAchin Gupta  * list of conditions and the following disclaimer.
9375f538aSAchin Gupta  *
10375f538aSAchin Gupta  * Redistributions in binary form must reproduce the above copyright notice,
11375f538aSAchin Gupta  * this list of conditions and the following disclaimer in the documentation
12375f538aSAchin Gupta  * and/or other materials provided with the distribution.
13375f538aSAchin Gupta  *
14375f538aSAchin Gupta  * Neither the name of ARM nor the names of its contributors may be used
15375f538aSAchin Gupta  * to endorse or promote products derived from this software without specific
16375f538aSAchin Gupta  * prior written permission.
17375f538aSAchin Gupta  *
18375f538aSAchin Gupta  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19375f538aSAchin Gupta  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20375f538aSAchin Gupta  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21375f538aSAchin Gupta  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22375f538aSAchin Gupta  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23375f538aSAchin Gupta  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24375f538aSAchin Gupta  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25375f538aSAchin Gupta  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26375f538aSAchin Gupta  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27375f538aSAchin Gupta  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28375f538aSAchin Gupta  * POSSIBILITY OF SUCH DAMAGE.
29375f538aSAchin Gupta  */
30375f538aSAchin Gupta 
31*97043ac9SDan Handley #ifndef __TSPD_PRIVATE_H__
32*97043ac9SDan Handley #define __TSPD_PRIVATE_H__
33375f538aSAchin Gupta 
34375f538aSAchin Gupta #include <arch.h>
35*97043ac9SDan Handley #include <context.h>
36*97043ac9SDan Handley #include <platform.h>
37375f538aSAchin Gupta #include <psci.h>
38375f538aSAchin Gupta 
39375f538aSAchin Gupta /*******************************************************************************
40375f538aSAchin Gupta  * Secure Payload PM state information e.g. SP is suspended, uninitialised etc
41375f538aSAchin Gupta  ******************************************************************************/
42375f538aSAchin Gupta #define TSP_STATE_OFF		0
43375f538aSAchin Gupta #define TSP_STATE_ON		1
44375f538aSAchin Gupta #define TSP_STATE_SUSPEND	2
45375f538aSAchin Gupta 
46375f538aSAchin Gupta /*******************************************************************************
47375f538aSAchin Gupta  * Secure Payload execution state information i.e. aarch32 or aarch64
48375f538aSAchin Gupta  ******************************************************************************/
49375f538aSAchin Gupta #define TSP_AARCH32		MODE_RW_32
50375f538aSAchin Gupta #define TSP_AARCH64		MODE_RW_64
51375f538aSAchin Gupta 
52375f538aSAchin Gupta /*******************************************************************************
53375f538aSAchin Gupta  * The SPD should know the type of Secure Payload.
54375f538aSAchin Gupta  ******************************************************************************/
55375f538aSAchin Gupta #define TSP_TYPE_UP		PSCI_TOS_NOT_UP_MIG_CAP
56375f538aSAchin Gupta #define TSP_TYPE_UPM		PSCI_TOS_UP_MIG_CAP
57375f538aSAchin Gupta #define TSP_TYPE_MP		PSCI_TOS_NOT_PRESENT_MP
58375f538aSAchin Gupta 
59375f538aSAchin Gupta /*******************************************************************************
60375f538aSAchin Gupta  * Secure Payload migrate type information as known to the SPD. We assume that
61375f538aSAchin Gupta  * the SPD is dealing with an MP Secure Payload.
62375f538aSAchin Gupta  ******************************************************************************/
63375f538aSAchin Gupta #define TSP_MIGRATE_INFO		TSP_TYPE_MP
64375f538aSAchin Gupta 
65375f538aSAchin Gupta /*******************************************************************************
66375f538aSAchin Gupta  * Number of cpus that the present on this platform. TODO: Rely on a topology
67375f538aSAchin Gupta  * tree to determine this in the future to avoid assumptions about mpidr
68375f538aSAchin Gupta  * allocation
69375f538aSAchin Gupta  ******************************************************************************/
70375f538aSAchin Gupta #define TSPD_CORE_COUNT		PLATFORM_CORE_COUNT
71375f538aSAchin Gupta 
72375f538aSAchin Gupta /*******************************************************************************
73375f538aSAchin Gupta  * Constants that allow assembler code to preserve callee-saved registers of the
74375f538aSAchin Gupta  * C runtime context while performing a security state switch.
75375f538aSAchin Gupta  ******************************************************************************/
76375f538aSAchin Gupta #define TSPD_C_RT_CTX_X19		0x0
77375f538aSAchin Gupta #define TSPD_C_RT_CTX_X20		0x8
78375f538aSAchin Gupta #define TSPD_C_RT_CTX_X21		0x10
79375f538aSAchin Gupta #define TSPD_C_RT_CTX_X22		0x18
80375f538aSAchin Gupta #define TSPD_C_RT_CTX_X23		0x20
81375f538aSAchin Gupta #define TSPD_C_RT_CTX_X24		0x28
82375f538aSAchin Gupta #define TSPD_C_RT_CTX_X25		0x30
83375f538aSAchin Gupta #define TSPD_C_RT_CTX_X26		0x38
84375f538aSAchin Gupta #define TSPD_C_RT_CTX_X27		0x40
85375f538aSAchin Gupta #define TSPD_C_RT_CTX_X28		0x48
86375f538aSAchin Gupta #define TSPD_C_RT_CTX_X29		0x50
87375f538aSAchin Gupta #define TSPD_C_RT_CTX_X30		0x58
88375f538aSAchin Gupta #define TSPD_C_RT_CTX_SIZE		0x60
89375f538aSAchin Gupta #define TSPD_C_RT_CTX_ENTRIES		(TSPD_C_RT_CTX_SIZE >> DWORD_SHIFT)
90375f538aSAchin Gupta 
91375f538aSAchin Gupta #ifndef __ASSEMBLY__
92375f538aSAchin Gupta 
93*97043ac9SDan Handley #include <cassert.h>
94*97043ac9SDan Handley #include <stdint.h>
95*97043ac9SDan Handley 
96375f538aSAchin Gupta /* AArch64 callee saved general purpose register context structure. */
97375f538aSAchin Gupta DEFINE_REG_STRUCT(c_rt_regs, TSPD_C_RT_CTX_ENTRIES);
98375f538aSAchin Gupta 
99375f538aSAchin Gupta /*
100375f538aSAchin Gupta  * Compile time assertion to ensure that both the compiler and linker
101375f538aSAchin Gupta  * have the same double word aligned view of the size of the C runtime
102375f538aSAchin Gupta  * register context.
103375f538aSAchin Gupta  */
104fb037bfbSDan Handley CASSERT(TSPD_C_RT_CTX_SIZE == sizeof(c_rt_regs_t),	\
105375f538aSAchin Gupta 	assert_spd_c_rt_regs_size_mismatch);
106375f538aSAchin Gupta 
107375f538aSAchin Gupta /*******************************************************************************
108375f538aSAchin Gupta  * Structure which helps the SPD to maintain the per-cpu state of the SP.
109375f538aSAchin Gupta  * 'state'    - collection of flags to track SP state e.g. on/off
110375f538aSAchin Gupta  * 'mpidr'    - mpidr to associate a context with a cpu
111375f538aSAchin Gupta  * 'c_rt_ctx' - stack address to restore C runtime context from after returning
112375f538aSAchin Gupta  *              from a synchronous entry into the SP.
113375f538aSAchin Gupta  * 'cpu_ctx'  - space to maintain SP architectural state
114375f538aSAchin Gupta  ******************************************************************************/
115fb037bfbSDan Handley typedef struct tsp_context {
116375f538aSAchin Gupta 	uint32_t state;
117375f538aSAchin Gupta 	uint64_t mpidr;
118375f538aSAchin Gupta 	uint64_t c_rt_ctx;
119fb037bfbSDan Handley 	cpu_context_t cpu_ctx;
120fb037bfbSDan Handley } tsp_context_t;
121375f538aSAchin Gupta 
1227f366605SJeenu Viswambharan /* TSPD power management handlers */
123fb037bfbSDan Handley extern const spd_pm_ops_t tspd_pm;
1247f366605SJeenu Viswambharan 
125375f538aSAchin Gupta /*******************************************************************************
126*97043ac9SDan Handley  * Forward declarations
127*97043ac9SDan Handley  ******************************************************************************/
128*97043ac9SDan Handley struct entry_info;
129*97043ac9SDan Handley 
130*97043ac9SDan Handley /*******************************************************************************
131375f538aSAchin Gupta  * Function & Data prototypes
132375f538aSAchin Gupta  ******************************************************************************/
133375f538aSAchin Gupta extern uint64_t tspd_enter_sp(uint64_t *c_rt_ctx);
134375f538aSAchin Gupta extern void __dead2 tspd_exit_sp(uint64_t c_rt_ctx, uint64_t ret);
135fb037bfbSDan Handley extern uint64_t tspd_synchronous_sp_entry(tsp_context_t *tsp_ctx);
136fb037bfbSDan Handley extern void __dead2 tspd_synchronous_sp_exit(tsp_context_t *tsp_ctx, uint64_t ret);
137375f538aSAchin Gupta extern int32_t tspd_init_secure_context(uint64_t entrypoint,
138375f538aSAchin Gupta 					uint32_t rw,
139375f538aSAchin Gupta 					uint64_t mpidr,
140fb037bfbSDan Handley 					tsp_context_t *tsp_ctx);
141fb037bfbSDan Handley extern tsp_context_t tspd_sp_context[TSPD_CORE_COUNT];
142*97043ac9SDan Handley extern struct entry_info *tsp_entry_info;
143375f538aSAchin Gupta #endif /*__ASSEMBLY__*/
144375f538aSAchin Gupta 
145*97043ac9SDan Handley #endif /* __TSPD_PRIVATE_H__ */
146