Lines Matching refs:fdt
13 static int fdt_blocks_misordered_(const void *fdt, in fdt_blocks_misordered_() argument
16 return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8)) in fdt_blocks_misordered_()
17 || (fdt_off_dt_struct(fdt) < in fdt_blocks_misordered_()
18 (fdt_off_mem_rsvmap(fdt) + mem_rsv_size)) in fdt_blocks_misordered_()
19 || (fdt_off_dt_strings(fdt) < in fdt_blocks_misordered_()
20 (fdt_off_dt_struct(fdt) + struct_size)) in fdt_blocks_misordered_()
21 || (fdt_totalsize(fdt) < in fdt_blocks_misordered_()
22 (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt))); in fdt_blocks_misordered_()
25 static int fdt_rw_probe_(void *fdt) in fdt_rw_probe_() argument
29 FDT_RO_PROBE(fdt); in fdt_rw_probe_()
31 if (!can_assume(LATEST) && fdt_version(fdt) < 17) in fdt_rw_probe_()
33 if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry), in fdt_rw_probe_()
34 fdt_size_dt_struct(fdt))) in fdt_rw_probe_()
36 if (!can_assume(LATEST) && fdt_version(fdt) > 17) in fdt_rw_probe_()
37 fdt_set_version(fdt, 17); in fdt_rw_probe_()
42 #define FDT_RW_PROBE(fdt) \ argument
45 if ((err_ = fdt_rw_probe_(fdt)) != 0) \
49 static inline unsigned int fdt_data_size_(void *fdt) in fdt_data_size_() argument
51 return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); in fdt_data_size_()
54 static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen) in fdt_splice_() argument
57 unsigned int dsize = fdt_data_size_(fdt); in fdt_splice_()
58 size_t soff = p - (char *)fdt; in fdt_splice_()
62 if ((p < (char *)fdt) || (dsize + newlen < (unsigned)oldlen)) in fdt_splice_()
64 if (dsize - oldlen + newlen > fdt_totalsize(fdt)) in fdt_splice_()
66 memmove(p + newlen, p + oldlen, ((char *)fdt + dsize) - (p + oldlen)); in fdt_splice_()
70 static int fdt_splice_mem_rsv_(void *fdt, struct fdt_reserve_entry *p, in fdt_splice_mem_rsv_() argument
75 err = fdt_splice_(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); in fdt_splice_mem_rsv_()
78 fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta); in fdt_splice_mem_rsv_()
79 fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); in fdt_splice_mem_rsv_()
83 static int fdt_splice_struct_(void *fdt, void *p, in fdt_splice_struct_() argument
89 if ((err = fdt_splice_(fdt, p, oldlen, newlen))) in fdt_splice_struct_()
92 fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta); in fdt_splice_struct_()
93 fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); in fdt_splice_struct_()
98 static void fdt_del_last_string_(void *fdt, const char *s) in fdt_del_last_string_() argument
102 fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) - newlen); in fdt_del_last_string_()
105 static int fdt_splice_string_(void *fdt, int newlen) in fdt_splice_string_() argument
107 void *p = (char *)fdt in fdt_splice_string_()
108 + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); in fdt_splice_string_()
111 if ((err = fdt_splice_(fdt, p, 0, newlen))) in fdt_splice_string_()
114 fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen); in fdt_splice_string_()
127 static int fdt_find_add_string_(void *fdt, const char *s, int *allocated) in fdt_find_add_string_() argument
129 char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); in fdt_find_add_string_()
138 p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s); in fdt_find_add_string_()
143 new = strtab + fdt_size_dt_strings(fdt); in fdt_find_add_string_()
144 err = fdt_splice_string_(fdt, len); in fdt_find_add_string_()
155 int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) in fdt_add_mem_rsv() argument
160 FDT_RW_PROBE(fdt); in fdt_add_mem_rsv()
162 re = fdt_mem_rsv_w_(fdt, fdt_num_mem_rsv(fdt)); in fdt_add_mem_rsv()
163 err = fdt_splice_mem_rsv_(fdt, re, 0, 1); in fdt_add_mem_rsv()
172 int fdt_del_mem_rsv(void *fdt, int n) in fdt_del_mem_rsv() argument
174 struct fdt_reserve_entry *re = fdt_mem_rsv_w_(fdt, n); in fdt_del_mem_rsv()
176 FDT_RW_PROBE(fdt); in fdt_del_mem_rsv()
178 if (n >= fdt_num_mem_rsv(fdt)) in fdt_del_mem_rsv()
181 return fdt_splice_mem_rsv_(fdt, re, 1, 0); in fdt_del_mem_rsv()
184 static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name, in fdt_resize_property_() argument
190 *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); in fdt_resize_property_()
194 if ((err = fdt_splice_struct_(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), in fdt_resize_property_()
202 static int fdt_add_property_(void *fdt, int nodeoffset, const char *name, in fdt_add_property_() argument
211 if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) in fdt_add_property_()
214 namestroff = fdt_find_add_string_(fdt, name, &allocated); in fdt_add_property_()
218 *prop = fdt_offset_ptr_w_(fdt, nextoffset); in fdt_add_property_()
221 err = fdt_splice_struct_(fdt, *prop, 0, proplen); in fdt_add_property_()
225 fdt_del_last_string_(fdt, name); in fdt_add_property_()
235 int fdt_set_name(void *fdt, int nodeoffset, const char *name) in fdt_set_name() argument
241 FDT_RW_PROBE(fdt); in fdt_set_name()
243 namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen); in fdt_set_name()
249 err = fdt_splice_struct_(fdt, namep, FDT_TAGALIGN(oldlen+1), in fdt_set_name()
258 int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, in fdt_setprop_placeholder() argument
264 FDT_RW_PROBE(fdt); in fdt_setprop_placeholder()
266 err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop); in fdt_setprop_placeholder()
268 err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); in fdt_setprop_placeholder()
276 int fdt_setprop(void *fdt, int nodeoffset, const char *name, in fdt_setprop() argument
282 err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data); in fdt_setprop()
291 int fdt_appendprop(void *fdt, int nodeoffset, const char *name, in fdt_appendprop() argument
297 FDT_RW_PROBE(fdt); in fdt_appendprop()
299 prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); in fdt_appendprop()
302 err = fdt_splice_struct_(fdt, prop->data, in fdt_appendprop()
310 err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); in fdt_appendprop()
318 int fdt_delprop(void *fdt, int nodeoffset, const char *name) in fdt_delprop() argument
323 FDT_RW_PROBE(fdt); in fdt_delprop()
325 prop = fdt_get_property_w(fdt, nodeoffset, name, &len); in fdt_delprop()
330 return fdt_splice_struct_(fdt, prop, proplen, 0); in fdt_delprop()
333 int fdt_add_subnode_namelen(void *fdt, int parentoffset, in fdt_add_subnode_namelen() argument
343 FDT_RW_PROBE(fdt); in fdt_add_subnode_namelen()
345 offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen); in fdt_add_subnode_namelen()
352 tag = fdt_next_tag(fdt, parentoffset, &nextoffset); in fdt_add_subnode_namelen()
358 tag = fdt_next_tag(fdt, offset, &nextoffset); in fdt_add_subnode_namelen()
361 nh = fdt_offset_ptr_w_(fdt, offset); in fdt_add_subnode_namelen()
364 err = fdt_splice_struct_(fdt, nh, 0, nodelen); in fdt_add_subnode_namelen()
377 int fdt_add_subnode(void *fdt, int parentoffset, const char *name) in fdt_add_subnode() argument
379 return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name)); in fdt_add_subnode()
382 int fdt_del_node(void *fdt, int nodeoffset) in fdt_del_node() argument
386 FDT_RW_PROBE(fdt); in fdt_del_node()
388 endoffset = fdt_node_end_offset_(fdt, nodeoffset); in fdt_del_node()
392 return fdt_splice_struct_(fdt, fdt_offset_ptr_w_(fdt, nodeoffset), in fdt_del_node()
419 int fdt_open_into(const void *fdt, void *buf, int bufsize) in fdt_open_into() argument
424 const char *fdtstart = fdt; in fdt_open_into()
425 const char *fdtend = fdtstart + fdt_totalsize(fdt); in fdt_open_into()
428 FDT_RO_PROBE(fdt); in fdt_open_into()
430 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) in fdt_open_into()
433 if (can_assume(LATEST) || fdt_version(fdt) >= 17) { in fdt_open_into()
434 struct_size = fdt_size_dt_struct(fdt); in fdt_open_into()
435 } else if (fdt_version(fdt) == 16) { in fdt_open_into()
437 while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END) in fdt_open_into()
446 !fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) { in fdt_open_into()
448 err = fdt_move(fdt, buf, bufsize); in fdt_open_into()
459 + struct_size + fdt_size_dt_strings(fdt); in fdt_open_into()
474 fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size, in fdt_open_into()
475 fdt_size_dt_strings(fdt)); in fdt_open_into()
482 fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt)); in fdt_open_into()
487 int fdt_pack(void *fdt) in fdt_pack() argument
491 FDT_RW_PROBE(fdt); in fdt_pack()
493 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) in fdt_pack()
495 fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt), in fdt_pack()
496 fdt_size_dt_strings(fdt)); in fdt_pack()
497 fdt_set_totalsize(fdt, fdt_data_size_(fdt)); in fdt_pack()