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.
This commit is contained in:
Liav A 2023-05-12 17:23:02 +03:00 committed by Andrew Kaster
parent a14dc9b569
commit d276cac82c
5 changed files with 37 additions and 34 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Types.h>
#include <Kernel/Bus/SerialIO/Controller.h>
#include <Kernel/Devices/HID/Controller.h>
#include <Kernel/Devices/HID/KeyboardDevice.h>
#include <Kernel/Devices/HID/MouseDevice.h>
@ -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;

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h>
#include <AK/IntrusiveList.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
namespace Kernel {
class HIDManagement;
class SerialIOController : public AtomicRefCounted<SerialIOController> {
friend class HIDManagement;
public:
virtual ~SerialIOController() = default;
protected:
SerialIOController() = default;
private:
IntrusiveListNode<SerialIOController, NonnullRefPtr<SerialIOController>> m_list_node;
};
}

View file

@ -1,30 +0,0 @@
/*
* 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>
#include <AK/NonnullRefPtr.h>
#include <AK/RefPtr.h>
namespace Kernel {
class HIDManagement;
class HIDController : public AtomicRefCounted<HIDController> {
friend class HIDManagement;
public:
virtual ~HIDController() = default;
protected:
HIDController() = default;
private:
IntrusiveListNode<HIDController, NonnullRefPtr<HIDController>> m_list_node;
};
}

View file

@ -155,7 +155,7 @@ UNMAP_AFTER_INIT ErrorOr<void> 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

View file

@ -14,7 +14,7 @@
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/API/KeyCode.h>
#include <Kernel/Devices/HID/Controller.h>
#include <Kernel/Bus/SerialIO/Controller.h>
#include <Kernel/Locking/Spinlock.h>
#include <Kernel/Locking/SpinlockProtected.h>
#include <Kernel/UnixTypes.h>
@ -60,7 +60,7 @@ private:
size_t m_keyboard_minor_number { 0 };
KeyboardClient* m_client { nullptr };
SpinlockProtected<IntrusiveList<&HIDController::m_list_node>, LockRank::None> m_hid_controllers;
SpinlockProtected<IntrusiveList<&SerialIOController::m_list_node>, LockRank::None> m_hid_serial_io_controllers;
Spinlock<LockRank::None> m_client_lock;
};