2005-04-27 05:08:35 +04:00
|
|
|
/*
|
2009-11-08 20:31:39 +03:00
|
|
|
* Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
|
2012-07-02 21:47:06 +04:00
|
|
|
* Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
|
2005-04-27 05:08:35 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _KERNEL_ARCH_x86_INT_H
|
|
|
|
#define _KERNEL_ARCH_x86_INT_H
|
|
|
|
|
|
|
|
|
|
|
|
#define ARCH_INTERRUPT_BASE 0x20
|
|
|
|
#define NUM_IO_VECTORS (256 - ARCH_INTERRUPT_BASE)
|
|
|
|
|
|
|
|
|
2013-12-20 04:07:08 +04:00
|
|
|
enum irq_source {
|
|
|
|
IRQ_SOURCE_INVALID,
|
|
|
|
IRQ_SOURCE_IOAPIC,
|
|
|
|
IRQ_SOURCE_MSI,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-01 18:33:10 +04:00
|
|
|
static inline void
|
|
|
|
arch_int_enable_interrupts_inline(void)
|
|
|
|
{
|
|
|
|
asm volatile("sti");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
arch_int_disable_interrupts_inline(void)
|
|
|
|
{
|
2012-07-03 23:55:36 +04:00
|
|
|
size_t flags;
|
2008-10-01 18:33:10 +04:00
|
|
|
|
2012-07-02 21:47:06 +04:00
|
|
|
asm volatile("pushf;\n"
|
|
|
|
"pop %0;\n"
|
2008-10-01 18:33:10 +04:00
|
|
|
"cli" : "=g" (flags));
|
2012-07-02 21:47:06 +04:00
|
|
|
return (flags & 0x200) != 0;
|
2008-10-01 18:33:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
2009-11-08 20:31:39 +03:00
|
|
|
arch_int_restore_interrupts_inline(int oldState)
|
2008-10-01 18:33:10 +04:00
|
|
|
{
|
2012-07-02 21:47:06 +04:00
|
|
|
if (oldState)
|
|
|
|
asm("sti");
|
2008-10-01 18:33:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
arch_int_are_interrupts_enabled_inline(void)
|
|
|
|
{
|
2012-07-03 23:55:36 +04:00
|
|
|
size_t flags;
|
2008-10-01 18:33:10 +04:00
|
|
|
|
2012-07-02 21:47:06 +04:00
|
|
|
asm volatile("pushf;\n"
|
|
|
|
"pop %0;\n" : "=g" (flags));
|
2009-11-08 20:31:39 +03:00
|
|
|
return (flags & 0x200) != 0;
|
2008-10-01 18:33:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// map the functions to the inline versions
|
|
|
|
#define arch_int_enable_interrupts() arch_int_enable_interrupts_inline()
|
|
|
|
#define arch_int_disable_interrupts() arch_int_disable_interrupts_inline()
|
|
|
|
#define arch_int_restore_interrupts(status) \
|
|
|
|
arch_int_restore_interrupts_inline(status)
|
|
|
|
#define arch_int_are_interrupts_enabled() \
|
|
|
|
arch_int_are_interrupts_enabled_inline()
|
|
|
|
|
|
|
|
|
2011-05-11 05:30:55 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2011-05-11 04:53:03 +04:00
|
|
|
typedef struct interrupt_controller_s {
|
|
|
|
const char *name;
|
|
|
|
void (*enable_io_interrupt)(int32 num);
|
|
|
|
void (*disable_io_interrupt)(int32 num);
|
|
|
|
void (*configure_io_interrupt)(int32 num, uint32 config);
|
|
|
|
bool (*is_spurious_interrupt)(int32 num);
|
|
|
|
bool (*is_level_triggered_interrupt)(int32 num);
|
|
|
|
bool (*end_of_interrupt)(int32 num);
|
2013-11-18 07:55:25 +04:00
|
|
|
void (*assign_interrupt_to_cpu)(int32 num, int32 cpu);
|
2011-05-11 04:53:03 +04:00
|
|
|
} interrupt_controller;
|
|
|
|
|
|
|
|
|
2013-12-20 04:07:08 +04:00
|
|
|
void x86_set_irq_source(int irq, irq_source source);
|
|
|
|
|
2011-05-11 04:53:03 +04:00
|
|
|
void arch_int_set_interrupt_controller(const interrupt_controller &controller);
|
|
|
|
|
2011-05-11 05:30:55 +04:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
2005-04-27 05:08:35 +04:00
|
|
|
#endif /* _KERNEL_ARCH_x86_INT_H */
|