xref: /linux/arch/x86/kernel/idt.c (revision 00229a54300108502f68c8777faca2d13f805f1a)
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 
7*00229a54SThomas Gleixner #include <asm/cpu_entry_area.h>
83318e974SThomas Gleixner #include <asm/traps.h>
93318e974SThomas Gleixner #include <asm/proto.h>
10d8ed9d48SThomas Gleixner #include <asm/desc.h>
11447ae316SNicolai Stange #include <asm/hw_irq.h>
12d8ed9d48SThomas Gleixner 
133318e974SThomas Gleixner struct idt_data {
143318e974SThomas Gleixner 	unsigned int	vector;
153318e974SThomas Gleixner 	unsigned int	segment;
163318e974SThomas Gleixner 	struct idt_bits	bits;
173318e974SThomas Gleixner 	const void	*addr;
183318e974SThomas Gleixner };
193318e974SThomas Gleixner 
203318e974SThomas Gleixner #define DPL0		0x0
213318e974SThomas Gleixner #define DPL3		0x3
223318e974SThomas Gleixner 
233318e974SThomas Gleixner #define DEFAULT_STACK	0
243318e974SThomas Gleixner 
253318e974SThomas Gleixner #define G(_vector, _addr, _ist, _type, _dpl, _segment)	\
263318e974SThomas Gleixner 	{						\
273318e974SThomas Gleixner 		.vector		= _vector,		\
283318e974SThomas Gleixner 		.bits.ist	= _ist,			\
293318e974SThomas Gleixner 		.bits.type	= _type,		\
303318e974SThomas Gleixner 		.bits.dpl	= _dpl,			\
313318e974SThomas Gleixner 		.bits.p		= 1,			\
323318e974SThomas Gleixner 		.addr		= _addr,		\
333318e974SThomas Gleixner 		.segment	= _segment,		\
343318e974SThomas Gleixner 	}
353318e974SThomas Gleixner 
363318e974SThomas Gleixner /* Interrupt gate */
373318e974SThomas Gleixner #define INTG(_vector, _addr)				\
383318e974SThomas Gleixner 	G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL0, __KERNEL_CS)
393318e974SThomas Gleixner 
403318e974SThomas Gleixner /* System interrupt gate */
413318e974SThomas Gleixner #define SYSG(_vector, _addr)				\
423318e974SThomas Gleixner 	G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL3, __KERNEL_CS)
433318e974SThomas Gleixner 
448f34c5b5SThomas Gleixner /*
458f34c5b5SThomas Gleixner  * Interrupt gate with interrupt stack. The _ist index is the index in
468f34c5b5SThomas Gleixner  * the tss.ist[] array, but for the descriptor it needs to start at 1.
478f34c5b5SThomas Gleixner  */
483318e974SThomas Gleixner #define ISTG(_vector, _addr, _ist)			\
498f34c5b5SThomas Gleixner 	G(_vector, _addr, _ist + 1, GATE_INTERRUPT, DPL0, __KERNEL_CS)
503318e974SThomas Gleixner 
513318e974SThomas Gleixner /* Task gate */
523318e974SThomas Gleixner #define TSKG(_vector, _gdt)				\
533318e974SThomas Gleixner 	G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3)
543318e974SThomas Gleixner 
555a2bafcaSThomas Gleixner #define IDT_TABLE_SIZE		(IDT_ENTRIES * sizeof(gate_desc))
5606184325SVitaly Kuznetsov 
5706184325SVitaly Kuznetsov static bool idt_setup_done __initdata;
5806184325SVitaly Kuznetsov 
59433f8924SThomas Gleixner /*
60433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
61433f8924SThomas Gleixner  * stacks work only after cpu_init().
62433f8924SThomas Gleixner  */
63327867faSAndi Kleen static const __initconst struct idt_data early_idts[] = {
642bbc68f8SThomas Gleixner 	INTG(X86_TRAP_DB,		asm_exc_debug),
658edd7e37SThomas Gleixner 	SYSG(X86_TRAP_BP,		asm_exc_int3),
6694438af4SThomas Gleixner 
67433f8924SThomas Gleixner #ifdef CONFIG_X86_32
6894438af4SThomas Gleixner 	/*
6994438af4SThomas Gleixner 	 * Not possible on 64-bit. See idt_setup_early_pf() for details.
7094438af4SThomas Gleixner 	 */
7191eeafeaSThomas Gleixner 	INTG(X86_TRAP_PF,		asm_exc_page_fault),
72433f8924SThomas Gleixner #endif
73433f8924SThomas Gleixner };
74433f8924SThomas Gleixner 
75b70543a0SThomas Gleixner /*
76b70543a0SThomas Gleixner  * The default IDT entries which are set up in trap_init() before
77b70543a0SThomas Gleixner  * cpu_init() is invoked. Interrupt stacks cannot be used at that point and
78b70543a0SThomas Gleixner  * the traps which use them are reinitialized with IST after cpu_init() has
79b70543a0SThomas Gleixner  * set up TSS.
80b70543a0SThomas Gleixner  */
81327867faSAndi Kleen static const __initconst struct idt_data def_idts[] = {
829d06c402SThomas Gleixner 	INTG(X86_TRAP_DE,		asm_exc_divide_error),
836271fef0SThomas Gleixner 	INTG(X86_TRAP_NMI,		asm_exc_nmi),
8458d9c81fSThomas Gleixner 	INTG(X86_TRAP_BR,		asm_exc_bounds),
8549893c5cSThomas Gleixner 	INTG(X86_TRAP_UD,		asm_exc_invalid_op),
86866ae2ccSThomas Gleixner 	INTG(X86_TRAP_NM,		asm_exc_device_not_available),
87f95658fdSThomas Gleixner 	INTG(X86_TRAP_OLD_MF,		asm_exc_coproc_segment_overrun),
8897b3d290SThomas Gleixner 	INTG(X86_TRAP_TS,		asm_exc_invalid_tss),
8999a3fb8dSThomas Gleixner 	INTG(X86_TRAP_NP,		asm_exc_segment_not_present),
90fd9689bfSThomas Gleixner 	INTG(X86_TRAP_SS,		asm_exc_stack_segment),
91be4c11afSThomas Gleixner 	INTG(X86_TRAP_GP,		asm_exc_general_protection),
92dad7106fSThomas Gleixner 	INTG(X86_TRAP_SPURIOUS,		asm_exc_spurious_interrupt_bug),
9314a8bd2aSThomas Gleixner 	INTG(X86_TRAP_MF,		asm_exc_coprocessor_error),
94436608bbSThomas Gleixner 	INTG(X86_TRAP_AC,		asm_exc_alignment_check),
9548227e21SThomas Gleixner 	INTG(X86_TRAP_XF,		asm_exc_simd_coprocessor_error),
96b70543a0SThomas Gleixner 
97b70543a0SThomas Gleixner #ifdef CONFIG_X86_32
98b70543a0SThomas Gleixner 	TSKG(X86_TRAP_DF,		GDT_ENTRY_DOUBLEFAULT_TSS),
99b70543a0SThomas Gleixner #else
100c29c775aSThomas Gleixner 	INTG(X86_TRAP_DF,		asm_exc_double_fault),
101b70543a0SThomas Gleixner #endif
1022bbc68f8SThomas Gleixner 	INTG(X86_TRAP_DB,		asm_exc_debug),
103b70543a0SThomas Gleixner 
104b70543a0SThomas Gleixner #ifdef CONFIG_X86_MCE
1058cd501c1SThomas Gleixner 	INTG(X86_TRAP_MC,		asm_exc_machine_check),
106b70543a0SThomas Gleixner #endif
107b70543a0SThomas Gleixner 
1084b6b9111SThomas Gleixner 	SYSG(X86_TRAP_OF,		asm_exc_overflow),
109b70543a0SThomas Gleixner #if defined(CONFIG_IA32_EMULATION)
110b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_compat),
111b70543a0SThomas Gleixner #elif defined(CONFIG_X86_32)
112b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_32),
113b70543a0SThomas Gleixner #endif
114b70543a0SThomas Gleixner };
115b70543a0SThomas Gleixner 
116636a7598SThomas Gleixner /*
117636a7598SThomas Gleixner  * The APIC and SMP idt entries
118636a7598SThomas Gleixner  */
119327867faSAndi Kleen static const __initconst struct idt_data apic_idts[] = {
120636a7598SThomas Gleixner #ifdef CONFIG_SMP
12113cad985SThomas Gleixner 	INTG(RESCHEDULE_VECTOR,			asm_sysvec_reschedule_ipi),
122582f9191SThomas Gleixner 	INTG(CALL_FUNCTION_VECTOR,		asm_sysvec_call_function),
123582f9191SThomas Gleixner 	INTG(CALL_FUNCTION_SINGLE_VECTOR,	asm_sysvec_call_function_single),
124582f9191SThomas Gleixner 	INTG(IRQ_MOVE_CLEANUP_VECTOR,		asm_sysvec_irq_move_cleanup),
125582f9191SThomas Gleixner 	INTG(REBOOT_VECTOR,			asm_sysvec_reboot),
126636a7598SThomas Gleixner #endif
127636a7598SThomas Gleixner 
128636a7598SThomas Gleixner #ifdef CONFIG_X86_THERMAL_VECTOR
129720909a7SThomas Gleixner 	INTG(THERMAL_APIC_VECTOR,		asm_sysvec_thermal),
130636a7598SThomas Gleixner #endif
131636a7598SThomas Gleixner 
132636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_THRESHOLD
133720909a7SThomas Gleixner 	INTG(THRESHOLD_APIC_VECTOR,		asm_sysvec_threshold),
134636a7598SThomas Gleixner #endif
135636a7598SThomas Gleixner 
136636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_AMD
137720909a7SThomas Gleixner 	INTG(DEFERRED_ERROR_VECTOR,		asm_sysvec_deferred_error),
138636a7598SThomas Gleixner #endif
139636a7598SThomas Gleixner 
140636a7598SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
141db0338eeSThomas Gleixner 	INTG(LOCAL_TIMER_VECTOR,		asm_sysvec_apic_timer_interrupt),
142db0338eeSThomas Gleixner 	INTG(X86_PLATFORM_IPI_VECTOR,		asm_sysvec_x86_platform_ipi),
143636a7598SThomas Gleixner # ifdef CONFIG_HAVE_KVM
1449c3b1f49SThomas Gleixner 	INTG(POSTED_INTR_VECTOR,		asm_sysvec_kvm_posted_intr_ipi),
1459c3b1f49SThomas Gleixner 	INTG(POSTED_INTR_WAKEUP_VECTOR,		asm_sysvec_kvm_posted_intr_wakeup_ipi),
1469c3b1f49SThomas Gleixner 	INTG(POSTED_INTR_NESTED_VECTOR,		asm_sysvec_kvm_posted_intr_nested_ipi),
147636a7598SThomas Gleixner # endif
148636a7598SThomas Gleixner # ifdef CONFIG_IRQ_WORK
149720909a7SThomas Gleixner 	INTG(IRQ_WORK_VECTOR,			asm_sysvec_irq_work),
150636a7598SThomas Gleixner # endif
151151ad17fSAndrew Banman # ifdef CONFIG_X86_UV
152720909a7SThomas Gleixner 	INTG(UV_BAU_MESSAGE,			asm_sysvec_uv_bau_message),
153151ad17fSAndrew Banman # endif
154db0338eeSThomas Gleixner 	INTG(SPURIOUS_APIC_VECTOR,		asm_sysvec_spurious_apic_interrupt),
155db0338eeSThomas Gleixner 	INTG(ERROR_APIC_VECTOR,			asm_sysvec_error_interrupt),
156636a7598SThomas Gleixner #endif
157636a7598SThomas Gleixner };
158636a7598SThomas Gleixner 
159433f8924SThomas Gleixner #ifdef CONFIG_X86_64
160433f8924SThomas Gleixner /*
161433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
162433f8924SThomas Gleixner  * stacks work only after cpu_init().
163433f8924SThomas Gleixner  */
164327867faSAndi Kleen static const __initconst struct idt_data early_pf_idts[] = {
16591eeafeaSThomas Gleixner 	INTG(X86_TRAP_PF,		asm_exc_page_fault),
166433f8924SThomas Gleixner };
167433f8924SThomas Gleixner #endif
168433f8924SThomas Gleixner 
169d8ed9d48SThomas Gleixner /* Must be page-aligned because the real IDT is used in a fixmap. */
170d8ed9d48SThomas Gleixner gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss;
171d8ed9d48SThomas Gleixner 
17216bc18d8SThomas Gleixner struct desc_ptr idt_descr __ro_after_init = {
1735a2bafcaSThomas Gleixner 	.size		= IDT_TABLE_SIZE - 1,
17416bc18d8SThomas Gleixner 	.address	= (unsigned long) idt_table,
17516bc18d8SThomas Gleixner };
17616bc18d8SThomas Gleixner 
177d8ed9d48SThomas Gleixner #ifdef CONFIG_X86_64
1780a30908bSThomas Gleixner /*
17990f6225fSThomas Gleixner  * The exceptions which use Interrupt stacks. They are setup after
18090f6225fSThomas Gleixner  * cpu_init() when the TSS has been initialized.
18190f6225fSThomas Gleixner  */
182327867faSAndi Kleen static const __initconst struct idt_data ist_idts[] = {
1832bbc68f8SThomas Gleixner 	ISTG(X86_TRAP_DB,	asm_exc_debug,		IST_INDEX_DB),
1846271fef0SThomas Gleixner 	ISTG(X86_TRAP_NMI,	asm_exc_nmi,		IST_INDEX_NMI),
185c29c775aSThomas Gleixner 	ISTG(X86_TRAP_DF,	asm_exc_double_fault,	IST_INDEX_DF),
18690f6225fSThomas Gleixner #ifdef CONFIG_X86_MCE
1878cd501c1SThomas Gleixner 	ISTG(X86_TRAP_MC,	asm_exc_machine_check,	IST_INDEX_MCE),
18890f6225fSThomas Gleixner #endif
18990f6225fSThomas Gleixner };
190d8ed9d48SThomas Gleixner #endif
191e802a51eSThomas Gleixner 
1923318e974SThomas Gleixner static inline void idt_init_desc(gate_desc *gate, const struct idt_data *d)
1933318e974SThomas Gleixner {
1943318e974SThomas Gleixner 	unsigned long addr = (unsigned long) d->addr;
1953318e974SThomas Gleixner 
1963318e974SThomas Gleixner 	gate->offset_low	= (u16) addr;
1973318e974SThomas Gleixner 	gate->segment		= (u16) d->segment;
1983318e974SThomas Gleixner 	gate->bits		= d->bits;
1993318e974SThomas Gleixner 	gate->offset_middle	= (u16) (addr >> 16);
2003318e974SThomas Gleixner #ifdef CONFIG_X86_64
2013318e974SThomas Gleixner 	gate->offset_high	= (u32) (addr >> 32);
2023318e974SThomas Gleixner 	gate->reserved		= 0;
2033318e974SThomas Gleixner #endif
2043318e974SThomas Gleixner }
2053318e974SThomas Gleixner 
206bdf5bde8SThomas Gleixner static __init void
207db18da78SThomas Gleixner idt_setup_from_table(gate_desc *idt, const struct idt_data *t, int size, bool sys)
2083318e974SThomas Gleixner {
2093318e974SThomas Gleixner 	gate_desc desc;
2103318e974SThomas Gleixner 
2113318e974SThomas Gleixner 	for (; size > 0; t++, size--) {
2123318e974SThomas Gleixner 		idt_init_desc(&desc, t);
2133318e974SThomas Gleixner 		write_idt_entry(idt, t->vector, &desc);
214db18da78SThomas Gleixner 		if (sys)
2157854f822SThomas Gleixner 			set_bit(t->vector, system_vectors);
2163318e974SThomas Gleixner 	}
2173318e974SThomas Gleixner }
2183318e974SThomas Gleixner 
219bdf5bde8SThomas Gleixner static __init void set_intr_gate(unsigned int n, const void *addr)
220facaa3e3SThomas Gleixner {
221facaa3e3SThomas Gleixner 	struct idt_data data;
222facaa3e3SThomas Gleixner 
223facaa3e3SThomas Gleixner 	BUG_ON(n > 0xFF);
224facaa3e3SThomas Gleixner 
225facaa3e3SThomas Gleixner 	memset(&data, 0, sizeof(data));
226facaa3e3SThomas Gleixner 	data.vector	= n;
227facaa3e3SThomas Gleixner 	data.addr	= addr;
228facaa3e3SThomas Gleixner 	data.segment	= __KERNEL_CS;
229facaa3e3SThomas Gleixner 	data.bits.type	= GATE_INTERRUPT;
230facaa3e3SThomas Gleixner 	data.bits.p	= 1;
231facaa3e3SThomas Gleixner 
232facaa3e3SThomas Gleixner 	idt_setup_from_table(idt_table, &data, 1, false);
233facaa3e3SThomas Gleixner }
234facaa3e3SThomas Gleixner 
235e802a51eSThomas Gleixner /**
236433f8924SThomas Gleixner  * idt_setup_early_traps - Initialize the idt table with early traps
237433f8924SThomas Gleixner  *
238433f8924SThomas Gleixner  * On X8664 these traps do not use interrupt stacks as they can't work
239433f8924SThomas Gleixner  * before cpu_init() is invoked and sets up TSS. The IST variants are
240433f8924SThomas Gleixner  * installed after that.
241433f8924SThomas Gleixner  */
242433f8924SThomas Gleixner void __init idt_setup_early_traps(void)
243433f8924SThomas Gleixner {
244db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, early_idts, ARRAY_SIZE(early_idts),
245db18da78SThomas Gleixner 			     true);
246433f8924SThomas Gleixner 	load_idt(&idt_descr);
247433f8924SThomas Gleixner }
248433f8924SThomas Gleixner 
249b70543a0SThomas Gleixner /**
250b70543a0SThomas Gleixner  * idt_setup_traps - Initialize the idt table with default traps
251b70543a0SThomas Gleixner  */
252b70543a0SThomas Gleixner void __init idt_setup_traps(void)
253b70543a0SThomas Gleixner {
254db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, def_idts, ARRAY_SIZE(def_idts), true);
255b70543a0SThomas Gleixner }
256b70543a0SThomas Gleixner 
257433f8924SThomas Gleixner #ifdef CONFIG_X86_64
258433f8924SThomas Gleixner /**
259433f8924SThomas Gleixner  * idt_setup_early_pf - Initialize the idt table with early pagefault handler
260433f8924SThomas Gleixner  *
261433f8924SThomas Gleixner  * On X8664 this does not use interrupt stacks as they can't work before
262433f8924SThomas Gleixner  * cpu_init() is invoked and sets up TSS. The IST variant is installed
263433f8924SThomas Gleixner  * after that.
264433f8924SThomas Gleixner  *
26594438af4SThomas Gleixner  * Note, that X86_64 cannot install the real #PF handler in
26694438af4SThomas Gleixner  * idt_setup_early_traps() because the memory intialization needs the #PF
26794438af4SThomas Gleixner  * handler from the early_idt_handler_array to initialize the early page
26894438af4SThomas Gleixner  * tables.
269433f8924SThomas Gleixner  */
270433f8924SThomas Gleixner void __init idt_setup_early_pf(void)
271433f8924SThomas Gleixner {
272433f8924SThomas Gleixner 	idt_setup_from_table(idt_table, early_pf_idts,
273db18da78SThomas Gleixner 			     ARRAY_SIZE(early_pf_idts), true);
274433f8924SThomas Gleixner }
2750a30908bSThomas Gleixner 
2760a30908bSThomas Gleixner /**
27790f6225fSThomas Gleixner  * idt_setup_ist_traps - Initialize the idt table with traps using IST
27890f6225fSThomas Gleixner  */
27990f6225fSThomas Gleixner void __init idt_setup_ist_traps(void)
28090f6225fSThomas Gleixner {
281db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, ist_idts, ARRAY_SIZE(ist_idts), true);
28290f6225fSThomas Gleixner }
283433f8924SThomas Gleixner #endif
284433f8924SThomas Gleixner 
285*00229a54SThomas Gleixner static void __init idt_map_in_cea(void)
286*00229a54SThomas Gleixner {
287*00229a54SThomas Gleixner 	/*
288*00229a54SThomas Gleixner 	 * Set the IDT descriptor to a fixed read-only location in the cpu
289*00229a54SThomas Gleixner 	 * entry area, so that the "sidt" instruction will not leak the
290*00229a54SThomas Gleixner 	 * location of the kernel, and to defend the IDT against arbitrary
291*00229a54SThomas Gleixner 	 * memory write vulnerabilities.
292*00229a54SThomas Gleixner 	 */
293*00229a54SThomas Gleixner 	cea_set_pte(CPU_ENTRY_AREA_RO_IDT_VADDR, __pa_symbol(idt_table),
294*00229a54SThomas Gleixner 		    PAGE_KERNEL_RO);
295*00229a54SThomas Gleixner 	idt_descr.address = CPU_ENTRY_AREA_RO_IDT;
296*00229a54SThomas Gleixner }
297*00229a54SThomas Gleixner 
298433f8924SThomas Gleixner /**
299636a7598SThomas Gleixner  * idt_setup_apic_and_irq_gates - Setup APIC/SMP and normal interrupt gates
300636a7598SThomas Gleixner  */
301636a7598SThomas Gleixner void __init idt_setup_apic_and_irq_gates(void)
302636a7598SThomas Gleixner {
303dc20b2d5SThomas Gleixner 	int i = FIRST_EXTERNAL_VECTOR;
304dc20b2d5SThomas Gleixner 	void *entry;
305dc20b2d5SThomas Gleixner 
306db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, apic_idts, ARRAY_SIZE(apic_idts), true);
307dc20b2d5SThomas Gleixner 
3087854f822SThomas Gleixner 	for_each_clear_bit_from(i, system_vectors, FIRST_SYSTEM_VECTOR) {
309dc20b2d5SThomas Gleixner 		entry = irq_entries_start + 8 * (i - FIRST_EXTERNAL_VECTOR);
310dc20b2d5SThomas Gleixner 		set_intr_gate(i, entry);
311dc20b2d5SThomas Gleixner 	}
312dc20b2d5SThomas Gleixner 
313dc20b2d5SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
31433662812SDou Liyang 	for_each_clear_bit_from(i, system_vectors, NR_VECTORS) {
3151f1fbc70SVitaly Kuznetsov 		/*
3161f1fbc70SVitaly Kuznetsov 		 * Don't set the non assigned system vectors in the
3171f1fbc70SVitaly Kuznetsov 		 * system_vectors bitmap. Otherwise they show up in
3181f1fbc70SVitaly Kuznetsov 		 * /proc/interrupts.
3191f1fbc70SVitaly Kuznetsov 		 */
320f8a8fe61SThomas Gleixner 		entry = spurious_entries_start + 8 * (i - FIRST_SYSTEM_VECTOR);
321f8a8fe61SThomas Gleixner 		set_intr_gate(i, entry);
322dc20b2d5SThomas Gleixner 	}
32333662812SDou Liyang #endif
324*00229a54SThomas Gleixner 	/* Map IDT into CPU entry area and reload it. */
325*00229a54SThomas Gleixner 	idt_map_in_cea();
326*00229a54SThomas Gleixner 	load_idt(&idt_descr);
327*00229a54SThomas Gleixner 
32806184325SVitaly Kuznetsov 	idt_setup_done = true;
329636a7598SThomas Gleixner }
330636a7598SThomas Gleixner 
331636a7598SThomas Gleixner /**
332588787fdSThomas Gleixner  * idt_setup_early_handler - Initializes the idt table with early handlers
333588787fdSThomas Gleixner  */
334588787fdSThomas Gleixner void __init idt_setup_early_handler(void)
335588787fdSThomas Gleixner {
336588787fdSThomas Gleixner 	int i;
337588787fdSThomas Gleixner 
338588787fdSThomas Gleixner 	for (i = 0; i < NUM_EXCEPTION_VECTORS; i++)
339588787fdSThomas Gleixner 		set_intr_gate(i, early_idt_handler_array[i]);
34087e81786SThomas Gleixner #ifdef CONFIG_X86_32
34187e81786SThomas Gleixner 	for ( ; i < NR_VECTORS; i++)
34287e81786SThomas Gleixner 		set_intr_gate(i, early_ignore_irq);
34387e81786SThomas Gleixner #endif
344588787fdSThomas Gleixner 	load_idt(&idt_descr);
345588787fdSThomas Gleixner }
346588787fdSThomas Gleixner 
347588787fdSThomas Gleixner /**
348e802a51eSThomas Gleixner  * idt_invalidate - Invalidate interrupt descriptor table
349e802a51eSThomas Gleixner  * @addr:	The virtual address of the 'invalid' IDT
350e802a51eSThomas Gleixner  */
351e802a51eSThomas Gleixner void idt_invalidate(void *addr)
352e802a51eSThomas Gleixner {
353e802a51eSThomas Gleixner 	struct desc_ptr idt = { .address = (unsigned long) addr, .size = 0 };
354e802a51eSThomas Gleixner 
355e802a51eSThomas Gleixner 	load_idt(&idt);
356e802a51eSThomas Gleixner }
357db18da78SThomas Gleixner 
35806184325SVitaly Kuznetsov void __init alloc_intr_gate(unsigned int n, const void *addr)
359db18da78SThomas Gleixner {
36006184325SVitaly Kuznetsov 	if (WARN_ON(n < FIRST_SYSTEM_VECTOR))
36106184325SVitaly Kuznetsov 		return;
36206184325SVitaly Kuznetsov 
36306184325SVitaly Kuznetsov 	if (WARN_ON(idt_setup_done))
36406184325SVitaly Kuznetsov 		return;
36506184325SVitaly Kuznetsov 
36606184325SVitaly Kuznetsov 	if (!WARN_ON(test_and_set_bit(n, system_vectors)))
367db18da78SThomas Gleixner 		set_intr_gate(n, addr);
368db18da78SThomas Gleixner }
369