1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:47: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

@ -158,6 +158,11 @@ public:
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
{
// 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");
if (m_pending_ports_interrupts.is_zeroed())
return false;
for (auto port_index : m_pending_ports_interrupts.to_vector()) {
auto port = m_handled_ports.get(port_index);
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.
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);
//^ IRQHandler
virtual void handle_irq(const RegisterState&) override;
virtual bool handle_irq(const RegisterState&) override;
enum class Direction : u8 {
Read,

View file

@ -63,7 +63,7 @@ static void print_ide_status(u8 status)
(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>();
@ -74,7 +74,7 @@ void BMIDEChannel::handle_irq(const RegisterState&)
if (!(bstatus & 0x4)) {
// interrupt not from this device, ignore
dbgln_if(PATA_DEBUG, "BMIDEChannel: ignore interrupt");
return;
return false;
}
// 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);
@ -87,7 +87,7 @@ void BMIDEChannel::handle_irq(const RegisterState&)
if (!m_current_request) {
dbgln("BMIDEChannel: IRQ but no pending request!");
return;
return false;
}
if (status & ATA_SR_ERR) {
@ -96,10 +96,11 @@ void BMIDEChannel::handle_irq(const RegisterState&)
dbgln("BMIDEChannel: Error {:#02x}!", (u8)m_device_error);
try_disambiguate_error();
complete_current_request(AsyncDeviceRequest::Failure);
return;
return true;
}
m_device_error = 0;
complete_current_request(AsyncDeviceRequest::Success);
return true;
}
void BMIDEChannel::complete_current_request(AsyncDeviceRequest::RequestResult result)

View file

@ -39,7 +39,7 @@ private:
void complete_current_request(AsyncDeviceRequest::RequestResult);
//^ IRQHandler
virtual void handle_irq(const RegisterState&) override;
virtual bool handle_irq(const RegisterState&) override;
//* IDEChannel
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>();
@ -204,7 +204,7 @@ void IDEChannel::handle_irq(const RegisterState&)
if (!m_current_request) {
dbgln("IDEChannel: IRQ but no pending request!");
return;
return false;
}
if (status & ATA_SR_ERR) {
@ -213,7 +213,7 @@ void IDEChannel::handle_irq(const RegisterState&)
dbgln("IDEChannel: Error {:#02x}!", (u8)m_device_error);
try_disambiguate_error();
complete_current_request(AsyncDeviceRequest::Failure);
return;
return true;
}
m_device_error = 0;
@ -251,6 +251,7 @@ void IDEChannel::handle_irq(const RegisterState&)
}
}
});
return true;
}
static void io_delay()

View file

@ -122,7 +122,7 @@ protected:
IDEChannel(const IDEController&, IOAddressGroup, ChannelType type);
IDEChannel(const IDEController&, u8 irq, IOAddressGroup, ChannelType type);
//^ 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;