Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 #ifndef _LINUX_OF_H
0003 #define _LINUX_OF_H
0004 /*
0005  * Definitions for talking to the Open Firmware PROM on
0006  * Power Macintosh and other computers.
0007  *
0008  * Copyright (C) 1996-2005 Paul Mackerras.
0009  *
0010  * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
0011  * Updates for SPARC64 by David S. Miller
0012  * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
0013  */
0014 #include <linux/types.h>
0015 #include <linux/bitops.h>
0016 #include <linux/errno.h>
0017 #include <linux/kobject.h>
0018 #include <linux/mod_devicetable.h>
0019 #include <linux/spinlock.h>
0020 #include <linux/topology.h>
0021 #include <linux/notifier.h>
0022 #include <linux/property.h>
0023 #include <linux/list.h>
0024 
0025 #include <asm/byteorder.h>
0026 #include <asm/errno.h>
0027 
0028 typedef u32 phandle;
0029 typedef u32 ihandle;
0030 
0031 struct property {
0032     char    *name;
0033     int length;
0034     void    *value;
0035     struct property *next;
0036 #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
0037     unsigned long _flags;
0038 #endif
0039 #if defined(CONFIG_OF_PROMTREE)
0040     unsigned int unique_id;
0041 #endif
0042 #if defined(CONFIG_OF_KOBJ)
0043     struct bin_attribute attr;
0044 #endif
0045 };
0046 
0047 #if defined(CONFIG_SPARC)
0048 struct of_irq_controller;
0049 #endif
0050 
0051 struct device_node {
0052     const char *name;
0053     phandle phandle;
0054     const char *full_name;
0055     struct fwnode_handle fwnode;
0056 
0057     struct  property *properties;
0058     struct  property *deadprops;    /* removed properties */
0059     struct  device_node *parent;
0060     struct  device_node *child;
0061     struct  device_node *sibling;
0062 #if defined(CONFIG_OF_KOBJ)
0063     struct  kobject kobj;
0064 #endif
0065     unsigned long _flags;
0066     void    *data;
0067 #if defined(CONFIG_SPARC)
0068     unsigned int unique_id;
0069     struct of_irq_controller *irq_trans;
0070 #endif
0071 };
0072 
0073 #define MAX_PHANDLE_ARGS 16
0074 struct of_phandle_args {
0075     struct device_node *np;
0076     int args_count;
0077     uint32_t args[MAX_PHANDLE_ARGS];
0078 };
0079 
0080 struct of_phandle_iterator {
0081     /* Common iterator information */
0082     const char *cells_name;
0083     int cell_count;
0084     const struct device_node *parent;
0085 
0086     /* List size information */
0087     const __be32 *list_end;
0088     const __be32 *phandle_end;
0089 
0090     /* Current position state */
0091     const __be32 *cur;
0092     uint32_t cur_count;
0093     phandle phandle;
0094     struct device_node *node;
0095 };
0096 
0097 struct of_reconfig_data {
0098     struct device_node  *dn;
0099     struct property     *prop;
0100     struct property     *old_prop;
0101 };
0102 
0103 /* initialize a node */
0104 extern struct kobj_type of_node_ktype;
0105 extern const struct fwnode_operations of_fwnode_ops;
0106 static inline void of_node_init(struct device_node *node)
0107 {
0108 #if defined(CONFIG_OF_KOBJ)
0109     kobject_init(&node->kobj, &of_node_ktype);
0110 #endif
0111     fwnode_init(&node->fwnode, &of_fwnode_ops);
0112 }
0113 
0114 #if defined(CONFIG_OF_KOBJ)
0115 #define of_node_kobj(n) (&(n)->kobj)
0116 #else
0117 #define of_node_kobj(n) NULL
0118 #endif
0119 
0120 #ifdef CONFIG_OF_DYNAMIC
0121 extern struct device_node *of_node_get(struct device_node *node);
0122 extern void of_node_put(struct device_node *node);
0123 #else /* CONFIG_OF_DYNAMIC */
0124 /* Dummy ref counting routines - to be implemented later */
0125 static inline struct device_node *of_node_get(struct device_node *node)
0126 {
0127     return node;
0128 }
0129 static inline void of_node_put(struct device_node *node) { }
0130 #endif /* !CONFIG_OF_DYNAMIC */
0131 
0132 /* Pointer for first entry in chain of all nodes. */
0133 extern struct device_node *of_root;
0134 extern struct device_node *of_chosen;
0135 extern struct device_node *of_aliases;
0136 extern struct device_node *of_stdout;
0137 extern raw_spinlock_t devtree_lock;
0138 
0139 /*
0140  * struct device_node flag descriptions
0141  * (need to be visible even when !CONFIG_OF)
0142  */
0143 #define OF_DYNAMIC      1 /* (and properties) allocated via kmalloc */
0144 #define OF_DETACHED     2 /* detached from the device tree */
0145 #define OF_POPULATED        3 /* device already created */
0146 #define OF_POPULATED_BUS    4 /* platform bus created for children */
0147 #define OF_OVERLAY      5 /* allocated for an overlay */
0148 #define OF_OVERLAY_FREE_CSET    6 /* in overlay cset being freed */
0149 
0150 #define OF_BAD_ADDR ((u64)-1)
0151 
0152 #ifdef CONFIG_OF
0153 void of_core_init(void);
0154 
0155 static inline bool is_of_node(const struct fwnode_handle *fwnode)
0156 {
0157     return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops;
0158 }
0159 
0160 #define to_of_node(__fwnode)                        \
0161     ({                              \
0162         typeof(__fwnode) __to_of_node_fwnode = (__fwnode);  \
0163                                     \
0164         is_of_node(__to_of_node_fwnode) ?           \
0165             container_of(__to_of_node_fwnode,       \
0166                      struct device_node, fwnode) :  \
0167             NULL;                       \
0168     })
0169 
0170 #define of_fwnode_handle(node)                      \
0171     ({                              \
0172         typeof(node) __of_fwnode_handle_node = (node);      \
0173                                     \
0174         __of_fwnode_handle_node ?               \
0175             &__of_fwnode_handle_node->fwnode : NULL;    \
0176     })
0177 
0178 static inline bool of_have_populated_dt(void)
0179 {
0180     return of_root != NULL;
0181 }
0182 
0183 static inline bool of_node_is_root(const struct device_node *node)
0184 {
0185     return node && (node->parent == NULL);
0186 }
0187 
0188 static inline int of_node_check_flag(const struct device_node *n, unsigned long flag)
0189 {
0190     return test_bit(flag, &n->_flags);
0191 }
0192 
0193 static inline int of_node_test_and_set_flag(struct device_node *n,
0194                         unsigned long flag)
0195 {
0196     return test_and_set_bit(flag, &n->_flags);
0197 }
0198 
0199 static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
0200 {
0201     set_bit(flag, &n->_flags);
0202 }
0203 
0204 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
0205 {
0206     clear_bit(flag, &n->_flags);
0207 }
0208 
0209 #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
0210 static inline int of_property_check_flag(const struct property *p, unsigned long flag)
0211 {
0212     return test_bit(flag, &p->_flags);
0213 }
0214 
0215 static inline void of_property_set_flag(struct property *p, unsigned long flag)
0216 {
0217     set_bit(flag, &p->_flags);
0218 }
0219 
0220 static inline void of_property_clear_flag(struct property *p, unsigned long flag)
0221 {
0222     clear_bit(flag, &p->_flags);
0223 }
0224 #endif
0225 
0226 extern struct device_node *__of_find_all_nodes(struct device_node *prev);
0227 extern struct device_node *of_find_all_nodes(struct device_node *prev);
0228 
0229 /*
0230  * OF address retrieval & translation
0231  */
0232 
0233 /* Helper to read a big number; size is in cells (not bytes) */
0234 static inline u64 of_read_number(const __be32 *cell, int size)
0235 {
0236     u64 r = 0;
0237     for (; size--; cell++)
0238         r = (r << 32) | be32_to_cpu(*cell);
0239     return r;
0240 }
0241 
0242 /* Like of_read_number, but we want an unsigned long result */
0243 static inline unsigned long of_read_ulong(const __be32 *cell, int size)
0244 {
0245     /* toss away upper bits if unsigned long is smaller than u64 */
0246     return of_read_number(cell, size);
0247 }
0248 
0249 #if defined(CONFIG_SPARC)
0250 #include <asm/prom.h>
0251 #endif
0252 
0253 #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
0254 #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
0255 
0256 extern bool of_node_name_eq(const struct device_node *np, const char *name);
0257 extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);
0258 
0259 static inline const char *of_node_full_name(const struct device_node *np)
0260 {
0261     return np ? np->full_name : "<no-node>";
0262 }
0263 
0264 #define for_each_of_allnodes_from(from, dn) \
0265     for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn))
0266 #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
0267 extern struct device_node *of_find_node_by_name(struct device_node *from,
0268     const char *name);
0269 extern struct device_node *of_find_node_by_type(struct device_node *from,
0270     const char *type);
0271 extern struct device_node *of_find_compatible_node(struct device_node *from,
0272     const char *type, const char *compat);
0273 extern struct device_node *of_find_matching_node_and_match(
0274     struct device_node *from,
0275     const struct of_device_id *matches,
0276     const struct of_device_id **match);
0277 
0278 extern struct device_node *of_find_node_opts_by_path(const char *path,
0279     const char **opts);
0280 static inline struct device_node *of_find_node_by_path(const char *path)
0281 {
0282     return of_find_node_opts_by_path(path, NULL);
0283 }
0284 
0285 extern struct device_node *of_find_node_by_phandle(phandle handle);
0286 extern struct device_node *of_get_parent(const struct device_node *node);
0287 extern struct device_node *of_get_next_parent(struct device_node *node);
0288 extern struct device_node *of_get_next_child(const struct device_node *node,
0289                          struct device_node *prev);
0290 extern struct device_node *of_get_next_available_child(
0291     const struct device_node *node, struct device_node *prev);
0292 
0293 extern struct device_node *of_get_compatible_child(const struct device_node *parent,
0294                     const char *compatible);
0295 extern struct device_node *of_get_child_by_name(const struct device_node *node,
0296                     const char *name);
0297 
0298 /* cache lookup */
0299 extern struct device_node *of_find_next_cache_node(const struct device_node *);
0300 extern int of_find_last_cache_level(unsigned int cpu);
0301 extern struct device_node *of_find_node_with_property(
0302     struct device_node *from, const char *prop_name);
0303 
0304 extern struct property *of_find_property(const struct device_node *np,
0305                      const char *name,
0306                      int *lenp);
0307 extern int of_property_count_elems_of_size(const struct device_node *np,
0308                 const char *propname, int elem_size);
0309 extern int of_property_read_u32_index(const struct device_node *np,
0310                        const char *propname,
0311                        u32 index, u32 *out_value);
0312 extern int of_property_read_u64_index(const struct device_node *np,
0313                        const char *propname,
0314                        u32 index, u64 *out_value);
0315 extern int of_property_read_variable_u8_array(const struct device_node *np,
0316                     const char *propname, u8 *out_values,
0317                     size_t sz_min, size_t sz_max);
0318 extern int of_property_read_variable_u16_array(const struct device_node *np,
0319                     const char *propname, u16 *out_values,
0320                     size_t sz_min, size_t sz_max);
0321 extern int of_property_read_variable_u32_array(const struct device_node *np,
0322                     const char *propname,
0323                     u32 *out_values,
0324                     size_t sz_min,
0325                     size_t sz_max);
0326 extern int of_property_read_u64(const struct device_node *np,
0327                 const char *propname, u64 *out_value);
0328 extern int of_property_read_variable_u64_array(const struct device_node *np,
0329                     const char *propname,
0330                     u64 *out_values,
0331                     size_t sz_min,
0332                     size_t sz_max);
0333 
0334 extern int of_property_read_string(const struct device_node *np,
0335                    const char *propname,
0336                    const char **out_string);
0337 extern int of_property_match_string(const struct device_node *np,
0338                     const char *propname,
0339                     const char *string);
0340 extern int of_property_read_string_helper(const struct device_node *np,
0341                           const char *propname,
0342                           const char **out_strs, size_t sz, int index);
0343 extern int of_device_is_compatible(const struct device_node *device,
0344                    const char *);
0345 extern int of_device_compatible_match(struct device_node *device,
0346                       const char *const *compat);
0347 extern bool of_device_is_available(const struct device_node *device);
0348 extern bool of_device_is_big_endian(const struct device_node *device);
0349 extern const void *of_get_property(const struct device_node *node,
0350                 const char *name,
0351                 int *lenp);
0352 extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
0353 extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
0354 extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
0355                          int index);
0356 extern u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread);
0357 
0358 #define for_each_property_of_node(dn, pp) \
0359     for (pp = dn->properties; pp != NULL; pp = pp->next)
0360 
0361 extern int of_n_addr_cells(struct device_node *np);
0362 extern int of_n_size_cells(struct device_node *np);
0363 extern const struct of_device_id *of_match_node(
0364     const struct of_device_id *matches, const struct device_node *node);
0365 extern int of_modalias_node(struct device_node *node, char *modalias, int len);
0366 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
0367 extern int __of_parse_phandle_with_args(const struct device_node *np,
0368     const char *list_name, const char *cells_name, int cell_count,
0369     int index, struct of_phandle_args *out_args);
0370 extern int of_parse_phandle_with_args_map(const struct device_node *np,
0371     const char *list_name, const char *stem_name, int index,
0372     struct of_phandle_args *out_args);
0373 extern int of_count_phandle_with_args(const struct device_node *np,
0374     const char *list_name, const char *cells_name);
0375 
0376 /* phandle iterator functions */
0377 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
0378                     const struct device_node *np,
0379                     const char *list_name,
0380                     const char *cells_name,
0381                     int cell_count);
0382 
0383 extern int of_phandle_iterator_next(struct of_phandle_iterator *it);
0384 extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
0385                     uint32_t *args,
0386                     int size);
0387 
0388 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
0389 extern int of_alias_get_id(struct device_node *np, const char *stem);
0390 extern int of_alias_get_highest_id(const char *stem);
0391 
0392 extern int of_machine_is_compatible(const char *compat);
0393 
0394 extern int of_add_property(struct device_node *np, struct property *prop);
0395 extern int of_remove_property(struct device_node *np, struct property *prop);
0396 extern int of_update_property(struct device_node *np, struct property *newprop);
0397 
0398 /* For updating the device tree at runtime */
0399 #define OF_RECONFIG_ATTACH_NODE     0x0001
0400 #define OF_RECONFIG_DETACH_NODE     0x0002
0401 #define OF_RECONFIG_ADD_PROPERTY    0x0003
0402 #define OF_RECONFIG_REMOVE_PROPERTY 0x0004
0403 #define OF_RECONFIG_UPDATE_PROPERTY 0x0005
0404 
0405 extern int of_attach_node(struct device_node *);
0406 extern int of_detach_node(struct device_node *);
0407 
0408 #define of_match_ptr(_ptr)  (_ptr)
0409 
0410 /*
0411  * struct property *prop;
0412  * const __be32 *p;
0413  * u32 u;
0414  *
0415  * of_property_for_each_u32(np, "propname", prop, p, u)
0416  *         printk("U32 value: %x\n", u);
0417  */
0418 const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
0419                    u32 *pu);
0420 /*
0421  * struct property *prop;
0422  * const char *s;
0423  *
0424  * of_property_for_each_string(np, "propname", prop, s)
0425  *         printk("String value: %s\n", s);
0426  */
0427 const char *of_prop_next_string(struct property *prop, const char *cur);
0428 
0429 bool of_console_check(struct device_node *dn, char *name, int index);
0430 
0431 extern int of_cpu_node_to_id(struct device_node *np);
0432 
0433 int of_map_id(struct device_node *np, u32 id,
0434            const char *map_name, const char *map_mask_name,
0435            struct device_node **target, u32 *id_out);
0436 
0437 phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
0438 
0439 struct kimage;
0440 void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
0441                    unsigned long initrd_load_addr,
0442                    unsigned long initrd_len,
0443                    const char *cmdline, size_t extra_fdt_size);
0444 #else /* CONFIG_OF */
0445 
0446 static inline void of_core_init(void)
0447 {
0448 }
0449 
0450 static inline bool is_of_node(const struct fwnode_handle *fwnode)
0451 {
0452     return false;
0453 }
0454 
0455 static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
0456 {
0457     return NULL;
0458 }
0459 
0460 static inline bool of_node_name_eq(const struct device_node *np, const char *name)
0461 {
0462     return false;
0463 }
0464 
0465 static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
0466 {
0467     return false;
0468 }
0469 
0470 static inline const char* of_node_full_name(const struct device_node *np)
0471 {
0472     return "<no-node>";
0473 }
0474 
0475 static inline struct device_node *of_find_node_by_name(struct device_node *from,
0476     const char *name)
0477 {
0478     return NULL;
0479 }
0480 
0481 static inline struct device_node *of_find_node_by_type(struct device_node *from,
0482     const char *type)
0483 {
0484     return NULL;
0485 }
0486 
0487 static inline struct device_node *of_find_matching_node_and_match(
0488     struct device_node *from,
0489     const struct of_device_id *matches,
0490     const struct of_device_id **match)
0491 {
0492     return NULL;
0493 }
0494 
0495 static inline struct device_node *of_find_node_by_path(const char *path)
0496 {
0497     return NULL;
0498 }
0499 
0500 static inline struct device_node *of_find_node_opts_by_path(const char *path,
0501     const char **opts)
0502 {
0503     return NULL;
0504 }
0505 
0506 static inline struct device_node *of_find_node_by_phandle(phandle handle)
0507 {
0508     return NULL;
0509 }
0510 
0511 static inline struct device_node *of_get_parent(const struct device_node *node)
0512 {
0513     return NULL;
0514 }
0515 
0516 static inline struct device_node *of_get_next_parent(struct device_node *node)
0517 {
0518     return NULL;
0519 }
0520 
0521 static inline struct device_node *of_get_next_child(
0522     const struct device_node *node, struct device_node *prev)
0523 {
0524     return NULL;
0525 }
0526 
0527 static inline struct device_node *of_get_next_available_child(
0528     const struct device_node *node, struct device_node *prev)
0529 {
0530     return NULL;
0531 }
0532 
0533 static inline struct device_node *of_find_node_with_property(
0534     struct device_node *from, const char *prop_name)
0535 {
0536     return NULL;
0537 }
0538 
0539 #define of_fwnode_handle(node) NULL
0540 
0541 static inline bool of_have_populated_dt(void)
0542 {
0543     return false;
0544 }
0545 
0546 static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
0547                     const char *compatible)
0548 {
0549     return NULL;
0550 }
0551 
0552 static inline struct device_node *of_get_child_by_name(
0553                     const struct device_node *node,
0554                     const char *name)
0555 {
0556     return NULL;
0557 }
0558 
0559 static inline int of_device_is_compatible(const struct device_node *device,
0560                       const char *name)
0561 {
0562     return 0;
0563 }
0564 
0565 static inline  int of_device_compatible_match(struct device_node *device,
0566                           const char *const *compat)
0567 {
0568     return 0;
0569 }
0570 
0571 static inline bool of_device_is_available(const struct device_node *device)
0572 {
0573     return false;
0574 }
0575 
0576 static inline bool of_device_is_big_endian(const struct device_node *device)
0577 {
0578     return false;
0579 }
0580 
0581 static inline struct property *of_find_property(const struct device_node *np,
0582                         const char *name,
0583                         int *lenp)
0584 {
0585     return NULL;
0586 }
0587 
0588 static inline struct device_node *of_find_compatible_node(
0589                         struct device_node *from,
0590                         const char *type,
0591                         const char *compat)
0592 {
0593     return NULL;
0594 }
0595 
0596 static inline int of_property_count_elems_of_size(const struct device_node *np,
0597             const char *propname, int elem_size)
0598 {
0599     return -ENOSYS;
0600 }
0601 
0602 static inline int of_property_read_u32_index(const struct device_node *np,
0603             const char *propname, u32 index, u32 *out_value)
0604 {
0605     return -ENOSYS;
0606 }
0607 
0608 static inline int of_property_read_u64_index(const struct device_node *np,
0609             const char *propname, u32 index, u64 *out_value)
0610 {
0611     return -ENOSYS;
0612 }
0613 
0614 static inline const void *of_get_property(const struct device_node *node,
0615                 const char *name,
0616                 int *lenp)
0617 {
0618     return NULL;
0619 }
0620 
0621 static inline struct device_node *of_get_cpu_node(int cpu,
0622                     unsigned int *thread)
0623 {
0624     return NULL;
0625 }
0626 
0627 static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
0628 {
0629     return NULL;
0630 }
0631 
0632 static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
0633                     int index)
0634 {
0635     return NULL;
0636 }
0637 
0638 static inline int of_n_addr_cells(struct device_node *np)
0639 {
0640     return 0;
0641 
0642 }
0643 static inline int of_n_size_cells(struct device_node *np)
0644 {
0645     return 0;
0646 }
0647 
0648 static inline int of_property_read_variable_u8_array(const struct device_node *np,
0649                     const char *propname, u8 *out_values,
0650                     size_t sz_min, size_t sz_max)
0651 {
0652     return -ENOSYS;
0653 }
0654 
0655 static inline int of_property_read_variable_u16_array(const struct device_node *np,
0656                     const char *propname, u16 *out_values,
0657                     size_t sz_min, size_t sz_max)
0658 {
0659     return -ENOSYS;
0660 }
0661 
0662 static inline int of_property_read_variable_u32_array(const struct device_node *np,
0663                     const char *propname,
0664                     u32 *out_values,
0665                     size_t sz_min,
0666                     size_t sz_max)
0667 {
0668     return -ENOSYS;
0669 }
0670 
0671 static inline int of_property_read_u64(const struct device_node *np,
0672                        const char *propname, u64 *out_value)
0673 {
0674     return -ENOSYS;
0675 }
0676 
0677 static inline int of_property_read_variable_u64_array(const struct device_node *np,
0678                     const char *propname,
0679                     u64 *out_values,
0680                     size_t sz_min,
0681                     size_t sz_max)
0682 {
0683     return -ENOSYS;
0684 }
0685 
0686 static inline int of_property_read_string(const struct device_node *np,
0687                       const char *propname,
0688                       const char **out_string)
0689 {
0690     return -ENOSYS;
0691 }
0692 
0693 static inline int of_property_match_string(const struct device_node *np,
0694                        const char *propname,
0695                        const char *string)
0696 {
0697     return -ENOSYS;
0698 }
0699 
0700 static inline int of_property_read_string_helper(const struct device_node *np,
0701                          const char *propname,
0702                          const char **out_strs, size_t sz, int index)
0703 {
0704     return -ENOSYS;
0705 }
0706 
0707 static inline int __of_parse_phandle_with_args(const struct device_node *np,
0708                            const char *list_name,
0709                            const char *cells_name,
0710                            int cell_count,
0711                            int index,
0712                            struct of_phandle_args *out_args)
0713 {
0714     return -ENOSYS;
0715 }
0716 
0717 static inline int of_parse_phandle_with_args_map(const struct device_node *np,
0718                          const char *list_name,
0719                          const char *stem_name,
0720                          int index,
0721                          struct of_phandle_args *out_args)
0722 {
0723     return -ENOSYS;
0724 }
0725 
0726 static inline int of_count_phandle_with_args(const struct device_node *np,
0727                          const char *list_name,
0728                          const char *cells_name)
0729 {
0730     return -ENOSYS;
0731 }
0732 
0733 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
0734                        const struct device_node *np,
0735                        const char *list_name,
0736                        const char *cells_name,
0737                        int cell_count)
0738 {
0739     return -ENOSYS;
0740 }
0741 
0742 static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
0743 {
0744     return -ENOSYS;
0745 }
0746 
0747 static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
0748                        uint32_t *args,
0749                        int size)
0750 {
0751     return 0;
0752 }
0753 
0754 static inline int of_alias_get_id(struct device_node *np, const char *stem)
0755 {
0756     return -ENOSYS;
0757 }
0758 
0759 static inline int of_alias_get_highest_id(const char *stem)
0760 {
0761     return -ENOSYS;
0762 }
0763 
0764 static inline int of_machine_is_compatible(const char *compat)
0765 {
0766     return 0;
0767 }
0768 
0769 static inline int of_add_property(struct device_node *np, struct property *prop)
0770 {
0771     return 0;
0772 }
0773 
0774 static inline int of_remove_property(struct device_node *np, struct property *prop)
0775 {
0776     return 0;
0777 }
0778 
0779 static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
0780 {
0781     return false;
0782 }
0783 
0784 static inline const __be32 *of_prop_next_u32(struct property *prop,
0785         const __be32 *cur, u32 *pu)
0786 {
0787     return NULL;
0788 }
0789 
0790 static inline const char *of_prop_next_string(struct property *prop,
0791         const char *cur)
0792 {
0793     return NULL;
0794 }
0795 
0796 static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
0797 {
0798     return 0;
0799 }
0800 
0801 static inline int of_node_test_and_set_flag(struct device_node *n,
0802                         unsigned long flag)
0803 {
0804     return 0;
0805 }
0806 
0807 static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
0808 {
0809 }
0810 
0811 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
0812 {
0813 }
0814 
0815 static inline int of_property_check_flag(const struct property *p,
0816                      unsigned long flag)
0817 {
0818     return 0;
0819 }
0820 
0821 static inline void of_property_set_flag(struct property *p, unsigned long flag)
0822 {
0823 }
0824 
0825 static inline void of_property_clear_flag(struct property *p, unsigned long flag)
0826 {
0827 }
0828 
0829 static inline int of_cpu_node_to_id(struct device_node *np)
0830 {
0831     return -ENODEV;
0832 }
0833 
0834 static inline int of_map_id(struct device_node *np, u32 id,
0835                  const char *map_name, const char *map_mask_name,
0836                  struct device_node **target, u32 *id_out)
0837 {
0838     return -EINVAL;
0839 }
0840 
0841 static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np)
0842 {
0843     return PHYS_ADDR_MAX;
0844 }
0845 
0846 #define of_match_ptr(_ptr)  NULL
0847 #define of_match_node(_matches, _node)  NULL
0848 #endif /* CONFIG_OF */
0849 
0850 /* Default string compare functions, Allow arch asm/prom.h to override */
0851 #if !defined(of_compat_cmp)
0852 #define of_compat_cmp(s1, s2, l)    strcasecmp((s1), (s2))
0853 #define of_prop_cmp(s1, s2)     strcmp((s1), (s2))
0854 #define of_node_cmp(s1, s2)     strcasecmp((s1), (s2))
0855 #endif
0856 
0857 static inline int of_prop_val_eq(struct property *p1, struct property *p2)
0858 {
0859     return p1->length == p2->length &&
0860            !memcmp(p1->value, p2->value, (size_t)p1->length);
0861 }
0862 
0863 #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
0864 extern int of_node_to_nid(struct device_node *np);
0865 #else
0866 static inline int of_node_to_nid(struct device_node *device)
0867 {
0868     return NUMA_NO_NODE;
0869 }
0870 #endif
0871 
0872 #ifdef CONFIG_OF_NUMA
0873 extern int of_numa_init(void);
0874 #else
0875 static inline int of_numa_init(void)
0876 {
0877     return -ENOSYS;
0878 }
0879 #endif
0880 
0881 static inline struct device_node *of_find_matching_node(
0882     struct device_node *from,
0883     const struct of_device_id *matches)
0884 {
0885     return of_find_matching_node_and_match(from, matches, NULL);
0886 }
0887 
0888 static inline const char *of_node_get_device_type(const struct device_node *np)
0889 {
0890     return of_get_property(np, "device_type", NULL);
0891 }
0892 
0893 static inline bool of_node_is_type(const struct device_node *np, const char *type)
0894 {
0895     const char *match = of_node_get_device_type(np);
0896 
0897     return np && match && type && !strcmp(match, type);
0898 }
0899 
0900 /**
0901  * of_parse_phandle - Resolve a phandle property to a device_node pointer
0902  * @np: Pointer to device node holding phandle property
0903  * @phandle_name: Name of property holding a phandle value
0904  * @index: For properties holding a table of phandles, this is the index into
0905  *         the table
0906  *
0907  * Return: The device_node pointer with refcount incremented.  Use
0908  * of_node_put() on it when done.
0909  */
0910 static inline struct device_node *of_parse_phandle(const struct device_node *np,
0911                            const char *phandle_name,
0912                            int index)
0913 {
0914     struct of_phandle_args args;
0915 
0916     if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
0917                      index, &args))
0918         return NULL;
0919 
0920     return args.np;
0921 }
0922 
0923 /**
0924  * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
0925  * @np:     pointer to a device tree node containing a list
0926  * @list_name:  property name that contains a list
0927  * @cells_name: property name that specifies phandles' arguments count
0928  * @index:  index of a phandle to parse out
0929  * @out_args:   optional pointer to output arguments structure (will be filled)
0930  *
0931  * This function is useful to parse lists of phandles and their arguments.
0932  * Returns 0 on success and fills out_args, on error returns appropriate
0933  * errno value.
0934  *
0935  * Caller is responsible to call of_node_put() on the returned out_args->np
0936  * pointer.
0937  *
0938  * Example::
0939  *
0940  *  phandle1: node1 {
0941  *  #list-cells = <2>;
0942  *  };
0943  *
0944  *  phandle2: node2 {
0945  *  #list-cells = <1>;
0946  *  };
0947  *
0948  *  node3 {
0949  *  list = <&phandle1 1 2 &phandle2 3>;
0950  *  };
0951  *
0952  * To get a device_node of the ``node2`` node you may call this:
0953  * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
0954  */
0955 static inline int of_parse_phandle_with_args(const struct device_node *np,
0956                          const char *list_name,
0957                          const char *cells_name,
0958                          int index,
0959                          struct of_phandle_args *out_args)
0960 {
0961     int cell_count = -1;
0962 
0963     /* If cells_name is NULL we assume a cell count of 0 */
0964     if (!cells_name)
0965         cell_count = 0;
0966 
0967     return __of_parse_phandle_with_args(np, list_name, cells_name,
0968                         cell_count, index, out_args);
0969 }
0970 
0971 /**
0972  * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
0973  * @np:     pointer to a device tree node containing a list
0974  * @list_name:  property name that contains a list
0975  * @cell_count: number of argument cells following the phandle
0976  * @index:  index of a phandle to parse out
0977  * @out_args:   optional pointer to output arguments structure (will be filled)
0978  *
0979  * This function is useful to parse lists of phandles and their arguments.
0980  * Returns 0 on success and fills out_args, on error returns appropriate
0981  * errno value.
0982  *
0983  * Caller is responsible to call of_node_put() on the returned out_args->np
0984  * pointer.
0985  *
0986  * Example::
0987  *
0988  *  phandle1: node1 {
0989  *  };
0990  *
0991  *  phandle2: node2 {
0992  *  };
0993  *
0994  *  node3 {
0995  *  list = <&phandle1 0 2 &phandle2 2 3>;
0996  *  };
0997  *
0998  * To get a device_node of the ``node2`` node you may call this:
0999  * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
1000  */
1001 static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
1002                            const char *list_name,
1003                            int cell_count,
1004                            int index,
1005                            struct of_phandle_args *out_args)
1006 {
1007     return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
1008                         index, out_args);
1009 }
1010 
1011 /**
1012  * of_property_count_u8_elems - Count the number of u8 elements in a property
1013  *
1014  * @np:     device node from which the property value is to be read.
1015  * @propname:   name of the property to be searched.
1016  *
1017  * Search for a property in a device node and count the number of u8 elements
1018  * in it.
1019  *
1020  * Return: The number of elements on sucess, -EINVAL if the property does
1021  * not exist or its length does not match a multiple of u8 and -ENODATA if the
1022  * property does not have a value.
1023  */
1024 static inline int of_property_count_u8_elems(const struct device_node *np,
1025                 const char *propname)
1026 {
1027     return of_property_count_elems_of_size(np, propname, sizeof(u8));
1028 }
1029 
1030 /**
1031  * of_property_count_u16_elems - Count the number of u16 elements in a property
1032  *
1033  * @np:     device node from which the property value is to be read.
1034  * @propname:   name of the property to be searched.
1035  *
1036  * Search for a property in a device node and count the number of u16 elements
1037  * in it.
1038  *
1039  * Return: The number of elements on sucess, -EINVAL if the property does
1040  * not exist or its length does not match a multiple of u16 and -ENODATA if the
1041  * property does not have a value.
1042  */
1043 static inline int of_property_count_u16_elems(const struct device_node *np,
1044                 const char *propname)
1045 {
1046     return of_property_count_elems_of_size(np, propname, sizeof(u16));
1047 }
1048 
1049 /**
1050  * of_property_count_u32_elems - Count the number of u32 elements in a property
1051  *
1052  * @np:     device node from which the property value is to be read.
1053  * @propname:   name of the property to be searched.
1054  *
1055  * Search for a property in a device node and count the number of u32 elements
1056  * in it.
1057  *
1058  * Return: The number of elements on sucess, -EINVAL if the property does
1059  * not exist or its length does not match a multiple of u32 and -ENODATA if the
1060  * property does not have a value.
1061  */
1062 static inline int of_property_count_u32_elems(const struct device_node *np,
1063                 const char *propname)
1064 {
1065     return of_property_count_elems_of_size(np, propname, sizeof(u32));
1066 }
1067 
1068 /**
1069  * of_property_count_u64_elems - Count the number of u64 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 u64 elements
1075  * in it.
1076  *
1077  * Return: The number of elements on sucess, -EINVAL if the property does
1078  * not exist or its length does not match a multiple of u64 and -ENODATA if the
1079  * property does not have a value.
1080  */
1081 static inline int of_property_count_u64_elems(const struct device_node *np,
1082                 const char *propname)
1083 {
1084     return of_property_count_elems_of_size(np, propname, sizeof(u64));
1085 }
1086 
1087 /**
1088  * of_property_read_string_array() - Read an array of strings from a multiple
1089  * strings property.
1090  * @np:     device node from which the property value is to be read.
1091  * @propname:   name of the property to be searched.
1092  * @out_strs:   output array of string pointers.
1093  * @sz:     number of array elements to read.
1094  *
1095  * Search for a property in a device tree node and retrieve a list of
1096  * terminated string values (pointer to data, not a copy) in that property.
1097  *
1098  * Return: If @out_strs is NULL, the number of strings in the property is returned.
1099  */
1100 static inline int of_property_read_string_array(const struct device_node *np,
1101                         const char *propname, const char **out_strs,
1102                         size_t sz)
1103 {
1104     return of_property_read_string_helper(np, propname, out_strs, sz, 0);
1105 }
1106 
1107 /**
1108  * of_property_count_strings() - Find and return the number of strings from a
1109  * multiple strings property.
1110  * @np:     device node from which the property value is to be read.
1111  * @propname:   name of the property to be searched.
1112  *
1113  * Search for a property in a device tree node and retrieve the number of null
1114  * terminated string contain in it.
1115  *
1116  * Return: The number of strings on success, -EINVAL if the property does not
1117  * exist, -ENODATA if property does not have a value, and -EILSEQ if the string
1118  * is not null-terminated within the length of the property data.
1119  */
1120 static inline int of_property_count_strings(const struct device_node *np,
1121                         const char *propname)
1122 {
1123     return of_property_read_string_helper(np, propname, NULL, 0, 0);
1124 }
1125 
1126 /**
1127  * of_property_read_string_index() - Find and read a string from a multiple
1128  * strings property.
1129  * @np:     device node from which the property value is to be read.
1130  * @propname:   name of the property to be searched.
1131  * @index:  index of the string in the list of strings
1132  * @output: pointer to null terminated return string, modified only if
1133  *      return value is 0.
1134  *
1135  * Search for a property in a device tree node and retrieve a null
1136  * terminated string value (pointer to data, not a copy) in the list of strings
1137  * contained in that property.
1138  *
1139  * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if
1140  * property does not have a value, and -EILSEQ if the string is not
1141  * null-terminated within the length of the property data.
1142  *
1143  * The out_string pointer is modified only if a valid string can be decoded.
1144  */
1145 static inline int of_property_read_string_index(const struct device_node *np,
1146                         const char *propname,
1147                         int index, const char **output)
1148 {
1149     int rc = of_property_read_string_helper(np, propname, output, 1, index);
1150     return rc < 0 ? rc : 0;
1151 }
1152 
1153 /**
1154  * of_property_read_bool - Find a property
1155  * @np:     device node from which the property value is to be read.
1156  * @propname:   name of the property to be searched.
1157  *
1158  * Search for a property in a device node.
1159  *
1160  * Return: true if the property exists false otherwise.
1161  */
1162 static inline bool of_property_read_bool(const struct device_node *np,
1163                      const char *propname)
1164 {
1165     struct property *prop = of_find_property(np, propname, NULL);
1166 
1167     return prop ? true : false;
1168 }
1169 
1170 /**
1171  * of_property_read_u8_array - Find and read an array of u8 from a property.
1172  *
1173  * @np:     device node from which the property value is to be read.
1174  * @propname:   name of the property to be searched.
1175  * @out_values: pointer to return value, modified only if return value is 0.
1176  * @sz:     number of array elements to read
1177  *
1178  * Search for a property in a device node and read 8-bit value(s) from
1179  * it.
1180  *
1181  * dts entry of array should be like:
1182  *  ``property = /bits/ 8 <0x50 0x60 0x70>;``
1183  *
1184  * Return: 0 on success, -EINVAL if the property does not exist,
1185  * -ENODATA if property does not have a value, and -EOVERFLOW if the
1186  * property data isn't large enough.
1187  *
1188  * The out_values is modified only if a valid u8 value can be decoded.
1189  */
1190 static inline int of_property_read_u8_array(const struct device_node *np,
1191                         const char *propname,
1192                         u8 *out_values, size_t sz)
1193 {
1194     int ret = of_property_read_variable_u8_array(np, propname, out_values,
1195                              sz, 0);
1196     if (ret >= 0)
1197         return 0;
1198     else
1199         return ret;
1200 }
1201 
1202 /**
1203  * of_property_read_u16_array - Find and read an array of u16 from a property.
1204  *
1205  * @np:     device node from which the property value is to be read.
1206  * @propname:   name of the property to be searched.
1207  * @out_values: pointer to return value, modified only if return value is 0.
1208  * @sz:     number of array elements to read
1209  *
1210  * Search for a property in a device node and read 16-bit value(s) from
1211  * it.
1212  *
1213  * dts entry of array should be like:
1214  *  ``property = /bits/ 16 <0x5000 0x6000 0x7000>;``
1215  *
1216  * Return: 0 on success, -EINVAL if the property does not exist,
1217  * -ENODATA if property does not have a value, and -EOVERFLOW if the
1218  * property data isn't large enough.
1219  *
1220  * The out_values is modified only if a valid u16 value can be decoded.
1221  */
1222 static inline int of_property_read_u16_array(const struct device_node *np,
1223                          const char *propname,
1224                          u16 *out_values, size_t sz)
1225 {
1226     int ret = of_property_read_variable_u16_array(np, propname, out_values,
1227                               sz, 0);
1228     if (ret >= 0)
1229         return 0;
1230     else
1231         return ret;
1232 }
1233 
1234 /**
1235  * of_property_read_u32_array - Find and read an array of 32 bit integers
1236  * from a property.
1237  *
1238  * @np:     device node from which the property value is to be read.
1239  * @propname:   name of the property to be searched.
1240  * @out_values: pointer to return value, modified only if return value is 0.
1241  * @sz:     number of array elements to read
1242  *
1243  * Search for a property in a device node and read 32-bit value(s) from
1244  * it.
1245  *
1246  * Return: 0 on success, -EINVAL if the property does not exist,
1247  * -ENODATA if property does not have a value, and -EOVERFLOW if the
1248  * property data isn't large enough.
1249  *
1250  * The out_values is modified only if a valid u32 value can be decoded.
1251  */
1252 static inline int of_property_read_u32_array(const struct device_node *np,
1253                          const char *propname,
1254                          u32 *out_values, size_t sz)
1255 {
1256     int ret = of_property_read_variable_u32_array(np, propname, out_values,
1257                               sz, 0);
1258     if (ret >= 0)
1259         return 0;
1260     else
1261         return ret;
1262 }
1263 
1264 /**
1265  * of_property_read_u64_array - Find and read an array of 64 bit integers
1266  * from a property.
1267  *
1268  * @np:     device node from which the property value is to be read.
1269  * @propname:   name of the property to be searched.
1270  * @out_values: pointer to return value, modified only if return value is 0.
1271  * @sz:     number of array elements to read
1272  *
1273  * Search for a property in a device node and read 64-bit value(s) from
1274  * it.
1275  *
1276  * Return: 0 on success, -EINVAL if the property does not exist,
1277  * -ENODATA if property does not have a value, and -EOVERFLOW if the
1278  * property data isn't large enough.
1279  *
1280  * The out_values is modified only if a valid u64 value can be decoded.
1281  */
1282 static inline int of_property_read_u64_array(const struct device_node *np,
1283                          const char *propname,
1284                          u64 *out_values, size_t sz)
1285 {
1286     int ret = of_property_read_variable_u64_array(np, propname, out_values,
1287                               sz, 0);
1288     if (ret >= 0)
1289         return 0;
1290     else
1291         return ret;
1292 }
1293 
1294 static inline int of_property_read_u8(const struct device_node *np,
1295                        const char *propname,
1296                        u8 *out_value)
1297 {
1298     return of_property_read_u8_array(np, propname, out_value, 1);
1299 }
1300 
1301 static inline int of_property_read_u16(const struct device_node *np,
1302                        const char *propname,
1303                        u16 *out_value)
1304 {
1305     return of_property_read_u16_array(np, propname, out_value, 1);
1306 }
1307 
1308 static inline int of_property_read_u32(const struct device_node *np,
1309                        const char *propname,
1310                        u32 *out_value)
1311 {
1312     return of_property_read_u32_array(np, propname, out_value, 1);
1313 }
1314 
1315 static inline int of_property_read_s32(const struct device_node *np,
1316                        const char *propname,
1317                        s32 *out_value)
1318 {
1319     return of_property_read_u32(np, propname, (u32*) out_value);
1320 }
1321 
1322 #define of_for_each_phandle(it, err, np, ln, cn, cc)            \
1323     for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)),    \
1324          err = of_phandle_iterator_next(it);            \
1325          err == 0;                          \
1326          err = of_phandle_iterator_next(it))
1327 
1328 #define of_property_for_each_u32(np, propname, prop, p, u)  \
1329     for (prop = of_find_property(np, propname, NULL),   \
1330         p = of_prop_next_u32(prop, NULL, &u);       \
1331         p;                      \
1332         p = of_prop_next_u32(prop, p, &u))
1333 
1334 #define of_property_for_each_string(np, propname, prop, s)  \
1335     for (prop = of_find_property(np, propname, NULL),   \
1336         s = of_prop_next_string(prop, NULL);        \
1337         s;                      \
1338         s = of_prop_next_string(prop, s))
1339 
1340 #define for_each_node_by_name(dn, name) \
1341     for (dn = of_find_node_by_name(NULL, name); dn; \
1342          dn = of_find_node_by_name(dn, name))
1343 #define for_each_node_by_type(dn, type) \
1344     for (dn = of_find_node_by_type(NULL, type); dn; \
1345          dn = of_find_node_by_type(dn, type))
1346 #define for_each_compatible_node(dn, type, compatible) \
1347     for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
1348          dn = of_find_compatible_node(dn, type, compatible))
1349 #define for_each_matching_node(dn, matches) \
1350     for (dn = of_find_matching_node(NULL, matches); dn; \
1351          dn = of_find_matching_node(dn, matches))
1352 #define for_each_matching_node_and_match(dn, matches, match) \
1353     for (dn = of_find_matching_node_and_match(NULL, matches, match); \
1354          dn; dn = of_find_matching_node_and_match(dn, matches, match))
1355 
1356 #define for_each_child_of_node(parent, child) \
1357     for (child = of_get_next_child(parent, NULL); child != NULL; \
1358          child = of_get_next_child(parent, child))
1359 #define for_each_available_child_of_node(parent, child) \
1360     for (child = of_get_next_available_child(parent, NULL); child != NULL; \
1361          child = of_get_next_available_child(parent, child))
1362 
1363 #define for_each_of_cpu_node(cpu) \
1364     for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
1365          cpu = of_get_next_cpu_node(cpu))
1366 
1367 #define for_each_node_with_property(dn, prop_name) \
1368     for (dn = of_find_node_with_property(NULL, prop_name); dn; \
1369          dn = of_find_node_with_property(dn, prop_name))
1370 
1371 static inline int of_get_child_count(const struct device_node *np)
1372 {
1373     struct device_node *child;
1374     int num = 0;
1375 
1376     for_each_child_of_node(np, child)
1377         num++;
1378 
1379     return num;
1380 }
1381 
1382 static inline int of_get_available_child_count(const struct device_node *np)
1383 {
1384     struct device_node *child;
1385     int num = 0;
1386 
1387     for_each_available_child_of_node(np, child)
1388         num++;
1389 
1390     return num;
1391 }
1392 
1393 #define _OF_DECLARE_STUB(table, name, compat, fn, fn_type)      \
1394     static const struct of_device_id __of_table_##name      \
1395         __attribute__((unused))                 \
1396          = { .compatible = compat,              \
1397              .data = (fn == (fn_type)NULL) ? fn : fn }
1398 
1399 #if defined(CONFIG_OF) && !defined(MODULE)
1400 #define _OF_DECLARE(table, name, compat, fn, fn_type)           \
1401     static const struct of_device_id __of_table_##name      \
1402         __used __section("__" #table "_of_table")       \
1403         __aligned(__alignof__(struct of_device_id))     \
1404          = { .compatible = compat,              \
1405              .data = (fn == (fn_type)NULL) ? fn : fn  }
1406 #else
1407 #define _OF_DECLARE(table, name, compat, fn, fn_type)           \
1408     _OF_DECLARE_STUB(table, name, compat, fn, fn_type)
1409 #endif
1410 
1411 typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
1412 typedef int (*of_init_fn_1_ret)(struct device_node *);
1413 typedef void (*of_init_fn_1)(struct device_node *);
1414 
1415 #define OF_DECLARE_1(table, name, compat, fn) \
1416         _OF_DECLARE(table, name, compat, fn, of_init_fn_1)
1417 #define OF_DECLARE_1_RET(table, name, compat, fn) \
1418         _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
1419 #define OF_DECLARE_2(table, name, compat, fn) \
1420         _OF_DECLARE(table, name, compat, fn, of_init_fn_2)
1421 
1422 /**
1423  * struct of_changeset_entry    - Holds a changeset entry
1424  *
1425  * @node:   list_head for the log list
1426  * @action: notifier action
1427  * @np:     pointer to the device node affected
1428  * @prop:   pointer to the property affected
1429  * @old_prop:   hold a pointer to the original property
1430  *
1431  * Every modification of the device tree during a changeset
1432  * is held in a list of of_changeset_entry structures.
1433  * That way we can recover from a partial application, or we can
1434  * revert the changeset
1435  */
1436 struct of_changeset_entry {
1437     struct list_head node;
1438     unsigned long action;
1439     struct device_node *np;
1440     struct property *prop;
1441     struct property *old_prop;
1442 };
1443 
1444 /**
1445  * struct of_changeset - changeset tracker structure
1446  *
1447  * @entries:    list_head for the changeset entries
1448  *
1449  * changesets are a convenient way to apply bulk changes to the
1450  * live tree. In case of an error, changes are rolled-back.
1451  * changesets live on after initial application, and if not
1452  * destroyed after use, they can be reverted in one single call.
1453  */
1454 struct of_changeset {
1455     struct list_head entries;
1456 };
1457 
1458 enum of_reconfig_change {
1459     OF_RECONFIG_NO_CHANGE = 0,
1460     OF_RECONFIG_CHANGE_ADD,
1461     OF_RECONFIG_CHANGE_REMOVE,
1462 };
1463 
1464 #ifdef CONFIG_OF_DYNAMIC
1465 extern int of_reconfig_notifier_register(struct notifier_block *);
1466 extern int of_reconfig_notifier_unregister(struct notifier_block *);
1467 extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
1468 extern int of_reconfig_get_state_change(unsigned long action,
1469                     struct of_reconfig_data *arg);
1470 
1471 extern void of_changeset_init(struct of_changeset *ocs);
1472 extern void of_changeset_destroy(struct of_changeset *ocs);
1473 extern int of_changeset_apply(struct of_changeset *ocs);
1474 extern int of_changeset_revert(struct of_changeset *ocs);
1475 extern int of_changeset_action(struct of_changeset *ocs,
1476         unsigned long action, struct device_node *np,
1477         struct property *prop);
1478 
1479 static inline int of_changeset_attach_node(struct of_changeset *ocs,
1480         struct device_node *np)
1481 {
1482     return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
1483 }
1484 
1485 static inline int of_changeset_detach_node(struct of_changeset *ocs,
1486         struct device_node *np)
1487 {
1488     return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
1489 }
1490 
1491 static inline int of_changeset_add_property(struct of_changeset *ocs,
1492         struct device_node *np, struct property *prop)
1493 {
1494     return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
1495 }
1496 
1497 static inline int of_changeset_remove_property(struct of_changeset *ocs,
1498         struct device_node *np, struct property *prop)
1499 {
1500     return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
1501 }
1502 
1503 static inline int of_changeset_update_property(struct of_changeset *ocs,
1504         struct device_node *np, struct property *prop)
1505 {
1506     return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
1507 }
1508 #else /* CONFIG_OF_DYNAMIC */
1509 static inline int of_reconfig_notifier_register(struct notifier_block *nb)
1510 {
1511     return -EINVAL;
1512 }
1513 static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
1514 {
1515     return -EINVAL;
1516 }
1517 static inline int of_reconfig_notify(unsigned long action,
1518                      struct of_reconfig_data *arg)
1519 {
1520     return -EINVAL;
1521 }
1522 static inline int of_reconfig_get_state_change(unsigned long action,
1523                         struct of_reconfig_data *arg)
1524 {
1525     return -EINVAL;
1526 }
1527 #endif /* CONFIG_OF_DYNAMIC */
1528 
1529 /**
1530  * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
1531  * @np: Pointer to the given device_node
1532  *
1533  * Return: true if present false otherwise
1534  */
1535 static inline bool of_device_is_system_power_controller(const struct device_node *np)
1536 {
1537     return of_property_read_bool(np, "system-power-controller");
1538 }
1539 
1540 /*
1541  * Overlay support
1542  */
1543 
1544 enum of_overlay_notify_action {
1545     OF_OVERLAY_INIT = 0,    /* kzalloc() of ovcs sets this value */
1546     OF_OVERLAY_PRE_APPLY,
1547     OF_OVERLAY_POST_APPLY,
1548     OF_OVERLAY_PRE_REMOVE,
1549     OF_OVERLAY_POST_REMOVE,
1550 };
1551 
1552 static inline char *of_overlay_action_name(enum of_overlay_notify_action action)
1553 {
1554     static char *of_overlay_action_name[] = {
1555         "init",
1556         "pre-apply",
1557         "post-apply",
1558         "pre-remove",
1559         "post-remove",
1560     };
1561 
1562     return of_overlay_action_name[action];
1563 }
1564 
1565 struct of_overlay_notify_data {
1566     struct device_node *overlay;
1567     struct device_node *target;
1568 };
1569 
1570 #ifdef CONFIG_OF_OVERLAY
1571 
1572 int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
1573              int *ovcs_id);
1574 int of_overlay_remove(int *ovcs_id);
1575 int of_overlay_remove_all(void);
1576 
1577 int of_overlay_notifier_register(struct notifier_block *nb);
1578 int of_overlay_notifier_unregister(struct notifier_block *nb);
1579 
1580 #else
1581 
1582 static inline int of_overlay_fdt_apply(void *overlay_fdt, u32 overlay_fdt_size,
1583                        int *ovcs_id)
1584 {
1585     return -ENOTSUPP;
1586 }
1587 
1588 static inline int of_overlay_remove(int *ovcs_id)
1589 {
1590     return -ENOTSUPP;
1591 }
1592 
1593 static inline int of_overlay_remove_all(void)
1594 {
1595     return -ENOTSUPP;
1596 }
1597 
1598 static inline int of_overlay_notifier_register(struct notifier_block *nb)
1599 {
1600     return 0;
1601 }
1602 
1603 static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
1604 {
1605     return 0;
1606 }
1607 
1608 #endif
1609 
1610 #endif /* _LINUX_OF_H */