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> |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 21 | #include <linux/irqdomain.h> |
Max Filippov | da844a8 | 2012-11-04 00:30:13 +0400 | [diff] [blame] | 22 | #include <linux/of.h> |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 23 | |
| 24 | #include <asm/uaccess.h> |
| 25 | #include <asm/platform.h> |
| 26 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 27 | static unsigned int cached_irq_mask; |
| 28 | |
| 29 | atomic_t irq_err_count; |
| 30 | |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 31 | static struct irq_domain *root_domain; |
| 32 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 33 | /* |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 34 | * do_IRQ handles all normal device IRQ's (the special |
| 35 | * SMP cross-CPU interrupts have their own specific |
| 36 | * handlers). |
| 37 | */ |
| 38 | |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 39 | asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 40 | { |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 41 | struct pt_regs *old_regs = set_irq_regs(regs); |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 42 | int irq = irq_find_mapping(root_domain, hwirq); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 43 | |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 44 | if (hwirq >= NR_IRQS) { |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 45 | printk(KERN_EMERG "%s: cannot handle IRQ %d\n", |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 46 | __func__, hwirq); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 49 | irq_enter(); |
| 50 | |
| 51 | #ifdef CONFIG_DEBUG_STACKOVERFLOW |
| 52 | /* Debugging check for stack overflow: is there less than 1KB free? */ |
| 53 | { |
| 54 | unsigned long sp; |
| 55 | |
| 56 | __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp)); |
| 57 | sp &= THREAD_SIZE - 1; |
| 58 | |
| 59 | if (unlikely(sp < (sizeof(thread_info) + 1024))) |
| 60 | printk("Stack overflow in do_IRQ: %ld\n", |
| 61 | sp - sizeof(struct thread_info)); |
| 62 | } |
| 63 | #endif |
Thomas Gleixner | 495e0c7 | 2011-02-06 22:10:52 +0100 | [diff] [blame] | 64 | generic_handle_irq(irq); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 65 | |
| 66 | irq_exit(); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 67 | set_irq_regs(old_regs); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Thomas Gleixner | 47a5d9d | 2011-03-24 18:28:40 +0100 | [diff] [blame] | 70 | int arch_show_interrupts(struct seq_file *p, int prec) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 71 | { |
Thomas Gleixner | 47a5d9d | 2011-03-24 18:28:40 +0100 | [diff] [blame] | 72 | seq_printf(p, "%*s: ", prec, "ERR"); |
| 73 | seq_printf(p, "%10u\n", atomic_read(&irq_err_count)); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 74 | return 0; |
| 75 | } |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 76 | |
Thomas Gleixner | 2ea4db6 | 2011-04-19 22:52:58 +0200 | [diff] [blame] | 77 | static void xtensa_irq_mask(struct irq_data *d) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 78 | { |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 79 | cached_irq_mask &= ~(1 << d->hwirq); |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 80 | set_sr (cached_irq_mask, intenable); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Thomas Gleixner | 2ea4db6 | 2011-04-19 22:52:58 +0200 | [diff] [blame] | 83 | static void xtensa_irq_unmask(struct irq_data *d) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 84 | { |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 85 | cached_irq_mask |= 1 << d->hwirq; |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 86 | set_sr (cached_irq_mask, intenable); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Thomas Gleixner | 2ea4db6 | 2011-04-19 22:52:58 +0200 | [diff] [blame] | 89 | static void xtensa_irq_enable(struct irq_data *d) |
Johannes Weiner | 4c0d2141 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 90 | { |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 91 | variant_irq_enable(d->hwirq); |
Max Filippov | 33c8213 | 2012-09-17 05:44:34 +0400 | [diff] [blame] | 92 | xtensa_irq_unmask(d); |
Johannes Weiner | 4c0d2141 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Thomas Gleixner | 2ea4db6 | 2011-04-19 22:52:58 +0200 | [diff] [blame] | 95 | static void xtensa_irq_disable(struct irq_data *d) |
Johannes Weiner | 4c0d2141 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 96 | { |
Max Filippov | 33c8213 | 2012-09-17 05:44:34 +0400 | [diff] [blame] | 97 | xtensa_irq_mask(d); |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 98 | variant_irq_disable(d->hwirq); |
Johannes Weiner | 4c0d2141 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Thomas Gleixner | 2ea4db6 | 2011-04-19 22:52:58 +0200 | [diff] [blame] | 101 | static void xtensa_irq_ack(struct irq_data *d) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 102 | { |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 103 | set_sr(1 << d->hwirq, intclear); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Thomas Gleixner | 2ea4db6 | 2011-04-19 22:52:58 +0200 | [diff] [blame] | 106 | static int xtensa_irq_retrigger(struct irq_data *d) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 107 | { |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 108 | set_sr(1 << d->hwirq, intset); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 109 | return 1; |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 112 | static struct irq_chip xtensa_irq_chip = { |
| 113 | .name = "xtensa", |
Thomas Gleixner | 495e0c7 | 2011-02-06 22:10:52 +0100 | [diff] [blame] | 114 | .irq_enable = xtensa_irq_enable, |
| 115 | .irq_disable = xtensa_irq_disable, |
| 116 | .irq_mask = xtensa_irq_mask, |
| 117 | .irq_unmask = xtensa_irq_unmask, |
| 118 | .irq_ack = xtensa_irq_ack, |
| 119 | .irq_retrigger = xtensa_irq_retrigger, |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 120 | }; |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 121 | |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 122 | static int xtensa_irq_map(struct irq_domain *d, unsigned int irq, |
| 123 | irq_hw_number_t hw) |
| 124 | { |
| 125 | u32 mask = 1 << hw; |
| 126 | |
| 127 | if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) { |
| 128 | irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, |
| 129 | handle_simple_irq, "level"); |
| 130 | irq_set_status_flags(irq, IRQ_LEVEL); |
| 131 | } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) { |
| 132 | irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, |
| 133 | handle_edge_irq, "edge"); |
| 134 | irq_clear_status_flags(irq, IRQ_LEVEL); |
| 135 | } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) { |
| 136 | irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, |
| 137 | handle_level_irq, "level"); |
| 138 | irq_set_status_flags(irq, IRQ_LEVEL); |
| 139 | } else if (mask & XCHAL_INTTYPE_MASK_TIMER) { |
| 140 | irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, |
| 141 | handle_edge_irq, "edge"); |
| 142 | irq_clear_status_flags(irq, IRQ_LEVEL); |
| 143 | } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */ |
| 144 | /* XCHAL_INTTYPE_MASK_NMI */ |
| 145 | |
| 146 | irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, |
| 147 | handle_level_irq, "level"); |
| 148 | irq_set_status_flags(irq, IRQ_LEVEL); |
| 149 | } |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static unsigned map_ext_irq(unsigned ext_irq) |
| 154 | { |
| 155 | unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE | |
| 156 | XCHAL_INTTYPE_MASK_EXTERN_LEVEL; |
| 157 | unsigned i; |
| 158 | |
| 159 | for (i = 0; mask; ++i, mask >>= 1) { |
| 160 | if ((mask & 1) && ext_irq-- == 0) |
| 161 | return i; |
| 162 | } |
| 163 | return XCHAL_NUM_INTERRUPTS; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Device Tree IRQ specifier translation function which works with one or |
| 168 | * two cell bindings. First cell value maps directly to the hwirq number. |
| 169 | * Second cell if present specifies whether hwirq number is external (1) or |
| 170 | * internal (0). |
| 171 | */ |
| 172 | int xtensa_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr, |
| 173 | const u32 *intspec, unsigned int intsize, |
| 174 | unsigned long *out_hwirq, unsigned int *out_type) |
| 175 | { |
| 176 | if (WARN_ON(intsize < 1 || intsize > 2)) |
| 177 | return -EINVAL; |
| 178 | if (intsize == 2 && intspec[1] == 1) { |
| 179 | unsigned int_irq = map_ext_irq(intspec[0]); |
| 180 | if (int_irq < XCHAL_NUM_INTERRUPTS) |
| 181 | *out_hwirq = int_irq; |
| 182 | else |
| 183 | return -EINVAL; |
| 184 | } else { |
| 185 | *out_hwirq = intspec[0]; |
| 186 | } |
| 187 | *out_type = IRQ_TYPE_NONE; |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static const struct irq_domain_ops xtensa_irq_domain_ops = { |
| 192 | .xlate = xtensa_irq_domain_xlate, |
| 193 | .map = xtensa_irq_map, |
| 194 | }; |
| 195 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 196 | void __init init_IRQ(void) |
| 197 | { |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 198 | struct device_node *intc = NULL; |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 199 | |
| 200 | cached_irq_mask = 0; |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 201 | set_sr(~0, intclear); |
| 202 | |
Max Filippov | da844a8 | 2012-11-04 00:30:13 +0400 | [diff] [blame] | 203 | #ifdef CONFIG_OF |
| 204 | /* The interrupt controller device node is mandatory */ |
| 205 | intc = of_find_compatible_node(NULL, NULL, "xtensa,pic"); |
| 206 | BUG_ON(!intc); |
| 207 | |
| 208 | root_domain = irq_domain_add_linear(intc, NR_IRQS, |
| 209 | &xtensa_irq_domain_ops, NULL); |
| 210 | #else |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 211 | root_domain = irq_domain_add_legacy(intc, NR_IRQS, 0, 0, |
| 212 | &xtensa_irq_domain_ops, NULL); |
Max Filippov | da844a8 | 2012-11-04 00:30:13 +0400 | [diff] [blame] | 213 | #endif |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 214 | irq_set_default_host(root_domain); |
Daniel Glöckner | 1beee21 | 2009-05-05 15:03:21 +0000 | [diff] [blame] | 215 | |
| 216 | variant_init_irq(); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 217 | } |