18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci#ifndef _LINUX_OF_PRIVATE_H
38c2ecf20Sopenharmony_ci#define _LINUX_OF_PRIVATE_H
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci * Private symbols used by OF support code
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Paul Mackerras	August 1996.
88c2ecf20Sopenharmony_ci * Copyright (C) 1996-2005 Paul Mackerras.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/**
128c2ecf20Sopenharmony_ci * struct alias_prop - Alias property in 'aliases' node
138c2ecf20Sopenharmony_ci * @link:	List node to link the structure in aliases_lookup list
148c2ecf20Sopenharmony_ci * @alias:	Alias property name
158c2ecf20Sopenharmony_ci * @np:		Pointer to device_node that the alias stands for
168c2ecf20Sopenharmony_ci * @id:		Index value from end of alias name
178c2ecf20Sopenharmony_ci * @stem:	Alias string without the index
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * The structure represents one alias property of 'aliases' node as
208c2ecf20Sopenharmony_ci * an entry in aliases_lookup list.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_cistruct alias_prop {
238c2ecf20Sopenharmony_ci	struct list_head link;
248c2ecf20Sopenharmony_ci	const char *alias;
258c2ecf20Sopenharmony_ci	struct device_node *np;
268c2ecf20Sopenharmony_ci	int id;
278c2ecf20Sopenharmony_ci	char stem[];
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#if defined(CONFIG_SPARC)
318c2ecf20Sopenharmony_ci#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
328c2ecf20Sopenharmony_ci#else
338c2ecf20Sopenharmony_ci#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
348c2ecf20Sopenharmony_ci#endif
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciextern struct mutex of_mutex;
398c2ecf20Sopenharmony_ciextern struct list_head aliases_lookup;
408c2ecf20Sopenharmony_ciextern struct kset *of_kset;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#if defined(CONFIG_OF_DYNAMIC)
438c2ecf20Sopenharmony_ciextern int of_property_notify(int action, struct device_node *np,
448c2ecf20Sopenharmony_ci			      struct property *prop, struct property *old_prop);
458c2ecf20Sopenharmony_ciextern void of_node_release(struct kobject *kobj);
468c2ecf20Sopenharmony_ciextern int __of_changeset_apply_entries(struct of_changeset *ocs,
478c2ecf20Sopenharmony_ci					int *ret_revert);
488c2ecf20Sopenharmony_ciextern int __of_changeset_apply_notify(struct of_changeset *ocs);
498c2ecf20Sopenharmony_ciextern int __of_changeset_revert_entries(struct of_changeset *ocs,
508c2ecf20Sopenharmony_ci					 int *ret_apply);
518c2ecf20Sopenharmony_ciextern int __of_changeset_revert_notify(struct of_changeset *ocs);
528c2ecf20Sopenharmony_ci#else /* CONFIG_OF_DYNAMIC */
538c2ecf20Sopenharmony_cistatic inline int of_property_notify(int action, struct device_node *np,
548c2ecf20Sopenharmony_ci				     struct property *prop, struct property *old_prop)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	return 0;
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci#endif /* CONFIG_OF_DYNAMIC */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#if defined(CONFIG_OF_KOBJ)
618c2ecf20Sopenharmony_ciint of_node_is_attached(struct device_node *node);
628c2ecf20Sopenharmony_ciint __of_add_property_sysfs(struct device_node *np, struct property *pp);
638c2ecf20Sopenharmony_civoid __of_remove_property_sysfs(struct device_node *np, struct property *prop);
648c2ecf20Sopenharmony_civoid __of_update_property_sysfs(struct device_node *np, struct property *newprop,
658c2ecf20Sopenharmony_ci		struct property *oldprop);
668c2ecf20Sopenharmony_ciint __of_attach_node_sysfs(struct device_node *np);
678c2ecf20Sopenharmony_civoid __of_detach_node_sysfs(struct device_node *np);
688c2ecf20Sopenharmony_ci#else
698c2ecf20Sopenharmony_cistatic inline int __of_add_property_sysfs(struct device_node *np, struct property *pp)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	return 0;
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_cistatic inline void __of_remove_property_sysfs(struct device_node *np, struct property *prop) {}
748c2ecf20Sopenharmony_cistatic inline void __of_update_property_sysfs(struct device_node *np,
758c2ecf20Sopenharmony_ci		struct property *newprop, struct property *oldprop) {}
768c2ecf20Sopenharmony_cistatic inline int __of_attach_node_sysfs(struct device_node *np)
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci	return 0;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_cistatic inline void __of_detach_node_sysfs(struct device_node *np) {}
818c2ecf20Sopenharmony_ci#endif
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#if defined(CONFIG_OF_RESOLVE)
848c2ecf20Sopenharmony_ciint of_resolve_phandles(struct device_node *tree);
858c2ecf20Sopenharmony_ci#endif
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_civoid __of_phandle_cache_inv_entry(phandle handle);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#if defined(CONFIG_OF_OVERLAY)
908c2ecf20Sopenharmony_civoid of_overlay_mutex_lock(void);
918c2ecf20Sopenharmony_civoid of_overlay_mutex_unlock(void);
928c2ecf20Sopenharmony_ci#else
938c2ecf20Sopenharmony_cistatic inline void of_overlay_mutex_lock(void) {};
948c2ecf20Sopenharmony_cistatic inline void of_overlay_mutex_unlock(void) {};
958c2ecf20Sopenharmony_ci#endif
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#if defined(CONFIG_OF_UNITTEST) && defined(CONFIG_OF_OVERLAY)
988c2ecf20Sopenharmony_ciextern void __init unittest_unflatten_overlay_base(void);
998c2ecf20Sopenharmony_ci#else
1008c2ecf20Sopenharmony_cistatic inline void unittest_unflatten_overlay_base(void) {};
1018c2ecf20Sopenharmony_ci#endif
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ciextern void *__unflatten_device_tree(const void *blob,
1048c2ecf20Sopenharmony_ci			      struct device_node *dad,
1058c2ecf20Sopenharmony_ci			      struct device_node **mynodes,
1068c2ecf20Sopenharmony_ci			      void *(*dt_alloc)(u64 size, u64 align),
1078c2ecf20Sopenharmony_ci			      bool detached);
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/**
1108c2ecf20Sopenharmony_ci * General utilities for working with live trees.
1118c2ecf20Sopenharmony_ci *
1128c2ecf20Sopenharmony_ci * All functions with two leading underscores operate
1138c2ecf20Sopenharmony_ci * without taking node references, so you either have to
1148c2ecf20Sopenharmony_ci * own the devtree lock or work on detached trees only.
1158c2ecf20Sopenharmony_ci */
1168c2ecf20Sopenharmony_cistruct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
1178c2ecf20Sopenharmony_cistruct device_node *__of_node_dup(const struct device_node *np,
1188c2ecf20Sopenharmony_ci				  const char *full_name);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistruct device_node *__of_find_node_by_path(struct device_node *parent,
1218c2ecf20Sopenharmony_ci						const char *path);
1228c2ecf20Sopenharmony_cistruct device_node *__of_find_node_by_full_path(struct device_node *node,
1238c2ecf20Sopenharmony_ci						const char *path);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ciextern const void *__of_get_property(const struct device_node *np,
1268c2ecf20Sopenharmony_ci				     const char *name, int *lenp);
1278c2ecf20Sopenharmony_ciextern int __of_add_property(struct device_node *np, struct property *prop);
1288c2ecf20Sopenharmony_ciextern int __of_add_property_sysfs(struct device_node *np,
1298c2ecf20Sopenharmony_ci		struct property *prop);
1308c2ecf20Sopenharmony_ciextern int __of_remove_property(struct device_node *np, struct property *prop);
1318c2ecf20Sopenharmony_ciextern void __of_remove_property_sysfs(struct device_node *np,
1328c2ecf20Sopenharmony_ci		struct property *prop);
1338c2ecf20Sopenharmony_ciextern int __of_update_property(struct device_node *np,
1348c2ecf20Sopenharmony_ci		struct property *newprop, struct property **oldprop);
1358c2ecf20Sopenharmony_ciextern void __of_update_property_sysfs(struct device_node *np,
1368c2ecf20Sopenharmony_ci		struct property *newprop, struct property *oldprop);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ciextern int __of_attach_node_sysfs(struct device_node *np);
1398c2ecf20Sopenharmony_ciextern void __of_detach_node(struct device_node *np);
1408c2ecf20Sopenharmony_ciextern void __of_detach_node_sysfs(struct device_node *np);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ciextern void __of_sysfs_remove_bin_file(struct device_node *np,
1438c2ecf20Sopenharmony_ci				       struct property *prop);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* illegal phandle value (set when unresolved) */
1468c2ecf20Sopenharmony_ci#define OF_PHANDLE_ILLEGAL	0xdeadbeef
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/* iterators for transactions, used for overlays */
1498c2ecf20Sopenharmony_ci/* forward iterator */
1508c2ecf20Sopenharmony_ci#define for_each_transaction_entry(_oft, _te) \
1518c2ecf20Sopenharmony_ci	list_for_each_entry(_te, &(_oft)->te_list, node)
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/* reverse iterator */
1548c2ecf20Sopenharmony_ci#define for_each_transaction_entry_reverse(_oft, _te) \
1558c2ecf20Sopenharmony_ci	list_for_each_entry_reverse(_te, &(_oft)->te_list, node)
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ciextern int of_bus_n_addr_cells(struct device_node *np);
1588c2ecf20Sopenharmony_ciextern int of_bus_n_size_cells(struct device_node *np);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistruct bus_dma_region;
1618c2ecf20Sopenharmony_ci#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
1628c2ecf20Sopenharmony_ciint of_dma_get_range(struct device_node *np,
1638c2ecf20Sopenharmony_ci		const struct bus_dma_region **map);
1648c2ecf20Sopenharmony_ci#else
1658c2ecf20Sopenharmony_cistatic inline int of_dma_get_range(struct device_node *np,
1668c2ecf20Sopenharmony_ci		const struct bus_dma_region **map)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	return -ENODEV;
1698c2ecf20Sopenharmony_ci}
1708c2ecf20Sopenharmony_ci#endif
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#endif /* _LINUX_OF_PRIVATE_H */
173