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

@ -129,25 +129,26 @@ UNMAP_AFTER_INIT void I8042Controller::detect_devices()
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());
u8 status = IO::in8(I8042_STATUS);
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;
u8 byte = IO::in8(I8042_BUFFER);
if (data_for_device == HIDDevice::Type::Mouse) {
VERIFY(m_mouse_device);
static_cast<PS2MouseDevice&>(*m_mouse_device).irq_handle_byte_read(byte);
return;
return true;
}
if (data_for_device == HIDDevice::Type::Keyboard) {
VERIFY(m_keyboard_device);
static_cast<PS2KeyboardDevice&>(*m_keyboard_device).irq_handle_byte_read(byte);
return;
return true;
}
return false;
}
void I8042Controller::do_drain()

View file

@ -89,7 +89,7 @@ public:
void prepare_for_output();
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<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
// 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)

View file

@ -39,7 +39,7 @@ private:
explicit PS2KeyboardDevice(const I8042Controller&);
// ^IRQHandler
virtual void handle_irq(const RegisterState&) override;
virtual bool handle_irq(const RegisterState&) override;
// ^CharacterDevice
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
// 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)

View file

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