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_CORE_PAUTH
46 	struct thread_pauth_keys keys;
47 #endif
48 #ifdef CFG_WITH_VFP
49 	struct thread_vfp_state vfp_state;
50 #endif
51 	void *rpc_arg;
52 	struct mobj *rpc_mobj;
53 	struct thread_shm_cache shm_cache;
54 	struct thread_specific_data tsd;
55 };
56 #endif /*__ASSEMBLER__*/
57 
58 /* Describes the flags field of struct thread_core_local */
59 #define THREAD_CLF_SAVED_SHIFT			4
60 #define THREAD_CLF_CURR_SHIFT			0
61 #define THREAD_CLF_MASK				0xf
62 #define THREAD_CLF_TMP_SHIFT			0
63 #define THREAD_CLF_ABORT_SHIFT			1
64 #define THREAD_CLF_IRQ_SHIFT			2
65 #define THREAD_CLF_FIQ_SHIFT			3
66 
67 #define THREAD_CLF_TMP				BIT(THREAD_CLF_TMP_SHIFT)
68 #define THREAD_CLF_ABORT			BIT(THREAD_CLF_ABORT_SHIFT)
69 #define THREAD_CLF_IRQ				BIT(THREAD_CLF_IRQ_SHIFT)
70 #define THREAD_CLF_FIQ				BIT(THREAD_CLF_FIQ_SHIFT)
71 
72 #ifndef __ASSEMBLER__
73 extern const void *stack_tmp_export;
74 extern const uint32_t stack_tmp_stride;
75 extern struct thread_ctx threads[];
76 extern struct thread_core_local thread_core_local[];
77 
78 #ifdef CFG_WITH_STACK_CANARIES
79 #define STACK_CANARY_SIZE	(4 * sizeof(long))
80 #else
81 #define STACK_CANARY_SIZE	0
82 #endif
83 
84 /* Checks stack canaries */
85 void thread_check_canaries(void);
86 
87 void thread_lock_global(void);
88 void thread_unlock_global(void);
89 
90 /* Frees the cache of allocated FS RPC memory */
91 void thread_rpc_shm_cache_clear(struct thread_shm_cache *cache);
92 #endif /*__ASSEMBLER__*/
93 #endif /*__KERNEL_THREAD_PRIVATE_H*/
94