system.h 5.9 KB

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