2 * Derived from arch/i386/kernel/irq.c
3 * Copyright (C) 1992 Linus Torvalds
4 * Adapted from arch/i386 by Gary Thomas
7 * Copyright (C) 1996-2001 Cort Dougan
8 * Adapted for Power Macintosh by Paul Mackerras
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
16 * This file contains the code used by various IRQ handling routines:
17 * asking for different IRQ's should be done through these routines
18 * instead of just grabbing them. Thus setups with different IRQ numbers
19 * shouldn't result in any weird surprises, and installing new handlers
22 * The MPC8xx has an interrupt mask in the SIU. If a bit is set, the
23 * interrupt is _enabled_. As expected, IRQ0 is bit 0 in the 32-bit
24 * mask register (of which only 16 are defined), hence the weird shifting
25 * and complement of the cached_irq_mask. I want to be able to stuff
26 * this right into the SIU SMASK register.
27 * Many of the prep/chrp functions are conditional compiled on CONFIG_8xx
28 * to reduce code space and undefined function references.
33 #include <linux/module.h>
34 #include <linux/threads.h>
35 #include <linux/kernel_stat.h>
36 #include <linux/signal.h>
37 #include <linux/sched.h>
38 #include <linux/ptrace.h>
39 #include <linux/ioport.h>
40 #include <linux/interrupt.h>
41 #include <linux/timex.h>
42 #include <linux/init.h>
43 #include <linux/slab.h>
44 #include <linux/delay.h>
45 #include <linux/irq.h>
46 #include <linux/seq_file.h>
47 #include <linux/cpumask.h>
48 #include <linux/profile.h>
49 #include <linux/bitops.h>
50 #include <linux/list.h>
51 #include <linux/radix-tree.h>
52 #include <linux/mutex.h>
53 #include <linux/bootmem.h>
54 #include <linux/pci.h>
55 #include <linux/debugfs.h>
56 #include <linux/perf_event.h>
58 #include <asm/uaccess.h>
59 #include <asm/system.h>
61 #include <asm/pgtable.h>
63 #include <asm/cache.h>
65 #include <asm/ptrace.h>
66 #include <asm/machdep.h>
70 #include <asm/firmware.h>
71 #include <asm/lv1call.h>
73 #define CREATE_TRACE_POINTS
74 #include <asm/trace.h>
76 DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
77 EXPORT_PER_CPU_SYMBOL(irq_stat);
79 int __irq_offset_value;
82 EXPORT_SYMBOL(__irq_offset_value);
83 atomic_t ppc_n_lost_interrupts;
86 extern int tau_initialized;
87 extern int tau_interrupts(int);
89 #endif /* CONFIG_PPC32 */
93 #ifndef CONFIG_SPARSE_IRQ
94 EXPORT_SYMBOL(irq_desc);
97 int distribute_irqs = 1;
99 static inline notrace unsigned long get_hard_enabled(void)
101 unsigned long enabled;
103 __asm__ __volatile__("lbz %0,%1(13)"
104 : "=r" (enabled) : "i" (offsetof(struct paca_struct, hard_enabled)));
109 static inline notrace void set_soft_enabled(unsigned long enable)
111 __asm__ __volatile__("stb %0,%1(13)"
112 : : "r" (enable), "i" (offsetof(struct paca_struct, soft_enabled)));
115 notrace void raw_local_irq_restore(unsigned long en)
118 * get_paca()->soft_enabled = en;
119 * Is it ever valid to use local_irq_restore(0) when soft_enabled is 1?
120 * That was allowed before, and in such a case we do need to take care
121 * that gcc will set soft_enabled directly via r13, not choose to use
122 * an intermediate register, lest we're preempted to a different cpu.
124 set_soft_enabled(en);
128 #ifdef CONFIG_PPC_STD_MMU_64
129 if (firmware_has_feature(FW_FEATURE_ISERIES)) {
131 * Do we need to disable preemption here? Not really: in the
132 * unlikely event that we're preempted to a different cpu in
133 * between getting r13, loading its lppaca_ptr, and loading
134 * its any_int, we might call iseries_handle_interrupts without
135 * an interrupt pending on the new cpu, but that's no disaster,
136 * is it? And the business of preempting us off the old cpu
137 * would itself involve a local_irq_restore which handles the
138 * interrupt to that cpu.
140 * But use "local_paca->lppaca_ptr" instead of "get_lppaca()"
141 * to avoid any preemption checking added into get_paca().
143 if (local_paca->lppaca_ptr->int_dword.any_int)
144 iseries_handle_interrupts();
146 #endif /* CONFIG_PPC_STD_MMU_64 */
148 if (test_perf_event_pending()) {
149 clear_perf_event_pending();
150 perf_event_do_pending();
154 * if (get_paca()->hard_enabled) return;
155 * But again we need to take care that gcc gets hard_enabled directly
156 * via r13, not choose to use an intermediate register, lest we're
157 * preempted to a different cpu in between the two instructions.
159 if (get_hard_enabled())
163 * Need to hard-enable interrupts here. Since currently disabled,
164 * no need to take further asm precautions against preemption; but
165 * use local_paca instead of get_paca() to avoid preemption checking.
167 local_paca->hard_enabled = en;
168 if ((int)mfspr(SPRN_DEC) < 0)
172 * Force the delivery of pending soft-disabled interrupts on PS3.
173 * Any HV call will have this side effect.
175 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
177 lv1_get_version_info(&tmp);
182 EXPORT_SYMBOL(raw_local_irq_restore);
183 #endif /* CONFIG_PPC64 */
185 static int show_other_interrupts(struct seq_file *p, int prec)
189 #if defined(CONFIG_PPC32) && defined(CONFIG_TAU_INT)
190 if (tau_initialized) {
191 seq_printf(p, "%*s: ", prec, "TAU");
192 for_each_online_cpu(j)
193 seq_printf(p, "%10u ", tau_interrupts(j));
194 seq_puts(p, " PowerPC Thermal Assist (cpu temp)\n");
196 #endif /* CONFIG_PPC32 && CONFIG_TAU_INT */
198 seq_printf(p, "%*s: ", prec, "LOC");
199 for_each_online_cpu(j)
200 seq_printf(p, "%10u ", per_cpu(irq_stat, j).timer_irqs);
201 seq_printf(p, " Local timer interrupts\n");
203 seq_printf(p, "%*s: ", prec, "SPU");
204 for_each_online_cpu(j)
205 seq_printf(p, "%10u ", per_cpu(irq_stat, j).spurious_irqs);
206 seq_printf(p, " Spurious interrupts\n");
208 seq_printf(p, "%*s: ", prec, "CNT");
209 for_each_online_cpu(j)
210 seq_printf(p, "%10u ", per_cpu(irq_stat, j).pmu_irqs);
211 seq_printf(p, " Performance monitoring interrupts\n");
213 seq_printf(p, "%*s: ", prec, "MCE");
214 for_each_online_cpu(j)
215 seq_printf(p, "%10u ", per_cpu(irq_stat, j).mce_exceptions);
216 seq_printf(p, " Machine check exceptions\n");
221 int show_interrupts(struct seq_file *p, void *v)
223 unsigned long flags, any_count = 0;
224 int i = *(loff_t *) v, j, prec;
225 struct irqaction *action;
226 struct irq_desc *desc;
231 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
235 return show_other_interrupts(p, prec);
239 seq_printf(p, "%*s", prec + 8, "");
240 for_each_online_cpu(j)
241 seq_printf(p, "CPU%-8d", j);
245 desc = irq_to_desc(i);
249 raw_spin_lock_irqsave(&desc->lock, flags);
250 for_each_online_cpu(j)
251 any_count |= kstat_irqs_cpu(i, j);
252 action = desc->action;
253 if (!action && !any_count)
256 seq_printf(p, "%*d: ", prec, i);
257 for_each_online_cpu(j)
258 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
261 seq_printf(p, " %-16s", desc->chip->name);
263 seq_printf(p, " %-16s", "None");
264 seq_printf(p, " %-8s", (desc->status & IRQ_LEVEL) ? "Level" : "Edge");
267 seq_printf(p, " %s", action->name);
268 while ((action = action->next) != NULL)
269 seq_printf(p, ", %s", action->name);
274 raw_spin_unlock_irqrestore(&desc->lock, flags);
281 u64 arch_irq_stat_cpu(unsigned int cpu)
283 u64 sum = per_cpu(irq_stat, cpu).timer_irqs;
285 sum += per_cpu(irq_stat, cpu).pmu_irqs;
286 sum += per_cpu(irq_stat, cpu).mce_exceptions;
287 sum += per_cpu(irq_stat, cpu).spurious_irqs;
292 #ifdef CONFIG_HOTPLUG_CPU
293 void fixup_irqs(const struct cpumask *map)
295 struct irq_desc *desc;
300 alloc_cpumask_var(&mask, GFP_KERNEL);
303 desc = irq_to_desc(irq);
304 if (desc && desc->status & IRQ_PER_CPU)
307 cpumask_and(mask, desc->affinity, map);
308 if (cpumask_any(mask) >= nr_cpu_ids) {
309 printk("Breaking affinity for irq %i\n", irq);
310 cpumask_copy(mask, map);
312 if (desc->chip->set_affinity)
313 desc->chip->set_affinity(irq, mask);
314 else if (desc->action && !(warned++))
315 printk("Cannot set affinity for irq %i\n", irq);
318 free_cpumask_var(mask);
326 #ifdef CONFIG_IRQSTACKS
327 static inline void handle_one_irq(unsigned int irq)
329 struct thread_info *curtp, *irqtp;
330 unsigned long saved_sp_limit;
331 struct irq_desc *desc;
333 /* Switch to the irq stack to handle this */
334 curtp = current_thread_info();
335 irqtp = hardirq_ctx[smp_processor_id()];
337 if (curtp == irqtp) {
338 /* We're already on the irq stack, just handle it */
339 generic_handle_irq(irq);
343 desc = irq_to_desc(irq);
344 saved_sp_limit = current->thread.ksp_limit;
346 irqtp->task = curtp->task;
349 /* Copy the softirq bits in preempt_count so that the
350 * softirq checks work in the hardirq context. */
351 irqtp->preempt_count = (irqtp->preempt_count & ~SOFTIRQ_MASK) |
352 (curtp->preempt_count & SOFTIRQ_MASK);
354 current->thread.ksp_limit = (unsigned long)irqtp +
355 _ALIGN_UP(sizeof(struct thread_info), 16);
357 call_handle_irq(irq, desc, irqtp, desc->handle_irq);
358 current->thread.ksp_limit = saved_sp_limit;
361 /* Set any flag that may have been set on the
365 set_bits(irqtp->flags, &curtp->flags);
368 static inline void handle_one_irq(unsigned int irq)
370 generic_handle_irq(irq);
374 static inline void check_stack_overflow(void)
376 #ifdef CONFIG_DEBUG_STACKOVERFLOW
379 sp = __get_SP() & (THREAD_SIZE-1);
381 /* check for stack overflow: is there less than 2KB free? */
382 if (unlikely(sp < (sizeof(struct thread_info) + 2048))) {
383 printk("do_IRQ: stack overflow: %ld\n",
384 sp - sizeof(struct thread_info));
390 void do_IRQ(struct pt_regs *regs)
392 struct pt_regs *old_regs = set_irq_regs(regs);
395 trace_irq_entry(regs);
399 check_stack_overflow();
401 irq = ppc_md.get_irq();
403 if (irq != NO_IRQ && irq != NO_IRQ_IGNORE)
405 else if (irq != NO_IRQ_IGNORE)
406 __get_cpu_var(irq_stat).spurious_irqs++;
409 set_irq_regs(old_regs);
411 #ifdef CONFIG_PPC_ISERIES
412 if (firmware_has_feature(FW_FEATURE_ISERIES) &&
413 get_lppaca()->int_dword.fields.decr_int) {
414 get_lppaca()->int_dword.fields.decr_int = 0;
415 /* Signal a fake decrementer interrupt */
416 timer_interrupt(regs);
420 trace_irq_exit(regs);
423 void __init init_IRQ(void)
433 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
434 struct thread_info *critirq_ctx[NR_CPUS] __read_mostly;
435 struct thread_info *dbgirq_ctx[NR_CPUS] __read_mostly;
436 struct thread_info *mcheckirq_ctx[NR_CPUS] __read_mostly;
438 void exc_lvl_ctx_init(void)
440 struct thread_info *tp;
443 for_each_possible_cpu(i) {
444 memset((void *)critirq_ctx[i], 0, THREAD_SIZE);
447 tp->preempt_count = 0;
450 memset((void *)dbgirq_ctx[i], 0, THREAD_SIZE);
453 tp->preempt_count = 0;
455 memset((void *)mcheckirq_ctx[i], 0, THREAD_SIZE);
456 tp = mcheckirq_ctx[i];
458 tp->preempt_count = HARDIRQ_OFFSET;
464 #ifdef CONFIG_IRQSTACKS
465 struct thread_info *softirq_ctx[NR_CPUS] __read_mostly;
466 struct thread_info *hardirq_ctx[NR_CPUS] __read_mostly;
468 void irq_ctx_init(void)
470 struct thread_info *tp;
473 for_each_possible_cpu(i) {
474 memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
477 tp->preempt_count = 0;
479 memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
482 tp->preempt_count = HARDIRQ_OFFSET;
486 static inline void do_softirq_onstack(void)
488 struct thread_info *curtp, *irqtp;
489 unsigned long saved_sp_limit = current->thread.ksp_limit;
491 curtp = current_thread_info();
492 irqtp = softirq_ctx[smp_processor_id()];
493 irqtp->task = curtp->task;
494 current->thread.ksp_limit = (unsigned long)irqtp +
495 _ALIGN_UP(sizeof(struct thread_info), 16);
496 call_do_softirq(irqtp);
497 current->thread.ksp_limit = saved_sp_limit;
502 #define do_softirq_onstack() __do_softirq()
503 #endif /* CONFIG_IRQSTACKS */
505 void do_softirq(void)
512 local_irq_save(flags);
514 if (local_softirq_pending())
515 do_softirq_onstack();
517 local_irq_restore(flags);
522 * IRQ controller and virtual interrupts
525 static LIST_HEAD(irq_hosts);
526 static DEFINE_RAW_SPINLOCK(irq_big_lock);
527 static unsigned int revmap_trees_allocated;
528 static DEFINE_MUTEX(revmap_trees_mutex);
529 struct irq_map_entry irq_map[NR_IRQS];
530 static unsigned int irq_virq_count = NR_IRQS;
531 static struct irq_host *irq_default_host;
533 irq_hw_number_t virq_to_hw(unsigned int virq)
535 return irq_map[virq].hwirq;
537 EXPORT_SYMBOL_GPL(virq_to_hw);
539 static int default_irq_host_match(struct irq_host *h, struct device_node *np)
541 return h->of_node != NULL && h->of_node == np;
544 struct irq_host *irq_alloc_host(struct device_node *of_node,
545 unsigned int revmap_type,
546 unsigned int revmap_arg,
547 struct irq_host_ops *ops,
548 irq_hw_number_t inval_irq)
550 struct irq_host *host;
551 unsigned int size = sizeof(struct irq_host);
556 /* Allocate structure and revmap table if using linear mapping */
557 if (revmap_type == IRQ_HOST_MAP_LINEAR)
558 size += revmap_arg * sizeof(unsigned int);
559 host = zalloc_maybe_bootmem(size, GFP_KERNEL);
564 host->revmap_type = revmap_type;
565 host->inval_irq = inval_irq;
567 host->of_node = of_node_get(of_node);
569 if (host->ops->match == NULL)
570 host->ops->match = default_irq_host_match;
572 raw_spin_lock_irqsave(&irq_big_lock, flags);
574 /* If it's a legacy controller, check for duplicates and
575 * mark it as allocated (we use irq 0 host pointer for that
577 if (revmap_type == IRQ_HOST_MAP_LEGACY) {
578 if (irq_map[0].host != NULL) {
579 raw_spin_unlock_irqrestore(&irq_big_lock, flags);
580 /* If we are early boot, we can't free the structure,
582 * this will be fixed once slab is made available early
583 * instead of the current cruft
589 irq_map[0].host = host;
592 list_add(&host->link, &irq_hosts);
593 raw_spin_unlock_irqrestore(&irq_big_lock, flags);
595 /* Additional setups per revmap type */
596 switch(revmap_type) {
597 case IRQ_HOST_MAP_LEGACY:
598 /* 0 is always the invalid number for legacy */
600 /* setup us as the host for all legacy interrupts */
601 for (i = 1; i < NUM_ISA_INTERRUPTS; i++) {
602 irq_map[i].hwirq = i;
604 irq_map[i].host = host;
607 /* Clear norequest flags */
608 irq_to_desc(i)->status &= ~IRQ_NOREQUEST;
610 /* Legacy flags are left to default at this point,
611 * one can then use irq_create_mapping() to
612 * explicitly change them
614 ops->map(host, i, i);
617 case IRQ_HOST_MAP_LINEAR:
618 rmap = (unsigned int *)(host + 1);
619 for (i = 0; i < revmap_arg; i++)
621 host->revmap_data.linear.size = revmap_arg;
623 host->revmap_data.linear.revmap = rmap;
629 pr_debug("irq: Allocated host of type %d @0x%p\n", revmap_type, host);
634 struct irq_host *irq_find_host(struct device_node *node)
636 struct irq_host *h, *found = NULL;
639 /* We might want to match the legacy controller last since
640 * it might potentially be set to match all interrupts in
641 * the absence of a device node. This isn't a problem so far
644 raw_spin_lock_irqsave(&irq_big_lock, flags);
645 list_for_each_entry(h, &irq_hosts, link)
646 if (h->ops->match(h, node)) {
650 raw_spin_unlock_irqrestore(&irq_big_lock, flags);
653 EXPORT_SYMBOL_GPL(irq_find_host);
655 void irq_set_default_host(struct irq_host *host)
657 pr_debug("irq: Default host set to @0x%p\n", host);
659 irq_default_host = host;
662 void irq_set_virq_count(unsigned int count)
664 pr_debug("irq: Trying to set virq count to %d\n", count);
666 BUG_ON(count < NUM_ISA_INTERRUPTS);
668 irq_virq_count = count;
671 static int irq_setup_virq(struct irq_host *host, unsigned int virq,
672 irq_hw_number_t hwirq)
674 struct irq_desc *desc;
676 desc = irq_to_desc_alloc_node(virq, 0);
678 pr_debug("irq: -> allocating desc failed\n");
682 /* Clear IRQ_NOREQUEST flag */
683 desc->status &= ~IRQ_NOREQUEST;
687 irq_map[virq].hwirq = hwirq;
690 if (host->ops->map(host, virq, hwirq)) {
691 pr_debug("irq: -> mapping failed, freeing\n");
698 irq_free_virt(virq, 1);
702 unsigned int irq_create_direct_mapping(struct irq_host *host)
707 host = irq_default_host;
709 BUG_ON(host == NULL);
710 WARN_ON(host->revmap_type != IRQ_HOST_MAP_NOMAP);
712 virq = irq_alloc_virt(host, 1, 0);
713 if (virq == NO_IRQ) {
714 pr_debug("irq: create_direct virq allocation failed\n");
718 pr_debug("irq: create_direct obtained virq %d\n", virq);
720 if (irq_setup_virq(host, virq, virq))
726 unsigned int irq_create_mapping(struct irq_host *host,
727 irq_hw_number_t hwirq)
729 unsigned int virq, hint;
731 pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", host, hwirq);
733 /* Look for default host if nececssary */
735 host = irq_default_host;
737 printk(KERN_WARNING "irq_create_mapping called for"
738 " NULL host, hwirq=%lx\n", hwirq);
742 pr_debug("irq: -> using host @%p\n", host);
744 /* Check if mapping already exist, if it does, call
745 * host->ops->map() to update the flags
747 virq = irq_find_mapping(host, hwirq);
748 if (virq != NO_IRQ) {
749 if (host->ops->remap)
750 host->ops->remap(host, virq, hwirq);
751 pr_debug("irq: -> existing mapping on virq %d\n", virq);
755 /* Get a virtual interrupt number */
756 if (host->revmap_type == IRQ_HOST_MAP_LEGACY) {
758 virq = (unsigned int)hwirq;
759 if (virq == 0 || virq >= NUM_ISA_INTERRUPTS)
763 /* Allocate a virtual interrupt number */
764 hint = hwirq % irq_virq_count;
765 virq = irq_alloc_virt(host, 1, hint);
766 if (virq == NO_IRQ) {
767 pr_debug("irq: -> virq allocation failed\n");
772 if (irq_setup_virq(host, virq, hwirq))
775 printk(KERN_DEBUG "irq: irq %lu on host %s mapped to virtual irq %u\n",
776 hwirq, host->of_node ? host->of_node->full_name : "null", virq);
780 EXPORT_SYMBOL_GPL(irq_create_mapping);
782 unsigned int irq_create_of_mapping(struct device_node *controller,
783 const u32 *intspec, unsigned int intsize)
785 struct irq_host *host;
786 irq_hw_number_t hwirq;
787 unsigned int type = IRQ_TYPE_NONE;
790 if (controller == NULL)
791 host = irq_default_host;
793 host = irq_find_host(controller);
795 printk(KERN_WARNING "irq: no irq host found for %s !\n",
796 controller->full_name);
800 /* If host has no translation, then we assume interrupt line */
801 if (host->ops->xlate == NULL)
804 if (host->ops->xlate(host, controller, intspec, intsize,
810 virq = irq_create_mapping(host, hwirq);
814 /* Set type if specified and different than the current one */
815 if (type != IRQ_TYPE_NONE &&
816 type != (irq_to_desc(virq)->status & IRQF_TRIGGER_MASK))
817 set_irq_type(virq, type);
820 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
822 unsigned int irq_of_parse_and_map(struct device_node *dev, int index)
826 if (of_irq_map_one(dev, index, &oirq))
829 return irq_create_of_mapping(oirq.controller, oirq.specifier,
832 EXPORT_SYMBOL_GPL(irq_of_parse_and_map);
834 void irq_dispose_mapping(unsigned int virq)
836 struct irq_host *host;
837 irq_hw_number_t hwirq;
842 host = irq_map[virq].host;
843 WARN_ON (host == NULL);
847 /* Never unmap legacy interrupts */
848 if (host->revmap_type == IRQ_HOST_MAP_LEGACY)
851 /* remove chip and handler */
852 set_irq_chip_and_handler(virq, NULL, NULL);
854 /* Make sure it's completed */
855 synchronize_irq(virq);
857 /* Tell the PIC about it */
858 if (host->ops->unmap)
859 host->ops->unmap(host, virq);
862 /* Clear reverse map */
863 hwirq = irq_map[virq].hwirq;
864 switch(host->revmap_type) {
865 case IRQ_HOST_MAP_LINEAR:
866 if (hwirq < host->revmap_data.linear.size)
867 host->revmap_data.linear.revmap[hwirq] = NO_IRQ;
869 case IRQ_HOST_MAP_TREE:
871 * Check if radix tree allocated yet, if not then nothing to
875 if (revmap_trees_allocated < 1)
877 mutex_lock(&revmap_trees_mutex);
878 radix_tree_delete(&host->revmap_data.tree, hwirq);
879 mutex_unlock(&revmap_trees_mutex);
885 irq_map[virq].hwirq = host->inval_irq;
888 irq_to_desc(virq)->status |= IRQ_NOREQUEST;
891 irq_free_virt(virq, 1);
893 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
895 unsigned int irq_find_mapping(struct irq_host *host,
896 irq_hw_number_t hwirq)
899 unsigned int hint = hwirq % irq_virq_count;
901 /* Look for default host if nececssary */
903 host = irq_default_host;
907 /* legacy -> bail early */
908 if (host->revmap_type == IRQ_HOST_MAP_LEGACY)
911 /* Slow path does a linear search of the map */
912 if (hint < NUM_ISA_INTERRUPTS)
913 hint = NUM_ISA_INTERRUPTS;
916 if (irq_map[i].host == host &&
917 irq_map[i].hwirq == hwirq)
920 if (i >= irq_virq_count)
921 i = NUM_ISA_INTERRUPTS;
925 EXPORT_SYMBOL_GPL(irq_find_mapping);
928 unsigned int irq_radix_revmap_lookup(struct irq_host *host,
929 irq_hw_number_t hwirq)
931 struct irq_map_entry *ptr;
934 WARN_ON(host->revmap_type != IRQ_HOST_MAP_TREE);
937 * Check if the radix tree exists and has bee initialized.
938 * If not, we fallback to slow mode
940 if (revmap_trees_allocated < 2)
941 return irq_find_mapping(host, hwirq);
943 /* Now try to resolve */
945 * No rcu_read_lock(ing) needed, the ptr returned can't go under us
946 * as it's referencing an entry in the static irq_map table.
948 ptr = radix_tree_lookup(&host->revmap_data.tree, hwirq);
951 * If found in radix tree, then fine.
952 * Else fallback to linear lookup - this should not happen in practice
953 * as it means that we failed to insert the node in the radix tree.
956 virq = ptr - irq_map;
958 virq = irq_find_mapping(host, hwirq);
963 void irq_radix_revmap_insert(struct irq_host *host, unsigned int virq,
964 irq_hw_number_t hwirq)
967 WARN_ON(host->revmap_type != IRQ_HOST_MAP_TREE);
970 * Check if the radix tree exists yet.
971 * If not, then the irq will be inserted into the tree when it gets
975 if (revmap_trees_allocated < 1)
978 if (virq != NO_IRQ) {
979 mutex_lock(&revmap_trees_mutex);
980 radix_tree_insert(&host->revmap_data.tree, hwirq,
982 mutex_unlock(&revmap_trees_mutex);
986 unsigned int irq_linear_revmap(struct irq_host *host,
987 irq_hw_number_t hwirq)
989 unsigned int *revmap;
991 WARN_ON(host->revmap_type != IRQ_HOST_MAP_LINEAR);
993 /* Check revmap bounds */
994 if (unlikely(hwirq >= host->revmap_data.linear.size))
995 return irq_find_mapping(host, hwirq);
997 /* Check if revmap was allocated */
998 revmap = host->revmap_data.linear.revmap;
999 if (unlikely(revmap == NULL))
1000 return irq_find_mapping(host, hwirq);
1002 /* Fill up revmap with slow path if no mapping found */
1003 if (unlikely(revmap[hwirq] == NO_IRQ))
1004 revmap[hwirq] = irq_find_mapping(host, hwirq);
1006 return revmap[hwirq];
1009 unsigned int irq_alloc_virt(struct irq_host *host,
1013 unsigned long flags;
1014 unsigned int i, j, found = NO_IRQ;
1016 if (count == 0 || count > (irq_virq_count - NUM_ISA_INTERRUPTS))
1019 raw_spin_lock_irqsave(&irq_big_lock, flags);
1021 /* Use hint for 1 interrupt if any */
1022 if (count == 1 && hint >= NUM_ISA_INTERRUPTS &&
1023 hint < irq_virq_count && irq_map[hint].host == NULL) {
1028 /* Look for count consecutive numbers in the allocatable
1029 * (non-legacy) space
1031 for (i = NUM_ISA_INTERRUPTS, j = 0; i < irq_virq_count; i++) {
1032 if (irq_map[i].host != NULL)
1038 found = i - count + 1;
1042 if (found == NO_IRQ) {
1043 raw_spin_unlock_irqrestore(&irq_big_lock, flags);
1047 for (i = found; i < (found + count); i++) {
1048 irq_map[i].hwirq = host->inval_irq;
1050 irq_map[i].host = host;
1052 raw_spin_unlock_irqrestore(&irq_big_lock, flags);
1056 void irq_free_virt(unsigned int virq, unsigned int count)
1058 unsigned long flags;
1061 WARN_ON (virq < NUM_ISA_INTERRUPTS);
1062 WARN_ON (count == 0 || (virq + count) > irq_virq_count);
1064 raw_spin_lock_irqsave(&irq_big_lock, flags);
1065 for (i = virq; i < (virq + count); i++) {
1066 struct irq_host *host;
1068 if (i < NUM_ISA_INTERRUPTS ||
1069 (virq + count) > irq_virq_count)
1072 host = irq_map[i].host;
1073 irq_map[i].hwirq = host->inval_irq;
1075 irq_map[i].host = NULL;
1077 raw_spin_unlock_irqrestore(&irq_big_lock, flags);
1080 int arch_early_irq_init(void)
1082 struct irq_desc *desc;
1085 for (i = 0; i < NR_IRQS; i++) {
1086 desc = irq_to_desc(i);
1088 desc->status |= IRQ_NOREQUEST;
1094 int arch_init_chip_data(struct irq_desc *desc, int node)
1096 desc->status |= IRQ_NOREQUEST;
1100 /* We need to create the radix trees late */
1101 static int irq_late_init(void)
1107 * No mutual exclusion with respect to accessors of the tree is needed
1108 * here as the synchronization is done via the state variable
1109 * revmap_trees_allocated.
1111 list_for_each_entry(h, &irq_hosts, link) {
1112 if (h->revmap_type == IRQ_HOST_MAP_TREE)
1113 INIT_RADIX_TREE(&h->revmap_data.tree, GFP_KERNEL);
1117 * Make sure the radix trees inits are visible before setting
1121 revmap_trees_allocated = 1;
1124 * Insert the reverse mapping for those interrupts already present
1127 mutex_lock(&revmap_trees_mutex);
1128 for (i = 0; i < irq_virq_count; i++) {
1129 if (irq_map[i].host &&
1130 (irq_map[i].host->revmap_type == IRQ_HOST_MAP_TREE))
1131 radix_tree_insert(&irq_map[i].host->revmap_data.tree,
1132 irq_map[i].hwirq, &irq_map[i]);
1134 mutex_unlock(&revmap_trees_mutex);
1137 * Make sure the radix trees insertions are visible before setting
1141 revmap_trees_allocated = 2;
1145 arch_initcall(irq_late_init);
1147 #ifdef CONFIG_VIRQ_DEBUG
1148 static int virq_debug_show(struct seq_file *m, void *private)
1150 unsigned long flags;
1151 struct irq_desc *desc;
1153 char none[] = "none";
1156 seq_printf(m, "%-5s %-7s %-15s %s\n", "virq", "hwirq",
1157 "chip name", "host name");
1159 for (i = 1; i < nr_irqs; i++) {
1160 desc = irq_to_desc(i);
1164 raw_spin_lock_irqsave(&desc->lock, flags);
1166 if (desc->action && desc->action->handler) {
1167 seq_printf(m, "%5d ", i);
1168 seq_printf(m, "0x%05lx ", virq_to_hw(i));
1170 if (desc->chip && desc->chip->name)
1171 p = desc->chip->name;
1174 seq_printf(m, "%-15s ", p);
1176 if (irq_map[i].host && irq_map[i].host->of_node)
1177 p = irq_map[i].host->of_node->full_name;
1180 seq_printf(m, "%s\n", p);
1183 raw_spin_unlock_irqrestore(&desc->lock, flags);
1189 static int virq_debug_open(struct inode *inode, struct file *file)
1191 return single_open(file, virq_debug_show, inode->i_private);
1194 static const struct file_operations virq_debug_fops = {
1195 .open = virq_debug_open,
1197 .llseek = seq_lseek,
1198 .release = single_release,
1201 static int __init irq_debugfs_init(void)
1203 if (debugfs_create_file("virq_mapping", S_IRUGO, powerpc_debugfs_root,
1204 NULL, &virq_debug_fops) == NULL)
1209 __initcall(irq_debugfs_init);
1210 #endif /* CONFIG_VIRQ_DEBUG */
1213 static int __init setup_noirqdistrib(char *str)
1215 distribute_irqs = 0;
1219 __setup("noirqdistrib", setup_noirqdistrib);
1220 #endif /* CONFIG_PPC64 */