diff options
author | Liav A <liavalb@gmail.com> | 2022-12-20 06:56:19 +0200 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-04-09 18:11:37 +0200 |
commit | d76c08c9b0e2743e752a182fc1cd9a48667bf23c (patch) | |
tree | 5bf64cbe888574539c3bde1e6d3f841087736180 /Kernel/Devices | |
parent | 6c4a47d916d2eff1d7c9bd7657609c213f5d7e26 (diff) | |
download | serenity-d76c08c9b0e2743e752a182fc1cd9a48667bf23c.zip |
Kernel: Introduce a new super class called HIDController
Use the new class in HID code, because all other HID device controllers
will be using this class as their parent class.
Hence, we no longer keep a reference to any PS/2 device in HIDManagement
and rely on HIDController derived classes to do this for us.
It also means that we removed another instance of a LockRefPtr, which
is designated to be removed and is replaced by the better pattern of
SpinlockProtected<RefPtr<>> instead.
Diffstat (limited to 'Kernel/Devices')
-rw-r--r-- | Kernel/Devices/HID/Controller.h | 28 | ||||
-rw-r--r-- | Kernel/Devices/HID/Management.cpp | 12 | ||||
-rw-r--r-- | Kernel/Devices/HID/Management.h | 9 |
3 files changed, 37 insertions, 12 deletions
diff --git a/Kernel/Devices/HID/Controller.h b/Kernel/Devices/HID/Controller.h new file mode 100644 index 0000000000..1d8868297c --- /dev/null +++ b/Kernel/Devices/HID/Controller.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/AtomicRefCounted.h> +#include <AK/IntrusiveList.h> + +namespace Kernel { + +class HIDManagement; +class HIDController : public AtomicRefCounted<HIDController> { + friend class HIDManagement; + +public: + virtual ~HIDController() = default; + +protected: + HIDController() = default; + +private: + IntrusiveListNode<HIDController, NonnullLockRefPtr<HIDController>> m_list_node; +}; + +} diff --git a/Kernel/Devices/HID/Management.cpp b/Kernel/Devices/HID/Management.cpp index 8338b6cf86..9c7be9ca5d 100644 --- a/Kernel/Devices/HID/Management.cpp +++ b/Kernel/Devices/HID/Management.cpp @@ -152,13 +152,11 @@ UNMAP_AFTER_INIT ErrorOr<void> HIDManagement::enumerate() // Note: If we happen to not have i8042 just return "gracefully" for now. if (!has_i8042_controller) return {}; - m_i8042_controller = i8042_controller; - TRY(m_i8042_controller->detect_devices()); - if (m_i8042_controller->mouse()) - m_hid_devices.append(m_i8042_controller->mouse().release_nonnull()); - - if (m_i8042_controller->keyboard()) - m_hid_devices.append(m_i8042_controller->keyboard().release_nonnull()); + if (auto result_or_error = i8042_controller->detect_devices(); result_or_error.is_error()) + return {}; + m_hid_controllers.with([&](auto& list) { + list.append(i8042_controller); + }); #endif return {}; } diff --git a/Kernel/Devices/HID/Management.h b/Kernel/Devices/HID/Management.h index c1acb1f6be..d55eb0d724 100644 --- a/Kernel/Devices/HID/Management.h +++ b/Kernel/Devices/HID/Management.h @@ -12,6 +12,7 @@ #include <AK/Types.h> #include <Kernel/API/KeyCode.h> #include <Kernel/API/MousePacket.h> +#include <Kernel/Devices/HID/Controller.h> #include <Kernel/Devices/HID/Device.h> #include <Kernel/Forward.h> #include <Kernel/Library/LockRefPtr.h> @@ -61,11 +62,9 @@ private: size_t m_mouse_minor_number { 0 }; size_t m_keyboard_minor_number { 0 }; KeyboardClient* m_client { nullptr }; -#if ARCH(X86_64) - LockRefPtr<I8042Controller> m_i8042_controller; -#endif - Vector<NonnullLockRefPtr<HIDDevice>> m_hid_devices; - Spinlock<LockRank::None> m_client_lock {}; + + SpinlockProtected<IntrusiveList<&HIDController::m_list_node>, LockRank::None> m_hid_controllers; + Spinlock<LockRank::None> m_client_lock; }; class KeyboardClient { |