irqflags.h 9.8 KB

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