Ver Fonte

Kernel: Add CommandLine option to disable or enable the PC speaker

By default, we disable the PC speaker as it's quite annoying when using
the text mode console.
Liav A há 3 anos atrás
pai
commit
69f054616d

+ 2 - 0
Base/usr/share/man/man7/boot_parameters.md

@@ -60,6 +60,8 @@ List of options:
 
 * **`root`** - This parameter configures the device to use as the root file system. It defaults to **`/dev/hda`** if unspecified.
 
+* **`pcspeaker`** - This parameter controls whether the kernel can use the PC speaker or not. It defaults to **`off`** and can be set to **`on`** to enable the PC speaker.
+
 * **`smp`** - This parameter expects a binary value of **`on`** or **`off`**. If enabled kernel will
   enable available APs (application processors) and use them with the BSP (Bootstrap processor) to
   schedule and run threads.

+ 10 - 0
Kernel/CommandLine.cpp

@@ -155,6 +155,16 @@ UNMAP_AFTER_INIT bool CommandLine::is_legacy_time_enabled() const
     return lookup("time"sv).value_or("modern"sv) == "legacy"sv;
 }
 
+bool CommandLine::is_pc_speaker_enabled() const
+{
+    auto value = lookup("pcspeaker"sv).value_or("off"sv);
+    if (value == "on"sv)
+        return true;
+    if (value == "off"sv)
+        return false;
+    PANIC("Unknown pcspeaker setting: {}", value);
+}
+
 UNMAP_AFTER_INIT bool CommandLine::is_force_pio() const
 {
     return contains("force_pio"sv);

+ 1 - 0
Kernel/CommandLine.h

@@ -71,6 +71,7 @@ public:
     [[nodiscard]] bool is_vmmouse_enabled() const;
     [[nodiscard]] PCIAccessLevel pci_access_level() const;
     [[nodiscard]] bool is_legacy_time_enabled() const;
+    [[nodiscard]] bool is_pc_speaker_enabled() const;
     [[nodiscard]] FrameBufferDevices are_framebuffer_devices_enabled() const;
     [[nodiscard]] bool is_force_pio() const;
     [[nodiscard]] AcpiFeatureLevel acpi_feature_level() const;

+ 3 - 0
Kernel/Syscalls/beep.cpp

@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <Kernel/CommandLine.h>
 #include <Kernel/Devices/PCSpeaker.h>
 #include <Kernel/Process.h>
 
@@ -12,6 +13,8 @@ namespace Kernel {
 ErrorOr<FlatPtr> Process::sys$beep()
 {
     VERIFY_NO_PROCESS_BIG_LOCK(this);
+    if (!kernel_command_line().is_pc_speaker_enabled())
+        return ENODEV;
     PCSpeaker::tone_on(440);
     auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000));
     PCSpeaker::tone_off();

+ 3 - 0
Kernel/TTY/VirtualConsole.cpp

@@ -7,6 +7,7 @@
  */
 
 #include <AK/StdLibExtras.h>
+#include <Kernel/CommandLine.h>
 #include <Kernel/Debug.h>
 #include <Kernel/Devices/DeviceManagement.h>
 #include <Kernel/Devices/HID/HIDManagement.h>
@@ -321,6 +322,8 @@ void VirtualConsole::flush_dirty_lines()
 
 void VirtualConsole::beep()
 {
+    if (!kernel_command_line().is_pc_speaker_enabled())
+        return;
     PCSpeaker::tone_on(440);
     IO::delay(10000);
     PCSpeaker::tone_off();