system.h 6.0 KB

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