diff --git a/Kernel/Bus/PCI/Access.cpp b/Kernel/Bus/PCI/Access.cpp index bd4ee02a182..f33191106f8 100644 --- a/Kernel/Bus/PCI/Access.cpp +++ b/Kernel/Bus/PCI/Access.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,11 @@ bool Access::is_initialized() return (s_access != nullptr); } +bool Access::is_disabled() +{ + return g_pci_access_is_disabled_from_commandline || g_pci_access_io_probe_failed; +} + UNMAP_AFTER_INIT bool Access::find_and_register_pci_host_bridges_from_acpi_mcfg_table(PhysicalAddress mcfg_table) { u32 length = 0; diff --git a/Kernel/Bus/PCI/Access.h b/Kernel/Bus/PCI/Access.h index f5c42c625c3..8444b80c182 100644 --- a/Kernel/Bus/PCI/Access.h +++ b/Kernel/Bus/PCI/Access.h @@ -26,6 +26,7 @@ public: static Access& the(); static bool is_initialized(); + static bool is_disabled(); void write8_field(Address address, u32 field, u8 value); void write16_field(Address address, u32 field, u16 value); diff --git a/Kernel/Bus/PCI/Initializer.cpp b/Kernel/Bus/PCI/Initializer.cpp index 9d63ccc602c..792e3fd8adf 100644 --- a/Kernel/Bus/PCI/Initializer.cpp +++ b/Kernel/Bus/PCI/Initializer.cpp @@ -17,6 +17,9 @@ namespace Kernel { namespace PCI { +READONLY_AFTER_INIT bool g_pci_access_io_probe_failed; +READONLY_AFTER_INIT bool g_pci_access_is_disabled_from_commandline; + static bool test_pci_io(); UNMAP_AFTER_INIT static PCIAccessLevel detect_optimal_access_type() @@ -28,7 +31,7 @@ UNMAP_AFTER_INIT static PCIAccessLevel detect_optimal_access_type() if (boot_determined != PCIAccessLevel::IOAddressing) return boot_determined; - if (test_pci_io()) + if (!g_pci_access_io_probe_failed) return PCIAccessLevel::IOAddressing; PANIC("No PCI bus access method detected!"); @@ -36,7 +39,10 @@ UNMAP_AFTER_INIT static PCIAccessLevel detect_optimal_access_type() UNMAP_AFTER_INIT void initialize() { - VERIFY(kernel_command_line().pci_access_level() != PCIAccessLevel::None); + g_pci_access_io_probe_failed = !test_pci_io(); + g_pci_access_is_disabled_from_commandline = kernel_command_line().is_pci_disabled(); + if (g_pci_access_is_disabled_from_commandline || g_pci_access_io_probe_failed) + return; switch (detect_optimal_access_type()) { case PCIAccessLevel::MemoryAddressing: { auto mcfg = ACPI::Parser::the()->find_table("MCFG"); diff --git a/Kernel/Bus/PCI/Initializer.h b/Kernel/Bus/PCI/Initializer.h index f9c01c4aadf..6bf92efeb57 100644 --- a/Kernel/Bus/PCI/Initializer.h +++ b/Kernel/Bus/PCI/Initializer.h @@ -9,6 +9,9 @@ namespace Kernel { namespace PCI { +extern bool g_pci_access_io_probe_failed; +extern bool g_pci_access_is_disabled_from_commandline; + void initialize(); } diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 0bdc7e0b14e..4c814cc9c2f 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -299,8 +299,8 @@ void init_stage2(void*) } // Initialize the PCI Bus as early as possible, for early boot (PCI based) serial logging - if (!kernel_command_line().is_pci_disabled()) { - PCI::initialize(); + PCI::initialize(); + if (!PCI::Access::is_disabled()) { PCISerialDevice::detect(); } @@ -323,12 +323,12 @@ void init_stage2(void*) auto boot_profiling = kernel_command_line().is_boot_profiling_enabled(); - if (!kernel_command_line().is_pci_disabled()) { + if (!PCI::Access::is_disabled()) { USB::USBManagement::initialize(); } FirmwareSysFSDirectory::initialize(); - if (!kernel_command_line().is_pci_disabled()) { + if (!PCI::Access::is_disabled()) { VirtIO::detect(); }