Kernel: Make PS/2 keyboard wait until interrupts are enabled

This commit is contained in:
Bananymous 2023-11-07 15:58:27 +02:00
parent 670c787af3
commit 6d4b684219
4 changed files with 13 additions and 9 deletions

View File

@ -12,6 +12,8 @@ namespace Kernel::Input
PS2Device(); PS2Device();
virtual ~PS2Device() {} virtual ~PS2Device() {}
virtual void send_initialize() = 0;
virtual BAN::StringView name() const override { return m_name; } virtual BAN::StringView name() const override { return m_name; }
private: private:

View File

@ -28,13 +28,13 @@ namespace Kernel::Input
public: public:
static BAN::ErrorOr<PS2Keyboard*> create(PS2Controller&); static BAN::ErrorOr<PS2Keyboard*> create(PS2Controller&);
virtual void send_initialize() override;
virtual void handle_irq() override; virtual void handle_irq() override;
virtual void update() override; virtual void update() override;
private: private:
PS2Keyboard(PS2Controller& controller); PS2Keyboard(PS2Controller& controller);
BAN::ErrorOr<void> initialize();
void append_command_queue(uint8_t); void append_command_queue(uint8_t);
void append_command_queue(uint8_t, uint8_t); void append_command_queue(uint8_t, uint8_t);

View File

@ -180,18 +180,24 @@ namespace Kernel::Input
m_devices[0]->set_irq(PS2::IRQ::DEVICE0); m_devices[0]->set_irq(PS2::IRQ::DEVICE0);
m_devices[0]->enable_interrupt(); m_devices[0]->enable_interrupt();
config |= PS2::Config::INTERRUPT_FIRST_PORT; config |= PS2::Config::INTERRUPT_FIRST_PORT;
DevFileSystem::get().add_device(m_devices[0]);
} }
if (m_devices[1]) if (m_devices[1])
{ {
m_devices[1]->set_irq(PS2::IRQ::DEVICE1); m_devices[1]->set_irq(PS2::IRQ::DEVICE1);
m_devices[1]->enable_interrupt(); m_devices[1]->enable_interrupt();
config |= PS2::Config::INTERRUPT_SECOND_PORT; config |= PS2::Config::INTERRUPT_SECOND_PORT;
DevFileSystem::get().add_device(m_devices[1]);
} }
controller_send_command(PS2::Command::WRITE_CONFIG, config); controller_send_command(PS2::Command::WRITE_CONFIG, config);
for (uint8_t device = 0; device < 2; device++)
{
if (m_devices[device] == nullptr)
continue;
m_devices[device]->send_initialize();
DevFileSystem::get().add_device(m_devices[device]);
}
return {}; return {};
} }

View File

@ -19,9 +19,6 @@ namespace Kernel::Input
PS2Keyboard* keyboard = new PS2Keyboard(controller); PS2Keyboard* keyboard = new PS2Keyboard(controller);
if (keyboard == nullptr) if (keyboard == nullptr)
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
BAN::ScopeGuard guard([keyboard] { delete keyboard; });
TRY(keyboard->initialize());
guard.disable();
return keyboard; return keyboard;
} }
@ -69,12 +66,11 @@ namespace Kernel::Input
} }
} }
BAN::ErrorOr<void> PS2Keyboard::initialize() void PS2Keyboard::send_initialize()
{ {
append_command_queue(Command::SET_LEDS, 0x00); append_command_queue(Command::SET_LEDS, 0x00);
append_command_queue(Command::SCANCODE, PS2::KBScancode::SET_SCANCODE_SET2); append_command_queue(Command::SCANCODE, PS2::KBScancode::SET_SCANCODE_SET2);
append_command_queue(Command::ENABLE_SCANNING); append_command_queue(Command::ENABLE_SCANNING);
return {};
} }
void PS2Keyboard::update() void PS2Keyboard::update()