1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

Kernel: Convert i8042 code to use the ErrorOr pattern more broadly

Not only does it makes the code more robust and correct as it allows
error propagation, it allows us to enforce timeouts on waiting loops so
we don't hang forever, by waiting for the i8042 controller to respond to
us.

Therefore, it makes the i8042 more resilient against faulty hardware and
bad behaving chipsets out there.
This commit is contained in:
Liav A 2022-02-10 10:50:37 +02:00 committed by Idan Horowitz
parent dc41a0b830
commit 41dae9b3c7
4 changed files with 117 additions and 81 deletions

View file

@ -99,30 +99,36 @@ void HIDManagement::set_maps(NonnullOwnPtr<KString> character_map_name, Keyboard
dbgln("New Character map '{}' passed in by client.", m_character_map_name);
}
UNMAP_AFTER_INIT void HIDManagement::enumerate()
UNMAP_AFTER_INIT ErrorOr<void> HIDManagement::enumerate()
{
// FIXME: When we have USB HID support, we should ensure that we disable
// emulation of the PS/2 controller if it was set by the BIOS.
// If ACPI indicates we have an i8042 controller and the USB controller was
// set to emulate PS/2, we should not initialize the PS/2 controller.
if (kernel_command_line().disable_ps2_controller())
return;
return {};
if (ACPI::Parser::the() && !ACPI::Parser::the()->have_8042())
return;
return {};
m_i8042_controller = I8042Controller::initialize();
m_i8042_controller->detect_devices();
// Note: If we happen to not have i8042 just return "gracefully" for now.
if (!m_i8042_controller->check_existence({}))
return {};
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());
return {};
}
UNMAP_AFTER_INIT void HIDManagement::initialize()
{
VERIFY(!s_the.is_initialized());
s_the.ensure_instance();
s_the->enumerate();
// FIXME: Propagate errors back to init to deal with them.
MUST(s_the->enumerate());
}
HIDManagement& HIDManagement::the()