Use Acpi.Header in ACPI table structures

This commit is contained in:
Josh Holtrop 2023-09-17 08:53:34 -04:00
parent 6514af8e94
commit e088f942d1

View File

@ -18,7 +18,7 @@ struct Acpi
enum uint MCFG_SIGNATURE = signature("MCFG");
enum uint XSDT_SIGNATURE = signature("XSDT");
static align(4) struct XsdtHeader
static align(4) struct Header
{
uint signature;
uint length;
@ -31,35 +31,27 @@ struct Acpi
uint creator_revision;
}
static struct Xsdt
static struct XSDT
{
XsdtHeader header;
Header header;
/* Table pointers are not ulong-aligned! They begin at offset 36. */
align(4) ulong[1] tables;
}
static struct MadtHeader
static struct MADT
{
uint signature;
uint length;
ubyte revision;
ubyte checksum;
char[6] oemid;
ulong oemtableid;
uint oem_revision;
uint creator_id;
uint creator_revision;
static struct Entry
{
ubyte type;
ubyte length;
}
Header header;
uint local_apic_address;
uint flags;
}
static struct MadtEntry
{
ubyte type;
ubyte length;
}
static struct MCFGTable
static struct MCFG
{
/* PCI Segment Group Memory Area Descriptor. */
static struct SGMADesc
@ -78,15 +70,7 @@ struct Acpi
static assert(SGMADesc.sizeof == 16);
static assert(SGMADesc.alignof == 4);
uint signature;
uint length;
ubyte revision;
ubyte checksum;
char[6] oemid;
ulong oemtableid;
uint oem_revision;
uint creator_id;
uint creator_revision;
Header header;
uint[2] _reserved;
SGMADesc[0] sgma_descs;
}
@ -96,8 +80,8 @@ struct Acpi
public static void initialize(ulong acpi_xsdt_phys)
{
/* Map the XSDT header. */
Hurl.identity_map_range(acpi_xsdt_phys, Xsdt.sizeof, 0u);
const(Xsdt) * xsdt = cast(const(Xsdt) *)acpi_xsdt_phys;
Hurl.identity_map_range(acpi_xsdt_phys, XSDT.sizeof, 0u);
const(XSDT) * xsdt = cast(const(XSDT) *)acpi_xsdt_phys;
if (xsdt.header.signature != XSDT_SIGNATURE)
{
Klog.writef("XSDT signature invalid\n");
@ -130,15 +114,15 @@ struct Acpi
private static parse_apic_table(ulong address)
{
const(MadtHeader) * madt_header = cast(const(MadtHeader) *)address;
Hurl.identity_map_range(address, madt_header.length, 0u);
apic_address = madt_header.local_apic_address;
const(MADT) * madt = cast(const(MADT) *)address;
Hurl.identity_map_range(address, madt.header.length, 0u);
apic_address = madt.local_apic_address;
Klog.writefln("Found 32-bit APIC address: 0x%x", apic_address);
const(void) * madt_end = cast(const(void) *)(address + madt_header.length);
const(MadtEntry) * madt_entry = cast(const(MadtEntry) *)(address + 0x2Cu);
const(void) * madt_end = cast(const(void) *)(address + madt.header.length);
const(MADT.Entry) * madt_entry = cast(const(MADT.Entry) *)(address + MADT.sizeof);
while (madt_entry < madt_end)
{
madt_entry = cast(const(MadtEntry) *)(cast(size_t)madt_entry + madt_entry.length);
madt_entry = cast(const(MADT.Entry) *)(cast(size_t)madt_entry + madt_entry.length);
if (madt_entry.type == 5u)
{
/* Found a 64-bit Local APIC Address Override entry. */
@ -150,18 +134,19 @@ struct Acpi
private static parse_mcfg_table(ulong address)
{
const(MCFGTable) * mcfg_table = cast(const(MCFGTable) *)address;
Hurl.identity_map_range(address, mcfg_table.length, 0u);
Klog.writefln("MCFG length = %u", mcfg_table.length);
size_t n_sgma_descs = (mcfg_table.length - MCFGTable.sgma_descs.offsetof) / MCFGTable.SGMADesc.sizeof;
Klog.writefln("# SGMA descriptors = %u", (mcfg_table.length - MCFGTable.sgma_descs.offsetof) / MCFGTable.SGMADesc.sizeof);
const(MCFG) * mcfg = cast(const(MCFG) *)address;
Hurl.identity_map_range(address, mcfg.header.length, 0u);
Klog.writefln("MCFG length = %u", mcfg.header.length);
size_t n_sgma_descs = (mcfg.header.length - MCFG.sgma_descs.offsetof) / MCFG.SGMADesc.sizeof;
Klog.writefln("# SGMA descriptors = %u", (mcfg.header.length - MCFG.sgma_descs.offsetof) / MCFG.SGMADesc.sizeof);
for (size_t i = 0; i < n_sgma_descs; i++)
{
Klog.writefln("SGMA %u: SG %u; Bus %u-%u; addr %p",
i, mcfg_table.sgma_descs[i].pci_segment_group_number,
mcfg_table.sgma_descs[i].start_pci_bus_number,
mcfg_table.sgma_descs[i].end_pci_bus_number,
mcfg_table.sgma_descs[i].base_address);
i,
mcfg.sgma_descs[i].pci_segment_group_number,
mcfg.sgma_descs[i].start_pci_bus_number,
mcfg.sgma_descs[i].end_pci_bus_number,
mcfg.sgma_descs[i].base_address);
}
}
}