xref: /linux/arch/x86/kernel/idt.c (revision 3207426925d2b4da390be8068df1d1c2b36e5918)
1d8ed9d48SThomas Gleixner /*
2d8ed9d48SThomas Gleixner  * Interrupt descriptor table related code
3d8ed9d48SThomas Gleixner  *
4d8ed9d48SThomas Gleixner  * This file is licensed under the GPL V2
5d8ed9d48SThomas Gleixner  */
6d8ed9d48SThomas Gleixner #include <linux/interrupt.h>
7d8ed9d48SThomas Gleixner 
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 
55433f8924SThomas Gleixner /*
56433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
57433f8924SThomas Gleixner  * stacks work only after cpu_init().
58433f8924SThomas Gleixner  */
59327867faSAndi Kleen static const __initconst struct idt_data early_idts[] = {
60433f8924SThomas Gleixner 	INTG(X86_TRAP_DB,		debug),
61433f8924SThomas Gleixner 	SYSG(X86_TRAP_BP,		int3),
62433f8924SThomas Gleixner #ifdef CONFIG_X86_32
63433f8924SThomas Gleixner 	INTG(X86_TRAP_PF,		page_fault),
64433f8924SThomas Gleixner #endif
65433f8924SThomas Gleixner };
66433f8924SThomas Gleixner 
67b70543a0SThomas Gleixner /*
68b70543a0SThomas Gleixner  * The default IDT entries which are set up in trap_init() before
69b70543a0SThomas Gleixner  * cpu_init() is invoked. Interrupt stacks cannot be used at that point and
70b70543a0SThomas Gleixner  * the traps which use them are reinitialized with IST after cpu_init() has
71b70543a0SThomas Gleixner  * set up TSS.
72b70543a0SThomas Gleixner  */
73327867faSAndi Kleen static const __initconst struct idt_data def_idts[] = {
74b70543a0SThomas Gleixner 	INTG(X86_TRAP_DE,		divide_error),
75b70543a0SThomas Gleixner 	INTG(X86_TRAP_NMI,		nmi),
76b70543a0SThomas Gleixner 	INTG(X86_TRAP_BR,		bounds),
77b70543a0SThomas Gleixner 	INTG(X86_TRAP_UD,		invalid_op),
78b70543a0SThomas Gleixner 	INTG(X86_TRAP_NM,		device_not_available),
79b70543a0SThomas Gleixner 	INTG(X86_TRAP_OLD_MF,		coprocessor_segment_overrun),
80b70543a0SThomas Gleixner 	INTG(X86_TRAP_TS,		invalid_TSS),
81b70543a0SThomas Gleixner 	INTG(X86_TRAP_NP,		segment_not_present),
82b70543a0SThomas Gleixner 	INTG(X86_TRAP_SS,		stack_segment),
83b70543a0SThomas Gleixner 	INTG(X86_TRAP_GP,		general_protection),
84b70543a0SThomas Gleixner 	INTG(X86_TRAP_SPURIOUS,		spurious_interrupt_bug),
85b70543a0SThomas Gleixner 	INTG(X86_TRAP_MF,		coprocessor_error),
86b70543a0SThomas Gleixner 	INTG(X86_TRAP_AC,		alignment_check),
87b70543a0SThomas Gleixner 	INTG(X86_TRAP_XF,		simd_coprocessor_error),
88b70543a0SThomas Gleixner 
89b70543a0SThomas Gleixner #ifdef CONFIG_X86_32
90b70543a0SThomas Gleixner 	TSKG(X86_TRAP_DF,		GDT_ENTRY_DOUBLEFAULT_TSS),
91b70543a0SThomas Gleixner #else
92b70543a0SThomas Gleixner 	INTG(X86_TRAP_DF,		double_fault),
93b70543a0SThomas Gleixner #endif
94b70543a0SThomas Gleixner 	INTG(X86_TRAP_DB,		debug),
95b70543a0SThomas Gleixner 
96b70543a0SThomas Gleixner #ifdef CONFIG_X86_MCE
97b70543a0SThomas Gleixner 	INTG(X86_TRAP_MC,		&machine_check),
98b70543a0SThomas Gleixner #endif
99b70543a0SThomas Gleixner 
100b70543a0SThomas Gleixner 	SYSG(X86_TRAP_OF,		overflow),
101b70543a0SThomas Gleixner #if defined(CONFIG_IA32_EMULATION)
102b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_compat),
103b70543a0SThomas Gleixner #elif defined(CONFIG_X86_32)
104b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_32),
105b70543a0SThomas Gleixner #endif
106b70543a0SThomas Gleixner };
107b70543a0SThomas Gleixner 
108636a7598SThomas Gleixner /*
109636a7598SThomas Gleixner  * The APIC and SMP idt entries
110636a7598SThomas Gleixner  */
111327867faSAndi Kleen static const __initconst struct idt_data apic_idts[] = {
112636a7598SThomas Gleixner #ifdef CONFIG_SMP
113636a7598SThomas Gleixner 	INTG(RESCHEDULE_VECTOR,		reschedule_interrupt),
114636a7598SThomas Gleixner 	INTG(CALL_FUNCTION_VECTOR,	call_function_interrupt),
115636a7598SThomas Gleixner 	INTG(CALL_FUNCTION_SINGLE_VECTOR, call_function_single_interrupt),
116636a7598SThomas Gleixner 	INTG(IRQ_MOVE_CLEANUP_VECTOR,	irq_move_cleanup_interrupt),
117636a7598SThomas Gleixner 	INTG(REBOOT_VECTOR,		reboot_interrupt),
118636a7598SThomas Gleixner #endif
119636a7598SThomas Gleixner 
120636a7598SThomas Gleixner #ifdef CONFIG_X86_THERMAL_VECTOR
121636a7598SThomas Gleixner 	INTG(THERMAL_APIC_VECTOR,	thermal_interrupt),
122636a7598SThomas Gleixner #endif
123636a7598SThomas Gleixner 
124636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_THRESHOLD
125636a7598SThomas Gleixner 	INTG(THRESHOLD_APIC_VECTOR,	threshold_interrupt),
126636a7598SThomas Gleixner #endif
127636a7598SThomas Gleixner 
128636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_AMD
129636a7598SThomas Gleixner 	INTG(DEFERRED_ERROR_VECTOR,	deferred_error_interrupt),
130636a7598SThomas Gleixner #endif
131636a7598SThomas Gleixner 
132636a7598SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
133636a7598SThomas Gleixner 	INTG(LOCAL_TIMER_VECTOR,	apic_timer_interrupt),
134636a7598SThomas Gleixner 	INTG(X86_PLATFORM_IPI_VECTOR,	x86_platform_ipi),
135636a7598SThomas Gleixner # ifdef CONFIG_HAVE_KVM
136636a7598SThomas Gleixner 	INTG(POSTED_INTR_VECTOR,	kvm_posted_intr_ipi),
137636a7598SThomas Gleixner 	INTG(POSTED_INTR_WAKEUP_VECTOR, kvm_posted_intr_wakeup_ipi),
138636a7598SThomas Gleixner 	INTG(POSTED_INTR_NESTED_VECTOR, kvm_posted_intr_nested_ipi),
139636a7598SThomas Gleixner # endif
140636a7598SThomas Gleixner # ifdef CONFIG_IRQ_WORK
141636a7598SThomas Gleixner 	INTG(IRQ_WORK_VECTOR,		irq_work_interrupt),
142636a7598SThomas Gleixner # endif
143151ad17fSAndrew Banman #ifdef CONFIG_X86_UV
144151ad17fSAndrew Banman 	INTG(UV_BAU_MESSAGE,		uv_bau_message_intr1),
145151ad17fSAndrew Banman #endif
146636a7598SThomas Gleixner 	INTG(SPURIOUS_APIC_VECTOR,	spurious_interrupt),
147636a7598SThomas Gleixner 	INTG(ERROR_APIC_VECTOR,		error_interrupt),
148636a7598SThomas Gleixner #endif
149636a7598SThomas Gleixner };
150636a7598SThomas Gleixner 
151433f8924SThomas Gleixner #ifdef CONFIG_X86_64
152433f8924SThomas Gleixner /*
153433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
154433f8924SThomas Gleixner  * stacks work only after cpu_init().
155433f8924SThomas Gleixner  */
156327867faSAndi Kleen static const __initconst struct idt_data early_pf_idts[] = {
157433f8924SThomas Gleixner 	INTG(X86_TRAP_PF,		page_fault),
158433f8924SThomas Gleixner };
1590a30908bSThomas Gleixner 
1600a30908bSThomas Gleixner /*
1610a30908bSThomas Gleixner  * Override for the debug_idt. Same as the default, but with interrupt
1620a30908bSThomas Gleixner  * stack set to DEFAULT_STACK (0). Required for NMI trap handling.
1630a30908bSThomas Gleixner  */
164327867faSAndi Kleen static const __initconst struct idt_data dbg_idts[] = {
1650a30908bSThomas Gleixner 	INTG(X86_TRAP_DB,	debug),
1660a30908bSThomas 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 = {
17316bc18d8SThomas Gleixner 	.size		= (IDT_ENTRIES * 2 * sizeof(unsigned long)) - 1,
17416bc18d8SThomas Gleixner 	.address	= (unsigned long) idt_table,
17516bc18d8SThomas Gleixner };
17616bc18d8SThomas Gleixner 
177d8ed9d48SThomas Gleixner #ifdef CONFIG_X86_64
178d8ed9d48SThomas Gleixner /* No need to be aligned, but done to keep all IDTs defined the same way. */
179d8ed9d48SThomas Gleixner gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
180d8ed9d48SThomas Gleixner 
1810a30908bSThomas Gleixner /*
18290f6225fSThomas Gleixner  * The exceptions which use Interrupt stacks. They are setup after
18390f6225fSThomas Gleixner  * cpu_init() when the TSS has been initialized.
18490f6225fSThomas Gleixner  */
185327867faSAndi Kleen static const __initconst struct idt_data ist_idts[] = {
186*32074269SThomas Gleixner 	ISTG(X86_TRAP_DB,	debug,		IST_INDEX_DB),
187*32074269SThomas Gleixner 	ISTG(X86_TRAP_NMI,	nmi,		IST_INDEX_NMI),
188*32074269SThomas Gleixner 	ISTG(X86_TRAP_DF,	double_fault,	IST_INDEX_DF),
18990f6225fSThomas Gleixner #ifdef CONFIG_X86_MCE
190*32074269SThomas Gleixner 	ISTG(X86_TRAP_MC,	&machine_check,	IST_INDEX_MCE),
19190f6225fSThomas Gleixner #endif
19290f6225fSThomas Gleixner };
19390f6225fSThomas Gleixner 
19490f6225fSThomas Gleixner /*
1950a30908bSThomas Gleixner  * Override for the debug_idt. Same as the default, but with interrupt
1960a30908bSThomas Gleixner  * stack set to DEFAULT_STACK (0). Required for NMI trap handling.
1970a30908bSThomas Gleixner  */
198d8ed9d48SThomas Gleixner const struct desc_ptr debug_idt_descr = {
199d8ed9d48SThomas Gleixner 	.size		= IDT_ENTRIES * 16 - 1,
200d8ed9d48SThomas Gleixner 	.address	= (unsigned long) debug_idt_table,
201d8ed9d48SThomas Gleixner };
202d8ed9d48SThomas Gleixner #endif
203e802a51eSThomas Gleixner 
2043318e974SThomas Gleixner static inline void idt_init_desc(gate_desc *gate, const struct idt_data *d)
2053318e974SThomas Gleixner {
2063318e974SThomas Gleixner 	unsigned long addr = (unsigned long) d->addr;
2073318e974SThomas Gleixner 
2083318e974SThomas Gleixner 	gate->offset_low	= (u16) addr;
2093318e974SThomas Gleixner 	gate->segment		= (u16) d->segment;
2103318e974SThomas Gleixner 	gate->bits		= d->bits;
2113318e974SThomas Gleixner 	gate->offset_middle	= (u16) (addr >> 16);
2123318e974SThomas Gleixner #ifdef CONFIG_X86_64
2133318e974SThomas Gleixner 	gate->offset_high	= (u32) (addr >> 32);
2143318e974SThomas Gleixner 	gate->reserved		= 0;
2153318e974SThomas Gleixner #endif
2163318e974SThomas Gleixner }
2173318e974SThomas Gleixner 
218db18da78SThomas Gleixner static void
219db18da78SThomas Gleixner idt_setup_from_table(gate_desc *idt, const struct idt_data *t, int size, bool sys)
2203318e974SThomas Gleixner {
2213318e974SThomas Gleixner 	gate_desc desc;
2223318e974SThomas Gleixner 
2233318e974SThomas Gleixner 	for (; size > 0; t++, size--) {
2243318e974SThomas Gleixner 		idt_init_desc(&desc, t);
2253318e974SThomas Gleixner 		write_idt_entry(idt, t->vector, &desc);
226db18da78SThomas Gleixner 		if (sys)
2277854f822SThomas Gleixner 			set_bit(t->vector, system_vectors);
2283318e974SThomas Gleixner 	}
2293318e974SThomas Gleixner }
2303318e974SThomas Gleixner 
231facaa3e3SThomas Gleixner static void set_intr_gate(unsigned int n, const void *addr)
232facaa3e3SThomas Gleixner {
233facaa3e3SThomas Gleixner 	struct idt_data data;
234facaa3e3SThomas Gleixner 
235facaa3e3SThomas Gleixner 	BUG_ON(n > 0xFF);
236facaa3e3SThomas Gleixner 
237facaa3e3SThomas Gleixner 	memset(&data, 0, sizeof(data));
238facaa3e3SThomas Gleixner 	data.vector	= n;
239facaa3e3SThomas Gleixner 	data.addr	= addr;
240facaa3e3SThomas Gleixner 	data.segment	= __KERNEL_CS;
241facaa3e3SThomas Gleixner 	data.bits.type	= GATE_INTERRUPT;
242facaa3e3SThomas Gleixner 	data.bits.p	= 1;
243facaa3e3SThomas Gleixner 
244facaa3e3SThomas Gleixner 	idt_setup_from_table(idt_table, &data, 1, false);
245facaa3e3SThomas Gleixner }
246facaa3e3SThomas Gleixner 
247e802a51eSThomas Gleixner /**
248433f8924SThomas Gleixner  * idt_setup_early_traps - Initialize the idt table with early traps
249433f8924SThomas Gleixner  *
250433f8924SThomas Gleixner  * On X8664 these traps do not use interrupt stacks as they can't work
251433f8924SThomas Gleixner  * before cpu_init() is invoked and sets up TSS. The IST variants are
252433f8924SThomas Gleixner  * installed after that.
253433f8924SThomas Gleixner  */
254433f8924SThomas Gleixner void __init idt_setup_early_traps(void)
255433f8924SThomas Gleixner {
256db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, early_idts, ARRAY_SIZE(early_idts),
257db18da78SThomas Gleixner 			     true);
258433f8924SThomas Gleixner 	load_idt(&idt_descr);
259433f8924SThomas Gleixner }
260433f8924SThomas Gleixner 
261b70543a0SThomas Gleixner /**
262b70543a0SThomas Gleixner  * idt_setup_traps - Initialize the idt table with default traps
263b70543a0SThomas Gleixner  */
264b70543a0SThomas Gleixner void __init idt_setup_traps(void)
265b70543a0SThomas Gleixner {
266db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, def_idts, ARRAY_SIZE(def_idts), true);
267b70543a0SThomas Gleixner }
268b70543a0SThomas Gleixner 
269433f8924SThomas Gleixner #ifdef CONFIG_X86_64
270433f8924SThomas Gleixner /**
271433f8924SThomas Gleixner  * idt_setup_early_pf - Initialize the idt table with early pagefault handler
272433f8924SThomas Gleixner  *
273433f8924SThomas Gleixner  * On X8664 this does not use interrupt stacks as they can't work before
274433f8924SThomas Gleixner  * cpu_init() is invoked and sets up TSS. The IST variant is installed
275433f8924SThomas Gleixner  * after that.
276433f8924SThomas Gleixner  *
277433f8924SThomas Gleixner  * FIXME: Why is 32bit and 64bit installing the PF handler at different
278433f8924SThomas Gleixner  * places in the early setup code?
279433f8924SThomas Gleixner  */
280433f8924SThomas Gleixner void __init idt_setup_early_pf(void)
281433f8924SThomas Gleixner {
282433f8924SThomas Gleixner 	idt_setup_from_table(idt_table, early_pf_idts,
283db18da78SThomas Gleixner 			     ARRAY_SIZE(early_pf_idts), true);
284433f8924SThomas Gleixner }
2850a30908bSThomas Gleixner 
2860a30908bSThomas Gleixner /**
28790f6225fSThomas Gleixner  * idt_setup_ist_traps - Initialize the idt table with traps using IST
28890f6225fSThomas Gleixner  */
28990f6225fSThomas Gleixner void __init idt_setup_ist_traps(void)
29090f6225fSThomas Gleixner {
291db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, ist_idts, ARRAY_SIZE(ist_idts), true);
29290f6225fSThomas Gleixner }
29390f6225fSThomas Gleixner 
29490f6225fSThomas Gleixner /**
2950a30908bSThomas Gleixner  * idt_setup_debugidt_traps - Initialize the debug idt table with debug traps
2960a30908bSThomas Gleixner  */
2970a30908bSThomas Gleixner void __init idt_setup_debugidt_traps(void)
2980a30908bSThomas Gleixner {
2990a30908bSThomas Gleixner 	memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
3000a30908bSThomas Gleixner 
301db18da78SThomas Gleixner 	idt_setup_from_table(debug_idt_table, dbg_idts, ARRAY_SIZE(dbg_idts), false);
3020a30908bSThomas Gleixner }
303433f8924SThomas Gleixner #endif
304433f8924SThomas Gleixner 
305433f8924SThomas Gleixner /**
306636a7598SThomas Gleixner  * idt_setup_apic_and_irq_gates - Setup APIC/SMP and normal interrupt gates
307636a7598SThomas Gleixner  */
308636a7598SThomas Gleixner void __init idt_setup_apic_and_irq_gates(void)
309636a7598SThomas Gleixner {
310dc20b2d5SThomas Gleixner 	int i = FIRST_EXTERNAL_VECTOR;
311dc20b2d5SThomas Gleixner 	void *entry;
312dc20b2d5SThomas Gleixner 
313db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, apic_idts, ARRAY_SIZE(apic_idts), true);
314dc20b2d5SThomas Gleixner 
3157854f822SThomas Gleixner 	for_each_clear_bit_from(i, system_vectors, FIRST_SYSTEM_VECTOR) {
316dc20b2d5SThomas Gleixner 		entry = irq_entries_start + 8 * (i - FIRST_EXTERNAL_VECTOR);
317dc20b2d5SThomas Gleixner 		set_intr_gate(i, entry);
318dc20b2d5SThomas Gleixner 	}
319dc20b2d5SThomas Gleixner 
320dc20b2d5SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
32133662812SDou Liyang 	for_each_clear_bit_from(i, system_vectors, NR_VECTORS) {
3227854f822SThomas Gleixner 		set_bit(i, system_vectors);
323dc20b2d5SThomas Gleixner 		set_intr_gate(i, spurious_interrupt);
324dc20b2d5SThomas Gleixner 	}
32533662812SDou Liyang #endif
326636a7598SThomas Gleixner }
327636a7598SThomas Gleixner 
328636a7598SThomas Gleixner /**
329588787fdSThomas Gleixner  * idt_setup_early_handler - Initializes the idt table with early handlers
330588787fdSThomas Gleixner  */
331588787fdSThomas Gleixner void __init idt_setup_early_handler(void)
332588787fdSThomas Gleixner {
333588787fdSThomas Gleixner 	int i;
334588787fdSThomas Gleixner 
335588787fdSThomas Gleixner 	for (i = 0; i < NUM_EXCEPTION_VECTORS; i++)
336588787fdSThomas Gleixner 		set_intr_gate(i, early_idt_handler_array[i]);
33787e81786SThomas Gleixner #ifdef CONFIG_X86_32
33887e81786SThomas Gleixner 	for ( ; i < NR_VECTORS; i++)
33987e81786SThomas Gleixner 		set_intr_gate(i, early_ignore_irq);
34087e81786SThomas Gleixner #endif
341588787fdSThomas Gleixner 	load_idt(&idt_descr);
342588787fdSThomas Gleixner }
343588787fdSThomas Gleixner 
344588787fdSThomas Gleixner /**
345e802a51eSThomas Gleixner  * idt_invalidate - Invalidate interrupt descriptor table
346e802a51eSThomas Gleixner  * @addr:	The virtual address of the 'invalid' IDT
347e802a51eSThomas Gleixner  */
348e802a51eSThomas Gleixner void idt_invalidate(void *addr)
349e802a51eSThomas Gleixner {
350e802a51eSThomas Gleixner 	struct desc_ptr idt = { .address = (unsigned long) addr, .size = 0 };
351e802a51eSThomas Gleixner 
352e802a51eSThomas Gleixner 	load_idt(&idt);
353e802a51eSThomas Gleixner }
354db18da78SThomas Gleixner 
355facaa3e3SThomas Gleixner void __init update_intr_gate(unsigned int n, const void *addr)
356db18da78SThomas Gleixner {
3577854f822SThomas Gleixner 	if (WARN_ON_ONCE(!test_bit(n, system_vectors)))
358facaa3e3SThomas Gleixner 		return;
359facaa3e3SThomas Gleixner 	set_intr_gate(n, addr);
360db18da78SThomas Gleixner }
361db18da78SThomas Gleixner 
362db18da78SThomas Gleixner void alloc_intr_gate(unsigned int n, const void *addr)
363db18da78SThomas Gleixner {
3644447ac11SThomas Gleixner 	BUG_ON(n < FIRST_SYSTEM_VECTOR);
3657854f822SThomas Gleixner 	if (!test_and_set_bit(n, system_vectors))
366db18da78SThomas Gleixner 		set_intr_gate(n, addr);
367db18da78SThomas Gleixner }
368