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 | * |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 7 | * Copyright (C) 2002 - 2013 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 | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 21 | #include <linux/irqchip.h> |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 22 | #include <linux/irqchip/xtensa-mx.h> |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 23 | #include <linux/irqchip/xtensa-pic.h> |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 24 | #include <linux/irqdomain.h> |
Max Filippov | da844a8 | 2012-11-04 00:30:13 +0400 | [diff] [blame] | 25 | #include <linux/of.h> |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 26 | |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 27 | #include <asm/mxregs.h> |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 28 | #include <asm/uaccess.h> |
| 29 | #include <asm/platform.h> |
| 30 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 31 | atomic_t irq_err_count; |
| 32 | |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 33 | asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 34 | { |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 35 | int irq = irq_find_mapping(NULL, hwirq); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 36 | |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 37 | if (hwirq >= NR_IRQS) { |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 38 | printk(KERN_EMERG "%s: cannot handle IRQ %d\n", |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 39 | __func__, hwirq); |
Chris Zankel | fd43fe1 | 2006-12-10 02:18:47 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_DEBUG_STACKOVERFLOW |
| 43 | /* Debugging check for stack overflow: is there less than 1KB free? */ |
| 44 | { |
| 45 | unsigned long sp; |
| 46 | |
| 47 | __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp)); |
| 48 | sp &= THREAD_SIZE - 1; |
| 49 | |
| 50 | if (unlikely(sp < (sizeof(thread_info) + 1024))) |
| 51 | printk("Stack overflow in do_IRQ: %ld\n", |
| 52 | sp - sizeof(struct thread_info)); |
| 53 | } |
| 54 | #endif |
Thomas Gleixner | 495e0c7 | 2011-02-06 22:10:52 +0100 | [diff] [blame] | 55 | generic_handle_irq(irq); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Thomas Gleixner | 47a5d9d | 2011-03-24 18:28:40 +0100 | [diff] [blame] | 58 | int arch_show_interrupts(struct seq_file *p, int prec) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 59 | { |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 60 | #ifdef CONFIG_SMP |
| 61 | show_ipi_list(p, prec); |
| 62 | #endif |
Thomas Gleixner | 47a5d9d | 2011-03-24 18:28:40 +0100 | [diff] [blame] | 63 | seq_printf(p, "%*s: ", prec, "ERR"); |
| 64 | seq_printf(p, "%10u\n", atomic_read(&irq_err_count)); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 65 | return 0; |
| 66 | } |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 67 | |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 68 | int xtensa_irq_domain_xlate(const u32 *intspec, unsigned int intsize, |
| 69 | unsigned long int_irq, unsigned long ext_irq, |
| 70 | unsigned long *out_hwirq, unsigned int *out_type) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 71 | { |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 72 | if (WARN_ON(intsize < 1 || intsize > 2)) |
| 73 | return -EINVAL; |
| 74 | if (intsize == 2 && intspec[1] == 1) { |
| 75 | int_irq = xtensa_map_ext_irq(ext_irq); |
| 76 | if (int_irq < XCHAL_NUM_INTERRUPTS) |
| 77 | *out_hwirq = int_irq; |
| 78 | else |
| 79 | return -EINVAL; |
| 80 | } else { |
| 81 | *out_hwirq = int_irq; |
| 82 | } |
| 83 | *out_type = IRQ_TYPE_NONE; |
| 84 | return 0; |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 87 | int xtensa_irq_map(struct irq_domain *d, unsigned int irq, |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 88 | irq_hw_number_t hw) |
| 89 | { |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 90 | struct irq_chip *irq_chip = d->host_data; |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 91 | u32 mask = 1 << hw; |
| 92 | |
| 93 | if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) { |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 94 | irq_set_chip_and_handler_name(irq, irq_chip, |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 95 | handle_simple_irq, "level"); |
| 96 | irq_set_status_flags(irq, IRQ_LEVEL); |
| 97 | } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) { |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 98 | irq_set_chip_and_handler_name(irq, irq_chip, |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 99 | handle_edge_irq, "edge"); |
| 100 | irq_clear_status_flags(irq, IRQ_LEVEL); |
| 101 | } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) { |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 102 | irq_set_chip_and_handler_name(irq, irq_chip, |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 103 | handle_level_irq, "level"); |
| 104 | irq_set_status_flags(irq, IRQ_LEVEL); |
| 105 | } else if (mask & XCHAL_INTTYPE_MASK_TIMER) { |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 106 | irq_set_chip_and_handler_name(irq, irq_chip, |
| 107 | handle_percpu_irq, "timer"); |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 108 | irq_clear_status_flags(irq, IRQ_LEVEL); |
| 109 | } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */ |
| 110 | /* XCHAL_INTTYPE_MASK_NMI */ |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 111 | irq_set_chip_and_handler_name(irq, irq_chip, |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 112 | handle_level_irq, "level"); |
| 113 | irq_set_status_flags(irq, IRQ_LEVEL); |
| 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 118 | unsigned xtensa_map_ext_irq(unsigned ext_irq) |
Max Filippov | 2206d5d | 2012-11-04 00:29:12 +0400 | [diff] [blame] | 119 | { |
| 120 | unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE | |
| 121 | XCHAL_INTTYPE_MASK_EXTERN_LEVEL; |
| 122 | unsigned i; |
| 123 | |
| 124 | for (i = 0; mask; ++i, mask >>= 1) { |
| 125 | if ((mask & 1) && ext_irq-- == 0) |
| 126 | return i; |
| 127 | } |
| 128 | return XCHAL_NUM_INTERRUPTS; |
| 129 | } |
| 130 | |
Max Filippov | 26a8e96 | 2013-12-01 12:04:57 +0400 | [diff] [blame] | 131 | unsigned xtensa_get_ext_irq_no(unsigned irq) |
| 132 | { |
| 133 | unsigned mask = (XCHAL_INTTYPE_MASK_EXTERN_EDGE | |
| 134 | XCHAL_INTTYPE_MASK_EXTERN_LEVEL) & |
| 135 | ((1u << irq) - 1); |
| 136 | return hweight32(mask); |
| 137 | } |
| 138 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 139 | void __init init_IRQ(void) |
| 140 | { |
Max Filippov | da844a8 | 2012-11-04 00:30:13 +0400 | [diff] [blame] | 141 | #ifdef CONFIG_OF |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 142 | irqchip_init(); |
Max Filippov | da844a8 | 2012-11-04 00:30:13 +0400 | [diff] [blame] | 143 | #else |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 144 | #ifdef CONFIG_HAVE_SMP |
| 145 | xtensa_mx_init_legacy(NULL); |
| 146 | #else |
Max Filippov | cbd1de2 | 2013-12-01 12:59:49 +0400 | [diff] [blame] | 147 | xtensa_pic_init_legacy(NULL); |
Max Filippov | da844a8 | 2012-11-04 00:30:13 +0400 | [diff] [blame] | 148 | #endif |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 149 | #endif |
| 150 | |
| 151 | #ifdef CONFIG_SMP |
| 152 | ipi_init(); |
| 153 | #endif |
Daniel Glöckner | 1beee21 | 2009-05-05 15:03:21 +0000 | [diff] [blame] | 154 | variant_init_irq(); |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 155 | } |
Max Filippov | 49b424f | 2013-10-17 02:42:28 +0400 | [diff] [blame] | 156 | |
| 157 | #ifdef CONFIG_HOTPLUG_CPU |
| 158 | static void route_irq(struct irq_data *data, unsigned int irq, unsigned int cpu) |
| 159 | { |
| 160 | struct irq_desc *desc = irq_to_desc(irq); |
| 161 | struct irq_chip *chip = irq_data_get_irq_chip(data); |
| 162 | unsigned long flags; |
| 163 | |
| 164 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 165 | if (chip->irq_set_affinity) |
| 166 | chip->irq_set_affinity(data, cpumask_of(cpu), false); |
| 167 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * The CPU has been marked offline. Migrate IRQs off this CPU. If |
| 172 | * the affinity settings do not allow other CPUs, force them onto any |
| 173 | * available CPU. |
| 174 | */ |
| 175 | void migrate_irqs(void) |
| 176 | { |
| 177 | unsigned int i, cpu = smp_processor_id(); |
| 178 | struct irq_desc *desc; |
| 179 | |
| 180 | for_each_irq_desc(i, desc) { |
| 181 | struct irq_data *data = irq_desc_get_irq_data(desc); |
| 182 | unsigned int newcpu; |
| 183 | |
| 184 | if (irqd_is_per_cpu(data)) |
| 185 | continue; |
| 186 | |
| 187 | if (!cpumask_test_cpu(cpu, data->affinity)) |
| 188 | continue; |
| 189 | |
| 190 | newcpu = cpumask_any_and(data->affinity, cpu_online_mask); |
| 191 | |
| 192 | if (newcpu >= nr_cpu_ids) { |
| 193 | pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n", |
| 194 | i, cpu); |
| 195 | |
| 196 | cpumask_setall(data->affinity); |
| 197 | newcpu = cpumask_any_and(data->affinity, |
| 198 | cpu_online_mask); |
| 199 | } |
| 200 | |
| 201 | route_irq(data, i, newcpu); |
| 202 | } |
| 203 | } |
| 204 | #endif /* CONFIG_HOTPLUG_CPU */ |