system_mm.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #ifndef _M68K_SYSTEM_H
  2. #define _M68K_SYSTEM_H
  3. #include <linux/linkage.h>
  4. #include <linux/kernel.h>
  5. #include <asm/segment.h>
  6. #include <asm/entry.h>
  7. #ifdef __KERNEL__
  8. /*
  9. * switch_to(n) should switch tasks to task ptr, first checking that
  10. * ptr isn't the current task, in which case it does nothing. This
  11. * also clears the TS-flag if the task we switched to has used the
  12. * math co-processor latest.
  13. */
  14. /*
  15. * switch_to() saves the extra registers, that are not saved
  16. * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
  17. * a0-a1. Some of these are used by schedule() and its predecessors
  18. * and so we might get see unexpected behaviors when a task returns
  19. * with unexpected register values.
  20. *
  21. * syscall stores these registers itself and none of them are used
  22. * by syscall after the function in the syscall has been called.
  23. *
  24. * Beware that resume now expects *next to be in d1 and the offset of
  25. * tss to be in a1. This saves a few instructions as we no longer have
  26. * to push them onto the stack and read them back right after.
  27. *
  28. * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
  29. *
  30. * Changed 96/09/19 by Andreas Schwab
  31. * pass prev in a0, next in a1
  32. */
  33. asmlinkage void resume(void);
  34. #define switch_to(prev,next,last) do { \
  35. register void *_prev __asm__ ("a0") = (prev); \
  36. register void *_next __asm__ ("a1") = (next); \
  37. register void *_last __asm__ ("d1"); \
  38. __asm__ __volatile__("jbsr resume" \
  39. : "=a" (_prev), "=a" (_next), "=d" (_last) \
  40. : "0" (_prev), "1" (_next) \
  41. : "d0", "d2", "d3", "d4", "d5"); \
  42. (last) = _last; \
  43. } while (0)
  44. /*
  45. * Force strict CPU ordering.
  46. * Not really required on m68k...
  47. */
  48. #define nop() do { asm volatile ("nop"); barrier(); } while (0)
  49. #define mb() barrier()
  50. #define rmb() barrier()
  51. #define wmb() barrier()
  52. #define read_barrier_depends() ((void)0)
  53. #define set_mb(var, value) ({ (var) = (value); wmb(); })
  54. #define smp_mb() barrier()
  55. #define smp_rmb() barrier()
  56. #define smp_wmb() barrier()
  57. #define smp_read_barrier_depends() ((void)0)
  58. /* interrupt control.. */
  59. #if 0
  60. #define local_irq_enable() asm volatile ("andiw %0,%%sr": : "i" (ALLOWINT) : "memory")
  61. #else
  62. #include <linux/hardirq.h>
  63. #define local_irq_enable() ({ \
  64. if (MACH_IS_Q40 || !hardirq_count()) \
  65. asm volatile ("andiw %0,%%sr": : "i" (ALLOWINT) : "memory"); \
  66. })
  67. #endif
  68. #define local_irq_disable() asm volatile ("oriw #0x0700,%%sr": : : "memory")
  69. #define local_save_flags(x) asm volatile ("movew %%sr,%0":"=d" (x) : : "memory")
  70. #define local_irq_restore(x) asm volatile ("movew %0,%%sr": :"d" (x) : "memory")
  71. static inline int irqs_disabled(void)
  72. {
  73. unsigned long flags;
  74. local_save_flags(flags);
  75. return flags & ~ALLOWINT;
  76. }
  77. /* For spinlocks etc */
  78. #define local_irq_save(x) ({ local_save_flags(x); local_irq_disable(); })
  79. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  80. struct __xchg_dummy { unsigned long a[100]; };
  81. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  82. #ifndef CONFIG_RMW_INSNS
  83. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  84. {
  85. unsigned long flags, tmp;
  86. local_irq_save(flags);
  87. switch (size) {
  88. case 1:
  89. tmp = *(u8 *)ptr;
  90. *(u8 *)ptr = x;
  91. x = tmp;
  92. break;
  93. case 2:
  94. tmp = *(u16 *)ptr;
  95. *(u16 *)ptr = x;
  96. x = tmp;
  97. break;
  98. case 4:
  99. tmp = *(u32 *)ptr;
  100. *(u32 *)ptr = x;
  101. x = tmp;
  102. break;
  103. default:
  104. BUG();
  105. }
  106. local_irq_restore(flags);
  107. return x;
  108. }
  109. #else
  110. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  111. {
  112. switch (size) {
  113. case 1:
  114. __asm__ __volatile__
  115. ("moveb %2,%0\n\t"
  116. "1:\n\t"
  117. "casb %0,%1,%2\n\t"
  118. "jne 1b"
  119. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  120. break;
  121. case 2:
  122. __asm__ __volatile__
  123. ("movew %2,%0\n\t"
  124. "1:\n\t"
  125. "casw %0,%1,%2\n\t"
  126. "jne 1b"
  127. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  128. break;
  129. case 4:
  130. __asm__ __volatile__
  131. ("movel %2,%0\n\t"
  132. "1:\n\t"
  133. "casl %0,%1,%2\n\t"
  134. "jne 1b"
  135. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  136. break;
  137. }
  138. return x;
  139. }
  140. #endif
  141. #include <asm-generic/cmpxchg-local.h>
  142. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  143. /*
  144. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  145. * store NEW in MEM. Return the initial value in MEM. Success is
  146. * indicated by comparing RETURN with OLD.
  147. */
  148. #ifdef CONFIG_RMW_INSNS
  149. #define __HAVE_ARCH_CMPXCHG 1
  150. static inline unsigned long __cmpxchg(volatile void *p, unsigned long old,
  151. unsigned long new, int size)
  152. {
  153. switch (size) {
  154. case 1:
  155. __asm__ __volatile__ ("casb %0,%2,%1"
  156. : "=d" (old), "=m" (*(char *)p)
  157. : "d" (new), "0" (old), "m" (*(char *)p));
  158. break;
  159. case 2:
  160. __asm__ __volatile__ ("casw %0,%2,%1"
  161. : "=d" (old), "=m" (*(short *)p)
  162. : "d" (new), "0" (old), "m" (*(short *)p));
  163. break;
  164. case 4:
  165. __asm__ __volatile__ ("casl %0,%2,%1"
  166. : "=d" (old), "=m" (*(int *)p)
  167. : "d" (new), "0" (old), "m" (*(int *)p));
  168. break;
  169. }
  170. return old;
  171. }
  172. #define cmpxchg(ptr, o, n) \
  173. ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
  174. (unsigned long)(n), sizeof(*(ptr))))
  175. #define cmpxchg_local(ptr, o, n) \
  176. ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
  177. (unsigned long)(n), sizeof(*(ptr))))
  178. #else
  179. /*
  180. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  181. * them available.
  182. */
  183. #define cmpxchg_local(ptr, o, n) \
  184. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  185. (unsigned long)(n), sizeof(*(ptr))))
  186. #ifndef CONFIG_SMP
  187. #include <asm-generic/cmpxchg.h>
  188. #endif
  189. #endif
  190. #define arch_align_stack(x) (x)
  191. #endif /* __KERNEL__ */
  192. #endif /* _M68K_SYSTEM_H */