ia64/xen-unstable

view linux-2.6-xen-sparse/arch/ia64/kernel/irq_ia64.c @ 10814:e917cda4b0a8

[IA64] remove a debug message

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Thu Jul 27 09:16:32 2006 -0600 (2006-07-27)
parents 4ebb9c91c886
children 1464adb95681
line source
1 /*
2 * linux/arch/ia64/kernel/irq.c
3 *
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 */
17 #include <linux/config.h>
18 #include <linux/module.h>
20 #include <linux/jiffies.h>
21 #include <linux/errno.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/ioport.h>
25 #include <linux/kernel_stat.h>
26 #include <linux/slab.h>
27 #include <linux/ptrace.h>
28 #include <linux/random.h> /* for rand_initialize_irq() */
29 #include <linux/signal.h>
30 #include <linux/smp.h>
31 #include <linux/smp_lock.h>
32 #include <linux/threads.h>
33 #include <linux/bitops.h>
34 #ifdef CONFIG_XEN
35 #include <linux/cpu.h>
36 #endif
38 #include <asm/delay.h>
39 #include <asm/intrinsics.h>
40 #include <asm/io.h>
41 #include <asm/hw_irq.h>
42 #include <asm/machvec.h>
43 #include <asm/pgtable.h>
44 #include <asm/system.h>
46 #ifdef CONFIG_PERFMON
47 # include <asm/perfmon.h>
48 #endif
50 #define IRQ_DEBUG 0
52 /* default base addr of IPI table */
53 void __iomem *ipi_base_addr = ((void __iomem *)
54 (__IA64_UNCACHED_OFFSET | IA64_IPI_DEFAULT_BASE_ADDR));
56 /*
57 * Legacy IRQ to IA-64 vector translation table.
58 */
59 __u8 isa_irq_to_vector_map[16] = {
60 /* 8259 IRQ translation, first 16 entries */
61 0x2f, 0x20, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29,
62 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21
63 };
64 EXPORT_SYMBOL(isa_irq_to_vector_map);
66 static unsigned long ia64_vector_mask[BITS_TO_LONGS(IA64_NUM_DEVICE_VECTORS)];
68 int
69 assign_irq_vector (int irq)
70 {
71 int pos, vector;
73 #ifdef CONFIG_XEN
74 if (is_running_on_xen()) {
75 extern int xen_assign_irq_vector(int);
76 return xen_assign_irq_vector(irq);
77 }
78 #endif
79 again:
80 pos = find_first_zero_bit(ia64_vector_mask, IA64_NUM_DEVICE_VECTORS);
81 vector = IA64_FIRST_DEVICE_VECTOR + pos;
82 if (vector > IA64_LAST_DEVICE_VECTOR)
83 return -ENOSPC;
84 if (test_and_set_bit(pos, ia64_vector_mask))
85 goto again;
86 return vector;
87 }
89 void
90 free_irq_vector (int vector)
91 {
92 int pos;
94 if (vector < IA64_FIRST_DEVICE_VECTOR || vector > IA64_LAST_DEVICE_VECTOR)
95 return;
97 pos = vector - IA64_FIRST_DEVICE_VECTOR;
98 if (!test_and_clear_bit(pos, ia64_vector_mask))
99 printk(KERN_WARNING "%s: double free!\n", __FUNCTION__);
100 }
102 #ifdef CONFIG_SMP
103 # define IS_RESCHEDULE(vec) (vec == IA64_IPI_RESCHEDULE)
104 #else
105 # define IS_RESCHEDULE(vec) (0)
106 #endif
107 /*
108 * That's where the IVT branches when we get an external
109 * interrupt. This branches to the correct hardware IRQ handler via
110 * function ptr.
111 */
112 void
113 ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
114 {
115 unsigned long saved_tpr;
117 #if IRQ_DEBUG
118 {
119 unsigned long bsp, sp;
121 /*
122 * Note: if the interrupt happened while executing in
123 * the context switch routine (ia64_switch_to), we may
124 * get a spurious stack overflow here. This is
125 * because the register and the memory stack are not
126 * switched atomically.
127 */
128 bsp = ia64_getreg(_IA64_REG_AR_BSP);
129 sp = ia64_getreg(_IA64_REG_SP);
131 if ((sp - bsp) < 1024) {
132 static unsigned char count;
133 static long last_time;
135 if (jiffies - last_time > 5*HZ)
136 count = 0;
137 if (++count < 5) {
138 last_time = jiffies;
139 printk("ia64_handle_irq: DANGER: less than "
140 "1KB of free stack space!!\n"
141 "(bsp=0x%lx, sp=%lx)\n", bsp, sp);
142 }
143 }
144 }
145 #endif /* IRQ_DEBUG */
147 /*
148 * Always set TPR to limit maximum interrupt nesting depth to
149 * 16 (without this, it would be ~240, which could easily lead
150 * to kernel stack overflows).
151 */
152 irq_enter();
153 saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
154 ia64_srlz_d();
155 while (vector != IA64_SPURIOUS_INT_VECTOR) {
156 if (!IS_RESCHEDULE(vector)) {
157 ia64_setreg(_IA64_REG_CR_TPR, vector);
158 ia64_srlz_d();
160 __do_IRQ(local_vector_to_irq(vector), regs);
162 /*
163 * Disable interrupts and send EOI:
164 */
165 local_irq_disable();
166 ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
167 }
168 ia64_eoi();
169 vector = ia64_get_ivr();
170 }
171 /*
172 * This must be done *after* the ia64_eoi(). For example, the keyboard softirq
173 * handler needs to be able to wait for further keyboard interrupts, which can't
174 * come through until ia64_eoi() has been done.
175 */
176 irq_exit();
177 }
179 #ifdef CONFIG_HOTPLUG_CPU
180 /*
181 * This function emulates a interrupt processing when a cpu is about to be
182 * brought down.
183 */
184 void ia64_process_pending_intr(void)
185 {
186 ia64_vector vector;
187 unsigned long saved_tpr;
188 extern unsigned int vectors_in_migration[NR_IRQS];
190 vector = ia64_get_ivr();
192 irq_enter();
193 saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
194 ia64_srlz_d();
196 /*
197 * Perform normal interrupt style processing
198 */
199 while (vector != IA64_SPURIOUS_INT_VECTOR) {
200 if (!IS_RESCHEDULE(vector)) {
201 ia64_setreg(_IA64_REG_CR_TPR, vector);
202 ia64_srlz_d();
204 /*
205 * Now try calling normal ia64_handle_irq as it would have got called
206 * from a real intr handler. Try passing null for pt_regs, hopefully
207 * it will work. I hope it works!.
208 * Probably could shared code.
209 */
210 vectors_in_migration[local_vector_to_irq(vector)]=0;
211 __do_IRQ(local_vector_to_irq(vector), NULL);
213 /*
214 * Disable interrupts and send EOI
215 */
216 local_irq_disable();
217 ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
218 }
219 ia64_eoi();
220 vector = ia64_get_ivr();
221 }
222 irq_exit();
223 }
224 #endif
227 #ifdef CONFIG_SMP
228 extern irqreturn_t handle_IPI (int irq, void *dev_id, struct pt_regs *regs);
230 static struct irqaction ipi_irqaction = {
231 .handler = handle_IPI,
232 .flags = SA_INTERRUPT,
233 .name = "IPI"
234 };
235 #endif
237 #ifdef CONFIG_XEN
238 #include <xen/evtchn.h>
239 #include <xen/interface/callback.h>
241 static DEFINE_PER_CPU(int, timer_irq) = -1;
242 static DEFINE_PER_CPU(int, ipi_irq) = -1;
243 static DEFINE_PER_CPU(int, resched_irq) = -1;
244 static char timer_name[NR_CPUS][15];
245 static char ipi_name[NR_CPUS][15];
246 static char resched_name[NR_CPUS][15];
248 struct saved_irq {
249 unsigned int irq;
250 struct irqaction *action;
251 };
252 /* 16 should be far optimistic value, since only several percpu irqs
253 * are registered early.
254 */
255 #define MAX_LATE_IRQ 16
256 static struct saved_irq saved_percpu_irqs[MAX_LATE_IRQ];
257 static unsigned short late_irq_cnt = 0;
258 static unsigned short saved_irq_cnt = 0;
259 static int xen_slab_ready = 0;
261 #ifdef CONFIG_SMP
262 /* Dummy stub. Though we may check RESCHEDULE_VECTOR before __do_IRQ,
263 * it ends up to issue several memory accesses upon percpu data and
264 * thus adds unnecessary traffic to other paths.
265 */
266 static irqreturn_t
267 handle_reschedule(int irq, void *dev_id, struct pt_regs *regs)
268 {
270 return IRQ_HANDLED;
271 }
273 static struct irqaction resched_irqaction = {
274 .handler = handle_reschedule,
275 .flags = SA_INTERRUPT,
276 .name = "RESCHED"
277 };
278 #endif
280 /*
281 * This is xen version percpu irq registration, which needs bind
282 * to xen specific evtchn sub-system. One trick here is that xen
283 * evtchn binding interface depends on kmalloc because related
284 * port needs to be freed at device/cpu down. So we cache the
285 * registration on BSP before slab is ready and then deal them
286 * at later point. For rest instances happening after slab ready,
287 * we hook them to xen evtchn immediately.
288 *
289 * FIXME: MCA is not supported by far, and thus "nomca" boot param is
290 * required.
291 */
292 static void
293 xen_register_percpu_irq (unsigned int irq, struct irqaction *action, int save)
294 {
295 unsigned int cpu = smp_processor_id();
296 int ret = 0;
298 if (xen_slab_ready) {
299 switch (irq) {
300 case IA64_TIMER_VECTOR:
301 sprintf(timer_name[cpu], "%s%d", action->name, cpu);
302 ret = bind_virq_to_irqhandler(VIRQ_ITC, cpu,
303 action->handler, action->flags,
304 timer_name[cpu], action->dev_id);
305 per_cpu(timer_irq,cpu) = ret;
306 printk(KERN_INFO "register VIRQ_ITC (%s) to xen irq (%d)\n", timer_name[cpu], ret);
307 break;
308 case IA64_IPI_RESCHEDULE:
309 sprintf(resched_name[cpu], "%s%d", action->name, cpu);
310 ret = bind_ipi_to_irqhandler(RESCHEDULE_VECTOR, cpu,
311 action->handler, action->flags,
312 resched_name[cpu], action->dev_id);
313 per_cpu(resched_irq,cpu) = ret;
314 printk(KERN_INFO "register RESCHEDULE_VECTOR (%s) to xen irq (%d)\n", resched_name[cpu], ret);
315 break;
316 case IA64_IPI_VECTOR:
317 sprintf(ipi_name[cpu], "%s%d", action->name, cpu);
318 ret = bind_ipi_to_irqhandler(IPI_VECTOR, cpu,
319 action->handler, action->flags,
320 ipi_name[cpu], action->dev_id);
321 per_cpu(ipi_irq,cpu) = ret;
322 printk(KERN_INFO "register IPI_VECTOR (%s) to xen irq (%d)\n", ipi_name[cpu], ret);
323 break;
324 case IA64_SPURIOUS_INT_VECTOR:
325 break;
326 default:
327 printk(KERN_WARNING "Percpu irq %d is unsupported by xen!\n", irq);
328 break;
329 }
330 BUG_ON(ret < 0);
331 }
333 /* For BSP, we cache registered percpu irqs, and then re-walk
334 * them when initializing APs
335 */
336 if (!cpu && save) {
337 BUG_ON(saved_irq_cnt == MAX_LATE_IRQ);
338 saved_percpu_irqs[saved_irq_cnt].irq = irq;
339 saved_percpu_irqs[saved_irq_cnt].action = action;
340 saved_irq_cnt++;
341 if (!xen_slab_ready)
342 late_irq_cnt++;
343 }
344 }
346 static void
347 xen_bind_early_percpu_irq (void)
348 {
349 int i;
351 xen_slab_ready = 1;
352 /* There's no race when accessing this cached array, since only
353 * BSP will face with such step shortly
354 */
355 for (i = 0; i < late_irq_cnt; i++)
356 xen_register_percpu_irq(saved_percpu_irqs[i].irq,
357 saved_percpu_irqs[i].action, 0);
358 }
360 /* FIXME: There's no obvious point to check whether slab is ready. So
361 * a hack is used here by utilizing a late time hook.
362 */
363 extern void (*late_time_init)(void);
364 extern char xen_event_callback;
365 extern void xen_init_IRQ(void);
367 #ifdef CONFIG_HOTPLUG_CPU
368 static int __devinit
369 unbind_evtchn_callback(struct notifier_block *nfb,
370 unsigned long action, void *hcpu)
371 {
372 unsigned int cpu = (unsigned long)hcpu;
374 if (action == CPU_DEAD) {
375 /* Unregister evtchn. */
376 if (per_cpu(ipi_irq,cpu) >= 0) {
377 unbind_from_irqhandler (per_cpu(ipi_irq, cpu), NULL);
378 per_cpu(ipi_irq, cpu) = -1;
379 }
380 if (per_cpu(resched_irq,cpu) >= 0) {
381 unbind_from_irqhandler (per_cpu(resched_irq, cpu),
382 NULL);
383 per_cpu(resched_irq, cpu) = -1;
384 }
385 if (per_cpu(timer_irq,cpu) >= 0) {
386 unbind_from_irqhandler (per_cpu(timer_irq, cpu), NULL);
387 per_cpu(timer_irq, cpu) = -1;
388 }
389 }
390 return NOTIFY_OK;
391 }
393 static struct notifier_block unbind_evtchn_notifier = {
394 .notifier_call = unbind_evtchn_callback,
395 .priority = 0
396 };
397 #endif
399 DECLARE_PER_CPU(int, ipi_to_irq[NR_IPIS]);
400 void xen_smp_intr_init(void)
401 {
402 #ifdef CONFIG_SMP
403 unsigned int cpu = smp_processor_id();
404 unsigned int i = 0;
405 struct callback_register event = {
406 .type = CALLBACKTYPE_event,
407 .address = (unsigned long)&xen_event_callback,
408 };
410 if (cpu == 0) {
411 /* Initialization was already done for boot cpu. */
412 #ifdef CONFIG_HOTPLUG_CPU
413 /* Register the notifier only once. */
414 register_cpu_notifier(&unbind_evtchn_notifier);
415 #endif
416 return;
417 }
419 /* This should be piggyback when setup vcpu guest context */
420 BUG_ON(HYPERVISOR_callback_op(CALLBACKOP_register, &event));
422 for (i = 0; i < saved_irq_cnt; i++)
423 xen_register_percpu_irq(saved_percpu_irqs[i].irq,
424 saved_percpu_irqs[i].action, 0);
425 #endif /* CONFIG_SMP */
426 }
427 #endif /* CONFIG_XEN */
429 void
430 register_percpu_irq (ia64_vector vec, struct irqaction *action)
431 {
432 irq_desc_t *desc;
433 unsigned int irq;
435 #ifdef CONFIG_XEN
436 if (is_running_on_xen())
437 return xen_register_percpu_irq(vec, action, 1);
438 #endif
440 for (irq = 0; irq < NR_IRQS; ++irq)
441 if (irq_to_vector(irq) == vec) {
442 desc = irq_descp(irq);
443 desc->status |= IRQ_PER_CPU;
444 desc->handler = &irq_type_ia64_lsapic;
445 if (action)
446 setup_irq(irq, action);
447 }
448 }
450 void __init
451 init_IRQ (void)
452 {
453 #ifdef CONFIG_XEN
454 /* Maybe put into platform_irq_init later */
455 if (is_running_on_xen()) {
456 struct callback_register event = {
457 .type = CALLBACKTYPE_event,
458 .address = (unsigned long)&xen_event_callback,
459 };
460 xen_init_IRQ();
461 BUG_ON(HYPERVISOR_callback_op(CALLBACKOP_register, &event));
462 late_time_init = xen_bind_early_percpu_irq;
463 #ifdef CONFIG_SMP
464 register_percpu_irq(IA64_IPI_RESCHEDULE, &resched_irqaction);
465 #endif /* CONFIG_SMP */
466 }
467 #endif /* CONFIG_XEN */
468 register_percpu_irq(IA64_SPURIOUS_INT_VECTOR, NULL);
469 #ifdef CONFIG_SMP
470 register_percpu_irq(IA64_IPI_VECTOR, &ipi_irqaction);
471 #endif
472 #ifdef CONFIG_PERFMON
473 pfm_init_percpu();
474 #endif
475 platform_irq_init();
476 }
478 void
479 ia64_send_ipi (int cpu, int vector, int delivery_mode, int redirect)
480 {
481 void __iomem *ipi_addr;
482 unsigned long ipi_data;
483 unsigned long phys_cpu_id;
485 #ifdef CONFIG_XEN
486 if (is_running_on_xen()) {
487 int irq = -1;
489 #ifdef CONFIG_SMP
490 /* TODO: we need to call vcpu_up here */
491 if (unlikely(vector == ap_wakeup_vector)) {
492 extern void xen_send_ipi (int cpu, int vec);
493 xen_send_ipi (cpu, vector);
494 //vcpu_prepare_and_up(cpu);
495 return;
496 }
497 #endif
499 switch(vector) {
500 case IA64_IPI_VECTOR:
501 irq = per_cpu(ipi_to_irq, cpu)[IPI_VECTOR];
502 break;
503 case IA64_IPI_RESCHEDULE:
504 irq = per_cpu(ipi_to_irq, cpu)[RESCHEDULE_VECTOR];
505 break;
506 default:
507 printk(KERN_WARNING"Unsupported IPI type 0x%x\n", vector);
508 irq = 0;
509 break;
510 }
512 BUG_ON(irq < 0);
513 notify_remote_via_irq(irq);
514 return;
515 }
516 #endif /* CONFIG_XEN */
518 #ifdef CONFIG_SMP
519 phys_cpu_id = cpu_physical_id(cpu);
520 #else
521 phys_cpu_id = (ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff;
522 #endif
524 /*
525 * cpu number is in 8bit ID and 8bit EID
526 */
528 ipi_data = (delivery_mode << 8) | (vector & 0xff);
529 ipi_addr = ipi_base_addr + ((phys_cpu_id << 4) | ((redirect & 1) << 3));
531 writeq(ipi_data, ipi_addr);
532 }