diff options
author | Marco Cutecchia <marco.cutecchia@outlook.it> | 2023-03-23 21:31:01 +0100 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2023-04-02 12:43:17 -0600 |
commit | 5fe6c6fc2431fcc1f1690d5af949a425f6c89884 (patch) | |
tree | f06805c0eed79da0dcca7016283f47b5d0cb51de /Kernel/Storage/StorageManagement.cpp | |
parent | 47cae8005f1f9a43154d7d830d7ff6edc0f6f301 (diff) | |
download | serenity-5fe6c6fc2431fcc1f1690d5af949a425f6c89884.zip |
Kernel: Add support for SD host controllers on the PCI bus
Diffstat (limited to 'Kernel/Storage/StorageManagement.cpp')
-rw-r--r-- | Kernel/Storage/StorageManagement.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index 5df9a741ef..3d982bc78a 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -28,6 +28,7 @@ #include <Kernel/Storage/ATA/AHCI/Controller.h> #include <Kernel/Storage/ATA/GenericIDE/Controller.h> #include <Kernel/Storage/NVMe/NVMeController.h> +#include <Kernel/Storage/SD/PCISDHostController.h> #include <Kernel/Storage/SD/SDHostController.h> #include <Kernel/Storage/StorageManagement.h> #include <LibPartition/EBRPartitionTable.h> @@ -88,7 +89,6 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_pci_controllers(bool force_pi { VERIFY(m_controllers.is_empty()); - using SubclassID = PCI::MassStorage::SubclassID; if (!kernel_command_line().disable_physical_storage()) { // NOTE: Search for VMD devices before actually searching for storage controllers // because the VMD device is only a bridge to such (NVMe) controllers. @@ -100,10 +100,8 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_pci_controllers(bool force_pi } })); - MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) -> void { - if (device_identifier.class_code().value() != to_underlying(PCI::ClassID::MassStorage)) { - return; - } + auto const& handle_mass_storage_device = [&](PCI::DeviceIdentifier const& device_identifier) { + using SubclassID = PCI::MassStorage::SubclassID; auto subclass_code = static_cast<SubclassID>(device_identifier.subclass_code().value()); #if ARCH(X86_64) @@ -135,6 +133,30 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_pci_controllers(bool force_pi m_controllers.append(controller.release_value()); } } + }; + + auto const& handle_base_device = [&](PCI::DeviceIdentifier const& device_identifier) { + using SubclassID = PCI::Base::SubclassID; + + auto subclass_code = static_cast<SubclassID>(device_identifier.subclass_code().value()); + if (subclass_code == SubclassID::SDHostController) { + + auto sdhc_or_error = PCISDHostController::try_initialize(device_identifier); + if (sdhc_or_error.is_error()) { + dmesgln("PCI: Failed to initialize SD Host Controller ({} - {}): {}", device_identifier.address(), device_identifier.hardware_id(), sdhc_or_error.error()); + } else { + m_controllers.append(sdhc_or_error.release_value()); + } + } + }; + + MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) -> void { + auto class_code = device_identifier.class_code().value(); + if (class_code == to_underlying(PCI::ClassID::MassStorage)) { + handle_mass_storage_device(device_identifier); + } else if (class_code == to_underlying(PCI::ClassID::Base)) { + handle_base_device(device_identifier); + } })); } } |