[ALSA] dynamic minors (4/6): dynamic minor number allocation
[linux-2.6/suspend2-2.6.18.git] / arch / arm26 / kernel / process.c
blob15833a0057dd1c9ad7360275cd81b4e1716d053b
1 /*
2 * linux/arch/arm26/kernel/process.c
4 * Copyright (C) 2003 Ian Molton - adapted for ARM26
5 * Copyright (C) 1996-2000 Russell King - Converted to ARM.
6 * Origional Copyright (C) 1995 Linus Torvalds
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <stdarg.h>
14 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/sched.h>
17 #include <linux/kernel.h>
18 #include <linux/mm.h>
19 #include <linux/stddef.h>
20 #include <linux/unistd.h>
21 #include <linux/ptrace.h>
22 #include <linux/slab.h>
23 #include <linux/user.h>
24 #include <linux/a.out.h>
25 #include <linux/delay.h>
26 #include <linux/reboot.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
30 #include <asm/system.h>
31 #include <asm/io.h>
32 #include <asm/leds.h>
33 #include <asm/processor.h>
34 #include <asm/uaccess.h>
36 extern const char *processor_modes[];
37 extern void setup_mm_for_reboot(char mode);
39 static volatile int hlt_counter;
41 void disable_hlt(void)
43 hlt_counter++;
46 EXPORT_SYMBOL(disable_hlt);
48 void enable_hlt(void)
50 hlt_counter--;
53 EXPORT_SYMBOL(enable_hlt);
55 static int __init nohlt_setup(char *__unused)
57 hlt_counter = 1;
58 return 1;
61 static int __init hlt_setup(char *__unused)
63 hlt_counter = 0;
64 return 1;
67 __setup("nohlt", nohlt_setup);
68 __setup("hlt", hlt_setup);
71 * This is our default idle handler. We need to disable
72 * interrupts here to ensure we don't miss a wakeup call.
74 void cpu_idle(void)
76 /* endless idle loop with no priority at all */
77 while (1) {
78 while (!need_resched())
79 cpu_relax();
80 preempt_enable_no_resched();
81 schedule();
82 preempt_disable();
86 static char reboot_mode = 'h';
88 int __init reboot_setup(char *str)
90 reboot_mode = str[0];
91 return 1;
94 __setup("reboot=", reboot_setup);
96 /* ARM26 cant do these but we still need to define them. */
97 void machine_halt(void)
100 void machine_power_off(void)
104 void machine_restart(char * __unused)
107 * Clean and disable cache, and turn off interrupts
109 cpu_proc_fin();
112 * Tell the mm system that we are going to reboot -
113 * we may need it to insert some 1:1 mappings so that
114 * soft boot works.
116 setup_mm_for_reboot(reboot_mode);
119 * copy branch instruction to reset location and call it
122 *(unsigned long *)0 = *(unsigned long *)0x03800000;
123 ((void(*)(void))0)();
126 * Whoops - the architecture was unable to reboot.
127 * Tell the user! Should never happen...
129 mdelay(1000);
130 printk("Reboot failed -- System halted\n");
131 while (1);
134 void show_regs(struct pt_regs * regs)
136 unsigned long flags;
138 flags = condition_codes(regs);
140 printk("pc : [<%08lx>] lr : [<%08lx>] %s\n"
141 "sp : %08lx ip : %08lx fp : %08lx\n",
142 instruction_pointer(regs),
143 regs->ARM_lr, print_tainted(), regs->ARM_sp,
144 regs->ARM_ip, regs->ARM_fp);
145 printk("r10: %08lx r9 : %08lx r8 : %08lx\n",
146 regs->ARM_r10, regs->ARM_r9,
147 regs->ARM_r8);
148 printk("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
149 regs->ARM_r7, regs->ARM_r6,
150 regs->ARM_r5, regs->ARM_r4);
151 printk("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
152 regs->ARM_r3, regs->ARM_r2,
153 regs->ARM_r1, regs->ARM_r0);
154 printk("Flags: %c%c%c%c",
155 flags & PSR_N_BIT ? 'N' : 'n',
156 flags & PSR_Z_BIT ? 'Z' : 'z',
157 flags & PSR_C_BIT ? 'C' : 'c',
158 flags & PSR_V_BIT ? 'V' : 'v');
159 printk(" IRQs o%s FIQs o%s Mode %s Segment %s\n",
160 interrupts_enabled(regs) ? "n" : "ff",
161 fast_interrupts_enabled(regs) ? "n" : "ff",
162 processor_modes[processor_mode(regs)],
163 get_fs() == get_ds() ? "kernel" : "user");
166 void show_fpregs(struct user_fp *regs)
168 int i;
170 for (i = 0; i < 8; i++) {
171 unsigned long *p;
172 char type;
174 p = (unsigned long *)(regs->fpregs + i);
176 switch (regs->ftype[i]) {
177 case 1: type = 'f'; break;
178 case 2: type = 'd'; break;
179 case 3: type = 'e'; break;
180 default: type = '?'; break;
182 if (regs->init_flag)
183 type = '?';
185 printk(" f%d(%c): %08lx %08lx %08lx%c",
186 i, type, p[0], p[1], p[2], i & 1 ? '\n' : ' ');
190 printk("FPSR: %08lx FPCR: %08lx\n",
191 (unsigned long)regs->fpsr,
192 (unsigned long)regs->fpcr);
196 * Task structure and kernel stack allocation.
198 static unsigned long *thread_info_head;
199 static unsigned int nr_thread_info;
201 extern unsigned long get_page_8k(int priority);
202 extern void free_page_8k(unsigned long page);
204 // FIXME - is this valid?
205 #define EXTRA_TASK_STRUCT 0
206 #define ll_alloc_task_struct() ((struct thread_info *)get_page_8k(GFP_KERNEL))
207 #define ll_free_task_struct(p) free_page_8k((unsigned long)(p))
209 //FIXME - do we use *task param below looks like we dont, which is ok?
210 //FIXME - if EXTRA_TASK_STRUCT is zero we can optimise the below away permanently. *IF* its supposed to be zero.
211 struct thread_info *alloc_thread_info(struct task_struct *task)
213 struct thread_info *thread = NULL;
215 if (EXTRA_TASK_STRUCT) {
216 unsigned long *p = thread_info_head;
218 if (p) {
219 thread_info_head = (unsigned long *)p[0];
220 nr_thread_info -= 1;
222 thread = (struct thread_info *)p;
225 if (!thread)
226 thread = ll_alloc_task_struct();
228 #ifdef CONFIG_MAGIC_SYSRQ
230 * The stack must be cleared if you want SYSRQ-T to
231 * give sensible stack usage information
233 if (thread) {
234 char *p = (char *)thread;
235 memzero(p+KERNEL_STACK_SIZE, KERNEL_STACK_SIZE);
237 #endif
238 return thread;
241 void free_thread_info(struct thread_info *thread)
243 if (EXTRA_TASK_STRUCT && nr_thread_info < EXTRA_TASK_STRUCT) {
244 unsigned long *p = (unsigned long *)thread;
245 p[0] = (unsigned long)thread_info_head;
246 thread_info_head = p;
247 nr_thread_info += 1;
248 } else
249 ll_free_task_struct(thread);
253 * Free current thread data structures etc..
255 void exit_thread(void)
259 void flush_thread(void)
261 struct thread_info *thread = current_thread_info();
262 struct task_struct *tsk = current;
264 memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
265 memset(&thread->fpstate, 0, sizeof(union fp_state));
267 clear_used_math();
270 void release_thread(struct task_struct *dead_task)
274 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
277 copy_thread(int nr, unsigned long clone_flags, unsigned long stack_start,
278 unsigned long unused, struct task_struct *p, struct pt_regs *regs)
280 struct thread_info *thread = p->thread_info;
281 struct pt_regs *childregs;
283 childregs = __get_user_regs(thread);
284 *childregs = *regs;
285 childregs->ARM_r0 = 0;
286 childregs->ARM_sp = stack_start;
288 memset(&thread->cpu_context, 0, sizeof(struct cpu_context_save));
289 thread->cpu_context.sp = (unsigned long)childregs;
290 thread->cpu_context.pc = (unsigned long)ret_from_fork | MODE_SVC26 | PSR_I_BIT;
292 return 0;
296 * fill in the fpe structure for a core dump...
298 int dump_fpu (struct pt_regs *regs, struct user_fp *fp)
300 struct thread_info *thread = current_thread_info();
301 int used_math = !!used_math();
303 if (used_math)
304 memcpy(fp, &thread->fpstate.soft, sizeof (*fp));
306 return used_math;
310 * fill in the user structure for a core dump..
312 void dump_thread(struct pt_regs * regs, struct user * dump)
314 struct task_struct *tsk = current;
316 dump->magic = CMAGIC;
317 dump->start_code = tsk->mm->start_code;
318 dump->start_stack = regs->ARM_sp & ~(PAGE_SIZE - 1);
320 dump->u_tsize = (tsk->mm->end_code - tsk->mm->start_code) >> PAGE_SHIFT;
321 dump->u_dsize = (tsk->mm->brk - tsk->mm->start_data + PAGE_SIZE - 1) >> PAGE_SHIFT;
322 dump->u_ssize = 0;
324 dump->u_debugreg[0] = tsk->thread.debug.bp[0].address;
325 dump->u_debugreg[1] = tsk->thread.debug.bp[1].address;
326 dump->u_debugreg[2] = tsk->thread.debug.bp[0].insn;
327 dump->u_debugreg[3] = tsk->thread.debug.bp[1].insn;
328 dump->u_debugreg[4] = tsk->thread.debug.nsaved;
330 if (dump->start_stack < 0x04000000)
331 dump->u_ssize = (0x04000000 - dump->start_stack) >> PAGE_SHIFT;
333 dump->regs = *regs;
334 dump->u_fpvalid = dump_fpu (regs, &dump->u_fp);
338 * Shuffle the argument into the correct register before calling the
339 * thread function. r1 is the thread argument, r2 is the pointer to
340 * the thread function, and r3 points to the exit function.
341 * FIXME - make sure this is right - the older code used to zero fp
342 * and cause the parent to call sys_exit (do_exit in this version)
344 extern void kernel_thread_helper(void);
346 asm( ".section .text\n"
347 " .align\n"
348 " .type kernel_thread_helper, #function\n"
349 "kernel_thread_helper:\n"
350 " mov r0, r1\n"
351 " mov lr, r3\n"
352 " mov pc, r2\n"
353 " .size kernel_thread_helper, . - kernel_thread_helper\n"
354 " .previous");
357 * Create a kernel thread.
359 pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
361 struct pt_regs regs;
363 memset(&regs, 0, sizeof(regs));
365 regs.ARM_r1 = (unsigned long)arg;
366 regs.ARM_r2 = (unsigned long)fn;
367 regs.ARM_r3 = (unsigned long)do_exit;
368 regs.ARM_pc = (unsigned long)kernel_thread_helper | MODE_SVC26;
370 return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
372 EXPORT_SYMBOL(kernel_thread);
375 unsigned long get_wchan(struct task_struct *p)
377 unsigned long fp, lr;
378 unsigned long stack_page;
379 int count = 0;
380 if (!p || p == current || p->state == TASK_RUNNING)
381 return 0;
383 stack_page = 4096 + (unsigned long)p;
384 fp = thread_saved_fp(p);
385 do {
386 if (fp < stack_page || fp > 4092+stack_page)
387 return 0;
388 lr = pc_pointer (((unsigned long *)fp)[-1]);
389 if (!in_sched_functions(lr))
390 return lr;
391 fp = *(unsigned long *) (fp - 12);
392 } while (count ++ < 16);
393 return 0;