Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / include / linux / of.h
blob086a60f3b8a6da1452f27757361af91d6c5c8bbd
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 #ifndef _LINUX_OF_H
3 #define _LINUX_OF_H
4 /*
5 * Definitions for talking to the Open Firmware PROM on
6 * Power Macintosh and other computers.
8 * Copyright (C) 1996-2005 Paul Mackerras.
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.
14 #include <linux/types.h>
15 #include <linux/bitops.h>
16 #include <linux/cleanup.h>
17 #include <linux/errno.h>
18 #include <linux/kobject.h>
19 #include <linux/mod_devicetable.h>
20 #include <linux/property.h>
21 #include <linux/list.h>
23 #include <asm/byteorder.h>
25 typedef u32 phandle;
26 typedef u32 ihandle;
28 struct property {
29 char *name;
30 int length;
31 void *value;
32 struct property *next;
33 #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
34 unsigned long _flags;
35 #endif
36 #if defined(CONFIG_OF_PROMTREE)
37 unsigned int unique_id;
38 #endif
39 #if defined(CONFIG_OF_KOBJ)
40 struct bin_attribute attr;
41 #endif
44 #if defined(CONFIG_SPARC)
45 struct of_irq_controller;
46 #endif
48 struct device_node {
49 const char *name;
50 phandle phandle;
51 const char *full_name;
52 struct fwnode_handle fwnode;
54 struct property *properties;
55 struct property *deadprops; /* removed properties */
56 struct device_node *parent;
57 struct device_node *child;
58 struct device_node *sibling;
59 #if defined(CONFIG_OF_KOBJ)
60 struct kobject kobj;
61 #endif
62 unsigned long _flags;
63 void *data;
64 #if defined(CONFIG_SPARC)
65 unsigned int unique_id;
66 struct of_irq_controller *irq_trans;
67 #endif
70 #define MAX_PHANDLE_ARGS 16
71 struct of_phandle_args {
72 struct device_node *np;
73 int args_count;
74 uint32_t args[MAX_PHANDLE_ARGS];
77 struct of_phandle_iterator {
78 /* Common iterator information */
79 const char *cells_name;
80 int cell_count;
81 const struct device_node *parent;
83 /* List size information */
84 const __be32 *list_end;
85 const __be32 *phandle_end;
87 /* Current position state */
88 const __be32 *cur;
89 uint32_t cur_count;
90 phandle phandle;
91 struct device_node *node;
94 struct of_reconfig_data {
95 struct device_node *dn;
96 struct property *prop;
97 struct property *old_prop;
100 extern const struct kobj_type of_node_ktype;
101 extern const struct fwnode_operations of_fwnode_ops;
104 * of_node_init - initialize a devicetree node
105 * @node: Pointer to device node that has been created by kzalloc()
107 * On return the device_node refcount is set to one. Use of_node_put()
108 * on @node when done to free the memory allocated for it. If the node
109 * is NOT a dynamic node the memory will not be freed. The decision of
110 * whether to free the memory will be done by node->release(), which is
111 * of_node_release().
113 static inline void of_node_init(struct device_node *node)
115 #if defined(CONFIG_OF_KOBJ)
116 kobject_init(&node->kobj, &of_node_ktype);
117 #endif
118 fwnode_init(&node->fwnode, &of_fwnode_ops);
121 #if defined(CONFIG_OF_KOBJ)
122 #define of_node_kobj(n) (&(n)->kobj)
123 #else
124 #define of_node_kobj(n) NULL
125 #endif
127 #ifdef CONFIG_OF_DYNAMIC
128 extern struct device_node *of_node_get(struct device_node *node);
129 extern void of_node_put(struct device_node *node);
130 #else /* CONFIG_OF_DYNAMIC */
131 /* Dummy ref counting routines - to be implemented later */
132 static inline struct device_node *of_node_get(struct device_node *node)
134 return node;
136 static inline void of_node_put(struct device_node *node) { }
137 #endif /* !CONFIG_OF_DYNAMIC */
138 DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))
140 /* Pointer for first entry in chain of all nodes. */
141 extern struct device_node *of_root;
142 extern struct device_node *of_chosen;
143 extern struct device_node *of_aliases;
144 extern struct device_node *of_stdout;
147 * struct device_node flag descriptions
148 * (need to be visible even when !CONFIG_OF)
150 #define OF_DYNAMIC 1 /* (and properties) allocated via kmalloc */
151 #define OF_DETACHED 2 /* detached from the device tree */
152 #define OF_POPULATED 3 /* device already created */
153 #define OF_POPULATED_BUS 4 /* platform bus created for children */
154 #define OF_OVERLAY 5 /* allocated for an overlay */
155 #define OF_OVERLAY_FREE_CSET 6 /* in overlay cset being freed */
157 #define OF_BAD_ADDR ((u64)-1)
159 #ifdef CONFIG_OF
160 void of_core_init(void);
162 static inline bool is_of_node(const struct fwnode_handle *fwnode)
164 return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops;
167 #define to_of_node(__fwnode) \
168 ({ \
169 typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
171 is_of_node(__to_of_node_fwnode) ? \
172 container_of(__to_of_node_fwnode, \
173 struct device_node, fwnode) : \
174 NULL; \
177 #define of_fwnode_handle(node) \
178 ({ \
179 typeof(node) __of_fwnode_handle_node = (node); \
181 __of_fwnode_handle_node ? \
182 &__of_fwnode_handle_node->fwnode : NULL; \
185 static inline bool of_node_is_root(const struct device_node *node)
187 return node && (node->parent == NULL);
190 static inline int of_node_check_flag(const struct device_node *n, unsigned long flag)
192 return test_bit(flag, &n->_flags);
195 static inline int of_node_test_and_set_flag(struct device_node *n,
196 unsigned long flag)
198 return test_and_set_bit(flag, &n->_flags);
201 static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
203 set_bit(flag, &n->_flags);
206 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
208 clear_bit(flag, &n->_flags);
211 #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
212 static inline int of_property_check_flag(const struct property *p, unsigned long flag)
214 return test_bit(flag, &p->_flags);
217 static inline void of_property_set_flag(struct property *p, unsigned long flag)
219 set_bit(flag, &p->_flags);
222 static inline void of_property_clear_flag(struct property *p, unsigned long flag)
224 clear_bit(flag, &p->_flags);
226 #endif
228 extern struct device_node *__of_find_all_nodes(struct device_node *prev);
229 extern struct device_node *of_find_all_nodes(struct device_node *prev);
232 * OF address retrieval & translation
235 /* Helper to read a big number; size is in cells (not bytes) */
236 static inline u64 of_read_number(const __be32 *cell, int size)
238 u64 r = 0;
239 for (; size--; cell++)
240 r = (r << 32) | be32_to_cpu(*cell);
241 return r;
244 /* Like of_read_number, but we want an unsigned long result */
245 static inline unsigned long of_read_ulong(const __be32 *cell, int size)
247 /* toss away upper bits if unsigned long is smaller than u64 */
248 return of_read_number(cell, size);
251 #if defined(CONFIG_SPARC)
252 #include <asm/prom.h>
253 #endif
255 #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
256 #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
258 extern bool of_node_name_eq(const struct device_node *np, const char *name);
259 extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);
261 static inline const char *of_node_full_name(const struct device_node *np)
263 return np ? np->full_name : "<no-node>";
266 #define for_each_of_allnodes_from(from, dn) \
267 for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn))
268 #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
269 extern struct device_node *of_find_node_by_name(struct device_node *from,
270 const char *name);
271 extern struct device_node *of_find_node_by_type(struct device_node *from,
272 const char *type);
273 extern struct device_node *of_find_compatible_node(struct device_node *from,
274 const char *type, const char *compat);
275 extern struct device_node *of_find_matching_node_and_match(
276 struct device_node *from,
277 const struct of_device_id *matches,
278 const struct of_device_id **match);
280 extern struct device_node *of_find_node_opts_by_path(const char *path,
281 const char **opts);
282 static inline struct device_node *of_find_node_by_path(const char *path)
284 return of_find_node_opts_by_path(path, NULL);
287 extern struct device_node *of_find_node_by_phandle(phandle handle);
288 extern struct device_node *of_get_parent(const struct device_node *node);
289 extern struct device_node *of_get_next_parent(struct device_node *node);
290 extern struct device_node *of_get_next_child(const struct device_node *node,
291 struct device_node *prev);
292 extern struct device_node *of_get_next_available_child(
293 const struct device_node *node, struct device_node *prev);
294 extern struct device_node *of_get_next_reserved_child(
295 const struct device_node *node, struct device_node *prev);
297 extern struct device_node *of_get_compatible_child(const struct device_node *parent,
298 const char *compatible);
299 extern struct device_node *of_get_child_by_name(const struct device_node *node,
300 const char *name);
302 /* cache lookup */
303 extern struct device_node *of_find_next_cache_node(const struct device_node *);
304 extern int of_find_last_cache_level(unsigned int cpu);
305 extern struct device_node *of_find_node_with_property(
306 struct device_node *from, const char *prop_name);
308 extern struct property *of_find_property(const struct device_node *np,
309 const char *name,
310 int *lenp);
311 extern int of_property_count_elems_of_size(const struct device_node *np,
312 const char *propname, int elem_size);
313 extern int of_property_read_u32_index(const struct device_node *np,
314 const char *propname,
315 u32 index, u32 *out_value);
316 extern int of_property_read_u64_index(const struct device_node *np,
317 const char *propname,
318 u32 index, u64 *out_value);
319 extern int of_property_read_variable_u8_array(const struct device_node *np,
320 const char *propname, u8 *out_values,
321 size_t sz_min, size_t sz_max);
322 extern int of_property_read_variable_u16_array(const struct device_node *np,
323 const char *propname, u16 *out_values,
324 size_t sz_min, size_t sz_max);
325 extern int of_property_read_variable_u32_array(const struct device_node *np,
326 const char *propname,
327 u32 *out_values,
328 size_t sz_min,
329 size_t sz_max);
330 extern int of_property_read_u64(const struct device_node *np,
331 const char *propname, u64 *out_value);
332 extern int of_property_read_variable_u64_array(const struct device_node *np,
333 const char *propname,
334 u64 *out_values,
335 size_t sz_min,
336 size_t sz_max);
338 extern int of_property_read_string(const struct device_node *np,
339 const char *propname,
340 const char **out_string);
341 extern int of_property_match_string(const struct device_node *np,
342 const char *propname,
343 const char *string);
344 extern int of_property_read_string_helper(const struct device_node *np,
345 const char *propname,
346 const char **out_strs, size_t sz, int index);
347 extern int of_device_is_compatible(const struct device_node *device,
348 const char *);
349 extern int of_device_compatible_match(const struct device_node *device,
350 const char *const *compat);
351 extern bool of_device_is_available(const struct device_node *device);
352 extern bool of_device_is_big_endian(const struct device_node *device);
353 extern const void *of_get_property(const struct device_node *node,
354 const char *name,
355 int *lenp);
356 extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
357 extern struct device_node *of_cpu_device_node_get(int cpu);
358 extern int of_cpu_node_to_id(struct device_node *np);
359 extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
360 extern struct device_node *of_get_cpu_state_node(const struct device_node *cpu_node,
361 int index);
362 extern u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread);
364 extern int of_n_addr_cells(struct device_node *np);
365 extern int of_n_size_cells(struct device_node *np);
366 extern const struct of_device_id *of_match_node(
367 const struct of_device_id *matches, const struct device_node *node);
368 extern const void *of_device_get_match_data(const struct device *dev);
369 extern int of_alias_from_compatible(const struct device_node *node, char *alias,
370 int len);
371 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
372 extern int __of_parse_phandle_with_args(const struct device_node *np,
373 const char *list_name, const char *cells_name, int cell_count,
374 int index, struct of_phandle_args *out_args);
375 extern int of_parse_phandle_with_args_map(const struct device_node *np,
376 const char *list_name, const char *stem_name, int index,
377 struct of_phandle_args *out_args);
378 extern int of_count_phandle_with_args(const struct device_node *np,
379 const char *list_name, const char *cells_name);
381 /* module functions */
382 extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len);
383 extern int of_request_module(const struct device_node *np);
385 /* phandle iterator functions */
386 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
387 const struct device_node *np,
388 const char *list_name,
389 const char *cells_name,
390 int cell_count);
392 extern int of_phandle_iterator_next(struct of_phandle_iterator *it);
393 extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
394 uint32_t *args,
395 int size);
397 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
398 extern int of_alias_get_id(const struct device_node *np, const char *stem);
399 extern int of_alias_get_highest_id(const char *stem);
401 bool of_machine_compatible_match(const char *const *compats);
404 * of_machine_is_compatible - Test root of device tree for a given compatible value
405 * @compat: compatible string to look for in root node's compatible property.
407 * Return: true if the root node has the given value in its compatible property.
409 static inline bool of_machine_is_compatible(const char *compat)
411 const char *compats[] = { compat, NULL };
413 return of_machine_compatible_match(compats);
416 extern int of_add_property(struct device_node *np, struct property *prop);
417 extern int of_remove_property(struct device_node *np, struct property *prop);
418 extern int of_update_property(struct device_node *np, struct property *newprop);
420 /* For updating the device tree at runtime */
421 #define OF_RECONFIG_ATTACH_NODE 0x0001
422 #define OF_RECONFIG_DETACH_NODE 0x0002
423 #define OF_RECONFIG_ADD_PROPERTY 0x0003
424 #define OF_RECONFIG_REMOVE_PROPERTY 0x0004
425 #define OF_RECONFIG_UPDATE_PROPERTY 0x0005
427 extern int of_attach_node(struct device_node *);
428 extern int of_detach_node(struct device_node *);
430 #define of_match_ptr(_ptr) (_ptr)
433 * u32 u;
435 * of_property_for_each_u32(np, "propname", u)
436 * printk("U32 value: %x\n", u);
438 const __be32 *of_prop_next_u32(const struct property *prop, const __be32 *cur,
439 u32 *pu);
441 * struct property *prop;
442 * const char *s;
444 * of_property_for_each_string(np, "propname", prop, s)
445 * printk("String value: %s\n", s);
447 const char *of_prop_next_string(const struct property *prop, const char *cur);
449 bool of_console_check(const struct device_node *dn, char *name, int index);
451 int of_map_id(const struct device_node *np, u32 id,
452 const char *map_name, const char *map_mask_name,
453 struct device_node **target, u32 *id_out);
455 phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
457 struct kimage;
458 void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
459 unsigned long initrd_load_addr,
460 unsigned long initrd_len,
461 const char *cmdline, size_t extra_fdt_size);
462 #else /* CONFIG_OF */
464 static inline void of_core_init(void)
468 static inline bool is_of_node(const struct fwnode_handle *fwnode)
470 return false;
473 static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
475 return NULL;
478 static inline bool of_node_name_eq(const struct device_node *np, const char *name)
480 return false;
483 static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
485 return false;
488 static inline const char* of_node_full_name(const struct device_node *np)
490 return "<no-node>";
493 static inline struct device_node *of_find_node_by_name(struct device_node *from,
494 const char *name)
496 return NULL;
499 static inline struct device_node *of_find_node_by_type(struct device_node *from,
500 const char *type)
502 return NULL;
505 static inline struct device_node *of_find_matching_node_and_match(
506 struct device_node *from,
507 const struct of_device_id *matches,
508 const struct of_device_id **match)
510 return NULL;
513 static inline struct device_node *of_find_node_by_path(const char *path)
515 return NULL;
518 static inline struct device_node *of_find_node_opts_by_path(const char *path,
519 const char **opts)
521 return NULL;
524 static inline struct device_node *of_find_node_by_phandle(phandle handle)
526 return NULL;
529 static inline struct device_node *of_get_parent(const struct device_node *node)
531 return NULL;
534 static inline struct device_node *of_get_next_parent(struct device_node *node)
536 return NULL;
539 static inline struct device_node *of_get_next_child(
540 const struct device_node *node, struct device_node *prev)
542 return NULL;
545 static inline struct device_node *of_get_next_available_child(
546 const struct device_node *node, struct device_node *prev)
548 return NULL;
551 static inline struct device_node *of_get_next_reserved_child(
552 const struct device_node *node, struct device_node *prev)
554 return NULL;
557 static inline struct device_node *of_find_node_with_property(
558 struct device_node *from, const char *prop_name)
560 return NULL;
563 #define of_fwnode_handle(node) NULL
565 static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
566 const char *compatible)
568 return NULL;
571 static inline struct device_node *of_get_child_by_name(
572 const struct device_node *node,
573 const char *name)
575 return NULL;
578 static inline int of_device_is_compatible(const struct device_node *device,
579 const char *name)
581 return 0;
584 static inline int of_device_compatible_match(const struct device_node *device,
585 const char *const *compat)
587 return 0;
590 static inline bool of_device_is_available(const struct device_node *device)
592 return false;
595 static inline bool of_device_is_big_endian(const struct device_node *device)
597 return false;
600 static inline struct property *of_find_property(const struct device_node *np,
601 const char *name,
602 int *lenp)
604 return NULL;
607 static inline struct device_node *of_find_compatible_node(
608 struct device_node *from,
609 const char *type,
610 const char *compat)
612 return NULL;
615 static inline int of_property_count_elems_of_size(const struct device_node *np,
616 const char *propname, int elem_size)
618 return -ENOSYS;
621 static inline int of_property_read_u32_index(const struct device_node *np,
622 const char *propname, u32 index, u32 *out_value)
624 return -ENOSYS;
627 static inline int of_property_read_u64_index(const struct device_node *np,
628 const char *propname, u32 index, u64 *out_value)
630 return -ENOSYS;
633 static inline const void *of_get_property(const struct device_node *node,
634 const char *name,
635 int *lenp)
637 return NULL;
640 static inline struct device_node *of_get_cpu_node(int cpu,
641 unsigned int *thread)
643 return NULL;
646 static inline struct device_node *of_cpu_device_node_get(int cpu)
648 return NULL;
651 static inline int of_cpu_node_to_id(struct device_node *np)
653 return -ENODEV;
656 static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
658 return NULL;
661 static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
662 int index)
664 return NULL;
667 static inline int of_n_addr_cells(struct device_node *np)
669 return 0;
672 static inline int of_n_size_cells(struct device_node *np)
674 return 0;
677 static inline int of_property_read_variable_u8_array(const struct device_node *np,
678 const char *propname, u8 *out_values,
679 size_t sz_min, size_t sz_max)
681 return -ENOSYS;
684 static inline int of_property_read_variable_u16_array(const struct device_node *np,
685 const char *propname, u16 *out_values,
686 size_t sz_min, size_t sz_max)
688 return -ENOSYS;
691 static inline int of_property_read_variable_u32_array(const struct device_node *np,
692 const char *propname,
693 u32 *out_values,
694 size_t sz_min,
695 size_t sz_max)
697 return -ENOSYS;
700 static inline int of_property_read_u64(const struct device_node *np,
701 const char *propname, u64 *out_value)
703 return -ENOSYS;
706 static inline int of_property_read_variable_u64_array(const struct device_node *np,
707 const char *propname,
708 u64 *out_values,
709 size_t sz_min,
710 size_t sz_max)
712 return -ENOSYS;
715 static inline int of_property_read_string(const struct device_node *np,
716 const char *propname,
717 const char **out_string)
719 return -ENOSYS;
722 static inline int of_property_match_string(const struct device_node *np,
723 const char *propname,
724 const char *string)
726 return -ENOSYS;
729 static inline int of_property_read_string_helper(const struct device_node *np,
730 const char *propname,
731 const char **out_strs, size_t sz, int index)
733 return -ENOSYS;
736 static inline int __of_parse_phandle_with_args(const struct device_node *np,
737 const char *list_name,
738 const char *cells_name,
739 int cell_count,
740 int index,
741 struct of_phandle_args *out_args)
743 return -ENOSYS;
746 static inline int of_parse_phandle_with_args_map(const struct device_node *np,
747 const char *list_name,
748 const char *stem_name,
749 int index,
750 struct of_phandle_args *out_args)
752 return -ENOSYS;
755 static inline int of_count_phandle_with_args(const struct device_node *np,
756 const char *list_name,
757 const char *cells_name)
759 return -ENOSYS;
762 static inline ssize_t of_modalias(const struct device_node *np, char *str,
763 ssize_t len)
765 return -ENODEV;
768 static inline int of_request_module(const struct device_node *np)
770 return -ENODEV;
773 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
774 const struct device_node *np,
775 const char *list_name,
776 const char *cells_name,
777 int cell_count)
779 return -ENOSYS;
782 static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
784 return -ENOSYS;
787 static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
788 uint32_t *args,
789 int size)
791 return 0;
794 static inline int of_alias_get_id(struct device_node *np, const char *stem)
796 return -ENOSYS;
799 static inline int of_alias_get_highest_id(const char *stem)
801 return -ENOSYS;
804 static inline int of_machine_is_compatible(const char *compat)
806 return 0;
809 static inline int of_add_property(struct device_node *np, struct property *prop)
811 return 0;
814 static inline int of_remove_property(struct device_node *np, struct property *prop)
816 return 0;
819 static inline bool of_machine_compatible_match(const char *const *compats)
821 return false;
824 static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
826 return false;
829 static inline const __be32 *of_prop_next_u32(const struct property *prop,
830 const __be32 *cur, u32 *pu)
832 return NULL;
835 static inline const char *of_prop_next_string(const struct property *prop,
836 const char *cur)
838 return NULL;
841 static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
843 return 0;
846 static inline int of_node_test_and_set_flag(struct device_node *n,
847 unsigned long flag)
849 return 0;
852 static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
856 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
860 static inline int of_property_check_flag(const struct property *p,
861 unsigned long flag)
863 return 0;
866 static inline void of_property_set_flag(struct property *p, unsigned long flag)
870 static inline void of_property_clear_flag(struct property *p, unsigned long flag)
874 static inline int of_map_id(const struct device_node *np, u32 id,
875 const char *map_name, const char *map_mask_name,
876 struct device_node **target, u32 *id_out)
878 return -EINVAL;
881 static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np)
883 return PHYS_ADDR_MAX;
886 static inline const void *of_device_get_match_data(const struct device *dev)
888 return NULL;
891 #define of_match_ptr(_ptr) NULL
892 #define of_match_node(_matches, _node) NULL
893 #endif /* CONFIG_OF */
895 /* Default string compare functions, Allow arch asm/prom.h to override */
896 #if !defined(of_compat_cmp)
897 #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
898 #define of_prop_cmp(s1, s2) strcmp((s1), (s2))
899 #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
900 #endif
902 static inline int of_prop_val_eq(const struct property *p1, const struct property *p2)
904 return p1->length == p2->length &&
905 !memcmp(p1->value, p2->value, (size_t)p1->length);
908 #define for_each_property_of_node(dn, pp) \
909 for (pp = dn->properties; pp != NULL; pp = pp->next)
911 #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
912 extern int of_node_to_nid(struct device_node *np);
913 #else
914 static inline int of_node_to_nid(struct device_node *device)
916 return NUMA_NO_NODE;
918 #endif
920 #ifdef CONFIG_OF_NUMA
921 extern int of_numa_init(void);
922 #else
923 static inline int of_numa_init(void)
925 return -ENOSYS;
927 #endif
929 static inline struct device_node *of_find_matching_node(
930 struct device_node *from,
931 const struct of_device_id *matches)
933 return of_find_matching_node_and_match(from, matches, NULL);
936 static inline const char *of_node_get_device_type(const struct device_node *np)
938 return of_get_property(np, "device_type", NULL);
941 static inline bool of_node_is_type(const struct device_node *np, const char *type)
943 const char *match = of_node_get_device_type(np);
945 return np && match && type && !strcmp(match, type);
949 * of_parse_phandle - Resolve a phandle property to a device_node pointer
950 * @np: Pointer to device node holding phandle property
951 * @phandle_name: Name of property holding a phandle value
952 * @index: For properties holding a table of phandles, this is the index into
953 * the table
955 * Return: The device_node pointer with refcount incremented. Use
956 * of_node_put() on it when done.
958 static inline struct device_node *of_parse_phandle(const struct device_node *np,
959 const char *phandle_name,
960 int index)
962 struct of_phandle_args args;
964 if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
965 index, &args))
966 return NULL;
968 return args.np;
972 * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
973 * @np: pointer to a device tree node containing a list
974 * @list_name: property name that contains a list
975 * @cells_name: property name that specifies phandles' arguments count
976 * @index: index of a phandle to parse out
977 * @out_args: optional pointer to output arguments structure (will be filled)
979 * This function is useful to parse lists of phandles and their arguments.
980 * Returns 0 on success and fills out_args, on error returns appropriate
981 * errno value.
983 * Caller is responsible to call of_node_put() on the returned out_args->np
984 * pointer.
986 * Example::
988 * phandle1: node1 {
989 * #list-cells = <2>;
990 * };
992 * phandle2: node2 {
993 * #list-cells = <1>;
994 * };
996 * node3 {
997 * list = <&phandle1 1 2 &phandle2 3>;
998 * };
1000 * To get a device_node of the ``node2`` node you may call this:
1001 * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
1003 static inline int of_parse_phandle_with_args(const struct device_node *np,
1004 const char *list_name,
1005 const char *cells_name,
1006 int index,
1007 struct of_phandle_args *out_args)
1009 int cell_count = -1;
1011 /* If cells_name is NULL we assume a cell count of 0 */
1012 if (!cells_name)
1013 cell_count = 0;
1015 return __of_parse_phandle_with_args(np, list_name, cells_name,
1016 cell_count, index, out_args);
1020 * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
1021 * @np: pointer to a device tree node containing a list
1022 * @list_name: property name that contains a list
1023 * @cell_count: number of argument cells following the phandle
1024 * @index: index of a phandle to parse out
1025 * @out_args: optional pointer to output arguments structure (will be filled)
1027 * This function is useful to parse lists of phandles and their arguments.
1028 * Returns 0 on success and fills out_args, on error returns appropriate
1029 * errno value.
1031 * Caller is responsible to call of_node_put() on the returned out_args->np
1032 * pointer.
1034 * Example::
1036 * phandle1: node1 {
1037 * };
1039 * phandle2: node2 {
1040 * };
1042 * node3 {
1043 * list = <&phandle1 0 2 &phandle2 2 3>;
1044 * };
1046 * To get a device_node of the ``node2`` node you may call this:
1047 * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
1049 static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
1050 const char *list_name,
1051 int cell_count,
1052 int index,
1053 struct of_phandle_args *out_args)
1055 return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
1056 index, out_args);
1060 * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list
1061 * @np: pointer to a device tree node containing a list
1062 * @list_name: property name that contains a list
1063 * @cells_name: property name that specifies phandles' arguments count
1064 * @index: index of a phandle to parse out
1065 * @out_args: optional pointer to output arguments structure (will be filled)
1067 * Same as of_parse_phandle_with_args() except that if the cells_name property
1068 * is not found, cell_count of 0 is assumed.
1070 * This is used to useful, if you have a phandle which didn't have arguments
1071 * before and thus doesn't have a '#*-cells' property but is now migrated to
1072 * having arguments while retaining backwards compatibility.
1074 static inline int of_parse_phandle_with_optional_args(const struct device_node *np,
1075 const char *list_name,
1076 const char *cells_name,
1077 int index,
1078 struct of_phandle_args *out_args)
1080 return __of_parse_phandle_with_args(np, list_name, cells_name,
1081 0, index, out_args);
1085 * of_phandle_args_equal() - Compare two of_phandle_args
1086 * @a1: First of_phandle_args to compare
1087 * @a2: Second of_phandle_args to compare
1089 * Return: True if a1 and a2 are the same (same node pointer, same phandle
1090 * args), false otherwise.
1092 static inline bool of_phandle_args_equal(const struct of_phandle_args *a1,
1093 const struct of_phandle_args *a2)
1095 return a1->np == a2->np &&
1096 a1->args_count == a2->args_count &&
1097 !memcmp(a1->args, a2->args, sizeof(a1->args[0]) * a1->args_count);
1101 * of_property_count_u8_elems - Count the number of u8 elements in a property
1103 * @np: device node from which the property value is to be read.
1104 * @propname: name of the property to be searched.
1106 * Search for a property in a device node and count the number of u8 elements
1107 * in it.
1109 * Return: The number of elements on sucess, -EINVAL if the property does
1110 * not exist or its length does not match a multiple of u8 and -ENODATA if the
1111 * property does not have a value.
1113 static inline int of_property_count_u8_elems(const struct device_node *np,
1114 const char *propname)
1116 return of_property_count_elems_of_size(np, propname, sizeof(u8));
1120 * of_property_count_u16_elems - Count the number of u16 elements in a property
1122 * @np: device node from which the property value is to be read.
1123 * @propname: name of the property to be searched.
1125 * Search for a property in a device node and count the number of u16 elements
1126 * in it.
1128 * Return: The number of elements on sucess, -EINVAL if the property does
1129 * not exist or its length does not match a multiple of u16 and -ENODATA if the
1130 * property does not have a value.
1132 static inline int of_property_count_u16_elems(const struct device_node *np,
1133 const char *propname)
1135 return of_property_count_elems_of_size(np, propname, sizeof(u16));
1139 * of_property_count_u32_elems - Count the number of u32 elements in a property
1141 * @np: device node from which the property value is to be read.
1142 * @propname: name of the property to be searched.
1144 * Search for a property in a device node and count the number of u32 elements
1145 * in it.
1147 * Return: The number of elements on sucess, -EINVAL if the property does
1148 * not exist or its length does not match a multiple of u32 and -ENODATA if the
1149 * property does not have a value.
1151 static inline int of_property_count_u32_elems(const struct device_node *np,
1152 const char *propname)
1154 return of_property_count_elems_of_size(np, propname, sizeof(u32));
1158 * of_property_count_u64_elems - Count the number of u64 elements in a property
1160 * @np: device node from which the property value is to be read.
1161 * @propname: name of the property to be searched.
1163 * Search for a property in a device node and count the number of u64 elements
1164 * in it.
1166 * Return: The number of elements on sucess, -EINVAL if the property does
1167 * not exist or its length does not match a multiple of u64 and -ENODATA if the
1168 * property does not have a value.
1170 static inline int of_property_count_u64_elems(const struct device_node *np,
1171 const char *propname)
1173 return of_property_count_elems_of_size(np, propname, sizeof(u64));
1177 * of_property_read_string_array() - Read an array of strings from a multiple
1178 * strings property.
1179 * @np: device node from which the property value is to be read.
1180 * @propname: name of the property to be searched.
1181 * @out_strs: output array of string pointers.
1182 * @sz: number of array elements to read.
1184 * Search for a property in a device tree node and retrieve a list of
1185 * terminated string values (pointer to data, not a copy) in that property.
1187 * Return: If @out_strs is NULL, the number of strings in the property is returned.
1189 static inline int of_property_read_string_array(const struct device_node *np,
1190 const char *propname, const char **out_strs,
1191 size_t sz)
1193 return of_property_read_string_helper(np, propname, out_strs, sz, 0);
1197 * of_property_count_strings() - Find and return the number of strings from a
1198 * multiple strings property.
1199 * @np: device node from which the property value is to be read.
1200 * @propname: name of the property to be searched.
1202 * Search for a property in a device tree node and retrieve the number of null
1203 * terminated string contain in it.
1205 * Return: The number of strings on success, -EINVAL if the property does not
1206 * exist, -ENODATA if property does not have a value, and -EILSEQ if the string
1207 * is not null-terminated within the length of the property data.
1209 static inline int of_property_count_strings(const struct device_node *np,
1210 const char *propname)
1212 return of_property_read_string_helper(np, propname, NULL, 0, 0);
1216 * of_property_read_string_index() - Find and read a string from a multiple
1217 * strings property.
1218 * @np: device node from which the property value is to be read.
1219 * @propname: name of the property to be searched.
1220 * @index: index of the string in the list of strings
1221 * @output: pointer to null terminated return string, modified only if
1222 * return value is 0.
1224 * Search for a property in a device tree node and retrieve a null
1225 * terminated string value (pointer to data, not a copy) in the list of strings
1226 * contained in that property.
1228 * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if
1229 * property does not have a value, and -EILSEQ if the string is not
1230 * null-terminated within the length of the property data.
1232 * The out_string pointer is modified only if a valid string can be decoded.
1234 static inline int of_property_read_string_index(const struct device_node *np,
1235 const char *propname,
1236 int index, const char **output)
1238 int rc = of_property_read_string_helper(np, propname, output, 1, index);
1239 return rc < 0 ? rc : 0;
1243 * of_property_read_bool - Find a property
1244 * @np: device node from which the property value is to be read.
1245 * @propname: name of the property to be searched.
1247 * Search for a boolean property in a device node. Usage on non-boolean
1248 * property types is deprecated.
1250 * Return: true if the property exists false otherwise.
1252 static inline bool of_property_read_bool(const struct device_node *np,
1253 const char *propname)
1255 const struct property *prop = of_find_property(np, propname, NULL);
1257 return prop ? true : false;
1261 * of_property_present - Test if a property is present in a node
1262 * @np: device node to search for the property.
1263 * @propname: name of the property to be searched.
1265 * Test for a property present in a device node.
1267 * Return: true if the property exists false otherwise.
1269 static inline bool of_property_present(const struct device_node *np, const char *propname)
1271 return of_property_read_bool(np, propname);
1275 * of_property_read_u8_array - Find and read an array of u8 from a property.
1277 * @np: device node from which the property value is to be read.
1278 * @propname: name of the property to be searched.
1279 * @out_values: pointer to return value, modified only if return value is 0.
1280 * @sz: number of array elements to read
1282 * Search for a property in a device node and read 8-bit value(s) from
1283 * it.
1285 * dts entry of array should be like:
1286 * ``property = /bits/ 8 <0x50 0x60 0x70>;``
1288 * Return: 0 on success, -EINVAL if the property does not exist,
1289 * -ENODATA if property does not have a value, and -EOVERFLOW if the
1290 * property data isn't large enough.
1292 * The out_values is modified only if a valid u8 value can be decoded.
1294 static inline int of_property_read_u8_array(const struct device_node *np,
1295 const char *propname,
1296 u8 *out_values, size_t sz)
1298 int ret = of_property_read_variable_u8_array(np, propname, out_values,
1299 sz, 0);
1300 if (ret >= 0)
1301 return 0;
1302 else
1303 return ret;
1307 * of_property_read_u16_array - Find and read an array of u16 from a property.
1309 * @np: device node from which the property value is to be read.
1310 * @propname: name of the property to be searched.
1311 * @out_values: pointer to return value, modified only if return value is 0.
1312 * @sz: number of array elements to read
1314 * Search for a property in a device node and read 16-bit value(s) from
1315 * it.
1317 * dts entry of array should be like:
1318 * ``property = /bits/ 16 <0x5000 0x6000 0x7000>;``
1320 * Return: 0 on success, -EINVAL if the property does not exist,
1321 * -ENODATA if property does not have a value, and -EOVERFLOW if the
1322 * property data isn't large enough.
1324 * The out_values is modified only if a valid u16 value can be decoded.
1326 static inline int of_property_read_u16_array(const struct device_node *np,
1327 const char *propname,
1328 u16 *out_values, size_t sz)
1330 int ret = of_property_read_variable_u16_array(np, propname, out_values,
1331 sz, 0);
1332 if (ret >= 0)
1333 return 0;
1334 else
1335 return ret;
1339 * of_property_read_u32_array - Find and read an array of 32 bit integers
1340 * from a property.
1342 * @np: device node from which the property value is to be read.
1343 * @propname: name of the property to be searched.
1344 * @out_values: pointer to return value, modified only if return value is 0.
1345 * @sz: number of array elements to read
1347 * Search for a property in a device node and read 32-bit value(s) from
1348 * it.
1350 * Return: 0 on success, -EINVAL if the property does not exist,
1351 * -ENODATA if property does not have a value, and -EOVERFLOW if the
1352 * property data isn't large enough.
1354 * The out_values is modified only if a valid u32 value can be decoded.
1356 static inline int of_property_read_u32_array(const struct device_node *np,
1357 const char *propname,
1358 u32 *out_values, size_t sz)
1360 int ret = of_property_read_variable_u32_array(np, propname, out_values,
1361 sz, 0);
1362 if (ret >= 0)
1363 return 0;
1364 else
1365 return ret;
1369 * of_property_read_u64_array - Find and read an array of 64 bit integers
1370 * from a property.
1372 * @np: device node from which the property value is to be read.
1373 * @propname: name of the property to be searched.
1374 * @out_values: pointer to return value, modified only if return value is 0.
1375 * @sz: number of array elements to read
1377 * Search for a property in a device node and read 64-bit value(s) from
1378 * it.
1380 * Return: 0 on success, -EINVAL if the property does not exist,
1381 * -ENODATA if property does not have a value, and -EOVERFLOW if the
1382 * property data isn't large enough.
1384 * The out_values is modified only if a valid u64 value can be decoded.
1386 static inline int of_property_read_u64_array(const struct device_node *np,
1387 const char *propname,
1388 u64 *out_values, size_t sz)
1390 int ret = of_property_read_variable_u64_array(np, propname, out_values,
1391 sz, 0);
1392 if (ret >= 0)
1393 return 0;
1394 else
1395 return ret;
1398 static inline int of_property_read_u8(const struct device_node *np,
1399 const char *propname,
1400 u8 *out_value)
1402 return of_property_read_u8_array(np, propname, out_value, 1);
1405 static inline int of_property_read_u16(const struct device_node *np,
1406 const char *propname,
1407 u16 *out_value)
1409 return of_property_read_u16_array(np, propname, out_value, 1);
1412 static inline int of_property_read_u32(const struct device_node *np,
1413 const char *propname,
1414 u32 *out_value)
1416 return of_property_read_u32_array(np, propname, out_value, 1);
1419 static inline int of_property_read_s32(const struct device_node *np,
1420 const char *propname,
1421 s32 *out_value)
1423 return of_property_read_u32(np, propname, (u32*) out_value);
1426 #define of_for_each_phandle(it, err, np, ln, cn, cc) \
1427 for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \
1428 err = of_phandle_iterator_next(it); \
1429 err == 0; \
1430 err = of_phandle_iterator_next(it))
1432 #define of_property_for_each_u32(np, propname, u) \
1433 for (struct {const struct property *prop; const __be32 *item; } _it = \
1434 {of_find_property(np, propname, NULL), \
1435 of_prop_next_u32(_it.prop, NULL, &u)}; \
1436 _it.item; \
1437 _it.item = of_prop_next_u32(_it.prop, _it.item, &u))
1439 #define of_property_for_each_string(np, propname, prop, s) \
1440 for (prop = of_find_property(np, propname, NULL), \
1441 s = of_prop_next_string(prop, NULL); \
1442 s; \
1443 s = of_prop_next_string(prop, s))
1445 #define for_each_node_by_name(dn, name) \
1446 for (dn = of_find_node_by_name(NULL, name); dn; \
1447 dn = of_find_node_by_name(dn, name))
1448 #define for_each_node_by_type(dn, type) \
1449 for (dn = of_find_node_by_type(NULL, type); dn; \
1450 dn = of_find_node_by_type(dn, type))
1451 #define for_each_compatible_node(dn, type, compatible) \
1452 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
1453 dn = of_find_compatible_node(dn, type, compatible))
1454 #define for_each_matching_node(dn, matches) \
1455 for (dn = of_find_matching_node(NULL, matches); dn; \
1456 dn = of_find_matching_node(dn, matches))
1457 #define for_each_matching_node_and_match(dn, matches, match) \
1458 for (dn = of_find_matching_node_and_match(NULL, matches, match); \
1459 dn; dn = of_find_matching_node_and_match(dn, matches, match))
1461 #define for_each_child_of_node(parent, child) \
1462 for (child = of_get_next_child(parent, NULL); child != NULL; \
1463 child = of_get_next_child(parent, child))
1465 #define for_each_child_of_node_scoped(parent, child) \
1466 for (struct device_node *child __free(device_node) = \
1467 of_get_next_child(parent, NULL); \
1468 child != NULL; \
1469 child = of_get_next_child(parent, child))
1471 #define for_each_available_child_of_node(parent, child) \
1472 for (child = of_get_next_available_child(parent, NULL); child != NULL; \
1473 child = of_get_next_available_child(parent, child))
1474 #define for_each_reserved_child_of_node(parent, child) \
1475 for (child = of_get_next_reserved_child(parent, NULL); child != NULL; \
1476 child = of_get_next_reserved_child(parent, child))
1478 #define for_each_available_child_of_node_scoped(parent, child) \
1479 for (struct device_node *child __free(device_node) = \
1480 of_get_next_available_child(parent, NULL); \
1481 child != NULL; \
1482 child = of_get_next_available_child(parent, child))
1484 #define for_each_of_cpu_node(cpu) \
1485 for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
1486 cpu = of_get_next_cpu_node(cpu))
1488 #define for_each_node_with_property(dn, prop_name) \
1489 for (dn = of_find_node_with_property(NULL, prop_name); dn; \
1490 dn = of_find_node_with_property(dn, prop_name))
1492 static inline int of_get_child_count(const struct device_node *np)
1494 struct device_node *child;
1495 int num = 0;
1497 for_each_child_of_node(np, child)
1498 num++;
1500 return num;
1503 static inline int of_get_available_child_count(const struct device_node *np)
1505 struct device_node *child;
1506 int num = 0;
1508 for_each_available_child_of_node(np, child)
1509 num++;
1511 return num;
1514 #define _OF_DECLARE_STUB(table, name, compat, fn, fn_type) \
1515 static const struct of_device_id __of_table_##name \
1516 __attribute__((unused)) \
1517 = { .compatible = compat, \
1518 .data = (fn == (fn_type)NULL) ? fn : fn }
1520 #if defined(CONFIG_OF) && !defined(MODULE)
1521 #define _OF_DECLARE(table, name, compat, fn, fn_type) \
1522 static const struct of_device_id __of_table_##name \
1523 __used __section("__" #table "_of_table") \
1524 __aligned(__alignof__(struct of_device_id)) \
1525 = { .compatible = compat, \
1526 .data = (fn == (fn_type)NULL) ? fn : fn }
1527 #else
1528 #define _OF_DECLARE(table, name, compat, fn, fn_type) \
1529 _OF_DECLARE_STUB(table, name, compat, fn, fn_type)
1530 #endif
1532 typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
1533 typedef int (*of_init_fn_1_ret)(struct device_node *);
1534 typedef void (*of_init_fn_1)(struct device_node *);
1536 #define OF_DECLARE_1(table, name, compat, fn) \
1537 _OF_DECLARE(table, name, compat, fn, of_init_fn_1)
1538 #define OF_DECLARE_1_RET(table, name, compat, fn) \
1539 _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
1540 #define OF_DECLARE_2(table, name, compat, fn) \
1541 _OF_DECLARE(table, name, compat, fn, of_init_fn_2)
1544 * struct of_changeset_entry - Holds a changeset entry
1546 * @node: list_head for the log list
1547 * @action: notifier action
1548 * @np: pointer to the device node affected
1549 * @prop: pointer to the property affected
1550 * @old_prop: hold a pointer to the original property
1552 * Every modification of the device tree during a changeset
1553 * is held in a list of of_changeset_entry structures.
1554 * That way we can recover from a partial application, or we can
1555 * revert the changeset
1557 struct of_changeset_entry {
1558 struct list_head node;
1559 unsigned long action;
1560 struct device_node *np;
1561 struct property *prop;
1562 struct property *old_prop;
1566 * struct of_changeset - changeset tracker structure
1568 * @entries: list_head for the changeset entries
1570 * changesets are a convenient way to apply bulk changes to the
1571 * live tree. In case of an error, changes are rolled-back.
1572 * changesets live on after initial application, and if not
1573 * destroyed after use, they can be reverted in one single call.
1575 struct of_changeset {
1576 struct list_head entries;
1579 enum of_reconfig_change {
1580 OF_RECONFIG_NO_CHANGE = 0,
1581 OF_RECONFIG_CHANGE_ADD,
1582 OF_RECONFIG_CHANGE_REMOVE,
1585 struct notifier_block;
1587 #ifdef CONFIG_OF_DYNAMIC
1588 extern int of_reconfig_notifier_register(struct notifier_block *);
1589 extern int of_reconfig_notifier_unregister(struct notifier_block *);
1590 extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
1591 extern int of_reconfig_get_state_change(unsigned long action,
1592 struct of_reconfig_data *arg);
1594 extern void of_changeset_init(struct of_changeset *ocs);
1595 extern void of_changeset_destroy(struct of_changeset *ocs);
1596 extern int of_changeset_apply(struct of_changeset *ocs);
1597 extern int of_changeset_revert(struct of_changeset *ocs);
1598 extern int of_changeset_action(struct of_changeset *ocs,
1599 unsigned long action, struct device_node *np,
1600 struct property *prop);
1602 static inline int of_changeset_attach_node(struct of_changeset *ocs,
1603 struct device_node *np)
1605 return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
1608 static inline int of_changeset_detach_node(struct of_changeset *ocs,
1609 struct device_node *np)
1611 return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
1614 static inline int of_changeset_add_property(struct of_changeset *ocs,
1615 struct device_node *np, struct property *prop)
1617 return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
1620 static inline int of_changeset_remove_property(struct of_changeset *ocs,
1621 struct device_node *np, struct property *prop)
1623 return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
1626 static inline int of_changeset_update_property(struct of_changeset *ocs,
1627 struct device_node *np, struct property *prop)
1629 return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
1632 struct device_node *of_changeset_create_node(struct of_changeset *ocs,
1633 struct device_node *parent,
1634 const char *full_name);
1635 int of_changeset_add_prop_string(struct of_changeset *ocs,
1636 struct device_node *np,
1637 const char *prop_name, const char *str);
1638 int of_changeset_add_prop_string_array(struct of_changeset *ocs,
1639 struct device_node *np,
1640 const char *prop_name,
1641 const char * const *str_array, size_t sz);
1642 int of_changeset_add_prop_u32_array(struct of_changeset *ocs,
1643 struct device_node *np,
1644 const char *prop_name,
1645 const u32 *array, size_t sz);
1646 static inline int of_changeset_add_prop_u32(struct of_changeset *ocs,
1647 struct device_node *np,
1648 const char *prop_name,
1649 const u32 val)
1651 return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1);
1654 int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np,
1655 const char *prop_name);
1657 #else /* CONFIG_OF_DYNAMIC */
1658 static inline int of_reconfig_notifier_register(struct notifier_block *nb)
1660 return -EINVAL;
1662 static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
1664 return -EINVAL;
1666 static inline int of_reconfig_notify(unsigned long action,
1667 struct of_reconfig_data *arg)
1669 return -EINVAL;
1671 static inline int of_reconfig_get_state_change(unsigned long action,
1672 struct of_reconfig_data *arg)
1674 return -EINVAL;
1676 #endif /* CONFIG_OF_DYNAMIC */
1679 * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
1680 * @np: Pointer to the given device_node
1682 * Return: true if present false otherwise
1684 static inline bool of_device_is_system_power_controller(const struct device_node *np)
1686 return of_property_read_bool(np, "system-power-controller");
1690 * of_have_populated_dt() - Has DT been populated by bootloader
1692 * Return: True if a DTB has been populated by the bootloader and it isn't the
1693 * empty builtin one. False otherwise.
1695 static inline bool of_have_populated_dt(void)
1697 #ifdef CONFIG_OF
1698 return of_property_present(of_root, "compatible");
1699 #else
1700 return false;
1701 #endif
1705 * Overlay support
1708 enum of_overlay_notify_action {
1709 OF_OVERLAY_INIT = 0, /* kzalloc() of ovcs sets this value */
1710 OF_OVERLAY_PRE_APPLY,
1711 OF_OVERLAY_POST_APPLY,
1712 OF_OVERLAY_PRE_REMOVE,
1713 OF_OVERLAY_POST_REMOVE,
1716 static inline const char *of_overlay_action_name(enum of_overlay_notify_action action)
1718 static const char *const of_overlay_action_name[] = {
1719 "init",
1720 "pre-apply",
1721 "post-apply",
1722 "pre-remove",
1723 "post-remove",
1726 return of_overlay_action_name[action];
1729 struct of_overlay_notify_data {
1730 struct device_node *overlay;
1731 struct device_node *target;
1734 #ifdef CONFIG_OF_OVERLAY
1736 int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
1737 int *ovcs_id, const struct device_node *target_base);
1738 int of_overlay_remove(int *ovcs_id);
1739 int of_overlay_remove_all(void);
1741 int of_overlay_notifier_register(struct notifier_block *nb);
1742 int of_overlay_notifier_unregister(struct notifier_block *nb);
1744 #else
1746 static inline int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
1747 int *ovcs_id, const struct device_node *target_base)
1749 return -ENOTSUPP;
1752 static inline int of_overlay_remove(int *ovcs_id)
1754 return -ENOTSUPP;
1757 static inline int of_overlay_remove_all(void)
1759 return -ENOTSUPP;
1762 static inline int of_overlay_notifier_register(struct notifier_block *nb)
1764 return 0;
1767 static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
1769 return 0;
1772 #endif
1774 #endif /* _LINUX_OF_H */