irqflags.h 10 KB

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