aboutsummaryrefslogtreecommitdiffstats
path: root/arch/xtensa/kernel/irq.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/xtensa/kernel/irq.c')
-rw-r--r--arch/xtensa/kernel/irq.c207
1 files changed, 97 insertions, 110 deletions
diff --git a/arch/xtensa/kernel/irq.c b/arch/xtensa/kernel/irq.c
index 6f4f9749cff7..482868a2de6e 100644
--- a/arch/xtensa/kernel/irq.c
+++ b/arch/xtensa/kernel/irq.c
@@ -4,7 +4,7 @@
4 * Xtensa built-in interrupt controller and some generic functions copied 4 * Xtensa built-in interrupt controller and some generic functions copied
5 * from i386. 5 * from i386.
6 * 6 *
7 * Copyright (C) 2002 - 2006 Tensilica, Inc. 7 * Copyright (C) 2002 - 2013 Tensilica, Inc.
8 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar 8 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
9 * 9 *
10 * 10 *
@@ -18,36 +18,27 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/irq.h> 19#include <linux/irq.h>
20#include <linux/kernel_stat.h> 20#include <linux/kernel_stat.h>
21#include <linux/irqchip.h>
22#include <linux/irqchip/xtensa-mx.h>
23#include <linux/irqchip/xtensa-pic.h>
21#include <linux/irqdomain.h> 24#include <linux/irqdomain.h>
22#include <linux/of.h> 25#include <linux/of.h>
23 26
27#include <asm/mxregs.h>
24#include <asm/uaccess.h> 28#include <asm/uaccess.h>
25#include <asm/platform.h> 29#include <asm/platform.h>
26 30
27static unsigned int cached_irq_mask;
28
29atomic_t irq_err_count; 31atomic_t irq_err_count;
30 32
31static struct irq_domain *root_domain;
32
33/*
34 * do_IRQ handles all normal device IRQ's (the special
35 * SMP cross-CPU interrupts have their own specific
36 * handlers).
37 */
38
39asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs) 33asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
40{ 34{
41 struct pt_regs *old_regs = set_irq_regs(regs); 35 int irq = irq_find_mapping(NULL, hwirq);
42 int irq = irq_find_mapping(root_domain, hwirq);
43 36
44 if (hwirq >= NR_IRQS) { 37 if (hwirq >= NR_IRQS) {
45 printk(KERN_EMERG "%s: cannot handle IRQ %d\n", 38 printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
46 __func__, hwirq); 39 __func__, hwirq);
47 } 40 }
48 41
49 irq_enter();
50
51#ifdef CONFIG_DEBUG_STACKOVERFLOW 42#ifdef CONFIG_DEBUG_STACKOVERFLOW
52 /* Debugging check for stack overflow: is there less than 1KB free? */ 43 /* Debugging check for stack overflow: is there less than 1KB free? */
53 { 44 {
@@ -62,95 +53,69 @@ asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
62 } 53 }
63#endif 54#endif
64 generic_handle_irq(irq); 55 generic_handle_irq(irq);
65
66 irq_exit();
67 set_irq_regs(old_regs);
68} 56}
69 57
70int arch_show_interrupts(struct seq_file *p, int prec) 58int arch_show_interrupts(struct seq_file *p, int prec)
71{ 59{
60#ifdef CONFIG_SMP
61 show_ipi_list(p, prec);
62#endif
72 seq_printf(p, "%*s: ", prec, "ERR"); 63 seq_printf(p, "%*s: ", prec, "ERR");
73 seq_printf(p, "%10u\n", atomic_read(&irq_err_count)); 64 seq_printf(p, "%10u\n", atomic_read(&irq_err_count));
74 return 0; 65 return 0;
75} 66}
76 67
77static void xtensa_irq_mask(struct irq_data *d) 68int xtensa_irq_domain_xlate(const u32 *intspec, unsigned int intsize,
78{ 69 unsigned long int_irq, unsigned long ext_irq,
79 cached_irq_mask &= ~(1 << d->hwirq); 70 unsigned long *out_hwirq, unsigned int *out_type)
80 set_sr (cached_irq_mask, intenable);
81}
82
83static void xtensa_irq_unmask(struct irq_data *d)
84{
85 cached_irq_mask |= 1 << d->hwirq;
86 set_sr (cached_irq_mask, intenable);
87}
88
89static void xtensa_irq_enable(struct irq_data *d)
90{
91 variant_irq_enable(d->hwirq);
92 xtensa_irq_unmask(d);
93}
94
95static void xtensa_irq_disable(struct irq_data *d)
96{
97 xtensa_irq_mask(d);
98 variant_irq_disable(d->hwirq);
99}
100
101static void xtensa_irq_ack(struct irq_data *d)
102{
103 set_sr(1 << d->hwirq, intclear);
104}
105
106static int xtensa_irq_retrigger(struct irq_data *d)
107{ 71{
108 set_sr(1 << d->hwirq, intset); 72 if (WARN_ON(intsize < 1 || intsize > 2))
109 return 1; 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;
110} 85}
111 86
112static struct irq_chip xtensa_irq_chip = { 87int xtensa_irq_map(struct irq_domain *d, unsigned int irq,
113 .name = "xtensa",
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,
120};
121
122static int xtensa_irq_map(struct irq_domain *d, unsigned int irq,
123 irq_hw_number_t hw) 88 irq_hw_number_t hw)
124{ 89{
90 struct irq_chip *irq_chip = d->host_data;
125 u32 mask = 1 << hw; 91 u32 mask = 1 << hw;
126 92
127 if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) { 93 if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) {
128 irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, 94 irq_set_chip_and_handler_name(irq, irq_chip,
129 handle_simple_irq, "level"); 95 handle_simple_irq, "level");
130 irq_set_status_flags(irq, IRQ_LEVEL); 96 irq_set_status_flags(irq, IRQ_LEVEL);
131 } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) { 97 } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) {
132 irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, 98 irq_set_chip_and_handler_name(irq, irq_chip,
133 handle_edge_irq, "edge"); 99 handle_edge_irq, "edge");
134 irq_clear_status_flags(irq, IRQ_LEVEL); 100 irq_clear_status_flags(irq, IRQ_LEVEL);
135 } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) { 101 } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) {
136 irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, 102 irq_set_chip_and_handler_name(irq, irq_chip,
137 handle_level_irq, "level"); 103 handle_level_irq, "level");
138 irq_set_status_flags(irq, IRQ_LEVEL); 104 irq_set_status_flags(irq, IRQ_LEVEL);
139 } else if (mask & XCHAL_INTTYPE_MASK_TIMER) { 105 } else if (mask & XCHAL_INTTYPE_MASK_TIMER) {
140 irq_set_chip_and_handler_name(irq, &xtensa_irq_chip, 106 irq_set_chip_and_handler_name(irq, irq_chip,
141 handle_edge_irq, "edge"); 107 handle_percpu_irq, "timer");
142 irq_clear_status_flags(irq, IRQ_LEVEL); 108 irq_clear_status_flags(irq, IRQ_LEVEL);
143 } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */ 109 } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */
144 /* XCHAL_INTTYPE_MASK_NMI */ 110 /* XCHAL_INTTYPE_MASK_NMI */
145 111 irq_set_chip_and_handler_name(irq, irq_chip,
146 irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
147 handle_level_irq, "level"); 112 handle_level_irq, "level");
148 irq_set_status_flags(irq, IRQ_LEVEL); 113 irq_set_status_flags(irq, IRQ_LEVEL);
149 } 114 }
150 return 0; 115 return 0;
151} 116}
152 117
153static unsigned map_ext_irq(unsigned ext_irq) 118unsigned xtensa_map_ext_irq(unsigned ext_irq)
154{ 119{
155 unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE | 120 unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE |
156 XCHAL_INTTYPE_MASK_EXTERN_LEVEL; 121 XCHAL_INTTYPE_MASK_EXTERN_LEVEL;
@@ -163,55 +128,77 @@ static unsigned map_ext_irq(unsigned ext_irq)
163 return XCHAL_NUM_INTERRUPTS; 128 return XCHAL_NUM_INTERRUPTS;
164} 129}
165 130
166/* 131unsigned xtensa_get_ext_irq_no(unsigned irq)
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 */
172int 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{ 132{
176 if (WARN_ON(intsize < 1 || intsize > 2)) 133 unsigned mask = (XCHAL_INTTYPE_MASK_EXTERN_EDGE |
177 return -EINVAL; 134 XCHAL_INTTYPE_MASK_EXTERN_LEVEL) &
178 if (intsize == 2 && intspec[1] == 1) { 135 ((1u << irq) - 1);
179 unsigned int_irq = map_ext_irq(intspec[0]); 136 return hweight32(mask);
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} 137}
190 138
191static const struct irq_domain_ops xtensa_irq_domain_ops = {
192 .xlate = xtensa_irq_domain_xlate,
193 .map = xtensa_irq_map,
194};
195
196void __init init_IRQ(void) 139void __init init_IRQ(void)
197{ 140{
198 struct device_node *intc = NULL;
199
200 cached_irq_mask = 0;
201 set_sr(~0, intclear);
202
203#ifdef CONFIG_OF 141#ifdef CONFIG_OF
204 /* The interrupt controller device node is mandatory */ 142 irqchip_init();
205 intc = of_find_compatible_node(NULL, NULL, "xtensa,pic"); 143#else
206 BUG_ON(!intc); 144#ifdef CONFIG_HAVE_SMP
207 145 xtensa_mx_init_legacy(NULL);
208 root_domain = irq_domain_add_linear(intc, NR_IRQS,
209 &xtensa_irq_domain_ops, NULL);
210#else 146#else
211 root_domain = irq_domain_add_legacy(intc, NR_IRQS, 0, 0, 147 xtensa_pic_init_legacy(NULL);
212 &xtensa_irq_domain_ops, NULL); 148#endif
213#endif 149#endif
214 irq_set_default_host(root_domain);
215 150
151#ifdef CONFIG_SMP
152 ipi_init();
153#endif
216 variant_init_irq(); 154 variant_init_irq();
217} 155}
156
157#ifdef CONFIG_HOTPLUG_CPU
158static 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 */
175void 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 */