system.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * U-boot - system.h
  3. *
  4. * Copyright (c) 2005 blackfin.uclinux.org
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #ifndef _BLACKFIN_SYSTEM_H
  25. #define _BLACKFIN_SYSTEM_H
  26. #include <linux/config.h> /* get configuration macros */
  27. #include <asm/linkage.h>
  28. #include <asm/blackfin.h>
  29. #include <asm/segment.h>
  30. #include <asm/entry.h>
  31. #define prepare_to_switch() do { } while(0)
  32. /*
  33. * switch_to(n) should switch tasks to task ptr, first checking that
  34. * ptr isn't the current task, in which case it does nothing. This
  35. * also clears the TS-flag if the task we switched to has used the
  36. * math co-processor latest.
  37. *
  38. * 05/25/01 - Tony Kou (tonyko@lineo.ca)
  39. *
  40. * Adapted for BlackFin (ADI) by Ted Ma, Metrowerks, and Motorola GSG
  41. * Copyright (c) 2002 Arcturus Networks Inc. (www.arcturusnetworks.com)
  42. * Copyright (c) 2003 Metrowerks (www.metrowerks.com)
  43. */
  44. asmlinkage void resume(void);
  45. #define switch_to(prev,next,last) { \
  46. void *_last; \
  47. __asm__ __volatile__( \
  48. "r0 = %1;\n\t" \
  49. "r1 = %2;\n\t" \
  50. "call resume;\n\t" \
  51. "%0 = r0;\n\t" \
  52. : "=d" (_last) \
  53. : "d" (prev), \
  54. "d" (next) \
  55. : "CC", "R0", "R1", "R2", "R3", "R4", "R5", "P0", "P1");\
  56. (last) = _last; \
  57. }
  58. /* Force kerenl switch to user mode -- Steven Chen */
  59. #define switch_to_user_mode() { \
  60. __asm__ __volatile__( \
  61. "call kernel_to_user_mode;\n\t" \
  62. :: \
  63. : "CC", "R0", "R1", "R2", "R3", "R4", "R5", "P0", "P1");\
  64. }
  65. /*
  66. * Interrupt configuring macros.
  67. */
  68. extern int irq_flags;
  69. #define __sti() { \
  70. __asm__ __volatile__ ( \
  71. "r3 = %0;" \
  72. "sti r3;" \
  73. ::"m"(irq_flags):"R3"); \
  74. }
  75. #define __cli() { \
  76. __asm__ __volatile__ ( \
  77. "cli r3;" \
  78. :::"R3"); \
  79. }
  80. #define __save_flags(x) { \
  81. __asm__ __volatile__ ( \
  82. "cli r3;" \
  83. "%0 = r3;" \
  84. "sti r3;" \
  85. ::"m"(x):"R3"); \
  86. }
  87. #define __save_and_cli(x) { \
  88. __asm__ __volatile__ ( \
  89. "cli r3;" \
  90. "%0 = r3;" \
  91. ::"m"(x):"R3"); \
  92. }
  93. #define __restore_flags(x) { \
  94. __asm__ __volatile__ ( \
  95. "r3 = %0;" \
  96. "sti r3;" \
  97. ::"m"(x):"R3"); \
  98. }
  99. /* For spinlocks etc */
  100. #define local_irq_save(x) __save_and_cli(x)
  101. #define local_irq_restore(x) __restore_flags(x)
  102. #define local_irq_disable() __cli()
  103. #define local_irq_enable() __sti()
  104. #define cli() __cli()
  105. #define sti() __sti()
  106. #define save_flags(x) __save_flags(x)
  107. #define restore_flags(x) __restore_flags(x)
  108. #define save_and_cli(x) __save_and_cli(x)
  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_rmb(var, value) do { xchg(&var, value); } while (0)
  117. #define set_mb(var, value) set_rmb(var, value)
  118. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  119. #ifdef CONFIG_SMP
  120. #define smp_mb() mb()
  121. #define smp_rmb() rmb()
  122. #define smp_wmb() wmb()
  123. #else
  124. #define smp_mb() barrier()
  125. #define smp_rmb() barrier()
  126. #define smp_wmb() barrier()
  127. #endif
  128. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  129. #define tas(ptr) (xchg((ptr),1))
  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;
  138. unsigned long flags = 0;
  139. save_and_cli(flags);
  140. switch (size) {
  141. case 1:
  142. __asm__ __volatile__("%0 = %2;\n\t" "%2 = %1;\n\t": "=&d"(tmp): "d"(x), "m"(*__xg(ptr)):"memory");
  143. break;
  144. case 2:
  145. __asm__ __volatile__("%0 = %2;\n\t" "%2 = %1;\n\t": "=&d"(tmp): "d"(x), "m"(*__xg(ptr)):"memory");
  146. break;
  147. case 4:
  148. __asm__ __volatile__("%0 = %2;\n\t" "%2 = %1;\n\t": "=&d"(tmp): "d"(x), "m"(*__xg(ptr)):"memory");
  149. break;
  150. }
  151. restore_flags(flags);
  152. return tmp;
  153. }
  154. /* Depend on whether Blackfin has hard reset function */
  155. /* YES it does, but it is tricky to implement - FIXME later ...MaTed--- */
  156. #define HARD_RESET_NOW() ({})
  157. #endif /* _BLACKFIN_SYSTEM_H */