libfdt.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * libfdt - Flat Device Tree manipulation
  3. * Copyright (C) 2006 David Gibson, IBM Corporation.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public License
  7. * as published by the Free Software Foundation; either version 2.1 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef _LIBFDT_H
  20. #define _LIBFDT_H
  21. #include <fdt.h>
  22. #include <libfdt_env.h>
  23. #define FDT_FIRST_SUPPORTED_VERSION 0x10
  24. #define FDT_LAST_SUPPORTED_VERSION 0x11
  25. /* Error codes: informative error codes */
  26. #define FDT_ERR_NOTFOUND 1
  27. #define FDT_ERR_EXISTS 2
  28. #define FDT_ERR_NOSPACE 3
  29. /* Error codes: codes for bad parameters */
  30. #define FDT_ERR_BADOFFSET 4
  31. #define FDT_ERR_BADPATH 5
  32. #define FDT_ERR_BADSTATE 6
  33. /* Error codes: codes for bad device tree blobs */
  34. #define FDT_ERR_TRUNCATED 7
  35. #define FDT_ERR_BADMAGIC 8
  36. #define FDT_ERR_BADVERSION 9
  37. #define FDT_ERR_BADSTRUCTURE 10
  38. #define FDT_ERR_BADLAYOUT 11
  39. #define FDT_ERR_MAX 11
  40. #define fdt_get_header(fdt, field) \
  41. (fdt32_to_cpu(((struct fdt_header *)(fdt))->field))
  42. #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
  43. #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
  44. #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
  45. #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
  46. #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
  47. #define fdt_version(fdt) (fdt_get_header(fdt, version))
  48. #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
  49. #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
  50. #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
  51. #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
  52. #define fdt_set_header(fdt, field, val) \
  53. ((struct fdt_header *)(fdt))->field = cpu_to_fdt32(val)
  54. int fdt_check_header(const void *fdt);
  55. void *fdt_offset_ptr(const void *fdt, int offset, int checklen);
  56. #define fdt_offset_ptr_typed(fdt, offset, var) \
  57. ((typeof(var))(fdt_offset_ptr((fdt), (offset), sizeof(*(var)))))
  58. int fdt_move(const void *fdt, void *buf, int bufsize);
  59. /* Read-only functions */
  60. char *fdt_string(const void *fdt, int stroffset);
  61. int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
  62. const char *name, int namelen);
  63. int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
  64. int fdt_find_node_by_path(const void *fdt, const char *path);
  65. int fdt_find_node_by_type(const void *fdt, int nodeoffset, const char *type);
  66. int fdt_node_is_compatible(const void *fdt, int nodeoffset,
  67. const char *compat);
  68. int fdt_find_compatible_node(const void *fdt, int nodeoffset,
  69. const char *type, const char *compat);
  70. struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
  71. const char *name, int *lenp);
  72. void *fdt_getprop(const void *fdt, int nodeoffset,
  73. const char *name, int *lenp);
  74. uint32_t fdt_next_tag(const void *fdt, int offset,
  75. int *nextoffset, char **namep);
  76. int fdt_num_reservemap(void *fdt, int *used, int *total);
  77. int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re);
  78. /* Write-in-place functions */
  79. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  80. const void *val, int len);
  81. #define fdt_setprop_inplace_typed(fdt, nodeoffset, name, val) \
  82. ({ \
  83. typeof(val) x = val; \
  84. fdt_setprop_inplace(fdt, nodeoffset, name, &x, sizeof(x)); \
  85. })
  86. int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
  87. int fdt_nop_node(void *fdt, int nodeoffset);
  88. int fdt_insert_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size);
  89. /* Sequential-write functions */
  90. int fdt_create(void *buf, int bufsize);
  91. int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
  92. int fdt_finish_reservemap(void *fdt);
  93. int fdt_begin_node(void *fdt, const char *name);
  94. int fdt_property(void *fdt, const char *name, const void *val, int len);
  95. #define fdt_property_typed(fdt, name, val) \
  96. ({ \
  97. typeof(val) x = (val); \
  98. fdt_property((fdt), (name), &x, sizeof(x)); \
  99. })
  100. #define fdt_property_string(fdt, name, str) \
  101. fdt_property(fdt, name, str, strlen(str)+1)
  102. int fdt_end_node(void *fdt);
  103. int fdt_finish(void *fdt);
  104. int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size);
  105. /* Read-write functions */
  106. int fdt_open_into(void *fdt, void *buf, int bufsize);
  107. int fdt_pack(void *fdt);
  108. int fdt_setprop(void *fdt, int nodeoffset, const char *name,
  109. const void *val, int len);
  110. #define fdt_setprop_typed(fdt, nodeoffset, name, val) \
  111. ({ \
  112. typeof(val) x = (val); \
  113. fdt_setprop((fdt), (nodeoffset), (name), &x, sizeof(x)); \
  114. })
  115. #define fdt_setprop_string(fdt, nodeoffset, name, str) \
  116. fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
  117. int fdt_delprop(void *fdt, int nodeoffset, const char *name);
  118. int fdt_add_subnode_namelen(void *fdt, int parentoffset,
  119. const char *name, int namelen);
  120. int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
  121. int fdt_del_node(void *fdt, int nodeoffset);
  122. /* Extra functions */
  123. const char *fdt_strerror(int errval);
  124. #endif /* _LIBFDT_H */