1*375f538aSAchin Gupta /* 2*375f538aSAchin Gupta * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 3*375f538aSAchin Gupta * 4*375f538aSAchin Gupta * Redistribution and use in source and binary forms, with or without 5*375f538aSAchin Gupta * modification, are permitted provided that the following conditions are met: 6*375f538aSAchin Gupta * 7*375f538aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this 8*375f538aSAchin Gupta * list of conditions and the following disclaimer. 9*375f538aSAchin Gupta * 10*375f538aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 11*375f538aSAchin Gupta * this list of conditions and the following disclaimer in the documentation 12*375f538aSAchin Gupta * and/or other materials provided with the distribution. 13*375f538aSAchin Gupta * 14*375f538aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 15*375f538aSAchin Gupta * to endorse or promote products derived from this software without specific 16*375f538aSAchin Gupta * prior written permission. 17*375f538aSAchin Gupta * 18*375f538aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*375f538aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*375f538aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*375f538aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*375f538aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*375f538aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*375f538aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*375f538aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*375f538aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*375f538aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*375f538aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 29*375f538aSAchin Gupta */ 30*375f538aSAchin Gupta 31*375f538aSAchin Gupta #ifndef __SPD_PRIVATE_H__ 32*375f538aSAchin Gupta #define __SPD_PRIVATE_H__ 33*375f538aSAchin Gupta 34*375f538aSAchin Gupta #include <context.h> 35*375f538aSAchin Gupta #include <arch.h> 36*375f538aSAchin Gupta #include <psci.h> 37*375f538aSAchin Gupta #include <tsp.h> 38*375f538aSAchin Gupta 39*375f538aSAchin Gupta /******************************************************************************* 40*375f538aSAchin Gupta * Secure Payload PM state information e.g. SP is suspended, uninitialised etc 41*375f538aSAchin Gupta ******************************************************************************/ 42*375f538aSAchin Gupta #define TSP_STATE_OFF 0 43*375f538aSAchin Gupta #define TSP_STATE_ON 1 44*375f538aSAchin Gupta #define TSP_STATE_SUSPEND 2 45*375f538aSAchin Gupta 46*375f538aSAchin Gupta /******************************************************************************* 47*375f538aSAchin Gupta * Secure Payload execution state information i.e. aarch32 or aarch64 48*375f538aSAchin Gupta ******************************************************************************/ 49*375f538aSAchin Gupta #define TSP_AARCH32 MODE_RW_32 50*375f538aSAchin Gupta #define TSP_AARCH64 MODE_RW_64 51*375f538aSAchin Gupta 52*375f538aSAchin Gupta /******************************************************************************* 53*375f538aSAchin Gupta * The SPD should know the type of Secure Payload. 54*375f538aSAchin Gupta ******************************************************************************/ 55*375f538aSAchin Gupta #define TSP_TYPE_UP PSCI_TOS_NOT_UP_MIG_CAP 56*375f538aSAchin Gupta #define TSP_TYPE_UPM PSCI_TOS_UP_MIG_CAP 57*375f538aSAchin Gupta #define TSP_TYPE_MP PSCI_TOS_NOT_PRESENT_MP 58*375f538aSAchin Gupta 59*375f538aSAchin Gupta /******************************************************************************* 60*375f538aSAchin Gupta * Secure Payload migrate type information as known to the SPD. We assume that 61*375f538aSAchin Gupta * the SPD is dealing with an MP Secure Payload. 62*375f538aSAchin Gupta ******************************************************************************/ 63*375f538aSAchin Gupta #define TSP_MIGRATE_INFO TSP_TYPE_MP 64*375f538aSAchin Gupta 65*375f538aSAchin Gupta /******************************************************************************* 66*375f538aSAchin Gupta * Number of cpus that the present on this platform. TODO: Rely on a topology 67*375f538aSAchin Gupta * tree to determine this in the future to avoid assumptions about mpidr 68*375f538aSAchin Gupta * allocation 69*375f538aSAchin Gupta ******************************************************************************/ 70*375f538aSAchin Gupta #define TSPD_CORE_COUNT PLATFORM_CORE_COUNT 71*375f538aSAchin Gupta 72*375f538aSAchin Gupta /******************************************************************************* 73*375f538aSAchin Gupta * Constants that allow assembler code to preserve callee-saved registers of the 74*375f538aSAchin Gupta * C runtime context while performing a security state switch. 75*375f538aSAchin Gupta ******************************************************************************/ 76*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X19 0x0 77*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X20 0x8 78*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X21 0x10 79*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X22 0x18 80*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X23 0x20 81*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X24 0x28 82*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X25 0x30 83*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X26 0x38 84*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X27 0x40 85*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X28 0x48 86*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X29 0x50 87*375f538aSAchin Gupta #define TSPD_C_RT_CTX_X30 0x58 88*375f538aSAchin Gupta #define TSPD_C_RT_CTX_SIZE 0x60 89*375f538aSAchin Gupta #define TSPD_C_RT_CTX_ENTRIES (TSPD_C_RT_CTX_SIZE >> DWORD_SHIFT) 90*375f538aSAchin Gupta 91*375f538aSAchin Gupta #ifndef __ASSEMBLY__ 92*375f538aSAchin Gupta 93*375f538aSAchin Gupta /* AArch64 callee saved general purpose register context structure. */ 94*375f538aSAchin Gupta DEFINE_REG_STRUCT(c_rt_regs, TSPD_C_RT_CTX_ENTRIES); 95*375f538aSAchin Gupta 96*375f538aSAchin Gupta /* 97*375f538aSAchin Gupta * Compile time assertion to ensure that both the compiler and linker 98*375f538aSAchin Gupta * have the same double word aligned view of the size of the C runtime 99*375f538aSAchin Gupta * register context. 100*375f538aSAchin Gupta */ 101*375f538aSAchin Gupta CASSERT(TSPD_C_RT_CTX_SIZE == sizeof(c_rt_regs), \ 102*375f538aSAchin Gupta assert_spd_c_rt_regs_size_mismatch); 103*375f538aSAchin Gupta 104*375f538aSAchin Gupta /******************************************************************************* 105*375f538aSAchin Gupta * Structure which helps the SPD to maintain the per-cpu state of the SP. 106*375f538aSAchin Gupta * 'state' - collection of flags to track SP state e.g. on/off 107*375f538aSAchin Gupta * 'mpidr' - mpidr to associate a context with a cpu 108*375f538aSAchin Gupta * 'c_rt_ctx' - stack address to restore C runtime context from after returning 109*375f538aSAchin Gupta * from a synchronous entry into the SP. 110*375f538aSAchin Gupta * 'cpu_ctx' - space to maintain SP architectural state 111*375f538aSAchin Gupta ******************************************************************************/ 112*375f538aSAchin Gupta typedef struct { 113*375f538aSAchin Gupta uint32_t state; 114*375f538aSAchin Gupta uint64_t mpidr; 115*375f538aSAchin Gupta uint64_t c_rt_ctx; 116*375f538aSAchin Gupta cpu_context cpu_ctx; 117*375f538aSAchin Gupta } tsp_context; 118*375f538aSAchin Gupta 119*375f538aSAchin Gupta /******************************************************************************* 120*375f538aSAchin Gupta * Function & Data prototypes 121*375f538aSAchin Gupta ******************************************************************************/ 122*375f538aSAchin Gupta extern uint64_t tspd_enter_sp(uint64_t *c_rt_ctx); 123*375f538aSAchin Gupta extern void __dead2 tspd_exit_sp(uint64_t c_rt_ctx, uint64_t ret); 124*375f538aSAchin Gupta extern uint64_t tspd_synchronous_sp_entry(tsp_context *tsp_ctx); 125*375f538aSAchin Gupta extern void __dead2 tspd_synchronous_sp_exit(tsp_context *tsp_ctx, uint64_t ret); 126*375f538aSAchin Gupta extern int32_t tspd_init_secure_context(uint64_t entrypoint, 127*375f538aSAchin Gupta uint32_t rw, 128*375f538aSAchin Gupta uint64_t mpidr, 129*375f538aSAchin Gupta tsp_context *tsp_ctx); 130*375f538aSAchin Gupta extern tsp_context tspd_sp_context[TSPD_CORE_COUNT]; 131*375f538aSAchin Gupta extern entry_info *tsp_entry_info; 132*375f538aSAchin Gupta #endif /*__ASSEMBLY__*/ 133*375f538aSAchin Gupta 134*375f538aSAchin Gupta #endif /* __SPD_PRIVATE_H__ */ 135