1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef _KERNEL_DRIVERS_DEVTREE_H
10#define _KERNEL_DRIVERS_DEVTREE_H
11
12#include <libkern/c_attrs.h>
13#include <libkern/types.h>
14#include <mem/boot.h>
15
16#define DEVTREE_HEADER_SIGNATURE ("odtr3")
17#define DEVTREE_HEADER_SIGNATURE_LEN (sizeof(DEVTREE_HEADER_SIGNATURE) - 1)
18
19struct PACKED devtree_header {
20 char signature[8];
21 uint32_t revision;
22 uint32_t flags;
23 uint32_t entries_count;
24 uint32_t name_list_offset;
25};
26typedef struct devtree_header devtree_header_t;
27
28#define DEVTREE_ENTRY_FLAGS_MMIO = (1 << 0)
29#define DEVTREE_ENTRY_TYPE_IO (0)
30#define DEVTREE_ENTRY_TYPE_FB (1)
31#define DEVTREE_ENTRY_TYPE_UART (2)
32#define DEVTREE_ENTRY_TYPE_RAM (3)
33#define DEVTREE_ENTRY_TYPE_STORAGE (4)
34#define DEVTREE_ENTRY_TYPE_BUS_CONTROLLER (5)
35
36struct PACKED devtree_entry {
37 uint32_t type;
38 uint32_t flags;
39 uint32_t paddr;
40 uint32_t rel_name_offset;
41};
42typedef struct devtree_entry devtree_entry_t;
43
44int devtree_init(boot_desc_t* boot_desc);
45devtree_entry_t* devtree_find_device(const char* name);
46const char* devtree_name_of_entry(devtree_entry_t* en);
47devtree_entry_t* devtree_new_entry(const devtree_entry_t* from);
48
49#endif // _KERNEL_DRIVERS_DEVTREE_H