From 368f5e979920e9719ebbfe1a8397a70fe2c8973c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 16 Aug 2024 22:09:24 +0300 Subject: [PATCH] Kernel: Add command lineoption `nousb` that will disable usb controller --- kernel/include/kernel/PCI.h | 2 +- kernel/kernel/PCI.cpp | 6 ++++-- kernel/kernel/kernel.cpp | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kernel/include/kernel/PCI.h b/kernel/include/kernel/PCI.h index 940fd6fe..4fd88308 100644 --- a/kernel/include/kernel/PCI.h +++ b/kernel/include/kernel/PCI.h @@ -139,7 +139,7 @@ namespace Kernel::PCI static void initialize(); static PCIManager& get(); - void initialize_devices(); + void initialize_devices(bool disable_usb); template void for_each_device(F callback) diff --git a/kernel/kernel/PCI.cpp b/kernel/kernel/PCI.cpp index 66c77c3a..828a03b9 100644 --- a/kernel/kernel/PCI.cpp +++ b/kernel/kernel/PCI.cpp @@ -177,7 +177,7 @@ namespace Kernel::PCI } } - void PCIManager::initialize_devices() + void PCIManager::initialize_devices(bool disable_usb) { for_each_device( [&](PCI::Device& pci_device) @@ -215,7 +215,9 @@ namespace Kernel::PCI switch (pci_device.subclass()) { case 0x03: - if (auto res = USBManager::get().add_controller(pci_device); res.is_error()) + if (disable_usb) + dprintln("USB support disabled, will not initialize {2H}.{2H}.{2H}", pci_device.class_code(), pci_device.subclass(), pci_device.prog_if()); + else if (auto res = USBManager::get().add_controller(pci_device); res.is_error()) dprintln("{}", res.error()); break; default: diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index 3e84b9f1..de908d96 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -37,6 +37,7 @@ struct ParsedCommandLine bool force_pic = false; bool disable_serial = false; bool disable_smp = false; + bool disable_usb = false; BAN::StringView console = "tty0"_sv; BAN::StringView root; }; @@ -75,6 +76,8 @@ static void parse_command_line() cmdline.disable_serial = true; else if (argument == "nosmp") cmdline.disable_smp = true; + else if (argument == "nousb") + cmdline.disable_usb = true; else if (argument.size() > 5 && argument.substring(0, 5) == "root=") cmdline.root = argument.substring(5); else if (argument.size() > 8 && argument.substring(0, 8) == "console=") @@ -199,8 +202,11 @@ static void init2(void*) PCI::PCIManager::initialize(); dprintln("PCI initialized"); - MUST(USBManager::initialize()); - dprintln("USBManager initialized"); + if (!cmdline.disable_usb) + { + MUST(USBManager::initialize()); + dprintln("USBManager initialized"); + } if (ACPI::ACPI::get().enter_acpi_mode(InterruptController::get().is_using_apic()).is_error()) dprintln("Failed to enter ACPI mode"); @@ -222,7 +228,7 @@ static void init2(void*) // NOTE: PCI devices are the last ones to be initialized // so other devices can reserve predefined interrupts - PCI::PCIManager::get().initialize_devices(); + PCI::PCIManager::get().initialize_devices(cmdline.disable_usb); dprintln("PCI devices initialized"); VirtualFileSystem::initialize(cmdline.root);