system.h 4.8 KB

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