irqflags.h 5.0 KB

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