1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef __DEVICE_TREE_H__
15#define __DEVICE_TREE_H__
16
17void *create_device_tree(int *sizep);
18void *load_device_tree(const char *filename_path, int *sizep);
19#ifdef CONFIG_LINUX
20
21
22
23
24
25void *load_device_tree_from_sysfs(void);
26#endif
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
44 Error **errp);
45
46int qemu_fdt_setprop(void *fdt, const char *node_path,
47 const char *property, const void *val, int size);
48int qemu_fdt_setprop_cell(void *fdt, const char *node_path,
49 const char *property, uint32_t val);
50int qemu_fdt_setprop_u64(void *fdt, const char *node_path,
51 const char *property, uint64_t val);
52int qemu_fdt_setprop_string(void *fdt, const char *node_path,
53 const char *property, const char *string);
54int qemu_fdt_setprop_phandle(void *fdt, const char *node_path,
55 const char *property,
56 const char *target_node_path);
57void *qemu_fdt_getprop(void *fdt, const char *node_path,
58 const char *property, int *lenp,
59 bool inherit, Error **errp);
60uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path,
61 const char *property, int offset,
62 bool inherit, Error **errp);
63uint64_t qemu_fdt_getprop_sized_cell(void *fdt, const char *node_path,
64 const char *property, int offset,
65 int size, Error **errp);
66char *qemu_fdt_getprop_string(void *fdt, const char*node_path,
67 const char *property, int cell,
68 bool inherit, Error **errp);
69uint32_t qemu_fdt_get_phandle(void *fdt, const char *path);
70uint32_t qemu_fdt_check_phandle(void *fdt, const char *path);
71uint32_t qemu_fdt_alloc_phandle(void *fdt);
72int qemu_fdt_nop_node(void *fdt, const char *node_path);
73int qemu_fdt_add_subnode(void *fdt, const char *name);
74
75#define qemu_fdt_setprop_cells(fdt, node_path, property, ...) \
76 do { \
77 uint32_t qdt_tmp[] = { __VA_ARGS__ }; \
78 int i; \
79 \
80 for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) { \
81 qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]); \
82 } \
83 qemu_fdt_setprop(fdt, node_path, property, qdt_tmp, \
84 sizeof(qdt_tmp)); \
85 } while (0)
86
87void qemu_fdt_dumpdtb(void *fdt, int size);
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116int qemu_fdt_setprop_sized_cells_from_array(void *fdt,
117 const char *node_path,
118 const char *property,
119 int numvalues,
120 uint64_t *values);
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139#define qemu_fdt_setprop_sized_cells(fdt, node_path, property, ...) \
140 ({ \
141 uint64_t qdt_tmp[] = { __VA_ARGS__ }; \
142 qemu_fdt_setprop_sized_cells_from_array(fdt, node_path, \
143 property, \
144 ARRAY_SIZE(qdt_tmp) / 2, \
145 qdt_tmp); \
146 })
147
148typedef struct QEMUDevtreeProp {
149 char *name;
150 int len;
151 void *value;
152} QEMUDevtreeProp;
153
154
155
156char *qemu_devtree_get_node_name(void *fdt, const char *node_path);
157int qemu_devtree_get_node_depth(void *fdt, const char *node_path);
158int qemu_devtree_get_num_children(void *fdt, const char *node_path, int depth);
159char **qemu_devtree_get_children(void *fdt, const char *node_path, int depth);
160int qemu_devtree_num_props(void *fdt, const char *node_path);
161QEMUDevtreeProp *qemu_devtree_get_props(void *fdt, const char *node_path);
162
163
164
165int qemu_devtree_node_by_compatible(void *fdt, char *node_path,
166 const char *compats);
167int qemu_devtree_get_node_by_name(void *fdt, char *node_path,
168 const char *cmpname);
169int qemu_devtree_get_node_by_phandle(void *fdt, char *node_path, int phandle);
170int qemu_devtree_getparent(void *fdt, char *node_path,
171 const char *current);
172int qemu_devtree_get_root_node(void *fdt, char *node_path);
173
174
175
176
177
178
179
180
181
182
183
184
185char *qemu_devtree_get_child_by_name(void *fdt, char *parent_path,
186 const char *cmpname);
187
188
189
190
191
192
193
194
195
196
197
198
199
200int qemu_devtree_get_n_nodes_by_name(void *fdt, char ***array,
201 const char *cmpname);
202
203
204
205int devtree_get_num_nodes(void *fdt);
206void devtree_info_dump(void *fdt);
207
208#define DT_PATH_LENGTH 1024
209
210#define FDT_PCI_RANGE_RELOCATABLE 0x80000000
211#define FDT_PCI_RANGE_PREFETCHABLE 0x40000000
212#define FDT_PCI_RANGE_ALIASED 0x20000000
213#define FDT_PCI_RANGE_TYPE_MASK 0x03000000
214#define FDT_PCI_RANGE_MMIO_64BIT 0x03000000
215#define FDT_PCI_RANGE_MMIO 0x02000000
216#define FDT_PCI_RANGE_IOPORT 0x01000000
217#define FDT_PCI_RANGE_CONFIG 0x00000000
218
219#endif
220