include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / arch / arm / kernel / process.c
index 89bfded..0e12e0a 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/mm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
-#include <linux/slab.h>
 #include <linux/user.h>
 #include <linux/delay.h>
 #include <linux/reboot.h>
 #include <linux/pm.h>
 #include <linux/tick.h>
 #include <linux/utsname.h>
+#include <linux/uaccess.h>
 
 #include <asm/leds.h>
 #include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/thread_notify.h>
-#include <asm/uaccess.h>
+#include <asm/stacktrace.h>
 #include <asm/mach/time.h>
 
 static const char *processor_modes[] = {
@@ -51,7 +51,7 @@ extern void setup_mm_for_reboot(char mode);
 
 static volatile int hlt_counter;
 
-#include <asm/arch/system.h>
+#include <mach/system.h>
 
 void disable_hlt(void)
 {
@@ -82,7 +82,7 @@ static int __init hlt_setup(char *__unused)
 __setup("nohlt", nohlt_setup);
 __setup("hlt", hlt_setup);
 
-void arm_machine_restart(char mode)
+void arm_machine_restart(char mode, const char *cmd)
 {
        /*
         * Clean and disable cache, and turn off interrupts
@@ -99,7 +99,7 @@ void arm_machine_restart(char mode)
        /*
         * Now call the architecture specific reboot code.
         */
-       arch_reset(mode);
+       arch_reset(mode, cmd);
 
        /*
         * Whoops - the architecture was unable to reboot.
@@ -113,13 +113,10 @@ void arm_machine_restart(char mode)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_idle)(void);
-EXPORT_SYMBOL(pm_idle);
-
 void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
-void (*arm_pm_restart)(char str) = arm_machine_restart;
+void (*arm_pm_restart)(char str, const char *cmd) = arm_machine_restart;
 EXPORT_SYMBOL_GPL(arm_pm_restart);
 
 
@@ -129,20 +126,19 @@ EXPORT_SYMBOL_GPL(arm_pm_restart);
  */
 static void default_idle(void)
 {
-       if (hlt_counter)
-               cpu_relax();
-       else {
-               local_irq_disable();
-               if (!need_resched())
-                       arch_idle();
-               local_irq_enable();
-       }
+       if (!need_resched())
+               arch_idle();
+       local_irq_enable();
 }
 
+void (*pm_idle)(void) = default_idle;
+EXPORT_SYMBOL(pm_idle);
+
 /*
- * The idle thread.  We try to conserve power, while trying to keep
- * overall latency low.  The architecture specific idle is passed
- * a value to indicate the level of "idleness" of the system.
+ * The idle thread, has rather strange semantics for calling pm_idle,
+ * but this is what x86 does and we need to do the same, so that
+ * things like cpuidle get called in the same way.  The only difference
+ * is that we always respect 'hlt_counter' to prevent low power idle.
  */
 void cpu_idle(void)
 {
@@ -150,21 +146,31 @@ void cpu_idle(void)
 
        /* endless idle loop with no priority at all */
        while (1) {
-               void (*idle)(void) = pm_idle;
-
+               tick_nohz_stop_sched_tick(1);
+               leds_event(led_idle_start);
+               while (!need_resched()) {
 #ifdef CONFIG_HOTPLUG_CPU
-               if (cpu_is_offline(smp_processor_id())) {
-                       leds_event(led_idle_start);
-                       cpu_die();
-               }
+                       if (cpu_is_offline(smp_processor_id()))
+                               cpu_die();
 #endif
 
-               if (!idle)
-                       idle = default_idle;
-               leds_event(led_idle_start);
-               tick_nohz_stop_sched_tick(1);
-               while (!need_resched())
-                       idle();
+                       local_irq_disable();
+                       if (hlt_counter) {
+                               local_irq_enable();
+                               cpu_relax();
+                       } else {
+                               stop_critical_timings();
+                               pm_idle();
+                               start_critical_timings();
+                               /*
+                                * This will eventually be removed - pm_idle
+                                * functions should always return with IRQs
+                                * enabled.
+                                */
+                               WARN_ON(irqs_disabled());
+                               local_irq_enable();
+                       }
+               }
                leds_event(led_idle_end);
                tick_nohz_restart_sched_tick();
                preempt_enable_no_resched();
@@ -194,9 +200,9 @@ void machine_power_off(void)
                pm_power_off();
 }
 
-void machine_restart(char * __unused)
+void machine_restart(char *cmd)
 {
-       arm_pm_restart(reboot_mode);
+       arm_pm_restart(reboot_mode, cmd);
 }
 
 void __show_regs(struct pt_regs *regs)
@@ -205,7 +211,8 @@ void __show_regs(struct pt_regs *regs)
        char buf[64];
 
        printk("CPU: %d    %s  (%s %.*s)\n",
-               smp_processor_id(), print_tainted(), init_utsname()->release,
+               raw_smp_processor_id(), print_tainted(),
+               init_utsname()->release,
                (int)strcspn(init_utsname()->version, " "),
                init_utsname()->version);
        print_symbol("PC is at %s\n", instruction_pointer(regs));
@@ -267,46 +274,18 @@ void show_regs(struct pt_regs * regs)
        __backtrace();
 }
 
-void show_fpregs(struct user_fp *regs)
-{
-       int i;
-
-       for (i = 0; i < 8; i++) {
-               unsigned long *p;
-               char type;
-
-               p = (unsigned long *)(regs->fpregs + i);
-
-               switch (regs->ftype[i]) {
-                       case 1: type = 'f'; break;
-                       case 2: type = 'd'; break;
-                       case 3: type = 'e'; break;
-                       default: type = '?'; break;
-               }
-               if (regs->init_flag)
-                       type = '?';
-
-               printk("  f%d(%c): %08lx %08lx %08lx%c",
-                       i, type, p[0], p[1], p[2], i & 1 ? '\n' : ' ');
-       }
-                       
+ATOMIC_NOTIFIER_HEAD(thread_notify_head);
 
-       printk("FPSR: %08lx FPCR: %08lx\n",
-               (unsigned long)regs->fpsr,
-               (unsigned long)regs->fpcr);
-}
+EXPORT_SYMBOL_GPL(thread_notify_head);
 
 /*
  * Free current thread data structures etc..
  */
 void exit_thread(void)
 {
+       thread_notify(THREAD_NOTIFY_EXIT, current_thread_info());
 }
 
-ATOMIC_NOTIFIER_HEAD(thread_notify_head);
-
-EXPORT_SYMBOL_GPL(thread_notify_head);
-
 void flush_thread(void)
 {
        struct thread_info *thread = current_thread_info();
@@ -321,15 +300,12 @@ void flush_thread(void)
 
 void release_thread(struct task_struct *dead_task)
 {
-       struct thread_info *thread = task_thread_info(dead_task);
-
-       thread_notify(THREAD_NOTIFY_RELEASE, thread);
 }
 
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
 
 int
-copy_thread(int nr, unsigned long clone_flags, unsigned long stack_start,
+copy_thread(unsigned long clone_flags, unsigned long stack_start,
            unsigned long stk_sz, struct task_struct *p, struct pt_regs *regs)
 {
        struct thread_info *thread = task_thread_info(p);
@@ -350,6 +326,15 @@ copy_thread(int nr, unsigned long clone_flags, unsigned long stack_start,
 }
 
 /*
+ * Fill in the task's elfregs structure for a core dump.
+ */
+int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs)
+{
+       elf_core_copy_regs(elfregs, task_pt_regs(t));
+       return 1;
+}
+
+/*
  * fill in the fpe structure for a core dump...
  */
 int dump_fpu (struct pt_regs *regs, struct user_fp *fp)
@@ -380,6 +365,23 @@ asm(       ".section .text\n"
 "      .size   kernel_thread_helper, . - kernel_thread_helper\n"
 "      .previous");
 
+#ifdef CONFIG_ARM_UNWIND
+extern void kernel_thread_exit(long code);
+asm(   ".section .text\n"
+"      .align\n"
+"      .type   kernel_thread_exit, #function\n"
+"kernel_thread_exit:\n"
+"      .fnstart\n"
+"      .cantunwind\n"
+"      bl      do_exit\n"
+"      nop\n"
+"      .fnend\n"
+"      .size   kernel_thread_exit, . - kernel_thread_exit\n"
+"      .previous");
+#else
+#define kernel_thread_exit     do_exit
+#endif
+
 /*
  * Create a kernel thread.
  */
@@ -391,9 +393,9 @@ pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
 
        regs.ARM_r1 = (unsigned long)arg;
        regs.ARM_r2 = (unsigned long)fn;
-       regs.ARM_r3 = (unsigned long)do_exit;
+       regs.ARM_r3 = (unsigned long)kernel_thread_exit;
        regs.ARM_pc = (unsigned long)kernel_thread_helper;
-       regs.ARM_cpsr = SVC_MODE;
+       regs.ARM_cpsr = SVC_MODE | PSR_ENDSTATE | PSR_ISETSTATE;
 
        return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
 }
@@ -401,23 +403,21 @@ EXPORT_SYMBOL(kernel_thread);
 
 unsigned long get_wchan(struct task_struct *p)
 {
-       unsigned long fp, lr;
-       unsigned long stack_start, stack_end;
+       struct stackframe frame;
        int count = 0;
        if (!p || p == current || p->state == TASK_RUNNING)
                return 0;
 
-       stack_start = (unsigned long)end_of_stack(p);
-       stack_end = (unsigned long)task_stack_page(p) + THREAD_SIZE;
-
-       fp = thread_saved_fp(p);
+       frame.fp = thread_saved_fp(p);
+       frame.sp = thread_saved_sp(p);
+       frame.lr = 0;                   /* recovered from the stack */
+       frame.pc = thread_saved_pc(p);
        do {
-               if (fp < stack_start || fp > stack_end)
+               int ret = unwind_frame(&frame);
+               if (ret < 0)
                        return 0;
-               lr = pc_pointer (((unsigned long *)fp)[-1]);
-               if (!in_sched_functions(lr))
-                       return lr;
-               fp = *(unsigned long *) (fp - 12);
+               if (!in_sched_functions(frame.pc))
+                       return frame.pc;
        } while (count ++ < 16);
        return 0;
 }