File Index
Files and directories
Sign in
FILE

of.h

File preview with syntax highlighting.

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