xref: /linux/include/linux/property.h (revision fe221742e388bea3f5856b5d9b2cb0a037020ea4)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * property.h - Unified device property interface.
4  *
5  * Copyright (C) 2014, Intel Corporation
6  * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
7  *          Mika Westerberg <mika.westerberg@linux.intel.com>
8  */
9 
10 #ifndef _LINUX_PROPERTY_H_
11 #define _LINUX_PROPERTY_H_
12 
13 #include <linux/args.h>
14 #include <linux/array_size.h>
15 #include <linux/bits.h>
16 #include <linux/cleanup.h>
17 #include <linux/fwnode.h>
18 #include <linux/stddef.h>
19 #include <linux/types.h>
20 #include <linux/util_macros.h>
21 
22 struct device;
23 
24 enum dev_prop_type {
25 	DEV_PROP_U8,
26 	DEV_PROP_U16,
27 	DEV_PROP_U32,
28 	DEV_PROP_U64,
29 	DEV_PROP_STRING,
30 	DEV_PROP_REF,
31 };
32 
33 const struct fwnode_handle *__dev_fwnode_const(const struct device *dev);
34 struct fwnode_handle *__dev_fwnode(struct device *dev);
35 #define dev_fwnode(dev)							\
36 	_Generic((dev),							\
37 		 const struct device *: __dev_fwnode_const,	\
38 		 struct device *: __dev_fwnode)(dev)
39 
40 bool device_property_present(const struct device *dev, const char *propname);
41 bool device_property_read_bool(const struct device *dev, const char *propname);
42 int device_property_read_u8_array(const struct device *dev, const char *propname,
43 				  u8 *val, size_t nval);
44 int device_property_read_u16_array(const struct device *dev, const char *propname,
45 				   u16 *val, size_t nval);
46 int device_property_read_u32_array(const struct device *dev, const char *propname,
47 				   u32 *val, size_t nval);
48 int device_property_read_u64_array(const struct device *dev, const char *propname,
49 				   u64 *val, size_t nval);
50 int device_property_read_string_array(const struct device *dev, const char *propname,
51 				      const char **val, size_t nval);
52 int device_property_read_string(const struct device *dev, const char *propname,
53 				const char **val);
54 int device_property_match_string(const struct device *dev,
55 				 const char *propname, const char *string);
56 
57 bool fwnode_property_present(const struct fwnode_handle *fwnode,
58 			     const char *propname);
59 bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
60 			     const char *propname);
61 int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
62 				  const char *propname, u8 *val,
63 				  size_t nval);
64 int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode,
65 				   const char *propname, u16 *val,
66 				   size_t nval);
67 int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode,
68 				   const char *propname, u32 *val,
69 				   size_t nval);
70 int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode,
71 				   const char *propname, u64 *val,
72 				   size_t nval);
73 int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
74 				      const char *propname, const char **val,
75 				      size_t nval);
76 int fwnode_property_read_string(const struct fwnode_handle *fwnode,
77 				const char *propname, const char **val);
78 int fwnode_property_match_string(const struct fwnode_handle *fwnode,
79 				 const char *propname, const char *string);
80 
81 bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
82 
83 static inline bool fwnode_device_is_big_endian(const struct fwnode_handle *fwnode)
84 {
85 	if (fwnode_property_present(fwnode, "big-endian"))
86 		return true;
87 	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) &&
88 	    fwnode_property_present(fwnode, "native-endian"))
89 		return true;
90 	return false;
91 }
92 
93 static inline
94 bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat)
95 {
96 	return fwnode_property_match_string(fwnode, "compatible", compat) >= 0;
97 }
98 
99 /**
100  * device_is_big_endian - check if a device has BE registers
101  * @dev: Pointer to the struct device
102  *
103  * Returns: true if the device has a "big-endian" property, or if the kernel
104  * was compiled for BE *and* the device has a "native-endian" property.
105  * Returns false otherwise.
106  *
107  * Callers would nominally use ioread32be/iowrite32be if
108  * device_is_big_endian() == true, or readl/writel otherwise.
109  */
110 static inline bool device_is_big_endian(const struct device *dev)
111 {
112 	return fwnode_device_is_big_endian(dev_fwnode(dev));
113 }
114 
115 /**
116  * device_is_compatible - match 'compatible' property of the device with a given string
117  * @dev: Pointer to the struct device
118  * @compat: The string to match 'compatible' property with
119  *
120  * Returns: true if matches, otherwise false.
121  */
122 static inline bool device_is_compatible(const struct device *dev, const char *compat)
123 {
124 	return fwnode_device_is_compatible(dev_fwnode(dev), compat);
125 }
126 
127 int fwnode_property_match_property_string(const struct fwnode_handle *fwnode,
128 					  const char *propname,
129 					  const char * const *array, size_t n);
130 
131 static inline
132 int device_property_match_property_string(const struct device *dev,
133 					  const char *propname,
134 					  const char * const *array, size_t n)
135 {
136 	return fwnode_property_match_property_string(dev_fwnode(dev), propname, array, n);
137 }
138 
139 int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
140 				       const char *prop, const char *nargs_prop,
141 				       unsigned int nargs, unsigned int index,
142 				       struct fwnode_reference_args *args);
143 
144 struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
145 					    const char *name,
146 					    unsigned int index);
147 
148 const char *fwnode_get_name(const struct fwnode_handle *fwnode);
149 const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
150 bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name);
151 
152 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
153 struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);
154 
155 #define fwnode_for_each_parent_node(fwnode, parent)		\
156 	for (parent = fwnode_get_parent(fwnode); parent;	\
157 	     parent = fwnode_get_next_parent(parent))
158 
159 unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
160 struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
161 					    unsigned int depth);
162 struct fwnode_handle *fwnode_get_next_child_node(
163 	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
164 struct fwnode_handle *fwnode_get_next_available_child_node(
165 	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
166 
167 #define fwnode_for_each_child_node(fwnode, child)			\
168 	for (child = fwnode_get_next_child_node(fwnode, NULL); child;	\
169 	     child = fwnode_get_next_child_node(fwnode, child))
170 
171 #define fwnode_for_each_named_child_node(fwnode, child, name)		\
172 	fwnode_for_each_child_node(fwnode, child)			\
173 		for_each_if(fwnode_name_eq(child, name))
174 
175 #define fwnode_for_each_available_child_node(fwnode, child)		       \
176 	for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\
177 	     child = fwnode_get_next_available_child_node(fwnode, child))
178 
179 #define fwnode_for_each_child_node_scoped(fwnode, child)		\
180 	for (struct fwnode_handle *child __free(fwnode_handle) =	\
181 		fwnode_get_next_child_node(fwnode, NULL);		\
182 	     child; child = fwnode_get_next_child_node(fwnode, child))
183 
184 #define fwnode_for_each_available_child_node_scoped(fwnode, child)	\
185 	for (struct fwnode_handle *child __free(fwnode_handle) =	\
186 		fwnode_get_next_available_child_node(fwnode, NULL);	\
187 	     child; child = fwnode_get_next_available_child_node(fwnode, child))
188 
189 struct fwnode_handle *device_get_next_child_node(const struct device *dev,
190 						 struct fwnode_handle *child);
191 
192 #define device_for_each_child_node(dev, child)				\
193 	for (child = device_get_next_child_node(dev, NULL); child;	\
194 	     child = device_get_next_child_node(dev, child))
195 
196 #define device_for_each_named_child_node(dev, child, name)		\
197 	device_for_each_child_node(dev, child)				\
198 		for_each_if(fwnode_name_eq(child, name))
199 
200 #define device_for_each_child_node_scoped(dev, child)			\
201 	for (struct fwnode_handle *child __free(fwnode_handle) =	\
202 		device_get_next_child_node(dev, NULL);			\
203 	     child; child = device_get_next_child_node(dev, child))
204 
205 #define device_for_each_named_child_node_scoped(dev, child, name)	\
206 	device_for_each_child_node_scoped(dev, child)			\
207 		for_each_if(fwnode_name_eq(child, name))
208 
209 struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
210 						  const char *childname);
211 struct fwnode_handle *device_get_named_child_node(const struct device *dev,
212 						  const char *childname);
213 
214 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
215 
216 /**
217  * fwnode_handle_put - Drop reference to a device node
218  * @fwnode: Pointer to the device node to drop the reference to.
219  *
220  * This has to be used when terminating device_for_each_child_node() iteration
221  * with break or return to prevent stale device node references from being left
222  * behind.
223  */
224 static inline void fwnode_handle_put(struct fwnode_handle *fwnode)
225 {
226 	fwnode_call_void_op(fwnode, put);
227 }
228 
229 DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T))
230 
231 int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
232 int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);
233 
234 unsigned int fwnode_get_child_node_count(const struct fwnode_handle *fwnode);
235 
236 static inline unsigned int device_get_child_node_count(const struct device *dev)
237 {
238 	return fwnode_get_child_node_count(dev_fwnode(dev));
239 }
240 
241 unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode,
242 					       const char *name);
243 static inline unsigned int device_get_named_child_node_count(const struct device *dev,
244 							     const char *name)
245 {
246 	return fwnode_get_named_child_node_count(dev_fwnode(dev), name);
247 }
248 
249 static inline int device_property_read_u8(const struct device *dev,
250 					  const char *propname, u8 *val)
251 {
252 	return device_property_read_u8_array(dev, propname, val, 1);
253 }
254 
255 static inline int device_property_read_u16(const struct device *dev,
256 					   const char *propname, u16 *val)
257 {
258 	return device_property_read_u16_array(dev, propname, val, 1);
259 }
260 
261 static inline int device_property_read_u32(const struct device *dev,
262 					   const char *propname, u32 *val)
263 {
264 	return device_property_read_u32_array(dev, propname, val, 1);
265 }
266 
267 static inline int device_property_read_u64(const struct device *dev,
268 					   const char *propname, u64 *val)
269 {
270 	return device_property_read_u64_array(dev, propname, val, 1);
271 }
272 
273 static inline int device_property_count_u8(const struct device *dev, const char *propname)
274 {
275 	return device_property_read_u8_array(dev, propname, NULL, 0);
276 }
277 
278 static inline int device_property_count_u16(const struct device *dev, const char *propname)
279 {
280 	return device_property_read_u16_array(dev, propname, NULL, 0);
281 }
282 
283 static inline int device_property_count_u32(const struct device *dev, const char *propname)
284 {
285 	return device_property_read_u32_array(dev, propname, NULL, 0);
286 }
287 
288 static inline int device_property_count_u64(const struct device *dev, const char *propname)
289 {
290 	return device_property_read_u64_array(dev, propname, NULL, 0);
291 }
292 
293 static inline int device_property_string_array_count(const struct device *dev,
294 						     const char *propname)
295 {
296 	return device_property_read_string_array(dev, propname, NULL, 0);
297 }
298 
299 static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
300 					  const char *propname, u8 *val)
301 {
302 	return fwnode_property_read_u8_array(fwnode, propname, val, 1);
303 }
304 
305 static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode,
306 					   const char *propname, u16 *val)
307 {
308 	return fwnode_property_read_u16_array(fwnode, propname, val, 1);
309 }
310 
311 static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode,
312 					   const char *propname, u32 *val)
313 {
314 	return fwnode_property_read_u32_array(fwnode, propname, val, 1);
315 }
316 
317 static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode,
318 					   const char *propname, u64 *val)
319 {
320 	return fwnode_property_read_u64_array(fwnode, propname, val, 1);
321 }
322 
323 static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode,
324 					   const char *propname)
325 {
326 	return fwnode_property_read_u8_array(fwnode, propname, NULL, 0);
327 }
328 
329 static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode,
330 					    const char *propname)
331 {
332 	return fwnode_property_read_u16_array(fwnode, propname, NULL, 0);
333 }
334 
335 static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode,
336 					    const char *propname)
337 {
338 	return fwnode_property_read_u32_array(fwnode, propname, NULL, 0);
339 }
340 
341 static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode,
342 					    const char *propname)
343 {
344 	return fwnode_property_read_u64_array(fwnode, propname, NULL, 0);
345 }
346 
347 static inline int
348 fwnode_property_string_array_count(const struct fwnode_handle *fwnode,
349 				   const char *propname)
350 {
351 	return fwnode_property_read_string_array(fwnode, propname, NULL, 0);
352 }
353 
354 struct software_node;
355 
356 /**
357  * struct software_node_ref_args - Reference property with additional arguments
358  * @swnode: Reference to a software node
359  * @fwnode: Alternative reference to a firmware node handle
360  * @nargs: Number of elements in @args array
361  * @args: Integer arguments
362  */
363 struct software_node_ref_args {
364 	const struct software_node *swnode;
365 	struct fwnode_handle *fwnode;
366 	unsigned int nargs;
367 	u64 args[NR_FWNODE_REFERENCE_ARGS];
368 };
369 
370 #define SOFTWARE_NODE_REFERENCE(_ref_, ...)			\
371 (const struct software_node_ref_args) {				\
372 	.swnode = _Generic(_ref_,				\
373 			   const struct software_node *: _ref_,	\
374 			   struct software_node *: _ref_,	\
375 			   default: NULL),			\
376 	.fwnode = _Generic(_ref_,				\
377 			   struct fwnode_handle *: _ref_,	\
378 			   default: NULL),			\
379 	.nargs = COUNT_ARGS(__VA_ARGS__),			\
380 	.args = { __VA_ARGS__ },				\
381 }
382 
383 /**
384  * struct property_entry - "Built-in" device property representation.
385  * @name: Name of the property.
386  * @length: Length of data making up the value.
387  * @is_inline: True when the property value is stored inline.
388  * @type: Type of the data in unions.
389  * @pointer: Pointer to the property when it is not stored inline.
390  * @value: Value of the property when it is stored inline.
391  */
392 struct property_entry {
393 	const char *name;
394 	size_t length;
395 	bool is_inline;
396 	enum dev_prop_type type;
397 	union {
398 		const void *pointer;
399 		union {
400 			u8 u8_data[sizeof(u64) / sizeof(u8)];
401 			u16 u16_data[sizeof(u64) / sizeof(u16)];
402 			u32 u32_data[sizeof(u64) / sizeof(u32)];
403 			u64 u64_data[sizeof(u64) / sizeof(u64)];
404 			const char *str[sizeof(u64) / sizeof(char *)];
405 		} value;
406 	};
407 };
408 
409 /*
410  * Note: the below initializers for the anonymous union are carefully
411  * crafted to avoid gcc-4.4.4's problems with initialization of anon unions
412  * and structs.
413  */
414 #define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)		\
415 (struct property_entry) {								\
416 	.name = _name_,									\
417 	.length = (_len_) * sizeof_field(struct property_entry, value._elem_[0]),	\
418 	.type = DEV_PROP_##_Type_,							\
419 	{ .pointer = _val_ },								\
420 }
421 
422 #define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_)		\
423 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_)
424 #define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_)		\
425 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_)
426 #define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_)		\
427 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_)
428 #define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_)		\
429 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_)
430 #define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_)		\
431 	__PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_)
432 
433 #define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_)		\
434 (struct property_entry) {						\
435 	.name = _name_,							\
436 	.length = (_len_) * sizeof(struct software_node_ref_args),	\
437 	.type = DEV_PROP_REF,						\
438 	{ .pointer = _val_ },						\
439 }
440 
441 #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_)				\
442 	PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
443 #define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_)				\
444 	PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
445 #define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_)				\
446 	PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
447 #define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_)				\
448 	PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
449 #define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_)			\
450 	PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
451 #define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_)				\
452 	PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
453 
454 #define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_)		\
455 (struct property_entry) {						\
456 	.name = _name_,							\
457 	.length = sizeof_field(struct property_entry, value._elem_[0]),	\
458 	.is_inline = true,						\
459 	.type = DEV_PROP_##_Type_,					\
460 	{ .value = { ._elem_[0] = _val_ } },				\
461 }
462 
463 #define PROPERTY_ENTRY_U8(_name_, _val_)				\
464 	__PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_)
465 #define PROPERTY_ENTRY_U16(_name_, _val_)				\
466 	__PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_)
467 #define PROPERTY_ENTRY_U32(_name_, _val_)				\
468 	__PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_)
469 #define PROPERTY_ENTRY_U64(_name_, _val_)				\
470 	__PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_)
471 #define PROPERTY_ENTRY_STRING(_name_, _val_)				\
472 	__PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_)
473 
474 #define __PROPERTY_ENTRY_REF_ARGS(_ref_, ...)				\
475 	_Generic(_ref_,							\
476 		 const struct software_node_ref_args *: _ref_,		\
477 		 struct software_node_ref_args *: _ref_,		\
478 		 default: &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__))
479 
480 #define PROPERTY_ENTRY_REF(_name_, _ref_, ...)				\
481 (struct property_entry) {						\
482 	.name = _name_,							\
483 	.length = sizeof(struct software_node_ref_args),		\
484 	.type = DEV_PROP_REF,						\
485 	{ .pointer = __PROPERTY_ENTRY_REF_ARGS(_ref_, ##__VA_ARGS__) },	\
486 }
487 
488 #define PROPERTY_ENTRY_BOOL(_name_)		\
489 (struct property_entry) {			\
490 	.name = _name_,				\
491 	.is_inline = true,			\
492 }
493 
494 struct property_entry *
495 property_entries_dup(const struct property_entry *properties);
496 void property_entries_free(const struct property_entry *properties);
497 
498 bool device_dma_supported(const struct device *dev);
499 enum dev_dma_attr device_get_dma_attr(const struct device *dev);
500 
501 const void *device_get_match_data(const struct device *dev);
502 
503 int device_get_phy_mode(struct device *dev);
504 int fwnode_get_phy_mode(const struct fwnode_handle *fwnode);
505 
506 void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);
507 
508 struct fwnode_handle *fwnode_graph_get_next_endpoint(
509 	const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
510 struct fwnode_handle *
511 fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode);
512 struct fwnode_handle *fwnode_graph_get_remote_port_parent(
513 	const struct fwnode_handle *fwnode);
514 struct fwnode_handle *fwnode_graph_get_remote_port(
515 	const struct fwnode_handle *fwnode);
516 struct fwnode_handle *fwnode_graph_get_remote_endpoint(
517 	const struct fwnode_handle *fwnode);
518 
519 static inline bool fwnode_graph_is_endpoint(const struct fwnode_handle *fwnode)
520 {
521 	return fwnode_property_present(fwnode, "remote-endpoint");
522 }
523 
524 /*
525  * Fwnode lookup flags
526  *
527  * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the
528  *				closest endpoint ID greater than the specified
529  *				one.
530  * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote
531  *				  endpoint of the given endpoint belongs to,
532  *				  may be disabled, or that the endpoint is not
533  *				  connected.
534  */
535 #define FWNODE_GRAPH_ENDPOINT_NEXT	BIT(0)
536 #define FWNODE_GRAPH_DEVICE_DISABLED	BIT(1)
537 
538 struct fwnode_handle *
539 fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
540 				u32 port, u32 endpoint, unsigned long flags);
541 unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode,
542 					     unsigned long flags);
543 
544 #define fwnode_graph_for_each_endpoint(fwnode, child)				\
545 	for (child = fwnode_graph_get_next_endpoint(fwnode, NULL); child;	\
546 	     child = fwnode_graph_get_next_endpoint(fwnode, child))
547 
548 int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
549 				struct fwnode_endpoint *endpoint);
550 
551 typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id,
552 				   void *data);
553 
554 void *fwnode_connection_find_match(const struct fwnode_handle *fwnode,
555 				   const char *con_id, void *data,
556 				   devcon_match_fn_t match);
557 
558 static inline void *device_connection_find_match(const struct device *dev,
559 						 const char *con_id, void *data,
560 						 devcon_match_fn_t match)
561 {
562 	return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match);
563 }
564 
565 int fwnode_connection_find_matches(const struct fwnode_handle *fwnode,
566 				   const char *con_id, void *data,
567 				   devcon_match_fn_t match,
568 				   void **matches, unsigned int matches_len);
569 
570 /* -------------------------------------------------------------------------- */
571 /* Software fwnode support - when HW description is incomplete or missing */
572 
573 /**
574  * struct software_node - Software node description
575  * @name: Name of the software node
576  * @parent: Parent of the software node
577  * @properties: Array of device properties
578  */
579 struct software_node {
580 	const char *name;
581 	const struct software_node *parent;
582 	const struct property_entry *properties;
583 };
584 
585 #define SOFTWARE_NODE(_name_, _properties_, _parent_)	\
586 	(struct software_node) {			\
587 		.name = _name_,				\
588 		.properties = _properties_,		\
589 		.parent = _parent_,			\
590 	}
591 
592 bool is_software_node(const struct fwnode_handle *fwnode);
593 const struct software_node *
594 to_software_node(const struct fwnode_handle *fwnode);
595 struct fwnode_handle *software_node_fwnode(const struct software_node *node);
596 
597 const struct software_node *
598 software_node_find_by_name(const struct software_node *parent,
599 			   const char *name);
600 
601 int software_node_register_node_group(const struct software_node * const *node_group);
602 void software_node_unregister_node_group(const struct software_node * const *node_group);
603 
604 int software_node_register(const struct software_node *node);
605 void software_node_unregister(const struct software_node *node);
606 
607 struct fwnode_handle *
608 fwnode_create_software_node(const struct property_entry *properties,
609 			    const struct fwnode_handle *parent);
610 void fwnode_remove_software_node(struct fwnode_handle *fwnode);
611 
612 int device_add_software_node(struct device *dev, const struct software_node *node);
613 void device_remove_software_node(struct device *dev);
614 
615 int device_create_managed_software_node(struct device *dev,
616 					const struct property_entry *properties,
617 					const struct software_node *parent);
618 
619 #endif /* _LINUX_PROPERTY_H_ */
620