irqflags.h 8.8 KB

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