| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/linkage.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/errno.h> | 
|  | 3 | #include <linux/signal.h> | 
|  | 4 | #include <linux/sched.h> | 
|  | 5 | #include <linux/ioport.h> | 
|  | 6 | #include <linux/interrupt.h> | 
|  | 7 | #include <linux/timex.h> | 
|  | 8 | #include <linux/slab.h> | 
|  | 9 | #include <linux/random.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> | 
|  | 11 | #include <linux/kernel_stat.h> | 
|  | 12 | #include <linux/sysdev.h> | 
|  | 13 | #include <linux/bitops.h> | 
| Jaswinder Singh Rajput | f50cec3 | 2009-01-04 16:36:25 +0530 | [diff] [blame] | 14 | #include <linux/acpi.h> | 
|  | 15 | #include <linux/io.h> | 
|  | 16 | #include <linux/delay.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/atomic.h> | 
|  | 19 | #include <asm/system.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/hw_irq.h> | 
|  | 21 | #include <asm/pgtable.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/desc.h> | 
|  | 23 | #include <asm/apic.h> | 
| Paul Jimenez | 2b8e05b | 2008-01-30 13:30:29 +0100 | [diff] [blame] | 24 | #include <asm/i8259.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts: | 
| Yinghai Lu | c97beb4 | 2007-03-28 23:10:29 -0600 | [diff] [blame] | 28 | * (these are usually mapped to vectors 0x30-0x3f) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* | 
| Paul Jimenez | 2b8e05b | 2008-01-30 13:30:29 +0100 | [diff] [blame] | 32 | * The IO-APIC gives us many more interrupt sources. Most of these | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * are unused but an SMP system is supposed to have enough memory ... | 
|  | 34 | * sometimes (mostly wrt. hw bugs) we get corrupted vectors all | 
|  | 35 | * across the spectrum, so we really want to be prepared to get all | 
|  | 36 | * of these. Plus, more powerful systems might have more than 64 | 
|  | 37 | * IO-APIC registers. | 
|  | 38 | * | 
|  | 39 | * (these are usually mapped into the 0x30-0xff vector range) | 
|  | 40 | */ | 
| Paul Jimenez | 2b8e05b | 2008-01-30 13:30:29 +0100 | [diff] [blame] | 41 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* | 
|  | 43 | * IRQ2 is cascade interrupt to second interrupt controller | 
|  | 44 | */ | 
|  | 45 |  | 
| Thomas Gleixner | df5ddf6 | 2007-10-17 18:04:36 +0200 | [diff] [blame] | 46 | static struct irqaction irq2 = { | 
|  | 47 | .handler = no_action, | 
| Thomas Gleixner | df5ddf6 | 2007-10-17 18:04:36 +0200 | [diff] [blame] | 48 | .name = "cascade", | 
|  | 49 | }; | 
| Eric W. Biederman | 550f229 | 2006-10-04 02:16:51 -0700 | [diff] [blame] | 50 | DEFINE_PER_CPU(vector_irq_t, vector_irq) = { | 
| Eric W. Biederman | bc5e81a | 2007-02-23 04:38:26 -0700 | [diff] [blame] | 51 | [0 ... IRQ0_VECTOR - 1] = -1, | 
|  | 52 | [IRQ0_VECTOR] = 0, | 
|  | 53 | [IRQ1_VECTOR] = 1, | 
|  | 54 | [IRQ2_VECTOR] = 2, | 
|  | 55 | [IRQ3_VECTOR] = 3, | 
|  | 56 | [IRQ4_VECTOR] = 4, | 
|  | 57 | [IRQ5_VECTOR] = 5, | 
|  | 58 | [IRQ6_VECTOR] = 6, | 
|  | 59 | [IRQ7_VECTOR] = 7, | 
|  | 60 | [IRQ8_VECTOR] = 8, | 
|  | 61 | [IRQ9_VECTOR] = 9, | 
|  | 62 | [IRQ10_VECTOR] = 10, | 
|  | 63 | [IRQ11_VECTOR] = 11, | 
|  | 64 | [IRQ12_VECTOR] = 12, | 
|  | 65 | [IRQ13_VECTOR] = 13, | 
|  | 66 | [IRQ14_VECTOR] = 14, | 
|  | 67 | [IRQ15_VECTOR] = 15, | 
|  | 68 | [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1 | 
| Eric W. Biederman | e500f57 | 2006-10-04 02:16:50 -0700 | [diff] [blame] | 69 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 |  | 
| Yinghai Lu | b77b881 | 2008-12-19 15:23:44 -0800 | [diff] [blame] | 71 | int vector_used_by_percpu_irq(unsigned int vector) | 
|  | 72 | { | 
|  | 73 | int cpu; | 
|  | 74 |  | 
|  | 75 | for_each_online_cpu(cpu) { | 
|  | 76 | if (per_cpu(vector_irq, cpu)[vector] != -1) | 
|  | 77 | return 1; | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | return 0; | 
|  | 81 | } | 
|  | 82 |  | 
| Jaswinder Singh Rajput | dd399dc | 2008-12-30 21:10:13 +0530 | [diff] [blame] | 83 | static void __init init_ISA_irqs(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { | 
|  | 85 | int i; | 
|  | 86 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | init_bsp_APIC(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | init_8259A(0); | 
|  | 89 |  | 
| Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame] | 90 | for (i = 0; i < NR_IRQS_LEGACY; i++) { | 
| Thomas Gleixner | ee32c97 | 2008-10-15 14:34:09 +0200 | [diff] [blame] | 91 | struct irq_desc *desc = irq_to_desc(i); | 
| Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | desc->status = IRQ_DISABLED; | 
|  | 94 | desc->action = NULL; | 
|  | 95 | desc->depth = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 |  | 
| Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 97 | /* | 
|  | 98 | * 16 old-style INTA-cycle interrupts: | 
|  | 99 | */ | 
|  | 100 | set_irq_chip_and_handler_name(i, &i8259A_chip, | 
| Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 101 | handle_level_irq, "XT"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } | 
|  | 103 | } | 
|  | 104 |  | 
| Glauber de Oliveira Costa | b038783 | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 105 | void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ"))); | 
|  | 106 |  | 
| Yinghai Lu | 9b658f6 | 2008-09-25 22:22:12 -0700 | [diff] [blame] | 107 | static void __init smp_intr_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #ifdef CONFIG_SMP | 
|  | 110 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | * The reschedule interrupt is a CPU-to-CPU reschedule-helper | 
|  | 112 | * IPI, driven by wakeup. | 
|  | 113 | */ | 
| Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 114 | alloc_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 |  | 
| Andi Kleen | e5bc8b6 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 116 | /* IPIs for invalidation */ | 
| Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 117 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+0, invalidate_interrupt0); | 
|  | 118 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+1, invalidate_interrupt1); | 
|  | 119 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+2, invalidate_interrupt2); | 
|  | 120 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+3, invalidate_interrupt3); | 
|  | 121 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+4, invalidate_interrupt4); | 
|  | 122 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+5, invalidate_interrupt5); | 
|  | 123 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+6, invalidate_interrupt6); | 
|  | 124 | alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+7, invalidate_interrupt7); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 |  | 
|  | 126 | /* IPI for generic function call */ | 
| Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 127 | alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt); | 
| Eric W. Biederman | 6101429 | 2007-02-23 04:40:58 -0700 | [diff] [blame] | 128 |  | 
| Ingo Molnar | 1a781a7 | 2008-07-15 21:55:59 +0200 | [diff] [blame] | 129 | /* IPI for generic single function call */ | 
|  | 130 | alloc_intr_gate(CALL_FUNCTION_SINGLE_VECTOR, | 
|  | 131 | call_function_single_interrupt); | 
|  | 132 |  | 
| Eric W. Biederman | 6101429 | 2007-02-23 04:40:58 -0700 | [diff] [blame] | 133 | /* Low priority IPI to cleanup after moving an irq */ | 
|  | 134 | set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt); | 
| Yinghai Lu | b77b881 | 2008-12-19 15:23:44 -0800 | [diff] [blame] | 135 | set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors); | 
| Eric W. Biederman | 6101429 | 2007-02-23 04:40:58 -0700 | [diff] [blame] | 136 | #endif | 
| Glauber Costa | 2f97435 | 2008-07-11 15:08:39 -0300 | [diff] [blame] | 137 | } | 
|  | 138 |  | 
| Yinghai Lu | 9b658f6 | 2008-09-25 22:22:12 -0700 | [diff] [blame] | 139 | static void __init apic_intr_init(void) | 
| Glauber Costa | 2f97435 | 2008-07-11 15:08:39 -0300 | [diff] [blame] | 140 | { | 
| Glauber Costa | 2f97435 | 2008-07-11 15:08:39 -0300 | [diff] [blame] | 141 | smp_intr_init(); | 
| Glauber Costa | 2f97435 | 2008-07-11 15:08:39 -0300 | [diff] [blame] | 142 |  | 
| Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 143 | alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt); | 
|  | 144 | alloc_intr_gate(THRESHOLD_APIC_VECTOR, threshold_interrupt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | /* self generated IPI for local APIC timer */ | 
| Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 147 | alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 |  | 
| Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 149 | /* generic IPI for platform specific use */ | 
|  | 150 | alloc_intr_gate(GENERIC_INTERRUPT_VECTOR, generic_interrupt); | 
|  | 151 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* IPI vectors for APIC spurious and error interrupts */ | 
| Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 153 | alloc_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt); | 
|  | 154 | alloc_intr_gate(ERROR_APIC_VECTOR, error_interrupt); | 
| Glauber Costa | 2f97435 | 2008-07-11 15:08:39 -0300 | [diff] [blame] | 155 | } | 
|  | 156 |  | 
|  | 157 | void __init native_init_IRQ(void) | 
|  | 158 | { | 
|  | 159 | int i; | 
|  | 160 |  | 
|  | 161 | init_ISA_irqs(); | 
|  | 162 | /* | 
|  | 163 | * Cover the whole vector space, no vector can escape | 
|  | 164 | * us. (some of these will be overridden and become | 
|  | 165 | * 'special' SMP interrupts) | 
|  | 166 | */ | 
|  | 167 | for (i = 0; i < (NR_VECTORS - FIRST_EXTERNAL_VECTOR); i++) { | 
|  | 168 | int vector = FIRST_EXTERNAL_VECTOR + i; | 
|  | 169 | if (vector != IA32_SYSCALL_VECTOR) | 
|  | 170 | set_intr_gate(vector, interrupt[i]); | 
|  | 171 | } | 
|  | 172 |  | 
|  | 173 | apic_intr_init(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (!acpi_ioapic) | 
|  | 176 | setup_irq(2, &irq2); | 
|  | 177 | } |