system.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * File: include/asm/system.h
  3. * Based on:
  4. * Author: Tony Kou (tonyko@lineo.ca)
  5. * Copyright (c) 2002 Arcturus Networks Inc.
  6. * (www.arcturusnetworks.com)
  7. * Copyright (c) 2003 Metrowerks (www.metrowerks.com)
  8. * Copyright (c) 2004 Analog Device Inc.
  9. * Created: 25Jan2001 - Tony Kou
  10. * Description: system.h include file
  11. *
  12. * Modified: 22Sep2006 - Robin Getz
  13. * - move include blackfin.h down, so I can get access to
  14. * irq functions in other include files.
  15. *
  16. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2, or (at your option)
  21. * any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; see the file COPYING.
  30. * If not, write to the Free Software Foundation,
  31. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32. */
  33. #ifndef _BLACKFIN_SYSTEM_H
  34. #define _BLACKFIN_SYSTEM_H
  35. #include <linux/linkage.h>
  36. #include <linux/compiler.h>
  37. #include <mach/anomaly.h>
  38. /*
  39. * Interrupt configuring macros.
  40. */
  41. extern unsigned long irq_flags;
  42. #define local_irq_enable() \
  43. __asm__ __volatile__( \
  44. "sti %0;" \
  45. : \
  46. : "d" (irq_flags) \
  47. )
  48. #define local_irq_disable() \
  49. do { \
  50. int __tmp_dummy; \
  51. __asm__ __volatile__( \
  52. "cli %0;" \
  53. : "=d" (__tmp_dummy) \
  54. ); \
  55. } while (0)
  56. #if ANOMALY_05000244 && defined(CONFIG_BFIN_ICACHE)
  57. # define NOP_PAD_ANOMALY_05000244 "nop; nop;"
  58. #else
  59. # define NOP_PAD_ANOMALY_05000244
  60. #endif
  61. #define idle_with_irq_disabled() \
  62. __asm__ __volatile__( \
  63. NOP_PAD_ANOMALY_05000244 \
  64. ".align 8;" \
  65. "sti %0;" \
  66. "idle;" \
  67. : \
  68. : "d" (irq_flags) \
  69. )
  70. #ifdef CONFIG_DEBUG_HWERR
  71. # define __save_and_cli(x) \
  72. __asm__ __volatile__( \
  73. "cli %0;" \
  74. "sti %1;" \
  75. : "=&d" (x) \
  76. : "d" (0x3F) \
  77. )
  78. #else
  79. # define __save_and_cli(x) \
  80. __asm__ __volatile__( \
  81. "cli %0;" \
  82. : "=&d" (x) \
  83. )
  84. #endif
  85. #define local_save_flags(x) \
  86. __asm__ __volatile__( \
  87. "cli %0;" \
  88. "sti %0;" \
  89. : "=d" (x) \
  90. )
  91. #ifdef CONFIG_DEBUG_HWERR
  92. #define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0)
  93. #else
  94. #define irqs_enabled_from_flags(x) ((x) != 0x1f)
  95. #endif
  96. #define local_irq_restore(x) \
  97. do { \
  98. if (irqs_enabled_from_flags(x)) \
  99. local_irq_enable(); \
  100. } while (0)
  101. /* For spinlocks etc */
  102. #define local_irq_save(x) __save_and_cli(x)
  103. #define irqs_disabled() \
  104. ({ \
  105. unsigned long flags; \
  106. local_save_flags(flags); \
  107. !irqs_enabled_from_flags(flags); \
  108. })
  109. /*
  110. * Force strict CPU ordering.
  111. */
  112. #define nop() asm volatile ("nop;\n\t"::)
  113. #define mb() asm volatile ("" : : :"memory")
  114. #define rmb() asm volatile ("" : : :"memory")
  115. #define wmb() asm volatile ("" : : :"memory")
  116. #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
  117. #define read_barrier_depends() do { } while(0)
  118. #ifdef CONFIG_SMP
  119. #define smp_mb() mb()
  120. #define smp_rmb() rmb()
  121. #define smp_wmb() wmb()
  122. #define smp_read_barrier_depends() read_barrier_depends()
  123. #else
  124. #define smp_mb() barrier()
  125. #define smp_rmb() barrier()
  126. #define smp_wmb() barrier()
  127. #define smp_read_barrier_depends() do { } while(0)
  128. #endif
  129. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  130. struct __xchg_dummy {
  131. unsigned long a[100];
  132. };
  133. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  134. static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
  135. int size)
  136. {
  137. unsigned long tmp = 0;
  138. unsigned long flags = 0;
  139. local_irq_save(flags);
  140. switch (size) {
  141. case 1:
  142. __asm__ __volatile__
  143. ("%0 = b%2 (z);\n\t"
  144. "b%2 = %1;\n\t"
  145. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  146. break;
  147. case 2:
  148. __asm__ __volatile__
  149. ("%0 = w%2 (z);\n\t"
  150. "w%2 = %1;\n\t"
  151. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  152. break;
  153. case 4:
  154. __asm__ __volatile__
  155. ("%0 = %2;\n\t"
  156. "%2 = %1;\n\t"
  157. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  158. break;
  159. }
  160. local_irq_restore(flags);
  161. return tmp;
  162. }
  163. #include <asm-generic/cmpxchg-local.h>
  164. /*
  165. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  166. * them available.
  167. */
  168. #define cmpxchg_local(ptr, o, n) \
  169. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  170. (unsigned long)(n), sizeof(*(ptr))))
  171. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  172. #ifndef CONFIG_SMP
  173. #include <asm-generic/cmpxchg.h>
  174. #endif
  175. #define prepare_to_switch() do { } while(0)
  176. /*
  177. * switch_to(n) should switch tasks to task ptr, first checking that
  178. * ptr isn't the current task, in which case it does nothing.
  179. */
  180. #include <asm/blackfin.h>
  181. asmlinkage struct task_struct *resume(struct task_struct *prev, struct task_struct *next);
  182. #define switch_to(prev,next,last) \
  183. do { \
  184. memcpy (&task_thread_info(prev)->l1_task_info, L1_SCRATCH_TASK_INFO, \
  185. sizeof *L1_SCRATCH_TASK_INFO); \
  186. memcpy (L1_SCRATCH_TASK_INFO, &task_thread_info(next)->l1_task_info, \
  187. sizeof *L1_SCRATCH_TASK_INFO); \
  188. (last) = resume (prev, next); \
  189. } while (0)
  190. #endif /* _BLACKFIN_SYSTEM_H */