blob: 4f1eed107b08217f8f2991ed17f92c424b6c437f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994 by Waldorf GMBH, written by Ralf Baechle
7 * Copyright (C) 1995, 96, 97, 98, 99, 2000, 01, 02, 03 by Ralf Baechle
8 */
9#ifndef _ASM_IRQ_H
10#define _ASM_IRQ_H
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/linkage.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +010013
14#include <asm/mipsmtregs.h>
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <irq.h>
17
18#ifdef CONFIG_I8259
19static inline int irq_canonicalize(int irq)
20{
Atsushi Nemoto2fa79372007-01-14 23:41:42 +090021 return ((irq == I8259A_IRQ_BASE + 2) ? I8259A_IRQ_BASE + 9 : irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022}
23#else
24#define irq_canonicalize(irq) (irq) /* Sane hardware, sane code ... */
25#endif
26
Ralf Baechle1146fe32007-09-21 17:13:55 +010027#ifdef CONFIG_MIPS_MT_SMTC
28
29struct irqaction;
30
31extern unsigned long irq_hwmask[];
32extern int setup_irq_smtc(unsigned int irq, struct irqaction * new,
33 unsigned long hwmask);
34
35static inline void smtc_im_ack_irq(unsigned int irq)
36{
37 if (irq_hwmask[irq] & ST0_IM)
38 set_c0_status(irq_hwmask[irq] & ST0_IM);
39}
40
41#else
42
43static inline void smtc_im_ack_irq(unsigned int irq)
44{
45}
46
47#endif /* CONFIG_MIPS_MT_SMTC */
48
Kevin D. Kissellf571eff2007-08-03 19:38:03 +020049#ifdef CONFIG_MIPS_MT_SMTC_IRQAFF
50#include <linux/cpumask.h>
51
Yinghai Lud5dedd42009-04-27 17:59:21 -070052extern int plat_set_irq_affinity(unsigned int irq,
Rusty Russell0de26522008-12-13 21:20:26 +103053 const struct cpumask *affinity);
Kevin D. Kissellf571eff2007-08-03 19:38:03 +020054extern void smtc_forward_irq(unsigned int irq);
55
56/*
57 * IRQ affinity hook invoked at the beginning of interrupt dispatch
58 * if option is enabled.
59 *
60 * Up through Linux 2.6.22 (at least) cpumask operations are very
61 * inefficient on MIPS. Initial prototypes of SMTC IRQ affinity
62 * used a "fast path" per-IRQ-descriptor cache of affinity information
63 * to reduce latency. As there is a project afoot to optimize the
64 * cpumask implementations, this version is optimistically assuming
65 * that cpumask.h macro overhead is reasonable during interrupt dispatch.
66 */
67#define IRQ_AFFINITY_HOOK(irq) \
68do { \
Mike Travise65e49d2009-01-12 15:27:13 -080069 if (!cpumask_test_cpu(smp_processor_id(), irq_desc[irq].affinity)) {\
Kevin D. Kissellf571eff2007-08-03 19:38:03 +020070 smtc_forward_irq(irq); \
71 irq_exit(); \
72 return; \
73 } \
74} while (0)
75
76#else /* Not doing SMTC affinity */
77
78#define IRQ_AFFINITY_HOOK(irq) do { } while (0)
79
80#endif /* CONFIG_MIPS_MT_SMTC_IRQAFF */
81
Kevin D. Kissell0db34212007-07-12 16:21:08 +010082#ifdef CONFIG_MIPS_MT_SMTC_IM_BACKSTOP
Ralf Baechle1146fe32007-09-21 17:13:55 +010083
Ralf Baechle41c594a2006-04-05 09:45:45 +010084/*
85 * Clear interrupt mask handling "backstop" if irq_hwmask
86 * entry so indicates. This implies that the ack() or end()
87 * functions will take over re-enabling the low-level mask.
88 * Otherwise it will be done on return from exception.
89 */
Atsushi Nemotof9bba752007-01-08 00:50:34 +090090#define __DO_IRQ_SMTC_HOOK(irq) \
Ralf Baechle41c594a2006-04-05 09:45:45 +010091do { \
Kevin D. Kissellf571eff2007-08-03 19:38:03 +020092 IRQ_AFFINITY_HOOK(irq); \
Ralf Baechle41c594a2006-04-05 09:45:45 +010093 if (irq_hwmask[irq] & 0x0000ff00) \
94 write_c0_tccontext(read_c0_tccontext() & \
Kevin D. Kissellf571eff2007-08-03 19:38:03 +020095 ~(irq_hwmask[irq] & 0x0000ff00)); \
Ralf Baechle41c594a2006-04-05 09:45:45 +010096} while (0)
Kevin D. Kissellf571eff2007-08-03 19:38:03 +020097
98#define __NO_AFFINITY_IRQ_SMTC_HOOK(irq) \
99do { \
100 if (irq_hwmask[irq] & 0x0000ff00) \
101 write_c0_tccontext(read_c0_tccontext() & \
102 ~(irq_hwmask[irq] & 0x0000ff00)); \
103} while (0)
104
Ralf Baechle41c594a2006-04-05 09:45:45 +0100105#else
Ralf Baechle1146fe32007-09-21 17:13:55 +0100106
Kevin D. Kissellf571eff2007-08-03 19:38:03 +0200107#define __DO_IRQ_SMTC_HOOK(irq) \
108do { \
109 IRQ_AFFINITY_HOOK(irq); \
110} while (0)
111#define __NO_AFFINITY_IRQ_SMTC_HOOK(irq) do { } while (0)
112
Ralf Baechle41c594a2006-04-05 09:45:45 +0100113#endif
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/*
116 * do_IRQ handles all normal device IRQ's (the special
117 * SMP cross-CPU interrupts have their own specific
118 * handlers).
119 *
120 * Ideally there should be away to get this into kernel/irq/handle.c to
121 * avoid the overhead of a call for just a tiny function ...
122 */
Ralf Baechle937a8012006-10-07 19:44:33 +0100123#define do_IRQ(irq) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124do { \
125 irq_enter(); \
Atsushi Nemotof9bba752007-01-08 00:50:34 +0900126 __DO_IRQ_SMTC_HOOK(irq); \
Atsushi Nemoto14178362006-11-14 01:13:18 +0900127 generic_handle_irq(irq); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 irq_exit(); \
129} while (0)
130
Kevin D. Kissellf571eff2007-08-03 19:38:03 +0200131#ifdef CONFIG_MIPS_MT_SMTC_IRQAFF
132/*
133 * To avoid inefficient and in some cases pathological re-checking of
134 * IRQ affinity, we have this variant that skips the affinity check.
135 */
136
137
138#define do_IRQ_no_affinity(irq) \
139do { \
140 irq_enter(); \
141 __NO_AFFINITY_IRQ_SMTC_HOOK(irq); \
142 generic_handle_irq(irq); \
143 irq_exit(); \
144} while (0)
145
146#endif /* CONFIG_MIPS_MT_SMTC_IRQAFF */
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148extern void arch_init_irq(void);
Ralf Baechle937a8012006-10-07 19:44:33 +0100149extern void spurious_interrupt(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Ralf Baechle4a4cf772006-11-06 17:41:06 +0000151extern int allocate_irqno(void);
152extern void alloc_legacy_irqno(void);
153extern void free_irqno(unsigned int irq);
154
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +0100155/*
156 * Before R2 the timer and performance counter interrupts were both fixed to
157 * IE7. Since R2 their number has to be read from the c0_intctl register.
158 */
159#define CP0_LEGACY_COMPARE_IRQ 7
160
161extern int cp0_compare_irq;
162extern int cp0_perfcount_irq;
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#endif /* _ASM_IRQ_H */