summaryrefslogtreecommitdiff
path: root/include/dtb.h
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-06-19 19:05:01 -0500
committerNathan Lee <me@nwlee.tech>2026-06-19 19:05:01 -0500
commit5c15e93fa87800b1f8fae7ef688a9d41221526f1 (patch)
tree2b8ed7b696edc9889b588dd79db14c564ea9a77e /include/dtb.h
parentb106df2447d23d6b3fcffa7cc87edde218d054f3 (diff)
create dtb allocator
the parent commit (b106df2447d23d6b3fcffa7cc87edde218d054f3) discussed the possibility of creating dtb device discovery. for that, we have replaced wdt device discovery with dtb device discovery. in the future, we will use the pci kernel module to use device discovery via a PCI controller
Diffstat (limited to 'include/dtb.h')
-rw-r--r--include/dtb.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/dtb.h b/include/dtb.h
new file mode 100644
index 0000000..1f8f14f
--- /dev/null
+++ b/include/dtb.h
@@ -0,0 +1,46 @@
+#pragma once
+#include <types.h>
+
+#define FDT_MAGIC 0xEDFE0DD0
+#define FDT_BEGIN_NODE 1
+#define FDT_END_NODE 2
+#define FDT_PROP 3
+#define FDT_NOP 4
+#define FDT_END 9
+
+#define DTB_MAX_NODES 16
+
+struct dt_node {
+ char *name;
+ struct dt_prop *props;
+ struct dt_node *children;
+ struct dt_node *next;
+};
+
+struct dt_prop {
+ char *name;
+ char *value;
+ size_t len;
+ struct dt_prop *next;
+};
+
+struct fdt_header {
+ uint32_t magic;
+ uint32_t totalsize;
+ uint32_t off_dt_struct;
+ uint32_t off_dt_strings;
+ uint32_t off_mem_rsvmap;
+ uint32_t version;
+ uint32_t last_comp_version;
+ uint32_t boot_cpuid_phys;
+ uint32_t size_dt_strings;
+ uint32_t size_dt_struct;
+};
+
+struct dt_node *dt_parse(void *fdt);
+void *dt_get_prop(struct dt_node *node, char *name, size_t *len);
+uint32_t dt_read_u32(struct dt_node *node, char *name, uint32_t *out);
+
+
+struct dt_node *dt_node_alloc(char *name);
+struct dt_prop *dt_prop_alloc(char *name, void *value, size_t len);