Commit | Line | Data |
---|---|---|
af6074fc | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
76c1ce78 SR |
2 | #ifndef _LINUX_OF_H |
3 | #define _LINUX_OF_H | |
4 | /* | |
5 | * Definitions for talking to the Open Firmware PROM on | |
6 | * Power Macintosh and other computers. | |
7 | * | |
8 | * Copyright (C) 1996-2005 Paul Mackerras. | |
9 | * | |
10 | * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp. | |
11 | * Updates for SPARC64 by David S. Miller | |
12 | * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp. | |
76c1ce78 SR |
13 | */ |
14 | #include <linux/types.h> | |
1977f032 | 15 | #include <linux/bitops.h> |
e51130c0 | 16 | #include <linux/errno.h> |
75b57ecf | 17 | #include <linux/kobject.h> |
283029d1 | 18 | #include <linux/mod_devicetable.h> |
b31384fa | 19 | #include <linux/property.h> |
7518b589 | 20 | #include <linux/list.h> |
76c1ce78 | 21 | |
2e89e685 JK |
22 | #include <asm/byteorder.h> |
23 | ||
731581e6 GL |
24 | typedef u32 phandle; |
25 | typedef u32 ihandle; | |
26 | ||
27 | struct property { | |
28 | char *name; | |
29 | int length; | |
30 | void *value; | |
31 | struct property *next; | |
16bba30e | 32 | #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC) |
731581e6 | 33 | unsigned long _flags; |
16bba30e | 34 | #endif |
36689ecd | 35 | #if defined(CONFIG_OF_PROMTREE) |
731581e6 | 36 | unsigned int unique_id; |
36689ecd | 37 | #endif |
b56b5528 | 38 | #if defined(CONFIG_OF_KOBJ) |
75b57ecf | 39 | struct bin_attribute attr; |
b56b5528 | 40 | #endif |
731581e6 GL |
41 | }; |
42 | ||
6f192492 GL |
43 | #if defined(CONFIG_SPARC) |
44 | struct of_irq_controller; | |
45 | #endif | |
46 | ||
47 | struct device_node { | |
48 | const char *name; | |
6016a363 | 49 | phandle phandle; |
c22618a1 | 50 | const char *full_name; |
8a0662d9 | 51 | struct fwnode_handle fwnode; |
6f192492 GL |
52 | |
53 | struct property *properties; | |
54 | struct property *deadprops; /* removed properties */ | |
55 | struct device_node *parent; | |
56 | struct device_node *child; | |
57 | struct device_node *sibling; | |
b56b5528 | 58 | #if defined(CONFIG_OF_KOBJ) |
75b57ecf | 59 | struct kobject kobj; |
b56b5528 | 60 | #endif |
6f192492 GL |
61 | unsigned long _flags; |
62 | void *data; | |
63 | #if defined(CONFIG_SPARC) | |
6f192492 GL |
64 | unsigned int unique_id; |
65 | struct of_irq_controller *irq_trans; | |
66 | #endif | |
67 | }; | |
68 | ||
b66548e2 | 69 | #define MAX_PHANDLE_ARGS 16 |
15c9a0ac GL |
70 | struct of_phandle_args { |
71 | struct device_node *np; | |
72 | int args_count; | |
73 | uint32_t args[MAX_PHANDLE_ARGS]; | |
74 | }; | |
75 | ||
74e1fbb1 JR |
76 | struct of_phandle_iterator { |
77 | /* Common iterator information */ | |
78 | const char *cells_name; | |
79 | int cell_count; | |
80 | const struct device_node *parent; | |
81 | ||
82 | /* List size information */ | |
83 | const __be32 *list_end; | |
84 | const __be32 *phandle_end; | |
85 | ||
86 | /* Current position state */ | |
87 | const __be32 *cur; | |
88 | uint32_t cur_count; | |
89 | phandle phandle; | |
90 | struct device_node *node; | |
91 | }; | |
92 | ||
f5242e5a GL |
93 | struct of_reconfig_data { |
94 | struct device_node *dn; | |
95 | struct property *prop; | |
96 | struct property *old_prop; | |
97 | }; | |
98 | ||
2582c531 SR |
99 | extern const struct kobj_type of_node_ktype; |
100 | extern const struct fwnode_operations of_fwnode_ops; | |
101 | ||
d9194e00 FR |
102 | /** |
103 | * of_node_init - initialize a devicetree node | |
104 | * @node: Pointer to device node that has been created by kzalloc() | |
d9194e00 FR |
105 | * |
106 | * On return the device_node refcount is set to one. Use of_node_put() | |
107 | * on @node when done to free the memory allocated for it. If the node | |
108 | * is NOT a dynamic node the memory will not be freed. The decision of | |
109 | * whether to free the memory will be done by node->release(), which is | |
110 | * of_node_release(). | |
111 | */ | |
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 |
01bb86b3 | 117 | fwnode_init(&node->fwnode, &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; |
41f88009 | 143 | |
144552c7 FR |
144 | /* |
145 | * struct device_node flag descriptions | |
146 | * (need to be visible even when !CONFIG_OF) | |
147 | */ | |
148 | #define OF_DYNAMIC 1 /* (and properties) allocated via kmalloc */ | |
149 | #define OF_DETACHED 2 /* detached from the device tree */ | |
150 | #define OF_POPULATED 3 /* device already created */ | |
151 | #define OF_POPULATED_BUS 4 /* platform bus created for children */ | |
152 | #define OF_OVERLAY 5 /* allocated for an overlay */ | |
153 | #define OF_OVERLAY_FREE_CSET 6 /* in overlay cset being freed */ | |
391b459d | 154 | |
b1d06b60 GR |
155 | #define OF_BAD_ADDR ((u64)-1) |
156 | ||
6d09dc6b | 157 | #ifdef CONFIG_OF |
194ec936 SH |
158 | void of_core_init(void); |
159 | ||
d20dc149 | 160 | static inline bool is_of_node(const struct fwnode_handle *fwnode) |
8a0662d9 | 161 | { |
db3e50f3 | 162 | return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops; |
8a0662d9 RW |
163 | } |
164 | ||
d20dc149 SA |
165 | #define to_of_node(__fwnode) \ |
166 | ({ \ | |
167 | typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \ | |
168 | \ | |
169 | is_of_node(__to_of_node_fwnode) ? \ | |
170 | container_of(__to_of_node_fwnode, \ | |
171 | struct device_node, fwnode) : \ | |
172 | NULL; \ | |
173 | }) | |
8a0662d9 | 174 | |
debd3a3b SA |
175 | #define of_fwnode_handle(node) \ |
176 | ({ \ | |
177 | typeof(node) __of_fwnode_handle_node = (node); \ | |
178 | \ | |
179 | __of_fwnode_handle_node ? \ | |
180 | &__of_fwnode_handle_node->fwnode : NULL; \ | |
181 | }) | |
67831837 | 182 | |
3bcbaf6e SAS |
183 | static inline bool of_have_populated_dt(void) |
184 | { | |
5063e25a | 185 | return of_root != NULL; |
3bcbaf6e SAS |
186 | } |
187 | ||
035ebefc AS |
188 | static inline bool of_node_is_root(const struct device_node *node) |
189 | { | |
190 | return node && (node->parent == NULL); | |
191 | } | |
192 | ||
a3c85b2e | 193 | static inline int of_node_check_flag(const struct device_node *n, unsigned long flag) |
50436312 GL |
194 | { |
195 | return test_bit(flag, &n->_flags); | |
196 | } | |
197 | ||
c6e126de PM |
198 | static inline int of_node_test_and_set_flag(struct device_node *n, |
199 | unsigned long flag) | |
200 | { | |
201 | return test_and_set_bit(flag, &n->_flags); | |
202 | } | |
203 | ||
50436312 GL |
204 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) |
205 | { | |
206 | set_bit(flag, &n->_flags); | |
207 | } | |
208 | ||
588453c6 PA |
209 | static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) |
210 | { | |
211 | clear_bit(flag, &n->_flags); | |
212 | } | |
213 | ||
16bba30e | 214 | #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC) |
39d64960 | 215 | static inline int of_property_check_flag(const struct property *p, unsigned long flag) |
588453c6 PA |
216 | { |
217 | return test_bit(flag, &p->_flags); | |
218 | } | |
219 | ||
220 | static inline void of_property_set_flag(struct property *p, unsigned long flag) | |
221 | { | |
222 | set_bit(flag, &p->_flags); | |
223 | } | |
224 | ||
225 | static inline void of_property_clear_flag(struct property *p, unsigned long flag) | |
226 | { | |
227 | clear_bit(flag, &p->_flags); | |
228 | } | |
16bba30e | 229 | #endif |
588453c6 | 230 | |
5063e25a | 231 | extern struct device_node *__of_find_all_nodes(struct device_node *prev); |
e91edcf5 GL |
232 | extern struct device_node *of_find_all_nodes(struct device_node *prev); |
233 | ||
b6caf2ad | 234 | /* |
3d6b8828 | 235 | * OF address retrieval & translation |
b6caf2ad GL |
236 | */ |
237 | ||
238 | /* Helper to read a big number; size is in cells (not bytes) */ | |
2e89e685 | 239 | static inline u64 of_read_number(const __be32 *cell, int size) |
b6caf2ad GL |
240 | { |
241 | u64 r = 0; | |
44086866 PT |
242 | for (; size--; cell++) |
243 | r = (r << 32) | be32_to_cpu(*cell); | |
b6caf2ad GL |
244 | return r; |
245 | } | |
246 | ||
247 | /* Like of_read_number, but we want an unsigned long result */ | |
2e89e685 | 248 | static inline unsigned long of_read_ulong(const __be32 *cell, int size) |
b6caf2ad | 249 | { |
2be09cb9 GL |
250 | /* toss away upper bits if unsigned long is smaller than u64 */ |
251 | return of_read_number(cell, size); | |
b6caf2ad | 252 | } |
b6caf2ad | 253 | |
b5b4bb3f | 254 | #if defined(CONFIG_SPARC) |
76c1ce78 | 255 | #include <asm/prom.h> |
b5b4bb3f | 256 | #endif |
76c1ce78 | 257 | |
61e955db GL |
258 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) |
259 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) | |
260 | ||
f42b0e18 RH |
261 | extern bool of_node_name_eq(const struct device_node *np, const char *name); |
262 | extern bool of_node_name_prefix(const struct device_node *np, const char *prefix); | |
263 | ||
c0a05bf0 | 264 | static inline const char *of_node_full_name(const struct device_node *np) |
74a7f084 GL |
265 | { |
266 | return np ? np->full_name : "<no-node>"; | |
267 | } | |
268 | ||
5063e25a GL |
269 | #define for_each_of_allnodes_from(from, dn) \ |
270 | for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn)) | |
271 | #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn) | |
76c1ce78 SR |
272 | extern struct device_node *of_find_node_by_name(struct device_node *from, |
273 | const char *name); | |
76c1ce78 SR |
274 | extern struct device_node *of_find_node_by_type(struct device_node *from, |
275 | const char *type); | |
76c1ce78 SR |
276 | extern struct device_node *of_find_compatible_node(struct device_node *from, |
277 | const char *type, const char *compat); | |
50c8af4c SW |
278 | extern struct device_node *of_find_matching_node_and_match( |
279 | struct device_node *from, | |
280 | const struct of_device_id *matches, | |
281 | const struct of_device_id **match); | |
662372e4 | 282 | |
75c28c09 LL |
283 | extern struct device_node *of_find_node_opts_by_path(const char *path, |
284 | const char **opts); | |
285 | static inline struct device_node *of_find_node_by_path(const char *path) | |
286 | { | |
287 | return of_find_node_opts_by_path(path, NULL); | |
288 | } | |
289 | ||
76c1ce78 SR |
290 | extern struct device_node *of_find_node_by_phandle(phandle handle); |
291 | extern struct device_node *of_get_parent(const struct device_node *node); | |
f4eb0107 | 292 | extern struct device_node *of_get_next_parent(struct device_node *node); |
76c1ce78 SR |
293 | extern struct device_node *of_get_next_child(const struct device_node *node, |
294 | struct device_node *prev); | |
3296193d TT |
295 | extern struct device_node *of_get_next_available_child( |
296 | const struct device_node *node, struct device_node *prev); | |
297 | ||
36156f92 JH |
298 | extern struct device_node *of_get_compatible_child(const struct device_node *parent, |
299 | const char *compatible); | |
9c19761a SK |
300 | extern struct device_node *of_get_child_by_name(const struct device_node *node, |
301 | const char *name); | |
954e04b9 | 302 | |
a3e31b45 SK |
303 | /* cache lookup */ |
304 | extern struct device_node *of_find_next_cache_node(const struct device_node *); | |
5fa23530 | 305 | extern int of_find_last_cache_level(unsigned int cpu); |
1e291b14 ME |
306 | extern struct device_node *of_find_node_with_property( |
307 | struct device_node *from, const char *prop_name); | |
1e291b14 | 308 | |
76c1ce78 SR |
309 | extern struct property *of_find_property(const struct device_node *np, |
310 | const char *name, | |
311 | int *lenp); | |
ad54a0cf HS |
312 | extern int of_property_count_elems_of_size(const struct device_node *np, |
313 | const char *propname, int elem_size); | |
3daf3726 TP |
314 | extern int of_property_read_u32_index(const struct device_node *np, |
315 | const char *propname, | |
316 | u32 index, u32 *out_value); | |
2475a2b6 AP |
317 | extern int of_property_read_u64_index(const struct device_node *np, |
318 | const char *propname, | |
319 | u32 index, u64 *out_value); | |
a67e9472 RF |
320 | extern int of_property_read_variable_u8_array(const struct device_node *np, |
321 | const char *propname, u8 *out_values, | |
322 | size_t sz_min, size_t sz_max); | |
323 | extern int of_property_read_variable_u16_array(const struct device_node *np, | |
324 | const char *propname, u16 *out_values, | |
325 | size_t sz_min, size_t sz_max); | |
326 | extern int of_property_read_variable_u32_array(const struct device_node *np, | |
327 | const char *propname, | |
328 | u32 *out_values, | |
329 | size_t sz_min, | |
330 | size_t sz_max); | |
4cd7f7a3 JI |
331 | extern int of_property_read_u64(const struct device_node *np, |
332 | const char *propname, u64 *out_value); | |
a67e9472 RF |
333 | extern int of_property_read_variable_u64_array(const struct device_node *np, |
334 | const char *propname, | |
335 | u64 *out_values, | |
336 | size_t sz_min, | |
337 | size_t sz_max); | |
0e373639 | 338 | |
fe99c707 | 339 | extern int of_property_read_string(const struct device_node *np, |
aac285c6 JI |
340 | const char *propname, |
341 | const char **out_string); | |
fe99c707 | 342 | extern int of_property_match_string(const struct device_node *np, |
7aff0fe3 GL |
343 | const char *propname, |
344 | const char *string); | |
fe99c707 | 345 | extern int of_property_read_string_helper(const struct device_node *np, |
a87fa1d8 GL |
346 | const char *propname, |
347 | const char **out_strs, size_t sz, int index); | |
76c1ce78 SR |
348 | extern int of_device_is_compatible(const struct device_node *device, |
349 | const char *); | |
88269151 | 350 | extern int of_device_compatible_match(const struct device_node *device, |
b9c13fe3 | 351 | const char *const *compat); |
53a4ab96 | 352 | extern bool of_device_is_available(const struct device_node *device); |
37786c7f | 353 | extern bool of_device_is_big_endian(const struct device_node *device); |
76c1ce78 SR |
354 | extern const void *of_get_property(const struct device_node *node, |
355 | const char *name, | |
356 | int *lenp); | |
183912d3 | 357 | extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); |
b58fa269 RH |
358 | extern struct device_node *of_cpu_device_node_get(int cpu); |
359 | extern int of_cpu_node_to_id(struct device_node *np); | |
f1f207e4 | 360 | extern struct device_node *of_get_next_cpu_node(struct device_node *prev); |
b9f8c26a UH |
361 | extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, |
362 | int index); | |
795e92ec | 363 | extern u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread); |
f1f207e4 | 364 | |
8af0da93 DA |
365 | #define for_each_property_of_node(dn, pp) \ |
366 | for (pp = dn->properties; pp != NULL; pp = pp->next) | |
611cad72 | 367 | |
76c1ce78 SR |
368 | extern int of_n_addr_cells(struct device_node *np); |
369 | extern int of_n_size_cells(struct device_node *np); | |
283029d1 GL |
370 | extern const struct of_device_id *of_match_node( |
371 | const struct of_device_id *matches, const struct device_node *node); | |
82174a0a | 372 | extern const void *of_device_get_match_data(const struct device *dev); |
673aa1ed MR |
373 | extern int of_alias_from_compatible(const struct device_node *node, char *alias, |
374 | int len); | |
624cfca5 | 375 | extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args); |
66a8f7f0 MW |
376 | extern int __of_parse_phandle_with_args(const struct device_node *np, |
377 | const char *list_name, const char *cells_name, int cell_count, | |
378 | int index, struct of_phandle_args *out_args); | |
bd6f2fd5 SB |
379 | extern int of_parse_phandle_with_args_map(const struct device_node *np, |
380 | const char *list_name, const char *stem_name, int index, | |
381 | struct of_phandle_args *out_args); | |
bd69f73f GL |
382 | extern int of_count_phandle_with_args(const struct device_node *np, |
383 | const char *list_name, const char *cells_name); | |
76c1ce78 | 384 | |
bd7a7ed7 MR |
385 | /* module functions */ |
386 | extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len); | |
e6506f06 | 387 | extern int of_request_module(const struct device_node *np); |
bd7a7ed7 | 388 | |
74e1fbb1 JR |
389 | /* phandle iterator functions */ |
390 | extern int of_phandle_iterator_init(struct of_phandle_iterator *it, | |
391 | const struct device_node *np, | |
392 | const char *list_name, | |
393 | const char *cells_name, | |
394 | int cell_count); | |
395 | ||
cd209b41 | 396 | extern int of_phandle_iterator_next(struct of_phandle_iterator *it); |
abdaa77b JR |
397 | extern int of_phandle_iterator_args(struct of_phandle_iterator *it, |
398 | uint32_t *args, | |
399 | int size); | |
cd209b41 | 400 | |
611cad72 SG |
401 | extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); |
402 | extern int of_alias_get_id(struct device_node *np, const char *stem); | |
351d224f | 403 | extern int of_alias_get_highest_id(const char *stem); |
611cad72 | 404 | |
21b082ec GL |
405 | extern int of_machine_is_compatible(const char *compat); |
406 | ||
79d1c712 NF |
407 | extern int of_add_property(struct device_node *np, struct property *prop); |
408 | extern int of_remove_property(struct device_node *np, struct property *prop); | |
409 | extern int of_update_property(struct device_node *np, struct property *newprop); | |
21b082ec | 410 | |
fcdeb7fe | 411 | /* For updating the device tree at runtime */ |
1cf3d8b3 NF |
412 | #define OF_RECONFIG_ATTACH_NODE 0x0001 |
413 | #define OF_RECONFIG_DETACH_NODE 0x0002 | |
414 | #define OF_RECONFIG_ADD_PROPERTY 0x0003 | |
415 | #define OF_RECONFIG_REMOVE_PROPERTY 0x0004 | |
416 | #define OF_RECONFIG_UPDATE_PROPERTY 0x0005 | |
417 | ||
1cf3d8b3 NF |
418 | extern int of_attach_node(struct device_node *); |
419 | extern int of_detach_node(struct device_node *); | |
fcdeb7fe | 420 | |
3a1e362e | 421 | #define of_match_ptr(_ptr) (_ptr) |
c541adc6 SW |
422 | |
423 | /* | |
424 | * struct property *prop; | |
425 | * const __be32 *p; | |
426 | * u32 u; | |
427 | * | |
428 | * of_property_for_each_u32(np, "propname", prop, p, u) | |
429 | * printk("U32 value: %x\n", u); | |
430 | */ | |
431 | const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, | |
432 | u32 *pu); | |
c541adc6 SW |
433 | /* |
434 | * struct property *prop; | |
435 | * const char *s; | |
436 | * | |
437 | * of_property_for_each_string(np, "propname", prop, s) | |
438 | * printk("String value: %s\n", s); | |
439 | */ | |
440 | const char *of_prop_next_string(struct property *prop, const char *cur); | |
c541adc6 | 441 | |
3482f2c5 | 442 | bool of_console_check(struct device_node *dn, char *name, int index); |
5c19e952 | 443 | |
746a71d0 | 444 | int of_map_id(struct device_node *np, u32 id, |
2a6db719 NG |
445 | const char *map_name, const char *map_mask_name, |
446 | struct device_node **target, u32 *id_out); | |
447 | ||
964db79d NSJ |
448 | phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); |
449 | ||
b30be4dc RH |
450 | struct kimage; |
451 | void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, | |
452 | unsigned long initrd_load_addr, | |
453 | unsigned long initrd_len, | |
454 | const char *cmdline, size_t extra_fdt_size); | |
b98c0239 | 455 | #else /* CONFIG_OF */ |
3bcbaf6e | 456 | |
194ec936 SH |
457 | static inline void of_core_init(void) |
458 | { | |
459 | } | |
460 | ||
d20dc149 | 461 | static inline bool is_of_node(const struct fwnode_handle *fwnode) |
8a0662d9 RW |
462 | { |
463 | return false; | |
464 | } | |
465 | ||
d20dc149 | 466 | static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode) |
8a0662d9 RW |
467 | { |
468 | return NULL; | |
469 | } | |
470 | ||
f42b0e18 RH |
471 | static inline bool of_node_name_eq(const struct device_node *np, const char *name) |
472 | { | |
473 | return false; | |
474 | } | |
475 | ||
476 | static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix) | |
477 | { | |
478 | return false; | |
479 | } | |
480 | ||
4c358e15 | 481 | static inline const char* of_node_full_name(const struct device_node *np) |
74a7f084 GL |
482 | { |
483 | return "<no-node>"; | |
484 | } | |
485 | ||
1cc44f43 PU |
486 | static inline struct device_node *of_find_node_by_name(struct device_node *from, |
487 | const char *name) | |
488 | { | |
489 | return NULL; | |
490 | } | |
491 | ||
662372e4 RH |
492 | static inline struct device_node *of_find_node_by_type(struct device_node *from, |
493 | const char *type) | |
066ec1dd AS |
494 | { |
495 | return NULL; | |
496 | } | |
497 | ||
662372e4 RH |
498 | static inline struct device_node *of_find_matching_node_and_match( |
499 | struct device_node *from, | |
500 | const struct of_device_id *matches, | |
501 | const struct of_device_id **match) | |
3bcbaf6e | 502 | { |
662372e4 | 503 | return NULL; |
3bcbaf6e SAS |
504 | } |
505 | ||
20cd477c AS |
506 | static inline struct device_node *of_find_node_by_path(const char *path) |
507 | { | |
508 | return NULL; | |
509 | } | |
510 | ||
75c28c09 LL |
511 | static inline struct device_node *of_find_node_opts_by_path(const char *path, |
512 | const char **opts) | |
513 | { | |
514 | return NULL; | |
515 | } | |
516 | ||
ce16b9d2 SA |
517 | static inline struct device_node *of_find_node_by_phandle(phandle handle) |
518 | { | |
519 | return NULL; | |
520 | } | |
521 | ||
662372e4 | 522 | static inline struct device_node *of_get_parent(const struct device_node *node) |
00b2c76a | 523 | { |
662372e4 | 524 | return NULL; |
00b2c76a DH |
525 | } |
526 | ||
943c8a80 RD |
527 | static inline struct device_node *of_get_next_parent(struct device_node *node) |
528 | { | |
529 | return NULL; | |
530 | } | |
531 | ||
662372e4 RH |
532 | static inline struct device_node *of_get_next_child( |
533 | const struct device_node *node, struct device_node *prev) | |
534 | { | |
535 | return NULL; | |
536 | } | |
aba3dfff | 537 | |
662372e4 RH |
538 | static inline struct device_node *of_get_next_available_child( |
539 | const struct device_node *node, struct device_node *prev) | |
540 | { | |
541 | return NULL; | |
542 | } | |
f6f0747e | 543 | |
662372e4 RH |
544 | static inline struct device_node *of_find_node_with_property( |
545 | struct device_node *from, const char *prop_name) | |
25c040c9 OJ |
546 | { |
547 | return NULL; | |
548 | } | |
549 | ||
67831837 SA |
550 | #define of_fwnode_handle(node) NULL |
551 | ||
662372e4 | 552 | static inline bool of_have_populated_dt(void) |
183f1d0c | 553 | { |
662372e4 | 554 | return false; |
183f1d0c DA |
555 | } |
556 | ||
36156f92 JH |
557 | static inline struct device_node *of_get_compatible_child(const struct device_node *parent, |
558 | const char *compatible) | |
559 | { | |
560 | return NULL; | |
561 | } | |
562 | ||
662372e4 RH |
563 | static inline struct device_node *of_get_child_by_name( |
564 | const struct device_node *node, | |
565 | const char *name) | |
954e04b9 | 566 | { |
662372e4 | 567 | return NULL; |
954e04b9 BW |
568 | } |
569 | ||
36a0904e RN |
570 | static inline int of_device_is_compatible(const struct device_node *device, |
571 | const char *name) | |
572 | { | |
573 | return 0; | |
574 | } | |
575 | ||
88269151 | 576 | static inline int of_device_compatible_match(const struct device_node *device, |
3bc16307 GU |
577 | const char *const *compat) |
578 | { | |
579 | return 0; | |
580 | } | |
581 | ||
53a4ab96 | 582 | static inline bool of_device_is_available(const struct device_node *device) |
d7195696 | 583 | { |
53a4ab96 | 584 | return false; |
d7195696 RH |
585 | } |
586 | ||
37786c7f KC |
587 | static inline bool of_device_is_big_endian(const struct device_node *device) |
588 | { | |
589 | return false; | |
d7195696 RH |
590 | } |
591 | ||
aba3dfff SW |
592 | static inline struct property *of_find_property(const struct device_node *np, |
593 | const char *name, | |
594 | int *lenp) | |
595 | { | |
596 | return NULL; | |
597 | } | |
598 | ||
2261cc62 SG |
599 | static inline struct device_node *of_find_compatible_node( |
600 | struct device_node *from, | |
601 | const char *type, | |
602 | const char *compat) | |
603 | { | |
604 | return NULL; | |
605 | } | |
606 | ||
ad54a0cf HS |
607 | static inline int of_property_count_elems_of_size(const struct device_node *np, |
608 | const char *propname, int elem_size) | |
609 | { | |
610 | return -ENOSYS; | |
611 | } | |
612 | ||
96c623e5 AB |
613 | static inline int of_property_read_u32_index(const struct device_node *np, |
614 | const char *propname, u32 index, u32 *out_value) | |
b98c0239 SG |
615 | { |
616 | return -ENOSYS; | |
617 | } | |
618 | ||
96c623e5 AB |
619 | static inline int of_property_read_u64_index(const struct device_node *np, |
620 | const char *propname, u32 index, u64 *out_value) | |
4fcd15a0 BC |
621 | { |
622 | return -ENOSYS; | |
623 | } | |
624 | ||
89272b8c SW |
625 | static inline const void *of_get_property(const struct device_node *node, |
626 | const char *name, | |
627 | int *lenp) | |
628 | { | |
629 | return NULL; | |
630 | } | |
631 | ||
183912d3 SK |
632 | static inline struct device_node *of_get_cpu_node(int cpu, |
633 | unsigned int *thread) | |
634 | { | |
635 | return NULL; | |
636 | } | |
637 | ||
b58fa269 RH |
638 | static inline struct device_node *of_cpu_device_node_get(int cpu) |
639 | { | |
640 | return NULL; | |
641 | } | |
642 | ||
643 | static inline int of_cpu_node_to_id(struct device_node *np) | |
644 | { | |
645 | return -ENODEV; | |
646 | } | |
647 | ||
f1f207e4 RH |
648 | static inline struct device_node *of_get_next_cpu_node(struct device_node *prev) |
649 | { | |
650 | return NULL; | |
651 | } | |
652 | ||
b9f8c26a UH |
653 | static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, |
654 | int index) | |
655 | { | |
656 | return NULL; | |
657 | } | |
658 | ||
8a1ac5dc AB |
659 | static inline int of_n_addr_cells(struct device_node *np) |
660 | { | |
661 | return 0; | |
662 | ||
663 | } | |
664 | static inline int of_n_size_cells(struct device_node *np) | |
665 | { | |
666 | return 0; | |
667 | } | |
668 | ||
96c623e5 AB |
669 | static inline int of_property_read_variable_u8_array(const struct device_node *np, |
670 | const char *propname, u8 *out_values, | |
671 | size_t sz_min, size_t sz_max) | |
672 | { | |
673 | return -ENOSYS; | |
674 | } | |
675 | ||
676 | static inline int of_property_read_variable_u16_array(const struct device_node *np, | |
677 | const char *propname, u16 *out_values, | |
678 | size_t sz_min, size_t sz_max) | |
679 | { | |
680 | return -ENOSYS; | |
681 | } | |
682 | ||
683 | static inline int of_property_read_variable_u32_array(const struct device_node *np, | |
684 | const char *propname, | |
685 | u32 *out_values, | |
686 | size_t sz_min, | |
687 | size_t sz_max) | |
688 | { | |
689 | return -ENOSYS; | |
690 | } | |
691 | ||
4cd7f7a3 JI |
692 | static inline int of_property_read_u64(const struct device_node *np, |
693 | const char *propname, u64 *out_value) | |
694 | { | |
695 | return -ENOSYS; | |
696 | } | |
697 | ||
96c623e5 AB |
698 | static inline int of_property_read_variable_u64_array(const struct device_node *np, |
699 | const char *propname, | |
700 | u64 *out_values, | |
701 | size_t sz_min, | |
702 | size_t sz_max) | |
703 | { | |
704 | return -ENOSYS; | |
705 | } | |
706 | ||
707 | static inline int of_property_read_string(const struct device_node *np, | |
708 | const char *propname, | |
709 | const char **out_string) | |
710 | { | |
711 | return -ENOSYS; | |
712 | } | |
713 | ||
fe99c707 | 714 | static inline int of_property_match_string(const struct device_node *np, |
bd3d5500 TR |
715 | const char *propname, |
716 | const char *string) | |
717 | { | |
718 | return -ENOSYS; | |
719 | } | |
720 | ||
96c623e5 AB |
721 | static inline int of_property_read_string_helper(const struct device_node *np, |
722 | const char *propname, | |
723 | const char **out_strs, size_t sz, int index) | |
724 | { | |
725 | return -ENOSYS; | |
726 | } | |
727 | ||
66a8f7f0 MW |
728 | static inline int __of_parse_phandle_with_args(const struct device_node *np, |
729 | const char *list_name, | |
730 | const char *cells_name, | |
731 | int cell_count, | |
732 | int index, | |
733 | struct of_phandle_args *out_args) | |
e05e5070 TR |
734 | { |
735 | return -ENOSYS; | |
736 | } | |
737 | ||
bd6f2fd5 SB |
738 | static inline int of_parse_phandle_with_args_map(const struct device_node *np, |
739 | const char *list_name, | |
740 | const char *stem_name, | |
741 | int index, | |
742 | struct of_phandle_args *out_args) | |
743 | { | |
744 | return -ENOSYS; | |
745 | } | |
746 | ||
a065d561 | 747 | static inline int of_count_phandle_with_args(const struct device_node *np, |
bd69f73f GL |
748 | const char *list_name, |
749 | const char *cells_name) | |
750 | { | |
751 | return -ENOSYS; | |
752 | } | |
753 | ||
bd7a7ed7 MR |
754 | static inline ssize_t of_modalias(const struct device_node *np, char *str, |
755 | ssize_t len) | |
756 | { | |
757 | return -ENODEV; | |
758 | } | |
759 | ||
e6506f06 MR |
760 | static inline int of_request_module(const struct device_node *np) |
761 | { | |
762 | return -ENODEV; | |
763 | } | |
764 | ||
74e1fbb1 JR |
765 | static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, |
766 | const struct device_node *np, | |
767 | const char *list_name, | |
768 | const char *cells_name, | |
769 | int cell_count) | |
770 | { | |
771 | return -ENOSYS; | |
772 | } | |
773 | ||
cd209b41 JR |
774 | static inline int of_phandle_iterator_next(struct of_phandle_iterator *it) |
775 | { | |
776 | return -ENOSYS; | |
777 | } | |
778 | ||
abdaa77b JR |
779 | static inline int of_phandle_iterator_args(struct of_phandle_iterator *it, |
780 | uint32_t *args, | |
781 | int size) | |
782 | { | |
783 | return 0; | |
784 | } | |
785 | ||
ed5f886d NF |
786 | static inline int of_alias_get_id(struct device_node *np, const char *stem) |
787 | { | |
788 | return -ENOSYS; | |
789 | } | |
790 | ||
351d224f WS |
791 | static inline int of_alias_get_highest_id(const char *stem) |
792 | { | |
793 | return -ENOSYS; | |
794 | } | |
795 | ||
50e07f88 SW |
796 | static inline int of_machine_is_compatible(const char *compat) |
797 | { | |
798 | return 0; | |
799 | } | |
800 | ||
fe794e39 WC |
801 | static inline int of_add_property(struct device_node *np, struct property *prop) |
802 | { | |
803 | return 0; | |
804 | } | |
805 | ||
0f7c5317 FF |
806 | static inline int of_remove_property(struct device_node *np, struct property *prop) |
807 | { | |
808 | return 0; | |
809 | } | |
810 | ||
3482f2c5 | 811 | static inline bool of_console_check(const struct device_node *dn, const char *name, int index) |
5c19e952 | 812 | { |
3482f2c5 | 813 | return false; |
5c19e952 SH |
814 | } |
815 | ||
2adfffa2 SAS |
816 | static inline const __be32 *of_prop_next_u32(struct property *prop, |
817 | const __be32 *cur, u32 *pu) | |
818 | { | |
819 | return NULL; | |
820 | } | |
821 | ||
822 | static inline const char *of_prop_next_string(struct property *prop, | |
823 | const char *cur) | |
824 | { | |
825 | return NULL; | |
826 | } | |
827 | ||
0384e8c6 PA |
828 | static inline int of_node_check_flag(struct device_node *n, unsigned long flag) |
829 | { | |
830 | return 0; | |
831 | } | |
832 | ||
833 | static inline int of_node_test_and_set_flag(struct device_node *n, | |
834 | unsigned long flag) | |
835 | { | |
836 | return 0; | |
837 | } | |
838 | ||
839 | static inline void of_node_set_flag(struct device_node *n, unsigned long flag) | |
840 | { | |
841 | } | |
842 | ||
843 | static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) | |
844 | { | |
845 | } | |
846 | ||
39d64960 CL |
847 | static inline int of_property_check_flag(const struct property *p, |
848 | unsigned long flag) | |
0384e8c6 PA |
849 | { |
850 | return 0; | |
851 | } | |
852 | ||
853 | static inline void of_property_set_flag(struct property *p, unsigned long flag) | |
854 | { | |
855 | } | |
856 | ||
857 | static inline void of_property_clear_flag(struct property *p, unsigned long flag) | |
858 | { | |
859 | } | |
860 | ||
746a71d0 | 861 | static inline int of_map_id(struct device_node *np, u32 id, |
2a6db719 NG |
862 | const char *map_name, const char *map_mask_name, |
863 | struct device_node **target, u32 *id_out) | |
864 | { | |
865 | return -EINVAL; | |
866 | } | |
867 | ||
964db79d NSJ |
868 | static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np) |
869 | { | |
870 | return PHYS_ADDR_MAX; | |
871 | } | |
872 | ||
82174a0a RH |
873 | static inline const void *of_device_get_match_data(const struct device *dev) |
874 | { | |
875 | return NULL; | |
876 | } | |
877 | ||
3a1e362e | 878 | #define of_match_ptr(_ptr) NULL |
5762c205 | 879 | #define of_match_node(_matches, _node) NULL |
9dfbf207 | 880 | #endif /* CONFIG_OF */ |
b98c0239 | 881 | |
613e9721 AT |
882 | /* Default string compare functions, Allow arch asm/prom.h to override */ |
883 | #if !defined(of_compat_cmp) | |
884 | #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2)) | |
885 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) | |
886 | #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) | |
887 | #endif | |
888 | ||
6f751188 FR |
889 | static inline int of_prop_val_eq(struct property *p1, struct property *p2) |
890 | { | |
891 | return p1->length == p2->length && | |
892 | !memcmp(p1->value, p2->value, (size_t)p1->length); | |
893 | } | |
894 | ||
0c3f061c RH |
895 | #if defined(CONFIG_OF) && defined(CONFIG_NUMA) |
896 | extern int of_node_to_nid(struct device_node *np); | |
897 | #else | |
c8fff7bc KK |
898 | static inline int of_node_to_nid(struct device_node *device) |
899 | { | |
900 | return NUMA_NO_NODE; | |
901 | } | |
5ca4db61 PM |
902 | #endif |
903 | ||
298535c0 DD |
904 | #ifdef CONFIG_OF_NUMA |
905 | extern int of_numa_init(void); | |
906 | #else | |
907 | static inline int of_numa_init(void) | |
908 | { | |
909 | return -ENOSYS; | |
910 | } | |
911 | #endif | |
912 | ||
662372e4 RH |
913 | static inline struct device_node *of_find_matching_node( |
914 | struct device_node *from, | |
915 | const struct of_device_id *matches) | |
916 | { | |
917 | return of_find_matching_node_and_match(from, matches, NULL); | |
918 | } | |
919 | ||
0413beda RH |
920 | static inline const char *of_node_get_device_type(const struct device_node *np) |
921 | { | |
5d5a0ab1 | 922 | return of_get_property(np, "device_type", NULL); |
0413beda RH |
923 | } |
924 | ||
925 | static inline bool of_node_is_type(const struct device_node *np, const char *type) | |
926 | { | |
927 | const char *match = of_node_get_device_type(np); | |
928 | ||
929 | return np && match && type && !strcmp(match, type); | |
930 | } | |
931 | ||
66a8f7f0 MW |
932 | /** |
933 | * of_parse_phandle - Resolve a phandle property to a device_node pointer | |
934 | * @np: Pointer to device node holding phandle property | |
935 | * @phandle_name: Name of property holding a phandle value | |
936 | * @index: For properties holding a table of phandles, this is the index into | |
937 | * the table | |
938 | * | |
939 | * Return: The device_node pointer with refcount incremented. Use | |
940 | * of_node_put() on it when done. | |
941 | */ | |
942 | static inline struct device_node *of_parse_phandle(const struct device_node *np, | |
943 | const char *phandle_name, | |
944 | int index) | |
945 | { | |
946 | struct of_phandle_args args; | |
947 | ||
948 | if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0, | |
949 | index, &args)) | |
950 | return NULL; | |
951 | ||
952 | return args.np; | |
953 | } | |
954 | ||
955 | /** | |
956 | * of_parse_phandle_with_args() - Find a node pointed by phandle in a list | |
957 | * @np: pointer to a device tree node containing a list | |
958 | * @list_name: property name that contains a list | |
959 | * @cells_name: property name that specifies phandles' arguments count | |
960 | * @index: index of a phandle to parse out | |
961 | * @out_args: optional pointer to output arguments structure (will be filled) | |
962 | * | |
963 | * This function is useful to parse lists of phandles and their arguments. | |
964 | * Returns 0 on success and fills out_args, on error returns appropriate | |
965 | * errno value. | |
966 | * | |
967 | * Caller is responsible to call of_node_put() on the returned out_args->np | |
968 | * pointer. | |
969 | * | |
970 | * Example:: | |
971 | * | |
972 | * phandle1: node1 { | |
973 | * #list-cells = <2>; | |
974 | * }; | |
975 | * | |
976 | * phandle2: node2 { | |
977 | * #list-cells = <1>; | |
978 | * }; | |
979 | * | |
980 | * node3 { | |
981 | * list = <&phandle1 1 2 &phandle2 3>; | |
982 | * }; | |
983 | * | |
984 | * To get a device_node of the ``node2`` node you may call this: | |
985 | * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args); | |
986 | */ | |
987 | static inline int of_parse_phandle_with_args(const struct device_node *np, | |
988 | const char *list_name, | |
989 | const char *cells_name, | |
990 | int index, | |
991 | struct of_phandle_args *out_args) | |
992 | { | |
993 | int cell_count = -1; | |
994 | ||
995 | /* If cells_name is NULL we assume a cell count of 0 */ | |
996 | if (!cells_name) | |
997 | cell_count = 0; | |
998 | ||
999 | return __of_parse_phandle_with_args(np, list_name, cells_name, | |
1000 | cell_count, index, out_args); | |
1001 | } | |
1002 | ||
1003 | /** | |
1004 | * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list | |
1005 | * @np: pointer to a device tree node containing a list | |
1006 | * @list_name: property name that contains a list | |
1007 | * @cell_count: number of argument cells following the phandle | |
1008 | * @index: index of a phandle to parse out | |
1009 | * @out_args: optional pointer to output arguments structure (will be filled) | |
1010 | * | |
1011 | * This function is useful to parse lists of phandles and their arguments. | |
1012 | * Returns 0 on success and fills out_args, on error returns appropriate | |
1013 | * errno value. | |
1014 | * | |
1015 | * Caller is responsible to call of_node_put() on the returned out_args->np | |
1016 | * pointer. | |
1017 | * | |
1018 | * Example:: | |
1019 | * | |
1020 | * phandle1: node1 { | |
1021 | * }; | |
1022 | * | |
1023 | * phandle2: node2 { | |
1024 | * }; | |
1025 | * | |
1026 | * node3 { | |
1027 | * list = <&phandle1 0 2 &phandle2 2 3>; | |
1028 | * }; | |
1029 | * | |
1030 | * To get a device_node of the ``node2`` node you may call this: | |
1031 | * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args); | |
1032 | */ | |
1033 | static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, | |
1034 | const char *list_name, | |
1035 | int cell_count, | |
1036 | int index, | |
1037 | struct of_phandle_args *out_args) | |
1038 | { | |
1039 | return __of_parse_phandle_with_args(np, list_name, NULL, cell_count, | |
1040 | index, out_args); | |
1041 | } | |
1042 | ||
c5d264d4 MW |
1043 | /** |
1044 | * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list | |
1045 | * @np: pointer to a device tree node containing a list | |
1046 | * @list_name: property name that contains a list | |
1047 | * @cells_name: property name that specifies phandles' arguments count | |
1048 | * @index: index of a phandle to parse out | |
1049 | * @out_args: optional pointer to output arguments structure (will be filled) | |
1050 | * | |
1051 | * Same as of_parse_phandle_with_args() except that if the cells_name property | |
1052 | * is not found, cell_count of 0 is assumed. | |
1053 | * | |
1054 | * This is used to useful, if you have a phandle which didn't have arguments | |
1055 | * before and thus doesn't have a '#*-cells' property but is now migrated to | |
1056 | * having arguments while retaining backwards compatibility. | |
1057 | */ | |
1058 | static inline int of_parse_phandle_with_optional_args(const struct device_node *np, | |
1059 | const char *list_name, | |
1060 | const char *cells_name, | |
1061 | int index, | |
1062 | struct of_phandle_args *out_args) | |
1063 | { | |
1064 | return __of_parse_phandle_with_args(np, list_name, cells_name, | |
1065 | 0, index, out_args); | |
1066 | } | |
1067 | ||
ad54a0cf HS |
1068 | /** |
1069 | * of_property_count_u8_elems - Count the number of u8 elements in a property | |
1070 | * | |
1071 | * @np: device node from which the property value is to be read. | |
1072 | * @propname: name of the property to be searched. | |
1073 | * | |
1074 | * Search for a property in a device node and count the number of u8 elements | |
8c8239c2 RH |
1075 | * in it. |
1076 | * | |
1077 | * Return: The number of elements on sucess, -EINVAL if the property does | |
ad54a0cf HS |
1078 | * not exist or its length does not match a multiple of u8 and -ENODATA if the |
1079 | * property does not have a value. | |
1080 | */ | |
1081 | static inline int of_property_count_u8_elems(const struct device_node *np, | |
1082 | const char *propname) | |
1083 | { | |
1084 | return of_property_count_elems_of_size(np, propname, sizeof(u8)); | |
1085 | } | |
1086 | ||
1087 | /** | |
1088 | * of_property_count_u16_elems - Count the number of u16 elements in a property | |
1089 | * | |
1090 | * @np: device node from which the property value is to be read. | |
1091 | * @propname: name of the property to be searched. | |
1092 | * | |
1093 | * Search for a property in a device node and count the number of u16 elements | |
8c8239c2 RH |
1094 | * in it. |
1095 | * | |
1096 | * Return: The number of elements on sucess, -EINVAL if the property does | |
ad54a0cf HS |
1097 | * not exist or its length does not match a multiple of u16 and -ENODATA if the |
1098 | * property does not have a value. | |
1099 | */ | |
1100 | static inline int of_property_count_u16_elems(const struct device_node *np, | |
1101 | const char *propname) | |
1102 | { | |
1103 | return of_property_count_elems_of_size(np, propname, sizeof(u16)); | |
1104 | } | |
1105 | ||
1106 | /** | |
1107 | * of_property_count_u32_elems - Count the number of u32 elements in a property | |
1108 | * | |
1109 | * @np: device node from which the property value is to be read. | |
1110 | * @propname: name of the property to be searched. | |
1111 | * | |
1112 | * Search for a property in a device node and count the number of u32 elements | |
8c8239c2 RH |
1113 | * in it. |
1114 | * | |
1115 | * Return: The number of elements on sucess, -EINVAL if the property does | |
ad54a0cf HS |
1116 | * not exist or its length does not match a multiple of u32 and -ENODATA if the |
1117 | * property does not have a value. | |
1118 | */ | |
1119 | static inline int of_property_count_u32_elems(const struct device_node *np, | |
1120 | const char *propname) | |
1121 | { | |
1122 | return of_property_count_elems_of_size(np, propname, sizeof(u32)); | |
1123 | } | |
1124 | ||
1125 | /** | |
1126 | * of_property_count_u64_elems - Count the number of u64 elements in a property | |
1127 | * | |
1128 | * @np: device node from which the property value is to be read. | |
1129 | * @propname: name of the property to be searched. | |
1130 | * | |
1131 | * Search for a property in a device node and count the number of u64 elements | |
8c8239c2 RH |
1132 | * in it. |
1133 | * | |
1134 | * Return: The number of elements on sucess, -EINVAL if the property does | |
ad54a0cf HS |
1135 | * not exist or its length does not match a multiple of u64 and -ENODATA if the |
1136 | * property does not have a value. | |
1137 | */ | |
1138 | static inline int of_property_count_u64_elems(const struct device_node *np, | |
1139 | const char *propname) | |
1140 | { | |
1141 | return of_property_count_elems_of_size(np, propname, sizeof(u64)); | |
1142 | } | |
1143 | ||
a87fa1d8 GL |
1144 | /** |
1145 | * of_property_read_string_array() - Read an array of strings from a multiple | |
1146 | * strings property. | |
1147 | * @np: device node from which the property value is to be read. | |
1148 | * @propname: name of the property to be searched. | |
1149 | * @out_strs: output array of string pointers. | |
1150 | * @sz: number of array elements to read. | |
1151 | * | |
1152 | * Search for a property in a device tree node and retrieve a list of | |
1153 | * terminated string values (pointer to data, not a copy) in that property. | |
1154 | * | |
8c8239c2 | 1155 | * Return: If @out_strs is NULL, the number of strings in the property is returned. |
a87fa1d8 | 1156 | */ |
fe99c707 | 1157 | static inline int of_property_read_string_array(const struct device_node *np, |
a87fa1d8 GL |
1158 | const char *propname, const char **out_strs, |
1159 | size_t sz) | |
1160 | { | |
1161 | return of_property_read_string_helper(np, propname, out_strs, sz, 0); | |
1162 | } | |
1163 | ||
1164 | /** | |
1165 | * of_property_count_strings() - Find and return the number of strings from a | |
1166 | * multiple strings property. | |
1167 | * @np: device node from which the property value is to be read. | |
1168 | * @propname: name of the property to be searched. | |
1169 | * | |
1170 | * Search for a property in a device tree node and retrieve the number of null | |
8c8239c2 RH |
1171 | * terminated string contain in it. |
1172 | * | |
1173 | * Return: The number of strings on success, -EINVAL if the property does not | |
1174 | * exist, -ENODATA if property does not have a value, and -EILSEQ if the string | |
1175 | * is not null-terminated within the length of the property data. | |
a87fa1d8 | 1176 | */ |
fe99c707 | 1177 | static inline int of_property_count_strings(const struct device_node *np, |
a87fa1d8 GL |
1178 | const char *propname) |
1179 | { | |
1180 | return of_property_read_string_helper(np, propname, NULL, 0, 0); | |
1181 | } | |
1182 | ||
1183 | /** | |
1184 | * of_property_read_string_index() - Find and read a string from a multiple | |
1185 | * strings property. | |
1186 | * @np: device node from which the property value is to be read. | |
1187 | * @propname: name of the property to be searched. | |
1188 | * @index: index of the string in the list of strings | |
c968b89a | 1189 | * @output: pointer to null terminated return string, modified only if |
a87fa1d8 GL |
1190 | * return value is 0. |
1191 | * | |
1192 | * Search for a property in a device tree node and retrieve a null | |
1193 | * terminated string value (pointer to data, not a copy) in the list of strings | |
1194 | * contained in that property. | |
8c8239c2 RH |
1195 | * |
1196 | * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if | |
a87fa1d8 GL |
1197 | * property does not have a value, and -EILSEQ if the string is not |
1198 | * null-terminated within the length of the property data. | |
1199 | * | |
1200 | * The out_string pointer is modified only if a valid string can be decoded. | |
1201 | */ | |
fe99c707 | 1202 | static inline int of_property_read_string_index(const struct device_node *np, |
a87fa1d8 GL |
1203 | const char *propname, |
1204 | int index, const char **output) | |
1205 | { | |
1206 | int rc = of_property_read_string_helper(np, propname, output, 1, index); | |
1207 | return rc < 0 ? rc : 0; | |
1208 | } | |
1209 | ||
fa4d34cc | 1210 | /** |
f1765a18 | 1211 | * of_property_read_bool - Find a property |
fa4d34cc JCPV |
1212 | * @np: device node from which the property value is to be read. |
1213 | * @propname: name of the property to be searched. | |
1214 | * | |
9cbad37c RH |
1215 | * Search for a boolean property in a device node. Usage on non-boolean |
1216 | * property types is deprecated. | |
8c8239c2 RH |
1217 | * |
1218 | * Return: true if the property exists false otherwise. | |
fa4d34cc JCPV |
1219 | */ |
1220 | static inline bool of_property_read_bool(const struct device_node *np, | |
1221 | const char *propname) | |
1222 | { | |
1223 | struct property *prop = of_find_property(np, propname, NULL); | |
1224 | ||
1225 | return prop ? true : false; | |
1226 | } | |
1227 | ||
9cbad37c RH |
1228 | /** |
1229 | * of_property_present - Test if a property is present in a node | |
1230 | * @np: device node to search for the property. | |
1231 | * @propname: name of the property to be searched. | |
1232 | * | |
1233 | * Test for a property present in a device node. | |
1234 | * | |
1235 | * Return: true if the property exists false otherwise. | |
1236 | */ | |
1237 | static inline bool of_property_present(const struct device_node *np, const char *propname) | |
1238 | { | |
1239 | return of_property_read_bool(np, propname); | |
1240 | } | |
1241 | ||
2ca42c3a MW |
1242 | /** |
1243 | * of_property_read_u8_array - Find and read an array of u8 from a property. | |
1244 | * | |
1245 | * @np: device node from which the property value is to be read. | |
1246 | * @propname: name of the property to be searched. | |
1247 | * @out_values: pointer to return value, modified only if return value is 0. | |
1248 | * @sz: number of array elements to read | |
1249 | * | |
1250 | * Search for a property in a device node and read 8-bit value(s) from | |
1251 | * it. | |
1252 | * | |
1253 | * dts entry of array should be like: | |
1254 | * ``property = /bits/ 8 <0x50 0x60 0x70>;`` | |
1255 | * | |
1256 | * Return: 0 on success, -EINVAL if the property does not exist, | |
1257 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | |
1258 | * property data isn't large enough. | |
1259 | * | |
1260 | * The out_values is modified only if a valid u8 value can be decoded. | |
1261 | */ | |
1262 | static inline int of_property_read_u8_array(const struct device_node *np, | |
1263 | const char *propname, | |
1264 | u8 *out_values, size_t sz) | |
1265 | { | |
1266 | int ret = of_property_read_variable_u8_array(np, propname, out_values, | |
1267 | sz, 0); | |
1268 | if (ret >= 0) | |
1269 | return 0; | |
1270 | else | |
1271 | return ret; | |
1272 | } | |
1273 | ||
1274 | /** | |
1275 | * of_property_read_u16_array - Find and read an array of u16 from a property. | |
1276 | * | |
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 | |
1281 | * | |
1282 | * Search for a property in a device node and read 16-bit value(s) from | |
1283 | * it. | |
1284 | * | |
1285 | * dts entry of array should be like: | |
1286 | * ``property = /bits/ 16 <0x5000 0x6000 0x7000>;`` | |
1287 | * | |
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. | |
1291 | * | |
1292 | * The out_values is modified only if a valid u16 value can be decoded. | |
1293 | */ | |
1294 | static inline int of_property_read_u16_array(const struct device_node *np, | |
1295 | const char *propname, | |
1296 | u16 *out_values, size_t sz) | |
1297 | { | |
1298 | int ret = of_property_read_variable_u16_array(np, propname, out_values, | |
1299 | sz, 0); | |
1300 | if (ret >= 0) | |
1301 | return 0; | |
1302 | else | |
1303 | return ret; | |
1304 | } | |
1305 | ||
1306 | /** | |
1307 | * of_property_read_u32_array - Find and read an array of 32 bit integers | |
1308 | * from a property. | |
1309 | * | |
1310 | * @np: device node from which the property value is to be read. | |
1311 | * @propname: name of the property to be searched. | |
1312 | * @out_values: pointer to return value, modified only if return value is 0. | |
1313 | * @sz: number of array elements to read | |
1314 | * | |
1315 | * Search for a property in a device node and read 32-bit value(s) from | |
1316 | * it. | |
1317 | * | |
1318 | * Return: 0 on success, -EINVAL if the property does not exist, | |
1319 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | |
1320 | * property data isn't large enough. | |
1321 | * | |
1322 | * The out_values is modified only if a valid u32 value can be decoded. | |
1323 | */ | |
1324 | static inline int of_property_read_u32_array(const struct device_node *np, | |
1325 | const char *propname, | |
1326 | u32 *out_values, size_t sz) | |
1327 | { | |
1328 | int ret = of_property_read_variable_u32_array(np, propname, out_values, | |
1329 | sz, 0); | |
1330 | if (ret >= 0) | |
1331 | return 0; | |
1332 | else | |
1333 | return ret; | |
1334 | } | |
1335 | ||
1336 | /** | |
1337 | * of_property_read_u64_array - Find and read an array of 64 bit integers | |
1338 | * from a property. | |
1339 | * | |
1340 | * @np: device node from which the property value is to be read. | |
1341 | * @propname: name of the property to be searched. | |
1342 | * @out_values: pointer to return value, modified only if return value is 0. | |
1343 | * @sz: number of array elements to read | |
1344 | * | |
1345 | * Search for a property in a device node and read 64-bit value(s) from | |
1346 | * it. | |
1347 | * | |
1348 | * Return: 0 on success, -EINVAL if the property does not exist, | |
1349 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | |
1350 | * property data isn't large enough. | |
1351 | * | |
1352 | * The out_values is modified only if a valid u64 value can be decoded. | |
1353 | */ | |
1354 | static inline int of_property_read_u64_array(const struct device_node *np, | |
1355 | const char *propname, | |
1356 | u64 *out_values, size_t sz) | |
1357 | { | |
1358 | int ret = of_property_read_variable_u64_array(np, propname, out_values, | |
1359 | sz, 0); | |
1360 | if (ret >= 0) | |
1361 | return 0; | |
1362 | else | |
1363 | return ret; | |
1364 | } | |
1365 | ||
be193249 VK |
1366 | static inline int of_property_read_u8(const struct device_node *np, |
1367 | const char *propname, | |
1368 | u8 *out_value) | |
1369 | { | |
1370 | return of_property_read_u8_array(np, propname, out_value, 1); | |
1371 | } | |
1372 | ||
1373 | static inline int of_property_read_u16(const struct device_node *np, | |
1374 | const char *propname, | |
1375 | u16 *out_value) | |
1376 | { | |
1377 | return of_property_read_u16_array(np, propname, out_value, 1); | |
1378 | } | |
1379 | ||
b98c0239 | 1380 | static inline int of_property_read_u32(const struct device_node *np, |
aac285c6 | 1381 | const char *propname, |
b98c0239 SG |
1382 | u32 *out_value) |
1383 | { | |
1384 | return of_property_read_u32_array(np, propname, out_value, 1); | |
1385 | } | |
1386 | ||
e7a00e42 SR |
1387 | static inline int of_property_read_s32(const struct device_node *np, |
1388 | const char *propname, | |
1389 | s32 *out_value) | |
1390 | { | |
1391 | return of_property_read_u32(np, propname, (u32*) out_value); | |
1392 | } | |
1393 | ||
f623ce95 JR |
1394 | #define of_for_each_phandle(it, err, np, ln, cn, cc) \ |
1395 | for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \ | |
1396 | err = of_phandle_iterator_next(it); \ | |
1397 | err == 0; \ | |
1398 | err = of_phandle_iterator_next(it)) | |
1399 | ||
2adfffa2 SAS |
1400 | #define of_property_for_each_u32(np, propname, prop, p, u) \ |
1401 | for (prop = of_find_property(np, propname, NULL), \ | |
1402 | p = of_prop_next_u32(prop, NULL, &u); \ | |
1403 | p; \ | |
1404 | p = of_prop_next_u32(prop, p, &u)) | |
1405 | ||
1406 | #define of_property_for_each_string(np, propname, prop, s) \ | |
1407 | for (prop = of_find_property(np, propname, NULL), \ | |
1408 | s = of_prop_next_string(prop, NULL); \ | |
1409 | s; \ | |
1410 | s = of_prop_next_string(prop, s)) | |
1411 | ||
662372e4 RH |
1412 | #define for_each_node_by_name(dn, name) \ |
1413 | for (dn = of_find_node_by_name(NULL, name); dn; \ | |
1414 | dn = of_find_node_by_name(dn, name)) | |
1415 | #define for_each_node_by_type(dn, type) \ | |
1416 | for (dn = of_find_node_by_type(NULL, type); dn; \ | |
1417 | dn = of_find_node_by_type(dn, type)) | |
1418 | #define for_each_compatible_node(dn, type, compatible) \ | |
1419 | for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ | |
1420 | dn = of_find_compatible_node(dn, type, compatible)) | |
1421 | #define for_each_matching_node(dn, matches) \ | |
1422 | for (dn = of_find_matching_node(NULL, matches); dn; \ | |
1423 | dn = of_find_matching_node(dn, matches)) | |
1424 | #define for_each_matching_node_and_match(dn, matches, match) \ | |
1425 | for (dn = of_find_matching_node_and_match(NULL, matches, match); \ | |
1426 | dn; dn = of_find_matching_node_and_match(dn, matches, match)) | |
1427 | ||
1428 | #define for_each_child_of_node(parent, child) \ | |
1429 | for (child = of_get_next_child(parent, NULL); child != NULL; \ | |
1430 | child = of_get_next_child(parent, child)) | |
1431 | #define for_each_available_child_of_node(parent, child) \ | |
1432 | for (child = of_get_next_available_child(parent, NULL); child != NULL; \ | |
1433 | child = of_get_next_available_child(parent, child)) | |
1434 | ||
f1f207e4 RH |
1435 | #define for_each_of_cpu_node(cpu) \ |
1436 | for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \ | |
1437 | cpu = of_get_next_cpu_node(cpu)) | |
1438 | ||
662372e4 RH |
1439 | #define for_each_node_with_property(dn, prop_name) \ |
1440 | for (dn = of_find_node_with_property(NULL, prop_name); dn; \ | |
1441 | dn = of_find_node_with_property(dn, prop_name)) | |
1442 | ||
1443 | static inline int of_get_child_count(const struct device_node *np) | |
1444 | { | |
1445 | struct device_node *child; | |
1446 | int num = 0; | |
1447 | ||
1448 | for_each_child_of_node(np, child) | |
1449 | num++; | |
1450 | ||
1451 | return num; | |
1452 | } | |
1453 | ||
1454 | static inline int of_get_available_child_count(const struct device_node *np) | |
1455 | { | |
1456 | struct device_node *child; | |
1457 | int num = 0; | |
1458 | ||
1459 | for_each_available_child_of_node(np, child) | |
1460 | num++; | |
1461 | ||
1462 | return num; | |
1463 | } | |
1464 | ||
67a066b3 DO |
1465 | #define _OF_DECLARE_STUB(table, name, compat, fn, fn_type) \ |
1466 | static const struct of_device_id __of_table_##name \ | |
1467 | __attribute__((unused)) \ | |
1468 | = { .compatible = compat, \ | |
1469 | .data = (fn == (fn_type)NULL) ? fn : fn } | |
1470 | ||
71f50c6d | 1471 | #if defined(CONFIG_OF) && !defined(MODULE) |
54196ccb RH |
1472 | #define _OF_DECLARE(table, name, compat, fn, fn_type) \ |
1473 | static const struct of_device_id __of_table_##name \ | |
33def849 | 1474 | __used __section("__" #table "_of_table") \ |
5812b32e | 1475 | __aligned(__alignof__(struct of_device_id)) \ |
54196ccb RH |
1476 | = { .compatible = compat, \ |
1477 | .data = (fn == (fn_type)NULL) ? fn : fn } | |
1478 | #else | |
5f563585 | 1479 | #define _OF_DECLARE(table, name, compat, fn, fn_type) \ |
67a066b3 | 1480 | _OF_DECLARE_STUB(table, name, compat, fn, fn_type) |
54196ccb RH |
1481 | #endif |
1482 | ||
1483 | typedef int (*of_init_fn_2)(struct device_node *, struct device_node *); | |
c35d9292 | 1484 | typedef int (*of_init_fn_1_ret)(struct device_node *); |
54196ccb RH |
1485 | typedef void (*of_init_fn_1)(struct device_node *); |
1486 | ||
1487 | #define OF_DECLARE_1(table, name, compat, fn) \ | |
1488 | _OF_DECLARE(table, name, compat, fn, of_init_fn_1) | |
c35d9292 DL |
1489 | #define OF_DECLARE_1_RET(table, name, compat, fn) \ |
1490 | _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret) | |
54196ccb RH |
1491 | #define OF_DECLARE_2(table, name, compat, fn) \ |
1492 | _OF_DECLARE(table, name, compat, fn, of_init_fn_2) | |
1493 | ||
201c910b PA |
1494 | /** |
1495 | * struct of_changeset_entry - Holds a changeset entry | |
1496 | * | |
1497 | * @node: list_head for the log list | |
1498 | * @action: notifier action | |
1499 | * @np: pointer to the device node affected | |
1500 | * @prop: pointer to the property affected | |
1501 | * @old_prop: hold a pointer to the original property | |
1502 | * | |
1503 | * Every modification of the device tree during a changeset | |
1504 | * is held in a list of of_changeset_entry structures. | |
1505 | * That way we can recover from a partial application, or we can | |
1506 | * revert the changeset | |
1507 | */ | |
1508 | struct of_changeset_entry { | |
1509 | struct list_head node; | |
1510 | unsigned long action; | |
1511 | struct device_node *np; | |
1512 | struct property *prop; | |
1513 | struct property *old_prop; | |
1514 | }; | |
1515 | ||
1516 | /** | |
1517 | * struct of_changeset - changeset tracker structure | |
1518 | * | |
1519 | * @entries: list_head for the changeset entries | |
1520 | * | |
1521 | * changesets are a convenient way to apply bulk changes to the | |
1522 | * live tree. In case of an error, changes are rolled-back. | |
1523 | * changesets live on after initial application, and if not | |
1524 | * destroyed after use, they can be reverted in one single call. | |
1525 | */ | |
1526 | struct of_changeset { | |
1527 | struct list_head entries; | |
1528 | }; | |
1529 | ||
b53a2340 PA |
1530 | enum of_reconfig_change { |
1531 | OF_RECONFIG_NO_CHANGE = 0, | |
1532 | OF_RECONFIG_CHANGE_ADD, | |
1533 | OF_RECONFIG_CHANGE_REMOVE, | |
1534 | }; | |
1535 | ||
2e8fff66 RH |
1536 | struct notifier_block; |
1537 | ||
201c910b | 1538 | #ifdef CONFIG_OF_DYNAMIC |
f6892d19 GL |
1539 | extern int of_reconfig_notifier_register(struct notifier_block *); |
1540 | extern int of_reconfig_notifier_unregister(struct notifier_block *); | |
f5242e5a GL |
1541 | extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd); |
1542 | extern int of_reconfig_get_state_change(unsigned long action, | |
1543 | struct of_reconfig_data *arg); | |
f6892d19 | 1544 | |
201c910b PA |
1545 | extern void of_changeset_init(struct of_changeset *ocs); |
1546 | extern void of_changeset_destroy(struct of_changeset *ocs); | |
1547 | extern int of_changeset_apply(struct of_changeset *ocs); | |
1548 | extern int of_changeset_revert(struct of_changeset *ocs); | |
1549 | extern int of_changeset_action(struct of_changeset *ocs, | |
1550 | unsigned long action, struct device_node *np, | |
1551 | struct property *prop); | |
1552 | ||
1553 | static inline int of_changeset_attach_node(struct of_changeset *ocs, | |
1554 | struct device_node *np) | |
1555 | { | |
1556 | return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL); | |
1557 | } | |
1558 | ||
1559 | static inline int of_changeset_detach_node(struct of_changeset *ocs, | |
1560 | struct device_node *np) | |
1561 | { | |
1562 | return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL); | |
1563 | } | |
1564 | ||
1565 | static inline int of_changeset_add_property(struct of_changeset *ocs, | |
1566 | struct device_node *np, struct property *prop) | |
1567 | { | |
1568 | return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop); | |
1569 | } | |
1570 | ||
1571 | static inline int of_changeset_remove_property(struct of_changeset *ocs, | |
1572 | struct device_node *np, struct property *prop) | |
1573 | { | |
1574 | return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop); | |
1575 | } | |
1576 | ||
1577 | static inline int of_changeset_update_property(struct of_changeset *ocs, | |
1578 | struct device_node *np, struct property *prop) | |
1579 | { | |
1580 | return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop); | |
1581 | } | |
b544fc2b LH |
1582 | |
1583 | struct device_node *of_changeset_create_node(struct of_changeset *ocs, | |
1584 | struct device_node *parent, | |
1585 | const char *full_name); | |
1586 | int of_changeset_add_prop_string(struct of_changeset *ocs, | |
1587 | struct device_node *np, | |
1588 | const char *prop_name, const char *str); | |
1589 | int of_changeset_add_prop_string_array(struct of_changeset *ocs, | |
1590 | struct device_node *np, | |
1591 | const char *prop_name, | |
1592 | const char **str_array, size_t sz); | |
1593 | int of_changeset_add_prop_u32_array(struct of_changeset *ocs, | |
1594 | struct device_node *np, | |
1595 | const char *prop_name, | |
1596 | const u32 *array, size_t sz); | |
1597 | static inline int of_changeset_add_prop_u32(struct of_changeset *ocs, | |
1598 | struct device_node *np, | |
1599 | const char *prop_name, | |
1600 | const u32 val) | |
1601 | { | |
1602 | return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1); | |
1603 | } | |
1604 | ||
f6892d19 GL |
1605 | #else /* CONFIG_OF_DYNAMIC */ |
1606 | static inline int of_reconfig_notifier_register(struct notifier_block *nb) | |
1607 | { | |
1608 | return -EINVAL; | |
1609 | } | |
1610 | static inline int of_reconfig_notifier_unregister(struct notifier_block *nb) | |
1611 | { | |
1612 | return -EINVAL; | |
1613 | } | |
f5242e5a GL |
1614 | static inline int of_reconfig_notify(unsigned long action, |
1615 | struct of_reconfig_data *arg) | |
f6892d19 GL |
1616 | { |
1617 | return -EINVAL; | |
1618 | } | |
f5242e5a GL |
1619 | static inline int of_reconfig_get_state_change(unsigned long action, |
1620 | struct of_reconfig_data *arg) | |
f6892d19 GL |
1621 | { |
1622 | return -EINVAL; | |
1623 | } | |
1624 | #endif /* CONFIG_OF_DYNAMIC */ | |
201c910b | 1625 | |
a4b4e046 | 1626 | /** |
8f73110f | 1627 | * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node |
a4b4e046 RP |
1628 | * @np: Pointer to the given device_node |
1629 | * | |
8c8239c2 | 1630 | * Return: true if present false otherwise |
a4b4e046 | 1631 | */ |
8f73110f | 1632 | static inline bool of_device_is_system_power_controller(const struct device_node *np) |
a4b4e046 | 1633 | { |
8f73110f | 1634 | return of_property_read_bool(np, "system-power-controller"); |
a4b4e046 RP |
1635 | } |
1636 | ||
c968b89a | 1637 | /* |
7518b589 PA |
1638 | * Overlay support |
1639 | */ | |
1640 | ||
39a842e2 | 1641 | enum of_overlay_notify_action { |
067c0987 FR |
1642 | OF_OVERLAY_INIT = 0, /* kzalloc() of ovcs sets this value */ |
1643 | OF_OVERLAY_PRE_APPLY, | |
39a842e2 AT |
1644 | OF_OVERLAY_POST_APPLY, |
1645 | OF_OVERLAY_PRE_REMOVE, | |
1646 | OF_OVERLAY_POST_REMOVE, | |
1647 | }; | |
1648 | ||
91924d9b | 1649 | static inline const char *of_overlay_action_name(enum of_overlay_notify_action action) |
1ac17586 | 1650 | { |
91924d9b | 1651 | static const char *const of_overlay_action_name[] = { |
1ac17586 FR |
1652 | "init", |
1653 | "pre-apply", | |
1654 | "post-apply", | |
1655 | "pre-remove", | |
1656 | "post-remove", | |
1657 | }; | |
1658 | ||
1659 | return of_overlay_action_name[action]; | |
1660 | } | |
1661 | ||
39a842e2 AT |
1662 | struct of_overlay_notify_data { |
1663 | struct device_node *overlay; | |
1664 | struct device_node *target; | |
1665 | }; | |
1666 | ||
7518b589 PA |
1667 | #ifdef CONFIG_OF_OVERLAY |
1668 | ||
39a751a4 | 1669 | int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, |
47284862 | 1670 | int *ovcs_id, struct device_node *target_base); |
24789c5c | 1671 | int of_overlay_remove(int *ovcs_id); |
0290c4ca | 1672 | int of_overlay_remove_all(void); |
7518b589 | 1673 | |
39a842e2 AT |
1674 | int of_overlay_notifier_register(struct notifier_block *nb); |
1675 | int of_overlay_notifier_unregister(struct notifier_block *nb); | |
1676 | ||
7518b589 PA |
1677 | #else |
1678 | ||
cf60ce92 PP |
1679 | static inline int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, |
1680 | int *ovcs_id, struct device_node *target_base) | |
7518b589 PA |
1681 | { |
1682 | return -ENOTSUPP; | |
1683 | } | |
1684 | ||
24789c5c | 1685 | static inline int of_overlay_remove(int *ovcs_id) |
7518b589 PA |
1686 | { |
1687 | return -ENOTSUPP; | |
1688 | } | |
1689 | ||
0290c4ca | 1690 | static inline int of_overlay_remove_all(void) |
7518b589 PA |
1691 | { |
1692 | return -ENOTSUPP; | |
1693 | } | |
1694 | ||
39a842e2 AT |
1695 | static inline int of_overlay_notifier_register(struct notifier_block *nb) |
1696 | { | |
1697 | return 0; | |
1698 | } | |
1699 | ||
1700 | static inline int of_overlay_notifier_unregister(struct notifier_block *nb) | |
1701 | { | |
1702 | return 0; | |
1703 | } | |
1704 | ||
7518b589 PA |
1705 | #endif |
1706 | ||
76c1ce78 | 1707 | #endif /* _LINUX_OF_H */ |