blob: 9428057a50cfa63b996c7f50fe10bea49bb069bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
4 * for more details.
5 *
Ralf Baechle0004a9d2006-10-31 03:45:07 +00006 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003, 06 by Ralf Baechle
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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.
11 */
12#ifndef _ASM_SYSTEM_H
13#define _ASM_SYSTEM_H
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/types.h>
Ralf Baechle192ef362006-07-07 14:07:18 +010016#include <linux/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/addrspace.h>
Ralf Baechle0004a9d2006-10-31 03:45:07 +000019#include <asm/barrier.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/cpu-features.h>
Ralf Baechlee50c0a82005-05-31 11:49:19 +000021#include <asm/dsp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/ptrace.h>
23#include <asm/war.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/*
27 * switch_to(n) should switch tasks to task nr n, first
28 * checking that n isn't the current task, in which case it does nothing.
29 */
30extern asmlinkage void *resume(void *last, void *next, void *next_ti);
31
32struct task_struct;
33
Ralf Baechlef088fc82006-04-05 09:45:47 +010034#ifdef CONFIG_MIPS_MT_FPAFF
35
36/*
37 * Handle the scheduler resume end of FPU affinity management. We do this
38 * inline to try to keep the overhead down. If we have been forced to run on
39 * a "CPU" with an FPU because of a previous high level of FP computation,
40 * but did not actually use the FPU during the most recent time-slice (CU1
41 * isn't set), we undo the restriction on cpus_allowed.
42 *
43 * We're not calling set_cpus_allowed() here, because we have no need to
44 * force prompt migration - we're already switching the current CPU to a
45 * different thread.
46 */
47
48#define switch_to(prev,next,last) \
49do { \
50 if (cpu_has_fpu && \
51 (prev->thread.mflags & MF_FPUBOUND) && \
52 (!(KSTK_STATUS(prev) & ST0_CU1))) { \
53 prev->thread.mflags &= ~MF_FPUBOUND; \
54 prev->cpus_allowed = prev->thread.user_cpus_allowed; \
55 } \
56 if (cpu_has_dsp) \
57 __save_dsp(prev); \
58 next->thread.emulated_fp = 0; \
59 (last) = resume(prev, next, next->thread_info); \
60 if (cpu_has_dsp) \
61 __restore_dsp(current); \
62} while(0)
63
64#else
Ralf Baechlee50c0a82005-05-31 11:49:19 +000065#define switch_to(prev,next,last) \
66do { \
67 if (cpu_has_dsp) \
68 __save_dsp(prev); \
Al Viro40bc9c62006-01-12 01:06:07 -080069 (last) = resume(prev, next, task_thread_info(next)); \
Ralf Baechlee50c0a82005-05-31 11:49:19 +000070 if (cpu_has_dsp) \
71 __restore_dsp(current); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070072} while(0)
Ralf Baechlef088fc82006-04-05 09:45:47 +010073#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Ingo Molnar4dc7a0b2006-01-12 01:05:27 -080075/*
76 * On SMP systems, when the scheduler does migration-cost autodetection,
77 * it needs a way to flush as much of the CPU's caches as possible.
78 *
79 * TODO: fill this in!
80 */
81static inline void sched_cacheflush(void)
82{
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
86{
87 __u32 retval;
88
89 if (cpu_has_llsc && R10000_LLSC_WAR) {
90 unsigned long dummy;
91
92 __asm__ __volatile__(
Maciej W. Rozyckic4559f62005-06-23 15:57:15 +000093 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 "1: ll %0, %3 # xchg_u32 \n"
Ralf Baechle72224242005-06-29 13:35:19 +000095 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 " move %2, %z4 \n"
Ralf Baechle72224242005-06-29 13:35:19 +000097 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 " sc %2, %1 \n"
99 " beqzl %2, 1b \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000100 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
102 : "R" (*m), "Jr" (val)
103 : "memory");
104 } else if (cpu_has_llsc) {
105 unsigned long dummy;
106
107 __asm__ __volatile__(
Maciej W. Rozyckic4559f62005-06-23 15:57:15 +0000108 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 "1: ll %0, %3 # xchg_u32 \n"
Ralf Baechle72224242005-06-29 13:35:19 +0000110 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 " move %2, %z4 \n"
Ralf Baechle72224242005-06-29 13:35:19 +0000112 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 " sc %2, %1 \n"
114 " beqz %2, 1b \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000115 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
117 : "R" (*m), "Jr" (val)
118 : "memory");
119 } else {
120 unsigned long flags;
121
122 local_irq_save(flags);
123 retval = *m;
124 *m = val;
125 local_irq_restore(flags); /* implies memory barrier */
126 }
127
Ralf Baechle0004a9d2006-10-31 03:45:07 +0000128 smp_mb();
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return retval;
131}
132
Ralf Baechle875d43e2005-09-03 15:56:16 -0700133#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
135{
136 __u64 retval;
137
138 if (cpu_has_llsc && R10000_LLSC_WAR) {
139 unsigned long dummy;
140
141 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000142 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 "1: lld %0, %3 # xchg_u64 \n"
144 " move %2, %z4 \n"
145 " scd %2, %1 \n"
146 " beqzl %2, 1b \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000147 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
149 : "R" (*m), "Jr" (val)
150 : "memory");
151 } else if (cpu_has_llsc) {
152 unsigned long dummy;
153
154 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000155 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 "1: lld %0, %3 # xchg_u64 \n"
157 " move %2, %z4 \n"
158 " scd %2, %1 \n"
159 " beqz %2, 1b \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000160 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
162 : "R" (*m), "Jr" (val)
163 : "memory");
164 } else {
165 unsigned long flags;
166
167 local_irq_save(flags);
168 retval = *m;
169 *m = val;
170 local_irq_restore(flags); /* implies memory barrier */
171 }
172
Ralf Baechle0004a9d2006-10-31 03:45:07 +0000173 smp_mb();
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 return retval;
176}
177#else
178extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
179#define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
180#endif
181
182/* This function doesn't exist, so you'll get a linker error
183 if something tries to do an invalid xchg(). */
184extern void __xchg_called_with_bad_pointer(void);
185
186static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
187{
188 switch (size) {
Ralf Baechle0cea0432006-03-03 09:42:05 +0000189 case 4:
190 return __xchg_u32(ptr, x);
191 case 8:
192 return __xchg_u64(ptr, x);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194 __xchg_called_with_bad_pointer();
195 return x;
196}
197
198#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
199#define tas(ptr) (xchg((ptr),1))
200
201#define __HAVE_ARCH_CMPXCHG 1
202
203static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
204 unsigned long new)
205{
206 __u32 retval;
207
208 if (cpu_has_llsc && R10000_LLSC_WAR) {
209 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000210 " .set push \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 " .set noat \n"
Maciej W. Rozyckic4559f62005-06-23 15:57:15 +0000212 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 "1: ll %0, %2 # __cmpxchg_u32 \n"
214 " bne %0, %z3, 2f \n"
Ralf Baechlef99d3022005-08-25 16:22:09 +0000215 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 " move $1, %z4 \n"
Ralf Baechlef99d3022005-08-25 16:22:09 +0000217 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 " sc $1, %1 \n"
219 " beqzl $1, 1b \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 "2: \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000221 " .set pop \n"
Ralf Baechle3e6cb2d2006-02-21 18:32:14 +0000222 : "=&r" (retval), "=R" (*m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 : "R" (*m), "Jr" (old), "Jr" (new)
224 : "memory");
225 } else if (cpu_has_llsc) {
226 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000227 " .set push \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 " .set noat \n"
Maciej W. Rozyckic4559f62005-06-23 15:57:15 +0000229 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 "1: ll %0, %2 # __cmpxchg_u32 \n"
231 " bne %0, %z3, 2f \n"
Ralf Baechlef99d3022005-08-25 16:22:09 +0000232 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 " move $1, %z4 \n"
Ralf Baechlef99d3022005-08-25 16:22:09 +0000234 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 " sc $1, %1 \n"
236 " beqz $1, 1b \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 "2: \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000238 " .set pop \n"
Ralf Baechle3e6cb2d2006-02-21 18:32:14 +0000239 : "=&r" (retval), "=R" (*m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 : "R" (*m), "Jr" (old), "Jr" (new)
241 : "memory");
242 } else {
243 unsigned long flags;
244
245 local_irq_save(flags);
246 retval = *m;
247 if (retval == old)
248 *m = new;
249 local_irq_restore(flags); /* implies memory barrier */
250 }
251
Ralf Baechle0004a9d2006-10-31 03:45:07 +0000252 smp_mb();
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return retval;
255}
256
Ralf Baechle875d43e2005-09-03 15:56:16 -0700257#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258static inline unsigned long __cmpxchg_u64(volatile int * m, unsigned long old,
259 unsigned long new)
260{
261 __u64 retval;
262
Ralf Baechle904880e2006-10-13 11:32:50 +0100263 if (cpu_has_llsc && R10000_LLSC_WAR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000265 " .set push \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 " .set noat \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000267 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 "1: lld %0, %2 # __cmpxchg_u64 \n"
269 " bne %0, %z3, 2f \n"
270 " move $1, %z4 \n"
271 " scd $1, %1 \n"
272 " beqzl $1, 1b \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 "2: \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000274 " .set pop \n"
Ralf Baechle3e6cb2d2006-02-21 18:32:14 +0000275 : "=&r" (retval), "=R" (*m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 : "R" (*m), "Jr" (old), "Jr" (new)
277 : "memory");
278 } else if (cpu_has_llsc) {
279 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000280 " .set push \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 " .set noat \n"
Maciej W. Rozyckic4559f62005-06-23 15:57:15 +0000282 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 "1: lld %0, %2 # __cmpxchg_u64 \n"
284 " bne %0, %z3, 2f \n"
285 " move $1, %z4 \n"
286 " scd $1, %1 \n"
287 " beqz $1, 1b \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 "2: \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000289 " .set pop \n"
Ralf Baechle3e6cb2d2006-02-21 18:32:14 +0000290 : "=&r" (retval), "=R" (*m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 : "R" (*m), "Jr" (old), "Jr" (new)
292 : "memory");
293 } else {
294 unsigned long flags;
295
296 local_irq_save(flags);
297 retval = *m;
298 if (retval == old)
299 *m = new;
300 local_irq_restore(flags); /* implies memory barrier */
301 }
302
Ralf Baechle0004a9d2006-10-31 03:45:07 +0000303 smp_mb();
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return retval;
306}
307#else
308extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
309 volatile int * m, unsigned long old, unsigned long new);
310#define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
311#endif
312
313/* This function doesn't exist, so you'll get a linker error
314 if something tries to do an invalid cmpxchg(). */
315extern void __cmpxchg_called_with_bad_pointer(void);
316
317static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
318 unsigned long new, int size)
319{
320 switch (size) {
321 case 4:
322 return __cmpxchg_u32(ptr, old, new);
323 case 8:
324 return __cmpxchg_u64(ptr, old, new);
325 }
326 __cmpxchg_called_with_bad_pointer();
327 return old;
328}
329
330#define cmpxchg(ptr,old,new) ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
331
Ralf Baechlee01402b2005-07-14 15:57:16 +0000332extern void set_handler (unsigned long offset, void *addr, unsigned long len);
333extern void set_uncached_handler (unsigned long offset, void *addr, unsigned long len);
334extern void *set_vi_handler (int n, void *addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335extern void *set_except_vector(int n, void *addr);
Ralf Baechle91b05e62006-03-29 18:53:00 +0100336extern unsigned long ebase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337extern void per_cpu_trap_init(void);
338
Ralf Baechle178086c2005-10-13 17:07:54 +0100339extern NORET_TYPE void die(const char *, struct pt_regs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Ralf Baechle178086c2005-10-13 17:07:54 +0100341static inline void die_if_kernel(const char *str, struct pt_regs *regs)
342{
343 if (unlikely(!user_mode(regs)))
344 die(str, regs);
345}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347extern int stop_a_enabled;
348
349/*
Nick Piggin4866cde2005-06-25 14:57:23 -0700350 * See include/asm-ia64/system.h; prevents deadlock on SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 * systems.
352 */
Nick Piggin4866cde2005-06-25 14:57:23 -0700353#define __ARCH_WANT_UNLOCKED_CTXSW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355#define arch_align_stack(x) (x)
356
357#endif /* _ASM_SYSTEM_H */