system.h 12 KB

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