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