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