irqflags.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_IRQFLAGS_H
  15. #define _ASM_TILE_IRQFLAGS_H
  16. #include <arch/interrupts.h>
  17. #include <arch/chip.h>
  18. /*
  19. * The set of interrupts we want to allow when interrupts are nominally
  20. * disabled. The remainder are effectively "NMI" interrupts from
  21. * the point of view of the generic Linux code. Note that synchronous
  22. * interrupts (aka "non-queued") are not blocked by the mask in any case.
  23. */
  24. #if CHIP_HAS_AUX_PERF_COUNTERS()
  25. #define LINUX_MASKABLE_INTERRUPTS \
  26. (~(INT_MASK(INT_PERF_COUNT) | INT_MASK(INT_AUX_PERF_COUNT)))
  27. #else
  28. #define LINUX_MASKABLE_INTERRUPTS \
  29. (~(INT_MASK(INT_PERF_COUNT)))
  30. #endif
  31. #ifndef __ASSEMBLY__
  32. /* NOTE: we can't include <linux/percpu.h> due to #include dependencies. */
  33. #include <asm/percpu.h>
  34. #include <arch/spr_def.h>
  35. /* Set and clear kernel interrupt masks. */
  36. #if CHIP_HAS_SPLIT_INTR_MASK()
  37. #if INT_PERF_COUNT < 32 || INT_AUX_PERF_COUNT < 32 || INT_MEM_ERROR >= 32
  38. # error Fix assumptions about which word various interrupts are in
  39. #endif
  40. #define interrupt_mask_set(n) do { \
  41. int __n = (n); \
  42. int __mask = 1 << (__n & 0x1f); \
  43. if (__n < 32) \
  44. __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_0, __mask); \
  45. else \
  46. __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_1, __mask); \
  47. } while (0)
  48. #define interrupt_mask_reset(n) do { \
  49. int __n = (n); \
  50. int __mask = 1 << (__n & 0x1f); \
  51. if (__n < 32) \
  52. __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_0, __mask); \
  53. else \
  54. __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_1, __mask); \
  55. } while (0)
  56. #define interrupt_mask_check(n) ({ \
  57. int __n = (n); \
  58. (((__n < 32) ? \
  59. __insn_mfspr(SPR_INTERRUPT_MASK_1_0) : \
  60. __insn_mfspr(SPR_INTERRUPT_MASK_1_1)) \
  61. >> (__n & 0x1f)) & 1; \
  62. })
  63. #define interrupt_mask_set_mask(mask) do { \
  64. unsigned long long __m = (mask); \
  65. __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_0, (unsigned long)(__m)); \
  66. __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_1, (unsigned long)(__m>>32)); \
  67. } while (0)
  68. #define interrupt_mask_reset_mask(mask) do { \
  69. unsigned long long __m = (mask); \
  70. __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_0, (unsigned long)(__m)); \
  71. __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_1, (unsigned long)(__m>>32)); \
  72. } while (0)
  73. #else
  74. #define interrupt_mask_set(n) \
  75. __insn_mtspr(SPR_INTERRUPT_MASK_SET_1, (1UL << (n)))
  76. #define interrupt_mask_reset(n) \
  77. __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1, (1UL << (n)))
  78. #define interrupt_mask_check(n) \
  79. ((__insn_mfspr(SPR_INTERRUPT_MASK_1) >> (n)) & 1)
  80. #define interrupt_mask_set_mask(mask) \
  81. __insn_mtspr(SPR_INTERRUPT_MASK_SET_1, (mask))
  82. #define interrupt_mask_reset_mask(mask) \
  83. __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1, (mask))
  84. #endif
  85. /*
  86. * The set of interrupts we want active if irqs are enabled.
  87. * Note that in particular, the tile timer interrupt comes and goes
  88. * from this set, since we have no other way to turn off the timer.
  89. * Likewise, INTCTRL_1 is removed and re-added during device
  90. * interrupts, as is the the hardwall UDN_FIREWALL interrupt.
  91. * We use a low bit (MEM_ERROR) as our sentinel value and make sure it
  92. * is always claimed as an "active interrupt" so we can query that bit
  93. * to know our current state.
  94. */
  95. DECLARE_PER_CPU(unsigned long long, interrupts_enabled_mask);
  96. #define INITIAL_INTERRUPTS_ENABLED INT_MASK(INT_MEM_ERROR)
  97. /* Disable interrupts. */
  98. #define raw_local_irq_disable() \
  99. interrupt_mask_set_mask(LINUX_MASKABLE_INTERRUPTS)
  100. /* Disable all interrupts, including NMIs. */
  101. #define raw_local_irq_disable_all() \
  102. interrupt_mask_set_mask(-1UL)
  103. /* Re-enable all maskable interrupts. */
  104. #define raw_local_irq_enable() \
  105. interrupt_mask_reset_mask(__get_cpu_var(interrupts_enabled_mask))
  106. /* Disable or enable interrupts based on flag argument. */
  107. #define raw_local_irq_restore(disabled) do { \
  108. if (disabled) \
  109. raw_local_irq_disable(); \
  110. else \
  111. raw_local_irq_enable(); \
  112. } while (0)
  113. /* Return true if "flags" argument means interrupts are disabled. */
  114. #define raw_irqs_disabled_flags(flags) ((flags) != 0)
  115. /* Return true if interrupts are currently disabled. */
  116. #define raw_irqs_disabled() interrupt_mask_check(INT_MEM_ERROR)
  117. /* Save whether interrupts are currently disabled. */
  118. #define raw_local_save_flags(flags) ((flags) = raw_irqs_disabled())
  119. /* Save whether interrupts are currently disabled, then disable them. */
  120. #define raw_local_irq_save(flags) \
  121. do { raw_local_save_flags(flags); raw_local_irq_disable(); } while (0)
  122. /* Prevent the given interrupt from being enabled next time we enable irqs. */
  123. #define raw_local_irq_mask(interrupt) \
  124. (__get_cpu_var(interrupts_enabled_mask) &= ~INT_MASK(interrupt))
  125. /* Prevent the given interrupt from being enabled immediately. */
  126. #define raw_local_irq_mask_now(interrupt) do { \
  127. raw_local_irq_mask(interrupt); \
  128. interrupt_mask_set(interrupt); \
  129. } while (0)
  130. /* Allow the given interrupt to be enabled next time we enable irqs. */
  131. #define raw_local_irq_unmask(interrupt) \
  132. (__get_cpu_var(interrupts_enabled_mask) |= INT_MASK(interrupt))
  133. /* Allow the given interrupt to be enabled immediately, if !irqs_disabled. */
  134. #define raw_local_irq_unmask_now(interrupt) do { \
  135. raw_local_irq_unmask(interrupt); \
  136. if (!irqs_disabled()) \
  137. interrupt_mask_reset(interrupt); \
  138. } while (0)
  139. #else /* __ASSEMBLY__ */
  140. /* We provide a somewhat more restricted set for assembly. */
  141. #ifdef __tilegx__
  142. #if INT_MEM_ERROR != 0
  143. # error Fix IRQ_DISABLED() macro
  144. #endif
  145. /* Return 0 or 1 to indicate whether interrupts are currently disabled. */
  146. #define IRQS_DISABLED(tmp) \
  147. mfspr tmp, INTERRUPT_MASK_1; \
  148. andi tmp, tmp, 1
  149. /* Load up a pointer to &interrupts_enabled_mask. */
  150. #define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
  151. moveli reg, hw2_last(interrupts_enabled_mask); \
  152. shl16insli reg, reg, hw1(interrupts_enabled_mask); \
  153. shl16insli reg, reg, hw0(interrupts_enabled_mask); \
  154. add reg, reg, tp
  155. /* Disable interrupts. */
  156. #define IRQ_DISABLE(tmp0, tmp1) \
  157. moveli tmp0, hw2_last(LINUX_MASKABLE_INTERRUPTS); \
  158. shl16insli tmp0, tmp0, hw1(LINUX_MASKABLE_INTERRUPTS); \
  159. shl16insli tmp0, tmp0, hw0(LINUX_MASKABLE_INTERRUPTS); \
  160. mtspr INTERRUPT_MASK_SET_1, tmp0
  161. /* Disable ALL synchronous interrupts (used by NMI entry). */
  162. #define IRQ_DISABLE_ALL(tmp) \
  163. movei tmp, -1; \
  164. mtspr INTERRUPT_MASK_SET_1, tmp
  165. /* Enable interrupts. */
  166. #define IRQ_ENABLE(tmp0, tmp1) \
  167. GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
  168. ld tmp0, tmp0; \
  169. mtspr INTERRUPT_MASK_RESET_1, tmp0
  170. #else /* !__tilegx__ */
  171. /*
  172. * Return 0 or 1 to indicate whether interrupts are currently disabled.
  173. * Note that it's important that we use a bit from the "low" mask word,
  174. * since when we are enabling, that is the word we write first, so if we
  175. * are interrupted after only writing half of the mask, the interrupt
  176. * handler will correctly observe that we have interrupts enabled, and
  177. * will enable interrupts itself on return from the interrupt handler
  178. * (making the original code's write of the "high" mask word idempotent).
  179. */
  180. #define IRQS_DISABLED(tmp) \
  181. mfspr tmp, INTERRUPT_MASK_1_0; \
  182. shri tmp, tmp, INT_MEM_ERROR; \
  183. andi tmp, tmp, 1
  184. /* Load up a pointer to &interrupts_enabled_mask. */
  185. #define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
  186. moveli reg, lo16(interrupts_enabled_mask); \
  187. auli reg, reg, ha16(interrupts_enabled_mask);\
  188. add reg, reg, tp
  189. /* Disable interrupts. */
  190. #define IRQ_DISABLE(tmp0, tmp1) \
  191. { \
  192. movei tmp0, -1; \
  193. moveli tmp1, lo16(LINUX_MASKABLE_INTERRUPTS) \
  194. }; \
  195. { \
  196. mtspr INTERRUPT_MASK_SET_1_0, tmp0; \
  197. auli tmp1, tmp1, ha16(LINUX_MASKABLE_INTERRUPTS) \
  198. }; \
  199. mtspr INTERRUPT_MASK_SET_1_1, tmp1
  200. /* Disable ALL synchronous interrupts (used by NMI entry). */
  201. #define IRQ_DISABLE_ALL(tmp) \
  202. movei tmp, -1; \
  203. mtspr INTERRUPT_MASK_SET_1_0, tmp; \
  204. mtspr INTERRUPT_MASK_SET_1_1, tmp
  205. /* Enable interrupts. */
  206. #define IRQ_ENABLE(tmp0, tmp1) \
  207. GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
  208. { \
  209. lw tmp0, tmp0; \
  210. addi tmp1, tmp0, 4 \
  211. }; \
  212. lw tmp1, tmp1; \
  213. mtspr INTERRUPT_MASK_RESET_1_0, tmp0; \
  214. mtspr INTERRUPT_MASK_RESET_1_1, tmp1
  215. #endif
  216. /*
  217. * Do the CPU's IRQ-state tracing from assembly code. We call a
  218. * C function, but almost everywhere we do, we don't mind clobbering
  219. * all the caller-saved registers.
  220. */
  221. #ifdef CONFIG_TRACE_IRQFLAGS
  222. # define TRACE_IRQS_ON jal trace_hardirqs_on
  223. # define TRACE_IRQS_OFF jal trace_hardirqs_off
  224. #else
  225. # define TRACE_IRQS_ON
  226. # define TRACE_IRQS_OFF
  227. #endif
  228. #endif /* __ASSEMBLY__ */
  229. #endif /* _ASM_TILE_IRQFLAGS_H */