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