irqflags.h 9.2 KB

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