system.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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 this where 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. static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
  148. {
  149. __u32 retval;
  150. if (cpu_has_llsc && R10000_LLSC_WAR) {
  151. unsigned long dummy;
  152. __asm__ __volatile__(
  153. " .set mips3 \n"
  154. "1: ll %0, %3 # xchg_u32 \n"
  155. " .set mips0 \n"
  156. " move %2, %z4 \n"
  157. " .set mips3 \n"
  158. " sc %2, %1 \n"
  159. " beqzl %2, 1b \n"
  160. #ifdef CONFIG_SMP
  161. " sync \n"
  162. #endif
  163. " .set mips0 \n"
  164. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  165. : "R" (*m), "Jr" (val)
  166. : "memory");
  167. } else if (cpu_has_llsc) {
  168. unsigned long dummy;
  169. __asm__ __volatile__(
  170. " .set mips3 \n"
  171. "1: ll %0, %3 # xchg_u32 \n"
  172. " .set mips0 \n"
  173. " move %2, %z4 \n"
  174. " .set mips3 \n"
  175. " sc %2, %1 \n"
  176. " beqz %2, 1b \n"
  177. #ifdef CONFIG_SMP
  178. " sync \n"
  179. #endif
  180. " .set mips0 \n"
  181. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  182. : "R" (*m), "Jr" (val)
  183. : "memory");
  184. } else {
  185. unsigned long flags;
  186. local_irq_save(flags);
  187. retval = *m;
  188. *m = val;
  189. local_irq_restore(flags); /* implies memory barrier */
  190. }
  191. return retval;
  192. }
  193. #ifdef CONFIG_64BIT
  194. static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
  195. {
  196. __u64 retval;
  197. if (cpu_has_llsc && R10000_LLSC_WAR) {
  198. unsigned long dummy;
  199. __asm__ __volatile__(
  200. " .set mips3 \n"
  201. "1: lld %0, %3 # xchg_u64 \n"
  202. " move %2, %z4 \n"
  203. " scd %2, %1 \n"
  204. " beqzl %2, 1b \n"
  205. #ifdef CONFIG_SMP
  206. " sync \n"
  207. #endif
  208. " .set mips0 \n"
  209. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  210. : "R" (*m), "Jr" (val)
  211. : "memory");
  212. } else if (cpu_has_llsc) {
  213. unsigned long dummy;
  214. __asm__ __volatile__(
  215. " .set mips3 \n"
  216. "1: lld %0, %3 # xchg_u64 \n"
  217. " move %2, %z4 \n"
  218. " scd %2, %1 \n"
  219. " beqz %2, 1b \n"
  220. #ifdef CONFIG_SMP
  221. " sync \n"
  222. #endif
  223. " .set mips0 \n"
  224. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  225. : "R" (*m), "Jr" (val)
  226. : "memory");
  227. } else {
  228. unsigned long flags;
  229. local_irq_save(flags);
  230. retval = *m;
  231. *m = val;
  232. local_irq_restore(flags); /* implies memory barrier */
  233. }
  234. return retval;
  235. }
  236. #else
  237. extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
  238. #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
  239. #endif
  240. /* This function doesn't exist, so you'll get a linker error
  241. if something tries to do an invalid xchg(). */
  242. extern void __xchg_called_with_bad_pointer(void);
  243. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  244. {
  245. switch (size) {
  246. case 4:
  247. return __xchg_u32(ptr, x);
  248. case 8:
  249. return __xchg_u64(ptr, x);
  250. }
  251. __xchg_called_with_bad_pointer();
  252. return x;
  253. }
  254. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  255. #define tas(ptr) (xchg((ptr),1))
  256. #define __HAVE_ARCH_CMPXCHG 1
  257. static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
  258. unsigned long new)
  259. {
  260. __u32 retval;
  261. if (cpu_has_llsc && R10000_LLSC_WAR) {
  262. __asm__ __volatile__(
  263. " .set push \n"
  264. " .set noat \n"
  265. " .set mips3 \n"
  266. "1: ll %0, %2 # __cmpxchg_u32 \n"
  267. " bne %0, %z3, 2f \n"
  268. " .set mips0 \n"
  269. " move $1, %z4 \n"
  270. " .set mips3 \n"
  271. " sc $1, %1 \n"
  272. " beqzl $1, 1b \n"
  273. #ifdef CONFIG_SMP
  274. " sync \n"
  275. #endif
  276. "2: \n"
  277. " .set pop \n"
  278. : "=&r" (retval), "=m" (*m)
  279. : "R" (*m), "Jr" (old), "Jr" (new)
  280. : "memory");
  281. } else if (cpu_has_llsc) {
  282. __asm__ __volatile__(
  283. " .set push \n"
  284. " .set noat \n"
  285. " .set mips3 \n"
  286. "1: ll %0, %2 # __cmpxchg_u32 \n"
  287. " bne %0, %z3, 2f \n"
  288. " .set mips0 \n"
  289. " move $1, %z4 \n"
  290. " .set mips3 \n"
  291. " sc $1, %1 \n"
  292. " beqz $1, 1b \n"
  293. #ifdef CONFIG_SMP
  294. " sync \n"
  295. #endif
  296. "2: \n"
  297. " .set pop \n"
  298. : "=&r" (retval), "=m" (*m)
  299. : "R" (*m), "Jr" (old), "Jr" (new)
  300. : "memory");
  301. } else {
  302. unsigned long flags;
  303. local_irq_save(flags);
  304. retval = *m;
  305. if (retval == old)
  306. *m = new;
  307. local_irq_restore(flags); /* implies memory barrier */
  308. }
  309. return retval;
  310. }
  311. #ifdef CONFIG_64BIT
  312. static inline unsigned long __cmpxchg_u64(volatile int * m, unsigned long old,
  313. unsigned long new)
  314. {
  315. __u64 retval;
  316. if (cpu_has_llsc) {
  317. __asm__ __volatile__(
  318. " .set push \n"
  319. " .set noat \n"
  320. " .set mips3 \n"
  321. "1: lld %0, %2 # __cmpxchg_u64 \n"
  322. " bne %0, %z3, 2f \n"
  323. " move $1, %z4 \n"
  324. " scd $1, %1 \n"
  325. " beqzl $1, 1b \n"
  326. #ifdef CONFIG_SMP
  327. " sync \n"
  328. #endif
  329. "2: \n"
  330. " .set pop \n"
  331. : "=&r" (retval), "=m" (*m)
  332. : "R" (*m), "Jr" (old), "Jr" (new)
  333. : "memory");
  334. } else if (cpu_has_llsc) {
  335. __asm__ __volatile__(
  336. " .set push \n"
  337. " .set noat \n"
  338. " .set mips3 \n"
  339. "1: lld %0, %2 # __cmpxchg_u64 \n"
  340. " bne %0, %z3, 2f \n"
  341. " move $1, %z4 \n"
  342. " scd $1, %1 \n"
  343. " beqz $1, 1b \n"
  344. #ifdef CONFIG_SMP
  345. " sync \n"
  346. #endif
  347. "2: \n"
  348. " .set pop \n"
  349. : "=&r" (retval), "=m" (*m)
  350. : "R" (*m), "Jr" (old), "Jr" (new)
  351. : "memory");
  352. } else {
  353. unsigned long flags;
  354. local_irq_save(flags);
  355. retval = *m;
  356. if (retval == old)
  357. *m = new;
  358. local_irq_restore(flags); /* implies memory barrier */
  359. }
  360. return retval;
  361. }
  362. #else
  363. extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
  364. volatile int * m, unsigned long old, unsigned long new);
  365. #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
  366. #endif
  367. /* This function doesn't exist, so you'll get a linker error
  368. if something tries to do an invalid cmpxchg(). */
  369. extern void __cmpxchg_called_with_bad_pointer(void);
  370. static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
  371. unsigned long new, int size)
  372. {
  373. switch (size) {
  374. case 4:
  375. return __cmpxchg_u32(ptr, old, new);
  376. case 8:
  377. return __cmpxchg_u64(ptr, old, new);
  378. }
  379. __cmpxchg_called_with_bad_pointer();
  380. return old;
  381. }
  382. #define cmpxchg(ptr,old,new) ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), (unsigned long)(new),sizeof(*(ptr))))
  383. extern void set_handler (unsigned long offset, void *addr, unsigned long len);
  384. extern void set_uncached_handler (unsigned long offset, void *addr, unsigned long len);
  385. extern void *set_vi_handler (int n, void *addr);
  386. extern void *set_vi_srs_handler (int n, void *addr, int regset);
  387. extern void *set_except_vector(int n, void *addr);
  388. extern void per_cpu_trap_init(void);
  389. extern NORET_TYPE void __die(const char *, struct pt_regs *, const char *file,
  390. const char *func, unsigned long line) ATTRIB_NORET;
  391. extern void __die_if_kernel(const char *, struct pt_regs *, const char *file,
  392. const char *func, unsigned long line);
  393. #define die(msg, regs) \
  394. __die(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
  395. #define die_if_kernel(msg, regs) \
  396. __die_if_kernel(msg, regs, __FILE__ ":", __FUNCTION__, __LINE__)
  397. extern int stop_a_enabled;
  398. /*
  399. * See include/asm-ia64/system.h; prevents deadlock on SMP
  400. * systems.
  401. */
  402. #define __ARCH_WANT_UNLOCKED_CTXSW
  403. #define arch_align_stack(x) (x)
  404. #endif /* _ASM_SYSTEM_H */