blob: cd30f83235bb292360233737dd87a4ac343b0830 [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>
Ralf Baechlefef74702007-10-01 04:15:00 +010020#include <asm/cmpxchg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/cpu-features.h>
Ralf Baechlee50c0a82005-05-31 11:49:19 +000022#include <asm/dsp.h>
David Daney2c708cb2008-09-23 00:09:51 -070023#include <asm/watch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/war.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/*
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.
30 */
31extern asmlinkage void *resume(void *last, void *next, void *next_ti);
32
33struct task_struct;
34
Ralf Baechlef088fc82006-04-05 09:45:47 +010035#ifdef CONFIG_MIPS_MT_FPAFF
36
37/*
38 * Handle the scheduler resume end of FPU affinity management. We do this
39 * inline to try to keep the overhead down. If we have been forced to run on
40 * a "CPU" with an FPU because of a previous high level of FP computation,
41 * but did not actually use the FPU during the most recent time-slice (CU1
42 * isn't set), we undo the restriction on cpus_allowed.
43 *
44 * We're not calling set_cpus_allowed() here, because we have no need to
45 * force prompt migration - we're already switching the current CPU to a
46 * different thread.
47 */
48
Ralf Baechled223a862007-07-10 17:33:02 +010049#define __mips_mt_fpaff_switch_to(prev) \
Ralf Baechlef088fc82006-04-05 09:45:47 +010050do { \
Ralf Baechle293c5bd2007-07-25 16:19:33 +010051 struct thread_info *__prev_ti = task_thread_info(prev); \
52 \
Ralf Baechlef088fc82006-04-05 09:45:47 +010053 if (cpu_has_fpu && \
Ralf Baechle293c5bd2007-07-25 16:19:33 +010054 test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \
55 (!(KSTK_STATUS(prev) & ST0_CU1))) { \
56 clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \
Ralf Baechlef088fc82006-04-05 09:45:47 +010057 prev->cpus_allowed = prev->thread.user_cpus_allowed; \
58 } \
Ralf Baechlef088fc82006-04-05 09:45:47 +010059 next->thread.emulated_fp = 0; \
Ralf Baechlef088fc82006-04-05 09:45:47 +010060} while(0)
61
62#else
Ralf Baechle35c700c2007-07-10 08:59:17 +010063#define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0)
Ralf Baechled223a862007-07-10 17:33:02 +010064#endif
65
Ralf Baechle21a151d2007-10-11 23:46:15 +010066#define switch_to(prev, next, last) \
Ralf Baechlee50c0a82005-05-31 11:49:19 +000067do { \
Ralf Baechled223a862007-07-10 17:33:02 +010068 __mips_mt_fpaff_switch_to(prev); \
Ralf Baechlee50c0a82005-05-31 11:49:19 +000069 if (cpu_has_dsp) \
70 __save_dsp(prev); \
Al Viro40bc9c62006-01-12 01:06:07 -080071 (last) = resume(prev, next, task_thread_info(next)); \
Ralf Baechle07500b02007-10-30 17:25:26 +000072} while (0)
73
74#define finish_arch_switch(prev) \
75do { \
Ralf Baechlee50c0a82005-05-31 11:49:19 +000076 if (cpu_has_dsp) \
77 __restore_dsp(current); \
Ralf Baechlea3692022007-07-10 17:33:02 +010078 if (cpu_has_userlocal) \
Ralf Baechle07500b02007-10-30 17:25:26 +000079 write_c0_userlocal(current_thread_info()->tp_value); \
David Daney2c708cb2008-09-23 00:09:51 -070080 __restore_watch(); \
Ralf Baechle07500b02007-10-30 17:25:26 +000081} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
84{
85 __u32 retval;
86
87 if (cpu_has_llsc && R10000_LLSC_WAR) {
88 unsigned long dummy;
89
90 __asm__ __volatile__(
Maciej W. Rozyckic4559f62005-06-23 15:57:15 +000091 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 "1: ll %0, %3 # xchg_u32 \n"
Ralf Baechle72224242005-06-29 13:35:19 +000093 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 " move %2, %z4 \n"
Ralf Baechle72224242005-06-29 13:35:19 +000095 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 " sc %2, %1 \n"
97 " beqzl %2, 1b \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +000098 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
100 : "R" (*m), "Jr" (val)
101 : "memory");
102 } else if (cpu_has_llsc) {
103 unsigned long dummy;
104
105 __asm__ __volatile__(
Maciej W. Rozyckic4559f62005-06-23 15:57:15 +0000106 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 "1: ll %0, %3 # xchg_u32 \n"
Ralf Baechle72224242005-06-29 13:35:19 +0000108 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 " move %2, %z4 \n"
Ralf Baechle72224242005-06-29 13:35:19 +0000110 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 " sc %2, %1 \n"
Ralf Baechlef65e4fa2006-09-28 01:45:21 +0100112 " beqz %2, 2f \n"
113 " .subsection 2 \n"
114 "2: b 1b \n"
115 " .previous \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000116 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
118 : "R" (*m), "Jr" (val)
119 : "memory");
120 } else {
121 unsigned long flags;
122
Ralf Baechle49edd092007-03-16 16:10:36 +0000123 raw_local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 retval = *m;
125 *m = val;
Ralf Baechle49edd092007-03-16 16:10:36 +0000126 raw_local_irq_restore(flags); /* implies memory barrier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
Ralf Baechle17099b12007-07-14 13:24:05 +0100129 smp_llsc_mb();
Ralf Baechle0004a9d2006-10-31 03:45:07 +0000130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return retval;
132}
133
Ralf Baechle875d43e2005-09-03 15:56:16 -0700134#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
136{
137 __u64 retval;
138
139 if (cpu_has_llsc && R10000_LLSC_WAR) {
140 unsigned long dummy;
141
142 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000143 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 "1: lld %0, %3 # xchg_u64 \n"
145 " move %2, %z4 \n"
146 " scd %2, %1 \n"
147 " beqzl %2, 1b \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000148 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
150 : "R" (*m), "Jr" (val)
151 : "memory");
152 } else if (cpu_has_llsc) {
153 unsigned long dummy;
154
155 __asm__ __volatile__(
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000156 " .set mips3 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 "1: lld %0, %3 # xchg_u64 \n"
158 " move %2, %z4 \n"
159 " scd %2, %1 \n"
Ralf Baechlef65e4fa2006-09-28 01:45:21 +0100160 " beqz %2, 2f \n"
161 " .subsection 2 \n"
162 "2: b 1b \n"
163 " .previous \n"
Maciej W. Rozyckiaac8aa72005-06-14 17:35:03 +0000164 " .set mips0 \n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 : "=&r" (retval), "=m" (*m), "=&r" (dummy)
166 : "R" (*m), "Jr" (val)
167 : "memory");
168 } else {
169 unsigned long flags;
170
Ralf Baechle49edd092007-03-16 16:10:36 +0000171 raw_local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 retval = *m;
173 *m = val;
Ralf Baechle49edd092007-03-16 16:10:36 +0000174 raw_local_irq_restore(flags); /* implies memory barrier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
176
Ralf Baechle17099b12007-07-14 13:24:05 +0100177 smp_llsc_mb();
Ralf Baechle0004a9d2006-10-31 03:45:07 +0000178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return retval;
180}
181#else
182extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
183#define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
184#endif
185
186/* This function doesn't exist, so you'll get a linker error
187 if something tries to do an invalid xchg(). */
188extern void __xchg_called_with_bad_pointer(void);
189
190static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
191{
192 switch (size) {
Ralf Baechle0cea0432006-03-03 09:42:05 +0000193 case 4:
194 return __xchg_u32(ptr, x);
195 case 8:
196 return __xchg_u64(ptr, x);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198 __xchg_called_with_bad_pointer();
199 return x;
200}
201
Ralf Baechle21a151d2007-10-11 23:46:15 +0100202#define xchg(ptr, x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100204extern void set_handler(unsigned long offset, void *addr, unsigned long len);
205extern void set_uncached_handler(unsigned long offset, void *addr, unsigned long len);
Ralf Baechleef300e42007-05-06 18:31:18 +0100206
207typedef void (*vi_handler_t)(void);
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100208extern void *set_vi_handler(int n, vi_handler_t addr);
Ralf Baechleef300e42007-05-06 18:31:18 +0100209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210extern void *set_except_vector(int n, void *addr);
Ralf Baechle91b05e62006-03-29 18:53:00 +0100211extern unsigned long ebase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212extern void per_cpu_trap_init(void);
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214/*
Nick Piggin4866cde2005-06-25 14:57:23 -0700215 * See include/asm-ia64/system.h; prevents deadlock on SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 * systems.
217 */
Nick Piggin4866cde2005-06-25 14:57:23 -0700218#define __ARCH_WANT_UNLOCKED_CTXSW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Franck Bui-Huu94109102007-07-19 14:04:21 +0200220extern unsigned long arch_align_stack(unsigned long sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222#endif /* _ASM_SYSTEM_H */