Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 6 | * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003, 06 by Ralf Baechle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 11 | */ |
| 12 | #ifndef _ASM_SYSTEM_H |
| 13 | #define _ASM_SYSTEM_H |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/types.h> |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 16 | #include <linux/irqflags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include <asm/addrspace.h> |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 19 | #include <asm/barrier.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/cpu-features.h> |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 21 | #include <asm/dsp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/war.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* |
| 26 | * switch_to(n) should switch tasks to task nr n, first |
| 27 | * checking that n isn't the current task, in which case it does nothing. |
| 28 | */ |
| 29 | extern asmlinkage void *resume(void *last, void *next, void *next_ti); |
| 30 | |
| 31 | struct task_struct; |
| 32 | |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 33 | #ifdef CONFIG_MIPS_MT_FPAFF |
| 34 | |
| 35 | /* |
| 36 | * Handle the scheduler resume end of FPU affinity management. We do this |
| 37 | * inline to try to keep the overhead down. If we have been forced to run on |
| 38 | * a "CPU" with an FPU because of a previous high level of FP computation, |
| 39 | * but did not actually use the FPU during the most recent time-slice (CU1 |
| 40 | * isn't set), we undo the restriction on cpus_allowed. |
| 41 | * |
| 42 | * We're not calling set_cpus_allowed() here, because we have no need to |
| 43 | * force prompt migration - we're already switching the current CPU to a |
| 44 | * different thread. |
| 45 | */ |
| 46 | |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 47 | #define __mips_mt_fpaff_switch_to(prev) \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 48 | do { \ |
| 49 | if (cpu_has_fpu && \ |
| 50 | (prev->thread.mflags & MF_FPUBOUND) && \ |
| 51 | (!(KSTK_STATUS(prev) & ST0_CU1))) { \ |
| 52 | prev->thread.mflags &= ~MF_FPUBOUND; \ |
| 53 | prev->cpus_allowed = prev->thread.user_cpus_allowed; \ |
| 54 | } \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 55 | next->thread.emulated_fp = 0; \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 56 | } while(0) |
| 57 | |
| 58 | #else |
Ralf Baechle | 35c700c | 2007-07-10 08:59:17 +0100 | [diff] [blame] | 59 | #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0) |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 60 | #endif |
| 61 | |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 62 | #define switch_to(prev,next,last) \ |
| 63 | do { \ |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 64 | __mips_mt_fpaff_switch_to(prev); \ |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 65 | if (cpu_has_dsp) \ |
| 66 | __save_dsp(prev); \ |
Al Viro | 40bc9c6 | 2006-01-12 01:06:07 -0800 | [diff] [blame] | 67 | (last) = resume(prev, next, task_thread_info(next)); \ |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 68 | if (cpu_has_dsp) \ |
| 69 | __restore_dsp(current); \ |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 70 | if (cpu_has_userlocal) \ |
| 71 | write_c0_userlocal(task_thread_info(current)->tp_value);\ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } while(0) |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | static inline unsigned long __xchg_u32(volatile int * m, unsigned int val) |
| 75 | { |
| 76 | __u32 retval; |
| 77 | |
| 78 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 79 | unsigned long dummy; |
| 80 | |
| 81 | __asm__ __volatile__( |
Maciej W. Rozycki | c4559f6 | 2005-06-23 15:57:15 +0000 | [diff] [blame] | 82 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | "1: ll %0, %3 # xchg_u32 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 84 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | " move %2, %z4 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 86 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | " sc %2, %1 \n" |
| 88 | " beqzl %2, 1b \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 89 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 91 | : "R" (*m), "Jr" (val) |
| 92 | : "memory"); |
| 93 | } else if (cpu_has_llsc) { |
| 94 | unsigned long dummy; |
| 95 | |
| 96 | __asm__ __volatile__( |
Maciej W. Rozycki | c4559f6 | 2005-06-23 15:57:15 +0000 | [diff] [blame] | 97 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | "1: ll %0, %3 # xchg_u32 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 99 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | " move %2, %z4 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 101 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | " sc %2, %1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 103 | " beqz %2, 2f \n" |
| 104 | " .subsection 2 \n" |
| 105 | "2: b 1b \n" |
| 106 | " .previous \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 107 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 109 | : "R" (*m), "Jr" (val) |
| 110 | : "memory"); |
| 111 | } else { |
| 112 | unsigned long flags; |
| 113 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 114 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | retval = *m; |
| 116 | *m = val; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 117 | raw_local_irq_restore(flags); /* implies memory barrier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 120 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return retval; |
| 123 | } |
| 124 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 125 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val) |
| 127 | { |
| 128 | __u64 retval; |
| 129 | |
| 130 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 131 | unsigned long dummy; |
| 132 | |
| 133 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 134 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | "1: lld %0, %3 # xchg_u64 \n" |
| 136 | " move %2, %z4 \n" |
| 137 | " scd %2, %1 \n" |
| 138 | " beqzl %2, 1b \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 139 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 141 | : "R" (*m), "Jr" (val) |
| 142 | : "memory"); |
| 143 | } else if (cpu_has_llsc) { |
| 144 | unsigned long dummy; |
| 145 | |
| 146 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 147 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | "1: lld %0, %3 # xchg_u64 \n" |
| 149 | " move %2, %z4 \n" |
| 150 | " scd %2, %1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 151 | " beqz %2, 2f \n" |
| 152 | " .subsection 2 \n" |
| 153 | "2: b 1b \n" |
| 154 | " .previous \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 155 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 157 | : "R" (*m), "Jr" (val) |
| 158 | : "memory"); |
| 159 | } else { |
| 160 | unsigned long flags; |
| 161 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 162 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | retval = *m; |
| 164 | *m = val; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 165 | raw_local_irq_restore(flags); /* implies memory barrier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 168 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | return retval; |
| 171 | } |
| 172 | #else |
| 173 | extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val); |
| 174 | #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels |
| 175 | #endif |
| 176 | |
| 177 | /* This function doesn't exist, so you'll get a linker error |
| 178 | if something tries to do an invalid xchg(). */ |
| 179 | extern void __xchg_called_with_bad_pointer(void); |
| 180 | |
| 181 | static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) |
| 182 | { |
| 183 | switch (size) { |
Ralf Baechle | 0cea043 | 2006-03-03 09:42:05 +0000 | [diff] [blame] | 184 | case 4: |
| 185 | return __xchg_u32(ptr, x); |
| 186 | case 8: |
| 187 | return __xchg_u64(ptr, x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | __xchg_called_with_bad_pointer(); |
| 190 | return x; |
| 191 | } |
| 192 | |
| 193 | #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | #define __HAVE_ARCH_CMPXCHG 1 |
| 196 | |
| 197 | static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old, |
| 198 | unsigned long new) |
| 199 | { |
| 200 | __u32 retval; |
| 201 | |
| 202 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 203 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 204 | " .set push \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | " .set noat \n" |
Maciej W. Rozycki | c4559f6 | 2005-06-23 15:57:15 +0000 | [diff] [blame] | 206 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | "1: ll %0, %2 # __cmpxchg_u32 \n" |
| 208 | " bne %0, %z3, 2f \n" |
Ralf Baechle | f99d302 | 2005-08-25 16:22:09 +0000 | [diff] [blame] | 209 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | " move $1, %z4 \n" |
Ralf Baechle | f99d302 | 2005-08-25 16:22:09 +0000 | [diff] [blame] | 211 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | " sc $1, %1 \n" |
| 213 | " beqzl $1, 1b \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | "2: \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 215 | " .set pop \n" |
Ralf Baechle | 3e6cb2d | 2006-02-21 18:32:14 +0000 | [diff] [blame] | 216 | : "=&r" (retval), "=R" (*m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | : "R" (*m), "Jr" (old), "Jr" (new) |
| 218 | : "memory"); |
| 219 | } else if (cpu_has_llsc) { |
| 220 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 221 | " .set push \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | " .set noat \n" |
Maciej W. Rozycki | c4559f6 | 2005-06-23 15:57:15 +0000 | [diff] [blame] | 223 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | "1: ll %0, %2 # __cmpxchg_u32 \n" |
| 225 | " bne %0, %z3, 2f \n" |
Ralf Baechle | f99d302 | 2005-08-25 16:22:09 +0000 | [diff] [blame] | 226 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | " move $1, %z4 \n" |
Ralf Baechle | f99d302 | 2005-08-25 16:22:09 +0000 | [diff] [blame] | 228 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | " sc $1, %1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 230 | " beqz $1, 3f \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | "2: \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 232 | " .subsection 2 \n" |
| 233 | "3: b 1b \n" |
| 234 | " .previous \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 235 | " .set pop \n" |
Ralf Baechle | 3e6cb2d | 2006-02-21 18:32:14 +0000 | [diff] [blame] | 236 | : "=&r" (retval), "=R" (*m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | : "R" (*m), "Jr" (old), "Jr" (new) |
| 238 | : "memory"); |
| 239 | } else { |
| 240 | unsigned long flags; |
| 241 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 242 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | retval = *m; |
| 244 | if (retval == old) |
| 245 | *m = new; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 246 | raw_local_irq_restore(flags); /* implies memory barrier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 249 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | return retval; |
| 252 | } |
| 253 | |
Mathieu Desnoyers | 7232311 | 2007-05-08 00:34:47 -0700 | [diff] [blame] | 254 | static inline unsigned long __cmpxchg_u32_local(volatile int * m, |
| 255 | unsigned long old, unsigned long new) |
| 256 | { |
| 257 | __u32 retval; |
| 258 | |
| 259 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 260 | __asm__ __volatile__( |
| 261 | " .set push \n" |
| 262 | " .set noat \n" |
| 263 | " .set mips3 \n" |
| 264 | "1: ll %0, %2 # __cmpxchg_u32 \n" |
| 265 | " bne %0, %z3, 2f \n" |
| 266 | " .set mips0 \n" |
| 267 | " move $1, %z4 \n" |
| 268 | " .set mips3 \n" |
| 269 | " sc $1, %1 \n" |
| 270 | " beqzl $1, 1b \n" |
| 271 | "2: \n" |
| 272 | " .set pop \n" |
| 273 | : "=&r" (retval), "=R" (*m) |
| 274 | : "R" (*m), "Jr" (old), "Jr" (new) |
| 275 | : "memory"); |
| 276 | } else if (cpu_has_llsc) { |
| 277 | __asm__ __volatile__( |
| 278 | " .set push \n" |
| 279 | " .set noat \n" |
| 280 | " .set mips3 \n" |
| 281 | "1: ll %0, %2 # __cmpxchg_u32 \n" |
| 282 | " bne %0, %z3, 2f \n" |
| 283 | " .set mips0 \n" |
| 284 | " move $1, %z4 \n" |
| 285 | " .set mips3 \n" |
| 286 | " sc $1, %1 \n" |
| 287 | " beqz $1, 1b \n" |
| 288 | "2: \n" |
| 289 | " .set pop \n" |
| 290 | : "=&r" (retval), "=R" (*m) |
| 291 | : "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 | |
| 303 | return retval; |
| 304 | } |
| 305 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 306 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | static inline unsigned long __cmpxchg_u64(volatile int * m, unsigned long old, |
| 308 | unsigned long new) |
| 309 | { |
| 310 | __u64 retval; |
| 311 | |
Ralf Baechle | 904880e | 2006-10-13 11:32:50 +0100 | [diff] [blame] | 312 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 314 | " .set push \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | " .set noat \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 316 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | "1: lld %0, %2 # __cmpxchg_u64 \n" |
| 318 | " bne %0, %z3, 2f \n" |
| 319 | " move $1, %z4 \n" |
| 320 | " scd $1, %1 \n" |
| 321 | " beqzl $1, 1b \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | "2: \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 323 | " .set pop \n" |
Ralf Baechle | 3e6cb2d | 2006-02-21 18:32:14 +0000 | [diff] [blame] | 324 | : "=&r" (retval), "=R" (*m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | : "R" (*m), "Jr" (old), "Jr" (new) |
| 326 | : "memory"); |
| 327 | } else if (cpu_has_llsc) { |
| 328 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 329 | " .set push \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | " .set noat \n" |
Maciej W. Rozycki | c4559f6 | 2005-06-23 15:57:15 +0000 | [diff] [blame] | 331 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | "1: lld %0, %2 # __cmpxchg_u64 \n" |
| 333 | " bne %0, %z3, 2f \n" |
| 334 | " move $1, %z4 \n" |
| 335 | " scd $1, %1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 336 | " beqz $1, 3f \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | "2: \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 338 | " .subsection 2 \n" |
| 339 | "3: b 1b \n" |
| 340 | " .previous \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 341 | " .set pop \n" |
Ralf Baechle | 3e6cb2d | 2006-02-21 18:32:14 +0000 | [diff] [blame] | 342 | : "=&r" (retval), "=R" (*m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | : "R" (*m), "Jr" (old), "Jr" (new) |
| 344 | : "memory"); |
| 345 | } else { |
| 346 | unsigned long flags; |
| 347 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 348 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | retval = *m; |
| 350 | if (retval == old) |
| 351 | *m = new; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 352 | raw_local_irq_restore(flags); /* implies memory barrier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 355 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | return retval; |
| 358 | } |
Mathieu Desnoyers | 7232311 | 2007-05-08 00:34:47 -0700 | [diff] [blame] | 359 | |
| 360 | static inline unsigned long __cmpxchg_u64_local(volatile int * m, |
| 361 | unsigned long old, unsigned long new) |
| 362 | { |
| 363 | __u64 retval; |
| 364 | |
| 365 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 366 | __asm__ __volatile__( |
| 367 | " .set push \n" |
| 368 | " .set noat \n" |
| 369 | " .set mips3 \n" |
| 370 | "1: lld %0, %2 # __cmpxchg_u64 \n" |
| 371 | " bne %0, %z3, 2f \n" |
| 372 | " move $1, %z4 \n" |
| 373 | " scd $1, %1 \n" |
| 374 | " beqzl $1, 1b \n" |
| 375 | "2: \n" |
| 376 | " .set pop \n" |
| 377 | : "=&r" (retval), "=R" (*m) |
| 378 | : "R" (*m), "Jr" (old), "Jr" (new) |
| 379 | : "memory"); |
| 380 | } else if (cpu_has_llsc) { |
| 381 | __asm__ __volatile__( |
| 382 | " .set push \n" |
| 383 | " .set noat \n" |
| 384 | " .set mips3 \n" |
| 385 | "1: lld %0, %2 # __cmpxchg_u64 \n" |
| 386 | " bne %0, %z3, 2f \n" |
| 387 | " move $1, %z4 \n" |
| 388 | " scd $1, %1 \n" |
| 389 | " beqz $1, 1b \n" |
| 390 | "2: \n" |
| 391 | " .set pop \n" |
| 392 | : "=&r" (retval), "=R" (*m) |
| 393 | : "R" (*m), "Jr" (old), "Jr" (new) |
| 394 | : "memory"); |
| 395 | } else { |
| 396 | unsigned long flags; |
| 397 | |
| 398 | local_irq_save(flags); |
| 399 | retval = *m; |
| 400 | if (retval == old) |
| 401 | *m = new; |
| 402 | local_irq_restore(flags); /* implies memory barrier */ |
| 403 | } |
| 404 | |
| 405 | return retval; |
| 406 | } |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | #else |
| 409 | extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels( |
| 410 | volatile int * m, unsigned long old, unsigned long new); |
| 411 | #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels |
Mathieu Desnoyers | 7232311 | 2007-05-08 00:34:47 -0700 | [diff] [blame] | 412 | extern unsigned long __cmpxchg_u64_local_unsupported_on_32bit_kernels( |
| 413 | volatile int * m, unsigned long old, unsigned long new); |
| 414 | #define __cmpxchg_u64_local __cmpxchg_u64_local_unsupported_on_32bit_kernels |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | #endif |
| 416 | |
| 417 | /* This function doesn't exist, so you'll get a linker error |
| 418 | if something tries to do an invalid cmpxchg(). */ |
| 419 | extern void __cmpxchg_called_with_bad_pointer(void); |
| 420 | |
| 421 | static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, |
| 422 | unsigned long new, int size) |
| 423 | { |
| 424 | switch (size) { |
| 425 | case 4: |
| 426 | return __cmpxchg_u32(ptr, old, new); |
| 427 | case 8: |
| 428 | return __cmpxchg_u64(ptr, old, new); |
| 429 | } |
| 430 | __cmpxchg_called_with_bad_pointer(); |
| 431 | return old; |
| 432 | } |
| 433 | |
Mathieu Desnoyers | 7232311 | 2007-05-08 00:34:47 -0700 | [diff] [blame] | 434 | static inline unsigned long __cmpxchg_local(volatile void * ptr, |
| 435 | unsigned long old, unsigned long new, int size) |
| 436 | { |
| 437 | switch (size) { |
| 438 | case 4: |
| 439 | return __cmpxchg_u32_local(ptr, old, new); |
| 440 | case 8: |
| 441 | return __cmpxchg_u64_local(ptr, old, new); |
| 442 | } |
| 443 | __cmpxchg_called_with_bad_pointer(); |
| 444 | return old; |
| 445 | } |
| 446 | |
| 447 | #define cmpxchg(ptr,old,new) \ |
| 448 | ((__typeof__(*(ptr)))__cmpxchg((ptr), \ |
| 449 | (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr)))) |
| 450 | |
| 451 | #define cmpxchg_local(ptr,old,new) \ |
| 452 | ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \ |
| 453 | (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 455 | extern void set_handler (unsigned long offset, void *addr, unsigned long len); |
| 456 | extern void set_uncached_handler (unsigned long offset, void *addr, unsigned long len); |
Ralf Baechle | ef300e4 | 2007-05-06 18:31:18 +0100 | [diff] [blame] | 457 | |
| 458 | typedef void (*vi_handler_t)(void); |
| 459 | extern void *set_vi_handler (int n, vi_handler_t addr); |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | extern void *set_except_vector(int n, void *addr); |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 462 | extern unsigned long ebase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | extern void per_cpu_trap_init(void); |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | extern int stop_a_enabled; |
| 466 | |
| 467 | /* |
Nick Piggin | 4866cde | 2005-06-25 14:57:23 -0700 | [diff] [blame] | 468 | * See include/asm-ia64/system.h; prevents deadlock on SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | * systems. |
| 470 | */ |
Nick Piggin | 4866cde | 2005-06-25 14:57:23 -0700 | [diff] [blame] | 471 | #define __ARCH_WANT_UNLOCKED_CTXSW |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | #define arch_align_stack(x) (x) |
| 474 | |
| 475 | #endif /* _ASM_SYSTEM_H */ |