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