From 0379742d7ee7a8ca7cce54ad1fe587fa7a5c0f90 Mon Sep 17 00:00:00 2001 From: Liav A Date: Thu, 13 Apr 2023 11:06:52 +0300 Subject: [PATCH] Kernel: Add boot parameter to determine i8042 first port translation This can be used mainly for bare metal hardware, if the user experiences problems with output from the PS2 keyboard. --- Base/usr/share/man/man7/boot_parameters.md | 4 ++++ Kernel/Boot/CommandLine.cpp | 10 ++++++++++ Kernel/Boot/CommandLine.h | 1 + Kernel/Devices/HID/Management.cpp | 3 ++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Base/usr/share/man/man7/boot_parameters.md b/Base/usr/share/man/man7/boot_parameters.md index 6ecda181fa..0f77ab50a3 100644 --- a/Base/usr/share/man/man7/boot_parameters.md +++ b/Base/usr/share/man/man7/boot_parameters.md @@ -67,6 +67,10 @@ has set up before booting the Kernel, don't initialize any driver. **`none`** - Assume there's no i8042 controller in the system. **`force`** - Assume there's i8042 controller in the system. +* **`i8042_first_port_translation`** - This parameter expects **`on`** or **`off`** and is by default set to **`off`**. + When set to **`off`**, the kernel will not enable first PS2 port translation. + When set to **`on`**, the kernel will enable first PS2 port translation. + * **`panic`** - This parameter expects **`halt`** or **`shutdown`**. This is particularly useful in CI contexts. * **`pci`** - This parameter expects **`ecam`**, **`io`** or **`none`**. When selecting **`none`** diff --git a/Kernel/Boot/CommandLine.cpp b/Kernel/Boot/CommandLine.cpp index c5babbb8d3..221191eef5 100644 --- a/Kernel/Boot/CommandLine.cpp +++ b/Kernel/Boot/CommandLine.cpp @@ -131,6 +131,16 @@ UNMAP_AFTER_INIT bool CommandLine::is_early_boot_console_disabled() const PANIC("Unknown early_boot_console setting: {}", value); } +UNMAP_AFTER_INIT bool CommandLine::i8042_enable_first_port_translation() const +{ + auto value = lookup("i8042_first_port_translation"sv).value_or("off"sv); + if (value == "off"sv) + return false; + if (value == "on"sv) + return true; + PANIC("Unknown i8042_enable_first_port_translation setting: {}", value); +} + UNMAP_AFTER_INIT I8042PresenceMode CommandLine::i8042_presence_mode() const { auto value = lookup("i8042_presence_mode"sv).value_or("auto"sv); diff --git a/Kernel/Boot/CommandLine.h b/Kernel/Boot/CommandLine.h index 180ddda392..35fd26e7d8 100644 --- a/Kernel/Boot/CommandLine.h +++ b/Kernel/Boot/CommandLine.h @@ -82,6 +82,7 @@ public: [[nodiscard]] bool is_pci_disabled() const; [[nodiscard]] bool is_legacy_time_enabled() const; [[nodiscard]] bool is_pc_speaker_enabled() const; + [[nodiscard]] bool i8042_enable_first_port_translation() const; [[nodiscard]] GraphicsSubsystemMode graphics_subsystem_mode() const; [[nodiscard]] I8042PresenceMode i8042_presence_mode() const; [[nodiscard]] bool is_force_pio() const; diff --git a/Kernel/Devices/HID/Management.cpp b/Kernel/Devices/HID/Management.cpp index 912302abdc..10c6119dfc 100644 --- a/Kernel/Devices/HID/Management.cpp +++ b/Kernel/Devices/HID/Management.cpp @@ -167,7 +167,8 @@ UNMAP_AFTER_INIT ErrorOr HIDManagement::enumerate() // Note: If we happen to not have i8042 just return "gracefully" for now. if (!has_i8042_controller) return {}; - if (auto result_or_error = i8042_controller->detect_devices(I8042Controller::EnableKeyboardFirstPortTranslation::No); result_or_error.is_error()) + auto i8042_enable_first_port_translation = kernel_command_line().i8042_enable_first_port_translation() ? I8042Controller::EnableKeyboardFirstPortTranslation::Yes : I8042Controller::EnableKeyboardFirstPortTranslation::No; + if (auto result_or_error = i8042_controller->detect_devices(i8042_enable_first_port_translation); result_or_error.is_error()) return {}; m_hid_serial_io_controllers.with([&](auto& list) { list.append(i8042_controller);