1 /*
2 * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
4 * Distributed under the terms of the MIT License.
5 */
6 #ifndef _KERNEL_ARCH_x86_INT_H
7 #define _KERNEL_ARCH_x86_INT_H
8
9
10 #define ARCH_INTERRUPT_BASE 0x20
11 #define NUM_IO_VECTORS (256 - ARCH_INTERRUPT_BASE)
12
13
14 enum irq_source {
15 IRQ_SOURCE_INVALID,
16 IRQ_SOURCE_IOAPIC,
17 IRQ_SOURCE_MSI,
18 };
19
20
21 static inline void
arch_int_enable_interrupts_inline(void)22 arch_int_enable_interrupts_inline(void)
23 {
24 asm volatile("sti");
25 }
26
27
28 static inline int
arch_int_disable_interrupts_inline(void)29 arch_int_disable_interrupts_inline(void)
30 {
31 size_t flags;
32
33 asm volatile("pushf;\n"
34 "pop %0;\n"
35 "cli" : "=g" (flags));
36 return (flags & 0x200) != 0;
37 }
38
39
40 static inline void
arch_int_restore_interrupts_inline(int oldState)41 arch_int_restore_interrupts_inline(int oldState)
42 {
43 if (oldState)
44 asm volatile("sti");
45 }
46
47
48 static inline bool
arch_int_are_interrupts_enabled_inline(void)49 arch_int_are_interrupts_enabled_inline(void)
50 {
51 size_t flags;
52
53 asm volatile("pushf;\n"
54 "pop %0;\n" : "=g" (flags));
55 return (flags & 0x200) != 0;
56 }
57
58
59 // map the functions to the inline versions
60 #define arch_int_enable_interrupts() arch_int_enable_interrupts_inline()
61 #define arch_int_disable_interrupts() arch_int_disable_interrupts_inline()
62 #define arch_int_restore_interrupts(status) \
63 arch_int_restore_interrupts_inline(status)
64 #define arch_int_are_interrupts_enabled() \
65 arch_int_are_interrupts_enabled_inline()
66
67
68 #ifdef __cplusplus
69
70 typedef struct interrupt_controller_s {
71 const char *name;
72 void (*enable_io_interrupt)(int32 num);
73 void (*disable_io_interrupt)(int32 num);
74 void (*configure_io_interrupt)(int32 num, uint32 config);
75 bool (*is_spurious_interrupt)(int32 num);
76 bool (*is_level_triggered_interrupt)(int32 num);
77 bool (*end_of_interrupt)(int32 num);
78 void (*assign_interrupt_to_cpu)(int32 num, int32 cpu);
79 } interrupt_controller;
80
81
82 void x86_set_irq_source(int32 irq, irq_source source);
83
84 void arch_int_set_interrupt_controller(const interrupt_controller &controller);
85
86 #endif // __cplusplus
87
88 #endif /* _KERNEL_ARCH_x86_INT_H */
89