Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/xtensa/kernel/irq.c |
| 3 | * |
| 4 | * Xtensa built-in interrupt controller and some generic functions copied |
| 5 | * from i386. |
| 6 | * |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 7 | * Copyright (C) 2002 - 2006 Tensilica, Inc. |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 8 | * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar |
| 9 | * |
| 10 | * |
| 11 | * Chris Zankel <chris@zankel.net> |
| 12 | * Kevin Chea |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/seq_file.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/kernel_stat.h> |
| 21 | |
| 22 | #include <asm/uaccess.h> |
| 23 | #include <asm/platform.h> |
| 24 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 25 | static unsigned int cached_irq_mask; |
| 26 | |
| 27 | atomic_t irq_err_count; |
| 28 | |
| 29 | /* |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 30 | * do_IRQ handles all normal device IRQ's (the special |
| 31 | * SMP cross-CPU interrupts have their own specific |
| 32 | * handlers). |
| 33 | */ |
| 34 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 35 | asmlinkage void do_IRQ(int irq, struct pt_regs *regs) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 36 | { |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 37 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 38 | struct irq_desc *desc = irq_desc + irq; |
| 39 | |
| 40 | if (irq >= NR_IRQS) { |
| 41 | printk(KERN_EMERG "%s: cannot handle IRQ %d\n", |
Harvey Harrison | 1b532c6 | 2008-07-30 12:48:54 -0700 | [diff] [blame] | 42 | __func__, irq); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 45 | irq_enter(); |
| 46 | |
| 47 | #ifdef CONFIG_DEBUG_STACKOVERFLOW |
| 48 | /* Debugging check for stack overflow: is there less than 1KB free? */ |
| 49 | { |
| 50 | unsigned long sp; |
| 51 | |
| 52 | __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp)); |
| 53 | sp &= THREAD_SIZE - 1; |
| 54 | |
| 55 | if (unlikely(sp < (sizeof(thread_info) + 1024))) |
| 56 | printk("Stack overflow in do_IRQ: %ld\n", |
| 57 | sp - sizeof(struct thread_info)); |
| 58 | } |
| 59 | #endif |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 60 | desc->handle_irq(irq, desc); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 61 | |
| 62 | irq_exit(); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 63 | set_irq_regs(old_regs); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Generic, controller-independent functions: |
| 68 | */ |
| 69 | |
| 70 | int show_interrupts(struct seq_file *p, void *v) |
| 71 | { |
| 72 | int i = *(loff_t *) v, j; |
| 73 | struct irqaction * action; |
| 74 | unsigned long flags; |
| 75 | |
| 76 | if (i == 0) { |
| 77 | seq_printf(p, " "); |
Andrew Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 78 | for_each_online_cpu(j) |
| 79 | seq_printf(p, "CPU%d ",j); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 80 | seq_putc(p, '\n'); |
| 81 | } |
| 82 | |
| 83 | if (i < NR_IRQS) { |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 84 | raw_spin_lock_irqsave(&irq_desc[i].lock, flags); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 85 | action = irq_desc[i].action; |
| 86 | if (!action) |
| 87 | goto skip; |
| 88 | seq_printf(p, "%3d: ",i); |
| 89 | #ifndef CONFIG_SMP |
| 90 | seq_printf(p, "%10u ", kstat_irqs(i)); |
| 91 | #else |
Andrew Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 92 | for_each_online_cpu(j) |
Yinghai Lu | dee4102 | 2009-01-11 00:29:15 -0800 | [diff] [blame] | 93 | seq_printf(p, "%10u ", kstat_irqs_cpu(i, j)); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 94 | #endif |
Thomas Gleixner | d1ea13c | 2010-09-23 18:40:07 +0200 | [diff] [blame] | 95 | seq_printf(p, " %14s", irq_desc[i].chip->name); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 96 | seq_printf(p, " %s", action->name); |
| 97 | |
| 98 | for (action=action->next; action; action = action->next) |
| 99 | seq_printf(p, ", %s", action->name); |
| 100 | |
| 101 | seq_putc(p, '\n'); |
| 102 | skip: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 103 | raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 104 | } else if (i == NR_IRQS) { |
| 105 | seq_printf(p, "NMI: "); |
Andrew Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 106 | for_each_online_cpu(j) |
| 107 | seq_printf(p, "%10u ", nmi_count(j)); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 108 | seq_putc(p, '\n'); |
| 109 | seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count)); |
| 110 | } |
| 111 | return 0; |
| 112 | } |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 113 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 114 | static void xtensa_irq_mask(unsigned int irq) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 115 | { |
| 116 | cached_irq_mask &= ~(1 << irq); |
| 117 | set_sr (cached_irq_mask, INTENABLE); |
| 118 | } |
| 119 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 120 | static void xtensa_irq_unmask(unsigned int irq) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 121 | { |
| 122 | cached_irq_mask |= 1 << irq; |
| 123 | set_sr (cached_irq_mask, INTENABLE); |
| 124 | } |
| 125 | |
Johannes Weiner | 4c0d214 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 126 | static void xtensa_irq_enable(unsigned int irq) |
| 127 | { |
| 128 | variant_irq_enable(irq); |
| 129 | xtensa_irq_unmask(irq); |
| 130 | } |
| 131 | |
| 132 | static void xtensa_irq_disable(unsigned int irq) |
| 133 | { |
| 134 | xtensa_irq_mask(irq); |
| 135 | variant_irq_disable(irq); |
| 136 | } |
| 137 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 138 | static void xtensa_irq_ack(unsigned int irq) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 139 | { |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 140 | set_sr(1 << irq, INTCLEAR); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 143 | static int xtensa_irq_retrigger(unsigned int irq) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 144 | { |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 145 | set_sr (1 << irq, INTSET); |
| 146 | return 1; |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 149 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 150 | static struct irq_chip xtensa_irq_chip = { |
| 151 | .name = "xtensa", |
Johannes Weiner | 4c0d214 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 152 | .enable = xtensa_irq_enable, |
| 153 | .disable = xtensa_irq_disable, |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 154 | .mask = xtensa_irq_mask, |
| 155 | .unmask = xtensa_irq_unmask, |
| 156 | .ack = xtensa_irq_ack, |
| 157 | .retrigger = xtensa_irq_retrigger, |
| 158 | }; |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 159 | |
| 160 | void __init init_IRQ(void) |
| 161 | { |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 162 | int index; |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 163 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 164 | for (index = 0; index < XTENSA_NR_IRQS; index++) { |
| 165 | int mask = 1 << index; |
| 166 | |
| 167 | if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) |
| 168 | set_irq_chip_and_handler(index, &xtensa_irq_chip, |
| 169 | handle_simple_irq); |
| 170 | |
| 171 | else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) |
| 172 | set_irq_chip_and_handler(index, &xtensa_irq_chip, |
| 173 | handle_edge_irq); |
| 174 | |
| 175 | else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) |
| 176 | set_irq_chip_and_handler(index, &xtensa_irq_chip, |
| 177 | handle_level_irq); |
| 178 | |
| 179 | else if (mask & XCHAL_INTTYPE_MASK_TIMER) |
| 180 | set_irq_chip_and_handler(index, &xtensa_irq_chip, |
| 181 | handle_edge_irq); |
| 182 | |
| 183 | else /* XCHAL_INTTYPE_MASK_WRITE_ERROR */ |
| 184 | /* XCHAL_INTTYPE_MASK_NMI */ |
| 185 | |
| 186 | set_irq_chip_and_handler(index, &xtensa_irq_chip, |
| 187 | handle_level_irq); |
| 188 | } |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 189 | |
| 190 | cached_irq_mask = 0; |
Daniel Glöckner | 1beee21 | 2009-05-05 15:03:21 +0000 | [diff] [blame] | 191 | |
| 192 | variant_init_irq(); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 193 | } |