blob: 640479304ac0f9a1e17b33d32b2422283e479ff3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * linux/arch/ia64/kernel/irq_ia64.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1998-2001 Hewlett-Packard Co
5 * Stephane Eranian <eranian@hpl.hp.com>
6 * David Mosberger-Tang <davidm@hpl.hp.com>
7 *
8 * 6/10/99: Updated to bring in sync with x86 version to facilitate
9 * support for SMP and different interrupt controllers.
10 *
11 * 09/15/00 Goutham Rao <goutham.rao@intel.com> Implemented pci_irq_to_vector
12 * PCI to vector allocation routine.
13 * 04/14/2004 Ashok Raj <ashok.raj@intel.com>
14 * Added CPU Hotplug handling for IPF.
15 */
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/module.h>
18
19#include <linux/jiffies.h>
20#include <linux/errno.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/ioport.h>
24#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/ptrace.h>
26#include <linux/random.h> /* for rand_initialize_irq() */
27#include <linux/signal.h>
28#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/threads.h>
30#include <linux/bitops.h>
Eric W. Biedermanb6cf2582006-10-04 02:16:38 -070031#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#include <asm/delay.h>
34#include <asm/intrinsics.h>
35#include <asm/io.h>
36#include <asm/hw_irq.h>
37#include <asm/machvec.h>
38#include <asm/pgtable.h>
39#include <asm/system.h>
Jack Steiner3be44b92007-05-08 14:50:43 -070040#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#ifdef CONFIG_PERFMON
43# include <asm/perfmon.h>
44#endif
45
46#define IRQ_DEBUG 0
47
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +090048#define IRQ_VECTOR_UNASSIGNED (0)
49
50#define IRQ_UNUSED (0)
51#define IRQ_USED (1)
52#define IRQ_RSVD (2)
53
Mark Maule10083072006-04-14 16:03:49 -050054/* These can be overridden in platform_irq_init */
55int ia64_first_device_vector = IA64_DEF_FIRST_DEVICE_VECTOR;
56int ia64_last_device_vector = IA64_DEF_LAST_DEVICE_VECTOR;
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/* default base addr of IPI table */
59void __iomem *ipi_base_addr = ((void __iomem *)
60 (__IA64_UNCACHED_OFFSET | IA64_IPI_DEFAULT_BASE_ADDR));
61
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +090062static cpumask_t vector_allocation_domain(int cpu);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/*
65 * Legacy IRQ to IA-64 vector translation table.
66 */
67__u8 isa_irq_to_vector_map[16] = {
68 /* 8259 IRQ translation, first 16 entries */
69 0x2f, 0x20, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29,
70 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21
71};
72EXPORT_SYMBOL(isa_irq_to_vector_map);
73
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +090074DEFINE_SPINLOCK(vector_lock);
75
76struct irq_cfg irq_cfg[NR_IRQS] __read_mostly = {
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +090077 [0 ... NR_IRQS - 1] = {
78 .vector = IRQ_VECTOR_UNASSIGNED,
79 .domain = CPU_MASK_NONE
80 }
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +090081};
82
83DEFINE_PER_CPU(int[IA64_NUM_VECTORS], vector_irq) = {
Kenji Kaneshige17764d22007-08-28 16:01:21 -070084 [0 ... IA64_NUM_VECTORS - 1] = -1
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +090085};
86
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +090087static cpumask_t vector_table[IA64_NUM_VECTORS] = {
88 [0 ... IA64_NUM_VECTORS - 1] = CPU_MASK_NONE
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +090089};
90
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +090091static int irq_status[NR_IRQS] = {
92 [0 ... NR_IRQS -1] = IRQ_UNUSED
93};
94
95int check_irq_used(int irq)
96{
97 if (irq_status[irq] == IRQ_USED)
98 return 1;
99
100 return -1;
101}
102
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900103static inline int find_unassigned_irq(void)
104{
105 int irq;
106
107 for (irq = IA64_FIRST_DEVICE_VECTOR; irq < NR_IRQS; irq++)
108 if (irq_status[irq] == IRQ_UNUSED)
109 return irq;
110 return -ENOSPC;
111}
112
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900113static inline int find_unassigned_vector(cpumask_t domain)
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900114{
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900115 cpumask_t mask;
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +0900116 int pos, vector;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900117
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900118 cpus_and(mask, domain, cpu_online_map);
119 if (cpus_empty(mask))
120 return -EINVAL;
121
122 for (pos = 0; pos < IA64_NUM_DEVICE_VECTORS; pos++) {
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +0900123 vector = IA64_FIRST_DEVICE_VECTOR + pos;
124 cpus_and(mask, domain, vector_table[vector]);
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900125 if (!cpus_empty(mask))
126 continue;
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +0900127 return vector;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900128 }
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900129 return -ENOSPC;
130}
131
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900132static int __bind_irq_vector(int irq, int vector, cpumask_t domain)
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900133{
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900134 cpumask_t mask;
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +0900135 int cpu;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900136 struct irq_cfg *cfg = &irq_cfg[irq];
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900137
Kenji Kaneshige6bde71e2007-07-26 15:30:45 +0900138 BUG_ON((unsigned)irq >= NR_IRQS);
139 BUG_ON((unsigned)vector >= IA64_NUM_VECTORS);
140
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900141 cpus_and(mask, domain, cpu_online_map);
142 if (cpus_empty(mask))
143 return -EINVAL;
144 if ((cfg->vector == vector) && cpus_equal(cfg->domain, domain))
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900145 return 0;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900146 if (cfg->vector != IRQ_VECTOR_UNASSIGNED)
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900147 return -EBUSY;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900148 for_each_cpu_mask(cpu, mask)
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900149 per_cpu(vector_irq, cpu)[vector] = irq;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900150 cfg->vector = vector;
151 cfg->domain = domain;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900152 irq_status[irq] = IRQ_USED;
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +0900153 cpus_or(vector_table[vector], vector_table[vector], domain);
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900154 return 0;
155}
156
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900157int bind_irq_vector(int irq, int vector, cpumask_t domain)
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900158{
159 unsigned long flags;
160 int ret;
161
162 spin_lock_irqsave(&vector_lock, flags);
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900163 ret = __bind_irq_vector(irq, vector, domain);
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900164 spin_unlock_irqrestore(&vector_lock, flags);
165 return ret;
166}
167
Yasuaki Ishimatsucd378f12007-07-17 21:22:48 +0900168static void __clear_irq_vector(int irq)
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900169{
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +0900170 int vector, cpu;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900171 cpumask_t mask;
172 cpumask_t domain;
173 struct irq_cfg *cfg = &irq_cfg[irq];
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900174
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900175 BUG_ON((unsigned)irq >= NR_IRQS);
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900176 BUG_ON(cfg->vector == IRQ_VECTOR_UNASSIGNED);
177 vector = cfg->vector;
178 domain = cfg->domain;
179 cpus_and(mask, cfg->domain, cpu_online_map);
180 for_each_cpu_mask(cpu, mask)
Kenji Kaneshige17764d22007-08-28 16:01:21 -0700181 per_cpu(vector_irq, cpu)[vector] = -1;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900182 cfg->vector = IRQ_VECTOR_UNASSIGNED;
183 cfg->domain = CPU_MASK_NONE;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900184 irq_status[irq] = IRQ_UNUSED;
Kenji Kaneshige6ffbc822007-07-25 17:59:22 +0900185 cpus_andnot(vector_table[vector], vector_table[vector], domain);
Yasuaki Ishimatsucd378f12007-07-17 21:22:48 +0900186}
187
188static void clear_irq_vector(int irq)
189{
190 unsigned long flags;
191
192 spin_lock_irqsave(&vector_lock, flags);
193 __clear_irq_vector(irq);
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900194 spin_unlock_irqrestore(&vector_lock, flags);
195}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197int
Isaku Yamahata85cbc502008-05-19 22:13:43 +0900198ia64_native_assign_irq_vector (int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900200 unsigned long flags;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900201 int vector, cpu;
Kenji Kaneshige373167e2007-08-22 19:28:36 +0900202 cpumask_t domain = CPU_MASK_NONE;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900203
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900204 vector = -ENOSPC;
205
206 spin_lock_irqsave(&vector_lock, flags);
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900207 for_each_online_cpu(cpu) {
208 domain = vector_allocation_domain(cpu);
209 vector = find_unassigned_vector(domain);
210 if (vector >= 0)
211 break;
212 }
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900213 if (vector < 0)
214 goto out;
Yasuaki Ishimatsu8f5ad1a2007-07-24 22:09:09 +0900215 if (irq == AUTO_ASSIGN)
216 irq = vector;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900217 BUG_ON(__bind_irq_vector(irq, vector, domain));
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900218 out:
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900219 spin_unlock_irqrestore(&vector_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return vector;
221}
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223void
Isaku Yamahata85cbc502008-05-19 22:13:43 +0900224ia64_native_free_irq_vector (int vector)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900226 if (vector < IA64_FIRST_DEVICE_VECTOR ||
227 vector > IA64_LAST_DEVICE_VECTOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900229 clear_irq_vector(vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
231
Mark Maule10083072006-04-14 16:03:49 -0500232int
233reserve_irq_vector (int vector)
234{
Mark Maule10083072006-04-14 16:03:49 -0500235 if (vector < IA64_FIRST_DEVICE_VECTOR ||
236 vector > IA64_LAST_DEVICE_VECTOR)
237 return -EINVAL;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900238 return !!bind_irq_vector(vector, vector, CPU_MASK_ALL);
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900239}
Mark Maule10083072006-04-14 16:03:49 -0500240
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900241/*
242 * Initialize vector_irq on a new cpu. This function must be called
243 * with vector_lock held.
244 */
245void __setup_vector_irq(int cpu)
246{
247 int irq, vector;
248
249 /* Clear vector_irq */
250 for (vector = 0; vector < IA64_NUM_VECTORS; ++vector)
Kenji Kaneshige17764d22007-08-28 16:01:21 -0700251 per_cpu(vector_irq, cpu)[vector] = -1;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900252 /* Mark the inuse vectors */
253 for (irq = 0; irq < NR_IRQS; ++irq) {
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900254 if (!cpu_isset(cpu, irq_cfg[irq].domain))
255 continue;
256 vector = irq_to_vector(irq);
257 per_cpu(vector_irq, cpu)[vector] = irq;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900258 }
259}
260
Yasuaki Ishimatsue5bd7622007-07-17 21:23:03 +0900261#if defined(CONFIG_SMP) && (defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_DIG))
Kenji Kaneshigea6cd63222008-02-25 14:32:22 +0900262
Yasuaki Ishimatsud080d392007-07-17 21:22:55 +0900263static enum vector_domain_type {
264 VECTOR_DOMAIN_NONE,
265 VECTOR_DOMAIN_PERCPU
266} vector_domain_type = VECTOR_DOMAIN_NONE;
267
268static cpumask_t vector_allocation_domain(int cpu)
269{
270 if (vector_domain_type == VECTOR_DOMAIN_PERCPU)
271 return cpumask_of_cpu(cpu);
272 return CPU_MASK_ALL;
273}
274
Kenji Kaneshigea6cd63222008-02-25 14:32:22 +0900275static int __irq_prepare_move(int irq, int cpu)
276{
277 struct irq_cfg *cfg = &irq_cfg[irq];
278 int vector;
279 cpumask_t domain;
280
281 if (cfg->move_in_progress || cfg->move_cleanup_count)
282 return -EBUSY;
283 if (cfg->vector == IRQ_VECTOR_UNASSIGNED || !cpu_online(cpu))
284 return -EINVAL;
285 if (cpu_isset(cpu, cfg->domain))
286 return 0;
287 domain = vector_allocation_domain(cpu);
288 vector = find_unassigned_vector(domain);
289 if (vector < 0)
290 return -ENOSPC;
291 cfg->move_in_progress = 1;
292 cfg->old_domain = cfg->domain;
293 cfg->vector = IRQ_VECTOR_UNASSIGNED;
294 cfg->domain = CPU_MASK_NONE;
295 BUG_ON(__bind_irq_vector(irq, vector, domain));
296 return 0;
297}
298
299int irq_prepare_move(int irq, int cpu)
300{
301 unsigned long flags;
302 int ret;
303
304 spin_lock_irqsave(&vector_lock, flags);
305 ret = __irq_prepare_move(irq, cpu);
306 spin_unlock_irqrestore(&vector_lock, flags);
307 return ret;
308}
309
310void irq_complete_move(unsigned irq)
311{
312 struct irq_cfg *cfg = &irq_cfg[irq];
313 cpumask_t cleanup_mask;
314 int i;
315
316 if (likely(!cfg->move_in_progress))
317 return;
318
319 if (unlikely(cpu_isset(smp_processor_id(), cfg->old_domain)))
320 return;
321
322 cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map);
323 cfg->move_cleanup_count = cpus_weight(cleanup_mask);
324 for_each_cpu_mask(i, cleanup_mask)
325 platform_send_ipi(i, IA64_IRQ_MOVE_VECTOR, IA64_IPI_DM_INT, 0);
326 cfg->move_in_progress = 0;
327}
328
329static irqreturn_t smp_irq_move_cleanup_interrupt(int irq, void *dev_id)
330{
331 int me = smp_processor_id();
332 ia64_vector vector;
333 unsigned long flags;
334
335 for (vector = IA64_FIRST_DEVICE_VECTOR;
336 vector < IA64_LAST_DEVICE_VECTOR; vector++) {
337 int irq;
338 struct irq_desc *desc;
339 struct irq_cfg *cfg;
340 irq = __get_cpu_var(vector_irq)[vector];
341 if (irq < 0)
342 continue;
343
344 desc = irq_desc + irq;
345 cfg = irq_cfg + irq;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100346 raw_spin_lock(&desc->lock);
Kenji Kaneshigea6cd63222008-02-25 14:32:22 +0900347 if (!cfg->move_cleanup_count)
348 goto unlock;
349
350 if (!cpu_isset(me, cfg->old_domain))
351 goto unlock;
352
353 spin_lock_irqsave(&vector_lock, flags);
354 __get_cpu_var(vector_irq)[vector] = -1;
355 cpu_clear(me, vector_table[vector]);
356 spin_unlock_irqrestore(&vector_lock, flags);
357 cfg->move_cleanup_count--;
358 unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100359 raw_spin_unlock(&desc->lock);
Kenji Kaneshigea6cd63222008-02-25 14:32:22 +0900360 }
361 return IRQ_HANDLED;
362}
363
364static struct irqaction irq_move_irqaction = {
365 .handler = smp_irq_move_cleanup_interrupt,
366 .flags = IRQF_DISABLED,
367 .name = "irq_move"
368};
369
Yasuaki Ishimatsud080d392007-07-17 21:22:55 +0900370static int __init parse_vector_domain(char *arg)
371{
372 if (!arg)
373 return -EINVAL;
374 if (!strcmp(arg, "percpu")) {
375 vector_domain_type = VECTOR_DOMAIN_PERCPU;
376 no_int_routing = 1;
377 }
Kenji Kaneshige074ff852007-07-26 15:32:38 +0900378 return 0;
Yasuaki Ishimatsud080d392007-07-17 21:22:55 +0900379}
380early_param("vector", parse_vector_domain);
381#else
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900382static cpumask_t vector_allocation_domain(int cpu)
383{
384 return CPU_MASK_ALL;
385}
Yasuaki Ishimatsud080d392007-07-17 21:22:55 +0900386#endif
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900387
388
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900389void destroy_and_reserve_irq(unsigned int irq)
390{
Kenji Kaneshige216fcd22007-07-30 11:56:30 +0900391 unsigned long flags;
392
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900393 dynamic_irq_cleanup(irq);
394
Kenji Kaneshige216fcd22007-07-30 11:56:30 +0900395 spin_lock_irqsave(&vector_lock, flags);
396 __clear_irq_vector(irq);
397 irq_status[irq] = IRQ_RSVD;
398 spin_unlock_irqrestore(&vector_lock, flags);
Mark Maule10083072006-04-14 16:03:49 -0500399}
400
Eric W. Biedermanb6cf2582006-10-04 02:16:38 -0700401/*
402 * Dynamic irq allocate and deallocation for MSI
403 */
404int create_irq(void)
405{
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900406 unsigned long flags;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900407 int irq, vector, cpu;
Kenji Kaneshige373167e2007-08-22 19:28:36 +0900408 cpumask_t domain = CPU_MASK_NONE;
Eric W. Biedermanb6cf2582006-10-04 02:16:38 -0700409
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900410 irq = vector = -ENOSPC;
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900411 spin_lock_irqsave(&vector_lock, flags);
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900412 for_each_online_cpu(cpu) {
413 domain = vector_allocation_domain(cpu);
414 vector = find_unassigned_vector(domain);
415 if (vector >= 0)
416 break;
417 }
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900418 if (vector < 0)
419 goto out;
420 irq = find_unassigned_irq();
421 if (irq < 0)
422 goto out;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900423 BUG_ON(__bind_irq_vector(irq, vector, domain));
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900424 out:
425 spin_unlock_irqrestore(&vector_lock, flags);
426 if (irq >= 0)
427 dynamic_irq_init(irq);
428 return irq;
Eric W. Biedermanb6cf2582006-10-04 02:16:38 -0700429}
430
431void destroy_irq(unsigned int irq)
432{
433 dynamic_irq_cleanup(irq);
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900434 clear_irq_vector(irq);
Eric W. Biedermanb6cf2582006-10-04 02:16:38 -0700435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#ifdef CONFIG_SMP
438# define IS_RESCHEDULE(vec) (vec == IA64_IPI_RESCHEDULE)
Jack Steiner3be44b92007-05-08 14:50:43 -0700439# define IS_LOCAL_TLB_FLUSH(vec) (vec == IA64_IPI_LOCAL_TLB_FLUSH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#else
441# define IS_RESCHEDULE(vec) (0)
Jack Steiner3be44b92007-05-08 14:50:43 -0700442# define IS_LOCAL_TLB_FLUSH(vec) (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#endif
444/*
445 * That's where the IVT branches when we get an external
446 * interrupt. This branches to the correct hardware IRQ handler via
447 * function ptr.
448 */
449void
450ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
451{
David Howells7d12e782006-10-05 14:55:46 +0100452 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 unsigned long saved_tpr;
454
455#if IRQ_DEBUG
456 {
457 unsigned long bsp, sp;
458
459 /*
460 * Note: if the interrupt happened while executing in
461 * the context switch routine (ia64_switch_to), we may
462 * get a spurious stack overflow here. This is
463 * because the register and the memory stack are not
464 * switched atomically.
465 */
466 bsp = ia64_getreg(_IA64_REG_AR_BSP);
467 sp = ia64_getreg(_IA64_REG_SP);
468
469 if ((sp - bsp) < 1024) {
470 static unsigned char count;
471 static long last_time;
472
S.Caglar Onur5cf1f7c2008-03-28 14:27:05 -0700473 if (time_after(jiffies, last_time + 5 * HZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 count = 0;
475 if (++count < 5) {
476 last_time = jiffies;
477 printk("ia64_handle_irq: DANGER: less than "
478 "1KB of free stack space!!\n"
479 "(bsp=0x%lx, sp=%lx)\n", bsp, sp);
480 }
481 }
482 }
483#endif /* IRQ_DEBUG */
484
485 /*
486 * Always set TPR to limit maximum interrupt nesting depth to
487 * 16 (without this, it would be ~240, which could easily lead
488 * to kernel stack overflows).
489 */
490 irq_enter();
491 saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
492 ia64_srlz_d();
493 while (vector != IA64_SPURIOUS_INT_VECTOR) {
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100494 int irq = local_vector_to_irq(vector);
Linus Torvalds7c730cc2009-03-28 13:40:20 -0700495 struct irq_desc *desc = irq_to_desc(irq);
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100496
Jack Steiner3be44b92007-05-08 14:50:43 -0700497 if (unlikely(IS_LOCAL_TLB_FLUSH(vector))) {
498 smp_local_flush_tlb();
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100499 kstat_incr_irqs_this_cpu(irq, desc);
Linus Torvalds7c730cc2009-03-28 13:40:20 -0700500 } else if (unlikely(IS_RESCHEDULE(vector))) {
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100501 kstat_incr_irqs_this_cpu(irq, desc);
Linus Torvalds7c730cc2009-03-28 13:40:20 -0700502 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 ia64_setreg(_IA64_REG_CR_TPR, vector);
504 ia64_srlz_d();
505
Kenji Kaneshige17764d22007-08-28 16:01:21 -0700506 if (unlikely(irq < 0)) {
507 printk(KERN_ERR "%s: Unexpected interrupt "
508 "vector %d on CPU %d is not mapped "
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800509 "to any IRQ!\n", __func__, vector,
Kenji Kaneshige17764d22007-08-28 16:01:21 -0700510 smp_processor_id());
511 } else
512 generic_handle_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 /*
515 * Disable interrupts and send EOI:
516 */
517 local_irq_disable();
518 ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
519 }
520 ia64_eoi();
521 vector = ia64_get_ivr();
522 }
523 /*
524 * This must be done *after* the ia64_eoi(). For example, the keyboard softirq
525 * handler needs to be able to wait for further keyboard interrupts, which can't
526 * come through until ia64_eoi() has been done.
527 */
528 irq_exit();
David Howells7d12e782006-10-05 14:55:46 +0100529 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530}
531
532#ifdef CONFIG_HOTPLUG_CPU
533/*
534 * This function emulates a interrupt processing when a cpu is about to be
535 * brought down.
536 */
537void ia64_process_pending_intr(void)
538{
539 ia64_vector vector;
540 unsigned long saved_tpr;
541 extern unsigned int vectors_in_migration[NR_IRQS];
542
543 vector = ia64_get_ivr();
544
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100545 irq_enter();
546 saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
547 ia64_srlz_d();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 /*
550 * Perform normal interrupt style processing
551 */
552 while (vector != IA64_SPURIOUS_INT_VECTOR) {
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100553 int irq = local_vector_to_irq(vector);
Linus Torvalds7c730cc2009-03-28 13:40:20 -0700554 struct irq_desc *desc = irq_to_desc(irq);
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100555
Jack Steiner3be44b92007-05-08 14:50:43 -0700556 if (unlikely(IS_LOCAL_TLB_FLUSH(vector))) {
557 smp_local_flush_tlb();
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100558 kstat_incr_irqs_this_cpu(irq, desc);
Linus Torvalds7c730cc2009-03-28 13:40:20 -0700559 } else if (unlikely(IS_RESCHEDULE(vector))) {
Jes Sorensen66f3e6a2009-03-27 16:55:41 +0100560 kstat_incr_irqs_this_cpu(irq, desc);
Linus Torvalds7c730cc2009-03-28 13:40:20 -0700561 } else {
Tony Luck8c1addb2006-10-06 10:09:41 -0700562 struct pt_regs *old_regs = set_irq_regs(NULL);
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 ia64_setreg(_IA64_REG_CR_TPR, vector);
565 ia64_srlz_d();
566
567 /*
568 * Now try calling normal ia64_handle_irq as it would have got called
569 * from a real intr handler. Try passing null for pt_regs, hopefully
570 * it will work. I hope it works!.
571 * Probably could shared code.
572 */
Kenji Kaneshige17764d22007-08-28 16:01:21 -0700573 if (unlikely(irq < 0)) {
574 printk(KERN_ERR "%s: Unexpected interrupt "
575 "vector %d on CPU %d not being mapped "
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800576 "to any IRQ!!\n", __func__, vector,
Kenji Kaneshige17764d22007-08-28 16:01:21 -0700577 smp_processor_id());
578 } else {
579 vectors_in_migration[irq]=0;
580 generic_handle_irq(irq);
581 }
Tony Luck8c1addb2006-10-06 10:09:41 -0700582 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 /*
585 * Disable interrupts and send EOI
586 */
587 local_irq_disable();
588 ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
589 }
590 ia64_eoi();
591 vector = ia64_get_ivr();
592 }
593 irq_exit();
594}
595#endif
596
597
598#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Jack Steiner9b3377f2006-10-16 16:17:43 -0500600static irqreturn_t dummy_handler (int irq, void *dev_id)
601{
602 BUG();
603}
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605static struct irqaction ipi_irqaction = {
606 .handler = handle_IPI,
Thomas Gleixner121a4222006-07-01 19:29:17 -0700607 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .name = "IPI"
609};
Jack Steiner9b3377f2006-10-16 16:17:43 -0500610
Marcelo Tosatti32f88402009-05-07 17:55:12 -0300611/*
612 * KVM uses this interrupt to force a cpu out of guest mode
613 */
Jack Steiner9b3377f2006-10-16 16:17:43 -0500614static struct irqaction resched_irqaction = {
615 .handler = dummy_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -0800616 .flags = IRQF_DISABLED,
Jack Steiner9b3377f2006-10-16 16:17:43 -0500617 .name = "resched"
618};
Jack Steiner3be44b92007-05-08 14:50:43 -0700619
620static struct irqaction tlb_irqaction = {
621 .handler = dummy_handler,
akpm@linux-foundation.org53295712007-05-09 00:43:17 -0700622 .flags = IRQF_DISABLED,
Jack Steiner3be44b92007-05-08 14:50:43 -0700623 .name = "tlb_flush"
624};
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#endif
627
628void
Isaku Yamahata85cbc502008-05-19 22:13:43 +0900629ia64_native_register_percpu_irq (ia64_vector vec, struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Thomas Gleixner86bc3df2009-06-10 12:45:00 -0700631 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 unsigned int irq;
633
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900634 irq = vec;
Yasuaki Ishimatsu4994be12007-07-17 21:22:33 +0900635 BUG_ON(bind_irq_vector(irq, vec, CPU_MASK_ALL));
Yasuaki Ishimatsue1b30a32007-07-17 21:22:23 +0900636 desc = irq_desc + irq;
637 desc->status |= IRQ_PER_CPU;
638 desc->chip = &irq_type_ia64_lsapic;
639 if (action)
640 setup_irq(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641}
642
643void __init
Isaku Yamahata85cbc502008-05-19 22:13:43 +0900644ia64_native_register_ipi(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#ifdef CONFIG_SMP
647 register_percpu_irq(IA64_IPI_VECTOR, &ipi_irqaction);
Jack Steiner9b3377f2006-10-16 16:17:43 -0500648 register_percpu_irq(IA64_IPI_RESCHEDULE, &resched_irqaction);
Jack Steiner3be44b92007-05-08 14:50:43 -0700649 register_percpu_irq(IA64_IPI_LOCAL_TLB_FLUSH, &tlb_irqaction);
Isaku Yamahata85cbc502008-05-19 22:13:43 +0900650#endif
651}
652
653void __init
654init_IRQ (void)
655{
656 ia64_register_ipi();
657 register_percpu_irq(IA64_SPURIOUS_INT_VECTOR, NULL);
658#ifdef CONFIG_SMP
Kenji Kaneshigea6cd63222008-02-25 14:32:22 +0900659#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_DIG)
Kenji Kaneshige09b366b2009-12-09 10:56:41 +0900660 if (vector_domain_type != VECTOR_DOMAIN_NONE)
Kenji Kaneshigea6cd63222008-02-25 14:32:22 +0900661 register_percpu_irq(IA64_IRQ_MOVE_VECTOR, &irq_move_irqaction);
Kenji Kaneshigea6cd63222008-02-25 14:32:22 +0900662#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663#endif
664#ifdef CONFIG_PERFMON
665 pfm_init_percpu();
666#endif
667 platform_irq_init();
668}
669
670void
671ia64_send_ipi (int cpu, int vector, int delivery_mode, int redirect)
672{
673 void __iomem *ipi_addr;
674 unsigned long ipi_data;
675 unsigned long phys_cpu_id;
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 phys_cpu_id = cpu_physical_id(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 /*
680 * cpu number is in 8bit ID and 8bit EID
681 */
682
683 ipi_data = (delivery_mode << 8) | (vector & 0xff);
684 ipi_addr = ipi_base_addr + ((phys_cpu_id << 4) | ((redirect & 1) << 3));
685
686 writeq(ipi_data, ipi_addr);
687}