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/list.h> 14 15 struct fwnode_operations; 16 struct device; 17 18 /* 19 * fwnode link flags 20 * 21 * LINKS_ADDED: The fwnode has already be parsed to add fwnode links. 22 */ 23 #define FWNODE_FLAG_LINKS_ADDED BIT(0) 24 25 struct fwnode_handle { 26 struct fwnode_handle *secondary; 27 const struct fwnode_operations *ops; 28 struct device *dev; 29 struct list_head suppliers; 30 struct list_head consumers; 31 u8 flags; 32 }; 33 34 struct fwnode_link { 35 struct fwnode_handle *supplier; 36 struct list_head s_hook; 37 struct fwnode_handle *consumer; 38 struct list_head c_hook; 39 }; 40 41 /** 42 * struct fwnode_endpoint - Fwnode graph endpoint 43 * @port: Port number 44 * @id: Endpoint id 45 * @local_fwnode: reference to the related fwnode 46 */ 47 struct fwnode_endpoint { 48 unsigned int port; 49 unsigned int id; 50 const struct fwnode_handle *local_fwnode; 51 }; 52 53 #define NR_FWNODE_REFERENCE_ARGS 8 54 55 /** 56 * struct fwnode_reference_args - Fwnode reference with additional arguments 57 * @fwnode:- A reference to the base fwnode 58 * @nargs: Number of elements in @args array 59 * @args: Integer arguments on the fwnode 60 */ 61 struct fwnode_reference_args { 62 struct fwnode_handle *fwnode; 63 unsigned int nargs; 64 u64 args[NR_FWNODE_REFERENCE_ARGS]; 65 }; 66 67 /** 68 * struct fwnode_operations - Operations for fwnode interface 69 * @get: Get a reference to an fwnode. 70 * @put: Put a reference to an fwnode. 71 * @device_is_available: Return true if the device is available. 72 * @device_get_match_data: Return the device driver match data. 73 * @property_present: Return true if a property is present. 74 * @property_read_int_array: Read an array of integer properties. Return zero on 75 * success, a negative error code otherwise. 76 * @property_read_string_array: Read an array of string properties. Return zero 77 * on success, a negative error code otherwise. 78 * @get_name: Return the name of an fwnode. 79 * @get_name_prefix: Get a prefix for a node (for printing purposes). 80 * @get_parent: Return the parent of an fwnode. 81 * @get_next_child_node: Return the next child node in an iteration. 82 * @get_named_child_node: Return a child node with a given name. 83 * @get_reference_args: Return a reference pointed to by a property, with args 84 * @graph_get_next_endpoint: Return an endpoint node in an iteration. 85 * @graph_get_remote_endpoint: Return the remote endpoint node of a local 86 * endpoint node. 87 * @graph_get_port_parent: Return the parent node of a port node. 88 * @graph_parse_endpoint: Parse endpoint for port and endpoint id. 89 * @add_links: Create fwnode links to all the suppliers of the fwnode. Return 90 * zero on success, a negative error code otherwise. 91 */ 92 struct fwnode_operations { 93 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); 94 void (*put)(struct fwnode_handle *fwnode); 95 bool (*device_is_available)(const struct fwnode_handle *fwnode); 96 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, 97 const struct device *dev); 98 bool (*property_present)(const struct fwnode_handle *fwnode, 99 const char *propname); 100 int (*property_read_int_array)(const struct fwnode_handle *fwnode, 101 const char *propname, 102 unsigned int elem_size, void *val, 103 size_t nval); 104 int 105 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, 106 const char *propname, const char **val, 107 size_t nval); 108 const char *(*get_name)(const struct fwnode_handle *fwnode); 109 const char *(*get_name_prefix)(const struct fwnode_handle *fwnode); 110 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); 111 struct fwnode_handle * 112 (*get_next_child_node)(const struct fwnode_handle *fwnode, 113 struct fwnode_handle *child); 114 struct fwnode_handle * 115 (*get_named_child_node)(const struct fwnode_handle *fwnode, 116 const char *name); 117 int (*get_reference_args)(const struct fwnode_handle *fwnode, 118 const char *prop, const char *nargs_prop, 119 unsigned int nargs, unsigned int index, 120 struct fwnode_reference_args *args); 121 struct fwnode_handle * 122 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, 123 struct fwnode_handle *prev); 124 struct fwnode_handle * 125 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); 126 struct fwnode_handle * 127 (*graph_get_port_parent)(struct fwnode_handle *fwnode); 128 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, 129 struct fwnode_endpoint *endpoint); 130 int (*add_links)(struct fwnode_handle *fwnode); 131 }; 132 133 #define fwnode_has_op(fwnode, op) \ 134 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) 135 #define fwnode_call_int_op(fwnode, op, ...) \ 136 (fwnode ? (fwnode_has_op(fwnode, op) ? \ 137 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ 138 -EINVAL) 139 140 #define fwnode_call_bool_op(fwnode, op, ...) \ 141 (fwnode_has_op(fwnode, op) ? \ 142 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) 143 144 #define fwnode_call_ptr_op(fwnode, op, ...) \ 145 (fwnode_has_op(fwnode, op) ? \ 146 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) 147 #define fwnode_call_void_op(fwnode, op, ...) \ 148 do { \ 149 if (fwnode_has_op(fwnode, op)) \ 150 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ 151 } while (false) 152 #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) 153 154 static inline void fwnode_init(struct fwnode_handle *fwnode, 155 const struct fwnode_operations *ops) 156 { 157 fwnode->ops = ops; 158 INIT_LIST_HEAD(&fwnode->consumers); 159 INIT_LIST_HEAD(&fwnode->suppliers); 160 } 161 162 extern u32 fw_devlink_get_flags(void); 163 int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup); 164 void fwnode_links_purge(struct fwnode_handle *fwnode); 165 166 #endif 167