fwnode.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * fwnode.h - Firmware device node object handle type definition.
  4. *
  5. * Copyright (C) 2015, Intel Corporation
  6. * Author: Rafael J. Wysocki <[email protected]>
  7. */
  8. #ifndef _LINUX_FWNODE_H_
  9. #define _LINUX_FWNODE_H_
  10. #include <linux/types.h>
  11. #include <linux/list.h>
  12. #include <linux/bits.h>
  13. #include <linux/err.h>
  14. #include <linux/android_kabi.h>
  15. struct fwnode_operations;
  16. struct device;
  17. /*
  18. * fwnode flags
  19. *
  20. * LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
  21. * NOT_DEVICE: The fwnode will never be populated as a struct device.
  22. * INITIALIZED: The hardware corresponding to fwnode has been initialized.
  23. * NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its
  24. * driver needs its child devices to be bound with
  25. * their respective drivers as soon as they are
  26. * added.
  27. * BEST_EFFORT: The fwnode/device needs to probe early and might be missing some
  28. * suppliers. Only enforce ordering with suppliers that have
  29. * drivers.
  30. */
  31. #define FWNODE_FLAG_LINKS_ADDED BIT(0)
  32. #define FWNODE_FLAG_NOT_DEVICE BIT(1)
  33. #define FWNODE_FLAG_INITIALIZED BIT(2)
  34. #define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3)
  35. #define FWNODE_FLAG_BEST_EFFORT BIT(4)
  36. #define FWNODE_FLAG_VISITED BIT(5)
  37. struct fwnode_handle {
  38. struct fwnode_handle *secondary;
  39. const struct fwnode_operations *ops;
  40. struct device *dev;
  41. struct list_head suppliers;
  42. struct list_head consumers;
  43. u8 flags;
  44. ANDROID_KABI_RESERVE(1);
  45. };
  46. /*
  47. * fwnode link flags
  48. *
  49. * CYCLE: The fwnode link is part of a cycle. Don't defer probe.
  50. */
  51. #define FWLINK_FLAG_CYCLE BIT(0)
  52. struct fwnode_link {
  53. struct fwnode_handle *supplier;
  54. struct list_head s_hook;
  55. struct fwnode_handle *consumer;
  56. struct list_head c_hook;
  57. u8 flags;
  58. ANDROID_KABI_RESERVE(1);
  59. ANDROID_KABI_RESERVE(2);
  60. ANDROID_KABI_RESERVE(3);
  61. };
  62. /**
  63. * struct fwnode_endpoint - Fwnode graph endpoint
  64. * @port: Port number
  65. * @id: Endpoint id
  66. * @local_fwnode: reference to the related fwnode
  67. */
  68. struct fwnode_endpoint {
  69. unsigned int port;
  70. unsigned int id;
  71. const struct fwnode_handle *local_fwnode;
  72. };
  73. /*
  74. * ports and endpoints defined as software_nodes should all follow a common
  75. * naming scheme; use these macros to ensure commonality.
  76. */
  77. #define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
  78. #define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
  79. #define NR_FWNODE_REFERENCE_ARGS 8
  80. /**
  81. * struct fwnode_reference_args - Fwnode reference with additional arguments
  82. * @fwnode:- A reference to the base fwnode
  83. * @nargs: Number of elements in @args array
  84. * @args: Integer arguments on the fwnode
  85. */
  86. struct fwnode_reference_args {
  87. struct fwnode_handle *fwnode;
  88. unsigned int nargs;
  89. u64 args[NR_FWNODE_REFERENCE_ARGS];
  90. };
  91. /**
  92. * struct fwnode_operations - Operations for fwnode interface
  93. * @get: Get a reference to an fwnode.
  94. * @put: Put a reference to an fwnode.
  95. * @device_is_available: Return true if the device is available.
  96. * @device_get_match_data: Return the device driver match data.
  97. * @property_present: Return true if a property is present.
  98. * @property_read_int_array: Read an array of integer properties. Return zero on
  99. * success, a negative error code otherwise.
  100. * @property_read_string_array: Read an array of string properties. Return zero
  101. * on success, a negative error code otherwise.
  102. * @get_name: Return the name of an fwnode.
  103. * @get_name_prefix: Get a prefix for a node (for printing purposes).
  104. * @get_parent: Return the parent of an fwnode.
  105. * @get_next_child_node: Return the next child node in an iteration.
  106. * @get_named_child_node: Return a child node with a given name.
  107. * @get_reference_args: Return a reference pointed to by a property, with args
  108. * @graph_get_next_endpoint: Return an endpoint node in an iteration.
  109. * @graph_get_remote_endpoint: Return the remote endpoint node of a local
  110. * endpoint node.
  111. * @graph_get_port_parent: Return the parent node of a port node.
  112. * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
  113. * @add_links: Create fwnode links to all the suppliers of the fwnode. Return
  114. * zero on success, a negative error code otherwise.
  115. */
  116. struct fwnode_operations {
  117. struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
  118. void (*put)(struct fwnode_handle *fwnode);
  119. bool (*device_is_available)(const struct fwnode_handle *fwnode);
  120. const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
  121. const struct device *dev);
  122. bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
  123. enum dev_dma_attr
  124. (*device_get_dma_attr)(const struct fwnode_handle *fwnode);
  125. bool (*property_present)(const struct fwnode_handle *fwnode,
  126. const char *propname);
  127. int (*property_read_int_array)(const struct fwnode_handle *fwnode,
  128. const char *propname,
  129. unsigned int elem_size, void *val,
  130. size_t nval);
  131. int
  132. (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
  133. const char *propname, const char **val,
  134. size_t nval);
  135. const char *(*get_name)(const struct fwnode_handle *fwnode);
  136. const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
  137. struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
  138. struct fwnode_handle *
  139. (*get_next_child_node)(const struct fwnode_handle *fwnode,
  140. struct fwnode_handle *child);
  141. struct fwnode_handle *
  142. (*get_named_child_node)(const struct fwnode_handle *fwnode,
  143. const char *name);
  144. int (*get_reference_args)(const struct fwnode_handle *fwnode,
  145. const char *prop, const char *nargs_prop,
  146. unsigned int nargs, unsigned int index,
  147. struct fwnode_reference_args *args);
  148. struct fwnode_handle *
  149. (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
  150. struct fwnode_handle *prev);
  151. struct fwnode_handle *
  152. (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
  153. struct fwnode_handle *
  154. (*graph_get_port_parent)(struct fwnode_handle *fwnode);
  155. int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
  156. struct fwnode_endpoint *endpoint);
  157. void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
  158. int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
  159. int (*add_links)(struct fwnode_handle *fwnode);
  160. };
  161. #define fwnode_has_op(fwnode, op) \
  162. (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op)
  163. #define fwnode_call_int_op(fwnode, op, ...) \
  164. (fwnode_has_op(fwnode, op) ? \
  165. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))
  166. #define fwnode_call_bool_op(fwnode, op, ...) \
  167. (fwnode_has_op(fwnode, op) ? \
  168. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
  169. #define fwnode_call_ptr_op(fwnode, op, ...) \
  170. (fwnode_has_op(fwnode, op) ? \
  171. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
  172. #define fwnode_call_void_op(fwnode, op, ...) \
  173. do { \
  174. if (fwnode_has_op(fwnode, op)) \
  175. (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
  176. } while (false)
  177. #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
  178. static inline void fwnode_init(struct fwnode_handle *fwnode,
  179. const struct fwnode_operations *ops)
  180. {
  181. fwnode->ops = ops;
  182. INIT_LIST_HEAD(&fwnode->consumers);
  183. INIT_LIST_HEAD(&fwnode->suppliers);
  184. }
  185. static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
  186. bool initialized)
  187. {
  188. if (IS_ERR_OR_NULL(fwnode))
  189. return;
  190. if (initialized)
  191. fwnode->flags |= FWNODE_FLAG_INITIALIZED;
  192. else
  193. fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
  194. }
  195. extern bool fw_devlink_is_strict(void);
  196. int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
  197. void fwnode_links_purge(struct fwnode_handle *fwnode);
  198. void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
  199. #endif