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