| 1 |
|
| 2 | |
| 3 | * fwnode.h - Firmware device node object handle type definition.
|
| 4 | *
|
| 5 | * This header file provides low-level data types and definitions for firmware
|
| 6 | * and device property providers. The respective API header files supplied by
|
| 7 | * them should contain all of the requisite data types and definitions for end
|
| 8 | * users, so including it directly should not be necessary.
|
| 9 | *
|
| 10 | * Copyright (C) 2015, Intel Corporation
|
| 11 | * Author: Rafael J. Wysocki <[email protected]>
|
| 12 |
|
| 13 |
|
| 14 | #ifndef _LINUX_FWNODE_H_
|
| 15 | #define _LINUX_FWNODE_H_
|
| 16 |
|
| 17 | #include <linux/bits.h>
|
| 18 | #include <linux/bitops.h>
|
| 19 | #include <linux/err.h>
|
| 20 | #include <linux/list.h>
|
| 21 | #include <linux/types.h>
|
| 22 |
|
| 23 | enum dev_dma_attr {
|
| 24 | DEV_DMA_NOT_SUPPORTED,
|
| 25 | DEV_DMA_NON_COHERENT,
|
| 26 | DEV_DMA_COHERENT,
|
| 27 | };
|
| 28 |
|
| 29 | struct fwnode_operations;
|
| 30 | struct device;
|
| 31 |
|
| 32 | |
| 33 | * fwnode flags
|
| 34 | *
|
| 35 | * LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
|
| 36 | * NOT_DEVICE: The fwnode will never be populated as a struct device.
|
| 37 | * INITIALIZED: The hardware corresponding to fwnode has been initialized.
|
| 38 | * NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its
|
| 39 | * driver needs its child devices to be bound with
|
| 40 | * their respective drivers as soon as they are
|
| 41 | * added.
|
| 42 | * BEST_EFFORT: The fwnode/device needs to probe early and might be missing some
|
| 43 | * suppliers. Only enforce ordering with suppliers that have
|
| 44 | * drivers.
|
| 45 |
|
| 46 | #define FWNODE_FLAG_LINKS_ADDED 0
|
| 47 | #define FWNODE_FLAG_NOT_DEVICE 1
|
| 48 | #define FWNODE_FLAG_INITIALIZED 2
|
| 49 | #define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD 3
|
| 50 | #define FWNODE_FLAG_BEST_EFFORT 4
|
| 51 | #define FWNODE_FLAG_VISITED 5
|
| 52 |
|
| 53 | struct fwnode_handle {
|
| 54 | struct fwnode_handle *secondary;
|
| 55 | const struct fwnode_operations *ops;
|
| 56 |
|
| 57 |
|
| 58 | struct device *dev;
|
| 59 | struct list_head suppliers;
|
| 60 | struct list_head consumers;
|
| 61 | unsigned long flags;
|
| 62 | };
|
| 63 |
|
| 64 | |
| 65 | * fwnode link flags
|
| 66 | *
|
| 67 | * CYCLE: The fwnode link is part of a cycle. Don't defer probe.
|
| 68 | * IGNORE: Completely ignore this link, even during cycle detection.
|
| 69 |
|
| 70 | #define FWLINK_FLAG_CYCLE BIT(0)
|
| 71 | #define FWLINK_FLAG_IGNORE BIT(1)
|
| 72 |
|
| 73 | struct fwnode_link {
|
| 74 | struct fwnode_handle *supplier;
|
| 75 | struct list_head s_hook;
|
| 76 | struct fwnode_handle *consumer;
|
| 77 | struct list_head c_hook;
|
| 78 | u8 flags;
|
| 79 | };
|
| 80 |
|
| 81 | |
| 82 | * struct fwnode_endpoint - Fwnode graph endpoint
|
| 83 | * @port: Port number
|
| 84 | * @id: Endpoint id
|
| 85 | * @local_fwnode: reference to the related fwnode
|
| 86 |
|
| 87 | struct fwnode_endpoint {
|
| 88 | unsigned int port;
|
| 89 | unsigned int id;
|
| 90 | const struct fwnode_handle *local_fwnode;
|
| 91 | };
|
| 92 |
|
| 93 | |
| 94 | * ports and endpoints defined as software_nodes should all follow a common
|
| 95 | * naming scheme; use these macros to ensure commonality.
|
| 96 |
|
| 97 | #define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
|
| 98 | #define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
|
| 99 |
|
| 100 | #define NR_FWNODE_REFERENCE_ARGS 16
|
| 101 |
|
| 102 | |
| 103 | * struct fwnode_reference_args - Fwnode reference with additional arguments
|
| 104 | * @fwnode:- A reference to the base fwnode
|
| 105 | * @nargs: Number of elements in @args array
|
| 106 | * @args: Integer arguments on the fwnode
|
| 107 |
|
| 108 | struct fwnode_reference_args {
|
| 109 | struct fwnode_handle *fwnode;
|
| 110 | unsigned int nargs;
|
| 111 | u64 args[NR_FWNODE_REFERENCE_ARGS];
|
| 112 | };
|
| 113 |
|
| 114 | |
| 115 | * struct fwnode_operations - Operations for fwnode interface
|
| 116 | * @get: Get a reference to an fwnode.
|
| 117 | * @put: Put a reference to an fwnode.
|
| 118 | * @device_is_available: Return true if the device is available.
|
| 119 | * @device_get_match_data: Return the device driver match data.
|
| 120 | * @device_dma_supported: Return true if DMA is supported.
|
| 121 | * @device_get_dma_attr: Return the device DMA attribute.
|
| 122 | * @property_present: Return true if a property is present.
|
| 123 | * @property_read_bool: Return a boolean property value.
|
| 124 | * @property_read_int_array: Read an array of integer properties. Return zero on
|
| 125 | * success, a negative error code otherwise.
|
| 126 | * @property_read_string_array: Read an array of string properties. Return zero
|
| 127 | * on success, a negative error code otherwise.
|
| 128 | * @get_name: Return the name of an fwnode.
|
| 129 | * @get_name_prefix: Get a prefix for a node (for printing purposes).
|
| 130 | * @get_parent: Return the parent of an fwnode.
|
| 131 | * @get_next_child_node: Return the next child node in an iteration.
|
| 132 | * @get_named_child_node: Return a child node with a given name.
|
| 133 | * @get_reference_args: Return a reference pointed to by a property, with args
|
| 134 | * @graph_get_next_endpoint: Return an endpoint node in an iteration.
|
| 135 | * @graph_get_remote_endpoint: Return the remote endpoint node of a local
|
| 136 | * endpoint node.
|
| 137 | * @graph_get_port_parent: Return the parent node of a port node.
|
| 138 | * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
|
| 139 | * @iomap: Map the I/O memory of a given index for a fwnode.
|
| 140 | * @irq_get: Get the IRQ of a given index for a fwnode.
|
| 141 | * @add_links: Create fwnode links to all the suppliers of the fwnode. Return
|
| 142 | * zero on success, a negative error code otherwise.
|
| 143 |
|
| 144 | struct fwnode_operations {
|
| 145 | struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
|
| 146 | void (*put)(struct fwnode_handle *fwnode);
|
| 147 | bool (*device_is_available)(const struct fwnode_handle *fwnode);
|
| 148 | const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
|
| 149 | const struct device *dev);
|
| 150 | bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
|
| 151 | enum dev_dma_attr
|
| 152 | (*device_get_dma_attr)(const struct fwnode_handle *fwnode);
|
| 153 | bool (*property_present)(const struct fwnode_handle *fwnode,
|
| 154 | const char *propname);
|
| 155 | bool (*property_read_bool)(const struct fwnode_handle *fwnode,
|
| 156 | const char *propname);
|
| 157 | int (*property_read_int_array)(const struct fwnode_handle *fwnode,
|
| 158 | const char *propname,
|
| 159 | unsigned int elem_size, void *val,
|
| 160 | size_t nval);
|
| 161 | int
|
| 162 | (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
|
| 163 | const char *propname, const char **val,
|
| 164 | size_t nval);
|
| 165 | const char *(*get_name)(const struct fwnode_handle *fwnode);
|
| 166 | const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
|
| 167 | struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
|
| 168 | struct fwnode_handle *
|
| 169 | (*get_next_child_node)(const struct fwnode_handle *fwnode,
|
| 170 | struct fwnode_handle *child);
|
| 171 | struct fwnode_handle *
|
| 172 | (*get_named_child_node)(const struct fwnode_handle *fwnode,
|
| 173 | const char *name);
|
| 174 | int (*get_reference_args)(const struct fwnode_handle *fwnode,
|
| 175 | const char *prop, const char *nargs_prop,
|
| 176 | unsigned int nargs, unsigned int index,
|
| 177 | struct fwnode_reference_args *args);
|
| 178 | struct fwnode_handle *
|
| 179 | (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
|
| 180 | struct fwnode_handle *prev);
|
| 181 | struct fwnode_handle *
|
| 182 | (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
|
| 183 | struct fwnode_handle *
|
| 184 | (*graph_get_port_parent)(struct fwnode_handle *fwnode);
|
| 185 | int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
|
| 186 | struct fwnode_endpoint *endpoint);
|
| 187 | void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
|
| 188 | int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
|
| 189 | int (*add_links)(struct fwnode_handle *fwnode);
|
| 190 | };
|
| 191 |
|
| 192 | #define fwnode_has_op(fwnode, op) \
|
| 193 | (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op)
|
| 194 |
|
| 195 | #define fwnode_call_int_op(fwnode, op, ...) \
|
| 196 | (fwnode_has_op(fwnode, op) ? \
|
| 197 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))
|
| 198 |
|
| 199 | #define fwnode_call_bool_op(fwnode, op, ...) \
|
| 200 | (fwnode_has_op(fwnode, op) ? \
|
| 201 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
|
| 202 |
|
| 203 | #define fwnode_call_ptr_op(fwnode, op, ...) \
|
| 204 | (fwnode_has_op(fwnode, op) ? \
|
| 205 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
|
| 206 | #define fwnode_call_void_op(fwnode, op, ...) \
|
| 207 | do { \
|
| 208 | if (fwnode_has_op(fwnode, op)) \
|
| 209 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
|
| 210 | } while (false)
|
| 211 |
|
| 212 | static inline void fwnode_init(struct fwnode_handle *fwnode,
|
| 213 | const struct fwnode_operations *ops)
|
| 214 | {
|
| 215 | fwnode->secondary = NULL;
|
| 216 | fwnode->ops = ops;
|
| 217 | fwnode->dev = NULL;
|
| 218 | INIT_LIST_HEAD(&fwnode->consumers);
|
| 219 | INIT_LIST_HEAD(&fwnode->suppliers);
|
| 220 | fwnode->flags = 0;
|
| 221 | }
|
| 222 |
|
| 223 | static inline void fwnode_set_flag(struct fwnode_handle *fwnode,
|
| 224 | unsigned int bit)
|
| 225 | {
|
| 226 | set_bit(bit, &fwnode->flags);
|
| 227 | }
|
| 228 |
|
| 229 | static inline void fwnode_clear_flag(struct fwnode_handle *fwnode,
|
| 230 | unsigned int bit)
|
| 231 | {
|
| 232 | clear_bit(bit, &fwnode->flags);
|
| 233 | }
|
| 234 |
|
| 235 | static inline void fwnode_assign_flag(struct fwnode_handle *fwnode,
|
| 236 | unsigned int bit, bool value)
|
| 237 | {
|
| 238 | assign_bit(bit, &fwnode->flags, value);
|
| 239 | }
|
| 240 |
|
| 241 | static inline bool fwnode_test_flag(struct fwnode_handle *fwnode,
|
| 242 | unsigned int bit)
|
| 243 | {
|
| 244 | return test_bit(bit, &fwnode->flags);
|
| 245 | }
|
| 246 |
|
| 247 | static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
|
| 248 | bool initialized)
|
| 249 | {
|
| 250 | if (IS_ERR_OR_NULL(fwnode))
|
| 251 | return;
|
| 252 |
|
| 253 | fwnode_assign_flag(fwnode, FWNODE_FLAG_INITIALIZED, initialized);
|
| 254 | }
|
| 255 |
|
| 256 | int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup,
|
| 257 | u8 flags);
|
| 258 | void fwnode_links_purge(struct fwnode_handle *fwnode);
|
| 259 | void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
|
| 260 | void fw_devlink_refresh_fwnode(struct fwnode_handle *fwnode);
|
| 261 | bool fw_devlink_is_strict(void);
|
| 262 |
|
| 263 | #endif
|