1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2016, Linaro Limited 4 * Copyright (c) 2014, STMicroelectronics International N.V. 5 */ 6 7 #ifndef SM_SM_H 8 #define SM_SM_H 9 10 #include <compiler.h> 11 #include <types_ext.h> 12 13 struct sm_unbanked_regs { 14 uint32_t usr_sp; 15 uint32_t usr_lr; 16 uint32_t irq_spsr; 17 uint32_t irq_sp; 18 uint32_t irq_lr; 19 uint32_t fiq_spsr; 20 uint32_t fiq_sp; 21 uint32_t fiq_lr; 22 /* 23 * Note that fiq_r{8-12} are not saved here. Instead thread_fiq_handler 24 * preserves r{8-12}. 25 */ 26 uint32_t svc_spsr; 27 uint32_t svc_sp; 28 uint32_t svc_lr; 29 uint32_t abt_spsr; 30 uint32_t abt_sp; 31 uint32_t abt_lr; 32 uint32_t und_spsr; 33 uint32_t und_sp; 34 uint32_t und_lr; 35 #ifdef CFG_SM_NO_CYCLE_COUNTING 36 uint32_t pmcr; 37 #endif 38 }; 39 40 struct sm_nsec_ctx { 41 struct sm_unbanked_regs ub_regs; 42 43 uint32_t r8; 44 uint32_t r9; 45 uint32_t r10; 46 uint32_t r11; 47 uint32_t r12; 48 49 uint32_t r0; 50 uint32_t r1; 51 uint32_t r2; 52 uint32_t r3; 53 uint32_t r4; 54 uint32_t r5; 55 uint32_t r6; 56 uint32_t r7; 57 58 /* return state */ 59 uint32_t mon_lr; 60 uint32_t mon_spsr; 61 }; 62 63 struct sm_sec_ctx { 64 struct sm_unbanked_regs ub_regs; 65 66 uint32_t r0; 67 uint32_t r1; 68 uint32_t r2; 69 uint32_t r3; 70 uint32_t r4; 71 uint32_t r5; 72 uint32_t r6; 73 uint32_t r7; 74 75 /* return state */ 76 uint32_t mon_lr; 77 uint32_t mon_spsr; 78 }; 79 80 struct sm_ctx { 81 #ifndef CFG_SM_NO_CYCLE_COUNTING 82 uint32_t pad; 83 #endif 84 struct sm_sec_ctx sec; 85 #ifdef CFG_SM_NO_CYCLE_COUNTING 86 uint32_t pad; 87 #endif 88 struct sm_nsec_ctx nsec; 89 }; 90 91 /* 92 * The secure monitor reserves space at top of stack_tmp to hold struct 93 * sm_ctx. 94 */ 95 #define SM_STACK_TMP_RESERVE_SIZE sizeof(struct sm_ctx) 96 97 98 99 /* Returns storage location of non-secure context for current CPU */ 100 struct sm_nsec_ctx *sm_get_nsec_ctx(void); 101 102 /* Returns stack pointer to use in monitor mode for current CPU */ 103 void *sm_get_sp(void); 104 105 /* 106 * Initializes secure monitor, must be called by each CPU 107 */ 108 void sm_init(vaddr_t stack_pointer); 109 110 #ifndef CFG_SM_PLATFORM_HANDLER 111 /* 112 * Returns false if we handled the monitor service and should now return 113 * back to the non-secure state 114 */ 115 static inline bool sm_platform_handler(__unused struct sm_ctx *ctx) 116 { 117 return true; 118 } 119 #else 120 bool sm_platform_handler(struct sm_ctx *ctx); 121 #endif 122 123 void sm_save_unbanked_regs(struct sm_unbanked_regs *regs); 124 void sm_restore_unbanked_regs(struct sm_unbanked_regs *regs); 125 #endif /*SM_SM_H*/ 126