PCISDHostController.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2023, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Bus/PCI/API.h>
  7. #include <Kernel/Devices/Storage/SD/PCISDHostController.h>
  8. namespace Kernel {
  9. ErrorOr<NonnullRefPtr<PCISDHostController>> PCISDHostController::try_initialize(PCI::DeviceIdentifier const& device_identifier)
  10. {
  11. auto sdhc = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) PCISDHostController(device_identifier)));
  12. TRY(sdhc->initialize());
  13. PCI::enable_bus_mastering(sdhc->device_identifier());
  14. PCI::enable_memory_space(sdhc->device_identifier());
  15. sdhc->try_enable_dma();
  16. return sdhc;
  17. }
  18. PCISDHostController::PCISDHostController(PCI::DeviceIdentifier const& device_identifier)
  19. : PCI::Device(device_identifier)
  20. , SDHostController()
  21. {
  22. auto slot_information_register = read_slot_information();
  23. if (slot_information_register.slots_available() != 1) {
  24. // TODO: Support multiple slots
  25. dmesgln("SD Host Controller has {} slots, but we currently only support using only one", slot_information_register.slots_available());
  26. }
  27. auto physical_address_of_sdhc_registers = PhysicalAddress {
  28. PCI::get_BAR(device_identifier, static_cast<PCI::HeaderType0BaseRegister>(slot_information_register.first_bar_number))
  29. };
  30. m_registers = Memory::map_typed_writable<SD::HostControlRegisterMap volatile>(physical_address_of_sdhc_registers).release_value_but_fixme_should_propagate_errors();
  31. }
  32. }