diff --git a/Kernel/Arch/init.cpp b/Kernel/Arch/init.cpp index 60578c4b42..205da3fb39 100644 --- a/Kernel/Arch/init.cpp +++ b/Kernel/Arch/init.cpp @@ -288,7 +288,8 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init([[maybe_unused]] BootInfo con ACPI::initialize(); #if ARCH(RISCV64) - // FIXME: Unflatten the device tree and use it for device discovery + MUST(unflatten_fdt()); + dump_fdt(); #endif diff --git a/Kernel/Arch/riscv64/CPU.cpp b/Kernel/Arch/riscv64/CPU.cpp index 6587e8560a..d2ff28e2c5 100644 --- a/Kernel/Arch/riscv64/CPU.cpp +++ b/Kernel/Arch/riscv64/CPU.cpp @@ -4,17 +4,27 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include +#include #include #include +static Singleton> s_device_tree; + namespace Kernel { BootInfo s_boot_info; alignas(PAGE_SIZE) __attribute__((section(".bss.fdt"))) u8 s_fdt_storage[fdt_storage_size]; +ErrorOr unflatten_fdt() +{ + *s_device_tree = TRY(DeviceTree::DeviceTree::parse({ s_fdt_storage, fdt_storage_size })); + return {}; +} + void dump_fdt() { auto& header = *bit_cast(&s_fdt_storage[0]); @@ -23,3 +33,9 @@ void dump_fdt() } } + +DeviceTree::DeviceTree const& DeviceTree::get() +{ + VERIFY(*s_device_tree); + return **s_device_tree; +} diff --git a/Kernel/Arch/riscv64/CPU.h b/Kernel/Arch/riscv64/CPU.h index 0ceba87467..2fc08a642e 100644 --- a/Kernel/Arch/riscv64/CPU.h +++ b/Kernel/Arch/riscv64/CPU.h @@ -8,6 +8,7 @@ #include #include +#include #include VALIDATE_IS_RISCV64() @@ -17,7 +18,14 @@ namespace Kernel { constexpr size_t fdt_storage_size = 2 * MiB; extern u8 s_fdt_storage[fdt_storage_size]; +// FIXME: These should move to an architecture independent location, +// once we need device tree parsing in other architectures, like aarch64 extern BootInfo s_boot_info; +ErrorOr unflatten_fdt(); void dump_fdt(); } + +namespace DeviceTree { +DeviceTree const& get(); +}