summaryrefslogtreecommitdiff
path: root/Kernel/Devices/PS2MouseDevice.h
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-11-07 12:09:28 -0700
committerAndreas Kling <kling@serenityos.org>2020-11-12 18:04:16 +0100
commit91db31880faae9526693670bb76e186a59959887 (patch)
tree0453afba372b24ffee9489700888bf4922810e42 /Kernel/Devices/PS2MouseDevice.h
parente1c27c16d8d513578892ce78697a03dd912091bb (diff)
downloadserenity-91db31880faae9526693670bb76e186a59959887.zip
Kernel: Add I8042Controller to detect and manage PS/2 devices
Rework the PS/2 keyboard and mouse drivers to use a common 8042 controller driver. Also, reset and reconfigure the 8042 controller as they are not guaranteed to be in the state that we expect.
Diffstat (limited to 'Kernel/Devices/PS2MouseDevice.h')
-rw-r--r--Kernel/Devices/PS2MouseDevice.h43
1 files changed, 27 insertions, 16 deletions
diff --git a/Kernel/Devices/PS2MouseDevice.h b/Kernel/Devices/PS2MouseDevice.h
index 045537e5d5..de555dbc07 100644
--- a/Kernel/Devices/PS2MouseDevice.h
+++ b/Kernel/Devices/PS2MouseDevice.h
@@ -29,20 +29,23 @@
#include <AK/CircularQueue.h>
#include <Kernel/API/MousePacket.h>
#include <Kernel/Devices/CharacterDevice.h>
+#include <Kernel/Devices/I8042Controller.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Random.h>
namespace Kernel {
class PS2MouseDevice final : public IRQHandler
- , public CharacterDevice {
+ , public CharacterDevice
+ , public I8042Device {
public:
PS2MouseDevice();
virtual ~PS2MouseDevice() override;
- static void create();
static PS2MouseDevice& the();
+ bool initialize();
+
// ^CharacterDevice
virtual bool can_read(const FileDescription&, size_t) const override;
virtual KResultOr<size_t> read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override;
@@ -51,6 +54,13 @@ public:
virtual const char* purpose() const override { return class_name(); }
+ // ^I8042Device
+ virtual void irq_handle_byte_read(u8 byte) override;
+ virtual void enable_interrupts() override
+ {
+ enable_irq();
+ }
+
private:
// ^IRQHandler
void handle_vmmouse_absolute_pointer();
@@ -59,24 +69,25 @@ private:
// ^CharacterDevice
virtual const char* class_name() const override { return "PS2MouseDevice"; }
- void initialize();
- void check_device_presence();
- void initialize_device();
- void prepare_for_input();
- void prepare_for_output();
- void mouse_write(u8);
- u8 mouse_read();
- void wait_then_write(u8 port, u8 data);
- u8 wait_then_read(u8 port);
- void parse_data_packet();
- void expect_ack();
+ struct RawPacket {
+ union {
+ u32 dword;
+ u8 bytes[4];
+ };
+ };
+
+ u8 read_from_device();
+ u8 send_command(u8 command);
+ u8 send_command(u8 command, u8 data);
+ MousePacket parse_data_packet(const RawPacket&);
void set_sample_rate(u8);
u8 get_device_id();
- bool m_device_present { false };
- CircularQueue<MousePacket, 100> m_queue;
+ I8042Controller& m_controller;
+ mutable SpinLock<u8> m_queue_lock;
+ CircularQueue<RawPacket, 100> m_queue;
u8 m_data_state { 0 };
- u8 m_data[4];
+ RawPacket m_data;
bool m_has_wheel { false };
bool m_has_five_buttons { false };
EntropySource m_entropy_source;