Kernel/riscv64: Unflatten the DeviceTree

This commit is contained in:
Hediadyoin1 2024-02-14 15:01:21 +01:00 committed by Andrew Kaster
parent d3f6b03733
commit 7309427d2f
Notes: sideshowbarker 2024-07-17 14:36:19 +09:00
3 changed files with 26 additions and 1 deletions

View File

@ -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

View File

@ -4,17 +4,27 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Singleton.h>
#include <Kernel/Arch/riscv64/CPU.h>
#include <Kernel/Memory/MemoryManager.h>
#include <LibDeviceTree/DeviceTree.h>
#include <Userland/Libraries/LibDeviceTree/FlattenedDeviceTree.h>
#include <Userland/Libraries/LibDeviceTree/Validation.h>
static Singleton<OwnPtr<DeviceTree::DeviceTree>> s_device_tree;
namespace Kernel {
BootInfo s_boot_info;
alignas(PAGE_SIZE) __attribute__((section(".bss.fdt"))) u8 s_fdt_storage[fdt_storage_size];
ErrorOr<void> unflatten_fdt()
{
*s_device_tree = TRY(DeviceTree::DeviceTree::parse({ s_fdt_storage, fdt_storage_size }));
return {};
}
void dump_fdt()
{
auto& header = *bit_cast<DeviceTree::FlattenedDeviceTreeHeader*>(&s_fdt_storage[0]);
@ -23,3 +33,9 @@ void dump_fdt()
}
}
DeviceTree::DeviceTree const& DeviceTree::get()
{
VERIFY(*s_device_tree);
return **s_device_tree;
}

View File

@ -8,6 +8,7 @@
#include <Kernel/Memory/PhysicalAddress.h>
#include <Kernel/Prekernel/Prekernel.h>
#include <LibDeviceTree/DeviceTree.h>
#include <AK/Platform.h>
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<void> unflatten_fdt();
void dump_fdt();
}
namespace DeviceTree {
DeviceTree const& get();
}