blob: a1d8118d47d0d04ac43302b60610118385bee78d [file] [log] [blame]
Mayank Groverf3b78182017-12-19 13:31:30 +05301#ifndef UFDT_TYPES_H
2#define UFDT_TYPES_H
3
4#include <libfdt.h>
5
6#define ASCII_PRINT_S (32)
7#define ASCII_PRINT_E (128)
8#define ASCII_PRINT_SZ (ASCII_PRINT_E - ASCII_PRINT_S)
9
10#define FDT_PROP_DELI ':'
11#define FDT_NODE_DELI '/'
12
13#define DTNL_INIT_SZ 4
14
15/* Empirical values for hash functions. */
16#define HASH_BASE 13131
17
18/* it has type : struct ufdt_node** */
19#define for_each(it, node_dict) \
20 if ((node_dict) != NULL) \
21 for (it = (node_dict)->nodes; \
22 it != (node_dict)->nodes + (node_dict)->mem_size; ++it) \
23 if (*it)
24
25#define for_each_child(it, node) \
26 if (tag_of(node) == FDT_BEGIN_NODE) \
27 for ((it) = &(((struct fdt_node_ufdt_node *)node)->child); *it; \
28 it = &((*it)->sibling))
29
30#define for_each_prop(it, node) \
31 for_each_child(it, node) if (tag_of(*it) == FDT_PROP)
32
33#define for_each_node(it, node) \
34 for_each_child(it, node) if (tag_of(*it) == FDT_BEGIN_NODE)
35
36/*
37 * Gets prop name from FDT requires complicated manipulation.
38 * To avoid the manipulation, the *name pointer in fdt_prop_ufdt_node
39 * is pointed to the final destination of the prop name in FDT.
40 * For the FDT_BEGIN_NODE name, it can be obtained from FDT directly.
41 */
42#define name_of(node) \
43 ((tag_of(node) == FDT_BEGIN_NODE) \
44 ? (((const struct fdt_node_header *)((node)->fdt_tag_ptr))->name) \
45 : (((const struct fdt_prop_ufdt_node *)node)->name))
46
47struct ufdt_node {
48 fdt32_t *fdt_tag_ptr;
49 struct ufdt_node *sibling;
50};
51
52struct ufdt_node_dict {
53 int mem_size;
54 int num_used;
55 struct ufdt_node **nodes;
56};
57
58struct fdt_prop_ufdt_node {
59 struct ufdt_node parent;
60 const char *name;
61};
62
63struct fdt_node_ufdt_node {
64 struct ufdt_node parent;
65 struct ufdt_node *child;
66 struct ufdt_node **last_child_p;
67};
68
69struct phandle_table_entry {
70 uint32_t phandle;
71 struct ufdt_node *node;
72};
73
74struct static_phandle_table {
75 int len;
76 struct phandle_table_entry *data;
77};
78
79struct ufdt {
80 void *fdtp;
81 struct ufdt_node *root;
82 struct static_phandle_table phandle_table;
83};
84
85typedef void func_on_ufdt_node(struct ufdt_node *, void *);
86
87struct ufdt_node_closure {
88 func_on_ufdt_node *func;
89 void *env;
90};
91
92static uint32_t tag_of(const struct ufdt_node *node) {
93 if (!node) return FDT_END;
94 return fdt32_to_cpu(*node->fdt_tag_ptr);
95}
96
97#endif /* UFDT_TYPES_H */