mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
Kernel: Move x86-specific HID code to the Arch/x86 directory
The i8042 controller with its attached devices, the PS2 keyboard and mouse, rely on x86-specific IO instructions to work. Therefore, move them to the Arch/x86 directory to make it easier to omit the handling code of these devices.
This commit is contained in:
parent
948be9674a
commit
c50a81e93e
11 changed files with 23 additions and 16 deletions
60
Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.cpp
Normal file
60
Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h>
|
||||
#include <Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h>
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<VMWareMouseDevice>> VMWareMouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
|
||||
{
|
||||
// FIXME: return the correct error
|
||||
if (!VMWareBackdoor::the())
|
||||
return Error::from_errno(EIO);
|
||||
if (!VMWareBackdoor::the()->vmmouse_is_absolute())
|
||||
return Error::from_errno(EIO);
|
||||
auto mouse_device = TRY(DeviceManagement::try_create_device<VMWareMouseDevice>(ps2_controller));
|
||||
TRY(mouse_device->initialize());
|
||||
return mouse_device;
|
||||
}
|
||||
|
||||
void VMWareMouseDevice::irq_handle_byte_read(u8)
|
||||
{
|
||||
auto backdoor = VMWareBackdoor::the();
|
||||
VERIFY(backdoor);
|
||||
VERIFY(backdoor->vmmouse_is_absolute());
|
||||
|
||||
// We will receive 4 bytes from the I8042 controller that we are going to
|
||||
// ignore. Instead, we will check with VMWareBackdoor to see how many bytes
|
||||
// of mouse event data are waiting for us. For each multiple of 4, we
|
||||
// produce a mouse packet.
|
||||
constexpr u8 max_iterations = 128;
|
||||
u8 current_iteration = 0;
|
||||
while (++current_iteration < max_iterations) {
|
||||
auto number_of_mouse_event_bytes = backdoor->read_mouse_status_queue_size();
|
||||
if (number_of_mouse_event_bytes == 0)
|
||||
break;
|
||||
VERIFY(number_of_mouse_event_bytes % 4 == 0);
|
||||
|
||||
auto mouse_packet = backdoor->receive_mouse_packet();
|
||||
m_entropy_source.add_random_event(mouse_packet);
|
||||
{
|
||||
SpinlockLocker lock(m_queue_lock);
|
||||
m_queue.enqueue(mouse_packet);
|
||||
}
|
||||
}
|
||||
evaluate_block_conditions();
|
||||
}
|
||||
|
||||
VMWareMouseDevice::VMWareMouseDevice(I8042Controller const& ps2_controller)
|
||||
: PS2MouseDevice(ps2_controller)
|
||||
{
|
||||
}
|
||||
VMWareMouseDevice::~VMWareMouseDevice() = default;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue