This source file includes following definitions.
- coprocessor_release_all
- coprocessor_flush_all
- arch_cpu_idle
- exit_thread
- flush_thread
- arch_dup_task_struct
- copy_thread_tls
- get_wchan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/sched/debug.h>
21 #include <linux/sched/task.h>
22 #include <linux/sched/task_stack.h>
23 #include <linux/kernel.h>
24 #include <linux/mm.h>
25 #include <linux/smp.h>
26 #include <linux/stddef.h>
27 #include <linux/unistd.h>
28 #include <linux/ptrace.h>
29 #include <linux/elf.h>
30 #include <linux/hw_breakpoint.h>
31 #include <linux/init.h>
32 #include <linux/prctl.h>
33 #include <linux/init_task.h>
34 #include <linux/module.h>
35 #include <linux/mqueue.h>
36 #include <linux/fs.h>
37 #include <linux/slab.h>
38 #include <linux/rcupdate.h>
39
40 #include <asm/pgtable.h>
41 #include <linux/uaccess.h>
42 #include <asm/io.h>
43 #include <asm/processor.h>
44 #include <asm/platform.h>
45 #include <asm/mmu.h>
46 #include <asm/irq.h>
47 #include <linux/atomic.h>
48 #include <asm/asm-offsets.h>
49 #include <asm/regs.h>
50 #include <asm/hw_breakpoint.h>
51
52 extern void ret_from_fork(void);
53 extern void ret_from_kernel_thread(void);
54
55 void (*pm_power_off)(void) = NULL;
56 EXPORT_SYMBOL(pm_power_off);
57
58
59 #ifdef CONFIG_STACKPROTECTOR
60 #include <linux/stackprotector.h>
61 unsigned long __stack_chk_guard __read_mostly;
62 EXPORT_SYMBOL(__stack_chk_guard);
63 #endif
64
65 #if XTENSA_HAVE_COPROCESSORS
66
67 void coprocessor_release_all(struct thread_info *ti)
68 {
69 unsigned long cpenable;
70 int i;
71
72
73
74 preempt_disable();
75
76
77
78 cpenable = ti->cpenable;
79
80 for (i = 0; i < XCHAL_CP_MAX; i++) {
81 if (coprocessor_owner[i] == ti) {
82 coprocessor_owner[i] = 0;
83 cpenable &= ~(1 << i);
84 }
85 }
86
87 ti->cpenable = cpenable;
88 if (ti == current_thread_info())
89 xtensa_set_sr(0, cpenable);
90
91 preempt_enable();
92 }
93
94 void coprocessor_flush_all(struct thread_info *ti)
95 {
96 unsigned long cpenable, old_cpenable;
97 int i;
98
99 preempt_disable();
100
101 old_cpenable = xtensa_get_sr(cpenable);
102 cpenable = ti->cpenable;
103 xtensa_set_sr(cpenable, cpenable);
104
105 for (i = 0; i < XCHAL_CP_MAX; i++) {
106 if ((cpenable & 1) != 0 && coprocessor_owner[i] == ti)
107 coprocessor_flush(ti, i);
108 cpenable >>= 1;
109 }
110 xtensa_set_sr(old_cpenable, cpenable);
111
112 preempt_enable();
113 }
114
115 #endif
116
117
118
119
120
121 void arch_cpu_idle(void)
122 {
123 platform_idle();
124 }
125
126
127
128
129 void exit_thread(struct task_struct *tsk)
130 {
131 #if XTENSA_HAVE_COPROCESSORS
132 coprocessor_release_all(task_thread_info(tsk));
133 #endif
134 }
135
136
137
138
139
140 void flush_thread(void)
141 {
142 #if XTENSA_HAVE_COPROCESSORS
143 struct thread_info *ti = current_thread_info();
144 coprocessor_flush_all(ti);
145 coprocessor_release_all(ti);
146 #endif
147 flush_ptrace_hw_breakpoint(current);
148 }
149
150
151
152
153
154 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
155 {
156 #if XTENSA_HAVE_COPROCESSORS
157 coprocessor_flush_all(task_thread_info(src));
158 #endif
159 *dst = *src;
160 return 0;
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 int copy_thread_tls(unsigned long clone_flags, unsigned long usp_thread_fn,
206 unsigned long thread_fn_arg, struct task_struct *p,
207 unsigned long tls)
208 {
209 struct pt_regs *childregs = task_pt_regs(p);
210
211 #if (XTENSA_HAVE_COPROCESSORS || XTENSA_HAVE_IO_PORTS)
212 struct thread_info *ti;
213 #endif
214
215
216 SPILL_SLOT(childregs, 1) = (unsigned long)childregs;
217 SPILL_SLOT(childregs, 0) = 0;
218
219 p->thread.sp = (unsigned long)childregs;
220
221 if (!(p->flags & PF_KTHREAD)) {
222 struct pt_regs *regs = current_pt_regs();
223 unsigned long usp = usp_thread_fn ?
224 usp_thread_fn : regs->areg[1];
225
226 p->thread.ra = MAKE_RA_FOR_CALL(
227 (unsigned long)ret_from_fork, 0x1);
228
229
230
231
232
233 *childregs = *regs;
234 childregs->areg[1] = usp;
235 childregs->areg[2] = 0;
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 if (clone_flags & CLONE_VM) {
251
252 int len = childregs->wmask & ~0xf;
253 if (regs->areg[1] == usp && len != 0) {
254 int callinc = (regs->areg[0] >> 30) & 3;
255 int caller_ars = XCHAL_NUM_AREGS - callinc * 4;
256 put_user(regs->areg[caller_ars+1],
257 (unsigned __user*)(usp - 12));
258 }
259 childregs->wmask = 1;
260 childregs->windowstart = 1;
261 childregs->windowbase = 0;
262 } else {
263 int len = childregs->wmask & ~0xf;
264 memcpy(&childregs->areg[XCHAL_NUM_AREGS - len/4],
265 ®s->areg[XCHAL_NUM_AREGS - len/4], len);
266 }
267
268 if (clone_flags & CLONE_SETTLS)
269 childregs->threadptr = tls;
270 } else {
271 p->thread.ra = MAKE_RA_FOR_CALL(
272 (unsigned long)ret_from_kernel_thread, 1);
273
274
275
276
277 SPILL_SLOT(childregs, 3) = thread_fn_arg;
278 SPILL_SLOT(childregs, 2) = usp_thread_fn;
279
280
281
282
283 }
284
285 #if (XTENSA_HAVE_COPROCESSORS || XTENSA_HAVE_IO_PORTS)
286 ti = task_thread_info(p);
287 ti->cpenable = 0;
288 #endif
289
290 clear_ptrace_hw_breakpoint(p);
291
292 return 0;
293 }
294
295
296
297
298
299
300 unsigned long get_wchan(struct task_struct *p)
301 {
302 unsigned long sp, pc;
303 unsigned long stack_page = (unsigned long) task_stack_page(p);
304 int count = 0;
305
306 if (!p || p == current || p->state == TASK_RUNNING)
307 return 0;
308
309 sp = p->thread.sp;
310 pc = MAKE_PC_FROM_RA(p->thread.ra, p->thread.sp);
311
312 do {
313 if (sp < stack_page + sizeof(struct task_struct) ||
314 sp >= (stack_page + THREAD_SIZE) ||
315 pc == 0)
316 return 0;
317 if (!in_sched_functions(pc))
318 return pc;
319
320
321
322 pc = MAKE_PC_FROM_RA(SPILL_SLOT(sp, 0), sp);
323 sp = SPILL_SLOT(sp, 1);
324 } while (count++ < 16);
325 return 0;
326 }