Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003, 06 by Ralf Baechle
0007  * Copyright (C) 1996 by Paul M. Antoine
0008  * Copyright (C) 1999 Silicon Graphics
0009  * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com
0010  * Copyright (C) 2000 MIPS Technologies, Inc.
0011  */
0012 #ifndef _ASM_SWITCH_TO_H
0013 #define _ASM_SWITCH_TO_H
0014 
0015 #include <asm/cpu-features.h>
0016 #include <asm/watch.h>
0017 #include <asm/dsp.h>
0018 #include <asm/cop2.h>
0019 #include <asm/fpu.h>
0020 
0021 struct task_struct;
0022 
0023 /**
0024  * resume - resume execution of a task
0025  * @prev:   The task previously executed.
0026  * @next:   The task to begin executing.
0027  * @next_ti:    task_thread_info(next).
0028  *
0029  * This function is used whilst scheduling to save the context of prev & load
0030  * the context of next. Returns prev.
0031  */
0032 extern asmlinkage struct task_struct *resume(struct task_struct *prev,
0033         struct task_struct *next, struct thread_info *next_ti);
0034 
0035 extern unsigned int ll_bit;
0036 extern struct task_struct *ll_task;
0037 
0038 #ifdef CONFIG_MIPS_MT_FPAFF
0039 
0040 /*
0041  * Handle the scheduler resume end of FPU affinity management.  We do this
0042  * inline to try to keep the overhead down. If we have been forced to run on
0043  * a "CPU" with an FPU because of a previous high level of FP computation,
0044  * but did not actually use the FPU during the most recent time-slice (CU1
0045  * isn't set), we undo the restriction on cpus_mask.
0046  *
0047  * We're not calling set_cpus_allowed() here, because we have no need to
0048  * force prompt migration - we're already switching the current CPU to a
0049  * different thread.
0050  */
0051 
0052 #define __mips_mt_fpaff_switch_to(prev)                 \
0053 do {                                    \
0054     struct thread_info *__prev_ti = task_thread_info(prev);     \
0055                                     \
0056     if (cpu_has_fpu &&                      \
0057         test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) &&     \
0058         (!(KSTK_STATUS(prev) & ST0_CU1))) {             \
0059         clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND);      \
0060         prev->cpus_mask = prev->thread.user_cpus_allowed;   \
0061     }                               \
0062     next->thread.emulated_fp = 0;                   \
0063 } while(0)
0064 
0065 #else
0066 #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0)
0067 #endif
0068 
0069 /*
0070  * Clear LLBit during context switches on MIPSr5+ such that eretnc can be used
0071  * unconditionally when returning to userland in entry.S.
0072  */
0073 #define __clear_r5_hw_ll_bit() do {                 \
0074     if (cpu_has_mips_r5 || cpu_has_mips_r6)             \
0075         write_c0_lladdr(0);                 \
0076 } while (0)
0077 
0078 #define __clear_software_ll_bit() do {                  \
0079     if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc)   \
0080         ll_bit = 0;                     \
0081 } while (0)
0082 
0083 /*
0084  * Check FCSR for any unmasked exceptions pending set with `ptrace',
0085  * clear them and send a signal.
0086  */
0087 #ifdef CONFIG_MIPS_FP_SUPPORT
0088 # define __sanitize_fcr31(next)                     \
0089 do {                                    \
0090     unsigned long fcr31 = mask_fcr31_x(next->thread.fpu.fcr31); \
0091     void __user *pc;                        \
0092                                     \
0093     if (unlikely(fcr31)) {                      \
0094         pc = (void __user *)task_pt_regs(next)->cp0_epc;    \
0095         next->thread.fpu.fcr31 &= ~fcr31;           \
0096         force_fcr31_sig(fcr31, pc, next);           \
0097     }                               \
0098 } while (0)
0099 #else
0100 # define __sanitize_fcr31(next)
0101 #endif
0102 
0103 /*
0104  * For newly created kernel threads switch_to() will return to
0105  * ret_from_kernel_thread, newly created user threads to ret_from_fork.
0106  * That is, everything following resume() will be skipped for new threads.
0107  * So everything that matters to new threads should be placed before resume().
0108  */
0109 #define switch_to(prev, next, last)                 \
0110 do {                                    \
0111     __mips_mt_fpaff_switch_to(prev);                \
0112     lose_fpu_inatomic(1, prev);                 \
0113     if (tsk_used_math(next))                    \
0114         __sanitize_fcr31(next);                 \
0115     if (cpu_has_dsp) {                      \
0116         __save_dsp(prev);                   \
0117         __restore_dsp(next);                    \
0118     }                               \
0119     if (cop2_present) {                     \
0120         u32 status = read_c0_status();              \
0121                                     \
0122         set_c0_status(ST0_CU2);                 \
0123         if ((KSTK_STATUS(prev) & ST0_CU2)) {            \
0124             if (cop2_lazy_restore)              \
0125                 KSTK_STATUS(prev) &= ~ST0_CU2;      \
0126             cop2_save(prev);                \
0127         }                           \
0128         if (KSTK_STATUS(next) & ST0_CU2 &&          \
0129             !cop2_lazy_restore) {               \
0130             cop2_restore(next);             \
0131         }                           \
0132         write_c0_status(status);                \
0133     }                               \
0134     __clear_r5_hw_ll_bit();                     \
0135     __clear_software_ll_bit();                  \
0136     if (cpu_has_userlocal)                      \
0137         write_c0_userlocal(task_thread_info(next)->tp_value);   \
0138     __restore_watch(next);                      \
0139     (last) = resume(prev, next, task_thread_info(next));        \
0140 } while (0)
0141 
0142 #endif /* _ASM_SWITCH_TO_H */