From d276cac82cbb7380eca2a68b57731f9c380ad6b8 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 12 May 2023 17:23:02 +0300 Subject: [PATCH] Kernel: Re-organize the abstractions around i8042, PS2 and HID concepts The HIDController class is removed and instead adding SerialIOController class. The HIDController class was a mistake - there's no such thing in real hardware as host controller only for human interface devices (VirtIO PCI input controller being the exception here, but it could be technically treated as serial IO controller too). Instead, we simply add a new abstraction layer - the SerialIO "bus", which will hold all the code that is related to serial communications with other devices. A PS2 controller is simply a serial IO controller, and the Intel 8042 Controller is simply a specific implementation of a PS2 controller. --- Kernel/Arch/x86_64/ISABus/I8042Controller.h | 3 +- Kernel/Bus/SerialIO/Controller.h | 32 +++++++++++++++++++++ Kernel/Devices/HID/Controller.h | 30 ------------------- Kernel/Devices/HID/Management.cpp | 2 +- Kernel/Devices/HID/Management.h | 4 +-- 5 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 Kernel/Bus/SerialIO/Controller.h delete mode 100644 Kernel/Devices/HID/Controller.h diff --git a/Kernel/Arch/x86_64/ISABus/I8042Controller.h b/Kernel/Arch/x86_64/ISABus/I8042Controller.h index bbb349a7782..0837defb3bd 100644 --- a/Kernel/Arch/x86_64/ISABus/I8042Controller.h +++ b/Kernel/Arch/x86_64/ISABus/I8042Controller.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -96,7 +97,7 @@ protected: class PS2KeyboardDevice; class PS2MouseDevice; class HIDManagement; -class I8042Controller final : public HIDController { +class I8042Controller final : public SerialIOController { friend class PS2KeyboardDevice; friend class PS2MouseDevice; diff --git a/Kernel/Bus/SerialIO/Controller.h b/Kernel/Bus/SerialIO/Controller.h new file mode 100644 index 00000000000..8c357e4337d --- /dev/null +++ b/Kernel/Bus/SerialIO/Controller.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023, Liav A. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace Kernel { + +class HIDManagement; +class SerialIOController : public AtomicRefCounted { + friend class HIDManagement; + +public: + virtual ~SerialIOController() = default; + +protected: + SerialIOController() = default; + +private: + IntrusiveListNode> m_list_node; +}; + +} diff --git a/Kernel/Devices/HID/Controller.h b/Kernel/Devices/HID/Controller.h deleted file mode 100644 index be11bc056da..00000000000 --- a/Kernel/Devices/HID/Controller.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include - -namespace Kernel { - -class HIDManagement; -class HIDController : public AtomicRefCounted { - friend class HIDManagement; - -public: - virtual ~HIDController() = default; - -protected: - HIDController() = default; - -private: - IntrusiveListNode> m_list_node; -}; - -} diff --git a/Kernel/Devices/HID/Management.cpp b/Kernel/Devices/HID/Management.cpp index 970a4cee472..d1fcf6a6b77 100644 --- a/Kernel/Devices/HID/Management.cpp +++ b/Kernel/Devices/HID/Management.cpp @@ -155,7 +155,7 @@ UNMAP_AFTER_INIT ErrorOr HIDManagement::enumerate() return {}; if (auto result_or_error = i8042_controller->detect_devices(); result_or_error.is_error()) return {}; - m_hid_controllers.with([&](auto& list) { + m_hid_serial_io_controllers.with([&](auto& list) { list.append(i8042_controller); }); #endif diff --git a/Kernel/Devices/HID/Management.h b/Kernel/Devices/HID/Management.h index 0dae995cd15..1a64ffcda6a 100644 --- a/Kernel/Devices/HID/Management.h +++ b/Kernel/Devices/HID/Management.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -60,7 +60,7 @@ private: size_t m_keyboard_minor_number { 0 }; KeyboardClient* m_client { nullptr }; - SpinlockProtected, LockRank::None> m_hid_controllers; + SpinlockProtected, LockRank::None> m_hid_serial_io_controllers; Spinlock m_client_lock; };