1 /* MN10300 Arch-specific interrupt handling
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #include <linux/module.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
14 #include <linux/seq_file.h>
15 #include <linux/cpumask.h>
16 #include <asm/setup.h>
17 #include <asm/serial-regs.h>
21 #define GxICR(X) CROSS_GxICR(X, irq_affinity_online[X])
24 #define GxICR_u8(X) CROSS_GxICR_u8(X, irq_affinity_online[X])
25 #endif /* CONFIG_SMP */
27 unsigned long __mn10300_irq_enabled_epsw
[NR_CPUS
] __cacheline_aligned_in_smp
= {
28 [0 ... NR_CPUS
- 1] = EPSW_IE
| EPSW_IM_7
30 EXPORT_SYMBOL(__mn10300_irq_enabled_epsw
);
33 static char irq_affinity_online
[NR_IRQS
] = {
34 [0 ... NR_IRQS
- 1] = 0
37 #define NR_IRQ_WORDS ((NR_IRQS + 31) / 32)
38 static unsigned long irq_affinity_request
[NR_IRQ_WORDS
] = {
39 [0 ... NR_IRQ_WORDS
- 1] = 0
41 #endif /* CONFIG_SMP */
43 atomic_t irq_err_count
;
46 * MN10300 interrupt controller operations
48 static void mn10300_cpupic_ack(unsigned int irq
)
53 flags
= arch_local_cli_save();
54 GxICR_u8(irq
) = GxICR_DETECT
;
56 arch_local_irq_restore(flags
);
59 static void __mask_and_set_icr(unsigned int irq
,
60 unsigned int mask
, unsigned int set
)
65 flags
= arch_local_cli_save();
67 GxICR(irq
) = (tmp
& mask
) | set
;
69 arch_local_irq_restore(flags
);
72 static void mn10300_cpupic_mask(unsigned int irq
)
74 __mask_and_set_icr(irq
, GxICR_LEVEL
, 0);
77 static void mn10300_cpupic_mask_ack(unsigned int irq
)
83 flags
= arch_local_cli_save();
85 if (!test_and_clear_bit(irq
, irq_affinity_request
)) {
87 GxICR(irq
) = (tmp
& GxICR_LEVEL
) | GxICR_DETECT
;
92 GxICR(irq
) = (tmp
& GxICR_LEVEL
);
95 irq_affinity_online
[irq
] = any_online_cpu(*irq_desc
[irq
].affinity
);
96 GxICR(irq
) = (tmp
& (GxICR_LEVEL
| GxICR_ENABLE
)) | GxICR_DETECT
;
100 arch_local_irq_restore(flags
);
101 #else /* CONFIG_SMP */
102 __mask_and_set_icr(irq
, GxICR_LEVEL
, GxICR_DETECT
);
103 #endif /* CONFIG_SMP */
106 static void mn10300_cpupic_unmask(unsigned int irq
)
108 __mask_and_set_icr(irq
, GxICR_LEVEL
, GxICR_ENABLE
);
111 static void mn10300_cpupic_unmask_clear(unsigned int irq
)
113 /* the MN10300 PIC latches its interrupt request bit, even after the
114 * device has ceased to assert its interrupt line and the interrupt
115 * channel has been disabled in the PIC, so for level-triggered
116 * interrupts we need to clear the request bit when we re-enable */
121 flags
= arch_local_cli_save();
123 if (!test_and_clear_bit(irq
, irq_affinity_request
)) {
125 GxICR(irq
) = (tmp
& GxICR_LEVEL
) | GxICR_ENABLE
| GxICR_DETECT
;
130 irq_affinity_online
[irq
] = any_online_cpu(*irq_desc
[irq
].affinity
);
131 GxICR(irq
) = (tmp
& GxICR_LEVEL
) | GxICR_ENABLE
| GxICR_DETECT
;
135 arch_local_irq_restore(flags
);
136 #else /* CONFIG_SMP */
137 __mask_and_set_icr(irq
, GxICR_LEVEL
, GxICR_ENABLE
| GxICR_DETECT
);
138 #endif /* CONFIG_SMP */
143 mn10300_cpupic_setaffinity(unsigned int irq
, const struct cpumask
*mask
)
148 flags
= arch_local_cli_save();
154 case CALL_FUNC_SINGLE_IPI
:
155 case LOCAL_TIMER_IPI
:
156 case FLUSH_CACHE_IPI
:
157 case CALL_FUNCTION_NMI_IPI
:
159 #ifdef CONFIG_MN10300_TTYSM0
162 #ifdef CONFIG_MN10300_TTYSM0_TIMER8
164 #elif CONFIG_MN10300_TTYSM0_TIMER2
166 #endif /* CONFIG_MN10300_TTYSM0_TIMER8 */
167 #endif /* CONFIG_MN10300_TTYSM0 */
169 #ifdef CONFIG_MN10300_TTYSM1
172 #ifdef CONFIG_MN10300_TTYSM1_TIMER12
174 #elif CONFIG_MN10300_TTYSM1_TIMER9
176 #elif CONFIG_MN10300_TTYSM1_TIMER3
178 #endif /* CONFIG_MN10300_TTYSM1_TIMER12 */
179 #endif /* CONFIG_MN10300_TTYSM1 */
181 #ifdef CONFIG_MN10300_TTYSM2
185 #endif /* CONFIG_MN10300_TTYSM2 */
190 set_bit(irq
, irq_affinity_request
);
195 arch_local_irq_restore(flags
);
198 #endif /* CONFIG_SMP */
201 * MN10300 PIC level-triggered IRQ handling.
203 * The PIC has no 'ACK' function per se. It is possible to clear individual
204 * channel latches, but each latch relatches whether or not the channel is
205 * masked, so we need to clear the latch when we unmask the channel.
207 * Also for this reason, we don't supply an ack() op (it's unused anyway if
208 * mask_ack() is provided), and mask_ack() just masks.
210 static struct irq_chip mn10300_cpu_pic_level
= {
212 .disable
= mn10300_cpupic_mask
,
213 .enable
= mn10300_cpupic_unmask_clear
,
215 .mask
= mn10300_cpupic_mask
,
216 .mask_ack
= mn10300_cpupic_mask
,
217 .unmask
= mn10300_cpupic_unmask_clear
,
219 .set_affinity
= mn10300_cpupic_setaffinity
,
220 #endif /* CONFIG_SMP */
224 * MN10300 PIC edge-triggered IRQ handling.
226 * We use the latch clearing function of the PIC as the 'ACK' function.
228 static struct irq_chip mn10300_cpu_pic_edge
= {
230 .disable
= mn10300_cpupic_mask
,
231 .enable
= mn10300_cpupic_unmask
,
232 .ack
= mn10300_cpupic_ack
,
233 .mask
= mn10300_cpupic_mask
,
234 .mask_ack
= mn10300_cpupic_mask_ack
,
235 .unmask
= mn10300_cpupic_unmask
,
237 .set_affinity
= mn10300_cpupic_setaffinity
,
238 #endif /* CONFIG_SMP */
242 * 'what should we do if we get a hw irq event on an illegal vector'.
243 * each architecture has to answer this themselves.
245 void ack_bad_irq(int irq
)
247 printk(KERN_WARNING
"unexpected IRQ trap at vector %02x\n", irq
);
251 * change the level at which an IRQ executes
252 * - must not be called whilst interrupts are being processed!
254 void set_intr_level(int irq
, u16 level
)
256 BUG_ON(in_interrupt());
258 __mask_and_set_icr(irq
, GxICR_ENABLE
, level
);
261 void mn10300_intc_set_level(unsigned int irq
, unsigned int level
)
263 set_intr_level(irq
, NUM2GxICR_LEVEL(level
) & GxICR_LEVEL
);
266 void mn10300_intc_clear(unsigned int irq
)
268 __mask_and_set_icr(irq
, GxICR_LEVEL
| GxICR_ENABLE
, GxICR_DETECT
);
271 void mn10300_intc_set(unsigned int irq
)
273 __mask_and_set_icr(irq
, 0, GxICR_REQUEST
| GxICR_DETECT
);
276 void mn10300_intc_enable(unsigned int irq
)
278 mn10300_cpupic_unmask(irq
);
281 void mn10300_intc_disable(unsigned int irq
)
283 mn10300_cpupic_mask(irq
);
287 * mark an interrupt to be ACK'd after interrupt handlers have been run rather
289 * - see Documentation/mn10300/features.txt
291 void mn10300_set_lateack_irq_type(int irq
)
293 set_irq_chip_and_handler(irq
, &mn10300_cpu_pic_level
,
298 * initialise the interrupt system
300 void __init
init_IRQ(void)
304 for (irq
= 0; irq
< NR_IRQS
; irq
++)
305 if (irq_desc
[irq
].chip
== &no_irq_chip
)
306 /* due to the PIC latching interrupt requests, even
307 * when the IRQ is disabled, IRQ_PENDING is superfluous
308 * and we can use handle_level_irq() for edge-triggered
310 set_irq_chip_and_handler(irq
, &mn10300_cpu_pic_edge
,
317 * handle normal device IRQs
319 asmlinkage
void do_IRQ(void)
321 unsigned long sp
, epsw
, irq_disabled_epsw
, old_irq_enabled_epsw
;
322 unsigned int cpu_id
= smp_processor_id();
325 sp
= current_stack_pointer();
326 BUG_ON(sp
- (sp
& ~(THREAD_SIZE
- 1)) < STACK_WARN
);
328 /* make sure local_irq_enable() doesn't muck up the interrupt priority
330 old_irq_enabled_epsw
= __mn10300_irq_enabled_epsw
[cpu_id
];
331 local_save_flags(epsw
);
332 __mn10300_irq_enabled_epsw
[cpu_id
] = EPSW_IE
| (EPSW_IM
& epsw
);
333 irq_disabled_epsw
= EPSW_IE
| MN10300_CLI_LEVEL
;
335 #ifdef CONFIG_MN10300_WD_TIMER
336 __IRQ_STAT(cpu_id
, __irq_count
)++;
342 /* ask the interrupt controller for the next IRQ to process
343 * - the result we get depends on EPSW.IM
345 irq
= IAGR
& IAGR_GN
;
349 local_irq_restore(irq_disabled_epsw
);
351 generic_handle_irq(irq
>> 2);
353 /* restore IRQ controls for IAGR access */
354 local_irq_restore(epsw
);
357 __mn10300_irq_enabled_epsw
[cpu_id
] = old_irq_enabled_epsw
;
363 * Display interrupt management information through /proc/interrupts
365 int show_interrupts(struct seq_file
*p
, void *v
)
367 int i
= *(loff_t
*) v
, j
, cpu
;
368 struct irqaction
*action
;
372 /* display column title bar naming CPUs */
375 for (j
= 0; j
< NR_CPUS
; j
++)
377 seq_printf(p
, "CPU%d ", j
);
381 /* display information rows, one per active CPU */
382 case 1 ... NR_IRQS
- 1:
383 raw_spin_lock_irqsave(&irq_desc
[i
].lock
, flags
);
385 action
= irq_desc
[i
].action
;
387 seq_printf(p
, "%3d: ", i
);
388 for_each_present_cpu(cpu
)
389 seq_printf(p
, "%10u ", kstat_irqs_cpu(i
, cpu
));
390 seq_printf(p
, " %14s.%u", irq_desc
[i
].chip
->name
,
391 (GxICR(i
) & GxICR_LEVEL
) >>
393 seq_printf(p
, " %s", action
->name
);
395 for (action
= action
->next
;
397 action
= action
->next
)
398 seq_printf(p
, ", %s", action
->name
);
403 raw_spin_unlock_irqrestore(&irq_desc
[i
].lock
, flags
);
406 /* polish off with NMI and error counters */
408 #ifdef CONFIG_MN10300_WD_TIMER
409 seq_printf(p
, "NMI: ");
410 for (j
= 0; j
< NR_CPUS
; j
++)
412 seq_printf(p
, "%10u ", nmi_count(j
));
416 seq_printf(p
, "ERR: %10u\n", atomic_read(&irq_err_count
));
423 #ifdef CONFIG_HOTPLUG_CPU
424 void migrate_irqs(void)
428 unsigned int self
, new;
431 self
= smp_processor_id();
432 for (irq
= 0; irq
< NR_IRQS
; irq
++) {
433 desc
= irq_desc
+ irq
;
435 if (desc
->status
== IRQ_PER_CPU
)
438 if (cpu_isset(self
, irq_desc
[irq
].affinity
) &&
439 !cpus_intersects(irq_affinity
[irq
], cpu_online_map
)) {
441 cpu_id
= first_cpu(cpu_online_map
);
442 cpu_set(cpu_id
, irq_desc
[irq
].affinity
);
444 /* We need to operate irq_affinity_online atomically. */
445 arch_local_cli_save(flags
);
446 if (irq_affinity_online
[irq
] == self
) {
449 x
= CROSS_GxICR(irq
, self
);
450 CROSS_GxICR(irq
, self
) = x
& GxICR_LEVEL
;
451 tmp
= CROSS_GxICR(irq
, self
);
453 new = any_online_cpu(irq_desc
[irq
].affinity
);
454 irq_affinity_online
[irq
] = new;
456 CROSS_GxICR(irq
, new) =
457 (x
& GxICR_LEVEL
) | GxICR_DETECT
;
458 tmp
= CROSS_GxICR(irq
, new);
460 x
&= GxICR_LEVEL
| GxICR_ENABLE
;
461 if (CROSS_GxICR(irq
, self
) & GxICR_REQUEST
)
462 x
|= GxICR_REQUEST
| GxICR_DETECT
;
463 CROSS_GxICR(irq
, new) = x
;
464 tmp
= CROSS_GxICR(irq
, new);
466 arch_local_irq_restore(flags
);
469 #endif /* CONFIG_HOTPLUG_CPU */