GenericInterruptHandler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/IntrusiveList.h>
  8. #include <AK/Types.h>
  9. #include <Kernel/Arch/x86/RegisterState.h>
  10. namespace Kernel {
  11. enum class HandlerType : u8 {
  12. IRQHandler = 1,
  13. SharedIRQHandler = 2,
  14. UnhandledInterruptHandler = 3,
  15. SpuriousInterruptHandler = 4
  16. };
  17. class GenericInterruptHandler {
  18. public:
  19. static GenericInterruptHandler& from(u8 interrupt_number);
  20. virtual ~GenericInterruptHandler()
  21. {
  22. VERIFY(!m_registered);
  23. }
  24. // Note: this method returns boolean value, to indicate if the handler handled
  25. // the interrupt or not. This is useful for shared handlers mostly.
  26. virtual bool handle_interrupt(const RegisterState& regs) = 0;
  27. void will_be_destroyed();
  28. bool is_registered() const { return m_registered; }
  29. void register_interrupt_handler();
  30. void unregister_interrupt_handler();
  31. u8 interrupt_number() const { return m_interrupt_number; }
  32. size_t get_invoking_count() const { return m_invoking_count; }
  33. virtual size_t sharing_devices_count() const = 0;
  34. virtual bool is_shared_handler() const = 0;
  35. virtual bool is_sharing_with_others() const = 0;
  36. virtual HandlerType type() const = 0;
  37. virtual StringView purpose() const = 0;
  38. virtual StringView controller() const = 0;
  39. virtual bool eoi() = 0;
  40. ALWAYS_INLINE void increment_invoking_counter()
  41. {
  42. m_invoking_count++;
  43. }
  44. protected:
  45. void change_interrupt_number(u8 number);
  46. GenericInterruptHandler(u8 interrupt_number, bool disable_remap = false);
  47. void disable_remap() { m_disable_remap = true; }
  48. private:
  49. Atomic<u32, AK::MemoryOrder::memory_order_relaxed> m_invoking_count { 0 };
  50. u8 m_interrupt_number { 0 };
  51. bool m_disable_remap { false };
  52. bool m_registered { false };
  53. IntrusiveListNode<GenericInterruptHandler> m_list_node;
  54. public:
  55. using List = IntrusiveList<GenericInterruptHandler, RawPtr<GenericInterruptHandler>, &GenericInterruptHandler::m_list_node>;
  56. };
  57. }