xref: /linux/arch/m68k/kernel/ints.c (revision b43ab901d671e3e3cad425ea5e9a3c74e266dcdd)
1 /*
2  * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file COPYING in the main directory of this archive
6  * for more details.
7  */
8 
9 #include <linux/module.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 
17 #include <asm/setup.h>
18 #include <asm/system.h>
19 #include <asm/irq.h>
20 #include <asm/traps.h>
21 #include <asm/page.h>
22 #include <asm/machdep.h>
23 #include <asm/cacheflush.h>
24 #include <asm/irq_regs.h>
25 
26 #ifdef CONFIG_Q40
27 #include <asm/q40ints.h>
28 #endif
29 
30 extern u32 auto_irqhandler_fixup[];
31 extern u16 user_irqvec_fixup[];
32 
33 static int m68k_first_user_vec;
34 
35 static struct irq_chip auto_irq_chip = {
36 	.name		= "auto",
37 	.irq_startup	= m68k_irq_startup,
38 	.irq_shutdown	= m68k_irq_shutdown,
39 };
40 
41 static struct irq_chip user_irq_chip = {
42 	.name		= "user",
43 	.irq_startup	= m68k_irq_startup,
44 	.irq_shutdown	= m68k_irq_shutdown,
45 };
46 
47 /*
48  * void init_IRQ(void)
49  *
50  * Parameters:	None
51  *
52  * Returns:	Nothing
53  *
54  * This function should be called during kernel startup to initialize
55  * the IRQ handling routines.
56  */
57 
58 void __init init_IRQ(void)
59 {
60 	int i;
61 
62 	/* assembly irq entry code relies on this... */
63 	if (HARDIRQ_MASK != 0x00ff0000) {
64 		extern void hardirq_mask_is_broken(void);
65 		hardirq_mask_is_broken();
66 	}
67 
68 	for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
69 		irq_set_chip_and_handler(i, &auto_irq_chip, handle_simple_irq);
70 
71 	mach_init_IRQ();
72 }
73 
74 /**
75  * m68k_setup_auto_interrupt
76  * @handler: called from auto vector interrupts
77  *
78  * setup the handler to be called from auto vector interrupts instead of the
79  * standard do_IRQ(), it will be called with irq numbers in the range
80  * from IRQ_AUTO_1 - IRQ_AUTO_7.
81  */
82 void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
83 {
84 	if (handler)
85 		*auto_irqhandler_fixup = (u32)handler;
86 	flush_icache();
87 }
88 
89 /**
90  * m68k_setup_user_interrupt
91  * @vec: first user vector interrupt to handle
92  * @cnt: number of active user vector interrupts
93  *
94  * setup user vector interrupts, this includes activating the specified range
95  * of interrupts, only then these interrupts can be requested (note: this is
96  * different from auto vector interrupts).
97  */
98 void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt)
99 {
100 	int i;
101 
102 	BUG_ON(IRQ_USER + cnt > NR_IRQS);
103 	m68k_first_user_vec = vec;
104 	for (i = 0; i < cnt; i++)
105 		irq_set_chip(IRQ_USER + i, &user_irq_chip);
106 	*user_irqvec_fixup = vec - IRQ_USER;
107 	flush_icache();
108 }
109 
110 /**
111  * m68k_setup_irq_controller
112  * @chip: irq chip which controls specified irq
113  * @handle: flow handler which handles specified irq
114  * @irq: first irq to be managed by the controller
115  * @cnt: number of irqs to be managed by the controller
116  *
117  * Change the controller for the specified range of irq, which will be used to
118  * manage these irq. auto/user irq already have a default controller, which can
119  * be changed as well, but the controller probably should use m68k_irq_startup/
120  * m68k_irq_shutdown.
121  */
122 void m68k_setup_irq_controller(struct irq_chip *chip,
123 			       irq_flow_handler_t handle, unsigned int irq,
124 			       unsigned int cnt)
125 {
126 	int i;
127 
128 	for (i = 0; i < cnt; i++) {
129 		irq_set_chip(irq + i, chip);
130 		if (handle)
131 			irq_set_handler(irq + i, handle);
132 	}
133 }
134 
135 unsigned int m68k_irq_startup_irq(unsigned int irq)
136 {
137 	if (irq <= IRQ_AUTO_7)
138 		vectors[VEC_SPUR + irq] = auto_inthandler;
139 	else
140 		vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
141 	return 0;
142 }
143 
144 unsigned int m68k_irq_startup(struct irq_data *data)
145 {
146 	return m68k_irq_startup_irq(data->irq);
147 }
148 
149 void m68k_irq_shutdown(struct irq_data *data)
150 {
151 	unsigned int irq = data->irq;
152 
153 	if (irq <= IRQ_AUTO_7)
154 		vectors[VEC_SPUR + irq] = bad_inthandler;
155 	else
156 		vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
157 }
158 
159 
160 unsigned int irq_canonicalize(unsigned int irq)
161 {
162 #ifdef CONFIG_Q40
163 	if (MACH_IS_Q40 && irq == 11)
164 		irq = 10;
165 #endif
166 	return irq;
167 }
168 
169 EXPORT_SYMBOL(irq_canonicalize);
170 
171 
172 asmlinkage void handle_badint(struct pt_regs *regs)
173 {
174 	atomic_inc(&irq_err_count);
175 	pr_warn("unexpected interrupt from %u\n", regs->vector);
176 }
177