1
2
3
4
5
6
7
8
9#ifndef _LINUX_FWNODE_H_
10#define _LINUX_FWNODE_H_
11
12#include <linux/types.h>
13#include <linux/list.h>
14#include <linux/err.h>
15
16struct fwnode_operations;
17struct device;
18
19
20
21
22
23
24
25
26
27
28
29
30#define FWNODE_FLAG_LINKS_ADDED BIT(0)
31#define FWNODE_FLAG_NOT_DEVICE BIT(1)
32#define FWNODE_FLAG_INITIALIZED BIT(2)
33#define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3)
34
35struct fwnode_handle {
36 struct fwnode_handle *secondary;
37 const struct fwnode_operations *ops;
38 struct device *dev;
39 struct list_head suppliers;
40 struct list_head consumers;
41 u8 flags;
42};
43
44struct fwnode_link {
45 struct fwnode_handle *supplier;
46 struct list_head s_hook;
47 struct fwnode_handle *consumer;
48 struct list_head c_hook;
49};
50
51
52
53
54
55
56
57struct fwnode_endpoint {
58 unsigned int port;
59 unsigned int id;
60 const struct fwnode_handle *local_fwnode;
61};
62
63
64
65
66
67#define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
68#define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
69
70#define NR_FWNODE_REFERENCE_ARGS 8
71
72
73
74
75
76
77
78struct fwnode_reference_args {
79 struct fwnode_handle *fwnode;
80 unsigned int nargs;
81 u64 args[NR_FWNODE_REFERENCE_ARGS];
82};
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109struct fwnode_operations {
110 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
111 void (*put)(struct fwnode_handle *fwnode);
112 bool (*device_is_available)(const struct fwnode_handle *fwnode);
113 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
114 const struct device *dev);
115 bool (*property_present)(const struct fwnode_handle *fwnode,
116 const char *propname);
117 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
118 const char *propname,
119 unsigned int elem_size, void *val,
120 size_t nval);
121 int
122 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
123 const char *propname, const char **val,
124 size_t nval);
125 const char *(*get_name)(const struct fwnode_handle *fwnode);
126 const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
127 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
128 struct fwnode_handle *
129 (*get_next_child_node)(const struct fwnode_handle *fwnode,
130 struct fwnode_handle *child);
131 struct fwnode_handle *
132 (*get_named_child_node)(const struct fwnode_handle *fwnode,
133 const char *name);
134 int (*get_reference_args)(const struct fwnode_handle *fwnode,
135 const char *prop, const char *nargs_prop,
136 unsigned int nargs, unsigned int index,
137 struct fwnode_reference_args *args);
138 struct fwnode_handle *
139 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
140 struct fwnode_handle *prev);
141 struct fwnode_handle *
142 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
143 struct fwnode_handle *
144 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
145 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
146 struct fwnode_endpoint *endpoint);
147 int (*add_links)(struct fwnode_handle *fwnode);
148};
149
150#define fwnode_has_op(fwnode, op) \
151 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
152#define fwnode_call_int_op(fwnode, op, ...) \
153 (fwnode ? (fwnode_has_op(fwnode, op) ? \
154 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
155 -EINVAL)
156
157#define fwnode_call_bool_op(fwnode, op, ...) \
158 (fwnode_has_op(fwnode, op) ? \
159 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
160
161#define fwnode_call_ptr_op(fwnode, op, ...) \
162 (fwnode_has_op(fwnode, op) ? \
163 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
164#define fwnode_call_void_op(fwnode, op, ...) \
165 do { \
166 if (fwnode_has_op(fwnode, op)) \
167 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
168 } while (false)
169#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
170
171static inline void fwnode_init(struct fwnode_handle *fwnode,
172 const struct fwnode_operations *ops)
173{
174 fwnode->ops = ops;
175 INIT_LIST_HEAD(&fwnode->consumers);
176 INIT_LIST_HEAD(&fwnode->suppliers);
177}
178
179static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
180 bool initialized)
181{
182 if (IS_ERR_OR_NULL(fwnode))
183 return;
184
185 if (initialized)
186 fwnode->flags |= FWNODE_FLAG_INITIALIZED;
187 else
188 fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
189}
190
191extern u32 fw_devlink_get_flags(void);
192extern bool fw_devlink_is_strict(void);
193int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
194void fwnode_links_purge(struct fwnode_handle *fwnode);
195void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
196
197#endif
198