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