xref: /OK3568_Linux_fs/u-boot/include/dm/ofnode.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2017 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef _DM_OFNODE_H
9 #define _DM_OFNODE_H
10 
11 /* TODO(sjg@chromium.org): Drop fdtdec.h include */
12 #include <fdtdec.h>
13 #include <dm/of.h>
14 
15 /* Enable checks to protect against invalid calls */
16 #undef OF_CHECKS
17 
18 struct resource;
19 
20 /**
21  * ofnode - reference to a device tree node
22  *
23  * This union can hold either a straightforward pointer to a struct device_node
24  * in the live device tree, or an offset within the flat device tree. In the
25  * latter case, the pointer value is just the integer offset within the flat DT.
26  *
27  * Thus we can reference nodes in both the live tree (once available) and the
28  * flat tree (until then). Functions are available to translate between an
29  * ofnode and either an offset or a struct device_node *.
30  *
31  * The reference can also hold a null offset, in which case the pointer value
32  * here is NULL. This corresponds to a struct device_node * value of
33  * NULL, or an offset of -1.
34  *
35  * There is no ambiguity as to whether ofnode holds an offset or a node
36  * pointer: when the live tree is active it holds a node pointer, otherwise it
37  * holds an offset. The value itself does not need to be unique and in theory
38  * the same value could point to a valid device node or a valid offset. We
39  * could arrange for a unique value to be used (e.g. by making the pointer
40  * point to an offset within the flat device tree in the case of an offset) but
41  * this increases code size slightly due to the subtraction. Since it offers no
42  * real benefit, the approach described here seems best.
43  *
44  * For now these points use constant types, since we don't allow writing
45  * the DT.
46  *
47  * @np: Pointer to device node, used for live tree
48  * @of_offset: Pointer into flat device tree, used for flat tree. Note that this
49  *	is not a really a pointer to a node: it is an offset value. See above.
50  */
51 typedef union ofnode_union {
52 	const struct device_node *np;	/* will be used for future live tree */
53 	long of_offset;
54 } ofnode;
55 
56 struct ofnode_phandle_args {
57 	ofnode node;
58 	int args_count;
59 	uint32_t args[OF_MAX_PHANDLE_ARGS];
60 };
61 
62 /**
63  * ofprop - reference to a property of a device tree node
64  *
65  * This struct hold the reference on one property of one node,
66  * using struct ofnode and an offset within the flat device tree or either
67  * a pointer to a struct property in the live device tree.
68  *
69  * Thus we can reference arguments in both the live tree and the flat tree.
70  *
71  * The property reference can also hold a null reference. This corresponds to
72  * a struct property NULL pointer or an offset of -1.
73  *
74  * @node: Pointer to device node
75  * @offset: Pointer into flat device tree, used for flat tree.
76  * @prop: Pointer to property, used for live treee.
77  */
78 
79 struct ofprop {
80 	ofnode node;
81 	union {
82 		int offset;
83 		const struct property *prop;
84 	};
85 };
86 
87 /**
88  * _ofnode_to_np() - convert an ofnode to a live DT node pointer
89  *
90  * This cannot be called if the reference contains an offset.
91  *
92  * @node: Reference containing struct device_node * (possibly invalid)
93  * @return pointer to device node (can be NULL)
94  */
ofnode_to_np(ofnode node)95 static inline const struct device_node *ofnode_to_np(ofnode node)
96 {
97 #ifdef OF_CHECKS
98 	if (!of_live_active())
99 		return NULL;
100 #endif
101 	return node.np;
102 }
103 
104 /**
105  * ofnode_to_offset() - convert an ofnode to a flat DT offset
106  *
107  * This cannot be called if the reference contains a node pointer.
108  *
109  * @node: Reference containing offset (possibly invalid)
110  * @return DT offset (can be -1)
111  */
ofnode_to_offset(ofnode node)112 static inline int ofnode_to_offset(ofnode node)
113 {
114 #ifdef OF_CHECKS
115 	if (of_live_active())
116 		return -1;
117 #endif
118 	return node.of_offset;
119 }
120 
121 /**
122  * ofnode_valid() - check if an ofnode is valid
123  *
124  * @return true if the reference contains a valid ofnode, false if it is NULL
125  */
ofnode_valid(ofnode node)126 static inline bool ofnode_valid(ofnode node)
127 {
128 	if (of_live_active())
129 		return node.np != NULL;
130 	else
131 		return node.of_offset != -1;
132 }
133 
134 /**
135  * offset_to_ofnode() - convert a DT offset to an ofnode
136  *
137  * @of_offset: DT offset (either valid, or -1)
138  * @return reference to the associated DT offset
139  */
offset_to_ofnode(int of_offset)140 static inline ofnode offset_to_ofnode(int of_offset)
141 {
142 	ofnode node;
143 
144 	if (of_live_active())
145 		node.np = NULL;
146 	else
147 		node.of_offset = of_offset;
148 
149 	return node;
150 }
151 
152 /**
153  * np_to_ofnode() - convert a node pointer to an ofnode
154  *
155  * @np: Live node pointer (can be NULL)
156  * @return reference to the associated node pointer
157  */
np_to_ofnode(const struct device_node * np)158 static inline ofnode np_to_ofnode(const struct device_node *np)
159 {
160 	ofnode node;
161 
162 	node.np = np;
163 
164 	return node;
165 }
166 
167 /**
168  * ofnode_is_np() - check if a reference is a node pointer
169  *
170  * This function associated that if there is a valid live tree then all
171  * references will use it. This is because using the flat DT when the live tree
172  * is valid is not permitted.
173  *
174  * @node: reference to check (possibly invalid)
175  * @return true if the reference is a live node pointer, false if it is a DT
176  * offset
177  */
ofnode_is_np(ofnode node)178 static inline bool ofnode_is_np(ofnode node)
179 {
180 #ifdef OF_CHECKS
181 	/*
182 	 * Check our assumption that flat tree offsets are not used when a
183 	 * live tree is in use.
184 	 */
185 	assert(!ofnode_valid(node) ||
186 	       (of_live_active() ? _ofnode_to_np(node)
187 				  : _ofnode_to_np(node)));
188 #endif
189 	return of_live_active() && ofnode_valid(node);
190 }
191 
192 /**
193  * ofnode_equal() - check if two references are equal
194  *
195  * @return true if equal, else false
196  */
ofnode_equal(ofnode ref1,ofnode ref2)197 static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
198 {
199 	/* We only need to compare the contents */
200 	return ref1.of_offset == ref2.of_offset;
201 }
202 
203 /**
204  * ofnode_null() - Obtain a null ofnode
205  *
206  * This returns an ofnode which points to no node. It works both with the flat
207  * tree and livetree.
208  */
ofnode_null(void)209 static inline ofnode ofnode_null(void)
210 {
211 	ofnode node;
212 
213 	if (of_live_active())
214 		node.np = NULL;
215 	else
216 		node.of_offset = -1;
217 
218 	return node;
219 }
220 
221 /**
222  * ofnode_read_u32() - Read a 32-bit integer from a property
223  *
224  * @ref:	valid node reference to read property from
225  * @propname:	name of the property to read from
226  * @outp:	place to put value (if found)
227  * @return 0 if OK, -ve on error
228  */
229 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
230 
231 /**
232  * ofnode_read_s32() - Read a 32-bit integer from a property
233  *
234  * @ref:	valid node reference to read property from
235  * @propname:	name of the property to read from
236  * @outp:	place to put value (if found)
237  * @return 0 if OK, -ve on error
238  */
ofnode_read_s32(ofnode node,const char * propname,s32 * out_value)239 static inline int ofnode_read_s32(ofnode node, const char *propname,
240 				  s32 *out_value)
241 {
242 	return ofnode_read_u32(node, propname, (u32 *)out_value);
243 }
244 
245 /**
246  * ofnode_read_u32_default() - Read a 32-bit integer from a property
247  *
248  * @ref:	valid node reference to read property from
249  * @propname:	name of the property to read from
250  * @def:	default value to return if the property has no value
251  * @return property value, or @def if not found
252  */
253 int ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
254 
255 /**
256  * ofnode_read_u64() - Read a 64-bit integer from a property
257  *
258  * @ref:	valid node reference to read property from
259  * @propname:	name of the property to read from
260  * @outp:	place to put value (if found)
261  * @return 0 if OK, -ve on error
262  */
263 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
264 
265 /**
266  * ofnode_read_s32_default() - Read a 32-bit integer from a property
267  *
268  * @ref:	valid node reference to read property from
269  * @propname:	name of the property to read from
270  * @def:	default value to return if the property has no value
271  * @return property value, or @def if not found
272  */
273 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
274 
275 /**
276  * ofnode_read_string() - Read a string from a property
277  *
278  * @ref:	valid node reference to read property from
279  * @propname:	name of the property to read
280  * @return string from property value, or NULL if there is no such property
281  */
282 const char *ofnode_read_string(ofnode node, const char *propname);
283 
284 /**
285  * ofnode_read_u32_array() - Find and read an array of 32 bit integers
286  *
287  * @node:	valid node reference to read property from
288  * @propname:	name of the property to read
289  * @out_values:	pointer to return value, modified only if return value is 0
290  * @sz:		number of array elements to read
291  *
292  * Search for a property in a device node and read 32-bit value(s) from
293  * it. Returns 0 on success, -EINVAL if the property does not exist,
294  * -ENODATA if property does not have a value, and -EOVERFLOW if the
295  * property data isn't large enough.
296  *
297  * The out_values is modified only if a valid u32 value can be decoded.
298  */
299 int ofnode_read_u32_array(ofnode node, const char *propname,
300 			  u32 *out_values, size_t sz);
301 
302 /**
303  * ofnode_write_u32_array() - Find and write an array of 32 bit integers
304  *
305  * @node:	valid node reference to read property from
306  * @propname:	name of the property to read
307  * @values:	pointer to update value, modified only if return value is 0
308  * @sz:		number of array elements to read
309  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA
310  * if property does not have a value, and -EOVERFLOW is longer than sz.
311  */
312 int ofnode_write_u32_array(ofnode node, const char *propname,
313 			   u32 *values, size_t sz);
314 
315 /**
316  * ofnode_read_bool() - read a boolean value from a property
317  *
318  * @node:	valid node reference to read property from
319  * @propname:	name of property to read
320  * @return true if property is present (meaning true), false if not present
321  */
322 bool ofnode_read_bool(ofnode node, const char *propname);
323 
324 /**
325  * ofnode_find_subnode() - find a named subnode of a parent node
326  *
327  * @node:	valid reference to parent node
328  * @subnode_name: name of subnode to find
329  * @return reference to subnode (which can be invalid if there is no such
330  * subnode)
331  */
332 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
333 
334 /**
335  * ofnode_first_subnode() - find the first subnode of a parent node
336  *
337  * @node:	valid reference to a valid parent node
338  * @return reference to the first subnode (which can be invalid if the parent
339  * node has no subnodes)
340  */
341 ofnode ofnode_first_subnode(ofnode node);
342 
343 /**
344  * ofnode_next_subnode() - find the next sibling of a subnode
345  *
346  * @node:	valid reference to previous node (sibling)
347  * @return reference to the next subnode (which can be invalid if the node
348  * has no more siblings)
349  */
350 ofnode ofnode_next_subnode(ofnode node);
351 
352 /**
353  * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
354  *
355  * @node: valid node to look up
356  * @return ofnode reference of the parent node
357  */
358 ofnode ofnode_get_parent(ofnode node);
359 
360 /**
361  * ofnode_get_name() - get the name of a node
362  *
363  * @node: valid node to look up
364  * @return name or node
365  */
366 const char *ofnode_get_name(ofnode node);
367 
368 /**
369  * ofnode_get_by_phandle() - get ofnode from phandle
370  *
371  * @phandle:	phandle to look up
372  * @return ofnode reference to the phandle
373  */
374 ofnode ofnode_get_by_phandle(uint phandle);
375 
376 /**
377  * ofnode_read_size() - read the size of a property
378  *
379  * @node: node to check
380  * @propname: property to check
381  * @return size of property if present, or -EINVAL if not
382  */
383 int ofnode_read_size(ofnode node, const char *propname);
384 
385 /**
386  * ofnode_get_addr_index() - get an address from a node
387  *
388  * This reads the register address from a node
389  *
390  * @node: node to read from
391  * @index: Index of address to read (0 for first)
392  * @return address, or FDT_ADDR_T_NONE if not present or invalid
393  */
394 phys_addr_t ofnode_get_addr_index(ofnode node, int index);
395 
396 /**
397  * ofnode_get_addr() - get an address from a node
398  *
399  * This reads the register address from a node
400  *
401  * @node: node to read from
402  * @return address, or FDT_ADDR_T_NONE if not present or invalid
403  */
404 phys_addr_t ofnode_get_addr(ofnode node);
405 
406 /**
407  * ofnode_stringlist_search() - find a string in a string list and return index
408  *
409  * Note that it is possible for this function to succeed on property values
410  * that are not NUL-terminated. That's because the function will stop after
411  * finding the first occurrence of @string. This can for example happen with
412  * small-valued cell properties, such as #address-cells, when searching for
413  * the empty string.
414  *
415  * @node: node to check
416  * @propname: name of the property containing the string list
417  * @string: string to look up in the string list
418  *
419  * @return:
420  *   the index of the string in the list of strings
421  *   -ENODATA if the property is not found
422  *   -EINVAL on some other error
423  */
424 int ofnode_stringlist_search(ofnode node, const char *propname,
425 			     const char *string);
426 
427 /**
428  * ofnode_read_string_index() - obtain an indexed string from a string list
429  *
430  * Note that this will successfully extract strings from properties with
431  * non-NUL-terminated values. For example on small-valued cell properties
432  * this function will return the empty string.
433  *
434  * If non-NULL, the length of the string (on success) or a negative error-code
435  * (on failure) will be stored in the integer pointer to by lenp.
436  *
437  * @node: node to check
438  * @propname: name of the property containing the string list
439  * @index: index of the string to return
440  * @lenp: return location for the string length or an error code on failure
441  *
442  * @return:
443  *   length of string, if found or -ve error value if not found
444  */
445 int ofnode_read_string_index(ofnode node, const char *propname, int index,
446 			     const char **outp);
447 
448 /**
449  * ofnode_read_string_count() - find the number of strings in a string list
450  *
451  * @node: node to check
452  * @propname: name of the property containing the string list
453  * @return:
454  *   number of strings in the list, or -ve error value if not found
455  */
456 int ofnode_read_string_count(ofnode node, const char *property);
457 
458 /**
459  * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
460  *
461  * This function is useful to parse lists of phandles and their arguments.
462  * Returns 0 on success and fills out_args, on error returns appropriate
463  * errno value.
464  *
465  * Caller is responsible to call of_node_put() on the returned out_args->np
466  * pointer.
467  *
468  * Example:
469  *
470  * phandle1: node1 {
471  *	#list-cells = <2>;
472  * }
473  *
474  * phandle2: node2 {
475  *	#list-cells = <1>;
476  * }
477  *
478  * node3 {
479  *	list = <&phandle1 1 2 &phandle2 3>;
480  * }
481  *
482  * To get a device_node of the `node2' node you may call this:
483  * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
484  *
485  * @node:	device tree node containing a list
486  * @list_name:	property name that contains a list
487  * @cells_name:	property name that specifies phandles' arguments count
488  * @cells_count: Cell count to use if @cells_name is NULL
489  * @index:	index of a phandle to parse out
490  * @out_args:	optional pointer to output arguments structure (will be filled)
491  * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
492  *	@list_name does not exist, -EINVAL if a phandle was not found,
493  *	@cells_name could not be found, the arguments were truncated or there
494  *	were too many arguments.
495  */
496 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
497 				   const char *cells_name, int cell_count,
498 				   int index,
499 				   struct ofnode_phandle_args *out_args);
500 
501 /**
502  * ofnode_count_phandle_with_args() - Count number of phandle in a list
503  *
504  * This function is useful to count phandles into a list.
505  * Returns number of phandle on success, on error returns appropriate
506  * errno value.
507  *
508  * @node:	device tree node containing a list
509  * @list_name:	property name that contains a list
510  * @cells_name:	property name that specifies phandles' arguments count
511  * @return number of phandle on success, -ENOENT if @list_name does not
512  *      exist, -EINVAL if a phandle was not found, @cells_name could not
513  *      be found.
514  */
515 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
516 				   const char *cells_name);
517 
518 /**
519  * ofnode_path() - find a node by full path
520  *
521  * @path: Full path to node, e.g. "/bus/spi@1"
522  * @return reference to the node found. Use ofnode_valid() to check if it exists
523  */
524 ofnode ofnode_path(const char *path);
525 
526 /**
527  * ofnode_get_chosen_prop() - get the value of a chosen property
528  *
529  * This looks for a property within the /chosen node and returns its value
530  *
531  * @propname: Property name to look for
532  */
533 const char *ofnode_get_chosen_prop(const char *propname);
534 
535 /**
536  * ofnode_get_chosen_node() - get the chosen node
537  *
538  * @return the chosen node if present, else ofnode_null()
539  */
540 ofnode ofnode_get_chosen_node(const char *name);
541 
542 struct display_timing;
543 /**
544  * ofnode_decode_display_timing() - decode display timings
545  *
546  * Decode display timings from the supplied 'display-timings' node.
547  * See doc/device-tree-bindings/video/display-timing.txt for binding
548  * information.
549  *
550  * @node	'display-timing' node containing the timing subnodes
551  * @index	Index number to read (0=first timing subnode)
552  * @config	Place to put timings
553  * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
554  */
555 int ofnode_decode_display_timing(ofnode node, int index,
556 				 struct display_timing *config);
557 
558 /**
559  * ofnode_get_property() - get a pointer to the value of a node property
560  *
561  * @node: node to read
562  * @propname: property to read
563  * @lenp: place to put length on success
564  * @return pointer to property, or NULL if not found
565  */
566 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
567 
568 /**
569  * ofnode_get_first_property()- get the reference of the first property
570  *
571  * Get reference to the first property of the node, it is used to iterate
572  * and read all the property with ofnode_get_property_by_prop().
573  *
574  * @node: node to read
575  * @prop: place to put argument reference
576  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
577  */
578 int ofnode_get_first_property(ofnode node, struct ofprop *prop);
579 
580 /**
581  * ofnode_get_next_property() - get the reference of the next property
582  *
583  * Get reference to the next property of the node, it is used to iterate
584  * and read all the property with ofnode_get_property_by_prop().
585  *
586  * @prop: reference of current argument and place to put reference of next one
587  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
588  */
589 int ofnode_get_next_property(struct ofprop *prop);
590 
591 /**
592  * ofnode_get_property_by_prop() - get a pointer to the value of a property
593  *
594  * Get value for the property identified by the provided reference.
595  *
596  * @prop: reference on property
597  * @propname: If non-NULL, place to property name on success,
598  * @lenp: If non-NULL, place to put length on success
599  * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
600  */
601 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
602 					const char **propname, int *lenp);
603 
604 /**
605  * ofnode_is_available() - check if a node is marked available
606  *
607  * @node: node to check
608  * @return true if node's 'status' property is "okay" (or is missing)
609  */
610 bool ofnode_is_available(ofnode node);
611 
612 /**
613  * ofnode_get_addr_size() - get address and size from a property
614  *
615  * This does no address translation. It simply reads an property that contains
616  * an address and a size value, one after the other.
617  *
618  * @node: node to read from
619  * @propname: property to read
620  * @sizep: place to put size value (on success)
621  * @return address value, or FDT_ADDR_T_NONE on error
622  */
623 phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
624 				 phys_size_t *sizep);
625 
626 /**
627  * ofnode_read_u8_array_ptr() - find an 8-bit array
628  *
629  * Look up a property in a node and return a pointer to its contents as a
630  * byte array of given length. The property must have at least enough data
631  * for the array (count bytes). It may have more, but this will be ignored.
632  * The data is not copied.
633  *
634  * @node	node to examine
635  * @propname	name of property to find
636  * @sz		number of array elements
637  * @return pointer to byte array if found, or NULL if the property is not
638  *		found or there is not enough data
639  */
640 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
641 					size_t sz);
642 
643 /**
644  * ofnode_read_pci_addr() - look up a PCI address
645  *
646  * Look at an address property in a node and return the PCI address which
647  * corresponds to the given type in the form of fdt_pci_addr.
648  * The property must hold one fdt_pci_addr with a lengh.
649  *
650  * @node	node to examine
651  * @type	pci address type (FDT_PCI_SPACE_xxx)
652  * @propname	name of property to find
653  * @addr	returns pci address in the form of fdt_pci_addr
654  * @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
655  *		format of the property was invalid, -ENXIO if the requested
656  *		address type was not found
657  */
658 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
659 			 const char *propname, struct fdt_pci_addr *addr);
660 
661 /**
662  * ofnode_read_addr_cells() - Get the number of address cells for a node
663  *
664  * This walks back up the tree to find the closest #address-cells property
665  * which controls the given node.
666  *
667  * @node: Node to check
668  * @return number of address cells this node uses
669  */
670 int ofnode_read_addr_cells(ofnode node);
671 
672 /**
673  * ofnode_read_size_cells() - Get the number of size cells for a node
674  *
675  * This walks back up the tree to find the closest #size-cells property
676  * which controls the given node.
677  *
678  * @node: Node to check
679  * @return number of size cells this node uses
680  */
681 int ofnode_read_size_cells(ofnode node);
682 
683 /**
684  * ofnode_read_simple_addr_cells() - Get the address cells property in a node
685  *
686  * This function matches fdt_address_cells().
687  *
688  * @np: Node pointer to check
689  * @return value of #address-cells property in this node, or 2 if none
690  */
691 int ofnode_read_simple_addr_cells(ofnode node);
692 
693 /**
694  * ofnode_read_simple_size_cells() - Get the size cells property in a node
695  *
696  * This function matches fdt_size_cells().
697  *
698  * @np: Node pointer to check
699  * @return value of #size-cells property in this node, or 2 if none
700  */
701 int ofnode_read_simple_size_cells(ofnode node);
702 
703 /**
704  * ofnode_pre_reloc() - check if a node should be bound before relocation
705  *
706  * Device tree nodes can be marked as needing-to-be-bound in the loader stages
707  * via special device tree properties.
708  *
709  * Before relocation this function can be used to check if nodes are required
710  * in either SPL or TPL stages.
711  *
712  * After relocation and jumping into the real U-Boot binary it is possible to
713  * determine if a node was bound in one of SPL/TPL stages.
714  *
715  * There are 3 settings currently in use
716  * -
717  * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
718  *   Existing platforms only use it to indicate nodes needed in
719  *   SPL. Should probably be replaced by u-boot,dm-spl for
720  *   new platforms.
721  *
722  * @node: node to check
723  * @eturns true if node is needed in SPL/TL, false otherwise
724  */
725 bool ofnode_pre_reloc(ofnode node);
726 
727 int ofnode_read_resource(ofnode node, uint index, struct resource *res);
728 int ofnode_read_resource_byname(ofnode node, const char *name,
729 				struct resource *res);
730 
731 /**
732  * ofnode_for_each_subnode() - iterate over all subnodes of a parent
733  *
734  * @node:       child node (ofnode, lvalue)
735  * @parent:     parent node (ofnode)
736  *
737  * This is a wrapper around a for loop and is used like so:
738  *
739  *	ofnode node;
740  *
741  *	ofnode_for_each_subnode(node, parent) {
742  *		Use node
743  *		...
744  *	}
745  *
746  * Note that this is implemented as a macro and @node is used as
747  * iterator in the loop. The parent variable can be a constant or even a
748  * literal.
749  */
750 #define ofnode_for_each_subnode(node, parent) \
751 	for (node = ofnode_first_subnode(parent); \
752 	     ofnode_valid(node); \
753 	     node = ofnode_next_subnode(node))
754 
755 /**
756  * ofnode_translate_address() - Tranlate a device-tree address
757  *
758  * Translate an address from the device-tree into a CPU physical address. This
759  * function walks up the tree and applies the various bus mappings along the
760  * way.
761  *
762  * @ofnode: Device tree node giving the context in which to translate the
763  *          address
764  * @in_addr: pointer to the address to translate
765  * @return the translated address; OF_BAD_ADDR on error
766  */
767 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
768 #endif
769