1 | /* |
---|
2 | * COPYRIGHT (c) 2013-2017 Chris Johns <chrisj@rtems.org> |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | * |
---|
8 | * Interface based on the libdft: |
---|
9 | * libfdt - Flat Device Tree manipulation |
---|
10 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
---|
11 | */ |
---|
12 | /** |
---|
13 | * @file |
---|
14 | * |
---|
15 | * @ingroup rtems_fdt |
---|
16 | * |
---|
17 | * @brief RTEMS Flattened Device Tree |
---|
18 | * |
---|
19 | * Support for loading, managing and accessing FDT blobs in RTEMS. |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined (_RTEMS_FDT_H_) |
---|
23 | #define _RTEMS_FDT_H_ |
---|
24 | |
---|
25 | #include <rtems.h> |
---|
26 | #include <rtems/chain.h> |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif /* __cplusplus */ |
---|
31 | |
---|
32 | /** |
---|
33 | * A blob. |
---|
34 | */ |
---|
35 | struct rtems_fdt_blob; |
---|
36 | typedef struct rtems_fdt_blob rtems_fdt_blob; |
---|
37 | |
---|
38 | /** |
---|
39 | * A blob handle is a way to manage access to the FDT blobs. The blob is |
---|
40 | * referenced via the handle to allow searches across loaded DTB's to return |
---|
41 | * the referenced DTB. |
---|
42 | */ |
---|
43 | typedef struct |
---|
44 | { |
---|
45 | rtems_fdt_blob* blob; /**< The blob the handle references. */ |
---|
46 | } rtems_fdt_handle; |
---|
47 | |
---|
48 | /* |
---|
49 | * The following are mappings to the standard FDT calls. |
---|
50 | */ |
---|
51 | |
---|
52 | /** |
---|
53 | * RTEMS_FDT_ERR_NOTFOUND: The requested node or property does not exist |
---|
54 | */ |
---|
55 | #define RTEMS_FDT_ERR_NOTFOUND 1 |
---|
56 | /** |
---|
57 | * RTEMS_FDT_ERR_EXISTS: Attemped to create a node or property which already |
---|
58 | * exists */ |
---|
59 | #define RTEMS_FDT_ERR_EXISTS 2 |
---|
60 | /** |
---|
61 | * RTEMS_FDT_ERR_NOSPACE: Operation needed to expand the device tree, but its |
---|
62 | * buffer did not have sufficient space to contain the expanded tree. Use |
---|
63 | * rtems_fdt_open_into() to move the device tree to a buffer with more space. |
---|
64 | */ |
---|
65 | #define RTEMS_FDT_ERR_NOSPACE 3 |
---|
66 | |
---|
67 | /* Error codes: codes for bad parameters */ |
---|
68 | /** |
---|
69 | * RTEMS_FDT_ERR_BADOFFSET: Function was passed a structure block offset which |
---|
70 | * is out-of-bounds, or which points to an unsuitable part of the structure for |
---|
71 | * the operation. |
---|
72 | */ |
---|
73 | #define RTEMS_FDT_ERR_BADOFFSET 4 |
---|
74 | /** |
---|
75 | * RTEMS_FDT_ERR_BADPATH: Function was passed a badly formatted path |
---|
76 | * (e.g. missing a leading / for a function which requires an absolute path) |
---|
77 | */ |
---|
78 | #define RTEMS_FDT_ERR_BADPATH 5 |
---|
79 | /** |
---|
80 | * RTEMS_FDT_ERR_BADPHANDLE: Function was passed an invalid phandle value. |
---|
81 | * phandle values of 0 and -1 are not permitted. |
---|
82 | */ |
---|
83 | #define RTEMS_FDT_ERR_BADPHANDLE 6 |
---|
84 | /** |
---|
85 | * RTEMS_FDT_ERR_BADSTATE: Function was passed an incomplete device tree |
---|
86 | * created by the sequential-write functions, which is not sufficiently |
---|
87 | * complete for the requested operation. |
---|
88 | */ |
---|
89 | #define RTEMS_FDT_ERR_BADSTATE 7 |
---|
90 | |
---|
91 | /* Error codes: codes for bad device tree blobs */ |
---|
92 | |
---|
93 | /** |
---|
94 | * RTEMS_FDT_ERR_TRUNCATED: Structure block of the given device tree ends |
---|
95 | * without an RTEMS_FDT_END tag. |
---|
96 | */ |
---|
97 | #define RTEMS_FDT_ERR_TRUNCATED 8 |
---|
98 | /** |
---|
99 | * RTEMS_FDT_ERR_BADMAGIC: Given "device tree" appears not to be a device tree |
---|
100 | * at all - it is missing the flattened device tree magic number. |
---|
101 | */ |
---|
102 | #define RTEMS_FDT_ERR_BADMAGIC 9 |
---|
103 | /** RTEMS_FDT_ERR_BADVERSION: Given device tree has a version which can't be |
---|
104 | * handled by the requested operation. For read-write functions, this may mean |
---|
105 | * that rtems_fdt_open_into() is required to convert the tree to the expected |
---|
106 | * version. |
---|
107 | */ |
---|
108 | #define RTEMS_FDT_ERR_BADVERSION 10 |
---|
109 | /** |
---|
110 | * RTEMS_FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt structure block |
---|
111 | * or other serious error (e.g. misnested nodes, or subnodes preceding |
---|
112 | * properties). |
---|
113 | */ |
---|
114 | #define RTEMS_FDT_ERR_BADSTRUCTURE 11 |
---|
115 | /** |
---|
116 | * RTEMS_FDT_ERR_BADLAYOUT: For read-write functions, the given device tree has |
---|
117 | * it's sub-blocks in an order that the function can't handle (memory reserve |
---|
118 | * map, then structure, then strings). Use rtems_fdt_open_into() to reorganize |
---|
119 | * the tree into a form suitable for the read-write operations. |
---|
120 | */ |
---|
121 | #define RTEMS_FDT_ERR_BADLAYOUT 12 |
---|
122 | /** |
---|
123 | * "Can't happen" error indicating a bug in libfdt |
---|
124 | */ |
---|
125 | #define RTEMS_FDT_ERR_INTERNAL 13 |
---|
126 | |
---|
127 | /* RTEMS error codes. */ |
---|
128 | |
---|
129 | /** |
---|
130 | * Invalid handle. |
---|
131 | */ |
---|
132 | #define RTEMS_FDT_ERR_INVALID_HANDLE 100 |
---|
133 | /** |
---|
134 | * No memory. |
---|
135 | */ |
---|
136 | #define RTEMS_FDT_ERR_NO_MEMORY 101 |
---|
137 | /** |
---|
138 | * File not found. |
---|
139 | */ |
---|
140 | #define RTEMS_FDT_ERR_NOT_FOUND 102 |
---|
141 | /** |
---|
142 | * Cannot read the DTB into memory. |
---|
143 | */ |
---|
144 | #define RTEMS_FDT_ERR_READ_FAIL 103 |
---|
145 | /** |
---|
146 | * The blob cannot be unloaded as it is referenced. |
---|
147 | */ |
---|
148 | #define RTEMS_FDT_ERR_REFERENCED 104 |
---|
149 | |
---|
150 | #define RTEMS_FDT_ERR_RTEMS_MIN 100 |
---|
151 | #define RTEMS_FDT_ERR_MAX 104 |
---|
152 | |
---|
153 | /** |
---|
154 | * Initialise a handle to a default state. |
---|
155 | * |
---|
156 | * @param handle The handle to initialise. |
---|
157 | */ |
---|
158 | void rtems_fdt_init_handle (rtems_fdt_handle* handle); |
---|
159 | |
---|
160 | /** |
---|
161 | * Duplicate a handle. The copy must be released. |
---|
162 | * |
---|
163 | * @param from Duplicate from this handle. |
---|
164 | * @param to Duplicate to this handle. |
---|
165 | */ |
---|
166 | void rtems_fdt_dup_handle (rtems_fdt_handle* from, rtems_fdt_handle* to); |
---|
167 | |
---|
168 | /** |
---|
169 | * Release a blob from a handle and clear it. |
---|
170 | * |
---|
171 | * @param handle The handle to check. |
---|
172 | */ |
---|
173 | void rtems_fdt_release_handle (rtems_fdt_handle* handle); |
---|
174 | |
---|
175 | /** |
---|
176 | * Check if a handle had a valid blob assigned. |
---|
177 | * |
---|
178 | * @param handle The handle to check. |
---|
179 | * @retval true The handle has a valid blob. |
---|
180 | * @retval false The handle does not have a valid blob. |
---|
181 | */ |
---|
182 | bool rtems_fdt_valid_handle (const rtems_fdt_handle* handle); |
---|
183 | |
---|
184 | /** |
---|
185 | * Find a tree node by its full path looking across of loaded blobs.. Each path |
---|
186 | * component may omit the unit address portion, but the results of this are |
---|
187 | * undefined if any such path component is ambiguous (that is if there are |
---|
188 | * multiple nodes at the relevant level matching the given component, |
---|
189 | * differentiated only by unit address). |
---|
190 | * |
---|
191 | * If the handle points to a valid blob it is release and the search starts |
---|
192 | * from the first blob. |
---|
193 | * |
---|
194 | * @param handle The FDT handle assigned to the blob if found else left invalid. |
---|
195 | * @param path Full path of the node to locate. |
---|
196 | * @param int If less than 0 an error code else the node offset is returned. |
---|
197 | */ |
---|
198 | int rtems_fdt_find_path_offset (rtems_fdt_handle* handle, const char* path); |
---|
199 | |
---|
200 | /** |
---|
201 | * Load a device tree blob or DTB file into memory and register it on the chain |
---|
202 | * of blobs. |
---|
203 | * |
---|
204 | * @param filename The name of the blob file to load. |
---|
205 | * @param handle The handle returns the reference to the blob once load. |
---|
206 | * @return int If less than 0 it is an error code else it is the blob descriptor. |
---|
207 | */ |
---|
208 | int rtems_fdt_load (const char* const filename, rtems_fdt_handle* handle); |
---|
209 | |
---|
210 | /** |
---|
211 | * Register a device tree blob or DTB on to the chain of blobs. |
---|
212 | * |
---|
213 | * @param blob_desc A pointer to the blob. |
---|
214 | * @param handle The handle returns the reference to the blob once load. |
---|
215 | * @return int If less than 0 it is an error code else it is the blob descriptor. |
---|
216 | */ |
---|
217 | int rtems_fdt_register (const void* blob, rtems_fdt_handle* handle); |
---|
218 | |
---|
219 | /** |
---|
220 | * Unload a device tree blob or DTB file and release any memory allocated when |
---|
221 | * loading. The blob is removed from the list of registered. |
---|
222 | * |
---|
223 | * @param blob_desc A valid blob descriptor. |
---|
224 | * @return int If less than 0 it is an error code else 0 is return on success. |
---|
225 | */ |
---|
226 | int rtems_fdt_unload (rtems_fdt_handle* handle); |
---|
227 | |
---|
228 | /** |
---|
229 | * Returns the number of entries in the device tree blob's memory |
---|
230 | * reservation map. This does not include the terminating 0,0 entry |
---|
231 | * or any other (0,0) entries reserved for expansion. |
---|
232 | * |
---|
233 | * @param blob_desc A valid blob descriptor. |
---|
234 | * @return int The number of entries. |
---|
235 | */ |
---|
236 | int rtems_fdt_num_mem_rsv (rtems_fdt_handle* handle); |
---|
237 | |
---|
238 | /** |
---|
239 | * Retrieve one memory reserve map entry. On success, *address and *size will |
---|
240 | * contain the address and size of the n-th reserve map entry from the device |
---|
241 | * tree blob, in native-endian format. |
---|
242 | * |
---|
243 | * @param blob_desc A valid blob descriptor. |
---|
244 | * @param address Pointer to 64-bit variables to hold the addresses. |
---|
245 | * @param size Pointer to 64-bit variables to hold the size. |
---|
246 | * @return int If less than 0 it is an error code else 0 is returned on |
---|
247 | * success. |
---|
248 | */ |
---|
249 | int rtems_fdt_get_mem_rsv (rtems_fdt_handle* handle, |
---|
250 | int n, |
---|
251 | uint64_t* address, |
---|
252 | uint64_t* size); |
---|
253 | |
---|
254 | /** |
---|
255 | * Find a subnode based on substring. Identical to rtems_fdt_subnode_offset(), |
---|
256 | * but only examine the first namelen characters of name for matching the |
---|
257 | * subnode name. This is useful for finding subnodes based on a portion of a |
---|
258 | * larger string, such as a full path. |
---|
259 | * |
---|
260 | * @param blob_desc A valid blob descriptor. |
---|
261 | * @param arentoffset Structure block offset of a node |
---|
262 | * @param name Name of the subnode to locate. |
---|
263 | * @param namelen Number of characters of name to consider. |
---|
264 | * @return int If less than 0 it is an error code else the node offset is |
---|
265 | * returned. |
---|
266 | */ |
---|
267 | int rtems_fdt_subnode_offset_namelen (rtems_fdt_handle* handle, |
---|
268 | int parentoffset, |
---|
269 | const char* const name, |
---|
270 | int namelen); |
---|
271 | |
---|
272 | /** |
---|
273 | * Find a subnode of a given node at structure block offset parentoffset with |
---|
274 | * the given name. The name may include a unit address, in which case |
---|
275 | * rtems_fdt_subnode_offset() will find the subnode with that unit address, or |
---|
276 | * the unit address may be omitted, in which case rtems_fdt_subnode_offset() |
---|
277 | * will find an arbitrary subnode whose name excluding unit address matches the |
---|
278 | * given name. |
---|
279 | * |
---|
280 | * @param blob_desc A valid blob descriptor. |
---|
281 | * @param parentoffset Structure block offset of a node. |
---|
282 | * @param name The name of the subnode to locate. |
---|
283 | * @return int If less than 0 it is an error code else the subnode offset is |
---|
284 | * returned. |
---|
285 | */ |
---|
286 | int rtems_fdt_subnode_offset (rtems_fdt_handle* handle, |
---|
287 | int parentoffset, |
---|
288 | const char* const name); |
---|
289 | |
---|
290 | /** |
---|
291 | * Find a tree node by its full path. Each path component may omit the unit |
---|
292 | * address portion, but the results of this are undefined if any such path |
---|
293 | * component is ambiguous (that is if there are multiple nodes at the relevant |
---|
294 | * level matching the given component, differentiated only by unit address). |
---|
295 | * |
---|
296 | * @param handle The FDT handle to the current blob. |
---|
297 | * @param path Full path of the node to locate. |
---|
298 | * @param int If less than 0 an error code else the node offset is returned. |
---|
299 | */ |
---|
300 | int rtems_fdt_path_offset (rtems_fdt_handle* handle, const char* path); |
---|
301 | |
---|
302 | /** |
---|
303 | * Retrieve the name of a given node (including unit address) of the device |
---|
304 | * tree node at structure block offset @nodeoffset. If @length is non-NULL, |
---|
305 | * the length of this name is also returned, in the integer pointed to by |
---|
306 | * @length. |
---|
307 | * |
---|
308 | * @param handle The FDT handle to the current blob. |
---|
309 | * @param nodeoffset Structure block offset of the starting node. |
---|
310 | * @param length Pointer to an integer variable (will be overwritten) or NULL. |
---|
311 | * @return const char* The node's name on success or NULL on error. The length |
---|
312 | * if non-NULL will hold the error code. |
---|
313 | */ |
---|
314 | const char* rtems_fdt_get_name (rtems_fdt_handle* handle, |
---|
315 | int nodeoffset, |
---|
316 | int* length); |
---|
317 | |
---|
318 | /** |
---|
319 | * Get property value based on substring. Identical to rtems_fdt_getprop(), but |
---|
320 | * only examine the first namelen characters of name for matching the property |
---|
321 | * name. |
---|
322 | * |
---|
323 | * @param handle The FDT handle to the current blob. |
---|
324 | * @param nodeoffset Offset of the node whose property to find |
---|
325 | * @param name The name of the property to find |
---|
326 | * @param namelen The number of characters of name to consider |
---|
327 | * @param length A pointer to an integer variable (will be overwritten) or |
---|
328 | * NULL. |
---|
329 | * @return const void* The node's property on success or NULL on error. The |
---|
330 | * length if non-NULL will hold the error code. |
---|
331 | */ |
---|
332 | const void *rtems_fdt_getprop_namelen (rtems_fdt_handle* handle, |
---|
333 | int nodeoffset, |
---|
334 | const char* const name, |
---|
335 | int namelen, |
---|
336 | int* length); |
---|
337 | |
---|
338 | /** |
---|
339 | * Retrieve the value of a given property. Retrieves a pointer to the value of |
---|
340 | * the property named 'name' of the node at offset nodeoffset (this will be a |
---|
341 | * pointer to within the device blob itself, not a copy of the value). If lenp |
---|
342 | * is non-NULL, the length of the property value is also returned, in the |
---|
343 | * integer pointed to by @length. |
---|
344 | * |
---|
345 | * @param handle The FDT handle to the current blob. |
---|
346 | * @param nodeoffset The offset of the node whose property to find. |
---|
347 | * @param name The name of the property to find. |
---|
348 | * @param length A pointer to an integer variable (will be overwritten) or |
---|
349 | * NULL. |
---|
350 | * @return const void* The node's property on success or NULL on error. The |
---|
351 | * length if non-NULL will hold the error code. |
---|
352 | */ |
---|
353 | const void *rtems_fdt_getprop (rtems_fdt_handle* handle, |
---|
354 | int nodeoffset, |
---|
355 | const char* const name, |
---|
356 | int* length); |
---|
357 | |
---|
358 | /** |
---|
359 | * Retrieve the phandle of a given of the device tree node at structure block |
---|
360 | * offset nodeoffset. |
---|
361 | * |
---|
362 | * @param handle The FDT handle to the current blob. |
---|
363 | * @oaram nodeoffset The structure block offset of the node. |
---|
364 | * return uint32_t The phandle of the node at nodeoffset, on success (!= 0, != |
---|
365 | * -1) 0, if the node has no phandle, or another error occurs. |
---|
366 | */ |
---|
367 | uint32_t rtems_fdt_get_phandle (rtems_fdt_handle* handle, int nodeoffset); |
---|
368 | |
---|
369 | /** |
---|
370 | * Get alias based on substring. Identical to rtems_fdt_get_alias(), but only |
---|
371 | * examine the first namelen characters of name for matching the alias name. |
---|
372 | * |
---|
373 | * @param handle The FDT handle to the current blob. |
---|
374 | * @param name The name of the alias th look up. |
---|
375 | * @param namelen The number of characters of name to consider. |
---|
376 | * @return const char* The alias or NULL. |
---|
377 | */ |
---|
378 | const char *rtems_fdt_get_alias_namelen (rtems_fdt_handle* handle, |
---|
379 | const char* const name, |
---|
380 | int namelen); |
---|
381 | |
---|
382 | /** |
---|
383 | * Retreive the path referenced by a given alias. That is, the value of the |
---|
384 | * property named 'name' in the node /aliases. |
---|
385 | * |
---|
386 | * @param handle The FDT handle to the current blob. |
---|
387 | * @param name The name of the alias to look up. |
---|
388 | * @return const char* A pointer to the expansion of the alias named 'name', of |
---|
389 | * it exists NULL, if the given alias or the /aliases node |
---|
390 | * does not exist |
---|
391 | */ |
---|
392 | const char* rtems_fdt_get_alias (rtems_fdt_handle* handle, const char* name); |
---|
393 | |
---|
394 | /** |
---|
395 | * Determine the full path of a node. This function is expensive, as it must |
---|
396 | * scan the device tree structure from the start to nodeoffset. It computes the |
---|
397 | * full path of the node at offset nodeoffset, and records that path in the |
---|
398 | * buffer at buf. |
---|
399 | * |
---|
400 | * @param handle The FDT handle to the current blob. |
---|
401 | * @param nodeoffset The offset of the node whose path to find. |
---|
402 | * @param buf A character buffer to contain the returned path (will be |
---|
403 | * overwritten) |
---|
404 | * @param buflen The size of the character buffer at buf. |
---|
405 | * @return int 0 on success of an error code. |
---|
406 | */ |
---|
407 | int rtems_fdt_get_path (rtems_fdt_handle* handle, |
---|
408 | int nodeoffset, |
---|
409 | char* buf, |
---|
410 | int buflen); |
---|
411 | |
---|
412 | /** |
---|
413 | * Find a specific ancestor of a node at a specific depth from the root (where |
---|
414 | * the root itself has depth 0, its immediate subnodes depth 1 and so forth). |
---|
415 | * So rtems_fdt_supernode_atdepth_offset(blob, nodeoffset, 0, NULL); will |
---|
416 | * always return 0, the offset of the root node. If the node at nodeoffset has |
---|
417 | * depth D, then: |
---|
418 | * rtems_fdt_supernode_atdepth_offset(blob, nodeoffset, D, NULL); |
---|
419 | * will return nodeoffset itself. |
---|
420 | * |
---|
421 | * @param handle The FDT handle to the current blob. |
---|
422 | * @param nodeoffset The offset of the node whose parent to find. |
---|
423 | * @param supernodedepth The depth of the ancestor to find. |
---|
424 | * @oaram nodedepth The pointer to an integer variable (will be overwritten) or |
---|
425 | * NULL |
---|
426 | * @return int If less than 0 an error else the node offset. |
---|
427 | */ |
---|
428 | int rtems_fdt_supernode_atdepth_offset (rtems_fdt_handle* handle, |
---|
429 | int nodeoffset, |
---|
430 | int supernodedepth, |
---|
431 | int* nodedepth); |
---|
432 | |
---|
433 | /** |
---|
434 | * Find the depth of a given node. The root node has depth 0, its immediate |
---|
435 | * subnodes depth 1 and so forth. |
---|
436 | * |
---|
437 | * @note This function is expensive, as it must scan the device tree structure |
---|
438 | * from the start to nodeoffset. |
---|
439 | * |
---|
440 | * @param handle The FDT handle to the current blob. |
---|
441 | * @param nodeoffset The offset of the node whose parent to find. |
---|
442 | * @return int If less than 0 an error else the node offset. |
---|
443 | */ |
---|
444 | int rtems_fdt_node_depth (rtems_fdt_handle* handle, int nodeoffset); |
---|
445 | |
---|
446 | /** |
---|
447 | * Find the parent of a given node. This funciton locates the parent node of a |
---|
448 | * given node (that is, it finds the offset of the node which contains the node |
---|
449 | * at nodeoffset as a subnode). |
---|
450 | * |
---|
451 | * @note This function is expensive, as it must scan the device tree structure |
---|
452 | * from the start to nodeoffset, *twice*. |
---|
453 | * |
---|
454 | * @param handle The FDT handle to the current blob. |
---|
455 | * @param nodeoffset The offset of the node whose parent to find. |
---|
456 | * @return int If less than 0 an error else the node offset. |
---|
457 | */ |
---|
458 | int rtems_fdt_parent_offset (rtems_fdt_handle* handle, int nodeoffset); |
---|
459 | |
---|
460 | /** |
---|
461 | * Find nodes with a given property value. This funtion returns the offset of |
---|
462 | * the first node after startoffset, which has a property named propname whose |
---|
463 | * value is of length proplen and has value equal to propval; or if startoffset |
---|
464 | * is -1, the very first such node in the tree. |
---|
465 | * |
---|
466 | * To iterate through all nodes matching the criterion, the following idiom can |
---|
467 | * be used: |
---|
468 | * offset = rtemsfdt_node_offset_by_prop_value(blob, -1, propname, |
---|
469 | * propval, proplen); |
---|
470 | * while (offset != -RTEMS_FDT_ERR_NOTFOUND) { |
---|
471 | * // other code here |
---|
472 | * offset = rtems_fdt_node_offset_by_prop_value(fdt, offset, propname, |
---|
473 | * propval, proplen); |
---|
474 | * } |
---|
475 | * |
---|
476 | * @note The -1 in the first call to the function, if 0 is used here |
---|
477 | * instead, the function will never locate the root node, even if it |
---|
478 | * matches the criterion. |
---|
479 | * |
---|
480 | * @param handle The FDT handle to the current blob. |
---|
481 | * @param startoffset Only find nodes after this offset. |
---|
482 | * @param propname The property name to check. |
---|
483 | * @param propval The property value to search for. |
---|
484 | * @param proplen The length of the value in propval. |
---|
485 | * @return int The structure block offset of the located node (>= 0, |
---|
486 | * >startoffset), on success and an error code is less |
---|
487 | * than 0. |
---|
488 | */ |
---|
489 | int rtems_fdt_node_offset_by_prop_value (rtems_fdt_handle* handle, |
---|
490 | int startoffset, |
---|
491 | const char* const propname, |
---|
492 | const void* propval, |
---|
493 | int proplen); |
---|
494 | |
---|
495 | /** |
---|
496 | * Find the node with a given phandle returning the offset of the node which |
---|
497 | * has the given phandle value. If there is more than one node in the tree |
---|
498 | * with the given phandle (an invalid tree), results are undefined. |
---|
499 | * |
---|
500 | * @param handle The FDT handle to the current blob. |
---|
501 | * @param phandle The phandle value. |
---|
502 | * @return int If less than 0 an error else the node offset. |
---|
503 | */ |
---|
504 | int rtems_fdt_node_offset_by_phandle (rtems_fdt_handle* handle, |
---|
505 | uint32_t phandle); |
---|
506 | |
---|
507 | /** |
---|
508 | * Check a node's compatible property returning 0 if the given node contains a |
---|
509 | * 'compatible' property with the given string as one of its elements, it |
---|
510 | * returns non-zero otherwise, or on error. |
---|
511 | * |
---|
512 | * @param handle The FDT handle to the current blob. |
---|
513 | * @param nodeoffset The offset of a tree node. |
---|
514 | * @param compatible The string to match against. |
---|
515 | * @retval 0, if the node has a 'compatible' property listing the given string. |
---|
516 | * @retval 1, if the node has a 'compatible' property, but it does not list the |
---|
517 | * given string |
---|
518 | */ |
---|
519 | int rtems_fdt_node_check_compatible (rtems_fdt_handle* handle, |
---|
520 | int nodeoffset, |
---|
521 | const char* const compatible); |
---|
522 | |
---|
523 | /** |
---|
524 | * Find nodes with a given 'compatible' value returning the offset of the first |
---|
525 | * node after startoffset, which has a 'compatible' property which lists the |
---|
526 | * given compatible string; or if startoffset is -1, the very first such node |
---|
527 | * in the tree. |
---|
528 | * |
---|
529 | * To iterate through all nodes matching the criterion, the following idiom can |
---|
530 | * be used: |
---|
531 | * |
---|
532 | * offset = rtems_fdt_node_offset_by_compatible(blob, -1, compatible); |
---|
533 | * while (offset != -RTEMS_FDT_ERR_NOTFOUND) { |
---|
534 | * // other code here |
---|
535 | * offset = rtems_fdt_node_offset_by_compatible(blob, offset, compatible); |
---|
536 | * } |
---|
537 | * |
---|
538 | * @note The -1 in the first call to the function, if 0 is used here instead, |
---|
539 | * the function will never locate the root node, even if it matches the |
---|
540 | * criterion. |
---|
541 | * |
---|
542 | * @param handle The FDT handle to the current blob. |
---|
543 | * @param startoffset Only find nodes after this offset. |
---|
544 | * @param compatible The 'compatible' string to match against. |
---|
545 | * @return int If less than 0 an error else the node offset. |
---|
546 | */ |
---|
547 | int rtems_fdt_node_offset_by_compatible(rtems_fdt_handle* handle, |
---|
548 | int startoffset, |
---|
549 | const char* compatible); |
---|
550 | |
---|
551 | /** |
---|
552 | * Traverse to the next node. |
---|
553 | * |
---|
554 | * @param handle The FDT handle to the current blob. |
---|
555 | * @param offset The offset in the blob to start looking for the next node. |
---|
556 | * @param depth Pointer to return the depth the node is. |
---|
557 | * @return int If less than 0 an error else the node offset. |
---|
558 | */ |
---|
559 | int rtems_fdt_next_node (rtems_fdt_handle* handle, int offset, int* depth); |
---|
560 | |
---|
561 | /** |
---|
562 | * Return an error string given an error value. |
---|
563 | * |
---|
564 | * @param errval The error value. |
---|
565 | * @return const char* The error string. |
---|
566 | */ |
---|
567 | const char* rtems_fdt_strerror (int errval); |
---|
568 | |
---|
569 | /** |
---|
570 | * Return a property given a path. |
---|
571 | */ |
---|
572 | int rtems_fdt_prop_value(const char* const path, |
---|
573 | const char* const propname, |
---|
574 | void* value, |
---|
575 | size_t* size); |
---|
576 | |
---|
577 | /** |
---|
578 | * Create a map given a path the property name and the names of the subnodes of |
---|
579 | * the path. |
---|
580 | */ |
---|
581 | int rtems_fdt_prop_map (const char* const path, |
---|
582 | const char* const propname, |
---|
583 | const char* const names[], |
---|
584 | uint32_t* values, |
---|
585 | size_t count); |
---|
586 | |
---|
587 | /* |
---|
588 | * Get a value given a path and a property. |
---|
589 | */ |
---|
590 | int rtems_fdt_get_value (const char* const path, |
---|
591 | const char* const property, |
---|
592 | size_t size, |
---|
593 | uint32_t* value); |
---|
594 | |
---|
595 | /** |
---|
596 | * Get the number of entries in an FDT handle. |
---|
597 | */ |
---|
598 | int rtems_fdt_num_entries(rtems_fdt_handle* handle); |
---|
599 | |
---|
600 | /** |
---|
601 | * Get the numbered entry name. Note that the id isn't the same as |
---|
602 | * the offset - it's numbered 0, 1, 2 ... num_entries-1 |
---|
603 | */ |
---|
604 | const char *rtems_fdt_entry_name(rtems_fdt_handle* handle, int id); |
---|
605 | |
---|
606 | /** |
---|
607 | * Get the numbered entry offset. Note that the id isn't the same as |
---|
608 | * the offset - it's numbered 0, 1, 2 ... num_entries-1 |
---|
609 | */ |
---|
610 | int rtems_fdt_entry_offset(rtems_fdt_handle* handle, int id); |
---|
611 | |
---|
612 | /* |
---|
613 | * Helper function to convert the void* property result to a 32bit unsigned int. |
---|
614 | */ |
---|
615 | uint32_t rtems_fdt_get_uint32 (const void* prop); |
---|
616 | |
---|
617 | #ifdef __cplusplus |
---|
618 | } |
---|
619 | #endif /* __cplusplus */ |
---|
620 | |
---|
621 | #endif |
---|