1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +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

@ -17,7 +17,7 @@ UNMAP_AFTER_INIT DynamicParser::DynamicParser(PhysicalAddress rsdp)
dmesgln("ACPI: Dynamic Parsing Enabled, Can parse AML"); dmesgln("ACPI: Dynamic Parsing Enabled, Can parse AML");
} }
void DynamicParser::handle_irq(const RegisterState&) bool DynamicParser::handle_irq(const RegisterState&)
{ {
// FIXME: Implement IRQ handling of ACPI signals! // FIXME: Implement IRQ handling of ACPI signals!
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();

View file

@ -36,7 +36,7 @@ protected:
private: private:
void build_namespace(); void build_namespace();
// ^IRQHandler // ^IRQHandler
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
OwnPtr<Region> m_acpi_namespace; OwnPtr<Region> m_acpi_namespace;
}; };

View file

@ -129,25 +129,26 @@ UNMAP_AFTER_INIT void I8042Controller::detect_devices()
m_mouse_device->enable_interrupts(); m_mouse_device->enable_interrupts();
} }
void I8042Controller::irq_process_input_buffer(HIDDevice::Type) bool I8042Controller::irq_process_input_buffer(HIDDevice::Type)
{ {
VERIFY(Processor::current().in_irq()); VERIFY(Processor::current().in_irq());
u8 status = IO::in8(I8042_STATUS); u8 status = IO::in8(I8042_STATUS);
if (!(status & I8042_BUFFER_FULL)) if (!(status & I8042_BUFFER_FULL))
return; return false;
HIDDevice::Type data_for_device = ((status & I8042_WHICH_BUFFER) == I8042_MOUSE_BUFFER) ? HIDDevice::Type::Mouse : HIDDevice::Type::Keyboard; HIDDevice::Type data_for_device = ((status & I8042_WHICH_BUFFER) == I8042_MOUSE_BUFFER) ? HIDDevice::Type::Mouse : HIDDevice::Type::Keyboard;
u8 byte = IO::in8(I8042_BUFFER); u8 byte = IO::in8(I8042_BUFFER);
if (data_for_device == HIDDevice::Type::Mouse) { if (data_for_device == HIDDevice::Type::Mouse) {
VERIFY(m_mouse_device); VERIFY(m_mouse_device);
static_cast<PS2MouseDevice&>(*m_mouse_device).irq_handle_byte_read(byte); static_cast<PS2MouseDevice&>(*m_mouse_device).irq_handle_byte_read(byte);
return; return true;
} }
if (data_for_device == HIDDevice::Type::Keyboard) { if (data_for_device == HIDDevice::Type::Keyboard) {
VERIFY(m_keyboard_device); VERIFY(m_keyboard_device);
static_cast<PS2KeyboardDevice&>(*m_keyboard_device).irq_handle_byte_read(byte); static_cast<PS2KeyboardDevice&>(*m_keyboard_device).irq_handle_byte_read(byte);
return; return true;
} }
return false;
} }
void I8042Controller::do_drain() void I8042Controller::do_drain()

View file

@ -89,7 +89,7 @@ public:
void prepare_for_output(); void prepare_for_output();
void prepare_for_input(HIDDevice::Type); void prepare_for_input(HIDDevice::Type);
void irq_process_input_buffer(HIDDevice::Type); bool irq_process_input_buffer(HIDDevice::Type);
RefPtr<MouseDevice> mouse() const; RefPtr<MouseDevice> mouse() const;
RefPtr<KeyboardDevice> keyboard() const; RefPtr<KeyboardDevice> keyboard() const;

View file

@ -85,11 +85,11 @@ void PS2KeyboardDevice::irq_handle_byte_read(u8 byte)
} }
} }
void PS2KeyboardDevice::handle_irq(const RegisterState&) bool PS2KeyboardDevice::handle_irq(const RegisterState&)
{ {
// The controller will read the data and call irq_handle_byte_read // The controller will read the data and call irq_handle_byte_read
// for the appropriate device // for the appropriate device
m_i8042_controller->irq_process_input_buffer(HIDDevice::Type::Keyboard); return m_i8042_controller->irq_process_input_buffer(HIDDevice::Type::Keyboard);
} }
UNMAP_AFTER_INIT RefPtr<PS2KeyboardDevice> PS2KeyboardDevice::try_to_initialize(const I8042Controller& ps2_controller) UNMAP_AFTER_INIT RefPtr<PS2KeyboardDevice> PS2KeyboardDevice::try_to_initialize(const I8042Controller& ps2_controller)

View file

@ -39,7 +39,7 @@ private:
explicit PS2KeyboardDevice(const I8042Controller&); explicit PS2KeyboardDevice(const I8042Controller&);
// ^IRQHandler // ^IRQHandler
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
// ^CharacterDevice // ^CharacterDevice
virtual const char* class_name() const override { return "KeyboardDevice"; } virtual const char* class_name() const override { return "KeyboardDevice"; }

View file

@ -40,11 +40,11 @@ UNMAP_AFTER_INIT PS2MouseDevice::~PS2MouseDevice()
{ {
} }
void PS2MouseDevice::handle_irq(const RegisterState&) bool PS2MouseDevice::handle_irq(const RegisterState&)
{ {
// The controller will read the data and call irq_handle_byte_read // The controller will read the data and call irq_handle_byte_read
// for the appropriate device // for the appropriate device
m_i8042_controller->irq_process_input_buffer(instrument_type()); return m_i8042_controller->irq_process_input_buffer(instrument_type());
} }
void PS2MouseDevice::irq_handle_byte_read(u8 byte) void PS2MouseDevice::irq_handle_byte_read(u8 byte)

View file

@ -35,7 +35,7 @@ public:
protected: protected:
explicit PS2MouseDevice(const I8042Controller&); explicit PS2MouseDevice(const I8042Controller&);
// ^IRQHandler // ^IRQHandler
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
struct RawPacket { struct RawPacket {
union { union {

View file

@ -205,8 +205,10 @@ void SB16::dma_start(uint32_t length)
IO::out8(0xd4, (channel % 4)); IO::out8(0xd4, (channel % 4));
} }
void SB16::handle_irq(const RegisterState&) bool SB16::handle_irq(const RegisterState&)
{ {
// FIXME: Check if the interrupt was actually for us or not... (shared IRQs)
// Stop sound output ready for the next block. // Stop sound output ready for the next block.
dsp_write(0xd5); dsp_write(0xd5);
@ -215,6 +217,7 @@ void SB16::handle_irq(const RegisterState&)
IO::in8(DSP_R_ACK); // 16 bit interrupt IO::in8(DSP_R_ACK); // 16 bit interrupt
m_irq_queue.wake_all(); m_irq_queue.wake_all();
return true;
} }
void SB16::wait_for_irq() void SB16::wait_for_irq()

View file

@ -40,7 +40,7 @@ public:
private: private:
// ^IRQHandler // ^IRQHandler
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
// ^CharacterDevice // ^CharacterDevice
virtual const char* class_name() const override { return "SB16"; } virtual const char* class_name() const override { return "SB16"; }

View file

@ -586,13 +586,13 @@ void UHCIController::spawn_port_proc()
}); });
} }
void UHCIController::handle_irq(const RegisterState&) bool UHCIController::handle_irq(const RegisterState&)
{ {
u32 status = read_usbsts(); u32 status = read_usbsts();
// Shared IRQ. Not ours! // Shared IRQ. Not ours!
if (!status) if (!status)
return; return false;
if constexpr (UHCI_DEBUG) { if constexpr (UHCI_DEBUG) {
dbgln("UHCI: Interrupt happened!"); dbgln("UHCI: Interrupt happened!");
@ -601,6 +601,7 @@ void UHCIController::handle_irq(const RegisterState&)
// Write back USBSTS to clear bits // Write back USBSTS to clear bits
write_usbsts(status); write_usbsts(status);
return true;
} }
} }

View file

@ -60,7 +60,7 @@ private:
void write_portsc1(u16 value) { m_io_base.offset(0x10).out(value); } void write_portsc1(u16 value) { m_io_base.offset(0x10).out(value); }
void write_portsc2(u16 value) { m_io_base.offset(0x12).out(value); } void write_portsc2(u16 value) { m_io_base.offset(0x12).out(value); }
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
void create_structures(); void create_structures();
void setup_schedule(); void setup_schedule();

View file

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

View file

@ -27,7 +27,9 @@ public:
{ {
VERIFY(!m_registered); 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(); void will_be_destroyed();
bool is_registered() const { return m_registered; } bool is_registered() const { return m_registered; }

View file

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

View file

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

View file

@ -19,7 +19,7 @@ class SharedIRQHandler final : public GenericInterruptHandler {
public: public:
static void initialize(u8 interrupt_number); static void initialize(u8 interrupt_number);
virtual ~SharedIRQHandler(); virtual ~SharedIRQHandler();
virtual void handle_interrupt(const RegisterState& regs) override; virtual bool handle_interrupt(const RegisterState& regs) override;
void register_handler(GenericInterruptHandler&); void register_handler(GenericInterruptHandler&);
void unregister_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. // 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())) { 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_irq = true; // remember that we had a real IRQ, when EOI later!
m_real_handler->increment_invoking_counter(); if (m_real_handler->handle_interrupt(state)) {
m_real_handler->handle_interrupt(state); m_real_handler->increment_invoking_counter();
return; return true;
}
return false;
} }
dbgln("Spurious interrupt, vector {}", interrupt_number()); dbgln("Spurious interrupt, vector {}", interrupt_number());
return true;
} }
void SpuriousInterruptHandler::enable_interrupt_vector() void SpuriousInterruptHandler::enable_interrupt_vector()

View file

@ -18,7 +18,7 @@ class SpuriousInterruptHandler final : public GenericInterruptHandler {
public: public:
static void initialize(u8 interrupt_number); static void initialize(u8 interrupt_number);
virtual ~SpuriousInterruptHandler(); virtual ~SpuriousInterruptHandler();
virtual void handle_interrupt(const RegisterState& regs) override; virtual bool handle_interrupt(const RegisterState& regs) override;
void register_handler(GenericInterruptHandler&); void register_handler(GenericInterruptHandler&);
void unregister_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()); PANIC("Interrupt: Unhandled vector {} was invoked for handle_interrupt(RegisterState&).", interrupt_number());
} }

View file

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

View file

@ -230,12 +230,15 @@ UNMAP_AFTER_INIT E1000NetworkAdapter::~E1000NetworkAdapter()
{ {
} }
void E1000NetworkAdapter::handle_irq(const RegisterState&) bool E1000NetworkAdapter::handle_irq(const RegisterState&)
{ {
u32 status = in32(REG_INTERRUPT_CAUSE_READ); u32 status = in32(REG_INTERRUPT_CAUSE_READ);
m_entropy_source.add_random_event(status); m_entropy_source.add_random_event(status);
if (status == 0)
return false;
if (status & INTERRUPT_LSC) { if (status & INTERRUPT_LSC) {
u32 flags = in32(REG_CTRL); u32 flags = in32(REG_CTRL);
out32(REG_CTRL, flags | ECTRL_SLU); out32(REG_CTRL, flags | ECTRL_SLU);
@ -253,6 +256,7 @@ void E1000NetworkAdapter::handle_irq(const RegisterState&)
m_wait_queue.wake_all(); m_wait_queue.wake_all();
out32(REG_INTERRUPT_CAUSE_READ, 0xffffffff); out32(REG_INTERRUPT_CAUSE_READ, 0xffffffff);
return true;
} }
UNMAP_AFTER_INIT void E1000NetworkAdapter::detect_eeprom() UNMAP_AFTER_INIT void E1000NetworkAdapter::detect_eeprom()

View file

@ -36,7 +36,7 @@ protected:
void setup_link(); void setup_link();
E1000NetworkAdapter(PCI::Address, u8 irq); E1000NetworkAdapter(PCI::Address, u8 irq);
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
virtual const char* class_name() const override { return "E1000NetworkAdapter"; } virtual const char* class_name() const override { return "E1000NetworkAdapter"; }
struct [[gnu::packed]] e1000_rx_desc { struct [[gnu::packed]] e1000_rx_desc {

View file

@ -184,10 +184,13 @@ UNMAP_AFTER_INIT NE2000NetworkAdapter::~NE2000NetworkAdapter()
{ {
} }
void NE2000NetworkAdapter::handle_irq(const RegisterState&) bool NE2000NetworkAdapter::handle_irq(const RegisterState&)
{ {
u8 status = in8(REG_RW_INTERRUPTSTATUS); u8 status = in8(REG_RW_INTERRUPTSTATUS);
dbgln_if(NE2000_DEBUG, "NE2000NetworkAdapter: Got interrupt, status={:#02x}", status); dbgln_if(NE2000_DEBUG, "NE2000NetworkAdapter: Got interrupt, status={:#02x}", status);
if (status == 0) {
return false;
}
if (status & BIT_INTERRUPTMASK_PRX) { if (status & BIT_INTERRUPTMASK_PRX) {
dbgln_if(NE2000_DEBUG, "NE2000NetworkAdapter: Interrupt for packet received"); dbgln_if(NE2000_DEBUG, "NE2000NetworkAdapter: Interrupt for packet received");
@ -223,6 +226,7 @@ void NE2000NetworkAdapter::handle_irq(const RegisterState&)
m_wait_queue.wake_all(); m_wait_queue.wake_all();
out8(REG_RW_INTERRUPTSTATUS, status); out8(REG_RW_INTERRUPTSTATUS, status);
return true;
} }
UNMAP_AFTER_INIT int NE2000NetworkAdapter::ram_test() UNMAP_AFTER_INIT int NE2000NetworkAdapter::ram_test()

View file

@ -29,7 +29,7 @@ public:
private: private:
NE2000NetworkAdapter(PCI::Address, u8 irq); NE2000NetworkAdapter(PCI::Address, u8 irq);
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
virtual const char* class_name() const override { return "NE2000NetworkAdapter"; } virtual const char* class_name() const override { return "NE2000NetworkAdapter"; }
int ram_test(); int ram_test();

View file

@ -155,8 +155,9 @@ UNMAP_AFTER_INIT RTL8139NetworkAdapter::~RTL8139NetworkAdapter()
{ {
} }
void RTL8139NetworkAdapter::handle_irq(const RegisterState&) bool RTL8139NetworkAdapter::handle_irq(const RegisterState&)
{ {
bool was_handled = false;
for (;;) { for (;;) {
int status = in16(REG_ISR); int status = in16(REG_ISR);
out16(REG_ISR, status); out16(REG_ISR, status);
@ -168,6 +169,7 @@ void RTL8139NetworkAdapter::handle_irq(const RegisterState&)
if ((status & (INT_RXOK | INT_RXERR | INT_TXOK | INT_TXERR | INT_RX_BUFFER_OVERFLOW | INT_LINK_CHANGE | INT_RX_FIFO_OVERFLOW | INT_LENGTH_CHANGE | INT_SYSTEM_ERROR)) == 0) if ((status & (INT_RXOK | INT_RXERR | INT_TXOK | INT_TXERR | INT_RX_BUFFER_OVERFLOW | INT_LINK_CHANGE | INT_RX_FIFO_OVERFLOW | INT_LENGTH_CHANGE | INT_SYSTEM_ERROR)) == 0)
break; break;
was_handled = true;
if (status & INT_RXOK) { if (status & INT_RXOK) {
dbgln_if(RTL8139_DEBUG, "RTL8139: RX ready"); dbgln_if(RTL8139_DEBUG, "RTL8139: RX ready");
receive(); receive();
@ -201,6 +203,7 @@ void RTL8139NetworkAdapter::handle_irq(const RegisterState&)
reset(); reset();
} }
} }
return was_handled;
} }
void RTL8139NetworkAdapter::reset() void RTL8139NetworkAdapter::reset()

View file

@ -31,7 +31,7 @@ public:
private: private:
RTL8139NetworkAdapter(PCI::Address, u8 irq); RTL8139NetworkAdapter(PCI::Address, u8 irq);
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
virtual const char* class_name() const override { return "RTL8139NetworkAdapter"; } virtual const char* class_name() const override { return "RTL8139NetworkAdapter"; }
void reset(); void reset();

View file

@ -1073,8 +1073,9 @@ UNMAP_AFTER_INIT RTL8168NetworkAdapter::~RTL8168NetworkAdapter()
{ {
} }
void RTL8168NetworkAdapter::handle_irq(const RegisterState&) bool RTL8168NetworkAdapter::handle_irq(const RegisterState&)
{ {
bool was_handled = false;
for (;;) { for (;;) {
int status = in16(REG_ISR); int status = in16(REG_ISR);
out16(REG_ISR, status); out16(REG_ISR, status);
@ -1086,6 +1087,7 @@ void RTL8168NetworkAdapter::handle_irq(const RegisterState&)
if ((status & (INT_RXOK | INT_RXERR | INT_TXOK | INT_TXERR | INT_RX_OVERFLOW | INT_LINK_CHANGE | INT_RX_FIFO_OVERFLOW | INT_SYS_ERR)) == 0) if ((status & (INT_RXOK | INT_RXERR | INT_TXOK | INT_TXERR | INT_RX_OVERFLOW | INT_LINK_CHANGE | INT_RX_FIFO_OVERFLOW | INT_SYS_ERR)) == 0)
break; break;
was_handled = true;
if (status & INT_RXOK) { if (status & INT_RXOK) {
dbgln_if(RTL8168_DEBUG, "RTL8168: RX ready"); dbgln_if(RTL8168_DEBUG, "RTL8168: RX ready");
receive(); receive();
@ -1116,6 +1118,7 @@ void RTL8168NetworkAdapter::handle_irq(const RegisterState&)
dmesgln("RTL8168: Fatal system error"); dmesgln("RTL8168: Fatal system error");
} }
} }
return was_handled;
} }
void RTL8168NetworkAdapter::reset() void RTL8168NetworkAdapter::reset()

View file

@ -36,7 +36,7 @@ private:
RTL8168NetworkAdapter(PCI::Address, u8 irq); RTL8168NetworkAdapter(PCI::Address, u8 irq);
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
virtual const char* class_name() const override { return "RTL8168NetworkAdapter"; } virtual const char* class_name() const override { return "RTL8168NetworkAdapter"; }
struct [[gnu::packed]] TXDescriptor { struct [[gnu::packed]] TXDescriptor {

View file

@ -158,6 +158,11 @@ public:
return m_bitfield & ((1 << port_index) & m_bit_mask); return m_bitfield & ((1 << port_index) & m_bit_mask);
} }
bool is_zeroed() const
{
return (m_bitfield & m_bit_mask) == 0;
}
Vector<u8> to_vector() const Vector<u8> to_vector() const
{ {
// FIXME: Add a sync mechanism! // FIXME: Add a sync mechanism!

View file

@ -82,9 +82,11 @@ AHCIPortHandler::~AHCIPortHandler()
{ {
} }
void AHCIPortHandler::handle_irq(const RegisterState&) bool AHCIPortHandler::handle_irq(const RegisterState&)
{ {
dbgln_if(AHCI_DEBUG, "AHCI Port Handler: IRQ received"); dbgln_if(AHCI_DEBUG, "AHCI Port Handler: IRQ received");
if (m_pending_ports_interrupts.is_zeroed())
return false;
for (auto port_index : m_pending_ports_interrupts.to_vector()) { for (auto port_index : m_pending_ports_interrupts.to_vector()) {
auto port = m_handled_ports.get(port_index); auto port = m_handled_ports.get(port_index);
VERIFY(port.has_value()); VERIFY(port.has_value());
@ -93,6 +95,7 @@ void AHCIPortHandler::handle_irq(const RegisterState&)
// We do this to clear the pending interrupt after we handled it. // We do this to clear the pending interrupt after we handled it.
m_pending_ports_interrupts.set_at(port_index); m_pending_ports_interrupts.set_at(port_index);
} }
return true;
} }
} }

View file

@ -48,7 +48,7 @@ private:
UNMAP_AFTER_INIT AHCIPortHandler(AHCIController&, u8 irq, AHCI::MaskedBitField taken_ports); UNMAP_AFTER_INIT AHCIPortHandler(AHCIController&, u8 irq, AHCI::MaskedBitField taken_ports);
//^ IRQHandler //^ IRQHandler
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
enum class Direction : u8 { enum class Direction : u8 {
Read, Read,

View file

@ -63,7 +63,7 @@ static void print_ide_status(u8 status)
(status & ATA_SR_ERR) != 0); (status & ATA_SR_ERR) != 0);
} }
void BMIDEChannel::handle_irq(const RegisterState&) bool BMIDEChannel::handle_irq(const RegisterState&)
{ {
u8 status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>(); u8 status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>();
@ -74,7 +74,7 @@ void BMIDEChannel::handle_irq(const RegisterState&)
if (!(bstatus & 0x4)) { if (!(bstatus & 0x4)) {
// interrupt not from this device, ignore // interrupt not from this device, ignore
dbgln_if(PATA_DEBUG, "BMIDEChannel: ignore interrupt"); dbgln_if(PATA_DEBUG, "BMIDEChannel: ignore interrupt");
return; return false;
} }
// clear bus master interrupt status // clear bus master interrupt status
m_io_group.bus_master_base().value().offset(2).out<u8>(m_io_group.bus_master_base().value().offset(2).in<u8>() | 4); m_io_group.bus_master_base().value().offset(2).out<u8>(m_io_group.bus_master_base().value().offset(2).in<u8>() | 4);
@ -87,7 +87,7 @@ void BMIDEChannel::handle_irq(const RegisterState&)
if (!m_current_request) { if (!m_current_request) {
dbgln("BMIDEChannel: IRQ but no pending request!"); dbgln("BMIDEChannel: IRQ but no pending request!");
return; return false;
} }
if (status & ATA_SR_ERR) { if (status & ATA_SR_ERR) {
@ -96,10 +96,11 @@ void BMIDEChannel::handle_irq(const RegisterState&)
dbgln("BMIDEChannel: Error {:#02x}!", (u8)m_device_error); dbgln("BMIDEChannel: Error {:#02x}!", (u8)m_device_error);
try_disambiguate_error(); try_disambiguate_error();
complete_current_request(AsyncDeviceRequest::Failure); complete_current_request(AsyncDeviceRequest::Failure);
return; return true;
} }
m_device_error = 0; m_device_error = 0;
complete_current_request(AsyncDeviceRequest::Success); complete_current_request(AsyncDeviceRequest::Success);
return true;
} }
void BMIDEChannel::complete_current_request(AsyncDeviceRequest::RequestResult result) void BMIDEChannel::complete_current_request(AsyncDeviceRequest::RequestResult result)

View file

@ -39,7 +39,7 @@ private:
void complete_current_request(AsyncDeviceRequest::RequestResult); void complete_current_request(AsyncDeviceRequest::RequestResult);
//^ IRQHandler //^ IRQHandler
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
//* IDEChannel //* IDEChannel
virtual void send_ata_io_command(LBAMode lba_mode, Direction direction) const; virtual void send_ata_io_command(LBAMode lba_mode, Direction direction) const;

View file

@ -190,7 +190,7 @@ void IDEChannel::try_disambiguate_error()
} }
} }
void IDEChannel::handle_irq(const RegisterState&) bool IDEChannel::handle_irq(const RegisterState&)
{ {
u8 status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>(); u8 status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>();
@ -204,7 +204,7 @@ void IDEChannel::handle_irq(const RegisterState&)
if (!m_current_request) { if (!m_current_request) {
dbgln("IDEChannel: IRQ but no pending request!"); dbgln("IDEChannel: IRQ but no pending request!");
return; return false;
} }
if (status & ATA_SR_ERR) { if (status & ATA_SR_ERR) {
@ -213,7 +213,7 @@ void IDEChannel::handle_irq(const RegisterState&)
dbgln("IDEChannel: Error {:#02x}!", (u8)m_device_error); dbgln("IDEChannel: Error {:#02x}!", (u8)m_device_error);
try_disambiguate_error(); try_disambiguate_error();
complete_current_request(AsyncDeviceRequest::Failure); complete_current_request(AsyncDeviceRequest::Failure);
return; return true;
} }
m_device_error = 0; m_device_error = 0;
@ -251,6 +251,7 @@ void IDEChannel::handle_irq(const RegisterState&)
} }
} }
}); });
return true;
} }
static void io_delay() static void io_delay()

View file

@ -122,7 +122,7 @@ protected:
IDEChannel(const IDEController&, IOAddressGroup, ChannelType type); IDEChannel(const IDEController&, IOAddressGroup, ChannelType type);
IDEChannel(const IDEController&, u8 irq, IOAddressGroup, ChannelType type); IDEChannel(const IDEController&, u8 irq, IOAddressGroup, ChannelType type);
//^ IRQHandler //^ IRQHandler
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
virtual void send_ata_io_command(LBAMode lba_mode, Direction direction) const; virtual void send_ata_io_command(LBAMode lba_mode, Direction direction) const;

View file

@ -51,11 +51,12 @@ void HPETComparator::set_non_periodic()
HPET::the().disable_periodic_interrupt(*this); HPET::the().disable_periodic_interrupt(*this);
} }
void HPETComparator::handle_irq(const RegisterState& regs) bool HPETComparator::handle_irq(const RegisterState& regs)
{ {
HardwareTimer::handle_irq(regs); auto result = HardwareTimer::handle_irq(regs);
if (!is_periodic()) if (!is_periodic())
set_new_countdown(); set_new_countdown();
return result;
} }
void HPETComparator::set_new_countdown() void HPETComparator::set_new_countdown()

View file

@ -43,7 +43,7 @@ public:
private: private:
void set_new_countdown(); void set_new_countdown();
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
HPETComparator(u8 number, u8 irq, bool periodic_capable, bool is_64bit_capable); HPETComparator(u8 number, u8 irq, bool periodic_capable, bool is_64bit_capable);
bool m_periodic : 1; bool m_periodic : 1;
bool m_periodic_capable : 1; bool m_periodic_capable : 1;

View file

@ -92,10 +92,14 @@ protected:
{ {
} }
virtual void handle_irq(const RegisterState& regs) override virtual bool handle_irq(const RegisterState& regs) override
{ {
if (m_callback) // Note: if we have an IRQ on this line, it's going to be the timer always
if (m_callback) {
m_callback(regs); m_callback(regs);
return true;
}
return false;
} }
u64 m_frequency { OPTIMAL_TICKS_PER_SECOND_RATE }; u64 m_frequency { OPTIMAL_TICKS_PER_SECOND_RATE };
@ -142,10 +146,14 @@ protected:
{ {
} }
virtual void handle_interrupt(const RegisterState& regs) override virtual bool handle_interrupt(const RegisterState& regs) override
{ {
if (m_callback) // Note: if we have an IRQ on this line, it's going to be the timer always
if (m_callback) {
m_callback(regs); m_callback(regs);
return true;
}
return false;
} }
u64 m_frequency { OPTIMAL_TICKS_PER_SECOND_RATE }; u64 m_frequency { OPTIMAL_TICKS_PER_SECOND_RATE };

View file

@ -27,10 +27,11 @@ RealTimeClock::RealTimeClock(Function<void(const RegisterState&)> callback)
CMOS::write(0x8B, CMOS::read(0xB) | 0x40); CMOS::write(0x8B, CMOS::read(0xB) | 0x40);
reset_to_default_ticks_per_second(); reset_to_default_ticks_per_second();
} }
void RealTimeClock::handle_irq(const RegisterState& regs) bool RealTimeClock::handle_irq(const RegisterState& regs)
{ {
HardwareTimer::handle_irq(regs); auto result = HardwareTimer::handle_irq(regs);
CMOS::read(0x8C); CMOS::read(0x8C);
return result;
} }
size_t RealTimeClock::ticks_per_second() const size_t RealTimeClock::ticks_per_second() const

View file

@ -31,6 +31,6 @@ public:
private: private:
explicit RealTimeClock(Function<void(const RegisterState&)> callback); explicit RealTimeClock(Function<void(const RegisterState&)> callback);
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
}; };
} }

View file

@ -342,11 +342,13 @@ u8 VirtIODevice::isr_status()
return config_read8(*m_isr_cfg, 0); return config_read8(*m_isr_cfg, 0);
} }
void VirtIODevice::handle_irq(const RegisterState&) bool VirtIODevice::handle_irq(const RegisterState&)
{ {
u8 isr_type = isr_status(); u8 isr_type = isr_status();
if ((isr_type & (QUEUE_INTERRUPT | DEVICE_CONFIG_INTERRUPT)) == 0) if ((isr_type & (QUEUE_INTERRUPT | DEVICE_CONFIG_INTERRUPT)) == 0) {
dbgln_if(VIRTIO_DEBUG, "{}: Handling interrupt with unknown type: {}", m_class_name, isr_type); dbgln_if(VIRTIO_DEBUG, "{}: Handling interrupt with unknown type: {}", m_class_name, isr_type);
return false;
}
if (isr_type & DEVICE_CONFIG_INTERRUPT) { if (isr_type & DEVICE_CONFIG_INTERRUPT) {
dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Device config interrupt!", m_class_name); dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Device config interrupt!", m_class_name);
if (!handle_device_config_change()) { if (!handle_device_config_change()) {
@ -357,11 +359,14 @@ void VirtIODevice::handle_irq(const RegisterState&)
if (isr_type & QUEUE_INTERRUPT) { if (isr_type & QUEUE_INTERRUPT) {
dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Queue interrupt!", m_class_name); dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Queue interrupt!", m_class_name);
for (size_t i = 0; i < m_queues.size(); i++) { for (size_t i = 0; i < m_queues.size(); i++) {
if (get_queue(i).new_data_available()) if (get_queue(i).new_data_available()) {
return handle_queue_update(i); handle_queue_update(i);
return true;
}
} }
dbgln_if(VIRTIO_DEBUG, "{}: Got queue interrupt but all queues are up to date!", m_class_name); dbgln_if(VIRTIO_DEBUG, "{}: Got queue interrupt but all queues are up to date!", m_class_name);
} }
return true;
} }
void VirtIODevice::supply_chain_and_notify(u16 queue_index, VirtIOQueueChain& chain) void VirtIODevice::supply_chain_and_notify(u16 queue_index, VirtIOQueueChain& chain)

View file

@ -222,7 +222,7 @@ private:
void reset_device(); void reset_device();
u8 isr_status(); u8 isr_status();
virtual void handle_irq(const RegisterState&) override; virtual bool handle_irq(const RegisterState&) override;
NonnullOwnPtrVector<VirtIOQueue> m_queues; NonnullOwnPtrVector<VirtIOQueue> m_queues;
NonnullOwnPtrVector<Configuration> m_configs; NonnullOwnPtrVector<Configuration> m_configs;