2020-02-28 19:22:32 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-28 19:22:32 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Kernel/Interrupts/InterruptManagement.h>
|
|
|
|
#include <Kernel/Interrupts/SpuriousInterruptHandler.h>
|
2021-06-22 18:40:16 +03:00
|
|
|
#include <Kernel/Sections.h>
|
2020-02-28 19:22:32 +03:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT void SpuriousInterruptHandler::initialize(u8 interrupt_number)
|
2020-02-28 19:22:32 +03:00
|
|
|
{
|
2021-02-27 03:17:57 +03:00
|
|
|
auto* handler = new SpuriousInterruptHandler(interrupt_number);
|
|
|
|
handler->register_interrupt_handler();
|
2020-02-28 19:22:32 +03:00
|
|
|
}
|
|
|
|
|
2020-12-19 09:49:15 +03:00
|
|
|
void SpuriousInterruptHandler::register_handler(GenericInterruptHandler& handler)
|
2020-02-28 19:22:32 +03:00
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(!m_real_handler);
|
2021-05-30 19:39:23 +03:00
|
|
|
m_real_handler = adopt_own_if_nonnull(&handler);
|
2020-02-28 19:22:32 +03:00
|
|
|
}
|
|
|
|
void SpuriousInterruptHandler::unregister_handler(GenericInterruptHandler&)
|
|
|
|
{
|
2020-12-19 09:49:15 +03:00
|
|
|
TODO();
|
2020-02-28 19:22:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SpuriousInterruptHandler::eoi()
|
|
|
|
{
|
2020-12-19 09:49:15 +03:00
|
|
|
// Actually check if IRQ7 or IRQ15 are spurious, and if not, call EOI with the correct interrupt number.
|
|
|
|
if (m_real_irq) {
|
|
|
|
m_responsible_irq_controller->eoi(*this);
|
|
|
|
m_real_irq = false; // return to default state!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
m_responsible_irq_controller->spurious_eoi(*this);
|
2020-02-28 19:22:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-11 02:46:09 +03:00
|
|
|
StringView SpuriousInterruptHandler::purpose() const
|
2021-03-23 20:51:15 +03:00
|
|
|
{
|
|
|
|
if (!m_real_handler)
|
|
|
|
return "Spurious Interrupt Handler";
|
|
|
|
return m_real_handler->purpose();
|
|
|
|
}
|
|
|
|
|
2020-02-28 19:22:32 +03:00
|
|
|
SpuriousInterruptHandler::SpuriousInterruptHandler(u8 irq)
|
|
|
|
: GenericInterruptHandler(irq)
|
2020-02-28 23:33:41 +03:00
|
|
|
, m_responsible_irq_controller(InterruptManagement::the().get_responsible_irq_controller(irq))
|
2020-02-28 19:22:32 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SpuriousInterruptHandler::~SpuriousInterruptHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-05 09:00:18 +03:00
|
|
|
bool SpuriousInterruptHandler::handle_interrupt(const RegisterState& state)
|
2020-02-28 19:22:32 +03:00
|
|
|
{
|
2020-12-19 09:49:15 +03:00
|
|
|
// Actually check if IRQ7 or IRQ15 are spurious, and if not, call the real handler to handle the IRQ.
|
2021-03-22 22:05:39 +03:00
|
|
|
if (m_responsible_irq_controller->get_isr() & (1 << interrupt_number())) {
|
2020-12-19 09:49:15 +03:00
|
|
|
m_real_irq = true; // remember that we had a real IRQ, when EOI later!
|
2021-06-05 09:00:18 +03:00
|
|
|
if (m_real_handler->handle_interrupt(state)) {
|
|
|
|
m_real_handler->increment_invoking_counter();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-12-19 09:49:15 +03:00
|
|
|
}
|
2021-03-12 16:06:37 +03:00
|
|
|
dbgln("Spurious interrupt, vector {}", interrupt_number());
|
2021-06-05 09:00:18 +03:00
|
|
|
return true;
|
2020-02-28 19:22:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpuriousInterruptHandler::enable_interrupt_vector()
|
|
|
|
{
|
|
|
|
if (m_enabled)
|
|
|
|
return;
|
|
|
|
m_enabled = true;
|
2020-03-08 13:47:33 +03:00
|
|
|
m_responsible_irq_controller->enable(*this);
|
2020-02-28 19:22:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpuriousInterruptHandler::disable_interrupt_vector()
|
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(!m_real_irq); // this flag should not be set when we call this method
|
2020-02-28 19:22:32 +03:00
|
|
|
if (!m_enabled)
|
|
|
|
return;
|
|
|
|
m_enabled = false;
|
2020-03-08 13:47:33 +03:00
|
|
|
m_responsible_irq_controller->disable(*this);
|
2020-02-28 19:22:32 +03:00
|
|
|
}
|
|
|
|
|
2021-07-11 02:46:09 +03:00
|
|
|
StringView SpuriousInterruptHandler::controller() const
|
2020-03-08 03:35:57 +03:00
|
|
|
{
|
|
|
|
if (m_responsible_irq_controller->type() == IRQControllerType::i82093AA)
|
|
|
|
return "";
|
|
|
|
return m_responsible_irq_controller->model();
|
|
|
|
}
|
2020-02-28 19:22:32 +03:00
|
|
|
}
|