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 31375f538aSAchin Gupta #ifndef __SPD_PRIVATE_H__ 32375f538aSAchin Gupta #define __SPD_PRIVATE_H__ 33375f538aSAchin Gupta 34375f538aSAchin Gupta #include <context.h> 35375f538aSAchin Gupta #include <arch.h> 36375f538aSAchin Gupta #include <psci.h> 37375f538aSAchin Gupta #include <tsp.h> 38bdbfc3c2SDan Handley #include <cassert.h> 39375f538aSAchin Gupta 40375f538aSAchin Gupta /******************************************************************************* 41375f538aSAchin Gupta * Secure Payload PM state information e.g. SP is suspended, uninitialised etc 42375f538aSAchin Gupta ******************************************************************************/ 43375f538aSAchin Gupta #define TSP_STATE_OFF 0 44375f538aSAchin Gupta #define TSP_STATE_ON 1 45375f538aSAchin Gupta #define TSP_STATE_SUSPEND 2 46375f538aSAchin Gupta 47375f538aSAchin Gupta /******************************************************************************* 48375f538aSAchin Gupta * Secure Payload execution state information i.e. aarch32 or aarch64 49375f538aSAchin Gupta ******************************************************************************/ 50375f538aSAchin Gupta #define TSP_AARCH32 MODE_RW_32 51375f538aSAchin Gupta #define TSP_AARCH64 MODE_RW_64 52375f538aSAchin Gupta 53375f538aSAchin Gupta /******************************************************************************* 54375f538aSAchin Gupta * The SPD should know the type of Secure Payload. 55375f538aSAchin Gupta ******************************************************************************/ 56375f538aSAchin Gupta #define TSP_TYPE_UP PSCI_TOS_NOT_UP_MIG_CAP 57375f538aSAchin Gupta #define TSP_TYPE_UPM PSCI_TOS_UP_MIG_CAP 58375f538aSAchin Gupta #define TSP_TYPE_MP PSCI_TOS_NOT_PRESENT_MP 59375f538aSAchin Gupta 60375f538aSAchin Gupta /******************************************************************************* 61375f538aSAchin Gupta * Secure Payload migrate type information as known to the SPD. We assume that 62375f538aSAchin Gupta * the SPD is dealing with an MP Secure Payload. 63375f538aSAchin Gupta ******************************************************************************/ 64375f538aSAchin Gupta #define TSP_MIGRATE_INFO TSP_TYPE_MP 65375f538aSAchin Gupta 66375f538aSAchin Gupta /******************************************************************************* 67375f538aSAchin Gupta * Number of cpus that the present on this platform. TODO: Rely on a topology 68375f538aSAchin Gupta * tree to determine this in the future to avoid assumptions about mpidr 69375f538aSAchin Gupta * allocation 70375f538aSAchin Gupta ******************************************************************************/ 71375f538aSAchin Gupta #define TSPD_CORE_COUNT PLATFORM_CORE_COUNT 72375f538aSAchin Gupta 73375f538aSAchin Gupta /******************************************************************************* 74375f538aSAchin Gupta * Constants that allow assembler code to preserve callee-saved registers of the 75375f538aSAchin Gupta * C runtime context while performing a security state switch. 76375f538aSAchin Gupta ******************************************************************************/ 77375f538aSAchin Gupta #define TSPD_C_RT_CTX_X19 0x0 78375f538aSAchin Gupta #define TSPD_C_RT_CTX_X20 0x8 79375f538aSAchin Gupta #define TSPD_C_RT_CTX_X21 0x10 80375f538aSAchin Gupta #define TSPD_C_RT_CTX_X22 0x18 81375f538aSAchin Gupta #define TSPD_C_RT_CTX_X23 0x20 82375f538aSAchin Gupta #define TSPD_C_RT_CTX_X24 0x28 83375f538aSAchin Gupta #define TSPD_C_RT_CTX_X25 0x30 84375f538aSAchin Gupta #define TSPD_C_RT_CTX_X26 0x38 85375f538aSAchin Gupta #define TSPD_C_RT_CTX_X27 0x40 86375f538aSAchin Gupta #define TSPD_C_RT_CTX_X28 0x48 87375f538aSAchin Gupta #define TSPD_C_RT_CTX_X29 0x50 88375f538aSAchin Gupta #define TSPD_C_RT_CTX_X30 0x58 89375f538aSAchin Gupta #define TSPD_C_RT_CTX_SIZE 0x60 90375f538aSAchin Gupta #define TSPD_C_RT_CTX_ENTRIES (TSPD_C_RT_CTX_SIZE >> DWORD_SHIFT) 91375f538aSAchin Gupta 92375f538aSAchin Gupta #ifndef __ASSEMBLY__ 93375f538aSAchin Gupta 94375f538aSAchin Gupta /* AArch64 callee saved general purpose register context structure. */ 95375f538aSAchin Gupta DEFINE_REG_STRUCT(c_rt_regs, TSPD_C_RT_CTX_ENTRIES); 96375f538aSAchin Gupta 97375f538aSAchin Gupta /* 98375f538aSAchin Gupta * Compile time assertion to ensure that both the compiler and linker 99375f538aSAchin Gupta * have the same double word aligned view of the size of the C runtime 100375f538aSAchin Gupta * register context. 101375f538aSAchin Gupta */ 102*fb037bfbSDan Handley CASSERT(TSPD_C_RT_CTX_SIZE == sizeof(c_rt_regs_t), \ 103375f538aSAchin Gupta assert_spd_c_rt_regs_size_mismatch); 104375f538aSAchin Gupta 105375f538aSAchin Gupta /******************************************************************************* 106375f538aSAchin Gupta * Structure which helps the SPD to maintain the per-cpu state of the SP. 107375f538aSAchin Gupta * 'state' - collection of flags to track SP state e.g. on/off 108375f538aSAchin Gupta * 'mpidr' - mpidr to associate a context with a cpu 109375f538aSAchin Gupta * 'c_rt_ctx' - stack address to restore C runtime context from after returning 110375f538aSAchin Gupta * from a synchronous entry into the SP. 111375f538aSAchin Gupta * 'cpu_ctx' - space to maintain SP architectural state 112375f538aSAchin Gupta ******************************************************************************/ 113*fb037bfbSDan Handley typedef struct tsp_context { 114375f538aSAchin Gupta uint32_t state; 115375f538aSAchin Gupta uint64_t mpidr; 116375f538aSAchin Gupta uint64_t c_rt_ctx; 117*fb037bfbSDan Handley cpu_context_t cpu_ctx; 118*fb037bfbSDan Handley } tsp_context_t; 119375f538aSAchin Gupta 1207f366605SJeenu Viswambharan /* TSPD power management handlers */ 121*fb037bfbSDan Handley extern const spd_pm_ops_t tspd_pm; 1227f366605SJeenu Viswambharan 123375f538aSAchin Gupta /******************************************************************************* 124375f538aSAchin Gupta * Function & Data prototypes 125375f538aSAchin Gupta ******************************************************************************/ 126375f538aSAchin Gupta extern uint64_t tspd_enter_sp(uint64_t *c_rt_ctx); 127375f538aSAchin Gupta extern void __dead2 tspd_exit_sp(uint64_t c_rt_ctx, uint64_t ret); 128*fb037bfbSDan Handley extern uint64_t tspd_synchronous_sp_entry(tsp_context_t *tsp_ctx); 129*fb037bfbSDan Handley extern void __dead2 tspd_synchronous_sp_exit(tsp_context_t *tsp_ctx, uint64_t ret); 130375f538aSAchin Gupta extern int32_t tspd_init_secure_context(uint64_t entrypoint, 131375f538aSAchin Gupta uint32_t rw, 132375f538aSAchin Gupta uint64_t mpidr, 133*fb037bfbSDan Handley tsp_context_t *tsp_ctx); 134*fb037bfbSDan Handley extern tsp_context_t tspd_sp_context[TSPD_CORE_COUNT]; 135*fb037bfbSDan Handley extern entry_info_t *tsp_entry_info; 136375f538aSAchin Gupta #endif /*__ASSEMBLY__*/ 137375f538aSAchin Gupta 138375f538aSAchin Gupta #endif /* __SPD_PRIVATE_H__ */ 139