xref: /linux/drivers/of/of_private.h (revision f43775625e28703469198657392168c5fe961edc)
1af6074fcSRob Herring /* SPDX-License-Identifier: GPL-2.0+ */
2ced4eec9SStepan Moskovchenko #ifndef _LINUX_OF_PRIVATE_H
3ced4eec9SStepan Moskovchenko #define _LINUX_OF_PRIVATE_H
4ced4eec9SStepan Moskovchenko /*
5ced4eec9SStepan Moskovchenko  * Private symbols used by OF support code
6ced4eec9SStepan Moskovchenko  *
7ced4eec9SStepan Moskovchenko  * Paul Mackerras	August 1996.
8ced4eec9SStepan Moskovchenko  * Copyright (C) 1996-2005 Paul Mackerras.
9ced4eec9SStepan Moskovchenko  */
10ced4eec9SStepan Moskovchenko 
11ced4eec9SStepan Moskovchenko /**
12ced4eec9SStepan Moskovchenko  * struct alias_prop - Alias property in 'aliases' node
13ced4eec9SStepan Moskovchenko  * @link:	List node to link the structure in aliases_lookup list
14ced4eec9SStepan Moskovchenko  * @alias:	Alias property name
15ced4eec9SStepan Moskovchenko  * @np:		Pointer to device_node that the alias stands for
16ced4eec9SStepan Moskovchenko  * @id:		Index value from end of alias name
17ced4eec9SStepan Moskovchenko  * @stem:	Alias string without the index
18ced4eec9SStepan Moskovchenko  *
19ced4eec9SStepan Moskovchenko  * The structure represents one alias property of 'aliases' node as
20ced4eec9SStepan Moskovchenko  * an entry in aliases_lookup list.
21ced4eec9SStepan Moskovchenko  */
22ced4eec9SStepan Moskovchenko struct alias_prop {
23ced4eec9SStepan Moskovchenko 	struct list_head link;
24ced4eec9SStepan Moskovchenko 	const char *alias;
25ced4eec9SStepan Moskovchenko 	struct device_node *np;
26ced4eec9SStepan Moskovchenko 	int id;
27*f4377562SGustavo A. R. Silva 	char stem[];
28ced4eec9SStepan Moskovchenko };
29ced4eec9SStepan Moskovchenko 
3000b7d1cfSRob Herring #if defined(CONFIG_SPARC)
3100b7d1cfSRob Herring #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
3200b7d1cfSRob Herring #else
3300b7d1cfSRob Herring #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
3400b7d1cfSRob Herring #endif
3500b7d1cfSRob Herring 
3600b7d1cfSRob Herring #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
3700b7d1cfSRob Herring 
38c05aba2bSPantelis Antoniou extern struct mutex of_mutex;
39ced4eec9SStepan Moskovchenko extern struct list_head aliases_lookup;
408a2b22a2SGrant Likely extern struct kset *of_kset;
418a2b22a2SGrant Likely 
426afc0dc3SGrant Likely #if defined(CONFIG_OF_DYNAMIC)
436afc0dc3SGrant Likely extern int of_property_notify(int action, struct device_node *np,
44259092a3SGrant Likely 			      struct property *prop, struct property *old_prop);
456afc0dc3SGrant Likely extern void of_node_release(struct kobject *kobj);
4624789c5cSFrank Rowand extern int __of_changeset_apply_entries(struct of_changeset *ocs,
4724789c5cSFrank Rowand 					int *ret_revert);
4824789c5cSFrank Rowand extern int __of_changeset_apply_notify(struct of_changeset *ocs);
4924789c5cSFrank Rowand extern int __of_changeset_revert_entries(struct of_changeset *ocs,
5024789c5cSFrank Rowand 					 int *ret_apply);
5124789c5cSFrank Rowand extern int __of_changeset_revert_notify(struct of_changeset *ocs);
526afc0dc3SGrant Likely #else /* CONFIG_OF_DYNAMIC */
536afc0dc3SGrant Likely static inline int of_property_notify(int action, struct device_node *np,
54259092a3SGrant Likely 				     struct property *prop, struct property *old_prop)
556afc0dc3SGrant Likely {
566afc0dc3SGrant Likely 	return 0;
576afc0dc3SGrant Likely }
586afc0dc3SGrant Likely #endif /* CONFIG_OF_DYNAMIC */
596afc0dc3SGrant Likely 
60b56b5528SRob Herring #if defined(CONFIG_OF_KOBJ)
61b56b5528SRob Herring int of_node_is_attached(struct device_node *node);
62b56b5528SRob Herring int __of_add_property_sysfs(struct device_node *np, struct property *pp);
63b56b5528SRob Herring void __of_remove_property_sysfs(struct device_node *np, struct property *prop);
64b56b5528SRob Herring void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
65b56b5528SRob Herring 		struct property *oldprop);
66b56b5528SRob Herring int __of_attach_node_sysfs(struct device_node *np);
67b56b5528SRob Herring void __of_detach_node_sysfs(struct device_node *np);
68b56b5528SRob Herring #else
69b56b5528SRob Herring static inline int __of_add_property_sysfs(struct device_node *np, struct property *pp)
70b56b5528SRob Herring {
71b56b5528SRob Herring 	return 0;
72b56b5528SRob Herring }
73b56b5528SRob Herring static inline void __of_remove_property_sysfs(struct device_node *np, struct property *prop) {}
74b56b5528SRob Herring static inline void __of_update_property_sysfs(struct device_node *np,
75b56b5528SRob Herring 		struct property *newprop, struct property *oldprop) {}
76b56b5528SRob Herring static inline int __of_attach_node_sysfs(struct device_node *np)
77b56b5528SRob Herring {
78b56b5528SRob Herring 	return 0;
79b56b5528SRob Herring }
80b56b5528SRob Herring static inline void __of_detach_node_sysfs(struct device_node *np) {}
81b56b5528SRob Herring #endif
82b56b5528SRob Herring 
83f948d6d8SFrank Rowand #if defined(CONFIG_OF_RESOLVE)
84f948d6d8SFrank Rowand int of_resolve_phandles(struct device_node *tree);
85f948d6d8SFrank Rowand #endif
86f948d6d8SFrank Rowand 
8790dc0d1cSRob Herring void __of_phandle_cache_inv_entry(phandle handle);
885801169aSFrank Rowand 
89f948d6d8SFrank Rowand #if defined(CONFIG_OF_OVERLAY)
90f948d6d8SFrank Rowand void of_overlay_mutex_lock(void);
91f948d6d8SFrank Rowand void of_overlay_mutex_unlock(void);
92f948d6d8SFrank Rowand #else
93f948d6d8SFrank Rowand static inline void of_overlay_mutex_lock(void) {};
94f948d6d8SFrank Rowand static inline void of_overlay_mutex_unlock(void) {};
95f948d6d8SFrank Rowand #endif
96f948d6d8SFrank Rowand 
975d4dd65bSArnd Bergmann #if defined(CONFIG_OF_UNITTEST) && defined(CONFIG_OF_OVERLAY)
9881d0848fSFrank Rowand extern void __init unittest_unflatten_overlay_base(void);
9981d0848fSFrank Rowand #else
10081d0848fSFrank Rowand static inline void unittest_unflatten_overlay_base(void) {};
10181d0848fSFrank Rowand #endif
10281d0848fSFrank Rowand 
10381d0848fSFrank Rowand extern void *__unflatten_device_tree(const void *blob,
10481d0848fSFrank Rowand 			      struct device_node *dad,
10581d0848fSFrank Rowand 			      struct device_node **mynodes,
10681d0848fSFrank Rowand 			      void *(*dt_alloc)(u64 size, u64 align),
10781d0848fSFrank Rowand 			      bool detached);
10881d0848fSFrank Rowand 
10969843396SPantelis Antoniou /**
11069843396SPantelis Antoniou  * General utilities for working with live trees.
11169843396SPantelis Antoniou  *
11269843396SPantelis Antoniou  * All functions with two leading underscores operate
11369843396SPantelis Antoniou  * without taking node references, so you either have to
11469843396SPantelis Antoniou  * own the devtree lock or work on detached trees only.
11569843396SPantelis Antoniou  */
11669843396SPantelis Antoniou struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
117b89dae18SFrank Rowand struct device_node *__of_node_dup(const struct device_node *np,
118b89dae18SFrank Rowand 				  const char *full_name);
11969843396SPantelis Antoniou 
120e0a58f3eSFrank Rowand struct device_node *__of_find_node_by_path(struct device_node *parent,
121e0a58f3eSFrank Rowand 						const char *path);
12227497e11SRob Herring struct device_node *__of_find_node_by_full_path(struct device_node *node,
12327497e11SRob Herring 						const char *path);
12427497e11SRob Herring 
125a25095d4SGrant Likely extern const void *__of_get_property(const struct device_node *np,
126a25095d4SGrant Likely 				     const char *name, int *lenp);
127d8c50088SPantelis Antoniou extern int __of_add_property(struct device_node *np, struct property *prop);
1288a2b22a2SGrant Likely extern int __of_add_property_sysfs(struct device_node *np,
1298a2b22a2SGrant Likely 		struct property *prop);
130d8c50088SPantelis Antoniou extern int __of_remove_property(struct device_node *np, struct property *prop);
1318a2b22a2SGrant Likely extern void __of_remove_property_sysfs(struct device_node *np,
1328a2b22a2SGrant Likely 		struct property *prop);
133d8c50088SPantelis Antoniou extern int __of_update_property(struct device_node *np,
134d8c50088SPantelis Antoniou 		struct property *newprop, struct property **oldprop);
1358a2b22a2SGrant Likely extern void __of_update_property_sysfs(struct device_node *np,
1368a2b22a2SGrant Likely 		struct property *newprop, struct property *oldprop);
137d8c50088SPantelis Antoniou 
1388a2b22a2SGrant Likely extern int __of_attach_node_sysfs(struct device_node *np);
139d8c50088SPantelis Antoniou extern void __of_detach_node(struct device_node *np);
1408a2b22a2SGrant Likely extern void __of_detach_node_sysfs(struct device_node *np);
141d8c50088SPantelis Antoniou 
142d9fc8807SFrank Rowand extern void __of_sysfs_remove_bin_file(struct device_node *np,
143d9fc8807SFrank Rowand 				       struct property *prop);
144d9fc8807SFrank Rowand 
1450b3ce78eSFrank Rowand /* illegal phandle value (set when unresolved) */
1460b3ce78eSFrank Rowand #define OF_PHANDLE_ILLEGAL	0xdeadbeef
1470b3ce78eSFrank Rowand 
148201c910bSPantelis Antoniou /* iterators for transactions, used for overlays */
149201c910bSPantelis Antoniou /* forward iterator */
150201c910bSPantelis Antoniou #define for_each_transaction_entry(_oft, _te) \
151201c910bSPantelis Antoniou 	list_for_each_entry(_te, &(_oft)->te_list, node)
152201c910bSPantelis Antoniou 
153201c910bSPantelis Antoniou /* reverse iterator */
154201c910bSPantelis Antoniou #define for_each_transaction_entry_reverse(_oft, _te) \
155201c910bSPantelis Antoniou 	list_for_each_entry_reverse(_te, &(_oft)->te_list, node)
156201c910bSPantelis Antoniou 
157b68ac8dcSRobin Murphy extern int of_bus_n_addr_cells(struct device_node *np);
158b68ac8dcSRobin Murphy extern int of_bus_n_size_cells(struct device_node *np);
159b68ac8dcSRobin Murphy 
1606e6faf63SRob Herring #ifdef CONFIG_OF_ADDRESS
1616e6faf63SRob Herring extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
1626e6faf63SRob Herring 			    u64 *paddr, u64 *size);
1636e6faf63SRob Herring #else
1646e6faf63SRob Herring static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
1656e6faf63SRob Herring 				   u64 *paddr, u64 *size)
1666e6faf63SRob Herring {
1676e6faf63SRob Herring 	return -ENODEV;
1686e6faf63SRob Herring }
1696e6faf63SRob Herring #endif
1706e6faf63SRob Herring 
171ced4eec9SStepan Moskovchenko #endif /* _LINUX_OF_PRIVATE_H */
172