of_private.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef _LINUX_OF_PRIVATE_H
  3. #define _LINUX_OF_PRIVATE_H
  4. /*
  5. * Private symbols used by OF support code
  6. *
  7. * Paul Mackerras August 1996.
  8. * Copyright (C) 1996-2005 Paul Mackerras.
  9. */
  10. #define FDT_ALIGN_SIZE 8
  11. #define MAX_RESERVED_REGIONS 64
  12. /**
  13. * struct alias_prop - Alias property in 'aliases' node
  14. * @link: List node to link the structure in aliases_lookup list
  15. * @alias: Alias property name
  16. * @np: Pointer to device_node that the alias stands for
  17. * @id: Index value from end of alias name
  18. * @stem: Alias string without the index
  19. *
  20. * The structure represents one alias property of 'aliases' node as
  21. * an entry in aliases_lookup list.
  22. */
  23. struct alias_prop {
  24. struct list_head link;
  25. const char *alias;
  26. struct device_node *np;
  27. int id;
  28. char stem[];
  29. };
  30. #if defined(CONFIG_SPARC)
  31. #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
  32. #else
  33. #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
  34. #endif
  35. #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
  36. extern struct mutex of_mutex;
  37. extern raw_spinlock_t devtree_lock;
  38. extern struct list_head aliases_lookup;
  39. extern struct kset *of_kset;
  40. struct kunit;
  41. extern void of_root_kunit_skip(struct kunit *test);
  42. #if defined(CONFIG_OF_DYNAMIC)
  43. extern int of_property_notify(int action, struct device_node *np,
  44. struct property *prop, struct property *old_prop);
  45. extern void of_node_release(struct kobject *kobj);
  46. extern int __of_changeset_apply_entries(struct of_changeset *ocs,
  47. int *ret_revert);
  48. extern int __of_changeset_apply_notify(struct of_changeset *ocs);
  49. extern int __of_changeset_revert_entries(struct of_changeset *ocs,
  50. int *ret_apply);
  51. extern int __of_changeset_revert_notify(struct of_changeset *ocs);
  52. #else /* CONFIG_OF_DYNAMIC */
  53. static inline int of_property_notify(int action, struct device_node *np,
  54. struct property *prop, struct property *old_prop)
  55. {
  56. return 0;
  57. }
  58. #endif /* CONFIG_OF_DYNAMIC */
  59. #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
  60. void of_platform_register_reconfig_notifier(void);
  61. #else
  62. static inline void of_platform_register_reconfig_notifier(void) { }
  63. #endif
  64. #if defined(CONFIG_OF_KOBJ)
  65. int of_node_is_attached(const struct device_node *node);
  66. int __of_add_property_sysfs(struct device_node *np, struct property *pp);
  67. void __of_remove_property_sysfs(struct device_node *np, struct property *prop);
  68. void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
  69. struct property *oldprop);
  70. int __of_attach_node_sysfs(struct device_node *np);
  71. void __of_detach_node_sysfs(struct device_node *np);
  72. #else
  73. static inline int __of_add_property_sysfs(struct device_node *np, struct property *pp)
  74. {
  75. return 0;
  76. }
  77. static inline void __of_remove_property_sysfs(struct device_node *np, struct property *prop) {}
  78. static inline void __of_update_property_sysfs(struct device_node *np,
  79. struct property *newprop, struct property *oldprop) {}
  80. static inline int __of_attach_node_sysfs(struct device_node *np)
  81. {
  82. return 0;
  83. }
  84. static inline void __of_detach_node_sysfs(struct device_node *np) {}
  85. #endif
  86. #if defined(CONFIG_OF_RESOLVE)
  87. int of_resolve_phandles(struct device_node *tree);
  88. #endif
  89. void __of_phandle_cache_inv_entry(phandle handle);
  90. #if defined(CONFIG_OF_OVERLAY)
  91. void of_overlay_mutex_lock(void);
  92. void of_overlay_mutex_unlock(void);
  93. #else
  94. static inline void of_overlay_mutex_lock(void) {};
  95. static inline void of_overlay_mutex_unlock(void) {};
  96. #endif
  97. #if defined(CONFIG_OF_UNITTEST) && defined(CONFIG_OF_OVERLAY)
  98. extern void __init unittest_unflatten_overlay_base(void);
  99. #else
  100. static inline void unittest_unflatten_overlay_base(void) {};
  101. #endif
  102. extern void *__unflatten_device_tree(const void *blob,
  103. struct device_node *dad,
  104. struct device_node **mynodes,
  105. void *(*dt_alloc)(u64 size, u64 align),
  106. bool detached);
  107. /**
  108. * General utilities for working with live trees.
  109. *
  110. * All functions with two leading underscores operate
  111. * without taking node references, so you either have to
  112. * own the devtree lock or work on detached trees only.
  113. */
  114. struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
  115. void __of_prop_free(struct property *prop);
  116. struct device_node *__of_node_dup(const struct device_node *np,
  117. const char *full_name);
  118. struct device_node *__of_find_node_by_path(struct device_node *parent,
  119. const char *path);
  120. struct device_node *__of_find_node_by_full_path(struct device_node *node,
  121. const char *path);
  122. extern const void *__of_get_property(const struct device_node *np,
  123. const char *name, int *lenp);
  124. extern int __of_add_property(struct device_node *np, struct property *prop);
  125. extern int __of_remove_property(struct device_node *np, struct property *prop);
  126. extern int __of_update_property(struct device_node *np,
  127. struct property *newprop, struct property **oldprop);
  128. extern void __of_detach_node(struct device_node *np);
  129. extern void __of_sysfs_remove_bin_file(struct device_node *np,
  130. struct property *prop);
  131. /* illegal phandle value (set when unresolved) */
  132. #define OF_PHANDLE_ILLEGAL 0xdeadbeef
  133. /* iterators for transactions, used for overlays */
  134. /* forward iterator */
  135. #define for_each_transaction_entry(_oft, _te) \
  136. list_for_each_entry(_te, &(_oft)->te_list, node)
  137. /* reverse iterator */
  138. #define for_each_transaction_entry_reverse(_oft, _te) \
  139. list_for_each_entry_reverse(_te, &(_oft)->te_list, node)
  140. extern int of_bus_n_addr_cells(struct device_node *np);
  141. extern int of_bus_n_size_cells(struct device_node *np);
  142. const __be32 *of_irq_parse_imap_parent(const __be32 *imap, int len,
  143. struct of_phandle_args *out_irq);
  144. struct bus_dma_region;
  145. #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
  146. int of_dma_get_range(struct device_node *np,
  147. const struct bus_dma_region **map);
  148. struct device_node *__of_get_dma_parent(const struct device_node *np);
  149. #else
  150. static inline int of_dma_get_range(struct device_node *np,
  151. const struct bus_dma_region **map)
  152. {
  153. return -ENODEV;
  154. }
  155. static inline struct device_node *__of_get_dma_parent(const struct device_node *np)
  156. {
  157. return of_get_parent(np);
  158. }
  159. #endif
  160. int fdt_scan_reserved_mem(void);
  161. void __init fdt_scan_reserved_mem_reg_nodes(void);
  162. bool of_fdt_device_is_available(const void *blob, unsigned long node);
  163. #endif /* _LINUX_OF_PRIVATE_H */