system.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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 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/config.h>
  15. #include <linux/types.h>
  16. #include <asm/addrspace.h>
  17. #include <asm/cpu-features.h>
  18. #include <asm/dsp.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/war.h>
  21. #include <asm/interrupt.h>
  22. /*
  23. * read_barrier_depends - Flush all pending reads that subsequents reads
  24. * depend on.
  25. *
  26. * No data-dependent reads from memory-like regions are ever reordered
  27. * over this barrier. All reads preceding this primitive are guaranteed
  28. * to access memory (but not necessarily other CPUs' caches) before any
  29. * reads following this primitive that depend on the data return by
  30. * any of the preceding reads. This primitive is much lighter weight than
  31. * rmb() on most CPUs, and is never heavier weight than is
  32. * rmb().
  33. *
  34. * These ordering constraints are respected by both the local CPU
  35. * and the compiler.
  36. *
  37. * Ordering is not guaranteed by anything other than these primitives,
  38. * not even by data dependencies. See the documentation for
  39. * memory_barrier() for examples and URLs to more information.
  40. *
  41. * For example, the following code would force ordering (the initial
  42. * value of "a" is zero, "b" is one, and "p" is "&a"):
  43. *
  44. * <programlisting>
  45. * CPU 0 CPU 1
  46. *
  47. * b = 2;
  48. * memory_barrier();
  49. * p = &b; q = p;
  50. * read_barrier_depends();
  51. * d = *q;
  52. * </programlisting>
  53. *
  54. * because the read of "*q" depends on the read of "p" and these
  55. * two reads are separated by a read_barrier_depends(). However,
  56. * the following code, with the same initial values for "a" and "b":
  57. *
  58. * <programlisting>
  59. * CPU 0 CPU 1
  60. *
  61. * a = 2;
  62. * memory_barrier();
  63. * b = 3; y = b;
  64. * read_barrier_depends();
  65. * x = a;
  66. * </programlisting>
  67. *
  68. * does not enforce ordering, since there is no data dependency between
  69. * the read of "a" and the read of "b". Therefore, on some CPUs, such
  70. * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
  71. * in cases like thiswhere there are no data dependencies.
  72. */
  73. #define read_barrier_depends() do { } while(0)
  74. #ifdef CONFIG_CPU_HAS_SYNC
  75. #define __sync() \
  76. __asm__ __volatile__( \
  77. ".set push\n\t" \
  78. ".set noreorder\n\t" \
  79. ".set mips2\n\t" \
  80. "sync\n\t" \
  81. ".set pop" \
  82. : /* no output */ \
  83. : /* no input */ \
  84. : "memory")
  85. #else
  86. #define __sync() do { } while(0)
  87. #endif
  88. #define __fast_iob() \
  89. __asm__ __volatile__( \
  90. ".set push\n\t" \
  91. ".set noreorder\n\t" \
  92. "lw $0,%0\n\t" \
  93. "nop\n\t" \
  94. ".set pop" \
  95. : /* no output */ \
  96. : "m" (*(int *)CKSEG1) \
  97. : "memory")
  98. #define fast_wmb() __sync()
  99. #define fast_rmb() __sync()
  100. #define fast_mb() __sync()
  101. #define fast_iob() \
  102. do { \
  103. __sync(); \
  104. __fast_iob(); \
  105. } while (0)
  106. #ifdef CONFIG_CPU_HAS_WB
  107. #include <asm/wbflush.h>
  108. #define wmb() fast_wmb()
  109. #define rmb() fast_rmb()
  110. #define mb() wbflush()
  111. #define iob() wbflush()
  112. #else /* !CONFIG_CPU_HAS_WB */
  113. #define wmb() fast_wmb()
  114. #define rmb() fast_rmb()
  115. #define mb() fast_mb()
  116. #define iob() fast_iob()
  117. #endif /* !CONFIG_CPU_HAS_WB */
  118. #ifdef CONFIG_SMP
  119. #define smp_mb() mb()
  120. #define smp_rmb() rmb()
  121. #define smp_wmb() wmb()
  122. #define smp_read_barrier_depends() read_barrier_depends()
  123. #else
  124. #define smp_mb() barrier()
  125. #define smp_rmb() barrier()
  126. #define smp_wmb() barrier()
  127. #define smp_read_barrier_depends() do { } while(0)
  128. #endif
  129. #define set_mb(var, value) \
  130. do { var = value; mb(); } while (0)
  131. #define set_wmb(var, value) \
  132. do { var = value; wmb(); } while (0)
  133. /*
  134. * switch_to(n) should switch tasks to task nr n, first
  135. * checking that n isn't the current task, in which case it does nothing.
  136. */
  137. extern asmlinkage void *resume(void *last, void *next, void *next_ti);
  138. struct task_struct;
  139. #define switch_to(prev,next,last) \
  140. do { \
  141. if (cpu_has_dsp) \
  142. __save_dsp(prev); \
  143. (last) = resume(prev, next, next->thread_info); \
  144. if (cpu_has_dsp) \
  145. __restore_dsp(current); \
  146. } while(0)
  147. #define ROT_IN_PIECES \
  148. " .set noreorder \n" \
  149. " .set reorder \n"
  150. static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
  151. {
  152. __u32 retval;
  153. if (cpu_has_llsc && R10000_LLSC_WAR) {
  154. unsigned long dummy;
  155. __asm__ __volatile__(
  156. " .set mips3 \n"
  157. "1: ll %0, %3 # xchg_u32 \n"
  158. " .set mips0 \n"
  159. " move %2, %z4 \n"
  160. " .set mips3 \n"
  161. " sc %2, %1 \n"
  162. " beqzl %2, 1b \n"
  163. ROT_IN_PIECES
  164. #ifdef CONFIG_SMP
  165. " sync \n"
  166. #endif
  167. " .set mips0 \n"
  168. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  169. : "R" (*m), "Jr" (val)
  170. : "memory");
  171. } else if (cpu_has_llsc) {
  172. unsigned long dummy;
  173. __asm__ __volatile__(
  174. " .set mips3 \n"
  175. "1: ll %0, %3 # xchg_u32 \n"
  176. " .set mips0 \n"
  177. " move %2, %z4 \n"
  178. " .set mips3 \n"
  179. " sc %2, %1 \n"
  180. " beqz %2, 1b \n"
  181. #ifdef CONFIG_SMP
  182. " sync \n"
  183. #endif
  184. " .set mips0 \n"
  185. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  186. : "R" (*m), "Jr" (val)
  187. : "memory");
  188. } else {
  189. unsigned long flags;
  190. local_irq_save(flags);
  191. retval = *m;
  192. *m = val;
  193. local_irq_restore(flags); /* implies memory barrier */
  194. }
  195. return retval;
  196. }
  197. #ifdef CONFIG_64BIT
  198. static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
  199. {
  200. __u64 retval;
  201. if (cpu_has_llsc && R10000_LLSC_WAR) {
  202. unsigned long dummy;
  203. __asm__ __volatile__(
  204. " .set mips3 \n"
  205. "1: lld %0, %3 # xchg_u64 \n"
  206. " move %2, %z4 \n"
  207. " scd %2, %1 \n"
  208. " beqzl %2, 1b \n"
  209. ROT_IN_PIECES
  210. #ifdef CONFIG_SMP
  211. " sync \n"
  212. #endif
  213. " .set mips0 \n"
  214. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  215. : "R" (*m), "Jr" (val)
  216. : "memory");
  217. } else if (cpu_has_llsc) {
  218. unsigned long dummy;
  219. __asm__ __volatile__(
  220. " .set mips3 \n"
  221. "1: lld %0, %3 # xchg_u64 \n"
  222. " move %2, %z4 \n"
  223. " scd %2, %1 \n"
  224. " beqz %2, 1b \n"
  225. #ifdef CONFIG_SMP
  226. " sync \n"
  227. #endif
  228. " .set mips0 \n"
  229. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  230. : "R" (*m), "Jr" (val)
  231. : "memory");
  232. } else {
  233. unsigned long flags;
  234. local_irq_save(flags);
  235. retval = *m;
  236. *m = val;
  237. local_irq_restore(flags); /* implies memory barrier */
  238. }
  239. return retval;
  240. }
  241. #else
  242. extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
  243. #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
  244. #endif
  245. /* This function doesn't exist, so you'll get a linker error
  246. if something tries to do an invalid xchg(). */
  247. extern void __xchg_called_with_bad_pointer(void);
  248. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  249. {
  250. switch (size) {
  251. case 4:
  252. return __xchg_u32(ptr, x);
  253. case 8:
  254. return __xchg_u64(ptr, x);
  255. }
  256. __xchg_called_with_bad_pointer();
  257. return x;
  258. }
  259. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  260. #define tas(ptr) (xchg((ptr),1))
  261. #define __HAVE_ARCH_CMPXCHG 1
  262. static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
  263. unsigned long new)
  264. {
  265. __u32 retval;
  266. if (cpu_has_llsc && R10000_LLSC_WAR) {
  267. __asm__ __volatile__(
  268. " .set push \n"
  269. " .set noat \n"
  270. " .set mips3 \n"
  271. "1: ll %0, %2 # __cmpxchg_u32 \n"
  272. " bne %0, %z3, 2f \n"
  273. " move $1, %z4 \n"
  274. " sc $1, %1 \n"
  275. " beqzl $1, 1b \n"
  276. ROT_IN_PIECES
  277. #ifdef CONFIG_SMP
  278. " sync \n"
  279. #endif
  280. "2: \n"
  281. " .set pop \n"
  282. : "=&r" (retval), "=m" (*m)
  283. : "R" (*m), "Jr" (old), "Jr" (new)
  284. : "memory");
  285. } else if (cpu_has_llsc) {
  286. __asm__ __volatile__(
  287. " .set push \n"
  288. " .set noat \n"
  289. " .set mips3 \n"
  290. "1: ll %0, %2 # __cmpxchg_u32 \n"
  291. " bne %0, %z3, 2f \n"
  292. " move $1, %z4 \n"
  293. " sc $1, %1 \n"
  294. " beqz $1, 1b \n"
  295. #ifdef CONFIG_SMP
  296. " sync \n"
  297. #endif
  298. "2: \n"
  299. " .set pop \n"
  300. : "=&r" (retval), "=m" (*m)
  301. : "R" (*m), "Jr" (old), "Jr" (new)
  302. : "memory");
  303. } else {
  304. unsigned long flags;
  305. local_irq_save(flags);
  306. retval = *m;
  307. if (retval == old)
  308. *m = new;
  309. local_irq_restore(flags); /* implies memory barrier */
  310. }
  311. return retval;
  312. }
  313. #ifdef CONFIG_64BIT
  314. static inline unsigned long __cmpxchg_u64(volatile int * m, unsigned long old,
  315. unsigned long new)
  316. {
  317. __u64 retval;
  318. if (cpu_has_llsc) {
  319. __asm__ __volatile__(
  320. " .set push \n"
  321. " .set noat \n"
  322. " .set mips3 \n"
  323. "1: lld %0, %2 # __cmpxchg_u64 \n"
  324. " bne %0, %z3, 2f \n"
  325. " move $1, %z4 \n"
  326. " scd $1, %1 \n"
  327. " beqzl $1, 1b \n"
  328. ROT_IN_PIECES
  329. #ifdef CONFIG_SMP
  330. " sync \n"
  331. #endif
  332. "2: \n"
  333. " .set pop \n"
  334. : "=&r" (retval), "=m" (*m)
  335. : "R" (*m), "Jr" (old), "Jr" (new)
  336. : "memory");
  337. } else if (cpu_has_llsc) {
  338. __asm__ __volatile__(
  339. " .set push \n"
  340. " .set noat \n"
  341. " .set mips3 \n"
  342. "1: lld %0, %2 # __cmpxchg_u64 \n"
  343. " bne %0, %z3, 2f \n"
  344. " move $1, %z4 \n"
  345. " scd $1, %1 \n"
  346. " beqz $1, 1b \n"
  347. #ifdef CONFIG_SMP
  348. " sync \n"
  349. #endif
  350. "2: \n"
  351. " .set pop \n"
  352. : "=&r" (retval), "=m" (*m)
  353. : "R" (*m), "Jr" (old), "Jr" (new)
  354. : "memory");
  355. } else {
  356. unsigned long flags;
  357. local_irq_save(flags);
  358. retval = *m;
  359. if (retval == old)
  360. *m = new;
  361. local_irq_restore(flags); /* implies memory barrier */
  362. }
  363. return retval;
  364. }
  365. #else
  366. extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
  367. volatile int * m, unsigned long old, unsigned long new);
  368. #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
  369. #endif
  370. /* This function doesn't exist, so you'll get a linker error
  371. if something tries to do an invalid cmpxchg(). */
  372. extern void __cmpxchg_called_with_bad_pointer(void);
  373. static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
  374. unsigned long new, int size)
  375. {
  376. switch (size) {
  377. case 4:
  378. return __cmpxchg_u32(ptr, old, new);
  379. case 8:
  380. return __cmpxchg_u64(ptr, old, new);
  381. }
  382. __cmpxchg_called_with_bad_pointer();
  383. return old;
  384. }
  385. #define cmpxchg(ptr,old,new) ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
  386. extern void set_handler (unsigned long offset, void *addr, unsigned long len);
  387. extern void set_uncached_handler (unsigned long offset, void *addr, unsigned long len);
  388. extern void *set_vi_handler (int n, void *addr);
  389. extern void *set_vi_srs_handler (int n, void *addr, int regset);
  390. extern void *set_except_vector(int n, void *addr);
  391. extern void per_cpu_trap_init(void);
  392. extern NORET_TYPE void __die(const char *, struct pt_regs *, const char *file,
  393. const char *func, unsigned long line) ATTRIB_NORET;
  394. extern void __die_if_kernel(const char *, struct pt_regs *, const char *file,
  395. const char *func, unsigned long line);
  396. #define die(msg, regs) \
  397. __die(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
  398. #define die_if_kernel(msg, regs) \
  399. __die_if_kernel(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
  400. extern int stop_a_enabled;
  401. /*
  402. * See include/asm-ia64/system.h; prevents deadlock on SMP
  403. * systems.
  404. */
  405. #define __ARCH_WANT_UNLOCKED_CTXSW
  406. #define arch_align_stack(x) (x)
  407. #endif /* _ASM_SYSTEM_H */