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