xref: /linux/arch/x86/kernel/idt.c (revision db18da78f9a8bbab1bdc5968ba47ace788b5061f)
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>
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 
433318e974SThomas Gleixner /* Interrupt gate with interrupt stack */
443318e974SThomas Gleixner #define ISTG(_vector, _addr, _ist)			\
453318e974SThomas Gleixner 	G(_vector, _addr, _ist, GATE_INTERRUPT, DPL0, __KERNEL_CS)
463318e974SThomas Gleixner 
473318e974SThomas Gleixner /* Task gate */
483318e974SThomas Gleixner #define TSKG(_vector, _gdt)				\
493318e974SThomas Gleixner 	G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3)
503318e974SThomas Gleixner 
51433f8924SThomas Gleixner /*
52433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
53433f8924SThomas Gleixner  * stacks work only after cpu_init().
54433f8924SThomas Gleixner  */
55433f8924SThomas Gleixner static const __initdata struct idt_data early_idts[] = {
56433f8924SThomas Gleixner 	INTG(X86_TRAP_DB,		debug),
57433f8924SThomas Gleixner 	SYSG(X86_TRAP_BP,		int3),
58433f8924SThomas Gleixner #ifdef CONFIG_X86_32
59433f8924SThomas Gleixner 	INTG(X86_TRAP_PF,		page_fault),
60433f8924SThomas Gleixner #endif
61433f8924SThomas Gleixner };
62433f8924SThomas Gleixner 
63b70543a0SThomas Gleixner /*
64b70543a0SThomas Gleixner  * The default IDT entries which are set up in trap_init() before
65b70543a0SThomas Gleixner  * cpu_init() is invoked. Interrupt stacks cannot be used at that point and
66b70543a0SThomas Gleixner  * the traps which use them are reinitialized with IST after cpu_init() has
67b70543a0SThomas Gleixner  * set up TSS.
68b70543a0SThomas Gleixner  */
69b70543a0SThomas Gleixner static const __initdata struct idt_data def_idts[] = {
70b70543a0SThomas Gleixner 	INTG(X86_TRAP_DE,		divide_error),
71b70543a0SThomas Gleixner 	INTG(X86_TRAP_NMI,		nmi),
72b70543a0SThomas Gleixner 	INTG(X86_TRAP_BR,		bounds),
73b70543a0SThomas Gleixner 	INTG(X86_TRAP_UD,		invalid_op),
74b70543a0SThomas Gleixner 	INTG(X86_TRAP_NM,		device_not_available),
75b70543a0SThomas Gleixner 	INTG(X86_TRAP_OLD_MF,		coprocessor_segment_overrun),
76b70543a0SThomas Gleixner 	INTG(X86_TRAP_TS,		invalid_TSS),
77b70543a0SThomas Gleixner 	INTG(X86_TRAP_NP,		segment_not_present),
78b70543a0SThomas Gleixner 	INTG(X86_TRAP_SS,		stack_segment),
79b70543a0SThomas Gleixner 	INTG(X86_TRAP_GP,		general_protection),
80b70543a0SThomas Gleixner 	INTG(X86_TRAP_SPURIOUS,		spurious_interrupt_bug),
81b70543a0SThomas Gleixner 	INTG(X86_TRAP_MF,		coprocessor_error),
82b70543a0SThomas Gleixner 	INTG(X86_TRAP_AC,		alignment_check),
83b70543a0SThomas Gleixner 	INTG(X86_TRAP_XF,		simd_coprocessor_error),
84b70543a0SThomas Gleixner 
85b70543a0SThomas Gleixner #ifdef CONFIG_X86_32
86b70543a0SThomas Gleixner 	TSKG(X86_TRAP_DF,		GDT_ENTRY_DOUBLEFAULT_TSS),
87b70543a0SThomas Gleixner #else
88b70543a0SThomas Gleixner 	INTG(X86_TRAP_DF,		double_fault),
89b70543a0SThomas Gleixner #endif
90b70543a0SThomas Gleixner 	INTG(X86_TRAP_DB,		debug),
91b70543a0SThomas Gleixner 	INTG(X86_TRAP_NMI,		nmi),
92b70543a0SThomas Gleixner 	INTG(X86_TRAP_BP,		int3),
93b70543a0SThomas Gleixner 
94b70543a0SThomas Gleixner #ifdef CONFIG_X86_MCE
95b70543a0SThomas Gleixner 	INTG(X86_TRAP_MC,		&machine_check),
96b70543a0SThomas Gleixner #endif
97b70543a0SThomas Gleixner 
98b70543a0SThomas Gleixner 	SYSG(X86_TRAP_OF,		overflow),
99b70543a0SThomas Gleixner #if defined(CONFIG_IA32_EMULATION)
100b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_compat),
101b70543a0SThomas Gleixner #elif defined(CONFIG_X86_32)
102b70543a0SThomas Gleixner 	SYSG(IA32_SYSCALL_VECTOR,	entry_INT80_32),
103b70543a0SThomas Gleixner #endif
104b70543a0SThomas Gleixner };
105b70543a0SThomas Gleixner 
106636a7598SThomas Gleixner /*
107636a7598SThomas Gleixner  * The APIC and SMP idt entries
108636a7598SThomas Gleixner  */
109636a7598SThomas Gleixner static const __initdata struct idt_data apic_idts[] = {
110636a7598SThomas Gleixner #ifdef CONFIG_SMP
111636a7598SThomas Gleixner 	INTG(RESCHEDULE_VECTOR,		reschedule_interrupt),
112636a7598SThomas Gleixner 	INTG(CALL_FUNCTION_VECTOR,	call_function_interrupt),
113636a7598SThomas Gleixner 	INTG(CALL_FUNCTION_SINGLE_VECTOR, call_function_single_interrupt),
114636a7598SThomas Gleixner 	INTG(IRQ_MOVE_CLEANUP_VECTOR,	irq_move_cleanup_interrupt),
115636a7598SThomas Gleixner 	INTG(REBOOT_VECTOR,		reboot_interrupt),
116636a7598SThomas Gleixner #endif
117636a7598SThomas Gleixner 
118636a7598SThomas Gleixner #ifdef CONFIG_X86_THERMAL_VECTOR
119636a7598SThomas Gleixner 	INTG(THERMAL_APIC_VECTOR,	thermal_interrupt),
120636a7598SThomas Gleixner #endif
121636a7598SThomas Gleixner 
122636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_THRESHOLD
123636a7598SThomas Gleixner 	INTG(THRESHOLD_APIC_VECTOR,	threshold_interrupt),
124636a7598SThomas Gleixner #endif
125636a7598SThomas Gleixner 
126636a7598SThomas Gleixner #ifdef CONFIG_X86_MCE_AMD
127636a7598SThomas Gleixner 	INTG(DEFERRED_ERROR_VECTOR,	deferred_error_interrupt),
128636a7598SThomas Gleixner #endif
129636a7598SThomas Gleixner 
130636a7598SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
131636a7598SThomas Gleixner 	INTG(LOCAL_TIMER_VECTOR,	apic_timer_interrupt),
132636a7598SThomas Gleixner 	INTG(X86_PLATFORM_IPI_VECTOR,	x86_platform_ipi),
133636a7598SThomas Gleixner # ifdef CONFIG_HAVE_KVM
134636a7598SThomas Gleixner 	INTG(POSTED_INTR_VECTOR,	kvm_posted_intr_ipi),
135636a7598SThomas Gleixner 	INTG(POSTED_INTR_WAKEUP_VECTOR, kvm_posted_intr_wakeup_ipi),
136636a7598SThomas Gleixner 	INTG(POSTED_INTR_NESTED_VECTOR, kvm_posted_intr_nested_ipi),
137636a7598SThomas Gleixner # endif
138636a7598SThomas Gleixner # ifdef CONFIG_IRQ_WORK
139636a7598SThomas Gleixner 	INTG(IRQ_WORK_VECTOR,		irq_work_interrupt),
140636a7598SThomas Gleixner # endif
141636a7598SThomas Gleixner 	INTG(SPURIOUS_APIC_VECTOR,	spurious_interrupt),
142636a7598SThomas Gleixner 	INTG(ERROR_APIC_VECTOR,		error_interrupt),
143636a7598SThomas Gleixner #endif
144636a7598SThomas Gleixner };
145636a7598SThomas Gleixner 
146433f8924SThomas Gleixner #ifdef CONFIG_X86_64
147433f8924SThomas Gleixner /*
148433f8924SThomas Gleixner  * Early traps running on the DEFAULT_STACK because the other interrupt
149433f8924SThomas Gleixner  * stacks work only after cpu_init().
150433f8924SThomas Gleixner  */
151433f8924SThomas Gleixner static const __initdata struct idt_data early_pf_idts[] = {
152433f8924SThomas Gleixner 	INTG(X86_TRAP_PF,		page_fault),
153433f8924SThomas Gleixner };
1540a30908bSThomas Gleixner 
1550a30908bSThomas Gleixner /*
1560a30908bSThomas Gleixner  * Override for the debug_idt. Same as the default, but with interrupt
1570a30908bSThomas Gleixner  * stack set to DEFAULT_STACK (0). Required for NMI trap handling.
1580a30908bSThomas Gleixner  */
1590a30908bSThomas Gleixner static const __initdata struct idt_data dbg_idts[] = {
1600a30908bSThomas Gleixner 	INTG(X86_TRAP_DB,	debug),
1610a30908bSThomas Gleixner 	INTG(X86_TRAP_BP,	int3),
1620a30908bSThomas Gleixner };
163433f8924SThomas Gleixner #endif
164433f8924SThomas Gleixner 
165d8ed9d48SThomas Gleixner /* Must be page-aligned because the real IDT is used in a fixmap. */
166d8ed9d48SThomas Gleixner gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss;
167d8ed9d48SThomas Gleixner 
16816bc18d8SThomas Gleixner struct desc_ptr idt_descr __ro_after_init = {
16916bc18d8SThomas Gleixner 	.size		= (IDT_ENTRIES * 2 * sizeof(unsigned long)) - 1,
17016bc18d8SThomas Gleixner 	.address	= (unsigned long) idt_table,
17116bc18d8SThomas Gleixner };
17216bc18d8SThomas Gleixner 
173d8ed9d48SThomas Gleixner #ifdef CONFIG_X86_64
174d8ed9d48SThomas Gleixner /* No need to be aligned, but done to keep all IDTs defined the same way. */
175d8ed9d48SThomas Gleixner gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
176d8ed9d48SThomas Gleixner 
1770a30908bSThomas Gleixner /*
17890f6225fSThomas Gleixner  * The exceptions which use Interrupt stacks. They are setup after
17990f6225fSThomas Gleixner  * cpu_init() when the TSS has been initialized.
18090f6225fSThomas Gleixner  */
18190f6225fSThomas Gleixner static const __initdata struct idt_data ist_idts[] = {
18290f6225fSThomas Gleixner 	ISTG(X86_TRAP_DB,	debug,		DEBUG_STACK),
18390f6225fSThomas Gleixner 	ISTG(X86_TRAP_NMI,	nmi,		NMI_STACK),
18490f6225fSThomas Gleixner 	ISTG(X86_TRAP_BP,	int3,		DEBUG_STACK),
18590f6225fSThomas Gleixner 	ISTG(X86_TRAP_DF,	double_fault,	DOUBLEFAULT_STACK),
18690f6225fSThomas Gleixner #ifdef CONFIG_X86_MCE
18790f6225fSThomas Gleixner 	ISTG(X86_TRAP_MC,	&machine_check,	MCE_STACK),
18890f6225fSThomas Gleixner #endif
18990f6225fSThomas Gleixner };
19090f6225fSThomas Gleixner 
19190f6225fSThomas Gleixner /*
1920a30908bSThomas Gleixner  * Override for the debug_idt. Same as the default, but with interrupt
1930a30908bSThomas Gleixner  * stack set to DEFAULT_STACK (0). Required for NMI trap handling.
1940a30908bSThomas Gleixner  */
195d8ed9d48SThomas Gleixner const struct desc_ptr debug_idt_descr = {
196d8ed9d48SThomas Gleixner 	.size		= IDT_ENTRIES * 16 - 1,
197d8ed9d48SThomas Gleixner 	.address	= (unsigned long) debug_idt_table,
198d8ed9d48SThomas Gleixner };
199d8ed9d48SThomas Gleixner #endif
200e802a51eSThomas Gleixner 
2013318e974SThomas Gleixner static inline void idt_init_desc(gate_desc *gate, const struct idt_data *d)
2023318e974SThomas Gleixner {
2033318e974SThomas Gleixner 	unsigned long addr = (unsigned long) d->addr;
2043318e974SThomas Gleixner 
2053318e974SThomas Gleixner 	gate->offset_low	= (u16) addr;
2063318e974SThomas Gleixner 	gate->segment		= (u16) d->segment;
2073318e974SThomas Gleixner 	gate->bits		= d->bits;
2083318e974SThomas Gleixner 	gate->offset_middle	= (u16) (addr >> 16);
2093318e974SThomas Gleixner #ifdef CONFIG_X86_64
2103318e974SThomas Gleixner 	gate->offset_high	= (u32) (addr >> 32);
2113318e974SThomas Gleixner 	gate->reserved		= 0;
2123318e974SThomas Gleixner #endif
2133318e974SThomas Gleixner }
2143318e974SThomas Gleixner 
215*db18da78SThomas Gleixner static void
216*db18da78SThomas Gleixner idt_setup_from_table(gate_desc *idt, const struct idt_data *t, int size, bool sys)
2173318e974SThomas Gleixner {
2183318e974SThomas Gleixner 	gate_desc desc;
2193318e974SThomas Gleixner 
2203318e974SThomas Gleixner 	for (; size > 0; t++, size--) {
2213318e974SThomas Gleixner 		idt_init_desc(&desc, t);
2223318e974SThomas Gleixner 		write_idt_entry(idt, t->vector, &desc);
223*db18da78SThomas Gleixner 		if (sys)
224*db18da78SThomas Gleixner 			set_bit(t->vector, used_vectors);
2253318e974SThomas Gleixner 	}
2263318e974SThomas Gleixner }
2273318e974SThomas Gleixner 
228e802a51eSThomas Gleixner /**
229433f8924SThomas Gleixner  * idt_setup_early_traps - Initialize the idt table with early traps
230433f8924SThomas Gleixner  *
231433f8924SThomas Gleixner  * On X8664 these traps do not use interrupt stacks as they can't work
232433f8924SThomas Gleixner  * before cpu_init() is invoked and sets up TSS. The IST variants are
233433f8924SThomas Gleixner  * installed after that.
234433f8924SThomas Gleixner  */
235433f8924SThomas Gleixner void __init idt_setup_early_traps(void)
236433f8924SThomas Gleixner {
237*db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, early_idts, ARRAY_SIZE(early_idts),
238*db18da78SThomas Gleixner 			     true);
239433f8924SThomas Gleixner 	load_idt(&idt_descr);
240433f8924SThomas Gleixner }
241433f8924SThomas Gleixner 
242b70543a0SThomas Gleixner /**
243b70543a0SThomas Gleixner  * idt_setup_traps - Initialize the idt table with default traps
244b70543a0SThomas Gleixner  */
245b70543a0SThomas Gleixner void __init idt_setup_traps(void)
246b70543a0SThomas Gleixner {
247*db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, def_idts, ARRAY_SIZE(def_idts), true);
248b70543a0SThomas Gleixner }
249b70543a0SThomas Gleixner 
250433f8924SThomas Gleixner #ifdef CONFIG_X86_64
251433f8924SThomas Gleixner /**
252433f8924SThomas Gleixner  * idt_setup_early_pf - Initialize the idt table with early pagefault handler
253433f8924SThomas Gleixner  *
254433f8924SThomas Gleixner  * On X8664 this does not use interrupt stacks as they can't work before
255433f8924SThomas Gleixner  * cpu_init() is invoked and sets up TSS. The IST variant is installed
256433f8924SThomas Gleixner  * after that.
257433f8924SThomas Gleixner  *
258433f8924SThomas Gleixner  * FIXME: Why is 32bit and 64bit installing the PF handler at different
259433f8924SThomas Gleixner  * places in the early setup code?
260433f8924SThomas Gleixner  */
261433f8924SThomas Gleixner void __init idt_setup_early_pf(void)
262433f8924SThomas Gleixner {
263433f8924SThomas Gleixner 	idt_setup_from_table(idt_table, early_pf_idts,
264*db18da78SThomas Gleixner 			     ARRAY_SIZE(early_pf_idts), true);
265433f8924SThomas Gleixner }
2660a30908bSThomas Gleixner 
2670a30908bSThomas Gleixner /**
26890f6225fSThomas Gleixner  * idt_setup_ist_traps - Initialize the idt table with traps using IST
26990f6225fSThomas Gleixner  */
27090f6225fSThomas Gleixner void __init idt_setup_ist_traps(void)
27190f6225fSThomas Gleixner {
272*db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, ist_idts, ARRAY_SIZE(ist_idts), true);
27390f6225fSThomas Gleixner }
27490f6225fSThomas Gleixner 
27590f6225fSThomas Gleixner /**
2760a30908bSThomas Gleixner  * idt_setup_debugidt_traps - Initialize the debug idt table with debug traps
2770a30908bSThomas Gleixner  */
2780a30908bSThomas Gleixner void __init idt_setup_debugidt_traps(void)
2790a30908bSThomas Gleixner {
2800a30908bSThomas Gleixner 	memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
2810a30908bSThomas Gleixner 
282*db18da78SThomas Gleixner 	idt_setup_from_table(debug_idt_table, dbg_idts, ARRAY_SIZE(dbg_idts), false);
2830a30908bSThomas Gleixner }
284433f8924SThomas Gleixner #endif
285433f8924SThomas Gleixner 
286433f8924SThomas Gleixner /**
287636a7598SThomas Gleixner  * idt_setup_apic_and_irq_gates - Setup APIC/SMP and normal interrupt gates
288636a7598SThomas Gleixner  */
289636a7598SThomas Gleixner void __init idt_setup_apic_and_irq_gates(void)
290636a7598SThomas Gleixner {
291dc20b2d5SThomas Gleixner 	int i = FIRST_EXTERNAL_VECTOR;
292dc20b2d5SThomas Gleixner 	void *entry;
293dc20b2d5SThomas Gleixner 
294*db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, apic_idts, ARRAY_SIZE(apic_idts), true);
295dc20b2d5SThomas Gleixner 
296dc20b2d5SThomas Gleixner 	for_each_clear_bit_from(i, used_vectors, FIRST_SYSTEM_VECTOR) {
297dc20b2d5SThomas Gleixner 		entry = irq_entries_start + 8 * (i - FIRST_EXTERNAL_VECTOR);
298dc20b2d5SThomas Gleixner 		set_intr_gate(i, entry);
299dc20b2d5SThomas Gleixner 	}
300dc20b2d5SThomas Gleixner 
301dc20b2d5SThomas Gleixner 	for_each_clear_bit_from(i, used_vectors, NR_VECTORS) {
302dc20b2d5SThomas Gleixner #ifdef CONFIG_X86_LOCAL_APIC
303dc20b2d5SThomas Gleixner 		set_bit(i, used_vectors);
304dc20b2d5SThomas Gleixner 		set_intr_gate(i, spurious_interrupt);
305dc20b2d5SThomas Gleixner #else
306dc20b2d5SThomas Gleixner 		entry = irq_entries_start + 8 * (i - FIRST_EXTERNAL_VECTOR);
307dc20b2d5SThomas Gleixner 		set_intr_gate(i, entry);
308dc20b2d5SThomas Gleixner #endif
309dc20b2d5SThomas Gleixner 	}
310636a7598SThomas Gleixner }
311636a7598SThomas Gleixner 
312636a7598SThomas Gleixner /**
313588787fdSThomas Gleixner  * idt_setup_early_handler - Initializes the idt table with early handlers
314588787fdSThomas Gleixner  */
315588787fdSThomas Gleixner void __init idt_setup_early_handler(void)
316588787fdSThomas Gleixner {
317588787fdSThomas Gleixner 	int i;
318588787fdSThomas Gleixner 
319588787fdSThomas Gleixner 	for (i = 0; i < NUM_EXCEPTION_VECTORS; i++)
320588787fdSThomas Gleixner 		set_intr_gate(i, early_idt_handler_array[i]);
32187e81786SThomas Gleixner #ifdef CONFIG_X86_32
32287e81786SThomas Gleixner 	for ( ; i < NR_VECTORS; i++)
32387e81786SThomas Gleixner 		set_intr_gate(i, early_ignore_irq);
32487e81786SThomas Gleixner #endif
325588787fdSThomas Gleixner 	load_idt(&idt_descr);
326588787fdSThomas Gleixner }
327588787fdSThomas Gleixner 
328588787fdSThomas Gleixner /**
329e802a51eSThomas Gleixner  * idt_invalidate - Invalidate interrupt descriptor table
330e802a51eSThomas Gleixner  * @addr:	The virtual address of the 'invalid' IDT
331e802a51eSThomas Gleixner  */
332e802a51eSThomas Gleixner void idt_invalidate(void *addr)
333e802a51eSThomas Gleixner {
334e802a51eSThomas Gleixner 	struct desc_ptr idt = { .address = (unsigned long) addr, .size = 0 };
335e802a51eSThomas Gleixner 
336e802a51eSThomas Gleixner 	load_idt(&idt);
337e802a51eSThomas Gleixner }
338*db18da78SThomas Gleixner 
339*db18da78SThomas Gleixner void set_intr_gate(unsigned int n, const void *addr)
340*db18da78SThomas Gleixner {
341*db18da78SThomas Gleixner 	struct idt_data data;
342*db18da78SThomas Gleixner 
343*db18da78SThomas Gleixner 	BUG_ON(n > 0xFF);
344*db18da78SThomas Gleixner 
345*db18da78SThomas Gleixner 	memset(&data, 0, sizeof(data));
346*db18da78SThomas Gleixner 	data.vector	= n;
347*db18da78SThomas Gleixner 	data.addr	= addr;
348*db18da78SThomas Gleixner 	data.segment	= __KERNEL_CS;
349*db18da78SThomas Gleixner 	data.bits.type	= GATE_INTERRUPT;
350*db18da78SThomas Gleixner 	data.bits.p	= 1;
351*db18da78SThomas Gleixner 
352*db18da78SThomas Gleixner 	idt_setup_from_table(idt_table, &data, 1, false);
353*db18da78SThomas Gleixner }
354*db18da78SThomas Gleixner 
355*db18da78SThomas Gleixner void alloc_intr_gate(unsigned int n, const void *addr)
356*db18da78SThomas Gleixner {
357*db18da78SThomas Gleixner 	BUG_ON(test_bit(n, used_vectors) || n < FIRST_SYSTEM_VECTOR);
358*db18da78SThomas Gleixner 	set_bit(n, used_vectors);
359*db18da78SThomas Gleixner 	set_intr_gate(n, addr);
360*db18da78SThomas Gleixner }
361