irqflags.h 8.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/*
 * Copyright 2010 Tilera Corporation. All Rights Reserved.
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation, version 2.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
 *   NON INFRINGEMENT.  See the GNU General Public License for
 *   more details.
 */

#ifndef _ASM_TILE_IRQFLAGS_H
#define _ASM_TILE_IRQFLAGS_H

#include <arch/interrupts.h>
#include <arch/chip.h>

/*
 * The set of interrupts we want to allow when interrupts are nominally
 * disabled.  The remainder are effectively "NMI" interrupts from
 * the point of view of the generic Linux code.  Note that synchronous
 * interrupts (aka "non-queued") are not blocked by the mask in any case.
 */
#if CHIP_HAS_AUX_PERF_COUNTERS()
#define LINUX_MASKABLE_INTERRUPTS \
	(~(INT_MASK(INT_PERF_COUNT) | INT_MASK(INT_AUX_PERF_COUNT)))
#else
#define LINUX_MASKABLE_INTERRUPTS \
	(~(INT_MASK(INT_PERF_COUNT)))
#endif

#ifndef __ASSEMBLY__

/* NOTE: we can't include <linux/percpu.h> due to #include dependencies. */
#include <asm/percpu.h>
#include <arch/spr_def.h>

/* Set and clear kernel interrupt masks. */
#if CHIP_HAS_SPLIT_INTR_MASK()
#if INT_PERF_COUNT < 32 || INT_AUX_PERF_COUNT < 32 || INT_MEM_ERROR >= 32
# error Fix assumptions about which word various interrupts are in
#endif
#define interrupt_mask_set(n) do { \
	int __n = (n); \
	int __mask = 1 << (__n & 0x1f); \
	if (__n < 32) \
50
		__insn_mtspr(SPR_INTERRUPT_MASK_SET_K_0, __mask); \
51
	else \
52
		__insn_mtspr(SPR_INTERRUPT_MASK_SET_K_1, __mask); \
53 54 55 56 57
} while (0)
#define interrupt_mask_reset(n) do { \
	int __n = (n); \
	int __mask = 1 << (__n & 0x1f); \
	if (__n < 32) \
58
		__insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_0, __mask); \
59
	else \
60
		__insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_1, __mask); \
61 62 63 64
} while (0)
#define interrupt_mask_check(n) ({ \
	int __n = (n); \
	(((__n < 32) ? \
65 66
	 __insn_mfspr(SPR_INTERRUPT_MASK_K_0) : \
	 __insn_mfspr(SPR_INTERRUPT_MASK_K_1)) \
67 68 69 70
	  >> (__n & 0x1f)) & 1; \
})
#define interrupt_mask_set_mask(mask) do { \
	unsigned long long __m = (mask); \
71 72
	__insn_mtspr(SPR_INTERRUPT_MASK_SET_K_0, (unsigned long)(__m)); \
	__insn_mtspr(SPR_INTERRUPT_MASK_SET_K_1, (unsigned long)(__m>>32)); \
73 74 75
} while (0)
#define interrupt_mask_reset_mask(mask) do { \
	unsigned long long __m = (mask); \
76 77
	__insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_0, (unsigned long)(__m)); \
	__insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_1, (unsigned long)(__m>>32)); \
78 79 80
} while (0)
#else
#define interrupt_mask_set(n) \
81
	__insn_mtspr(SPR_INTERRUPT_MASK_SET_K, (1UL << (n)))
82
#define interrupt_mask_reset(n) \
83
	__insn_mtspr(SPR_INTERRUPT_MASK_RESET_K, (1UL << (n)))
84
#define interrupt_mask_check(n) \
85
	((__insn_mfspr(SPR_INTERRUPT_MASK_K) >> (n)) & 1)
86
#define interrupt_mask_set_mask(mask) \
87
	__insn_mtspr(SPR_INTERRUPT_MASK_SET_K, (mask))
88
#define interrupt_mask_reset_mask(mask) \
89
	__insn_mtspr(SPR_INTERRUPT_MASK_RESET_K, (mask))
90 91 92 93 94 95
#endif

/*
 * The set of interrupts we want active if irqs are enabled.
 * Note that in particular, the tile timer interrupt comes and goes
 * from this set, since we have no other way to turn off the timer.
96
 * Likewise, INTCTRL_K is removed and re-added during device
97 98 99 100 101 102 103 104 105
 * interrupts, as is the the hardwall UDN_FIREWALL interrupt.
 * We use a low bit (MEM_ERROR) as our sentinel value and make sure it
 * is always claimed as an "active interrupt" so we can query that bit
 * to know our current state.
 */
DECLARE_PER_CPU(unsigned long long, interrupts_enabled_mask);
#define INITIAL_INTERRUPTS_ENABLED INT_MASK(INT_MEM_ERROR)

/* Disable interrupts. */
D
David Howells 已提交
106
#define arch_local_irq_disable() \
107 108 109
	interrupt_mask_set_mask(LINUX_MASKABLE_INTERRUPTS)

/* Disable all interrupts, including NMIs. */
D
David Howells 已提交
110
#define arch_local_irq_disable_all() \
111 112 113
	interrupt_mask_set_mask(-1UL)

/* Re-enable all maskable interrupts. */
D
David Howells 已提交
114
#define arch_local_irq_enable() \
115 116 117
	interrupt_mask_reset_mask(__get_cpu_var(interrupts_enabled_mask))

/* Disable or enable interrupts based on flag argument. */
D
David Howells 已提交
118
#define arch_local_irq_restore(disabled) do { \
119
	if (disabled) \
D
David Howells 已提交
120
		arch_local_irq_disable(); \
121
	else \
D
David Howells 已提交
122
		arch_local_irq_enable(); \
123 124 125
} while (0)

/* Return true if "flags" argument means interrupts are disabled. */
D
David Howells 已提交
126
#define arch_irqs_disabled_flags(flags) ((flags) != 0)
127 128

/* Return true if interrupts are currently disabled. */
D
David Howells 已提交
129
#define arch_irqs_disabled() interrupt_mask_check(INT_MEM_ERROR)
130 131

/* Save whether interrupts are currently disabled. */
D
David Howells 已提交
132
#define arch_local_save_flags() arch_irqs_disabled()
133 134

/* Save whether interrupts are currently disabled, then disable them. */
D
David Howells 已提交
135 136 137 138
#define arch_local_irq_save() ({ \
	unsigned long __flags = arch_local_save_flags(); \
	arch_local_irq_disable(); \
	__flags; })
139 140

/* Prevent the given interrupt from being enabled next time we enable irqs. */
D
David Howells 已提交
141
#define arch_local_irq_mask(interrupt) \
142 143 144
	(__get_cpu_var(interrupts_enabled_mask) &= ~INT_MASK(interrupt))

/* Prevent the given interrupt from being enabled immediately. */
D
David Howells 已提交
145 146
#define arch_local_irq_mask_now(interrupt) do { \
	arch_local_irq_mask(interrupt); \
147 148 149 150
	interrupt_mask_set(interrupt); \
} while (0)

/* Allow the given interrupt to be enabled next time we enable irqs. */
D
David Howells 已提交
151
#define arch_local_irq_unmask(interrupt) \
152 153 154
	(__get_cpu_var(interrupts_enabled_mask) |= INT_MASK(interrupt))

/* Allow the given interrupt to be enabled immediately, if !irqs_disabled. */
D
David Howells 已提交
155 156
#define arch_local_irq_unmask_now(interrupt) do { \
	arch_local_irq_unmask(interrupt); \
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
	if (!irqs_disabled()) \
		interrupt_mask_reset(interrupt); \
} while (0)

#else /* __ASSEMBLY__ */

/* We provide a somewhat more restricted set for assembly. */

#ifdef __tilegx__

#if INT_MEM_ERROR != 0
# error Fix IRQ_DISABLED() macro
#endif

/* Return 0 or 1 to indicate whether interrupts are currently disabled. */
#define IRQS_DISABLED(tmp)					\
173
	mfspr   tmp, SPR_INTERRUPT_MASK_K;			\
174 175 176 177
	andi    tmp, tmp, 1

/* Load up a pointer to &interrupts_enabled_mask. */
#define GET_INTERRUPTS_ENABLED_MASK_PTR(reg)			\
178 179 180
	moveli reg, hw2_last(interrupts_enabled_mask);		\
	shl16insli reg, reg, hw1(interrupts_enabled_mask);	\
	shl16insli reg, reg, hw0(interrupts_enabled_mask);	\
181 182 183 184 185 186 187
	add     reg, reg, tp

/* Disable interrupts. */
#define IRQ_DISABLE(tmp0, tmp1)					\
	moveli  tmp0, hw2_last(LINUX_MASKABLE_INTERRUPTS);	\
	shl16insli tmp0, tmp0, hw1(LINUX_MASKABLE_INTERRUPTS);	\
	shl16insli tmp0, tmp0, hw0(LINUX_MASKABLE_INTERRUPTS);	\
188
	mtspr   SPR_INTERRUPT_MASK_SET_K, tmp0
189 190 191 192

/* Disable ALL synchronous interrupts (used by NMI entry). */
#define IRQ_DISABLE_ALL(tmp)					\
	movei   tmp, -1;					\
193
	mtspr   SPR_INTERRUPT_MASK_SET_K, tmp
194 195 196 197 198

/* Enable interrupts. */
#define IRQ_ENABLE(tmp0, tmp1)					\
	GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0);			\
	ld      tmp0, tmp0;					\
199
	mtspr   SPR_INTERRUPT_MASK_RESET_K, tmp0
200 201 202 203 204 205 206 207 208 209 210 211 212

#else /* !__tilegx__ */

/*
 * Return 0 or 1 to indicate whether interrupts are currently disabled.
 * Note that it's important that we use a bit from the "low" mask word,
 * since when we are enabling, that is the word we write first, so if we
 * are interrupted after only writing half of the mask, the interrupt
 * handler will correctly observe that we have interrupts enabled, and
 * will enable interrupts itself on return from the interrupt handler
 * (making the original code's write of the "high" mask word idempotent).
 */
#define IRQS_DISABLED(tmp)					\
213
	mfspr   tmp, SPR_INTERRUPT_MASK_K_0;			\
214 215 216 217 218
	shri    tmp, tmp, INT_MEM_ERROR;			\
	andi    tmp, tmp, 1

/* Load up a pointer to &interrupts_enabled_mask. */
#define GET_INTERRUPTS_ENABLED_MASK_PTR(reg)			\
219 220
	moveli  reg, lo16(interrupts_enabled_mask);		\
	auli    reg, reg, ha16(interrupts_enabled_mask);	\
221 222 223 224 225 226 227 228 229
	add     reg, reg, tp

/* Disable interrupts. */
#define IRQ_DISABLE(tmp0, tmp1)					\
	{							\
	 movei  tmp0, -1;					\
	 moveli tmp1, lo16(LINUX_MASKABLE_INTERRUPTS)		\
	};							\
	{							\
230
	 mtspr  SPR_INTERRUPT_MASK_SET_K_0, tmp0;		\
231 232
	 auli   tmp1, tmp1, ha16(LINUX_MASKABLE_INTERRUPTS)	\
	};							\
233
	mtspr   SPR_INTERRUPT_MASK_SET_K_1, tmp1
234 235 236 237

/* Disable ALL synchronous interrupts (used by NMI entry). */
#define IRQ_DISABLE_ALL(tmp)					\
	movei   tmp, -1;					\
238 239
	mtspr   SPR_INTERRUPT_MASK_SET_K_0, tmp;		\
	mtspr   SPR_INTERRUPT_MASK_SET_K_1, tmp
240 241 242 243 244 245 246 247 248

/* Enable interrupts. */
#define IRQ_ENABLE(tmp0, tmp1)					\
	GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0);			\
	{							\
	 lw     tmp0, tmp0;					\
	 addi   tmp1, tmp0, 4					\
	};							\
	lw      tmp1, tmp1;					\
249 250
	mtspr   SPR_INTERRUPT_MASK_RESET_K_0, tmp0;		\
	mtspr   SPR_INTERRUPT_MASK_RESET_K_1, tmp1
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
#endif

/*
 * Do the CPU's IRQ-state tracing from assembly code. We call a
 * C function, but almost everywhere we do, we don't mind clobbering
 * all the caller-saved registers.
 */
#ifdef CONFIG_TRACE_IRQFLAGS
# define TRACE_IRQS_ON  jal trace_hardirqs_on
# define TRACE_IRQS_OFF jal trace_hardirqs_off
#else
# define TRACE_IRQS_ON
# define TRACE_IRQS_OFF
#endif

#endif /* __ASSEMBLY__ */

#endif /* _ASM_TILE_IRQFLAGS_H */