system.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #define switch_to(prev, next, last) \
  57. do { \
  58. __mips_mt_fpaff_switch_to(prev); \
  59. if (cpu_has_dsp) \
  60. __save_dsp(prev); \
  61. (last) = resume(prev, next, task_thread_info(next)); \
  62. } while (0)
  63. #define finish_arch_switch(prev) \
  64. do { \
  65. if (cpu_has_dsp) \
  66. __restore_dsp(current); \
  67. if (cpu_has_userlocal) \
  68. write_c0_userlocal(current_thread_info()->tp_value); \
  69. __restore_watch(); \
  70. } while (0)
  71. static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
  72. {
  73. __u32 retval;
  74. if (cpu_has_llsc && R10000_LLSC_WAR) {
  75. unsigned long dummy;
  76. __asm__ __volatile__(
  77. " .set mips3 \n"
  78. "1: ll %0, %3 # xchg_u32 \n"
  79. " .set mips0 \n"
  80. " move %2, %z4 \n"
  81. " .set mips3 \n"
  82. " sc %2, %1 \n"
  83. " beqzl %2, 1b \n"
  84. " .set mips0 \n"
  85. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  86. : "R" (*m), "Jr" (val)
  87. : "memory");
  88. } else if (cpu_has_llsc) {
  89. unsigned long dummy;
  90. __asm__ __volatile__(
  91. " .set mips3 \n"
  92. "1: ll %0, %3 # xchg_u32 \n"
  93. " .set mips0 \n"
  94. " move %2, %z4 \n"
  95. " .set mips3 \n"
  96. " sc %2, %1 \n"
  97. " beqz %2, 2f \n"
  98. " .subsection 2 \n"
  99. "2: b 1b \n"
  100. " .previous \n"
  101. " .set mips0 \n"
  102. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  103. : "R" (*m), "Jr" (val)
  104. : "memory");
  105. } else {
  106. unsigned long flags;
  107. raw_local_irq_save(flags);
  108. retval = *m;
  109. *m = val;
  110. raw_local_irq_restore(flags); /* implies memory barrier */
  111. }
  112. smp_llsc_mb();
  113. return retval;
  114. }
  115. #ifdef CONFIG_64BIT
  116. static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
  117. {
  118. __u64 retval;
  119. if (cpu_has_llsc && R10000_LLSC_WAR) {
  120. unsigned long dummy;
  121. __asm__ __volatile__(
  122. " .set mips3 \n"
  123. "1: lld %0, %3 # xchg_u64 \n"
  124. " move %2, %z4 \n"
  125. " scd %2, %1 \n"
  126. " beqzl %2, 1b \n"
  127. " .set mips0 \n"
  128. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  129. : "R" (*m), "Jr" (val)
  130. : "memory");
  131. } else if (cpu_has_llsc) {
  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. " beqz %2, 2f \n"
  139. " .subsection 2 \n"
  140. "2: b 1b \n"
  141. " .previous \n"
  142. " .set mips0 \n"
  143. : "=&r" (retval), "=m" (*m), "=&r" (dummy)
  144. : "R" (*m), "Jr" (val)
  145. : "memory");
  146. } else {
  147. unsigned long flags;
  148. raw_local_irq_save(flags);
  149. retval = *m;
  150. *m = val;
  151. raw_local_irq_restore(flags); /* implies memory barrier */
  152. }
  153. smp_llsc_mb();
  154. return retval;
  155. }
  156. #else
  157. extern __u64 __xchg_u64_unsupported_on_32bit_kernels(volatile __u64 * m, __u64 val);
  158. #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
  159. #endif
  160. /* This function doesn't exist, so you'll get a linker error
  161. if something tries to do an invalid xchg(). */
  162. extern void __xchg_called_with_bad_pointer(void);
  163. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  164. {
  165. switch (size) {
  166. case 4:
  167. return __xchg_u32(ptr, x);
  168. case 8:
  169. return __xchg_u64(ptr, x);
  170. }
  171. __xchg_called_with_bad_pointer();
  172. return x;
  173. }
  174. #define xchg(ptr, x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
  175. extern void set_handler(unsigned long offset, void *addr, unsigned long len);
  176. extern void set_uncached_handler(unsigned long offset, void *addr, unsigned long len);
  177. typedef void (*vi_handler_t)(void);
  178. extern void *set_vi_handler(int n, vi_handler_t addr);
  179. extern void *set_except_vector(int n, void *addr);
  180. extern unsigned long ebase;
  181. extern void per_cpu_trap_init(void);
  182. /*
  183. * See include/asm-ia64/system.h; prevents deadlock on SMP
  184. * systems.
  185. */
  186. #define __ARCH_WANT_UNLOCKED_CTXSW
  187. extern unsigned long arch_align_stack(unsigned long sp);
  188. #endif /* _ASM_SYSTEM_H */