Lines Matching defs:fdt
31 #include <fdt.h>
37 static int _fdt_blocks_misordered(const void *fdt,
40 return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8))
41 || (fdt_off_dt_struct(fdt) <
42 (fdt_off_mem_rsvmap(fdt) + mem_rsv_size))
43 || (fdt_off_dt_strings(fdt) <
44 (fdt_off_dt_struct(fdt) + struct_size))
45 || (fdt_totalsize(fdt) <
46 (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)));
49 static int _fdt_rw_check_header(void *fdt)
51 FDT_CHECK_HEADER(fdt);
53 if (fdt_version(fdt) < 17)
55 if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry),
56 fdt_size_dt_struct(fdt)))
58 if (fdt_version(fdt) > 17)
59 fdt_set_version(fdt, 17);
64 #define FDT_RW_CHECK_HEADER(fdt) \
67 if ((err = _fdt_rw_check_header(fdt)) != 0) \
71 static inline int _fdt_data_size(void *fdt)
73 return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
76 static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen)
79 char *end = (char *)fdt + _fdt_data_size(fdt);
83 if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
89 static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p,
94 err = _fdt_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p));
97 fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta);
98 fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);
102 static int _fdt_splice_struct(void *fdt, void *p,
108 if ((err = _fdt_splice(fdt, p, oldlen, newlen)))
111 fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta);
112 fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);
116 static int _fdt_splice_string(void *fdt, int newlen)
118 void *p = (char *)fdt
119 + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
122 if ((err = _fdt_splice(fdt, p, 0, newlen)))
125 fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen);
129 static int _fdt_find_add_string(void *fdt, const char *s)
131 char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
137 p = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s);
142 new = strtab + fdt_size_dt_strings(fdt);
143 err = _fdt_splice_string(fdt, len);
151 int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)
156 FDT_RW_CHECK_HEADER(fdt);
158 re = _fdt_mem_rsv_w(fdt, fdt_num_mem_rsv(fdt));
159 err = _fdt_splice_mem_rsv(fdt, re, 0, 1);
168 int fdt_del_mem_rsv(void *fdt, int n)
170 struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n);
173 FDT_RW_CHECK_HEADER(fdt);
175 if (n >= fdt_num_mem_rsv(fdt))
178 err = _fdt_splice_mem_rsv(fdt, re, 1, 0);
184 static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name,
190 *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
194 if ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen),
202 static int _fdt_add_property(void *fdt, int nodeoffset, const char *name,
210 if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)
213 namestroff = _fdt_find_add_string(fdt, name);
217 *prop = _fdt_offset_ptr_w(fdt, nextoffset);
220 err = _fdt_splice_struct(fdt, *prop, 0, proplen);
230 int fdt_set_name(void *fdt, int nodeoffset, const char *name)
236 FDT_RW_CHECK_HEADER(fdt);
238 namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen);
244 err = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1),
253 int fdt_setprop(void *fdt, int nodeoffset, const char *name,
259 FDT_RW_CHECK_HEADER(fdt);
261 err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop);
263 err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
271 int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
277 FDT_RW_CHECK_HEADER(fdt);
279 prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
282 err = _fdt_splice_struct(fdt, prop->data,
290 err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
298 int fdt_delprop(void *fdt, int nodeoffset, const char *name)
303 FDT_RW_CHECK_HEADER(fdt);
305 prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
310 return _fdt_splice_struct(fdt, prop, proplen, 0);
313 int fdt_add_subnode_namelen(void *fdt, int parentoffset,
323 FDT_RW_CHECK_HEADER(fdt);
325 offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
332 fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
335 tag = fdt_next_tag(fdt, offset, &nextoffset);
338 nh = _fdt_offset_ptr_w(fdt, offset);
341 err = _fdt_splice_struct(fdt, nh, 0, nodelen);
354 int fdt_add_subnode(void *fdt, int parentoffset, const char *name)
356 return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name));
359 int fdt_del_node(void *fdt, int nodeoffset)
363 FDT_RW_CHECK_HEADER(fdt);
365 endoffset = _fdt_node_end_offset(fdt, nodeoffset);
369 return _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset),
395 int fdt_open_into(const void *fdt, void *buf, int bufsize)
400 const char *fdtstart = fdt;
401 const char *fdtend = fdtstart + fdt_totalsize(fdt);
404 FDT_CHECK_HEADER(fdt);
406 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
409 if (fdt_version(fdt) >= 17) {
410 struct_size = fdt_size_dt_struct(fdt);
413 while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)
419 if (!_fdt_blocks_misordered(fdt, mem_rsv_size, struct_size)) {
421 err = fdt_move(fdt, buf, bufsize);
432 + struct_size + fdt_size_dt_strings(fdt);
447 _fdt_packblocks(fdt, tmp, mem_rsv_size, struct_size);
454 fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));
459 int fdt_pack(void *fdt)
463 FDT_RW_CHECK_HEADER(fdt);
465 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
467 _fdt_packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt));
468 fdt_set_totalsize(fdt, _fdt_data_size(fdt));