1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 18:05:07 +00:00
serenity/Kernel/Bus/PCI/DeviceIdentifier.cpp
Pankaj Raghav d0fbaf790a Kernel: Add MSIxInfo struct to PCI DeviceIdentifier
Add a struct named MSIxInfo that stores all the relevant MSIx
information as a part of PCI DeviceIdentifier struct.

Populate the MSIx struct during the PCI device init. As the
DeviceIdentifier struct need to populate MSIx info, don't mark
DeviceIdentifier as const in the PCI::Device class.
2023-05-07 21:16:41 +02:00

32 lines
958 B
C++

/*
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/AnyOf.h>
#include <AK/Error.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefPtr.h>
#include <Kernel/Bus/PCI/Definitions.h>
namespace Kernel::PCI {
ErrorOr<NonnullRefPtr<DeviceIdentifier>> DeviceIdentifier::from_enumerable_identifier(EnumerableDeviceIdentifier const& other_identifier)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) DeviceIdentifier(other_identifier));
}
void DeviceIdentifier::initialize()
{
for (auto cap : capabilities()) {
if (cap.id() == PCI::Capabilities::ID::MSIX) {
auto msix_bir_bar = (cap.read8(4) & msix_table_bir_mask);
auto msix_bir_offset = (cap.read32(4) & msix_table_offset_mask);
auto msix_count = (cap.read16(2) & msix_control_table_mask) + 1;
m_msix_info = MSIxInfo(msix_count, msix_bir_bar, msix_bir_offset);
}
}
}
}