1 /* irq.c: UltraSparc IRQ handling/init/registry.
3 * Copyright (C) 1997, 2007 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)
8 #include <linux/module.h>
9 #include <linux/sched.h>
10 #include <linux/ptrace.h>
11 #include <linux/errno.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/signal.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/bootmem.h>
23 #include <linux/irq.h>
25 #include <asm/ptrace.h>
26 #include <asm/processor.h>
27 #include <asm/atomic.h>
28 #include <asm/system.h>
32 #include <asm/iommu.h>
34 #include <asm/oplib.h>
36 #include <asm/timer.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>
44 #include <asm/hypervisor.h>
45 #include <asm/cacheflush.h>
47 /* UPA nodes send interrupt packet to UltraSparc with first data reg
48 * value low 5 (7 on Starfire) bits holding the IRQ identifier being
49 * delivered. We must translate this into a non-vector IRQ so we can
50 * set the softint on this cpu.
52 * To make processing these packets efficient and race free we use
53 * an array of irq buckets below. The interrupt vector handler in
54 * entry.S feeds incoming packets into per-cpu pil-indexed lists.
56 * If you make changes to ino_bucket, please update hand coded assembler
57 * of the vectored interrupt trap handler(s) in entry.S and sun4v_ivec.S
60 /*0x00*/unsigned long __irq_chain_pa;
62 /* Virtual interrupt number assigned to this INO. */
63 /*0x08*/unsigned int __virt_irq;
64 /*0x0c*/unsigned int __pad;
67 #define NUM_IVECS (IMAP_INR + 1)
68 struct ino_bucket *ivector_table;
69 unsigned long ivector_table_pa;
71 /* On several sun4u processors, it is illegal to mix bypass and
72 * non-bypass accesses. Therefore we access all INO buckets
73 * using bypass accesses only.
75 static unsigned long bucket_get_chain_pa(unsigned long bucket_pa)
79 __asm__ __volatile__("ldxa [%1] %2, %0"
82 offsetof(struct ino_bucket,
84 "i" (ASI_PHYS_USE_EC));
89 static void bucket_clear_chain_pa(unsigned long bucket_pa)
91 __asm__ __volatile__("stxa %%g0, [%0] %1"
94 offsetof(struct ino_bucket,
96 "i" (ASI_PHYS_USE_EC));
99 static unsigned int bucket_get_virt_irq(unsigned long bucket_pa)
103 __asm__ __volatile__("lduwa [%1] %2, %0"
106 offsetof(struct ino_bucket,
108 "i" (ASI_PHYS_USE_EC));
113 static void bucket_set_virt_irq(unsigned long bucket_pa,
114 unsigned int virt_irq)
116 __asm__ __volatile__("stwa %0, [%1] %2"
120 offsetof(struct ino_bucket,
122 "i" (ASI_PHYS_USE_EC));
125 #define __bucket(irq) ((struct ino_bucket *)(irq))
126 #define __irq(bucket) ((unsigned long)(bucket))
128 #define irq_work_pa(__cpu) &(trap_block[(__cpu)].irq_worklist_pa)
132 unsigned int dev_handle;
133 unsigned int dev_ino;
134 } virt_to_real_irq_table[NR_IRQS];
135 static DEFINE_SPINLOCK(virt_irq_alloc_lock);
137 unsigned char virt_irq_alloc(unsigned long real_irq,
138 unsigned int dev_handle,
139 unsigned int dev_ino)
144 BUILD_BUG_ON(NR_IRQS >= 256);
146 spin_lock_irqsave(&virt_irq_alloc_lock, flags);
148 for (ent = 1; ent < NR_IRQS; ent++) {
149 if (!virt_to_real_irq_table[ent].irq)
152 if (ent >= NR_IRQS) {
153 printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
156 virt_to_real_irq_table[ent].irq = real_irq;
157 virt_to_real_irq_table[ent].dev_handle = dev_handle;
158 virt_to_real_irq_table[ent].dev_ino = dev_ino;
161 spin_unlock_irqrestore(&virt_irq_alloc_lock, flags);
166 #ifdef CONFIG_PCI_MSI
167 void virt_irq_free(unsigned int virt_irq)
171 if (virt_irq >= NR_IRQS)
174 spin_lock_irqsave(&virt_irq_alloc_lock, flags);
176 virt_to_real_irq_table[virt_irq].irq = 0;
178 spin_unlock_irqrestore(&virt_irq_alloc_lock, flags);
182 static unsigned long virt_to_real_irq(unsigned char virt_irq)
184 return virt_to_real_irq_table[virt_irq].irq;
188 * /proc/interrupts printing:
191 int show_interrupts(struct seq_file *p, void *v)
193 int i = *(loff_t *) v, j;
194 struct irqaction * action;
199 for_each_online_cpu(j)
200 seq_printf(p, "CPU%d ",j);
205 spin_lock_irqsave(&irq_desc[i].lock, flags);
206 action = irq_desc[i].action;
209 seq_printf(p, "%3d: ",i);
211 seq_printf(p, "%10u ", kstat_irqs(i));
213 for_each_online_cpu(j)
214 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
216 seq_printf(p, " %9s", irq_desc[i].chip->typename);
217 seq_printf(p, " %s", action->name);
219 for (action=action->next; action; action = action->next)
220 seq_printf(p, ", %s", action->name);
224 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
229 static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
233 if (this_is_starfire) {
234 tid = starfire_translate(imap, cpuid);
235 tid <<= IMAP_TID_SHIFT;
238 if (tlb_type == cheetah || tlb_type == cheetah_plus) {
241 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
242 if ((ver >> 32UL) == __JALAPENO_ID ||
243 (ver >> 32UL) == __SERRANO_ID) {
244 tid = cpuid << IMAP_TID_SHIFT;
245 tid &= IMAP_TID_JBUS;
247 unsigned int a = cpuid & 0x1f;
248 unsigned int n = (cpuid >> 5) & 0x1f;
250 tid = ((a << IMAP_AID_SHIFT) |
251 (n << IMAP_NID_SHIFT));
252 tid &= (IMAP_AID_SAFARI |
256 tid = cpuid << IMAP_TID_SHIFT;
264 struct irq_handler_data {
268 void (*pre_handler)(unsigned int, void *, void *);
269 void *pre_handler_arg1;
270 void *pre_handler_arg2;
273 static inline struct ino_bucket *virt_irq_to_bucket(unsigned int virt_irq)
275 unsigned long real_irq = virt_to_real_irq(virt_irq);
276 struct ino_bucket *bucket = NULL;
278 if (likely(real_irq))
279 bucket = __bucket(real_irq);
285 static int irq_choose_cpu(unsigned int virt_irq)
287 cpumask_t mask = irq_desc[virt_irq].affinity;
290 if (cpus_equal(mask, CPU_MASK_ALL)) {
291 static int irq_rover;
292 static DEFINE_SPINLOCK(irq_rover_lock);
295 /* Round-robin distribution... */
297 spin_lock_irqsave(&irq_rover_lock, flags);
299 while (!cpu_online(irq_rover)) {
300 if (++irq_rover >= NR_CPUS)
305 if (++irq_rover >= NR_CPUS)
307 } while (!cpu_online(irq_rover));
309 spin_unlock_irqrestore(&irq_rover_lock, flags);
313 cpus_and(tmp, cpu_online_map, mask);
318 cpuid = first_cpu(tmp);
324 static int irq_choose_cpu(unsigned int virt_irq)
326 return real_hard_smp_processor_id();
330 static void sun4u_irq_enable(unsigned int virt_irq)
332 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
335 unsigned long cpuid, imap, val;
338 cpuid = irq_choose_cpu(virt_irq);
341 tid = sun4u_compute_tid(imap, cpuid);
343 val = upa_readq(imap);
344 val &= ~(IMAP_TID_UPA | IMAP_TID_JBUS |
345 IMAP_AID_SAFARI | IMAP_NID_SAFARI);
346 val |= tid | IMAP_VALID;
347 upa_writeq(val, imap);
351 static void sun4u_set_affinity(unsigned int virt_irq, cpumask_t mask)
353 sun4u_irq_enable(virt_irq);
356 static void sun4u_irq_disable(unsigned int virt_irq)
358 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
361 unsigned long imap = data->imap;
362 unsigned long tmp = upa_readq(imap);
365 upa_writeq(tmp, imap);
369 static void sun4u_irq_end(unsigned int virt_irq)
371 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
372 struct irq_desc *desc = irq_desc + virt_irq;
374 if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS)))
378 upa_writeq(ICLR_IDLE, data->iclr);
381 static void sun4v_irq_enable(unsigned int virt_irq)
383 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
384 unsigned int ino = bucket - &ivector_table[0];
386 if (likely(bucket)) {
390 cpuid = irq_choose_cpu(virt_irq);
392 err = sun4v_intr_settarget(ino, cpuid);
394 printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
395 "err(%d)\n", ino, cpuid, err);
396 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
398 printk(KERN_ERR "sun4v_intr_setstate(%x): "
399 "err(%d)\n", ino, err);
400 err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
402 printk(KERN_ERR "sun4v_intr_setenabled(%x): err(%d)\n",
407 static void sun4v_set_affinity(unsigned int virt_irq, cpumask_t mask)
409 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
410 unsigned int ino = bucket - &ivector_table[0];
412 if (likely(bucket)) {
416 cpuid = irq_choose_cpu(virt_irq);
418 err = sun4v_intr_settarget(ino, cpuid);
420 printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
421 "err(%d)\n", ino, cpuid, err);
425 static void sun4v_irq_disable(unsigned int virt_irq)
427 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
428 unsigned int ino = bucket - &ivector_table[0];
430 if (likely(bucket)) {
433 err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
435 printk(KERN_ERR "sun4v_intr_setenabled(%x): "
436 "err(%d)\n", ino, err);
440 static void sun4v_irq_end(unsigned int virt_irq)
442 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
443 unsigned int ino = bucket - &ivector_table[0];
444 struct irq_desc *desc = irq_desc + virt_irq;
446 if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS)))
449 if (likely(bucket)) {
452 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
454 printk(KERN_ERR "sun4v_intr_setstate(%x): "
455 "err(%d)\n", ino, err);
459 static void sun4v_virq_enable(unsigned int virt_irq)
461 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
463 if (likely(bucket)) {
464 unsigned long cpuid, dev_handle, dev_ino;
467 cpuid = irq_choose_cpu(virt_irq);
469 dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
470 dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
472 err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
474 printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
476 dev_handle, dev_ino, cpuid, err);
477 err = sun4v_vintr_set_state(dev_handle, dev_ino,
480 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
481 "HV_INTR_STATE_IDLE): err(%d)\n",
482 dev_handle, dev_ino, err);
483 err = sun4v_vintr_set_valid(dev_handle, dev_ino,
486 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
487 "HV_INTR_ENABLED): err(%d)\n",
488 dev_handle, dev_ino, err);
492 static void sun4v_virt_set_affinity(unsigned int virt_irq, cpumask_t mask)
494 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
496 if (likely(bucket)) {
497 unsigned long cpuid, dev_handle, dev_ino;
500 cpuid = irq_choose_cpu(virt_irq);
502 dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
503 dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
505 err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
507 printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
509 dev_handle, dev_ino, cpuid, err);
513 static void sun4v_virq_disable(unsigned int virt_irq)
515 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
517 if (likely(bucket)) {
518 unsigned long dev_handle, dev_ino;
521 dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
522 dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
524 err = sun4v_vintr_set_valid(dev_handle, dev_ino,
527 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
528 "HV_INTR_DISABLED): err(%d)\n",
529 dev_handle, dev_ino, err);
533 static void sun4v_virq_end(unsigned int virt_irq)
535 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
536 struct irq_desc *desc = irq_desc + virt_irq;
538 if (unlikely(desc->status & (IRQ_DISABLED|IRQ_INPROGRESS)))
541 if (likely(bucket)) {
542 unsigned long dev_handle, dev_ino;
545 dev_handle = virt_to_real_irq_table[virt_irq].dev_handle;
546 dev_ino = virt_to_real_irq_table[virt_irq].dev_ino;
548 err = sun4v_vintr_set_state(dev_handle, dev_ino,
551 printk(KERN_ERR "sun4v_vintr_set_state(%lx,%lx,"
552 "HV_INTR_STATE_IDLE): err(%d)\n",
553 dev_handle, dev_ino, err);
557 static void run_pre_handler(unsigned int virt_irq)
559 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
562 ino = virt_to_real_irq_table[virt_irq].dev_ino;
563 if (likely(data->pre_handler)) {
564 data->pre_handler(ino,
565 data->pre_handler_arg1,
566 data->pre_handler_arg2);
570 static struct irq_chip sun4u_irq = {
572 .enable = sun4u_irq_enable,
573 .disable = sun4u_irq_disable,
574 .end = sun4u_irq_end,
575 .set_affinity = sun4u_set_affinity,
578 static struct irq_chip sun4u_irq_ack = {
579 .typename = "sun4u+ack",
580 .enable = sun4u_irq_enable,
581 .disable = sun4u_irq_disable,
582 .ack = run_pre_handler,
583 .end = sun4u_irq_end,
584 .set_affinity = sun4u_set_affinity,
587 static struct irq_chip sun4v_irq = {
589 .enable = sun4v_irq_enable,
590 .disable = sun4v_irq_disable,
591 .end = sun4v_irq_end,
592 .set_affinity = sun4v_set_affinity,
595 static struct irq_chip sun4v_virq = {
596 .typename = "vsun4v",
597 .enable = sun4v_virq_enable,
598 .disable = sun4v_virq_disable,
599 .end = sun4v_virq_end,
600 .set_affinity = sun4v_virt_set_affinity,
603 void irq_install_pre_handler(int virt_irq,
604 void (*func)(unsigned int, void *, void *),
605 void *arg1, void *arg2)
607 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
608 struct irq_chip *chip = get_irq_chip(virt_irq);
610 if (WARN_ON(chip == &sun4v_irq || chip == &sun4v_virq)) {
611 printk(KERN_ERR "IRQ: Trying to install pre-handler on "
612 "sun4v irq %u\n", virt_irq);
616 data->pre_handler = func;
617 data->pre_handler_arg1 = arg1;
618 data->pre_handler_arg2 = arg2;
620 if (chip == &sun4u_irq_ack)
623 set_irq_chip(virt_irq, &sun4u_irq_ack);
626 unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
628 struct ino_bucket *bucket;
629 struct irq_handler_data *data;
630 unsigned int virt_irq;
633 BUG_ON(tlb_type == hypervisor);
635 ino = (upa_readq(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
636 bucket = &ivector_table[ino];
637 virt_irq = bucket_get_virt_irq(__pa(bucket));
639 virt_irq = virt_irq_alloc(__irq(bucket), 0, ino);
640 bucket_set_virt_irq(__pa(bucket), virt_irq);
641 set_irq_chip(virt_irq, &sun4u_irq);
644 data = get_irq_chip_data(virt_irq);
648 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
649 if (unlikely(!data)) {
650 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
653 set_irq_chip_data(virt_irq, data);
662 static unsigned int sun4v_build_common(unsigned long sysino,
663 struct irq_chip *chip)
665 struct ino_bucket *bucket;
666 struct irq_handler_data *data;
667 unsigned int virt_irq;
669 BUG_ON(tlb_type != hypervisor);
671 bucket = &ivector_table[sysino];
672 virt_irq = bucket_get_virt_irq(__pa(bucket));
674 virt_irq = virt_irq_alloc(__irq(bucket), 0, sysino);
675 bucket_set_virt_irq(__pa(bucket), virt_irq);
676 set_irq_chip(virt_irq, chip);
679 data = get_irq_chip_data(virt_irq);
683 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
684 if (unlikely(!data)) {
685 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
688 set_irq_chip_data(virt_irq, data);
690 /* Catch accidental accesses to these things. IMAP/ICLR handling
691 * is done by hypervisor calls on sun4v platforms, not by direct
701 unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
703 unsigned long sysino = sun4v_devino_to_sysino(devhandle, devino);
705 return sun4v_build_common(sysino, &sun4v_irq);
708 unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino)
710 struct irq_handler_data *data;
711 struct ino_bucket *bucket;
712 unsigned long hv_err, cookie;
713 unsigned int virt_irq;
715 bucket = kzalloc(sizeof(struct ino_bucket), GFP_ATOMIC);
716 if (unlikely(!bucket))
718 __flush_dcache_range((unsigned long) bucket,
719 ((unsigned long) bucket +
720 sizeof(struct ino_bucket)));
722 virt_irq = virt_irq_alloc(__irq(bucket), devhandle, devino);
723 bucket_set_virt_irq(__pa(bucket), virt_irq);
724 set_irq_chip(virt_irq, &sun4v_virq);
726 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
730 set_irq_chip_data(virt_irq, data);
732 /* Catch accidental accesses to these things. IMAP/ICLR handling
733 * is done by hypervisor calls on sun4v platforms, not by direct
739 cookie = ~__pa(bucket);
740 hv_err = sun4v_vintr_set_cookie(devhandle, devino, cookie);
742 prom_printf("IRQ: Fatal, cannot set cookie for [%x:%x] "
743 "err=%lu\n", devhandle, devino, hv_err);
750 void ack_bad_irq(unsigned int virt_irq)
752 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
753 unsigned int ino = 0xdeadbeef;
756 ino = bucket - &ivector_table[0];
758 printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
762 void handler_irq(int irq, struct pt_regs *regs)
764 unsigned long pstate, bucket_pa;
765 struct pt_regs *old_regs;
767 clear_softint(1 << irq);
769 old_regs = set_irq_regs(regs);
772 /* Grab an atomic snapshot of the pending IVECs. */
773 __asm__ __volatile__("rdpr %%pstate, %0\n\t"
774 "wrpr %0, %3, %%pstate\n\t"
777 "wrpr %0, 0x0, %%pstate\n\t"
778 : "=&r" (pstate), "=&r" (bucket_pa)
779 : "r" (irq_work_pa(smp_processor_id())),
784 unsigned long next_pa;
785 unsigned int virt_irq;
787 next_pa = bucket_get_chain_pa(bucket_pa);
788 virt_irq = bucket_get_virt_irq(bucket_pa);
789 bucket_clear_chain_pa(bucket_pa);
797 set_irq_regs(old_regs);
800 #ifdef CONFIG_HOTPLUG_CPU
801 void fixup_irqs(void)
805 for (irq = 0; irq < NR_IRQS; irq++) {
808 spin_lock_irqsave(&irq_desc[irq].lock, flags);
809 if (irq_desc[irq].action &&
810 !(irq_desc[irq].status & IRQ_PER_CPU)) {
811 if (irq_desc[irq].chip->set_affinity)
812 irq_desc[irq].chip->set_affinity(irq,
813 irq_desc[irq].affinity);
815 spin_unlock_irqrestore(&irq_desc[irq].lock, flags);
827 static struct sun5_timer *prom_timers;
828 static u64 prom_limit0, prom_limit1;
830 static void map_prom_timers(void)
832 struct device_node *dp;
833 const unsigned int *addr;
835 /* PROM timer node hangs out in the top level of device siblings... */
836 dp = of_find_node_by_path("/");
839 if (!strcmp(dp->name, "counter-timer"))
844 /* Assume if node is not present, PROM uses different tick mechanism
845 * which we should not care about.
848 prom_timers = (struct sun5_timer *) 0;
852 /* If PROM is really using this, it must be mapped by him. */
853 addr = of_get_property(dp, "address", NULL);
855 prom_printf("PROM does not have timer mapped, trying to continue.\n");
856 prom_timers = (struct sun5_timer *) 0;
859 prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
862 static void kill_prom_timer(void)
867 /* Save them away for later. */
868 prom_limit0 = prom_timers->limit0;
869 prom_limit1 = prom_timers->limit1;
871 /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
872 * We turn both off here just to be paranoid.
874 prom_timers->limit0 = 0;
875 prom_timers->limit1 = 0;
877 /* Wheee, eat the interrupt packet too... */
878 __asm__ __volatile__(
880 " ldxa [%%g0] %0, %%g1\n"
881 " ldxa [%%g2] %1, %%g1\n"
882 " stxa %%g0, [%%g0] %0\n"
885 : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
889 void init_irqwork_curcpu(void)
891 int cpu = hard_smp_processor_id();
893 trap_block[cpu].irq_worklist_pa = 0UL;
896 /* Please be very careful with register_one_mondo() and
897 * sun4v_register_mondo_queues().
899 * On SMP this gets invoked from the CPU trampoline before
900 * the cpu has fully taken over the trap table from OBP,
901 * and it's kernel stack + %g6 thread register state is
902 * not fully cooked yet.
904 * Therefore you cannot make any OBP calls, not even prom_printf,
905 * from these two routines.
907 static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type, unsigned long qmask)
909 unsigned long num_entries = (qmask + 1) / 64;
910 unsigned long status;
912 status = sun4v_cpu_qconf(type, paddr, num_entries);
913 if (status != HV_EOK) {
914 prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, "
915 "err %lu\n", type, paddr, num_entries, status);
920 void __cpuinit sun4v_register_mondo_queues(int this_cpu)
922 struct trap_per_cpu *tb = &trap_block[this_cpu];
924 register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO,
925 tb->cpu_mondo_qmask);
926 register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO,
927 tb->dev_mondo_qmask);
928 register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR,
930 register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR,
934 static void __init alloc_one_mondo(unsigned long *pa_ptr, unsigned long qmask)
936 unsigned long size = PAGE_ALIGN(qmask + 1);
937 void *p = __alloc_bootmem_low(size, size, 0);
939 prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
946 static void __init alloc_one_kbuf(unsigned long *pa_ptr, unsigned long qmask)
948 unsigned long size = PAGE_ALIGN(qmask + 1);
949 void *p = __alloc_bootmem_low(size, size, 0);
952 prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
959 static void __init init_cpu_send_mondo_info(struct trap_per_cpu *tb)
964 BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
966 page = alloc_bootmem_low_pages(PAGE_SIZE);
968 prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
972 tb->cpu_mondo_block_pa = __pa(page);
973 tb->cpu_list_pa = __pa(page + 64);
977 /* Allocate mondo and error queues for all possible cpus. */
978 static void __init sun4v_init_mondo_queues(void)
982 for_each_possible_cpu(cpu) {
983 struct trap_per_cpu *tb = &trap_block[cpu];
985 alloc_one_mondo(&tb->cpu_mondo_pa, tb->cpu_mondo_qmask);
986 alloc_one_mondo(&tb->dev_mondo_pa, tb->dev_mondo_qmask);
987 alloc_one_mondo(&tb->resum_mondo_pa, tb->resum_qmask);
988 alloc_one_kbuf(&tb->resum_kernel_buf_pa, tb->resum_qmask);
989 alloc_one_mondo(&tb->nonresum_mondo_pa, tb->nonresum_qmask);
990 alloc_one_kbuf(&tb->nonresum_kernel_buf_pa,
993 init_cpu_send_mondo_info(tb);
996 /* Load up the boot cpu's entries. */
997 sun4v_register_mondo_queues(hard_smp_processor_id());
1000 static struct irqaction timer_irq_action = {
1004 /* Only invoked on boot processor. */
1005 void __init init_IRQ(void)
1012 size = sizeof(struct ino_bucket) * NUM_IVECS;
1013 ivector_table = alloc_bootmem_low(size);
1014 if (!ivector_table) {
1015 prom_printf("Fatal error, cannot allocate ivector_table\n");
1018 __flush_dcache_range((unsigned long) ivector_table,
1019 ((unsigned long) ivector_table) + size);
1021 ivector_table_pa = __pa(ivector_table);
1023 if (tlb_type == hypervisor)
1024 sun4v_init_mondo_queues();
1026 /* We need to clear any IRQ's pending in the soft interrupt
1027 * registers, a spurious one could be left around from the
1028 * PROM timer which we just disabled.
1030 clear_softint(get_softint());
1032 /* Now that ivector table is initialized, it is safe
1033 * to receive IRQ vector traps. We will normally take
1034 * one or two right now, in case some device PROM used
1035 * to boot us wants to speak to us. We just ignore them.
1037 __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
1038 "or %%g1, %0, %%g1\n\t"
1039 "wrpr %%g1, 0x0, %%pstate"
1044 irq_desc[0].action = &timer_irq_action;