irqflags.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 arch_local_irq_disable() \
  99. interrupt_mask_set_mask(LINUX_MASKABLE_INTERRUPTS)
  100. /* Disable all interrupts, including NMIs. */
  101. #define arch_local_irq_disable_all() \
  102. interrupt_mask_set_mask(-1UL)
  103. /* Re-enable all maskable interrupts. */
  104. #define arch_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 arch_local_irq_restore(disabled) do { \
  108. if (disabled) \
  109. arch_local_irq_disable(); \
  110. else \
  111. arch_local_irq_enable(); \
  112. } while (0)
  113. /* Return true if "flags" argument means interrupts are disabled. */
  114. #define arch_irqs_disabled_flags(flags) ((flags) != 0)
  115. /* Return true if interrupts are currently disabled. */
  116. #define arch_irqs_disabled() interrupt_mask_check(INT_MEM_ERROR)
  117. /* Save whether interrupts are currently disabled. */
  118. #define arch_local_save_flags() arch_irqs_disabled()
  119. /* Save whether interrupts are currently disabled, then disable them. */
  120. #define arch_local_irq_save() ({ \
  121. unsigned long __flags = arch_local_save_flags(); \
  122. arch_local_irq_disable(); \
  123. __flags; })
  124. /* Prevent the given interrupt from being enabled next time we enable irqs. */
  125. #define arch_local_irq_mask(interrupt) \
  126. (__get_cpu_var(interrupts_enabled_mask) &= ~INT_MASK(interrupt))
  127. /* Prevent the given interrupt from being enabled immediately. */
  128. #define arch_local_irq_mask_now(interrupt) do { \
  129. arch_local_irq_mask(interrupt); \
  130. interrupt_mask_set(interrupt); \
  131. } while (0)
  132. /* Allow the given interrupt to be enabled next time we enable irqs. */
  133. #define arch_local_irq_unmask(interrupt) \
  134. (__get_cpu_var(interrupts_enabled_mask) |= INT_MASK(interrupt))
  135. /* Allow the given interrupt to be enabled immediately, if !irqs_disabled. */
  136. #define arch_local_irq_unmask_now(interrupt) do { \
  137. arch_local_irq_unmask(interrupt); \
  138. if (!irqs_disabled()) \
  139. interrupt_mask_reset(interrupt); \
  140. } while (0)
  141. #else /* __ASSEMBLY__ */
  142. /* We provide a somewhat more restricted set for assembly. */
  143. #ifdef __tilegx__
  144. #if INT_MEM_ERROR != 0
  145. # error Fix IRQ_DISABLED() macro
  146. #endif
  147. /* Return 0 or 1 to indicate whether interrupts are currently disabled. */
  148. #define IRQS_DISABLED(tmp) \
  149. mfspr tmp, INTERRUPT_MASK_1; \
  150. andi tmp, tmp, 1
  151. /* Load up a pointer to &interrupts_enabled_mask. */
  152. #define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
  153. moveli reg, hw2_last(interrupts_enabled_mask); \
  154. shl16insli reg, reg, hw1(interrupts_enabled_mask); \
  155. shl16insli reg, reg, hw0(interrupts_enabled_mask); \
  156. add reg, reg, tp
  157. /* Disable interrupts. */
  158. #define IRQ_DISABLE(tmp0, tmp1) \
  159. moveli tmp0, hw2_last(LINUX_MASKABLE_INTERRUPTS); \
  160. shl16insli tmp0, tmp0, hw1(LINUX_MASKABLE_INTERRUPTS); \
  161. shl16insli tmp0, tmp0, hw0(LINUX_MASKABLE_INTERRUPTS); \
  162. mtspr INTERRUPT_MASK_SET_1, tmp0
  163. /* Disable ALL synchronous interrupts (used by NMI entry). */
  164. #define IRQ_DISABLE_ALL(tmp) \
  165. movei tmp, -1; \
  166. mtspr INTERRUPT_MASK_SET_1, tmp
  167. /* Enable interrupts. */
  168. #define IRQ_ENABLE(tmp0, tmp1) \
  169. GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
  170. ld tmp0, tmp0; \
  171. mtspr INTERRUPT_MASK_RESET_1, tmp0
  172. #else /* !__tilegx__ */
  173. /*
  174. * Return 0 or 1 to indicate whether interrupts are currently disabled.
  175. * Note that it's important that we use a bit from the "low" mask word,
  176. * since when we are enabling, that is the word we write first, so if we
  177. * are interrupted after only writing half of the mask, the interrupt
  178. * handler will correctly observe that we have interrupts enabled, and
  179. * will enable interrupts itself on return from the interrupt handler
  180. * (making the original code's write of the "high" mask word idempotent).
  181. */
  182. #define IRQS_DISABLED(tmp) \
  183. mfspr tmp, INTERRUPT_MASK_1_0; \
  184. shri tmp, tmp, INT_MEM_ERROR; \
  185. andi tmp, tmp, 1
  186. /* Load up a pointer to &interrupts_enabled_mask. */
  187. #define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
  188. moveli reg, lo16(interrupts_enabled_mask); \
  189. auli reg, reg, ha16(interrupts_enabled_mask);\
  190. add reg, reg, tp
  191. /* Disable interrupts. */
  192. #define IRQ_DISABLE(tmp0, tmp1) \
  193. { \
  194. movei tmp0, -1; \
  195. moveli tmp1, lo16(LINUX_MASKABLE_INTERRUPTS) \
  196. }; \
  197. { \
  198. mtspr INTERRUPT_MASK_SET_1_0, tmp0; \
  199. auli tmp1, tmp1, ha16(LINUX_MASKABLE_INTERRUPTS) \
  200. }; \
  201. mtspr INTERRUPT_MASK_SET_1_1, tmp1
  202. /* Disable ALL synchronous interrupts (used by NMI entry). */
  203. #define IRQ_DISABLE_ALL(tmp) \
  204. movei tmp, -1; \
  205. mtspr INTERRUPT_MASK_SET_1_0, tmp; \
  206. mtspr INTERRUPT_MASK_SET_1_1, tmp
  207. /* Enable interrupts. */
  208. #define IRQ_ENABLE(tmp0, tmp1) \
  209. GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
  210. { \
  211. lw tmp0, tmp0; \
  212. addi tmp1, tmp0, 4 \
  213. }; \
  214. lw tmp1, tmp1; \
  215. mtspr INTERRUPT_MASK_RESET_1_0, tmp0; \
  216. mtspr INTERRUPT_MASK_RESET_1_1, tmp1
  217. #endif
  218. /*
  219. * Do the CPU's IRQ-state tracing from assembly code. We call a
  220. * C function, but almost everywhere we do, we don't mind clobbering
  221. * all the caller-saved registers.
  222. */
  223. #ifdef CONFIG_TRACE_IRQFLAGS
  224. # define TRACE_IRQS_ON jal trace_hardirqs_on
  225. # define TRACE_IRQS_OFF jal trace_hardirqs_off
  226. #else
  227. # define TRACE_IRQS_ON
  228. # define TRACE_IRQS_OFF
  229. #endif
  230. #endif /* __ASSEMBLY__ */
  231. #endif /* _ASM_TILE_IRQFLAGS_H */