• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <rafael.j.wysocki@intel.com>
7  */
8 
9 #ifndef _LINUX_FWNODE_H_
10 #define _LINUX_FWNODE_H_
11 
12 #include <linux/types.h>
13 #include <linux/android_kabi.h>
14 
15 struct fwnode_operations;
16 struct device;
17 
18 struct fwnode_handle {
19 	struct fwnode_handle *secondary;
20 	const struct fwnode_operations *ops;
21 	struct device *dev;
22 
23 	ANDROID_KABI_RESERVE(1);
24 	ANDROID_KABI_RESERVE(2);
25 	ANDROID_KABI_RESERVE(3);
26 	ANDROID_KABI_RESERVE(4);
27 };
28 
29 /**
30  * struct fwnode_endpoint - Fwnode graph endpoint
31  * @port: Port number
32  * @id: Endpoint id
33  * @local_fwnode: reference to the related fwnode
34  */
35 struct fwnode_endpoint {
36 	unsigned int port;
37 	unsigned int id;
38 	const struct fwnode_handle *local_fwnode;
39 };
40 
41 #define NR_FWNODE_REFERENCE_ARGS	8
42 
43 /**
44  * struct fwnode_reference_args - Fwnode reference with additional arguments
45  * @fwnode:- A reference to the base fwnode
46  * @nargs: Number of elements in @args array
47  * @args: Integer arguments on the fwnode
48  */
49 struct fwnode_reference_args {
50 	struct fwnode_handle *fwnode;
51 	unsigned int nargs;
52 	u64 args[NR_FWNODE_REFERENCE_ARGS];
53 };
54 
55 /**
56  * struct fwnode_operations - Operations for fwnode interface
57  * @get: Get a reference to an fwnode.
58  * @put: Put a reference to an fwnode.
59  * @device_get_match_data: Return the device driver match data.
60  * @property_present: Return true if a property is present.
61  * @property_read_integer_array: Read an array of integer properties. Return
62  *				 zero on success, a negative error code
63  *				 otherwise.
64  * @property_read_string_array: Read an array of string properties. Return zero
65  *				on success, a negative error code otherwise.
66  * @get_parent: Return the parent of an fwnode.
67  * @get_next_child_node: Return the next child node in an iteration.
68  * @get_named_child_node: Return a child node with a given name.
69  * @get_reference_args: Return a reference pointed to by a property, with args
70  * @graph_get_next_endpoint: Return an endpoint node in an iteration.
71  * @graph_get_remote_endpoint: Return the remote endpoint node of a local
72  *			       endpoint node.
73  * @graph_get_port_parent: Return the parent node of a port node.
74  * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
75  * @add_links:	Called after the device corresponding to the fwnode is added
76  *		using device_add(). The function is expected to create device
77  *		links to all the suppliers of the device that are available at
78  *		the time this function is called.  The function must NOT stop
79  *		at the first failed device link if other unlinked supplier
80  *		devices are present in the system.  This is necessary for the
81  *		driver/bus sync_state() callbacks to work correctly.
82  *
83  *		For example, say Device-C depends on suppliers Device-S1 and
84  *		Device-S2 and the dependency is listed in that order in the
85  *		firmware.  Say, S1 gets populated from the firmware after
86  *		late_initcall_sync().  Say S2 is populated and probed way
87  *		before that in device_initcall(). When C is populated, if this
88  *		add_links() function doesn't continue past a "failed linking to
89  *		S1" and continue linking C to S2, then S2 will get a
90  *		sync_state() callback before C is probed. This is because from
91  *		the perspective of S2, C was never a consumer when its
92  *		sync_state() evaluation is done. To avoid this, the add_links()
93  *		function has to go through all available suppliers of the
94  *		device (that corresponds to this fwnode) and link to them
95  *		before returning.
96  *
97  *		If some suppliers are not yet available (indicated by an error
98  *		return value), this function will be called again when other
99  *		devices are added to allow creating device links to any newly
100  *		available suppliers.
101  *
102  *		Return 0 if device links have been successfully created to all
103  *		the known suppliers of this device or if the supplier
104  *		information is not known.
105  *
106  *		Return -ENODEV if the suppliers needed for probing this device
107  *		have not been registered yet (because device links can only be
108  *		created to devices registered with the driver core).
109  *
110  *		Return -EAGAIN if some of the suppliers of this device have not
111  *		been registered yet, but none of those suppliers are necessary
112  *		for probing the device.
113  */
114 struct fwnode_operations {
115 	struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
116 	void (*put)(struct fwnode_handle *fwnode);
117 	bool (*device_is_available)(const struct fwnode_handle *fwnode);
118 	const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
119 					     const struct device *dev);
120 	bool (*property_present)(const struct fwnode_handle *fwnode,
121 				 const char *propname);
122 	int (*property_read_int_array)(const struct fwnode_handle *fwnode,
123 				       const char *propname,
124 				       unsigned int elem_size, void *val,
125 				       size_t nval);
126 	int
127 	(*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
128 				      const char *propname, const char **val,
129 				      size_t nval);
130 	struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
131 	struct fwnode_handle *
132 	(*get_next_child_node)(const struct fwnode_handle *fwnode,
133 			       struct fwnode_handle *child);
134 	struct fwnode_handle *
135 	(*get_named_child_node)(const struct fwnode_handle *fwnode,
136 				const char *name);
137 	int (*get_reference_args)(const struct fwnode_handle *fwnode,
138 				  const char *prop, const char *nargs_prop,
139 				  unsigned int nargs, unsigned int index,
140 				  struct fwnode_reference_args *args);
141 	struct fwnode_handle *
142 	(*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
143 				   struct fwnode_handle *prev);
144 	struct fwnode_handle *
145 	(*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
146 	struct fwnode_handle *
147 	(*graph_get_port_parent)(struct fwnode_handle *fwnode);
148 	int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
149 				    struct fwnode_endpoint *endpoint);
150 	int (*add_links)(const struct fwnode_handle *fwnode,
151 			 struct device *dev);
152 };
153 
154 #define fwnode_has_op(fwnode, op)				\
155 	((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
156 #define fwnode_call_int_op(fwnode, op, ...)				\
157 	(fwnode ? (fwnode_has_op(fwnode, op) ?				\
158 		   (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
159 	 -EINVAL)
160 
161 #define fwnode_call_bool_op(fwnode, op, ...)		\
162 	(fwnode_has_op(fwnode, op) ?			\
163 	 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
164 
165 #define fwnode_call_ptr_op(fwnode, op, ...)		\
166 	(fwnode_has_op(fwnode, op) ?			\
167 	 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
168 #define fwnode_call_void_op(fwnode, op, ...)				\
169 	do {								\
170 		if (fwnode_has_op(fwnode, op))				\
171 			(fwnode)->ops->op(fwnode, ## __VA_ARGS__);	\
172 	} while (false)
173 #define get_dev_from_fwnode(fwnode)	get_device((fwnode)->dev)
174 
175 void fw_devlink_pause(void);
176 void fw_devlink_resume(void);
177 #endif
178