irq.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file COPYING in the main directory of this archive
  4. * for more details.
  5. *
  6. * Changed by HuTao Apr18, 2003
  7. *
  8. * Copyright was missing when I got the code so took from MIPS arch ...MaTed---
  9. * Copyright (C) 1994 by Waldorf GMBH, written by Ralf Baechle
  10. * Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001 by Ralf Baechle
  11. *
  12. * Adapted for BlackFin (ADI) by Ted Ma <mated@sympatico.ca>
  13. * Copyright (c) 2002 Arcturus Networks Inc. (www.arcturusnetworks.com)
  14. * Copyright (c) 2002 Lineo, Inc. <mattw@lineo.com>
  15. */
  16. #ifndef _BFIN_IRQ_H_
  17. #define _BFIN_IRQ_H_
  18. /* SYS_IRQS and NR_IRQS are defined in <mach-bf5xx/irq.h>*/
  19. #include <mach/irq.h>
  20. #include <asm/pda.h>
  21. #include <asm/processor.h>
  22. #ifdef CONFIG_SMP
  23. /* Forward decl needed due to cdef inter dependencies */
  24. static inline uint32_t __pure bfin_dspid(void);
  25. # define blackfin_core_id() (bfin_dspid() & 0xff)
  26. # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
  27. #else
  28. extern unsigned long bfin_irq_flags;
  29. #endif
  30. #ifdef CONFIG_IPIPE
  31. #include <linux/ipipe_trace.h>
  32. void __ipipe_unstall_root(void);
  33. void __ipipe_restore_root(unsigned long flags);
  34. #ifdef CONFIG_DEBUG_HWERR
  35. # define __all_masked_irq_flags 0x3f
  36. # define __save_and_cli_hw(x) \
  37. __asm__ __volatile__( \
  38. "cli %0;" \
  39. "sti %1;" \
  40. : "=&d"(x) \
  41. : "d" (0x3F) \
  42. )
  43. #else
  44. # define __all_masked_irq_flags 0x1f
  45. # define __save_and_cli_hw(x) \
  46. __asm__ __volatile__( \
  47. "cli %0;" \
  48. : "=&d"(x) \
  49. )
  50. #endif
  51. #define irqs_enabled_from_flags_hw(x) ((x) != __all_masked_irq_flags)
  52. #define raw_irqs_disabled_flags(flags) (!irqs_enabled_from_flags_hw(flags))
  53. #define local_test_iflag_hw(x) irqs_enabled_from_flags_hw(x)
  54. #define local_save_flags(x) \
  55. do { \
  56. (x) = __ipipe_test_root() ? \
  57. __all_masked_irq_flags : bfin_irq_flags; \
  58. } while (0)
  59. #define local_irq_save(x) \
  60. do { \
  61. (x) = __ipipe_test_and_stall_root(); \
  62. } while (0)
  63. #define local_irq_restore(x) __ipipe_restore_root(x)
  64. #define local_irq_disable() __ipipe_stall_root()
  65. #define local_irq_enable() __ipipe_unstall_root()
  66. #define irqs_disabled() __ipipe_test_root()
  67. #define local_save_flags_hw(x) \
  68. __asm__ __volatile__( \
  69. "cli %0;" \
  70. "sti %0;" \
  71. : "=d"(x) \
  72. )
  73. #define irqs_disabled_hw() \
  74. ({ \
  75. unsigned long flags; \
  76. local_save_flags_hw(flags); \
  77. !irqs_enabled_from_flags_hw(flags); \
  78. })
  79. static inline unsigned long raw_mangle_irq_bits(int virt, unsigned long real)
  80. {
  81. /* Merge virtual and real interrupt mask bits into a single
  82. 32bit word. */
  83. return (real & ~(1 << 31)) | ((virt != 0) << 31);
  84. }
  85. static inline int raw_demangle_irq_bits(unsigned long *x)
  86. {
  87. int virt = (*x & (1 << 31)) != 0;
  88. *x &= ~(1L << 31);
  89. return virt;
  90. }
  91. #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
  92. #define local_irq_disable_hw() \
  93. do { \
  94. int _tmp_dummy; \
  95. if (!irqs_disabled_hw()) \
  96. ipipe_trace_begin(0x80000000); \
  97. __asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : ); \
  98. } while (0)
  99. #define local_irq_enable_hw() \
  100. do { \
  101. if (irqs_disabled_hw()) \
  102. ipipe_trace_end(0x80000000); \
  103. __asm__ __volatile__ ("sti %0;" : : "d"(bfin_irq_flags)); \
  104. } while (0)
  105. #define local_irq_save_hw(x) \
  106. do { \
  107. __save_and_cli_hw(x); \
  108. if (local_test_iflag_hw(x)) \
  109. ipipe_trace_begin(0x80000001); \
  110. } while (0)
  111. #define local_irq_restore_hw(x) \
  112. do { \
  113. if (local_test_iflag_hw(x)) { \
  114. ipipe_trace_end(0x80000001); \
  115. local_irq_enable_hw_notrace(); \
  116. } \
  117. } while (0)
  118. #define local_irq_disable_hw_notrace() \
  119. do { \
  120. int _tmp_dummy; \
  121. __asm__ __volatile__ ("cli %0;" : "=d" (_tmp_dummy) : ); \
  122. } while (0)
  123. #define local_irq_enable_hw_notrace() \
  124. __asm__ __volatile__( \
  125. "sti %0;" \
  126. : \
  127. : "d"(bfin_irq_flags) \
  128. )
  129. #define local_irq_save_hw_notrace(x) __save_and_cli_hw(x)
  130. #define local_irq_restore_hw_notrace(x) \
  131. do { \
  132. if (local_test_iflag_hw(x)) \
  133. local_irq_enable_hw_notrace(); \
  134. } while (0)
  135. #else /* CONFIG_IPIPE_TRACE_IRQSOFF */
  136. #define local_irq_enable_hw() \
  137. __asm__ __volatile__( \
  138. "sti %0;" \
  139. : \
  140. : "d"(bfin_irq_flags) \
  141. )
  142. #define local_irq_disable_hw() \
  143. do { \
  144. int _tmp_dummy; \
  145. __asm__ __volatile__ ( \
  146. "cli %0;" \
  147. : "=d" (_tmp_dummy)); \
  148. } while (0)
  149. #define local_irq_restore_hw(x) \
  150. do { \
  151. if (irqs_enabled_from_flags_hw(x)) \
  152. local_irq_enable_hw(); \
  153. } while (0)
  154. #define local_irq_save_hw(x) __save_and_cli_hw(x)
  155. #define local_irq_disable_hw_notrace() local_irq_disable_hw()
  156. #define local_irq_enable_hw_notrace() local_irq_enable_hw()
  157. #define local_irq_save_hw_notrace(x) local_irq_save_hw(x)
  158. #define local_irq_restore_hw_notrace(x) local_irq_restore_hw(x)
  159. #endif /* CONFIG_IPIPE_TRACE_IRQSOFF */
  160. #else /* !CONFIG_IPIPE */
  161. /*
  162. * Interrupt configuring macros.
  163. */
  164. #define local_irq_disable() \
  165. do { \
  166. int __tmp_dummy; \
  167. __asm__ __volatile__( \
  168. "cli %0;" \
  169. : "=d" (__tmp_dummy) \
  170. ); \
  171. } while (0)
  172. #define local_irq_enable() \
  173. __asm__ __volatile__( \
  174. "sti %0;" \
  175. : \
  176. : "d" (bfin_irq_flags) \
  177. )
  178. #ifdef CONFIG_DEBUG_HWERR
  179. # define __save_and_cli(x) \
  180. __asm__ __volatile__( \
  181. "cli %0;" \
  182. "sti %1;" \
  183. : "=&d" (x) \
  184. : "d" (0x3F) \
  185. )
  186. #else
  187. # define __save_and_cli(x) \
  188. __asm__ __volatile__( \
  189. "cli %0;" \
  190. : "=&d" (x) \
  191. )
  192. #endif
  193. #define local_save_flags(x) \
  194. __asm__ __volatile__( \
  195. "cli %0;" \
  196. "sti %0;" \
  197. : "=d" (x) \
  198. )
  199. #ifdef CONFIG_DEBUG_HWERR
  200. #define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0)
  201. #else
  202. #define irqs_enabled_from_flags(x) ((x) != 0x1f)
  203. #endif
  204. #define local_irq_restore(x) \
  205. do { \
  206. if (irqs_enabled_from_flags(x)) \
  207. local_irq_enable(); \
  208. } while (0)
  209. /* For spinlocks etc */
  210. #define local_irq_save(x) __save_and_cli(x)
  211. #define irqs_disabled() \
  212. ({ \
  213. unsigned long flags; \
  214. local_save_flags(flags); \
  215. !irqs_enabled_from_flags(flags); \
  216. })
  217. #define local_irq_save_hw(x) local_irq_save(x)
  218. #define local_irq_restore_hw(x) local_irq_restore(x)
  219. #define local_irq_enable_hw() local_irq_enable()
  220. #define local_irq_disable_hw() local_irq_disable()
  221. #define irqs_disabled_hw() irqs_disabled()
  222. #endif /* !CONFIG_IPIPE */
  223. #if ANOMALY_05000244 && defined(CONFIG_BFIN_ICACHE)
  224. # define NOP_PAD_ANOMALY_05000244 "nop; nop;"
  225. #else
  226. # define NOP_PAD_ANOMALY_05000244
  227. #endif
  228. #define idle_with_irq_disabled() \
  229. __asm__ __volatile__( \
  230. NOP_PAD_ANOMALY_05000244 \
  231. ".align 8;" \
  232. "sti %0;" \
  233. "idle;" \
  234. : \
  235. : "d" (bfin_irq_flags) \
  236. )
  237. static inline int irq_canonicalize(int irq)
  238. {
  239. return irq;
  240. }
  241. #endif /* _BFIN_IRQ_H_ */