diff options
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/include/kapi/cpu/interrupts.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/kapi/include/kapi/cpu/interrupts.hpp b/kapi/include/kapi/cpu/interrupts.hpp index 26a215e..328e4a7 100644 --- a/kapi/include/kapi/cpu/interrupts.hpp +++ b/kapi/include/kapi/cpu/interrupts.hpp @@ -3,9 +3,32 @@ // IWYU pragma: private, include "kapi/cpu.hpp" +#include <cstdint> + namespace kapi::cpu { + enum class status : bool + { + unhandled, + handled, + }; + + //! The interface for all interrupt handlers. + struct interrupt_handler + { + virtual ~interrupt_handler() = default; + + //! Handle an interrupt with the given IRQ number. + // + //! This function will be called by the kernel in an interrupt context. As such, the function should complete its + //! task quickly and must take care when acquiring globally shared locks. + //! + //! @param irq_number The identifier of the interrupt request that triggered the handler. + //! @return status::handled if the handler successfully handled the interrupt, status::unhandled otherwise. + virtual auto handle_interrupt(std::uint32_t irq_number) -> status = 0; + }; + //! @qualifier platform-defined //! Enable external interrupts. auto enable_interrupts() -> void; @@ -14,6 +37,27 @@ namespace kapi::cpu //! Disable external interrupts. auto disable_interrupts() -> void; + //! @qualifier platform-defined + //! Register an interrupt handler for the given IRQ number. + //! + //! @param irq_number The IRQ number to register the handler for. + //! @param handler The interrupt handler to register. + auto register_interrupt_handler(std::uint32_t irq_number, interrupt_handler & handler) -> void; + + //! @qualifier platform-defined + //! Unregister a previously registered interrupt handler. + //! + //! @param irq_number The IRQ number to unregister the handler for. + //! @param handler The interrupt handler to unregister. + auto unregister_interrupt_handler(std::uint32_t irq_number, interrupt_handler & handler) -> void; + + //! @qualifier platform-defined + //! Dispatch an interrupt to all registered handlers. + //! + //! @param irq_number The IRQ number to dispatch. + //! @return status::handled if the interrupt was handled by at least one handler, status::unhandled otherwise. + auto dispatch_interrupt(std::uint32_t irq_number) -> status; + } // namespace kapi::cpu #endif
\ No newline at end of file |
