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.
This commit is contained in:
Liav A 2022-12-20 06:56:19 +02:00 committed by Jelle Raaijmakers
parent 6c4a47d916
commit d76c08c9b0
Notes: sideshowbarker 2024-07-17 05:19:06 +09:00
5 changed files with 39 additions and 25 deletions

View file

@ -19,15 +19,6 @@ UNMAP_AFTER_INIT NonnullLockRefPtr<I8042Controller> I8042Controller::initialize(
return adopt_lock_ref(*new I8042Controller());
}
LockRefPtr<MouseDevice> I8042Controller::mouse() const
{
return m_mouse_device;
}
LockRefPtr<KeyboardDevice> I8042Controller::keyboard() const
{
return m_keyboard_device;
}
UNMAP_AFTER_INIT I8042Controller::I8042Controller()
{
}

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/AtomicRefCounted.h>
#include <Kernel/Devices/HID/Controller.h>
#include <Kernel/Devices/HID/KeyboardDevice.h>
#include <Kernel/Devices/HID/MouseDevice.h>
#include <Kernel/Locking/Spinlock.h>
@ -84,7 +85,7 @@ protected:
class PS2KeyboardDevice;
class PS2MouseDevice;
class HIDManagement;
class I8042Controller final : public AtomicRefCounted<I8042Controller> {
class I8042Controller final : public HIDController {
friend class PS2KeyboardDevice;
friend class PS2MouseDevice;
@ -133,9 +134,6 @@ public:
bool irq_process_input_buffer(HIDDevice::Type);
LockRefPtr<MouseDevice> mouse() const;
LockRefPtr<KeyboardDevice> keyboard() const;
// Note: This function exists only for the initialization process of the controller
bool check_existence_via_probing(Badge<HIDManagement>);

View file

@ -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;
};
}

View file

@ -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 {};
}

View file

@ -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 {