system.h 11 KB

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