feat: partial PCIe support (MCFG table parsing)
[lunaix-os.git] / lunaix-os / hal / acpi / parser / mcfg_parser.c
diff --git a/lunaix-os/hal/acpi/parser/mcfg_parser.c b/lunaix-os/hal/acpi/parser/mcfg_parser.c
new file mode 100644 (file)
index 0000000..0efe0d5
--- /dev/null
@@ -0,0 +1,27 @@
+#include "lunaix/syslog.h"
+#include "parser.h"
+#include <lunaix/mm/kalloc.h>
+
+LOG_MODULE("MCFG")
+
+void
+mcfg_parse(acpi_sdthdr_t* mcfg, acpi_context* toc)
+{
+    size_t alloc_num = (mcfg->length - sizeof(acpi_sdthdr_t) - 8) /
+                       sizeof(struct acpi_mcfg_alloc);
+    struct acpi_mcfg_alloc* allocs =
+      (struct acpi_mcfg_alloc*)((uintptr_t)mcfg + (sizeof(acpi_sdthdr_t) + 8));
+
+    toc->mcfg.alloc_num = alloc_num;
+    toc->mcfg.allocations =
+      lxmalloc(sizeof(struct mcfg_alloc_info) * alloc_num);
+
+    for (size_t i = 0; i < alloc_num; i++) {
+        toc->mcfg.allocations[i] = (struct mcfg_alloc_info){
+            .base_addr = allocs[i].base_addr_lo,
+            .pci_bus_start = allocs[i].pci_bus_start,
+            .pci_bus_end = allocs[i].pci_bus_end,
+            .pci_seg_num = allocs[i].pci_seg_num,
+        };
+    }
+}
\ No newline at end of file