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