irqflags.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #ifdef CONFIG_SMP
  10. # include <asm/pda.h>
  11. # include <asm/processor.h>
  12. /* Forward decl needed due to cdef inter dependencies */
  13. static inline uint32_t __pure bfin_dspid(void);
  14. # define blackfin_core_id() (bfin_dspid() & 0xff)
  15. # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
  16. #else
  17. extern unsigned long bfin_irq_flags;
  18. #endif
  19. static inline void bfin_sti(unsigned long flags)
  20. {
  21. asm volatile("sti %0;" : : "d" (flags));
  22. }
  23. static inline unsigned long bfin_cli(void)
  24. {
  25. unsigned long flags;
  26. asm volatile("cli %0;" : "=d" (flags));
  27. return flags;
  28. }
  29. #ifdef CONFIG_IPIPE
  30. #include <linux/compiler.h>
  31. #include <linux/ipipe_base.h>
  32. #include <linux/ipipe_trace.h>
  33. #ifdef CONFIG_DEBUG_HWERR
  34. # define bfin_no_irqs 0x3f
  35. #else
  36. # define bfin_no_irqs 0x1f
  37. #endif
  38. #define raw_local_irq_disable() \
  39. do { \
  40. ipipe_check_context(ipipe_root_domain); \
  41. __ipipe_stall_root(); \
  42. barrier(); \
  43. } while (0)
  44. #define raw_local_irq_enable() \
  45. do { \
  46. barrier(); \
  47. ipipe_check_context(ipipe_root_domain); \
  48. __ipipe_unstall_root(); \
  49. } while (0)
  50. #define raw_local_save_flags_ptr(x) \
  51. do { \
  52. *(x) = __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags; \
  53. } while (0)
  54. #define raw_local_save_flags(x) raw_local_save_flags_ptr(&(x))
  55. #define raw_irqs_disabled_flags(x) ((x) == bfin_no_irqs)
  56. #define raw_local_irq_save_ptr(x) \
  57. do { \
  58. *(x) = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags; \
  59. barrier(); \
  60. } while (0)
  61. #define raw_local_irq_save(x) \
  62. do { \
  63. ipipe_check_context(ipipe_root_domain); \
  64. raw_local_irq_save_ptr(&(x)); \
  65. } while (0)
  66. static inline unsigned long raw_mangle_irq_bits(int virt, unsigned long real)
  67. {
  68. /*
  69. * Merge virtual and real interrupt mask bits into a single
  70. * 32bit word.
  71. */
  72. return (real & ~(1 << 31)) | ((virt != 0) << 31);
  73. }
  74. static inline int raw_demangle_irq_bits(unsigned long *x)
  75. {
  76. int virt = (*x & (1 << 31)) != 0;
  77. *x &= ~(1L << 31);
  78. return virt;
  79. }
  80. static inline void local_irq_disable_hw_notrace(void)
  81. {
  82. bfin_cli();
  83. }
  84. static inline void local_irq_enable_hw_notrace(void)
  85. {
  86. bfin_sti(bfin_irq_flags);
  87. }
  88. #define local_save_flags_hw(flags) \
  89. do { \
  90. (flags) = bfin_read_IMASK(); \
  91. } while (0)
  92. #define irqs_disabled_flags_hw(flags) (((flags) & ~0x3f) == 0)
  93. #define irqs_disabled_hw() \
  94. ({ \
  95. unsigned long flags; \
  96. local_save_flags_hw(flags); \
  97. irqs_disabled_flags_hw(flags); \
  98. })
  99. static inline void local_irq_save_ptr_hw(unsigned long *flags)
  100. {
  101. *flags = bfin_cli();
  102. #ifdef CONFIG_DEBUG_HWERR
  103. bfin_sti(0x3f);
  104. #endif
  105. }
  106. #define local_irq_save_hw_notrace(flags) \
  107. do { \
  108. local_irq_save_ptr_hw(&(flags)); \
  109. } while (0)
  110. static inline void local_irq_restore_hw_notrace(unsigned long flags)
  111. {
  112. if (!irqs_disabled_flags_hw(flags))
  113. local_irq_enable_hw_notrace();
  114. }
  115. #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
  116. # define local_irq_disable_hw() \
  117. do { \
  118. if (!irqs_disabled_hw()) { \
  119. local_irq_disable_hw_notrace(); \
  120. ipipe_trace_begin(0x80000000); \
  121. } \
  122. } while (0)
  123. # define local_irq_enable_hw() \
  124. do { \
  125. if (irqs_disabled_hw()) { \
  126. ipipe_trace_end(0x80000000); \
  127. local_irq_enable_hw_notrace(); \
  128. } \
  129. } while (0)
  130. # define local_irq_save_hw(flags) \
  131. do { \
  132. local_save_flags_hw(flags); \
  133. if (!irqs_disabled_flags_hw(flags)) { \
  134. local_irq_disable_hw_notrace(); \
  135. ipipe_trace_begin(0x80000001); \
  136. } \
  137. } while (0)
  138. # define local_irq_restore_hw(flags) \
  139. do { \
  140. if (!irqs_disabled_flags_hw(flags)) { \
  141. ipipe_trace_end(0x80000001); \
  142. local_irq_enable_hw_notrace(); \
  143. } \
  144. } while (0)
  145. #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  146. # define local_irq_disable_hw() local_irq_disable_hw_notrace()
  147. # define local_irq_enable_hw() local_irq_enable_hw_notrace()
  148. # define local_irq_save_hw(flags) local_irq_save_hw_notrace(flags)
  149. # define local_irq_restore_hw(flags) local_irq_restore_hw_notrace(flags)
  150. #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  151. #else /* CONFIG_IPIPE */
  152. static inline void raw_local_irq_disable(void)
  153. {
  154. bfin_cli();
  155. }
  156. static inline void raw_local_irq_enable(void)
  157. {
  158. bfin_sti(bfin_irq_flags);
  159. }
  160. #define raw_local_save_flags(flags) do { (flags) = bfin_read_IMASK(); } while (0)
  161. #define raw_irqs_disabled_flags(flags) (((flags) & ~0x3f) == 0)
  162. static inline unsigned long __raw_local_irq_save(void)
  163. {
  164. unsigned long flags = bfin_cli();
  165. #ifdef CONFIG_DEBUG_HWERR
  166. bfin_sti(0x3f);
  167. #endif
  168. return flags;
  169. }
  170. #define raw_local_irq_save(flags) do { (flags) = __raw_local_irq_save(); } while (0)
  171. #define local_irq_save_hw(flags) raw_local_irq_save(flags)
  172. #define local_irq_restore_hw(flags) raw_local_irq_restore(flags)
  173. #define local_irq_enable_hw() raw_local_irq_enable()
  174. #define local_irq_disable_hw() raw_local_irq_disable()
  175. #define irqs_disabled_hw() irqs_disabled()
  176. #endif /* !CONFIG_IPIPE */
  177. static inline void raw_local_irq_restore(unsigned long flags)
  178. {
  179. if (!raw_irqs_disabled_flags(flags))
  180. raw_local_irq_enable();
  181. }
  182. #endif