fdt_ro.c (204488) | fdt_ro.c (238742) |
---|---|
1/* 2 * libfdt - Flat Device Tree manipulation 3 * Copyright (C) 2006 David Gibson, IBM Corporation. 4 * 5 * libfdt is dual licensed: you can use it either under the terms of 6 * the GPL, or the BSD license, at your option. 7 * 8 * a) This library is free software; you can redistribute it and/or --- 91 unchanged lines hidden (view full) --- 100{ 101 int i = 0; 102 103 while (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0) 104 i++; 105 return i; 106} 107 | 1/* 2 * libfdt - Flat Device Tree manipulation 3 * Copyright (C) 2006 David Gibson, IBM Corporation. 4 * 5 * libfdt is dual licensed: you can use it either under the terms of 6 * the GPL, or the BSD license, at your option. 7 * 8 * a) This library is free software; you can redistribute it and/or --- 91 unchanged lines hidden (view full) --- 100{ 101 int i = 0; 102 103 while (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0) 104 i++; 105 return i; 106} 107 |
108static int _nextprop(const void *fdt, int offset) 109{ 110 uint32_t tag; 111 int nextoffset; 112 113 do { 114 tag = fdt_next_tag(fdt, offset, &nextoffset); 115 116 switch (tag) { 117 case FDT_END: 118 if (nextoffset >= 0) 119 return -FDT_ERR_BADSTRUCTURE; 120 else 121 return nextoffset; 122 123 case FDT_PROP: 124 return offset; 125 } 126 offset = nextoffset; 127 } while (tag == FDT_NOP); 128 129 return -FDT_ERR_NOTFOUND; 130} 131 |
|
108int fdt_subnode_offset_namelen(const void *fdt, int offset, 109 const char *name, int namelen) 110{ 111 int depth; 112 113 FDT_CHECK_HEADER(fdt); 114 115 for (depth = 0; --- 73 unchanged lines hidden (view full) --- 189 return nh->name; 190 191 fail: 192 if (len) 193 *len = err; 194 return NULL; 195} 196 | 132int fdt_subnode_offset_namelen(const void *fdt, int offset, 133 const char *name, int namelen) 134{ 135 int depth; 136 137 FDT_CHECK_HEADER(fdt); 138 139 for (depth = 0; --- 73 unchanged lines hidden (view full) --- 213 return nh->name; 214 215 fail: 216 if (len) 217 *len = err; 218 return NULL; 219} 220 |
197const struct fdt_property *fdt_get_property_namelen(const void *fdt, 198 int nodeoffset, 199 const char *name, 200 int namelen, int *lenp) | 221int fdt_first_property_offset(const void *fdt, int nodeoffset) |
201{ | 222{ |
202 uint32_t tag; 203 const struct fdt_property *prop; 204 int offset, nextoffset; | 223 int offset; 224 225 if ((offset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) 226 return offset; 227 228 return _nextprop(fdt, offset); 229} 230 231int fdt_next_property_offset(const void *fdt, int offset) 232{ 233 if ((offset = _fdt_check_prop_offset(fdt, offset)) < 0) 234 return offset; 235 236 return _nextprop(fdt, offset); 237} 238 239const struct fdt_property *fdt_get_property_by_offset(const void *fdt, 240 int offset, 241 int *lenp) 242{ |
205 int err; | 243 int err; |
244 const struct fdt_property *prop; |
|
206 | 245 |
207 if (((err = fdt_check_header(fdt)) != 0) 208 || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0)) 209 goto fail; | 246 if ((err = _fdt_check_prop_offset(fdt, offset)) < 0) { 247 if (lenp) 248 *lenp = err; 249 return NULL; 250 } |
210 | 251 |
211 nextoffset = err; 212 do { 213 offset = nextoffset; | 252 prop = _fdt_offset_ptr(fdt, offset); |
214 | 253 |
215 tag = fdt_next_tag(fdt, offset, &nextoffset); 216 switch (tag) { 217 case FDT_END: 218 if (nextoffset < 0) 219 err = nextoffset; 220 else 221 /* FDT_END tag with unclosed nodes */ 222 err = -FDT_ERR_BADSTRUCTURE; 223 goto fail; | 254 if (lenp) 255 *lenp = fdt32_to_cpu(prop->len); |
224 | 256 |
225 case FDT_PROP: 226 prop = _fdt_offset_ptr(fdt, offset); 227 if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff), 228 name, namelen)) { 229 /* Found it! */ 230 if (lenp) 231 *lenp = fdt32_to_cpu(prop->len); | 257 return prop; 258} |
232 | 259 |
233 return prop; 234 } | 260const struct fdt_property *fdt_get_property_namelen(const void *fdt, 261 int offset, 262 const char *name, 263 int namelen, int *lenp) 264{ 265 for (offset = fdt_first_property_offset(fdt, offset); 266 (offset >= 0); 267 (offset = fdt_next_property_offset(fdt, offset))) { 268 const struct fdt_property *prop; 269 270 if (!(prop = fdt_get_property_by_offset(fdt, offset, lenp))) { 271 offset = -FDT_ERR_INTERNAL; |
235 break; 236 } | 272 break; 273 } |
237 } while ((tag != FDT_BEGIN_NODE) && (tag != FDT_END_NODE)); | 274 if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff), 275 name, namelen)) 276 return prop; 277 } |
238 | 278 |
239 err = -FDT_ERR_NOTFOUND; 240 fail: | |
241 if (lenp) | 279 if (lenp) |
242 *lenp = err; | 280 *lenp = offset; |
243 return NULL; 244} 245 246const struct fdt_property *fdt_get_property(const void *fdt, 247 int nodeoffset, 248 const char *name, int *lenp) 249{ 250 return fdt_get_property_namelen(fdt, nodeoffset, name, --- 7 unchanged lines hidden (view full) --- 258 259 prop = fdt_get_property_namelen(fdt, nodeoffset, name, namelen, lenp); 260 if (! prop) 261 return NULL; 262 263 return prop->data; 264} 265 | 281 return NULL; 282} 283 284const struct fdt_property *fdt_get_property(const void *fdt, 285 int nodeoffset, 286 const char *name, int *lenp) 287{ 288 return fdt_get_property_namelen(fdt, nodeoffset, name, --- 7 unchanged lines hidden (view full) --- 296 297 prop = fdt_get_property_namelen(fdt, nodeoffset, name, namelen, lenp); 298 if (! prop) 299 return NULL; 300 301 return prop->data; 302} 303 |
304const void *fdt_getprop_by_offset(const void *fdt, int offset, 305 const char **namep, int *lenp) 306{ 307 const struct fdt_property *prop; 308 309 prop = fdt_get_property_by_offset(fdt, offset, lenp); 310 if (!prop) 311 return NULL; 312 if (namep) 313 *namep = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); 314 return prop->data; 315} 316 |
|
266const void *fdt_getprop(const void *fdt, int nodeoffset, 267 const char *name, int *lenp) 268{ 269 return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp); 270} 271 272uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) 273{ --- 250 unchanged lines hidden --- | 317const void *fdt_getprop(const void *fdt, int nodeoffset, 318 const char *name, int *lenp) 319{ 320 return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp); 321} 322 323uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) 324{ --- 250 unchanged lines hidden --- |