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
27 FDT_RO_PROBE(fdt); in fdt_rw_probe_()
29 if (fdt_version(fdt) < 17) in fdt_rw_probe_()
31 if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry), in fdt_rw_probe_()
32 fdt_size_dt_struct(fdt))) in fdt_rw_probe_()
34 if (fdt_version(fdt) > 17) in fdt_rw_probe_()
35 fdt_set_version(fdt, 17); in fdt_rw_probe_()
40 #define FDT_RW_PROBE(fdt) \ argument
43 if ((err_ = fdt_rw_probe_(fdt)) != 0) \
47 static inline int fdt_data_size_(void *fdt) in fdt_data_size_() argument
49 return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); in fdt_data_size_()
52 static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen) in fdt_splice_() argument
55 char *end = (char *)fdt + fdt_data_size_(fdt); in fdt_splice_()
59 if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt)) in fdt_splice_()
61 if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt))) in fdt_splice_()
67 static int fdt_splice_mem_rsv_(void *fdt, struct fdt_reserve_entry *p, in fdt_splice_mem_rsv_() argument
72 err = fdt_splice_(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); in fdt_splice_mem_rsv_()
75 fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta); in fdt_splice_mem_rsv_()
76 fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); in fdt_splice_mem_rsv_()
80 static int fdt_splice_struct_(void *fdt, void *p, in fdt_splice_struct_() argument
86 if ((err = fdt_splice_(fdt, p, oldlen, newlen))) in fdt_splice_struct_()
89 fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta); in fdt_splice_struct_()
90 fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); in fdt_splice_struct_()
95 static void fdt_del_last_string_(void *fdt, const char *s) in fdt_del_last_string_() argument
99 fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) - newlen); in fdt_del_last_string_()
102 static int fdt_splice_string_(void *fdt, int newlen) in fdt_splice_string_() argument
104 void *p = (char *)fdt in fdt_splice_string_()
105 + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); in fdt_splice_string_()
108 if ((err = fdt_splice_(fdt, p, 0, newlen))) in fdt_splice_string_()
111 fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen); in fdt_splice_string_()
115 static int fdt_find_add_string_(void *fdt, const char *s, int *allocated) in fdt_find_add_string_() argument
117 char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); in fdt_find_add_string_()
125 p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s); in fdt_find_add_string_()
130 new = strtab + fdt_size_dt_strings(fdt); in fdt_find_add_string_()
131 err = fdt_splice_string_(fdt, len); in fdt_find_add_string_()
141 int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) in fdt_add_mem_rsv() argument
146 FDT_RW_PROBE(fdt); in fdt_add_mem_rsv()
148 re = fdt_mem_rsv_w_(fdt, fdt_num_mem_rsv(fdt)); in fdt_add_mem_rsv()
149 err = fdt_splice_mem_rsv_(fdt, re, 0, 1); in fdt_add_mem_rsv()
158 int fdt_del_mem_rsv(void *fdt, int n) in fdt_del_mem_rsv() argument
160 struct fdt_reserve_entry *re = fdt_mem_rsv_w_(fdt, n); in fdt_del_mem_rsv()
162 FDT_RW_PROBE(fdt); in fdt_del_mem_rsv()
164 if (n >= fdt_num_mem_rsv(fdt)) in fdt_del_mem_rsv()
167 return fdt_splice_mem_rsv_(fdt, re, 1, 0); in fdt_del_mem_rsv()
170 static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name, in fdt_resize_property_() argument
176 *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); in fdt_resize_property_()
180 if ((err = fdt_splice_struct_(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), in fdt_resize_property_()
188 static int fdt_add_property_(void *fdt, int nodeoffset, const char *name, in fdt_add_property_() argument
197 if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) in fdt_add_property_()
200 namestroff = fdt_find_add_string_(fdt, name, &allocated); in fdt_add_property_()
204 *prop = fdt_offset_ptr_w_(fdt, nextoffset); in fdt_add_property_()
207 err = fdt_splice_struct_(fdt, *prop, 0, proplen); in fdt_add_property_()
210 fdt_del_last_string_(fdt, name); in fdt_add_property_()
220 int fdt_set_name(void *fdt, int nodeoffset, const char *name) in fdt_set_name() argument
226 FDT_RW_PROBE(fdt); in fdt_set_name()
228 namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen); in fdt_set_name()
234 err = fdt_splice_struct_(fdt, namep, FDT_TAGALIGN(oldlen+1), in fdt_set_name()
243 int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, in fdt_setprop_placeholder() argument
249 FDT_RW_PROBE(fdt); in fdt_setprop_placeholder()
251 err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop); in fdt_setprop_placeholder()
253 err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); in fdt_setprop_placeholder()
261 int fdt_setprop(void *fdt, int nodeoffset, const char *name, in fdt_setprop() argument
267 err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data); in fdt_setprop()
276 int fdt_appendprop(void *fdt, int nodeoffset, const char *name, in fdt_appendprop() argument
282 FDT_RW_PROBE(fdt); in fdt_appendprop()
284 prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); in fdt_appendprop()
287 err = fdt_splice_struct_(fdt, prop->data, in fdt_appendprop()
295 err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); in fdt_appendprop()
303 int fdt_delprop(void *fdt, int nodeoffset, const char *name) in fdt_delprop() argument
308 FDT_RW_PROBE(fdt); in fdt_delprop()
310 prop = fdt_get_property_w(fdt, nodeoffset, name, &len); in fdt_delprop()
315 return fdt_splice_struct_(fdt, prop, proplen, 0); in fdt_delprop()
318 int fdt_add_subnode_namelen(void *fdt, int parentoffset, in fdt_add_subnode_namelen() argument
328 FDT_RW_PROBE(fdt); in fdt_add_subnode_namelen()
330 offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen); in fdt_add_subnode_namelen()
337 fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */ in fdt_add_subnode_namelen()
340 tag = fdt_next_tag(fdt, offset, &nextoffset); in fdt_add_subnode_namelen()
343 nh = fdt_offset_ptr_w_(fdt, offset); in fdt_add_subnode_namelen()
346 err = fdt_splice_struct_(fdt, nh, 0, nodelen); in fdt_add_subnode_namelen()
359 int fdt_add_subnode(void *fdt, int parentoffset, const char *name) in fdt_add_subnode() argument
361 return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name)); in fdt_add_subnode()
364 int fdt_del_node(void *fdt, int nodeoffset) in fdt_del_node() argument
368 FDT_RW_PROBE(fdt); in fdt_del_node()
370 endoffset = fdt_node_end_offset_(fdt, nodeoffset); in fdt_del_node()
374 return fdt_splice_struct_(fdt, fdt_offset_ptr_w_(fdt, nodeoffset), in fdt_del_node()
400 int fdt_open_into(const void *fdt, void *buf, int bufsize) in fdt_open_into() argument
405 const char *fdtstart = fdt; in fdt_open_into()
406 const char *fdtend = fdtstart + fdt_totalsize(fdt); in fdt_open_into()
409 FDT_RO_PROBE(fdt); in fdt_open_into()
411 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) in fdt_open_into()
414 if (fdt_version(fdt) >= 17) { in fdt_open_into()
415 struct_size = fdt_size_dt_struct(fdt); in fdt_open_into()
418 while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END) in fdt_open_into()
424 if (!fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) { in fdt_open_into()
426 err = fdt_move(fdt, buf, bufsize); in fdt_open_into()
437 + struct_size + fdt_size_dt_strings(fdt); in fdt_open_into()
452 fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size); in fdt_open_into()
459 fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt)); in fdt_open_into()
464 int fdt_pack(void *fdt) in fdt_pack() argument
468 FDT_RW_PROBE(fdt); in fdt_pack()
470 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) in fdt_pack()
472 fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt)); in fdt_pack()
473 fdt_set_totalsize(fdt, fdt_data_size_(fdt)); in fdt_pack()