irqinit.c 5.3 KB
Newer Older
1
#include <linux/linkage.h>
L
Linus Torvalds 已提交
2 3 4 5 6
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
7
#include <linux/timex.h>
L
Linus Torvalds 已提交
8
#include <linux/random.h>
9
#include <linux/kprobes.h>
L
Linus Torvalds 已提交
10 11
#include <linux/init.h>
#include <linux/kernel_stat.h>
K
Kay Sievers 已提交
12
#include <linux/device.h>
L
Linus Torvalds 已提交
13
#include <linux/bitops.h>
14
#include <linux/acpi.h>
15 16
#include <linux/io.h>
#include <linux/delay.h>
L
Linus Torvalds 已提交
17

A
Arun Sharma 已提交
18
#include <linux/atomic.h>
L
Linus Torvalds 已提交
19
#include <asm/timer.h>
20
#include <asm/hw_irq.h>
L
Linus Torvalds 已提交
21 22 23
#include <asm/pgtable.h>
#include <asm/desc.h>
#include <asm/apic.h>
I
Ingo Molnar 已提交
24
#include <asm/setup.h>
L
Linus Torvalds 已提交
25
#include <asm/i8259.h>
26
#include <asm/traps.h>
27
#include <asm/prom.h>
L
Linus Torvalds 已提交
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/*
 * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
 * (these are usually mapped to vectors 0x30-0x3f)
 */

/*
 * The IO-APIC gives us many more interrupt sources. Most of these
 * are unused but an SMP system is supposed to have enough memory ...
 * sometimes (mostly wrt. hw bugs) we get corrupted vectors all
 * across the spectrum, so we really want to be prepared to get all
 * of these. Plus, more powerful systems might have more than 64
 * IO-APIC registers.
 *
 * (these are usually mapped into the 0x30-0xff vector range)
 */
L
Linus Torvalds 已提交
44

45 46 47 48 49 50
/*
 * IRQ2 is cascade interrupt to second interrupt controller
 */
static struct irqaction irq2 = {
	.handler = no_action,
	.name = "cascade",
51
	.flags = IRQF_NO_THREAD,
52 53
};

54
DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
55
	[0 ... NR_VECTORS - 1] = VECTOR_UNUSED,
56 57
};

58 59 60 61 62
int vector_used_by_percpu_irq(unsigned int vector)
{
	int cpu;

	for_each_online_cpu(cpu) {
63
		if (!IS_ERR_OR_NULL(per_cpu(vector_irq, cpu)[vector]))
64 65 66 67 68 69
			return 1;
	}

	return 0;
}

70
void __init init_ISA_irqs(void)
L
Linus Torvalds 已提交
71
{
72
	struct irq_chip *chip = legacy_pic->chip;
L
Linus Torvalds 已提交
73 74
	int i;

75
#if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
76 77
	init_bsp_APIC();
#endif
78
	legacy_pic->init(0);
L
Linus Torvalds 已提交
79

80
	for (i = 0; i < nr_legacy_irqs(); i++)
81
		irq_set_chip_and_handler(i, chip, handle_level_irq);
82
}
L
Linus Torvalds 已提交
83

84
void __init init_IRQ(void)
85
{
86 87 88
	int i;

	/*
89
	 * On cpu 0, Assign ISA_IRQ_VECTOR(irq) to IRQ 0..15.
90 91 92 93 94 95
	 * If these IRQ's are handled by legacy interrupt-controllers like PIC,
	 * then this configuration will likely be static after the boot. If
	 * these IRQ's are handled by more mordern controllers like IO-APIC,
	 * then this vector space can be freed and re-used dynamically as the
	 * irq's migrate etc.
	 */
96
	for (i = 0; i < nr_legacy_irqs(); i++)
97
		per_cpu(vector_irq, 0)[ISA_IRQ_VECTOR(i)] = irq_to_desc(i);
98

99 100
	x86_init.irqs.intr_init();
}
101

102 103
static void __init smp_intr_init(void)
{
104
#ifdef CONFIG_SMP
105 106 107 108 109 110 111 112 113
	/*
	 * The reschedule interrupt is a CPU-to-CPU reschedule-helper
	 * IPI, driven by wakeup.
	 */
	alloc_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);

	/* IPI for generic function call */
	alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);

114
	/* IPI for generic single function call */
115
	alloc_intr_gate(CALL_FUNCTION_SINGLE_VECTOR,
116
			call_function_single_interrupt);
117 118 119

	/* Low priority IPI to cleanup after moving an irq */
	set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
120
	set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors);
121 122 123

	/* IPI used for rebooting/stopping */
	alloc_intr_gate(REBOOT_VECTOR, reboot_interrupt);
124
#endif /* CONFIG_SMP */
125 126
}

127
static void __init apic_intr_init(void)
L
Linus Torvalds 已提交
128
{
129
	smp_intr_init();
130

131
#ifdef CONFIG_X86_THERMAL_VECTOR
132
	alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
133
#endif
134
#ifdef CONFIG_X86_MCE_THRESHOLD
135 136 137
	alloc_intr_gate(THRESHOLD_APIC_VECTOR, threshold_interrupt);
#endif

138 139 140 141
#ifdef CONFIG_X86_MCE_AMD
	alloc_intr_gate(DEFERRED_ERROR_VECTOR, deferred_error_interrupt);
#endif

142
#ifdef CONFIG_X86_LOCAL_APIC
143 144 145
	/* self generated IPI for local APIC timer */
	alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);

146 147
	/* IPI for X86 platform specific use */
	alloc_intr_gate(X86_PLATFORM_IPI_VECTOR, x86_platform_ipi);
148 149 150
#ifdef CONFIG_HAVE_KVM
	/* IPI for KVM to deliver posted interrupt */
	alloc_intr_gate(POSTED_INTR_VECTOR, kvm_posted_intr_ipi);
151 152
	/* IPI for KVM to deliver interrupt to wake up tasks */
	alloc_intr_gate(POSTED_INTR_WAKEUP_VECTOR, kvm_posted_intr_wakeup_ipi);
153 154
	/* IPI for KVM to deliver nested posted interrupt */
	alloc_intr_gate(POSTED_INTR_NESTED_VECTOR, kvm_posted_intr_nested_ipi);
155
#endif
156

157 158 159 160
	/* IPI vectors for APIC spurious and error interrupts */
	alloc_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
	alloc_intr_gate(ERROR_APIC_VECTOR, error_interrupt);

161 162 163
	/* IRQ work interrupts: */
# ifdef CONFIG_IRQ_WORK
	alloc_intr_gate(IRQ_WORK_VECTOR, irq_work_interrupt);
164 165
# endif

166
#endif
167
}
168

169 170 171 172 173
void __init native_init_IRQ(void)
{
	int i;

	/* Execute any quirks before the call gates are initialised: */
174
	x86_init.irqs.pre_vector_init();
175

Y
Yinghai Lu 已提交
176 177
	apic_intr_init();

178 179 180 181 182
	/*
	 * Cover the whole vector space, no vector can escape
	 * us. (some of these will be overridden and become
	 * 'special' SMP interrupts)
	 */
183
	i = FIRST_EXTERNAL_VECTOR;
184 185 186 187
#ifndef CONFIG_X86_LOCAL_APIC
#define first_system_vector NR_VECTORS
#endif
	for_each_clear_bit_from(i, used_vectors, first_system_vector) {
Y
Yinghai Lu 已提交
188
		/* IA32_SYSCALL_VECTOR could be used in trap_init already. */
189 190
		set_intr_gate(i, irq_entries_start +
				8 * (i - FIRST_EXTERNAL_VECTOR));
191
	}
192 193 194 195
#ifdef CONFIG_X86_LOCAL_APIC
	for_each_clear_bit_from(i, used_vectors, NR_VECTORS)
		set_intr_gate(i, spurious_interrupt);
#endif
196

197
	if (!acpi_ioapic && !of_ioapic && nr_legacy_irqs())
198 199
		setup_irq(2, &irq2);

L
Linus Torvalds 已提交
200 201
	irq_ctx_init(smp_processor_id());
}