9 #include <libfdt_env.h> 12 #define FDT_FIRST_SUPPORTED_VERSION 0x02 13 #define FDT_LAST_SUPPORTED_VERSION 0x11 16 #define FDT_ERR_NOTFOUND 1 18 #define FDT_ERR_EXISTS 2 21 #define FDT_ERR_NOSPACE 3 28 #define FDT_ERR_BADOFFSET 4 32 #define FDT_ERR_BADPATH 5 36 #define FDT_ERR_BADPHANDLE 6 41 #define FDT_ERR_BADSTATE 7 47 #define FDT_ERR_TRUNCATED 8 51 #define FDT_ERR_BADMAGIC 9 55 #define FDT_ERR_BADVERSION 10 60 #define FDT_ERR_BADSTRUCTURE 11 64 #define FDT_ERR_BADLAYOUT 12 72 #define FDT_ERR_INTERNAL 13 78 #define FDT_ERR_BADNCELLS 14 82 #define FDT_ERR_BADVALUE 15 87 #define FDT_ERR_BADOVERLAY 16 92 #define FDT_ERR_NOPHANDLES 17 96 #define FDT_ERR_BADFLAGS 18 100 #define FDT_ERR_MAX 18 103 #define FDT_MAX_PHANDLE 0xfffffffe 111 const void *fdt_offset_ptr(
const void *fdt,
int offset,
unsigned int checklen);
113 static inline void *fdt_offset_ptr_w(
void *fdt,
int offset,
int checklen)
115 return (
void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
118 uint32_t fdt_next_tag(
const void *fdt,
int offset,
int *nextoffset);
127 static inline uint32_t fdt32_ld(
const fdt32_t *
p)
129 const uint8_t *bp = (
const uint8_t *)
p;
131 return ((uint32_t)bp[0] << 24)
132 | ((uint32_t)bp[1] << 16)
133 | ((uint32_t)bp[2] << 8)
137 static inline void fdt32_st(
void *property, uint32_t value)
139 uint8_t *bp = (uint8_t *)property;
142 bp[1] = (value >> 16) & 0xff;
143 bp[2] = (value >> 8) & 0xff;
144 bp[3] = value & 0xff;
147 static inline uint64_t fdt64_ld(
const fdt64_t *
p)
149 const uint8_t *bp = (
const uint8_t *)
p;
151 return ((uint64_t)bp[0] << 56)
152 | ((uint64_t)bp[1] << 48)
153 | ((uint64_t)bp[2] << 40)
154 | ((uint64_t)bp[3] << 32)
155 | ((uint64_t)bp[4] << 24)
156 | ((uint64_t)bp[5] << 16)
157 | ((uint64_t)bp[6] << 8)
161 static inline void fdt64_st(
void *property, uint64_t value)
163 uint8_t *bp = (uint8_t *)property;
166 bp[1] = (value >> 48) & 0xff;
167 bp[2] = (value >> 40) & 0xff;
168 bp[3] = (value >> 32) & 0xff;
169 bp[4] = (value >> 24) & 0xff;
170 bp[5] = (value >> 16) & 0xff;
171 bp[6] = (value >> 8) & 0xff;
172 bp[7] = value & 0xff;
179 int fdt_next_node(
const void *fdt,
int offset,
int *depth);
188 int fdt_first_subnode(
const void *fdt,
int offset);
201 int fdt_next_subnode(
const void *fdt,
int offset);
226 #define fdt_for_each_subnode(node, fdt, parent) \ 227 for (node = fdt_first_subnode(fdt, parent); \ 229 node = fdt_next_subnode(fdt, node)) 234 #define fdt_get_header(fdt, field) \ 235 (fdt32_ld(&((const struct fdt_header *)(fdt))->field)) 236 #define fdt_magic(fdt) (fdt_get_header(fdt, magic)) 237 #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) 238 #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) 239 #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) 240 #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) 241 #define fdt_version(fdt) (fdt_get_header(fdt, version)) 242 #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) 243 #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) 244 #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) 245 #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) 247 #define fdt_set_hdr_(name) \ 248 static inline void fdt_set_##name(void *fdt, uint32_t val) \ 250 struct fdt_header *fdth = (struct fdt_header *)fdt; \ 251 fdth->name = cpu_to_fdt32(val); \ 254 fdt_set_hdr_(totalsize);
255 fdt_set_hdr_(off_dt_struct);
256 fdt_set_hdr_(off_dt_strings);
257 fdt_set_hdr_(off_mem_rsvmap);
258 fdt_set_hdr_(version);
259 fdt_set_hdr_(last_comp_version);
260 fdt_set_hdr_(boot_cpuid_phys);
261 fdt_set_hdr_(size_dt_strings);
262 fdt_set_hdr_(size_dt_struct);
269 size_t fdt_header_size(
const void *fdt);
274 size_t fdt_header_size_(uint32_t version);
293 int fdt_check_header(
const void *fdt);
314 int fdt_move(
const void *fdt,
void *buf,
int bufsize);
320 int fdt_check_full(
const void *fdt,
size_t bufsize);
336 const char *fdt_get_string(
const void *fdt,
int stroffset,
int *lenp);
350 const char *fdt_string(
const void *fdt,
int stroffset);
364 int fdt_find_max_phandle(
const void *fdt, uint32_t *phandle);
381 static inline uint32_t fdt_get_max_phandle(
const void *fdt)
386 err = fdt_find_max_phandle(fdt, &phandle);
406 int fdt_generate_phandle(
const void *fdt, uint32_t *phandle);
419 int fdt_num_mem_rsv(
const void *fdt);
436 int fdt_get_mem_rsv(
const void *fdt,
int n, uint64_t *address, uint64_t *
size);
451 int fdt_subnode_offset_namelen(
const void *fdt,
int parentoffset,
452 const char *name,
int namelen);
478 int fdt_subnode_offset(
const void *fdt,
int parentoffset,
const char *name);
490 int fdt_path_offset_namelen(
const void *fdt,
const char *path,
int namelen);
516 int fdt_path_offset(
const void *fdt,
const char *path);
541 const char *fdt_get_name(
const void *fdt,
int nodeoffset,
int *lenp);
561 int fdt_first_property_offset(
const void *fdt,
int nodeoffset);
582 int fdt_next_property_offset(
const void *fdt,
int offset);
606 #define fdt_for_each_property_offset(property, fdt, node) \ 607 for (property = fdt_first_property_offset(fdt, node); \ 609 property = fdt_next_property_offset(fdt, property)) 638 const struct fdt_property *fdt_get_property_by_offset(
const void *fdt,
654 const struct fdt_property *fdt_get_property_namelen(
const void *fdt,
657 int namelen,
int *lenp);
688 const struct fdt_property *fdt_get_property(
const void *fdt,
int nodeoffset,
689 const char *name,
int *lenp);
690 static inline struct fdt_property *fdt_get_property_w(
void *fdt,
int nodeoffset,
695 fdt_get_property(fdt, nodeoffset, name, lenp);
730 const void *fdt_getprop_by_offset(
const void *fdt,
int offset,
731 const char **namep,
int *lenp);
746 const void *fdt_getprop_namelen(
const void *fdt,
int nodeoffset,
747 const char *name,
int namelen,
int *lenp);
748 static inline void *fdt_getprop_namelen_w(
void *fdt,
int nodeoffset,
749 const char *name,
int namelen,
752 return (
void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
785 const void *fdt_getprop(
const void *fdt,
int nodeoffset,
786 const char *name,
int *lenp);
787 static inline void *fdt_getprop_w(
void *fdt,
int nodeoffset,
788 const char *name,
int *lenp)
790 return (
void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
805 uint32_t fdt_get_phandle(
const void *fdt,
int nodeoffset);
817 const char *fdt_get_alias_namelen(
const void *fdt,
818 const char *name,
int namelen);
833 const char *fdt_get_alias(
const void *fdt,
const char *name);
860 int fdt_get_path(
const void *fdt,
int nodeoffset,
char *buf,
int buflen);
892 int fdt_supernode_atdepth_offset(
const void *fdt,
int nodeoffset,
893 int supernodedepth,
int *nodedepth);
914 int fdt_node_depth(
const void *fdt,
int nodeoffset);
937 int fdt_parent_offset(
const void *fdt,
int nodeoffset);
977 int fdt_node_offset_by_prop_value(
const void *fdt,
int startoffset,
978 const char *propname,
979 const void *propval,
int proplen);
1000 int fdt_node_offset_by_phandle(
const void *fdt, uint32_t phandle);
1024 int fdt_node_check_compatible(
const void *fdt,
int nodeoffset,
1025 const char *compatible);
1061 int fdt_node_offset_by_compatible(
const void *fdt,
int startoffset,
1062 const char *compatible);
1076 int fdt_stringlist_contains(
const char *strlist,
int listlen,
const char *str);
1088 int fdt_stringlist_count(
const void *fdt,
int nodeoffset,
const char *property);
1109 int fdt_stringlist_search(
const void *fdt,
int nodeoffset,
const char *property,
1110 const char *
string);
1136 const char *fdt_stringlist_get(
const void *fdt,
int nodeoffset,
1137 const char *property,
int index,
1153 #define FDT_MAX_NCELLS 4 1173 int fdt_address_cells(
const void *fdt,
int nodeoffset);
1194 int fdt_size_cells(
const void *fdt,
int nodeoffset);
1218 int fdt_setprop_inplace_namelen_partial(
void *fdt,
int nodeoffset,
1219 const char *name,
int namelen,
1220 uint32_t idx,
const void *val,
1253 int fdt_setprop_inplace(
void *fdt,
int nodeoffset,
const char *name,
1254 const void *val,
int len);
1285 static inline int fdt_setprop_inplace_u32(
void *fdt,
int nodeoffset,
1286 const char *name, uint32_t val)
1288 fdt32_t tmp = cpu_to_fdt32(val);
1289 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1320 static inline int fdt_setprop_inplace_u64(
void *fdt,
int nodeoffset,
1321 const char *name, uint64_t val)
1323 fdt64_t tmp = cpu_to_fdt64(val);
1324 return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1332 static inline int fdt_setprop_inplace_cell(
void *fdt,
int nodeoffset,
1333 const char *name, uint32_t val)
1335 return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
1362 int fdt_nop_property(
void *fdt,
int nodeoffset,
const char *name);
1386 int fdt_nop_node(
void *fdt,
int nodeoffset);
1393 #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1 1398 #define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP) 1416 int fdt_create_with_flags(
void *buf,
int bufsize, uint32_t flags);
1429 int fdt_create(
void *buf,
int bufsize);
1431 int fdt_resize(
void *fdt,
void *buf,
int bufsize);
1432 int fdt_add_reservemap_entry(
void *fdt, uint64_t addr, uint64_t
size);
1433 int fdt_finish_reservemap(
void *fdt);
1434 int fdt_begin_node(
void *fdt,
const char *name);
1435 int fdt_property(
void *fdt,
const char *name,
const void *val,
int len);
1436 static inline int fdt_property_u32(
void *fdt,
const char *name, uint32_t val)
1438 fdt32_t tmp = cpu_to_fdt32(val);
1441 static inline int fdt_property_u64(
void *fdt,
const char *name, uint64_t val)
1443 fdt64_t tmp = cpu_to_fdt64(val);
1448 static inline int fdt_property_cell(
void *fdt,
const char *name, uint32_t val)
1450 return fdt_property_u32(fdt, name, val);
1467 int fdt_property_placeholder(
void *fdt,
const char *name,
int len,
void **valp);
1469 #define fdt_property_string(fdt, name, str) \ 1470 fdt_property(fdt, name, str, strlen(str)+1) 1471 int fdt_end_node(
void *fdt);
1472 int fdt_finish(
void *fdt);
1478 int fdt_create_empty_tree(
void *buf,
int bufsize);
1479 int fdt_open_into(
const void *fdt,
void *buf,
int bufsize);
1480 int fdt_pack(
void *fdt);
1504 int fdt_add_mem_rsv(
void *fdt, uint64_t address, uint64_t
size);
1528 int fdt_del_mem_rsv(
void *fdt,
int n);
1554 int fdt_set_name(
void *fdt,
int nodeoffset,
const char *name);
1584 int fdt_setprop(
void *fdt,
int nodeoffset,
const char *name,
1585 const void *val,
int len);
1615 int fdt_setprop_placeholder(
void *fdt,
int nodeoffset,
const char *name,
1616 int len,
void **prop_data);
1646 static inline int fdt_setprop_u32(
void *fdt,
int nodeoffset,
const char *name,
1649 fdt32_t tmp = cpu_to_fdt32(val);
1650 return fdt_setprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1681 static inline int fdt_setprop_u64(
void *fdt,
int nodeoffset,
const char *name,
1684 fdt64_t tmp = cpu_to_fdt64(val);
1685 return fdt_setprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1693 static inline int fdt_setprop_cell(
void *fdt,
int nodeoffset,
const char *name,
1696 return fdt_setprop_u32(fdt, nodeoffset, name, val);
1727 #define fdt_setprop_string(fdt, nodeoffset, name, str) \ 1728 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 1757 #define fdt_setprop_empty(fdt, nodeoffset, name) \ 1758 fdt_setprop((fdt), (nodeoffset), (name), NULL, 0) 1787 int fdt_appendprop(
void *fdt,
int nodeoffset,
const char *name,
1788 const void *val,
int len);
1818 static inline int fdt_appendprop_u32(
void *fdt,
int nodeoffset,
1819 const char *name, uint32_t val)
1821 fdt32_t tmp = cpu_to_fdt32(val);
1822 return fdt_appendprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1853 static inline int fdt_appendprop_u64(
void *fdt,
int nodeoffset,
1854 const char *name, uint64_t val)
1856 fdt64_t tmp = cpu_to_fdt64(val);
1857 return fdt_appendprop(fdt, nodeoffset, name, &tmp,
sizeof(tmp));
1865 static inline int fdt_appendprop_cell(
void *fdt,
int nodeoffset,
1866 const char *name, uint32_t val)
1868 return fdt_appendprop_u32(fdt, nodeoffset, name, val);
1898 #define fdt_appendprop_string(fdt, nodeoffset, name, str) \ 1899 fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 1935 int fdt_appendprop_addrrange(
void *fdt,
int parent,
int nodeoffset,
1936 const char *name, uint64_t addr, uint64_t
size);
1960 int fdt_delprop(
void *fdt,
int nodeoffset,
const char *name);
1975 int fdt_add_subnode_namelen(
void *fdt,
int parentoffset,
1976 const char *name,
int namelen);
2010 int fdt_add_subnode(
void *fdt,
int parentoffset,
const char *name);
2033 int fdt_del_node(
void *fdt,
int nodeoffset);
2064 int fdt_overlay_apply(
void *fdt,
void *fdto);
2070 const char *fdt_strerror(
int errval);
unsigned p
Definition: tte.h:90
unsigned size
Definition: tte.h:74