irqflags.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. return (flags & ~0x3f) == 0;
  60. }
  61. static inline notrace int hard_irqs_disabled(void)
  62. {
  63. unsigned long flags = hard_local_save_flags();
  64. return hard_irqs_disabled_flags(flags);
  65. }
  66. static inline notrace void __hard_local_irq_restore(unsigned long flags)
  67. {
  68. if (!hard_irqs_disabled_flags(flags))
  69. __hard_local_irq_enable();
  70. }
  71. /*****************************************************************************/
  72. /*
  73. * Interrupt pipe handling.
  74. */
  75. #ifdef CONFIG_IPIPE
  76. #include <linux/compiler.h>
  77. #include <linux/ipipe_trace.h>
  78. /*
  79. * Way too many inter-deps between low-level headers in this port, so
  80. * we redeclare the required bits we cannot pick from
  81. * <asm/ipipe_base.h> to prevent circular dependencies.
  82. */
  83. void __ipipe_stall_root(void);
  84. void __ipipe_unstall_root(void);
  85. unsigned long __ipipe_test_root(void);
  86. unsigned long __ipipe_test_and_stall_root(void);
  87. void __ipipe_restore_root(unsigned long flags);
  88. #ifdef CONFIG_IPIPE_DEBUG_CONTEXT
  89. struct ipipe_domain;
  90. extern struct ipipe_domain ipipe_root;
  91. void ipipe_check_context(struct ipipe_domain *ipd);
  92. #define __check_irqop_context(ipd) ipipe_check_context(&ipipe_root)
  93. #else /* !CONFIG_IPIPE_DEBUG_CONTEXT */
  94. #define __check_irqop_context(ipd) do { } while (0)
  95. #endif /* !CONFIG_IPIPE_DEBUG_CONTEXT */
  96. /*
  97. * Interrupt pipe interface to linux/irqflags.h.
  98. */
  99. static inline notrace void arch_local_irq_disable(void)
  100. {
  101. __check_irqop_context();
  102. __ipipe_stall_root();
  103. barrier();
  104. }
  105. static inline notrace void arch_local_irq_enable(void)
  106. {
  107. barrier();
  108. __check_irqop_context();
  109. __ipipe_unstall_root();
  110. }
  111. static inline notrace unsigned long arch_local_save_flags(void)
  112. {
  113. return __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags;
  114. }
  115. static inline notrace int arch_irqs_disabled_flags(unsigned long flags)
  116. {
  117. return flags == bfin_no_irqs;
  118. }
  119. static inline notrace unsigned long arch_local_irq_save(void)
  120. {
  121. unsigned long flags;
  122. __check_irqop_context();
  123. flags = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags;
  124. barrier();
  125. return flags;
  126. }
  127. static inline notrace void arch_local_irq_restore(unsigned long flags)
  128. {
  129. __check_irqop_context();
  130. __ipipe_restore_root(flags == bfin_no_irqs);
  131. }
  132. static inline notrace unsigned long arch_mangle_irq_bits(int virt, unsigned long real)
  133. {
  134. /*
  135. * Merge virtual and real interrupt mask bits into a single
  136. * 32bit word.
  137. */
  138. return (real & ~(1 << 31)) | ((virt != 0) << 31);
  139. }
  140. static inline notrace int arch_demangle_irq_bits(unsigned long *x)
  141. {
  142. int virt = (*x & (1 << 31)) != 0;
  143. *x &= ~(1L << 31);
  144. return virt;
  145. }
  146. /*
  147. * Interface to various arch routines that may be traced.
  148. */
  149. #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
  150. static inline notrace void hard_local_irq_disable(void)
  151. {
  152. if (!hard_irqs_disabled()) {
  153. __hard_local_irq_disable();
  154. ipipe_trace_begin(0x80000000);
  155. }
  156. }
  157. static inline notrace void hard_local_irq_enable(void)
  158. {
  159. if (hard_irqs_disabled()) {
  160. ipipe_trace_end(0x80000000);
  161. __hard_local_irq_enable();
  162. }
  163. }
  164. static inline notrace unsigned long hard_local_irq_save(void)
  165. {
  166. unsigned long flags = hard_local_save_flags();
  167. if (!hard_irqs_disabled_flags(flags)) {
  168. __hard_local_irq_disable();
  169. ipipe_trace_begin(0x80000001);
  170. }
  171. return flags;
  172. }
  173. static inline notrace void hard_local_irq_restore(unsigned long flags)
  174. {
  175. if (!hard_irqs_disabled_flags(flags)) {
  176. ipipe_trace_end(0x80000001);
  177. __hard_local_irq_enable();
  178. }
  179. }
  180. #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  181. # define hard_local_irq_disable() __hard_local_irq_disable()
  182. # define hard_local_irq_enable() __hard_local_irq_enable()
  183. # define hard_local_irq_save() __hard_local_irq_save()
  184. # define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
  185. #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  186. #define hard_local_irq_save_cond() hard_local_irq_save()
  187. #define hard_local_irq_restore_cond(flags) hard_local_irq_restore(flags)
  188. #else /* !CONFIG_IPIPE */
  189. /*
  190. * Direct interface to linux/irqflags.h.
  191. */
  192. #define arch_local_save_flags() hard_local_save_flags()
  193. #define arch_local_irq_save(flags) __hard_local_irq_save()
  194. #define arch_local_irq_restore(flags) __hard_local_irq_restore(flags)
  195. #define arch_local_irq_enable() __hard_local_irq_enable()
  196. #define arch_local_irq_disable() __hard_local_irq_disable()
  197. #define arch_irqs_disabled_flags(flags) hard_irqs_disabled_flags(flags)
  198. #define arch_irqs_disabled() hard_irqs_disabled()
  199. /*
  200. * Interface to various arch routines that may be traced.
  201. */
  202. #define hard_local_irq_save() __hard_local_irq_save()
  203. #define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
  204. #define hard_local_irq_enable() __hard_local_irq_enable()
  205. #define hard_local_irq_disable() __hard_local_irq_disable()
  206. #define hard_local_irq_save_cond() hard_local_save_flags()
  207. #define hard_local_irq_restore_cond(flags) do { (void)(flags); } while (0)
  208. #endif /* !CONFIG_IPIPE */
  209. #ifdef CONFIG_SMP
  210. #define hard_local_irq_save_smp() hard_local_irq_save()
  211. #define hard_local_irq_restore_smp(flags) hard_local_irq_restore(flags)
  212. #else
  213. #define hard_local_irq_save_smp() hard_local_save_flags()
  214. #define hard_local_irq_restore_smp(flags) do { (void)(flags); } while (0)
  215. #endif
  216. /*
  217. * Remap the arch-neutral IRQ state manipulation macros to the
  218. * blackfin-specific hard_local_irq_* API.
  219. */
  220. #define local_irq_save_hw(flags) \
  221. do { \
  222. (flags) = hard_local_irq_save(); \
  223. } while (0)
  224. #define local_irq_restore_hw(flags) \
  225. do { \
  226. hard_local_irq_restore(flags); \
  227. } while (0)
  228. #define local_irq_disable_hw() \
  229. do { \
  230. hard_local_irq_disable(); \
  231. } while (0)
  232. #define local_irq_enable_hw() \
  233. do { \
  234. hard_local_irq_enable(); \
  235. } while (0)
  236. #define local_irq_save_hw_notrace(flags) \
  237. do { \
  238. (flags) = __hard_local_irq_save(); \
  239. } while (0)
  240. #define local_irq_restore_hw_notrace(flags) \
  241. do { \
  242. __hard_local_irq_restore(flags); \
  243. } while (0)
  244. #define irqs_disabled_hw() hard_irqs_disabled()
  245. #endif