system.h 5.9 KB

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