diff --git a/src/hulk/acpi.d b/src/hulk/acpi.d index 1dad759..ce8dad9 100644 --- a/src/hulk/acpi.d +++ b/src/hulk/acpi.d @@ -15,7 +15,6 @@ struct Acpi */ private static __gshared List!Header tables; - enum uint MCFG_SIGNATURE = signature("MCFG"); enum uint XSDT_SIGNATURE = signature("XSDT"); /** @@ -45,37 +44,9 @@ struct Acpi } static assert(XSDT.tables.offsetof == 36); - static struct MCFG - { - /* 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); - - Header header; - uint[2] _reserved; - SGMADesc[0] sgma_descs; - - size_t n_sgma_descs() - { - return (header.length - MCFG.sgma_descs.offsetof) / MCFG.SGMADesc.sizeof; - } - } - - public __gshared MCFG * mcfg; - + /** + * Initialize ACPI. + */ public static void initialize(ulong acpi_xsdt_phys) { Klog.writefln("\a3Initializing ACPI"); @@ -112,14 +83,6 @@ struct Acpi (signature >> 16u) & 0xFFu, (signature >> 24u) & 0xFFu, address); - if (signature == MCFG_SIGNATURE) - { - mcfg = cast(MCFG *)address; - } - } - if (mcfg == null) - { - Klog.fatal_error("MCFG table not found"); } } @@ -143,6 +106,9 @@ struct Acpi return null; } + /** + * Map an ACPI table. + */ private static void map_table(ulong address, ulong length) { Hurl.identity_map_range(address, length, PT_WRITABLE | PT_DISABLE_CACHE | PT_NO_EXECUTE); diff --git a/src/hulk/pci.d b/src/hulk/pci.d index a6a0891..fad38e9 100644 --- a/src/hulk/pci.d +++ b/src/hulk/pci.d @@ -29,6 +29,38 @@ struct Pci /** XHCI controller device type. */ enum XHCI_CONTROLLER = Type(0x0Cu, 0x03u, 0x30u); + /** + * MCFG ACPI table structure. + */ + static struct MCFG + { + /* 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); + + Acpi.Header header; + uint[2] _reserved; + SGMADesc[0] sgma_descs; + + size_t n_sgma_descs() + { + return (header.length - MCFG.sgma_descs.offsetof) / MCFG.SGMADesc.sizeof; + } + } + /** * PCI device address (bus number, device number, function number). */ @@ -385,11 +417,12 @@ struct Pci public static void initialize() { - Klog.writefln("\a3Initializing PCI Bus"); - size_t n_sgma_descs = Acpi.mcfg.n_sgma_descs; + Klog.writefln("\a3Initializing PCI"); + MCFG * mcfg = cast(MCFG *)Acpi.get_table("MCFG"); + size_t n_sgma_descs = mcfg.n_sgma_descs; for (size_t i = 0u; i < n_sgma_descs; i++) { - Acpi.MCFG.SGMADesc * sgma_desc = &Acpi.mcfg.sgma_descs[i]; + MCFG.SGMADesc * sgma_desc = &mcfg.sgma_descs[i]; ulong base_address = sgma_desc.base_address; uint start_pci_bus = sgma_desc.start_pci_bus_number; uint end_pci_bus = sgma_desc.end_pci_bus_number;