summaryrefslogtreecommitdiff
path: root/Kernel/PCI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-08 18:06:08 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-08 18:07:35 +0200
commit66f7c8e0e87e7b60ff87b5ab7d8375684834b1ab (patch)
tree48761b87253a82f50a66dc07c3cb90aec1dcf3b3 /Kernel/PCI
parente171c25a6732db80da0feb845e5d9abea5aab135 (diff)
downloadserenity-66f7c8e0e87e7b60ff87b5ab7d8375684834b1ab.zip
Kernel: Simplify PCI::initialize()
Choosing between I/O and MMIO is not as difficult as we were making it.
Diffstat (limited to 'Kernel/PCI')
-rw-r--r--Kernel/PCI/Access.h5
-rw-r--r--Kernel/PCI/Initializer.cpp59
2 files changed, 23 insertions, 41 deletions
diff --git a/Kernel/PCI/Access.h b/Kernel/PCI/Access.h
index d6a3877ed2..9c4afb3c14 100644
--- a/Kernel/PCI/Access.h
+++ b/Kernel/PCI/Access.h
@@ -33,6 +33,11 @@ namespace Kernel {
class PCI::Access {
public:
+ enum class Type {
+ IO,
+ MMIO,
+ };
+
virtual void enumerate_all(Function<void(Address, ID)>&) = 0;
void enumerate_bus(int type, u8 bus, Function<void(Address, ID)>&);
diff --git a/Kernel/PCI/Initializer.cpp b/Kernel/PCI/Initializer.cpp
index fac67a8cdb..2f770f3941 100644
--- a/Kernel/PCI/Initializer.cpp
+++ b/Kernel/PCI/Initializer.cpp
@@ -38,17 +38,31 @@ namespace PCI {
static void initialize_pci_mmio_access(PhysicalAddress mcfg);
static void initialize_pci_io_access();
-static void test_and_initialize(bool disable_pci_mmio);
static void detect_devices();
static bool test_acpi();
static bool test_pci_io();
static bool test_pci_mmio();
-static void initialize_pci_mmio_access_after_test();
+
+static Access::Type detect_optimal_access_type(bool mmio_allowed)
+{
+ if (mmio_allowed && test_acpi() && test_pci_mmio())
+ return Access::Type::MMIO;
+
+ if (test_pci_io())
+ return Access::Type::IO;
+
+ klog() << "No PCI bus access method detected!";
+ hang();
+}
void initialize()
{
- bool pci_mmio = kernel_command_line().lookup("pci_mmio").value_or("off") == "on";
- test_and_initialize(!pci_mmio);
+ bool mmio_allowed = kernel_command_line().lookup("pci_mmio").value_or("off") == "on";
+
+ if (detect_optimal_access_type(mmio_allowed) == Access::Type::MMIO)
+ initialize_pci_mmio_access(ACPI::Parser::the().find_table("MCFG"));
+ else
+ initialize_pci_io_access();
}
void initialize_pci_mmio_access(PhysicalAddress mcfg)
@@ -72,38 +86,6 @@ void detect_devices()
});
}
-void test_and_initialize(bool disable_pci_mmio)
-{
- if (disable_pci_mmio) {
- if (test_pci_io()) {
- initialize_pci_io_access();
- } else {
- klog() << "No PCI Bus Access Method Detected, Halt!";
- ASSERT_NOT_REACHED(); // NO PCI Access ?!
- }
- return;
- }
- if (test_acpi()) {
- if (test_pci_mmio()) {
- initialize_pci_mmio_access_after_test();
- } else {
- if (test_pci_io()) {
- initialize_pci_io_access();
- } else {
- klog() << "No PCI Bus Access Method Detected, Halt!";
- ASSERT_NOT_REACHED(); // NO PCI Access ?!
- }
- }
- } else {
- if (test_pci_io()) {
- initialize_pci_io_access();
- } else {
- klog() << "No PCI Bus Access Method Detected, Halt!";
- ASSERT_NOT_REACHED(); // NO PCI Access ?!
- }
- }
-}
-
bool test_acpi()
{
if ((kernel_command_line().contains("noacpi")) || !ACPI::Parser::the().is_operable())
@@ -131,10 +113,5 @@ bool test_pci_mmio()
return !ACPI::Parser::the().find_table("MCFG").is_null();
}
-void initialize_pci_mmio_access_after_test()
-{
- initialize_pci_mmio_access(ACPI::Parser::the().find_table("MCFG"));
-}
-
}
}