system.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* system.h: FR-V CPU control definitions
  2. *
  3. * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_SYSTEM_H
  12. #define _ASM_SYSTEM_H
  13. #include <linux/types.h>
  14. #include <linux/linkage.h>
  15. #include <linux/kernel.h>
  16. struct thread_struct;
  17. /*
  18. * switch_to(prev, next) should switch from task `prev' to `next'
  19. * `prev' will never be the same as `next'.
  20. * The `mb' is to tell GCC not to cache `current' across this call.
  21. */
  22. extern asmlinkage
  23. struct task_struct *__switch_to(struct thread_struct *prev_thread,
  24. struct thread_struct *next_thread,
  25. struct task_struct *prev);
  26. #define switch_to(prev, next, last) \
  27. do { \
  28. (prev)->thread.sched_lr = \
  29. (unsigned long) __builtin_return_address(0); \
  30. (last) = __switch_to(&(prev)->thread, &(next)->thread, (prev)); \
  31. mb(); \
  32. } while(0)
  33. /*
  34. * interrupt flag manipulation
  35. * - use virtual interrupt management since touching the PSR is slow
  36. * - ICC2.Z: T if interrupts virtually disabled
  37. * - ICC2.C: F if interrupts really disabled
  38. * - if Z==1 upon interrupt:
  39. * - C is set to 0
  40. * - interrupts are really disabled
  41. * - entry.S returns immediately
  42. * - uses TIHI (TRAP if Z==0 && C==0) #2 to really reenable interrupts
  43. * - if taken, the trap:
  44. * - sets ICC2.C
  45. * - enables interrupts
  46. */
  47. #define local_irq_disable() \
  48. do { \
  49. /* set Z flag, but don't change the C flag */ \
  50. asm volatile(" andcc gr0,gr0,gr0,icc2 \n" \
  51. : \
  52. : \
  53. : "memory", "icc2" \
  54. ); \
  55. } while(0)
  56. #define local_irq_enable() \
  57. do { \
  58. /* clear Z flag and then test the C flag */ \
  59. asm volatile(" oricc gr0,#1,gr0,icc2 \n" \
  60. " tihi icc2,gr0,#2 \n" \
  61. : \
  62. : \
  63. : "memory", "icc2" \
  64. ); \
  65. } while(0)
  66. #define local_save_flags(flags) \
  67. do { \
  68. typecheck(unsigned long, flags); \
  69. asm volatile("movsg ccr,%0" \
  70. : "=r"(flags) \
  71. : \
  72. : "memory"); \
  73. \
  74. /* shift ICC2.Z to bit 0 */ \
  75. flags >>= 26; \
  76. \
  77. /* make flags 1 if interrupts disabled, 0 otherwise */ \
  78. flags &= 1UL; \
  79. } while(0)
  80. #define irqs_disabled() \
  81. ({unsigned long flags; local_save_flags(flags); !!flags; })
  82. #define local_irq_save(flags) \
  83. do { \
  84. typecheck(unsigned long, flags); \
  85. local_save_flags(flags); \
  86. local_irq_disable(); \
  87. } while(0)
  88. #define local_irq_restore(flags) \
  89. do { \
  90. typecheck(unsigned long, flags); \
  91. \
  92. /* load the Z flag by turning 1 if disabled into 0 if disabled \
  93. * and thus setting the Z flag but not the C flag */ \
  94. asm volatile(" xoricc %0,#1,gr0,icc2 \n" \
  95. /* then test Z=0 and C=0 */ \
  96. " tihi icc2,gr0,#2 \n" \
  97. : \
  98. : "r"(flags) \
  99. : "memory", "icc2" \
  100. ); \
  101. \
  102. } while(0)
  103. /*
  104. * real interrupt flag manipulation
  105. */
  106. #define __local_irq_disable() \
  107. do { \
  108. unsigned long psr; \
  109. asm volatile(" movsg psr,%0 \n" \
  110. " andi %0,%2,%0 \n" \
  111. " ori %0,%1,%0 \n" \
  112. " movgs %0,psr \n" \
  113. : "=r"(psr) \
  114. : "i" (PSR_PIL_14), "i" (~PSR_PIL) \
  115. : "memory"); \
  116. } while(0)
  117. #define __local_irq_enable() \
  118. do { \
  119. unsigned long psr; \
  120. asm volatile(" movsg psr,%0 \n" \
  121. " andi %0,%1,%0 \n" \
  122. " movgs %0,psr \n" \
  123. : "=r"(psr) \
  124. : "i" (~PSR_PIL) \
  125. : "memory"); \
  126. } while(0)
  127. #define __local_save_flags(flags) \
  128. do { \
  129. typecheck(unsigned long, flags); \
  130. asm("movsg psr,%0" \
  131. : "=r"(flags) \
  132. : \
  133. : "memory"); \
  134. } while(0)
  135. #define __local_irq_save(flags) \
  136. do { \
  137. unsigned long npsr; \
  138. typecheck(unsigned long, flags); \
  139. asm volatile(" movsg psr,%0 \n" \
  140. " andi %0,%3,%1 \n" \
  141. " ori %1,%2,%1 \n" \
  142. " movgs %1,psr \n" \
  143. : "=r"(flags), "=r"(npsr) \
  144. : "i" (PSR_PIL_14), "i" (~PSR_PIL) \
  145. : "memory"); \
  146. } while(0)
  147. #define __local_irq_restore(flags) \
  148. do { \
  149. typecheck(unsigned long, flags); \
  150. asm volatile(" movgs %0,psr \n" \
  151. : \
  152. : "r" (flags) \
  153. : "memory"); \
  154. } while(0)
  155. #define __irqs_disabled() \
  156. ((__get_PSR() & PSR_PIL) >= PSR_PIL_14)
  157. /*
  158. * Force strict CPU ordering.
  159. */
  160. #define nop() asm volatile ("nop"::)
  161. #define mb() asm volatile ("membar" : : :"memory")
  162. #define rmb() asm volatile ("membar" : : :"memory")
  163. #define wmb() asm volatile ("membar" : : :"memory")
  164. #define read_barrier_depends() do { } while (0)
  165. #ifdef CONFIG_SMP
  166. #define smp_mb() mb()
  167. #define smp_rmb() rmb()
  168. #define smp_wmb() wmb()
  169. #define smp_read_barrier_depends() read_barrier_depends()
  170. #define set_mb(var, value) \
  171. do { xchg(&var, (value)); } while (0)
  172. #else
  173. #define smp_mb() barrier()
  174. #define smp_rmb() barrier()
  175. #define smp_wmb() barrier()
  176. #define smp_read_barrier_depends() do {} while(0)
  177. #define set_mb(var, value) \
  178. do { var = (value); barrier(); } while (0)
  179. #endif
  180. extern void die_if_kernel(const char *, ...) __attribute__((format(printf, 1, 2)));
  181. extern void free_initmem(void);
  182. #define arch_align_stack(x) (x)
  183. /*****************************************************************************/
  184. /*
  185. * compare and conditionally exchange value with memory
  186. * - if (*ptr == test) then orig = *ptr; *ptr = test;
  187. * - if (*ptr != test) then orig = *ptr;
  188. */
  189. #ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
  190. #define cmpxchg(ptr, test, new) \
  191. ({ \
  192. __typeof__(ptr) __xg_ptr = (ptr); \
  193. __typeof__(*(ptr)) __xg_orig, __xg_tmp; \
  194. __typeof__(*(ptr)) __xg_test = (test); \
  195. __typeof__(*(ptr)) __xg_new = (new); \
  196. \
  197. switch (sizeof(__xg_orig)) { \
  198. case 4: \
  199. asm volatile( \
  200. "0: \n" \
  201. " orcc gr0,gr0,gr0,icc3 \n" \
  202. " ckeq icc3,cc7 \n" \
  203. " ld.p %M0,%1 \n" \
  204. " orcr cc7,cc7,cc3 \n" \
  205. " sub%I4cc %1,%4,%2,icc0 \n" \
  206. " bne icc0,#0,1f \n" \
  207. " cst.p %3,%M0 ,cc3,#1 \n" \
  208. " corcc gr29,gr29,gr0 ,cc3,#1 \n" \
  209. " beq icc3,#0,0b \n" \
  210. "1: \n" \
  211. : "+U"(*__xg_ptr), "=&r"(__xg_orig), "=&r"(__xg_tmp) \
  212. : "r"(__xg_new), "NPr"(__xg_test) \
  213. : "memory", "cc7", "cc3", "icc3", "icc0" \
  214. ); \
  215. break; \
  216. \
  217. default: \
  218. __xg_orig = (__typeof__(__xg_orig))0; \
  219. asm volatile("break"); \
  220. break; \
  221. } \
  222. \
  223. __xg_orig; \
  224. })
  225. #else
  226. extern uint32_t __cmpxchg_32(uint32_t *v, uint32_t test, uint32_t new);
  227. #define cmpxchg(ptr, test, new) \
  228. ({ \
  229. __typeof__(ptr) __xg_ptr = (ptr); \
  230. __typeof__(*(ptr)) __xg_orig; \
  231. __typeof__(*(ptr)) __xg_test = (test); \
  232. __typeof__(*(ptr)) __xg_new = (new); \
  233. \
  234. switch (sizeof(__xg_orig)) { \
  235. case 4: __xg_orig = (__force __typeof__(*ptr)) \
  236. __cmpxchg_32((__force uint32_t *)__xg_ptr, \
  237. (__force uint32_t)__xg_test, \
  238. (__force uint32_t)__xg_new); break; \
  239. default: \
  240. __xg_orig = (__typeof__(__xg_orig))0; \
  241. asm volatile("break"); \
  242. break; \
  243. } \
  244. \
  245. __xg_orig; \
  246. })
  247. #endif
  248. #include <asm-generic/cmpxchg-local.h>
  249. static inline unsigned long __cmpxchg_local(volatile void *ptr,
  250. unsigned long old,
  251. unsigned long new, int size)
  252. {
  253. switch (size) {
  254. case 4:
  255. return cmpxchg((unsigned long *)ptr, old, new);
  256. default:
  257. return __cmpxchg_local_generic(ptr, old, new, size);
  258. }
  259. return old;
  260. }
  261. /*
  262. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  263. * them available.
  264. */
  265. #define cmpxchg_local(ptr, o, n) \
  266. ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
  267. (unsigned long)(n), sizeof(*(ptr))))
  268. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  269. #endif /* _ASM_SYSTEM_H */