Kernel: Move PS/2 command queue to controller instead of device
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/CircularQueue.h>
|
||||
#include <BAN/UniqPtr.h>
|
||||
#include <kernel/Device/Device.h>
|
||||
#include <kernel/Input/PS2/Config.h>
|
||||
@@ -17,19 +18,17 @@ namespace Kernel::Input
|
||||
static BAN::ErrorOr<void> initialize();
|
||||
static PS2Controller& get();
|
||||
|
||||
BAN::ErrorOr<void> device_send_byte(PS2Device* device, uint8_t byte);
|
||||
|
||||
[[nodiscard]] bool lock_command(PS2Device*);
|
||||
void unlock_command(PS2Device*);
|
||||
bool append_command_queue(PS2Device*, uint8_t command, uint8_t response_size);
|
||||
bool append_command_queue(PS2Device*, uint8_t command, uint8_t data, uint8_t response_size);
|
||||
void update_command_queue();
|
||||
// Returns true, if byte is used as command, if returns false, byte is meant to device
|
||||
bool handle_command_byte(PS2Device*, uint8_t);
|
||||
|
||||
private:
|
||||
PS2Controller() = default;
|
||||
BAN::ErrorOr<void> initialize_impl();
|
||||
BAN::ErrorOr<void> initialize_device(uint8_t);
|
||||
|
||||
BAN::ErrorOr<void> reset_device(uint8_t);
|
||||
BAN::ErrorOr<void> set_scanning(uint8_t, bool);
|
||||
|
||||
BAN::ErrorOr<uint8_t> read_byte();
|
||||
BAN::ErrorOr<void> send_byte(uint16_t port, uint8_t byte);
|
||||
|
||||
@@ -37,14 +36,31 @@ namespace Kernel::Input
|
||||
BAN::ErrorOr<void> send_command(PS2::Command command, uint8_t data);
|
||||
|
||||
BAN::ErrorOr<void> device_send_byte(uint8_t device_index, uint8_t byte);
|
||||
BAN::ErrorOr<void> device_read_ack(uint8_t device_index);
|
||||
BAN::ErrorOr<void> device_send_byte_and_wait_ack(uint8_t device_index, uint8_t byte);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
enum class State : uint8_t
|
||||
{
|
||||
NotSent,
|
||||
Sending,
|
||||
WaitingAck,
|
||||
WaitingResponse,
|
||||
};
|
||||
State state;
|
||||
uint8_t device_index;
|
||||
uint8_t out_data[2];
|
||||
uint8_t out_count;
|
||||
uint8_t in_count;
|
||||
uint8_t send_index;
|
||||
};
|
||||
|
||||
private:
|
||||
BAN::RefPtr<PS2Device> m_devices[2];
|
||||
RecursiveSpinLock m_lock;
|
||||
|
||||
PS2Device* m_executing_device { nullptr };
|
||||
PS2Device* m_pending_device { nullptr };
|
||||
BAN::CircularQueue<Command, 128> m_command_queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/CircularQueue.h>
|
||||
#include <kernel/Input/PS2/Controller.h>
|
||||
#include <kernel/InterruptController.h>
|
||||
|
||||
@@ -20,39 +19,16 @@ namespace Kernel::Input
|
||||
virtual void handle_irq() final override;
|
||||
|
||||
virtual void handle_byte(uint8_t) = 0;
|
||||
virtual void handle_device_command_response(uint8_t) = 0;
|
||||
|
||||
virtual BAN::StringView name() const final override { return m_name; }
|
||||
virtual dev_t rdev() const final override { return m_rdev; }
|
||||
|
||||
private:
|
||||
void update_command();
|
||||
|
||||
private:
|
||||
enum class State
|
||||
{
|
||||
Normal,
|
||||
WaitingAck,
|
||||
WaitingResponse,
|
||||
};
|
||||
|
||||
struct Command
|
||||
{
|
||||
uint8_t out_data[2];
|
||||
uint8_t out_count;
|
||||
uint8_t in_count;
|
||||
uint8_t send_index;
|
||||
};
|
||||
virtual void update() final override { m_controller.update_command_queue(); }
|
||||
|
||||
private:
|
||||
const BAN::String m_name;
|
||||
const dev_t m_rdev;
|
||||
|
||||
PS2Controller& m_controller;
|
||||
State m_state = State::Normal;
|
||||
BAN::CircularQueue<Command, 10> m_command_queue;
|
||||
|
||||
friend class PS2Controller;
|
||||
PS2Controller& m_controller;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Kernel::Input
|
||||
virtual void send_initialize() override;
|
||||
|
||||
virtual void handle_byte(uint8_t) final override;
|
||||
virtual void handle_device_command_response(uint8_t) final override;
|
||||
|
||||
private:
|
||||
PS2Keyboard(PS2Controller& controller);
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace Kernel::Input
|
||||
virtual void send_initialize() override;
|
||||
|
||||
virtual void handle_byte(uint8_t) final override;
|
||||
virtual void handle_device_command_response(uint8_t) final override;
|
||||
|
||||
private:
|
||||
PS2Mouse(PS2Controller& controller);
|
||||
|
||||
Reference in New Issue
Block a user