Some minor adjustments to ensure alignment of PCI header.

This commit is contained in:
Patrick 2024-01-29 18:39:45 +01:00
parent 54a5ee720f
commit 00f4e0de3a
2 changed files with 12 additions and 8 deletions

View File

@ -9,6 +9,7 @@
namespace baos::pci
{
// <editor-fold desc="PCI Class Enums">
enum class BaseClass : std::uint8_t
{
UNCLASSIFIED = 0x0,
@ -164,6 +165,7 @@ enum class SubClass : std::uint8_t
COMMUNICATION_SYNCHRONIZER = 0x10,
SIGNAL_PROCESSING_MANAGEMENT = 0x20
};
//</editor-fold>
enum class HeaderType : std::uint8_t
{
@ -172,7 +174,7 @@ enum class HeaderType : std::uint8_t
PCI_TO_CARDBUS_BRIDGE = 0x2
};
struct Header
struct alignas(32) Header
{
std::uint8_t bus;
std::uint8_t device;
@ -183,10 +185,12 @@ struct Header
std::uint16_t deviceID;
std::uint16_t command;
std::uint16_t status;
std::uint8_t revisionID;
std::uint8_t progIf;
SubClass subClass;
BaseClass baseClass;
std::uint8_t cacheLineSize;
std::uint8_t latencyTimer;
HeaderType headerType : 7;

View File

@ -96,23 +96,23 @@ void enumerateDevice(const Header& header, std::vector<Header>& outHeaders) noex
std::vector<Header> enumerateDevices() noexcept
{
Header header = {};
if (!getHeader(0, 0, 0, header)) {
Header hostControllerHeader = {};
if (!getHeader(0, 0, 0, hostControllerHeader)) {
return {};
}
// also add the controller itself
std::vector<Header> headers;
headers.push_back(header);
// also add the controller itself
headers.push_back(hostControllerHeader);
enumerateBusDevices(0, headers, /* firstDevice = */ 1);
if (header.multiFunction)
if (hostControllerHeader.multiFunction)
{
for (std::uint8_t function = 1; function < 8; ++function)
{
if (!getHeader(0, 0, function, header)) {
if (!getHeader(0, 0, function, hostControllerHeader)) {
continue;
}
headers.push_back(header);
headers.push_back(hostControllerHeader);
enumerateBusDevices(function, headers);
}
}