2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003, 06 by Ralf Baechle
7 * Copyright (C) 1996 by Paul M. Antoine
8 * Copyright (C) 1999 Silicon Graphics
9 * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com
10 * Copyright (C) 2000 MIPS Technologies, Inc.
15 #include <linux/types.h>
16 #include <linux/irqflags.h>
18 #include <asm/addrspace.h>
19 #include <asm/barrier.h>
20 #include <asm/cmpxchg.h>
21 #include <asm/cpu-features.h>
23 #include <asm/watch.h>
28 * switch_to(n) should switch tasks to task nr n, first
29 * checking that n isn't the current task, in which case it does nothing.
31 extern asmlinkage
void *resume(void *last
, void *next
, void *next_ti
);
35 extern unsigned int ll_bit
;
36 extern struct task_struct
*ll_task
;
38 #ifdef CONFIG_MIPS_MT_FPAFF
41 * Handle the scheduler resume end of FPU affinity management. We do this
42 * inline to try to keep the overhead down. If we have been forced to run on
43 * a "CPU" with an FPU because of a previous high level of FP computation,
44 * but did not actually use the FPU during the most recent time-slice (CU1
45 * isn't set), we undo the restriction on cpus_allowed.
47 * We're not calling set_cpus_allowed() here, because we have no need to
48 * force prompt migration - we're already switching the current CPU to a
52 #define __mips_mt_fpaff_switch_to(prev) \
54 struct thread_info *__prev_ti = task_thread_info(prev); \
57 test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \
58 (!(KSTK_STATUS(prev) & ST0_CU1))) { \
59 clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \
60 prev->cpus_allowed = prev->thread.user_cpus_allowed; \
62 next->thread.emulated_fp = 0; \
66 #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0)
69 #define __clear_software_ll_bit() \
71 if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc) \
75 #define switch_to(prev, next, last) \
77 __mips_mt_fpaff_switch_to(prev); \
80 __clear_software_ll_bit(); \
81 (last) = resume(prev, next, task_thread_info(next)); \
84 #define finish_arch_switch(prev) \
87 __restore_dsp(current); \
88 if (cpu_has_userlocal) \
89 write_c0_userlocal(current_thread_info()->tp_value); \
93 static inline unsigned long __xchg_u32(volatile int * m
, unsigned int val
)
97 if (kernel_uses_llsc
&& R10000_LLSC_WAR
) {
100 __asm__
__volatile__(
102 "1: ll %0, %3 # xchg_u32 \n"
109 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
110 : "R" (*m
), "Jr" (val
)
112 } else if (kernel_uses_llsc
) {
115 __asm__
__volatile__(
117 "1: ll %0, %3 # xchg_u32 \n"
127 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
128 : "R" (*m
), "Jr" (val
)
133 raw_local_irq_save(flags
);
136 raw_local_irq_restore(flags
); /* implies memory barrier */
145 static inline __u64
__xchg_u64(volatile __u64
* m
, __u64 val
)
149 if (kernel_uses_llsc
&& R10000_LLSC_WAR
) {
152 __asm__
__volatile__(
154 "1: lld %0, %3 # xchg_u64 \n"
159 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
160 : "R" (*m
), "Jr" (val
)
162 } else if (kernel_uses_llsc
) {
165 __asm__
__volatile__(
167 "1: lld %0, %3 # xchg_u64 \n"
175 : "=&r" (retval
), "=m" (*m
), "=&r" (dummy
)
176 : "R" (*m
), "Jr" (val
)
181 raw_local_irq_save(flags
);
184 raw_local_irq_restore(flags
); /* implies memory barrier */
192 extern __u64
__xchg_u64_unsupported_on_32bit_kernels(volatile __u64
* m
, __u64 val
);
193 #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
196 /* This function doesn't exist, so you'll get a linker error
197 if something tries to do an invalid xchg(). */
198 extern void __xchg_called_with_bad_pointer(void);
200 static inline unsigned long __xchg(unsigned long x
, volatile void * ptr
, int size
)
204 return __xchg_u32(ptr
, x
);
206 return __xchg_u64(ptr
, x
);
208 __xchg_called_with_bad_pointer();
212 #define xchg(ptr, x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
214 extern void set_handler(unsigned long offset
, void *addr
, unsigned long len
);
215 extern void set_uncached_handler(unsigned long offset
, void *addr
, unsigned long len
);
217 typedef void (*vi_handler_t
)(void);
218 extern void *set_vi_handler(int n
, vi_handler_t addr
);
220 extern void *set_except_vector(int n
, void *addr
);
221 extern unsigned long ebase
;
222 extern void per_cpu_trap_init(void);
225 * See include/asm-ia64/system.h; prevents deadlock on SMP
228 #define __ARCH_WANT_UNLOCKED_CTXSW
230 extern unsigned long arch_align_stack(unsigned long sp
);
232 #endif /* _ASM_SYSTEM_H */