diff --git a/src/hulk/acpi.d b/src/hulk/acpi.d index 3741714..2d042f8 100644 --- a/src/hulk/acpi.d +++ b/src/hulk/acpi.d @@ -9,8 +9,14 @@ import hulk.memory; struct Acpi { - enum uint APIC_SIGNATURE = 0x43495041u; - enum uint XSDT_SIGNATURE = 0x54445358u; + static uint signature(string s) + { + return s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); + } + + enum uint APIC_SIGNATURE = signature("APIC"); + enum uint MCFG_SIGNATURE = signature("MCFG"); + enum uint XSDT_SIGNATURE = signature("XSDT"); static align(4) struct XsdtHeader { @@ -53,6 +59,38 @@ struct Acpi ubyte length; } + static struct MCFGTable + { + /* PCI Segment Group Memory Area Descriptor. */ + static struct SGMADesc + { + uint[2] base_address_a; + ushort pci_segment_group_number; + ubyte start_pci_bus_number; + ubyte end_pci_bus_number; + uint _reserved; + + public @property ulong base_address() const + { + return base_address_a[0] | (cast(ulong)base_address_a[1] << 32); + } + } + 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; + uint[2] _reserved; + SGMADesc[0] sgma_descs; + } + public static __gshared ulong apic_address; public static void initialize(ulong acpi_xsdt_phys) @@ -83,6 +121,10 @@ struct Acpi { parse_apic_table(address); } + else if (signature == MCFG_SIGNATURE) + { + parse_mcfg_table(address); + } } } @@ -105,4 +147,21 @@ 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); + 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); + } + } } diff --git a/src/hulk/usb/xhci.d b/src/hulk/usb/xhci.d index f54a8dd..5df6a61 100644 --- a/src/hulk/usb/xhci.d +++ b/src/hulk/usb/xhci.d @@ -84,7 +84,7 @@ struct XHCI void initialize(Pci.Device * pci_device) { void * base_address = pci_device.memory_ranges[0].address; - Klog.writefln("Found XHCI controller at address %x", base_address); + Klog.writefln("Found XHCI controller at address %p", base_address); m_capability_registers = cast(CapabilityRegisters *)base_address; m_operational_registers = cast(OperationalRegisters *)(base_address + m_capability_registers.capability_length); /* TODO: confirm if 0x400 offset is from m_operation_registers or base_address. */