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 uint32_t pad; 38 #endif 39 }; 40 41 struct sm_nsec_ctx { 42 struct sm_unbanked_regs ub_regs; 43 44 uint32_t r8; 45 uint32_t r9; 46 uint32_t r10; 47 uint32_t r11; 48 uint32_t r12; 49 50 uint32_t r0; 51 uint32_t r1; 52 uint32_t r2; 53 uint32_t r3; 54 uint32_t r4; 55 uint32_t r5; 56 uint32_t r6; 57 uint32_t r7; 58 59 /* return state */ 60 uint32_t mon_lr; 61 uint32_t mon_spsr; 62 }; 63 64 struct sm_sec_ctx { 65 struct sm_unbanked_regs ub_regs; 66 67 uint32_t r0; 68 uint32_t r1; 69 uint32_t r2; 70 uint32_t r3; 71 uint32_t r4; 72 uint32_t r5; 73 uint32_t r6; 74 uint32_t r7; 75 76 /* return state */ 77 uint32_t mon_lr; 78 uint32_t mon_spsr; 79 }; 80 81 struct sm_ctx { 82 uint32_t pad; 83 struct sm_sec_ctx sec; 84 struct sm_nsec_ctx nsec; 85 }; 86 87 /* 88 * The secure monitor reserves space at top of stack_tmp to hold struct 89 * sm_ctx. 90 */ 91 #define SM_STACK_TMP_RESERVE_SIZE sizeof(struct sm_ctx) 92 93 94 95 /* Returns storage location of non-secure context for current CPU */ 96 struct sm_nsec_ctx *sm_get_nsec_ctx(void); 97 98 /* Returns stack pointer to use in monitor mode for current CPU */ 99 void *sm_get_sp(void); 100 101 /* 102 * Initializes secure monitor, must be called by each CPU 103 */ 104 void sm_init(vaddr_t stack_pointer); 105 106 #ifndef CFG_SM_PLATFORM_HANDLER 107 /* 108 * Returns false if we handled the monitor service and should now return 109 * back to the non-secure state 110 */ 111 static inline bool sm_platform_handler(__unused struct sm_ctx *ctx) 112 { 113 return true; 114 } 115 #else 116 bool sm_platform_handler(struct sm_ctx *ctx); 117 #endif 118 119 void sm_save_unbanked_regs(struct sm_unbanked_regs *regs); 120 void sm_restore_unbanked_regs(struct sm_unbanked_regs *regs); 121 #endif /*SM_SM_H*/ 122