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> |
Ralf Baechle | fef7470 | 2007-10-01 04:15:00 +0100 | [diff] [blame] | 20 | #include <asm/cmpxchg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/cpu-features.h> |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 22 | #include <asm/dsp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/war.h> |
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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* |
| 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 | */ |
| 30 | extern asmlinkage void *resume(void *last, void *next, void *next_ti); |
| 31 | |
| 32 | struct task_struct; |
| 33 | |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 34 | #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 | |
Ralf Baechle | d223a861 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 48 | #define __mips_mt_fpaff_switch_to(prev) \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 49 | do { \ |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 50 | struct thread_info *__prev_ti = task_thread_info(prev); \ |
| 51 | \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 52 | if (cpu_has_fpu && \ |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 53 | test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \ |
| 54 | (!(KSTK_STATUS(prev) & ST0_CU1))) { \ |
| 55 | clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 56 | prev->cpus_allowed = prev->thread.user_cpus_allowed; \ |
| 57 | } \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 58 | next->thread.emulated_fp = 0; \ |
Ralf Baechle | f088fc8 | 2006-04-05 09:45:47 +0100 | [diff] [blame] | 59 | } while(0) |
| 60 | |
| 61 | #else |
Ralf Baechle | 35c700c | 2007-07-10 08:59:17 +0100 | [diff] [blame] | 62 | #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0) |
Ralf Baechle | d223a861 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 63 | #endif |
| 64 | |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 65 | #define switch_to(prev, next, last) \ |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 66 | do { \ |
Ralf Baechle | d223a861 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 67 | __mips_mt_fpaff_switch_to(prev); \ |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 68 | if (cpu_has_dsp) \ |
| 69 | __save_dsp(prev); \ |
Al Viro | 40bc9c6 | 2006-01-12 01:06:07 -0800 | [diff] [blame] | 70 | (last) = resume(prev, next, task_thread_info(next)); \ |
Ralf Baechle | 07500b0 | 2007-10-30 17:25:26 +0000 | [diff] [blame] | 71 | } while (0) |
| 72 | |
| 73 | #define finish_arch_switch(prev) \ |
| 74 | do { \ |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 75 | if (cpu_has_dsp) \ |
| 76 | __restore_dsp(current); \ |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 77 | if (cpu_has_userlocal) \ |
Ralf Baechle | 07500b0 | 2007-10-30 17:25:26 +0000 | [diff] [blame] | 78 | write_c0_userlocal(current_thread_info()->tp_value); \ |
| 79 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static inline unsigned long __xchg_u32(volatile int * m, unsigned int val) |
| 82 | { |
| 83 | __u32 retval; |
| 84 | |
| 85 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 86 | unsigned long dummy; |
| 87 | |
| 88 | __asm__ __volatile__( |
Maciej W. Rozycki | c4559f6 | 2005-06-23 15:57:15 +0000 | [diff] [blame] | 89 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | "1: ll %0, %3 # xchg_u32 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 91 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | " move %2, %z4 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 93 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | " sc %2, %1 \n" |
| 95 | " beqzl %2, 1b \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 96 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 98 | : "R" (*m), "Jr" (val) |
| 99 | : "memory"); |
| 100 | } else if (cpu_has_llsc) { |
| 101 | unsigned long dummy; |
| 102 | |
| 103 | __asm__ __volatile__( |
Maciej W. Rozycki | c4559f6 | 2005-06-23 15:57:15 +0000 | [diff] [blame] | 104 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | "1: ll %0, %3 # xchg_u32 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 106 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | " move %2, %z4 \n" |
Ralf Baechle | 7222424 | 2005-06-29 13:35:19 +0000 | [diff] [blame] | 108 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | " sc %2, %1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 110 | " beqz %2, 2f \n" |
| 111 | " .subsection 2 \n" |
| 112 | "2: b 1b \n" |
| 113 | " .previous \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 114 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 116 | : "R" (*m), "Jr" (val) |
| 117 | : "memory"); |
| 118 | } else { |
| 119 | unsigned long flags; |
| 120 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 121 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | retval = *m; |
| 123 | *m = val; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 124 | raw_local_irq_restore(flags); /* implies memory barrier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame] | 127 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return retval; |
| 130 | } |
| 131 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 132 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val) |
| 134 | { |
| 135 | __u64 retval; |
| 136 | |
| 137 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 138 | unsigned long dummy; |
| 139 | |
| 140 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 141 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | "1: lld %0, %3 # xchg_u64 \n" |
| 143 | " move %2, %z4 \n" |
| 144 | " scd %2, %1 \n" |
| 145 | " beqzl %2, 1b \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 146 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 148 | : "R" (*m), "Jr" (val) |
| 149 | : "memory"); |
| 150 | } else if (cpu_has_llsc) { |
| 151 | unsigned long dummy; |
| 152 | |
| 153 | __asm__ __volatile__( |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 154 | " .set mips3 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | "1: lld %0, %3 # xchg_u64 \n" |
| 156 | " move %2, %z4 \n" |
| 157 | " scd %2, %1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 158 | " beqz %2, 2f \n" |
| 159 | " .subsection 2 \n" |
| 160 | "2: b 1b \n" |
| 161 | " .previous \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 162 | " .set mips0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | : "=&r" (retval), "=m" (*m), "=&r" (dummy) |
| 164 | : "R" (*m), "Jr" (val) |
| 165 | : "memory"); |
| 166 | } else { |
| 167 | unsigned long flags; |
| 168 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 169 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | retval = *m; |
| 171 | *m = val; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 172 | raw_local_irq_restore(flags); /* implies memory barrier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame] | 175 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | return retval; |
| 178 | } |
| 179 | #else |
| 180 | extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val); |
| 181 | #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels |
| 182 | #endif |
| 183 | |
| 184 | /* This function doesn't exist, so you'll get a linker error |
| 185 | if something tries to do an invalid xchg(). */ |
| 186 | extern void __xchg_called_with_bad_pointer(void); |
| 187 | |
| 188 | static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) |
| 189 | { |
| 190 | switch (size) { |
Ralf Baechle | 0cea043 | 2006-03-03 09:42:05 +0000 | [diff] [blame] | 191 | case 4: |
| 192 | return __xchg_u32(ptr, x); |
| 193 | case 8: |
| 194 | return __xchg_u64(ptr, x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | __xchg_called_with_bad_pointer(); |
| 197 | return x; |
| 198 | } |
| 199 | |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 200 | #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] | 201 | |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 202 | extern void set_handler(unsigned long offset, void *addr, unsigned long len); |
| 203 | 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] | 204 | |
| 205 | typedef void (*vi_handler_t)(void); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 206 | extern void *set_vi_handler(int n, vi_handler_t addr); |
Ralf Baechle | ef300e4 | 2007-05-06 18:31:18 +0100 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | extern void *set_except_vector(int n, void *addr); |
Ralf Baechle | 91b05e6 | 2006-03-29 18:53:00 +0100 | [diff] [blame] | 209 | extern unsigned long ebase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | extern void per_cpu_trap_init(void); |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* |
Nick Piggin | 4866cde | 2005-06-25 14:57:23 -0700 | [diff] [blame] | 213 | * See include/asm-ia64/system.h; prevents deadlock on SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | * systems. |
| 215 | */ |
Nick Piggin | 4866cde | 2005-06-25 14:57:23 -0700 | [diff] [blame] | 216 | #define __ARCH_WANT_UNLOCKED_CTXSW |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Franck Bui-Huu | 9410910 | 2007-07-19 14:04:21 +0200 | [diff] [blame] | 218 | extern unsigned long arch_align_stack(unsigned long sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | #endif /* _ASM_SYSTEM_H */ |