system.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * include/asm-xtensa/system.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2001 - 2005 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_SYSTEM_H
  11. #define _XTENSA_SYSTEM_H
  12. #include <linux/stringify.h>
  13. #include <asm/processor.h>
  14. /* interrupt control */
  15. #define local_save_flags(x) \
  16. __asm__ __volatile__ ("rsr %0,"__stringify(PS) : "=a" (x));
  17. #define local_irq_restore(x) do { \
  18. __asm__ __volatile__ ("wsr %0, "__stringify(PS)" ; rsync" \
  19. :: "a" (x) : "memory"); } while(0);
  20. #define local_irq_save(x) do { \
  21. __asm__ __volatile__ ("rsil %0, "__stringify(LOCKLEVEL) \
  22. : "=a" (x) :: "memory");} while(0);
  23. static inline void local_irq_disable(void)
  24. {
  25. unsigned long flags;
  26. __asm__ __volatile__ ("rsil %0, "__stringify(LOCKLEVEL)
  27. : "=a" (flags) :: "memory");
  28. }
  29. static inline void local_irq_enable(void)
  30. {
  31. unsigned long flags;
  32. __asm__ __volatile__ ("rsil %0, 0" : "=a" (flags) :: "memory");
  33. }
  34. static inline int irqs_disabled(void)
  35. {
  36. unsigned long flags;
  37. local_save_flags(flags);
  38. return flags & 0xf;
  39. }
  40. #define smp_read_barrier_depends() do { } while(0)
  41. #define read_barrier_depends() do { } while(0)
  42. #define mb() barrier()
  43. #define rmb() mb()
  44. #define wmb() mb()
  45. #ifdef CONFIG_SMP
  46. #error smp_* not defined
  47. #else
  48. #define smp_mb() barrier()
  49. #define smp_rmb() barrier()
  50. #define smp_wmb() barrier()
  51. #endif
  52. #define set_mb(var, value) do { var = value; mb(); } while (0)
  53. #if !defined (__ASSEMBLY__)
  54. /* * switch_to(n) should switch tasks to task nr n, first
  55. * checking that n isn't the current task, in which case it does nothing.
  56. */
  57. extern void *_switch_to(void *last, void *next);
  58. #endif /* __ASSEMBLY__ */
  59. #define switch_to(prev,next,last) \
  60. do { \
  61. (last) = _switch_to(prev, next); \
  62. } while(0)
  63. /*
  64. * cmpxchg
  65. */
  66. static inline unsigned long
  67. __cmpxchg_u32(volatile int *p, int old, int new)
  68. {
  69. __asm__ __volatile__("rsil a15, "__stringify(LOCKLEVEL)"\n\t"
  70. "l32i %0, %1, 0 \n\t"
  71. "bne %0, %2, 1f \n\t"
  72. "s32i %3, %1, 0 \n\t"
  73. "1: \n\t"
  74. "wsr a15, "__stringify(PS)" \n\t"
  75. "rsync \n\t"
  76. : "=&a" (old)
  77. : "a" (p), "a" (old), "r" (new)
  78. : "a15", "memory");
  79. return old;
  80. }
  81. /* This function doesn't exist, so you'll get a linker error
  82. * if something tries to do an invalid cmpxchg(). */
  83. extern void __cmpxchg_called_with_bad_pointer(void);
  84. static __inline__ unsigned long
  85. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  86. {
  87. switch (size) {
  88. case 4: return __cmpxchg_u32(ptr, old, new);
  89. default: __cmpxchg_called_with_bad_pointer();
  90. return old;
  91. }
  92. }
  93. #define cmpxchg(ptr,o,n) \
  94. ({ __typeof__(*(ptr)) _o_ = (o); \
  95. __typeof__(*(ptr)) _n_ = (n); \
  96. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  97. (unsigned long)_n_, sizeof (*(ptr))); \
  98. })
  99. #include <asm-generic/cmpxchg-local.h>
  100. static inline unsigned long __cmpxchg_local(volatile void *ptr,
  101. unsigned long old,
  102. unsigned long new, int size)
  103. {
  104. switch (size) {
  105. case 4:
  106. return __cmpxchg_u32(ptr, old, new);
  107. default:
  108. return __cmpxchg_local_generic(ptr, old, new, size);
  109. }
  110. return old;
  111. }
  112. /*
  113. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  114. * them available.
  115. */
  116. #define cmpxchg_local(ptr, o, n) \
  117. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  118. (unsigned long)(n), sizeof(*(ptr))))
  119. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  120. /*
  121. * xchg_u32
  122. *
  123. * Note that a15 is used here because the register allocation
  124. * done by the compiler is not guaranteed and a window overflow
  125. * may not occur between the rsil and wsr instructions. By using
  126. * a15 in the rsil, the machine is guaranteed to be in a state
  127. * where no register reference will cause an overflow.
  128. */
  129. static inline unsigned long xchg_u32(volatile int * m, unsigned long val)
  130. {
  131. unsigned long tmp;
  132. __asm__ __volatile__("rsil a15, "__stringify(LOCKLEVEL)"\n\t"
  133. "l32i %0, %1, 0 \n\t"
  134. "s32i %2, %1, 0 \n\t"
  135. "wsr a15, "__stringify(PS)" \n\t"
  136. "rsync \n\t"
  137. : "=&a" (tmp)
  138. : "a" (m), "a" (val)
  139. : "a15", "memory");
  140. return tmp;
  141. }
  142. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  143. /*
  144. * This only works if the compiler isn't horribly bad at optimizing.
  145. * gcc-2.5.8 reportedly can't handle this, but I define that one to
  146. * be dead anyway.
  147. */
  148. extern void __xchg_called_with_bad_pointer(void);
  149. static __inline__ unsigned long
  150. __xchg(unsigned long x, volatile void * ptr, int size)
  151. {
  152. switch (size) {
  153. case 4:
  154. return xchg_u32(ptr, x);
  155. }
  156. __xchg_called_with_bad_pointer();
  157. return x;
  158. }
  159. extern void set_except_vector(int n, void *addr);
  160. static inline void spill_registers(void)
  161. {
  162. unsigned int a0, ps;
  163. __asm__ __volatile__ (
  164. "movi a14," __stringify (PS_EXCM_BIT) " | 1\n\t"
  165. "mov a12, a0\n\t"
  166. "rsr a13," __stringify(SAR) "\n\t"
  167. "xsr a14," __stringify(PS) "\n\t"
  168. "movi a0, _spill_registers\n\t"
  169. "rsync\n\t"
  170. "callx0 a0\n\t"
  171. "mov a0, a12\n\t"
  172. "wsr a13," __stringify(SAR) "\n\t"
  173. "wsr a14," __stringify(PS) "\n\t"
  174. :: "a" (&a0), "a" (&ps)
  175. : "a2", "a3", "a4", "a7", "a11", "a12", "a13", "a14", "a15", "memory");
  176. }
  177. #define arch_align_stack(x) (x)
  178. #endif /* _XTENSA_SYSTEM_H */