system.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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/kernel.h>
  15. #include <linux/types.h>
  16. #include <linux/irqflags.h>
  17. #include <asm/addrspace.h>
  18. #include <asm/barrier.h>
  19. #include <asm/cmpxchg.h>
  20. #include <asm/cpu-features.h>
  21. #include <asm/dsp.h>
  22. #include <asm/watch.h>
  23. #include <asm/war.h>
  24. /*
  25. * switch_to(n) should switch tasks to task nr n, first
  26. * checking that n isn't the current task, in which case it does nothing.
  27. */
  28. extern asmlinkage void *resume(void *last, void *next, void *next_ti);
  29. struct task_struct;
  30. extern unsigned int ll_bit;
  31. extern struct task_struct *ll_task;
  32. #ifdef CONFIG_MIPS_MT_FPAFF
  33. /*
  34. * Handle the scheduler resume end of FPU affinity management. We do this
  35. * inline to try to keep the overhead down. If we have been forced to run on
  36. * a "CPU" with an FPU because of a previous high level of FP computation,
  37. * but did not actually use the FPU during the most recent time-slice (CU1
  38. * isn't set), we undo the restriction on cpus_allowed.
  39. *
  40. * We're not calling set_cpus_allowed() here, because we have no need to
  41. * force prompt migration - we're already switching the current CPU to a
  42. * different thread.
  43. */
  44. #define __mips_mt_fpaff_switch_to(prev) \
  45. do { \
  46. struct thread_info *__prev_ti = task_thread_info(prev); \
  47. \
  48. if (cpu_has_fpu && \
  49. test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \
  50. (!(KSTK_STATUS(prev) & ST0_CU1))) { \
  51. clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \
  52. prev->cpus_allowed = prev->thread.user_cpus_allowed; \
  53. } \
  54. next->thread.emulated_fp = 0; \
  55. } while(0)
  56. #else
  57. #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0)
  58. #endif
  59. #define __clear_software_ll_bit() \
  60. do { \
  61. if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc) \
  62. ll_bit = 0; \
  63. } while (0)
  64. #define switch_to(prev, next, last) \
  65. do { \
  66. __mips_mt_fpaff_switch_to(prev); \
  67. if (cpu_has_dsp) \
  68. __save_dsp(prev); \
  69. __clear_software_ll_bit(); \
  70. (last) = resume(prev, next, task_thread_info(next)); \
  71. } while (0)
  72. #define finish_arch_switch(prev) \
  73. do { \
  74. if (cpu_has_dsp) \
  75. __restore_dsp(current); \
  76. if (cpu_has_userlocal) \
  77. write_c0_userlocal(current_thread_info()->tp_value); \
  78. __restore_watch(); \
  79. } while (0)
  80. static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
  81. {
  82. __u32 retval;
  83. if (kernel_uses_llsc && R10000_LLSC_WAR) {
  84. unsigned long dummy;
  85. __asm__ __volatile__(
  86. " .set mips3 \n"
  87. "1: ll %0, %3 # xchg_u32 \n"
  88. " .set mips0 \n"
  89. " move %2, %z4 \n"
  90. " .set mips3 \n"
  91. " sc %2, %1 \n"
  92. " beqzl %2, 1b \n"
  93. " .set mips0 \n"
  94. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  95. : "R" (*m), "Jr" (val)
  96. : "memory");
  97. } else if (kernel_uses_llsc) {
  98. unsigned long dummy;
  99. __asm__ __volatile__(
  100. " .set mips3 \n"
  101. "1: ll %0, %3 # xchg_u32 \n"
  102. " .set mips0 \n"
  103. " move %2, %z4 \n"
  104. " .set mips3 \n"
  105. " sc %2, %1 \n"
  106. " beqz %2, 2f \n"
  107. " .subsection 2 \n"
  108. "2: b 1b \n"
  109. " .previous \n"
  110. " .set mips0 \n"
  111. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  112. : "R" (*m), "Jr" (val)
  113. : "memory");
  114. } else {
  115. unsigned long flags;
  116. raw_local_irq_save(flags);
  117. retval = *m;
  118. *m = val;
  119. raw_local_irq_restore(flags); /* implies memory barrier */
  120. }
  121. smp_llsc_mb();
  122. return retval;
  123. }
  124. #ifdef CONFIG_64BIT
  125. static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
  126. {
  127. __u64 retval;
  128. if (kernel_uses_llsc && R10000_LLSC_WAR) {
  129. unsigned long dummy;
  130. __asm__ __volatile__(
  131. " .set mips3 \n"
  132. "1: lld %0, %3 # xchg_u64 \n"
  133. " move %2, %z4 \n"
  134. " scd %2, %1 \n"
  135. " beqzl %2, 1b \n"
  136. " .set mips0 \n"
  137. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  138. : "R" (*m), "Jr" (val)
  139. : "memory");
  140. } else if (kernel_uses_llsc) {
  141. unsigned long dummy;
  142. __asm__ __volatile__(
  143. " .set mips3 \n"
  144. "1: lld %0, %3 # xchg_u64 \n"
  145. " move %2, %z4 \n"
  146. " scd %2, %1 \n"
  147. " beqz %2, 2f \n"
  148. " .subsection 2 \n"
  149. "2: b 1b \n"
  150. " .previous \n"
  151. " .set mips0 \n"
  152. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  153. : "R" (*m), "Jr" (val)
  154. : "memory");
  155. } else {
  156. unsigned long flags;
  157. raw_local_irq_save(flags);
  158. retval = *m;
  159. *m = val;
  160. raw_local_irq_restore(flags); /* implies memory barrier */
  161. }
  162. smp_llsc_mb();
  163. return retval;
  164. }
  165. #else
  166. extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
  167. #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
  168. #endif
  169. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  170. {
  171. switch (size) {
  172. case 4:
  173. return __xchg_u32(ptr, x);
  174. case 8:
  175. return __xchg_u64(ptr, x);
  176. }
  177. return x;
  178. }
  179. #define xchg(ptr, x) \
  180. ({ \
  181. BUILD_BUG_ON(sizeof(*(ptr)) & ~0xc); \
  182. \
  183. ((__typeof__(*(ptr))) \
  184. __xchg((unsigned long)(x), (ptr), sizeof(*(ptr)))); \
  185. })
  186. extern void set_handler(unsigned long offset, void *addr, unsigned long len);
  187. extern void set_uncached_handler(unsigned long offset, void *addr, unsigned long len);
  188. typedef void (*vi_handler_t)(void);
  189. extern void *set_vi_handler(int n, vi_handler_t addr);
  190. extern void *set_except_vector(int n, void *addr);
  191. extern unsigned long ebase;
  192. extern void per_cpu_trap_init(void);
  193. /*
  194. * See include/asm-ia64/system.h; prevents deadlock on SMP
  195. * systems.
  196. */
  197. #define __ARCH_WANT_UNLOCKED_CTXSW
  198. extern unsigned long arch_align_stack(unsigned long sp);
  199. #endif /* _ASM_SYSTEM_H */