DeviceIdentifier.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/AnyOf.h>
  7. #include <AK/Error.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/RefPtr.h>
  10. #include <Kernel/Bus/PCI/Definitions.h>
  11. namespace Kernel::PCI {
  12. ErrorOr<NonnullRefPtr<DeviceIdentifier>> DeviceIdentifier::from_enumerable_identifier(EnumerableDeviceIdentifier const& other_identifier)
  13. {
  14. return adopt_nonnull_ref_or_enomem(new (nothrow) DeviceIdentifier(other_identifier));
  15. }
  16. void DeviceIdentifier::initialize()
  17. {
  18. for (auto cap : capabilities()) {
  19. if (cap.id() == PCI::Capabilities::ID::MSIX) {
  20. auto msix_bir_bar = (cap.read8(4) & msix_table_bir_mask);
  21. auto msix_bir_offset = (cap.read32(4) & msix_table_offset_mask);
  22. auto msix_count = (cap.read16(2) & msix_control_table_mask) + 1;
  23. m_msix_info = MSIxInfo(msix_count, msix_bir_bar, msix_bir_offset);
  24. }
  25. if (cap.id() == PCI::Capabilities::ID::MSI) {
  26. bool message_address_64_bit_format = (cap.read8(msi_control_offset) & msi_address_format_mask);
  27. u8 count = 1;
  28. u8 mme_count = (cap.read8(msi_control_offset) & msi_mmc_format_mask) >> 1;
  29. if (mme_count)
  30. count = mme_count;
  31. m_msi_info = MSIInfo(message_address_64_bit_format, count);
  32. }
  33. }
  34. }
  35. }