Merge branch 'drm-forlinus' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[pandora-kernel.git] / arch / powerpc / kernel / process.c
index 047da1a..5770399 100644 (file)
@@ -46,9 +46,9 @@
 #include <asm/processor.h>
 #include <asm/mmu.h>
 #include <asm/prom.h>
+#include <asm/machdep.h>
 #ifdef CONFIG_PPC64
 #include <asm/firmware.h>
-#include <asm/plpar_wrappers.h>
 #include <asm/time.h>
 #endif
 
@@ -201,28 +201,38 @@ int dump_spe(struct pt_regs *regs, elf_vrregset_t *evrregs)
 }
 #endif /* CONFIG_SPE */
 
-static void set_dabr_spr(unsigned long val)
+#ifndef CONFIG_SMP
+/*
+ * If we are doing lazy switching of CPU state (FP, altivec or SPE),
+ * and the current task has some state, discard it.
+ */
+void discard_lazy_cpu_state(void)
 {
-       mtspr(SPRN_DABR, val);
+       preempt_disable();
+       if (last_task_used_math == current)
+               last_task_used_math = NULL;
+#ifdef CONFIG_ALTIVEC
+       if (last_task_used_altivec == current)
+               last_task_used_altivec = NULL;
+#endif /* CONFIG_ALTIVEC */
+#ifdef CONFIG_SPE
+       if (last_task_used_spe == current)
+               last_task_used_spe = NULL;
+#endif
+       preempt_enable();
 }
+#endif /* CONFIG_SMP */
 
+#ifdef CONFIG_PPC_MERGE                /* XXX for now */
 int set_dabr(unsigned long dabr)
 {
-       int ret = 0;
+       if (ppc_md.set_dabr)
+               return ppc_md.set_dabr(dabr);
 
-#ifdef CONFIG_PPC64
-       if (firmware_has_feature(FW_FEATURE_XDABR)) {
-               /* We want to catch accesses from kernel and userspace */
-               unsigned long flags = H_DABRX_KERNEL|H_DABRX_USER;
-               ret = plpar_set_xdabr(dabr, flags);
-       } else if (firmware_has_feature(FW_FEATURE_DABR)) {
-               ret = plpar_set_dabr(dabr);
-       } else
-#endif
-               set_dabr_spr(dabr);
-
-       return ret;
+       mtspr(SPRN_DABR, dabr);
+       return 0;
 }
+#endif
 
 #ifdef CONFIG_PPC64
 DEFINE_PER_CPU(struct cpu_usage, cpu_usage_array);
@@ -416,7 +426,7 @@ void show_regs(struct pt_regs * regs)
        if (trap == 0x300 || trap == 0x600)
                printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
        printk("TASK = %p[%d] '%s' THREAD: %p",
-              current, current->pid, current->comm, current->thread_info);
+              current, current->pid, current->comm, task_thread_info(current));
 
 #ifdef CONFIG_SMP
        printk(" CPU: %d", smp_processor_id());
@@ -448,19 +458,7 @@ void show_regs(struct pt_regs * regs)
 void exit_thread(void)
 {
        kprobe_flush_task(current);
-
-#ifndef CONFIG_SMP
-       if (last_task_used_math == current)
-               last_task_used_math = NULL;
-#ifdef CONFIG_ALTIVEC
-       if (last_task_used_altivec == current)
-               last_task_used_altivec = NULL;
-#endif /* CONFIG_ALTIVEC */
-#ifdef CONFIG_SPE
-       if (last_task_used_spe == current)
-               last_task_used_spe = NULL;
-#endif
-#endif /* CONFIG_SMP */
+       discard_lazy_cpu_state();
 }
 
 void flush_thread(void)
@@ -471,20 +469,8 @@ void flush_thread(void)
        if (t->flags & _TIF_ABI_PENDING)
                t->flags ^= (_TIF_ABI_PENDING | _TIF_32BIT);
 #endif
-       kprobe_flush_task(current);
 
-#ifndef CONFIG_SMP
-       if (last_task_used_math == current)
-               last_task_used_math = NULL;
-#ifdef CONFIG_ALTIVEC
-       if (last_task_used_altivec == current)
-               last_task_used_altivec = NULL;
-#endif /* CONFIG_ALTIVEC */
-#ifdef CONFIG_SPE
-       if (last_task_used_spe == current)
-               last_task_used_spe = NULL;
-#endif
-#endif /* CONFIG_SMP */
+       discard_lazy_cpu_state();
 
 #ifdef CONFIG_PPC64    /* for now */
        if (current->thread.dabr) {
@@ -519,7 +505,7 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
 {
        struct pt_regs *childregs, *kregs;
        extern void ret_from_fork(void);
-       unsigned long sp = (unsigned long)p->thread_info + THREAD_SIZE;
+       unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
 
        CHECK_FULL_REGS(regs);
        /* Copy registers */
@@ -532,7 +518,7 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
 #ifdef CONFIG_PPC32
                childregs->gpr[2] = (unsigned long) p;
 #else
-               clear_ti_thread_flag(p->thread_info, TIF_32BIT);
+               clear_tsk_thread_flag(p, TIF_32BIT);
 #endif
                p->thread.regs = NULL;  /* no user register state */
        } else {
@@ -566,12 +552,10 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
 #ifdef CONFIG_PPC64
        if (cpu_has_feature(CPU_FTR_SLB)) {
                unsigned long sp_vsid = get_kernel_vsid(sp);
+               unsigned long llp = mmu_psize_defs[mmu_linear_psize].sllp;
 
                sp_vsid <<= SLB_VSID_SHIFT;
-               sp_vsid |= SLB_VSID_KERNEL;
-               if (cpu_has_feature(CPU_FTR_16M_PAGE))
-                       sp_vsid |= SLB_VSID_L;
-
+               sp_vsid |= SLB_VSID_KERNEL | llp;
                p->thread.ksp_vsid = sp_vsid;
        }
 
@@ -606,10 +590,8 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
         * set.  Do it now.
         */
        if (!current->thread.regs) {
-               unsigned long childregs = (unsigned long)current->thread_info +
-                                               THREAD_SIZE;
-               childregs -= sizeof(struct pt_regs);
-               current->thread.regs = (struct pt_regs *)childregs;
+               struct pt_regs *regs = task_stack_page(current) + THREAD_SIZE;
+               current->thread.regs = regs - 1;
        }
 
        memset(regs->gpr, 0, sizeof(regs->gpr));
@@ -652,20 +634,9 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
        }
 #endif
 
-#ifndef CONFIG_SMP
-       if (last_task_used_math == current)
-               last_task_used_math = NULL;
-#ifdef CONFIG_ALTIVEC
-       if (last_task_used_altivec == current)
-               last_task_used_altivec = NULL;
-#endif
-#ifdef CONFIG_SPE
-       if (last_task_used_spe == current)
-               last_task_used_spe = NULL;
-#endif
-#endif /* CONFIG_SMP */
+       discard_lazy_cpu_state();
        memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
-       current->thread.fpscr = 0;
+       current->thread.fpscr.val = 0;
 #ifdef CONFIG_ALTIVEC
        memset(current->thread.vr, 0, sizeof(current->thread.vr));
        memset(&current->thread.vscr, 0, sizeof(current->thread.vscr));
@@ -796,7 +767,7 @@ out:
 static int validate_sp(unsigned long sp, struct task_struct *p,
                       unsigned long nbytes)
 {
-       unsigned long stack_page = (unsigned long)p->thread_info;
+       unsigned long stack_page = (unsigned long)task_stack_page(p);
 
        if (sp >= stack_page + sizeof(struct thread_struct)
            && sp <= stack_page + THREAD_SIZE - nbytes)