system.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* MN10300 System definitions
  2. *
  3. * Copyright (C) 2007 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 Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_SYSTEM_H
  12. #define _ASM_SYSTEM_H
  13. #include <asm/cpu-regs.h>
  14. #ifdef __KERNEL__
  15. #ifndef __ASSEMBLY__
  16. #include <linux/kernel.h>
  17. struct task_struct;
  18. struct thread_struct;
  19. extern asmlinkage
  20. struct task_struct *__switch_to(struct thread_struct *prev,
  21. struct thread_struct *next,
  22. struct task_struct *prev_task);
  23. /* context switching is now performed out-of-line in switch_to.S */
  24. #define switch_to(prev, next, last) \
  25. do { \
  26. current->thread.wchan = (u_long) __builtin_return_address(0); \
  27. (last) = __switch_to(&(prev)->thread, &(next)->thread, (prev)); \
  28. mb(); \
  29. current->thread.wchan = 0; \
  30. } while (0)
  31. #define arch_align_stack(x) (x)
  32. #define nop() asm volatile ("nop")
  33. #endif /* !__ASSEMBLY__ */
  34. /*
  35. * Force strict CPU ordering.
  36. * And yes, this is required on UP too when we're talking
  37. * to devices.
  38. *
  39. * For now, "wmb()" doesn't actually do anything, as all
  40. * Intel CPU's follow what Intel calls a *Processor Order*,
  41. * in which all writes are seen in the program order even
  42. * outside the CPU.
  43. *
  44. * I expect future Intel CPU's to have a weaker ordering,
  45. * but I'd also expect them to finally get their act together
  46. * and add some real memory barriers if so.
  47. *
  48. * Some non intel clones support out of order store. wmb() ceases to be a
  49. * nop for these.
  50. */
  51. #define mb() asm volatile ("": : :"memory")
  52. #define rmb() mb()
  53. #define wmb() asm volatile ("": : :"memory")
  54. #ifdef CONFIG_SMP
  55. #define smp_mb() mb()
  56. #define smp_rmb() rmb()
  57. #define smp_wmb() wmb()
  58. #else
  59. #define smp_mb() barrier()
  60. #define smp_rmb() barrier()
  61. #define smp_wmb() barrier()
  62. #endif
  63. #define set_mb(var, value) do { var = value; mb(); } while (0)
  64. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  65. #define read_barrier_depends() do {} while (0)
  66. #define smp_read_barrier_depends() do {} while (0)
  67. /*****************************************************************************/
  68. /*
  69. * interrupt control
  70. * - "disabled": run in IM1/2
  71. * - level 0 - GDB stub
  72. * - level 1 - virtual serial DMA (if present)
  73. * - level 5 - normal interrupt priority
  74. * - level 6 - timer interrupt
  75. * - "enabled": run in IM7
  76. */
  77. #ifdef CONFIG_MN10300_TTYSM
  78. #define MN10300_CLI_LEVEL EPSW_IM_2
  79. #else
  80. #define MN10300_CLI_LEVEL EPSW_IM_1
  81. #endif
  82. #define local_save_flags(x) \
  83. do { \
  84. typecheck(unsigned long, x); \
  85. asm volatile( \
  86. " mov epsw,%0 \n" \
  87. : "=d"(x) \
  88. ); \
  89. } while (0)
  90. #define local_irq_disable() \
  91. do { \
  92. asm volatile( \
  93. " and %0,epsw \n" \
  94. " or %1,epsw \n" \
  95. " nop \n" \
  96. " nop \n" \
  97. " nop \n" \
  98. : \
  99. : "i"(~EPSW_IM), "i"(EPSW_IE | MN10300_CLI_LEVEL) \
  100. ); \
  101. } while (0)
  102. #define local_irq_save(x) \
  103. do { \
  104. local_save_flags(x); \
  105. local_irq_disable(); \
  106. } while (0)
  107. /*
  108. * we make sure local_irq_enable() doesn't cause priority inversion
  109. */
  110. #ifndef __ASSEMBLY__
  111. extern unsigned long __mn10300_irq_enabled_epsw;
  112. #endif
  113. #define local_irq_enable() \
  114. do { \
  115. unsigned long tmp; \
  116. \
  117. asm volatile( \
  118. " mov epsw,%0 \n" \
  119. " and %1,%0 \n" \
  120. " or %2,%0 \n" \
  121. " mov %0,epsw \n" \
  122. : "=&d"(tmp) \
  123. : "i"(~EPSW_IM), "r"(__mn10300_irq_enabled_epsw) \
  124. ); \
  125. } while (0)
  126. #define local_irq_restore(x) \
  127. do { \
  128. typecheck(unsigned long, x); \
  129. asm volatile( \
  130. " mov %0,epsw \n" \
  131. " nop \n" \
  132. " nop \n" \
  133. " nop \n" \
  134. : \
  135. : "d"(x) \
  136. : "memory", "cc" \
  137. ); \
  138. } while (0)
  139. #define irqs_disabled() \
  140. ({ \
  141. unsigned long flags; \
  142. local_save_flags(flags); \
  143. (flags & EPSW_IM) <= MN10300_CLI_LEVEL; \
  144. })
  145. /* hook to save power by halting the CPU
  146. * - called from the idle loop
  147. * - must reenable interrupts (which takes three instruction cycles to complete)
  148. */
  149. #define safe_halt() \
  150. do { \
  151. asm volatile(" or %0,epsw \n" \
  152. " nop \n" \
  153. " nop \n" \
  154. " bset %2,(%1) \n" \
  155. : \
  156. : "i"(EPSW_IE|EPSW_IM), "n"(&CPUM), "i"(CPUM_SLEEP)\
  157. : "cc" \
  158. ); \
  159. } while (0)
  160. #define STI or EPSW_IE|EPSW_IM,epsw
  161. #define CLI and ~EPSW_IM,epsw; or EPSW_IE|MN10300_CLI_LEVEL,epsw; nop; nop; nop
  162. /*****************************************************************************/
  163. /*
  164. * MN10300 doesn't actually have an exchange instruction
  165. */
  166. #ifndef __ASSEMBLY__
  167. struct __xchg_dummy { unsigned long a[100]; };
  168. #define __xg(x) ((struct __xchg_dummy *)(x))
  169. static inline
  170. unsigned long __xchg(volatile unsigned long *m, unsigned long val)
  171. {
  172. unsigned long retval;
  173. unsigned long flags;
  174. local_irq_save(flags);
  175. retval = *m;
  176. *m = val;
  177. local_irq_restore(flags);
  178. return retval;
  179. }
  180. #define xchg(ptr, v) \
  181. ((__typeof__(*(ptr))) __xchg((unsigned long *)(ptr), \
  182. (unsigned long)(v)))
  183. static inline unsigned long __cmpxchg(volatile unsigned long *m,
  184. unsigned long old, unsigned long new)
  185. {
  186. unsigned long retval;
  187. unsigned long flags;
  188. local_irq_save(flags);
  189. retval = *m;
  190. if (retval == old)
  191. *m = new;
  192. local_irq_restore(flags);
  193. return retval;
  194. }
  195. #define cmpxchg(ptr, o, n) \
  196. ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \
  197. (unsigned long)(o), \
  198. (unsigned long)(n)))
  199. #endif /* !__ASSEMBLY__ */
  200. #endif /* __KERNEL__ */
  201. #endif /* _ASM_SYSTEM_H */