irqflags.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 void bfin_sti(unsigned long flags)
  18. {
  19. asm volatile("sti %0;" : : "d" (flags));
  20. }
  21. static inline 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 void __hard_local_irq_disable(void)
  37. {
  38. bfin_cli();
  39. }
  40. static inline void __hard_local_irq_enable(void)
  41. {
  42. bfin_sti(bfin_irq_flags);
  43. }
  44. static inline unsigned long hard_local_save_flags(void)
  45. {
  46. return bfin_read_IMASK();
  47. }
  48. static inline 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 int hard_irqs_disabled_flags(unsigned long flags)
  58. {
  59. return (flags & ~0x3f) == 0;
  60. }
  61. static inline 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 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_base.h>
  78. #include <linux/ipipe_trace.h>
  79. /*
  80. * Interrupt pipe interface to linux/irqflags.h.
  81. */
  82. static inline void arch_local_irq_disable(void)
  83. {
  84. ipipe_check_context(ipipe_root_domain);
  85. __ipipe_stall_root();
  86. barrier();
  87. }
  88. static inline void arch_local_irq_enable(void)
  89. {
  90. barrier();
  91. ipipe_check_context(ipipe_root_domain);
  92. __ipipe_unstall_root();
  93. }
  94. static inline unsigned long arch_local_save_flags(void)
  95. {
  96. return __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags;
  97. }
  98. static inline int arch_irqs_disabled_flags(unsigned long flags)
  99. {
  100. return flags == bfin_no_irqs;
  101. }
  102. static inline void arch_local_irq_save_ptr(unsigned long *_flags)
  103. {
  104. x = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags;
  105. barrier();
  106. }
  107. static inline unsigned long arch_local_irq_save(void)
  108. {
  109. ipipe_check_context(ipipe_root_domain);
  110. return __hard_local_irq_save();
  111. }
  112. static inline unsigned long arch_mangle_irq_bits(int virt, unsigned long real)
  113. {
  114. /*
  115. * Merge virtual and real interrupt mask bits into a single
  116. * 32bit word.
  117. */
  118. return (real & ~(1 << 31)) | ((virt != 0) << 31);
  119. }
  120. static inline int arch_demangle_irq_bits(unsigned long *x)
  121. {
  122. int virt = (*x & (1 << 31)) != 0;
  123. *x &= ~(1L << 31);
  124. return virt;
  125. }
  126. /*
  127. * Interface to various arch routines that may be traced.
  128. */
  129. #ifdef CONFIG_IPIPE_TRACE_IRQSOFF
  130. static inline void hard_local_irq_disable(void)
  131. {
  132. if (!hard_irqs_disabled()) {
  133. __hard_local_irq_disable();
  134. ipipe_trace_begin(0x80000000);
  135. }
  136. }
  137. static inline void hard_local_irq_enable(void)
  138. {
  139. if (hard_irqs_disabled()) {
  140. ipipe_trace_end(0x80000000);
  141. __hard_local_irq_enable();
  142. }
  143. }
  144. static inline unsigned long hard_local_irq_save(void)
  145. {
  146. unsigned long flags = hard_local_save_flags();
  147. if (!hard_irqs_disabled_flags(flags)) {
  148. __hard_local_irq_disable();
  149. ipipe_trace_begin(0x80000001);
  150. }
  151. return flags;
  152. }
  153. static inline void hard_local_irq_restore(unsigned long flags)
  154. {
  155. if (!hard_irqs_disabled_flags(flags)) {
  156. ipipe_trace_end(0x80000001);
  157. __hard_local_irq_enable();
  158. }
  159. }
  160. #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  161. # define hard_local_irq_disable() __hard_local_irq_disable()
  162. # define hard_local_irq_enable() __hard_local_irq_enable()
  163. # define hard_local_irq_save() __hard_local_irq_save()
  164. # define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
  165. #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
  166. #else /* CONFIG_IPIPE */
  167. /*
  168. * Direct interface to linux/irqflags.h.
  169. */
  170. #define arch_local_save_flags() hard_local_save_flags()
  171. #define arch_local_irq_save(flags) __hard_local_irq_save()
  172. #define arch_local_irq_restore(flags) __hard_local_irq_restore(flags)
  173. #define arch_local_irq_enable() __hard_local_irq_enable()
  174. #define arch_local_irq_disable() __hard_local_irq_disable()
  175. #define arch_irqs_disabled_flags(flags) hard_irqs_disabled_flags(flags)
  176. #define arch_irqs_disabled() hard_irqs_disabled()
  177. /*
  178. * Interface to various arch routines that may be traced.
  179. */
  180. #define hard_local_irq_save() __hard_local_irq_save()
  181. #define hard_local_irq_restore(flags) __hard_local_irq_restore(flags)
  182. #define hard_local_irq_enable() __hard_local_irq_enable()
  183. #define hard_local_irq_disable() __hard_local_irq_disable()
  184. #endif /* !CONFIG_IPIPE */
  185. #endif