The discovered bit in PGCCSR register indicates if the device has been
[linux-2.6/next.git] / arch / sparc / kernel / irq_64.c
blobd45b710ea7e429eb86c5fbcb1c7fb55c5a2a1f6a
1 /* irq.c: UltraSparc IRQ handling/init/registry.
3 * Copyright (C) 1997, 2007, 2008 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
6 */
8 #include <linux/sched.h>
9 #include <linux/linkage.h>
10 #include <linux/ptrace.h>
11 #include <linux/errno.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/signal.h>
14 #include <linux/mm.h>
15 #include <linux/interrupt.h>
16 #include <linux/slab.h>
17 #include <linux/random.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
20 #include <linux/proc_fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/ftrace.h>
23 #include <linux/irq.h>
24 #include <linux/kmemleak.h>
26 #include <asm/ptrace.h>
27 #include <asm/processor.h>
28 #include <linux/atomic.h>
29 #include <asm/system.h>
30 #include <asm/irq.h>
31 #include <asm/io.h>
32 #include <asm/iommu.h>
33 #include <asm/upa.h>
34 #include <asm/oplib.h>
35 #include <asm/prom.h>
36 #include <asm/timer.h>
37 #include <asm/smp.h>
38 #include <asm/starfire.h>
39 #include <asm/uaccess.h>
40 #include <asm/cache.h>
41 #include <asm/cpudata.h>
42 #include <asm/auxio.h>
43 #include <asm/head.h>
44 #include <asm/hypervisor.h>
45 #include <asm/cacheflush.h>
47 #include "entry.h"
48 #include "cpumap.h"
49 #include "kstack.h"
51 #define NUM_IVECS (IMAP_INR + 1)
53 struct ino_bucket *ivector_table;
54 unsigned long ivector_table_pa;
56 /* On several sun4u processors, it is illegal to mix bypass and
57 * non-bypass accesses. Therefore we access all INO buckets
58 * using bypass accesses only.
60 static unsigned long bucket_get_chain_pa(unsigned long bucket_pa)
62 unsigned long ret;
64 __asm__ __volatile__("ldxa [%1] %2, %0"
65 : "=&r" (ret)
66 : "r" (bucket_pa +
67 offsetof(struct ino_bucket,
68 __irq_chain_pa)),
69 "i" (ASI_PHYS_USE_EC));
71 return ret;
74 static void bucket_clear_chain_pa(unsigned long bucket_pa)
76 __asm__ __volatile__("stxa %%g0, [%0] %1"
77 : /* no outputs */
78 : "r" (bucket_pa +
79 offsetof(struct ino_bucket,
80 __irq_chain_pa)),
81 "i" (ASI_PHYS_USE_EC));
84 static unsigned int bucket_get_irq(unsigned long bucket_pa)
86 unsigned int ret;
88 __asm__ __volatile__("lduwa [%1] %2, %0"
89 : "=&r" (ret)
90 : "r" (bucket_pa +
91 offsetof(struct ino_bucket,
92 __irq)),
93 "i" (ASI_PHYS_USE_EC));
95 return ret;
98 static void bucket_set_irq(unsigned long bucket_pa, unsigned int irq)
100 __asm__ __volatile__("stwa %0, [%1] %2"
101 : /* no outputs */
102 : "r" (irq),
103 "r" (bucket_pa +
104 offsetof(struct ino_bucket,
105 __irq)),
106 "i" (ASI_PHYS_USE_EC));
109 #define irq_work_pa(__cpu) &(trap_block[(__cpu)].irq_worklist_pa)
111 static struct {
112 unsigned int dev_handle;
113 unsigned int dev_ino;
114 unsigned int in_use;
115 } irq_table[NR_IRQS];
116 static DEFINE_SPINLOCK(irq_alloc_lock);
118 unsigned char irq_alloc(unsigned int dev_handle, unsigned int dev_ino)
120 unsigned long flags;
121 unsigned char ent;
123 BUILD_BUG_ON(NR_IRQS >= 256);
125 spin_lock_irqsave(&irq_alloc_lock, flags);
127 for (ent = 1; ent < NR_IRQS; ent++) {
128 if (!irq_table[ent].in_use)
129 break;
131 if (ent >= NR_IRQS) {
132 printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
133 ent = 0;
134 } else {
135 irq_table[ent].dev_handle = dev_handle;
136 irq_table[ent].dev_ino = dev_ino;
137 irq_table[ent].in_use = 1;
140 spin_unlock_irqrestore(&irq_alloc_lock, flags);
142 return ent;
145 #ifdef CONFIG_PCI_MSI
146 void irq_free(unsigned int irq)
148 unsigned long flags;
150 if (irq >= NR_IRQS)
151 return;
153 spin_lock_irqsave(&irq_alloc_lock, flags);
155 irq_table[irq].in_use = 0;
157 spin_unlock_irqrestore(&irq_alloc_lock, flags);
159 #endif
162 * /proc/interrupts printing:
164 int arch_show_interrupts(struct seq_file *p, int prec)
166 int j;
168 seq_printf(p, "NMI: ");
169 for_each_online_cpu(j)
170 seq_printf(p, "%10u ", cpu_data(j).__nmi_count);
171 seq_printf(p, " Non-maskable interrupts\n");
172 return 0;
175 static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
177 unsigned int tid;
179 if (this_is_starfire) {
180 tid = starfire_translate(imap, cpuid);
181 tid <<= IMAP_TID_SHIFT;
182 tid &= IMAP_TID_UPA;
183 } else {
184 if (tlb_type == cheetah || tlb_type == cheetah_plus) {
185 unsigned long ver;
187 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
188 if ((ver >> 32UL) == __JALAPENO_ID ||
189 (ver >> 32UL) == __SERRANO_ID) {
190 tid = cpuid << IMAP_TID_SHIFT;
191 tid &= IMAP_TID_JBUS;
192 } else {
193 unsigned int a = cpuid & 0x1f;
194 unsigned int n = (cpuid >> 5) & 0x1f;
196 tid = ((a << IMAP_AID_SHIFT) |
197 (n << IMAP_NID_SHIFT));
198 tid &= (IMAP_AID_SAFARI |
199 IMAP_NID_SAFARI);
201 } else {
202 tid = cpuid << IMAP_TID_SHIFT;
203 tid &= IMAP_TID_UPA;
207 return tid;
210 struct irq_handler_data {
211 unsigned long iclr;
212 unsigned long imap;
214 void (*pre_handler)(unsigned int, void *, void *);
215 void *arg1;
216 void *arg2;
219 #ifdef CONFIG_SMP
220 static int irq_choose_cpu(unsigned int irq, const struct cpumask *affinity)
222 cpumask_t mask;
223 int cpuid;
225 cpumask_copy(&mask, affinity);
226 if (cpumask_equal(&mask, cpu_online_mask)) {
227 cpuid = map_to_cpu(irq);
228 } else {
229 cpumask_t tmp;
231 cpumask_and(&tmp, cpu_online_mask, &mask);
232 cpuid = cpumask_empty(&tmp) ? map_to_cpu(irq) : cpumask_first(&tmp);
235 return cpuid;
237 #else
238 #define irq_choose_cpu(irq, affinity) \
239 real_hard_smp_processor_id()
240 #endif
242 static void sun4u_irq_enable(struct irq_data *data)
244 struct irq_handler_data *handler_data = data->handler_data;
246 if (likely(handler_data)) {
247 unsigned long cpuid, imap, val;
248 unsigned int tid;
250 cpuid = irq_choose_cpu(data->irq, data->affinity);
251 imap = handler_data->imap;
253 tid = sun4u_compute_tid(imap, cpuid);
255 val = upa_readq(imap);
256 val &= ~(IMAP_TID_UPA | IMAP_TID_JBUS |
257 IMAP_AID_SAFARI | IMAP_NID_SAFARI);
258 val |= tid | IMAP_VALID;
259 upa_writeq(val, imap);
260 upa_writeq(ICLR_IDLE, handler_data->iclr);
264 static int sun4u_set_affinity(struct irq_data *data,
265 const struct cpumask *mask, bool force)
267 struct irq_handler_data *handler_data = data->handler_data;
269 if (likely(handler_data)) {
270 unsigned long cpuid, imap, val;
271 unsigned int tid;
273 cpuid = irq_choose_cpu(data->irq, mask);
274 imap = handler_data->imap;
276 tid = sun4u_compute_tid(imap, cpuid);
278 val = upa_readq(imap);
279 val &= ~(IMAP_TID_UPA | IMAP_TID_JBUS |
280 IMAP_AID_SAFARI | IMAP_NID_SAFARI);
281 val |= tid | IMAP_VALID;
282 upa_writeq(val, imap);
283 upa_writeq(ICLR_IDLE, handler_data->iclr);
286 return 0;
289 /* Don't do anything. The desc->status check for IRQ_DISABLED in
290 * handler_irq() will skip the handler call and that will leave the
291 * interrupt in the sent state. The next ->enable() call will hit the
292 * ICLR register to reset the state machine.
294 * This scheme is necessary, instead of clearing the Valid bit in the
295 * IMAP register, to handle the case of IMAP registers being shared by
296 * multiple INOs (and thus ICLR registers). Since we use a different
297 * virtual IRQ for each shared IMAP instance, the generic code thinks
298 * there is only one user so it prematurely calls ->disable() on
299 * free_irq().
301 * We have to provide an explicit ->disable() method instead of using
302 * NULL to get the default. The reason is that if the generic code
303 * sees that, it also hooks up a default ->shutdown method which
304 * invokes ->mask() which we do not want. See irq_chip_set_defaults().
306 static void sun4u_irq_disable(struct irq_data *data)
310 static void sun4u_irq_eoi(struct irq_data *data)
312 struct irq_handler_data *handler_data = data->handler_data;
314 if (likely(handler_data))
315 upa_writeq(ICLR_IDLE, handler_data->iclr);
318 static void sun4v_irq_enable(struct irq_data *data)
320 unsigned int ino = irq_table[data->irq].dev_ino;
321 unsigned long cpuid = irq_choose_cpu(data->irq, data->affinity);
322 int err;
324 err = sun4v_intr_settarget(ino, cpuid);
325 if (err != HV_EOK)
326 printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
327 "err(%d)\n", ino, cpuid, err);
328 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
329 if (err != HV_EOK)
330 printk(KERN_ERR "sun4v_intr_setstate(%x): "
331 "err(%d)\n", ino, err);
332 err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
333 if (err != HV_EOK)
334 printk(KERN_ERR "sun4v_intr_setenabled(%x): err(%d)\n",
335 ino, err);
338 static int sun4v_set_affinity(struct irq_data *data,
339 const struct cpumask *mask, bool force)
341 unsigned int ino = irq_table[data->irq].dev_ino;
342 unsigned long cpuid = irq_choose_cpu(data->irq, mask);
343 int err;
345 err = sun4v_intr_settarget(ino, cpuid);
346 if (err != HV_EOK)
347 printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
348 "err(%d)\n", ino, cpuid, err);
350 return 0;
353 static void sun4v_irq_disable(struct irq_data *data)
355 unsigned int ino = irq_table[data->irq].dev_ino;
356 int err;
358 err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
359 if (err != HV_EOK)
360 printk(KERN_ERR "sun4v_intr_setenabled(%x): "
361 "err(%d)\n", ino, err);
364 static void sun4v_irq_eoi(struct irq_data *data)
366 unsigned int ino = irq_table[data->irq].dev_ino;
367 int err;
369 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
370 if (err != HV_EOK)
371 printk(KERN_ERR "sun4v_intr_setstate(%x): "
372 "err(%d)\n", ino, err);
375 static void sun4v_virq_enable(struct irq_data *data)
377 unsigned long cpuid, dev_handle, dev_ino;
378 int err;
380 cpuid = irq_choose_cpu(data->irq, data->affinity);
382 dev_handle = irq_table[data->irq].dev_handle;
383 dev_ino = irq_table[data->irq].dev_ino;
385 err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
386 if (err != HV_EOK)
387 printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
388 "err(%d)\n",
389 dev_handle, dev_ino, cpuid, err);
390 err = sun4v_vintr_set_state(dev_handle, dev_ino,
391 HV_INTR_STATE_IDLE);
392 if (err != HV_EOK)
393 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
394 "HV_INTR_STATE_IDLE): err(%d)\n",
395 dev_handle, dev_ino, err);
396 err = sun4v_vintr_set_valid(dev_handle, dev_ino,
397 HV_INTR_ENABLED);
398 if (err != HV_EOK)
399 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
400 "HV_INTR_ENABLED): err(%d)\n",
401 dev_handle, dev_ino, err);
404 static int sun4v_virt_set_affinity(struct irq_data *data,
405 const struct cpumask *mask, bool force)
407 unsigned long cpuid, dev_handle, dev_ino;
408 int err;
410 cpuid = irq_choose_cpu(data->irq, mask);
412 dev_handle = irq_table[data->irq].dev_handle;
413 dev_ino = irq_table[data->irq].dev_ino;
415 err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
416 if (err != HV_EOK)
417 printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
418 "err(%d)\n",
419 dev_handle, dev_ino, cpuid, err);
421 return 0;
424 static void sun4v_virq_disable(struct irq_data *data)
426 unsigned long dev_handle, dev_ino;
427 int err;
429 dev_handle = irq_table[data->irq].dev_handle;
430 dev_ino = irq_table[data->irq].dev_ino;
432 err = sun4v_vintr_set_valid(dev_handle, dev_ino,
433 HV_INTR_DISABLED);
434 if (err != HV_EOK)
435 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
436 "HV_INTR_DISABLED): err(%d)\n",
437 dev_handle, dev_ino, err);
440 static void sun4v_virq_eoi(struct irq_data *data)
442 unsigned long dev_handle, dev_ino;
443 int err;
445 dev_handle = irq_table[data->irq].dev_handle;
446 dev_ino = irq_table[data->irq].dev_ino;
448 err = sun4v_vintr_set_state(dev_handle, dev_ino,
449 HV_INTR_STATE_IDLE);
450 if (err != HV_EOK)
451 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
452 "HV_INTR_STATE_IDLE): err(%d)\n",
453 dev_handle, dev_ino, err);
456 static struct irq_chip sun4u_irq = {
457 .name = "sun4u",
458 .irq_enable = sun4u_irq_enable,
459 .irq_disable = sun4u_irq_disable,
460 .irq_eoi = sun4u_irq_eoi,
461 .irq_set_affinity = sun4u_set_affinity,
462 .flags = IRQCHIP_EOI_IF_HANDLED,
465 static struct irq_chip sun4v_irq = {
466 .name = "sun4v",
467 .irq_enable = sun4v_irq_enable,
468 .irq_disable = sun4v_irq_disable,
469 .irq_eoi = sun4v_irq_eoi,
470 .irq_set_affinity = sun4v_set_affinity,
471 .flags = IRQCHIP_EOI_IF_HANDLED,
474 static struct irq_chip sun4v_virq = {
475 .name = "vsun4v",
476 .irq_enable = sun4v_virq_enable,
477 .irq_disable = sun4v_virq_disable,
478 .irq_eoi = sun4v_virq_eoi,
479 .irq_set_affinity = sun4v_virt_set_affinity,
480 .flags = IRQCHIP_EOI_IF_HANDLED,
483 static void pre_flow_handler(struct irq_data *d)
485 struct irq_handler_data *handler_data = irq_data_get_irq_handler_data(d);
486 unsigned int ino = irq_table[d->irq].dev_ino;
488 handler_data->pre_handler(ino, handler_data->arg1, handler_data->arg2);
491 void irq_install_pre_handler(int irq,
492 void (*func)(unsigned int, void *, void *),
493 void *arg1, void *arg2)
495 struct irq_handler_data *handler_data = irq_get_handler_data(irq);
497 handler_data->pre_handler = func;
498 handler_data->arg1 = arg1;
499 handler_data->arg2 = arg2;
501 __irq_set_preflow_handler(irq, pre_flow_handler);
504 unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
506 struct ino_bucket *bucket;
507 struct irq_handler_data *handler_data;
508 unsigned int irq;
509 int ino;
511 BUG_ON(tlb_type == hypervisor);
513 ino = (upa_readq(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
514 bucket = &ivector_table[ino];
515 irq = bucket_get_irq(__pa(bucket));
516 if (!irq) {
517 irq = irq_alloc(0, ino);
518 bucket_set_irq(__pa(bucket), irq);
519 irq_set_chip_and_handler_name(irq, &sun4u_irq,
520 handle_fasteoi_irq, "IVEC");
523 handler_data = irq_get_handler_data(irq);
524 if (unlikely(handler_data))
525 goto out;
527 handler_data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
528 if (unlikely(!handler_data)) {
529 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
530 prom_halt();
532 irq_set_handler_data(irq, handler_data);
534 handler_data->imap = imap;
535 handler_data->iclr = iclr;
537 out:
538 return irq;
541 static unsigned int sun4v_build_common(unsigned long sysino,
542 struct irq_chip *chip)
544 struct ino_bucket *bucket;
545 struct irq_handler_data *handler_data;
546 unsigned int irq;
548 BUG_ON(tlb_type != hypervisor);
550 bucket = &ivector_table[sysino];
551 irq = bucket_get_irq(__pa(bucket));
552 if (!irq) {
553 irq = irq_alloc(0, sysino);
554 bucket_set_irq(__pa(bucket), irq);
555 irq_set_chip_and_handler_name(irq, chip, handle_fasteoi_irq,
556 "IVEC");
559 handler_data = irq_get_handler_data(irq);
560 if (unlikely(handler_data))
561 goto out;
563 handler_data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
564 if (unlikely(!handler_data)) {
565 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
566 prom_halt();
568 irq_set_handler_data(irq, handler_data);
570 /* Catch accidental accesses to these things. IMAP/ICLR handling
571 * is done by hypervisor calls on sun4v platforms, not by direct
572 * register accesses.
574 handler_data->imap = ~0UL;
575 handler_data->iclr = ~0UL;
577 out:
578 return irq;
581 unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
583 unsigned long sysino = sun4v_devino_to_sysino(devhandle, devino);
585 return sun4v_build_common(sysino, &sun4v_irq);
588 unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino)
590 struct irq_handler_data *handler_data;
591 unsigned long hv_err, cookie;
592 struct ino_bucket *bucket;
593 unsigned int irq;
595 bucket = kzalloc(sizeof(struct ino_bucket), GFP_ATOMIC);
596 if (unlikely(!bucket))
597 return 0;
599 /* The only reference we store to the IRQ bucket is
600 * by physical address which kmemleak can't see, tell
601 * it that this object explicitly is not a leak and
602 * should be scanned.
604 kmemleak_not_leak(bucket);
606 __flush_dcache_range((unsigned long) bucket,
607 ((unsigned long) bucket +
608 sizeof(struct ino_bucket)));
610 irq = irq_alloc(devhandle, devino);
611 bucket_set_irq(__pa(bucket), irq);
613 irq_set_chip_and_handler_name(irq, &sun4v_virq, handle_fasteoi_irq,
614 "IVEC");
616 handler_data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
617 if (unlikely(!handler_data))
618 return 0;
620 /* In order to make the LDC channel startup sequence easier,
621 * especially wrt. locking, we do not let request_irq() enable
622 * the interrupt.
624 irq_set_status_flags(irq, IRQ_NOAUTOEN);
625 irq_set_handler_data(irq, handler_data);
627 /* Catch accidental accesses to these things. IMAP/ICLR handling
628 * is done by hypervisor calls on sun4v platforms, not by direct
629 * register accesses.
631 handler_data->imap = ~0UL;
632 handler_data->iclr = ~0UL;
634 cookie = ~__pa(bucket);
635 hv_err = sun4v_vintr_set_cookie(devhandle, devino, cookie);
636 if (hv_err) {
637 prom_printf("IRQ: Fatal, cannot set cookie for [%x:%x] "
638 "err=%lu\n", devhandle, devino, hv_err);
639 prom_halt();
642 return irq;
645 void ack_bad_irq(unsigned int irq)
647 unsigned int ino = irq_table[irq].dev_ino;
649 if (!ino)
650 ino = 0xdeadbeef;
652 printk(KERN_CRIT "Unexpected IRQ from ino[%x] irq[%u]\n",
653 ino, irq);
656 void *hardirq_stack[NR_CPUS];
657 void *softirq_stack[NR_CPUS];
659 void __irq_entry handler_irq(int pil, struct pt_regs *regs)
661 unsigned long pstate, bucket_pa;
662 struct pt_regs *old_regs;
663 void *orig_sp;
665 clear_softint(1 << pil);
667 old_regs = set_irq_regs(regs);
668 irq_enter();
670 /* Grab an atomic snapshot of the pending IVECs. */
671 __asm__ __volatile__("rdpr %%pstate, %0\n\t"
672 "wrpr %0, %3, %%pstate\n\t"
673 "ldx [%2], %1\n\t"
674 "stx %%g0, [%2]\n\t"
675 "wrpr %0, 0x0, %%pstate\n\t"
676 : "=&r" (pstate), "=&r" (bucket_pa)
677 : "r" (irq_work_pa(smp_processor_id())),
678 "i" (PSTATE_IE)
679 : "memory");
681 orig_sp = set_hardirq_stack();
683 while (bucket_pa) {
684 unsigned long next_pa;
685 unsigned int irq;
687 next_pa = bucket_get_chain_pa(bucket_pa);
688 irq = bucket_get_irq(bucket_pa);
689 bucket_clear_chain_pa(bucket_pa);
691 generic_handle_irq(irq);
693 bucket_pa = next_pa;
696 restore_hardirq_stack(orig_sp);
698 irq_exit();
699 set_irq_regs(old_regs);
702 void do_softirq(void)
704 unsigned long flags;
706 if (in_interrupt())
707 return;
709 local_irq_save(flags);
711 if (local_softirq_pending()) {
712 void *orig_sp, *sp = softirq_stack[smp_processor_id()];
714 sp += THREAD_SIZE - 192 - STACK_BIAS;
716 __asm__ __volatile__("mov %%sp, %0\n\t"
717 "mov %1, %%sp"
718 : "=&r" (orig_sp)
719 : "r" (sp));
720 __do_softirq();
721 __asm__ __volatile__("mov %0, %%sp"
722 : : "r" (orig_sp));
725 local_irq_restore(flags);
728 #ifdef CONFIG_HOTPLUG_CPU
729 void fixup_irqs(void)
731 unsigned int irq;
733 for (irq = 0; irq < NR_IRQS; irq++) {
734 struct irq_desc *desc = irq_to_desc(irq);
735 struct irq_data *data = irq_desc_get_irq_data(desc);
736 unsigned long flags;
738 raw_spin_lock_irqsave(&desc->lock, flags);
739 if (desc->action && !irqd_is_per_cpu(data)) {
740 if (data->chip->irq_set_affinity)
741 data->chip->irq_set_affinity(data,
742 data->affinity,
743 false);
745 raw_spin_unlock_irqrestore(&desc->lock, flags);
748 tick_ops->disable_irq();
750 #endif
752 struct sun5_timer {
753 u64 count0;
754 u64 limit0;
755 u64 count1;
756 u64 limit1;
759 static struct sun5_timer *prom_timers;
760 static u64 prom_limit0, prom_limit1;
762 static void map_prom_timers(void)
764 struct device_node *dp;
765 const unsigned int *addr;
767 /* PROM timer node hangs out in the top level of device siblings... */
768 dp = of_find_node_by_path("/");
769 dp = dp->child;
770 while (dp) {
771 if (!strcmp(dp->name, "counter-timer"))
772 break;
773 dp = dp->sibling;
776 /* Assume if node is not present, PROM uses different tick mechanism
777 * which we should not care about.
779 if (!dp) {
780 prom_timers = (struct sun5_timer *) 0;
781 return;
784 /* If PROM is really using this, it must be mapped by him. */
785 addr = of_get_property(dp, "address", NULL);
786 if (!addr) {
787 prom_printf("PROM does not have timer mapped, trying to continue.\n");
788 prom_timers = (struct sun5_timer *) 0;
789 return;
791 prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
794 static void kill_prom_timer(void)
796 if (!prom_timers)
797 return;
799 /* Save them away for later. */
800 prom_limit0 = prom_timers->limit0;
801 prom_limit1 = prom_timers->limit1;
803 /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
804 * We turn both off here just to be paranoid.
806 prom_timers->limit0 = 0;
807 prom_timers->limit1 = 0;
809 /* Wheee, eat the interrupt packet too... */
810 __asm__ __volatile__(
811 " mov 0x40, %%g2\n"
812 " ldxa [%%g0] %0, %%g1\n"
813 " ldxa [%%g2] %1, %%g1\n"
814 " stxa %%g0, [%%g0] %0\n"
815 " membar #Sync\n"
816 : /* no outputs */
817 : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
818 : "g1", "g2");
821 void notrace init_irqwork_curcpu(void)
823 int cpu = hard_smp_processor_id();
825 trap_block[cpu].irq_worklist_pa = 0UL;
828 /* Please be very careful with register_one_mondo() and
829 * sun4v_register_mondo_queues().
831 * On SMP this gets invoked from the CPU trampoline before
832 * the cpu has fully taken over the trap table from OBP,
833 * and it's kernel stack + %g6 thread register state is
834 * not fully cooked yet.
836 * Therefore you cannot make any OBP calls, not even prom_printf,
837 * from these two routines.
839 static void __cpuinit notrace register_one_mondo(unsigned long paddr, unsigned long type, unsigned long qmask)
841 unsigned long num_entries = (qmask + 1) / 64;
842 unsigned long status;
844 status = sun4v_cpu_qconf(type, paddr, num_entries);
845 if (status != HV_EOK) {
846 prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, "
847 "err %lu\n", type, paddr, num_entries, status);
848 prom_halt();
852 void __cpuinit notrace sun4v_register_mondo_queues(int this_cpu)
854 struct trap_per_cpu *tb = &trap_block[this_cpu];
856 register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO,
857 tb->cpu_mondo_qmask);
858 register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO,
859 tb->dev_mondo_qmask);
860 register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR,
861 tb->resum_qmask);
862 register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR,
863 tb->nonresum_qmask);
866 /* Each queue region must be a power of 2 multiple of 64 bytes in
867 * size. The base real address must be aligned to the size of the
868 * region. Thus, an 8KB queue must be 8KB aligned, for example.
870 static void __init alloc_one_queue(unsigned long *pa_ptr, unsigned long qmask)
872 unsigned long size = PAGE_ALIGN(qmask + 1);
873 unsigned long order = get_order(size);
874 unsigned long p;
876 p = __get_free_pages(GFP_KERNEL, order);
877 if (!p) {
878 prom_printf("SUN4V: Error, cannot allocate queue.\n");
879 prom_halt();
882 *pa_ptr = __pa(p);
885 static void __init init_cpu_send_mondo_info(struct trap_per_cpu *tb)
887 #ifdef CONFIG_SMP
888 unsigned long page;
890 BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
892 page = get_zeroed_page(GFP_KERNEL);
893 if (!page) {
894 prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
895 prom_halt();
898 tb->cpu_mondo_block_pa = __pa(page);
899 tb->cpu_list_pa = __pa(page + 64);
900 #endif
903 /* Allocate mondo and error queues for all possible cpus. */
904 static void __init sun4v_init_mondo_queues(void)
906 int cpu;
908 for_each_possible_cpu(cpu) {
909 struct trap_per_cpu *tb = &trap_block[cpu];
911 alloc_one_queue(&tb->cpu_mondo_pa, tb->cpu_mondo_qmask);
912 alloc_one_queue(&tb->dev_mondo_pa, tb->dev_mondo_qmask);
913 alloc_one_queue(&tb->resum_mondo_pa, tb->resum_qmask);
914 alloc_one_queue(&tb->resum_kernel_buf_pa, tb->resum_qmask);
915 alloc_one_queue(&tb->nonresum_mondo_pa, tb->nonresum_qmask);
916 alloc_one_queue(&tb->nonresum_kernel_buf_pa,
917 tb->nonresum_qmask);
921 static void __init init_send_mondo_info(void)
923 int cpu;
925 for_each_possible_cpu(cpu) {
926 struct trap_per_cpu *tb = &trap_block[cpu];
928 init_cpu_send_mondo_info(tb);
932 static struct irqaction timer_irq_action = {
933 .name = "timer",
936 /* Only invoked on boot processor. */
937 void __init init_IRQ(void)
939 unsigned long size;
941 map_prom_timers();
942 kill_prom_timer();
944 size = sizeof(struct ino_bucket) * NUM_IVECS;
945 ivector_table = kzalloc(size, GFP_KERNEL);
946 if (!ivector_table) {
947 prom_printf("Fatal error, cannot allocate ivector_table\n");
948 prom_halt();
950 __flush_dcache_range((unsigned long) ivector_table,
951 ((unsigned long) ivector_table) + size);
953 ivector_table_pa = __pa(ivector_table);
955 if (tlb_type == hypervisor)
956 sun4v_init_mondo_queues();
958 init_send_mondo_info();
960 if (tlb_type == hypervisor) {
961 /* Load up the boot cpu's entries. */
962 sun4v_register_mondo_queues(hard_smp_processor_id());
965 /* We need to clear any IRQ's pending in the soft interrupt
966 * registers, a spurious one could be left around from the
967 * PROM timer which we just disabled.
969 clear_softint(get_softint());
971 /* Now that ivector table is initialized, it is safe
972 * to receive IRQ vector traps. We will normally take
973 * one or two right now, in case some device PROM used
974 * to boot us wants to speak to us. We just ignore them.
976 __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
977 "or %%g1, %0, %%g1\n\t"
978 "wrpr %%g1, 0x0, %%pstate"
979 : /* No outputs */
980 : "i" (PSTATE_IE)
981 : "g1");
983 irq_to_desc(0)->action = &timer_irq_action;