]>
Commit | Line | Data |
---|---|---|
b920de1b DH |
1 | /* MN10300 Process handling code |
2 | * | |
3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public Licence | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the Licence, or (at your option) any later version. | |
10 | */ | |
11 | #include <linux/module.h> | |
12 | #include <linux/errno.h> | |
13 | #include <linux/sched.h> | |
14 | #include <linux/kernel.h> | |
15 | #include <linux/mm.h> | |
16 | #include <linux/smp.h> | |
b920de1b DH |
17 | #include <linux/stddef.h> |
18 | #include <linux/unistd.h> | |
19 | #include <linux/ptrace.h> | |
b920de1b | 20 | #include <linux/user.h> |
b920de1b DH |
21 | #include <linux/interrupt.h> |
22 | #include <linux/delay.h> | |
23 | #include <linux/reboot.h> | |
24 | #include <linux/percpu.h> | |
25 | #include <linux/err.h> | |
26 | #include <linux/fs.h> | |
5a0e3ad6 | 27 | #include <linux/slab.h> |
b920de1b DH |
28 | #include <asm/uaccess.h> |
29 | #include <asm/pgtable.h> | |
b920de1b DH |
30 | #include <asm/io.h> |
31 | #include <asm/processor.h> | |
32 | #include <asm/mmu_context.h> | |
33 | #include <asm/fpu.h> | |
34 | #include <asm/reset-regs.h> | |
35 | #include <asm/gdb-stub.h> | |
36 | #include "internal.h" | |
37 | ||
38 | /* | |
39 | * power management idle function, if any.. | |
40 | */ | |
41 | void (*pm_idle)(void); | |
42 | EXPORT_SYMBOL(pm_idle); | |
43 | ||
44 | /* | |
45 | * return saved PC of a blocked thread. | |
46 | */ | |
47 | unsigned long thread_saved_pc(struct task_struct *tsk) | |
48 | { | |
49 | return ((unsigned long *) tsk->thread.sp)[3]; | |
50 | } | |
51 | ||
52 | /* | |
53 | * power off function, if any | |
54 | */ | |
55 | void (*pm_power_off)(void); | |
56 | EXPORT_SYMBOL(pm_power_off); | |
57 | ||
368dd5ac | 58 | #if !defined(CONFIG_SMP) || defined(CONFIG_HOTPLUG_CPU) |
b920de1b DH |
59 | /* |
60 | * we use this if we don't have any better idle routine | |
61 | */ | |
62 | static void default_idle(void) | |
63 | { | |
64 | local_irq_disable(); | |
65 | if (!need_resched()) | |
66 | safe_halt(); | |
67 | else | |
68 | local_irq_enable(); | |
69 | } | |
70 | ||
368dd5ac AT |
71 | #else /* !CONFIG_SMP || CONFIG_HOTPLUG_CPU */ |
72 | /* | |
73 | * On SMP it's slightly faster (but much more power-consuming!) | |
74 | * to poll the ->work.need_resched flag instead of waiting for the | |
75 | * cross-CPU IPI to arrive. Use this option with caution. | |
76 | */ | |
77 | static inline void poll_idle(void) | |
78 | { | |
79 | int oldval; | |
80 | ||
81 | local_irq_enable(); | |
82 | ||
83 | /* | |
84 | * Deal with another CPU just having chosen a thread to | |
85 | * run here: | |
86 | */ | |
87 | oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED); | |
88 | ||
89 | if (!oldval) { | |
90 | set_thread_flag(TIF_POLLING_NRFLAG); | |
91 | while (!need_resched()) | |
92 | cpu_relax(); | |
93 | clear_thread_flag(TIF_POLLING_NRFLAG); | |
94 | } else { | |
95 | set_need_resched(); | |
96 | } | |
97 | } | |
98 | #endif /* !CONFIG_SMP || CONFIG_HOTPLUG_CPU */ | |
99 | ||
b920de1b DH |
100 | /* |
101 | * the idle thread | |
102 | * - there's no useful work to be done, so just try to conserve power and have | |
103 | * a low exit latency (ie sit in a loop waiting for somebody to say that | |
104 | * they'd like to reschedule) | |
105 | */ | |
106 | void cpu_idle(void) | |
107 | { | |
b920de1b DH |
108 | /* endless idle loop with no priority at all */ |
109 | for (;;) { | |
110 | while (!need_resched()) { | |
111 | void (*idle)(void); | |
112 | ||
113 | smp_rmb(); | |
114 | idle = pm_idle; | |
368dd5ac AT |
115 | if (!idle) { |
116 | #if defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU) | |
117 | idle = poll_idle; | |
118 | #else /* CONFIG_SMP && !CONFIG_HOTPLUG_CPU */ | |
b920de1b | 119 | idle = default_idle; |
368dd5ac AT |
120 | #endif /* CONFIG_SMP && !CONFIG_HOTPLUG_CPU */ |
121 | } | |
b920de1b DH |
122 | idle(); |
123 | } | |
124 | ||
bd2f5536 | 125 | schedule_preempt_disabled(); |
b920de1b DH |
126 | } |
127 | } | |
128 | ||
129 | void release_segments(struct mm_struct *mm) | |
130 | { | |
131 | } | |
132 | ||
133 | void machine_restart(char *cmd) | |
134 | { | |
044264bb | 135 | #ifdef CONFIG_KERNEL_DEBUGGER |
b920de1b DH |
136 | gdbstub_exit(0); |
137 | #endif | |
138 | ||
139 | #ifdef mn10300_unit_hard_reset | |
140 | mn10300_unit_hard_reset(); | |
141 | #else | |
142 | mn10300_proc_hard_reset(); | |
143 | #endif | |
144 | } | |
145 | ||
146 | void machine_halt(void) | |
147 | { | |
044264bb | 148 | #ifdef CONFIG_KERNEL_DEBUGGER |
b920de1b DH |
149 | gdbstub_exit(0); |
150 | #endif | |
151 | } | |
152 | ||
153 | void machine_power_off(void) | |
154 | { | |
044264bb | 155 | #ifdef CONFIG_KERNEL_DEBUGGER |
b920de1b DH |
156 | gdbstub_exit(0); |
157 | #endif | |
158 | } | |
159 | ||
160 | void show_regs(struct pt_regs *regs) | |
161 | { | |
162 | } | |
163 | ||
164 | /* | |
165 | * create a kernel thread | |
166 | */ | |
167 | int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) | |
168 | { | |
255461c5 AV |
169 | struct pt_regs regs = { |
170 | .a0 = (unsigned long) fn; | |
171 | .d0 = (unsigned long) arg; | |
172 | }; | |
b920de1b | 173 | |
b920de1b DH |
174 | local_save_flags(regs.epsw); |
175 | regs.epsw |= EPSW_IE | EPSW_IM_7; | |
176 | ||
177 | /* Ok, create the new process.. */ | |
178 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, ®s, 0, | |
179 | NULL, NULL); | |
180 | } | |
181 | ||
182 | /* | |
183 | * free current thread data structures etc.. | |
184 | */ | |
185 | void exit_thread(void) | |
186 | { | |
187 | exit_fpu(); | |
188 | } | |
189 | ||
190 | void flush_thread(void) | |
191 | { | |
192 | flush_fpu(); | |
193 | } | |
194 | ||
195 | void release_thread(struct task_struct *dead_task) | |
196 | { | |
197 | } | |
198 | ||
199 | /* | |
200 | * we do not have to muck with descriptors here, that is | |
201 | * done in switch_mm() as needed. | |
202 | */ | |
203 | void copy_segments(struct task_struct *p, struct mm_struct *new_mm) | |
204 | { | |
205 | } | |
206 | ||
207 | /* | |
55ccf3fe SS |
208 | * this gets called so that we can store lazy state into memory and copy the |
209 | * current task into the new thread. | |
b920de1b | 210 | */ |
55ccf3fe | 211 | int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) |
b920de1b | 212 | { |
55ccf3fe SS |
213 | unlazy_fpu(src); |
214 | *dst = *src; | |
215 | return 0; | |
b920de1b DH |
216 | } |
217 | ||
218 | /* | |
219 | * set up the kernel stack for a new thread and copy arch-specific thread | |
220 | * control information | |
221 | */ | |
6f2c55b8 | 222 | int copy_thread(unsigned long clone_flags, |
b920de1b DH |
223 | unsigned long c_usp, unsigned long ustk_size, |
224 | struct task_struct *p, struct pt_regs *kregs) | |
225 | { | |
7c7fcf76 | 226 | struct thread_info *ti = task_thread_info(p); |
255461c5 | 227 | struct pt_regs *c_regs; |
b920de1b DH |
228 | unsigned long c_ksp; |
229 | ||
b920de1b DH |
230 | c_ksp = (unsigned long) task_stack_page(p) + THREAD_SIZE; |
231 | ||
232 | /* allocate the userspace exception frame and set it up */ | |
233 | c_ksp -= sizeof(struct pt_regs); | |
255461c5 | 234 | c_regs = (struct pt_regs *) c_ksp; |
b920de1b | 235 | |
255461c5 AV |
236 | p->thread.uregs = c_regs; |
237 | *c_regs = *kregs; | |
238 | c_regs->sp = c_usp; | |
239 | c_regs->epsw &= ~EPSW_FE; /* my FPU */ | |
b920de1b DH |
240 | |
241 | c_ksp -= 12; /* allocate function call ABI slack */ | |
242 | ||
243 | /* the new TLS pointer is passed in as arg #5 to sys_clone() */ | |
244 | if (clone_flags & CLONE_SETTLS) | |
255461c5 | 245 | c_regs->e2 = current_frame()->d3; |
b920de1b | 246 | |
255461c5 AV |
247 | if (unlikely(!user_mode(kregs))) |
248 | p->thread.pc = (unsigned long) ret_from_kernel_thread; | |
249 | else | |
250 | p->thread.pc = (unsigned long) ret_from_fork; | |
b920de1b DH |
251 | |
252 | /* set up things up so the scheduler can start the new task */ | |
255461c5 AV |
253 | ti->frame = c_regs; |
254 | p->thread.a3 = (unsigned long) c_regs; | |
b920de1b | 255 | p->thread.sp = c_ksp; |
255461c5 | 256 | p->thread.wchan = p->thread.pc; |
b920de1b DH |
257 | p->thread.usp = c_usp; |
258 | ||
259 | return 0; | |
260 | } | |
261 | ||
262 | /* | |
263 | * clone a process | |
7c7fcf76 | 264 | * - tlsptr is retrieved by copy_thread() from current_frame()->d3 |
b920de1b DH |
265 | */ |
266 | asmlinkage long sys_clone(unsigned long clone_flags, unsigned long newsp, | |
267 | int __user *parent_tidptr, int __user *child_tidptr, | |
268 | int __user *tlsptr) | |
269 | { | |
7c7fcf76 DH |
270 | return do_fork(clone_flags, newsp ?: current_frame()->sp, |
271 | current_frame(), 0, parent_tidptr, child_tidptr); | |
b920de1b DH |
272 | } |
273 | ||
274 | asmlinkage long sys_fork(void) | |
275 | { | |
7c7fcf76 DH |
276 | return do_fork(SIGCHLD, current_frame()->sp, |
277 | current_frame(), 0, NULL, NULL); | |
b920de1b DH |
278 | } |
279 | ||
280 | asmlinkage long sys_vfork(void) | |
281 | { | |
7c7fcf76 DH |
282 | return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, current_frame()->sp, |
283 | current_frame(), 0, NULL, NULL); | |
b920de1b DH |
284 | } |
285 | ||
b920de1b DH |
286 | unsigned long get_wchan(struct task_struct *p) |
287 | { | |
288 | return p->thread.wchan; | |
289 | } |