IRQHandler.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Arch/x86/InterruptDisabler.h>
  7. #include <Kernel/Debug.h>
  8. #include <Kernel/Interrupts/IRQHandler.h>
  9. #include <Kernel/Interrupts/InterruptManagement.h>
  10. namespace Kernel {
  11. IRQHandler::IRQHandler(u8 irq)
  12. : GenericInterruptHandler(irq)
  13. , m_responsible_irq_controller(InterruptManagement::the().get_responsible_irq_controller(irq))
  14. {
  15. disable_irq();
  16. }
  17. IRQHandler::~IRQHandler()
  18. {
  19. }
  20. bool IRQHandler::eoi()
  21. {
  22. dbgln_if(IRQ_DEBUG, "EOI IRQ {}", interrupt_number());
  23. if (!m_shared_with_others) {
  24. VERIFY(!m_responsible_irq_controller.is_null());
  25. m_responsible_irq_controller->eoi(*this);
  26. return true;
  27. }
  28. return false;
  29. }
  30. void IRQHandler::enable_irq()
  31. {
  32. dbgln_if(IRQ_DEBUG, "Enable IRQ {}", interrupt_number());
  33. if (!is_registered())
  34. register_interrupt_handler();
  35. m_enabled = true;
  36. if (!m_shared_with_others)
  37. m_responsible_irq_controller->enable(*this);
  38. }
  39. void IRQHandler::disable_irq()
  40. {
  41. dbgln_if(IRQ_DEBUG, "Disable IRQ {}", interrupt_number());
  42. m_enabled = false;
  43. if (!m_shared_with_others)
  44. m_responsible_irq_controller->disable(*this);
  45. }
  46. void IRQHandler::change_irq_number(u8 irq)
  47. {
  48. InterruptDisabler disabler;
  49. change_interrupt_number(irq);
  50. m_responsible_irq_controller = InterruptManagement::the().get_responsible_irq_controller(irq);
  51. }
  52. }