blob: 241c0bb60b12e5cf4e9eedce50279d648d313e25 [file] [log] [blame]
Chris Metcalf867e3592010-05-28 23:09:12 -04001/*
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
15#ifndef _ASM_TILE_IRQFLAGS_H
16#define _ASM_TILE_IRQFLAGS_H
17
Chris Metcalf867e3592010-05-28 23:09:12 -040018#include <arch/interrupts.h>
19#include <arch/chip.h>
20
21/*
22 * The set of interrupts we want to allow when interrupts are nominally
23 * disabled. The remainder are effectively "NMI" interrupts from
24 * the point of view of the generic Linux code. Note that synchronous
25 * interrupts (aka "non-queued") are not blocked by the mask in any case.
26 */
Chris Metcalf867e3592010-05-28 23:09:12 -040027#define LINUX_MASKABLE_INTERRUPTS \
Chris Metcalf7f04f082013-02-01 13:01:36 -050028 (~((_AC(1,ULL) << INT_PERF_COUNT) | (_AC(1,ULL) << INT_AUX_PERF_COUNT)))
Chris Metcalf867e3592010-05-28 23:09:12 -040029
Chris Metcalf7f04f082013-02-01 13:01:36 -050030#if CHIP_HAS_SPLIT_INTR_MASK()
31/* The same macro, but for the two 32-bit SPRs separately. */
32#define LINUX_MASKABLE_INTERRUPTS_LO (-1)
33#define LINUX_MASKABLE_INTERRUPTS_HI \
34 (~((1 << (INT_PERF_COUNT - 32)) | (1 << (INT_AUX_PERF_COUNT - 32))))
Chris Metcalf0dccb042011-03-17 14:32:06 -040035#endif
36
Chris Metcalf867e3592010-05-28 23:09:12 -040037#ifndef __ASSEMBLY__
38
39/* NOTE: we can't include <linux/percpu.h> due to #include dependencies. */
40#include <asm/percpu.h>
41#include <arch/spr_def.h>
42
43/* Set and clear kernel interrupt masks. */
44#if CHIP_HAS_SPLIT_INTR_MASK()
45#if INT_PERF_COUNT < 32 || INT_AUX_PERF_COUNT < 32 || INT_MEM_ERROR >= 32
46# error Fix assumptions about which word various interrupts are in
47#endif
48#define interrupt_mask_set(n) do { \
49 int __n = (n); \
50 int __mask = 1 << (__n & 0x1f); \
51 if (__n < 32) \
Chris Metcalfa78c9422010-10-14 16:23:03 -040052 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_0, __mask); \
Chris Metcalf867e3592010-05-28 23:09:12 -040053 else \
Chris Metcalfa78c9422010-10-14 16:23:03 -040054 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_1, __mask); \
Chris Metcalf867e3592010-05-28 23:09:12 -040055} while (0)
56#define interrupt_mask_reset(n) do { \
57 int __n = (n); \
58 int __mask = 1 << (__n & 0x1f); \
59 if (__n < 32) \
Chris Metcalfa78c9422010-10-14 16:23:03 -040060 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_0, __mask); \
Chris Metcalf867e3592010-05-28 23:09:12 -040061 else \
Chris Metcalfa78c9422010-10-14 16:23:03 -040062 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_1, __mask); \
Chris Metcalf867e3592010-05-28 23:09:12 -040063} while (0)
64#define interrupt_mask_check(n) ({ \
65 int __n = (n); \
66 (((__n < 32) ? \
Chris Metcalfa78c9422010-10-14 16:23:03 -040067 __insn_mfspr(SPR_INTERRUPT_MASK_K_0) : \
68 __insn_mfspr(SPR_INTERRUPT_MASK_K_1)) \
Chris Metcalf867e3592010-05-28 23:09:12 -040069 >> (__n & 0x1f)) & 1; \
70})
71#define interrupt_mask_set_mask(mask) do { \
72 unsigned long long __m = (mask); \
Chris Metcalfa78c9422010-10-14 16:23:03 -040073 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_0, (unsigned long)(__m)); \
74 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_1, (unsigned long)(__m>>32)); \
Chris Metcalf867e3592010-05-28 23:09:12 -040075} while (0)
76#define interrupt_mask_reset_mask(mask) do { \
77 unsigned long long __m = (mask); \
Chris Metcalfa78c9422010-10-14 16:23:03 -040078 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_0, (unsigned long)(__m)); \
79 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_1, (unsigned long)(__m>>32)); \
Chris Metcalf867e3592010-05-28 23:09:12 -040080} while (0)
Chris Metcalf51007002012-03-27 15:40:20 -040081#define interrupt_mask_save_mask() \
82 (__insn_mfspr(SPR_INTERRUPT_MASK_SET_K_0) | \
83 (((unsigned long long)__insn_mfspr(SPR_INTERRUPT_MASK_SET_K_1))<<32))
84#define interrupt_mask_restore_mask(mask) do { \
85 unsigned long long __m = (mask); \
86 __insn_mtspr(SPR_INTERRUPT_MASK_K_0, (unsigned long)(__m)); \
87 __insn_mtspr(SPR_INTERRUPT_MASK_K_1, (unsigned long)(__m>>32)); \
88} while (0)
Chris Metcalf867e3592010-05-28 23:09:12 -040089#else
90#define interrupt_mask_set(n) \
Chris Metcalfa78c9422010-10-14 16:23:03 -040091 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K, (1UL << (n)))
Chris Metcalf867e3592010-05-28 23:09:12 -040092#define interrupt_mask_reset(n) \
Chris Metcalfa78c9422010-10-14 16:23:03 -040093 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K, (1UL << (n)))
Chris Metcalf867e3592010-05-28 23:09:12 -040094#define interrupt_mask_check(n) \
Chris Metcalfa78c9422010-10-14 16:23:03 -040095 ((__insn_mfspr(SPR_INTERRUPT_MASK_K) >> (n)) & 1)
Chris Metcalf867e3592010-05-28 23:09:12 -040096#define interrupt_mask_set_mask(mask) \
Chris Metcalfa78c9422010-10-14 16:23:03 -040097 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K, (mask))
Chris Metcalf867e3592010-05-28 23:09:12 -040098#define interrupt_mask_reset_mask(mask) \
Chris Metcalfa78c9422010-10-14 16:23:03 -040099 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K, (mask))
Chris Metcalf51007002012-03-27 15:40:20 -0400100#define interrupt_mask_save_mask() \
101 __insn_mfspr(SPR_INTERRUPT_MASK_K)
102#define interrupt_mask_restore_mask(mask) \
103 __insn_mtspr(SPR_INTERRUPT_MASK_K, (mask))
Chris Metcalf867e3592010-05-28 23:09:12 -0400104#endif
105
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.
Chris Metcalfa78c9422010-10-14 16:23:03 -0400110 * Likewise, INTCTRL_K is removed and re-added during device
Chris Metcalf867e3592010-05-28 23:09:12 -0400111 * 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 */
116DECLARE_PER_CPU(unsigned long long, interrupts_enabled_mask);
Chris Metcalf7f04f082013-02-01 13:01:36 -0500117#define INITIAL_INTERRUPTS_ENABLED (1ULL << INT_MEM_ERROR)
Chris Metcalf867e3592010-05-28 23:09:12 -0400118
119/* Disable interrupts. */
David Howellsdf9ee292010-10-07 14:08:55 +0100120#define arch_local_irq_disable() \
Chris Metcalf867e3592010-05-28 23:09:12 -0400121 interrupt_mask_set_mask(LINUX_MASKABLE_INTERRUPTS)
122
123/* Disable all interrupts, including NMIs. */
David Howellsdf9ee292010-10-07 14:08:55 +0100124#define arch_local_irq_disable_all() \
Chris Metcalf51007002012-03-27 15:40:20 -0400125 interrupt_mask_set_mask(-1ULL)
Chris Metcalf867e3592010-05-28 23:09:12 -0400126
127/* Re-enable all maskable interrupts. */
David Howellsdf9ee292010-10-07 14:08:55 +0100128#define arch_local_irq_enable() \
Chris Metcalf867e3592010-05-28 23:09:12 -0400129 interrupt_mask_reset_mask(__get_cpu_var(interrupts_enabled_mask))
130
131/* Disable or enable interrupts based on flag argument. */
David Howellsdf9ee292010-10-07 14:08:55 +0100132#define arch_local_irq_restore(disabled) do { \
Chris Metcalf867e3592010-05-28 23:09:12 -0400133 if (disabled) \
David Howellsdf9ee292010-10-07 14:08:55 +0100134 arch_local_irq_disable(); \
Chris Metcalf867e3592010-05-28 23:09:12 -0400135 else \
David Howellsdf9ee292010-10-07 14:08:55 +0100136 arch_local_irq_enable(); \
Chris Metcalf867e3592010-05-28 23:09:12 -0400137} while (0)
138
139/* Return true if "flags" argument means interrupts are disabled. */
David Howellsdf9ee292010-10-07 14:08:55 +0100140#define arch_irqs_disabled_flags(flags) ((flags) != 0)
Chris Metcalf867e3592010-05-28 23:09:12 -0400141
142/* Return true if interrupts are currently disabled. */
David Howellsdf9ee292010-10-07 14:08:55 +0100143#define arch_irqs_disabled() interrupt_mask_check(INT_MEM_ERROR)
Chris Metcalf867e3592010-05-28 23:09:12 -0400144
145/* Save whether interrupts are currently disabled. */
David Howellsdf9ee292010-10-07 14:08:55 +0100146#define arch_local_save_flags() arch_irqs_disabled()
Chris Metcalf867e3592010-05-28 23:09:12 -0400147
148/* Save whether interrupts are currently disabled, then disable them. */
David Howellsdf9ee292010-10-07 14:08:55 +0100149#define arch_local_irq_save() ({ \
150 unsigned long __flags = arch_local_save_flags(); \
151 arch_local_irq_disable(); \
152 __flags; })
Chris Metcalf867e3592010-05-28 23:09:12 -0400153
154/* Prevent the given interrupt from being enabled next time we enable irqs. */
David Howellsdf9ee292010-10-07 14:08:55 +0100155#define arch_local_irq_mask(interrupt) \
Chris Metcalf7f04f082013-02-01 13:01:36 -0500156 (__get_cpu_var(interrupts_enabled_mask) &= ~(1ULL << (interrupt)))
Chris Metcalf867e3592010-05-28 23:09:12 -0400157
158/* Prevent the given interrupt from being enabled immediately. */
David Howellsdf9ee292010-10-07 14:08:55 +0100159#define arch_local_irq_mask_now(interrupt) do { \
160 arch_local_irq_mask(interrupt); \
Chris Metcalf867e3592010-05-28 23:09:12 -0400161 interrupt_mask_set(interrupt); \
162} while (0)
163
164/* Allow the given interrupt to be enabled next time we enable irqs. */
David Howellsdf9ee292010-10-07 14:08:55 +0100165#define arch_local_irq_unmask(interrupt) \
Chris Metcalf7f04f082013-02-01 13:01:36 -0500166 (__get_cpu_var(interrupts_enabled_mask) |= (1ULL << (interrupt)))
Chris Metcalf867e3592010-05-28 23:09:12 -0400167
168/* Allow the given interrupt to be enabled immediately, if !irqs_disabled. */
David Howellsdf9ee292010-10-07 14:08:55 +0100169#define arch_local_irq_unmask_now(interrupt) do { \
170 arch_local_irq_unmask(interrupt); \
Chris Metcalf867e3592010-05-28 23:09:12 -0400171 if (!irqs_disabled()) \
172 interrupt_mask_reset(interrupt); \
173} while (0)
174
175#else /* __ASSEMBLY__ */
176
177/* We provide a somewhat more restricted set for assembly. */
178
179#ifdef __tilegx__
180
181#if INT_MEM_ERROR != 0
Chris Metcalf51007002012-03-27 15:40:20 -0400182# error Fix IRQS_DISABLED() macro
Chris Metcalf867e3592010-05-28 23:09:12 -0400183#endif
184
185/* Return 0 or 1 to indicate whether interrupts are currently disabled. */
186#define IRQS_DISABLED(tmp) \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400187 mfspr tmp, SPR_INTERRUPT_MASK_K; \
Chris Metcalf867e3592010-05-28 23:09:12 -0400188 andi tmp, tmp, 1
189
190/* Load up a pointer to &interrupts_enabled_mask. */
191#define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400192 moveli reg, hw2_last(interrupts_enabled_mask); \
193 shl16insli reg, reg, hw1(interrupts_enabled_mask); \
194 shl16insli reg, reg, hw0(interrupts_enabled_mask); \
Chris Metcalf867e3592010-05-28 23:09:12 -0400195 add reg, reg, tp
196
197/* Disable interrupts. */
198#define IRQ_DISABLE(tmp0, tmp1) \
199 moveli tmp0, hw2_last(LINUX_MASKABLE_INTERRUPTS); \
200 shl16insli tmp0, tmp0, hw1(LINUX_MASKABLE_INTERRUPTS); \
201 shl16insli tmp0, tmp0, hw0(LINUX_MASKABLE_INTERRUPTS); \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400202 mtspr SPR_INTERRUPT_MASK_SET_K, tmp0
Chris Metcalf867e3592010-05-28 23:09:12 -0400203
204/* Disable ALL synchronous interrupts (used by NMI entry). */
205#define IRQ_DISABLE_ALL(tmp) \
206 movei tmp, -1; \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400207 mtspr SPR_INTERRUPT_MASK_SET_K, tmp
Chris Metcalf867e3592010-05-28 23:09:12 -0400208
209/* Enable interrupts. */
Chris Metcalf51007002012-03-27 15:40:20 -0400210#define IRQ_ENABLE_LOAD(tmp0, tmp1) \
Chris Metcalf867e3592010-05-28 23:09:12 -0400211 GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
Chris Metcalf51007002012-03-27 15:40:20 -0400212 ld tmp0, tmp0
213#define IRQ_ENABLE_APPLY(tmp0, tmp1) \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400214 mtspr SPR_INTERRUPT_MASK_RESET_K, tmp0
Chris Metcalf867e3592010-05-28 23:09:12 -0400215
216#else /* !__tilegx__ */
217
218/*
219 * Return 0 or 1 to indicate whether interrupts are currently disabled.
220 * Note that it's important that we use a bit from the "low" mask word,
221 * since when we are enabling, that is the word we write first, so if we
222 * are interrupted after only writing half of the mask, the interrupt
223 * handler will correctly observe that we have interrupts enabled, and
224 * will enable interrupts itself on return from the interrupt handler
225 * (making the original code's write of the "high" mask word idempotent).
226 */
227#define IRQS_DISABLED(tmp) \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400228 mfspr tmp, SPR_INTERRUPT_MASK_K_0; \
Chris Metcalf867e3592010-05-28 23:09:12 -0400229 shri tmp, tmp, INT_MEM_ERROR; \
230 andi tmp, tmp, 1
231
232/* Load up a pointer to &interrupts_enabled_mask. */
233#define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400234 moveli reg, lo16(interrupts_enabled_mask); \
235 auli reg, reg, ha16(interrupts_enabled_mask); \
Chris Metcalf867e3592010-05-28 23:09:12 -0400236 add reg, reg, tp
237
238/* Disable interrupts. */
239#define IRQ_DISABLE(tmp0, tmp1) \
240 { \
Chris Metcalf7f04f082013-02-01 13:01:36 -0500241 movei tmp0, LINUX_MASKABLE_INTERRUPTS_LO; \
Chris Metcalf0dccb042011-03-17 14:32:06 -0400242 moveli tmp1, lo16(LINUX_MASKABLE_INTERRUPTS_HI) \
Chris Metcalf867e3592010-05-28 23:09:12 -0400243 }; \
244 { \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400245 mtspr SPR_INTERRUPT_MASK_SET_K_0, tmp0; \
Chris Metcalf0dccb042011-03-17 14:32:06 -0400246 auli tmp1, tmp1, ha16(LINUX_MASKABLE_INTERRUPTS_HI) \
Chris Metcalf867e3592010-05-28 23:09:12 -0400247 }; \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400248 mtspr SPR_INTERRUPT_MASK_SET_K_1, tmp1
Chris Metcalf867e3592010-05-28 23:09:12 -0400249
250/* Disable ALL synchronous interrupts (used by NMI entry). */
251#define IRQ_DISABLE_ALL(tmp) \
252 movei tmp, -1; \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400253 mtspr SPR_INTERRUPT_MASK_SET_K_0, tmp; \
254 mtspr SPR_INTERRUPT_MASK_SET_K_1, tmp
Chris Metcalf867e3592010-05-28 23:09:12 -0400255
256/* Enable interrupts. */
Chris Metcalf51007002012-03-27 15:40:20 -0400257#define IRQ_ENABLE_LOAD(tmp0, tmp1) \
Chris Metcalf867e3592010-05-28 23:09:12 -0400258 GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
259 { \
260 lw tmp0, tmp0; \
261 addi tmp1, tmp0, 4 \
262 }; \
Chris Metcalf51007002012-03-27 15:40:20 -0400263 lw tmp1, tmp1
264#define IRQ_ENABLE_APPLY(tmp0, tmp1) \
Chris Metcalfa78c9422010-10-14 16:23:03 -0400265 mtspr SPR_INTERRUPT_MASK_RESET_K_0, tmp0; \
266 mtspr SPR_INTERRUPT_MASK_RESET_K_1, tmp1
Chris Metcalf867e3592010-05-28 23:09:12 -0400267#endif
268
Chris Metcalf51007002012-03-27 15:40:20 -0400269#define IRQ_ENABLE(tmp0, tmp1) \
270 IRQ_ENABLE_LOAD(tmp0, tmp1); \
271 IRQ_ENABLE_APPLY(tmp0, tmp1)
272
Chris Metcalf867e3592010-05-28 23:09:12 -0400273/*
274 * Do the CPU's IRQ-state tracing from assembly code. We call a
275 * C function, but almost everywhere we do, we don't mind clobbering
276 * all the caller-saved registers.
277 */
278#ifdef CONFIG_TRACE_IRQFLAGS
279# define TRACE_IRQS_ON jal trace_hardirqs_on
280# define TRACE_IRQS_OFF jal trace_hardirqs_off
281#else
282# define TRACE_IRQS_ON
283# define TRACE_IRQS_OFF
284#endif
285
286#endif /* __ASSEMBLY__ */
287
288#endif /* _ASM_TILE_IRQFLAGS_H */