IRQHandler.cpp 1.5 KB

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