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