2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
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.
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
15 #ifndef _ASM_TILE_IRQFLAGS_H
16 #define _ASM_TILE_IRQFLAGS_H
18 #include <asm/processor.h>
19 #include <arch/interrupts.h>
20 #include <arch/chip.h>
23 * The set of interrupts we want to allow when interrupts are nominally
24 * disabled. The remainder are effectively "NMI" interrupts from
25 * the point of view of the generic Linux code. Note that synchronous
26 * interrupts (aka "non-queued") are not blocked by the mask in any case.
28 #if CHIP_HAS_AUX_PERF_COUNTERS()
29 #define LINUX_MASKABLE_INTERRUPTS \
30 (~(INT_MASK(INT_PERF_COUNT) | INT_MASK(INT_AUX_PERF_COUNT)))
32 #define LINUX_MASKABLE_INTERRUPTS \
33 (~(INT_MASK(INT_PERF_COUNT)))
38 /* NOTE: we can't include <linux/percpu.h> due to #include dependencies. */
39 #include <asm/percpu.h>
40 #include <arch/spr_def.h>
42 /* Set and clear kernel interrupt masks. */
43 #if CHIP_HAS_SPLIT_INTR_MASK()
44 #if INT_PERF_COUNT < 32 || INT_AUX_PERF_COUNT < 32 || INT_MEM_ERROR >= 32
45 # error Fix assumptions about which word various interrupts are in
47 #define interrupt_mask_set(n) do { \
49 int __mask = 1 << (__n & 0x1f); \
51 __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_0, __mask); \
53 __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_1, __mask); \
55 #define interrupt_mask_reset(n) do { \
57 int __mask = 1 << (__n & 0x1f); \
59 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_0, __mask); \
61 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_1, __mask); \
63 #define interrupt_mask_check(n) ({ \
66 __insn_mfspr(SPR_INTERRUPT_MASK_1_0) : \
67 __insn_mfspr(SPR_INTERRUPT_MASK_1_1)) \
68 >> (__n & 0x1f)) & 1; \
70 #define interrupt_mask_set_mask(mask) do { \
71 unsigned long long __m = (mask); \
72 __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_0, (unsigned long)(__m)); \
73 __insn_mtspr(SPR_INTERRUPT_MASK_SET_1_1, (unsigned long)(__m>>32)); \
75 #define interrupt_mask_reset_mask(mask) do { \
76 unsigned long long __m = (mask); \
77 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_0, (unsigned long)(__m)); \
78 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1_1, (unsigned long)(__m>>32)); \
81 #define interrupt_mask_set(n) \
82 __insn_mtspr(SPR_INTERRUPT_MASK_SET_1, (1UL << (n)))
83 #define interrupt_mask_reset(n) \
84 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1, (1UL << (n)))
85 #define interrupt_mask_check(n) \
86 ((__insn_mfspr(SPR_INTERRUPT_MASK_1) >> (n)) & 1)
87 #define interrupt_mask_set_mask(mask) \
88 __insn_mtspr(SPR_INTERRUPT_MASK_SET_1, (mask))
89 #define interrupt_mask_reset_mask(mask) \
90 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_1, (mask))
94 * The set of interrupts we want active if irqs are enabled.
95 * Note that in particular, the tile timer interrupt comes and goes
96 * from this set, since we have no other way to turn off the timer.
97 * Likewise, INTCTRL_1 is removed and re-added during device
98 * interrupts, as is the the hardwall UDN_FIREWALL interrupt.
99 * We use a low bit (MEM_ERROR) as our sentinel value and make sure it
100 * is always claimed as an "active interrupt" so we can query that bit
101 * to know our current state.
103 DECLARE_PER_CPU(unsigned long long, interrupts_enabled_mask
);
104 #define INITIAL_INTERRUPTS_ENABLED INT_MASK(INT_MEM_ERROR)
106 /* Disable interrupts. */
107 #define raw_local_irq_disable() \
108 interrupt_mask_set_mask(LINUX_MASKABLE_INTERRUPTS)
110 /* Disable all interrupts, including NMIs. */
111 #define raw_local_irq_disable_all() \
112 interrupt_mask_set_mask(-1UL)
114 /* Re-enable all maskable interrupts. */
115 #define raw_local_irq_enable() \
116 interrupt_mask_reset_mask(__get_cpu_var(interrupts_enabled_mask))
118 /* Disable or enable interrupts based on flag argument. */
119 #define raw_local_irq_restore(disabled) do { \
121 raw_local_irq_disable(); \
123 raw_local_irq_enable(); \
126 /* Return true if "flags" argument means interrupts are disabled. */
127 #define raw_irqs_disabled_flags(flags) ((flags) != 0)
129 /* Return true if interrupts are currently disabled. */
130 #define raw_irqs_disabled() interrupt_mask_check(INT_MEM_ERROR)
132 /* Save whether interrupts are currently disabled. */
133 #define raw_local_save_flags(flags) ((flags) = raw_irqs_disabled())
135 /* Save whether interrupts are currently disabled, then disable them. */
136 #define raw_local_irq_save(flags) \
137 do { raw_local_save_flags(flags); raw_local_irq_disable(); } while (0)
139 /* Prevent the given interrupt from being enabled next time we enable irqs. */
140 #define raw_local_irq_mask(interrupt) \
141 (__get_cpu_var(interrupts_enabled_mask) &= ~INT_MASK(interrupt))
143 /* Prevent the given interrupt from being enabled immediately. */
144 #define raw_local_irq_mask_now(interrupt) do { \
145 raw_local_irq_mask(interrupt); \
146 interrupt_mask_set(interrupt); \
149 /* Allow the given interrupt to be enabled next time we enable irqs. */
150 #define raw_local_irq_unmask(interrupt) \
151 (__get_cpu_var(interrupts_enabled_mask) |= INT_MASK(interrupt))
153 /* Allow the given interrupt to be enabled immediately, if !irqs_disabled. */
154 #define raw_local_irq_unmask_now(interrupt) do { \
155 raw_local_irq_unmask(interrupt); \
156 if (!irqs_disabled()) \
157 interrupt_mask_reset(interrupt); \
160 #else /* __ASSEMBLY__ */
162 /* We provide a somewhat more restricted set for assembly. */
166 #if INT_MEM_ERROR != 0
167 # error Fix IRQ_DISABLED() macro
170 /* Return 0 or 1 to indicate whether interrupts are currently disabled. */
171 #define IRQS_DISABLED(tmp) \
172 mfspr tmp, INTERRUPT_MASK_1; \
175 /* Load up a pointer to &interrupts_enabled_mask. */
176 #define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
177 moveli reg, hw2_last(interrupts_enabled_mask); \
178 shl16insli reg, reg, hw1(interrupts_enabled_mask); \
179 shl16insli reg, reg, hw0(interrupts_enabled_mask); \
182 /* Disable interrupts. */
183 #define IRQ_DISABLE(tmp0, tmp1) \
184 moveli tmp0, hw2_last(LINUX_MASKABLE_INTERRUPTS); \
185 shl16insli tmp0, tmp0, hw1(LINUX_MASKABLE_INTERRUPTS); \
186 shl16insli tmp0, tmp0, hw0(LINUX_MASKABLE_INTERRUPTS); \
187 mtspr INTERRUPT_MASK_SET_1, tmp0
189 /* Disable ALL synchronous interrupts (used by NMI entry). */
190 #define IRQ_DISABLE_ALL(tmp) \
192 mtspr INTERRUPT_MASK_SET_1, tmp
194 /* Enable interrupts. */
195 #define IRQ_ENABLE(tmp0, tmp1) \
196 GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
198 mtspr INTERRUPT_MASK_RESET_1, tmp0
200 #else /* !__tilegx__ */
203 * Return 0 or 1 to indicate whether interrupts are currently disabled.
204 * Note that it's important that we use a bit from the "low" mask word,
205 * since when we are enabling, that is the word we write first, so if we
206 * are interrupted after only writing half of the mask, the interrupt
207 * handler will correctly observe that we have interrupts enabled, and
208 * will enable interrupts itself on return from the interrupt handler
209 * (making the original code's write of the "high" mask word idempotent).
211 #define IRQS_DISABLED(tmp) \
212 mfspr tmp, INTERRUPT_MASK_1_0; \
213 shri tmp, tmp, INT_MEM_ERROR; \
216 /* Load up a pointer to &interrupts_enabled_mask. */
217 #define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
218 moveli reg, lo16(interrupts_enabled_mask); \
219 auli reg, reg, ha16(interrupts_enabled_mask);\
222 /* Disable interrupts. */
223 #define IRQ_DISABLE(tmp0, tmp1) \
226 moveli tmp1, lo16(LINUX_MASKABLE_INTERRUPTS) \
229 mtspr INTERRUPT_MASK_SET_1_0, tmp0; \
230 auli tmp1, tmp1, ha16(LINUX_MASKABLE_INTERRUPTS) \
232 mtspr INTERRUPT_MASK_SET_1_1, tmp1
234 /* Disable ALL synchronous interrupts (used by NMI entry). */
235 #define IRQ_DISABLE_ALL(tmp) \
237 mtspr INTERRUPT_MASK_SET_1_0, tmp; \
238 mtspr INTERRUPT_MASK_SET_1_1, tmp
240 /* Enable interrupts. */
241 #define IRQ_ENABLE(tmp0, tmp1) \
242 GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
248 mtspr INTERRUPT_MASK_RESET_1_0, tmp0; \
249 mtspr INTERRUPT_MASK_RESET_1_1, tmp1
253 * Do the CPU's IRQ-state tracing from assembly code. We call a
254 * C function, but almost everywhere we do, we don't mind clobbering
255 * all the caller-saved registers.
257 #ifdef CONFIG_TRACE_IRQFLAGS
258 # define TRACE_IRQS_ON jal trace_hardirqs_on
259 # define TRACE_IRQS_OFF jal trace_hardirqs_off
261 # define TRACE_IRQS_ON
262 # define TRACE_IRQS_OFF
265 #endif /* __ASSEMBLY__ */
267 #endif /* _ASM_TILE_IRQFLAGS_H */
This page took 0.036932 seconds and 5 git commands to generate.