system.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #include <asm/pda.h>
  39. #include <asm/processor.h>
  40. #include <asm/irq.h>
  41. /*
  42. * Force strict CPU ordering.
  43. */
  44. #define nop() __asm__ __volatile__ ("nop;\n\t" : : )
  45. #define mb() __asm__ __volatile__ ("" : : : "memory")
  46. #define rmb() __asm__ __volatile__ ("" : : : "memory")
  47. #define wmb() __asm__ __volatile__ ("" : : : "memory")
  48. #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
  49. #define read_barrier_depends() do { } while(0)
  50. #ifdef CONFIG_SMP
  51. asmlinkage unsigned long __raw_xchg_1_asm(volatile void *ptr, unsigned long value);
  52. asmlinkage unsigned long __raw_xchg_2_asm(volatile void *ptr, unsigned long value);
  53. asmlinkage unsigned long __raw_xchg_4_asm(volatile void *ptr, unsigned long value);
  54. asmlinkage unsigned long __raw_cmpxchg_1_asm(volatile void *ptr,
  55. unsigned long new, unsigned long old);
  56. asmlinkage unsigned long __raw_cmpxchg_2_asm(volatile void *ptr,
  57. unsigned long new, unsigned long old);
  58. asmlinkage unsigned long __raw_cmpxchg_4_asm(volatile void *ptr,
  59. unsigned long new, unsigned long old);
  60. #ifdef __ARCH_SYNC_CORE_DCACHE
  61. # define smp_mb() do { barrier(); smp_check_barrier(); smp_mark_barrier(); } while (0)
  62. # define smp_rmb() do { barrier(); smp_check_barrier(); } while (0)
  63. # define smp_wmb() do { barrier(); smp_mark_barrier(); } while (0)
  64. #define smp_read_barrier_depends() do { barrier(); smp_check_barrier(); } while (0)
  65. #else
  66. # define smp_mb() barrier()
  67. # define smp_rmb() barrier()
  68. # define smp_wmb() barrier()
  69. #define smp_read_barrier_depends() barrier()
  70. #endif
  71. static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
  72. int size)
  73. {
  74. unsigned long tmp;
  75. switch (size) {
  76. case 1:
  77. tmp = __raw_xchg_1_asm(ptr, x);
  78. break;
  79. case 2:
  80. tmp = __raw_xchg_2_asm(ptr, x);
  81. break;
  82. case 4:
  83. tmp = __raw_xchg_4_asm(ptr, x);
  84. break;
  85. }
  86. return tmp;
  87. }
  88. /*
  89. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  90. * store NEW in MEM. Return the initial value in MEM. Success is
  91. * indicated by comparing RETURN with OLD.
  92. */
  93. static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  94. unsigned long new, int size)
  95. {
  96. unsigned long tmp;
  97. switch (size) {
  98. case 1:
  99. tmp = __raw_cmpxchg_1_asm(ptr, new, old);
  100. break;
  101. case 2:
  102. tmp = __raw_cmpxchg_2_asm(ptr, new, old);
  103. break;
  104. case 4:
  105. tmp = __raw_cmpxchg_4_asm(ptr, new, old);
  106. break;
  107. }
  108. return tmp;
  109. }
  110. #define cmpxchg(ptr, o, n) \
  111. ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
  112. (unsigned long)(n), sizeof(*(ptr))))
  113. #else /* !CONFIG_SMP */
  114. #define smp_mb() barrier()
  115. #define smp_rmb() barrier()
  116. #define smp_wmb() barrier()
  117. #define smp_read_barrier_depends() do { } while(0)
  118. struct __xchg_dummy {
  119. unsigned long a[100];
  120. };
  121. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  122. static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
  123. int size)
  124. {
  125. unsigned long tmp = 0;
  126. unsigned long flags = 0;
  127. local_irq_save_hw(flags);
  128. switch (size) {
  129. case 1:
  130. __asm__ __volatile__
  131. ("%0 = b%2 (z);\n\t"
  132. "b%2 = %1;\n\t"
  133. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  134. break;
  135. case 2:
  136. __asm__ __volatile__
  137. ("%0 = w%2 (z);\n\t"
  138. "w%2 = %1;\n\t"
  139. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  140. break;
  141. case 4:
  142. __asm__ __volatile__
  143. ("%0 = %2;\n\t"
  144. "%2 = %1;\n\t"
  145. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  146. break;
  147. }
  148. local_irq_restore_hw(flags);
  149. return tmp;
  150. }
  151. #include <asm-generic/cmpxchg-local.h>
  152. /*
  153. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  154. * them available.
  155. */
  156. #define cmpxchg_local(ptr, o, n) \
  157. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  158. (unsigned long)(n), sizeof(*(ptr))))
  159. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  160. #include <asm-generic/cmpxchg.h>
  161. #endif /* !CONFIG_SMP */
  162. #define xchg(ptr, x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
  163. #define tas(ptr) ((void)xchg((ptr), 1))
  164. #define prepare_to_switch() do { } while(0)
  165. /*
  166. * switch_to(n) should switch tasks to task ptr, first checking that
  167. * ptr isn't the current task, in which case it does nothing.
  168. */
  169. #include <asm/l1layout.h>
  170. #include <asm/mem_map.h>
  171. asmlinkage struct task_struct *resume(struct task_struct *prev, struct task_struct *next);
  172. #ifndef CONFIG_SMP
  173. #define switch_to(prev,next,last) \
  174. do { \
  175. memcpy (&task_thread_info(prev)->l1_task_info, L1_SCRATCH_TASK_INFO, \
  176. sizeof *L1_SCRATCH_TASK_INFO); \
  177. memcpy (L1_SCRATCH_TASK_INFO, &task_thread_info(next)->l1_task_info, \
  178. sizeof *L1_SCRATCH_TASK_INFO); \
  179. (last) = resume (prev, next); \
  180. } while (0)
  181. #else
  182. #define switch_to(prev, next, last) \
  183. do { \
  184. (last) = resume(prev, next); \
  185. } while (0)
  186. #endif
  187. #endif /* _BLACKFIN_SYSTEM_H */