xref: /linux/arch/x86/kernel/idt.c (revision 48227e21f7430e31042f63e078a45cd230e9fdfc)
182c73e0aSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d8ed9d48SThomas Gleixner /*
3d8ed9d48SThomas Gleixner  * Interrupt descriptor table related code
4d8ed9d48SThomas Gleixner  */
5d8ed9d48SThomas Gleixner #include <linux/interrupt.h>
6d8ed9d48SThomas Gleixner 
73318e974SThomas Gleixner #include <asm/traps.h>
83318e974SThomas Gleixner #include <asm/proto.h>
9d8ed9d48SThomas Gleixner #include <asm/desc.h>
10447ae316SNicolai Stange #include <asm/hw_irq.h>
11d8ed9d48SThomas Gleixner 
123318e974SThomas Gleixner struct idt_data {
133318e974SThomas Gleixner 	unsigned int	vector;
143318e974SThomas Gleixner 	unsigned int	segment;
153318e974SThomas Gleixner 	struct idt_bits	bits;
163318e974SThomas Gleixner 	const void	*addr;
173318e974SThomas Gleixner };
183318e974SThomas Gleixner 
193318e974SThomas Gleixner #define DPL0		0x0
203318e974SThomas Gleixner #define DPL3		0x3
213318e974SThomas Gleixner 
223318e974SThomas Gleixner #define DEFAULT_STACK	0
233318e974SThomas Gleixner 
243318e974SThomas Gleixner #define G(_vector, _addr, _ist, _type, _dpl, _segment)	\
253318e974SThomas Gleixner 	{						\
263318e974SThomas Gleixner 		.vector		= _vector,		\
273318e974SThomas Gleixner 		.bits.ist	= _ist,			\
283318e974SThomas Gleixner 		.bits.type	= _type,		\
293318e974SThomas Gleixner 		.bits.dpl	= _dpl,			\
303318e974SThomas Gleixner 		.bits.p		= 1,			\
313318e974SThomas Gleixner 		.addr		= _addr,		\
323318e974SThomas Gleixner 		.segment	= _segment,		\
333318e974SThomas Gleixner 	}
343318e974SThomas Gleixner 
353318e974SThomas Gleixner /* Interrupt gate */
363318e974SThomas Gleixner #define INTG(_vector, _addr)				\
373318e974SThomas Gleixner 	G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL0, __KERNEL_CS)
383318e974SThomas Gleixner 
393318e974SThomas Gleixner /* System interrupt gate */
403318e974SThomas Gleixner #define SYSG(_vector, _addr)				\
413318e974SThomas Gleixner 	G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL3, __KERNEL_CS)
423318e974SThomas Gleixner 
438f34c5b5SThomas Gleixner /*
448f34c5b5SThomas Gleixner  * Interrupt gate with interrupt stack. The _ist index is the index in
458f34c5b5SThomas Gleixner  * the tss.ist[] array, but for the descriptor it needs to start at 1.
468f34c5b5SThomas Gleixner  */
473318e974SThomas Gleixner #define ISTG(_vector, _addr, _ist)			\
488f34c5b5SThomas Gleixner 	G(_vector, _addr, _ist + 1, GATE_INTERRUPT, DPL0, __KERNEL_CS)
493318e974SThomas Gleixner 
503318e974SThomas Gleixner /* Task gate */
513318e974SThomas Gleixner #define TSKG(_vector, _gdt)				\
523318e974SThomas Gleixner 	G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3)
533318e974SThomas Gleixner 
5406184325SVitaly Kuznetsov 
5506184325SVitaly Kuznetsov static bool idt_setup_done __initdata;
5606184325SVitaly Kuznetsov 
57433f8924SThomas Gleixner /*
58433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
59433f8924SThomas Gleixner  * stacks work only after cpu_init().
60433f8924SThomas Gleixner  */
61327867faSAndi Kleen static const __initconst struct idt_data early_idts[] = {
62433f8924SThomas Gleixner 	INTG(X86_TRAP_DB,		debug),
63433f8924SThomas Gleixner 	SYSG(X86_TRAP_BP,		int3),
64433f8924SThomas Gleixner #ifdef CONFIG_X86_32
65433f8924SThomas Gleixner 	INTG(X86_TRAP_PF,		page_fault),
66433f8924SThomas Gleixner #endif
67433f8924SThomas Gleixner };
68433f8924SThomas Gleixner 
69b70543a0SThomas Gleixner /*
70b70543a0SThomas Gleixner  * The default IDT entries which are set up in trap_init() before
71b70543a0SThomas Gleixner  * cpu_init() is invoked. Interrupt stacks cannot be used at that point and
72b70543a0SThomas Gleixner  * the traps which use them are reinitialized with IST after cpu_init() has
73b70543a0SThomas Gleixner  * set up TSS.
74b70543a0SThomas Gleixner  */
75327867faSAndi Kleen static const __initconst struct idt_data def_idts[] = {
769d06c402SThomas Gleixner 	INTG(X86_TRAP_DE,		asm_exc_divide_error),
77b70543a0SThomas Gleixner 	INTG(X86_TRAP_NMI,		nmi),
7858d9c81fSThomas Gleixner 	INTG(X86_TRAP_BR,		asm_exc_bounds),
7949893c5cSThomas Gleixner 	INTG(X86_TRAP_UD,		asm_exc_invalid_op),
80866ae2ccSThomas Gleixner 	INTG(X86_TRAP_NM,		asm_exc_device_not_available),
81f95658fdSThomas Gleixner 	INTG(X86_TRAP_OLD_MF,		asm_exc_coproc_segment_overrun),
8297b3d290SThomas Gleixner 	INTG(X86_TRAP_TS,		asm_exc_invalid_tss),
8399a3fb8dSThomas Gleixner 	INTG(X86_TRAP_NP,		asm_exc_segment_not_present),
84fd9689bfSThomas Gleixner 	INTG(X86_TRAP_SS,		asm_exc_stack_segment),
85be4c11afSThomas Gleixner 	INTG(X86_TRAP_GP,		asm_exc_general_protection),
86dad7106fSThomas Gleixner 	INTG(X86_TRAP_SPURIOUS,		asm_exc_spurious_interrupt_bug),
8714a8bd2aSThomas Gleixner 	INTG(X86_TRAP_MF,		asm_exc_coprocessor_error),
88436608bbSThomas Gleixner 	INTG(X86_TRAP_AC,		asm_exc_alignment_check),
89*48227e21SThomas Gleixner 	INTG(X86_TRAP_XF,		asm_exc_simd_coprocessor_error),
90b70543a0SThomas Gleixner 
91b70543a0SThomas Gleixner #ifdef CONFIG_X86_32
92b70543a0SThomas Gleixner 	TSKG(X86_TRAP_DF,		GDT_ENTRY_DOUBLEFAULT_TSS),
93b70543a0SThomas Gleixner #else
94b70543a0SThomas Gleixner 	INTG(X86_TRAP_DF,		double_fault),
95b70543a0SThomas Gleixner #endif
96b70543a0SThomas Gleixner 	INTG(X86_TRAP_DB,		debug),
97b70543a0SThomas Gleixner 
98b70543a0SThomas Gleixner #ifdef CONFIG_X86_MCE
99fbaed278SLai Jiangshan 	INTG(X86_TRAP_MC,		machine_check),
100b70543a0SThomas Gleixner #endif
101b70543a0SThomas Gleixner 
1024b6b9111SThomas Gleixner 	SYSG(X86_TRAP_OF,		asm_exc_overflow),
103b70543a0SThomas Gleixner #if defined(CONFIG_IA32_EMULATION)
104b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_compat),
105b70543a0SThomas Gleixner #elif defined(CONFIG_X86_32)
106b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_32),
107b70543a0SThomas Gleixner #endif
108b70543a0SThomas Gleixner };
109b70543a0SThomas Gleixner 
110636a7598SThomas Gleixner /*
111636a7598SThomas Gleixner  * The APIC and SMP idt entries
112636a7598SThomas Gleixner  */
113327867faSAndi Kleen static const __initconst struct idt_data apic_idts[] = {
114636a7598SThomas Gleixner #ifdef CONFIG_SMP
115636a7598SThomas Gleixner 	INTG(RESCHEDULE_VECTOR,		reschedule_interrupt),
116636a7598SThomas Gleixner 	INTG(CALL_FUNCTION_VECTOR,	call_function_interrupt),
117636a7598SThomas Gleixner 	INTG(CALL_FUNCTION_SINGLE_VECTOR, call_function_single_interrupt),
118636a7598SThomas Gleixner 	INTG(IRQ_MOVE_CLEANUP_VECTOR,	irq_move_cleanup_interrupt),
119636a7598SThomas Gleixner 	INTG(REBOOT_VECTOR,		reboot_interrupt),
120636a7598SThomas Gleixner #endif
121636a7598SThomas Gleixner 
122636a7598SThomas Gleixner #ifdef CONFIG_X86_THERMAL_VECTOR
123636a7598SThomas Gleixner 	INTG(THERMAL_APIC_VECTOR,	thermal_interrupt),
124636a7598SThomas Gleixner #endif
125636a7598SThomas Gleixner 
126636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_THRESHOLD
127636a7598SThomas Gleixner 	INTG(THRESHOLD_APIC_VECTOR,	threshold_interrupt),
128636a7598SThomas Gleixner #endif
129636a7598SThomas Gleixner 
130636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_AMD
131636a7598SThomas Gleixner 	INTG(DEFERRED_ERROR_VECTOR,	deferred_error_interrupt),
132636a7598SThomas Gleixner #endif
133636a7598SThomas Gleixner 
134636a7598SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
135636a7598SThomas Gleixner 	INTG(LOCAL_TIMER_VECTOR,	apic_timer_interrupt),
136636a7598SThomas Gleixner 	INTG(X86_PLATFORM_IPI_VECTOR,	x86_platform_ipi),
137636a7598SThomas Gleixner # ifdef CONFIG_HAVE_KVM
138636a7598SThomas Gleixner 	INTG(POSTED_INTR_VECTOR,	kvm_posted_intr_ipi),
139636a7598SThomas Gleixner 	INTG(POSTED_INTR_WAKEUP_VECTOR, kvm_posted_intr_wakeup_ipi),
140636a7598SThomas Gleixner 	INTG(POSTED_INTR_NESTED_VECTOR, kvm_posted_intr_nested_ipi),
141636a7598SThomas Gleixner # endif
142636a7598SThomas Gleixner # ifdef CONFIG_IRQ_WORK
143636a7598SThomas Gleixner 	INTG(IRQ_WORK_VECTOR,		irq_work_interrupt),
144636a7598SThomas Gleixner # endif
145151ad17fSAndrew Banman #ifdef CONFIG_X86_UV
146151ad17fSAndrew Banman 	INTG(UV_BAU_MESSAGE,		uv_bau_message_intr1),
147151ad17fSAndrew Banman #endif
148636a7598SThomas Gleixner 	INTG(SPURIOUS_APIC_VECTOR,	spurious_interrupt),
149636a7598SThomas Gleixner 	INTG(ERROR_APIC_VECTOR,		error_interrupt),
150636a7598SThomas Gleixner #endif
151636a7598SThomas Gleixner };
152636a7598SThomas Gleixner 
153433f8924SThomas Gleixner #ifdef CONFIG_X86_64
154433f8924SThomas Gleixner /*
155433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
156433f8924SThomas Gleixner  * stacks work only after cpu_init().
157433f8924SThomas Gleixner  */
158327867faSAndi Kleen static const __initconst struct idt_data early_pf_idts[] = {
159433f8924SThomas Gleixner 	INTG(X86_TRAP_PF,		page_fault),
160433f8924SThomas Gleixner };
1610a30908bSThomas Gleixner 
1620a30908bSThomas Gleixner /*
1630a30908bSThomas Gleixner  * Override for the debug_idt. Same as the default, but with interrupt
1640a30908bSThomas Gleixner  * stack set to DEFAULT_STACK (0). Required for NMI trap handling.
1650a30908bSThomas Gleixner  */
166327867faSAndi Kleen static const __initconst struct idt_data dbg_idts[] = {
1670a30908bSThomas Gleixner 	INTG(X86_TRAP_DB,	debug),
1680a30908bSThomas Gleixner };
169433f8924SThomas Gleixner #endif
170433f8924SThomas Gleixner 
171d8ed9d48SThomas Gleixner /* Must be page-aligned because the real IDT is used in a fixmap. */
172d8ed9d48SThomas Gleixner gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss;
173d8ed9d48SThomas Gleixner 
17416bc18d8SThomas Gleixner struct desc_ptr idt_descr __ro_after_init = {
17516bc18d8SThomas Gleixner 	.size		= (IDT_ENTRIES * 2 * sizeof(unsigned long)) - 1,
17616bc18d8SThomas Gleixner 	.address	= (unsigned long) idt_table,
17716bc18d8SThomas Gleixner };
17816bc18d8SThomas Gleixner 
179d8ed9d48SThomas Gleixner #ifdef CONFIG_X86_64
180d8ed9d48SThomas Gleixner /* No need to be aligned, but done to keep all IDTs defined the same way. */
181d8ed9d48SThomas Gleixner gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
182d8ed9d48SThomas Gleixner 
1830a30908bSThomas Gleixner /*
18490f6225fSThomas Gleixner  * The exceptions which use Interrupt stacks. They are setup after
18590f6225fSThomas Gleixner  * cpu_init() when the TSS has been initialized.
18690f6225fSThomas Gleixner  */
187327867faSAndi Kleen static const __initconst struct idt_data ist_idts[] = {
18832074269SThomas Gleixner 	ISTG(X86_TRAP_DB,	debug,		IST_INDEX_DB),
18932074269SThomas Gleixner 	ISTG(X86_TRAP_NMI,	nmi,		IST_INDEX_NMI),
19032074269SThomas Gleixner 	ISTG(X86_TRAP_DF,	double_fault,	IST_INDEX_DF),
19190f6225fSThomas Gleixner #ifdef CONFIG_X86_MCE
192fbaed278SLai Jiangshan 	ISTG(X86_TRAP_MC,	machine_check,	IST_INDEX_MCE),
19390f6225fSThomas Gleixner #endif
19490f6225fSThomas Gleixner };
19590f6225fSThomas Gleixner 
19690f6225fSThomas Gleixner /*
1970a30908bSThomas Gleixner  * Override for the debug_idt. Same as the default, but with interrupt
1980a30908bSThomas Gleixner  * stack set to DEFAULT_STACK (0). Required for NMI trap handling.
1990a30908bSThomas Gleixner  */
200d8ed9d48SThomas Gleixner const struct desc_ptr debug_idt_descr = {
201d8ed9d48SThomas Gleixner 	.size		= IDT_ENTRIES * 16 - 1,
202d8ed9d48SThomas Gleixner 	.address	= (unsigned long) debug_idt_table,
203d8ed9d48SThomas Gleixner };
204d8ed9d48SThomas Gleixner #endif
205e802a51eSThomas Gleixner 
2063318e974SThomas Gleixner static inline void idt_init_desc(gate_desc *gate, const struct idt_data *d)
2073318e974SThomas Gleixner {
2083318e974SThomas Gleixner 	unsigned long addr = (unsigned long) d->addr;
2093318e974SThomas Gleixner 
2103318e974SThomas Gleixner 	gate->offset_low	= (u16) addr;
2113318e974SThomas Gleixner 	gate->segment		= (u16) d->segment;
2123318e974SThomas Gleixner 	gate->bits		= d->bits;
2133318e974SThomas Gleixner 	gate->offset_middle	= (u16) (addr >> 16);
2143318e974SThomas Gleixner #ifdef CONFIG_X86_64
2153318e974SThomas Gleixner 	gate->offset_high	= (u32) (addr >> 32);
2163318e974SThomas Gleixner 	gate->reserved		= 0;
2173318e974SThomas Gleixner #endif
2183318e974SThomas Gleixner }
2193318e974SThomas Gleixner 
220db18da78SThomas Gleixner static void
221db18da78SThomas Gleixner idt_setup_from_table(gate_desc *idt, const struct idt_data *t, int size, bool sys)
2223318e974SThomas Gleixner {
2233318e974SThomas Gleixner 	gate_desc desc;
2243318e974SThomas Gleixner 
2253318e974SThomas Gleixner 	for (; size > 0; t++, size--) {
2263318e974SThomas Gleixner 		idt_init_desc(&desc, t);
2273318e974SThomas Gleixner 		write_idt_entry(idt, t->vector, &desc);
228db18da78SThomas Gleixner 		if (sys)
2297854f822SThomas Gleixner 			set_bit(t->vector, system_vectors);
2303318e974SThomas Gleixner 	}
2313318e974SThomas Gleixner }
2323318e974SThomas Gleixner 
233facaa3e3SThomas Gleixner static void set_intr_gate(unsigned int n, const void *addr)
234facaa3e3SThomas Gleixner {
235facaa3e3SThomas Gleixner 	struct idt_data data;
236facaa3e3SThomas Gleixner 
237facaa3e3SThomas Gleixner 	BUG_ON(n > 0xFF);
238facaa3e3SThomas Gleixner 
239facaa3e3SThomas Gleixner 	memset(&data, 0, sizeof(data));
240facaa3e3SThomas Gleixner 	data.vector	= n;
241facaa3e3SThomas Gleixner 	data.addr	= addr;
242facaa3e3SThomas Gleixner 	data.segment	= __KERNEL_CS;
243facaa3e3SThomas Gleixner 	data.bits.type	= GATE_INTERRUPT;
244facaa3e3SThomas Gleixner 	data.bits.p	= 1;
245facaa3e3SThomas Gleixner 
246facaa3e3SThomas Gleixner 	idt_setup_from_table(idt_table, &data, 1, false);
247facaa3e3SThomas Gleixner }
248facaa3e3SThomas Gleixner 
249e802a51eSThomas Gleixner /**
250433f8924SThomas Gleixner  * idt_setup_early_traps - Initialize the idt table with early traps
251433f8924SThomas Gleixner  *
252433f8924SThomas Gleixner  * On X8664 these traps do not use interrupt stacks as they can't work
253433f8924SThomas Gleixner  * before cpu_init() is invoked and sets up TSS. The IST variants are
254433f8924SThomas Gleixner  * installed after that.
255433f8924SThomas Gleixner  */
256433f8924SThomas Gleixner void __init idt_setup_early_traps(void)
257433f8924SThomas Gleixner {
258db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, early_idts, ARRAY_SIZE(early_idts),
259db18da78SThomas Gleixner 			     true);
260433f8924SThomas Gleixner 	load_idt(&idt_descr);
261433f8924SThomas Gleixner }
262433f8924SThomas Gleixner 
263b70543a0SThomas Gleixner /**
264b70543a0SThomas Gleixner  * idt_setup_traps - Initialize the idt table with default traps
265b70543a0SThomas Gleixner  */
266b70543a0SThomas Gleixner void __init idt_setup_traps(void)
267b70543a0SThomas Gleixner {
268db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, def_idts, ARRAY_SIZE(def_idts), true);
269b70543a0SThomas Gleixner }
270b70543a0SThomas Gleixner 
271433f8924SThomas Gleixner #ifdef CONFIG_X86_64
272433f8924SThomas Gleixner /**
273433f8924SThomas Gleixner  * idt_setup_early_pf - Initialize the idt table with early pagefault handler
274433f8924SThomas Gleixner  *
275433f8924SThomas Gleixner  * On X8664 this does not use interrupt stacks as they can't work before
276433f8924SThomas Gleixner  * cpu_init() is invoked and sets up TSS. The IST variant is installed
277433f8924SThomas Gleixner  * after that.
278433f8924SThomas Gleixner  *
279433f8924SThomas Gleixner  * FIXME: Why is 32bit and 64bit installing the PF handler at different
280433f8924SThomas Gleixner  * places in the early setup code?
281433f8924SThomas Gleixner  */
282433f8924SThomas Gleixner void __init idt_setup_early_pf(void)
283433f8924SThomas Gleixner {
284433f8924SThomas Gleixner 	idt_setup_from_table(idt_table, early_pf_idts,
285db18da78SThomas Gleixner 			     ARRAY_SIZE(early_pf_idts), true);
286433f8924SThomas Gleixner }
2870a30908bSThomas Gleixner 
2880a30908bSThomas Gleixner /**
28990f6225fSThomas Gleixner  * idt_setup_ist_traps - Initialize the idt table with traps using IST
29090f6225fSThomas Gleixner  */
29190f6225fSThomas Gleixner void __init idt_setup_ist_traps(void)
29290f6225fSThomas Gleixner {
293db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, ist_idts, ARRAY_SIZE(ist_idts), true);
29490f6225fSThomas Gleixner }
29590f6225fSThomas Gleixner 
29690f6225fSThomas Gleixner /**
2970a30908bSThomas Gleixner  * idt_setup_debugidt_traps - Initialize the debug idt table with debug traps
2980a30908bSThomas Gleixner  */
2990a30908bSThomas Gleixner void __init idt_setup_debugidt_traps(void)
3000a30908bSThomas Gleixner {
3010a30908bSThomas Gleixner 	memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
3020a30908bSThomas Gleixner 
303db18da78SThomas Gleixner 	idt_setup_from_table(debug_idt_table, dbg_idts, ARRAY_SIZE(dbg_idts), false);
3040a30908bSThomas Gleixner }
305433f8924SThomas Gleixner #endif
306433f8924SThomas Gleixner 
307433f8924SThomas Gleixner /**
308636a7598SThomas Gleixner  * idt_setup_apic_and_irq_gates - Setup APIC/SMP and normal interrupt gates
309636a7598SThomas Gleixner  */
310636a7598SThomas Gleixner void __init idt_setup_apic_and_irq_gates(void)
311636a7598SThomas Gleixner {
312dc20b2d5SThomas Gleixner 	int i = FIRST_EXTERNAL_VECTOR;
313dc20b2d5SThomas Gleixner 	void *entry;
314dc20b2d5SThomas Gleixner 
315db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, apic_idts, ARRAY_SIZE(apic_idts), true);
316dc20b2d5SThomas Gleixner 
3177854f822SThomas Gleixner 	for_each_clear_bit_from(i, system_vectors, FIRST_SYSTEM_VECTOR) {
318dc20b2d5SThomas Gleixner 		entry = irq_entries_start + 8 * (i - FIRST_EXTERNAL_VECTOR);
319dc20b2d5SThomas Gleixner 		set_intr_gate(i, entry);
320dc20b2d5SThomas Gleixner 	}
321dc20b2d5SThomas Gleixner 
322dc20b2d5SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
32333662812SDou Liyang 	for_each_clear_bit_from(i, system_vectors, NR_VECTORS) {
3241f1fbc70SVitaly Kuznetsov 		/*
3251f1fbc70SVitaly Kuznetsov 		 * Don't set the non assigned system vectors in the
3261f1fbc70SVitaly Kuznetsov 		 * system_vectors bitmap. Otherwise they show up in
3271f1fbc70SVitaly Kuznetsov 		 * /proc/interrupts.
3281f1fbc70SVitaly Kuznetsov 		 */
329f8a8fe61SThomas Gleixner 		entry = spurious_entries_start + 8 * (i - FIRST_SYSTEM_VECTOR);
330f8a8fe61SThomas Gleixner 		set_intr_gate(i, entry);
331dc20b2d5SThomas Gleixner 	}
33233662812SDou Liyang #endif
33306184325SVitaly Kuznetsov 	idt_setup_done = true;
334636a7598SThomas Gleixner }
335636a7598SThomas Gleixner 
336636a7598SThomas Gleixner /**
337588787fdSThomas Gleixner  * idt_setup_early_handler - Initializes the idt table with early handlers
338588787fdSThomas Gleixner  */
339588787fdSThomas Gleixner void __init idt_setup_early_handler(void)
340588787fdSThomas Gleixner {
341588787fdSThomas Gleixner 	int i;
342588787fdSThomas Gleixner 
343588787fdSThomas Gleixner 	for (i = 0; i < NUM_EXCEPTION_VECTORS; i++)
344588787fdSThomas Gleixner 		set_intr_gate(i, early_idt_handler_array[i]);
34587e81786SThomas Gleixner #ifdef CONFIG_X86_32
34687e81786SThomas Gleixner 	for ( ; i < NR_VECTORS; i++)
34787e81786SThomas Gleixner 		set_intr_gate(i, early_ignore_irq);
34887e81786SThomas Gleixner #endif
349588787fdSThomas Gleixner 	load_idt(&idt_descr);
350588787fdSThomas Gleixner }
351588787fdSThomas Gleixner 
352588787fdSThomas Gleixner /**
353e802a51eSThomas Gleixner  * idt_invalidate - Invalidate interrupt descriptor table
354e802a51eSThomas Gleixner  * @addr:	The virtual address of the 'invalid' IDT
355e802a51eSThomas Gleixner  */
356e802a51eSThomas Gleixner void idt_invalidate(void *addr)
357e802a51eSThomas Gleixner {
358e802a51eSThomas Gleixner 	struct desc_ptr idt = { .address = (unsigned long) addr, .size = 0 };
359e802a51eSThomas Gleixner 
360e802a51eSThomas Gleixner 	load_idt(&idt);
361e802a51eSThomas Gleixner }
362db18da78SThomas Gleixner 
36306184325SVitaly Kuznetsov void __init alloc_intr_gate(unsigned int n, const void *addr)
364db18da78SThomas Gleixner {
36506184325SVitaly Kuznetsov 	if (WARN_ON(n < FIRST_SYSTEM_VECTOR))
36606184325SVitaly Kuznetsov 		return;
36706184325SVitaly Kuznetsov 
36806184325SVitaly Kuznetsov 	if (WARN_ON(idt_setup_done))
36906184325SVitaly Kuznetsov 		return;
37006184325SVitaly Kuznetsov 
37106184325SVitaly Kuznetsov 	if (!WARN_ON(test_and_set_bit(n, system_vectors)))
372db18da78SThomas Gleixner 		set_intr_gate(n, addr);
373db18da78SThomas Gleixner }
374