system.h 5.6 KB

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