irqflags.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * interface to Blackfin CEC
  3. *
  4. * Copyright 2009 Analog Devices Inc.
  5. * Licensed under the GPL-2 or later.
  6. */
  7. #ifndef __ASM_BFIN_IRQFLAGS_H__
  8. #define __ASM_BFIN_IRQFLAGS_H__
  9. #include <mach/blackfin.h>
  10. #ifdef CONFIG_SMP
  11. # include <asm/pda.h>
  12. # include <asm/processor.h>
  13. # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
  14. #else
  15. extern unsigned long bfin_irq_flags;
  16. #endif
  17. static inline notrace void bfin_sti(unsigned long flags)
  18. {
  19. asm volatile("sti %0;" : : "d" (flags));
  20. }
  21. static inline notrace unsigned long bfin_cli(void)
  22. {
  23. unsigned long flags;
  24. asm volatile("cli %0;" : "=d" (flags));
  25. return flags;
  26. }
  27. #ifdef CONFIG_DEBUG_HWERR
  28. # define bfin_no_irqs 0x3f
  29. #else
  30. # define bfin_no_irqs 0x1f
  31. #endif
  32. /*****************************************************************************/
  33. /*
  34. * Hard, untraced CPU interrupt flag manipulation and access.
  35. */
  36. static inline notrace void __hard_local_irq_disable(void)
  37. {
  38. bfin_cli();
  39. }
  40. static inline notrace void __hard_local_irq_enable(void)
  41. {
  42. bfin_sti(bfin_irq_flags);
  43. }
  44. static inline notrace unsigned long hard_local_save_flags(void)
  45. {
  46. return bfin_read_IMASK();
  47. }
  48. static inline notrace unsigned long __hard_local_irq_save(void)
  49. {
  50. unsigned long flags;
  51. flags = bfin_cli();
  52. #ifdef CONFIG_DEBUG_HWERR
  53. bfin_sti(0x3f);
  54. #endif
  55. return flags;
  56. }
  57. static inline notrace int hard_irqs_disabled_flags(unsigned long flags)
  58. {
  59. #ifdef CONFIG_BF60x
  60. return (flags & IMASK_IVG11) == 0;
  61. #else
  62. return (flags & ~0x3f) == 0;
  63. #endif
  64. }
  65. static inline notrace int hard_irqs_disabled(void)
  66. {
  67. unsigned long flags = hard_local_save_flags();
  68. return hard_irqs_disabled_flags(flags);
  69. }
  70. static inline notrace void __hard_local_irq_restore(unsigned long flags)
  71. {
  72. if (!hard_irqs_disabled_flags(flags))
  73. __hard_local_irq_enable();
  74. }
  75. /*****************************************************************************/
  76. /*
  77. * Interrupt pipe handling.
  78. */
  79. #ifdef CONFIG_IPIPE
  80. #include <linux/compiler.h>
  81. #include <linux/ipipe_trace.h>
  82. /*
  83. * Way too many inter-deps between low-level headers in this port, so
  84. * we redeclare the required bits we cannot pick from
  85. * <asm/ipipe_base.h> to prevent circular dependencies.
  86. */
  87. void __ipipe_stall_root(void);
  88. void __ipipe_unstall_root(void);
  89. unsigned long __ipipe_test_root(void);
  90. unsigned long __ipipe_test_and_stall_root(void);
  91. void __ipipe_restore_root(unsigned long flags);
  92. #ifdef CONFIG_IPIPE_DEBUG_CONTEXT
  93. struct ipipe_domain;
  94. extern struct ipipe_domain ipipe_root;
  95. void ipipe_check_context(struct ipipe_domain *ipd);
  96. #define __check_irqop_context(ipd) ipipe_check_context(&ipipe_root)
  97. #else /* !CONFIG_IPIPE_DEBUG_CONTEXT */
  98. #define __check_irqop_context(ipd) do { } while (0)
  99. #endif /* !CONFIG_IPIPE_DEBUG_CONTEXT */
  100. /*
  101. * Interrupt pipe interface to linux/irqflags.h.
  102. */
  103. static inline notrace void arch_local_irq_disable(void)
  104. {
  105. __check_irqop_context();
  106. __ipipe_stall_root();
  107. barrier();
  108. }
  109. static inline notrace void arch_local_irq_enable(void)
  110. {
  111. barrier();
  112. __check_irqop_context();
  113. __ipipe_unstall_root();
  114. }
  115. static inline notrace unsigned long arch_local_save_flags(void)
  116. {
  117. return __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags;
  118. }
  119. static inline notrace int arch_irqs_disabled_flags(unsigned long flags)
  120. {
  121. return flags == bfin_no_irqs;
  122. }
  123. static inline notrace unsigned long arch_local_irq_save(void)
  124. {
  125. unsigned long flags;
  126. __check_irqop_context();
  127. flags = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags;
  128. barrier();
  129. return flags;
  130. }
  131. static inline notrace void arch_local_irq_restore(unsigned long flags)
  132. {
  133. __check_irqop_context();
  134. __ipipe_restore_root(flags == bfin_no_irqs);
  135. }
  136. static inline notrace unsigned long arch_mangle_irq_bits(int virt, unsigned long real)
  137. {
  138. /*
  139. * Merge virtual and real interrupt mask bits into a single
  140. * 32bit word.
  141. */
  142. return (real & ~(1 << 31)) | ((virt != 0) << 31);
  143. }
  144. static inline notrace int arch_demangle_irq_bits(unsigned long *x)
  145. {
  146. int virt = (*x & (1 << 31)) != 0;
  147. *x &= ~(1L << 31);
  148. return virt;
  149. }
  150. /*
  151. * Interface to various arch routines that may be traced.
  152. */
  153. #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
  154. static inline notrace void hard_local_irq_disable(void)
  155. {
  156. if (!hard_irqs_disabled()) {
  157. __hard_local_irq_disable();
  158. ipipe_trace_begin(0x80000000);
  159. }
  160. }
  161. static inline notrace void hard_local_irq_enable(void)
  162. {
  163. if (hard_irqs_disabled()) {
  164. ipipe_trace_end(0x80000000);
  165. __hard_local_irq_enable();
  166. }
  167. }
  168. static inline notrace unsigned long hard_local_irq_save(void)
  169. {
  170. unsigned long flags = hard_local_save_flags();
  171. if (!hard_irqs_disabled_flags(flags)) {
  172. __hard_local_irq_disable();
  173. ipipe_trace_begin(0x80000001);
  174. }
  175. return flags;
  176. }
  177. static inline notrace void hard_local_irq_restore(unsigned long flags)
  178. {
  179. if (!hard_irqs_disabled_flags(flags)) {
  180. ipipe_trace_end(0x80000001);
  181. __hard_local_irq_enable();
  182. }
  183. }
  184. #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  185. # define hard_local_irq_disable() __hard_local_irq_disable()
  186. # define hard_local_irq_enable() __hard_local_irq_enable()
  187. # define hard_local_irq_save() __hard_local_irq_save()
  188. # define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
  189. #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  190. #define hard_local_irq_save_cond() hard_local_irq_save()
  191. #define hard_local_irq_restore_cond(flags) hard_local_irq_restore(flags)
  192. #else /* !CONFIG_IPIPE */
  193. /*
  194. * Direct interface to linux/irqflags.h.
  195. */
  196. #define arch_local_save_flags() hard_local_save_flags()
  197. #define arch_local_irq_save() __hard_local_irq_save()
  198. #define arch_local_irq_restore(flags) __hard_local_irq_restore(flags)
  199. #define arch_local_irq_enable() __hard_local_irq_enable()
  200. #define arch_local_irq_disable() __hard_local_irq_disable()
  201. #define arch_irqs_disabled_flags(flags) hard_irqs_disabled_flags(flags)
  202. #define arch_irqs_disabled() hard_irqs_disabled()
  203. /*
  204. * Interface to various arch routines that may be traced.
  205. */
  206. #define hard_local_irq_save() __hard_local_irq_save()
  207. #define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
  208. #define hard_local_irq_enable() __hard_local_irq_enable()
  209. #define hard_local_irq_disable() __hard_local_irq_disable()
  210. #define hard_local_irq_save_cond() hard_local_save_flags()
  211. #define hard_local_irq_restore_cond(flags) do { (void)(flags); } while (0)
  212. #endif /* !CONFIG_IPIPE */
  213. #ifdef CONFIG_SMP
  214. #define hard_local_irq_save_smp() hard_local_irq_save()
  215. #define hard_local_irq_restore_smp(flags) hard_local_irq_restore(flags)
  216. #else
  217. #define hard_local_irq_save_smp() hard_local_save_flags()
  218. #define hard_local_irq_restore_smp(flags) do { (void)(flags); } while (0)
  219. #endif
  220. /*
  221. * Remap the arch-neutral IRQ state manipulation macros to the
  222. * blackfin-specific hard_local_irq_* API.
  223. */
  224. #define local_irq_save_hw(flags) \
  225. do { \
  226. (flags) = hard_local_irq_save(); \
  227. } while (0)
  228. #define local_irq_restore_hw(flags) \
  229. do { \
  230. hard_local_irq_restore(flags); \
  231. } while (0)
  232. #define local_irq_disable_hw() \
  233. do { \
  234. hard_local_irq_disable(); \
  235. } while (0)
  236. #define local_irq_enable_hw() \
  237. do { \
  238. hard_local_irq_enable(); \
  239. } while (0)
  240. #define local_irq_save_hw_notrace(flags) \
  241. do { \
  242. (flags) = __hard_local_irq_save(); \
  243. } while (0)
  244. #define local_irq_restore_hw_notrace(flags) \
  245. do { \
  246. __hard_local_irq_restore(flags); \
  247. } while (0)
  248. #define irqs_disabled_hw() hard_irqs_disabled()
  249. #endif