irqflags.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. #ifdef CONFIG_DEBUG_PREEMPT
  119. /* Due to inclusion issues, we can't rely on <linux/smp.h> here. */
  120. extern unsigned int debug_smp_processor_id(void);
  121. # define smp_processor_id() debug_smp_processor_id()
  122. #endif
  123. /* Disable interrupts. */
  124. #define arch_local_irq_disable() \
  125. interrupt_mask_set_mask(LINUX_MASKABLE_INTERRUPTS)
  126. /* Disable all interrupts, including NMIs. */
  127. #define arch_local_irq_disable_all() \
  128. interrupt_mask_set_mask(-1ULL)
  129. /*
  130. * Read the set of maskable interrupts.
  131. * We avoid the preemption warning here via raw_cpu_ptr since even
  132. * if irqs are already enabled, it's harmless to read the wrong cpu's
  133. * enabled mask.
  134. */
  135. #define arch_local_irqs_enabled() \
  136. (*raw_cpu_ptr(&interrupts_enabled_mask))
  137. /* Re-enable all maskable interrupts. */
  138. #define arch_local_irq_enable() \
  139. interrupt_mask_reset_mask(arch_local_irqs_enabled())
  140. /* Disable or enable interrupts based on flag argument. */
  141. #define arch_local_irq_restore(disabled) do { \
  142. if (disabled) \
  143. arch_local_irq_disable(); \
  144. else \
  145. arch_local_irq_enable(); \
  146. } while (0)
  147. /* Return true if "flags" argument means interrupts are disabled. */
  148. #define arch_irqs_disabled_flags(flags) ((flags) != 0)
  149. /* Return true if interrupts are currently disabled. */
  150. #define arch_irqs_disabled() interrupt_mask_check(INT_MEM_ERROR)
  151. /* Save whether interrupts are currently disabled. */
  152. #define arch_local_save_flags() arch_irqs_disabled()
  153. /* Save whether interrupts are currently disabled, then disable them. */
  154. #define arch_local_irq_save() ({ \
  155. unsigned long __flags = arch_local_save_flags(); \
  156. arch_local_irq_disable(); \
  157. __flags; })
  158. /* Prevent the given interrupt from being enabled next time we enable irqs. */
  159. #define arch_local_irq_mask(interrupt) \
  160. this_cpu_and(interrupts_enabled_mask, ~(1ULL << (interrupt)))
  161. /* Prevent the given interrupt from being enabled immediately. */
  162. #define arch_local_irq_mask_now(interrupt) do { \
  163. arch_local_irq_mask(interrupt); \
  164. interrupt_mask_set(interrupt); \
  165. } while (0)
  166. /* Allow the given interrupt to be enabled next time we enable irqs. */
  167. #define arch_local_irq_unmask(interrupt) \
  168. this_cpu_or(interrupts_enabled_mask, (1ULL << (interrupt)))
  169. /* Allow the given interrupt to be enabled immediately, if !irqs_disabled. */
  170. #define arch_local_irq_unmask_now(interrupt) do { \
  171. arch_local_irq_unmask(interrupt); \
  172. if (!irqs_disabled()) \
  173. interrupt_mask_reset(interrupt); \
  174. } while (0)
  175. #else /* __ASSEMBLY__ */
  176. /* We provide a somewhat more restricted set for assembly. */
  177. #ifdef __tilegx__
  178. #if INT_MEM_ERROR != 0
  179. # error Fix IRQS_DISABLED() macro
  180. #endif
  181. /* Return 0 or 1 to indicate whether interrupts are currently disabled. */
  182. #define IRQS_DISABLED(tmp) \
  183. mfspr tmp, SPR_INTERRUPT_MASK_K; \
  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, hw2_last(interrupts_enabled_mask); \
  188. shl16insli reg, reg, hw1(interrupts_enabled_mask); \
  189. shl16insli reg, reg, hw0(interrupts_enabled_mask); \
  190. add reg, reg, tp
  191. /* Disable interrupts. */
  192. #define IRQ_DISABLE(tmp0, tmp1) \
  193. moveli tmp0, hw2_last(LINUX_MASKABLE_INTERRUPTS); \
  194. shl16insli tmp0, tmp0, hw1(LINUX_MASKABLE_INTERRUPTS); \
  195. shl16insli tmp0, tmp0, hw0(LINUX_MASKABLE_INTERRUPTS); \
  196. mtspr SPR_INTERRUPT_MASK_SET_K, tmp0
  197. /* Disable ALL synchronous interrupts (used by NMI entry). */
  198. #define IRQ_DISABLE_ALL(tmp) \
  199. movei tmp, -1; \
  200. mtspr SPR_INTERRUPT_MASK_SET_K, tmp
  201. /* Enable interrupts. */
  202. #define IRQ_ENABLE_LOAD(tmp0, tmp1) \
  203. GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
  204. ld tmp0, tmp0
  205. #define IRQ_ENABLE_APPLY(tmp0, tmp1) \
  206. mtspr SPR_INTERRUPT_MASK_RESET_K, tmp0
  207. #else /* !__tilegx__ */
  208. /*
  209. * Return 0 or 1 to indicate whether interrupts are currently disabled.
  210. * Note that it's important that we use a bit from the "low" mask word,
  211. * since when we are enabling, that is the word we write first, so if we
  212. * are interrupted after only writing half of the mask, the interrupt
  213. * handler will correctly observe that we have interrupts enabled, and
  214. * will enable interrupts itself on return from the interrupt handler
  215. * (making the original code's write of the "high" mask word idempotent).
  216. */
  217. #define IRQS_DISABLED(tmp) \
  218. mfspr tmp, SPR_INTERRUPT_MASK_K_0; \
  219. shri tmp, tmp, INT_MEM_ERROR; \
  220. andi tmp, tmp, 1
  221. /* Load up a pointer to &interrupts_enabled_mask. */
  222. #define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
  223. moveli reg, lo16(interrupts_enabled_mask); \
  224. auli reg, reg, ha16(interrupts_enabled_mask); \
  225. add reg, reg, tp
  226. /* Disable interrupts. */
  227. #define IRQ_DISABLE(tmp0, tmp1) \
  228. { \
  229. movei tmp0, LINUX_MASKABLE_INTERRUPTS_LO; \
  230. moveli tmp1, lo16(LINUX_MASKABLE_INTERRUPTS_HI) \
  231. }; \
  232. { \
  233. mtspr SPR_INTERRUPT_MASK_SET_K_0, tmp0; \
  234. auli tmp1, tmp1, ha16(LINUX_MASKABLE_INTERRUPTS_HI) \
  235. }; \
  236. mtspr SPR_INTERRUPT_MASK_SET_K_1, tmp1
  237. /* Disable ALL synchronous interrupts (used by NMI entry). */
  238. #define IRQ_DISABLE_ALL(tmp) \
  239. movei tmp, -1; \
  240. mtspr SPR_INTERRUPT_MASK_SET_K_0, tmp; \
  241. mtspr SPR_INTERRUPT_MASK_SET_K_1, tmp
  242. /* Enable interrupts. */
  243. #define IRQ_ENABLE_LOAD(tmp0, tmp1) \
  244. GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
  245. { \
  246. lw tmp0, tmp0; \
  247. addi tmp1, tmp0, 4 \
  248. }; \
  249. lw tmp1, tmp1
  250. #define IRQ_ENABLE_APPLY(tmp0, tmp1) \
  251. mtspr SPR_INTERRUPT_MASK_RESET_K_0, tmp0; \
  252. mtspr SPR_INTERRUPT_MASK_RESET_K_1, tmp1
  253. #endif
  254. #define IRQ_ENABLE(tmp0, tmp1) \
  255. IRQ_ENABLE_LOAD(tmp0, tmp1); \
  256. IRQ_ENABLE_APPLY(tmp0, tmp1)
  257. /*
  258. * Do the CPU's IRQ-state tracing from assembly code. We call a
  259. * C function, but almost everywhere we do, we don't mind clobbering
  260. * all the caller-saved registers.
  261. */
  262. #ifdef CONFIG_TRACE_IRQFLAGS
  263. # define TRACE_IRQS_ON jal trace_hardirqs_on
  264. # define TRACE_IRQS_OFF jal trace_hardirqs_off
  265. #else
  266. # define TRACE_IRQS_ON
  267. # define TRACE_IRQS_OFF
  268. #endif
  269. #endif /* __ASSEMBLY__ */
  270. #endif /* _ASM_TILE_IRQFLAGS_H */