system.h 5.6 KB

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