xref: /optee_os/core/include/kernel/thread_private.h (revision c44d734b6366cbf4d12610310e809872db65f89d)
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 __KERNEL_THREAD_PRIVATE_H
8 #define __KERNEL_THREAD_PRIVATE_H
9 
10 #include <util.h>
11 #ifndef __ASSEMBLER__
12 
13 #include <kernel/mutex.h>
14 #include <kernel/thread.h>
15 #include <kernel/thread_private_arch.h>
16 #include <mm/core_mmu.h>
17 #include <mm/pgt_cache.h>
18 
19 enum thread_state {
20 	THREAD_STATE_FREE,
21 	THREAD_STATE_SUSPENDED,
22 	THREAD_STATE_ACTIVE,
23 };
24 
25 struct thread_shm_cache_entry {
26 	struct mobj *mobj;
27 	size_t size;
28 	enum thread_shm_type type;
29 	enum thread_shm_cache_user user;
30 	SLIST_ENTRY(thread_shm_cache_entry) link;
31 };
32 
33 SLIST_HEAD(thread_shm_cache, thread_shm_cache_entry);
34 
35 struct thread_ctx {
36 	struct thread_ctx_regs regs;
37 	enum thread_state state;
38 	vaddr_t stack_va_end;
39 	uint32_t flags;
40 	struct core_mmu_user_map user_map;
41 	bool have_user_map;
42 #ifdef ARM64
43 	vaddr_t kern_sp;	/* Saved kernel SP during user TA execution */
44 #endif
45 #ifdef CFG_WITH_VFP
46 	struct thread_vfp_state vfp_state;
47 #endif
48 	void *rpc_arg;
49 	struct mobj *rpc_mobj;
50 	struct thread_shm_cache shm_cache;
51 	struct thread_specific_data tsd;
52 };
53 #endif /*__ASSEMBLER__*/
54 
55 /* Describes the flags field of struct thread_core_local */
56 #define THREAD_CLF_SAVED_SHIFT			4
57 #define THREAD_CLF_CURR_SHIFT			0
58 #define THREAD_CLF_MASK				0xf
59 #define THREAD_CLF_TMP_SHIFT			0
60 #define THREAD_CLF_ABORT_SHIFT			1
61 #define THREAD_CLF_IRQ_SHIFT			2
62 #define THREAD_CLF_FIQ_SHIFT			3
63 
64 #define THREAD_CLF_TMP				BIT(THREAD_CLF_TMP_SHIFT)
65 #define THREAD_CLF_ABORT			BIT(THREAD_CLF_ABORT_SHIFT)
66 #define THREAD_CLF_IRQ				BIT(THREAD_CLF_IRQ_SHIFT)
67 #define THREAD_CLF_FIQ				BIT(THREAD_CLF_FIQ_SHIFT)
68 
69 #ifndef __ASSEMBLER__
70 extern const void *stack_tmp_export;
71 extern const uint32_t stack_tmp_stride;
72 extern struct thread_ctx threads[];
73 extern struct thread_core_local thread_core_local[];
74 
75 #ifdef CFG_WITH_STACK_CANARIES
76 #define STACK_CANARY_SIZE	(4 * sizeof(long))
77 #else
78 #define STACK_CANARY_SIZE	0
79 #endif
80 
81 /* Checks stack canaries */
82 void thread_check_canaries(void);
83 
84 void thread_lock_global(void);
85 void thread_unlock_global(void);
86 
87 /* Frees the cache of allocated FS RPC memory */
88 void thread_rpc_shm_cache_clear(struct thread_shm_cache *cache);
89 #endif /*__ASSEMBLER__*/
90 #endif /*__KERNEL_THREAD_PRIVATE_H*/
91