1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2022 NXP
4  */
5 
6 #ifndef __KERNEL_THREAD_ARCH_H
7 #define __KERNEL_THREAD_ARCH_H
8 
9 #ifndef __ASSEMBLER__
10 #include <compiler.h>
11 #include <riscv.h>
12 #include <types_ext.h>
13 #endif
14 
15 #ifndef __ASSEMBLER__
16 
17 #define THREAD_CORE_LOCAL_ALIGNED __aligned(2 * RISCV_XLEN_BYTES)
18 
19 struct thread_pauth_keys {
20 };
21 
22 struct thread_core_local {
23 	uint32_t hart_id;
24 	vaddr_t tmp_stack_va_end;
25 	short int curr_thread;
26 	uint32_t flags;
27 	vaddr_t abt_stack_va_end;
28 #ifdef CFG_TEE_CORE_DEBUG
29 	unsigned int locked_count; /* Number of spinlocks held */
30 #endif
31 #ifdef CFG_CORE_DEBUG_CHECK_STACKS
32 	bool stackcheck_recursion;
33 #endif
34 } THREAD_CORE_LOCAL_ALIGNED;
35 
36 struct thread_smc_args {
37 	unsigned long a0;	/* SBI function ID */
38 	unsigned long a1;	/* Parameter */
39 	unsigned long a2;	/* Parameter */
40 	unsigned long a3;	/* Thread ID when returning from RPC */
41 	unsigned long a4;	/* Not used */
42 	unsigned long a5;	/* Not used */
43 	unsigned long a6;	/* Not used */
44 	unsigned long a7;	/* Hypervisor Client ID */
45 };
46 
47 struct thread_abort_regs {
48 	unsigned long ra;
49 	unsigned long sp;
50 	unsigned long gp;
51 	unsigned long tp;
52 	unsigned long t0;
53 	unsigned long t1;
54 	unsigned long t2;
55 	unsigned long a0;
56 	unsigned long a1;
57 	unsigned long a2;
58 	unsigned long a3;
59 	unsigned long a4;
60 	unsigned long a5;
61 	unsigned long a6;
62 	unsigned long a7;
63 	unsigned long t3;
64 	unsigned long t4;
65 	unsigned long t5;
66 	unsigned long t6;
67 	unsigned long epc;
68 	unsigned long status;
69 };
70 
71 struct thread_svc_regs {
72 	unsigned long a0;
73 	unsigned long a1;
74 	unsigned long a2;
75 	unsigned long a3;
76 	unsigned long a4;
77 	unsigned long a5;
78 	unsigned long a6;
79 	unsigned long a7;
80 	unsigned long t0;
81 	unsigned long t1;
82 	unsigned long t2;
83 	unsigned long t3;
84 	unsigned long t4;
85 	unsigned long t5;
86 	unsigned long t6;
87 	unsigned long ra;
88 	unsigned long status;
89 };
90 
91 struct thread_ctx_regs {
92 	unsigned long ra;
93 	unsigned long sp;
94 	unsigned long fp;
95 	unsigned long a0;
96 	unsigned long a1;
97 	unsigned long a2;
98 	unsigned long a3;
99 	unsigned long a4;
100 	unsigned long a5;
101 	unsigned long a6;
102 	unsigned long a7;
103 	unsigned long status;
104 };
105 
106 struct user_mode_ctx;
107 
108 /*
109  * These flags should vary according to the privilege mode selected
110  * to run OP-TEE core on (M/HS/S). For now default to S-Mode.
111  */
112 #define THREAD_EXCP_FOREIGN_INTR	MIP_SEIP
113 #define THREAD_EXCP_NATIVE_INTR		MIP_SSIP
114 #define THREAD_EXCP_ALL			(THREAD_EXCP_FOREIGN_INTR |	\
115 					 THREAD_EXCP_NATIVE_INTR |	\
116 					 MIP_STIP)
117 
thread_get_user_kcode(struct mobj ** mobj,size_t * offset,vaddr_t * va,size_t * sz)118 static inline void thread_get_user_kcode(struct mobj **mobj, size_t *offset,
119 					 vaddr_t *va, size_t *sz)
120 {
121 	*mobj = NULL;
122 	*offset = 0;
123 	*va = 0;
124 	*sz = 0;
125 }
126 
thread_get_user_kdata(struct mobj ** mobj,size_t * offset,vaddr_t * va,size_t * sz)127 static inline void thread_get_user_kdata(struct mobj **mobj, size_t *offset,
128 					 vaddr_t *va, size_t *sz)
129 {
130 	*mobj = NULL;
131 	*offset = 0;
132 	*va = 0;
133 	*sz = 0;
134 }
135 
136 #endif /*__ASSEMBLER__*/
137 #endif /*__KERNEL_THREAD_ARCH_H*/
138