0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LINUX_FWNODE_H_
0010 #define _LINUX_FWNODE_H_
0011
0012 #include <linux/types.h>
0013 #include <linux/list.h>
0014 #include <linux/bits.h>
0015 #include <linux/err.h>
0016
0017 struct fwnode_operations;
0018 struct device;
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #define FWNODE_FLAG_LINKS_ADDED BIT(0)
0035 #define FWNODE_FLAG_NOT_DEVICE BIT(1)
0036 #define FWNODE_FLAG_INITIALIZED BIT(2)
0037 #define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3)
0038 #define FWNODE_FLAG_BEST_EFFORT BIT(4)
0039
0040 struct fwnode_handle {
0041 struct fwnode_handle *secondary;
0042 const struct fwnode_operations *ops;
0043 struct device *dev;
0044 struct list_head suppliers;
0045 struct list_head consumers;
0046 u8 flags;
0047 };
0048
0049 struct fwnode_link {
0050 struct fwnode_handle *supplier;
0051 struct list_head s_hook;
0052 struct fwnode_handle *consumer;
0053 struct list_head c_hook;
0054 };
0055
0056
0057
0058
0059
0060
0061
0062 struct fwnode_endpoint {
0063 unsigned int port;
0064 unsigned int id;
0065 const struct fwnode_handle *local_fwnode;
0066 };
0067
0068
0069
0070
0071
0072 #define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
0073 #define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
0074
0075 #define NR_FWNODE_REFERENCE_ARGS 8
0076
0077
0078
0079
0080
0081
0082
0083 struct fwnode_reference_args {
0084 struct fwnode_handle *fwnode;
0085 unsigned int nargs;
0086 u64 args[NR_FWNODE_REFERENCE_ARGS];
0087 };
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 struct fwnode_operations {
0115 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
0116 void (*put)(struct fwnode_handle *fwnode);
0117 bool (*device_is_available)(const struct fwnode_handle *fwnode);
0118 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
0119 const struct device *dev);
0120 bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
0121 enum dev_dma_attr
0122 (*device_get_dma_attr)(const struct fwnode_handle *fwnode);
0123 bool (*property_present)(const struct fwnode_handle *fwnode,
0124 const char *propname);
0125 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
0126 const char *propname,
0127 unsigned int elem_size, void *val,
0128 size_t nval);
0129 int
0130 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
0131 const char *propname, const char **val,
0132 size_t nval);
0133 const char *(*get_name)(const struct fwnode_handle *fwnode);
0134 const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
0135 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
0136 struct fwnode_handle *
0137 (*get_next_child_node)(const struct fwnode_handle *fwnode,
0138 struct fwnode_handle *child);
0139 struct fwnode_handle *
0140 (*get_named_child_node)(const struct fwnode_handle *fwnode,
0141 const char *name);
0142 int (*get_reference_args)(const struct fwnode_handle *fwnode,
0143 const char *prop, const char *nargs_prop,
0144 unsigned int nargs, unsigned int index,
0145 struct fwnode_reference_args *args);
0146 struct fwnode_handle *
0147 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
0148 struct fwnode_handle *prev);
0149 struct fwnode_handle *
0150 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
0151 struct fwnode_handle *
0152 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
0153 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
0154 struct fwnode_endpoint *endpoint);
0155 void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
0156 int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
0157 int (*add_links)(struct fwnode_handle *fwnode);
0158 };
0159
0160 #define fwnode_has_op(fwnode, op) \
0161 (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op)
0162
0163 #define fwnode_call_int_op(fwnode, op, ...) \
0164 (fwnode_has_op(fwnode, op) ? \
0165 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))
0166
0167 #define fwnode_call_bool_op(fwnode, op, ...) \
0168 (fwnode_has_op(fwnode, op) ? \
0169 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
0170
0171 #define fwnode_call_ptr_op(fwnode, op, ...) \
0172 (fwnode_has_op(fwnode, op) ? \
0173 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
0174 #define fwnode_call_void_op(fwnode, op, ...) \
0175 do { \
0176 if (fwnode_has_op(fwnode, op)) \
0177 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
0178 } while (false)
0179 #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
0180
0181 static inline void fwnode_init(struct fwnode_handle *fwnode,
0182 const struct fwnode_operations *ops)
0183 {
0184 fwnode->ops = ops;
0185 INIT_LIST_HEAD(&fwnode->consumers);
0186 INIT_LIST_HEAD(&fwnode->suppliers);
0187 }
0188
0189 static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
0190 bool initialized)
0191 {
0192 if (IS_ERR_OR_NULL(fwnode))
0193 return;
0194
0195 if (initialized)
0196 fwnode->flags |= FWNODE_FLAG_INITIALIZED;
0197 else
0198 fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
0199 }
0200
0201 extern u32 fw_devlink_get_flags(void);
0202 extern bool fw_devlink_is_strict(void);
0203 int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
0204 void fwnode_links_purge(struct fwnode_handle *fwnode);
0205 void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
0206
0207 #endif