2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2021-05-21 17:42:33 +00:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-04-08 11:54:44 +00:00
|
|
|
#include <Kernel/CommandLine.h>
|
2021-03-03 08:51:55 +00:00
|
|
|
#include <Kernel/Panic.h>
|
2021-06-22 15:40:16 +00:00
|
|
|
#include <Kernel/Sections.h>
|
2020-08-25 01:35:27 +00:00
|
|
|
#include <Kernel/StdLib.h>
|
2019-06-04 10:54:27 +00:00
|
|
|
|
2020-04-08 11:54:44 +00:00
|
|
|
namespace Kernel {
|
2019-06-04 10:54:27 +00:00
|
|
|
|
2020-08-25 01:35:27 +00:00
|
|
|
static char s_cmd_line[1024];
|
2021-05-21 17:42:33 +00:00
|
|
|
static constexpr StringView s_embedded_cmd_line = "";
|
2020-04-08 11:54:44 +00:00
|
|
|
static CommandLine* s_the;
|
|
|
|
|
2021-02-19 20:29:46 +00:00
|
|
|
UNMAP_AFTER_INIT void CommandLine::early_initialize(const char* cmd_line)
|
2020-08-25 01:35:27 +00:00
|
|
|
{
|
|
|
|
if (!cmd_line)
|
|
|
|
return;
|
|
|
|
size_t length = strlen(cmd_line);
|
|
|
|
if (length >= sizeof(s_cmd_line))
|
2020-09-18 07:49:51 +00:00
|
|
|
length = sizeof(s_cmd_line) - 1;
|
2020-08-25 01:35:27 +00:00
|
|
|
memcpy(s_cmd_line, cmd_line, length);
|
|
|
|
s_cmd_line[length] = '\0';
|
|
|
|
}
|
|
|
|
|
2022-01-21 09:36:32 +00:00
|
|
|
bool CommandLine::was_initialized()
|
|
|
|
{
|
|
|
|
return s_the != nullptr;
|
|
|
|
}
|
|
|
|
|
2020-04-08 11:54:44 +00:00
|
|
|
const CommandLine& kernel_command_line()
|
2019-06-04 10:54:27 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(s_the);
|
2019-06-04 10:54:27 +00:00
|
|
|
return *s_the;
|
|
|
|
}
|
|
|
|
|
2021-02-19 20:29:46 +00:00
|
|
|
UNMAP_AFTER_INIT void CommandLine::initialize()
|
2020-04-08 11:54:44 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(!s_the);
|
2020-08-25 01:35:27 +00:00
|
|
|
s_the = new CommandLine(s_cmd_line);
|
2021-05-21 17:12:29 +00:00
|
|
|
dmesgln("Kernel Commandline: {}", kernel_command_line().string());
|
2021-10-23 15:31:00 +00:00
|
|
|
// Validate the modes the user passed in.
|
|
|
|
(void)s_the->panic_mode(Validate::Yes);
|
2021-10-23 16:26:50 +00:00
|
|
|
if (s_the->contains("boot_mode"sv)) {
|
|
|
|
// I know, we don't do legacy, but even though I eliminated 'boot_mode' from the codebase, there
|
|
|
|
// is a good chance that someone's still using it. Let's be nice and tell them where to look.
|
|
|
|
// TODO: Remove this in 2022.
|
|
|
|
PANIC("'boot_mode' is now split into panic=[halt|shutdown], fbdev=[on|off], and system_mode=[graphical|text|selftest].");
|
|
|
|
}
|
2020-04-08 11:54:44 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 19:12:12 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullOwnPtr<KString> CommandLine::build_commandline(StringView cmdline_from_bootloader)
|
2019-06-04 10:54:27 +00:00
|
|
|
{
|
2021-05-21 17:42:33 +00:00
|
|
|
StringBuilder builder;
|
|
|
|
builder.append(cmdline_from_bootloader);
|
2021-10-07 17:51:24 +00:00
|
|
|
if constexpr (!s_embedded_cmd_line.is_empty()) {
|
2021-05-21 17:42:33 +00:00
|
|
|
builder.append(" ");
|
|
|
|
builder.append(s_embedded_cmd_line);
|
|
|
|
}
|
2022-01-11 19:12:12 +00:00
|
|
|
return KString::must_create(builder.string_view());
|
2021-05-21 17:42:33 +00:00
|
|
|
}
|
2020-08-22 14:34:14 +00:00
|
|
|
|
2021-05-31 08:59:02 +00:00
|
|
|
UNMAP_AFTER_INIT void CommandLine::add_arguments(const Vector<StringView>& args)
|
2021-05-21 17:42:33 +00:00
|
|
|
{
|
2020-08-23 13:04:49 +00:00
|
|
|
for (auto&& str : args) {
|
2021-05-31 08:59:02 +00:00
|
|
|
if (str == ""sv) {
|
2019-06-04 11:55:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-31 08:59:02 +00:00
|
|
|
auto pair = str.split_view('=', false);
|
|
|
|
VERIFY(pair.size() == 2 || pair.size() == 1);
|
2019-06-04 10:54:27 +00:00
|
|
|
|
|
|
|
if (pair.size() == 1) {
|
2021-12-28 23:42:39 +00:00
|
|
|
m_params.set(pair[0], ""sv);
|
2019-06-04 10:54:27 +00:00
|
|
|
} else {
|
2021-12-28 23:42:39 +00:00
|
|
|
m_params.set(pair[0], pair[1]);
|
2019-06-04 10:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 19:12:12 +00:00
|
|
|
UNMAP_AFTER_INIT CommandLine::CommandLine(StringView cmdline_from_bootloader)
|
|
|
|
: m_string(build_commandline(cmdline_from_bootloader))
|
2021-05-21 17:42:33 +00:00
|
|
|
{
|
|
|
|
s_the = this;
|
2022-01-11 19:12:12 +00:00
|
|
|
const auto& args = m_string->view().split_view(' ');
|
2021-05-21 17:42:33 +00:00
|
|
|
m_params.ensure_capacity(args.size());
|
|
|
|
add_arguments(args);
|
|
|
|
}
|
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
Optional<StringView> CommandLine::lookup(StringView key) const
|
2020-04-08 14:35:00 +00:00
|
|
|
{
|
|
|
|
return m_params.get(key);
|
|
|
|
}
|
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
bool CommandLine::contains(StringView key) const
|
2019-06-04 10:54:27 +00:00
|
|
|
{
|
|
|
|
return m_params.contains(key);
|
|
|
|
}
|
2020-04-08 11:54:44 +00:00
|
|
|
|
2021-03-03 09:00:41 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_boot_profiling_enabled() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return contains("boot_prof"sv);
|
2021-03-03 09:00:41 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 08:51:55 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_ide_enabled() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return !contains("disable_ide"sv);
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_smp_enabled() const
|
|
|
|
{
|
2021-12-19 19:30:36 +00:00
|
|
|
// Note: We can't enable SMP mode without enabling the IOAPIC.
|
|
|
|
if (!is_ioapic_enabled())
|
|
|
|
return false;
|
2021-05-31 08:59:02 +00:00
|
|
|
return lookup("smp"sv).value_or("off"sv) == "on"sv;
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2021-12-19 19:30:36 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_smp_enabled_without_ioapic_enabled() const
|
|
|
|
{
|
|
|
|
auto smp_enabled = lookup("smp"sv).value_or("off"sv) == "on"sv;
|
|
|
|
return smp_enabled && !is_ioapic_enabled();
|
|
|
|
}
|
|
|
|
|
2021-11-28 15:38:10 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_ioapic_enabled() const
|
|
|
|
{
|
|
|
|
auto value = lookup("enable_ioapic"sv).value_or("on"sv);
|
|
|
|
if (value == "on"sv)
|
|
|
|
return true;
|
|
|
|
if (value == "off"sv)
|
|
|
|
return false;
|
|
|
|
PANIC("Unknown enable_ioapic setting: {}", value);
|
|
|
|
}
|
|
|
|
|
2021-03-03 08:51:55 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_vmmouse_enabled() const
|
|
|
|
{
|
2021-10-23 20:31:28 +00:00
|
|
|
return lookup("vmmouse"sv).value_or("on"sv) == "on"sv;
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 13:46:04 +00:00
|
|
|
UNMAP_AFTER_INIT PCIAccessLevel CommandLine::pci_access_level() const
|
2021-03-03 08:51:55 +00:00
|
|
|
{
|
2022-01-21 14:09:05 +00:00
|
|
|
auto value = lookup("pci"sv).value_or("ecam"sv);
|
|
|
|
if (value == "ecam"sv)
|
Kernel/PCI: Simplify the entire subsystem
A couple of things were changed:
1. Semantic changes - PCI segments are now called PCI domains, to better
match what they are really. It's also the name that Linux gave, and it
seems that Wikipedia also uses this name.
We also remove PCI::ChangeableAddress, because it was used in the past
but now it's no longer being used.
2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as
they made a bunch of unnecessary complexity. Instead, Windowed access is
removed entirely (this was tested, but never was benchmarked), so we are
left with IO access and memory access options. The memory access option
is essentially mapping the PCI bus (from the chosen PCI domain), to
virtual memory as-is. This means that unless needed, at any time, there
is only one PCI bus being mapped, and this is changed if access to
another PCI bus in the same PCI domain is needed. For now, we don't
support mapping of different PCI buses from different PCI domains at the
same time, because basically it's still a non-issue for most machines
out there.
2. OOM-safety is increased, especially when constructing the Access
object. It means that we pre-allocating any needed resources, and we try
to find PCI domains (if requested to initialize memory access) after we
attempt to construct the Access object, so it's possible to fail at this
point "gracefully".
3. All PCI API functions are now separated into a different header file,
which means only "clients" of the PCI subsystem API will need to include
that header file.
4. Functional changes - we only allow now to enumerate the bus after
a hardware scan. This means that the old method "enumerate_hardware"
is removed, so, when initializing an Access object, the initializing
function must call rescan on it to force it to find devices. This makes
it possible to fail rescan, and also to defer it after construction from
both OOM-safety terms and hotplug capabilities.
2021-09-07 09:08:38 +00:00
|
|
|
return PCIAccessLevel::MemoryAddressing;
|
2022-01-21 14:09:05 +00:00
|
|
|
if (value == "io"sv)
|
2021-04-03 13:46:04 +00:00
|
|
|
return PCIAccessLevel::IOAddressing;
|
2022-01-21 14:09:05 +00:00
|
|
|
if (value == "none"sv)
|
|
|
|
return PCIAccessLevel::None;
|
2021-04-03 10:29:07 +00:00
|
|
|
PANIC("Unknown PCI ECAM setting: {}", value);
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 14:09:05 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_pci_disabled() const
|
|
|
|
{
|
|
|
|
return lookup("pci"sv).value_or("ecam"sv) == "none"sv;
|
|
|
|
}
|
|
|
|
|
2021-03-03 08:51:55 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_legacy_time_enabled() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return lookup("time"sv).value_or("modern"sv) == "legacy"sv;
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 10:29:55 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-03-03 08:51:55 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_force_pio() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return contains("force_pio"sv);
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 06:49:17 +00:00
|
|
|
UNMAP_AFTER_INIT StringView CommandLine::root_device() const
|
2021-03-03 08:51:55 +00:00
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return lookup("root"sv).value_or("/dev/hda"sv);
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 10:55:39 +00:00
|
|
|
bool CommandLine::is_nvme_polling_enabled() const
|
|
|
|
{
|
|
|
|
return contains("nvme_poll"sv);
|
|
|
|
}
|
|
|
|
|
2021-03-03 08:51:55 +00:00
|
|
|
UNMAP_AFTER_INIT AcpiFeatureLevel CommandLine::acpi_feature_level() const
|
|
|
|
{
|
2021-09-10 13:45:12 +00:00
|
|
|
auto value = kernel_command_line().lookup("acpi"sv).value_or("limited"sv);
|
2021-05-31 08:59:02 +00:00
|
|
|
if (value == "limited"sv)
|
2021-03-03 08:51:55 +00:00
|
|
|
return AcpiFeatureLevel::Limited;
|
2021-05-31 08:59:02 +00:00
|
|
|
if (value == "off"sv)
|
2021-03-03 08:51:55 +00:00
|
|
|
return AcpiFeatureLevel::Disabled;
|
2021-09-10 15:06:26 +00:00
|
|
|
if (value == "on"sv)
|
|
|
|
return AcpiFeatureLevel::Enabled;
|
|
|
|
PANIC("Unknown ACPI feature level: {}", value);
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT HPETMode CommandLine::hpet_mode() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
auto hpet_mode = lookup("hpet"sv).value_or("periodic"sv);
|
|
|
|
if (hpet_mode == "periodic"sv)
|
2021-03-03 08:51:55 +00:00
|
|
|
return HPETMode::Periodic;
|
2021-05-31 08:59:02 +00:00
|
|
|
if (hpet_mode == "nonperiodic"sv)
|
2021-03-03 08:51:55 +00:00
|
|
|
return HPETMode::NonPeriodic;
|
|
|
|
PANIC("Unknown HPETMode: {}", hpet_mode);
|
|
|
|
}
|
|
|
|
|
2021-06-04 05:02:14 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::is_physical_networking_disabled() const
|
|
|
|
{
|
|
|
|
return contains("disable_physical_networking"sv);
|
|
|
|
}
|
|
|
|
|
2021-04-08 18:18:48 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::disable_ps2_controller() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return contains("disable_ps2_controller"sv);
|
2021-04-08 18:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT bool CommandLine::disable_physical_storage() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return contains("disable_physical_storage"sv);
|
2021-04-08 18:18:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 19:36:53 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::disable_uhci_controller() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return contains("disable_uhci_controller"sv);
|
2021-04-17 19:36:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 18:50:20 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::disable_usb() const
|
|
|
|
{
|
|
|
|
return contains("disable_usb"sv);
|
|
|
|
}
|
|
|
|
|
2021-04-18 13:06:35 +00:00
|
|
|
UNMAP_AFTER_INIT bool CommandLine::disable_virtio() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return contains("disable_virtio"sv);
|
2021-04-18 13:06:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 16:35:16 +00:00
|
|
|
UNMAP_AFTER_INIT AHCIResetMode CommandLine::ahci_reset_mode() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
const auto ahci_reset_mode = lookup("ahci_reset_mode"sv).value_or("controllers"sv);
|
|
|
|
if (ahci_reset_mode == "controllers"sv) {
|
2021-03-12 16:35:16 +00:00
|
|
|
return AHCIResetMode::ControllerOnly;
|
2021-12-28 23:44:39 +00:00
|
|
|
}
|
|
|
|
if (ahci_reset_mode == "aggressive"sv) {
|
2021-05-28 22:18:45 +00:00
|
|
|
return AHCIResetMode::Aggressive;
|
2021-03-12 16:35:16 +00:00
|
|
|
}
|
|
|
|
PANIC("Unknown AHCIResetMode: {}", ahci_reset_mode);
|
|
|
|
}
|
|
|
|
|
2021-10-23 16:26:50 +00:00
|
|
|
StringView CommandLine::system_mode() const
|
2021-03-03 08:51:55 +00:00
|
|
|
{
|
2021-10-23 16:26:50 +00:00
|
|
|
return lookup("system_mode"sv).value_or("graphical"sv);
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 15:31:00 +00:00
|
|
|
PanicMode CommandLine::panic_mode(Validate should_validate) const
|
|
|
|
{
|
|
|
|
const auto panic_mode = lookup("panic"sv).value_or("halt"sv);
|
|
|
|
if (panic_mode == "halt"sv) {
|
|
|
|
return PanicMode::Halt;
|
2021-12-28 23:44:39 +00:00
|
|
|
}
|
|
|
|
if (panic_mode == "shutdown"sv) {
|
2021-10-23 15:31:00 +00:00
|
|
|
return PanicMode::Shutdown;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (should_validate == Validate::Yes)
|
|
|
|
PANIC("Unknown PanicMode: {}", panic_mode);
|
|
|
|
|
|
|
|
return PanicMode::Halt;
|
|
|
|
}
|
|
|
|
|
2022-01-05 21:45:29 +00:00
|
|
|
UNMAP_AFTER_INIT auto CommandLine::are_framebuffer_devices_enabled() const -> FrameBufferDevices
|
|
|
|
{
|
|
|
|
const auto fbdev_value = lookup("fbdev"sv).value_or("on"sv);
|
|
|
|
if (fbdev_value == "on"sv)
|
|
|
|
return FrameBufferDevices::Enabled;
|
|
|
|
if (fbdev_value == "bootloader"sv)
|
|
|
|
return FrameBufferDevices::BootloaderOnly;
|
|
|
|
return FrameBufferDevices::ConsoleOnly;
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 06:49:17 +00:00
|
|
|
StringView CommandLine::userspace_init() const
|
2021-03-03 08:51:55 +00:00
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
return lookup("init"sv).value_or("/bin/SystemServer"sv);
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 09:36:40 +00:00
|
|
|
NonnullOwnPtrVector<KString> CommandLine::userspace_init_args() const
|
2021-03-03 08:51:55 +00:00
|
|
|
{
|
2021-09-09 09:36:40 +00:00
|
|
|
NonnullOwnPtrVector<KString> args;
|
2021-03-03 08:51:55 +00:00
|
|
|
|
2021-09-09 09:36:40 +00:00
|
|
|
auto init_args = lookup("init_args"sv).value_or(""sv).split_view(';');
|
|
|
|
if (!init_args.is_empty())
|
2022-01-03 11:18:56 +00:00
|
|
|
MUST(args.try_prepend(KString::must_create(userspace_init())));
|
2021-09-09 09:36:40 +00:00
|
|
|
for (auto& init_arg : init_args)
|
|
|
|
args.append(KString::must_create(init_arg));
|
|
|
|
return args;
|
2021-03-03 08:51:55 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 21:22:02 +00:00
|
|
|
UNMAP_AFTER_INIT size_t CommandLine::switch_to_tty() const
|
|
|
|
{
|
2021-05-31 08:59:02 +00:00
|
|
|
const auto default_tty = lookup("switch_to_tty"sv).value_or("1"sv);
|
2021-05-13 21:22:02 +00:00
|
|
|
auto switch_tty_number = default_tty.to_uint();
|
|
|
|
if (switch_tty_number.has_value() && switch_tty_number.value() >= 1) {
|
|
|
|
return switch_tty_number.value() - 1;
|
|
|
|
}
|
|
|
|
PANIC("Invalid default tty value: {}", default_tty);
|
|
|
|
}
|
2020-04-08 11:54:44 +00:00
|
|
|
}
|