From f6e635938fb71aa54294ee69a151240645af5d02 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 21 Jan 2022 16:09:05 +0200 Subject: [PATCH] Kernel: Change PCI access commandline option to also represent no access This change allow the user to request the kernel to not use any PCI resources/devices at all. Also, don't try to initialize devices that rely on PCI if disabled. --- Base/usr/share/man/man7/boot_parameters.md | 3 ++- Kernel/Bus/PCI/Initializer.cpp | 1 + Kernel/CommandLine.cpp | 13 ++++++++++--- Kernel/CommandLine.h | 2 ++ Kernel/init.cpp | 14 ++++++++++---- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Base/usr/share/man/man7/boot_parameters.md b/Base/usr/share/man/man7/boot_parameters.md index 2338a74675..0a1fc305ae 100644 --- a/Base/usr/share/man/man7/boot_parameters.md +++ b/Base/usr/share/man/man7/boot_parameters.md @@ -56,7 +56,8 @@ List of options: * **`panic`** - This parameter expects **`halt`** or **`shutdown`**. This is particularly useful in CI contexts. -* **`pci_ecam`** - This parameter expects **`on`** or **`off`**. +* **`pci`** - This parameter expects **`ecam`**, **`io`** or **`none`**. When selecting **`none`** + the kernel will not use PCI resources/devices. * **`root`** - This parameter configures the device to use as the root file system. It defaults to **`/dev/hda`** if unspecified. diff --git a/Kernel/Bus/PCI/Initializer.cpp b/Kernel/Bus/PCI/Initializer.cpp index 3a17957678..9d63ccc602 100644 --- a/Kernel/Bus/PCI/Initializer.cpp +++ b/Kernel/Bus/PCI/Initializer.cpp @@ -36,6 +36,7 @@ UNMAP_AFTER_INIT static PCIAccessLevel detect_optimal_access_type() UNMAP_AFTER_INIT void initialize() { + VERIFY(kernel_command_line().pci_access_level() != PCIAccessLevel::None); switch (detect_optimal_access_type()) { case PCIAccessLevel::MemoryAddressing: { auto mcfg = ACPI::Parser::the()->find_table("MCFG"); diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp index 13e315d557..1bf2f0a228 100644 --- a/Kernel/CommandLine.cpp +++ b/Kernel/CommandLine.cpp @@ -142,14 +142,21 @@ UNMAP_AFTER_INIT bool CommandLine::is_vmmouse_enabled() const UNMAP_AFTER_INIT PCIAccessLevel CommandLine::pci_access_level() const { - auto value = lookup("pci_ecam"sv).value_or("on"sv); - if (value == "on"sv) + auto value = lookup("pci"sv).value_or("ecam"sv); + if (value == "ecam"sv) return PCIAccessLevel::MemoryAddressing; - if (value == "off"sv) + if (value == "io"sv) return PCIAccessLevel::IOAddressing; + if (value == "none"sv) + return PCIAccessLevel::None; PANIC("Unknown PCI ECAM setting: {}", value); } +UNMAP_AFTER_INIT bool CommandLine::is_pci_disabled() const +{ + return lookup("pci"sv).value_or("ecam"sv) == "none"sv; +} + UNMAP_AFTER_INIT bool CommandLine::is_legacy_time_enabled() const { return lookup("time"sv).value_or("modern"sv) == "legacy"sv; diff --git a/Kernel/CommandLine.h b/Kernel/CommandLine.h index ad94755222..b4ef9b7fb6 100644 --- a/Kernel/CommandLine.h +++ b/Kernel/CommandLine.h @@ -31,6 +31,7 @@ enum class AcpiFeatureLevel { }; enum class PCIAccessLevel { + None, IOAddressing, MemoryAddressing, }; @@ -70,6 +71,7 @@ public: [[nodiscard]] bool is_physical_networking_disabled() const; [[nodiscard]] bool is_vmmouse_enabled() const; [[nodiscard]] PCIAccessLevel pci_access_level() const; + [[nodiscard]] bool is_pci_disabled() const; [[nodiscard]] bool is_legacy_time_enabled() const; [[nodiscard]] bool is_pc_speaker_enabled() const; [[nodiscard]] FrameBufferDevices are_framebuffer_devices_enabled() const; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 50828444fc..0bdc7e0b14 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -299,8 +299,10 @@ void init_stage2(void*) } // Initialize the PCI Bus as early as possible, for early boot (PCI based) serial logging - PCI::initialize(); - PCISerialDevice::detect(); + if (!kernel_command_line().is_pci_disabled()) { + PCI::initialize(); + PCISerialDevice::detect(); + } VirtualFileSystem::initialize(); @@ -321,10 +323,14 @@ void init_stage2(void*) auto boot_profiling = kernel_command_line().is_boot_profiling_enabled(); - USB::USBManagement::initialize(); + if (!kernel_command_line().is_pci_disabled()) { + USB::USBManagement::initialize(); + } FirmwareSysFSDirectory::initialize(); - VirtIO::detect(); + if (!kernel_command_line().is_pci_disabled()) { + VirtIO::detect(); + } NetworkingManagement::the().initialize(); Syscall::initialize();