1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:57:45 +00:00

Kernel/Interrupts: Return boolean on whether we handled the interrupt

If we are in a shared interrupt handler, the called handlers might
indicate it was not their interrupt, so we should not increment the
call counter of these handlers.
This commit is contained in:
Liav A 2021-06-05 09:00:18 +03:00 committed by Andreas Kling
parent 7a6d5a7b8b
commit b91df26d4a
43 changed files with 125 additions and 71 deletions

View file

@ -70,7 +70,7 @@ public:
handler->register_interrupt_handler();
}
virtual void handle_interrupt(const RegisterState&) override;
virtual bool handle_interrupt(const RegisterState&) override;
virtual bool eoi() override;
@ -101,7 +101,7 @@ public:
handler->register_interrupt_handler();
}
virtual void handle_interrupt(const RegisterState&) override;
virtual bool handle_interrupt(const RegisterState&) override;
virtual bool eoi() override;
@ -555,9 +555,10 @@ u32 APIC::get_timer_divisor()
return 16;
}
void APICIPIInterruptHandler::handle_interrupt(const RegisterState&)
bool APICIPIInterruptHandler::handle_interrupt(const RegisterState&)
{
dbgln_if(APIC_SMP_DEBUG, "APIC IPI on CPU #{}", Processor::id());
return true;
}
bool APICIPIInterruptHandler::eoi()
@ -567,9 +568,10 @@ bool APICIPIInterruptHandler::eoi()
return true;
}
void APICErrInterruptHandler::handle_interrupt(const RegisterState&)
bool APICErrInterruptHandler::handle_interrupt(const RegisterState&)
{
dbgln("APIC: SMP error on CPU #{}", Processor::id());
return true;
}
bool APICErrInterruptHandler::eoi()

View file

@ -27,7 +27,9 @@ public:
{
VERIFY(!m_registered);
}
virtual void handle_interrupt(const RegisterState& regs) = 0;
// Note: this method returns boolean value, to indicate if the handler handled
// the interrupt or not. This is useful for shared handlers mostly.
virtual bool handle_interrupt(const RegisterState& regs) = 0;
void will_be_destroyed();
bool is_registered() const { return m_registered; }

View file

@ -19,8 +19,8 @@ class IRQHandler : public GenericInterruptHandler {
public:
virtual ~IRQHandler();
virtual void handle_interrupt(const RegisterState& regs) { handle_irq(regs); }
virtual void handle_irq(const RegisterState&) = 0;
virtual bool handle_interrupt(const RegisterState& regs) { return handle_irq(regs); }
virtual bool handle_irq(const RegisterState&) = 0;
void enable_irq();
void disable_irq();

View file

@ -63,7 +63,7 @@ SharedIRQHandler::~SharedIRQHandler()
disable_interrupt_vector();
}
void SharedIRQHandler::handle_interrupt(const RegisterState& regs)
bool SharedIRQHandler::handle_interrupt(const RegisterState& regs)
{
VERIFY_INTERRUPTS_DISABLED();
@ -71,16 +71,19 @@ void SharedIRQHandler::handle_interrupt(const RegisterState& regs)
dbgln("Interrupt @ {}", interrupt_number());
dbgln("Interrupt Handlers registered - {}", m_handlers.size());
}
int i = 0;
bool was_handled = false;
for (auto* handler : m_handlers) {
dbgln_if(INTERRUPT_DEBUG, "Going for Interrupt Handling @ {}, Shared Interrupt {}", i, interrupt_number());
VERIFY(handler != nullptr);
handler->increment_invoking_counter();
handler->handle_interrupt(regs);
if (handler->handle_interrupt(regs)) {
handler->increment_invoking_counter();
was_handled = true;
}
dbgln_if(INTERRUPT_DEBUG, "Going for Interrupt Handling @ {}, Shared Interrupt {} - End", i, interrupt_number());
i++;
}
return was_handled;
}
void SharedIRQHandler::enable_interrupt_vector()

View file

@ -19,7 +19,7 @@ class SharedIRQHandler final : public GenericInterruptHandler {
public:
static void initialize(u8 interrupt_number);
virtual ~SharedIRQHandler();
virtual void handle_interrupt(const RegisterState& regs) override;
virtual bool handle_interrupt(const RegisterState& regs) override;
void register_handler(GenericInterruptHandler&);
void unregister_handler(GenericInterruptHandler&);

View file

@ -54,16 +54,19 @@ SpuriousInterruptHandler::~SpuriousInterruptHandler()
{
}
void SpuriousInterruptHandler::handle_interrupt(const RegisterState& state)
bool SpuriousInterruptHandler::handle_interrupt(const RegisterState& state)
{
// Actually check if IRQ7 or IRQ15 are spurious, and if not, call the real handler to handle the IRQ.
if (m_responsible_irq_controller->get_isr() & (1 << interrupt_number())) {
m_real_irq = true; // remember that we had a real IRQ, when EOI later!
m_real_handler->increment_invoking_counter();
m_real_handler->handle_interrupt(state);
return;
if (m_real_handler->handle_interrupt(state)) {
m_real_handler->increment_invoking_counter();
return true;
}
return false;
}
dbgln("Spurious interrupt, vector {}", interrupt_number());
return true;
}
void SpuriousInterruptHandler::enable_interrupt_vector()

View file

@ -18,7 +18,7 @@ class SpuriousInterruptHandler final : public GenericInterruptHandler {
public:
static void initialize(u8 interrupt_number);
virtual ~SpuriousInterruptHandler();
virtual void handle_interrupt(const RegisterState& regs) override;
virtual bool handle_interrupt(const RegisterState& regs) override;
void register_handler(GenericInterruptHandler&);
void unregister_handler(GenericInterruptHandler&);

View file

@ -13,7 +13,7 @@ UnhandledInterruptHandler::UnhandledInterruptHandler(u8 interrupt_vector)
{
}
void UnhandledInterruptHandler::handle_interrupt(const RegisterState&)
bool UnhandledInterruptHandler::handle_interrupt(const RegisterState&)
{
PANIC("Interrupt: Unhandled vector {} was invoked for handle_interrupt(RegisterState&).", interrupt_number());
}

View file

@ -17,7 +17,7 @@ public:
explicit UnhandledInterruptHandler(u8 interrupt_vector);
virtual ~UnhandledInterruptHandler();
virtual void handle_interrupt(const RegisterState&) override;
virtual bool handle_interrupt(const RegisterState&) override;
[[noreturn]] virtual bool eoi() override;