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