system.h 12 KB

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