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)
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>
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>
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>
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)
64 __asm__ __volatile__("ldxa [%1] %2, %0"
67 offsetof(struct ino_bucket,
69 "i" (ASI_PHYS_USE_EC));
74 static void bucket_clear_chain_pa(unsigned long bucket_pa)
76 __asm__ __volatile__("stxa %%g0, [%0] %1"
79 offsetof(struct ino_bucket,
81 "i" (ASI_PHYS_USE_EC));
84 static unsigned int bucket_get_irq(unsigned long bucket_pa)
88 __asm__ __volatile__("lduwa [%1] %2, %0"
91 offsetof(struct ino_bucket,
93 "i" (ASI_PHYS_USE_EC));
98 static void bucket_set_irq(unsigned long bucket_pa, unsigned int irq)
100 __asm__ __volatile__("stwa %0, [%1] %2"
104 offsetof(struct ino_bucket,
106 "i" (ASI_PHYS_USE_EC));
109 #define irq_work_pa(__cpu) &(trap_block[(__cpu)].irq_worklist_pa)
112 unsigned int dev_handle;
113 unsigned int dev_ino;
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)
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)
131 if (ent >= NR_IRQS) {
132 printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
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);
145 #ifdef CONFIG_PCI_MSI
146 void irq_free(unsigned int irq)
153 spin_lock_irqsave(&irq_alloc_lock, flags);
155 irq_table[irq].in_use = 0;
157 spin_unlock_irqrestore(&irq_alloc_lock, flags);
162 * /proc/interrupts printing:
164 int arch_show_interrupts(struct seq_file *p, int prec)
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");
175 static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
179 if (this_is_starfire) {
180 tid = starfire_translate(imap, cpuid);
181 tid <<= IMAP_TID_SHIFT;
184 if (tlb_type == cheetah || tlb_type == cheetah_plus) {
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;
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 |
202 tid = cpuid << IMAP_TID_SHIFT;
210 struct irq_handler_data {
214 void (*pre_handler)(unsigned int, void *, void *);
220 static int irq_choose_cpu(unsigned int irq, const struct cpumask *affinity)
225 cpumask_copy(&mask, affinity);
226 if (cpumask_equal(&mask, cpu_online_mask)) {
227 cpuid = map_to_cpu(irq);
231 cpumask_and(&tmp, cpu_online_mask, &mask);
232 cpuid = cpumask_empty(&tmp) ? map_to_cpu(irq) : cpumask_first(&tmp);
238 #define irq_choose_cpu(irq, affinity) \
239 real_hard_smp_processor_id()
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;
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;
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);
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
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);
324 err = sun4v_intr_settarget(ino, cpuid);
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);
330 printk(KERN_ERR "sun4v_intr_setstate(%x): "
331 "err(%d)\n", ino, err);
332 err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
334 printk(KERN_ERR "sun4v_intr_setenabled(%x): err(%d)\n",
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);
345 err = sun4v_intr_settarget(ino, cpuid);
347 printk(KERN_ERR "sun4v_intr_settarget(%x,%lu): "
348 "err(%d)\n", ino, cpuid, err);
353 static void sun4v_irq_disable(struct irq_data *data)
355 unsigned int ino = irq_table[data->irq].dev_ino;
358 err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
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;
369 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
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;
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);
387 printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
389 dev_handle, dev_ino, cpuid, err);
390 err = sun4v_vintr_set_state(dev_handle, dev_ino,
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,
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;
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);
417 printk(KERN_ERR "sun4v_vintr_set_target(%lx,%lx,%lu): "
419 dev_handle, dev_ino, cpuid, err);
424 static void sun4v_virq_disable(struct irq_data *data)
426 unsigned long dev_handle, dev_ino;
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,
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;
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,
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 = {
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 = {
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 = {
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;
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));
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))
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");
532 irq_set_handler_data(irq, handler_data);
534 handler_data->imap = imap;
535 handler_data->iclr = iclr;
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;
548 BUG_ON(tlb_type != hypervisor);
550 bucket = &ivector_table[sysino];
551 irq = bucket_get_irq(__pa(bucket));
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,
559 handler_data = irq_get_handler_data(irq);
560 if (unlikely(handler_data))
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");
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
574 handler_data->imap = ~0UL;
575 handler_data->iclr = ~0UL;
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;
595 bucket = kzalloc(sizeof(struct ino_bucket), GFP_ATOMIC);
596 if (unlikely(!bucket))
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
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,
616 handler_data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
617 if (unlikely(!handler_data))
620 /* In order to make the LDC channel startup sequence easier,
621 * especially wrt. locking, we do not let request_irq() enable
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
631 handler_data->imap = ~0UL;
632 handler_data->iclr = ~0UL;
634 cookie = ~__pa(bucket);
635 hv_err = sun4v_vintr_set_cookie(devhandle, devino, cookie);
637 prom_printf("IRQ: Fatal, cannot set cookie for [%x:%x] "
638 "err=%lu\n", devhandle, devino, hv_err);
645 void ack_bad_irq(unsigned int irq)
647 unsigned int ino = irq_table[irq].dev_ino;
652 printk(KERN_CRIT "Unexpected IRQ from ino[%x] irq[%u]\n",
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;
665 clear_softint(1 << pil);
667 old_regs = set_irq_regs(regs);
670 /* Grab an atomic snapshot of the pending IVECs. */
671 __asm__ __volatile__("rdpr %%pstate, %0\n\t"
672 "wrpr %0, %3, %%pstate\n\t"
675 "wrpr %0, 0x0, %%pstate\n\t"
676 : "=&r" (pstate), "=&r" (bucket_pa)
677 : "r" (irq_work_pa(smp_processor_id())),
681 orig_sp = set_hardirq_stack();
684 unsigned long next_pa;
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);
696 restore_hardirq_stack(orig_sp);
699 set_irq_regs(old_regs);
702 void do_softirq(void)
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"
721 __asm__ __volatile__("mov %0, %%sp"
725 local_irq_restore(flags);
728 #ifdef CONFIG_HOTPLUG_CPU
729 void fixup_irqs(void)
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);
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,
745 raw_spin_unlock_irqrestore(&desc->lock, flags);
748 tick_ops->disable_irq();
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("/");
771 if (!strcmp(dp->name, "counter-timer"))
776 /* Assume if node is not present, PROM uses different tick mechanism
777 * which we should not care about.
780 prom_timers = (struct sun5_timer *) 0;
784 /* If PROM is really using this, it must be mapped by him. */
785 addr = of_get_property(dp, "address", NULL);
787 prom_printf("PROM does not have timer mapped, trying to continue.\n");
788 prom_timers = (struct sun5_timer *) 0;
791 prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
794 static void kill_prom_timer(void)
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__(
812 " ldxa [%%g0] %0, %%g1\n"
813 " ldxa [%%g2] %1, %%g1\n"
814 " stxa %%g0, [%%g0] %0\n"
817 : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
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);
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,
862 register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR,
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);
876 p = __get_free_pages(GFP_KERNEL, order);
878 prom_printf("SUN4V: Error, cannot allocate queue.\n");
885 static void __init init_cpu_send_mondo_info(struct trap_per_cpu *tb)
890 BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
892 page = get_zeroed_page(GFP_KERNEL);
894 prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
898 tb->cpu_mondo_block_pa = __pa(page);
899 tb->cpu_list_pa = __pa(page + 64);
903 /* Allocate mondo and error queues for all possible cpus. */
904 static void __init sun4v_init_mondo_queues(void)
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,
921 static void __init init_send_mondo_info(void)
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 = {
936 /* Only invoked on boot processor. */
937 void __init init_IRQ(void)
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");
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"
983 irq_to_desc(0)->action = &timer_irq_action;