1 /* SPDX-License-Identifier: GPL-2.0+ */
2 #ifndef _LINUX_OF_H
3 #define _LINUX_OF_H
4 /*
5 * Definitions for talking to the Open Firmware PROM on
6 * Power Macintosh and other computers.
7 *
8 * Copyright (C) 1996-2005 Paul Mackerras.
9 *
10 * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
11 * Updates for SPARC64 by David S. Miller
12 * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
13 */
14 #include <linux/types.h>
15 #include <linux/bitops.h>
16 #include <linux/errno.h>
17 #include <linux/kobject.h>
18 #include <linux/mod_devicetable.h>
19 #include <linux/spinlock.h>
20 #include <linux/topology.h>
21 #include <linux/notifier.h>
22 #include <linux/property.h>
23 #include <linux/list.h>
24
25 #include <asm/byteorder.h>
26 #include <asm/errno.h>
27
28 typedef u32 phandle;
29 typedef u32 ihandle;
30
31 struct property {
32 char *name;
33 int length;
34 void *value;
35 struct property *next;
36 #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
37 unsigned long _flags;
38 #endif
39 #if defined(CONFIG_OF_PROMTREE)
40 unsigned int unique_id;
41 #endif
42 #if defined(CONFIG_OF_KOBJ)
43 struct bin_attribute attr;
44 #endif
45 };
46
47 #if defined(CONFIG_SPARC)
48 struct of_irq_controller;
49 #endif
50
51 struct device_node {
52 const char *name;
53 const char *type;
54 phandle phandle;
55 const char *full_name;
56 struct fwnode_handle fwnode;
57
58 struct property *properties;
59 struct property *deadprops; /* removed properties */
60 struct device_node *parent;
61 struct device_node *child;
62 struct device_node *sibling;
63 #if defined(CONFIG_OF_KOBJ)
64 struct kobject kobj;
65 #endif
66 unsigned long _flags;
67 void *data;
68 #if defined(CONFIG_SPARC)
69 const char *path_component_name;
70 unsigned int unique_id;
71 struct of_irq_controller *irq_trans;
72 #endif
73 };
74
75 #define MAX_PHANDLE_ARGS 16
76 struct of_phandle_args {
77 struct device_node *np;
78 int args_count;
79 uint32_t args[MAX_PHANDLE_ARGS];
80 };
81
82 struct of_phandle_iterator {
83 /* Common iterator information */
84 const char *cells_name;
85 int cell_count;
86 const struct device_node *parent;
87
88 /* List size information */
89 const __be32 *list_end;
90 const __be32 *phandle_end;
91
92 /* Current position state */
93 const __be32 *cur;
94 uint32_t cur_count;
95 phandle phandle;
96 struct device_node *node;
97 };
98
99 struct of_reconfig_data {
100 struct device_node *dn;
101 struct property *prop;
102 struct property *old_prop;
103 };
104
105 /* initialize a node */
106 extern struct kobj_type of_node_ktype;
107 extern const struct fwnode_operations of_fwnode_ops;
of_node_init(struct device_node * node)108 static inline void of_node_init(struct device_node *node)
109 {
110 #if defined(CONFIG_OF_KOBJ)
111 kobject_init(&node->kobj, &of_node_ktype);
112 #endif
113 node->fwnode.ops = &of_fwnode_ops;
114 }
115
116 #if defined(CONFIG_OF_KOBJ)
117 #define of_node_kobj(n) (&(n)->kobj)
118 #else
119 #define of_node_kobj(n) NULL
120 #endif
121
122 #ifdef CONFIG_OF_DYNAMIC
123 extern struct device_node *of_node_get(struct device_node *node);
124 extern void of_node_put(struct device_node *node);
125 #else /* CONFIG_OF_DYNAMIC */
126 /* Dummy ref counting routines - to be implemented later */
of_node_get(struct device_node * node)127 static inline struct device_node *of_node_get(struct device_node *node)
128 {
129 return node;
130 }
of_node_put(struct device_node * node)131 static inline void of_node_put(struct device_node *node) { }
132 #endif /* !CONFIG_OF_DYNAMIC */
133
134 /* Pointer for first entry in chain of all nodes. */
135 extern struct device_node *of_root;
136 extern struct device_node *of_chosen;
137 extern struct device_node *of_aliases;
138 extern struct device_node *of_stdout;
139 extern raw_spinlock_t devtree_lock;
140
141 /* flag descriptions (need to be visible even when !CONFIG_OF) */
142 #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
143 #define OF_DETACHED 2 /* node has been detached from the device tree */
144 #define OF_POPULATED 3 /* device already created for the node */
145 #define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */
146
147 #define OF_BAD_ADDR ((u64)-1)
148
149 #ifdef CONFIG_OF
150 void of_core_init(void);
151
is_of_node(const struct fwnode_handle * fwnode)152 static inline bool is_of_node(const struct fwnode_handle *fwnode)
153 {
154 return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops;
155 }
156
157 #define to_of_node(__fwnode) \
158 ({ \
159 typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
160 \
161 is_of_node(__to_of_node_fwnode) ? \
162 container_of(__to_of_node_fwnode, \
163 struct device_node, fwnode) : \
164 NULL; \
165 })
166
167 #define of_fwnode_handle(node) \
168 ({ \
169 typeof(node) __of_fwnode_handle_node = (node); \
170 \
171 __of_fwnode_handle_node ? \
172 &__of_fwnode_handle_node->fwnode : NULL; \
173 })
174
of_have_populated_dt(void)175 static inline bool of_have_populated_dt(void)
176 {
177 return of_root != NULL;
178 }
179
of_node_is_root(const struct device_node * node)180 static inline bool of_node_is_root(const struct device_node *node)
181 {
182 return node && (node->parent == NULL);
183 }
184
of_node_check_flag(struct device_node * n,unsigned long flag)185 static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
186 {
187 return test_bit(flag, &n->_flags);
188 }
189
of_node_test_and_set_flag(struct device_node * n,unsigned long flag)190 static inline int of_node_test_and_set_flag(struct device_node *n,
191 unsigned long flag)
192 {
193 return test_and_set_bit(flag, &n->_flags);
194 }
195
of_node_set_flag(struct device_node * n,unsigned long flag)196 static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
197 {
198 set_bit(flag, &n->_flags);
199 }
200
of_node_clear_flag(struct device_node * n,unsigned long flag)201 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
202 {
203 clear_bit(flag, &n->_flags);
204 }
205
206 #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
of_property_check_flag(struct property * p,unsigned long flag)207 static inline int of_property_check_flag(struct property *p, unsigned long flag)
208 {
209 return test_bit(flag, &p->_flags);
210 }
211
of_property_set_flag(struct property * p,unsigned long flag)212 static inline void of_property_set_flag(struct property *p, unsigned long flag)
213 {
214 set_bit(flag, &p->_flags);
215 }
216
of_property_clear_flag(struct property * p,unsigned long flag)217 static inline void of_property_clear_flag(struct property *p, unsigned long flag)
218 {
219 clear_bit(flag, &p->_flags);
220 }
221 #endif
222
223 extern struct device_node *__of_find_all_nodes(struct device_node *prev);
224 extern struct device_node *of_find_all_nodes(struct device_node *prev);
225
226 /*
227 * OF address retrieval & translation
228 */
229
230 /* Helper to read a big number; size is in cells (not bytes) */
of_read_number(const __be32 * cell,int size)231 static inline u64 of_read_number(const __be32 *cell, int size)
232 {
233 u64 r = 0;
234 while (size--)
235 r = (r << 32) | be32_to_cpu(*(cell++));
236 return r;
237 }
238
239 /* Like of_read_number, but we want an unsigned long result */
of_read_ulong(const __be32 * cell,int size)240 static inline unsigned long of_read_ulong(const __be32 *cell, int size)
241 {
242 /* toss away upper bits if unsigned long is smaller than u64 */
243 return of_read_number(cell, size);
244 }
245
246 #if defined(CONFIG_SPARC)
247 #include <asm/prom.h>
248 #endif
249
250 /* Default #address and #size cells. Allow arch asm/prom.h to override */
251 #if !defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT)
252 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
253 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
254 #endif
255
256 #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
257 #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
258
259 extern bool of_node_name_eq(const struct device_node *np, const char *name);
260 extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);
261
of_node_full_name(const struct device_node * np)262 static inline const char *of_node_full_name(const struct device_node *np)
263 {
264 return np ? np->full_name : "<no-node>";
265 }
266
267 #define for_each_of_allnodes_from(from, dn) \
268 for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn))
269 #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
270 extern struct device_node *of_find_node_by_name(struct device_node *from,
271 const char *name);
272 extern struct device_node *of_find_node_by_type(struct device_node *from,
273 const char *type);
274 extern struct device_node *of_find_compatible_node(struct device_node *from,
275 const char *type, const char *compat);
276 extern struct device_node *of_find_matching_node_and_match(
277 struct device_node *from,
278 const struct of_device_id *matches,
279 const struct of_device_id **match);
280
281 extern struct device_node *of_find_node_opts_by_path(const char *path,
282 const char **opts);
of_find_node_by_path(const char * path)283 static inline struct device_node *of_find_node_by_path(const char *path)
284 {
285 return of_find_node_opts_by_path(path, NULL);
286 }
287
288 extern struct device_node *of_find_node_by_phandle(phandle handle);
289 extern struct device_node *of_get_parent(const struct device_node *node);
290 extern struct device_node *of_get_next_parent(struct device_node *node);
291 extern struct device_node *of_get_next_child(const struct device_node *node,
292 struct device_node *prev);
293 extern struct device_node *of_get_next_available_child(
294 const struct device_node *node, struct device_node *prev);
295
296 extern struct device_node *of_get_compatible_child(const struct device_node *parent,
297 const char *compatible);
298 extern struct device_node *of_get_child_by_name(const struct device_node *node,
299 const char *name);
300
301 /* cache lookup */
302 extern struct device_node *of_find_next_cache_node(const struct device_node *);
303 extern int of_find_last_cache_level(unsigned int cpu);
304 extern struct device_node *of_find_node_with_property(
305 struct device_node *from, const char *prop_name);
306
307 extern struct property *of_find_property(const struct device_node *np,
308 const char *name,
309 int *lenp);
310 extern int of_property_count_elems_of_size(const struct device_node *np,
311 const char *propname, int elem_size);
312 extern int of_property_read_u32_index(const struct device_node *np,
313 const char *propname,
314 u32 index, u32 *out_value);
315 extern int of_property_read_u64_index(const struct device_node *np,
316 const char *propname,
317 u32 index, u64 *out_value);
318 extern int of_property_read_variable_u8_array(const struct device_node *np,
319 const char *propname, u8 *out_values,
320 size_t sz_min, size_t sz_max);
321 extern int of_property_read_variable_u16_array(const struct device_node *np,
322 const char *propname, u16 *out_values,
323 size_t sz_min, size_t sz_max);
324 extern int of_property_read_variable_u32_array(const struct device_node *np,
325 const char *propname,
326 u32 *out_values,
327 size_t sz_min,
328 size_t sz_max);
329 extern int of_property_read_u64(const struct device_node *np,
330 const char *propname, u64 *out_value);
331 extern int of_property_read_variable_u64_array(const struct device_node *np,
332 const char *propname,
333 u64 *out_values,
334 size_t sz_min,
335 size_t sz_max);
336
337 extern int of_property_read_string(const struct device_node *np,
338 const char *propname,
339 const char **out_string);
340 extern int of_property_match_string(const struct device_node *np,
341 const char *propname,
342 const char *string);
343 extern int of_property_read_string_helper(const struct device_node *np,
344 const char *propname,
345 const char **out_strs, size_t sz, int index);
346 extern int of_device_is_compatible(const struct device_node *device,
347 const char *);
348 extern int of_device_compatible_match(struct device_node *device,
349 const char *const *compat);
350 extern bool of_device_is_available(const struct device_node *device);
351 extern bool of_device_is_big_endian(const struct device_node *device);
352 extern const void *of_get_property(const struct device_node *node,
353 const char *name,
354 int *lenp);
355 extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
356 #define for_each_property_of_node(dn, pp) \
357 for (pp = dn->properties; pp != NULL; pp = pp->next)
358
359 extern int of_n_addr_cells(struct device_node *np);
360 extern int of_n_size_cells(struct device_node *np);
361 extern const struct of_device_id *of_match_node(
362 const struct of_device_id *matches, const struct device_node *node);
363 extern int of_modalias_node(struct device_node *node, char *modalias, int len);
364 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
365 extern struct device_node *of_parse_phandle(const struct device_node *np,
366 const char *phandle_name,
367 int index);
368 extern int of_parse_phandle_with_args(const struct device_node *np,
369 const char *list_name, const char *cells_name, int index,
370 struct of_phandle_args *out_args);
371 extern int of_parse_phandle_with_args_map(const struct device_node *np,
372 const char *list_name, const char *stem_name, int index,
373 struct of_phandle_args *out_args);
374 extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
375 const char *list_name, int cells_count, int index,
376 struct of_phandle_args *out_args);
377 extern int of_count_phandle_with_args(const struct device_node *np,
378 const char *list_name, const char *cells_name);
379
380 /* phandle iterator functions */
381 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
382 const struct device_node *np,
383 const char *list_name,
384 const char *cells_name,
385 int cell_count);
386
387 extern int of_phandle_iterator_next(struct of_phandle_iterator *it);
388 extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
389 uint32_t *args,
390 int size);
391
392 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
393 extern int of_alias_get_id(struct device_node *np, const char *stem);
394 extern int of_alias_get_highest_id(const char *stem);
395
396 extern int of_machine_is_compatible(const char *compat);
397
398 extern int of_add_property(struct device_node *np, struct property *prop);
399 extern int of_remove_property(struct device_node *np, struct property *prop);
400 extern int of_update_property(struct device_node *np, struct property *newprop);
401
402 /* For updating the device tree at runtime */
403 #define OF_RECONFIG_ATTACH_NODE 0x0001
404 #define OF_RECONFIG_DETACH_NODE 0x0002
405 #define OF_RECONFIG_ADD_PROPERTY 0x0003
406 #define OF_RECONFIG_REMOVE_PROPERTY 0x0004
407 #define OF_RECONFIG_UPDATE_PROPERTY 0x0005
408
409 extern int of_attach_node(struct device_node *);
410 extern int of_detach_node(struct device_node *);
411
412 #define of_match_ptr(_ptr) (_ptr)
413
414 /**
415 * of_property_read_u8_array - Find and read an array of u8 from a property.
416 *
417 * @np: device node from which the property value is to be read.
418 * @propname: name of the property to be searched.
419 * @out_values: pointer to return value, modified only if return value is 0.
420 * @sz: number of array elements to read
421 *
422 * Search for a property in a device node and read 8-bit value(s) from
423 * it. Returns 0 on success, -EINVAL if the property does not exist,
424 * -ENODATA if property does not have a value, and -EOVERFLOW if the
425 * property data isn't large enough.
426 *
427 * dts entry of array should be like:
428 * property = /bits/ 8 <0x50 0x60 0x70>;
429 *
430 * The out_values is modified only if a valid u8 value can be decoded.
431 */
of_property_read_u8_array(const struct device_node * np,const char * propname,u8 * out_values,size_t sz)432 static inline int of_property_read_u8_array(const struct device_node *np,
433 const char *propname,
434 u8 *out_values, size_t sz)
435 {
436 int ret = of_property_read_variable_u8_array(np, propname, out_values,
437 sz, 0);
438 if (ret >= 0)
439 return 0;
440 else
441 return ret;
442 }
443
444 /**
445 * of_property_read_u16_array - Find and read an array of u16 from a property.
446 *
447 * @np: device node from which the property value is to be read.
448 * @propname: name of the property to be searched.
449 * @out_values: pointer to return value, modified only if return value is 0.
450 * @sz: number of array elements to read
451 *
452 * Search for a property in a device node and read 16-bit value(s) from
453 * it. Returns 0 on success, -EINVAL if the property does not exist,
454 * -ENODATA if property does not have a value, and -EOVERFLOW if the
455 * property data isn't large enough.
456 *
457 * dts entry of array should be like:
458 * property = /bits/ 16 <0x5000 0x6000 0x7000>;
459 *
460 * The out_values is modified only if a valid u16 value can be decoded.
461 */
of_property_read_u16_array(const struct device_node * np,const char * propname,u16 * out_values,size_t sz)462 static inline int of_property_read_u16_array(const struct device_node *np,
463 const char *propname,
464 u16 *out_values, size_t sz)
465 {
466 int ret = of_property_read_variable_u16_array(np, propname, out_values,
467 sz, 0);
468 if (ret >= 0)
469 return 0;
470 else
471 return ret;
472 }
473
474 /**
475 * of_property_read_u32_array - Find and read an array of 32 bit integers
476 * from a property.
477 *
478 * @np: device node from which the property value is to be read.
479 * @propname: name of the property to be searched.
480 * @out_values: pointer to return value, modified only if return value is 0.
481 * @sz: number of array elements to read
482 *
483 * Search for a property in a device node and read 32-bit value(s) from
484 * it. Returns 0 on success, -EINVAL if the property does not exist,
485 * -ENODATA if property does not have a value, and -EOVERFLOW if the
486 * property data isn't large enough.
487 *
488 * The out_values is modified only if a valid u32 value can be decoded.
489 */
of_property_read_u32_array(const struct device_node * np,const char * propname,u32 * out_values,size_t sz)490 static inline int of_property_read_u32_array(const struct device_node *np,
491 const char *propname,
492 u32 *out_values, size_t sz)
493 {
494 int ret = of_property_read_variable_u32_array(np, propname, out_values,
495 sz, 0);
496 if (ret >= 0)
497 return 0;
498 else
499 return ret;
500 }
501
502 /**
503 * of_property_read_u64_array - Find and read an array of 64 bit integers
504 * from a property.
505 *
506 * @np: device node from which the property value is to be read.
507 * @propname: name of the property to be searched.
508 * @out_values: pointer to return value, modified only if return value is 0.
509 * @sz: number of array elements to read
510 *
511 * Search for a property in a device node and read 64-bit value(s) from
512 * it. Returns 0 on success, -EINVAL if the property does not exist,
513 * -ENODATA if property does not have a value, and -EOVERFLOW if the
514 * property data isn't large enough.
515 *
516 * The out_values is modified only if a valid u64 value can be decoded.
517 */
of_property_read_u64_array(const struct device_node * np,const char * propname,u64 * out_values,size_t sz)518 static inline int of_property_read_u64_array(const struct device_node *np,
519 const char *propname,
520 u64 *out_values, size_t sz)
521 {
522 int ret = of_property_read_variable_u64_array(np, propname, out_values,
523 sz, 0);
524 if (ret >= 0)
525 return 0;
526 else
527 return ret;
528 }
529
530 /*
531 * struct property *prop;
532 * const __be32 *p;
533 * u32 u;
534 *
535 * of_property_for_each_u32(np, "propname", prop, p, u)
536 * printk("U32 value: %x\n", u);
537 */
538 const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
539 u32 *pu);
540 /*
541 * struct property *prop;
542 * const char *s;
543 *
544 * of_property_for_each_string(np, "propname", prop, s)
545 * printk("String value: %s\n", s);
546 */
547 const char *of_prop_next_string(struct property *prop, const char *cur);
548
549 bool of_console_check(struct device_node *dn, char *name, int index);
550
551 extern int of_cpu_node_to_id(struct device_node *np);
552
553 #else /* CONFIG_OF */
554
of_core_init(void)555 static inline void of_core_init(void)
556 {
557 }
558
is_of_node(const struct fwnode_handle * fwnode)559 static inline bool is_of_node(const struct fwnode_handle *fwnode)
560 {
561 return false;
562 }
563
to_of_node(const struct fwnode_handle * fwnode)564 static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
565 {
566 return NULL;
567 }
568
of_node_name_eq(const struct device_node * np,const char * name)569 static inline bool of_node_name_eq(const struct device_node *np, const char *name)
570 {
571 return false;
572 }
573
of_node_name_prefix(const struct device_node * np,const char * prefix)574 static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
575 {
576 return false;
577 }
578
of_node_full_name(const struct device_node * np)579 static inline const char* of_node_full_name(const struct device_node *np)
580 {
581 return "<no-node>";
582 }
583
of_find_node_by_name(struct device_node * from,const char * name)584 static inline struct device_node *of_find_node_by_name(struct device_node *from,
585 const char *name)
586 {
587 return NULL;
588 }
589
of_find_node_by_type(struct device_node * from,const char * type)590 static inline struct device_node *of_find_node_by_type(struct device_node *from,
591 const char *type)
592 {
593 return NULL;
594 }
595
of_find_matching_node_and_match(struct device_node * from,const struct of_device_id * matches,const struct of_device_id ** match)596 static inline struct device_node *of_find_matching_node_and_match(
597 struct device_node *from,
598 const struct of_device_id *matches,
599 const struct of_device_id **match)
600 {
601 return NULL;
602 }
603
of_find_node_by_path(const char * path)604 static inline struct device_node *of_find_node_by_path(const char *path)
605 {
606 return NULL;
607 }
608
of_find_node_opts_by_path(const char * path,const char ** opts)609 static inline struct device_node *of_find_node_opts_by_path(const char *path,
610 const char **opts)
611 {
612 return NULL;
613 }
614
of_find_node_by_phandle(phandle handle)615 static inline struct device_node *of_find_node_by_phandle(phandle handle)
616 {
617 return NULL;
618 }
619
of_get_parent(const struct device_node * node)620 static inline struct device_node *of_get_parent(const struct device_node *node)
621 {
622 return NULL;
623 }
624
of_get_next_child(const struct device_node * node,struct device_node * prev)625 static inline struct device_node *of_get_next_child(
626 const struct device_node *node, struct device_node *prev)
627 {
628 return NULL;
629 }
630
of_get_next_available_child(const struct device_node * node,struct device_node * prev)631 static inline struct device_node *of_get_next_available_child(
632 const struct device_node *node, struct device_node *prev)
633 {
634 return NULL;
635 }
636
of_find_node_with_property(struct device_node * from,const char * prop_name)637 static inline struct device_node *of_find_node_with_property(
638 struct device_node *from, const char *prop_name)
639 {
640 return NULL;
641 }
642
643 #define of_fwnode_handle(node) NULL
644
of_have_populated_dt(void)645 static inline bool of_have_populated_dt(void)
646 {
647 return false;
648 }
649
of_get_compatible_child(const struct device_node * parent,const char * compatible)650 static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
651 const char *compatible)
652 {
653 return NULL;
654 }
655
of_get_child_by_name(const struct device_node * node,const char * name)656 static inline struct device_node *of_get_child_by_name(
657 const struct device_node *node,
658 const char *name)
659 {
660 return NULL;
661 }
662
of_device_is_compatible(const struct device_node * device,const char * name)663 static inline int of_device_is_compatible(const struct device_node *device,
664 const char *name)
665 {
666 return 0;
667 }
668
of_device_compatible_match(struct device_node * device,const char * const * compat)669 static inline int of_device_compatible_match(struct device_node *device,
670 const char *const *compat)
671 {
672 return 0;
673 }
674
of_device_is_available(const struct device_node * device)675 static inline bool of_device_is_available(const struct device_node *device)
676 {
677 return false;
678 }
679
of_device_is_big_endian(const struct device_node * device)680 static inline bool of_device_is_big_endian(const struct device_node *device)
681 {
682 return false;
683 }
684
of_find_property(const struct device_node * np,const char * name,int * lenp)685 static inline struct property *of_find_property(const struct device_node *np,
686 const char *name,
687 int *lenp)
688 {
689 return NULL;
690 }
691
of_find_compatible_node(struct device_node * from,const char * type,const char * compat)692 static inline struct device_node *of_find_compatible_node(
693 struct device_node *from,
694 const char *type,
695 const char *compat)
696 {
697 return NULL;
698 }
699
of_property_count_elems_of_size(const struct device_node * np,const char * propname,int elem_size)700 static inline int of_property_count_elems_of_size(const struct device_node *np,
701 const char *propname, int elem_size)
702 {
703 return -ENOSYS;
704 }
705
of_property_read_u8_array(const struct device_node * np,const char * propname,u8 * out_values,size_t sz)706 static inline int of_property_read_u8_array(const struct device_node *np,
707 const char *propname, u8 *out_values, size_t sz)
708 {
709 return -ENOSYS;
710 }
711
of_property_read_u16_array(const struct device_node * np,const char * propname,u16 * out_values,size_t sz)712 static inline int of_property_read_u16_array(const struct device_node *np,
713 const char *propname, u16 *out_values, size_t sz)
714 {
715 return -ENOSYS;
716 }
717
of_property_read_u32_array(const struct device_node * np,const char * propname,u32 * out_values,size_t sz)718 static inline int of_property_read_u32_array(const struct device_node *np,
719 const char *propname,
720 u32 *out_values, size_t sz)
721 {
722 return -ENOSYS;
723 }
724
of_property_read_u64_array(const struct device_node * np,const char * propname,u64 * out_values,size_t sz)725 static inline int of_property_read_u64_array(const struct device_node *np,
726 const char *propname,
727 u64 *out_values, size_t sz)
728 {
729 return -ENOSYS;
730 }
731
of_property_read_u32_index(const struct device_node * np,const char * propname,u32 index,u32 * out_value)732 static inline int of_property_read_u32_index(const struct device_node *np,
733 const char *propname, u32 index, u32 *out_value)
734 {
735 return -ENOSYS;
736 }
737
of_property_read_u64_index(const struct device_node * np,const char * propname,u32 index,u64 * out_value)738 static inline int of_property_read_u64_index(const struct device_node *np,
739 const char *propname, u32 index, u64 *out_value)
740 {
741 return -ENOSYS;
742 }
743
of_get_property(const struct device_node * node,const char * name,int * lenp)744 static inline const void *of_get_property(const struct device_node *node,
745 const char *name,
746 int *lenp)
747 {
748 return NULL;
749 }
750
of_get_cpu_node(int cpu,unsigned int * thread)751 static inline struct device_node *of_get_cpu_node(int cpu,
752 unsigned int *thread)
753 {
754 return NULL;
755 }
756
of_n_addr_cells(struct device_node * np)757 static inline int of_n_addr_cells(struct device_node *np)
758 {
759 return 0;
760
761 }
of_n_size_cells(struct device_node * np)762 static inline int of_n_size_cells(struct device_node *np)
763 {
764 return 0;
765 }
766
of_property_read_variable_u8_array(const struct device_node * np,const char * propname,u8 * out_values,size_t sz_min,size_t sz_max)767 static inline int of_property_read_variable_u8_array(const struct device_node *np,
768 const char *propname, u8 *out_values,
769 size_t sz_min, size_t sz_max)
770 {
771 return -ENOSYS;
772 }
773
of_property_read_variable_u16_array(const struct device_node * np,const char * propname,u16 * out_values,size_t sz_min,size_t sz_max)774 static inline int of_property_read_variable_u16_array(const struct device_node *np,
775 const char *propname, u16 *out_values,
776 size_t sz_min, size_t sz_max)
777 {
778 return -ENOSYS;
779 }
780
of_property_read_variable_u32_array(const struct device_node * np,const char * propname,u32 * out_values,size_t sz_min,size_t sz_max)781 static inline int of_property_read_variable_u32_array(const struct device_node *np,
782 const char *propname,
783 u32 *out_values,
784 size_t sz_min,
785 size_t sz_max)
786 {
787 return -ENOSYS;
788 }
789
of_property_read_u64(const struct device_node * np,const char * propname,u64 * out_value)790 static inline int of_property_read_u64(const struct device_node *np,
791 const char *propname, u64 *out_value)
792 {
793 return -ENOSYS;
794 }
795
of_property_read_variable_u64_array(const struct device_node * np,const char * propname,u64 * out_values,size_t sz_min,size_t sz_max)796 static inline int of_property_read_variable_u64_array(const struct device_node *np,
797 const char *propname,
798 u64 *out_values,
799 size_t sz_min,
800 size_t sz_max)
801 {
802 return -ENOSYS;
803 }
804
of_property_read_string(const struct device_node * np,const char * propname,const char ** out_string)805 static inline int of_property_read_string(const struct device_node *np,
806 const char *propname,
807 const char **out_string)
808 {
809 return -ENOSYS;
810 }
811
of_property_match_string(const struct device_node * np,const char * propname,const char * string)812 static inline int of_property_match_string(const struct device_node *np,
813 const char *propname,
814 const char *string)
815 {
816 return -ENOSYS;
817 }
818
of_property_read_string_helper(const struct device_node * np,const char * propname,const char ** out_strs,size_t sz,int index)819 static inline int of_property_read_string_helper(const struct device_node *np,
820 const char *propname,
821 const char **out_strs, size_t sz, int index)
822 {
823 return -ENOSYS;
824 }
825
of_parse_phandle(const struct device_node * np,const char * phandle_name,int index)826 static inline struct device_node *of_parse_phandle(const struct device_node *np,
827 const char *phandle_name,
828 int index)
829 {
830 return NULL;
831 }
832
of_parse_phandle_with_args(const struct device_node * np,const char * list_name,const char * cells_name,int index,struct of_phandle_args * out_args)833 static inline int of_parse_phandle_with_args(const struct device_node *np,
834 const char *list_name,
835 const char *cells_name,
836 int index,
837 struct of_phandle_args *out_args)
838 {
839 return -ENOSYS;
840 }
841
of_parse_phandle_with_args_map(const struct device_node * np,const char * list_name,const char * stem_name,int index,struct of_phandle_args * out_args)842 static inline int of_parse_phandle_with_args_map(const struct device_node *np,
843 const char *list_name,
844 const char *stem_name,
845 int index,
846 struct of_phandle_args *out_args)
847 {
848 return -ENOSYS;
849 }
850
of_parse_phandle_with_fixed_args(const struct device_node * np,const char * list_name,int cells_count,int index,struct of_phandle_args * out_args)851 static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
852 const char *list_name, int cells_count, int index,
853 struct of_phandle_args *out_args)
854 {
855 return -ENOSYS;
856 }
857
of_count_phandle_with_args(struct device_node * np,const char * list_name,const char * cells_name)858 static inline int of_count_phandle_with_args(struct device_node *np,
859 const char *list_name,
860 const char *cells_name)
861 {
862 return -ENOSYS;
863 }
864
of_phandle_iterator_init(struct of_phandle_iterator * it,const struct device_node * np,const char * list_name,const char * cells_name,int cell_count)865 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
866 const struct device_node *np,
867 const char *list_name,
868 const char *cells_name,
869 int cell_count)
870 {
871 return -ENOSYS;
872 }
873
of_phandle_iterator_next(struct of_phandle_iterator * it)874 static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
875 {
876 return -ENOSYS;
877 }
878
of_phandle_iterator_args(struct of_phandle_iterator * it,uint32_t * args,int size)879 static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
880 uint32_t *args,
881 int size)
882 {
883 return 0;
884 }
885
of_alias_get_id(struct device_node * np,const char * stem)886 static inline int of_alias_get_id(struct device_node *np, const char *stem)
887 {
888 return -ENOSYS;
889 }
890
of_alias_get_highest_id(const char * stem)891 static inline int of_alias_get_highest_id(const char *stem)
892 {
893 return -ENOSYS;
894 }
895
of_machine_is_compatible(const char * compat)896 static inline int of_machine_is_compatible(const char *compat)
897 {
898 return 0;
899 }
900
of_console_check(const struct device_node * dn,const char * name,int index)901 static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
902 {
903 return false;
904 }
905
of_prop_next_u32(struct property * prop,const __be32 * cur,u32 * pu)906 static inline const __be32 *of_prop_next_u32(struct property *prop,
907 const __be32 *cur, u32 *pu)
908 {
909 return NULL;
910 }
911
of_prop_next_string(struct property * prop,const char * cur)912 static inline const char *of_prop_next_string(struct property *prop,
913 const char *cur)
914 {
915 return NULL;
916 }
917
of_node_check_flag(struct device_node * n,unsigned long flag)918 static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
919 {
920 return 0;
921 }
922
of_node_test_and_set_flag(struct device_node * n,unsigned long flag)923 static inline int of_node_test_and_set_flag(struct device_node *n,
924 unsigned long flag)
925 {
926 return 0;
927 }
928
of_node_set_flag(struct device_node * n,unsigned long flag)929 static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
930 {
931 }
932
of_node_clear_flag(struct device_node * n,unsigned long flag)933 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
934 {
935 }
936
of_property_check_flag(struct property * p,unsigned long flag)937 static inline int of_property_check_flag(struct property *p, unsigned long flag)
938 {
939 return 0;
940 }
941
of_property_set_flag(struct property * p,unsigned long flag)942 static inline void of_property_set_flag(struct property *p, unsigned long flag)
943 {
944 }
945
of_property_clear_flag(struct property * p,unsigned long flag)946 static inline void of_property_clear_flag(struct property *p, unsigned long flag)
947 {
948 }
949
of_cpu_node_to_id(struct device_node * np)950 static inline int of_cpu_node_to_id(struct device_node *np)
951 {
952 return -ENODEV;
953 }
954
955 #define of_match_ptr(_ptr) NULL
956 #define of_match_node(_matches, _node) NULL
957 #endif /* CONFIG_OF */
958
959 /* Default string compare functions, Allow arch asm/prom.h to override */
960 #if !defined(of_compat_cmp)
961 #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
962 #define of_prop_cmp(s1, s2) strcmp((s1), (s2))
963 #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
964 #endif
965
966 #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
967 extern int of_node_to_nid(struct device_node *np);
968 #else
of_node_to_nid(struct device_node * device)969 static inline int of_node_to_nid(struct device_node *device)
970 {
971 return NUMA_NO_NODE;
972 }
973 #endif
974
975 #ifdef CONFIG_OF_NUMA
976 extern int of_numa_init(void);
977 #else
of_numa_init(void)978 static inline int of_numa_init(void)
979 {
980 return -ENOSYS;
981 }
982 #endif
983
of_find_matching_node(struct device_node * from,const struct of_device_id * matches)984 static inline struct device_node *of_find_matching_node(
985 struct device_node *from,
986 const struct of_device_id *matches)
987 {
988 return of_find_matching_node_and_match(from, matches, NULL);
989 }
990
of_node_get_device_type(const struct device_node * np)991 static inline const char *of_node_get_device_type(const struct device_node *np)
992 {
993 return of_get_property(np, "type", NULL);
994 }
995
of_node_is_type(const struct device_node * np,const char * type)996 static inline bool of_node_is_type(const struct device_node *np, const char *type)
997 {
998 const char *match = of_node_get_device_type(np);
999
1000 return np && match && type && !strcmp(match, type);
1001 }
1002
1003 /**
1004 * of_property_count_u8_elems - Count the number of u8 elements in a property
1005 *
1006 * @np: device node from which the property value is to be read.
1007 * @propname: name of the property to be searched.
1008 *
1009 * Search for a property in a device node and count the number of u8 elements
1010 * in it. Returns number of elements on sucess, -EINVAL if the property does
1011 * not exist or its length does not match a multiple of u8 and -ENODATA if the
1012 * property does not have a value.
1013 */
of_property_count_u8_elems(const struct device_node * np,const char * propname)1014 static inline int of_property_count_u8_elems(const struct device_node *np,
1015 const char *propname)
1016 {
1017 return of_property_count_elems_of_size(np, propname, sizeof(u8));
1018 }
1019
1020 /**
1021 * of_property_count_u16_elems - Count the number of u16 elements in a property
1022 *
1023 * @np: device node from which the property value is to be read.
1024 * @propname: name of the property to be searched.
1025 *
1026 * Search for a property in a device node and count the number of u16 elements
1027 * in it. Returns number of elements on sucess, -EINVAL if the property does
1028 * not exist or its length does not match a multiple of u16 and -ENODATA if the
1029 * property does not have a value.
1030 */
of_property_count_u16_elems(const struct device_node * np,const char * propname)1031 static inline int of_property_count_u16_elems(const struct device_node *np,
1032 const char *propname)
1033 {
1034 return of_property_count_elems_of_size(np, propname, sizeof(u16));
1035 }
1036
1037 /**
1038 * of_property_count_u32_elems - Count the number of u32 elements in a property
1039 *
1040 * @np: device node from which the property value is to be read.
1041 * @propname: name of the property to be searched.
1042 *
1043 * Search for a property in a device node and count the number of u32 elements
1044 * in it. Returns number of elements on sucess, -EINVAL if the property does
1045 * not exist or its length does not match a multiple of u32 and -ENODATA if the
1046 * property does not have a value.
1047 */
of_property_count_u32_elems(const struct device_node * np,const char * propname)1048 static inline int of_property_count_u32_elems(const struct device_node *np,
1049 const char *propname)
1050 {
1051 return of_property_count_elems_of_size(np, propname, sizeof(u32));
1052 }
1053
1054 /**
1055 * of_property_count_u64_elems - Count the number of u64 elements in a property
1056 *
1057 * @np: device node from which the property value is to be read.
1058 * @propname: name of the property to be searched.
1059 *
1060 * Search for a property in a device node and count the number of u64 elements
1061 * in it. Returns number of elements on sucess, -EINVAL if the property does
1062 * not exist or its length does not match a multiple of u64 and -ENODATA if the
1063 * property does not have a value.
1064 */
of_property_count_u64_elems(const struct device_node * np,const char * propname)1065 static inline int of_property_count_u64_elems(const struct device_node *np,
1066 const char *propname)
1067 {
1068 return of_property_count_elems_of_size(np, propname, sizeof(u64));
1069 }
1070
1071 /**
1072 * of_property_read_string_array() - Read an array of strings from a multiple
1073 * strings property.
1074 * @np: device node from which the property value is to be read.
1075 * @propname: name of the property to be searched.
1076 * @out_strs: output array of string pointers.
1077 * @sz: number of array elements to read.
1078 *
1079 * Search for a property in a device tree node and retrieve a list of
1080 * terminated string values (pointer to data, not a copy) in that property.
1081 *
1082 * If @out_strs is NULL, the number of strings in the property is returned.
1083 */
of_property_read_string_array(const struct device_node * np,const char * propname,const char ** out_strs,size_t sz)1084 static inline int of_property_read_string_array(const struct device_node *np,
1085 const char *propname, const char **out_strs,
1086 size_t sz)
1087 {
1088 return of_property_read_string_helper(np, propname, out_strs, sz, 0);
1089 }
1090
1091 /**
1092 * of_property_count_strings() - Find and return the number of strings from a
1093 * multiple strings property.
1094 * @np: device node from which the property value is to be read.
1095 * @propname: name of the property to be searched.
1096 *
1097 * Search for a property in a device tree node and retrieve the number of null
1098 * terminated string contain in it. Returns the number of strings on
1099 * success, -EINVAL if the property does not exist, -ENODATA if property
1100 * does not have a value, and -EILSEQ if the string is not null-terminated
1101 * within the length of the property data.
1102 */
of_property_count_strings(const struct device_node * np,const char * propname)1103 static inline int of_property_count_strings(const struct device_node *np,
1104 const char *propname)
1105 {
1106 return of_property_read_string_helper(np, propname, NULL, 0, 0);
1107 }
1108
1109 /**
1110 * of_property_read_string_index() - Find and read a string from a multiple
1111 * strings property.
1112 * @np: device node from which the property value is to be read.
1113 * @propname: name of the property to be searched.
1114 * @index: index of the string in the list of strings
1115 * @out_string: pointer to null terminated return string, modified only if
1116 * return value is 0.
1117 *
1118 * Search for a property in a device tree node and retrieve a null
1119 * terminated string value (pointer to data, not a copy) in the list of strings
1120 * contained in that property.
1121 * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
1122 * property does not have a value, and -EILSEQ if the string is not
1123 * null-terminated within the length of the property data.
1124 *
1125 * The out_string pointer is modified only if a valid string can be decoded.
1126 */
of_property_read_string_index(const struct device_node * np,const char * propname,int index,const char ** output)1127 static inline int of_property_read_string_index(const struct device_node *np,
1128 const char *propname,
1129 int index, const char **output)
1130 {
1131 int rc = of_property_read_string_helper(np, propname, output, 1, index);
1132 return rc < 0 ? rc : 0;
1133 }
1134
1135 /**
1136 * of_property_read_bool - Findfrom a property
1137 * @np: device node from which the property value is to be read.
1138 * @propname: name of the property to be searched.
1139 *
1140 * Search for a property in a device node.
1141 * Returns true if the property exists false otherwise.
1142 */
of_property_read_bool(const struct device_node * np,const char * propname)1143 static inline bool of_property_read_bool(const struct device_node *np,
1144 const char *propname)
1145 {
1146 struct property *prop = of_find_property(np, propname, NULL);
1147
1148 return prop ? true : false;
1149 }
1150
of_property_read_u8(const struct device_node * np,const char * propname,u8 * out_value)1151 static inline int of_property_read_u8(const struct device_node *np,
1152 const char *propname,
1153 u8 *out_value)
1154 {
1155 return of_property_read_u8_array(np, propname, out_value, 1);
1156 }
1157
of_property_read_u16(const struct device_node * np,const char * propname,u16 * out_value)1158 static inline int of_property_read_u16(const struct device_node *np,
1159 const char *propname,
1160 u16 *out_value)
1161 {
1162 return of_property_read_u16_array(np, propname, out_value, 1);
1163 }
1164
of_property_read_u32(const struct device_node * np,const char * propname,u32 * out_value)1165 static inline int of_property_read_u32(const struct device_node *np,
1166 const char *propname,
1167 u32 *out_value)
1168 {
1169 return of_property_read_u32_array(np, propname, out_value, 1);
1170 }
1171
of_property_read_s32(const struct device_node * np,const char * propname,s32 * out_value)1172 static inline int of_property_read_s32(const struct device_node *np,
1173 const char *propname,
1174 s32 *out_value)
1175 {
1176 return of_property_read_u32(np, propname, (u32*) out_value);
1177 }
1178
1179 #define of_for_each_phandle(it, err, np, ln, cn, cc) \
1180 for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \
1181 err = of_phandle_iterator_next(it); \
1182 err == 0; \
1183 err = of_phandle_iterator_next(it))
1184
1185 #define of_property_for_each_u32(np, propname, prop, p, u) \
1186 for (prop = of_find_property(np, propname, NULL), \
1187 p = of_prop_next_u32(prop, NULL, &u); \
1188 p; \
1189 p = of_prop_next_u32(prop, p, &u))
1190
1191 #define of_property_for_each_string(np, propname, prop, s) \
1192 for (prop = of_find_property(np, propname, NULL), \
1193 s = of_prop_next_string(prop, NULL); \
1194 s; \
1195 s = of_prop_next_string(prop, s))
1196
1197 #define for_each_node_by_name(dn, name) \
1198 for (dn = of_find_node_by_name(NULL, name); dn; \
1199 dn = of_find_node_by_name(dn, name))
1200 #define for_each_node_by_type(dn, type) \
1201 for (dn = of_find_node_by_type(NULL, type); dn; \
1202 dn = of_find_node_by_type(dn, type))
1203 #define for_each_compatible_node(dn, type, compatible) \
1204 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
1205 dn = of_find_compatible_node(dn, type, compatible))
1206 #define for_each_matching_node(dn, matches) \
1207 for (dn = of_find_matching_node(NULL, matches); dn; \
1208 dn = of_find_matching_node(dn, matches))
1209 #define for_each_matching_node_and_match(dn, matches, match) \
1210 for (dn = of_find_matching_node_and_match(NULL, matches, match); \
1211 dn; dn = of_find_matching_node_and_match(dn, matches, match))
1212
1213 #define for_each_child_of_node(parent, child) \
1214 for (child = of_get_next_child(parent, NULL); child != NULL; \
1215 child = of_get_next_child(parent, child))
1216 #define for_each_available_child_of_node(parent, child) \
1217 for (child = of_get_next_available_child(parent, NULL); child != NULL; \
1218 child = of_get_next_available_child(parent, child))
1219
1220 #define for_each_node_with_property(dn, prop_name) \
1221 for (dn = of_find_node_with_property(NULL, prop_name); dn; \
1222 dn = of_find_node_with_property(dn, prop_name))
1223
of_get_child_count(const struct device_node * np)1224 static inline int of_get_child_count(const struct device_node *np)
1225 {
1226 struct device_node *child;
1227 int num = 0;
1228
1229 for_each_child_of_node(np, child)
1230 num++;
1231
1232 return num;
1233 }
1234
of_get_available_child_count(const struct device_node * np)1235 static inline int of_get_available_child_count(const struct device_node *np)
1236 {
1237 struct device_node *child;
1238 int num = 0;
1239
1240 for_each_available_child_of_node(np, child)
1241 num++;
1242
1243 return num;
1244 }
1245
1246 #if defined(CONFIG_OF) && !defined(MODULE)
1247 #define _OF_DECLARE(table, name, compat, fn, fn_type) \
1248 static const struct of_device_id __of_table_##name \
1249 __used __section(__##table##_of_table) \
1250 = { .compatible = compat, \
1251 .data = (fn == (fn_type)NULL) ? fn : fn }
1252 #else
1253 #define _OF_DECLARE(table, name, compat, fn, fn_type) \
1254 static const struct of_device_id __of_table_##name \
1255 __attribute__((unused)) \
1256 = { .compatible = compat, \
1257 .data = (fn == (fn_type)NULL) ? fn : fn }
1258 #endif
1259
1260 typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
1261 typedef int (*of_init_fn_1_ret)(struct device_node *);
1262 typedef void (*of_init_fn_1)(struct device_node *);
1263
1264 #define OF_DECLARE_1(table, name, compat, fn) \
1265 _OF_DECLARE(table, name, compat, fn, of_init_fn_1)
1266 #define OF_DECLARE_1_RET(table, name, compat, fn) \
1267 _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
1268 #define OF_DECLARE_2(table, name, compat, fn) \
1269 _OF_DECLARE(table, name, compat, fn, of_init_fn_2)
1270
1271 /**
1272 * struct of_changeset_entry - Holds a changeset entry
1273 *
1274 * @node: list_head for the log list
1275 * @action: notifier action
1276 * @np: pointer to the device node affected
1277 * @prop: pointer to the property affected
1278 * @old_prop: hold a pointer to the original property
1279 *
1280 * Every modification of the device tree during a changeset
1281 * is held in a list of of_changeset_entry structures.
1282 * That way we can recover from a partial application, or we can
1283 * revert the changeset
1284 */
1285 struct of_changeset_entry {
1286 struct list_head node;
1287 unsigned long action;
1288 struct device_node *np;
1289 struct property *prop;
1290 struct property *old_prop;
1291 };
1292
1293 /**
1294 * struct of_changeset - changeset tracker structure
1295 *
1296 * @entries: list_head for the changeset entries
1297 *
1298 * changesets are a convenient way to apply bulk changes to the
1299 * live tree. In case of an error, changes are rolled-back.
1300 * changesets live on after initial application, and if not
1301 * destroyed after use, they can be reverted in one single call.
1302 */
1303 struct of_changeset {
1304 struct list_head entries;
1305 };
1306
1307 enum of_reconfig_change {
1308 OF_RECONFIG_NO_CHANGE = 0,
1309 OF_RECONFIG_CHANGE_ADD,
1310 OF_RECONFIG_CHANGE_REMOVE,
1311 };
1312
1313 #ifdef CONFIG_OF_DYNAMIC
1314 extern int of_reconfig_notifier_register(struct notifier_block *);
1315 extern int of_reconfig_notifier_unregister(struct notifier_block *);
1316 extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
1317 extern int of_reconfig_get_state_change(unsigned long action,
1318 struct of_reconfig_data *arg);
1319
1320 extern void of_changeset_init(struct of_changeset *ocs);
1321 extern void of_changeset_destroy(struct of_changeset *ocs);
1322 extern int of_changeset_apply(struct of_changeset *ocs);
1323 extern int of_changeset_revert(struct of_changeset *ocs);
1324 extern int of_changeset_action(struct of_changeset *ocs,
1325 unsigned long action, struct device_node *np,
1326 struct property *prop);
1327
of_changeset_attach_node(struct of_changeset * ocs,struct device_node * np)1328 static inline int of_changeset_attach_node(struct of_changeset *ocs,
1329 struct device_node *np)
1330 {
1331 return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
1332 }
1333
of_changeset_detach_node(struct of_changeset * ocs,struct device_node * np)1334 static inline int of_changeset_detach_node(struct of_changeset *ocs,
1335 struct device_node *np)
1336 {
1337 return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
1338 }
1339
of_changeset_add_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1340 static inline int of_changeset_add_property(struct of_changeset *ocs,
1341 struct device_node *np, struct property *prop)
1342 {
1343 return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
1344 }
1345
of_changeset_remove_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1346 static inline int of_changeset_remove_property(struct of_changeset *ocs,
1347 struct device_node *np, struct property *prop)
1348 {
1349 return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
1350 }
1351
of_changeset_update_property(struct of_changeset * ocs,struct device_node * np,struct property * prop)1352 static inline int of_changeset_update_property(struct of_changeset *ocs,
1353 struct device_node *np, struct property *prop)
1354 {
1355 return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
1356 }
1357 #else /* CONFIG_OF_DYNAMIC */
of_reconfig_notifier_register(struct notifier_block * nb)1358 static inline int of_reconfig_notifier_register(struct notifier_block *nb)
1359 {
1360 return -EINVAL;
1361 }
of_reconfig_notifier_unregister(struct notifier_block * nb)1362 static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
1363 {
1364 return -EINVAL;
1365 }
of_reconfig_notify(unsigned long action,struct of_reconfig_data * arg)1366 static inline int of_reconfig_notify(unsigned long action,
1367 struct of_reconfig_data *arg)
1368 {
1369 return -EINVAL;
1370 }
of_reconfig_get_state_change(unsigned long action,struct of_reconfig_data * arg)1371 static inline int of_reconfig_get_state_change(unsigned long action,
1372 struct of_reconfig_data *arg)
1373 {
1374 return -EINVAL;
1375 }
1376 #endif /* CONFIG_OF_DYNAMIC */
1377
1378 /**
1379 * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
1380 * @np: Pointer to the given device_node
1381 *
1382 * return true if present false otherwise
1383 */
of_device_is_system_power_controller(const struct device_node * np)1384 static inline bool of_device_is_system_power_controller(const struct device_node *np)
1385 {
1386 return of_property_read_bool(np, "system-power-controller");
1387 }
1388
1389 /**
1390 * Overlay support
1391 */
1392
1393 enum of_overlay_notify_action {
1394 OF_OVERLAY_PRE_APPLY = 0,
1395 OF_OVERLAY_POST_APPLY,
1396 OF_OVERLAY_PRE_REMOVE,
1397 OF_OVERLAY_POST_REMOVE,
1398 };
1399
1400 struct of_overlay_notify_data {
1401 struct device_node *overlay;
1402 struct device_node *target;
1403 };
1404
1405 #ifdef CONFIG_OF_OVERLAY
1406
1407 int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
1408 int *ovcs_id);
1409 int of_overlay_remove(int *ovcs_id);
1410 int of_overlay_remove_all(void);
1411
1412 int of_overlay_notifier_register(struct notifier_block *nb);
1413 int of_overlay_notifier_unregister(struct notifier_block *nb);
1414
1415 #else
1416
of_overlay_fdt_apply(void * overlay_fdt,int * ovcs_id)1417 static inline int of_overlay_fdt_apply(void *overlay_fdt, int *ovcs_id)
1418 {
1419 return -ENOTSUPP;
1420 }
1421
of_overlay_remove(int * ovcs_id)1422 static inline int of_overlay_remove(int *ovcs_id)
1423 {
1424 return -ENOTSUPP;
1425 }
1426
of_overlay_remove_all(void)1427 static inline int of_overlay_remove_all(void)
1428 {
1429 return -ENOTSUPP;
1430 }
1431
of_overlay_notifier_register(struct notifier_block * nb)1432 static inline int of_overlay_notifier_register(struct notifier_block *nb)
1433 {
1434 return 0;
1435 }
1436
of_overlay_notifier_unregister(struct notifier_block * nb)1437 static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
1438 {
1439 return 0;
1440 }
1441
1442 #endif
1443
1444 #endif /* _LINUX_OF_H */
1445