Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 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 | |
| 17 | #ifndef FLATDEVTREE_H |
| 18 | #define FLATDEVTREE_H |
| 19 | |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 20 | #include "flatdevtree_env.h" |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 21 | |
| 22 | /* Definitions used by the flattened device tree */ |
| 23 | #define OF_DT_HEADER 0xd00dfeed /* marker */ |
| 24 | #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ |
| 25 | #define OF_DT_END_NODE 0x2 /* End node */ |
| 26 | #define OF_DT_PROP 0x3 /* Property: name off, size, content */ |
| 27 | #define OF_DT_NOP 0x4 /* nop */ |
| 28 | #define OF_DT_END 0x9 |
| 29 | |
| 30 | #define OF_DT_VERSION 0x10 |
| 31 | |
| 32 | struct boot_param_header { |
| 33 | u32 magic; /* magic word OF_DT_HEADER */ |
| 34 | u32 totalsize; /* total size of DT block */ |
| 35 | u32 off_dt_struct; /* offset to structure */ |
| 36 | u32 off_dt_strings; /* offset to strings */ |
| 37 | u32 off_mem_rsvmap; /* offset to memory reserve map */ |
| 38 | u32 version; /* format version */ |
| 39 | u32 last_comp_version; /* last compatible version */ |
| 40 | /* version 2 fields below */ |
| 41 | u32 boot_cpuid_phys; /* Physical CPU id we're booting on */ |
| 42 | /* version 3 fields below */ |
| 43 | u32 dt_strings_size; /* size of the DT strings block */ |
| 44 | }; |
| 45 | |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 46 | struct ft_reserve { |
| 47 | u64 start; |
| 48 | u64 len; |
| 49 | }; |
| 50 | |
| 51 | struct ft_region { |
| 52 | char *start; |
| 53 | unsigned long size; |
| 54 | }; |
| 55 | |
| 56 | enum ft_rgn_id { |
| 57 | FT_RSVMAP, |
| 58 | FT_STRUCT, |
| 59 | FT_STRINGS, |
| 60 | FT_N_REGION |
| 61 | }; |
| 62 | |
| 63 | #define FT_MAX_DEPTH 50 |
| 64 | |
| 65 | struct ft_cxt { |
| 66 | struct boot_param_header *bph; |
| 67 | int max_size; /* maximum size of tree */ |
| 68 | int isordered; /* everything in standard order */ |
| 69 | void *(*realloc)(void *, unsigned long); |
| 70 | char *str_anchor; |
| 71 | char *p; /* current insertion point in structs */ |
| 72 | struct ft_region rgn[FT_N_REGION]; |
| 73 | void *genealogy[FT_MAX_DEPTH+1]; |
| 74 | char **node_tbl; |
| 75 | unsigned int node_max; |
| 76 | unsigned int nodes_used; |
| 77 | }; |
| 78 | |
| 79 | int ft_begin_node(struct ft_cxt *cxt, const char *name); |
| 80 | void ft_end_node(struct ft_cxt *cxt); |
| 81 | |
| 82 | void ft_begin_tree(struct ft_cxt *cxt); |
| 83 | void ft_end_tree(struct ft_cxt *cxt); |
| 84 | |
| 85 | void ft_nop(struct ft_cxt *cxt); |
| 86 | int ft_prop(struct ft_cxt *cxt, const char *name, |
| 87 | const void *data, unsigned int sz); |
| 88 | int ft_prop_str(struct ft_cxt *cxt, const char *name, const char *str); |
| 89 | int ft_prop_int(struct ft_cxt *cxt, const char *name, unsigned int val); |
| 90 | void ft_begin(struct ft_cxt *cxt, void *blob, unsigned int max_size, |
| 91 | void *(*realloc_fn)(void *, unsigned long)); |
| 92 | int ft_open(struct ft_cxt *cxt, void *blob, unsigned int max_size, |
| 93 | unsigned int max_find_device, |
| 94 | void *(*realloc_fn)(void *, unsigned long)); |
| 95 | int ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size); |
| 96 | |
| 97 | void ft_dump_blob(const void *bphp); |
| 98 | void ft_merge_blob(struct ft_cxt *cxt, void *blob); |
| 99 | void *ft_find_device(struct ft_cxt *cxt, const char *srch_path); |
Scott Wood | fc58341 | 2007-03-12 14:41:53 -0600 | [diff] [blame^] | 100 | void *ft_find_device_rel(struct ft_cxt *cxt, const void *top, |
| 101 | const char *srch_path); |
Mark A. Greer | 6fb4efc | 2006-10-16 13:50:05 -0700 | [diff] [blame] | 102 | void *ft_find_descendent(struct ft_cxt *cxt, void *top, const char *srch_path); |
| 103 | int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname, |
| 104 | void *buf, const unsigned int buflen); |
| 105 | int ft_set_prop(struct ft_cxt *cxt, const void *phandle, const char *propname, |
| 106 | const void *buf, const unsigned int buflen); |
| 107 | |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 108 | #endif /* FLATDEVTREE_H */ |