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