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