From 1405712f26cc6a92d65f886441908e33475ab814 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 7 Nov 2023 15:58:27 +0200 Subject: [PATCH] Kernel: Make PS/2 keyboard wait until interrupts are enabled --- kernel/include/kernel/Input/PS2Controller.h | 2 ++ kernel/include/kernel/Input/PS2Keyboard.h | 2 +- kernel/kernel/Input/PS2Controller.cpp | 12 +++++++++--- kernel/kernel/Input/PS2Keyboard.cpp | 6 +----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/kernel/include/kernel/Input/PS2Controller.h b/kernel/include/kernel/Input/PS2Controller.h index 0c75cf9a..e451313d 100644 --- a/kernel/include/kernel/Input/PS2Controller.h +++ b/kernel/include/kernel/Input/PS2Controller.h @@ -12,6 +12,8 @@ namespace Kernel::Input PS2Device(); virtual ~PS2Device() {} + virtual void send_initialize() = 0; + virtual BAN::StringView name() const override { return m_name; } private: diff --git a/kernel/include/kernel/Input/PS2Keyboard.h b/kernel/include/kernel/Input/PS2Keyboard.h index 4ee18922..e31ea716 100644 --- a/kernel/include/kernel/Input/PS2Keyboard.h +++ b/kernel/include/kernel/Input/PS2Keyboard.h @@ -28,13 +28,13 @@ namespace Kernel::Input public: static BAN::ErrorOr create(PS2Controller&); + virtual void send_initialize() override; virtual void handle_irq() override; virtual void update() override; private: PS2Keyboard(PS2Controller& controller); - BAN::ErrorOr initialize(); void append_command_queue(uint8_t); void append_command_queue(uint8_t, uint8_t); diff --git a/kernel/kernel/Input/PS2Controller.cpp b/kernel/kernel/Input/PS2Controller.cpp index 8c6c9d05..cf8eaae4 100644 --- a/kernel/kernel/Input/PS2Controller.cpp +++ b/kernel/kernel/Input/PS2Controller.cpp @@ -180,18 +180,24 @@ namespace Kernel::Input m_devices[0]->set_irq(PS2::IRQ::DEVICE0); m_devices[0]->enable_interrupt(); config |= PS2::Config::INTERRUPT_FIRST_PORT; - DevFileSystem::get().add_device(m_devices[0]); } if (m_devices[1]) { m_devices[1]->set_irq(PS2::IRQ::DEVICE1); m_devices[1]->enable_interrupt(); config |= PS2::Config::INTERRUPT_SECOND_PORT; - DevFileSystem::get().add_device(m_devices[1]); } 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 {}; } diff --git a/kernel/kernel/Input/PS2Keyboard.cpp b/kernel/kernel/Input/PS2Keyboard.cpp index e4f7a3d5..c2efe5bf 100644 --- a/kernel/kernel/Input/PS2Keyboard.cpp +++ b/kernel/kernel/Input/PS2Keyboard.cpp @@ -19,9 +19,6 @@ namespace Kernel::Input PS2Keyboard* keyboard = new PS2Keyboard(controller); if (keyboard == nullptr) return BAN::Error::from_errno(ENOMEM); - BAN::ScopeGuard guard([keyboard] { delete keyboard; }); - TRY(keyboard->initialize()); - guard.disable(); return keyboard; } @@ -69,12 +66,11 @@ namespace Kernel::Input } } - BAN::ErrorOr PS2Keyboard::initialize() + void PS2Keyboard::send_initialize() { append_command_queue(Command::SET_LEDS, 0x00); append_command_queue(Command::SCANCODE, PS2::KBScancode::SET_SCANCODE_SET2); append_command_queue(Command::ENABLE_SCANNING); - return {}; } void PS2Keyboard::update()