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