flatdevtree.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef FLATDEVTREE_H
  17. #define FLATDEVTREE_H
  18. #include "flatdevtree_env.h"
  19. /* Definitions used by the flattened device tree */
  20. #define OF_DT_HEADER 0xd00dfeed /* marker */
  21. #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */
  22. #define OF_DT_END_NODE 0x2 /* End node */
  23. #define OF_DT_PROP 0x3 /* Property: name off, size, content */
  24. #define OF_DT_NOP 0x4 /* nop */
  25. #define OF_DT_END 0x9
  26. #define OF_DT_VERSION 0x10
  27. struct boot_param_header {
  28. u32 magic; /* magic word OF_DT_HEADER */
  29. u32 totalsize; /* total size of DT block */
  30. u32 off_dt_struct; /* offset to structure */
  31. u32 off_dt_strings; /* offset to strings */
  32. u32 off_mem_rsvmap; /* offset to memory reserve map */
  33. u32 version; /* format version */
  34. u32 last_comp_version; /* last compatible version */
  35. /* version 2 fields below */
  36. u32 boot_cpuid_phys; /* Physical CPU id we're booting on */
  37. /* version 3 fields below */
  38. u32 dt_strings_size; /* size of the DT strings block */
  39. };
  40. struct ft_reserve {
  41. u64 start;
  42. u64 len;
  43. };
  44. struct ft_region {
  45. char *start;
  46. unsigned long size;
  47. };
  48. enum ft_rgn_id {
  49. FT_RSVMAP,
  50. FT_STRUCT,
  51. FT_STRINGS,
  52. FT_N_REGION
  53. };
  54. #define FT_MAX_DEPTH 50
  55. struct ft_cxt {
  56. struct boot_param_header *bph;
  57. int max_size; /* maximum size of tree */
  58. int isordered; /* everything in standard order */
  59. void *(*realloc)(void *, unsigned long);
  60. char *str_anchor;
  61. char *p; /* current insertion point in structs */
  62. struct ft_region rgn[FT_N_REGION];
  63. void *genealogy[FT_MAX_DEPTH+1];
  64. char **node_tbl;
  65. unsigned int node_max;
  66. unsigned int nodes_used;
  67. };
  68. int ft_begin_node(struct ft_cxt *cxt, const char *name);
  69. void ft_end_node(struct ft_cxt *cxt);
  70. void ft_begin_tree(struct ft_cxt *cxt);
  71. void ft_end_tree(struct ft_cxt *cxt);
  72. void ft_nop(struct ft_cxt *cxt);
  73. int ft_prop(struct ft_cxt *cxt, const char *name,
  74. const void *data, unsigned int sz);
  75. int ft_prop_str(struct ft_cxt *cxt, const char *name, const char *str);
  76. int ft_prop_int(struct ft_cxt *cxt, const char *name, unsigned int val);
  77. void ft_begin(struct ft_cxt *cxt, void *blob, unsigned int max_size,
  78. void *(*realloc_fn)(void *, unsigned long));
  79. int ft_open(struct ft_cxt *cxt, void *blob, unsigned int max_size,
  80. unsigned int max_find_device,
  81. void *(*realloc_fn)(void *, unsigned long));
  82. int ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size);
  83. void ft_dump_blob(const void *bphp);
  84. void ft_merge_blob(struct ft_cxt *cxt, void *blob);
  85. void *ft_find_device(struct ft_cxt *cxt, const char *srch_path);
  86. void *ft_find_descendent(struct ft_cxt *cxt, void *top, const char *srch_path);
  87. int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
  88. void *buf, const unsigned int buflen);
  89. int ft_set_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
  90. const void *buf, const unsigned int buflen);
  91. #endif /* FLATDEVTREE_H */